summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-04-30 21:41:40 -0700
committerGarrett D'Amore <garrett@damore.org>2018-05-01 12:27:19 -0700
commit4998964a435fe0f02a2d81b01fdb837214674e72 (patch)
treedc5fe29da0574fc1510ab6f9b23b54ffd68cd97b /tests
parent63bdb2c28bc185096e579d1922d57cb71ecaa36b (diff)
downloadnng-4998964a435fe0f02a2d81b01fdb837214674e72.tar.gz
nng-4998964a435fe0f02a2d81b01fdb837214674e72.tar.bz2
nng-4998964a435fe0f02a2d81b01fdb837214674e72.zip
fixes #381 Want comparators for various types
Diffstat (limited to 'tests')
-rw-r--r--tests/message.c12
-rw-r--r--tests/pair1.c36
-rw-r--r--tests/reconnect.c2
-rw-r--r--tests/sock.c17
-rw-r--r--tests/surveyctx.c10
-rw-r--r--tests/tcp.c2
-rw-r--r--tests/tcp6.c4
-rw-r--r--tests/tls.c6
-rw-r--r--tests/trantest.h78
-rw-r--r--tests/ws.c2
-rw-r--r--tests/wss.c2
-rw-r--r--tests/wssfile.c6
-rw-r--r--tests/zt.c2
13 files changed, 103 insertions, 76 deletions
diff --git a/tests/message.c b/tests/message.c
index bf212b48..7f40cd38 100644
--- a/tests/message.c
+++ b/tests/message.c
@@ -113,13 +113,17 @@ TestMain("Message Tests", {
});
Convey("Pipe retrievals work", {
- nng_pipe p;
+ nng_pipe p = NNG_PIPE_INITIALIZER;
+ nng_pipe p0 = NNG_PIPE_INITIALIZER;
+
+ So(nng_pipe_id(p0) < 0);
p = nng_msg_get_pipe(msg);
- So(p.id == 0);
- p.id = 45;
+ So(nng_pipe_id(p) < 0);
+ memset(&p, 0x22, sizeof(p));
nng_msg_set_pipe(msg, p);
p = nng_msg_get_pipe(msg);
- So(p.id == 45);
+ So(nng_pipe_id(p) != nng_pipe_id(p0));
+ So(nng_pipe_id(p) == 0x22222222);
});
Convey("Message realloc works", {
diff --git a/tests/pair1.c b/tests/pair1.c
index 8a27bc6e..c777725c 100644
--- a/tests/pair1.c
+++ b/tests/pair1.c
@@ -28,14 +28,13 @@
TestMain("PAIRv1 protocol", {
const char * templ = "inproc://pairv1/%u";
char addr[NNG_MAXADDRLEN + 1];
- nng_socket s1;
- nng_socket c1;
- nng_socket c2;
+ nng_socket s1 = NNG_SOCKET_INITIALIZER;
+ nng_socket c1 = NNG_SOCKET_INITIALIZER;
+ nng_socket c2 = NNG_SOCKET_INITIALIZER;
nng_duration tmo;
uint32_t v;
size_t sz;
- s1.id = c1.id = c2.id = 0;
atexit(nng_fini);
Convey("Given a few sockets", {
@@ -44,6 +43,13 @@ TestMain("PAIRv1 protocol", {
So(nng_pair1_open(&c1) == 0);
So(nng_pair1_open(&c2) == 0);
+ So(nng_socket_id(s1) > 0);
+ So(nng_socket_id(c1) > 0);
+ So(nng_socket_id(c2) > 0);
+ So(nng_socket_id(s1) != nng_socket_id(c1));
+ So(nng_socket_id(s1) != nng_socket_id(c2));
+ So(nng_socket_id(c1) != nng_socket_id(c2));
+
Reset({
nng_close(s1);
nng_close(c1);
@@ -211,7 +217,7 @@ TestMain("PAIRv1 protocol", {
So(nng_recvmsg(s1, &msg, 0) == 0);
CHECKSTR(msg, "ONE");
p1 = nng_msg_get_pipe(msg);
- So(p1.id != 0);
+ So(nng_pipe_id(p1) > 0);
nng_msg_free(msg);
So(nng_msg_alloc(&msg, 0) == 0);
@@ -220,10 +226,10 @@ TestMain("PAIRv1 protocol", {
So(nng_recvmsg(s1, &msg, 0) == 0);
CHECKSTR(msg, "TWO");
p2 = nng_msg_get_pipe(msg);
- So(p2.id != 0);
+ So(nng_pipe_id(p2) > 0);
nng_msg_free(msg);
- So(p1.id != p2.id);
+ So(nng_pipe_id(p1) != nng_pipe_id(p2));
So(nng_msg_alloc(&msg, 0) == 0);
@@ -308,7 +314,7 @@ TestMain("PAIRv1 protocol", {
nng_msleep(20);
Convey("Send/recv work", {
- nng_pipe p;
+ nng_pipe p = NNG_PIPE_INITIALIZER;
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "GAMMA");
So(nng_msg_header_append_u32(msg, 1) == 0);
@@ -316,7 +322,8 @@ TestMain("PAIRv1 protocol", {
So(nng_sendmsg(c1, msg, 0) == 0);
So(nng_recvmsg(s1, &msg, 0) == 0);
p = nng_msg_get_pipe(msg);
- So(p.id != 0);
+ So(nng_pipe_id(p) > 0);
+
CHECKSTR(msg, "GAMMA");
So(nng_msg_header_len(msg) == sizeof(uint32_t));
So(nng_msg_header_trim_u32(msg, &hops) == 0);
@@ -332,7 +339,8 @@ TestMain("PAIRv1 protocol", {
So(nng_msg_header_len(msg) == sizeof(uint32_t));
So(nng_msg_header_trim_u32(msg, &hops) == 0);
p = nng_msg_get_pipe(msg);
- So(p.id != 0);
+ So(nng_pipe_id(p) > 0);
+
So(hops == 2);
nng_msg_free(msg);
});
@@ -474,7 +482,7 @@ TestMain("PAIRv1 protocol", {
So(nng_recvmsg(s1, &msg, 0) == 0);
CHECKSTR(msg, "ONE");
p1 = nng_msg_get_pipe(msg);
- So(p1.id != 0);
+ So(nng_pipe_id(p1) > 0);
So(nng_msg_header_trim_u32(msg, &hops) == 0);
So(hops == 1);
nng_msg_free(msg);
@@ -485,12 +493,12 @@ TestMain("PAIRv1 protocol", {
So(nng_recvmsg(s1, &msg, 0) == 0);
CHECKSTR(msg, "TWO");
p2 = nng_msg_get_pipe(msg);
- So(p2.id != 0);
+ So(nng_pipe_id(p2) > 0);
So(nng_msg_header_trim_u32(msg, &hops) == 0);
So(hops == 1);
nng_msg_free(msg);
- So(p1.id != p2.id);
+ So(nng_pipe_id(p1) != nng_pipe_id(p2));
So(nng_msg_alloc(&msg, 0) == 0);
nng_msg_set_pipe(msg, p1);
@@ -518,7 +526,7 @@ TestMain("PAIRv1 protocol", {
So(nng_recvmsg(s1, &msg, 0) == 0);
CHECKSTR(msg, "ONE");
p1 = nng_msg_get_pipe(msg);
- So(p1.id != 0);
+ So(nng_pipe_id(p1) > 0);
nng_msg_free(msg);
nng_close(c1);
diff --git a/tests/reconnect.c b/tests/reconnect.c
index 4cd6cb3a..6b4e8586 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -96,7 +96,7 @@ TestMain("Reconnect works", {
CHECKSTR(msg, "again");
p2 = nng_msg_get_pipe(msg);
nng_msg_free(msg);
- So(p2.id != p1.id);
+ So(nng_pipe_id(p2) != nng_pipe_id(p1));
});
});
});
diff --git a/tests/sock.c b/tests/sock.c
index d6e36235..37b713dd 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -333,10 +333,12 @@ TestMain("Socket Operations", {
Convey("Listening works", {
char * a = "inproc://here";
- nng_listener l;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
+
+ So(nng_listener_id(l) < 0);
rv = nng_listen(s1, a, &l, 0);
So(rv == 0);
- So(l.id != 0);
+ So(nng_listener_id(l) > 0);
Convey("Second listen fails ADDRINUSE", {
rv = nng_listen(s1, a, NULL, 0);
@@ -347,7 +349,8 @@ TestMain("Socket Operations", {
{ So(nng_listener_start(l, 0) == NNG_ESTATE); });
Convey("We can connect to it", {
- nng_socket s2;
+ nng_socket s2 = NNG_SOCKET_INITIALIZER;
+ So(nng_socket_id(s2) < 0);
So(nng_pair_open(&s2) == 0);
Reset({ nng_close(s2); });
So(nng_dial(s2, a, NULL, 0) == 0);
@@ -356,9 +359,13 @@ TestMain("Socket Operations", {
});
Convey("Dialer creation ok", {
- nng_dialer ep;
- char * a = "tcp://127.0.0.1:2929";
+ nng_dialer ep = NNG_DIALER_INITIALIZER;
+ char * a = "tcp://127.0.0.1:2929";
+
+ So(nng_dialer_id(ep) < 0);
So(nng_dialer_create(&ep, s1, a) == 0);
+ So(nng_dialer_id(ep) > 0);
+
Convey("Options work", {
size_t sz;
So(nng_dialer_setopt_size(
diff --git a/tests/surveyctx.c b/tests/surveyctx.c
index f4d8e703..aa36eca1 100644
--- a/tests/surveyctx.c
+++ b/tests/surveyctx.c
@@ -92,7 +92,7 @@ TestMain("Surveyor concurrent contexts", {
atexit(nng_fini);
Convey("We can use Surveyor contexts concurrently", {
- nng_socket surv;
+ nng_socket surv = NNG_SOCKET_INITIALIZER;
So(nng_aio_alloc(&resp_state.aio, (void *) resp_cb, NULL) ==
0);
@@ -145,6 +145,14 @@ TestMain("Surveyor concurrent contexts", {
if ((rv = nng_ctx_open(&ctxs[i], surv)) != 0) {
break;
}
+ if (nng_ctx_id(ctxs[i]) < 0) {
+ Fail("Invalid context ID");
+ break;
+ }
+ if ((i > 0) &&
+ (nng_ctx_id(ctxs[i]) == nng_ctx_id(ctxs[i - 1]))) {
+ Fail("Context IDs not different");
+ }
}
So(rv == 0);
So(i == NCTX);
diff --git a/tests/tcp.c b/tests/tcp.c
index 3d2ecfc8..d29ceb8d 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -30,7 +30,7 @@ check_props_v4(nng_msg *msg)
bool b;
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_sockaddr(p, NNG_OPT_LOCADDR, &la) == 0);
So(la.s_family == NNG_AF_INET);
So(la.s_in.sa_port == htons(trantest_port - 1));
diff --git a/tests/tcp6.c b/tests/tcp6.c
index 80135b33..c023997f 100644
--- a/tests/tcp6.c
+++ b/tests/tcp6.c
@@ -49,7 +49,7 @@ check_props_v6(nng_msg *msg)
nng_sockaddr la;
z = sizeof(nng_sockaddr);
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0);
So(z == sizeof(la));
So(la.s_family == NNG_AF_INET6);
@@ -62,7 +62,7 @@ check_props_v6(nng_msg *msg)
nng_sockaddr ra;
z = sizeof(nng_sockaddr);
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0);
So(z == sizeof(ra));
So(ra.s_family == NNG_AF_INET6);
diff --git a/tests/tls.c b/tests/tls.c
index 71e28deb..8ecf342a 100644
--- a/tests/tls.c
+++ b/tests/tls.c
@@ -114,7 +114,7 @@ check_props_v4(nng_msg *msg)
nng_sockaddr ra;
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
// Typed access
So(nng_pipe_getopt_sockaddr(p, NNG_OPT_LOCADDR, &la) == 0);
@@ -426,7 +426,7 @@ TestMain("TLS Transport", {
So(nng_msg_len(msg) == 6);
So(strcmp(nng_msg_body(msg), "hello") == 0);
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_bool(p, NNG_OPT_TLS_VERIFIED, &b) == 0);
So(b == false);
nng_msg_free(msg);
@@ -468,7 +468,7 @@ TestMain("TLS Transport", {
So(nng_msg_len(msg) == 6);
So(strcmp(nng_msg_body(msg), "hello") == 0);
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_bool(p, NNG_OPT_TLS_VERIFIED, &b) == 0);
So(b == true);
int i;
diff --git a/tests/trantest.h b/tests/trantest.h
index ed1eccb7..de82099c 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -170,9 +170,8 @@ trantest_fini(trantest *tt)
int
trantest_dial(trantest *tt, nng_dialer *dp)
{
- nng_dialer d;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
int rv;
- d.id = 0;
rv = nng_dialer_create(&d, tt->reqsock, tt->addr);
if (rv != 0) {
@@ -196,8 +195,7 @@ int
trantest_listen(trantest *tt, nng_listener *lp)
{
int rv;
- nng_listener l;
- l.id = 0;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
rv = nng_listener_create(&l, tt->repsock, tt->addr);
if (rv != 0) {
@@ -231,13 +229,12 @@ void
trantest_conn_refused(trantest *tt)
{
Convey("Connection refused works", {
- nng_dialer d;
- d.id = 0;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
So(trantest_dial(tt, &d) == NNG_ECONNREFUSED);
- So(d.id == 0);
+ So(nng_dialer_id(d) < 0);
So(trantest_dial(tt, &d) == NNG_ECONNREFUSED);
- So(d.id == 0);
+ So(nng_dialer_id(d) < 0);
});
}
@@ -245,14 +242,15 @@ void
trantest_duplicate_listen(trantest *tt)
{
Convey("Duplicate listen rejected", {
- nng_listener l;
+ nng_listener l1 = NNG_LISTENER_INITIALIZER;
+ nng_listener l2 = NNG_LISTENER_INITIALIZER;
int rv;
- rv = trantest_listen(tt, &l);
+ rv = trantest_listen(tt, &l1);
So(rv == 0);
- So(l.id != 0);
- l.id = 0;
- So(trantest_listen(tt, &l) == NNG_EADDRINUSE);
- So(l.id == 0);
+ So(nng_listener_id(l1) > 0);
+ So(trantest_listen(tt, &l2) == NNG_EADDRINUSE);
+ So(nng_listener_id(l2) < 0);
+ So(nng_listener_id(l1) != nng_listener_id(l2));
});
}
@@ -260,15 +258,16 @@ void
trantest_listen_accept(trantest *tt)
{
Convey("Listen and accept", {
- nng_listener l;
- nng_dialer d;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
+ nng_dialer d0 = NNG_DIALER_INITIALIZER;
So(trantest_listen(tt, &l) == 0);
- So(l.id != 0);
+ So(nng_listener_id(l) > 0);
nng_msleep(200);
- d.id = 0;
So(trantest_dial(tt, &d) == 0);
- So(d.id != 0);
+ So(nng_dialer_id(d) > 0);
+ So(nng_dialer_id(d0) < 0);
});
}
@@ -276,18 +275,19 @@ void
trantest_send_recv(trantest *tt)
{
Convey("Send and recv", {
- nng_listener l;
- nng_dialer d;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
+ nng_pipe p = NNG_PIPE_INITIALIZER;
nng_msg * send;
nng_msg * recv;
size_t len;
- nng_pipe p;
char * url;
So(trantest_listen(tt, &l) == 0);
- So(l.id != 0);
+ So(nng_listener_id(l) > 0);
+
So(trantest_dial(tt, &d) == 0);
- So(d.id != 0);
+ So(nng_dialer_id(d) > 0);
nng_msleep(200); // listener may be behind slightly
@@ -313,7 +313,7 @@ trantest_send_recv(trantest *tt)
So(nng_msg_len(recv) == strlen("acknowledge"));
So(strcmp(nng_msg_body(recv), "acknowledge") == 0);
p = nng_msg_get_pipe(recv);
- So(p.id != 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_string(p, NNG_OPT_URL, &url) == 0);
So(strcmp(url, tt->addr) == 0);
nng_strfree(url);
@@ -325,19 +325,19 @@ void
trantest_send_recv_multi(trantest *tt)
{
Convey("Send and recv multi", {
- nng_listener l;
- nng_dialer d;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
+ nng_pipe p = NNG_PIPE_INITIALIZER;
nng_msg * send;
nng_msg * recv;
- nng_pipe p;
char * url;
int i;
char msgbuf[16];
So(trantest_listen(tt, &l) == 0);
- So(l.id != 0);
+ So(nng_listener_id(l) > 0);
So(trantest_dial(tt, &d) == 0);
- So(d.id != 0);
+ So(nng_dialer_id(d) > 0);
nng_msleep(200); // listener may be behind slightly
@@ -367,7 +367,7 @@ trantest_send_recv_multi(trantest *tt)
So(nng_msg_len(recv) == strlen(msgbuf) + 1);
So(strcmp(nng_msg_body(recv), msgbuf) == 0);
p = nng_msg_get_pipe(recv);
- So(p.id != 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_string(p, NNG_OPT_URL, &url) == 0);
So(strcmp(url, tt->addr) == 0);
nng_strfree(url);
@@ -380,16 +380,16 @@ void
trantest_check_properties(trantest *tt, trantest_proptest_t f)
{
Convey("Properties test", {
- nng_listener l;
- nng_dialer d;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
nng_msg * send;
nng_msg * recv;
int rv;
So(trantest_listen(tt, &l) == 0);
- So(l.id != 0);
+ So(nng_listener_id(l) > 0);
So(trantest_dial(tt, &d) == 0);
- So(d.id != 0);
+ So(nng_dialer_id(d) > 0);
nng_msleep(200); // listener may be behind slightly
@@ -415,8 +415,8 @@ void
trantest_send_recv_large(trantest *tt)
{
Convey("Send and recv large data", {
- nng_listener l;
- nng_dialer d;
+ nng_listener l = NNG_LISTENER_INITIALIZER;
+ nng_dialer d = NNG_DIALER_INITIALIZER;
nng_msg * send;
nng_msg * recv;
char * data;
@@ -430,9 +430,9 @@ trantest_send_recv_large(trantest *tt)
}
So(trantest_listen(tt, &l) == 0);
- So(l.id != 0);
+ So(nng_listener_id(l) > 0);
So(trantest_dial(tt, &d) == 0);
- So(d.id != 0);
+ So(nng_dialer_id(d) > 0);
nng_msleep(200); // listener may be behind slightly
diff --git a/tests/ws.c b/tests/ws.c
index b58ac40f..753f6be9 100644
--- a/tests/ws.c
+++ b/tests/ws.c
@@ -32,7 +32,7 @@ check_props_v4(nng_msg *msg)
size_t len;
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_sockaddr(p, NNG_OPT_LOCADDR, &la) == 0);
So(la.s_family == NNG_AF_INET);
diff --git a/tests/wss.c b/tests/wss.c
index 333af56c..fac33398 100644
--- a/tests/wss.c
+++ b/tests/wss.c
@@ -141,7 +141,7 @@ check_props(nng_msg *msg)
size_t len;
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
z = sizeof(nng_sockaddr);
So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0);
diff --git a/tests/wssfile.c b/tests/wssfile.c
index 6b1d1a7b..9117c277 100644
--- a/tests/wssfile.c
+++ b/tests/wssfile.c
@@ -142,7 +142,7 @@ check_props(nng_msg *msg)
size_t len;
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
// Typed
z = sizeof(nng_sockaddr);
@@ -349,7 +349,7 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
So(nng_msg_len(msg) == 6);
So(strcmp(nng_msg_body(msg), "hello") == 0);
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_bool(p, NNG_OPT_TLS_VERIFIED, &b) == 0);
So(b == false);
nng_msg_free(msg);
@@ -391,7 +391,7 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
So(nng_msg_len(msg) == 6);
So(strcmp(nng_msg_body(msg), "hello") == 0);
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
So(nng_pipe_getopt_bool(p, NNG_OPT_TLS_VERIFIED, &b) == 0);
So(b == true);
nng_msg_free(msg);
diff --git a/tests/zt.c b/tests/zt.c
index d178f334..237cc01a 100644
--- a/tests/zt.c
+++ b/tests/zt.c
@@ -44,7 +44,7 @@ check_props(nng_msg *msg)
{
nng_pipe p;
p = nng_msg_get_pipe(msg);
- So(p.id > 0);
+ So(nng_pipe_id(p) > 0);
// Check local address.
Convey("Local address property works", {