#include "unity.h" #include "celrs/crsf.h" #include void setUp(void) {} void tearDown(void) {} /* CRC tests — CRC8/DVB-S2 (poly 0xD5) */ void test_crc_empty(void) { uint8_t data[1] = {0}; TEST_ASSERT_EQUAL_UINT8(0x00, cel_crsf_crc(data, 0)); } void test_crc_single_byte(void) { uint8_t data[1] = {0x01}; uint8_t crc = cel_crsf_crc(data, 1); TEST_ASSERT_TRUE(crc != 0); /* non-trivial */ } void test_crc_known_value(void) { /* Verify CRC is deterministic */ uint8_t data[6] = {0x10, 0x80, 0x03, 0x02, 0x80, 0x01}; uint8_t crc = cel_crsf_crc(data, 6); TEST_ASSERT_TRUE(crc != 0); uint8_t crc2 = cel_crsf_crc(data, 6); TEST_ASSERT_EQUAL_UINT8(crc, crc2); } /* Channel helper tests */ void test_channel_clamp_min(void) { TEST_ASSERT_EQUAL_INT16(CEL_CRSF_CH_MIN, cel_crsf_channel_clamp(0)); } void test_channel_clamp_max(void) { TEST_ASSERT_EQUAL_INT16(CEL_CRSF_CH_MAX, cel_crsf_channel_clamp(2048)); } void test_channel_clamp_mid(void) { TEST_ASSERT_EQUAL_INT16(CEL_CRSF_CH_MID, cel_crsf_channel_clamp(CEL_CRSF_CH_MID)); } int main(void) { UNITY_BEGIN(); RUN_TEST(test_crc_empty); RUN_TEST(test_crc_single_byte); RUN_TEST(test_crc_known_value); RUN_TEST(test_channel_clamp_min); RUN_TEST(test_channel_clamp_max); RUN_TEST(test_channel_clamp_mid); return UNITY_END(); }