Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c620ad1

Browse files
committedDec 22, 2021
Add test case to check multivalue properties split
1 parent 0e97621 commit c620ad1

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
 

‎extras/test/src/test_encode.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,53 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]"
443443
}
444444

445445
/************************************************************************************/
446+
447+
WHEN("The size of the encoded properties is exceeding the CBOR buffer size and includes a multivalue property")
448+
{
449+
PropertyContainer property_container;
450+
451+
CloudInt int_0; int_0 = 1000000;
452+
CloudInt int_1; int_1 = 1000001;
453+
CloudInt int_2; int_2 = 1000002;
454+
CloudInt int_3; int_3 = 1000003;
455+
CloudInt int_4; int_4 = 1000004;
456+
CloudInt int_5; int_5 = 1000005;
457+
CloudInt int_6; int_6 = 1000006;
458+
CloudInt int_7; int_7 = 1000007;
459+
CloudInt int_8; int_8 = 1000008;
460+
CloudInt int_9; int_9 = 1000009;
461+
CloudInt int_A; int_A = 1000010;
462+
CloudSchedule schedule = CloudSchedule(1633305600, 1633651200, 600, 1140850708);
463+
464+
addPropertyToContainer(property_container, int_0, "int_value_0", Permission::ReadWrite);
465+
addPropertyToContainer(property_container, int_1, "int_value_1", Permission::ReadWrite);
466+
addPropertyToContainer(property_container, int_2, "int_value_2", Permission::ReadWrite);
467+
addPropertyToContainer(property_container, int_3, "int_value_3", Permission::ReadWrite);
468+
addPropertyToContainer(property_container, int_4, "int_value_4", Permission::ReadWrite);
469+
addPropertyToContainer(property_container, int_5, "int_value_5", Permission::ReadWrite);
470+
addPropertyToContainer(property_container, int_6, "int_value_6", Permission::ReadWrite);
471+
addPropertyToContainer(property_container, int_7, "int_value_7", Permission::ReadWrite);
472+
addPropertyToContainer(property_container, int_8, "int_value_8", Permission::ReadWrite);
473+
addPropertyToContainer(property_container, int_9, "int_value_9", Permission::ReadWrite);
474+
addPropertyToContainer(property_container, int_A, "int_value_A", Permission::ReadWrite);
475+
addPropertyToContainer(property_container, schedule, "schedule", Permission::ReadWrite);
476+
477+
/* Due to the size if the encoded properties exceeding 256 bytes if encoded all at
478+
* once they are encoded in subsequent calls to CBOREncoder::encode.
479+
*/
480+
481+
/* [{0: "int_value_0", 2: 1000000}, {0: "int_value_1", 2: 1000001}, {0: "int_value_2", 2: 1000002}, {0: "int_value_3", 2: 1000003}, {0: "int_value_4", 2: 1000004}, {0: "int_value_5", 2: 1000005}, {0: "int_value_6", 2: 1000006}, {0: "int_value_7", 2: 1000007}, {0: "int_value_8", 2: 1000008}, {0: "int_value_9", 2: 1000009}, {0: "int_value_A", 2: 1000010}]
482+
* = 9F A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 30 02 1A 00 0F 42 40 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 31 02 1A 00 0F 42 41 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 32 02 1A 00 0F 42 42 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 33 02 1A 00 0F 42 43 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 34 02 1A 00 0F 42 44 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 35 02 1A 00 0F 42 45 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 36 02 1A 00 0F 42 46 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 37 02 1A 00 0F 42 47 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 38 02 1A 00 0F 42 48 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 39 02 1A 00 0F 42 49 A2 00 6B 69 6E 74 5F 76 61 6C 75 65 5F 41 02 1A 00 0F 42 4A FF
483+
*/
484+
std::vector<uint8_t> const expected_1 = {0x9F, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x30, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x40, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x31, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x41, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x32, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x42, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x33, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x43, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x34, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x44, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x35, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x45, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x36, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x46, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x37, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x47, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x38, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x48, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x39, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x49, 0xA2, 0x00, 0x6B, 0x69, 0x6E, 0x74, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x5F, 0x41, 0x02, 0x1A, 0x00, 0x0F, 0x42, 0x4A, 0xFF};
485+
std::vector<uint8_t> const actual_1 = cbor::encode(property_container);
486+
REQUIRE(actual_1 == expected_1);
487+
488+
/* [{0: "schedule:frm", 2: 1633305600}, {0: "schedule:to", 2: 1633651200}, {0: "schedule:len", 2: 600}, {0: "schedule:msk", 2: 1140850708}]
489+
* = 9F A2 00 6C 73 63 68 65 64 75 6C 65 3A 66 72 6D 02 1A 61 5A 44 00 A2 00 6B 73 63 68 65 64 75 6C 65 3A 74 6F 02 1A 61 5F 8A 00 A2 00 6C 73 63 68 65 64 75 6C 65 3A 6C 65 6E 02 19 02 58 A2 00 6C 73 63 68 65 64 75 6C 65 3A 6D 73 6B 02 1A 44 00 00 14 FF
490+
*/
491+
std::vector<uint8_t> const expected_2 = {0x9F, 0xA2, 0x00, 0x6C, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6C, 0x65, 0x3A, 0x66, 0x72, 0x6D, 0x02, 0x1A, 0x61, 0x5A, 0x44, 0x00, 0xA2, 0x00, 0x6B, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6C, 0x65, 0x3A, 0x74, 0x6F, 0x02, 0x1A, 0x61, 0x5F, 0x8A, 0x00, 0xA2, 0x00, 0x6C, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6C, 0x65, 0x3A, 0x6C, 0x65, 0x6E, 0x02, 0x19, 0x02, 0x58, 0xA2, 0x00, 0x6C, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6C, 0x65, 0x3A, 0x6D, 0x73, 0x6B, 0x02, 0x1A, 0x44, 0x00, 0x00, 0x14, 0xFF};
492+
std::vector<uint8_t> const actual_2 = cbor::encode(property_container);
493+
REQUIRE(actual_2 == expected_2);
494+
}
446495
}

0 commit comments

Comments
 (0)
Please sign in to comment.