11d03ef4280df54122b98cfd584fecc392a47fde
[socket_wrapper.git] / tests / test_public_functions.c
1 #include "torture.h"
2
3 #include <errno.h>
4 #include <stdio.h>
5 #include <cmocka.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8
9 #include <socket_wrapper.h>
10
11 static int setup_enabled(void **state)
12 {
13         torture_setup_socket_dir(state);
14
15         return 0;
16 }
17
18 static int teardown_enabled(void **state)
19 {
20         torture_teardown_socket_dir(state);
21
22         return 0;
23 }
24
25 static int setup_disabled(void **state)
26 {
27         (void) state; /* unused */
28
29         unsetenv("SOCKET_WRAPPER_DIR");
30         unsetenv("SOCKET_WRAPPER_DEFAULT_IFACE");
31         unsetenv("SOCKET_WRAPPER_PCAP_FILE");
32
33         return 0;
34 }
35
36 static int teardown_disabled(void **state)
37 {
38         (void) state; /* unused */
39
40         return 0;
41 }
42
43 static void test_call_enabled_true(void **state)
44 {
45         char *s = getenv("SOCKET_WRAPPER_DIR");
46
47         (void) state; /* unused */
48
49         assert_true(socket_wrapper_enabled());
50         assert_true(s != NULL);
51 }
52
53 static void test_call_enabled_false(void **state)
54 {
55         char *s = getenv("SOCKET_WRAPPER_DIR");
56
57         (void) state; /* unused */
58
59         assert_false(socket_wrapper_enabled());
60         assert_false(s != NULL);
61 }
62
63 int main(void) {
64         int rc;
65
66         const struct CMUnitTest max_sockets_tests[] = {
67                 cmocka_unit_test_setup_teardown(test_call_enabled_true,
68                                                 setup_enabled,
69                                                 teardown_enabled),
70                 cmocka_unit_test_setup_teardown(test_call_enabled_false,
71                                                 setup_disabled,
72                                                 teardown_disabled),
73         };
74
75         rc = cmocka_run_group_tests(max_sockets_tests, NULL, NULL);
76
77         return rc;
78 }