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+ }
0 commit comments