Skip to content

Commit ca3e6a1

Browse files
committed
Renaming TestUtil to CBORTestUtil and encapsulating its methods in the namespace 'cbor'
1 parent 1d8d99a commit ca3e6a1

12 files changed

+92
-66
lines changed

extras/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ set(TEST_SRCS
4343
src/test_readOnly.cpp
4444
src/test_writeOnly.cpp
4545

46+
src/util/CBORTestUtil.cpp
4647
src/util/OTATestDataGenerator.cpp
47-
src/util/TestUtil.cpp
4848

4949
../../src/utility/ota/crc.cpp
5050
../../src/utility/ota/OTALogic.cpp

extras/test/include/util/TestUtil.h renamed to extras/test/include/util/CBORTestUtil.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Copyright (c) 2019 Arduino. All rights reserved.
33
*/
44

5-
#ifndef INCLUDE_TESTUTIL_H_
6-
#define INCLUDE_TESTUTIL_H_
5+
#ifndef INCLUDE_CBOR_TESTUTIL_H_
6+
#define INCLUDE_CBOR_TESTUTIL_H_
77

88
/**************************************************************************************
99
INCLUDE
@@ -13,11 +13,24 @@
1313

1414
#include <vector>
1515

16+
/**************************************************************************************
17+
NAMESPACE
18+
**************************************************************************************/
19+
20+
namespace cbor
21+
{
22+
1623
/**************************************************************************************
1724
PROTOTYPES
1825
**************************************************************************************/
1926

2027
std::vector<uint8_t> encode(ArduinoCloudThing & thing, bool lightPayload = false);
2128
void print(std::vector<uint8_t> const & vect);
2229

23-
#endif /* INCLUDE_TESTUTIL_H_ */
30+
/**************************************************************************************
31+
NAMESPACE
32+
**************************************************************************************/
33+
34+
} /* cbor */
35+
36+
#endif /* INCLUDE_CBOR_TESTUTIL_H_ */

extras/test/src/test_CloudColor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313

1414
/**************************************************************************************

extras/test/src/test_callback.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313
#include "types/CloudWrapperBool.h"
1414

@@ -70,7 +70,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat
7070
GIVEN("CloudProtocol::V2") {
7171
ArduinoCloudThing thing;
7272
thing.begin();
73-
encode(thing);
73+
cbor::encode(thing);
7474

7575
thing.addPropertyReal(switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback);
7676

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

8989
/* [{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*/
9090
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};
91-
std::vector<uint8_t> const actual = encode(thing);
91+
std::vector<uint8_t> const actual = cbor::encode(thing);
9292
REQUIRE(actual == expected);
9393
}
9494
}

extras/test/src/test_decode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313
#include "types/CloudWrapperBool.h"
1414
#include "types/CloudWrapperFloat.h"

extras/test/src/test_encode.cpp

+37-37
Large diffs are not rendered by default.

extras/test/src/test_publishEvery.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313

