aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-18 12:46:31 -0700
committerGarrett D'Amore <garrett@damore.org>2018-03-18 12:46:31 -0700
commit8b979454d891b84da727a329906c4293fadc5f3c (patch)
treecb491c476080de11c7fc5b5868579f4ef86f4df4 /tests
parent3a2af394a7d94ac5f924aaea6cbad825a9b05d75 (diff)
downloadnng-8b979454d891b84da727a329906c4293fadc5f3c.tar.gz
nng-8b979454d891b84da727a329906c4293fadc5f3c.tar.bz2
nng-8b979454d891b84da727a329906c4293fadc5f3c.zip
fixes #295 boolean options should use C99 bool type
fixes #275 nng_pipe_getopt_ptr() missing? fixes #285 nng_setopt_ptr MIS fixes #297 nng_listener/dialer_close does not validate mode This change adds some missing APIs, and changes others. In particular, certain options are now of type bool, with size of just one. This is a *breaking* change for code that uses those options -- NNG_OPT_RAW, NNG_OPT_PAIR1_POLY, NNG_OPT_TLS_VERIFIED.
Diffstat (limited to 'tests')
-rw-r--r--tests/device.c6
-rw-r--r--tests/pair1.c48
-rw-r--r--tests/pubsub.c2
-rw-r--r--tests/sock.c70
4 files changed, 84 insertions, 42 deletions
diff --git a/tests/device.c b/tests/device.c
index 535371e6..c177a2e5 100644
--- a/tests/device.c
+++ b/tests/device.c
@@ -11,8 +11,8 @@
#include "convey.h"
#include "nng.h"
#include "protocol/pair1/pair.h"
-#include "supplemental/util/platform.h"
#include "stubs.h"
+#include "supplemental/util/platform.h"
#include <string.h>
@@ -54,8 +54,8 @@ Main({
So(nng_pair1_open(&dev1) == 0);
So(nng_pair1_open(&dev2) == 0);
- So(nng_setopt_int(dev1, NNG_OPT_RAW, 1) == 0);
- So(nng_setopt_int(dev2, NNG_OPT_RAW, 1) == 0);
+ So(nng_setopt_bool(dev1, NNG_OPT_RAW, true) == 0);
+ So(nng_setopt_bool(dev2, NNG_OPT_RAW, true) == 0);
struct dev_data ddata;
ddata.s1 = dev1;
diff --git a/tests/pair1.c b/tests/pair1.c
index cd3a1035..bff6a44b 100644
--- a/tests/pair1.c
+++ b/tests/pair1.c
@@ -105,8 +105,10 @@ TestMain("PAIRv1 protocol", {
So(nng_dial(c1, addr, NULL, 0) == 0);
nng_msleep(100);
- So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == NNG_ESTATE);
- So(nng_setopt_int(c1, NNG_OPT_RAW, 1) == NNG_ESTATE);
+ So(nng_setopt_bool(s1, NNG_OPT_RAW, true) ==
+ NNG_ESTATE);
+ So(nng_setopt_bool(c1, NNG_OPT_RAW, false) ==
+ NNG_ESTATE);
});
Convey("Polyamorous mode is best effort", {
@@ -115,7 +117,7 @@ TestMain("PAIRv1 protocol", {
nng_msg * msg;
nng_duration to = MILLISECOND(100);
- So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) == 0);
+ So(nng_setopt_bool(s1, NNG_OPT_PAIR1_POLY, true) == 0);
So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 1) == 0);
So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0);
@@ -170,7 +172,7 @@ TestMain("PAIRv1 protocol", {
So(nng_dial(c1, addr, NULL, 0) == 0);
nng_msleep(100);
- So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) ==
+ So(nng_setopt_bool(s1, NNG_OPT_PAIR1_POLY, true) ==
NNG_ESTATE);
});
@@ -178,9 +180,9 @@ TestMain("PAIRv1 protocol", {
nng_msg *msg;
uint32_t hops;
- So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0);
- So(nng_setopt_int(c1, NNG_OPT_RAW, 1) == 0);
- So(nng_setopt_int(c2, NNG_OPT_RAW, 1) == 0);
+ So(nng_setopt_bool(s1, NNG_OPT_RAW, true) == 0);
+ So(nng_setopt_bool(c1, NNG_OPT_RAW, true) == 0);
+ So(nng_setopt_bool(c2, NNG_OPT_RAW, true) == 0);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
@@ -336,16 +338,16 @@ TestMain("PAIRv1 protocol", {
Convey("Polyamorous cooked mode works", {
nng_msg *msg;
- int v;
+ bool v;
nng_pipe p1;
nng_pipe p2;
- So(nng_getopt_int(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
- So(v == 0);
+ So(nng_getopt_bool(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
+ So(v == false);
- So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) == 0);
- So(nng_getopt_int(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
- So(v == 1);
+ So(nng_setopt_bool(s1, NNG_OPT_PAIR1_POLY, true) == 0);
+ So(nng_getopt_bool(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
+ So(v == true);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
@@ -401,7 +403,7 @@ TestMain("PAIRv1 protocol", {
Convey("Polyamorous default works", {
nng_msg *msg;
- So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) == 0);
+ So(nng_setopt_bool(s1, NNG_OPT_PAIR1_POLY, true) == 0);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
@@ -429,22 +431,22 @@ TestMain("PAIRv1 protocol", {
Convey("Polyamorous raw mode works", {
nng_msg *msg;
- int v;
+ bool v;
uint32_t hops;
nng_pipe p1;
nng_pipe p2;
- So(nng_getopt_int(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
+ So(nng_getopt_bool(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
So(v == 0);
- So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) == 0);
- So(nng_getopt_int(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
- So(v == 1);
+ So(nng_setopt_bool(s1, NNG_OPT_PAIR1_POLY, true) == 0);
+ So(nng_getopt_bool(s1, NNG_OPT_PAIR1_POLY, &v) == 0);
+ So(v == true);
- v = 0;
- So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0);
- So(nng_getopt_int(s1, NNG_OPT_RAW, &v) == 0);
- So(v == 1);
+ v = false;
+ So(nng_setopt_bool(s1, NNG_OPT_RAW, true) == 0);
+ So(nng_getopt_bool(s1, NNG_OPT_RAW, &v) == 0);
+ So(v == true);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
diff --git a/tests/pubsub.c b/tests/pubsub.c
index 3fd95b42..bd0d7f56 100644
--- a/tests/pubsub.c
+++ b/tests/pubsub.c
@@ -151,7 +151,7 @@ TestMain("PUB/SUB pattern", {
nng_msg *msg;
So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0);
- So(nng_setopt_int(sub, NNG_OPT_RAW, 1) == 0);
+ So(nng_setopt_bool(sub, NNG_OPT_RAW, true) == 0);
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "/some/like/it/raw");
diff --git a/tests/sock.c b/tests/sock.c
index f1570fd8..8ff8b002 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -120,12 +120,15 @@ TestMain("Socket Operations", {
});
Convey("RAW option works", {
- int raw;
- So(nng_getopt_int(s1, NNG_OPT_RAW, &raw) == 0);
- So(raw == 0);
- So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0);
- So(nng_getopt_int(s1, NNG_OPT_RAW, &raw) == 0);
- So(raw == 1);
+ bool raw;
+ So(nng_getopt_bool(s1, NNG_OPT_RAW, &raw) ==
+ 0);
+ So(raw == false);
+ So(nng_setopt_bool(s1, NNG_OPT_RAW, true) ==
+ 0);
+ So(nng_getopt_bool(s1, NNG_OPT_RAW, &raw) ==
+ 0);
+ So(raw == true);
});
Convey("URL option works", {
@@ -249,12 +252,14 @@ TestMain("Socket Operations", {
});
Convey("Bogus raw fails", {
+ // Bool type is 1 byte.
So(nng_setopt_int(s1, NNG_OPT_RAW, 42) ==
NNG_EINVAL);
So(nng_setopt_int(s1, NNG_OPT_RAW, -42) ==
NNG_EINVAL);
- So(nng_setopt_int(s1, NNG_OPT_RAW, 0) == 0);
- So(nng_setopt(s1, NNG_OPT_RAW, "a", 1) ==
+ So(nng_setopt_int(s1, NNG_OPT_RAW, 0) ==
+ NNG_EINVAL);
+ So(nng_setopt(s1, NNG_OPT_RAW, "abcd", 4) ==
NNG_EINVAL);
});
@@ -370,12 +375,29 @@ TestMain("Socket Operations", {
ep, NNG_OPT_RECVMAXSZ, &sz) == 0);
So(sz == 4321);
});
+
+ Convey("Cannot access as listener", {
+ bool b;
+ So(nng_listener_getopt_bool(
+ ep, NNG_OPT_RAW, &b) == NNG_ENOENT);
+ So(nng_listener_close(ep) == NNG_ENOENT);
+ });
+
Convey("Socket opts not for dialer", {
// Not appropriate for dialer.
- So(nng_dialer_setopt_int(ep, NNG_OPT_RAW, 1) ==
- NNG_ENOTSUP);
+ So(nng_dialer_setopt_bool(
+ ep, NNG_OPT_RAW, true) == NNG_ENOTSUP);
So(nng_dialer_setopt_ms(ep, NNG_OPT_RECONNMINT,
1) == NNG_ENOTSUP);
+ So(nng_dialer_setopt_string(ep,
+ NNG_OPT_SOCKNAME,
+ "bogus") == NNG_ENOTSUP);
+ });
+
+ Convey("URL is readonly", {
+ So(nng_dialer_setopt_string(ep, NNG_OPT_URL,
+ "tcp://somewhere.else.com:8888") ==
+ NNG_EREADONLY);
});
Convey("Bad size checks", {
So(nng_dialer_setopt(ep, NNG_OPT_RECVMAXSZ,
@@ -398,13 +420,30 @@ TestMain("Socket Operations", {
ep, NNG_OPT_RECVMAXSZ, &sz) == 0);
So(sz == 4321);
});
- Convey("Socket opts not for dialer", {
+ Convey("Cannot access as dialer", {
+ bool b;
+ So(nng_dialer_getopt_bool(
+ ep, NNG_OPT_RAW, &b) == NNG_ENOENT);
+ So(nng_dialer_close(ep) == NNG_ENOENT);
+ });
+
+ Convey("Socket opts not for listener", {
// Not appropriate for dialer.
- So(nng_listener_setopt_int(
- ep, NNG_OPT_RAW, 1) == NNG_ENOTSUP);
+ So(nng_listener_setopt_bool(
+ ep, NNG_OPT_RAW, true) == NNG_ENOTSUP);
So(nng_listener_setopt_ms(ep,
NNG_OPT_RECONNMINT, 1) == NNG_ENOTSUP);
+ So(nng_listener_setopt_string(ep,
+ NNG_OPT_SOCKNAME,
+ "bogus") == NNG_ENOTSUP);
});
+
+ Convey("URL is readonly", {
+ So(nng_listener_setopt_string(ep, NNG_OPT_URL,
+ "tcp://somewhere.else.com:8888") ==
+ NNG_EREADONLY);
+ });
+
Convey("Bad size checks", {
So(nng_listener_setopt(ep, NNG_OPT_RECVMAXSZ,
"a", 1) == NNG_EINVAL);
@@ -417,6 +456,7 @@ TestMain("Socket Operations", {
size_t s;
int i;
nng_duration t;
+ bool b;
So(nng_dialer_setopt_size(
1999, NNG_OPT_RECVMAXSZ, 10) == NNG_ENOENT);
@@ -424,9 +464,9 @@ TestMain("Socket Operations", {
1999, NNG_OPT_RECVMAXSZ, 10) == NNG_ENOENT);
s = 1;
- So(nng_dialer_getopt(1999, NNG_OPT_RAW, &i, &s) ==
+ So(nng_dialer_getopt_bool(1999, NNG_OPT_RAW, &b) ==
NNG_ENOENT);
- So(nng_listener_getopt(1999, NNG_OPT_RAW, &i, &s) ==
+ So(nng_listener_getopt_bool(1999, NNG_OPT_RAW, &b) ==
NNG_ENOENT);
So(nng_dialer_getopt_size(