summaryrefslogtreecommitdiff
path: root/test/cmd.c
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2015-08-09 15:28:08 +0200
committerAlfred E. Heggestad <aeh@db.org>2015-08-09 15:28:08 +0200
commit0535a3244acc2a6c096703090b467e60e630cf60 (patch)
treed5ea6873d5c092c7494818581253a7d03b4c14e0 /test/cmd.c
parent7d43d386d03047f4f1a3b5abbb4f4ecf81eb650b (diff)
selftest: new binary
- move selftest code from module/selftest to test/. - create a new binary called 'selftest' - the selftest is testing the Baresip Core only
Diffstat (limited to 'test/cmd.c')
-rw-r--r--test/cmd.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/cmd.c b/test/cmd.c
new file mode 100644
index 0000000..dfd42fa
--- /dev/null
+++ b/test/cmd.c
@@ -0,0 +1,77 @@
+/**
+ * @file test/cmd.c Baresip selftest -- cmd
+ *
+ * Copyright (C) 2010 Creytiv.com
+ */
+#include <re.h>
+#include <baresip.h>
+#include "test.h"
+
+
+static bool cmd_called;
+
+
+static int cmd_test(struct re_printf *pf, void *arg)
+{
+ struct cmd_arg *carg = arg;
+ int err = 0;
+ (void)pf;
+
+ ASSERT_EQ(false, cmd_called);
+
+ ASSERT_EQ('@', carg->key);
+ ASSERT_TRUE(NULL == carg->prm);
+ ASSERT_EQ(true, carg->complete);
+
+ cmd_called = true;
+
+ out:
+ return err;
+}
+
+
+static const struct cmd cmdv[] = {
+ {'@', 0, "Test command", cmd_test},
+};
+
+
+static int vprintf_null(const char *p, size_t size, void *arg)
+{
+ (void)p;
+ (void)size;
+ (void)arg;
+ return 0;
+}
+
+
+static struct re_printf pf_null = {vprintf_null, 0};
+
+
+int test_cmd(void)
+{
+ struct cmd_ctx *ctx = 0;
+ int err = 0;
+
+ cmd_called = false;
+
+ err = cmd_register(cmdv, ARRAY_SIZE(cmdv));
+ ASSERT_EQ(0, err);
+
+ /* issue a different command */
+ err = cmd_process(&ctx, 'h', &pf_null);
+ ASSERT_EQ(0, err);
+ ASSERT_EQ(false, cmd_called);
+
+ /* issue our command, expect handler to be called */
+ err = cmd_process(&ctx, '@', &pf_null);
+ ASSERT_EQ(0, err);
+ ASSERT_EQ(true, cmd_called);
+
+ cmd_unregister(cmdv);
+
+ /* verify that context was not created */
+ ASSERT_TRUE(NULL == ctx);
+
+ out:
+ return err;
+}