Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1ee31e5

Browse files
Merge pull request #137 from arduino-libraries/encode-timestamp-opt
Allow an optional encoding of the timestamp in the CBOR message
2 parents 419fd32 + 4959e2b commit 1ee31e5

21 files changed

+241
-190
lines changed

‎extras/test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(TEST_SRCS
4646
set(TEST_UTIL_SRCS
4747
src/util/CBORTestUtil.cpp
4848
src/util/OTATestUtil.cpp
49+
src/util/PropertyTestUtil.cpp
4950
)
5051

5152
set(TEST_DUT_SRCS
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
#ifndef PROPERTY_TEST_UTIL_H_
6+
#define PROPERTY_TEST_UTIL_H_
7+
8+
/**************************************************************************************
9+
FUNCTION DECLARATION
10+
**************************************************************************************/
11+
12+
extern "C" unsigned long getTime();
13+
14+
#endif /* PROPERTY_TEST_UTIL_H_ */

‎extras/test/src/test_addPropertyReal.cpp‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
TEST CODE
2020
**************************************************************************************/
2121

22-
SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyReal]") {
22+
SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyToContainer]") {
2323
WHEN("The same bool property is added multiple times") {
2424
PropertyContainer property_container;
2525

2626
CloudBool bool_property = false;
2727

28-
Property * bool_property_ptr_1 = &property_container.addPropertyReal(bool_property, "bool_property", Permission::ReadWrite);
29-
Property * bool_property_ptr_2 = &property_container.addPropertyReal(bool_property, "bool_property", Permission::ReadWrite);
28+
Property * bool_property_ptr_1 = &addPropertyToContainer(property_container, bool_property, "bool_property", Permission::ReadWrite);
29+
Property * bool_property_ptr_2 = &addPropertyToContainer(property_container, bool_property, "bool_property", Permission::ReadWrite);
3030
THEN("No new property is added and the first added property is returned instead of a new one") {
3131
REQUIRE(bool_property_ptr_1 == bool_property_ptr_2);
3232
}
@@ -39,8 +39,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
3939

4040
CloudInt int_property = 1;
4141

42-
Property * int_property_ptr_1 = &property_container.addPropertyReal(int_property, "int_property", Permission::ReadWrite);
43-
Property * int_property_ptr_2 = &property_container.addPropertyReal(int_property, "int_property", Permission::ReadWrite);
42+
Property * int_property_ptr_1 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite);
43+
Property * int_property_ptr_2 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite);
4444

4545
THEN("No new property is added and the first added property is returned instead of a new one") {
4646
REQUIRE(int_property_ptr_1 == int_property_ptr_2);
@@ -54,8 +54,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
5454

5555
CloudFloat float_property = 1.0f;
5656

57-
Property * float_property_ptr_1 = &property_container.addPropertyReal(float_property, "float_property", Permission::ReadWrite);
58-
Property * float_property_ptr_2 = &property_container.addPropertyReal(float_property, "float_property", Permission::ReadWrite);
57+
Property * float_property_ptr_1 = &addPropertyToContainer(property_container, float_property, "float_property", Permission::ReadWrite);
58+
Property * float_property_ptr_2 = &addPropertyToContainer(property_container, float_property, "float_property", Permission::ReadWrite);
5959

6060
THEN("No new property is added and the first added property is returned instead of a new one") {
6161
REQUIRE(float_property_ptr_1 == float_property_ptr_2);
@@ -69,8 +69,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
6969

7070
CloudString str_property;
7171

72-
Property * str_property_ptr_1 = &property_container.addPropertyReal(str_property, "str_property", Permission::ReadWrite);
73-
Property * str_property_ptr_2 = &property_container.addPropertyReal(str_property, "str_property", Permission::ReadWrite);
72+
Property * str_property_ptr_1 = &addPropertyToContainer(property_container, str_property, "str_property", Permission::ReadWrite);
73+
Property * str_property_ptr_2 = &addPropertyToContainer(property_container, str_property, "str_property", Permission::ReadWrite);
7474

7575
THEN("No new property is added and the first added property is returned instead of a new one") {
7676
REQUIRE(str_property_ptr_1 == str_property_ptr_2);

‎extras/test/src/test_callback.cpp‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang
4545
thing.begin(&property_container);
4646

4747
CloudInt test = 10;
48-
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2);
48+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2);
4949

5050
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */
5151
uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07};
@@ -75,7 +75,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
7575
thing.begin(&property_container);
7676
cbor::encode(thing);
7777

78-
property_container.addPropertyReal(switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback);
78+
addPropertyToContainer(property_container, switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback);
7979

8080
/* [{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 */
8181
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};
@@ -120,7 +120,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
120120
ArduinoCloudThing thing;
121121
thing.begin(&property_container);
122122

123-
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
123+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
124124

125125
test.setLastLocalChangeTimestamp(1550138809);
126126

@@ -148,7 +148,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
148148
ArduinoCloudThing thing;
149149
thing.begin(&property_container);
150150

151-
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
151+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
152152
test = false;
153153
test.setLastLocalChangeTimestamp(1550138811);
154154

@@ -175,9 +175,9 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
175175
ArduinoCloudThing thing;
176176
thing.begin(&property_container);
177177

178-
property_container.addPropertyReal(*p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
178+
addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
179179
test = false;
180-
property_container.updateTimestampOnLocallyChangedProperties();
180+
updateTimestampOnLocallyChangedProperties(property_container);
181181
//There is no RTC on test execution environment so we force the local timestamp
182182
p->setLastLocalChangeTimestamp(1550138809);
183183

@@ -206,9 +206,9 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
206206
ArduinoCloudThing thing;
207207
thing.begin(&property_container);
208208

209-
property_container.addPropertyReal(*p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
209+
addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
210210
test = false;
211-
property_container.updateTimestampOnLocallyChangedProperties();
211+
updateTimestampOnLocallyChangedProperties(property_container);
212212
//There is no RTC on test execution environment so we force the local timestamp
213213
p->setLastLocalChangeTimestamp(1550138811);
214214

@@ -234,7 +234,7 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
234234
ArduinoCloudThing thing;
235235
thing.begin(&property_container);
236236

237-
property_container.addPropertyReal(location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
237+
addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
238238
location_test.setLastLocalChangeTimestamp(1550138809);
239239

240240
/* [{-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*/
@@ -266,7 +266,7 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
266266
ArduinoCloudThing thing;
267267
thing.begin(&property_container);
268268

269-
property_container.addPropertyReal(location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
269+
addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
270270
location_test.setLastLocalChangeTimestamp(1550138811);
271271

272272
/* [{-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*/
@@ -304,7 +304,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
304304
ArduinoCloudThing thing;
305305
thing.begin(&property_container);
306306

307-
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback);
307+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback);
308308

309309
/* [{-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 */
310310
uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5};
@@ -337,7 +337,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
337337
ArduinoCloudThing thing;
338338
thing.begin(&property_container);
339339

340-
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_cloud_sync_callback);
340+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_cloud_sync_callback);
341341

342342
/* [{-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 */
343343
uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5};
@@ -364,7 +364,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed.
364364
ArduinoCloudThing thing;
365365
thing.begin(&property_container);
366366

367-
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback);
367+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback);
368368

369369
/* [{-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 */
370370
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /