Skip to content

Commit 2d71ccf

Browse files
authored
Merge pull request #129 from arduino-libraries/integrate-ArduinoCloudThing
Integrate ArduinoCloudThing with ArduinoIoTCloud
2 parents c6723e8 + d47720f commit 2d71ccf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+11895
-22
lines changed

Diff for: .github/workflows/compile-examples.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
env:
2020
# libraries to install for all boards
21-
UNIVERSAL_LIBRARIES: '"ArduinoCloudThing" "Arduino_ConnectionHandler" "Arduino_DebugUtils" "ArduinoMqttClient"'
21+
UNIVERSAL_LIBRARIES: '"Arduino_ConnectionHandler" "Arduino_DebugUtils" "ArduinoMqttClient"'
2222
# sketch paths to compile (recursive) for all boards
2323
UNIVERSAL_SKETCH_PATHS: '"examples/ArduinoIoTCloud-Advanced" "examples/ArduinoIoTCloud-Basic" "examples/utility/ArduinoIoTCloud_Travis_CI"'
2424

Diff for: .github/workflows/unit-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
cd "$BUILD_PATH"
3939
sudo apt-get --assume-yes install lcov > /dev/null
4040
lcov --directory . --capture --output-file coverage.info
41-
lcov --quiet --remove coverage.info '*/extras/test/*' '/usr/*' --output-file coverage.info
41+
lcov --quiet --remove coverage.info '*/extras/test/*' '/usr/*' '*/src/cbor/lib/*' --output-file coverage.info
4242
lcov --list coverage.info
4343
4444
- name: Upload coverage report to Codecov

Diff for: extras/test/CMakeLists.txt

+48-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project(testArduinoIoTCloud)
99
##########################################################################
1010

1111
include_directories(include)
12+
include_directories(../../src/cbor)
1213
include_directories(../../src/utility/ota)
1314
include_directories(external/catch/v2.12.1/include)
1415
include_directories(external/fakeit/v2.0.5/include)
@@ -21,14 +22,57 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2122

2223
##########################################################################
2324

24-
set(TEST_TARGET testArduinoIoTCloud)
25+
set(TEST_TARGET ${CMAKE_PROJECT_NAME})
26+
27+
##########################################################################
2528

2629
set(TEST_SRCS
27-
src/test_main.cpp
2830
src/test_OTALogic.cpp
29-
src/OTATestData.cpp
31+
32+
src/test_addPropertyReal.cpp
33+
src/test_callback.cpp
34+
src/test_CloudColor.cpp
35+
src/test_CloudLocation.cpp
36+
src/test_decode.cpp
37+
src/test_encode.cpp
38+
src/test_publishEvery.cpp
39+
src/test_publishOnChange.cpp
40+
src/test_publishOnChangeRateLimit.cpp
41+
src/test_readOnly.cpp
42+
src/test_writeOnly.cpp
43+
)
44+
45+
set(TEST_UTIL_SRCS
46+
src/util/CBORTestUtil.cpp
47+
src/util/OTATestUtil.cpp
48+
)
49+
50+
set(TEST_DUT_SRCS
3051
../../src/utility/ota/crc.cpp
3152
../../src/utility/ota/OTALogic.cpp
53+
54+
../../src/cbor/ArduinoCloudThing.cpp
55+
../../src/cbor/ArduinoCloudProperty.cpp
56+
../../src/cbor/lib/tinycbor/src/cborencoder.c
57+
../../src/cbor/lib/tinycbor/src/cborencoder_close_container_checked.c
58+
../../src/cbor/lib/tinycbor/src/cborerrorstrings.c
59+
../../src/cbor/lib/tinycbor/src/cborparser.c
60+
../../src/cbor/lib/tinycbor/src/cborparser_dup_string.c
61+
../../src/cbor/lib/tinycbor/src/cborpretty.c
62+
../../src/cbor/lib/tinycbor/src/cborpretty_stdio.c
63+
../../src/cbor/lib/tinycbor/src/cbortojson.c
64+
../../src/cbor/lib/tinycbor/src/cborvalidation.c
65+
../../src/cbor/lib/tinycbor/src/open_memstream.c
66+
)
67+
68+
##########################################################################
69+
70+
set(TEST_TARGET_SRCS
71+
src/Arduino.cpp
72+
src/test_main.cpp
73+
${TEST_SRCS}
74+
${TEST_UTIL_SRCS}
75+
${TEST_DUT_SRCS}
3276
)
3377

