Debian Codegraph @

testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c

raw
1 /*
2 * HEADER Testing netsnmp_parse_ep_str()
3 */
4
5 struct one_test_data {
6 const char *in;
7 int res;
8 struct { const char *addr; const char *iface; const char *port; } expected;
9 };
10
11 static struct one_test_data test_data[] = {
12 { "9999", 1, { "", "", "9999" } },
13 { ":777", 1, { "", "", "777" } },
14 { "hostname:777", 1, { "hostname", "", "777" } },
15 { "hostname", 1, { "hostname", "", "" } },
16 { "1.2.3.4", 1, { "1.2.3.4", "", "" } },
17 { "hostname@if", 1, { "hostname", "if", "" } },
18 { "hostname@if:833", 1, { "hostname", "if", "833" } },
19 { "[hostname]@if:833", 1, { "hostname", "if", "833" } },
20 { "[hostname]?", 0, { } },
21 { "[hostname", 0, { } },
22 { "@if:844", 1, { "", "if", "844" } },
23 { "::1", 1, { "::1", "", "" } },
24 { "::1@if", 1, { "::1", "if", "" } },
25 { "1::2", 1, { "1::2", "", "" } },
26 { "[::1]", 1, { "::1", "", "" } },
27 { "[::1]:0", 1, { "::1", "", "0" } },
28 { "[::1]:2", 1, { "::1", "", "2" } },
29 { "[::1]@if:2", 1, { "::1", "if", "2" } },
30 { "[::1]:2@if", 0, { } },
31 };
32
33 SOCK_STARTUP;
34
35 {
36 int i;
37
38 for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
39 const struct one_test_data *p = &test_data[i];
40 struct netsnmp_ep_str ep_str;
41 int res;
42
43 memset(&ep_str, 0, sizeof(ep_str));
44 res = netsnmp_parse_ep_str(&ep_str, p->in);
45 OKF(res == p->res, ("%s: return value %d <> %d", p->in, res, p->res));
46 if (res && p->res) {
47 OKF((!ep_str.addr && !p->expected.addr[0]) ||
48 strcmp(ep_str.addr, p->expected.addr) == 0,
49 ("%s: network address %s <> %s", p->in, ep_str.addr,
50 p->expected.addr));
51 OKF(strcmp(ep_str.iface, p->expected.iface) == 0,
52 ("%s: network interface %s <> %s", p->in, ep_str.iface,
53 p->expected.iface));
54 OKF(strcmp(ep_str.port, p->expected.port) == 0,
55 ("%s: port %s <> %s", p->in, ep_str.port, p->expected.port));
56 }
57 free(ep_str.addr);
58 }
59 }
60
61 SOCK_CLEANUP;