@@ -64,3 +64,43 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang
6464
6565 /* ***********************************************************************************/
6666}
67+
68+ /* *************************************************************************************/
69+
70+ static bool switch_turned_on = false ;
71+ static bool switch_callback_called = false ;
72+
73+ void switch_callback ()
74+ {
75+ switch_turned_on = false ;
76+ switch_callback_called = true ;
77+ }
78+
79+ SCENARIO (" A (boolean) property is manipulated in the callback to its origin state" , " [ArduinoCloudThing::decode]" )
80+ {
81+ GIVEN (" CloudProtocol::V1" )
82+ {
83+ ArduinoCloudThing thing (CloudProtocol::V1);
84+ thing.begin ();
85+ encode (thing);
86+
87+ thing.addPropertyReal (switch_turned_on, " switch_turned_on" , Permission::ReadWrite).onUpdate (switch_callback);
88+
89+ /* [{"n": "switch_turned_on", "vb": true}] = 81 A2 61 6E 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 62 76 62 F5 */
90+ uint8_t const payload[] = {0x81 , 0xA2 , 0x61 , 0x6E , 0x70 , 0x73 , 0x77 , 0x69 , 0x74 , 0x63 , 0x68 , 0x5F , 0x74 , 0x75 , 0x72 , 0x6E , 0x65 , 0x64 , 0x5F , 0x6F , 0x6E , 0x62 , 0x76 , 0x62 , 0xF5 };
91+ int const payload_length = sizeof (payload)/sizeof (uint8_t );
92+ thing.decode (payload, payload_length);
93+
94+ REQUIRE (switch_callback_called == true );
95+
96+ /* Since the property was reset to its origin state in the callback we
97+ * expect that on the next call to encode this change is propagated to
98+ * the cloud.
99+ */
100+
101+ /* [{"n": "switch_turned_on", "vb": false}] = 81 BF 61 6E 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 62 76 62 F4 FF */
102+ std::vector<uint8_t > const expected = {0x81 , 0xBF , 0x61 , 0x6E , 0x70 , 0x73 , 0x77 , 0x69 , 0x74 , 0x63 , 0x68 , 0x5F , 0x74 , 0x75 , 0x72 , 0x6E , 0x65 , 0x64 , 0x5F , 0x6F , 0x6E , 0x62 , 0x76 , 0x62 , 0xF4 , 0xFF };
103+ std::vector<uint8_t > const actual = encode (thing);
104+ REQUIRE (actual == expected);
105+ }
106+ }
0 commit comments