a3486fcd8fbba376b48e3013cf177deb289b0965
[tinc] / test / unit / test_netutl.c
1 #include "unittest.h"
2 #include "../../src/netutl.h"
3
4 static void test_service_to_port_invalid(void **state) {
5         (void)state;
6
7         assert_int_equal(0, service_to_port(NULL));
8         assert_int_equal(0, service_to_port(""));
9         assert_int_equal(0, service_to_port("-1"));
10         assert_int_equal(0, service_to_port("foobar"));
11 }
12
13 static void test_service_to_port_valid(void **state) {
14         (void)state;
15
16         assert_int_equal(22, service_to_port("ssh"));
17         assert_int_equal(80, service_to_port("http"));
18         assert_int_equal(443, service_to_port("https"));
19         assert_int_equal(1234, service_to_port("1234"));
20 }
21
22 int main(void) {
23         const struct CMUnitTest tests[] = {
24                 cmocka_unit_test(test_service_to_port_invalid),
25                 cmocka_unit_test(test_service_to_port_valid),
26         };
27         return cmocka_run_group_tests(tests, NULL, NULL);
28 }