aboutsummaryrefslogtreecommitdiff
path: root/tests/resolv.c
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/resolv.c
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/resolv.c')
-rw-r--r--tests/resolv.c111
1 files changed, 53 insertions, 58 deletions
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();
})