Skip to content

Commit 31cb0ba

Browse files
committed
fix(cc/nif): Add testing for unpacking extended cc
Origin: SiliconLabsSoftware#125 Bug-SiliconLabs: UIC-3664 Relate-to: SLVDBBP-3162484 Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#42 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 73a2e18 commit 31cb0ba

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

applications/zpc/components/zwave/zwave_controller/test/zwave_controller_utils_test.c

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "zwave_tx_mock.h"
2323

2424
// Generic includes
25+
#include <assert.h>
2526
#include <stdbool.h>
2627

2728
// Test constant
@@ -185,4 +186,100 @@ void test_send_nop_to_node()
185186
test_discard_timeout_ms,
186187
test_callback,
187188
test_user));
188-
}
189+
}
190+
191+
void test_zwave_command_class_list_pack_empty()
192+
{
193+
zwave_node_info_t node_info = {.listening_protocol = 2,
194+
.optional_protocol = 3,
195+
.basic_device_class = 4,
196+
.generic_device_class = 5,
197+
.specific_device_class = 6,
198+
.command_class_list_length = 0,
199+
.command_class_list = {0}};
200+
201+
uint8_t nif[ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH * 2] = {0};
202+
uint8_t nif_length = 0;
203+
204+
zwave_command_class_list_pack(&node_info, nif, &nif_length);
205+
TEST_ASSERT_EQUAL(0, nif_length);
206+
zwave_command_class_list_unpack(&node_info, nif, nif_length);
207+
TEST_ASSERT_EQUAL(0, node_info.command_class_list_length);
208+
}
209+
210+
void test_zwave_command_class_list_pack()
211+
{
212+
zwave_node_info_t node_info = {.listening_protocol = 2,
213+
.optional_protocol = 3,
214+
.basic_device_class = 4,
215+
.generic_device_class = 5,
216+
.specific_device_class = 6,
217+
.command_class_list_length = 3,
218+
.command_class_list = {0x01, 0xF0, 0xFF}};
219+
220+
uint8_t nif[ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH] = {0};
221+
uint8_t nif_length = 0;
222+
223+
zwave_command_class_list_pack(&node_info, nif, &nif_length);
224+
225+
TEST_ASSERT_EQUAL(node_info.command_class_list_length, nif_length);
226+
TEST_ASSERT_EQUAL(node_info.command_class_list[0], nif[0]);
227+
TEST_ASSERT_EQUAL(node_info.command_class_list[1], nif[1]);
228+
TEST_ASSERT_EQUAL(node_info.command_class_list[2], nif[2]);
229+
}
230+
231+
void test_zwave_command_class_list_pack_extended()
232+
{
233+
zwave_node_info_t node_info = {
234+
.listening_protocol = 2,
235+
.optional_protocol = 3,
236+
.basic_device_class = 4,
237+
.generic_device_class = 5,
238+
.specific_device_class = 6,
239+
.command_class_list_length = 3 + 3,
240+
.command_class_list = {0x20, 0xEF, 0xF0, 0xF100, 0xF101, 0xFFFF}
241+
};
242+
243+
uint8_t nif[ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH * 2] = {0};
244+
uint8_t nif_length = 0;
245+
246+
zwave_command_class_list_pack(&node_info, nif, &nif_length);
247+
248+
TEST_ASSERT_EQUAL(3 + 3 * 2, nif_length);
249+
250+
TEST_ASSERT_EQUAL(node_info.command_class_list[0], nif[0]);
251+
TEST_ASSERT_EQUAL(node_info.command_class_list[1], nif[1]);
252+
TEST_ASSERT_EQUAL(node_info.command_class_list[2], nif[2]);
253+
TEST_ASSERT_EQUAL(node_info.command_class_list[3], (nif[3] << 8) | nif[4]);
254+
TEST_ASSERT_EQUAL(node_info.command_class_list[4], (nif[5] << 8) | nif[6]);
255+
TEST_ASSERT_EQUAL(node_info.command_class_list[5], (nif[7] << 8) | nif[8]);
256+
zwave_command_class_list_unpack(&node_info, nif, nif_length);
257+
TEST_ASSERT_EQUAL(3 + 3, node_info.command_class_list_length);
258+
}
259+
260+
void test_zwave_command_class_list_pack_extended_full()
261+
{
262+
zwave_node_info_t node_info = {
263+
.listening_protocol = 2,
264+
.optional_protocol = 3,
265+
.basic_device_class = 4,
266+
.generic_device_class = 5,
267+
.specific_device_class = 6,
268+
.command_class_list_length
269+
= ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH,
270+
};
271+
272+
for (int i = 0; i < ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH; i++) {
273+
node_info.command_class_list[i] = 0xFFFF;
274+
}
275+
uint8_t nif[ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH * 2] = {0};
276+
uint8_t nif_length = 0;
277+
278+
zwave_command_class_list_pack(&node_info, nif, &nif_length);
279+
TEST_ASSERT_EQUAL(ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH * 2,
280+
nif_length);
281+
282+
zwave_command_class_list_unpack(&node_info, nif, nif_length);
283+
TEST_ASSERT_EQUAL(ZWAVE_CONTROLLER_MAXIMUM_COMMAND_CLASS_LIST_LENGTH,
284+
node_info.command_class_list_length);
285+
}

applications/zpc/components/zwave_command_classes/test/zwave_command_class_node_info_resolver_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,4 @@ void test_on_secure_nif_resolution_aborted()
551551
TEST_ASSERT_EQUAL_UINT8_ARRAY(command_class_list_expected_u8,
552552
command_class_list_result_u8,
553553
secure_nif_length_expected);
554-
}
554+
}

0 commit comments

Comments
 (0)