Skip to content

Commit ca81751

Browse files
Including Arduino_CloudUtils in cmake unit testing
1 parent 7e6f473 commit ca81751

File tree

5 files changed

+148
-124
lines changed

5 files changed

+148
-124
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
coverage-exclude-paths: |
3333
- '*/extras/test/*'
3434
- '/usr/*'
35-
- '*/src/cbor/lib/*'
3635
coverage-data-path: ${{ env.COVERAGE_DATA_PATH }}
3736

3837
# A token is used to avoid intermittent spurious job failures caused by rate limiting.

Diff for: .gitmodules

Whitespace-only changes.

Diff for: extras/test/CMakeLists.txt

+42-14
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,42 @@ FetchContent_Declare(
1414
GIT_TAG v3.4.0
1515
)
1616

17+
FetchContent_Declare(
18+
cloudutils
19+
GIT_REPOSITORY https://github.com/arduino-libraries/Arduino_CloudUtils.git
20+
GIT_TAG main
21+
)
22+
1723
FetchContent_MakeAvailable(Catch2)
1824

25+
FetchContent_MakeAvailable(cloudutils)
1926
##########################################################################
2027

2128
include_directories(include)
2229
include_directories(../../src)
30+
include_directories(../../src/message)
2331
include_directories(../../src/cbor)
2432
include_directories(../../src/property)
2533
include_directories(../../src/utility/time)
2634

35+
# add_library(cloudutils STATIC IMPORTED GLOBAL)
36+
add_library(cloudutils INTERFACE)
37+
38+
target_include_directories(
39+
cloudutils INTERFACE
40+
${cloudutils_SOURCE_DIR}/src/
41+
)
42+
43+
target_include_directories(
44+
cloudutils INTERFACE
45+
${cloudutils_SOURCE_DIR}/src/cbor
46+
)
47+
48+
target_include_directories(
49+
cloudutils INTERFACE
50+
${cloudutils_SOURCE_DIR}/src/interfaces
51+
)
52+
2753
##########################################################################
2854

2955
set(CMAKE_CXX_STANDARD 11)
@@ -67,21 +93,22 @@ set(TEST_DUT_SRCS
6793
../../src/property/PropertyContainer.cpp
6894
../../src/cbor/CBORDecoder.cpp
6995
../../src/cbor/CBOREncoder.cpp
70-
../../src/cbor/MessageDecoder.cpp
71-
../../src/cbor/MessageEncoder.cpp
72-
../../src/cbor/CBOR.cpp
73-
../../src/cbor/lib/tinycbor/src/cborencoder.c
74-
../../src/cbor/lib/tinycbor/src/cborencoder_close_container_checked.c
75-
../../src/cbor/lib/tinycbor/src/cborerrorstrings.c
76-
../../src/cbor/lib/tinycbor/src/cborparser.c
77-
../../src/cbor/lib/tinycbor/src/cborparser_dup_string.c
78-
../../src/cbor/lib/tinycbor/src/cborpretty.c
79-
../../src/cbor/lib/tinycbor/src/cborpretty_stdio.c
80-
../../src/cbor/lib/tinycbor/src/cbortojson.c
81-
../../src/cbor/lib/tinycbor/src/cborvalidation.c
82-
../../src/cbor/lib/tinycbor/src/open_memstream.c
96+
../../src/cbor/IoTCloudMessageDecoder.cpp
97+
../../src/cbor/IoTCloudMessageEncoder.cpp
98+
99+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborencoder.c
100+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborencoder_close_container_checked.c
101+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborerrorstrings.c
102+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborparser.c
103+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborparser_dup_string.c
104+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborpretty.c
105+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborpretty_stdio.c
106+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cbortojson.c
107+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborvalidation.c
108+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/open_memstream.c
109+
${cloudutils_SOURCE_DIR}/src/cbor/MessageDecoder.cpp
110+
${cloudutils_SOURCE_DIR}/src/cbor/MessageEncoder.cpp
83111
)
84-
85112
##########################################################################
86113

