@@ -174,6 +174,53 @@ SCENARIO("Test the decoding of command messages") {
174174 }
175175 }
176176
177+ WHEN (" Decode the TimezoneCommandDown message, but offset is incorrectly encoded" )
178+ {
179+ CommandDown command;
180+
181+ /*
182+ DA 00010764 # tag(67840)
183+ 81 # array(1)
184+ 1A 65DC # unsigned(26076)
185+ */
186+
187+ uint8_t const payload[] = {0xDA , 0x00 , 0x01 , 0x09 , 0x00 , 0x81 , 0x1A ,};
188+
189+ size_t payload_length = sizeof (payload) / sizeof (uint8_t );
190+ CBORMessageDecoder decoder;
191+ MessageDecoder::Status err = decoder.decode ((Message*)&command, payload, payload_length);
192+
193+ THEN (" The decode is unsuccessful" ) {
194+ REQUIRE (err == MessageDecoder::Status::Error);
195+ }
196+ }
197+
198+ WHEN (" Decode the TimezoneCommandDown message, but offset is a byte array instead of an integer" )
199+ {
200+ CommandDown command;
201+
202+ /*
203+ DA 00010764 # tag(67840)
204+ 81 # array(2)
205+ 4D # bytes(13)
206+ 00010203040506070809101112 # "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\u0010\u0011\u0012"
207+ 1A 65DCB821 # unsigned(1708963873)
208+ */
209+
210+ uint8_t const payload[] = {0xDA , 0x00 , 0x01 , 0x09 , 0x00 , 0x81 , 0x21 , 0x4D ,
211+ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
212+ 0x08 , 0x09 , 0x10 , 0x11 , 0x12 , 0x1A , 0x65 , 0xDC ,
213+ 0xB8 ,};
214+
215+ size_t payload_length = sizeof (payload) / sizeof (uint8_t );
216+ CBORMessageDecoder decoder;
217+ MessageDecoder::Status err = decoder.decode ((Message*)&command, payload, payload_length);
218+
219+ THEN (" The decode is unsuccessful" ) {
220+ REQUIRE (err == MessageDecoder::Status::Error);
221+ }
222+ }
223+
177224 WHEN (" Decode the TimezoneCommandDown message, but until is a byte array instead of an integer" )
178225 {
179226 CommandDown command;
@@ -200,6 +247,28 @@ SCENARIO("Test the decoding of command messages") {
200247 }
201248 }
202249
250+ WHEN (" Decode the TimezoneCommandDown message, but until is incorrectly encoded" )
251+ {
252+ CommandDown command;
253+
254+ /*
255+ DA 00010764 # tag(67840)
256+ 82 # array(2)
257+ 1A 65DCB821 # unsigned(1708963873)
258+ 1A 78AC # unsigned(30892)
259+ */
260+
261+ uint8_t const payload[] = {0xDA , 0x00 , 0x01 , 0x09 , 0x00 , 0x82 , 0x1A , 0x65 ,
262+ 0xDC , 0xB8 , 0x21 , 0x1A , 0x78 , 0xAC };
263+
264+ size_t payload_length = sizeof (payload) / sizeof (uint8_t );
265+ CBORMessageDecoder decoder;
266+ MessageDecoder::Status err = decoder.decode ((Message*)&command, payload, payload_length);
267+
268+ THEN (" The decode is unsuccessful" ) {
269+ REQUIRE (err == MessageDecoder::Status::Error);
270+ }
271+ }
203272
204273 /* ***************************************************************************/
205274
0 commit comments