summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-08 21:19:09 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-09 02:38:55 -0700
commitd64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba (patch)
treef6bdac79578176f0d00528d191f862009e761eac /tests
parent5f0398de8edd1ed4ddbf6455c66273a6608aad9a (diff)
downloadnng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.tar.gz
nng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.tar.bz2
nng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.zip
fixes #44 open protocol by "name" (symbol) instead number
fixes #38 Make protocols "pluggable", or at least optional This is a breaking change, as we've done away with the central registered list of protocols, and instead demand the user call nng_xxx_open() where xxx is a protocol name. (We did keep a table around in the compat framework though.) There is a nice way for protocols to plug in via an nni_proto_open(), where they can use a generic constructor that they use to build a protocol specific constructor (passing their ops vector in.)
Diffstat (limited to 'tests')
-rw-r--r--tests/bus.c61
-rw-r--r--tests/event.c68
-rw-r--r--tests/pipeline.c100
-rw-r--r--tests/pollfd.c174
-rw-r--r--tests/pubsub.c113
-rw-r--r--tests/reqrep.c58
-rw-r--r--tests/scalability.c4
-rw-r--r--tests/sock.c330
-rw-r--r--tests/survey.c240
-rw-r--r--tests/tcp.c24
-rw-r--r--tests/trantest.h4
11 files changed, 613 insertions, 563 deletions
diff --git a/tests/bus.c b/tests/bus.c
index 78740a37..e96a0a53 100644
--- a/tests/bus.c
+++ b/tests/bus.c
@@ -8,14 +8,15 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
-#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
-#define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\
- So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
+#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
+#define CHECKSTR(m, s) \
+ So(nng_msg_len(m) == strlen(s)); \
+ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
Main({
const char *addr = "inproc://test";
@@ -27,54 +28,57 @@ Main({
Convey("We can create a BUS socket", {
nng_socket bus;
- So(nng_open(&bus, NNG_PROTO_BUS) == 0);
+ So(nng_bus_open(&bus) == 0);
- Reset({
- nng_close(bus);
- })
+ Reset({ nng_close(bus); });
Convey("Protocols match", {
So(nng_protocol(bus) == NNG_PROTO_BUS);
So(nng_peer(bus) == NNG_PROTO_BUS);
- })
- })
+ });
+ });
Convey("We can create a linked BUS topology", {
nng_socket bus1;
nng_socket bus2;
nng_socket bus3;
- uint64_t rtimeo;
+ uint64_t rtimeo;
+
+ So(nng_bus_open(&bus1) == 0);
+ So(nng_bus_open(&bus2) == 0);
+ So(nng_bus_open(&bus3) == 0);
- So(nng_open(&bus1, NNG_PROTO_BUS) == 0);
- So(nng_open(&bus2, NNG_PROTO_BUS) == 0);
- So(nng_open(&bus3, NNG_PROTO_BUS) == 0);
-
Reset({
nng_close(bus1);
nng_close(bus2);
nng_close(bus3);
- })
+ });
So(nng_listen(bus1, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(bus2, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(bus3, addr, NULL, NNG_FLAG_SYNCH) == 0);
rtimeo = 50000;
- So(nng_setopt(bus1, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(bus1, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
rtimeo = 50000;
- So(nng_setopt(bus2, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(bus2, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
rtimeo = 50000;
- So(nng_setopt(bus3, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(bus3, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
Convey("Messages delivered", {
nng_msg *msg;
-
// This is just a poor man's sleep.
- So(nng_recvmsg(bus1, &msg, 0) == NNG_ETIMEDOUT);
- So(nng_recvmsg(bus2, &msg, 0) == NNG_ETIMEDOUT);
- So(nng_recvmsg(bus3, &msg, 0) == NNG_ETIMEDOUT);
-
+ So(nng_recvmsg(bus1, &msg, 0) ==
+ NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus2, &msg, 0) ==
+ NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus3, &msg, 0) ==
+ NNG_ETIMEDOUT);
+
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "99bits");
So(nng_sendmsg(bus2, msg, 0) == 0);
@@ -82,7 +86,8 @@ Main({
So(nng_recvmsg(bus1, &msg, 0) == 0);
CHECKSTR(msg, "99bits");
nng_msg_free(msg);
- So(nng_recvmsg(bus3, &msg, 0) == NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus3, &msg, 0) ==
+ NNG_ETIMEDOUT);
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "onthe");
@@ -95,7 +100,7 @@ Main({
So(nng_recvmsg(bus3, &msg, 0) == 0);
CHECKSTR(msg, "onthe");
nng_msg_free(msg);
- })
- })
- })
+ });
+ });
+ });
})
diff --git a/tests/event.c b/tests/event.c
index 4c7014e9..b2d15780 100644
--- a/tests/event.c
+++ b/tests/event.c
@@ -9,21 +9,22 @@
#include "convey.h"
#include "nng.h"
-#include <string.h>
#include <assert.h>
+#include <string.h>
-#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
-#define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\
- So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
+#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
+#define CHECKSTR(m, s) \
+ So(nng_msg_len(m) == strlen(s)); \
+ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
struct evcnt {
nng_socket sock;
- int readable;
- int writeable;
- int pipeadd;
- int piperem;
- int epadd;
- int eprem;
- int err;
+ int readable;
+ int writeable;
+ int pipeadd;
+ int piperem;
+ int epadd;
+ int eprem;
+ int err;
};
void
@@ -68,25 +69,25 @@ Main({
Test("Event Handling", {
Convey("Given a connected pair of pair sockets", {
- nng_socket sock1;
- nng_socket sock2;
+ nng_socket sock1;
+ nng_socket sock2;
struct evcnt evcnt1;
struct evcnt evcnt2;
- nng_notify *notify1;
- nng_notify *notify2;
+ nng_notify * notify1;
+ nng_notify * notify2;
- So(nng_open(&sock1, NNG_PROTO_PAIR) == 0);
- So(nng_open(&sock2, NNG_PROTO_PAIR) == 0);
+ So(nng_pair0_open(&sock1) == 0);
+ So(nng_pair0_open(&sock2) == 0);
- memset(&evcnt1, 0, sizeof (evcnt1));
- memset(&evcnt2, 0, sizeof (evcnt2));
+ memset(&evcnt1, 0, sizeof(evcnt1));
+ memset(&evcnt2, 0, sizeof(evcnt2));
evcnt1.sock = sock1;
evcnt2.sock = sock2;
Reset({
nng_close(sock1);
nng_close(sock2);
- })
+ });
So(nng_listen(sock1, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(sock2, addr, NULL, NNG_FLAG_SYNCH) == 0);
@@ -95,8 +96,12 @@ Main({
nng_usleep(100000);
Convey("We can register callbacks", {
- So((notify1 = nng_setnotify(sock1, NNG_EV_CAN_SND, bump, &evcnt1)) != NULL);
- So((notify2 = nng_setnotify(sock2, NNG_EV_CAN_RCV, bump, &evcnt2)) != NULL);
+ So((notify1 = nng_setnotify(sock1,
+ NNG_EV_CAN_SND, bump, &evcnt1)) !=
+ NULL);
+ So((notify2 = nng_setnotify(sock2,
+ NNG_EV_CAN_RCV, bump, &evcnt2)) !=
+ NULL);
Convey("They are called", {
nng_msg *msg;
@@ -112,27 +117,28 @@ Main({
// this. Probably the msgq needs to
// toggle on reads.
- //nng_usleep(20000);
+ // nng_usleep(20000);
- //So(nng_recvmsg(sock2, &msg, 0) == 0);
+ // So(nng_recvmsg(sock2, &msg, 0) ==
+ // 0);
- //CHECKSTR(msg, "abc");
- //nng_msg_free(msg);
+ // CHECKSTR(msg, "abc");
+ // nng_msg_free(msg);
// The notify runs async...
nng_usleep(100000);
So(evcnt1.writeable == 1);
So(evcnt2.readable == 1);
- })
+ });
Convey("We can unregister them", {
nng_unsetnotify(sock1, notify1);
So(1);
nng_unsetnotify(sock2, notify2);
So(1);
- })
- })
- })
- })
+ });
+ });
+ });
+ });
})
diff --git a/tests/pipeline.c b/tests/pipeline.c
index aa01c2d1..510b7f77 100644
--- a/tests/pipeline.c
+++ b/tests/pipeline.c
@@ -8,13 +8,14 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
-#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
-#define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\
- So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
+#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
+#define CHECKSTR(m, s) \
+ So(nng_msg_len(m) == strlen(s)); \
+ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
Main({
const char *addr = "inproc://test";
@@ -25,58 +26,54 @@ Main({
Convey("We can create a PUSH socket", {
nng_socket push;
- So(nng_open(&push, NNG_PROTO_PUSH) == 0);
+ So(nng_push_open(&push) == 0);
- Reset({
- nng_close(push);
- })
+ Reset({ nng_close(push); });
Convey("Protocols match", {
So(nng_protocol(push) == NNG_PROTO_PUSH);
So(nng_peer(push) == NNG_PROTO_PULL);
- })
+ });
Convey("Recv fails", {
nng_msg *msg;
So(nng_recvmsg(push, &msg, 0) == NNG_ENOTSUP);
- })
- })
+ });
+ });
Convey("We can create a PULL socket", {
nng_socket pull;
- So(nng_open(&pull, NNG_PROTO_PULL) == 0);
+ So(nng_pull_open(&pull) == 0);
- Reset({
- nng_close(pull);
- })
+ Reset({ nng_close(pull); });
Convey("Protocols match", {
So(nng_protocol(pull) == NNG_PROTO_PULL);
So(nng_peer(pull) == NNG_PROTO_PUSH);
- })
+ });
Convey("Send fails", {
nng_msg *msg;
So(nng_msg_alloc(&msg, 0) == 0);
So(nng_sendmsg(pull, msg, 0) == NNG_ENOTSUP);
nng_msg_free(msg);
- })
- })
+ });
+ });
Convey("We can create a linked PUSH/PULL pair", {
nng_socket push;
nng_socket pull;
nng_socket what;
- So(nng_open(&push, NNG_PROTO_PUSH) == 0);
- So(nng_open(&pull, NNG_PROTO_PULL) == 0);
- So(nng_open(&what, NNG_PROTO_PUSH) == 0);
+ So(nng_push_open(&push) == 0);
+ So(nng_pull_open(&pull) == 0);
+ So(nng_push_open(&what) == 0);
Reset({
nng_close(push);
nng_close(pull);
nng_close(what);
- })
+ });
// Its important to avoid a startup race that the
// sender be the dialer. Otherwise you need a delay
@@ -97,30 +94,30 @@ Main({
So(msg != NULL);
CHECKSTR(msg, "hello");
nng_msg_free(msg);
- })
- })
+ });
+ });
Convey("Load balancing", {
- nng_msg *abc;
- nng_msg *def;
- uint64_t usecs;
- int len;
+ nng_msg * abc;
+ nng_msg * def;
+ uint64_t usecs;
+ int len;
nng_socket push;
nng_socket pull1;
nng_socket pull2;
nng_socket pull3;
- So(nng_open(&push, NNG_PROTO_PUSH) == 0);
- So(nng_open(&pull1, NNG_PROTO_PULL) == 0);
- So(nng_open(&pull2, NNG_PROTO_PULL) == 0);
- So(nng_open(&pull3, NNG_PROTO_PULL) == 0);
+ So(nng_push_open(&push) == 0);
+ So(nng_pull_open(&pull1) == 0);
+ So(nng_pull_open(&pull2) == 0);
+ So(nng_pull_open(&pull3) == 0);
Reset({
nng_close(push);
nng_close(pull1);
nng_close(pull2);
nng_close(pull3);
- })
+ });
// We need to increase the buffer from zero, because
// there is no guarantee that the various listeners
@@ -129,14 +126,22 @@ Main({
// ensures that we can write to each stream, even if
// the listeners are not running yet.
len = 4;
- So(nng_setopt(push, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(push, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull1, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull1, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull2, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull2, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull3, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull3, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
+ So(nng_setopt(
+ push, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ push, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull1, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull1, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull2, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull2, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull3, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull3, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
So(nng_msg_alloc(&abc, 0) == 0);
APPENDSTR(abc, "abc");
@@ -144,9 +149,12 @@ Main({
APPENDSTR(def, "def");
usecs = 100000;
- So(nng_setopt(pull1, NNG_OPT_RCVTIMEO, &usecs, sizeof (usecs)) == 0);
- So(nng_setopt(pull2, NNG_OPT_RCVTIMEO, &usecs, sizeof (usecs)) == 0);
- So(nng_setopt(pull3, NNG_OPT_RCVTIMEO, &usecs, sizeof (usecs)) == 0);
+ So(nng_setopt(pull1, NNG_OPT_RCVTIMEO, &usecs,
+ sizeof(usecs)) == 0);
+ So(nng_setopt(pull2, NNG_OPT_RCVTIMEO, &usecs,
+ sizeof(usecs)) == 0);
+ So(nng_setopt(pull3, NNG_OPT_RCVTIMEO, &usecs,
+ sizeof(usecs)) == 0);
So(nng_listen(push, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(pull1, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(pull2, addr, NULL, NNG_FLAG_SYNCH) == 0);
@@ -175,8 +183,8 @@ Main({
So(nng_recvmsg(pull1, &abc, 0) == NNG_ETIMEDOUT);
So(nng_recvmsg(pull2, &abc, 0) == NNG_ETIMEDOUT);
- })
- })
+ });
+ });
nni_fini();
})
diff --git a/tests/pollfd.c b/tests/pollfd.c
index f6b9cf30..e2cd2fb6 100644
--- a/tests/pollfd.c
+++ b/tests/pollfd.c
@@ -11,9 +11,9 @@
#include "nng.h"
#ifndef _WIN32
-#include <unistd.h>
#include <poll.h>
-#define INVALID_SOCKET -1
+#include <unistd.h>
+#define INVALID_SOCKET -1
#else
#define poll WSAPoll
@@ -22,94 +22,92 @@
#endif
#include <windows.h>
-#include <winsock2.h>
+
#include <mswsock.h>
+
+#include <winsock2.h>
#include <ws2tcpip.h>
#endif
-// Inproc tests.
-
-TestMain("Poll FDs", {
-
- Convey("Given a connected pair of sockets", {
- nng_socket s1;
- nng_socket s2;
-
- So(nng_open(&s1, NNG_PROTO_PAIR) == 0);
- So(nng_open(&s2, NNG_PROTO_PAIR) == 0);
- Reset({
- nng_close(s1);
- nng_close(s2);
- })
- So(nng_listen(s1, "inproc://yeahbaby", NULL, 0) == 0);
- nng_usleep(50000);
-
- So(nng_dial(s2, "inproc://yeahbaby", NULL, 0) == 0);
- nng_usleep(50000);
-
- Convey("We can get a recv FD", {
- int fd;
- size_t sz;
-
- sz = sizeof (fd);
- So(nng_getopt(s1, NNG_OPT_RCVFD, &fd, &sz) == 0);
- So(fd != INVALID_SOCKET);
-
- Convey("And they start non pollable", {
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
- So(poll(&pfd, 1, 0) == 0);
- So(pfd.revents == 0);
- })
-
- Convey("But if we write they are pollable", {
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
- So(nng_send(s2, "kick", 5, 0) == 0);
- So(poll(&pfd, 1, 1000) == 1);
- So((pfd.revents & POLLIN) != 0);
- })
- })
-
- Convey("We can get a send FD", {
- int fd;
- size_t sz;
-
- sz = sizeof (fd);
- So(nng_getopt(s1, NNG_OPT_SNDFD, &fd, &sz) == 0);
- So(fd != INVALID_SOCKET);
- So(nng_send(s1, "oops", 4, 0) == 0);
- })
-
- Convey("We cannot get a send FD for PULL", {
- nng_socket s3;
- int fd;
- size_t sz;
- So(nng_open(&s3, NNG_PROTO_PULL) == 0);
- Reset({
- nng_close(s3);
- })
- sz = sizeof (fd);
- So(nng_getopt(s3, NNG_OPT_SNDFD, &fd, &sz) == NNG_ENOTSUP);
- })
-
- Convey("We cannot get a recv FD for PUSH", {
- nng_socket s3;
- int fd;
- size_t sz;
- So(nng_open(&s3, NNG_PROTO_PUSH) == 0);
- Reset({
- nng_close(s3);
- })
- sz = sizeof (fd);
- So(nng_getopt(s3, NNG_OPT_RCVFD, &fd, &sz) == NNG_ENOTSUP);
- })
- })
-})
+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);
+ Reset({
+ nng_close(s1);
+ nng_close(s2);
+ });
+ So(nng_listen(s1, "inproc://yeahbaby", NULL, 0) == 0);
+ nng_usleep(50000);
+
+ So(nng_dial(s2, "inproc://yeahbaby", NULL, 0) == 0);
+ nng_usleep(50000);
+
+ Convey("We can get a recv FD", {
+ int fd;
+ size_t sz;
+
+ sz = sizeof(fd);
+ So(nng_getopt(s1, NNG_OPT_RCVFD, &fd, &sz) == 0);
+ So(fd != INVALID_SOCKET);
+
+ Convey("And they start non pollable", {
+ struct pollfd pfd;
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+
+ So(poll(&pfd, 1, 0) == 0);
+ So(pfd.revents == 0);
+ });
+
+ Convey("But if we write they are pollable", {
+ struct pollfd pfd;
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+
+ So(nng_send(s2, "kick", 5, 0) == 0);
+ So(poll(&pfd, 1, 1000) == 1);
+ So((pfd.revents & POLLIN) != 0);
+ });
+ });
+
+ Convey("We can get a send FD", {
+ int fd;
+ size_t sz;
+
+ sz = sizeof(fd);
+ So(nng_getopt(s1, NNG_OPT_SNDFD, &fd, &sz) == 0);
+ So(fd != INVALID_SOCKET);
+ So(nng_send(s1, "oops", 4, 0) == 0);
+ });
+
+ 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_SNDFD, &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_RCVFD, &fd, &sz) ==
+ NNG_ENOTSUP);
+ });
+ }) })
diff --git a/tests/pubsub.c b/tests/pubsub.c
index 94558f39..19d85848 100644
--- a/tests/pubsub.c
+++ b/tests/pubsub.c
@@ -1,5 +1,6 @@
//
// 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
@@ -8,14 +9,15 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
-#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
-#define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\
- So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
+#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
+#define CHECKSTR(m, s) \
+ So(nng_msg_len(m) == strlen(s)); \
+ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
Main({
const char *addr = "inproc://test";
@@ -25,90 +27,95 @@ Main({
Convey("We can create a PUB socket", {
nng_socket pub;
- So(nng_open(&pub, NNG_PROTO_PUB) == 0);
+ So(nng_pub_open(&pub) == 0);
- Reset({
- nng_close(pub);
- })
+ Reset({ nng_close(pub); });
Convey("Protocols match", {
So(nng_protocol(pub) == NNG_PROTO_PUB);
So(nng_peer(pub) == NNG_PROTO_SUB);
- })
+ });
Convey("Recv fails", {
nng_msg *msg;
So(nng_recvmsg(pub, &msg, 0) == NNG_ENOTSUP);
- })
- })
+ });
+ });
Convey("We can create a SUB socket", {
nng_socket sub;
- So(nng_open(&sub, NNG_PROTO_SUB) == 0);
+ So(nng_sub_open(&sub) == 0);
- Reset({
- nng_close(sub);
- })
+ Reset({ nng_close(sub); });
Convey("Protocols match", {
So(nng_protocol(sub) == NNG_PROTO_SUB);
So(nng_peer(sub) == NNG_PROTO_PUB);
- })
+ });
Convey("Send fails", {
nng_msg *msg;
So(nng_msg_alloc(&msg, 0) == 0);
So(nng_sendmsg(sub, msg, 0) == NNG_ENOTSUP);
nng_msg_free(msg);
- })
- })
+ });
+ });
Convey("We can create a linked PUB/SUB pair", {
nng_socket pub;
nng_socket sub;
- So(nng_open(&pub, NNG_PROTO_PUB) == 0);
+ So(nng_pub_open(&pub) == 0);
- So(nng_open(&sub, NNG_PROTO_SUB) == 0);
+ So(nng_sub_open(&sub) == 0);
Reset({
nng_close(pub);
nng_close(sub);
- })
-
- // Most consumers will usually have the pub listen,
- // and the sub dial. However, this creates a problem
- // for our tests, since we can wind up trying to push
- // data before the pipe is fully registered (the
- // accept runs in an asynch thread.) Doing the reverse
- // here ensures that we won't lose data.
+ });
+
+ // Most consumers will usually have the pub
+ // listen, and the sub dial. However, this
+ // creates a problem for our tests, since we
+ // can wind up trying to push data before the
+ // pipe is fully registered (the accept runs in
+ // an asynch thread.) Doing the reverse here
+ // ensures that we won't lose data.
So(nng_listen(sub, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(pub, addr, NULL, NNG_FLAG_SYNCH) == 0);
Convey("Sub can subscribe", {
- So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "ABC", 3) == 0);
- So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "", 0) == 0);
+ So(nng_setopt(
+ sub, NNG_OPT_SUBSCRIBE, "ABC", 3) == 0);
+ So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "", 0) ==
+ 0);
Convey("Unsubscribe works", {
- So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, "ABC", 3) == 0);
- So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, "", 0) == 0);
-
- So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, "", 0) == NNG_ENOENT);
- So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, "HELLO", 0) == NNG_ENOENT);
- })
- })
+ So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE,
+ "ABC", 3) == 0);
+ So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE,
+ "", 0) == 0);
+
+ So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE,
+ "", 0) == NNG_ENOENT);
+ So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE,
+ "HELLO", 0) == NNG_ENOENT);
+ });
+ });
Convey("Pub cannot subscribe", {
- So(nng_setopt(pub, NNG_OPT_SUBSCRIBE, "", 0) == NNG_ENOTSUP);
- })
+ So(nng_setopt(pub, NNG_OPT_SUBSCRIBE, "", 0) ==
+ NNG_ENOTSUP);
+ });
Convey("Subs can receive from pubs", {
nng_msg *msg;
uint64_t rtimeo;
-
- So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "/some/", strlen("/some/")) == 0);
+ So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "/some/",
+ strlen("/some/")) == 0);
rtimeo = 50000; // 50ms
- So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "/some/like/it/hot");
@@ -132,28 +139,31 @@ Main({
So(nng_recvmsg(sub, &msg, 0) == 0);
CHECKSTR(msg, "/some/day/some/how");
nng_msg_free(msg);
- })
+ });
Convey("Subs without subsciptions don't receive", {
uint64_t rtimeo = 50000; // 50ms
nng_msg *msg;
- So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "/some/don't/like/it");
So(nng_sendmsg(pub, msg, 0) == 0);
So(nng_recvmsg(sub, &msg, 0) == NNG_ETIMEDOUT);
- })
+ });
Convey("Subs in raw receive", {
uint64_t rtimeo = 50000; // 500ms
- int raw = 1;
+ int raw = 1;
nng_msg *msg;
- So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
- So(nng_setopt(sub, NNG_OPT_RAW, &raw, sizeof (raw)) == 0);
+ So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
+ So(nng_setopt(sub, NNG_OPT_RAW, &raw,
+ sizeof(raw)) == 0);
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "/some/like/it/raw");
@@ -161,10 +171,9 @@ Main({
So(nng_recvmsg(sub, &msg, 0) == 0);
CHECKSTR(msg, "/some/like/it/raw");
nng_msg_free(msg);
- })
-
- })
- })
+ });
+ });
+ });
nni_fini();
})
diff --git a/tests/reqrep.c b/tests/reqrep.c
index d4040bdb..cadd0a5f 100644
--- a/tests/reqrep.c
+++ b/tests/reqrep.c
@@ -8,13 +8,13 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
Main({
- int rv;
+ int rv;
const char *addr = "inproc://test";
nni_init();
@@ -22,36 +22,32 @@ Main({
Convey("We can create a REQ socket", {
nng_socket req;
- So(nng_open(&req, NNG_PROTO_REQ) == 0);
+ So(nng_req_open(&req) == 0);
- Reset({
- nng_close(req);
- })
+ Reset({ nng_close(req); });
Convey("Protocols match", {
So(nng_protocol(req) == NNG_PROTO_REQ);
So(nng_peer(req) == NNG_PROTO_REP);
- })
+ });
Convey("Recv with no send fails", {
nng_msg *msg;
rv = nng_recvmsg(req, &msg, 0);
So(rv == NNG_ESTATE);
- })
- })
+ });
+ });
Convey("We can create a REP socket", {
nng_socket rep;
- So(nng_open(&rep, NNG_PROTO_REP) == 0);
+ So(nng_rep_open(&rep) == 0);
- Reset({
- nng_close(rep);
- })
+ Reset({ nng_close(rep); });
Convey("Protocols match", {
So(nng_protocol(rep) == NNG_PROTO_REP);
So(nng_peer(rep) == NNG_PROTO_REQ);
- })
+ });
Convey("Send with no recv fails", {
nng_msg *msg;
@@ -60,21 +56,21 @@ Main({
rv = nng_sendmsg(rep, msg, 0);
So(rv == NNG_ESTATE);
nng_msg_free(msg);
- })
- })
+ });
+ });
Convey("We can create a linked REQ/REP pair", {
nng_socket req;
nng_socket rep;
- So(nng_open(&rep, NNG_PROTO_REP) == 0);
+ So(nng_rep_open(&rep) == 0);
- So(nng_open(&req, NNG_PROTO_REQ) == 0);
+ So(nng_req_open(&req) == 0);
Reset({
nng_close(rep);
nng_close(req);
- })
+ });
So(nng_listen(rep, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(req, addr, NULL, NNG_FLAG_SYNCH) == 0);
@@ -102,31 +98,33 @@ Main({
So(nng_msg_len(ping) == 5);
So(memcmp(nng_msg_body(ping), "pong", 5) == 0);
nng_msg_free(ping);
- })
- })
+ });
+ });
Convey("Request cancellation works", {
nng_msg *abc;
nng_msg *def;
nng_msg *cmd;
- uint64_t retry = 100000; // 100 ms
- size_t len;
+ uint64_t retry = 100000; // 100 ms
+ size_t len;
nng_socket req;
nng_socket rep;
- So(nng_open(&rep, NNG_PROTO_REP) == 0);
+ So(nng_rep_open(&rep) == 0);
- So(nng_open(&req, NNG_PROTO_REQ) == 0);
+ So(nng_req_open(&req) == 0);
Reset({
nng_close(rep);
nng_close(req);
- })
+ });
- So(nng_setopt(req, NNG_OPT_RESENDTIME, &retry, sizeof (retry)) == 0);
+ So(nng_setopt(req, NNG_OPT_RESENDTIME, &retry,
+ sizeof(retry)) == 0);
len = 16;
- So(nng_setopt(req, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
+ So(nng_setopt(
+ req, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
So(nng_msg_alloc(&abc, 0) == 0);
So(nng_msg_append(abc, "abc", 4) == 0);
@@ -149,8 +147,8 @@ Main({
So(nng_msg_len(cmd) == 4);
So(memcmp(nng_msg_body(cmd), "def", 4) == 0);
nng_msg_free(cmd);
- })
- })
+ });
+ });
nni_fini();
})
diff --git a/tests/scalability.c b/tests/scalability.c
index 1e0ea2a9..e9422f8e 100644
--- a/tests/scalability.c
+++ b/tests/scalability.c
@@ -43,7 +43,7 @@ openclients(nng_socket *clients, int num)
int i;
uint64_t t;
for (i = 0; i < num; i++) {
- if ((rv = nng_open(&clients[i], NNG_PROTO_REQ)) != 0) {
+ if ((rv = nng_req_open(&clients[i])) != 0) {
printf("open #%d: %s\n", i, nng_strerror(rv));
return (rv);
}
@@ -120,7 +120,7 @@ Main({
clients = calloc(nclients, sizeof(nng_socket));
results = calloc(nclients, sizeof(int));
- if ((nng_open(&rep, NNG_PROTO_REP) != 0) ||
+ if ((nng_rep_open(&rep) != 0) ||
(nng_setopt(rep, NNG_OPT_RCVBUF, &depth, sizeof(depth)) != 0) ||
(nng_setopt(rep, NNG_OPT_SNDBUF, &depth, sizeof(depth)) != 0) ||
(nng_listen(rep, addr, NULL, NNG_FLAG_SYNCH) != 0) ||
diff --git a/tests/sock.c b/tests/sock.c
index 6c6d5b06..27599e47 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -8,175 +8,185 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
Main({
Test("Socket Operations", {
- Convey("We are able to open a PAIR socket", {
- int rv;
- nng_socket sock;
-
- So(nng_open(&sock, NNG_PROTO_PAIR) == 0);
-
- Reset({
- nng_close(sock);
- })
-
- Convey("And we can shut it down", {
- rv = nng_shutdown(sock);
- So(rv == 0);
- rv = nng_shutdown(sock);
- So(rv == NNG_ECLOSED);
- })
-
- Convey("It's type is still proto", {
- So(nng_protocol(sock) == NNG_PROTO_PAIR);
- })
-
- Convey("Recv with no pipes times out correctly", {
- nng_msg *msg = NULL;
- int64_t when = 100000;
- uint64_t now;
-
- now = nni_clock();
-
- rv = nng_setopt(sock, NNG_OPT_RCVTIMEO, &when,
- sizeof (when));
- So(rv == 0);
- rv = nng_recvmsg(sock, &msg, 0);
- So(rv == NNG_ETIMEDOUT);
- So(msg == NULL);
- So(nni_clock() >= (now + when));
- So(nni_clock() < (now + (when * 2)));
- })
-
- Convey("Recv nonblock with no pipes gives EAGAIN", {
- nng_msg *msg = NULL;
- rv = nng_recvmsg(sock, &msg, NNG_FLAG_NONBLOCK);
- So(rv == NNG_EAGAIN);
- So(msg == NULL);
- })
-
- Convey("Send with no pipes times out correctly", {
- nng_msg *msg = NULL;
- int64_t when = 100000;
- uint64_t now;
-
- // We cheat to get access to the core's clock.
- So(nng_msg_alloc(&msg, 0) == 0);
- So(msg != NULL);
- now = nni_clock();
-
- rv = nng_setopt(sock, NNG_OPT_SNDTIMEO, &when,
- sizeof (when));
- So(rv == 0);
- rv = nng_sendmsg(sock, msg, 0);
- So(rv == NNG_ETIMEDOUT);
- So(nni_clock() >= (now + when));
- So(nni_clock() < (now + (when * 2)));
- nng_msg_free(msg);
- })
-
- Convey("We can set and get options", {
- int64_t when = 1234;
- int64_t check = 0;
- size_t sz;
- rv = nng_setopt(sock, NNG_OPT_SNDTIMEO, &when,
- sizeof (when));
- So(rv == 0);
- sz = sizeof (check);
- Convey("Short size is not copied", {
- sz = 0;
- rv = nng_getopt(sock, NNG_OPT_SNDTIMEO,
- &check, &sz);
+ Convey("We are able to open a PAIR socket", {
+ int rv;
+ nng_socket sock;
+
+ So(nng_pair_open(&sock) == 0);
+
+ Reset({ nng_close(sock); });
+
+ Convey("And we can shut it down", {
+ rv = nng_shutdown(sock);
So(rv == 0);
- So(sz == sizeof (check));
- So(check == 0);
- })
- Convey("Correct size is copied", {
- sz = sizeof (check);
- rv = nng_getopt(sock, NNG_OPT_SNDTIMEO, &check,
- &sz);
+ rv = nng_shutdown(sock);
+ So(rv == NNG_ECLOSED);
+ });
+
+ Convey("It's type is still proto",
+ { So(nng_protocol(sock) == NNG_PROTO_PAIR); });
+
+ Convey("Recv with no pipes times out correctly", {
+ nng_msg *msg = NULL;
+ int64_t when = 100000;
+ uint64_t now;
+
+ now = nni_clock();
+
+ rv = nng_setopt(sock, NNG_OPT_RCVTIMEO, &when,
+ sizeof(when));
So(rv == 0);
- So(sz == sizeof (check));
- So(check == 1234);
- })
- })
-
- Convey("Bogus URLs not supported", {
- Convey("Dialing fails properly", {
- rv = nng_dial(sock, "bogus://somewhere", NULL, 0);
- So(rv == NNG_ENOTSUP);
- })
- Convey("Listening fails properly", {
- rv = nng_listen(sock, "bogus://elsewhere", NULL, 0);
- So(rv == NNG_ENOTSUP);
- })
- })
-
- Convey("Dialing synch can get refused", {
- rv = nng_dial(sock, "inproc://notthere", NULL, NNG_FLAG_SYNCH);
- So(rv == NNG_ECONNREFUSED);
- })
-
- Convey("Listening works", {
- rv = nng_listen(sock, "inproc://here", NULL, NNG_FLAG_SYNCH);
- So(rv == 0);
-
- Convey("Second listen fails ADDRINUSE", {
- rv = nng_listen(sock, "inproc://here", NULL, NNG_FLAG_SYNCH);
- So(rv == NNG_EADDRINUSE);
- })
-
- Convey("We can connect to it", {
- nng_socket sock2;
- So(nng_open(&sock2, NNG_PROTO_PAIR) == 0);
- Reset({
- nng_close(sock2);
+ rv = nng_recvmsg(sock, &msg, 0);
+ So(rv == NNG_ETIMEDOUT);
+ So(msg == NULL);
+ So(nni_clock() >= (now + when));
+ So(nni_clock() < (now + (when * 2)));
+ });
+
+ Convey("Recv nonblock with no pipes gives EAGAIN", {
+ nng_msg *msg = NULL;
+ rv =
+ nng_recvmsg(sock, &msg, NNG_FLAG_NONBLOCK);
+ So(rv == NNG_EAGAIN);
+ So(msg == NULL);
+ });
+
+ Convey("Send with no pipes times out correctly", {
+ nng_msg *msg = NULL;
+ int64_t when = 100000;
+ uint64_t now;
+
+ // We cheat to get access to the core's clock.
+ So(nng_msg_alloc(&msg, 0) == 0);
+ So(msg != NULL);
+ now = nni_clock();
+
+ rv = nng_setopt(sock, NNG_OPT_SNDTIMEO, &when,
+ sizeof(when));
+ So(rv == 0);
+ rv = nng_sendmsg(sock, msg, 0);
+ So(rv == NNG_ETIMEDOUT);
+ So(nni_clock() >= (now + when));
+ So(nni_clock() < (now + (when * 2)));
+ nng_msg_free(msg);
+ });
+
+ Convey("We can set and get options", {
+ int64_t when = 1234;
+ int64_t check = 0;
+ size_t sz;
+ rv = nng_setopt(sock, NNG_OPT_SNDTIMEO, &when,
+ sizeof(when));
+ So(rv == 0);
+ sz = sizeof(check);
+ Convey("Short size is not copied", {
+ sz = 0;
+ rv = nng_getopt(sock, NNG_OPT_SNDTIMEO,
+ &check, &sz);
+ So(rv == 0);
+ So(sz == sizeof(check));
+ So(check == 0);
+ }) Convey("Correct size is copied", {
+ sz = sizeof(check);
+ rv = nng_getopt(sock, NNG_OPT_SNDTIMEO,
+ &check, &sz);
+ So(rv == 0);
+ So(sz == sizeof(check));
+ So(check == 1234);
})
- rv = nng_dial(sock2, "inproc://here", NULL, NNG_FLAG_SYNCH);
+ });
+
+ Convey("Bogus URLs not supported", {
+ Convey("Dialing fails properly", {
+ rv = nng_dial(sock,
+ "bogus://somewhere", NULL, 0);
+ So(rv == NNG_ENOTSUP);
+ });
+ Convey("Listening fails properly", {
+ rv = nng_listen(sock,
+ "bogus://elsewhere", NULL, 0);
+ So(rv == NNG_ENOTSUP);
+ });
+ });
+
+ Convey("Dialing synch can get refused", {
+ rv = nng_dial(sock, "inproc://notthere", NULL,
+ NNG_FLAG_SYNCH);
+ So(rv == NNG_ECONNREFUSED);
+ });
+
+ Convey("Listening works", {
+ rv = nng_listen(sock, "inproc://here", NULL,
+ NNG_FLAG_SYNCH);
So(rv == 0);
- nng_close(sock2);
- })
- })
-
- Convey("We can send and receive messages", {
- nng_socket sock2;
- int len = 1;
- size_t sz;
- uint64_t second = 3000000;
- char *buf;
-
- So(nng_open(&sock2, NNG_PROTO_PAIR) == 0);
- Reset({
- nng_close(sock2);
- })
-
- So(nng_setopt(sock, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(sock, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
-
- So(nng_setopt(sock2, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(sock2, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
-
- So(nng_setopt(sock, NNG_OPT_SNDTIMEO, &second, sizeof (second)) == 0);
- So(nng_setopt(sock, NNG_OPT_RCVTIMEO, &second, sizeof (second)) == 0);
- So(nng_setopt(sock2, NNG_OPT_SNDTIMEO, &second, sizeof (second)) == 0);
- So(nng_setopt(sock2, NNG_OPT_RCVTIMEO, &second, sizeof (second)) == 0);
-
- So(nng_listen(sock, "inproc://test1", NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(sock2, "inproc://test1", NULL, NNG_FLAG_SYNCH) == 0);
-
- So(nng_send(sock, "abc", 4, 0) == 0);
- So(nng_recv(sock2 , &buf, &sz, NNG_FLAG_ALLOC) == 0);
- So(buf != NULL);
- So(sz == 4);
- So(memcmp(buf, "abc", 4) == 0);
- nng_free(buf, sz);
- })
- })
- })
+
+ Convey("Second listen fails ADDRINUSE", {
+ rv = nng_listen(sock, "inproc://here",
+ NULL, NNG_FLAG_SYNCH);
+ So(rv == NNG_EADDRINUSE);
+ });
+
+ Convey("We can connect to it", {
+ nng_socket sock2;
+ So(nng_pair_open(&sock2) == 0);
+ Reset({ nng_close(sock2); });
+ rv = nng_dial(sock2, "inproc://here",
+ NULL, NNG_FLAG_SYNCH);
+ So(rv == 0);
+ nng_close(sock2);
+ });
+ });
+
+ Convey("We can send and receive messages", {
+ nng_socket sock2;
+ int len = 1;
+ size_t sz;
+ uint64_t second = 3000000;
+ char * buf;
+
+ So(nng_pair_open(&sock2) == 0);
+ Reset({ nng_close(sock2); });
+
+ So(nng_setopt(sock, NNG_OPT_RCVBUF, &len,
+ sizeof(len)) == 0);
+ So(nng_setopt(sock, NNG_OPT_SNDBUF, &len,
+ sizeof(len)) == 0);
+
+ So(nng_setopt(sock2, NNG_OPT_RCVBUF, &len,
+ sizeof(len)) == 0);
+ So(nng_setopt(sock2, NNG_OPT_SNDBUF, &len,
+ sizeof(len)) == 0);
+
+ So(nng_setopt(sock, NNG_OPT_SNDTIMEO, &second,
+ sizeof(second)) == 0);
+ So(nng_setopt(sock, NNG_OPT_RCVTIMEO, &second,
+ sizeof(second)) == 0);
+ So(nng_setopt(sock2, NNG_OPT_SNDTIMEO, &second,
+ sizeof(second)) == 0);
+ So(nng_setopt(sock2, NNG_OPT_RCVTIMEO, &second,
+ sizeof(second)) == 0);
+
+ So(nng_listen(sock, "inproc://test1", NULL,
+ NNG_FLAG_SYNCH) == 0);
+ So(nng_dial(sock2, "inproc://test1", NULL,
+ NNG_FLAG_SYNCH) == 0);
+
+ So(nng_send(sock, "abc", 4, 0) == 0);
+ So(nng_recv(
+ sock2, &buf, &sz, NNG_FLAG_ALLOC) == 0);
+ So(buf != NULL);
+ So(sz == 4);
+ So(memcmp(buf, "abc", 4) == 0);
+ nng_free(buf, sz);
+ });
+ });
+ });
})
diff --git a/tests/survey.c b/tests/survey.c
index a7dd3cca..6f85850f 100644
--- a/tests/survey.c
+++ b/tests/survey.c
@@ -1,5 +1,6 @@
//
// 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
@@ -8,14 +9,15 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
-#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
-#define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\
- So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
+#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
+#define CHECKSTR(m, s) \
+ So(nng_msg_len(m) == strlen(s)); \
+ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
Main({
const char *addr = "inproc://test";
@@ -23,113 +25,129 @@ Main({
nni_init();
Test("SURVEY pattern", {
- Convey("We can create a SURVEYOR socket", {
- nng_socket surv;
-
- So(nng_open(&surv, NNG_PROTO_SURVEYOR) == 0);
-
- Reset({
- nng_close(surv);
- })
-
- Convey("Protocols match", {
- So(nng_protocol(surv) == NNG_PROTO_SURVEYOR);
- So(nng_peer(surv) == NNG_PROTO_RESPONDENT);
- })
-
- Convey("Recv with no survey fails", {
- nng_msg *msg;
- So(nng_recvmsg(surv, &msg, 0) == NNG_ESTATE);
- })
-
- Convey("Survey without responder times out", {
- uint64_t expire = 50000;
- nng_msg *msg;
-
- So(nng_setopt(surv, NNG_OPT_SURVEYTIME, &expire, sizeof (expire)) == 0);
- So(nng_msg_alloc(&msg, 0) == 0);
- So(nng_sendmsg(surv, msg, 0) == 0);
- So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT);
- })
- })
-
- Convey("We can create a RESPONDENT socket", {
- nng_socket resp;
- So(nng_open(&resp, NNG_PROTO_RESPONDENT) == 0);
-
- Reset({
- nng_close(resp);
- })
-
- Convey("Protocols match", {
- So(nng_protocol(resp) == NNG_PROTO_RESPONDENT);
- So(nng_peer(resp) == NNG_PROTO_SURVEYOR);
- })
-
- Convey("Send fails with no suvey", {
- nng_msg *msg;
- So(nng_msg_alloc(&msg, 0) == 0);
- So(nng_sendmsg(resp, msg, 0) == NNG_ESTATE);
- nng_msg_free(msg);
- })
- })
-
- Convey("We can create a linked survey pair", {
- nng_socket surv;
- nng_socket resp;
- nng_socket sock;
- uint64_t expire;
-
- So(nng_open(&surv, NNG_PROTO_SURVEYOR) == 0);
- So(nng_open(&resp, NNG_PROTO_RESPONDENT) == 0);
-
- Reset({
- nng_close(surv);
- nng_close(resp);
- })
-
- expire = 50000;
- So(nng_setopt(surv, NNG_OPT_SURVEYTIME, &expire, sizeof (expire)) == 0);
-
- So(nng_listen(surv, addr, NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(resp, addr, NULL, NNG_FLAG_SYNCH) == 0);
-
- // We dial another socket as that will force the
- // earlier dial to have completed *fully*. This is a
- // hack that only works because our listen logic is
- // single threaded.
- So(nng_open(&sock, NNG_PROTO_RESPONDENT) == 0);
- So(nng_dial(sock, addr, NULL, NNG_FLAG_SYNCH) == 0);
- nng_close(sock);
-
- Convey("Survey works", {
- nng_msg *msg;
- uint64_t rtimeo;
-
- So(nng_msg_alloc(&msg, 0) == 0);
- APPENDSTR(msg, "abc");
- So(nng_sendmsg(surv, msg, 0) == 0);
- msg = NULL;
- So(nng_recvmsg(resp, &msg, 0) == 0);
- CHECKSTR(msg, "abc");
- nng_msg_trunc(msg, 3);
- APPENDSTR(msg, "def");
- So(nng_sendmsg(resp, msg, 0) == 0);
- msg = NULL;
- So(nng_recvmsg(surv, &msg, 0) == 0);
- CHECKSTR(msg, "def");
- nng_msg_free(msg);
-
- So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT);
-
- Convey("And goes to non-survey state", {
- rtimeo = 200000;
- So(nng_setopt(surv, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
- So(nng_recvmsg(surv, &msg, 0) == NNG_ESTATE);
- })
- })
- })
- })
+ Convey("We can create a SURVEYOR socket",
+ {
+ nng_socket surv;
+
+ So(nng_surveyor_open(&surv) == 0);
+
+ Reset({ nng_close(surv); });
+
+ Convey("Protocols match", {
+ So(nng_protocol(surv) ==
+ NNG_PROTO_SURVEYOR);
+ So(nng_peer(surv) == NNG_PROTO_RESPONDENT);
+ });
+
+ Convey("Recv with no survey fails", {
+ nng_msg *msg;
+ So(nng_recvmsg(surv, &msg, 0) ==
+ NNG_ESTATE);
+ });
+
+ Convey("Survey without responder times out", {
+ uint64_t expire = 50000;
+ nng_msg *msg;
+
+ So(nng_setopt(surv, NNG_OPT_SURVEYTIME,
+ &expire, sizeof(expire)) == 0);
+ So(nng_msg_alloc(&msg, 0) == 0);
+ So(nng_sendmsg(surv, msg, 0) == 0);
+ So(nng_recvmsg(surv, &msg, 0) ==
+ NNG_ETIMEDOUT);
+ });
+ })
+
+ Convey("We can create a RESPONDENT socket",
+ {
+ nng_socket resp;
+ So(nng_respondent_open(&resp) == 0);
+
+ Reset({ nng_close(resp); });
+
+ Convey("Protocols match", {
+ So(nng_protocol(resp) ==
+ NNG_PROTO_RESPONDENT);
+ So(nng_peer(resp) ==
+ NNG_PROTO_SURVEYOR);
+ });
+
+ Convey("Send fails with no suvey", {
+ nng_msg *msg;
+ So(nng_msg_alloc(&msg, 0) == 0);
+ So(nng_sendmsg(resp, msg, 0) ==
+ NNG_ESTATE);
+ nng_msg_free(msg);
+ });
+ })
+
+ Convey("We can create a linked survey pair", {
+ nng_socket surv;
+ nng_socket resp;
+ nng_socket sock;
+ uint64_t expire;
+
+ So(nng_surveyor_open(&surv) == 0);
+ So(nng_respondent_open(&resp) == 0);
+
+ Reset({
+ nng_close(surv);
+ nng_close(resp);
+ });
+
+ expire = 50000;
+ So(nng_setopt(surv, NNG_OPT_SURVEYTIME,
+ &expire, sizeof(expire)) == 0);
+
+ So(nng_listen(
+ surv, addr, NULL, NNG_FLAG_SYNCH) == 0);
+ So(nng_dial(
+ resp, addr, NULL, NNG_FLAG_SYNCH) == 0);
+
+ // We dial another socket as that will force
+ // the earlier dial to have completed *fully*.
+ // This is a hack that only works because our
+ // listen logic is single threaded.
+ So(nng_respondent_open(&sock) == 0);
+ So(nng_dial(
+ sock, addr, NULL, NNG_FLAG_SYNCH) == 0);
+ nng_close(sock);
+
+ Convey("Survey works", {
+ nng_msg *msg;
+ uint64_t rtimeo;
+
+ So(nng_msg_alloc(&msg, 0) == 0);
+ APPENDSTR(msg, "abc");
+ So(nng_sendmsg(surv, msg, 0) == 0);
+ msg = NULL;
+ So(nng_recvmsg(resp, &msg, 0) == 0);
+ CHECKSTR(msg, "abc");
+ nng_msg_trunc(msg, 3);
+ APPENDSTR(msg, "def");
+ So(nng_sendmsg(resp, msg, 0) == 0);
+ msg = NULL;
+ So(nng_recvmsg(surv, &msg, 0) == 0);
+ CHECKSTR(msg, "def");
+ nng_msg_free(msg);
+
+ So(nng_recvmsg(surv, &msg, 0) ==
+ NNG_ETIMEDOUT);
+
+ Convey(
+ "And goes to non-survey state", {
+ rtimeo = 200000;
+ So(nng_setopt(surv,
+ NNG_OPT_RCVTIMEO,
+ &rtimeo,
+ sizeof(rtimeo)) ==
+ 0);
+ So(nng_recvmsg(surv, &msg,
+ 0) == NNG_ESTATE);
+ });
+ });
+ });
+ });
nni_fini();
})
diff --git a/tests/tcp.c b/tests/tcp.c
index b37e239c..3910cb7f 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -10,36 +10,34 @@
#include "convey.h"
#include "trantest.h"
-
// Inproc tests.
TestMain("TCP Transport", {
trantest_test_all("tcp://127.0.0.1:4450");
-
Convey("We cannot connect to wild cards", {
nng_socket s;
- So(nng_open(&s, NNG_PROTO_PAIR) == 0);
- Reset({
- nng_close(s);
- })
- So(nng_dial(s, "tcp://*:5555", NULL, NNG_FLAG_SYNCH) == NNG_EADDRINVAL);
- })
+ So(nng_pair_open(&s) == 0);
+ Reset({ nng_close(s); });
+ So(nng_dial(s, "tcp://*:5555", NULL, NNG_FLAG_SYNCH) ==
+ NNG_EADDRINVAL);
+ });
Convey("We can bind to wild card", {
nng_socket s1;
nng_socket s2;
- So(nng_open(&s1, NNG_PROTO_PAIR) == 0);
- So(nng_open(&s2, NNG_PROTO_PAIR) == 0);
+ So(nng_pair_open(&s1) == 0);
+ So(nng_pair_open(&s2) == 0);
Reset({
nng_close(s2);
nng_close(s1);
- })
+ });
So(nng_listen(s1, "tcp://*:5771", NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(s2, "tcp://127.0.0.1:5771", NULL, NNG_FLAG_SYNCH) == 0);
- })
+ So(nng_dial(
+ s2, "tcp://127.0.0.1:5771", NULL, NNG_FLAG_SYNCH) == 0);
+ });
nng_fini();
})
diff --git a/tests/trantest.h b/tests/trantest.h
index fe6e5431..173c6b45 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -29,8 +29,8 @@ void
trantest_init(trantest *tt, const char *addr)
{
(void) snprintf(tt->addr, sizeof(tt->addr), "%s", addr);
- So(nng_open(&tt->reqsock, NNG_PROTO_REQ) == 0);
- So(nng_open(&tt->repsock, NNG_PROTO_REP) == 0);
+ So(nng_req_open(&tt->reqsock) == 0);
+ So(nng_rep_open(&tt->repsock) == 0);
tt->tran = nni_tran_find(addr);
So(tt->tran != NULL);