Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8c1da19

Browse files
committedJul 2, 2020
Adjusting unit tests after extracting cbor encode functionality
1 parent dfcc74a commit 8c1da19

File tree

9 files changed

+59
-56
lines changed

9 files changed

+59
-56
lines changed
 

‎extras/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set(TEST_DUT_SRCS
5656
../../src/property/Property.cpp
5757
../../src/property/PropertyContainer.cpp
5858
../../src/cbor/ArduinoCloudThing.cpp
59+
../../src/cbor/CBOREncoder.cpp
5960
../../src/cbor/lib/tinycbor/src/cborencoder.c
6061
../../src/cbor/lib/tinycbor/src/cborencoder_close_container_checked.c
6162
../../src/cbor/lib/tinycbor/src/cborerrorstrings.c

‎extras/test/include/util/CBORTestUtil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
INCLUDE
1010
**************************************************************************************/
1111

12-
#include <ArduinoCloudThing.h>
12+
#include <PropertyContainer.h>
1313

1414
#include <vector>
1515

@@ -24,7 +24,7 @@ namespace cbor
2424
PROTOTYPES
2525
**************************************************************************************/
2626

27-
std::vector<uint8_t> encode(ArduinoCloudThing & thing, bool lightPayload = false);
27+
std::vector<uint8_t> encode(PropertyContainer & property_container, bool lightPayload = false);
2828
void print(std::vector<uint8_t> const & vect);
2929

3030
/**************************************************************************************

‎extras/test/src/test_callback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
7373
PropertyContainer property_container;
7474
ArduinoCloudThing thing;
7575
thing.begin(&property_container);
76-
cbor::encode(thing);
76+
cbor::encode(property_container);
7777

7878
addPropertyToContainer(property_container, switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback);
7979

@@ -91,7 +91,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
9191

9292
/* [{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*/
9393
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);
94+
std::vector<uint8_t> const actual = cbor::encode(property_container);
9595
REQUIRE(actual == expected);
9696
}
9797
}

‎extras/test/src/test_encode.cpp

Lines changed: 36 additions & 36 deletions
Large diffs are not rendered by default.

