diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-01-17 18:46:43 +0100 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-01-17 18:46:43 +0100 |
commit | dd9ccaf01650d77e6ea7e90f6ca588711e554d3f (patch) | |
tree | a6c08f9332eb4c724cb6afd75a68d69019588e59 /test | |
parent | 782ff0f986caab726afcd8424c63e9372409c5f8 (diff) |
selftest: add testcase for events
Diffstat (limited to 'test')
-rw-r--r-- | test/event.c | 55 | ||||
-rw-r--r-- | test/main.c | 1 | ||||
-rw-r--r-- | test/srcs.mk | 1 | ||||
-rw-r--r-- | test/test.h | 1 |
4 files changed, 58 insertions, 0 deletions
diff --git a/test/event.c b/test/event.c new file mode 100644 index 0000000..563d5d3 --- /dev/null +++ b/test/event.c @@ -0,0 +1,55 @@ +/** + * @file test/event.c Baresip selftest -- event handling + * + * Copyright (C) 2010 Creytiv.com + */ +#include <string.h> +#include <re.h> +#include <baresip.h> +#include "test.h" + + +int test_event(void) +{ + struct odict *od = NULL; + size_t i; + int err = 0; + + static const enum ua_event eventv[] = { + UA_EVENT_REGISTERING, + UA_EVENT_REGISTER_OK, + UA_EVENT_REGISTER_FAIL, + UA_EVENT_UNREGISTERING, + UA_EVENT_SHUTDOWN, + UA_EVENT_EXIT + /* .. more events .. */ + }; + + for (i=0; i<ARRAY_SIZE(eventv); i++) { + + const enum ua_event ev = eventv[i]; + const struct odict_entry *entry; + + err = odict_alloc(&od, 8); + ASSERT_EQ(0, err); + + err = event_encode_dict(od, NULL, ev, NULL, NULL); + ASSERT_EQ(0, err); + + /* verify that something was added */ + ASSERT_TRUE(odict_count(od, false) >= 2); + + /* verify the mandatory entries */ + entry = odict_lookup(od, "type"); + ASSERT_TRUE(entry != NULL); + ASSERT_EQ(ODICT_STRING, entry->type); + ASSERT_STREQ(uag_event_str(ev), entry->u.str); + + od = mem_deref(od); + } + + out: + mem_deref(od); + + return err; +} diff --git a/test/main.c b/test/main.c index e917f2d..09ff19e 100644 --- a/test/main.c +++ b/test/main.c @@ -44,6 +44,7 @@ static const struct test tests[] = { TEST(test_cmd_long), TEST(test_contact), TEST(test_cplusplus), + TEST(test_event), TEST(test_message), TEST(test_mos), TEST(test_network), diff --git a/test/srcs.mk b/test/srcs.mk index 0bcb6de..bdb0d0b 100644 --- a/test/srcs.mk +++ b/test/srcs.mk @@ -14,6 +14,7 @@ TEST_SRCS += call.c TEST_SRCS += cmd.c TEST_SRCS += contact.c TEST_SRCS += cplusplus.c +TEST_SRCS += event.c TEST_SRCS += message.c TEST_SRCS += mos.c TEST_SRCS += net.c diff --git a/test/test.h b/test/test.h index f276a8d..7977272 100644 --- a/test/test.h +++ b/test/test.h @@ -181,6 +181,7 @@ int test_account(void); int test_aulevel(void); int test_cmd(void); int test_cmd_long(void); +int test_event(void); int test_contact(void); int test_ua_alloc(void); int test_uag_find_param(void); |