summaryrefslogtreecommitdiff
path: root/test/main.c
blob: c32cd4b4df03c62d599e7059e7f037269e6b4ceb (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 * @file test/main.c  Selftest for Baresip core
 *
 * Copyright (C) 2010 Creytiv.com
 */
#include <re.h>
#include <baresip.h>
#include "test.h"


static int run_tests(void)
{
	int err;

	err = test_cmd();
	if (err)
		return err;

	err = test_ua_alloc();
	if (err)
		return err;

	err = test_uag_find_param();
	if (err)
		return err;

	err = test_ua_register();
	if (err)
		return err;

	return 0;
}


int main(void)
{
	struct config *config;
	int err;

	err = libre_init();
	if (err)
		return err;

	re_printf("running test..\n");

	/* note: run SIP-traffic on localhost */
	config = conf_config();
	if (!config) {
		err = ENOENT;
		goto out;
	}
	str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local));

	/* XXX: needed for ua tests */
	err = ua_init("test", true, true, false, false);
	if (err)
		goto out;

	err = run_tests();
	if (err)
		goto out;

#if 1
	ua_stop_all(false);
	err = re_main_timeout(5);
	if (err)
		goto out;
#endif

	re_printf("\x1b[32mOK. selftest passed successfully\x1b[;m\n");

 out:
	if (err) {
		warning("test failed (%m)\n", err);
		re_printf("%H\n", re_debug, 0);
	}
	ua_stop_all(true);
	ua_close();

	libre_close();

	tmr_debug();
	mem_debug();

	return err;
}