1010
1111#include < util/CBORTestUtil.h>
1212#include < ArduinoCloudThing.h>
13+ #include < PropertyContainer.h>
1314#include " types/CloudWrapperBool.h"
1415
1516/* *************************************************************************************
@@ -39,11 +40,12 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang
3940 /* ***********************************************************************************/
4041
4142 GIVEN (" CloudProtocol::V2" ) {
43+ PropertyContainer property_container;
4244 ArduinoCloudThing thing;
43- thing.begin ();
45+ thing.begin (&property_container );
4446
4547 CloudInt test = 10 ;
46- thing .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (externalCallbackV2);
48+ property_container .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (externalCallbackV2);
4749
4850 /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */
4951 uint8_t const payload[] = {0x81 , 0xA2 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x02 , 0x07 };
@@ -68,11 +70,12 @@ void switch_callback() {
6870
6971SCENARIO (" A (boolean) property is manipulated in the callback to its origin state" , " [ArduinoCloudThing::decode]" ) {
7072 GIVEN (" CloudProtocol::V2" ) {
73+ PropertyContainer property_container;
7174 ArduinoCloudThing thing;
72- thing.begin ();
75+ thing.begin (&property_container );
7376 cbor::encode (thing);
7477
75- thing .addPropertyReal (switch_turned_on, " switch_turned_on" , Permission::ReadWrite).onUpdate (switch_callback);
78+ property_container .addPropertyReal (switch_turned_on, " switch_turned_on" , Permission::ReadWrite).onUpdate (switch_callback);
7679
7780 /* [{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 */
7881 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 };
@@ -98,7 +101,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
98101static bool sync_callback_called = false ;
99102static bool change_callback_called = false ;
100103
101- void auto_sync_callback (ArduinoCloudProperty & property) {
104+ void auto_sync_callback (Property & property) {
102105 MOST_RECENT_WINS (property);
103106 sync_callback_called = true ;
104107}
@@ -113,10 +116,11 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
113116 sync_callback_called = false ;
114117 change_callback_called = false ;
115118
119+ PropertyContainer property_container;
116120 ArduinoCloudThing thing;
117- thing.begin ();
121+ thing.begin (&property_container );
118122
119- thing .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
123+ property_container .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
120124
121125 test.setLastLocalChangeTimestamp (1550138809 );
122126
@@ -140,10 +144,11 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
140144 sync_callback_called = false ;
141145 change_callback_called = false ;
142146
147+ PropertyContainer property_container;
143148 ArduinoCloudThing thing;
144- thing.begin ();
149+ thing.begin (&property_container );
145150
146- thing .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
151+ property_container .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
147152 test = false ;
148153 test.setLastLocalChangeTimestamp (1550138811 );
149154
@@ -162,16 +167,17 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
162167SCENARIO (" 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." ) {
163168 GIVEN (" CloudProtocol::V2" ) {
164169 bool test = true ;
165- std::unique_ptr<ArduinoCloudProperty > p (new CloudWrapperBool (test));
170+ std::unique_ptr<Property > p (new CloudWrapperBool (test));
166171 sync_callback_called = false ;
167172 change_callback_called = false ;
168173
174+ PropertyContainer property_container;
169175 ArduinoCloudThing thing;
170- thing.begin ();
176+ thing.begin (&property_container );
171177
172- thing .addPropertyReal (*p, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
178+ property_container .addPropertyReal (*p, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
173179 test = false ;
174- thing .updateTimestampOnLocallyChangedProperties ();
180+ property_container .updateTimestampOnLocallyChangedProperties ();
175181 // There is no RTC on test execution environment so we force the local timestamp
176182 p->setLastLocalChangeTimestamp (1550138809 );
177183
@@ -192,16 +198,17 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
192198SCENARIO (" 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." ) {
193199 GIVEN (" CloudProtocol::V2" ) {
194200 bool test = true ;
195- std::unique_ptr<ArduinoCloudProperty > p (new CloudWrapperBool (test));
201+ std::unique_ptr<Property > p (new CloudWrapperBool (test));
196202 sync_callback_called = false ;
197203 change_callback_called = false ;
198204
205+ PropertyContainer property_container;
199206 ArduinoCloudThing thing;
200- thing.begin ();
207+ thing.begin (&property_container );
201208
202- thing .addPropertyReal (*p, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
209+ property_container .addPropertyReal (*p, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
203210 test = false ;
204- thing .updateTimestampOnLocallyChangedProperties ();
211+ property_container .updateTimestampOnLocallyChangedProperties ();
205212 // There is no RTC on test execution environment so we force the local timestamp
206213 p->setLastLocalChangeTimestamp (1550138811 );
207214
@@ -223,10 +230,11 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
223230 sync_callback_called = false ;
224231 change_callback_called = false ;
225232
233+ PropertyContainer property_container;
226234 ArduinoCloudThing thing;
227- thing.begin ();
235+ thing.begin (&property_container );
228236
229- thing .addPropertyReal (location_test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
237+ property_container .addPropertyReal (location_test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
230238 location_test.setLastLocalChangeTimestamp (1550138809 );
231239
232240 /* [{-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*/
@@ -254,10 +262,11 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
254262 sync_callback_called = false ;
255263 change_callback_called = false ;
256264
265+ PropertyContainer property_container;
257266 ArduinoCloudThing thing;
258- thing.begin ();
267+ thing.begin (&property_container );
259268
260- thing .addPropertyReal (location_test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
269+ property_container .addPropertyReal (location_test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
261270 location_test.setLastLocalChangeTimestamp (1550138811 );
262271
263272 /* [{-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*/
@@ -279,7 +288,7 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
279288
280289/* *************************************************************************************/
281290
282- void force_device_sync_callback (ArduinoCloudProperty & property) {
291+ void force_device_sync_callback (Property & property) {
283292 DEVICE_WINS (property);
284293 sync_callback_called = true ;
285294}
@@ -291,10 +300,11 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
291300 sync_callback_called = false ;
292301 change_callback_called = false ;
293302
303+ PropertyContainer property_container;
294304 ArduinoCloudThing thing;
295- thing.begin ();
305+ thing.begin (&property_container );
296306
297- thing .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (force_device_sync_callback);
307+ property_container .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (force_device_sync_callback);
298308
299309 /* [{-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 */
300310 uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
@@ -311,7 +321,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
311321
312322/* *************************************************************************************/
313323
314- void force_cloud_sync_callback (ArduinoCloudProperty & property) {
324+ void force_cloud_sync_callback (Property & property) {
315325 CLOUD_WINS (property);
316326 sync_callback_called = true ;
317327}
@@ -323,10 +333,11 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
323333 sync_callback_called = false ;
324334 change_callback_called = false ;
325335
336+ PropertyContainer property_container;
326337 ArduinoCloudThing thing;
327- thing.begin ();
338+ thing.begin (&property_container );
328339
329- thing .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (force_cloud_sync_callback);
340+ property_container .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (force_cloud_sync_callback);
330341
331342 /* [{-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 */
332343 uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
@@ -349,10 +360,11 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed.
349360 sync_callback_called = false ;
350361 change_callback_called = false ;
351362
363+ PropertyContainer property_container;
352364 ArduinoCloudThing thing;
353- thing.begin ();
365+ thing.begin (&property_container );
354366
355- thing .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback);
367+ property_container .addPropertyReal (test, " test" , Permission::ReadWrite).onUpdate (change_callback);
356368
357369 /* [{-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 */
358370 uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
0 commit comments