diff --git a/extras/test/src/Arduino.cpp b/extras/test/src/Arduino.cpp index 9287ff399..74cd71252 100644 --- a/extras/test/src/Arduino.cpp +++ b/extras/test/src/Arduino.cpp @@ -18,10 +18,12 @@ static unsigned long current_millis = 0; PUBLIC FUNCTIONS ******************************************************************************/ -void set_millis(unsigned long const millis) { +void set_millis(unsigned long const millis) +{ current_millis = millis; } -unsigned long millis() { +unsigned long millis() +{ return current_millis; } diff --git a/extras/test/src/test_CloudColor.cpp b/extras/test/src/test_CloudColor.cpp index b621eff28..89ecfa955 100644 --- a/extras/test/src/test_CloudColor.cpp +++ b/extras/test/src/test_CloudColor.cpp @@ -16,109 +16,100 @@ TEST CODE **************************************************************************************/ -/************************************************************************************/ -SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudColor]") { - WHEN("Set invalid color HSB") { - GIVEN("CloudProtocol::V2") { - - - CloudColor color_test = CloudColor(0.0, 0.0, 0.0); - - Color value_color_test = color_test.getValue(); - REQUIRE(value_color_test.setColorHSB(500.0, 20.0, 30.0) == false); - - } +SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudColor]") +{ + WHEN("Set invalid color HSB") + { + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); + + Color value_color_test = color_test.getValue(); + REQUIRE(value_color_test.setColorHSB(500.0, 20.0, 30.0) == false); } - WHEN("Set and Get different RGB colors") { - GIVEN("CloudProtocol::V2") { + WHEN("Set and Get different RGB colors") + { + uint8_t r, g, b; - uint8_t r, g, b; + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); - CloudColor color_test = CloudColor(0.0, 0.0, 0.0); + Color value_color_test = color_test.getValue(); - Color value_color_test = color_test.getValue(); + value_color_test.setColorRGB(128, 64, 64); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(128, 64, 64); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 128); + REQUIRE(g == 64); + REQUIRE(b == 64); - REQUIRE(r == 128); - REQUIRE(g == 64); - REQUIRE(b == 64); + value_color_test.setColorRGB(126, 128, 64); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(126, 128, 64); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 126); + REQUIRE(g == 128); + REQUIRE(b == 64); - REQUIRE(r == 126); - REQUIRE(g == 128); - REQUIRE(b == 64); + value_color_test.setColorRGB(64, 128, 64); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(64, 128, 64); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 64); + REQUIRE(g == 128); + REQUIRE(b == 64); - REQUIRE(r == 64); - REQUIRE(g == 128); - REQUIRE(b == 64); + value_color_test.setColorRGB(64, 64, 128); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(64, 64, 128); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 64); + REQUIRE(g == 64); + REQUIRE(b == 128); - REQUIRE(r == 64); - REQUIRE(g == 64); - REQUIRE(b == 128); + value_color_test.setColorRGB(255, 0, 255); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(255, 0, 255); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 255); + REQUIRE(g == 0); + REQUIRE(b == 255); - REQUIRE(r == 255); - REQUIRE(g == 0); - REQUIRE(b == 255); + value_color_test.setColorRGB(0, 0, 0); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(0, 0, 0); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 0); + REQUIRE(g == 0); + REQUIRE(b == 0); - REQUIRE(r == 0); - REQUIRE(g == 0); - REQUIRE(b == 0); + value_color_test.setColorRGB(50, 100, 20); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(50, 100, 20); - value_color_test.getRGB(r, g, b); + REQUIRE(r == 50); + REQUIRE(g == 100); + REQUIRE(b == 20); - REQUIRE(r == 50); - REQUIRE(g == 100); - REQUIRE(b == 20); + value_color_test.setColorRGB(20, 50, 70); + value_color_test.getRGB(r, g, b); - value_color_test.setColorRGB(20, 50, 70); - value_color_test.getRGB(r, g, b); - - REQUIRE(r == 20); - REQUIRE(g == 50); - REQUIRE(b == 70); - - } + REQUIRE(r == 20); + REQUIRE(g == 50); + REQUIRE(b == 70); } - WHEN("Set HSB colors and get RGB") { - GIVEN("CloudProtocol::V2") { - bool verify; - uint8_t r, g, b; - - CloudColor color_test = CloudColor(0.0, 0.0, 0.0); + WHEN("Set HSB colors and get RGB") + { + bool verify; + uint8_t r, g, b; - Color value_color_test = color_test.getValue(); + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); - value_color_test.setColorHSB(240, 50, 50); - value_color_test.getRGB(r, g, b); - verify = r == 64 && g == 64 && b == 128; + Color value_color_test = color_test.getValue(); - REQUIRE(verify); + value_color_test.setColorHSB(240, 50, 50); + value_color_test.getRGB(r, g, b); + verify = r == 64 && g == 64 && b == 128; - value_color_test.setColorHSB(120, 50, 50); - value_color_test.getRGB(r, g, b); - verify = r == 64 && g == 128 && b == 64; + REQUIRE(verify); - REQUIRE(verify); + value_color_test.setColorHSB(120, 50, 50); + value_color_test.getRGB(r, g, b); + verify = r == 64 && g == 128 && b == 64; - } + REQUIRE(verify); } } \ No newline at end of file diff --git a/extras/test/src/test_CloudLocation.cpp b/extras/test/src/test_CloudLocation.cpp index 079bfaff9..d9acd0ae4 100644 --- a/extras/test/src/test_CloudLocation.cpp +++ b/extras/test/src/test_CloudLocation.cpp @@ -14,8 +14,10 @@ TEST CODE **************************************************************************************/ -SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]") { - WHEN("A Location(1.0f, 2.0f) is being instantiated") { +SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]") +{ + WHEN("A Location(1.0f, 2.0f) is being instantiated") + { Location loc(1.0f, 2.0f); THEN("The member variable 'lat' should be 1.0f") { REQUIRE(loc.lat == 1.0f); @@ -28,11 +30,14 @@ SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]") { /**************************************************************************************/ -SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operator =]") { +SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operator =]") +{ Location loc1(1.0f, 2.0f), loc2(3.0f, 4.0f); loc1 = loc2; - WHEN("One location is assigned to the other") { + + WHEN("One location is assigned to the other") + { THEN("The coordinates of the second location should be assigned to the first") { REQUIRE(loc1.lat == 3.0f); REQUIRE(loc1.lon == 4.0f); @@ -42,11 +47,14 @@ SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operato /**************************************************************************************/ -SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]") { +SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]") +{ Location loc1(1.0f, 2.0f), loc2(3.0f, 4.0f); Location loc3 = loc1 - loc2; - WHEN("One location is subtracted from the other") { + + WHEN("One location is subtracted from the other") + { THEN("The result should be calculated according the rule lon3 = lon1 - lon2, lat3 = lat1 - lat2") { REQUIRE(loc3.lat == loc1.lat - loc2.lat); REQUIRE(loc3.lon == loc1.lon - loc2.lon); @@ -56,17 +64,21 @@ SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]") { /**************************************************************************************/ -SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::operator ==]") { +SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::operator ==]") +{ Location loc1(1.0f, 2.0f), loc2(3.0f, 4.0f), loc3(1.0f, 2.0f); - WHEN("Two locations are identical (lat as well as lon)") { + + WHEN("Two locations are identical (lat as well as lon)") + { THEN("The comparison operation should return true") { REQUIRE((loc1 == loc3) == true); } } - WHEN("Two locations are not identical (either lat or lon do not match)") { + WHEN("Two locations are not identical (either lat or lon do not match)") + { THEN("The comparison operation should return false") { REQUIRE((loc1 == loc2) == false); } @@ -75,17 +87,21 @@ SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::oper /**************************************************************************************/ -SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::operator !=]") { +SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::operator !=]") +{ Location loc1(1.0f, 2.0f), loc2(3.0f, 4.0f), loc3(1.0f, 2.0f); - WHEN("Two locations are identical (lat as well as lon)") { + + WHEN("Two locations are identical (lat as well as lon)") + { THEN("The comparison operation should return false") { REQUIRE((loc1 != loc3) == false); } } - WHEN("Two locations are not identical (either lat or lon do not match)") { + WHEN("Two locations are not identical (either lat or lon do not match)") + { THEN("The comparison operation should return true") { REQUIRE((loc1 != loc2) == true); } @@ -94,9 +110,10 @@ SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::oper /**************************************************************************************/ -SCENARIO("Tesing cloud type 'Location' function distance for calculating euclidean 2d distance between two points", "[Location::distance]") { +SCENARIO("Tesing cloud type 'Location' function distance for calculating euclidean 2d distance between two points", "[Location::distance]") +{ Location loc1(0.0f, 0.0f), loc2(1.0f, 1.0f); REQUIRE(Location::distance(loc1, loc2) == sqrt(2.0f)); -} \ No newline at end of file +} diff --git a/extras/test/src/test_addPropertyReal.cpp b/extras/test/src/test_addPropertyReal.cpp index 1f97d172f..27500c97f 100644 --- a/extras/test/src/test_addPropertyReal.cpp +++ b/extras/test/src/test_addPropertyReal.cpp @@ -19,8 +19,10 @@ TEST CODE **************************************************************************************/ -SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyToContainer]") { - WHEN("The same bool property is added multiple times") { +SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyToContainer]") +{ + WHEN("The same bool property is added multiple times") + { PropertyContainer property_container; CloudBool bool_property = false; @@ -34,7 +36,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino /**************************************************************************************/ - WHEN("the same int property is added multiple times") { + WHEN("the same int property is added multiple times") + { PropertyContainer property_container; CloudInt int_property = 1; @@ -49,7 +52,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino /**************************************************************************************/ - WHEN("the same float property is added multiple times") { + WHEN("the same float property is added multiple times") + { PropertyContainer property_container; CloudFloat float_property = 1.0f; @@ -64,7 +68,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino /**************************************************************************************/ - WHEN("the same String property is added multiple times") { + WHEN("the same String property is added multiple times") + { PropertyContainer property_container; CloudString str_property; diff --git a/extras/test/src/test_callback.cpp b/extras/test/src/test_callback.cpp index 1a97832df..b4b30e37d 100644 --- a/extras/test/src/test_callback.cpp +++ b/extras/test/src/test_callback.cpp @@ -24,11 +24,13 @@ static bool callback_called_protocol_v2 = false; TEST HELPER FUNCTIONS **************************************************************************************/ -void externalCallbackV1() { +void externalCallbackV1() +{ callback_called_protocol_v1 = true; } -void externalCallbackV2() { +void externalCallbackV2() +{ callback_called_protocol_v2 = true; } @@ -36,24 +38,19 @@ void externalCallbackV2() { TEST CODE **************************************************************************************/ -SCENARIO("A callback is registered via 'onUpdate' to be called on property change", "[ArduinoCloudThing::decode]") { - /************************************************************************************/ - - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; +SCENARIO("A callback is registered via 'onUpdate' to be called on property change", "[ArduinoCloudThing::decode]") +{ + PropertyContainer property_container; - CloudInt test = 10; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2); - - /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + CloudInt test = 10; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2); - REQUIRE(callback_called_protocol_v2 == true); - } + /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - /************************************************************************************/ + REQUIRE(callback_called_protocol_v2 == true); } /**************************************************************************************/ @@ -61,35 +58,35 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang static CloudBool switch_turned_on = false; static CloudBool switch_callback_called = false; -void switch_callback() { +void switch_callback() +{ switch_turned_on = false; switch_callback_called = true; } -SCENARIO("A (boolean) property is manipulated in the callback to its origin state", "[ArduinoCloudThing::decode]") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); +SCENARIO("A (boolean) property is manipulated in the callback to its origin state", "[ArduinoCloudThing::decode]") +{ + PropertyContainer property_container; + cbor::encode(property_container); - addPropertyToContainer(property_container, switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback); + addPropertyToContainer(property_container, switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback); - /* [{0: "switch_turned_on", 4: true}] = 81 A2 00 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 04 F5 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x70, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x5F, 0x74, 0x75, 0x72, 0x6E, 0x65, 0x64, 0x5F, 0x6F, 0x6E, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: "switch_turned_on", 4: true}] = 81 A2 00 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 04 F5 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x70, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x5F, 0x74, 0x75, 0x72, 0x6E, 0x65, 0x64, 0x5F, 0x6F, 0x6E, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(switch_callback_called == true); + REQUIRE(switch_callback_called == true); - /* Since the property was reset to its origin state in the callback we - expect that on the next call to encode this change is propagated to - the cloud. - */ + /* Since the property was reset to its origin state in the callback we + expect that on the next call to encode this change is propagated to + the cloud. + */ - /* [{0: "switch_turned_on", 4: false}] = 9F A2 00 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 04 F4 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x70, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x5F, 0x74, 0x75, 0x72, 0x6E, 0x65, 0x64, 0x5F, 0x6F, 0x6E, 0x04, 0xF4, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "switch_turned_on", 4: false}] = 9F A2 00 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 04 F4 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x70, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x5F, 0x74, 0x75, 0x72, 0x6E, 0x65, 0x64, 0x5F, 0x6F, 0x6E, 0x04, 0xF4, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /**************************************************************************************/ @@ -97,261 +94,252 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat static bool sync_callback_called = false; static bool change_callback_called = false; -void auto_sync_callback(Property& property) { +void auto_sync_callback(Property& property) +{ MOST_RECENT_WINS(property); sync_callback_called = true; } -void change_callback() { +void change_callback() +{ change_callback_called = true; } -SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") { - GIVEN("CloudProtocol::V2") { - CloudBool test = false; - sync_callback_called = false; - change_callback_called = false; +SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") +{ + CloudBool test = false; + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); - test.setLastLocalChangeTimestamp(1550138809); + test.setLastLocalChangeTimestamp(1550138809); - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == true); + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == true); - REQUIRE(test == true); - } + REQUIRE(test == true); } /**************************************************************************************/ -SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") { - GIVEN("CloudProtocol::V2") { - CloudBool test = true; - sync_callback_called = false; - change_callback_called = false; +SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") +{ + CloudBool test = true; + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); - test = false; - test.setLastLocalChangeTimestamp(1550138811); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + test = false; + test.setLastLocalChangeTimestamp(1550138811); - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == false); + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == false); - REQUIRE(test == false); - } + REQUIRE(test == false); } -SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") { - GIVEN("CloudProtocol::V2") { - bool test = true; - std::unique_ptr p(new CloudWrapperBool(test)); - sync_callback_called = false; - change_callback_called = false; +SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") +{ + bool test = true; + std::unique_ptr p(new CloudWrapperBool(test)); + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); - test = false; - updateTimestampOnLocallyChangedProperties(property_container); - //There is no RTC on test execution environment so we force the local timestamp - p->setLastLocalChangeTimestamp(1550138809); - - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); - - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == true); - - REQUIRE(test == true); - } + addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + test = false; + updateTimestampOnLocallyChangedProperties(property_container); + //There is no RTC on test execution environment so we force the local timestamp + p->setLastLocalChangeTimestamp(1550138809); + + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); + + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == true); + + REQUIRE(test == true); } /**************************************************************************************/ -SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") { - GIVEN("CloudProtocol::V2") { - bool test = true; - std::unique_ptr p(new CloudWrapperBool(test)); - sync_callback_called = false; - change_callback_called = false; +SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") +{ + bool test = true; + std::unique_ptr p(new CloudWrapperBool(test)); + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); - test = false; - updateTimestampOnLocallyChangedProperties(property_container); - //There is no RTC on test execution environment so we force the local timestamp - p->setLastLocalChangeTimestamp(1550138811); - - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); - - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == false); - - REQUIRE(test == false); - } + addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + test = false; + updateTimestampOnLocallyChangedProperties(property_container); + //There is no RTC on test execution environment so we force the local timestamp + p->setLastLocalChangeTimestamp(1550138811); + + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); + + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == false); + + REQUIRE(test == false); } -SCENARIO("Object property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") { - GIVEN("CloudProtocol::V2") { - CloudLocation location_test = CloudLocation(0, 1); - sync_callback_called = false; - change_callback_called = false; +SCENARIO("Object property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") +{ + CloudLocation location_test = CloudLocation(0, 1); + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); - location_test.setLastLocalChangeTimestamp(1550138809); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + location_test.setLastLocalChangeTimestamp(1550138809); - /* [{-3: 1550138810.00, 0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ - uint8_t const payload[] = { 0x82, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; + /* [{-3: 1550138810.00, 0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ + uint8_t const payload[] = { 0x82, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == true); + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == true); - Location location_compare = Location(2, 3); - Location value_location_test = location_test.getValue(); - bool verify = (value_location_test == location_compare); + Location location_compare = Location(2, 3); + Location value_location_test = location_test.getValue(); + bool verify = (value_location_test == location_compare); - REQUIRE(verify); - } + REQUIRE(verify); } /**************************************************************************************/ -SCENARIO("Object property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") { - GIVEN("CloudProtocol::V2") { - CloudLocation location_test = CloudLocation(0, 1); - sync_callback_called = false; - change_callback_called = false; +SCENARIO("Object property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") +{ + CloudLocation location_test = CloudLocation(0, 1); + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); - location_test.setLastLocalChangeTimestamp(1550138811); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + location_test.setLastLocalChangeTimestamp(1550138811); - /* [{-3: 1550138810.00, 0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ - uint8_t const payload[] = { 0x82, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; + /* [{-3: 1550138810.00, 0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ + uint8_t const payload[] = { 0x82, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == false); + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == false); - Location location_compare = Location(0, 1); - Location value_location_test = location_test.getValue(); - bool verify = (value_location_test == location_compare); + Location location_compare = Location(0, 1); + Location value_location_test = location_test.getValue(); + bool verify = (value_location_test == location_compare); - REQUIRE(verify); - } + REQUIRE(verify); } /**************************************************************************************/ -void force_device_sync_callback(Property& property) { +void force_device_sync_callback(Property& property) +{ DEVICE_WINS(property); sync_callback_called = true; } -SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the FORCE_DEVICE_SYNC policy (the property keeps the local value and, if the cloud value is different from the local one, the value is propagated to the cloud). The onUpdate function is not executed") { - GIVEN("CloudProtocol::V2") { - - CloudBool test = false; - sync_callback_called = false; - change_callback_called = false; +SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the FORCE_DEVICE_SYNC policy (the property keeps the local value and, if the cloud value is different from the local one, the value is propagated to the cloud). The onUpdate function is not executed") +{ + CloudBool test = false; + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; - - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback); + PropertyContainer property_container; + + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback); - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == false); + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == false); - REQUIRE(test == false); - } + REQUIRE(test == false); } - /**************************************************************************************/ -void force_cloud_sync_callback(Property& property) { +void force_cloud_sync_callback(Property& property) +{ CLOUD_WINS(property); sync_callback_called = true; } -SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the FORCE_CLOUD_SYNC policy (the property always assumes the value incoming from the broker message). The onUpdate function is executed only if the local value of the property was different from the one taken from the incoming message") { - GIVEN("CloudProtocol::V2") { - - CloudBool test = false; - sync_callback_called = false; - change_callback_called = false; +SCENARIO("After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the FORCE_CLOUD_SYNC policy (the property always assumes the value incoming from the broker message). The onUpdate function is executed only if the local value of the property was different from the one taken from the incoming message") +{ + CloudBool test = false; + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_cloud_sync_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_cloud_sync_callback); - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == true); - REQUIRE(change_callback_called == true); + REQUIRE(sync_callback_called == true); + REQUIRE(change_callback_called == true); - REQUIRE(test == true); - } + REQUIRE(test == true); } /**************************************************************************************/ -SCENARIO("After a connection/reconnection an incoming cbor payload is processed. Any synchronization function is passed to the property so the value in the incoming message is discarded") { - GIVEN("CloudProtocol::V2") { - - CloudBool test = false; - sync_callback_called = false; - change_callback_called = false; +SCENARIO("After a connection/reconnection an incoming cbor payload is processed. Any synchronization function is passed to the property so the value in the incoming message is discarded") +{ + CloudBool test = false; + sync_callback_called = false; + change_callback_called = false; - PropertyContainer property_container; + PropertyContainer property_container; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback); - /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length, true); + /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length, true); - REQUIRE(sync_callback_called == false); - REQUIRE(change_callback_called == false); + REQUIRE(sync_callback_called == false); + REQUIRE(change_callback_called == false); - REQUIRE(test == false); - } + REQUIRE(test == false); } diff --git a/extras/test/src/test_decode.cpp b/extras/test/src/test_decode.cpp index 19a9a54eb..efcfe10b4 100644 --- a/extras/test/src/test_decode.cpp +++ b/extras/test/src/test_decode.cpp @@ -31,595 +31,576 @@ TEST CODE **************************************************************************************/ -SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") { - /************************************************************************************/ +SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") +{ - WHEN("A boolean property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A boolean property is changed via CBOR message") + { + PropertyContainer property_container; - CloudBool test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudBool test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 4: false}] = 81 A2 00 64 74 65 73 74 04 F4 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: "test", 4: false}] = 81 A2 00 64 74 65 73 74 04 F4 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(test == false); - } + REQUIRE(test == false); } /************************************************************************************/ - WHEN("A boolean property is changed via CBOR message - light payload") { + WHEN("A boolean property is changed via CBOR message - light payload") + { /*An integer identifier has been encoded instead of the name of the property in order to have a shorter payload*/ - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + PropertyContainer property_container; - CloudBool test = true; - /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); + CloudBool test = true; + /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); - /* [{0: 1, 4: false}] = 81 A2 00 01 04 F4 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x01, 0x04, 0xF4}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: 1, 4: false}] = 81 A2 00 01 04 F4 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x01, 0x04, 0xF4}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(test == false); - } + REQUIRE(test == false); } /************************************************************************************/ - WHEN("A int property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A positive int property is changed via CBOR message") + { + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(test == 7); - } - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + REQUIRE(test == 7); + } + + WHEN("A negative int property is changed via CBOR message") + { + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 2: -7}] = 81 A2 00 64 74 65 73 74 02 26 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x26}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: "test", 2: -7}] = 81 A2 00 64 74 65 73 74 02 26 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x26}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(test == -7); - } + REQUIRE(test == -7); } /************************************************************************************/ - WHEN("A float property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A float property is changed via CBOR message") + { + PropertyContainer property_container; - CloudFloat test = 0.0f; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudFloat test = 0.0f; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(test == Approx(3.1459).epsilon(0.01)); - } + REQUIRE(test == Approx(3.1459).epsilon(0.01)); } /************************************************************************************/ - WHEN("A String property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A String property is changed via CBOR message") + { + PropertyContainer property_container; - CloudString str_test; - str_test = "test"; - addPropertyToContainer(property_container, str_test, "test", Permission::ReadWrite); + CloudString str_test; + str_test = "test"; + addPropertyToContainer(property_container, str_test, "test", Permission::ReadWrite); - /* [{0: "test", 3: "testtt"}] = 81 A2 00 64 74 65 73 74 03 66 74 65 73 74 74 74 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x66, 0x74, 0x65, 0x73, 0x74, 0x74, 0x74}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 3: "testtt"}] = 81 A2 00 64 74 65 73 74 03 66 74 65 73 74 74 74 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x66, 0x74, 0x65, 0x73, 0x74, 0x74, 0x74}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(str_test == "testtt"); - } + REQUIRE(str_test == "testtt"); } /************************************************************************************/ - WHEN("A Location property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A Location property is changed via CBOR message") + { + PropertyContainer property_container; - CloudLocation location_test = CloudLocation(0, 1); - addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); - - /* [{0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A2 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ - uint8_t const payload[] = { 0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - Location location_compare = Location(2, 3); - Location value_location_test = location_test.getValue(); - REQUIRE(value_location_test.lat == location_compare.lat); - REQUIRE(value_location_test.lon == location_compare.lon); - } + CloudLocation location_test = CloudLocation(0, 1); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); + + /* [{0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A2 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ + uint8_t const payload[] = { 0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + Location location_compare = Location(2, 3); + Location value_location_test = location_test.getValue(); + REQUIRE(value_location_test.lat == location_compare.lat); + REQUIRE(value_location_test.lon == location_compare.lon); } /************************************************************************************/ - WHEN("A Color property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A Color property is changed via CBOR message") + { + PropertyContainer property_container; - CloudColor color_test = CloudColor(0.0, 0.0, 0.0); + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); - /* [{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ - uint8_t const payload[] = {0x83, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ + uint8_t const payload[] = {0x83, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - Color color_compare = Color(2.0, 2.0, 2.0); - Color value_color_test = color_test.getValue(); - bool verify = (value_color_test == color_compare); - REQUIRE(verify); - REQUIRE(value_color_test.hue == color_compare.hue); - REQUIRE(value_color_test.sat == color_compare.sat); - REQUIRE(value_color_test.bri == color_compare.bri); - } + Color color_compare = Color(2.0, 2.0, 2.0); + Color value_color_test = color_test.getValue(); + bool verify = (value_color_test == color_compare); + REQUIRE(verify); + REQUIRE(value_color_test.hue == color_compare.hue); + REQUIRE(value_color_test.sat == color_compare.sat); + REQUIRE(value_color_test.bri == color_compare.bri); } /************************************************************************************/ - WHEN("A Color property is changed via CBOR message - light payload") { + WHEN("A Color property is changed via CBOR message - light payload") + { /*An integer identifier has been encoded instead of the name of the property in order to have a shorter payload*/ - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + PropertyContainer property_container; - CloudColor color_test = CloudColor(0.0, 0.0, 0.0); + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); + + /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite, 1); + + /* [{0: 257, 2: 2.0},{0: 513, 2: 2.0},{0: 769, 2: 2.0}] = 83 A2 00 19 01 01 02 FA 40 00 00 00 A2 00 19 02 01 02 FA 40 00 00 00 A2 00 19 03 01 02 FA 40 00 00 00 */ + uint8_t const payload[] = {0x83, 0xA2, 0x00, 0x19, 0x01, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x02, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x03, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + + Color color_compare = Color(2.0, 2.0, 2.0); + Color value_color_test = color_test.getValue(); + bool verify = (value_color_test == color_compare); + REQUIRE(verify); + REQUIRE(value_color_test.hue == color_compare.hue); + REQUIRE(value_color_test.sat == color_compare.sat); + REQUIRE(value_color_test.bri == color_compare.bri); + } - /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite, 1); + /************************************************************************************/ - /* [{0: 257, 2: 2.0},{0: 513, 2: 2.0},{0: 769, 2: 2.0}] = 83 A2 00 19 01 01 02 FA 40 00 00 00 A2 00 19 02 01 02 FA 40 00 00 00 A2 00 19 03 01 02 FA 40 00 00 00 */ - uint8_t const payload[] = {0x83, 0xA2, 0x00, 0x19, 0x01, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x02, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x03, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + WHEN("A ColoredLight property is changed via CBOR message") + { + PropertyContainer property_container; + + CloudColoredLight color_test = CloudColoredLight(false, 0.0, 0.0, 0.0); + + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); + + /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ + uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + + ColoredLight color_compare = ColoredLight(true, 2.0, 2.0, 2.0); + ColoredLight value_color_test = color_test.getValue(); + bool verify = (value_color_test == color_compare); + REQUIRE(verify); + REQUIRE(value_color_test.swi == color_compare.swi); + REQUIRE(value_color_test.hue == color_compare.hue); + REQUIRE(value_color_test.sat == color_compare.sat); + REQUIRE(value_color_test.bri == color_compare.bri); + } - Color color_compare = Color(2.0, 2.0, 2.0); - Color value_color_test = color_test.getValue(); - bool verify = (value_color_test == color_compare); - REQUIRE(verify); - REQUIRE(value_color_test.hue == color_compare.hue); - REQUIRE(value_color_test.sat == color_compare.sat); - REQUIRE(value_color_test.bri == color_compare.bri); - } + /************************************************************************************/ + + WHEN("A Television property is changed via CBOR message") + { + PropertyContainer property_container; + + CloudTelevision tv_test = CloudTelevision(false, 0, false, PlaybackCommands::Stop, InputValue::AUX1, 0); + + addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); + + /* [{0: "test:swi", 4: true},{0: "test:vol", 2: 50},{0: "test:mut", 2: false},{0: "test:pbc", 2: 3},{0: "test:inp", 2: 55},{0: "test:cha", 2: 7}] = 9F A2 00 68 74 65 73 74 3A 73 77 69 04 F5 A2 00 68 74 65 73 74 3A 76 6F 6C 02 18 32 A2 00 68 74 65 73 74 3A 6D 75 74 04 F4 A2 00 68 74 65 73 74 3A 70 62 63 02 03 A2 00 68 74 65 73 74 3A 69 6E 70 02 18 37 A2 00 68 74 65 73 74 3A 63 68 61 02 07 FF */ + uint8_t const payload[] = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x76, 0x6F, 0x6C, 0x02, 0x18, 0x32, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6D, 0x75, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x70, 0x62, 0x63, 0x02, 0x03, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x69, 0x6E, 0x70, 0x02, 0x18, 0x37, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x63, 0x68, 0x61, 0x02, 0x07, 0xFF}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + + Television tv_compare = Television(true, 50, false, PlaybackCommands::Play, InputValue::TV, 7); + Television value_tv_test = tv_test.getValue(); + bool verify = (value_tv_test == tv_compare); + REQUIRE(verify); + REQUIRE(value_tv_test.swi == tv_compare.swi); + REQUIRE(value_tv_test.vol == tv_compare.vol); + REQUIRE(value_tv_test.mut == tv_compare.mut); + REQUIRE(value_tv_test.pbc == tv_compare.pbc); + REQUIRE(value_tv_test.inp == tv_compare.inp); + REQUIRE(value_tv_test.cha == tv_compare.cha); } /************************************************************************************/ - WHEN("A ColoredLight property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A DimmedLight property is changed via CBOR message") + { + PropertyContainer property_container; - CloudColoredLight color_test = CloudColoredLight(false, 0.0, 0.0, 0.0); + CloudDimmedLight light_test = CloudDimmedLight(false, 0.0); - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); - /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ - uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test:swi", 4: true},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ + uint8_t const payload[] = {0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - ColoredLight color_compare = ColoredLight(true, 2.0, 2.0, 2.0); - ColoredLight value_color_test = color_test.getValue(); - bool verify = (value_color_test == color_compare); - REQUIRE(verify); - REQUIRE(value_color_test.swi == color_compare.swi); - REQUIRE(value_color_test.hue == color_compare.hue); - REQUIRE(value_color_test.sat == color_compare.sat); - REQUIRE(value_color_test.bri == color_compare.bri); - } + DimmedLight light_compare = DimmedLight(true, 2.0); + DimmedLight value_light_test = light_test.getValue(); + bool verify = (value_light_test == light_compare); + REQUIRE(verify); + REQUIRE(value_light_test.swi == light_compare.swi); + REQUIRE(value_light_test.bri == light_compare.bri); } /************************************************************************************/ - WHEN("A Television property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A Light property is changed via CBOR message") + { + PropertyContainer property_container; - CloudTelevision tv_test = CloudTelevision(false, 0, false, PlaybackCommands::Stop, InputValue::AUX1, 0); - + CloudLight light_test; + light_test = false; - addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); - /* [{0: "test:swi", 4: true},{0: "test:vol", 2: 50},{0: "test:mut", 2: false},{0: "test:pbc", 2: 3},{0: "test:inp", 2: 55},{0: "test:cha", 2: 7}] = 9F A2 00 68 74 65 73 74 3A 73 77 69 04 F5 A2 00 68 74 65 73 74 3A 76 6F 6C 02 18 32 A2 00 68 74 65 73 74 3A 6D 75 74 04 F4 A2 00 68 74 65 73 74 3A 70 62 63 02 03 A2 00 68 74 65 73 74 3A 69 6E 70 02 18 37 A2 00 68 74 65 73 74 3A 63 68 61 02 07 FF */ - uint8_t const payload[] = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x76, 0x6F, 0x6C, 0x02, 0x18, 0x32, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6D, 0x75, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x70, 0x62, 0x63, 0x02, 0x03, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x69, 0x6E, 0x70, 0x02, 0x18, 0x37, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x63, 0x68, 0x61, 0x02, 0x07, 0xFF}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - Television tv_compare = Television(true, 50, false, PlaybackCommands::Play, InputValue::TV, 7); - Television value_tv_test = tv_test.getValue(); - bool verify = (value_tv_test == tv_compare); - REQUIRE(verify); - REQUIRE(value_tv_test.swi == tv_compare.swi); - REQUIRE(value_tv_test.vol == tv_compare.vol); - REQUIRE(value_tv_test.mut == tv_compare.mut); - REQUIRE(value_tv_test.pbc == tv_compare.pbc); - REQUIRE(value_tv_test.inp == tv_compare.inp); - REQUIRE(value_tv_test.cha == tv_compare.cha); - } + REQUIRE(light_test == true); } /************************************************************************************/ - WHEN("A DimmedLight property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A ContactSensor property is changed via CBOR message") + { + PropertyContainer property_container; - CloudDimmedLight light_test = CloudDimmedLight(false, 0.0); + CloudContactSensor contact_test; + contact_test = false; - addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, contact_test, "test", Permission::ReadWrite); - /* [{0: "test:swi", 4: true},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ - uint8_t const payload[] = {0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - DimmedLight light_compare = DimmedLight(true, 2.0); - DimmedLight value_light_test = light_test.getValue(); - bool verify = (value_light_test == light_compare); - REQUIRE(verify); - REQUIRE(value_light_test.swi == light_compare.swi); - REQUIRE(value_light_test.bri == light_compare.bri); - } + REQUIRE(contact_test == true); } /************************************************************************************/ - WHEN("A Light property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A MotionSensor property is changed via CBOR message") + { + PropertyContainer property_container; - CloudLight light_test; - light_test = false; + CloudMotionSensor motion_test; + motion_test = false; - addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, motion_test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(light_test == true); - } + REQUIRE(motion_test == true); } /************************************************************************************/ - WHEN("A ContactSensor property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A SmartPlug property is changed via CBOR message") + { + PropertyContainer property_container; - CloudContactSensor contact_test; - contact_test = false; + CloudSmartPlug plug_test; + plug_test = false; - addPropertyToContainer(property_container, contact_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, plug_test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(contact_test == true); - } + REQUIRE(plug_test == true); } /************************************************************************************/ - WHEN("A MotionSensor property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A Switch property is changed via CBOR message") + { + PropertyContainer property_container; - CloudMotionSensor motion_test; - motion_test = false; + CloudSwitch switch_test; + switch_test = false; - addPropertyToContainer(property_container, motion_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, switch_test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(motion_test == true); - } + REQUIRE(switch_test == true); } /************************************************************************************/ - WHEN("A SmartPlug property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A Temperature property is changed via CBOR message") + { + PropertyContainer property_container; - CloudSmartPlug plug_test; - plug_test = false; + CloudTemperature test; + test = 0.0f; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - addPropertyToContainer(property_container, plug_test, "test", Permission::ReadWrite); - - /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - REQUIRE(plug_test == true); - } + REQUIRE(test == Approx(3.1459).epsilon(0.01)); } /************************************************************************************/ - WHEN("A Switch property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { + WHEN("Multiple properties is changed via CBOR message") + { + WHEN("Multiple properties of different type are changed via CBOR message") + { PropertyContainer property_container; - - CloudSwitch switch_test; - switch_test = false; + + CloudBool bool_test = false; + CloudInt int_test = 1; + CloudFloat float_test = 2.0f; + CloudString str_test; + str_test = ("str_test"); - addPropertyToContainer(property_container, switch_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); + addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); + addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite); + addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; + /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] + = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F + */ + uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x0A, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x4D, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x6D, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F}; CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(switch_test == true); + REQUIRE(bool_test == true); + REQUIRE(int_test == 10); + REQUIRE(float_test == Approx(20.0).epsilon(0.01)); + REQUIRE(str_test == "hello arduino"); } - } - /************************************************************************************/ + /********************************************************************************/ - WHEN("A Temperature property is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { + WHEN("Multiple properties of different type are synchronized via CBOR message. FORCE_CLOUD_SYNC is passed as synchronization function and as a consequence values contained in the incoming message are stored in the properties") + { PropertyContainer property_container; - - CloudTemperature test; - test = 0.0f; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + + CloudBool bool_test = false; + CloudInt int_test = 1; + CloudFloat float_test = 2.0f; + CloudString str_test; + str_test = ("str_test"); + + addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); - /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] + = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F + */ + uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x0A, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x4D, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x6D, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t), true); - REQUIRE(test == Approx(3.1459).epsilon(0.01)); + REQUIRE(bool_test == true); + REQUIRE(int_test == 10); + REQUIRE(float_test == Approx(20.0).epsilon(0.01)); + REQUIRE(str_test == "hello arduino"); } - } - /************************************************************************************/ + /********************************************************************************/ - WHEN("Multiple properties is changed via CBOR message") { - GIVEN("CloudProtocol::V2") { - WHEN("Multiple properties of different type are changed via CBOR message") { - PropertyContainer property_container; - - CloudBool bool_test = false; - CloudInt int_test = 1; - CloudFloat float_test = 2.0f; - CloudString str_test; - str_test = ("str_test"); - - addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); - addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); - addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite); - addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite); - - /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] - = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F - */ - uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x0A, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x4D, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x6D, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - - REQUIRE(bool_test == true); - REQUIRE(int_test == 10); - REQUIRE(float_test == Approx(20.0).epsilon(0.01)); - REQUIRE(str_test == "hello arduino"); - } - - /********************************************************************************/ - - WHEN("Multiple properties of different type are synchronized via CBOR message. FORCE_CLOUD_SYNC is passed as synchronization function and as a consequence values contained in the incoming message are stored in the properties") { - PropertyContainer property_container; - - CloudBool bool_test = false; - CloudInt int_test = 1; - CloudFloat float_test = 2.0f; - CloudString str_test; - str_test = ("str_test"); - - addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); - addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); - addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); - addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); - - /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] - = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F - */ - uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x0A, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x4D, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x6D, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t), true); - - REQUIRE(bool_test == true); - REQUIRE(int_test == 10); - REQUIRE(float_test == Approx(20.0).epsilon(0.01)); - REQUIRE(str_test == "hello arduino"); - } - - /********************************************************************************/ - - WHEN("Multiple primitive properties of different type are synchronized via CBOR message. FORCE_CLOUD_SYNC is passed as synchronization function and as a consequence values contained in the incoming message are stored in the properties") { - PropertyContainer property_container; + WHEN("Multiple primitive properties of different type are synchronized via CBOR message. FORCE_CLOUD_SYNC is passed as synchronization function and as a consequence values contained in the incoming message are stored in the properties") + { + PropertyContainer property_container; - int int_test = 1; - bool bool_test = false; - float float_test = 2.0f; - String str_test; - str_test = "str_test"; - - std::unique_ptr i(new CloudWrapperInt(int_test)); - std::unique_ptr b(new CloudWrapperBool(bool_test)); - std::unique_ptr f(new CloudWrapperFloat(float_test)); - std::unique_ptr s(new CloudWrapperString(str_test)); - - addPropertyToContainer(property_container, *b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); - addPropertyToContainer(property_container, *i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); - addPropertyToContainer(property_container, *f, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); - addPropertyToContainer(property_container, *s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); - - updateTimestampOnLocallyChangedProperties(property_container); - - /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] - = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F - */ - uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x0A, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x4D, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x6D, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t), true); - - REQUIRE(bool_test == true); - REQUIRE(int_test == 10); - REQUIRE(float_test == Approx(20.0).epsilon(0.01)); - REQUIRE(str_test == "hello arduino"); - } - - /********************************************************************************/ - - WHEN("Multiple String properties are changed via CBOR message") { - PropertyContainer property_container; + int int_test = 1; + bool bool_test = false; + float float_test = 2.0f; + String str_test; + str_test = "str_test"; + + std::unique_ptr i(new CloudWrapperInt(int_test)); + std::unique_ptr b(new CloudWrapperBool(bool_test)); + std::unique_ptr f(new CloudWrapperFloat(float_test)); + std::unique_ptr s(new CloudWrapperString(str_test)); + + addPropertyToContainer(property_container, *b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *f, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); + + updateTimestampOnLocallyChangedProperties(property_container); + + /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] + = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F + */ + uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x0A, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x4D, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x6D, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t), true); + + REQUIRE(bool_test == true); + REQUIRE(int_test == 10); + REQUIRE(float_test == Approx(20.0).epsilon(0.01)); + REQUIRE(str_test == "hello arduino"); + } + + /********************************************************************************/ + + WHEN("Multiple String properties are changed via CBOR message") + { + PropertyContainer property_container; - CloudString str_1("hello"), - str_2("arduino"), - str_3("cloud"), - str_4("test"); - - addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite); - addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite); - addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite); - addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite); - - /* [{0: "str_1", 3: "I'd like"}, {0: "str_2", 3: "a"}, {0: "str_3", 3: "cup"}, {0: "str_4", 3: "of coffee"}] - = 84 A2 00 65 73 74 72 5F 31 03 68 49 27 64 20 6C 69 6B 65 A2 00 65 73 74 72 5F 32 03 61 61 A2 00 65 73 74 72 5F 33 03 63 63 75 70 A2 00 65 73 74 72 5F 34 03 69 6F 66 20 63 6F 66 66 65 65 - */ - uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x31, 0x03, 0x68, 0x49, 0x27, 0x64, 0x20, 0x6C, 0x69, 0x6B, 0x65, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x32, 0x03, 0x61, 0x61, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x33, 0x03, 0x63, 0x63, 0x75, 0x70, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x34, 0x03, 0x69, 0x6F, 0x66, 0x20, 0x63, 0x6F, 0x66, 0x66, 0x65, 0x65}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - - REQUIRE(str_1 == "I'd like"); - REQUIRE(str_2 == "a"); - REQUIRE(str_3 == "cup"); - REQUIRE(str_4 == "of coffee"); - } + CloudString str_1("hello"), + str_2("arduino"), + str_3("cloud"), + str_4("test"); + + addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite); + addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite); + addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite); + addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite); + + /* [{0: "str_1", 3: "I'd like"}, {0: "str_2", 3: "a"}, {0: "str_3", 3: "cup"}, {0: "str_4", 3: "of coffee"}] + = 84 A2 00 65 73 74 72 5F 31 03 68 49 27 64 20 6C 69 6B 65 A2 00 65 73 74 72 5F 32 03 61 61 A2 00 65 73 74 72 5F 33 03 63 63 75 70 A2 00 65 73 74 72 5F 34 03 69 6F 66 20 63 6F 66 66 65 65 + */ + uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x31, 0x03, 0x68, 0x49, 0x27, 0x64, 0x20, 0x6C, 0x69, 0x6B, 0x65, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x32, 0x03, 0x61, 0x61, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x33, 0x03, 0x63, 0x63, 0x75, 0x70, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x34, 0x03, 0x69, 0x6F, 0x66, 0x20, 0x63, 0x6F, 0x66, 0x66, 0x65, 0x65}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + + REQUIRE(str_1 == "I'd like"); + REQUIRE(str_2 == "a"); + REQUIRE(str_3 == "cup"); + REQUIRE(str_4 == "of coffee"); } } /************************************************************************************/ - WHEN("A payload containing a CBOR base name is parsed") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A payload containing a CBOR base name is parsed") + { + PropertyContainer property_container; - CloudString str = "hello"; - addPropertyToContainer(property_container, str, "test", Permission::ReadWrite); + CloudString str = "hello"; + addPropertyToContainer(property_container, str, "test", Permission::ReadWrite); - /* [{-2: "some-test-base-name", 0: "test", 3: "test"}] = 81 A3 21 73 73 6F 6D 65 2D 74 65 73 74 2D 62 61 73 65 2D 6E 61 6D 65 00 64 74 65 73 74 03 64 74 65 73 74 */ - uint8_t const payload[] = {0x81, 0xA3, 0x21, 0x73, 0x73, 0x6F, 0x6D, 0x65, 0x2D, 0x74, 0x65, 0x73, 0x74, 0x2D, 0x62, 0x61, 0x73, 0x65, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x64, 0x74, 0x65, 0x73, 0x74}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{-2: "some-test-base-name", 0: "test", 3: "test"}] = 81 A3 21 73 73 6F 6D 65 2D 74 65 73 74 2D 62 61 73 65 2D 6E 61 6D 65 00 64 74 65 73 74 03 64 74 65 73 74 */ + uint8_t const payload[] = {0x81, 0xA3, 0x21, 0x73, 0x73, 0x6F, 0x6D, 0x65, 0x2D, 0x74, 0x65, 0x73, 0x74, 0x2D, 0x62, 0x61, 0x73, 0x65, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x64, 0x74, 0x65, 0x73, 0x74}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(str == "test"); - } + REQUIRE(str == "test"); } /************************************************************************************/ - WHEN("A payload containing a CBOR base time is parsed") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + WHEN("A payload containing a CBOR base time is parsed") + { + PropertyContainer property_container; + + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{-3: 123.456, 0: "test", 2: 1}] = 81 A3 22 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 */ - uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{-3: 123.456, 0: "test", 2: 1}] = 81 A3 22 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 */ + uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(test == 1); - } + REQUIRE(test == 1); } /************************************************************************************/ - WHEN("A payload containing a CBOR time is parsed") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A payload containing a CBOR time is parsed") + { + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{6: 123.456, 0: "test", 2: 1}] = 81 A3 06 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 */ - uint8_t const payload[] = {0x81, 0xA3, 0x06, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{6: 123.456, 0: "test", 2: 1}] = 81 A3 06 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 */ + uint8_t const payload[] = {0x81, 0xA3, 0x06, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(test == 1); - } + REQUIRE(test == 1); } /************************************************************************************/ - WHEN("A payload containing a CBOR BaseVersion is parsed") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A payload containing a CBOR BaseVersion is parsed") + { + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{-1: 1, 0: "test", 2: 1}] = 81 A3 20 01 00 64 74 65 73 74 02 01 */ - uint8_t const payload[] = {0x81, 0xA3, 0x20, 0x01, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{-1: 1, 0: "test", 2: 1}] = 81 A3 20 01 00 64 74 65 73 74 02 01 */ + uint8_t const payload[] = {0x81, 0xA3, 0x20, 0x01, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(test == 1); - } + REQUIRE(test == 1); } /************************************************************************************/ - WHEN("A payload containing a CBOR BaseName, BaseTime and Time is parsed") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A payload containing a CBOR BaseName, BaseTime and Time is parsed") + { + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{-2: "base-name", -3: 654.321, 6: 123.456, 0: "test", 2: 1}] = - 81 A5 21 69 62 61 73 65 2D 6E 61 6D 65 22 FB 40 84 72 91 68 72 B0 21 06 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 - */ - uint8_t const payload[] = {0x81, 0xA5, 0x21, 0x69, 0x62, 0x61, 0x73, 0x65, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x22, 0xFB, 0x40, 0x84, 0x72, 0x91, 0x68, 0x72, 0xB0, 0x21, 0x06, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{-2: "base-name", -3: 654.321, 6: 123.456, 0: "test", 2: 1}] = + 81 A5 21 69 62 61 73 65 2D 6E 61 6D 65 22 FB 40 84 72 91 68 72 B0 21 06 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 + */ + uint8_t const payload[] = {0x81, 0xA5, 0x21, 0x69, 0x62, 0x61, 0x73, 0x65, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x22, 0xFB, 0x40, 0x84, 0x72, 0x91, 0x68, 0x72, 0xB0, 0x21, 0x06, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(test == 1); - } + REQUIRE(test == 1); } /************************************************************************************/ - WHEN("A payload containing a invalid CBOR key is parsed") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("A payload containing a invalid CBOR key is parsed") + { + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{123: 123, 0: "test", 2: 1}] = 81 A3 18 7B 18 7B 00 64 74 65 73 74 02 01 */ - uint8_t const payload[] = {0x81, 0xA3, 0x18, 0x7B, 0x18, 0x7B, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; - CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); + /* [{123: 123, 0: "test", 2: 1}] = 81 A3 18 7B 18 7B 00 64 74 65 73 74 02 01 */ + uint8_t const payload[] = {0x81, 0xA3, 0x18, 0x7B, 0x18, 0x7B, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; + CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); - REQUIRE(test == 1); - } + REQUIRE(test == 1); } /************************************************************************************/ diff --git a/extras/test/src/test_encode.cpp b/extras/test/src/test_encode.cpp index 24df1f0ac..985d1c2dc 100644 --- a/extras/test/src/test_encode.cpp +++ b/extras/test/src/test_encode.cpp @@ -23,416 +23,396 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]") { /************************************************************************************/ - WHEN("A 'bool' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); - - CloudBool test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - - /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + WHEN("A 'bool' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); + + CloudBool test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + + /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'bool' property is added - light payload") { + WHEN("A 'bool' property is added - light payload") + { /*An integer identifier must be instead of the name of the property in order to have a shorter payload*/ - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); - - CloudBool test = true; - /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); - - /* [{0: 1, 4: true}] = 9F A2 00 01 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x01, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container, true); - REQUIRE(actual == expected); - } + PropertyContainer property_container; + cbor::encode(property_container); + + CloudBool test = true; + /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); + + /* [{0: 1, 4: true}] = 9F A2 00 01 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x01, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container, true); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'int' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'int' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudInt int_test = 123; - addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite); + CloudInt int_test = 123; + addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite); - /* [{0: "test", 3: 123}] = 9F A2 00 64 74 65 73 74 02 18 7B FF */ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x18, 0x7B, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 3: 123}] = 9F A2 00 64 74 65 73 74 02 18 7B FF */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x18, 0x7B, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'float' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'float' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudFloat float_test = 3.14159; - addPropertyToContainer(property_container, float_test, "test", Permission::ReadWrite); + CloudFloat float_test = 3.14159; + addPropertyToContainer(property_container, float_test, "test", Permission::ReadWrite); - /* [{0: "test", 2: 3.141590118408203}] = 9F A2 00 64 74 65 73 74 02 FA 40 49 0F D0 FF */ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x49, 0x0F, 0xD0, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 2: 3.141590118408203}] = 9F A2 00 64 74 65 73 74 02 FA 40 49 0F D0 FF */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x49, 0x0F, 0xD0, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'String' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'String' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudString string_test; - string_test = "test"; - addPropertyToContainer(property_container, string_test, "test", Permission::ReadWrite); + CloudString string_test; + string_test = "test"; + addPropertyToContainer(property_container, string_test, "test", Permission::ReadWrite); - /* [{0: "test", 3: "test"}] = 9F A2 00 64 74 65 73 74 03 64 74 65 73 74 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x64, 0x74, 0x65, 0x73, 0x74, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 3: "test"}] = 9F A2 00 64 74 65 73 74 03 64 74 65 73 74 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x64, 0x74, 0x65, 0x73, 0x74, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'Location' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'Location' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudLocation location_test = CloudLocation(2.0f, 3.0f); - addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); + CloudLocation location_test = CloudLocation(2.0f, 3.0f); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); - /* [{0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 9F A2 00 68 74 65 73 74 3A 6C 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 FA 40 40 00 00 FF*/ - std::vector const expected = { 0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0xFA, 0x40, 0x40, 0x00, 0x00, 0xFF }; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 9F A2 00 68 74 65 73 74 3A 6C 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 FA 40 40 00 00 FF*/ + std::vector const expected = { 0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0xFA, 0x40, 0x40, 0x00, 0x00, 0xFF }; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'Color' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'Color' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudColor color_test = CloudColor(2.0, 2.0, 2.0); - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); + CloudColor color_test = CloudColor(2.0, 2.0, 2.0); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); - /* [{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 9F A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 9F A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'Color' property is added - light payload") { + WHEN("A 'Color' property is added - light payload") + { /*An integer identifier must be encoded instead of the name of the property in order to have a shorter payload*/ - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); - - CloudColor color_test = CloudColor(2.0, 2.0, 2.0); - /*The property is added with identifier 1 that will be used instead of the string "name" as property identifier */ - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite, 1); - - /* [{0: 257, 2: 2.0},{0: 513, 2: 2.0},{0: 769, 2: 2.0}] = 9F A2 00 19 01 01 02 FA 40 00 00 00 A2 00 19 02 01 02 FA 40 00 00 00 A2 00 19 03 01 02 FA 40 00 00 00 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x19, 0x01, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x02, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x03, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; - std::vector const actual = cbor::encode(property_container, true); - REQUIRE(actual == expected); - } + PropertyContainer property_container; + cbor::encode(property_container); + + CloudColor color_test = CloudColor(2.0, 2.0, 2.0); + /*The property is added with identifier 1 that will be used instead of the string "name" as property identifier */ + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite, 1); + + /* [{0: 257, 2: 2.0},{0: 513, 2: 2.0},{0: 769, 2: 2.0}] = 9F A2 00 19 01 01 02 FA 40 00 00 00 A2 00 19 02 01 02 FA 40 00 00 00 A2 00 19 03 01 02 FA 40 00 00 00 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x19, 0x01, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x02, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x03, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; + std::vector const actual = cbor::encode(property_container, true); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'ColoredLight' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'ColoredLight' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudColoredLight color_test = CloudColoredLight(true, 2.0, 2.0, 2.0); - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); + CloudColoredLight color_test = CloudColoredLight(true, 2.0, 2.0, 2.0); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); - /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'Television' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'Television' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudTelevision tv_test = CloudTelevision(true, 50, false, PlaybackCommands::Play, InputValue::TV, 7); - addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); + CloudTelevision tv_test = CloudTelevision(true, 50, false, PlaybackCommands::Play, InputValue::TV, 7); + addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); - /* [{0: "test:swi", 4: true},{0: "test:vol", 2: 50},{0: "test:mut", 2: false},{0: "test:pbc", 2: 3},{0: "test:inp", 2: 55},{0: "test:cha", 2: 7}] = 9F A2 00 68 74 65 73 74 3A 73 77 69 04 F5 A2 00 68 74 65 73 74 3A 76 6F 6C 02 18 32 A2 00 68 74 65 73 74 3A 6D 75 74 04 F4 A2 00 68 74 65 73 74 3A 70 62 63 02 03 A2 00 68 74 65 73 74 3A 69 6E 70 02 18 37 A2 00 68 74 65 73 74 3A 63 68 61 02 07 FF */ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x76, 0x6F, 0x6C, 0x02, 0x18, 0x32, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6D, 0x75, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x70, 0x62, 0x63, 0x02, 0x03, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x69, 0x6E, 0x70, 0x02, 0x18, 0x37, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x63, 0x68, 0x61, 0x02, 0x07, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test:swi", 4: true},{0: "test:vol", 2: 50},{0: "test:mut", 2: false},{0: "test:pbc", 2: 3},{0: "test:inp", 2: 55},{0: "test:cha", 2: 7}] = 9F A2 00 68 74 65 73 74 3A 73 77 69 04 F5 A2 00 68 74 65 73 74 3A 76 6F 6C 02 18 32 A2 00 68 74 65 73 74 3A 6D 75 74 04 F4 A2 00 68 74 65 73 74 3A 70 62 63 02 03 A2 00 68 74 65 73 74 3A 69 6E 70 02 18 37 A2 00 68 74 65 73 74 3A 63 68 61 02 07 FF */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x76, 0x6F, 0x6C, 0x02, 0x18, 0x32, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6D, 0x75, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x70, 0x62, 0x63, 0x02, 0x03, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x69, 0x6E, 0x70, 0x02, 0x18, 0x37, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x63, 0x68, 0x61, 0x02, 0x07, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A 'DimmedLight' property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A 'DimmedLight' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudDimmedLight color_test = CloudDimmedLight(true, 2.0); - addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); + CloudDimmedLight color_test = CloudDimmedLight(true, 2.0); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); - /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 0.0},{0: "test:sat", 2: 0.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 0.0},{0: "test:sat", 2: 0.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A light property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A light property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudLight test; - test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudLight test; + test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A contact sensor property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A contact sensor property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudContactSensor test; - test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudContactSensor test; + test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A motion sensor property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A motion sensor property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudMotionSensor test; - test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudMotionSensor test; + test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A smart plug property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A smart plug property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudSmartPlug test; - test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudSmartPlug test; + test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A Temperature property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A Temperature property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudTemperature float_test; - float_test = 3.14159; - addPropertyToContainer(property_container, float_test, "test", Permission::ReadWrite); + CloudTemperature float_test; + float_test = 3.14159; + addPropertyToContainer(property_container, float_test, "test", Permission::ReadWrite); - /* [{0: "test", 2: 3.141590118408203}] = 9F A2 00 64 74 65 73 74 02 FA 40 49 0F D0 FF */ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x49, 0x0F, 0xD0, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 2: 3.141590118408203}] = 9F A2 00 64 74 65 73 74 02 FA 40 49 0F D0 FF */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x49, 0x0F, 0xD0, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("A switch property is added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - cbor::encode(property_container); + WHEN("A switch property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); - CloudSwitch test; - test = true; - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); + CloudSwitch test; + test = true; + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); - /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("Multiple properties are added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("Multiple properties are added") + { + PropertyContainer property_container; - CloudInt int_test = 1; - CloudBool bool_test = false; - CloudFloat float_test = 2.0f; - CloudString str_test; - str_test = "str_test"; - - addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); - addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); - addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite); - addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite); - - /* [{0: "int_test", 2: 1}, {0: "bool_test", 4: false}, {0: "float_test", 2: 2.0}, {0: "str_test", 3: "str_test"}] - = 9F A2 00 68 69 6E 74 5F 74 65 73 74 02 01 A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA 40 00 00 00 A2 00 68 73 74 72 5F 74 65 73 74 03 68 73 74 72 5F 74 65 73 74 FF - */ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + CloudInt int_test = 1; + CloudBool bool_test = false; + CloudFloat float_test = 2.0f; + CloudString str_test; + str_test = "str_test"; + + addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); + addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); + addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite); + addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite); + + /* [{0: "int_test", 2: 1}, {0: "bool_test", 4: false}, {0: "float_test", 2: 2.0}, {0: "str_test", 3: "str_test"}] + = 9F A2 00 68 69 6E 74 5F 74 65 73 74 02 01 A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA 40 00 00 00 A2 00 68 73 74 72 5F 74 65 73 74 03 68 73 74 72 5F 74 65 73 74 FF + */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("Multiple primitive properties are added") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; + WHEN("Multiple primitive properties are added") + { + PropertyContainer property_container; - int int_test = 1; - bool bool_test = false; - float float_test = 2.0f; - String str_test; - str_test = "str_test"; - - std::unique_ptr i(new CloudWrapperInt(int_test)); - std::unique_ptr b(new CloudWrapperBool(bool_test)); - std::unique_ptr f(new CloudWrapperFloat(float_test)); - std::unique_ptr s(new CloudWrapperString(str_test)); - - addPropertyToContainer(property_container, *i, "int_test", Permission::ReadWrite); - addPropertyToContainer(property_container, *b, "bool_test", Permission::ReadWrite); - addPropertyToContainer(property_container, *f, "float_test", Permission::ReadWrite); - addPropertyToContainer(property_container, *s, "str_test", Permission::ReadWrite); - - updateTimestampOnLocallyChangedProperties(property_container); - - /* [{0: "int_test", 2: 1}, {0: "bool_test", 4: false}, {0: "float_test", 2: 2.0}, {0: "str_test", 3: "str_test"}] - = 9F A2 00 68 69 6E 74 5F 74 65 73 74 02 01 A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA 40 00 00 00 A2 00 68 73 74 72 5F 74 65 73 74 03 68 73 74 72 5F 74 65 73 74 FF - */ - std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0xFF}; - std::vector const actual = cbor::encode(property_container); - REQUIRE(actual == expected); - } + int int_test = 1; + bool bool_test = false; + float float_test = 2.0f; + String str_test; + str_test = "str_test"; + + std::unique_ptr i(new CloudWrapperInt(int_test)); + std::unique_ptr b(new CloudWrapperBool(bool_test)); + std::unique_ptr f(new CloudWrapperFloat(float_test)); + std::unique_ptr s(new CloudWrapperString(str_test)); + + addPropertyToContainer(property_container, *i, "int_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *b, "bool_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *f, "float_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *s, "str_test", Permission::ReadWrite); + + updateTimestampOnLocallyChangedProperties(property_container); + + /* [{0: "int_test", 2: 1}, {0: "bool_test", 4: false}, {0: "float_test", 2: 2.0}, {0: "str_test", 3: "str_test"}] + = 9F A2 00 68 69 6E 74 5F 74 65 73 74 02 01 A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA 40 00 00 00 A2 00 68 73 74 72 5F 74 65 73 74 03 68 73 74 72 5F 74 65 73 74 FF + */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x69, 0x6E, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01, 0xA2, 0x00, 0x69, 0x62, 0x6F, 0x6F, 0x6C, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x6A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x03, 0x68, 0x73, 0x74, 0x72, 0x5F, 0x74, 0x65, 0x73, 0x74, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); } /************************************************************************************/ - WHEN("The size of the encoded properties is exceeding the CBOR buffer size") { - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; - - CloudString str_0; str_0 = "This string is 30 bytes long."; - CloudString str_1; str_1 = "This string is 30 bytes long."; - CloudString str_2; str_2 = "This string is 30 bytes long."; - CloudString str_3; str_3 = "This string is 30 bytes long."; - CloudString str_4; str_4 = "This string is 30 bytes long."; - CloudString str_5; str_5 = "This string is 30 bytes long."; - CloudString str_6; str_6 = "This string is 30 bytes long."; - CloudString str_7; str_7 = "This string is 30 bytes long."; - CloudString str_8; str_8 = "This string is 30 bytes long."; - CloudString str_9; str_9 = "This string is 30 bytes long."; - - addPropertyToContainer(property_container, str_0, "str_0", Permission::ReadWrite); - addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite); - addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite); - addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite); - addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite); - addPropertyToContainer(property_container, str_5, "str_5", Permission::ReadWrite); - addPropertyToContainer(property_container, str_6, "str_6", Permission::ReadWrite); - addPropertyToContainer(property_container, str_7, "str_7", Permission::ReadWrite); - addPropertyToContainer(property_container, str_8, "str_8", Permission::ReadWrite); - addPropertyToContainer(property_container, str_9, "str_9", Permission::ReadWrite); - - /* Due to the size if the encoded properties exceeding 256 bytes if encoded all at - * once they are encoded in subsequent calls to CBOREncoder::encode. - */ - - /* [{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."}] - * = 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 - */ - std::vector 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}; - std::vector const actual_1 = cbor::encode(property_container); - REQUIRE(actual_1 == expected_1); - - /* [{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."}] - * = 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 - */ - std::vector 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}; - std::vector const actual_2 = cbor::encode(property_container); - REQUIRE(actual_2 == expected_2); - - /* [{0: "str_8", 3: "This string is 30 bytes long."}, {0: "str_9", 3: "This string is 30 bytes long."}] - * = 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 - */ - std::vector 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}; - std::vector const actual_3 = cbor::encode(property_container); - REQUIRE(actual_3 == expected_3); - } + WHEN("The size of the encoded properties is exceeding the CBOR buffer size") + { + PropertyContainer property_container; + + CloudString str_0; str_0 = "This string is 30 bytes long."; + CloudString str_1; str_1 = "This string is 30 bytes long."; + CloudString str_2; str_2 = "This string is 30 bytes long."; + CloudString str_3; str_3 = "This string is 30 bytes long."; + CloudString str_4; str_4 = "This string is 30 bytes long."; + CloudString str_5; str_5 = "This string is 30 bytes long."; + CloudString str_6; str_6 = "This string is 30 bytes long."; + CloudString str_7; str_7 = "This string is 30 bytes long."; + CloudString str_8; str_8 = "This string is 30 bytes long."; + CloudString str_9; str_9 = "This string is 30 bytes long."; + + addPropertyToContainer(property_container, str_0, "str_0", Permission::ReadWrite); + addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite); + addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite); + addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite); + addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite); + addPropertyToContainer(property_container, str_5, "str_5", Permission::ReadWrite); + addPropertyToContainer(property_container, str_6, "str_6", Permission::ReadWrite); + addPropertyToContainer(property_container, str_7, "str_7", Permission::ReadWrite); + addPropertyToContainer(property_container, str_8, "str_8", Permission::ReadWrite); + addPropertyToContainer(property_container, str_9, "str_9", Permission::ReadWrite); + + /* Due to the size if the encoded properties exceeding 256 bytes if encoded all at + * once they are encoded in subsequent calls to CBOREncoder::encode. + */ + + /* [{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."}] + * = 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 + */ + std::vector 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}; + std::vector const actual_1 = cbor::encode(property_container); + REQUIRE(actual_1 == expected_1); + + /* [{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."}] + * = 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 + */ + std::vector 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}; + std::vector const actual_2 = cbor::encode(property_container); + REQUIRE(actual_2 == expected_2); + + /* [{0: "str_8", 3: "This string is 30 bytes long."}, {0: "str_9", 3: "This string is 30 bytes long."}] + * = 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 + */ + std::vector 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}; + std::vector const actual_3 = cbor::encode(property_container); + REQUIRE(actual_3 == expected_3); } /************************************************************************************/ diff --git a/extras/test/src/test_publishEvery.cpp b/extras/test/src/test_publishEvery.cpp index 7d9886b3e..0ac083487 100644 --- a/extras/test/src/test_publishEvery.cpp +++ b/extras/test/src/test_publishEvery.cpp @@ -15,38 +15,35 @@ TEST CODE **************************************************************************************/ -SCENARIO("A Arduino cloud property is published periodically", "[ArduinoCloudThing::publishEvery]") { - /************************************************************************************/ - - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; +SCENARIO("A Arduino cloud property is published periodically", "[ArduinoCloudThing::publishEvery]") +{ + PropertyContainer property_container; - CloudBool test = true; - unsigned long const PUBLISH_INTERVAL_SEC = 1 * SECONDS; - - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishEvery(PUBLISH_INTERVAL_SEC); - - WHEN("t = 0 ms, publish interval = 1000 ms, 1st call to 'encode'") { - set_millis(0); - THEN("'encode' should encode the property") { - REQUIRE(cbor::encode(property_container).size() != 0); - WHEN("t = 999 ms") { - set_millis(999); - THEN("'encode' should not encode the property") { - REQUIRE(cbor::encode(property_container).size() == 0); - WHEN("t = 1000 ms") { - set_millis(1000); - THEN("'encode' should encode the property") { - REQUIRE(cbor::encode(property_container).size() != 0); - WHEN("t = 1999 ms") { - set_millis(1999); - THEN("'encode' should not encode the property") { - REQUIRE(cbor::encode(property_container).size() == 0); - WHEN("t = 2000 ms") { - set_millis(2000); - THEN("'encode' should encode the property") { - REQUIRE(cbor::encode(property_container).size() != 0); - } + CloudBool test = true; + unsigned long const PUBLISH_INTERVAL_SEC = 1 * SECONDS; + + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishEvery(PUBLISH_INTERVAL_SEC); + + WHEN("t = 0 ms, publish interval = 1000 ms, 1st call to 'encode'") { + set_millis(0); + THEN("'encode' should encode the property") { + REQUIRE(cbor::encode(property_container).size() != 0); + WHEN("t = 999 ms") { + set_millis(999); + THEN("'encode' should not encode the property") { + REQUIRE(cbor::encode(property_container).size() == 0); + WHEN("t = 1000 ms") { + set_millis(1000); + THEN("'encode' should encode the property") { + REQUIRE(cbor::encode(property_container).size() != 0); + WHEN("t = 1999 ms") { + set_millis(1999); + THEN("'encode' should not encode the property") { + REQUIRE(cbor::encode(property_container).size() == 0); + WHEN("t = 2000 ms") { + set_millis(2000); + THEN("'encode' should encode the property") { + REQUIRE(cbor::encode(property_container).size() != 0); } } } @@ -57,6 +54,4 @@ SCENARIO("A Arduino cloud property is published periodically", "[ArduinoCloudThi } } } - - /************************************************************************************/ } diff --git a/extras/test/src/test_publishOnChange.cpp b/extras/test/src/test_publishOnChange.cpp index 9568f13f3..7b4592790 100644 --- a/extras/test/src/test_publishOnChange.cpp +++ b/extras/test/src/test_publishOnChange.cpp @@ -14,35 +14,30 @@ TEST CODE **************************************************************************************/ -SCENARIO("A Arduino cloud property is published on value change", "[ArduinoCloudThing::publishOnChange]") { - /************************************************************************************/ - - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; +SCENARIO("A Arduino cloud property is published on value change", "[ArduinoCloudThing::publishOnChange]") +{ + PropertyContainer property_container; - CloudInt test = 10; - int const DELTA = 6; - - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(DELTA); - - WHEN("test = 10, delta = 6, the property is encoded for the 1st time") { - THEN("The property should be encoded") { - REQUIRE(cbor::encode(property_container).size() != 0); - WHEN("test +=4 -> test = 14") { - test += 4; - THEN("Since the increment since the last update (4) is smaller than the delta of 6 the property should not be encoded") { - REQUIRE(cbor::encode(property_container).size() == 0); - WHEN("test +=4 -> test = 18") { - test += 4; - THEN("Since the increment since the last update (8) is greater than the delta of 6 the property should be encoded") { - REQUIRE(cbor::encode(property_container).size() != 0); - } + CloudInt test = 10; + int const DELTA = 6; + + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(DELTA); + + WHEN("test = 10, delta = 6, the property is encoded for the 1st time") { + THEN("The property should be encoded") { + REQUIRE(cbor::encode(property_container).size() != 0); + WHEN("test +=4 -> test = 14") { + test += 4; + THEN("Since the increment since the last update (4) is smaller than the delta of 6 the property should not be encoded") { + REQUIRE(cbor::encode(property_container).size() == 0); + WHEN("test +=4 -> test = 18") { + test += 4; + THEN("Since the increment since the last update (8) is greater than the delta of 6 the property should be encoded") { + REQUIRE(cbor::encode(property_container).size() != 0); } } } } } } - - /************************************************************************************/ } diff --git a/extras/test/src/test_publishOnChangeRateLimit.cpp b/extras/test/src/test_publishOnChangeRateLimit.cpp index ccb51148e..9f96a5610 100644 --- a/extras/test/src/test_publishOnChangeRateLimit.cpp +++ b/extras/test/src/test_publishOnChangeRateLimit.cpp @@ -14,43 +14,40 @@ TEST CODE **************************************************************************************/ -SCENARIO("A Arduino cloud property is published on value change but the update rate is limited", "[ArduinoCloudThing::publishOnChange]") { - /************************************************************************************/ - - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; +SCENARIO("A Arduino cloud property is published on value change but the update rate is limited", "[ArduinoCloudThing::publishOnChange]") +{ + PropertyContainer property_container; - CloudInt test = 0; - int const MIN_DELTA = 0; - unsigned long const MIN_TIME_BETWEEN_UPDATES_ms = 500; /* No updates faster than 500 ms */ - - addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(MIN_DELTA, MIN_TIME_BETWEEN_UPDATES_ms); - - WHEN("t = 0 ms, min time between updates = 500 ms, property not modified, 1st call to 'encode'") { - set_millis(0); - THEN("'encode' should encode the property") { - REQUIRE(cbor::encode(property_container).size() != 0); - WHEN("t = 499 ms, property modified") { - test++; - set_millis(499); - THEN("'encode' should not encode any property") { - REQUIRE(cbor::encode(property_container).size() == 0); - WHEN("t = 500 ms, property modified") { - test++; - set_millis(500); - THEN("'encode' should encode the property") { - REQUIRE(cbor::encode(property_container).size() != 0); - WHEN("t = 999 ms, property modified") { - test++; - set_millis(999); - THEN("'encode' should not encode any property") { - REQUIRE(cbor::encode(property_container).size() == 0); - WHEN("t = 1000 ms, property modified") { - test++; - set_millis(1000); - THEN("'encode' should encode the property") { - REQUIRE(cbor::encode(property_container).size() != 0); - } + CloudInt test = 0; + int const MIN_DELTA = 0; + unsigned long const MIN_TIME_BETWEEN_UPDATES_ms = 500; /* No updates faster than 500 ms */ + + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(MIN_DELTA, MIN_TIME_BETWEEN_UPDATES_ms); + + WHEN("t = 0 ms, min time between updates = 500 ms, property not modified, 1st call to 'encode'") { + set_millis(0); + THEN("'encode' should encode the property") { + REQUIRE(cbor::encode(property_container).size() != 0); + WHEN("t = 499 ms, property modified") { + test++; + set_millis(499); + THEN("'encode' should not encode any property") { + REQUIRE(cbor::encode(property_container).size() == 0); + WHEN("t = 500 ms, property modified") { + test++; + set_millis(500); + THEN("'encode' should encode the property") { + REQUIRE(cbor::encode(property_container).size() != 0); + WHEN("t = 999 ms, property modified") { + test++; + set_millis(999); + THEN("'encode' should not encode any property") { + REQUIRE(cbor::encode(property_container).size() == 0); + WHEN("t = 1000 ms, property modified") { + test++; + set_millis(1000); + THEN("'encode' should encode the property") { + REQUIRE(cbor::encode(property_container).size() != 0); } } } @@ -61,6 +58,4 @@ SCENARIO("A Arduino cloud property is published on value change but the update r } } } - - /************************************************************************************/ } diff --git a/extras/test/src/test_readOnly.cpp b/extras/test/src/test_readOnly.cpp index f29468cdd..ef080922d 100644 --- a/extras/test/src/test_readOnly.cpp +++ b/extras/test/src/test_readOnly.cpp @@ -17,22 +17,17 @@ TEST CODE **************************************************************************************/ -SCENARIO("A Arduino cloud property is marked 'read only'", "[ArduinoCloudThing::decode]") { - /************************************************************************************/ - - GIVEN("CloudProtocol::V2") { - PropertyContainer property_container; +SCENARIO("A Arduino cloud property is marked 'read only'", "[ArduinoCloudThing::decode]") +{ + PropertyContainer property_container; - CloudInt test = 0; - addPropertyToContainer(property_container, test, "test", Permission::Read); - - /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ - uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; - int const payload_length = sizeof(payload) / sizeof(uint8_t); - CBORDecoder::decode(property_container, payload, payload_length); + CloudInt test = 0; + addPropertyToContainer(property_container, test, "test", Permission::Read); - REQUIRE(test == 0); - } + /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; + int const payload_length = sizeof(payload) / sizeof(uint8_t); + CBORDecoder::decode(property_container, payload, payload_length); - /************************************************************************************/ + REQUIRE(test == 0); } diff --git a/extras/test/src/test_writeOnly.cpp b/extras/test/src/test_writeOnly.cpp index 643f6d779..82283752e 100644 --- a/extras/test/src/test_writeOnly.cpp +++ b/extras/test/src/test_writeOnly.cpp @@ -17,15 +17,12 @@ TEST CODE **************************************************************************************/ -SCENARIO("A Arduino cloud property is marked 'write only'", "[ArduinoCloudThing::encode]") { - /************************************************************************************/ - +SCENARIO("A Arduino cloud property is marked 'write only'", "[ArduinoCloudThing::encode]") +{ PropertyContainer property_container; CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::Write); REQUIRE(cbor::encode(property_container).size() == 0); /* Since 'test' is 'write only' it should not be encoded */ - - /************************************************************************************/ } diff --git a/extras/test/src/util/CBORTestUtil.cpp b/extras/test/src/util/CBORTestUtil.cpp index 04ad7b3f0..021ffc6b7 100644 --- a/extras/test/src/util/CBORTestUtil.cpp +++ b/extras/test/src/util/CBORTestUtil.cpp @@ -24,7 +24,8 @@ namespace cbor PUBLIC FUNCTIONS **************************************************************************************/ -std::vector encode(PropertyContainer & property_container, bool lightPayload) { +std::vector encode(PropertyContainer & property_container, bool lightPayload) +{ int bytes_encoded = 0; uint8_t buf[200] = {0}; @@ -34,7 +35,8 @@ std::vector encode(PropertyContainer & property_container, bool lightPa return std::vector(); } -void print(std::vector const & vect) { +void print(std::vector const & vect) +{ for (auto i = vect.begin(); i != vect.end(); i++) { std::cout << std::uppercase << std::hex