diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/tcp.c | 42 | ||||
| -rw-r--r-- | tests/tcp6.c | 86 | ||||
| -rw-r--r-- | tests/trantest.h | 4 |
4 files changed, 127 insertions, 6 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 70c9de3a..b34c5275 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -122,6 +122,7 @@ add_nng_test(survey 5) add_nng_test(synch 5) add_nng_test(transport 5) add_nng_test(tcp 5) +add_nng_test(tcp6 5) add_nng_test(scalability 20) add_nng_test(message 5) add_nng_test(device 5) diff --git a/tests/tcp.c b/tests/tcp.c index 324c167e..92e50a8b 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -11,11 +11,49 @@ #include "convey.h" #include "trantest.h" -// Inproc tests. +// TCP tests. + +#ifndef _WIN32 +#include <arpa/inet.h> +#endif + +static int +check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d) +{ + nng_pipe p; + size_t z; + p = nng_msg_get_pipe(msg); + So(p > 0); + + Convey("Local address property works", { + nng_sockaddr la; + z = sizeof(nng_sockaddr); + So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); + So(z == sizeof(la)); + So(la.s_un.s_family == NNG_AF_INET); + // So(la.s_un.s_in.sa_port == (trantest_port - 1)); + So(la.s_un.s_in.sa_port != 0); + So(la.s_un.s_in.sa_addr == htonl(0x7f000001)); + }); + + Convey("Remote address property works", { + nng_sockaddr ra; + z = sizeof(nng_sockaddr); + So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); + So(z == sizeof(ra)); + So(ra.s_un.s_family == NNG_AF_INET); + So(ra.s_un.s_in.sa_port != 0); + So(ra.s_un.s_in.sa_addr == htonl(0x7f000001)); + + So(nng_dialer_getopt(d, NNG_OPT_REMADDR, &ra, &z) != 0); + }); + + return (0); +} TestMain("TCP Transport", { - trantest_test_all("tcp://127.0.0.1:%u"); + trantest_test_extended("tcp://127.0.0.1:%u", check_props_v4); Convey("We cannot connect to wild cards", { nng_socket s; diff --git a/tests/tcp6.c b/tests/tcp6.c new file mode 100644 index 00000000..6f84d282 --- /dev/null +++ b/tests/tcp6.c @@ -0,0 +1,86 @@ +// +// Copyright 2017 Garrett D'Amore <garrett@damore.org> +// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "convey.h" +#include "trantest.h" + +#include "core/nng_impl.h" +// TCP tests for IPv6. + +static int +has_v6(void) +{ + nng_sockaddr sa; + nni_plat_udp *u; + int rv; + + sa.s_un.s_in6.sa_family = NNG_AF_INET6; + sa.s_un.s_in6.sa_port = 0; + memset(sa.s_un.s_in6.sa_addr, 0, 16); + sa.s_un.s_in6.sa_addr[15] = 1; + + rv = nni_plat_udp_open(&u, &sa); + if (rv == 0) { + nni_plat_udp_close(u); + } + return (rv == 0 ? 1 : 0); +} + +static int +check_props_v6(nng_msg *msg, nng_listener l, nng_dialer d) +{ + nng_pipe p; + size_t z; + uint8_t loopback[16]; + + memset(loopback, 0, sizeof(loopback)); + loopback[15] = 1; + Convey("IPv6 Local address property works", { + nng_sockaddr la; + z = sizeof(nng_sockaddr); + p = nng_msg_get_pipe(msg); + So(p > 0); + So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); + So(z == sizeof(la)); + So(la.s_un.s_family == NNG_AF_INET6); + // So(la.s_un.s_in.sa_port == (trantest_port - 1)); + So(la.s_un.s_in6.sa_port != 0); + So(memcmp(la.s_un.s_in6.sa_addr, loopback, 16) == 0); + }); + + Convey("IPv6 Remote address property works", { + nng_sockaddr ra; + z = sizeof(nng_sockaddr); + p = nng_msg_get_pipe(msg); + So(p > 0); + So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); + So(z == sizeof(ra)); + So(ra.s_un.s_family == NNG_AF_INET6); + So(ra.s_un.s_in6.sa_port != 0); + So(memcmp(ra.s_un.s_in6.sa_addr, loopback, 16) == 0); + + So(nng_dialer_getopt(d, NNG_OPT_REMADDR, &ra, &z) != 0); + }); + + return (0); +} + +TestMain("TCP (IPv6) Transport", { + + nni_init(); + + if (has_v6()) { + trantest_test_extended("tcp://[::1]:%u", check_props_v6); + } else { + SkipSo("IPv6 not available"); + } + + nng_fini(); +}) diff --git a/tests/trantest.h b/tests/trantest.h index 542cff32..52b6b2ea 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -179,10 +179,6 @@ trantest_check_properties(trantest *tt, trantest_proptest_t f) nng_dialer d; nng_msg * send; nng_msg * recv; - size_t len; - nng_pipe p; - char url[NNG_MAXADDRLEN]; - size_t sz; int rv; So(nng_listen(tt->repsock, tt->addr, &l, 0) == 0); |
