summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-01-28 23:14:23 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-01-28 23:14:23 +0100
commit05ce1932c60cc303e808255b43950f63012ca665 (patch)
tree88602e09542e3aa0947edf75872a5493d6e86a48 /test
parent903ce9869c933e4f13995cd9f10c1498665cfd58 (diff)
cmd: make struct commands opaque
Diffstat (limited to 'test')
-rw-r--r--test/cmd.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/test/cmd.c b/test/cmd.c
index ae3838b..2df09ec 100644
--- a/test/cmd.c
+++ b/test/cmd.c
@@ -50,7 +50,7 @@ static struct re_printf pf_null = {vprintf_null, 0};
int test_cmd(void)
{
- struct commands commands;
+ struct commands *commands = NULL;
struct cmd_ctx *ctx = 0;
struct test test;
int err = 0;
@@ -60,29 +60,29 @@ int test_cmd(void)
err = cmd_init(&commands);
ASSERT_EQ(0, err);
- err = cmd_register(&commands, cmdv, ARRAY_SIZE(cmdv));
+ err = cmd_register(commands, cmdv, ARRAY_SIZE(cmdv));
ASSERT_EQ(0, err);
/* it is not possible to register same block twice */
- ASSERT_EQ(EALREADY, cmd_register(&commands, cmdv, ARRAY_SIZE(cmdv)));
+ ASSERT_EQ(EALREADY, cmd_register(commands, cmdv, ARRAY_SIZE(cmdv)));
/* issue a different command */
- err = cmd_process(&commands, &ctx, 'h', &pf_null, &test);
+ err = cmd_process(commands, &ctx, 'h', &pf_null, &test);
ASSERT_EQ(0, err);
ASSERT_EQ(0, test.cmd_called);
/* issue our command, expect handler to be called */
- err = cmd_process(&commands, &ctx, '@', &pf_null, &test);
+ err = cmd_process(commands, &ctx, '@', &pf_null, &test);
ASSERT_EQ(0, err);
ASSERT_EQ(1, test.cmd_called);
- cmd_unregister(&commands, cmdv);
+ cmd_unregister(commands, cmdv);
/* verify that context was not created */
ASSERT_TRUE(NULL == ctx);
out:
- cmd_close(&commands);
+ mem_deref(commands);
return err;
}
@@ -110,7 +110,7 @@ static const struct cmd longcmdv[] = {
int test_cmd_long(void)
{
- struct commands commands;
+ struct commands *commands = NULL;
struct test test;
const struct cmd *cmd;
static const char *input_str = "/test 123\n";
@@ -124,38 +124,38 @@ int test_cmd_long(void)
ASSERT_EQ(0, err);
/* Verify that the command does not exist */
- cmd = cmd_find_long(&commands, "test");
+ cmd = cmd_find_long(commands, "test");
ASSERT_TRUE(cmd == NULL);
/* Register and verify command */
- err = cmd_register(&commands, longcmdv, ARRAY_SIZE(longcmdv));
+ err = cmd_register(commands, longcmdv, ARRAY_SIZE(longcmdv));
ASSERT_EQ(0, err);
- cmd = cmd_find_long(&commands, "test");
+ cmd = cmd_find_long(commands, "test");
ASSERT_TRUE(cmd != NULL);
/* Feed it some input data .. */
for (i=0; i<strlen(input_str); i++) {
- err = cmd_process(&commands, &ctx, input_str[i],
+ err = cmd_process(commands, &ctx, input_str[i],
&pf_null, &test);
ASSERT_EQ(0, err);
}
- err = cmd_process_long(&commands, "test 123", 8, &pf_null, &test);
+ err = cmd_process_long(commands, "test 123", 8, &pf_null, &test);
ASSERT_EQ(0, err);
ASSERT_EQ(2, test.cmd_called);
/* Cleanup .. */
- cmd_unregister(&commands, longcmdv);
+ cmd_unregister(commands, longcmdv);
- cmd = cmd_find_long(&commands, "test");
+ cmd = cmd_find_long(commands, "test");
ASSERT_TRUE(cmd == NULL);
out:
- cmd_close(&commands);
+ mem_deref(commands);
return err;
}