aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2011-07-22 16:44:20 +0200
committerPatrick McHardy <kaber@trash.net>2011-07-22 16:44:20 +0200
commit2b9be10b177024bd663bd5fce19ea0fb76260c27 (patch)
treef6c296350683ee94c120213bef57e14fd153b23a /tests
parent916e420bf0c8db7a8cb1f60557cd2807652142cf (diff)
parent28da2a199d7e1624ac56ccb27d3671117f4e2717 (diff)
Merge branch 'master' of 192.168.0.100:/repos/git/asteriskHEADmaster
Diffstat (limited to 'tests')
-rw-r--r--tests/test_acl.c1
-rw-r--r--tests/test_amihooks.c1
-rw-r--r--tests/test_aoc.c1
-rw-r--r--tests/test_app.c1
-rw-r--r--tests/test_ast_format_str_reduce.c1
-rw-r--r--tests/test_astobj2.c1
-rw-r--r--tests/test_db.c28
-rw-r--r--tests/test_devicestate.c1
-rw-r--r--tests/test_dlinklists.c1
-rw-r--r--tests/test_event.c1
-rw-r--r--tests/test_expr.c1
-rw-r--r--tests/test_func_file.c1
-rw-r--r--tests/test_gosub.c1
-rw-r--r--tests/test_heap.c1
-rw-r--r--tests/test_linkedlists.c215
-rw-r--r--tests/test_locale.c1
-rw-r--r--tests/test_logger.c1
-rw-r--r--tests/test_netsock2.c5
-rw-r--r--tests/test_pbx.c1
-rw-r--r--tests/test_poll.c1
-rw-r--r--tests/test_sched.c1
-rw-r--r--tests/test_security_events.c1
-rw-r--r--tests/test_skel.c1
-rw-r--r--tests/test_stringfields.c1
-rw-r--r--tests/test_strings.c1
-rw-r--r--tests/test_substitution.c4
-rw-r--r--tests/test_time.c1
-rw-r--r--tests/test_utils.c1
28 files changed, 274 insertions, 2 deletions
diff --git a/tests/test_acl.c b/tests/test_acl.c
index 693c8054d..b84ca4364 100644
--- a/tests/test_acl.c
+++ b/tests/test_acl.c
@@ -26,6 +26,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_amihooks.c b/tests/test_amihooks.c
index 2fd23a476..dfb64866b 100644
--- a/tests/test_amihooks.c
+++ b/tests/test_amihooks.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<defaultenabled>no</defaultenabled>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_aoc.c b/tests/test_aoc.c
index 23663ee02..2a4294300 100644
--- a/tests/test_aoc.c
+++ b/tests/test_aoc.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_app.c b/tests/test_app.c
index b4b2c22e1..75992f30f 100644
--- a/tests/test_app.c
+++ b/tests/test_app.c
@@ -26,6 +26,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_ast_format_str_reduce.c b/tests/test_ast_format_str_reduce.c
index c92245213..6723513b8 100644
--- a/tests/test_ast_format_str_reduce.c
+++ b/tests/test_ast_format_str_reduce.c
@@ -36,6 +36,7 @@
<depend>format_sln</depend>
<depend>format_wav</depend>
<depend>format_wav_gsm</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_astobj2.c b/tests/test_astobj2.c
index 12632c63a..9466f3384 100644
--- a/tests/test_astobj2.c
+++ b/tests/test_astobj2.c
@@ -25,6 +25,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_db.c b/tests/test_db.c
index 105a6ab1e..95532c780 100644
--- a/tests/test_db.c
+++ b/tests/test_db.c
@@ -205,10 +205,37 @@ AST_TEST_DEFINE(gettree_deltree)
return res;
}
+AST_TEST_DEFINE(perftest)
+{
+ int res = AST_TEST_PASS;
+ size_t x;
+ char buf[10];
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "perftest";
+ info->category = "/main/astdb/";
+ info->summary = "astdb performance unit test";
+ info->description =
+ "Measure astdb performance";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ for (x = 0; x < 100000; x++) {
+ sprintf(buf, "%zu", x);
+ ast_db_put("astdbtest", buf, buf);
+ }
+ ast_db_deltree("astdbtest", NULL);
+
+ return res;
+}
static int unload_module(void)
{
AST_TEST_UNREGISTER(put_get_del);
AST_TEST_UNREGISTER(gettree_deltree);
+ AST_TEST_UNREGISTER(perftest);
return 0;
}
@@ -216,6 +243,7 @@ static int load_module(void)
{
AST_TEST_REGISTER(put_get_del);
AST_TEST_REGISTER(gettree_deltree);
+ AST_TEST_REGISTER(perftest);
return AST_MODULE_LOAD_SUCCESS;
}
diff --git a/tests/test_devicestate.c b/tests/test_devicestate.c
index 415cda271..77e718bd2 100644
--- a/tests/test_devicestate.c
+++ b/tests/test_devicestate.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_dlinklists.c b/tests/test_dlinklists.c
index 45a34eaf7..2af251f71 100644
--- a/tests/test_dlinklists.c
+++ b/tests/test_dlinklists.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<defaultenabled>no</defaultenabled>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_event.c b/tests/test_event.c
index e6f345133..01bb9ee4c 100644
--- a/tests/test_event.c
+++ b/tests/test_event.c
@@ -44,6 +44,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_expr.c b/tests/test_expr.c
index b4adc4aac..b7f416446 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_func_file.c b/tests/test_func_file.c
index 4e8823ba9..6e35fe921 100644
--- a/tests/test_func_file.c
+++ b/tests/test_func_file.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_gosub.c b/tests/test_gosub.c
index e69acfb17..f8b7482fd 100644
--- a/tests/test_gosub.c
+++ b/tests/test_gosub.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_heap.c b/tests/test_heap.c
index 3e70848d1..d14f1620f 100644
--- a/tests/test_heap.c
+++ b/tests/test_heap.c
@@ -25,6 +25,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_linkedlists.c b/tests/test_linkedlists.c
new file mode 100644
index 000000000..55944570b
--- /dev/null
+++ b/tests/test_linkedlists.c
@@ -0,0 +1,215 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2011, Terry Wilson
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Linked List Tests
+ *
+ * \author Terry Wilson <twilson@digium.com>
+ *
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+ <defaultenabled>no</defaultenabled>
+ <support_level>extended</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/test.h"
+#include "asterisk/strings.h"
+#include "asterisk/logger.h"
+#include "asterisk/linkedlists.h"
+
+struct test_val {
+ const char *name;
+ AST_LIST_ENTRY(test_val) list;
+};
+
+static struct test_val a = { "A" };
+static struct test_val b = { "B" };
+static struct test_val c = { "C" };
+static struct test_val d = { "D" };
+
+AST_LIST_HEAD_NOLOCK(test_list, test_val);
+
+static int list_expect(struct test_list *test_list, char *expect, struct ast_str **buf)
+{
+ struct test_val *i;
+
+ ast_str_reset(*buf);
+ AST_LIST_TRAVERSE(test_list, i, list) {
+ ast_str_append(buf, 0, "%s", i->name);
+ }
+
+ return strcmp(expect, ast_str_buffer(*buf));
+}
+
+#define MATCH_OR_FAIL(list, val, retbuf) \
+ if (list_expect(list, val, &retbuf)) { \
+ ast_test_status_update(test, "Expected: %s, Got: %s\n", val, ast_str_buffer(retbuf)); \
+ ast_free(retbuf); \
+ return AST_TEST_FAIL; \
+ }
+
+#define ELEM_OR_FAIL(x,y) \
+ if ((x) != (y)) { \
+ ast_test_status_update(test, "Expected: %s, Got: %s\n", (x)->name, (y)->name); \
+ return AST_TEST_FAIL; \
+ }
+
+AST_TEST_DEFINE(ll_tests)
+{
+ struct ast_str *buf;
+ struct test_list test_list = { 0, };
+ struct test_val *bogus;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "ll_tests";
+ info->category = "/main/linkedlists";
+ info->summary = "linked list unit test";
+ info->description =
+ "Test the linked list API";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ if (!(buf = ast_str_create(16))) {
+ return AST_TEST_FAIL;
+ }
+
+ if (!(bogus = alloca(sizeof(*bogus)))) {
+ return AST_TEST_FAIL;
+ }
+
+ if (AST_LIST_REMOVE(&test_list, bogus, list)) {
+ ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for missing element from empty list\n");
+ return AST_TEST_FAIL;
+ }
+
+ /* INSERT_HEAD and REMOVE_HEAD tests */
+ AST_LIST_INSERT_HEAD(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_HEAD(&test_list, &b, list);
+ MATCH_OR_FAIL(&test_list, "BA", buf);
+ AST_LIST_INSERT_HEAD(&test_list, &c, list);
+ MATCH_OR_FAIL(&test_list, "CBA", buf);
+ AST_LIST_INSERT_HEAD(&test_list, &d, list);
+ MATCH_OR_FAIL(&test_list, "DCBA", buf);
+ AST_LIST_REMOVE_HEAD(&test_list, list);
+ MATCH_OR_FAIL(&test_list, "CBA", buf);
+ AST_LIST_REMOVE_HEAD(&test_list, list);
+ MATCH_OR_FAIL(&test_list, "BA", buf);
+ AST_LIST_REMOVE_HEAD(&test_list, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_REMOVE_HEAD(&test_list, list);
+ MATCH_OR_FAIL(&test_list, "", buf);
+
+ if (AST_LIST_REMOVE_HEAD(&test_list, list)) {
+ ast_test_status_update(test, "Somehow removed an item from the head of a list that didn't exist\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty\n");
+ return AST_TEST_FAIL;
+ }
+
+ AST_LIST_INSERT_TAIL(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &b, list);
+ MATCH_OR_FAIL(&test_list, "AB", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &c, list);
+ MATCH_OR_FAIL(&test_list, "ABC", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &d, list);
+ MATCH_OR_FAIL(&test_list, "ABCD", buf);
+
+ if (AST_LIST_REMOVE(&test_list, bogus, list)) {
+ ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for missing element\n");
+ return AST_TEST_FAIL;
+ }
+
+ bogus = NULL;
+
+ if (AST_LIST_REMOVE(&test_list, bogus, list)) {
+ ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for element set to NULL\n");
+ return AST_TEST_FAIL;
+ }
+
+ AST_LIST_REMOVE(&test_list, &b, list);
+ MATCH_OR_FAIL(&test_list, "ACD", buf);
+ AST_LIST_REMOVE(&test_list, &d, list);
+ MATCH_OR_FAIL(&test_list, "AC", buf);
+ AST_LIST_REMOVE(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "C", buf);
+ AST_LIST_REMOVE(&test_list, &c, list);
+ MATCH_OR_FAIL(&test_list, "", buf);
+
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (AST_LIST_REMOVE(&test_list, bogus, list)) {
+ ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL asked to remove a NULL pointer from an empty list\n");
+ return AST_TEST_FAIL;
+ }
+
+ AST_LIST_INSERT_HEAD(&test_list, &a, list);
+ MATCH_OR_FAIL(&test_list, "A", buf);
+ AST_LIST_INSERT_TAIL(&test_list, &b, list);
+ MATCH_OR_FAIL(&test_list, "AB", buf);
+ AST_LIST_INSERT_AFTER(&test_list, &a, &c, list);
+ MATCH_OR_FAIL(&test_list, "ACB", buf);
+ AST_LIST_INSERT_AFTER(&test_list, &b, &d, list);
+ MATCH_OR_FAIL(&test_list, "ACBD", buf);
+
+ ELEM_OR_FAIL(AST_LIST_FIRST(&test_list), &a);
+ ELEM_OR_FAIL(AST_LIST_LAST(&test_list), &d);
+ ELEM_OR_FAIL(AST_LIST_NEXT(&a, list), &c);
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+
+ if (!AST_LIST_EMPTY(&test_list)) {
+ ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(ll_tests);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(ll_tests);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test Linked Lists");
diff --git a/tests/test_locale.c b/tests/test_locale.c
index 46271c232..89148d17a 100644
--- a/tests/test_locale.c
+++ b/tests/test_locale.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<defaultenabled>no</defaultenabled>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_logger.c b/tests/test_logger.c
index 04b5a1058..41467ee6e 100644
--- a/tests/test_logger.c
+++ b/tests/test_logger.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<defaultenabled>no</defaultenabled>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_netsock2.c b/tests/test_netsock2.c
index 3bbf25770..8d7e1ebd8 100644
--- a/tests/test_netsock2.c
+++ b/tests/test_netsock2.c
@@ -69,7 +69,6 @@ AST_TEST_DEFINE(parsing)
{ "[2001::1]", 1 },
{ "[2001:0000:4136:e378:8000:63bf:3fff:fdd2]:5060", 1 },
{ "2001:0000:4136:e378:8000:63bf:3fff:fdd2:5060", 0 }, /* port, but no brackets */
- { "[fe80::200:5aee:feaa:20a2%eth0]", 1 }, /* link-local with scope id */
{ "[fe80::200::abcd", 0 }, /* multiple zero expansions */
};
@@ -101,7 +100,9 @@ AST_TEST_DEFINE(parsing)
tmp = ast_sockaddr_stringify(&addr);
ast_sockaddr_parse(&tmp_addr, tmp, 0);
if (ast_sockaddr_cmp_addr(&addr, &tmp_addr)) {
- ast_test_status_update(test, "Re-parsed stringification did not match: '%s' vs '%s'\n", ast_sockaddr_stringify(&addr), ast_sockaddr_stringify(&tmp_addr));
+ char buf[64];
+ ast_copy_string(buf, ast_sockaddr_stringify(&addr), sizeof(buf));
+ ast_test_status_update(test, "Re-parsed stringification of '%s' did not match: '%s' vs '%s'\n", test_vals[x].address, buf, ast_sockaddr_stringify(&tmp_addr));
res = AST_TEST_FAIL;
}
}
diff --git a/tests/test_pbx.c b/tests/test_pbx.c
index 3ecc9e937..a86ba36b8 100644
--- a/tests/test_pbx.c
+++ b/tests/test_pbx.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_poll.c b/tests/test_poll.c
index 815e0c6c4..bdab29142 100644
--- a/tests/test_poll.c
+++ b/tests/test_poll.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_sched.c b/tests/test_sched.c
index 0062afb09..bcd501aa0 100644
--- a/tests/test_sched.c
+++ b/tests/test_sched.c
@@ -25,6 +25,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_security_events.c b/tests/test_security_events.c
index 33b40e877..c2c7c2921 100644
--- a/tests/test_security_events.c
+++ b/tests/test_security_events.c
@@ -25,6 +25,7 @@
/*** MODULEINFO
<defaultenabled>no</defaultenabled>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_skel.c b/tests/test_skel.c
index 609e399a7..98d604012 100644
--- a/tests/test_skel.c
+++ b/tests/test_skel.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_stringfields.c b/tests/test_stringfields.c
index dd3f0aaa1..2cd51ddae 100644
--- a/tests/test_stringfields.c
+++ b/tests/test_stringfields.c
@@ -29,6 +29,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_strings.c b/tests/test_strings.c
index 34062f04d..b1d1205e6 100644
--- a/tests/test_strings.c
+++ b/tests/test_strings.c
@@ -29,6 +29,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_substitution.c b/tests/test_substitution.c
index aa7d14f91..eb3bb54e2 100644
--- a/tests/test_substitution.c
+++ b/tests/test_substitution.c
@@ -28,6 +28,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
<depend>func_curl</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
@@ -261,6 +262,9 @@ AST_TEST_DEFINE(test_substitution)
TEST(test_expected_result(test, c, "A${${baz}o:-2:-1}A", "A2A"));
pbx_builtin_setvar_helper(c, "list1", "ab&cd&ef");
TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,cd)}", "ab&ef"));
+ TEST(test_expected_result(test, c, "${SHELL(printf '%d' 123)},${SHELL(printf '%d' 456)}", "123,456"));
+ TEST(test_expected_result(test, c, "${foo},${CDR(answer)},${SHELL(printf '%d' 456)}", "123,,456"));
+ TEST(test_expected_result(test, c, "${foo},${this_does_not_exist},${THIS_DOES_NOT_EXIST(either)}", "123,,"));
#undef TEST
/* For testing dialplan functions */
diff --git a/tests/test_time.c b/tests/test_time.c
index c81c9bb12..ae8834d94 100644
--- a/tests/test_time.c
+++ b/tests/test_time.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"
diff --git a/tests/test_utils.c b/tests/test_utils.c
index fd9d3bc4a..3e7df97e2 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
+ <support_level>extended</support_level>
***/
#include "asterisk.h"