Skip to content

Commit

Permalink
chore: astyle (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfields authored Jan 29, 2025
1 parent 23c2338 commit 3910cbd
Showing 1 changed file with 86 additions and 113 deletions.
199 changes: 86 additions & 113 deletions test/src/_crcError_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,170 +22,143 @@ extern bool notecardFirmwareSupportsCrc;
namespace
{

SCENARIO("_crcError")
{
GIVEN("The Notecard firmware does NOT support CRC") {
notecardFirmwareSupportsCrc = false;
SCENARIO("_crcError")
{
GIVEN("The Notecard firmware does NOT support CRC") {
notecardFirmwareSupportsCrc = false;

NoteSetFnDefault(malloc, free, NULL, NULL);
NoteSetFnDefault(malloc, free, NULL, NULL);

uint16_t seqNo = 1;
uint16_t seqNo = 1;

AND_GIVEN("An empty string")
{
char json[] = "";
AND_GIVEN("An empty string") {
char json[] = "";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("Invalid JSON")
{
char json[] = "{\"req\":";
AND_GIVEN("Invalid JSON") {
char json[] = "{\"req\":";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("The Notecard returns an error message") {
char json[] = "{\"err\":\"cannot interpret JSON: bool being placed into a non-bool field {io}\"}";
AND_GIVEN("The Notecard returns an error message") {
char json[] = "{\"err\":\"cannot interpret JSON: bool being placed into a non-bool field {io}\"}";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("No CRC field")
{
char json[] = "{\"req\": \"hub.sync\"}";
AND_GIVEN("No CRC field") {
char json[] = "{\"req\": \"hub.sync\"}";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("The CRC field exists, but is not at the tail of the response")
{
char json[] = "{\"crc\":\"0009:10BAC79A\",\"req\": \"hub.sync\"}";
AND_GIVEN("The CRC field exists, but is not at the tail of the response") {
char json[] = "{\"crc\":\"0009:10BAC79A\",\"req\": \"hub.sync\"}";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}
}

GIVEN("The Notecard firmware supports CRC") {
notecardFirmwareSupportsCrc = true;
GIVEN("The Notecard firmware supports CRC") {
notecardFirmwareSupportsCrc = true;

NoteSetFnDefault(malloc, free, NULL, NULL);
NoteSetFnDefault(malloc, free, NULL, NULL);

uint16_t seqNo = 1;
uint16_t seqNo = 1;

AND_GIVEN("An empty string")
{
char json[] = "";
AND_GIVEN("An empty string") {
char json[] = "";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("Invalid JSON")
{
char json[] = "{\"req\":";
AND_GIVEN("Invalid JSON") {
char json[] = "{\"req\":";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("The Notecard returns an error message") {
char json[] = "{\"err\":\"cannot interpret JSON: bool being placed into a non-bool field {io}\"}";
AND_GIVEN("The Notecard returns an error message") {
char json[] = "{\"err\":\"cannot interpret JSON: bool being placed into a non-bool field {io}\"}";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("No CRC field")
{
char json[] = "{\"req\": \"hub.sync\"}";
AND_GIVEN("No CRC field") {
char json[] = "{\"req\": \"hub.sync\"}";

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}
}

AND_GIVEN("The CRC field exists, but is not at the tail of the response")
{
char json[] = "{\"crc\":\"0009:10BAC79A\",\"req\": \"hub.sync\"}";
AND_GIVEN("The CRC field exists, but is not at the tail of the response") {
char json[] = "{\"crc\":\"0009:10BAC79A\",\"req\": \"hub.sync\"}";

THEN("A CRC error SHALL be reported")
{
CHECK(_crcError(json, seqNo));
}
THEN("A CRC error SHALL be reported") {
CHECK(_crcError(json, seqNo));
}
}

AND_GIVEN("Valid JSON and CRC field present")
{
WHEN("CRC doesn't match")
{
char json[] = "{\"req\":\"hub.sync\",\"crc\":\"0001:DEADBEEF\"}";
AND_GIVEN("Valid JSON and CRC field present") {
WHEN("CRC doesn't match") {
char json[] = "{\"req\":\"hub.sync\",\"crc\":\"0001:DEADBEEF\"}";

THEN("A CRC error SHALL be reported")
{
CHECK(_crcError(json, seqNo));
}
THEN("A CRC error SHALL be reported") {
CHECK(_crcError(json, seqNo));
}
}

WHEN("Sequence number doesn't match")
{
char json[] = "{\"req\":\"hub.sync\",\"crc\":\"0009:10BAC79A\"}";
WHEN("Sequence number doesn't match") {
char json[] = "{\"req\":\"hub.sync\",\"crc\":\"0009:10BAC79A\"}";

THEN("A CRC error SHALL be reported")
{
CHECK(_crcError(json, seqNo));
}
THEN("A CRC error SHALL be reported") {
CHECK(_crcError(json, seqNo));
}
}

WHEN("Everything matches")
{
char json[] = "{\"req\":\"hub.sync\"}";
char *jsonWithCrc = _crcAdd(json, seqNo);
REQUIRE(jsonWithCrc != NULL);

THEN("A CRC error SHALL NOT be reported")
{
CHECK(!_crcError(json, seqNo));
}
WHEN("Everything matches") {
char json[] = "{\"req\":\"hub.sync\"}";
char *jsonWithCrc = _crcAdd(json, seqNo);
REQUIRE(jsonWithCrc != NULL);

NoteFree(jsonWithCrc);
THEN("A CRC error SHALL NOT be reported") {
CHECK(!_crcError(json, seqNo));
}

AND_GIVEN("a trailing CRLF")
{
char json[] = "{\"req\":\"hub.sync\",\"crc\":\"0001:10BAC79A\"}\r\n";
NoteFree(jsonWithCrc);
}

AND_GIVEN("a trailing CRLF") {
char json[] = "{\"req\":\"hub.sync\",\"crc\":\"0001:10BAC79A\"}\r\n";

THEN("A CRC error SHALL NOT be reported")
{
// Trailing \r\n should be ignored.
CHECK(!_crcError(json, seqNo));
}
THEN("A CRC error SHALL NOT be reported") {
// Trailing \r\n should be ignored.
CHECK(!_crcError(json, seqNo));
}
}
}
}
}
}

#endif // !NOTE_C_LOW_MEM

0 comments on commit 3910cbd

Please sign in to comment.