Inital commit
CI / macOS (push) Has been cancelled
CI / Windows / Clang (push) Has been cancelled
CI / macOS (push) Has been cancelled
CI / Windows / Clang (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include "unity.h"
|
||||
#include "celrs/serial.h"
|
||||
#include "Mocklog_write.h"
|
||||
|
||||
void setUp(void) { Mocklog_write_Init(); }
|
||||
void tearDown(void) { Mocklog_write_Verify(); Mocklog_write_Destroy(); }
|
||||
|
||||
void test_open_valid_path(void) {
|
||||
cel_serial_port* port = cel_serial_open("COM3", 400000);
|
||||
TEST_ASSERT_NOT_NULL(port);
|
||||
cel_serial_close(port);
|
||||
}
|
||||
|
||||
void test_open_null_path(void) {
|
||||
TEST_ASSERT_NULL(cel_serial_open(NULL, 400000));
|
||||
}
|
||||
|
||||
void test_open_preserves_path(void) {
|
||||
cel_serial_port* port = cel_serial_open("/dev/ttyUSB0", 400000);
|
||||
TEST_ASSERT_NOT_NULL(port);
|
||||
/* path is stored internally; verify by roundtrip behavior */
|
||||
cel_serial_close(port);
|
||||
}
|
||||
|
||||
void test_close_null(void) {
|
||||
/* Should not crash */
|
||||
cel_serial_close(NULL);
|
||||
}
|
||||
|
||||
void test_read_returns_zero_stub(void) {
|
||||
cel_serial_port* port = cel_serial_open("COM3", 400000);
|
||||
TEST_ASSERT_NOT_NULL(port);
|
||||
uint8_t buf[16];
|
||||
/* Stub implementation returns 0 */
|
||||
size_t n = cel_serial_read(port, buf, sizeof(buf), 100);
|
||||
TEST_ASSERT_EQUAL_UINT(0, n);
|
||||
cel_serial_close(port);
|
||||
}
|
||||
|
||||
void test_write_returns_zero_stub(void) {
|
||||
cel_serial_port* port = cel_serial_open("COM3", 400000);
|
||||
TEST_ASSERT_NOT_NULL(port);
|
||||
uint8_t buf[4] = {0xC8, 0x10, 0x80, 0x03};
|
||||
/* Stub implementation returns 0 */
|
||||
size_t n = cel_serial_write(port, buf, sizeof(buf));
|
||||
TEST_ASSERT_EQUAL_UINT(0, n);
|
||||
cel_serial_close(port);
|
||||
}
|
||||
|
||||
void test_flush_no_crash(void) {
|
||||
cel_serial_port* port = cel_serial_open("COM3", 400000);
|
||||
TEST_ASSERT_NOT_NULL(port);
|
||||
cel_serial_flush(port); /* should not crash */
|
||||
cel_serial_close(port);
|
||||
}
|
||||
|
||||
void test_flush_null(void) {
|
||||
cel_serial_flush(NULL); /* should not crash */
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_open_valid_path);
|
||||
RUN_TEST(test_open_null_path);
|
||||
RUN_TEST(test_open_preserves_path);
|
||||
RUN_TEST(test_close_null);
|
||||
RUN_TEST(test_read_returns_zero_stub);
|
||||
RUN_TEST(test_write_returns_zero_stub);
|
||||
RUN_TEST(test_flush_no_crash);
|
||||
RUN_TEST(test_flush_null);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user