Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit c869a88

Browse files
authored
Merge pull request #12 from bcmi-labs/test/add-test-for-undefined-cbor-map-key
Implementing test for verifying correct behaviour in case of a undefined CBOR map key
2 parents ecceec0 + 85b4543 commit c869a88

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/src/test_decode.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,38 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
412412
}
413413

414414
/************************************************************************************/
415+
416+
WHEN("A payload containing a invalid CBOR key is parsed")
417+
{
418+
GIVEN("CloudProtocol::V1")
419+
{
420+
ArduinoCloudThing thing(CloudProtocol::V1);
421+
thing.begin();
422+
423+
int test = 0;
424+
thing.addPropertyReal(test, "test", Permission::ReadWrite);
425+
426+
/* [{"undef": 123, "n": "test", "v": 1}] = 81 A3 65 75 6E 64 65 66 18 7B 61 6E 64 74 65 73 74 61 76 01 */
427+
uint8_t const payload[] = {0x81, 0xA3, 0x65, 0x75, 0x6E, 0x64, 0x65, 0x66, 0x18, 0x7B, 0x61, 0x6E, 0x64, 0x74, 0x65, 0x73, 0x74, 0x61, 0x76, 0x01};
428+
thing.decode(payload, sizeof(payload)/sizeof(uint8_t));
429+
430+
REQUIRE(test == 1);
431+
}
432+
GIVEN("CloudProtocol::V2")
433+
{
434+
ArduinoCloudThing thing(CloudProtocol::V2);
435+
thing.begin();
436+
437+
int test = 0;
438+
thing.addPropertyReal(test, "test", Permission::ReadWrite);
439+
440+
/* [{123: 123, 0: "test", 2: 1}] = 81 A3 18 7B 18 7B 00 64 74 65 73 74 02 01 */
441+
uint8_t const payload[] = {0x81, 0xA3, 0x18, 0x7B, 0x18, 0x7B, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01};
442+
thing.decode(payload, sizeof(payload)/sizeof(uint8_t));
443+
444+
REQUIRE(test == 1);
445+
}
446+
}
447+
448+
/************************************************************************************/
415449
}

0 commit comments

Comments
 (0)