Skip to content

Commit

Permalink
Add tests for Note Transactions that check that both UTF-8 encoded st…
Browse files Browse the repository at this point in the history
…rings will parse JSON objects, and that UTF-16 encoded strings generate an {io} error on JSON parse (#154)
  • Loading branch information
gwolffblues authored Sep 10, 2024
1 parent c828782 commit 55a51be
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/src/NoteTransaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,47 @@ SCENARIO("NoteTransaction")
JDelete(resp);
}

WHEN("The transaction is successful, and contains UTF-8 encoded characters in valid JSON"){
J* req = NoteNewRequest("web.get");
REQUIRE(req != NULL);
noteJSONTransaction_fake.custom_fake = [] (const char *, size_t, char **response, uint32_t) -> const char * {
const char rsp_str[] = "{\"area\":\"\"}";
*response = (char *)malloc(sizeof(rsp_str));
strncpy(*response, rsp_str, sizeof(rsp_str));
return nullptr;
};
J* resp = NoteTransaction(req);
THEN("An error is not returned") {
CHECK(resp != NULL);
CHECK(!JIsPresent(resp, "err"));
}

JDelete(req);
JDelete(resp);
}

WHEN("The transaction is successful, and contains UTF-16 encoded characters in valid JSON"){
J* req = NoteNewRequest("web.get");
REQUIRE(req != NULL);
noteJSONTransaction_fake.custom_fake = [] (const char *, size_t, char **response, uint32_t) -> const char * {
const uint8_t rsp_str[] = {0xff, 0xfe, 0x7b, 0x00, 0x22, 0x00, 0x61, 0x00, 0x72, 0x00, 0x65, 0x00, 0x61, 0x00, 0x22, 0x00, 0x3a, 0x00, 0x22, 0x00, 0x62, 0x00, 0xed, 0x00, 0x22, 0x00, 0x7d, 0x00};
*response = (char *)malloc(sizeof(rsp_str));
memcpy(*response, rsp_str, sizeof(rsp_str));
return nullptr;
};
J* resp = NoteTransaction(req);
THEN("An {io} error is returned") {
CHECK(resp != NULL);
CHECK(JIsPresent(resp, "err"));
CHECK(JContainsString(resp, "err", "{io}"));
}

JDelete(req);
JDelete(resp);
}



#ifndef NOTE_C_LOW_MEM
SECTION("Bad CRC") {
J *req = NoteNewRequest("note.add");
Expand Down

0 comments on commit 55a51be

Please sign in to comment.