3478
##########################################################################
@@ -43,7 +87,7 @@ set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage")
4387

4488
add_executable(
4589
${TEST_TARGET}
46-
${TEST_SRCS}
90+
${TEST_TARGET_SRCS}
4791
)
4892

4993
##########################################################################

Diff for: extras/test/include/Arduino.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
#ifndef TEST_ARDUINO_H_
6+
#define TEST_ARDUINO_H_
7+
8+
/******************************************************************************
9+
INCLUDE
10+
******************************************************************************/
11+
12+
#include <string>
13+
14+
/******************************************************************************
15+
TYPEDEF
16+
******************************************************************************/
17+
18+
typedef std::string String;
19+
20+
/******************************************************************************
21+
FUNCTION PROTOTYPES
22+
******************************************************************************/
23+
24+
void set_millis(unsigned long const millis);
25+
unsigned long millis();
26+
27+
#endif /* TEST_ARDUINO_H_ */

Diff for: extras/test/include/util/CBORTestUtil.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
#ifndef INCLUDE_CBOR_TESTUTIL_H_
6+
#define INCLUDE_CBOR_TESTUTIL_H_
7+
8+
/**************************************************************************************
9+
INCLUDE
10+
**************************************************************************************/
11+
12+
#include <ArduinoCloudThing.h>
13+
14+
#include <vector>
15+
16+
/**************************************************************************************
17+
NAMESPACE
18+
**************************************************************************************/
19+
20+
namespace cbor
21+
{
22+
23+
/**************************************************************************************
24+
PROTOTYPES
25+
**************************************************************************************/
26+
27+
std::vector<uint8_t> encode(ArduinoCloudThing & thing, bool lightPayload = false);
28+
void print(std::vector<uint8_t> const & vect);
29+
30+
/**************************************************************************************
31+
NAMESPACE
32+
**************************************************************************************/
33+
34+
} /* cbor */
35+
36+
#endif /* INCLUDE_CBOR_TESTUTIL_H_ */

Diff for: extras/test/include/OTATestData.h renamed to extras/test/include/util/OTATestUtil.h

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

5-
#ifndef OTA_TEST_DATA_H_
6-
#define OTA_TEST_DATA_H_
5+
#ifndef OTA_TEST_DATA_GENERATOR_H_
6+
#define OTA_TEST_DATA_GENERATOR_H_
77

88
/**************************************************************************************
99
INCLUDE
1010
**************************************************************************************/
1111

1212
#include <stdint.h>
1313

14+
/**************************************************************************************
15+
NAMESPACE
16+
**************************************************************************************/
17+
18+
namespace ota
19+
{
20+
1421
/**************************************************************************************
1522
TYPEDEF
1623
**************************************************************************************/
@@ -33,5 +40,10 @@ union OTAData
3340
void generate_valid_ota_data(OTAData & ota_data);
3441
void generate_invalid_ota_data_crc_wrong(OTAData & ota_data);
3542

43+
/**************************************************************************************
44+
NAMESPACE
45+
**************************************************************************************/
46+
47+
} /* ota */
3648

37-
#endif /* OTA_TEST_DATA_H_ */
49+
#endif /* OTA_TEST_DATA_GENERATOR_H_ */

