Skip to content

Allow an optional encoding of the timestamp in the CBOR message #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set(TEST_SRCS
set(TEST_UTIL_SRCS
src/util/CBORTestUtil.cpp
src/util/OTATestUtil.cpp
src/util/PropertyTestUtil.cpp
)

set(TEST_DUT_SRCS
Expand Down
14 changes: 14 additions & 0 deletions extras/test/include/util/PropertyTestUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/

#ifndef PROPERTY_TEST_UTIL_H_
#define PROPERTY_TEST_UTIL_H_

/**************************************************************************************
FUNCTION DECLARATION
**************************************************************************************/

extern "C" unsigned long getTime();

#endif /* PROPERTY_TEST_UTIL_H_ */
18 changes: 9 additions & 9 deletions extras/test/src/test_addPropertyReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
TEST CODE
**************************************************************************************/

SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyReal]") {
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;

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

CloudInt int_property = 1;

Property * int_property_ptr_1 = &property_container.addPropertyReal(int_property, "int_property", Permission::ReadWrite);
Property * int_property_ptr_2 = &property_container.addPropertyReal(int_property, "int_property", Permission::ReadWrite);
Property * int_property_ptr_1 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite);
Property * int_property_ptr_2 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite);

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

CloudFloat float_property = 1.0f;

Property * float_property_ptr_1 = &property_container.addPropertyReal(float_property, "float_property", Permission::ReadWrite);
Property * float_property_ptr_2 = &property_container.addPropertyReal(float_property, "float_property", Permission::ReadWrite);
Property * float_property_ptr_1 = &addPropertyToContainer(property_container, float_property, "float_property", Permission::ReadWrite);
Property * float_property_ptr_2 = &addPropertyToContainer(property_container, float_property, "float_property", Permission::ReadWrite);

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

CloudString str_property;

Property * str_property_ptr_1 = &property_container.addPropertyReal(str_property, "str_property", Permission::ReadWrite);
Property * str_property_ptr_2 = &property_container.addPropertyReal(str_property, "str_property", Permission::ReadWrite);
Property * str_property_ptr_1 = &addPropertyToContainer(property_container, str_property, "str_property", Permission::ReadWrite);
Property * str_property_ptr_2 = &addPropertyToContainer(property_container, str_property, "str_property", Permission::ReadWrite);

THEN("No new property is added and the first added property is returned instead of a new one") {
REQUIRE(str_property_ptr_1 == str_property_ptr_2);
Expand Down
26 changes: 13 additions & 13 deletions extras/test/src/test_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang
thing.begin(&property_container);

CloudInt test = 10;
property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2);
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};
Expand Down Expand Up @@ -75,7 +75,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
thing.begin(&property_container);
cbor::encode(thing);

property_container.addPropertyReal(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};
Expand Down Expand Up @@ -120,7 +120,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
ArduinoCloudThing thing;
thing.begin(&property_container);

property_container.addPropertyReal(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);

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

property_container.addPropertyReal(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 = false;
test.setLastLocalChangeTimestamp(1550138811);

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

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

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

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

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

property_container.addPropertyReal(location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
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*/
Expand Down Expand Up @@ -266,7 +266,7 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl
ArduinoCloudThing thing;
thing.begin(&property_container);

property_container.addPropertyReal(location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback);
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*/
Expand Down Expand Up @@ -304,7 +304,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
ArduinoCloudThing thing;
thing.begin(&property_container);

property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback);
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};
Expand Down Expand Up @@ -337,7 +337,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
ArduinoCloudThing thing;
thing.begin(&property_container);

property_container.addPropertyReal(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};
Expand All @@ -364,7 +364,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed.
ArduinoCloudThing thing;
thing.begin(&property_container);

property_container.addPropertyReal(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};
Expand Down
Loading