rclone/librclone/ctest/ctest.c
Nick Craig-Wood f38c262471 librclone: change interface for C code and add Mobile interface #4891
This changes the interface for the C code to return a struct on the
stack that is defined in the code rather than one which is defined by
the cgo compiler. This is more future proof and inline with the
gomobile interface.

This also adds a gomobile interface RcloneMobileRPC which uses generic
go types conforming to the gobind restrictions.

It also fixes up initialisation errors.
2021-04-28 16:55:08 +01:00

63 lines
1.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include "librclone.h"
void testRPC(char *method, char *in) {
struct RcloneRPCResult out = RcloneRPC(method, in);
printf("status: %d\n", out.Status);
printf("output: %s\n", out.Output);
free(out.Output);
}
// noop command
void testNoOp() {
printf("test rc/noop\n");
testRPC("rc/noop",
"{"
" \"p1\": [1,\"2\",null,4],"
" \"p2\": { \"a\":1, \"b\":2 } "
"}");
}
// error command
void testError() {
printf("test rc/error\n");
testRPC("rc/error",
"{"
" \"p1\": [1,\"2\",null,4],"
" \"p2\": { \"a\":1, \"b\":2 } "
"}");
}
// copy file using "operations/copyfile" command
void testCopyFile() {
printf("test operations/copyfile\n");
testRPC("operations/copyfile",
"{"
"\"srcFs\": \"/tmp\","
"\"srcRemote\": \"tmpfile\","
"\"dstFs\": \"/tmp\","
"\"dstRemote\": \"tmpfile2\""
"}");
}
// list the remotes
void testListRemotes() {
printf("test operations/listremotes\n");
testRPC("config/listremotes", "{}");
}
int main(int argc, char** argv) {
printf("c main begin\n");
RcloneInitialize();
testNoOp();
testError();
testCopyFile();
testListRemotes();
RcloneFinalize();
return EXIT_SUCCESS;
}