Skip to content

Commit f882f71

Browse files
[TMP] readapting cmake testing by using cloudutils
1 parent d7c6d76 commit f882f71

File tree

5 files changed

+87
-58
lines changed

5 files changed

+87
-58
lines changed

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 1 deletion
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.

.gitmodules

Whitespace-only changes.

extras/test/CMakeLists.txt

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ FetchContent_Declare(
1414
GIT_TAG v3.4.0
1515
)
1616

17+
FetchContent_Declare(
18+
cloudutils
19+
GIT_REPOSITORY https://github.com/andreagilardoni/Arduino_CloudUtils.git
20+
GIT_TAG cbor-messages
21+
CONFIGURE_COMMAND ""
22+
BUILD_COMMAND ""
23+
)
24+
1725
FetchContent_MakeAvailable(Catch2)
1826

27+
FetchContent_GetProperties(cloudutils)
28+
if(NOT cloudutils_POPULATED)
29+
FetchContent_Populate(cloudutils)
30+
endif()
31+
1932
##########################################################################
2033

2134
include_directories(include)
@@ -24,6 +37,24 @@ include_directories(../../src/cbor)
2437
include_directories(../../src/property)
2538
include_directories(../../src/utility/time)
2639

40+
# add_library(cloudutils STATIC IMPORTED GLOBAL)
41+
add_library(cloudutils INTERFACE)
42+
43+
target_include_directories(
44+
cloudutils INTERFACE
45+
${cloudutils_SOURCE_DIR}/src/
46+
)
47+
48+
target_include_directories(
49+
cloudutils INTERFACE
50+
${cloudutils_SOURCE_DIR}/src/cbor
51+
)
52+
53+
target_include_directories(
54+
cloudutils INTERFACE
55+
${cloudutils_SOURCE_DIR}/src/interfaces
56+
)
57+
2758
##########################################################################
2859

2960
set(CMAKE_CXX_STANDARD 11)
@@ -69,19 +100,20 @@ set(TEST_DUT_SRCS
69100
../../src/cbor/CBOREncoder.cpp
70101
../../src/cbor/MessageDecoder.cpp
71102
../../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
83-
)
84103

104+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborencoder.c
105+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborencoder_close_container_checked.c
106+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborerrorstrings.c
107+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborparser.c
108+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborparser_dup_string.c
109+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborpretty.c
110+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborpretty_stdio.c
111+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cbortojson.c
112+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborvalidation.c
113+
${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/open_memstream.c
114+
${cloudutils_SOURCE_DIR}/src/cbor/CborDecoder.cpp
115+
${cloudutils_SOURCE_DIR}/src/cbor/CborEncoder.cpp
116+
)
85117
##########################################################################
86118

