--- testing/fulltests/support/clib_build | 1 + .../T022netsnmp_parse_ep_str_clib.c | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c
diff --git a/testing/fulltests/support/clib_build b/testing/fulltests/support/clib_build index f94bebd02e36..3ae4dc9b5b7f 100755 --- a/testing/fulltests/support/clib_build +++ b/testing/fulltests/support/clib_build @@ -15,6 +15,7 @@ cat >>"$2.c" <<EOF #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/library/large_fd_set.h> +#include <net-snmp/library/snmpIPBaseDomain.h> /* testing specific header */ #include <net-snmp/library/testing.h> diff --git a/testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c b/testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c new file mode 100644 index 000000000000..7f06746ad299 --- /dev/null +++ b/testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c @@ -0,0 +1,55 @@ +/* + * HEADER Testing netsnmp_parse_ep_str() + */ + +struct one_test_data { + const char *in; + int res; + struct netsnmp_ep_str expected; +}; + +static struct one_test_data test_data[] = { + { "9999", 1, { "", "", 9999 } }, + { ":777", 1, { "", "", 777 } }, + { "hostname:777", 1, { "hostname", "", 777 } }, + { "hostname", 1, { "hostname", "", 0 } }, + { "1.2.3.4", 1, { "1.2.3.4", "", 0 } }, + { "hostname@if", 1, { "hostname", "if", 0 } }, + { "hostname@if:833", 1, { "hostname", "if", 833 } }, + { "[hostname]@if:833", 1, { "hostname", "if", 833 } }, + { "[hostname]?", 0, { } }, + { "[hostname", 0, { } }, + { "@if:844", 1, { "", "if", 844 } }, + { "[::1]", 1, { "::1", "", 0 } }, + { "[::1]:2", 1, { "::1", "", 2 } }, + { "[::1]@if:2", 1, { "::1", "if", 2 } }, + { "[::1]:2@if", 0, { } }, +}; + +SOCK_STARTUP; + +{ + int i; + + for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) { + const struct one_test_data *p = &test_data[i]; + struct netsnmp_ep_str ep_str; + int res; + + memset(&ep_str, 0, sizeof(ep_str)); + res = netsnmp_parse_ep_str(&ep_str, p->in); + OKF(res == p->res, ("%s: return value %d <> %d", p->in, res, p->res)); + if (res && p->res) { + OKF(strcmp(ep_str.addr, p->expected.addr) == 0, + ("%s: network address %s <> %s", p->in, ep_str.addr, + p->expected.addr)); + OKF(strcmp(ep_str.iface, p->expected.iface) == 0, + ("%s: network interface %s <> %s", p->in, ep_str.iface, + p->expected.iface)); + OKF(ep_str.port == p->expected.port, + ("%s: port %d <> %d", p->in, ep_str.port, p->expected.port)); + } + } +} + +SOCK_CLEANUP; -- 2.19.1 _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders