From 28f36a2e69e13ee326d8bda50ad7a8df4e74d63a Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Sun, 4 Oct 2026 23:51:01 +0200 Subject: Saving done --- test/auth.c | 85 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'test/auth.c') diff --git a/test/auth.c b/test/auth.c index 40e2678..1a31ae4 100644 --- a/test/auth.c +++ b/test/auth.c @@ -1,48 +1,11 @@ #include -#include -#include +#include #include #include #include "api.h" -struct ExpectedRequest { - bool ignore; - char *url; - char *token; - char *reqBody; - - struct SizedBlock retBody; - enum ReturnCode rc; -}; - -struct ExpectedRequest *nextResult = NULL; - -enum ReturnCode transport_request(char *url, char *token, char *reqBody, struct SizedBlock *retBody) { - assert(nextResult != NULL); - assert(strcmp(nextResult->url, url) == 0); - if(nextResult->reqBody == NULL) { - assert(nextResult->reqBody == NULL); - } else { - assert(reqBody != NULL); - assert(strcmp(nextResult->reqBody, reqBody) == 0); - } - - if(nextResult->token == NULL) { - assert(nextResult->token == NULL); - } else { - assert(token != NULL); - assert(strcmp(nextResult->token, token) == 0); - } - - - memcpy(retBody, &nextResult->retBody, sizeof(struct SizedBlock)); - - enum ReturnCode rc = nextResult->rc; - nextResult++; - return rc; -} - +extern struct ExpectedRequest *nextResult; #define STATIC_SIZED_BLOCK(str) {.size = sizeof(str), .memory = strdup(str)} int main() { @@ -95,7 +58,7 @@ int main() { char *code = "123456"; struct RMDevice device = { - .id = "5E35708B-59B6-4715-A5D8-576C741D8276" + .id = "5E35708B-59B6-4715-A5D8-576C741D8276", }; rc = rm_device_open(&device, code); assert(rc == RC_SUCCESS); @@ -140,5 +103,47 @@ int main() { // @COMPLETE We currently don't check that all the requests fired } + nextResult = (struct ExpectedRequest[]) { + { + .url = "https://internal.cloud.remarkable.com/sync/v4/root", + .token = "SomeUserToken", + .reqBody = NULL, + .retBody = STATIC_SIZED_BLOCK("{\"hash\": \"0000000000000000000000000000000000000000000000000000000000000000\", \"generation\": 1}"), + .rc = RC_SUCCESS, + }, + { + .url = "https://internal.cloud.remarkable.com/sync/v4/files/0000000000000000000000000000000000000000000000000000000000000000", + .token = "SomeUserToken", + .reqBody = NULL, + .retBody = STATIC_SIZED_BLOCK( + "3\n" + "0000000000000000000000000000000000000000000000000000000000000001:CollectionType:someId:1:0\n" + ), + .rc = RC_SUCCESS, + }, + }; + + { + enum ReturnCode rc; + + struct RMDevice device = { + .userToken = strdup("SomeUserToken"), + .deviceToken = strdup("SomeDeviceToken"), + }; + rc = rm_device_reopen(&device); + assert(rc == RC_SUCCESS); + + assert(memcmp(device.root, "0000000000000000000000000000000000000000000000000000000000000000", sizeof(device.root)) == 0); + assert(device.generation == 1); + + struct RMDir dir = {}; + rc = rm_dir_root(&device, &dir); + assert(rc == RC_SUCCESS); + + rm_device_close(&device); + + // @COMPLETE We currently don't check that all the requests fired + } + return 0; } -- cgit v1.2.3