|
20 | 20 | TEST CODE
|
21 | 21 | **************************************************************************************/
|
22 | 22 |
|
23 |
| -SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") { |
| 23 | +SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]") { |
24 | 24 | /************************************************************************************/
|
25 | 25 |
|
26 | 26 | WHEN("A 'bool' property is added") {
|
@@ -381,4 +381,59 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]")
|
381 | 381 | }
|
382 | 382 |
|
383 | 383 | /************************************************************************************/
|
| 384 | + |
| 385 | + WHEN("The size of the encoded properties is exceeding the CBOR buffer size") { |
| 386 | + GIVEN("CloudProtocol::V2") { |
| 387 | + PropertyContainer property_container; |
| 388 | + |
| 389 | + CloudString str_0; str_0 = "This string is 30 bytes long."; |
| 390 | + CloudString str_1; str_1 = "This string is 30 bytes long."; |
| 391 | + CloudString str_2; str_2 = "This string is 30 bytes long."; |
| 392 | + CloudString str_3; str_3 = "This string is 30 bytes long."; |
| 393 | + CloudString str_4; str_4 = "This string is 30 bytes long."; |
| 394 | + CloudString str_5; str_5 = "This string is 30 bytes long."; |
| 395 | + CloudString str_6; str_6 = "This string is 30 bytes long."; |
| 396 | + CloudString str_7; str_7 = "This string is 30 bytes long."; |
| 397 | + CloudString str_8; str_8 = "This string is 30 bytes long."; |
| 398 | + CloudString str_9; str_9 = "This string is 30 bytes long."; |
| 399 | + |
| 400 | + addPropertyToContainer(property_container, str_0, "str_0", Permission::ReadWrite); |
| 401 | + addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite); |
| 402 | + addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite); |
| 403 | + addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite); |
| 404 | + addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite); |
| 405 | + addPropertyToContainer(property_container, str_5, "str_5", Permission::ReadWrite); |
| 406 | + addPropertyToContainer(property_container, str_6, "str_6", Permission::ReadWrite); |
| 407 | + addPropertyToContainer(property_container, str_7, "str_7", Permission::ReadWrite); |
| 408 | + addPropertyToContainer(property_container, str_8, "str_8", Permission::ReadWrite); |
| 409 | + addPropertyToContainer(property_container, str_9, "str_9", Permission::ReadWrite); |
| 410 | + |
| 411 | + /* Due to the size if the encoded properties exceeding 256 bytes if encoded all at |
| 412 | + * once they are encoded in subsequent calls to CBOREncoder::encode. |
| 413 | + */ |
| 414 | + |
| 415 | + /* [{0: "str_0", 3: "This string is 30 bytes long."}, {0: "str_1", 3: "This string is 30 bytes long."}, {0: "str_2", 3: "This string is 30 bytes long."}, {0: "str_3", 3: "This string is 30 bytes long."}] |
| 416 | + * = 9F A2 00 65 73 74 72 5F 30 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 31 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 32 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 33 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E FF |
| 417 | + */ |
| 418 | + std::vector<uint8_t> const expected_1 = {0x9F, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x30, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x31, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x32, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x33, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xFF}; |
| 419 | + std::vector<uint8_t> const actual_1 = cbor::encode(property_container); |
| 420 | + REQUIRE(actual_1 == expected_1); |
| 421 | + |
| 422 | + /* [{0: "str_4", 3: "This string is 30 bytes long."}, {0: "str_5", 3: "This string is 30 bytes long."}, {0: "str_6", 3: "This string is 30 bytes long."}, {0: "str_7", 3: "This string is 30 bytes long."}] |
| 423 | + * = 9F A2 00 65 73 74 72 5F 34 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 35 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 36 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 37 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E FF |
| 424 | + */ |
| 425 | + std::vector<uint8_t> const expected_2 = {0x9F, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x34, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x35, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x36, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x37, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xFF}; |
| 426 | + std::vector<uint8_t> const actual_2 = cbor::encode(property_container); |
| 427 | + REQUIRE(actual_2 == expected_2); |
| 428 | + |
| 429 | + /* [{0: "str_8", 3: "This string is 30 bytes long."}, {0: "str_9", 3: "This string is 30 bytes long."}] |
| 430 | + * = 9F A2 00 65 73 74 72 5F 38 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 39 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E FF |
| 431 | + */ |
| 432 | + std::vector<uint8_t> const expected_3 = {0x9F, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x38, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x39, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xFF}; |
| 433 | + std::vector<uint8_t> const actual_3 = cbor::encode(property_container); |
| 434 | + REQUIRE(actual_3 == expected_3); |
| 435 | + } |
| 436 | + } |
| 437 | + |
| 438 | + /************************************************************************************/ |
384 | 439 | }
|
0 commit comments