87114
set(TEST_TARGET_SRCS
@@ -108,6 +135,7 @@ add_executable(
108135
${TEST_TARGET_SRCS}
109136
)
110137

138+
target_link_libraries( ${TEST_TARGET} cloudutils)
111139
target_link_libraries( ${TEST_TARGET} Catch2WithMain )
112140

113141
##########################################################################

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

+41-40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <memory>
1313

1414
#include <util/CBORTestUtil.h>
15+
#include <IoTCloudMessageEncoder.h>
1516
#include <MessageDecoder.h>
1617

1718
/******************************************************************************
@@ -39,11 +40,11 @@ SCENARIO("Test the decoding of command messages") {
3940

4041
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
4142
CBORMessageDecoder decoder;
42-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
43+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
4344
const char *thingIdToMatch = "e4494d55-872a-4fd2-9646-92f87949394c";
4445

4546
THEN("The decode is successful") {
46-
REQUIRE(err == Decoder::Status::Complete);
47+
REQUIRE(err == MessageDecoder::Status::Complete);
4748
REQUIRE(strcmp(command.thingUpdateCmd.params.thing_id, thingIdToMatch) == 0);
4849
REQUIRE(command.c.id == ThingUpdateCmdId);
4950
}
@@ -68,11 +69,11 @@ SCENARIO("Test the decoding of command messages") {
6869

6970
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
7071
CBORMessageDecoder decoder;
71-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
72+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
7273
const char *thingIdToMatch = "e4494d55-872a-4fd2-9646-92f87949394c";
7374

7475
THEN("The decode is successful") {
75-
REQUIRE(err == Decoder::Status::Complete);
76+
REQUIRE(err == MessageDecoder::Status::Complete);
7677
REQUIRE(strcmp(command.thingDetachCmd.params.thing_id, thingIdToMatch) == 0);
7778
REQUIRE(command.c.id == ThingDetachCmdId);
7879
}
@@ -93,10 +94,10 @@ SCENARIO("Test the decoding of command messages") {
9394

9495
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
9596
CBORMessageDecoder decoder;
96-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
97+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
9798

9899
THEN("The decode is unsuccessful") {
99-
REQUIRE(err == Decoder::Status::Error);
100+
REQUIRE(err == MessageDecoder::Status::Error);
100101
}
101102
}
102103

@@ -114,10 +115,10 @@ SCENARIO("Test the decoding of command messages") {
114115

115116
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
116117
CBORMessageDecoder decoder;
117-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
118+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
118119

119120
THEN("The decode is successful") {
120-
REQUIRE(err == Decoder::Status::Error);
121+
REQUIRE(err == MessageDecoder::Status::Error);
121122
}
122123
}
123124

@@ -139,10 +140,10 @@ SCENARIO("Test the decoding of command messages") {
139140

140141
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
141142
CBORMessageDecoder decoder;
142-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
143+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
143144

144145
THEN("The decode is successful") {
145-
REQUIRE(err == Decoder::Status::Complete);
146+
REQUIRE(err == MessageDecoder::Status::Complete);
146147
REQUIRE(command.timezoneCommandDown.params.offset == (uint32_t)1708963873);
147148
REQUIRE(command.timezoneCommandDown.params.until == (uint32_t)2024579473);
148149
REQUIRE(command.c.id == TimezoneCommandDownId);
@@ -169,10 +170,10 @@ SCENARIO("Test the decoding of command messages") {
169170

170171
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
171172
CBORMessageDecoder decoder;
172-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
173+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
173174

174175
THEN("The decode is successful") {
175-
REQUIRE(err == Decoder::Status::Complete);
176+
REQUIRE(err == MessageDecoder::Status::Complete);
176177
REQUIRE(command.lastValuesUpdateCmd.params.length == 13);
177178
REQUIRE(command.lastValuesUpdateCmd.params.last_values[0] == (uint8_t)0x00);
178179
REQUIRE(command.lastValuesUpdateCmd.params.last_values[1] == (uint8_t)0x01);
@@ -249,14 +250,14 @@ SCENARIO("Test the decoding of command messages") {
249250

250251
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
251252
CBORMessageDecoder decoder;
252-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
253+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
253254

254255
uint8_t otaIdToMatch[ID_SIZE] = { 0xC7, 0x3C, 0xB0, 0x45, 0xF9, 0xC2, 0x43, 0x45,
255256
0x85, 0xAF, 0xFA, 0x36, 0xA3, 0x07, 0xBF, 0xE7};
256257
const char *urlToMatch = "https://boards-int.oniudra.cc/storage/firmware/v1/df1eac9c7bd63473fffb117f9873703e4ec955931e267f26262b0949bc16dc49";
257258

258259
THEN("The decode is successful") {
259-
REQUIRE(err == Decoder::Status::Complete);
260+
REQUIRE(err == MessageDecoder::Status::Complete);
260261
REQUIRE(memcmp(command.otaUpdateCmdDown.params.id, otaIdToMatch, ID_SIZE) == 0);
261262
REQUIRE(strcmp(command.otaUpdateCmdDown.params.url, urlToMatch) == 0);
262263
// Initial SHA256 check
@@ -388,10 +389,10 @@ SCENARIO("Test the decoding of command messages") {
388389

389390
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
390391
CBORMessageDecoder decoder;
391-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
392+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
392393

393394
THEN("The decode is successful") {
394-
REQUIRE(err == Decoder::Status::Error);
395+
REQUIRE(err == MessageDecoder::Status::Error);
395396
}
396397
}
397398

@@ -452,10 +453,10 @@ SCENARIO("Test the decoding of command messages") {
452453

453454
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
454455
CBORMessageDecoder decoder;
455-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
456+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
456457

457458
THEN("The decode is successful") {
458-
REQUIRE(err == Decoder::Status::Error);
459+
REQUIRE(err == MessageDecoder::Status::Error);
459460
}
460461
}
461462

@@ -511,10 +512,10 @@ SCENARIO("Test the decoding of command messages") {
511512

512513
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
513514
CBORMessageDecoder decoder;
514-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
515+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
515516

516517
THEN("The decode is successful") {
517-
REQUIRE(err == Decoder::Status::Error);
518+
REQUIRE(err == MessageDecoder::Status::Error);
518519
}
519520
}
520521

@@ -570,10 +571,10 @@ SCENARIO("Test the decoding of command messages") {
570571

571572
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
572573
CBORMessageDecoder decoder;
573-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
574+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
574575

575576
THEN("The decode is successful") {
576-
REQUIRE(err == Decoder::Status::Error);
577+
REQUIRE(err == MessageDecoder::Status::Error);
577578
}
578579
}
579580

@@ -596,10 +597,10 @@ SCENARIO("Test the decoding of command messages") {
596597

597598
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
598599
CBORMessageDecoder decoder;
599-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
600+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
600601

601602
THEN("The decode is unsuccessful - OtaBeginUp is not supported") {
602-
REQUIRE(err == Decoder::Status::Error);
603+
REQUIRE(err == MessageDecoder::Status::Error);
603604
}
604605
}
605606

@@ -619,10 +620,10 @@ SCENARIO("Test the decoding of command messages") {
619620

620621
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
621622
CBORMessageDecoder decoder;
622-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
623+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
623624

624625
THEN("The decode is unsuccessful - ThingBeginCmd is not supported") {
625-
REQUIRE(err == Decoder::Status::Error);
626+
REQUIRE(err == MessageDecoder::Status::Error);
626627
}
627628
}
628629

@@ -639,10 +640,10 @@ SCENARIO("Test the decoding of command messages") {
639640

640641
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
641642
CBORMessageDecoder decoder;
642-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
643+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
643644

644645
THEN("The decode is unsuccessful - LastValuesBeginCmd is not supported") {
645-
REQUIRE(err == Decoder::Status::Error);
646+
REQUIRE(err == MessageDecoder::Status::Error);
646647
}
647648
}
648649

@@ -662,10 +663,10 @@ SCENARIO("Test the decoding of command messages") {
662663

663664
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
664665
CBORMessageDecoder decoder;
665-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
666+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
666667

667668
THEN("The decode is unsuccessful - DeviceBeginCmd is not supported") {
668-
REQUIRE(err == Decoder::Status::Error);
669+
REQUIRE(err == MessageDecoder::Status::Error);
669670
}
670671
}
671672

@@ -690,10 +691,10 @@ SCENARIO("Test the decoding of command messages") {
690691

691692
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
692693
CBORMessageDecoder decoder;
693-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
694+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
694695

695696
THEN("The decode is unsuccessful - OtaProgressCmdUp is not supported") {
696-
REQUIRE(err == Decoder::Status::Error);
697+
REQUIRE(err == MessageDecoder::Status::Error);
697698
}
698699
}
699700

@@ -710,10 +711,10 @@ SCENARIO("Test the decoding of command messages") {
710711

711712
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
712713
CBORMessageDecoder decoder;
713-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
714+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
714715

715716
THEN("The decode is unsuccessful - TimezoneCommandUp is not supported") {
716-
REQUIRE(err == Decoder::Status::Error);
717+
REQUIRE(err == MessageDecoder::Status::Error);
717718
}
718719
}
719720

@@ -735,10 +736,10 @@ SCENARIO("Test the decoding of command messages") {
735736

736737
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
737738
CBORMessageDecoder decoder;
738-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
739+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
739740

740741
THEN("The decode is unsuccessful") {
741-
REQUIRE(err == Decoder::Status::Error);
742+
REQUIRE(err == MessageDecoder::Status::Error);
742743
}
743744
}
744745

@@ -759,10 +760,10 @@ SCENARIO("Test the decoding of command messages") {
759760

760761
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
761762
CBORMessageDecoder decoder;
762-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
763+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
763764

764765
THEN("The decode is unsuccessful") {
765-
REQUIRE(err == Decoder::Status::Error);
766+
REQUIRE(err == MessageDecoder::Status::Error);
766767
}
767768
}
768769

@@ -776,10 +777,10 @@ SCENARIO("Test the decoding of command messages") {
776777

777778
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
778779
CBORMessageDecoder decoder;
779-
Decoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
780+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
780781

781782
THEN("The decode is unsuccessful") {
782-
REQUIRE(err == Decoder::Status::Error);
783+
REQUIRE(err == MessageDecoder::Status::Error);
783784
}
784785
}
785786

0 commit comments

Comments
 (0)