Skip to content

Commit d214e0a

Browse files
committed
Added test
1 parent 6a5c420 commit d214e0a

File tree

3 files changed

+81
-14
lines changed

3 files changed

+81
-14
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}

src/ArduinoIoTCloudTCP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void ArduinoIoTCloudTCP::decode(){
309309

310310
DEBUG_INFO("Message THING id is %d", message->command);
311311

312-
GetThingIdCommand * thingCommand = (GetThingIdCommand*) message;
312+
ThingGetIdCmdDown * thingCommand = (ThingGetIdCmdDown*) message;
313313
DEBUG_INFO("Thing id is %s", thingCommand->fields.params.thing_id);
314314

315315
delete message;

src/models/models.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ struct GenericCommand {
3434
uint8_t content[MAX_PAYLOAD_SIZE];
3535
};
3636

37-
struct ThingIdCommand {
38-
Command command;
39-
};
40-
41-
union GetThingIdCommand {
42-
struct {
43-
ThingIdCommand thingIdCommand;
44-
struct {
45-
char thing_id[THING_ID_SIZE];
46-
} params;
47-
} fields;
48-
};
49-
5037
struct ThingGetIdCmdUpCommand {
5138
Command command;
5239
};

0 commit comments

Comments
 (0)