diff options
author | Alfred E. Heggestad <aeh@db.org> | 2016-06-06 10:14:12 +0200 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2016-06-06 10:14:12 +0200 |
commit | 6910d50e9b1e80fe758b259149012e7e062eecd0 (patch) | |
tree | aecd149deed8ae71349e3b2e626e53f57a9c974a /test/net.c | |
parent | 362914f55831f4ad3afd7c0cad8f01f2f8b4892c (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/net.c')
-rw-r--r-- | test/net.c | 46 |
1 files changed, 46 insertions, 0 deletions
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; +} |