9
9
#include < catch.hpp>
10
10
11
11
#include < util/CBORTestUtil.h>
12
- #include < ArduinoCloudThing .h>
12
+ #include < CBORDecoder .h>
13
13
#include < PropertyContainer.h>
14
14
#include " types/CloudWrapperBool.h"
15
15
@@ -41,16 +41,14 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang
41
41
42
42
GIVEN (" CloudProtocol::V2" ) {
43
43
PropertyContainer property_container;
44
- ArduinoCloudThing thing;
45
- thing.begin (&property_container);
46
-
44
+
47
45
CloudInt test = 10 ;
48
46
addPropertyToContainer (property_container, test, " test" , Permission::ReadWrite).onUpdate (externalCallbackV2);
49
47
50
48
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */
51
49
uint8_t const payload[] = {0x81 , 0xA2 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x02 , 0x07 };
52
50
int const payload_length = sizeof (payload) / sizeof (uint8_t );
53
- thing. decode (payload, payload_length);
51
+ CBORDecoder:: decode (property_container, payload, payload_length);
54
52
55
53
REQUIRE (callback_called_protocol_v2 == true );
56
54
}
@@ -71,16 +69,14 @@ void switch_callback() {
71
69
SCENARIO (" A (boolean) property is manipulated in the callback to its origin state" , " [ArduinoCloudThing::decode]" ) {
72
70
GIVEN (" CloudProtocol::V2" ) {
73
71
PropertyContainer property_container;
74
- ArduinoCloudThing thing;
75
- thing.begin (&property_container);
76
- cbor::encode (thing);
72
+ cbor::encode (property_container);
77
73
78
74
addPropertyToContainer (property_container, switch_turned_on, " switch_turned_on" , Permission::ReadWrite).onUpdate (switch_callback);
79
75
80
76
/* [{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 */
81
77
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 };
82
78
int const payload_length = sizeof (payload) / sizeof (uint8_t );
83
- thing. decode (payload, payload_length);
79
+ CBORDecoder:: decode (property_container, payload, payload_length);
84
80
85
81
REQUIRE (switch_callback_called == true );
86
82
@@ -91,7 +87,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
91
87
92
88
/* [{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*/
93
89
std::vector<uint8_t > 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 };
94
- std::vector<uint8_t > const actual = cbor::encode (thing );
90
+ std::vector<uint8_t > const actual = cbor::encode (property_container );
95
91
REQUIRE (actual == expected);
96
92
}
97
93
}
@@ -117,17 +113,15 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
117
113
change_callback_called = false ;
118
114
119
115
PropertyContainer property_container;
120
- ArduinoCloudThing thing;
121
- thing.begin (&property_container);
122
-
116
+
123
117
addPropertyToContainer (property_container, test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
124
118
125
119
test.setLastLocalChangeTimestamp (1550138809 );
126
120
127
121
/* [{-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 */
128
122
uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
129
123
int const payload_length = sizeof (payload) / sizeof (uint8_t );
130
- thing. decode (payload, payload_length, true );
124
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
131
125
132
126
REQUIRE (sync_callback_called == true );
133
127
REQUIRE (change_callback_called == true );
@@ -145,17 +139,15 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
145
139
change_callback_called = false ;
146
140
147
141
PropertyContainer property_container;
148
- ArduinoCloudThing thing;
149
- thing.begin (&property_container);
150
-
142
+
151
143
addPropertyToContainer (property_container, test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
152
144
test = false ;
153
145
test.setLastLocalChangeTimestamp (1550138811 );
154
146
155
147
/* [{-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 */
156
148
uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
157
149
int const payload_length = sizeof (payload) / sizeof (uint8_t );
158
- thing. decode (payload, payload_length, true );
150
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
159
151
160
152
REQUIRE (sync_callback_called == true );
161
153
REQUIRE (change_callback_called == false );
@@ -172,9 +164,7 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
172
164
change_callback_called = false ;
173
165
174
166
PropertyContainer property_container;
175
- ArduinoCloudThing thing;
176
- thing.begin (&property_container);
177
-
167
+
178
168
addPropertyToContainer (property_container, *p, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
179
169
test = false ;
180
170
updateTimestampOnLocallyChangedProperties (property_container);
@@ -184,7 +174,7 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
184
174
/* [{-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 */
185
175
uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
186
176
int const payload_length = sizeof (payload) / sizeof (uint8_t );
187
- thing. decode (payload, payload_length, true );
177
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
188
178
189
179
REQUIRE (sync_callback_called == true );
190
180
REQUIRE (change_callback_called == true );
@@ -203,9 +193,7 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
203
193
change_callback_called = false ;
204
194
205
195
PropertyContainer property_container;
206
- ArduinoCloudThing thing;
207
- thing.begin (&property_container);
208
-
196
+
209
197
addPropertyToContainer (property_container, *p, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
210
198
test = false ;
211
199
updateTimestampOnLocallyChangedProperties (property_container);
@@ -215,7 +203,7 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
215
203
/* [{-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 */
216
204
uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
217
205
int const payload_length = sizeof (payload) / sizeof (uint8_t );
218
- thing. decode (payload, payload_length, true );
206
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
219
207
220
208
REQUIRE (sync_callback_called == true );
221
209
REQUIRE (change_callback_called == false );
@@ -231,17 +219,15 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
231
219
change_callback_called = false ;
232
220
233
221
PropertyContainer property_container;
234
- ArduinoCloudThing thing;
235
- thing.begin (&property_container);
236
-
222
+
237
223
addPropertyToContainer (property_container, location_test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
238
224
location_test.setLastLocalChangeTimestamp (1550138809 );
239
225
240
226
/* [{-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*/
241
227
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 };
242
228
243
229
int const payload_length = sizeof (payload) / sizeof (uint8_t );
244
- thing. decode (payload, payload_length, true );
230
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
245
231
246
232
REQUIRE (sync_callback_called == true );
247
233
REQUIRE (change_callback_called == true );
@@ -263,17 +249,15 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
263
249
change_callback_called = false ;
264
250
265
251
PropertyContainer property_container;
266
- ArduinoCloudThing thing;
267
- thing.begin (&property_container);
268
-
252
+
269
253
addPropertyToContainer (property_container, location_test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (auto_sync_callback);
270
254
location_test.setLastLocalChangeTimestamp (1550138811 );
271
255
272
256
/* [{-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*/
273
257
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 };
274
258
275
259
int const payload_length = sizeof (payload) / sizeof (uint8_t );
276
- thing. decode (payload, payload_length, true );
260
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
277
261
278
262
REQUIRE (sync_callback_called == true );
279
263
REQUIRE (change_callback_called == false );
@@ -301,15 +285,13 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
301
285
change_callback_called = false ;
302
286
303
287
PropertyContainer property_container;
304
- ArduinoCloudThing thing;
305
- thing.begin (&property_container);
306
-
288
+
307
289
addPropertyToContainer (property_container, test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (force_device_sync_callback);
308
290
309
291
/* [{-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 */
310
292
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
293
int const payload_length = sizeof (payload) / sizeof (uint8_t );
312
- thing. decode (payload, payload_length, true );
294
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
313
295
314
296
REQUIRE (sync_callback_called == true );
315
297
REQUIRE (change_callback_called == false );
@@ -334,15 +316,13 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
334
316
change_callback_called = false ;
335
317
336
318
PropertyContainer property_container;
337
- ArduinoCloudThing thing;
338
- thing.begin (&property_container);
339
-
319
+
340
320
addPropertyToContainer (property_container, test, " test" , Permission::ReadWrite).onUpdate (change_callback).onSync (force_cloud_sync_callback);
341
321
342
322
/* [{-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 */
343
323
uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
344
324
int const payload_length = sizeof (payload) / sizeof (uint8_t );
345
- thing. decode (payload, payload_length, true );
325
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
346
326
347
327
REQUIRE (sync_callback_called == true );
348
328
REQUIRE (change_callback_called == true );
@@ -361,15 +341,13 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed.
361
341
change_callback_called = false ;
362
342
363
343
PropertyContainer property_container;
364
- ArduinoCloudThing thing;
365
- thing.begin (&property_container);
366
-
344
+
367
345
addPropertyToContainer (property_container, test, " test" , Permission::ReadWrite).onUpdate (change_callback);
368
346
369
347
/* [{-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 */
370
348
uint8_t const payload[] = {0x81 , 0xA3 , 0x22 , 0xFB , 0x41 , 0xD7 , 0x19 , 0x4F , 0x6E , 0x80 , 0x00 , 0x00 , 0x00 , 0x64 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0xF5 };
371
349
int const payload_length = sizeof (payload) / sizeof (uint8_t );
372
- thing. decode (payload, payload_length, true );
350
+ CBORDecoder:: decode (property_container, payload, payload_length, true );
373
351
374
352
REQUIRE (sync_callback_called == false );
375
353
REQUIRE (change_callback_called == false );
0 commit comments