|
| 1 | +/****************************************************************************** |
| 2 | + * # License |
| 3 | + * <b>Copyright 2025 Silicon Laboratories Inc. www.silabs.com</b> |
| 4 | + ****************************************************************************** |
| 5 | + * The licensor of this software is Silicon Laboratories Inc. Your use of this |
| 6 | + * software is governed by the terms of Silicon Labs Master Software License |
| 7 | + * Agreement (MSLA) available at |
| 8 | + * www.silabs.com/about-us/legal/master-software-license-agreement. This |
| 9 | + * software is distributed to you in Source Code format and is governed by the |
| 10 | + * sections of the MSLA applicable to Source Code. |
| 11 | + * |
| 12 | + *****************************************************************************/ |
| 13 | +#include "unity.h" |
| 14 | +#include <stdio.h> |
| 15 | + |
| 16 | +#include <unity.h> |
| 17 | +#include "zwapi_connection.h" |
| 18 | + |
| 19 | +#ifdef __clang__ |
| 20 | +#pragma clang diagnostic ignored "-Woverflow" |
| 21 | +#endif |
| 22 | + |
| 23 | +#ifdef __GNUC__ |
| 24 | +#pragma GCC diagnostic ignored "-Woverflow" |
| 25 | +#endif |
| 26 | + |
| 27 | +/// Setup the test suite (called once before all test_xxx functions are called) |
| 28 | +void suiteSetUp() {} |
| 29 | + |
| 30 | +/// Teardown the test suite (called once after all test_xxx functions are called) |
| 31 | +int suiteTearDown(int num_failures) |
| 32 | +{ |
| 33 | + return num_failures; |
| 34 | +} |
| 35 | + |
| 36 | +/// Called before each and every test |
| 37 | +void setUp() {} |
| 38 | + |
| 39 | +void test_zwapi_connection_tx_invalid_payload_full() |
| 40 | +{ |
| 41 | + uint8_t cmd = 0x01; |
| 42 | + uint8_t type = 0x02; |
| 43 | + uint8_t buffer [0xFF] = {0}; ///< Maximum of len type |
| 44 | + uint8_t len = sizeof(buffer); |
| 45 | + bool ack_needed = true; |
| 46 | + |
| 47 | + // Expect the function to detect overflow |
| 48 | + zwapi_connection_tx(cmd, type, buffer, len, ack_needed); |
| 49 | +} |
| 50 | + |
| 51 | +void test_zwapi_connection_tx_valid_inputs() |
| 52 | +{ |
| 53 | + uint8_t cmd = 0x01; |
| 54 | + uint8_t type = 0x02; |
| 55 | + uint8_t buffer[10] |
| 56 | + = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0}; |
| 57 | + uint8_t len = sizeof(buffer); |
| 58 | + bool ack_needed = true; |
| 59 | + |
| 60 | + // Expect the function to execute without errors |
| 61 | + zwapi_connection_tx(cmd, type, buffer, len, ack_needed); |
| 62 | +} |
| 63 | + |
| 64 | +void test_zwapi_connection_tx_null_buffer() |
| 65 | +{ |
| 66 | + uint8_t cmd = 0x01; |
| 67 | + uint8_t type = 0x02; |
| 68 | + uint8_t *buffer = NULL; |
| 69 | + uint8_t len = 0; |
| 70 | + bool ack_needed = true; |
| 71 | + |
| 72 | + // Expect the function to not crash |
| 73 | + zwapi_connection_tx(cmd, type, buffer, len, ack_needed); |
| 74 | +} |
0 commit comments