refactor: mock serial platform backend in test_serial
test_serial mocked log_write.h, which serial.c never calls. Split celrs_serial into celrs_serial (platform-agnostic logic) and celrs_serial_platform (real Win/POSIX backend), matching the celrs_logger/celrs_log_write split. test_serial now mocks celrs/platform/serial_internal.h and links only celrs_serial, so the list-ports tests verify the max_ports clamping and pass-through logic without hitting the real registry or /dev.
This commit is contained in:
+9
-10
@@ -2,10 +2,10 @@
|
||||
|
||||
#include "unity.h"
|
||||
#include "celrs/serial.h"
|
||||
#include "Mocklog_write.h"
|
||||
#include "Mockserial_internal.h"
|
||||
|
||||
void setUp(void) { Mocklog_write_Init(); }
|
||||
void tearDown(void) { Mocklog_write_Verify(); Mocklog_write_Destroy(); }
|
||||
void setUp(void) { Mockserial_internal_Init(); }
|
||||
void tearDown(void) { Mockserial_internal_Verify(); Mockserial_internal_Destroy(); }
|
||||
|
||||
void test_open_valid_path(void) {
|
||||
cel_serial_port* port = cel_serial_open("COM3", 400000);
|
||||
@@ -64,19 +64,18 @@ void test_list_ports_null_out(void) {
|
||||
TEST_ASSERT_EQUAL_INT(-1, cel_serial_list_ports(NULL, 16));
|
||||
}
|
||||
|
||||
void test_list_ports_runs_without_crash(void) {
|
||||
void test_list_ports_passes_max_ports_through(void) {
|
||||
char** ports = NULL;
|
||||
cel_serial_platform_list_ports_ExpectAndReturn(&ports, 16, 2);
|
||||
int count = cel_serial_list_ports(&ports, 16);
|
||||
/* count >= 0 is valid (may be 0 if no ports available) */
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_INT(0, count);
|
||||
cel_serial_free_ports(ports, count);
|
||||
TEST_ASSERT_EQUAL_INT(2, count);
|
||||
}
|
||||
|
||||
void test_list_ports_zero_max_uses_default(void) {
|
||||
char** ports = NULL;
|
||||
cel_serial_platform_list_ports_ExpectAndReturn(&ports, 64, 0);
|
||||
int count = cel_serial_list_ports(&ports, 0);
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_INT(0, count);
|
||||
cel_serial_free_ports(ports, count);
|
||||
TEST_ASSERT_EQUAL_INT(0, count);
|
||||
}
|
||||
|
||||
void test_free_ports_null(void) {
|
||||
@@ -99,7 +98,7 @@ int main(void) {
|
||||
RUN_TEST(test_flush_no_crash);
|
||||
RUN_TEST(test_flush_null);
|
||||
RUN_TEST(test_list_ports_null_out);
|
||||
RUN_TEST(test_list_ports_runs_without_crash);
|
||||
RUN_TEST(test_list_ports_passes_max_ports_through);
|
||||
RUN_TEST(test_list_ports_zero_max_uses_default);
|
||||
RUN_TEST(test_free_ports_null);
|
||||
RUN_TEST(test_free_ports_zero_count);
|
||||
|
||||
Reference in New Issue
Block a user