File: net.c

package info (click to toggle)
baresip 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,328 kB
  • sloc: ansic: 53,606; cpp: 2,268; makefile: 332; objc: 320; python: 259; sh: 40; xml: 19
file content (49 lines) | stat: -rw-r--r-- 814 bytes parent folder | download
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
47
48
49
/**
 * @file test/net.c  Baresip selftest -- networking
 *
 * Copyright (C) 2010 - 2016 Alfred E. Heggestad
 */
#include <string.h>
#include <re.h>
#include <baresip.h>
#include "test.h"


static struct config_net default_config = {
	.af = AF_INET
};


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);
	TEST_ERR(err);
	ASSERT_TRUE(net != NULL);

	ASSERT_TRUE( net_af_enabled(net, AF_INET));
	ASSERT_TRUE(!net_af_enabled(net, AF_INET6));

	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;
}