|
7 | 7 | ******************************************************************************/
|
8 | 8 |
|
9 | 9 | #include <catch2/catch_test_macros.hpp>
|
| 10 | +#include <catch2/matchers/catch_matchers_vector.hpp> |
| 11 | + |
10 | 12 | #include <string.h>
|
11 | 13 |
|
12 | 14 | #include <memory>
|
@@ -174,20 +176,15 @@ SCENARIO("Test the decoding of command messages") {
|
174 | 176 |
|
175 | 177 | THEN("The decode is successful") {
|
176 | 178 | REQUIRE(err == MessageDecoder::Status::Complete);
|
177 |
| - REQUIRE(command.lastValuesUpdateCmd.params.length == 13); |
178 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[0] == (uint8_t)0x00); |
179 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[1] == (uint8_t)0x01); |
180 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[2] == (uint8_t)0x02); |
181 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[3] == (uint8_t)0x03); |
182 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[4] == (uint8_t)0x04); |
183 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[5] == (uint8_t)0x05); |
184 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[6] == (uint8_t)0x06); |
185 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[7] == (uint8_t)0x07); |
186 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[8] == (uint8_t)0x08); |
187 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[9] == (uint8_t)0x09); |
188 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[10] == (uint8_t)0x10); |
189 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[11] == (uint8_t)0x11); |
190 |
| - REQUIRE(command.lastValuesUpdateCmd.params.last_values[12] == (uint8_t)0x12); |
| 179 | + |
| 180 | + std::vector<int> last_values(command.lastValuesUpdateCmd.params.last_values, |
| 181 | + command.lastValuesUpdateCmd.params.last_values+13); |
| 182 | + |
| 183 | + REQUIRE_THAT(last_values, |
| 184 | + Catch::Matchers::Equals(std::vector<int>{ |
| 185 | + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, |
| 186 | + })); |
| 187 | + |
191 | 188 | REQUIRE(command.c.id == LastValuesUpdateCmdId);
|
192 | 189 | }
|
193 | 190 | free(command.lastValuesUpdateCmd.params.last_values);
|
@@ -260,73 +257,24 @@ SCENARIO("Test the decoding of command messages") {
|
260 | 257 | REQUIRE(err == MessageDecoder::Status::Complete);
|
261 | 258 | REQUIRE(memcmp(command.otaUpdateCmdDown.params.id, otaIdToMatch, ID_SIZE) == 0);
|
262 | 259 | REQUIRE(strcmp(command.otaUpdateCmdDown.params.url, urlToMatch) == 0);
|
263 |
| - // Initial SHA256 check |
264 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[0] == (uint8_t)0x00); |
265 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[1] == (uint8_t)0x00); |
266 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[2] == (uint8_t)0x00); |
267 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[3] == (uint8_t)0x00); |
268 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[4] == (uint8_t)0x00); |
269 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[5] == (uint8_t)0x00); |
270 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[6] == (uint8_t)0x00); |
271 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[7] == (uint8_t)0x00); |
272 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[8] == (uint8_t)0x00); |
273 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[9] == (uint8_t)0x00); |
274 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[10] == (uint8_t)0x00); |
275 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[11] == (uint8_t)0x00); |
276 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[12] == (uint8_t)0x00); |
277 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[13] == (uint8_t)0x00); |
278 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[14] == (uint8_t)0x00); |
279 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[15] == (uint8_t)0x00); |
280 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[16] == (uint8_t)0x00); |
281 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[17] == (uint8_t)0x00); |
282 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[18] == (uint8_t)0x00); |
283 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[19] == (uint8_t)0x00); |
284 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[20] == (uint8_t)0x00); |
285 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[21] == (uint8_t)0x00); |
286 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[22] == (uint8_t)0x00); |
287 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[23] == (uint8_t)0x00); |
288 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[24] == (uint8_t)0x00); |
289 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[25] == (uint8_t)0x00); |
290 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[26] == (uint8_t)0x00); |
291 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[27] == (uint8_t)0x00); |
292 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[28] == (uint8_t)0x00); |
293 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[29] == (uint8_t)0x00); |
294 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[30] == (uint8_t)0x00); |
295 |
| - REQUIRE(command.otaUpdateCmdDown.params.initialSha256[31] == (uint8_t)0x00); |
296 |
| - |
297 |
| - // Final SHA256 check |
298 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[0] == (uint8_t)0xdf); |
299 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[1] == (uint8_t)0x1e); |
300 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[2] == (uint8_t)0xac); |
301 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[3] == (uint8_t)0x9c); |
302 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[4] == (uint8_t)0x7b); |
303 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[5] == (uint8_t)0xd6); |
304 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[6] == (uint8_t)0x34); |
305 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[7] == (uint8_t)0x73); |
306 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[8] == (uint8_t)0xff); |
307 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[9] == (uint8_t)0xfb); |
308 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[10] == (uint8_t)0x11); |
309 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[11] == (uint8_t)0x7f); |
310 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[12] == (uint8_t)0x98); |
311 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[13] == (uint8_t)0x73); |
312 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[14] == (uint8_t)0x70); |
313 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[15] == (uint8_t)0x3e); |
314 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[16] == (uint8_t)0x4e); |
315 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[17] == (uint8_t)0xc9); |
316 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[18] == (uint8_t)0x55); |
317 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[19] == (uint8_t)0x93); |
318 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[20] == (uint8_t)0x1e); |
319 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[21] == (uint8_t)0x26); |
320 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[22] == (uint8_t)0x7f); |
321 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[23] == (uint8_t)0x26); |
322 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[24] == (uint8_t)0x26); |
323 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[25] == (uint8_t)0x2b); |
324 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[26] == (uint8_t)0x09); |
325 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[27] == (uint8_t)0x49); |
326 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[28] == (uint8_t)0xbc); |
327 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[29] == (uint8_t)0x16); |
328 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[30] == (uint8_t)0xdc); |
329 |
| - REQUIRE(command.otaUpdateCmdDown.params.finalSha256[31] == (uint8_t)0x49); |
| 260 | + |
| 261 | + std::vector<int> initialSha256(command.otaUpdateCmdDown.params.initialSha256, |
| 262 | + command.otaUpdateCmdDown.params.initialSha256+32); |
| 263 | + |
| 264 | + REQUIRE_THAT(initialSha256, |
| 265 | + Catch::Matchers::Equals(std::vector<int>{ |
| 266 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 267 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 268 | + })); |
| 269 | + |
| 270 | + std::vector<int> finalSha256(command.otaUpdateCmdDown.params.finalSha256, |
| 271 | + command.otaUpdateCmdDown.params.finalSha256+32); |
| 272 | + |
| 273 | + REQUIRE_THAT(finalSha256, |
| 274 | + Catch::Matchers::Equals(std::vector<int>{ |
| 275 | + 0xdf, 0x1e, 0xac, 0x9c, 0x7b, 0xd6, 0x34, 0x73, 0xff, 0xfb, 0x11, 0x7f, 0x98, 0x73, 0x70, 0x3e, |
| 276 | + 0x4e, 0xc9, 0x55, 0x93, 0x1e, 0x26, 0x7f, 0x26, 0x26, 0x2b, 0x09, 0x49, 0xbc, 0x16, 0xdc, 0x49 |
| 277 | + })); |
330 | 278 |
|
331 | 279 | REQUIRE(command.c.id == OtaUpdateCmdDownId);
|
332 | 280 | }
|
|
0 commit comments