diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cmd.c | 70 | ||||
-rw-r--r-- | test/main.c | 1 | ||||
-rw-r--r-- | test/test.h | 1 |
3 files changed, 71 insertions, 1 deletions
@@ -32,7 +32,7 @@ static int cmd_test(struct re_printf *pf, void *arg) static const struct cmd cmdv[] = { - {'@', 0, "Test command", cmd_test}, + {NULL, '@', 0, "Test command", cmd_test}, }; @@ -77,3 +77,71 @@ int test_cmd(void) out: return err; } + + +static int long_handler(struct re_printf *pf, void *arg) +{ + struct cmd_arg *carg = arg; + struct test *test = carg->data; + int err = 0; + (void)pf; + + ASSERT_STREQ("123", carg->prm); + + ++test->cmd_called; + + out: + return err; +} + + +static const struct cmd longcmdv[] = { + { "test", 0, 0, "Test Command", long_handler}, +}; + + +int test_cmd_long(void) +{ + struct test test; + const struct cmd *cmd; + static const char *input_str = "/test 123\n"; + struct cmd_ctx *ctx = NULL; + size_t i; + int err; + + memset(&test, 0, sizeof(test)); + + /* Verify that the command does not exist */ + cmd = cmd_find_long("test"); + ASSERT_TRUE(cmd == NULL); + + /* Register and verify command */ + err = cmd_register(longcmdv, ARRAY_SIZE(longcmdv)); + ASSERT_EQ(0, err); + + cmd = cmd_find_long("test"); + ASSERT_TRUE(cmd != NULL); + + /* Feed it some input data .. */ + + for (i=0; i<strlen(input_str); i++) { + + err = cmd_process(&ctx, input_str[i], &pf_null, &test); + ASSERT_EQ(0, err); + } + + err = cmd_process_long("test 123", 8, &pf_null, &test); + ASSERT_EQ(0, err); + + ASSERT_EQ(2, test.cmd_called); + + /* Cleanup .. */ + + cmd_unregister(longcmdv); + + cmd = cmd_find_long("test"); + ASSERT_TRUE(cmd == NULL); + + out: + return err; +} diff --git a/test/main.c b/test/main.c index 6991671..3a5dd77 100644 --- a/test/main.c +++ b/test/main.c @@ -29,6 +29,7 @@ static const struct test tests[] = { TEST(test_call_max), TEST(test_call_dtmf), TEST(test_cmd), + TEST(test_cmd_long), TEST(test_contact), TEST(test_cplusplus), TEST(test_mos), diff --git a/test/test.h b/test/test.h index 4c6c11b..bd41c82 100644 --- a/test/test.h +++ b/test/test.h @@ -95,6 +95,7 @@ int mock_ausrc_register(struct ausrc **ausrcp); /* test cases */ int test_cmd(void); +int test_cmd_long(void); int test_contact(void); int test_ua_alloc(void); int test_uag_find_param(void); |