summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2015-10-10 21:17:00 +0200
committerAlfred E. Heggestad <aeh@db.org>2015-10-10 21:17:00 +0200
commit399dc2bc0c07fbe904742a1f109142be70ab4a56 (patch)
treee6a75601521ffb78cd6680be6590c3372a463dbd
parentdf805d411841359d52f553fe2cf38447399fceaa (diff)
test: run all testcases from an array of tests
-rw-r--r--test/main.c55
-rw-r--r--test/ua.c6
2 files changed, 38 insertions, 23 deletions
diff --git a/test/main.c b/test/main.c
index d39adfe..29e8460 100644
--- a/test/main.c
+++ b/test/main.c
@@ -8,29 +8,43 @@
#include "test.h"
-static int run_tests(void)
-{
- int err;
+typedef int (test_exec_h)(void);
- err = test_cmd();
- if (err)
- return err;
+struct test {
+ test_exec_h *exec;
+ const char *name;
+};
- err = test_ua_alloc();
- if (err)
- return err;
+#define TEST(a) {a, #a}
- err = test_uag_find_param();
- if (err)
- return err;
+static const struct test tests[] = {
+ TEST(test_cmd),
+ TEST(test_ua_alloc),
+ TEST(test_uag_find_param),
+ TEST(test_ua_register),
+ TEST(test_cplusplus),
+};
- err = test_ua_register();
- if (err)
- return err;
- err = test_cplusplus();
- if (err)
- return err;
+static int run_tests(bool verbose)
+{
+ size_t i;
+ int err;
+
+ for (i=0; i<ARRAY_SIZE(tests); i++) {
+
+ if (verbose) {
+ re_printf("test %u -- %s\n",
+ i, tests[i].name);
+ }
+
+ err = tests[i].exec();
+ if (err) {
+ warning("%s: test failed (%m)\n",
+ tests[i].name, err);
+ return err;
+ }
+ }
return 0;
}
@@ -60,7 +74,7 @@ int main(void)
if (err)
goto out;
- err = run_tests();
+ err = run_tests(false);
if (err)
goto out;
@@ -71,7 +85,8 @@ int main(void)
goto out;
#endif
- re_printf("\x1b[32mOK. selftest passed successfully\x1b[;m\n");
+ re_printf("\x1b[32mOK. %zu tests passed successfully\x1b[;m\n",
+ ARRAY_SIZE(tests));
out:
if (err) {
diff --git a/test/ua.c b/test/ua.c
index 80fd3a4..a7e3154 100644
--- a/test/ua.c
+++ b/test/ua.c
@@ -13,7 +13,7 @@ struct test {
struct sip_server *srv;
struct ua *ua;
int err;
- bool got_register_ok;
+ unsigned got_register_ok;
};
@@ -32,7 +32,7 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
if (ev == UA_EVENT_REGISTER_OK) {
- t->got_register_ok = true;
+ ++t->got_register_ok;
/* verify register success */
ASSERT_TRUE(ua_isregistered(t->ua));
@@ -84,7 +84,7 @@ static int reg(enum sip_transp tp)
ASSERT_TRUE(t.srv->n_register_req > 0);
ASSERT_EQ(tp, t.srv->tp_last);
- ASSERT_TRUE(t.got_register_ok);
+ ASSERT_TRUE(t.got_register_ok > 0);
out:
if (err) {