Skip to content

Commit a1ea0fe

Browse files
Unit testing adding missing test cases for failing decode
1 parent b1e09a5 commit a1ea0fe

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

extras/test/src/test_command_decode.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,55 @@ SCENARIO("Test the decoding of command messages") {
152152
}
153153
}
154154

155+
WHEN("Decode the TimezoneCommandDown message, but until is not present")
156+
{
157+
CommandDown command;
158+
159+
/*
160+
DA 00010764 # tag(67840)
161+
81 # array(1)
162+
1A 65DCB821 # unsigned(1708963873)
163+
*/
164+
165+
uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x09, 0x00, 0x81, 0x1A, 0x65,
166+
0xDC, 0xB8, 0x21};
167+
168+
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
169+
CBORMessageDecoder decoder;
170+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
171+
172+
THEN("The decode is unsuccessful") {
173+
REQUIRE(err == MessageDecoder::Status::Error);
174+
}
175+
}
176+
177+
WHEN("Decode the TimezoneCommandDown message, but until is a byte array instead of an integer")
178+
{
179+
CommandDown command;
180+
181+
/*
182+
DA 00010764 # tag(67840)
183+
82 # array(2)
184+
1A 65DCB821 # unsigned(1708963873)
185+
4D # bytes(13)
186+
00010203040506070809101112 # "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\u0010\u0011\u0012"
187+
*/
188+
189+
uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x09, 0x00, 0x82, 0x1A, 0x65,
190+
0xDC, 0xB8, 0x21, 0x4D, 0x00, 0x01, 0x02, 0x03,
191+
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11,
192+
0x12};
193+
194+
size_t payload_length = sizeof(payload) / sizeof(uint8_t);
195+
CBORMessageDecoder decoder;
196+
MessageDecoder::Status err = decoder.decode((Message*)&command, payload, payload_length);
197+
198+
THEN("The decode is unsuccessful") {
199+
REQUIRE(err == MessageDecoder::Status::Error);
200+
}
201+
}
202+
203+
155204
/****************************************************************************/
156205

157206
WHEN("Decode the LastValuesUpdateCmd message")

0 commit comments

Comments
 (0)