‎extras/test/src/test_publishEvery.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ SCENARIO("A Arduino cloud property is published periodically", "[ArduinoCloudThi
3131
WHEN("t = 0 ms, publish interval = 1000 ms, 1st call to 'encode'") {
3232
set_millis(0);
3333
THEN("'encode' should encode the property") {
34-
REQUIRE(cbor::encode(thing).size() != 0);
34+
REQUIRE(cbor::encode(property_container).size() != 0);
3535
WHEN("t = 999 ms") {
3636
set_millis(999);
3737
THEN("'encode' should not encode the property") {
38-
REQUIRE(cbor::encode(thing).size() == 0);
38+
REQUIRE(cbor::encode(property_container).size() == 0);
3939
WHEN("t = 1000 ms") {
4040
set_millis(1000);
4141
THEN("'encode' should encode the property") {
42-
REQUIRE(cbor::encode(thing).size() != 0);
42+
REQUIRE(cbor::encode(property_container).size() != 0);
4343
WHEN("t = 1999 ms") {
4444
set_millis(1999);
4545
THEN("'encode' should not encode the property") {
46-
REQUIRE(cbor::encode(thing).size() == 0);
46+
REQUIRE(cbor::encode(property_container).size() == 0);
4747
WHEN("t = 2000 ms") {
4848
set_millis(2000);
4949
THEN("'encode' should encode the property") {
50-
REQUIRE(cbor::encode(thing).size() != 0);
50+
REQUIRE(cbor::encode(property_container).size() != 0);
5151
}
5252
}
5353
}

‎extras/test/src/test_publishOnChange.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ SCENARIO("A Arduino cloud property is published on value change", "[ArduinoCloud
3030

3131
WHEN("test = 10, delta = 6, the property is encoded for the 1st time") {
3232
THEN("The property should be encoded") {
33-
REQUIRE(cbor::encode(thing).size() != 0);
33+
REQUIRE(cbor::encode(property_container).size() != 0);
3434
WHEN("test +=4 -> test = 14") {
3535
test += 4;
3636
THEN("Since the increment since the last update (4) is smaller than the delta of 6 the property should not be encoded") {
37-
REQUIRE(cbor::encode(thing).size() == 0);
37+
REQUIRE(cbor::encode(property_container).size() == 0);
3838
WHEN("test +=4 -> test = 18") {
3939
test += 4;
4040
THEN("Since the increment since the last update (8) is greater than the delta of 6 the property should be encoded") {
41-
REQUIRE(cbor::encode(thing).size() != 0);
41+
REQUIRE(cbor::encode(property_container).size() != 0);
4242
}
4343
}
4444
}

‎extras/test/src/test_publishOnChangeRateLimit.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ SCENARIO("A Arduino cloud property is published on value change but the update r
3232
WHEN("t = 0 ms, min time between updates = 500 ms, property not modified, 1st call to 'encode'") {
3333
set_millis(0);
3434
THEN("'encode' should encode the property") {
35-
REQUIRE(cbor::encode(thing).size() != 0);
35+
REQUIRE(cbor::encode(property_container).size() != 0);
3636
WHEN("t = 499 ms, property modified") {
3737
test++;
3838
set_millis(499);
3939
THEN("'encode' should not encode any property") {
40-
REQUIRE(cbor::encode(thing).size() == 0);
40+
REQUIRE(cbor::encode(property_container).size() == 0);
4141
WHEN("t = 500 ms, property modified") {
4242
test++;
4343
set_millis(500);
4444
THEN("'encode' should encode the property") {
45-
REQUIRE(cbor::encode(thing).size() != 0);
45+
REQUIRE(cbor::encode(property_container).size() != 0);
4646
WHEN("t = 999 ms, property modified") {
4747
test++;
4848
set_millis(999);
4949
THEN("'encode' should not encode any property") {
50-
REQUIRE(cbor::encode(thing).size() == 0);
50+
REQUIRE(cbor::encode(property_container).size() == 0);
5151
WHEN("t = 1000 ms, property modified") {
5252
test++;
5353
set_millis(1000);
5454
THEN("'encode' should encode the property") {
55-
REQUIRE(cbor::encode(thing).size() != 0);
55+
REQUIRE(cbor::encode(property_container).size() != 0);
5656
}
5757
}
5858
}

‎extras/test/src/test_writeOnly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SCENARIO("A Arduino cloud property is marked 'write only'", "[ArduinoCloudThing:
2525
CloudInt test = 0;
2626
addPropertyToContainer(property_container, test, "test", Permission::Write);
2727

28-
REQUIRE(cbor::encode(thing).size() == 0); /* Since 'test' is 'write only' it should not be encoded */
28+
REQUIRE(cbor::encode(property_container).size() == 0); /* Since 'test' is 'write only' it should not be encoded */
2929

3030
/************************************************************************************/
3131
}

‎extras/test/src/util/CBORTestUtil.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <iomanip>
1212
#include <iostream>
1313

14+
#include <CBOREncoder.h>
15+
1416
/**************************************************************************************
1517
NAMESPACE
1618
**************************************************************************************/
@@ -22,9 +24,9 @@ namespace cbor
2224
PUBLIC FUNCTIONS
2325
**************************************************************************************/
2426

25-
std::vector<uint8_t> encode(ArduinoCloudThing & thing, bool lightPayload) {
27+
std::vector<uint8_t> encode(PropertyContainer & property_container, bool lightPayload) {
2628
uint8_t buf[200] = {0};
27-
int const bytes_buf = thing.encode(buf, 200, lightPayload);
29+
int const bytes_buf = CBOREncoder::encode(property_container, buf, 200, lightPayload);
2830
if (bytes_buf == -1) {
2931
return std::vector<uint8_t>();
3032
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.