|
| 1 | +/* |
| 2 | + Copyright (c) 2019 Arduino. All rights reserved. |
| 3 | +*/ |
| 4 | + |
| 5 | +/************************************************************************************** |
| 6 | + INCLUDE |
| 7 | + **************************************************************************************/ |
| 8 | + |
| 9 | +#include <catch.hpp> |
| 10 | + |
| 11 | +#include <memory> |
| 12 | + |
| 13 | +#include <util/CBORTestUtil.h> |
| 14 | +#include <MessageDecoder.h> |
| 15 | + |
| 16 | +/************************************************************************************** |
| 17 | + TEST CODE |
| 18 | + **************************************************************************************/ |
| 19 | + |
| 20 | +SCENARIO("Test the decoding of command messages") { |
| 21 | + /************************************************************************************/ |
| 22 | + |
| 23 | + WHEN("Decode the ThingGetIdCmdDown message") |
| 24 | + { |
| 25 | + ThingGetIdCmdDown * message = new ThingGetIdCmdDown(); |
| 26 | + |
| 27 | + /* |
| 28 | + |
| 29 | + DA 00010300 # tag(66304) |
| 30 | + 81 # array(1) |
| 31 | + 78 24 # text(36) |
| 32 | + 65343439346435352D383732612D346664322D393634362D393266383739343933393463 # "e4494d55-872a-4fd2-9646-92f87949394c" |
| 33 | + |
| 34 | + */ |
| 35 | + |
| 36 | + uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x03, 0x00, 0x81, 0x78, 0x24, 0x65, 0x34, 0x34, 0x39, 0x34, 0x64, 0x35, 0x35, 0x2D, 0x38, 0x37, 0x32, 0x61, 0x2D, 0x34, 0x66, 0x64, 0x32, 0x2D, 0x39, 0x36, 0x34, 0x36, 0x2D, 0x39, 0x32, 0x66, 0x38, 0x37, 0x39, 0x34, 0x39, 0x33, 0x39, 0x34, 0x63}; |
| 37 | + |
| 38 | + int payload_length = sizeof(payload) / sizeof(uint8_t); |
| 39 | + CborError err = MessageDecoder::decode((Message*) message, payload, payload_length); |
| 40 | + |
| 41 | + THEN("The decode is successful") { |
| 42 | + REQUIRE(err == CborNoError); |
| 43 | + REQUIRE(message->fields.params.thing_id == "e4494d55-872a-4fd2-9646-92f87949394c"); |
| 44 | + REQUIRE(message->command == 66304); |
| 45 | + } |
| 46 | + |
| 47 | + delete message; |
| 48 | + } |
| 49 | + |
| 50 | + /************************************************************************************/ |
| 51 | + |
| 52 | + WHEN("Decode the SetTimezoneCommand message") |
| 53 | + { |
| 54 | + SetTimezoneCommand * message = new SetTimezoneCommand(); |
| 55 | + |
| 56 | + /* |
| 57 | + |
| 58 | + DA 00010764 # tag(67428) |
| 59 | + 82 # array(2) |
| 60 | + 1A 65DCB821 # unsigned(1708963873) |
| 61 | + 1A 78ACA191 # unsigned(2024579473) |
| 62 | + |
| 63 | + */ |
| 64 | + |
| 65 | + uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x07, 0x64, 0x82, 0x1A, 0x65, 0xDC, 0xB8, 0x21, 0x1A, 0x78, 0xAC, 0xA1, 0x91}; |
| 66 | + |
| 67 | + int payload_length = sizeof(payload) / sizeof(uint8_t); |
| 68 | + CborError err = MessageDecoder::decode((Message*) message, payload, payload_length); |
| 69 | + |
| 70 | + THEN("The decode is successful") { |
| 71 | + REQUIRE(err == CborNoError); |
| 72 | + REQUIRE(message->fields.params.offset == (uint32_t)1708963873); |
| 73 | + REQUIRE(message->fields.params.until == (uint32_t)2024579473); |
| 74 | + REQUIRE(message->command == 67428); |
| 75 | + } |
| 76 | + |
| 77 | + delete message; |
| 78 | + } |
| 79 | + |
| 80 | +} |
0 commit comments