#include "unity.h" #include "celrs/serial.h" #include "Mockserial_internal.h" #include void setUp(void) { Mockserial_internal_Init(); } void tearDown(void) { Mockserial_internal_Verify(); Mockserial_internal_Destroy(); } /* cel_serial_find_elrs_port tests */ void test_find_elrs_port_null_out(void) { TEST_ASSERT_EQUAL_INT(-1, cel_serial_find_elrs_port(NULL, 0)); } void test_find_elrs_port_zero_size(void) { char buf[1]; TEST_ASSERT_EQUAL_INT(-1, cel_serial_find_elrs_port(buf, 0)); } void test_find_elrs_port_no_match(void) { char buf[256]; cel_serial_platform_list_ports_ExpectAnyArgsAndReturn(0); int rc = cel_serial_find_elrs_port(buf, sizeof(buf)); TEST_ASSERT_EQUAL_INT(-1, rc); } /* cel_serial_open_probe tests */ void test_open_probe_null_path(void) { int bauds[] = {400000}; int actual; TEST_ASSERT_NULL(cel_serial_open_probe(NULL, bauds, 1, &actual)); } void test_open_probe_null_bauds(void) { int actual; TEST_ASSERT_NULL(cel_serial_open_probe("COM999", NULL, 1, &actual)); } void test_open_probe_zero_count(void) { int actual; TEST_ASSERT_NULL(cel_serial_open_probe("COM999", NULL, 0, &actual)); } void test_open_probe_out_baud_set(void) { cel_serial_platform_open_ExpectAndReturn("COM999", 400000, CEL_SERIAL_PLATFORM_INVALID_HANDLE); int bauds[] = {400000}; int actual = 0; cel_serial_port* port = cel_serial_open_probe("COM999", bauds, 1, &actual); TEST_ASSERT_NULL(port); } void test_open_probe_success_sets_baud(void) { cel_serial_platform_open_ExpectAndReturn("COM3", 921600, (cel_serial_platform_handle)42); cel_serial_platform_close_Expect((cel_serial_platform_handle)42); int bauds[] = {921600, 400000}; int actual = 0; cel_serial_port* port = cel_serial_open_probe("COM3", bauds, 2, &actual); TEST_ASSERT_NOT_NULL(port); TEST_ASSERT_EQUAL_INT(921600, actual); cel_serial_close(port); } void test_open_probe_null_out_baud(void) { cel_serial_platform_open_ExpectAndReturn("COM999", 400000, CEL_SERIAL_PLATFORM_INVALID_HANDLE); int bauds[] = {400000}; TEST_ASSERT_NULL(cel_serial_open_probe("COM999", bauds, 1, NULL)); } int main(void) { UNITY_BEGIN(); RUN_TEST(test_find_elrs_port_null_out); RUN_TEST(test_find_elrs_port_zero_size); RUN_TEST(test_find_elrs_port_no_match); RUN_TEST(test_open_probe_null_path); RUN_TEST(test_open_probe_null_bauds); RUN_TEST(test_open_probe_zero_count); RUN_TEST(test_open_probe_out_baud_set); RUN_TEST(test_open_probe_success_sets_baud); RUN_TEST(test_open_probe_null_out_baud); return UNITY_END(); }