summaryrefslogtreecommitdiff
path: root/test/net.c
blob: 170fc3bee2cfdc7185f83c9d5b60f815482cb87a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}