87119
set(TEST_TARGET_SRCS
@@ -108,6 +140,7 @@ add_executable(
108140
${TEST_TARGET_SRCS}
109141
)
110142

143+
target_link_libraries( ${TEST_TARGET} cloudutils)
111144
target_link_libraries( ${TEST_TARGET} Catch2WithMain )
112145

113146
##########################################################################

extras/test/src/test_command_decode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <memory>
1313

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

1718
/******************************************************************************

extras/test/src/test_command_encode.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include <memory>
1212

1313
#include <util/CBORTestUtil.h>
14+
#include <CborEncoder.h>
1415
#include <MessageEncoder.h>
16+
#include <catch2/matchers/catch_matchers_vector.hpp>
1517

1618
/******************************************************************************
1719
TEST CODE
@@ -34,23 +36,22 @@ SCENARIO("Test the encoding of command messages") {
3436
CBORMessageEncoder encoder;
3537
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
3638

37-
uint8_t expected_result[] = {
38-
0xda, 0x00, 0x01, 0x00, 0x00, 0x81, 0x58, 0x20,
39-
0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
40-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
43-
};
44-
4539
// Test the encoding is
4640
// DA 00010000 # tag(65536)
4741
// 81 # array(1)
4842
// 58 20 # bytes(32)
4943
// 01020304
5044
THEN("The encoding is successful") {
5145
REQUIRE(err == Encoder::Status::Complete);
52-
REQUIRE(bytes_encoded == sizeof(expected_result));
53-
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
46+
std::vector<int> res(buffer, buffer+bytes_encoded);
47+
48+
REQUIRE_THAT(res, Catch::Matchers::Equals(std::vector<int>{
49+
0xda, 0x00, 0x01, 0x00, 0x00, 0x81, 0x58, 0x20,
50+
0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
51+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
54+
}));
5455
}
5556
}
5657

@@ -71,11 +72,6 @@ SCENARIO("Test the encoding of command messages") {
7172
CBORMessageEncoder encoder;
7273
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
7374

74-
uint8_t expected_result[] = {
75-
0xda, 0x00, 0x01, 0x03, 0x00, 0x81, 0x68, 0x74,
76-
0x68, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64
77-
};
78-
7975
// Test the encoding is
8076
// DA 00010300 # tag(66304)
8177
// 81 # array(1)
@@ -84,8 +80,12 @@ SCENARIO("Test the encoding of command messages") {
8480

8581
THEN("The encoding is successful") {
8682
REQUIRE(err == Encoder::Status::Complete);
87-
REQUIRE(bytes_encoded == sizeof(expected_result));
88-
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
83+
std::vector<int> res(buffer, buffer+bytes_encoded);
84+
85+
REQUIRE_THAT(res, Catch::Matchers::Equals(std::vector<int>{
86+
0xda, 0x00, 0x01, 0x03, 0x00, 0x81, 0x68, 0x74,
87+
0x68, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64
88+
}));
8989
}
9090
}
9191

@@ -102,17 +102,16 @@ SCENARIO("Test the encoding of command messages") {
102102
CBORMessageEncoder encoder;
103103
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
104104

105-
uint8_t expected_result[] = {
106-
0xda, 0x00, 0x01, 0x05, 0x00, 0x80
107-
};
108-
109105
// Test the encoding is
110106
// DA 00010500 # tag(66816)
111107
// 80 # array(0)
112108
THEN("The encoding is successful") {
113109
REQUIRE(err == Encoder::Status::Complete);
114-
REQUIRE(bytes_encoded == sizeof(expected_result));
115-
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
110+
std::vector<int> res(buffer, buffer+bytes_encoded);
111+
112+
REQUIRE_THAT(res, Catch::Matchers::Equals(std::vector<int>{
113+
0xda, 0x00, 0x01, 0x05, 0x00, 0x80
114+
}));
116115
}
117116
}
118117

@@ -132,20 +131,19 @@ SCENARIO("Test the encoding of command messages") {
132131
CBORMessageEncoder encoder;
133132
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
134133

135-
uint8_t expected_result[] = {
136-
0xda, 0x00, 0x01, 0x07, 0x00, 0x81, 0x65, 0x32,
137-
0x2e, 0x30, 0x2e, 0x30
138-
};
139-
140134
// Test the encoding is
141135
// DA 00010700 # tag(67328)
142136
// 81 # array(1)
143137
// 65 # text(5)
144138
// 322E302E30 # "2.0.0"
145139
THEN("The encoding is successful") {
146140
REQUIRE(err == Encoder::Status::Complete);
147-
REQUIRE(bytes_encoded == sizeof(expected_result));
148-
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
141+
std::vector<int> res(buffer, buffer+bytes_encoded);
142+
143+
REQUIRE_THAT(res, Catch::Matchers::Equals(std::vector<int>{
144+
0xda, 0x00, 0x01, 0x07, 0x00, 0x81, 0x65, 0x32,
145+
0x2e, 0x30, 0x2e, 0x30
146+
}));
149147
}
150148
}
151149

@@ -170,13 +168,6 @@ SCENARIO("Test the encoding of command messages") {
170168
CBORMessageEncoder encoder;
171169
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
172170

173-
uint8_t expected_result[] = {
174-
0xda, 0x00, 0x01, 0x02, 0x00, 0x84, 0x50, 0x00,
175-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
176-
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xe1,
177-
0x20, 0x18, 0x64
178-
};
179-
180171
// Test the encoding is
181172
// DA 00010200 # tag(66048)
182173
// 84 # array(4)
@@ -187,8 +178,14 @@ SCENARIO("Test the encoding of command messages") {
187178
// 18 64 # unsigned(100)
188179
THEN("The encoding is successful") {
189180
REQUIRE(err == Encoder::Status::Complete);
190-
REQUIRE(bytes_encoded == sizeof(expected_result));
191-
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
181+
std::vector<int> res(buffer, buffer+bytes_encoded);
182+
183+
REQUIRE_THAT(res, Catch::Matchers::Equals(std::vector<int>{
184+
0xda, 0x00, 0x01, 0x02, 0x00, 0x84, 0x50, 0x00,
185+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
186+
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xe1,
187+
0x20, 0x18, 0x64
188+
}));
192189
}
193190
}
194191

@@ -205,17 +202,16 @@ SCENARIO("Test the encoding of command messages") {
205202
CBORMessageEncoder encoder;
206203
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
207204

208-
uint8_t expected_result[] = {
209-
0xda, 0x00, 0x01, 0x08, 0x00, 0x80
210-
};
211-
212205
// Test the encoding is
213206
// DA 00010800 # tag(67584)
214207
// 80 # array(0)
215208
THEN("The encoding is successful") {
216209
REQUIRE(err == Encoder::Status::Complete);
217-
REQUIRE(bytes_encoded == sizeof(expected_result));
218-
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
210+
std::vector<int> res(buffer, buffer+bytes_encoded);
211+
212+
REQUIRE_THAT(res, Catch::Matchers::Equals(std::vector<int>{
213+
0xda, 0x00, 0x01, 0x08, 0x00, 0x80
214+
}));
219215
}
220216
}
221217

0 commit comments

Comments
 (0)