1414
/**************************************************************************************
@@ -30,23 +30,23 @@ SCENARIO("A Arduino cloud property is published periodically", "[ArduinoCloudThi
3030
WHEN("t = 0 ms, publish interval = 1000 ms, 1st call to 'encode'") {
3131
set_millis(0);
3232
THEN("'encode' should encode the property") {
33-
REQUIRE(encode(thing).size() != 0);
33+
REQUIRE(cbor::encode(thing).size() != 0);
3434
WHEN("t = 999 ms") {
3535
set_millis(999);
3636
THEN("'encode' should not encode the property") {
37-
REQUIRE(encode(thing).size() == 0);
37+
REQUIRE(cbor::encode(thing).size() == 0);
3838
WHEN("t = 1000 ms") {
3939
set_millis(1000);
4040
THEN("'encode' should encode the property") {
41-
REQUIRE(encode(thing).size() != 0);
41+
REQUIRE(cbor::encode(thing).size() != 0);
4242
WHEN("t = 1999 ms") {
4343
set_millis(1999);
4444
THEN("'encode' should not encode the property") {
45-
REQUIRE(encode(thing).size() == 0);
45+
REQUIRE(cbor::encode(thing).size() == 0);
4646
WHEN("t = 2000 ms") {
4747
set_millis(2000);
4848
THEN("'encode' should encode the property") {
49-
REQUIRE(encode(thing).size() != 0);
49+
REQUIRE(cbor::encode(thing).size() != 0);
5050
}
5151
}
5252
}

extras/test/src/test_publishOnChange.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313

1414
/**************************************************************************************
@@ -29,15 +29,15 @@ SCENARIO("A Arduino cloud property is published on value change", "[ArduinoCloud
2929

3030
WHEN("test = 10, delta = 6, the property is encoded for the 1st time") {
3131
THEN("The property should be encoded") {
32-
REQUIRE(encode(thing).size() != 0);
32+
REQUIRE(cbor::encode(thing).size() != 0);
3333
WHEN("test +=4 -> test = 14") {
3434
test += 4;
3535
THEN("Since the increment since the last update (4) is smaller than the delta of 6 the property should not be encoded") {
36-
REQUIRE(encode(thing).size() == 0);
36+
REQUIRE(cbor::encode(thing).size() == 0);
3737
WHEN("test +=4 -> test = 18") {
3838
test += 4;
3939
THEN("Since the increment since the last update (8) is greater than the delta of 6 the property should be encoded") {
40-
REQUIRE(encode(thing).size() != 0);
40+
REQUIRE(cbor::encode(thing).size() != 0);
4141
}
4242
}
4343
}

extras/test/src/test_publishOnChangeRateLimit.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313

1414
/**************************************************************************************
@@ -31,27 +31,27 @@ SCENARIO("A Arduino cloud property is published on value change but the update r
3131
WHEN("t = 0 ms, min time between updates = 500 ms, property not modified, 1st call to 'encode'") {
3232
set_millis(0);
3333
THEN("'encode' should encode the property") {
34-
REQUIRE(encode(thing).size() != 0);
34+
REQUIRE(cbor::encode(thing).size() != 0);
3535
WHEN("t = 499 ms, property modified") {
3636
test++;
3737
set_millis(499);
3838
THEN("'encode' should not encode any property") {
39-
REQUIRE(encode(thing).size() == 0);
39+
REQUIRE(cbor::encode(thing).size() == 0);
4040
WHEN("t = 500 ms, property modified") {
4141
test++;
4242
set_millis(500);
4343
THEN("'encode' should encode the property") {
44-
REQUIRE(encode(thing).size() != 0);
44+
REQUIRE(cbor::encode(thing).size() != 0);
4545
WHEN("t = 999 ms, property modified") {
4646
test++;
4747
set_millis(999);
4848
THEN("'encode' should not encode any property") {
49-
REQUIRE(encode(thing).size() == 0);
49+
REQUIRE(cbor::encode(thing).size() == 0);
5050
WHEN("t = 1000 ms, property modified") {
5151
test++;
5252
set_millis(1000);
5353
THEN("'encode' should encode the property") {
54-
REQUIRE(encode(thing).size() != 0);
54+
REQUIRE(cbor::encode(thing).size() != 0);
5555
}
5656
}
5757
}

extras/test/src/test_readOnly.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313

1414
/**************************************************************************************

extras/test/src/test_writeOnly.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <catch.hpp>
1010

11-
#include <util/TestUtil.h>
11+
#include <util/CBORTestUtil.h>
1212
#include <ArduinoCloudThing.h>
1313

1414
/**************************************************************************************
@@ -24,7 +24,7 @@ SCENARIO("A Arduino cloud property is marked 'write only'", "[ArduinoCloudThing:
2424
CloudInt test = 0;
2525
thing.addPropertyReal(test, "test", Permission::Write);
2626

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

2929
/************************************************************************************/
3030
}

extras/test/src/util/TestUtil.cpp renamed to extras/test/src/util/CBORTestUtil.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
INCLUDE
77
**************************************************************************************/
88

9-
#include <util/TestUtil.h>
9+
#include <util/CBORTestUtil.h>
1010

1111
#include <iomanip>
1212
#include <iostream>
1313

14+
/**************************************************************************************
15+
NAMESPACE
16+
**************************************************************************************/
17+
18+
namespace cbor
19+
{
20+
1421
/**************************************************************************************
1522
PUBLIC FUNCTIONS
1623
**************************************************************************************/
@@ -38,3 +45,9 @@ void print(std::vector<uint8_t> const & vect) {
3845
}
3946
std::cout << std::endl;
4047
}
48+
49+
/**************************************************************************************
50+
NAMESPACE
51+
**************************************************************************************/
52+
53+
} /* cbor */

0 commit comments

Comments
 (0)