feat: Parser für die UART-Testkonsole
This commit is contained in:
@@ -34,3 +34,4 @@ nl_test(test_settings test_settings.c fake_flash.c ${NL_SRC}/config/nl_settings.
|
||||
nl_test(test_state_log test_state_log.c fake_flash.c ${NL_SRC}/config/nl_state_log.c
|
||||
${NL_SRC}/light/nl_boot_state.c ${NL_SRC}/util/nl_crc.c)
|
||||
nl_test(test_reset_counter test_reset_counter.c fake_flash.c ${NL_SRC}/config/nl_reset_counter.c)
|
||||
nl_test(test_console_cmd test_console_cmd.c ${NL_SRC}/sys/nl_console_cmd.c)
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "unity.h"
|
||||
#include "sys/nl_console_cmd.h"
|
||||
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
static void test_empty_and_unknown(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(NL_CMD_NONE, nl_console_parse("").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_NONE, nl_console_parse(" \r\n").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("dance").type);
|
||||
}
|
||||
|
||||
static void test_on_off(void)
|
||||
{
|
||||
nl_cmd_t c = nl_console_parse("on");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ON, c.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, c.argc);
|
||||
c = nl_console_parse("off 1500\r");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_OFF, c.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, c.argc);
|
||||
TEST_ASSERT_EQUAL_INT32(1500, c.arg[0]);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("on 60001").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("on abc").type);
|
||||
}
|
||||
|
||||
static void test_bri(void)
|
||||
{
|
||||
nl_cmd_t c = nl_console_parse("bri 50 200");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_BRI, c.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(2, c.argc);
|
||||
TEST_ASSERT_EQUAL_INT32(50, c.arg[0]);
|
||||
TEST_ASSERT_EQUAL_INT32(200, c.arg[1]);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("bri 0").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("bri").type);
|
||||
}
|
||||
|
||||
static void test_rgb(void)
|
||||
{
|
||||
nl_cmd_t c = nl_console_parse("rgb 255 0 128 1000");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_RGB, c.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(4, c.argc);
|
||||
TEST_ASSERT_EQUAL_INT32(128, c.arg[2]);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("rgb 255 0").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("rgb 256 0 0").type);
|
||||
}
|
||||
|
||||
static void test_ct(void)
|
||||
{
|
||||
nl_cmd_t c = nl_console_parse("ct 2700");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_CT, c.type);
|
||||
TEST_ASSERT_EQUAL_INT32(2700, c.arg[0]);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("ct 500").type);
|
||||
}
|
||||
|
||||
static void test_pob_fade_blink_pulse(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT32(0, nl_console_parse("pob last").arg[0]);
|
||||
TEST_ASSERT_EQUAL_INT32(1, nl_console_parse("pob on").arg[0]);
|
||||
TEST_ASSERT_EQUAL_INT32(2, nl_console_parse("pob off").arg[0]);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("pob maybe").type);
|
||||
|
||||
nl_cmd_t c = nl_console_parse("fade 300 800");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_FADE, c.type);
|
||||
TEST_ASSERT_EQUAL_INT32(800, c.arg[1]);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("fade 300").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("fade 300 10001").type);
|
||||
|
||||
c = nl_console_parse("blink");
|
||||
TEST_ASSERT_EQUAL(NL_CMD_BLINK, c.type);
|
||||
TEST_ASSERT_EQUAL_INT32(3, c.arg[0]);
|
||||
TEST_ASSERT_EQUAL_INT32(5, nl_console_parse("blink 5").arg[0]);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(1, nl_console_parse("pulse on").arg[0]);
|
||||
TEST_ASSERT_EQUAL_INT32(0, nl_console_parse("pulse off").arg[0]);
|
||||
}
|
||||
|
||||
static void test_simple_commands(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(NL_CMD_STATE, nl_console_parse("state").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_FACTORY, nl_console_parse("factory").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_REBOOT, nl_console_parse("reboot").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_HELP, nl_console_parse("help").type);
|
||||
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("state now").type);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_empty_and_unknown);
|
||||
RUN_TEST(test_on_off);
|
||||
RUN_TEST(test_bri);
|
||||
RUN_TEST(test_rgb);
|
||||
RUN_TEST(test_ct);
|
||||
RUN_TEST(test_pob_fade_blink_pulse);
|
||||
RUN_TEST(test_simple_commands);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user