|
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 | + |
30 | 43 | /// Setup the test suite (called once before all test_xxx functions are called)
|
31 | 44 | void suiteSetUp() {}
|
32 | 45 |
|
@@ -233,6 +246,113 @@ void test_zwapi_init()
|
233 | 246 | TEST_ASSERT_EQUAL(3, serial_fd);
|
234 | 247 | }
|
235 | 248 |
|
| 249 | +void test_zwapi_refresh_capabilities_bitmask(void) |
| 250 | +{ |
| 251 | + zwapi_chip_data_t chip; |
| 252 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 253 | + uint8_t response_length = IDX_DATA + 7 + sizeof(chip.supported_bitmask); |
| 254 | + memset(response_buffer, |
| 255 | + 0xAA, |
| 256 | + sizeof(response_buffer)); // Fill with dummy data |
| 257 | + |
| 258 | + // Simulate a valid response with sufficient length for supported_bitmask |
| 259 | + zwapi_session_send_frame_with_response_ExpectAndReturn( |
| 260 | + FUNC_ID_SERIAL_API_GET_CAPABILITIES, |
| 261 | + NULL, |
| 262 | + 0, |
| 263 | + NULL, |
| 264 | + NULL, |
| 265 | + SL_STATUS_OK); |
| 266 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 267 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 268 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 269 | + response_buffer, |
| 270 | + response_length); |
| 271 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 272 | + &response_length); |
| 273 | + |
| 274 | + zwapi_get_zw_library_version_Stub( |
| 275 | + (CMOCK_zwapi_get_zw_library_version_CALLBACK) |
| 276 | + zwapi_get_zw_library_version_stub); |
| 277 | + |
| 278 | + zwapi_session_flush_queue_Expect(); |
| 279 | + { |
| 280 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 281 | + uint8_t response_length = IDX_DATA + 1; |
| 282 | + |
| 283 | + zwapi_session_send_frame_with_response_ExpectAndReturn( |
| 284 | + FUNC_ID_SERIAL_API_GET_INIT_DATA, |
| 285 | + NULL, |
| 286 | + 0, |
| 287 | + NULL, |
| 288 | + NULL, |
| 289 | + SL_STATUS_OK); |
| 290 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 291 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 292 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 293 | + response_buffer, |
| 294 | + response_length); |
| 295 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 296 | + &response_length); |
| 297 | + } |
| 298 | + |
| 299 | + zwapi_get_rf_region_Stub(zwapi_get_rf_region_stub); |
| 300 | + TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_refresh_capabilities()); |
| 301 | +} |
| 302 | + |
| 303 | +void test_zwapi_refresh_capabilities_bitmask_injection(void) |
| 304 | +{ |
| 305 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 306 | + uint8_t response_length = FRAME_LENGTH_MAX; |
| 307 | + memset(response_buffer, |
| 308 | + 0xAA, |
| 309 | + sizeof(response_buffer)); // Fill with dummy data |
| 310 | + |
| 311 | + // Simulate a valid response with sufficient length for supported_bitmask |
| 312 | + zwapi_session_send_frame_with_response_ExpectAndReturn( |
| 313 | + FUNC_ID_SERIAL_API_GET_CAPABILITIES, |
| 314 | + NULL, |
| 315 | + 0, |
| 316 | + NULL, |
| 317 | + NULL, |
| 318 | + SL_STATUS_OK); |
| 319 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 320 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 321 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 322 | + response_buffer, |
| 323 | + response_length); |
| 324 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 325 | + &response_length); |
| 326 | + |
| 327 | + zwapi_get_zw_library_version_Stub( |
| 328 | + (CMOCK_zwapi_get_zw_library_version_CALLBACK) |
| 329 | + zwapi_get_zw_library_version_stub); |
| 330 | + zwapi_session_flush_queue_Expect(); |
| 331 | + { |
| 332 | + uint8_t response_buffer[FRAME_LENGTH_MAX] = {0}; |
| 333 | + uint8_t response_length = IDX_DATA + 1; |
| 334 | + |
| 335 | + zwapi_session_send_frame_with_response_ExpectAndReturn( |
| 336 | + FUNC_ID_SERIAL_API_GET_INIT_DATA, |
| 337 | + NULL, |
| 338 | + 0, |
| 339 | + NULL, |
| 340 | + NULL, |
| 341 | + SL_STATUS_OK); |
| 342 | + zwapi_session_send_frame_with_response_IgnoreArg_response_buf(); |
| 343 | + zwapi_session_send_frame_with_response_IgnoreArg_response_len(); |
| 344 | + zwapi_session_send_frame_with_response_ReturnMemThruPtr_response_buf( |
| 345 | + response_buffer, |
| 346 | + response_length); |
| 347 | + zwapi_session_send_frame_with_response_ReturnThruPtr_response_len( |
| 348 | + &response_length); |
| 349 | + } |
| 350 | + |
| 351 | + zwapi_get_rf_region_Stub(zwapi_get_rf_region_stub); |
| 352 | + TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_refresh_capabilities()); |
| 353 | + |
| 354 | +} |
| 355 | + |
236 | 356 | void test_zwapi_refresh_capabilities_bad_cases()
|
237 | 357 | {
|
238 | 358 | //Capablities status fail
|
|
0 commit comments