|
22 | 22 | #include "zwapi_func_ids.h"
|
23 | 23 | #include "zwapi_session_mock.h"
|
24 | 24 | #include "zwapi_protocol_basis_mock.h"
|
| 25 | +#include "zwapi_internal.h" |
25 | 26 |
|
26 | 27 | // Static variables
|
27 | 28 | static uint8_t response_length = 0;
|
28 | 29 | static uint8_t response_buffer[255] = {0};
|
29 | 30 |
|
| 31 | +// Unmocked stubs functions: |
| 32 | + |
| 33 | +uint8_t* zwapi_get_zw_library_version_stub(uint8_t* dst, int cmock_num_calls) |
| 34 | +{ |
| 35 | + return 0; //defaut, not valid |
| 36 | +} |
| 37 | + |
| 38 | +zwave_rf_region_t zwapi_get_rf_region_stub(int cmock_num_calls) |
| 39 | +{ |
| 40 | + return 0; // default |
| 41 | +} |
| 42 | + |
| 43 | + |
30 | 44 | /// Setup the test suite (called once before all test_xxx functions are called)
|
31 | 45 | void suiteSetUp() {}
|
32 | 46 |
|
@@ -233,6 +247,111 @@ void test_zwapi_init()
|
233 | 247 | TEST_ASSERT_EQUAL(3, serial_fd);
|
234 | 248 | }
|
235 | 249 |
|
| 250 | +void test_zwapi_refresh_capabilities_bitmask(void) |
| 251 | +{ |
| 252 | + zwapi_chip_data_t chip; |
| 253 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 254 | + uint8_t response_length = IDX_DATA + 7 + sizeof(chip.supported_bitmask); |
| 255 | + memset(response_buffer, 0xAA, sizeof(response_buffer)); // Fill with dummy data |
| 256 | + |
| 257 | + // Simulate a valid response with sufficient length for supported_bitmask |
| 258 | + zwapi_session_send_frame_with_response_ExpectAndReturn( |
| 259 | + FUNC_ID_SERIAL_API_GET_CAPABILITIES, |
| 260 | + NULL, |
| 261 | + 0, |
| 262 | + NULL, |
| 263 | + NULL, |
| 264 | + SL_STATUS_OK); |
| 265 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 266 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 267 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 268 | + response_buffer, |
| 269 | + response_length); |
| 270 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 271 | + &response_length); |
| 272 | + |
| 273 | + zwapi_get_zw_library_version_Stub(zwapi_get_zw_library_version_stub); |
| 274 | + |
| 275 | + zwapi_session_flush_queue_Expect(); |
| 276 | + |
| 277 | + { |
| 278 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 279 | + uint8_t response_length = IDX_DATA + 1; |
| 280 | + |
| 281 | + zwapi_session_send_frame_with_response_ExpectAndReturn(FUNC_ID_SERIAL_API_GET_INIT_DATA, |
| 282 | + NULL, |
| 283 | + 0, |
| 284 | + NULL, |
| 285 | + NULL, |
| 286 | + SL_STATUS_OK); |
| 287 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 288 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 289 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 290 | + response_buffer, |
| 291 | + response_length); |
| 292 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 293 | + &response_length); |
| 294 | + } |
| 295 | + |
| 296 | + zwapi_get_rf_region_Stub(zwapi_get_rf_region_stub); |
| 297 | + //TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_session_flush_queue()); |
| 298 | + TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_refresh_capabilities()); |
| 299 | + // TEST_ASSERT_EQUAL_UINT8_ARRAY(response_buffer + IDX_DATA + 7, chip.supported_bitmask, sizeof(chip.supported_bitmask)); |
| 300 | +} |
| 301 | + |
| 302 | +void test_zwapi_refresh_capabilities_bitmask_injection(void) |
| 303 | +{ |
| 304 | + zwapi_chip_data_t chip; |
| 305 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 306 | + uint8_t response_length = FRAME_LENGTH_MAX; |
| 307 | + memset(response_buffer, 0xAA, sizeof(response_buffer)); // Fill with dummy data |
| 308 | + |
| 309 | + // Simulate a valid response with sufficient length for supported_bitmask |
| 310 | + zwapi_session_send_frame_with_response_ExpectAndReturn( |
| 311 | + FUNC_ID_SERIAL_API_GET_CAPABILITIES, |
| 312 | + NULL, |
| 313 | + 0, |
| 314 | + NULL, |
| 315 | + NULL, |
| 316 | + SL_STATUS_OK); |
| 317 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 318 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 319 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 320 | + response_buffer, |
| 321 | + response_length); |
| 322 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 323 | + &response_length); |
| 324 | + |
| 325 | + zwapi_get_zw_library_version_Stub(zwapi_get_zw_library_version_stub); |
| 326 | + if (false) { |
| 327 | + zwapi_session_flush_queue_Expect(); |
| 328 | + // TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_session_flush_queue()); |
| 329 | + |
| 330 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 331 | + uint8_t response_length = IDX_DATA + 1; |
| 332 | + |
| 333 | + zwapi_session_send_frame_with_response_ExpectAndReturn(FUNC_ID_SERIAL_API_GET_INIT_DATA, |
| 334 | + NULL, |
| 335 | + 0, |
| 336 | + NULL, |
| 337 | + NULL, |
| 338 | + SL_STATUS_OK); |
| 339 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 340 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 341 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 342 | + response_buffer, |
| 343 | + response_length); |
| 344 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 345 | + &response_length); |
| 346 | + } |
| 347 | + |
| 348 | + zwapi_get_rf_region_Stub(zwapi_get_rf_region_stub); |
| 349 | + // |
| 350 | + TEST_ASSERT_EQUAL(SL_STATUS_FAIL, zwapi_refresh_capabilities()); |
| 351 | + // TEST_ASSERT_EQUAL_UINT8_ARRAY(response_buffer + IDX_DATA + 7, chip.supported_bitmask, sizeof(chip.supported_bitmask)); |
| 352 | +} |
| 353 | + |
| 354 | + |
236 | 355 | void test_zwapi_refresh_capabilities_bad_cases()
|
237 | 356 | {
|
238 | 357 | //Capablities status fail
|
@@ -360,4 +479,5 @@ void test_zwapi_log_to_file_enable(void)
|
360 | 479 | void test_zwapi_log_to_file_disable(void)
|
361 | 480 | {
|
362 | 481 | TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_log_to_file_disable());
|
| 482 | + |
363 | 483 | }
|
0 commit comments