Diff for: extras/test/src/Arduino.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
/******************************************************************************
6+
INCLUDE
7+
******************************************************************************/
8+
9+
#include <Arduino.h>
10+
11+
/******************************************************************************
12+
GLOBAL VARIABLES
13+
******************************************************************************/
14+
15+
static unsigned long current_millis = 0;
16+
17+
/******************************************************************************
18+
PUBLIC FUNCTIONS
19+
******************************************************************************/
20+
21+
void set_millis(unsigned long const millis) {
22+
current_millis = millis;
23+
}
24+
25+
unsigned long millis() {
26+
return current_millis;
27+
}

Diff for: extras/test/src/test_CloudColor.cpp

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <util/CBORTestUtil.h>
12+
#include <ArduinoCloudThing.h>
13+
14+
/**************************************************************************************
15+
TEST CODE
16+
**************************************************************************************/
17+
18+
/************************************************************************************/
19+
SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudColor]") {
20+
WHEN("Set invalid color HSB") {
21+
GIVEN("CloudProtocol::V2") {
22+
23+
24+
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
25+
26+
Color value_color_test = color_test.getValue();
27+
REQUIRE(value_color_test.setColorHSB(500.0, 20.0, 30.0) == false);
28+
29+
}
30+
}
31+
32+
WHEN("Set and Get different RGB colors") {
33+
GIVEN("CloudProtocol::V2") {
34+
35+
uint8_t r, g, b;
36+
37+
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
38+
39+
Color value_color_test = color_test.getValue();
40+
41+
value_color_test.setColorRGB(128, 64, 64);
42+
value_color_test.getRGB(r, g, b);
43+
44+
REQUIRE(r == 128);
45+
REQUIRE(g == 64);
46+
REQUIRE(b == 64);
47+
48+
value_color_test.setColorRGB(126, 128, 64);
49+
value_color_test.getRGB(r, g, b);
50+
51+
REQUIRE(r == 126);
52+
REQUIRE(g == 128);
53+
REQUIRE(b == 64);
54+
55+
value_color_test.setColorRGB(64, 128, 64);
56+
value_color_test.getRGB(r, g, b);
57+
58+
REQUIRE(r == 64);
59+
REQUIRE(g == 128);
60+
REQUIRE(b == 64);
61+
62+
value_color_test.setColorRGB(64, 64, 128);
63+
value_color_test.getRGB(r, g, b);
64+
65+
REQUIRE(r == 64);
66+
REQUIRE(g == 64);
67+
REQUIRE(b == 128);
68+
69+
value_color_test.setColorRGB(255, 0, 255);
70+
value_color_test.getRGB(r, g, b);
71+
72+
REQUIRE(r == 255);
73+
REQUIRE(g == 0);
74+
REQUIRE(b == 255);
75+
76+
value_color_test.setColorRGB(0, 0, 0);
77+
value_color_test.getRGB(r, g, b);
78+
79+
REQUIRE(r == 0);
80+
REQUIRE(g == 0);
81+
REQUIRE(b == 0);
82+
83+
value_color_test.setColorRGB(50, 100, 20);
84+
value_color_test.getRGB(r, g, b);
85+
86+
REQUIRE(r == 50);
87+
REQUIRE(g == 100);
88+
REQUIRE(b == 20);
89+
90+
value_color_test.setColorRGB(20, 50, 70);
91+
value_color_test.getRGB(r, g, b);
92+
93+
REQUIRE(r == 20);
94+
REQUIRE(g == 50);
95+
REQUIRE(b == 70);
96+
97+
}
98+
}
99+
100+
WHEN("Set HSB colors and get RGB") {
101+
GIVEN("CloudProtocol::V2") {
102+
bool verify;
103+
uint8_t r, g, b;
104+
105+
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
106+
107+
Color value_color_test = color_test.getValue();
108+
109+
value_color_test.setColorHSB(240, 50, 50);
110+
value_color_test.getRGB(r, g, b);
111+
verify = r == 64 && g == 64 && b == 128;
112+
113+
REQUIRE(verify);
114+
115+
value_color_test.setColorHSB(120, 50, 50);
116+
value_color_test.getRGB(r, g, b);
117+
verify = r == 64 && g == 128 && b == 64;
118+
119+
REQUIRE(verify);
120+
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)