aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-10-31 13:06:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-11-02 16:10:26 -0700
commit7bf591e20a94b8d926f92ab9b320f3b75d342345 (patch)
treed67ce7cab328a004346419047feede7d579dad77 /tests
parentd340af7dc250388f48d36c5078c4857c51bb6121 (diff)
downloadnng-7bf591e20a94b8d926f92ab9b320f3b75d342345.tar.gz
nng-7bf591e20a94b8d926f92ab9b320f3b75d342345.tar.bz2
nng-7bf591e20a94b8d926f92ab9b320f3b75d342345.zip
fixes #143 Protocols and transports should be "configurable"
This makes all the protocols and transports optional. All of them except ZeroTier are enabled by default, but you can now disable them (remove from the build) with cmake options. The test suite is modified so that tests still run as much as they can, but skip over things caused by missing functionality from the library (due to configuration). Further, the constant definitions and prototypes for functions that are specific to transports or protocols are moved into appropriate headers, which should be included directly by applications wishing to use these. We have also added and improved documentation -- all of the transports are documented, and several more man pages for protocols have been added. (Req/Rep and Surveyor are still missing.)
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt51
-rw-r--r--tests/aio.c4
-rw-r--r--tests/bus.c4
-rw-r--r--tests/cplusplus_pair.cc99
-rw-r--r--tests/device.c6
-rw-r--r--tests/pair1.c3
-rw-r--r--tests/pipeline.c4
-rw-r--r--tests/pollfd.c53
-rw-r--r--tests/pubsub.c52
-rw-r--r--tests/reconnect.c4
-rw-r--r--tests/reqrep.c3
-rw-r--r--tests/resolv.c111
-rw-r--r--tests/scalability.c4
-rw-r--r--tests/sock.c3
-rw-r--r--tests/stubs.h47
-rw-r--r--tests/survey.c4
-rw-r--r--tests/tcp.c3
-rw-r--r--tests/tcp6.c3
-rw-r--r--tests/trantest.h52
-rw-r--r--tests/zt.c16
20 files changed, 357 insertions, 169 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7cb4786f..3263e0a5 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -61,20 +61,37 @@ if (NNG_TESTS)
math (EXPR TEST_PORT "${TEST_PORT}+20")
endmacro (add_nng_test)
- macro (add_nng_compat_test NAME TIMEOUT)
- list (APPEND all_tests ${NAME})
- add_executable (${NAME} ${NAME}.c)
- target_link_libraries (${NAME} ${PROJECT_NAME}_static)
- target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES})
- target_compile_definitions(${NAME} PUBLIC -DNNG_STATIC_LIB)
- if (CMAKE_THREAD_LIBS_INIT)
- target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}")
- endif()
+ # Compatibility tests are only added if all of the legacy protocols
+ # are present. It's not worth trying to figure out which of these
+ # should work and which shouldn't.
+ if (NNG_PROTO_BUS0 AND
+ NNG_PROTO_PAIR0 AND
+ NNG_PROTO_REQ0 AND
+ NNG_PROTO_REP0 AND
+ NNG_PROTO_PUB0 AND
+ NNG_PROTO_SUB0 AND
+ NNG_PROTO_PUSH0 AND
+ NNG_PROTO_PULL0)
+
+ macro (add_nng_compat_test NAME TIMEOUT)
+ list (APPEND all_tests ${NAME})
+ add_executable (${NAME} ${NAME}.c)
+ target_link_libraries (${NAME} ${PROJECT_NAME}_static)
+ target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES})
+ target_compile_definitions(${NAME} PUBLIC -DNNG_STATIC_LIB)
+ if (CMAKE_THREAD_LIBS_INIT)
+ target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
- add_test (NAME ${NAME} COMMAND ${NAME} ${TEST_PORT})
- set_tests_properties (${NAME} PROPERTIES TIMEOUT ${TIMEOUT})
- math (EXPR TEST_PORT "${TEST_PORT}+10")
- endmacro (add_nng_compat_test)
+ add_test (NAME ${NAME} COMMAND ${NAME} ${TEST_PORT})
+ set_tests_properties (${NAME} PROPERTIES TIMEOUT ${TIMEOUT})
+ math (EXPR TEST_PORT "${TEST_PORT}+10")
+ endmacro (add_nng_compat_test)
+ else ()
+ macro (add_nng_compat_test NAME TIMEOUT)
+ endmacro (add_nng_compat_test)
+ message (STATUS "Compatibility tests disabled (unconfigured legacy protocols)")
+ endif ()
macro (add_nng_cpp_test NAME TIMEOUT)
if (NOT NNG_ENABLE_COVERAGE)
@@ -130,11 +147,13 @@ add_nng_test(device 5)
add_nng_test(errors 2)
add_nng_test(pair1 5)
add_nng_test(udp 5)
-if (NNG_HAVE_ZEROTIER)
- add_nng_test(zt 60)
-endif()
+add_nng_test(zt 60)
# compatbility tests
+# We only support these if ALL the legacy protocols are supported. This
+# is because we don't want to make modifications to partially enable some
+# of these tests. Folks minimizing the library probably don't care too
+# much about these anyway.
add_nng_compat_test(compat_block 5)
add_nng_compat_test(compat_bug777 5)
add_nng_compat_test(compat_bus 5)
diff --git a/tests/aio.c b/tests/aio.c
index 2a31319d..0746fa51 100644
--- a/tests/aio.c
+++ b/tests/aio.c
@@ -11,6 +11,10 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/pair1/pair.h"
+
+#include "stubs.h"
+
#include <string.h>
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
diff --git a/tests/bus.c b/tests/bus.c
index 8283bf21..88137b81 100644
--- a/tests/bus.c
+++ b/tests/bus.c
@@ -11,6 +11,10 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/bus0/bus.h"
+
+#include "stubs.h"
+
#include <string.h>
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc
index 54a99737..11ce1912 100644
--- a/tests/cplusplus_pair.cc
+++ b/tests/cplusplus_pair.cc
@@ -8,59 +8,68 @@
//
#include "nng.h"
+#include "protocol/pair1/pair.h"
#include <cstring>
+#include <iostream>
#define SOCKET_ADDRESS "inproc://c++"
int
main(int argc, char **argv)
{
- nng_socket s1;
- nng_socket s2;
- int rv;
- size_t sz;
- char buf[8];
- if ((rv = nng_pair0_open(&s1)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_pair0_open(&s2)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_send(s2, (void *)"ABC", 4, 0)) != 0) {
- throw nng_strerror(rv);
- }
- sz = sizeof (buf);
- if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) {
- throw "Contents did not match";
- }
- if ((rv = nng_send(s1, (void *)"DEF", 4, 0)) != 0) {
- throw nng_strerror(rv);
- }
- sz = sizeof (buf);
- if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) {
- throw "Contents did not match";
- }
- if ((rv = nng_close(s1)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_close(s2)) != 0) {
- throw nng_strerror(rv);
- }
+#if defined(NNG_HAVE_PAIR1)
- return (0);
-}
+ nng_socket s1;
+ nng_socket s2;
+ int rv;
+ size_t sz;
+ char buf[8];
+
+ if ((rv = nng_pair1_open(&s1)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_pair1_open(&s2)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_send(s2, (void *) "ABC", 4, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ sz = sizeof(buf);
+ if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) {
+ throw "Contents did not match";
+ }
+ if ((rv = nng_send(s1, (void *) "DEF", 4, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ sz = sizeof(buf);
+ if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) {
+ throw "Contents did not match";
+ }
+ if ((rv = nng_close(s1)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_close(s2)) != 0) {
+ throw nng_strerror(rv);
+ }
+ std::cout << "Pass." << std::endl;
+#else
+ std::cout << "Skipped (protocol unconfigured)." << std::endl;
+#endif
+
+ return (0);
+}
diff --git a/tests/device.c b/tests/device.c
index 5c650a91..56ad2cb5 100644
--- a/tests/device.c
+++ b/tests/device.c
@@ -10,6 +10,8 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/pair1/pair.h"
+#include "stubs.h"
#include <string.h>
@@ -68,8 +70,8 @@ Main({
So(nng_listen(dev1, addr1, NULL, 0) == 0);
So(nng_listen(dev2, addr2, NULL, 0) == 0);
- So(nng_pair_open(&end1) == 0);
- So(nng_pair_open(&end2) == 0);
+ So(nng_pair1_open(&end1) == 0);
+ So(nng_pair1_open(&end2) == 0);
So(nng_dial(end1, addr1, NULL, 0) == 0);
So(nng_dial(end2, addr2, NULL, 0) == 0);
diff --git a/tests/pair1.c b/tests/pair1.c
index 9ed73037..cd3a1035 100644
--- a/tests/pair1.c
+++ b/tests/pair1.c
@@ -10,8 +10,11 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/pair1/pair.h"
#include "trantest.h"
+#include "stubs.h"
+
#include <string.h>
#define SECOND(x) ((x) *1000)
diff --git a/tests/pipeline.c b/tests/pipeline.c
index 67be57c6..96ae3d17 100644
--- a/tests/pipeline.c
+++ b/tests/pipeline.c
@@ -10,6 +10,10 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/pipeline0/pull.h"
+#include "protocol/pipeline0/push.h"
+#include "stubs.h"
+
#include <string.h>
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
diff --git a/tests/pollfd.c b/tests/pollfd.c
index e1965b09..8526c705 100644
--- a/tests/pollfd.c
+++ b/tests/pollfd.c
@@ -8,9 +8,6 @@
// found online at https://opensource.org/licenses/MIT.
//
-#include "convey.h"
-#include "nng.h"
-
#include <string.h>
#ifndef _WIN32
@@ -32,14 +29,21 @@
#endif
+#include "convey.h"
+#include "nng.h"
+#include "protocol/pair1/pair.h"
+#include "protocol/pipeline0/pull.h"
+#include "protocol/pipeline0/push.h"
+#include "stubs.h"
+
TestMain("Poll FDs", {
Convey("Given a connected pair of sockets", {
nng_socket s1;
nng_socket s2;
- So(nng_pair_open(&s1) == 0);
- So(nng_pair_open(&s2) == 0);
+ So(nng_pair1_open(&s1) == 0);
+ So(nng_pair1_open(&s2) == 0);
Reset({
nng_close(s1);
nng_close(s2);
@@ -106,26 +110,25 @@ TestMain("Poll FDs", {
So(nng_getopt(s1, NNG_OPT_RECVFD, &fd, &sz) == 0);
So(sz == sizeof(fd));
});
- Convey("We cannot get a send FD for PULL", {
- nng_socket s3;
- int fd;
- size_t sz;
- So(nng_pull_open(&s3) == 0);
- Reset({ nng_close(s3); });
- sz = sizeof(fd);
- So(nng_getopt(s3, NNG_OPT_SENDFD, &fd, &sz) ==
- NNG_ENOTSUP);
- });
+ });
- Convey("We cannot get a recv FD for PUSH", {
- nng_socket s3;
- int fd;
- size_t sz;
- So(nng_push_open(&s3) == 0);
- Reset({ nng_close(s3); });
- sz = sizeof(fd);
- So(nng_getopt(s3, NNG_OPT_RECVFD, &fd, &sz) ==
- NNG_ENOTSUP);
- });
+ Convey("We cannot get a send FD for PULL", {
+ nng_socket s3;
+ int fd;
+ size_t sz;
+ So(nng_pull0_open(&s3) == 0);
+ Reset({ nng_close(s3); });
+ sz = sizeof(fd);
+ So(nng_getopt(s3, NNG_OPT_SENDFD, &fd, &sz) == NNG_ENOTSUP);
+ });
+
+ Convey("We cannot get a recv FD for PUSH", {
+ nng_socket s3;
+ int fd;
+ size_t sz;
+ So(nng_push0_open(&s3) == 0);
+ Reset({ nng_close(s3); });
+ sz = sizeof(fd);
+ So(nng_getopt(s3, NNG_OPT_RECVFD, &fd, &sz) == NNG_ENOTSUP);
});
})
diff --git a/tests/pubsub.c b/tests/pubsub.c
index a8209a7d..796d951e 100644
--- a/tests/pubsub.c
+++ b/tests/pubsub.c
@@ -10,6 +10,9 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/pubsub0/pub.h"
+#include "protocol/pubsub0/sub.h"
+#include "stubs.h"
#include <string.h>
@@ -34,6 +37,16 @@ TestMain("PUB/SUB pattern", {
nng_msg *msg;
So(nng_recvmsg(pub, &msg, 0) == NNG_ENOTSUP);
});
+
+ Convey("It cannot subscribe", {
+ So(nng_setopt(pub, NNG_OPT_SUB_SUBSCRIBE, "", 0) ==
+ NNG_ENOTSUP);
+ });
+
+ Convey("It cannot unsubscribe", {
+ So(nng_setopt(pub, NNG_OPT_SUB_UNSUBSCRIBE, "", 0) ==
+ NNG_ENOTSUP);
+ });
});
Convey("We can create a SUB socket", {
@@ -48,6 +61,23 @@ TestMain("PUB/SUB pattern", {
So(nng_sendmsg(sub, msg, 0) == NNG_ENOTSUP);
nng_msg_free(msg);
});
+
+ Convey("It can subscribe", {
+ So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "ABC", 3) ==
+ 0);
+ So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "", 0) == 0);
+ Convey("And it can unsubscribe", {
+ So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE,
+ "ABC", 3) == 0);
+ So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "",
+ 0) == 0);
+
+ So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "",
+ 0) == NNG_ENOENT);
+ So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE,
+ "HELLO", 0) == NNG_ENOENT);
+ });
+ });
});
Convey("We can create a linked PUB/SUB pair", {
@@ -73,28 +103,6 @@ TestMain("PUB/SUB pattern", {
nng_msleep(20); // give time for connecting threads
- Convey("Sub can subscribe", {
- So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "ABC", 3) ==
- 0);
- So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "", 0) == 0);
- Convey("Unsubscribe works", {
- So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE,
- "ABC", 3) == 0);
- So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "",
- 0) == 0);
-
- So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "",
- 0) == NNG_ENOENT);
- So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE,
- "HELLO", 0) == NNG_ENOENT);
- });
- });
-
- Convey("Pub cannot subscribe", {
- So(nng_setopt(pub, NNG_OPT_SUB_SUBSCRIBE, "", 0) ==
- NNG_ENOTSUP);
- });
-
Convey("Subs can receive from pubs", {
nng_msg *msg;
diff --git a/tests/reconnect.c b/tests/reconnect.c
index 8179055d..e191f70a 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -10,6 +10,10 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/pipeline0/pull.h"
+#include "protocol/pipeline0/push.h"
+#include "stubs.h"
+
#include <string.h>
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
diff --git a/tests/reqrep.c b/tests/reqrep.c
index df0621bc..4e837c34 100644
--- a/tests/reqrep.c
+++ b/tests/reqrep.c
@@ -10,6 +10,9 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/reqrep0/rep.h"
+#include "protocol/reqrep0/req.h"
+#include "stubs.h"
#include <string.h>
diff --git a/tests/resolv.c b/tests/resolv.c
index 49d258c3..0678b05f 100644
--- a/tests/resolv.c
+++ b/tests/resolv.c
@@ -51,26 +51,6 @@ ip6tostr(void *addr)
// too much on them, since localhost can be configured weirdly. Notably
// the normal assumptions on Linux do *not* hold true.
#if 0
-
- Convey("Localhost IPv4 resolves", {
- nni_aio aio;
- const char *str;
- memset(&aio, 0, sizeof (aio));
- nni_aio_init(&aio, NULL, NULL);
- nni_plat_tcp_resolv("localhost", "80", NNG_AF_INET, 1,
- &aio);
- nni_aio_wait(&aio);
- So(nni_aio_result(&aio) == 0);
- So(aio.a_naddrs == 1);
- So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET);
- So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80));
- So(aio.a_addrs[0].s_un.s_in.sa_addr == ntohl(0x7f000001));
- str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr);
- So(strcmp(str, "127.0.0.1") == 0);
- nni_aio_fini(&aio);
- }
- );
-
Convey("Localhost IPv6 resolves", {
nni_aio aio;
memset(&aio, 0, sizeof (aio));
@@ -87,44 +67,6 @@ ip6tostr(void *addr)
So(strcmp(str, "::1") == 0);
nni_aio_fini(&aio);
}
- );
- Convey("Localhost UNSPEC resolves", {
- nni_aio aio;
- memset(&aio, 0, sizeof (aio));
- const char *str;
- int i;
- nni_aio_init(&aio, NULL, NULL);
- nni_plat_tcp_resolv("localhost", "80", NNG_AF_UNSPEC, 1,
- &aio);
- nni_aio_wait(&aio);
- So(nni_aio_result(&aio) == 0);
- So(aio.a_naddrs == 2);
- for (i = 0; i < 2; i++) {
- switch (aio.a_addrs[i].s_un.s_family) {
- case NNG_AF_INET6:
- So(aio.a_addrs[i].s_un.s_in6.sa_port ==
- ntohs(80));
- str =
- ip6tostr(&aio.a_addrs[i].s_un.s_in6.sa_addr);
- So(strcmp(str, "::1") == 0);
- break;
-
- case NNG_AF_INET:
- So(aio.a_addrs[i].s_un.s_in.sa_port ==
- ntohs(80));
- str =
- ip4tostr(&aio.a_addrs[i].s_un.s_in.sa_addr);
- So(strcmp(str, "127.0.0.1") == 0);
- break;
- default:
- So(1 == 0);
- }
- }
- So(aio.a_addrs[0].s_un.s_family !=
- aio.a_addrs[1].s_un.s_family);
- nni_aio_fini(&aio);
- }
- );
#endif
TestMain("Resolver", {
@@ -179,11 +121,18 @@ TestMain("Resolver", {
So(strcmp(str, "8.8.4.4") == 0);
nni_aio_fini(aio);
});
+
Convey("Numeric v6 resolves", {
nni_aio * aio;
const char * str;
nng_sockaddr sa;
+ // Travis CI has moved some of their services to host that
+ // apparently don't support IPv6 at all. This is very sad.
+ if (getenv("TRAVIS") != NULL) {
+ ConveySkip("IPv6 missing from CI provider");
+ }
+
nni_aio_init(&aio, NULL, NULL);
aio->a_addr = &sa;
nni_plat_tcp_resolv("::1", "80", NNG_AF_INET6, 1, aio);
@@ -230,5 +179,51 @@ TestMain("Resolver", {
nni_aio_fini(aio);
});
+ Convey("Localhost IPv4 resolves", {
+ nni_aio * aio;
+ const char * str;
+ nng_sockaddr sa;
+
+ nni_aio_init(&aio, NULL, NULL);
+ aio->a_addr = &sa;
+ nni_plat_tcp_resolv("localhost", "80", NNG_AF_INET, 1, aio);
+ nni_aio_wait(aio);
+ So(nni_aio_result(aio) == 0);
+ So(sa.s_un.s_in.sa_family == NNG_AF_INET);
+ So(sa.s_un.s_in.sa_port == ntohs(80));
+ So(sa.s_un.s_in.sa_addr == ntohl(0x7f000001));
+ str = ip4tostr(&sa.s_un.s_in.sa_addr);
+ So(strcmp(str, "127.0.0.1") == 0);
+ nni_aio_fini(aio);
+ });
+
+ Convey("Localhost UNSPEC resolves", {
+ nni_aio * aio;
+ const char * str;
+ nng_sockaddr sa;
+
+ nni_aio_init(&aio, NULL, NULL);
+ aio->a_addr = &sa;
+ nni_plat_tcp_resolv("localhost", "80", NNG_AF_UNSPEC, 1, aio);
+ nni_aio_wait(aio);
+ So(nni_aio_result(aio) == 0);
+ So((sa.s_un.s_family == NNG_AF_INET) ||
+ (sa.s_un.s_family == NNG_AF_INET6));
+ switch (sa.s_un.s_family) {
+ case NNG_AF_INET:
+ So(sa.s_un.s_in.sa_port == ntohs(80));
+ So(sa.s_un.s_in.sa_addr == ntohl(0x7f000001));
+ str = ip4tostr(&sa.s_un.s_in.sa_addr);
+ So(strcmp(str, "127.0.0.1") == 0);
+ break;
+ case NNG_AF_INET6:
+ So(sa.s_un.s_in6.sa_port == ntohs(80));
+ str = ip6tostr(&sa.s_un.s_in6.sa_addr);
+ So(strcmp(str, "::1") == 0);
+ break;
+ }
+ nni_aio_fini(aio);
+ });
+
nni_fini();
})
diff --git a/tests/scalability.c b/tests/scalability.c
index b1a9b767..d869d5fc 100644
--- a/tests/scalability.c
+++ b/tests/scalability.c
@@ -11,6 +11,10 @@
#include "convey.h"
#include "nng.h"
+#include "protocol/reqrep0/rep.h"
+#include "protocol/reqrep0/req.h"
+#include "stubs.h"
+
#include <string.h>
static int nclients = 200;
diff --git a/tests/sock.c b/tests/sock.c
index 1c277b46..d3af414a 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -12,6 +12,9 @@
#include "nng.h"
#include "trantest.h"
+#include "protocol/pubsub0/sub.h"
+
+#include "protocol/pair1/pair.h"
#include "stubs.h"
#include <string.h>
diff --git a/tests/stubs.h b/tests/stubs.h
index 780ac772..0641c970 100644
--- a/tests/stubs.h
+++ b/tests/stubs.h
@@ -44,4 +44,51 @@ getms(void)
#endif
}
+int
+nosocket(nng_socket *s)
+{
+ ConveySkip("Protocol unconfigured");
+ return (NNG_ENOTSUP);
+}
+
+#ifndef NNG_HAVE_REQ0
+#define nng_req0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_REP0
+#define nng_rep0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_PUB0
+#define nng_pub0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_SUB0
+#define nng_sub0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_PAIR0
+#define nng_pair0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_PAIR1
+#define nng_pair1_open nosocket
+#endif
+
+#ifndef NNG_HAVE_PUSH0
+#define nng_push0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_PULL0
+#define nng_pull0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_SURVEYOR0
+#define nng_surveyor0_open nosocket
+#endif
+
+#ifndef NNG_HAVE_RESPONDENT0
+#define nng_respondent0_open nosocket
+#endif
+
#endif // STUBS_H
diff --git a/tests/survey.c b/tests/survey.c
index f4fab009..a3a7ba1d 100644
--- a/tests/survey.c
+++ b/tests/survey.c
@@ -9,7 +9,11 @@
//
#include "convey.h"
+
#include "nng.h"
+#include "protocol/survey0/respond.h"
+#include "protocol/survey0/survey.h"
+#include "stubs.h"
#include <string.h>
diff --git a/tests/tcp.c b/tests/tcp.c
index 79fe1893..fdcf458c 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -9,8 +9,11 @@
//
#include "convey.h"
+#include "nng.h"
+#include "protocol/pair1/pair.h"
#include "trantest.h"
+#include "stubs.h"
// TCP tests.
#ifndef _WIN32
diff --git a/tests/tcp6.c b/tests/tcp6.c
index b1695c84..a3e55d18 100644
--- a/tests/tcp6.c
+++ b/tests/tcp6.c
@@ -13,6 +13,9 @@
#include "core/nng_impl.h"
// TCP tests for IPv6.
+#include "protocol/pair1/pair.h"
+
+#include "stubs.h"
static int
has_v6(void)
diff --git a/tests/trantest.h b/tests/trantest.h
index 37763d24..d334c257 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -11,6 +11,8 @@
#include "convey.h"
#include "core/nng_impl.h"
#include "nng.h"
+#include "protocol/reqrep0/rep.h"
+#include "protocol/reqrep0/req.h"
#include <stdlib.h>
#include <string.h>
@@ -30,9 +32,54 @@ unsigned trantest_port = 0;
typedef int (*trantest_proptest_t)(nng_msg *, nng_listener, nng_dialer);
+#ifndef NNG_HAVE_ZEROTIER
+#define nng_zt_register notransport
+#endif
+#ifndef NNG_HAVE_INPROC
+#define nng_inproc_register notransport
+#endif
+#ifndef NNG_HAVE_IPC
+#define nng_ipc_register notransport
+#endif
+#ifndef NNG_HAVE_TCP
+#define nng_tcp_register notransport
+#endif
+
+int
+notransport(void)
+{
+ ConveySkip("Transport not configured");
+ return (NNG_ENOTSUP);
+}
+
+#define CHKTRAN(s, t) \
+ if (strncmp(s, t, strlen(t)) == 0) \
+ notransport()
+
+void
+trantest_checktran(const char *url)
+{
+#ifndef NNG_HAVE_ZEROTIER
+ CHKTRAN(url, "zt:");
+#endif
+#ifndef NNG_HAVE_INPROC
+ CHKTRAN(url, "inproc:");
+#endif
+#ifndef NNG_HAVE_IPC
+ CHKTRAN(url, "ipc:");
+#endif
+#ifndef NNG_HAVE_TCP
+ CHKTRAN(url, "tcp:");
+#endif
+
+ (void) url;
+}
+
void
trantest_next_address(char *out, const char *template)
{
+ trantest_checktran(template);
+
if (trantest_port == 0) {
char *pstr;
trantest_port = 5555;
@@ -56,11 +103,16 @@ void
trantest_init(trantest *tt, const char *addr)
{
trantest_next_address(tt->addr, addr);
+
+#if defined(NNG_HAVE_REQ0) && defined(NNG_HAVE_REP0)
So(nng_req_open(&tt->reqsock) == 0);
So(nng_rep_open(&tt->repsock) == 0);
tt->tran = nni_tran_find(addr);
So(tt->tran != NULL);
+#else
+ ConveySkip("Missing REQ or REP protocols");
+#endif
}
void
diff --git a/tests/zt.c b/tests/zt.c
index 562f4ee1..9680f82d 100644
--- a/tests/zt.c
+++ b/tests/zt.c
@@ -9,9 +9,12 @@
//
#include "convey.h"
+#include "nng.h"
+#include "protocol/pair0/pair.h"
+#include "transport/zerotier/zerotier.h"
#include "trantest.h"
-#include "transport/zerotier/zerotier.h"
+#include "stubs.h"
// zerotier tests.
@@ -35,6 +38,10 @@ mkdir(const char *path, int mode)
#include <unistd.h>
#endif // WIN32
+#ifndef NNG_HAVE_ZEROTIER
+#define nng_zt_network_status_ok 0
+#endif
+
static int
check_props(nng_msg *msg, nng_listener l, nng_dialer d)
{
@@ -197,6 +204,8 @@ TestMain("ZeroTier Transport", {
char addr[NNG_MAXADDRLEN];
int rv;
+ So(nng_zt_register() == 0);
+
snprintf(addr, sizeof(addr), "zt://" NWID ":%u", port);
So(nng_pair_open(&s) == 0);
@@ -240,6 +249,8 @@ TestMain("ZeroTier Transport", {
// uint64_t node = 0xb000072fa6ull; // my personal host
uint64_t node = 0x2d2f619cccull; // my personal host
+ So(nng_zt_register() == 0);
+
snprintf(addr, sizeof(addr), "zt://" NWID "/%llx:%u",
(unsigned long long) node, port);
@@ -258,6 +269,8 @@ TestMain("ZeroTier Transport", {
uint64_t node1 = 0;
uint64_t node2 = 0;
+ So(nng_zt_register() == 0);
+
snprintf(addr, sizeof(addr), "zt://" NWID ":%u", port);
So(nng_pair_open(&s) == 0);
@@ -306,6 +319,7 @@ TestMain("ZeroTier Transport", {
port = 9944;
// uint64_t node = 0xb000072fa6ull; // my personal host
+ So(nng_zt_register() == 0);
snprintf(addr1, sizeof(addr1), "zt://" NWID ":%u", port);