summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-06-06 10:14:12 +0200
committerAlfred E. Heggestad <aeh@db.org>2016-06-06 10:14:12 +0200
commit6910d50e9b1e80fe758b259149012e7e062eecd0 (patch)
treeaecd149deed8ae71349e3b2e626e53f57a9c974a /test
parent362914f55831f4ad3afd7c0cad8f01f2f8b4892c (diff)
net: make networking code re-entrant
- The network instance is now in struct network and does not use any local/static data - A new top-level struct in baresip.c owns the single instance of struct network it is a long-term goal to remove all local/static data from libbaresip and make it fully re-entrant.
Diffstat (limited to 'test')
-rw-r--r--test/main.c8
-rw-r--r--test/net.c46
-rw-r--r--test/srcs.mk1
-rw-r--r--test/test.h1
-rw-r--r--test/ua.c6
5 files changed, 60 insertions, 2 deletions
diff --git a/test/main.c b/test/main.c
index 42e381e..db99328 100644
--- a/test/main.c
+++ b/test/main.c
@@ -27,6 +27,7 @@ static const struct test tests[] = {
TEST(test_cmd),
TEST(test_cplusplus),
TEST(test_mos),
+ TEST(test_network),
TEST(test_ua_alloc),
TEST(test_ua_register),
TEST(test_ua_register_dns),
@@ -182,6 +183,11 @@ int main(int argc, char *argv[])
err = ENOENT;
goto out;
}
+
+ err = baresip_init(config, false);
+ if (err)
+ goto out;
+
str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local));
uag_set_exit_handler(ua_exit_handler, NULL);
@@ -228,6 +234,8 @@ int main(int argc, char *argv[])
ua_stop_all(true);
ua_close();
+ baresip_close();
+
libre_close();
tmr_debug();
diff --git a/test/net.c b/test/net.c
new file mode 100644
index 0000000..170fc3b
--- /dev/null
+++ b/test/net.c
@@ -0,0 +1,46 @@
+/**
+ * @file test/net.c Baresip selftest -- networking
+ *
+ * Copyright (C) 2010 - 2016 Creytiv.com
+ */
+#include <string.h>
+#include <re.h>
+#include <baresip.h>
+#include "test.h"
+
+
+static struct config_net default_config;
+
+
+static void net_change_handler(void *arg)
+{
+ unsigned *count = arg;
+ ++*count;
+ info("network changed\n");
+}
+
+
+int test_network(void)
+{
+ struct network *net = NULL;
+ unsigned change_count = 0;
+ int err;
+
+ err = net_alloc(&net, &default_config, AF_INET);
+ TEST_ERR(err);
+ ASSERT_TRUE(net != NULL);
+
+ ASSERT_EQ(AF_INET, net_af(net));
+
+ net_change(net, 1, net_change_handler, &change_count);
+
+ ASSERT_EQ(0, change_count);
+
+ net_force_change(net);
+
+ ASSERT_EQ(1, change_count);
+
+ out:
+ mem_deref(net);
+ return err;
+}
diff --git a/test/srcs.mk b/test/srcs.mk
index a68ff94..06b4482 100644
--- a/test/srcs.mk
+++ b/test/srcs.mk
@@ -13,6 +13,7 @@ TEST_SRCS += ua.c
TEST_SRCS += cplusplus.c
TEST_SRCS += call.c
TEST_SRCS += mos.c
+TEST_SRCS += net.c
#
diff --git a/test/test.h b/test/test.h
index 87972f9..cd00514 100644
--- a/test/test.h
+++ b/test/test.h
@@ -94,6 +94,7 @@ int test_ua_register_dns(void);
int test_ua_register_auth(void);
int test_ua_register_auth_dns(void);
int test_mos(void);
+int test_network(void);
int test_call_answer(void);
int test_call_reject(void);
diff --git a/test/ua.c b/test/ua.c
index 0473da5..abebe0c 100644
--- a/test/ua.c
+++ b/test/ua.c
@@ -217,6 +217,7 @@ static int reg_dns(enum sip_transp tp)
struct dns_server *dnssrv = NULL;
struct test t;
const char *domain = "test.invalid";
+ struct network *net = baresip_network();
unsigned server_count = 1;
char aor[256];
char srv[256];
@@ -235,7 +236,7 @@ static int reg_dns(enum sip_transp tp)
info("| DNS-server on %J\n", &dnssrv->addr);
/* NOTE: must be done before ua_init() */
- err = net_dnssrv_add(&dnssrv->addr);
+ err = net_use_nameserver(net, &dnssrv->addr);
TEST_ERR(err);
for (i=0; i<server_count; i++) {
@@ -443,6 +444,7 @@ int test_ua_register_auth(void)
static int reg_auth_dns(enum sip_transp tp)
{
+ struct network *net = baresip_network();
struct dns_server *dnssrv = NULL;
struct test t;
const char *username = "alfredh";
@@ -466,7 +468,7 @@ static int reg_auth_dns(enum sip_transp tp)
info("| DNS-server on %J\n", &dnssrv->addr);
/* NOTE: must be done before ua_init() */
- err = net_dnssrv_add(&dnssrv->addr);
+ err = net_use_nameserver(net, &dnssrv->addr);
TEST_ERR(err);
for (i=0; i<server_count; i++) {