aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/survey0/survey_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol/survey0/survey_test.c')
-rw-r--r--src/protocol/survey0/survey_test.c540
1 files changed, 240 insertions, 300 deletions
diff --git a/src/protocol/survey0/survey_test.c b/src/protocol/survey0/survey_test.c
index 65395eee..95d27adf 100644
--- a/src/protocol/survey0/survey_test.c
+++ b/src/protocol/survey0/survey_test.c
@@ -8,14 +8,7 @@
// found online at https://opensource.org/licenses/MIT.
//
-#include <string.h>
-
-#include <nng/nng.h>
-#include <nng/protocol/survey0/respond.h>
-#include <nng/protocol/survey0/survey.h>
-
-#include <acutest.h>
-#include <testutil.h>
+#include <nuts.h>
static void
test_surv_identity(void)
@@ -24,18 +17,18 @@ test_surv_identity(void)
int p;
char * n;
- TEST_NNG_PASS(nng_surveyor0_open(&s));
- TEST_NNG_PASS(nng_getopt_int(s, NNG_OPT_PROTO, &p));
- TEST_CHECK(p == NNG_SURVEYOR0_SELF);
- TEST_NNG_PASS(nng_getopt_int(s, NNG_OPT_PEER, &p));
- TEST_CHECK(p == NNG_SURVEYOR0_PEER); // 49
- TEST_NNG_PASS(nng_getopt_string(s, NNG_OPT_PROTONAME, &n));
- TEST_CHECK(strcmp(n, NNG_SURVEYOR0_SELF_NAME) == 0);
+ NUTS_PASS(nng_surveyor0_open(&s));
+ NUTS_PASS(nng_socket_get_int(s, NNG_OPT_PROTO, &p));
+ NUTS_TRUE(p == NNG_SURVEYOR0_SELF);
+ NUTS_PASS(nng_socket_get_int(s, NNG_OPT_PEER, &p));
+ NUTS_TRUE(p == NNG_SURVEYOR0_PEER); // 49
+ NUTS_PASS(nng_socket_get_string(s, NNG_OPT_PROTONAME, &n));
+ NUTS_MATCH(n, NNG_SURVEYOR0_SELF_NAME);
nng_strfree(n);
- TEST_NNG_PASS(nng_getopt_string(s, NNG_OPT_PEERNAME, &n));
- TEST_CHECK(strcmp(n, NNG_SURVEYOR0_PEER_NAME) == 0);
+ NUTS_PASS(nng_socket_get_string(s, NNG_OPT_PEERNAME, &n));
+ NUTS_MATCH(n, NNG_SURVEYOR0_PEER_NAME);
nng_strfree(n);
- TEST_NNG_PASS(nng_close(s));
+ NUTS_CLOSE(s);
}
static void
@@ -47,31 +40,31 @@ test_surv_ttl_option(void)
size_t sz;
const char *opt = NNG_OPT_MAXTTL;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_setopt_int(surv, opt, 1));
- TEST_NNG_FAIL(nng_setopt_int(surv, opt, 0), NNG_EINVAL);
- TEST_NNG_FAIL(nng_setopt_int(surv, opt, -1), NNG_EINVAL);
+ NUTS_PASS(nng_socket_set_int(surv, opt, 1));
+ NUTS_FAIL(nng_socket_set_int(surv, opt, 0), NNG_EINVAL);
+ NUTS_FAIL(nng_socket_set_int(surv, opt, -1), NNG_EINVAL);
// This test will fail if the NNI_MAX_MAX_TTL is changed from the
// builtin default of 15.
- TEST_NNG_FAIL(nng_setopt_int(surv, opt, 16), NNG_EINVAL);
- TEST_NNG_FAIL(nng_setopt_int(surv, opt, 256), NNG_EINVAL);
- TEST_NNG_PASS(nng_setopt_int(surv, opt, 3));
- TEST_NNG_PASS(nng_getopt_int(surv, opt, &v));
- TEST_CHECK(v == 3);
+ NUTS_FAIL(nng_socket_set_int(surv, opt, 16), NNG_EINVAL);
+ NUTS_FAIL(nng_socket_set_int(surv, opt, 256), NNG_EINVAL);
+ NUTS_PASS(nng_socket_set_int(surv, opt, 3));
+ NUTS_PASS(nng_socket_get_int(surv, opt, &v));
+ NUTS_TRUE(v == 3);
v = 0;
sz = sizeof(v);
- TEST_NNG_PASS(nng_getopt(surv, opt, &v, &sz));
- TEST_CHECK(v == 3);
- TEST_CHECK(sz == sizeof(v));
+ NUTS_PASS(nng_socket_get(surv, opt, &v, &sz));
+ NUTS_TRUE(v == 3);
+ NUTS_TRUE(sz == sizeof(v));
- TEST_NNG_FAIL(nng_setopt(surv, opt, "", 1), NNG_EINVAL);
+ NUTS_FAIL(nng_socket_set(surv, opt, "", 1), NNG_EINVAL);
sz = 1;
- TEST_NNG_FAIL(nng_getopt(surv, opt, &v, &sz), NNG_EINVAL);
- TEST_NNG_FAIL(nng_setopt_bool(surv, opt, true), NNG_EBADTYPE);
- TEST_NNG_FAIL(nng_getopt_bool(surv, opt, &b), NNG_EBADTYPE);
+ NUTS_FAIL(nng_socket_get(surv, opt, &v, &sz), NNG_EINVAL);
+ NUTS_FAIL(nng_socket_set_bool(surv, opt, true), NNG_EBADTYPE);
+ NUTS_FAIL(nng_socket_get_bool(surv, opt, &b), NNG_EBADTYPE);
- TEST_NNG_PASS(nng_close(surv));
+ NUTS_CLOSE(surv);
}
static void
@@ -83,17 +76,17 @@ test_surv_survey_time_option(void)
size_t sz = sizeof(b);
const char * opt = NNG_OPT_SURVEYOR_SURVEYTIME;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_setopt_ms(surv, opt, 10));
- TEST_NNG_FAIL(nng_setopt(surv, opt, "", 1), NNG_EINVAL);
- TEST_NNG_FAIL(nng_getopt(surv, opt, &b, &sz), NNG_EINVAL);
- TEST_NNG_FAIL(nng_setopt_bool(surv, opt, true), NNG_EBADTYPE);
- TEST_NNG_FAIL(nng_getopt_bool(surv, opt, &b), NNG_EBADTYPE);
+ NUTS_PASS(nng_socket_set_ms(surv, opt, 10));
+ NUTS_FAIL(nng_socket_set(surv, opt, "", 1), NNG_EINVAL);
+ NUTS_FAIL(nng_socket_get(surv, opt, &b, &sz), NNG_EINVAL);
+ NUTS_FAIL(nng_socket_set_bool(surv, opt, true), NNG_EBADTYPE);
+ NUTS_FAIL(nng_socket_get_bool(surv, opt, &b), NNG_EBADTYPE);
- TEST_NNG_PASS(nng_getopt_ms(surv, opt, &d));
- TEST_CHECK(d == 10);
- TEST_NNG_PASS(nng_close(surv));
+ NUTS_PASS(nng_socket_get_ms(surv, opt, &d));
+ NUTS_TRUE(d == 10);
+ NUTS_CLOSE(surv);
}
void
@@ -102,10 +95,10 @@ test_surv_recv_bad_state(void)
nng_socket surv;
nng_msg * msg = NULL;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_FAIL(nng_recvmsg(surv, &msg, 0), NNG_ESTATE);
- TEST_CHECK(msg == NULL);
- TEST_NNG_PASS(nng_close(surv));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_FAIL(nng_recvmsg(surv, &msg, 0), NNG_ESTATE);
+ NUTS_TRUE(msg == NULL);
+ NUTS_CLOSE(surv);
}
static void
@@ -116,31 +109,31 @@ test_surv_recv_garbage(void)
nng_msg * m;
uint32_t surv_id;
- TEST_NNG_PASS(nng_respondent0_open_raw(&resp));
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, 100));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000));
+ NUTS_PASS(nng_respondent0_open_raw(&resp));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, 100));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SENDTIMEO, 1000));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 1000));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 1000));
- TEST_NNG_PASS(testutil_marry(surv, resp));
+ NUTS_MARRY(surv, resp);
- TEST_NNG_PASS(nng_msg_alloc(&m, 0));
- TEST_NNG_PASS(nng_sendmsg(surv, m, 0));
+ NUTS_PASS(nng_msg_alloc(&m, 0));
+ NUTS_PASS(nng_sendmsg(surv, m, 0));
- TEST_NNG_PASS(nng_recvmsg(resp, &m, 0));
+ NUTS_PASS(nng_recvmsg(resp, &m, 0));
// The message will have a header that contains the 32-bit pipe ID,
// followed by the 32-bit request ID. We will discard the request
// ID before sending it out.
- TEST_CHECK(nng_msg_header_len(m) == 8);
- TEST_NNG_PASS(nng_msg_header_chop_u32(m, &surv_id));
+ NUTS_TRUE(nng_msg_header_len(m) == 8);
+ NUTS_PASS(nng_msg_header_chop_u32(m, &surv_id));
- TEST_NNG_PASS(nng_sendmsg(resp, m, 0));
- TEST_NNG_FAIL(nng_recvmsg(surv, &m, 0), NNG_ETIMEDOUT);
+ NUTS_PASS(nng_sendmsg(resp, m, 0));
+ NUTS_FAIL(nng_recvmsg(surv, &m, 0), NNG_ETIMEDOUT);
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
#define SECOND 1000
@@ -150,188 +143,138 @@ test_surv_resp_exchange(void)
{
nng_socket surv;
nng_socket resp;
- nng_msg * msg = NULL;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
-
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, SECOND));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, SECOND));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, SECOND));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, SECOND));
-
- TEST_NNG_PASS(testutil_marry(resp, surv));
-
- TEST_NNG_PASS(nng_msg_alloc(&msg, 0));
- TEST_NNG_PASS(nng_msg_append(msg, "ping", 5));
- TEST_CHECK(nng_msg_len(msg) == 5);
- TEST_CHECK(strcmp(nng_msg_body(msg), "ping") == 0);
- TEST_NNG_PASS(nng_sendmsg(surv, msg, 0));
- msg = NULL;
- TEST_NNG_PASS(nng_recvmsg(resp, &msg, 0));
- TEST_CHECK(msg != NULL);
- TEST_CHECK(nng_msg_len(msg) == 5);
- TEST_CHECK(strcmp(nng_msg_body(msg), "ping") == 0);
- nng_msg_trim(msg, 5);
- TEST_NNG_PASS(nng_msg_append(msg, "pong", 5));
- TEST_NNG_PASS(nng_sendmsg(resp, msg, 0));
- msg = NULL;
- TEST_NNG_PASS(nng_recvmsg(surv, &msg, 0));
- TEST_CHECK(msg != NULL);
- TEST_CHECK(nng_msg_len(msg) == 5);
- TEST_CHECK(strcmp(nng_msg_body(msg), "pong") == 0);
- nng_msg_free(msg);
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, SECOND));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_RECVTIMEO, SECOND));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SENDTIMEO, SECOND));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, SECOND));
+
+ NUTS_MARRY(resp, surv);
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_SEND(surv, "ping");
+ NUTS_RECV(resp, "ping");
+ NUTS_SEND(resp, "pong");
+ NUTS_RECV(surv, "pong");
+
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
void
test_surv_cancel(void)
{
- nng_msg * abc;
- nng_msg * def;
- nng_msg * cmd;
nng_socket surv;
nng_socket resp;
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
-
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, SECOND));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, SECOND));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 5 * SECOND));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 5 * SECOND));
- TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 16));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_msg_alloc(&abc, 0));
- TEST_NNG_PASS(nng_msg_append(abc, "abc", 4));
- TEST_NNG_PASS(nng_msg_alloc(&def, 0));
- TEST_NNG_PASS(nng_msg_append(def, "def", 4));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, SECOND));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_RECVTIMEO, SECOND));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SENDTIMEO, 5 * SECOND));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 5 * SECOND));
+ NUTS_PASS(nng_socket_set_int(surv, NNG_OPT_SENDBUF, 16));
- TEST_NNG_PASS(testutil_marry(resp, surv));
+ NUTS_MARRY(resp, surv);
// Send req #1 (abc).
- TEST_CHECK(nng_sendmsg(surv, abc, 0) == 0);
+ NUTS_SEND(surv, "abc");
// Sleep a bit. This is so that we ensure that our request gets
// to the far side. (If we cancel too fast, then our outgoing send
// will be canceled before it gets to the peer.)
- testutil_sleep(100);
+ NUTS_SLEEP(100);
// Send the next next request ("def"). Note that
// the RESP side server will have already buffered the receive
// request, and should simply be waiting for us to reply to abc.
- TEST_NNG_PASS(nng_sendmsg(surv, def, 0));
+ NUTS_SEND(surv, "def");
// Receive the first request (should be abc) on the REP server.
- TEST_NNG_PASS(nng_recvmsg(resp, &cmd, 0));
- TEST_ASSERT(cmd != NULL);
- TEST_CHECK(nng_msg_len(cmd) == 4);
- TEST_CHECK(strcmp(nng_msg_body(cmd), "abc") == 0);
+ NUTS_RECV(resp, "abc");
// RESP sends the reply to first command. This will be discarded
// by the SURV socket.
- TEST_NNG_PASS(nng_sendmsg(resp, cmd, 0));
+ NUTS_SEND(resp, "abc");
// Now get the next command from the REP; should be "def".
- TEST_NNG_PASS(nng_recvmsg(resp, &cmd, 0));
- TEST_ASSERT(cmd != NULL);
- TEST_CHECK(nng_msg_len(cmd) == 4);
- TEST_CHECK(strcmp(nng_msg_body(cmd), "def") == 0);
- TEST_MSG("Received body was %s", nng_msg_body(cmd));
+ NUTS_RECV(resp, "def");
// And send it back to REQ.
- TEST_NNG_PASS(nng_sendmsg(resp, cmd, 0));
+ NUTS_SEND(resp, "def");
// Try a req command. This should give back "def"
- TEST_NNG_PASS(nng_recvmsg(surv, &cmd, 0));
- TEST_CHECK(nng_msg_len(cmd) == 4);
- TEST_CHECK(strcmp(nng_msg_body(cmd), "def") == 0);
- nng_msg_free(cmd);
+ NUTS_RECV(surv, "def");
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
void
test_surv_cancel_abort_recv(void)
{
-
- nng_msg * abc;
- nng_msg * def;
- nng_msg * cmd;
nng_aio * aio;
nng_duration time = SECOND * 10; // 10s (kind of never)
nng_socket surv;
nng_socket resp;
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, time));
- TEST_NNG_PASS(nng_setopt_int(surv, NNG_OPT_SENDBUF, 16));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, 5 * SECOND));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 5 * SECOND));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 5 * SECOND));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 5 * SECOND));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, time));
+ NUTS_PASS(nng_socket_set_int(surv, NNG_OPT_SENDBUF, 16));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, 5 * SECOND));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_RECVTIMEO, 5 * SECOND));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SENDTIMEO, 5 * SECOND));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 5 * SECOND));
- TEST_NNG_PASS(nng_msg_alloc(&abc, 0));
- TEST_NNG_PASS(nng_msg_append(abc, "abc", 4));
- TEST_NNG_PASS(nng_msg_alloc(&def, 0));
- TEST_NNG_PASS(nng_msg_append(def, "def", 4));
-
- TEST_NNG_PASS(testutil_marry(resp, surv));
+ NUTS_MARRY(resp, surv);
// Send survey #1 (abc).
- TEST_NNG_PASS(nng_sendmsg(surv, abc, 0));
+ NUTS_SEND(surv, "abc");
// Wait for it to get ot the other side.
- testutil_sleep(100);
+ NUTS_SLEEP(100);
nng_aio_set_timeout(aio, 5 * SECOND);
nng_recv_aio(surv, aio);
// Give time for this recv to post properly.
- testutil_sleep(100);
+ NUTS_SLEEP(100);
// Send the next next request ("def"). Note that
// the respondent side server will have already buffered the receive
// request, and should simply be waiting for us to reply to
// abc.
- TEST_NNG_PASS(nng_sendmsg(surv, def, 0));
+ NUTS_SEND(surv, "def");
// Our pending I/O should have been canceled.
nng_aio_wait(aio);
- TEST_NNG_FAIL(nng_aio_result(aio), NNG_ECANCELED);
+ NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED);
// Receive the first request (should be abc) on the respondent.
- TEST_NNG_PASS(nng_recvmsg(resp, &cmd, 0));
- TEST_CHECK(nng_msg_len(cmd) == 4);
- TEST_CHECK(strcmp(nng_msg_body(cmd), "abc") == 0);
+ NUTS_RECV(resp, "abc");
// Respondent sends the reply to first survey. This will be
// discarded by the SURV socket.
- TEST_CHECK(nng_sendmsg(resp, cmd, 0) == 0);
+ NUTS_SEND(resp, "abc");
// Now get the next survey from the RESP; should be "def".
- TEST_NNG_PASS(nng_recvmsg(resp, &cmd, 0));
- TEST_CHECK(nng_msg_len(cmd) == 4);
- TEST_CHECK(strcmp(nng_msg_body(cmd), "def") == 0);
+ NUTS_RECV(resp, "def");
// And send it back to REQ.
- TEST_NNG_PASS(nng_sendmsg(resp, cmd, 0));
+ NUTS_SEND(resp, "def");
// Try a req command. This should give back "def"
- TEST_NNG_PASS(nng_recvmsg(surv, &cmd, 0));
- TEST_CHECK(nng_msg_len(cmd) == 4);
- TEST_CHECK(strcmp(nng_msg_body(cmd), "def") == 0);
- nng_msg_free(cmd);
+ NUTS_RECV(surv, "def");
nng_aio_free(aio);
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
static void
@@ -340,25 +283,25 @@ test_surv_cancel_post_recv(void)
nng_socket surv;
nng_socket resp;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 1000));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 1000));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, 1000));
- TEST_NNG_PASS(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 1000));
- TEST_NNG_PASS(testutil_marry(surv, resp));
-
- TEST_NNG_SEND_STR(surv, "ONE");
- TEST_NNG_RECV_STR(resp, "ONE");
- TEST_NNG_SEND_STR(resp, "one");
- testutil_sleep(100); // Make sure reply arrives!
- TEST_NNG_SEND_STR(surv, "TWO");
- TEST_NNG_RECV_STR(resp, "TWO");
- TEST_NNG_SEND_STR(resp, "two");
- TEST_NNG_RECV_STR(surv, "two");
-
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SENDTIMEO, 1000));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 1000));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, 1000));
+ NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_RECVTIMEO, 1000));
+ NUTS_MARRY(surv, resp);
+
+ NUTS_SEND(surv, "ONE");
+ NUTS_RECV(resp, "ONE");
+ NUTS_SEND(resp, "one");
+ NUTS_SLEEP(100); // Make sure reply arrives!
+ NUTS_SEND(surv, "TWO");
+ NUTS_RECV(resp, "TWO");
+ NUTS_SEND(resp, "two");
+ NUTS_RECV(surv, "two");
+
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
static void
@@ -368,21 +311,21 @@ test_surv_poll_writeable(void)
nng_socket surv;
nng_socket resp;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_getopt_int(surv, NNG_OPT_SENDFD, &fd));
- TEST_CHECK(fd >= 0);
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_socket_get_int(surv, NNG_OPT_SENDFD, &fd));
+ NUTS_TRUE(fd >= 0);
// Survey is broadcast, so we can always write.
- TEST_CHECK(testutil_pollfd(fd) == true);
+ NUTS_TRUE(nuts_poll_fd(fd));
- TEST_NNG_PASS(testutil_marry(surv, resp));
+ NUTS_MARRY(surv, resp);
// Now it's writable.
- TEST_CHECK(testutil_pollfd(fd) == true);
+ NUTS_TRUE(nuts_poll_fd(fd));
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
void
@@ -393,39 +336,39 @@ test_surv_poll_readable(void)
nng_socket resp;
nng_msg * msg;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_getopt_int(surv, NNG_OPT_RECVFD, &fd));
- TEST_CHECK(fd >= 0);
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_socket_get_int(surv, NNG_OPT_RECVFD, &fd));
+ NUTS_TRUE(fd >= 0);
// Not readable if not connected!
- TEST_CHECK(testutil_pollfd(fd) == false);
+ NUTS_TRUE(nuts_poll_fd(fd) == false);
// Even after connect (no message yet)
- TEST_NNG_PASS(testutil_marry(surv, resp));
- TEST_CHECK(testutil_pollfd(fd) == false);
+ NUTS_MARRY(surv, resp);
+ NUTS_TRUE(nuts_poll_fd(fd) == false);
// But once we send messages, it is.
// We have to send a request, in order to send a reply.
- TEST_NNG_PASS(nng_msg_alloc(&msg, 0));
- TEST_NNG_PASS(nng_msg_append(msg, "xyz", 3));
- TEST_NNG_PASS(nng_sendmsg(surv, msg, 0));
- TEST_NNG_PASS(nng_recvmsg(resp, &msg, 0)); // recv on rep
- TEST_NNG_PASS(nng_sendmsg(resp, msg, 0)); // echo it back
- testutil_sleep(200); // give time for message to arrive
+ NUTS_PASS(nng_msg_alloc(&msg, 0));
+ NUTS_PASS(nng_msg_append(msg, "xyz", 3));
+ NUTS_PASS(nng_sendmsg(surv, msg, 0));
+ NUTS_PASS(nng_recvmsg(resp, &msg, 0)); // recv on rep
+ NUTS_PASS(nng_sendmsg(resp, msg, 0)); // echo it back
+ NUTS_SLEEP(200); // give time for message to arrive
- TEST_CHECK(testutil_pollfd(fd) == true);
+ NUTS_TRUE(nuts_poll_fd(fd) == true);
// and receiving makes it no longer ready
- TEST_NNG_PASS(nng_recvmsg(surv, &msg, 0));
+ NUTS_PASS(nng_recvmsg(surv, &msg, 0));
nng_msg_free(msg);
- TEST_CHECK(testutil_pollfd(fd) == false);
+ NUTS_TRUE(nuts_poll_fd(fd) == false);
// TODO verify unsolicited response
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
static void
@@ -435,14 +378,12 @@ test_surv_ctx_no_poll(void)
nng_socket surv;
nng_ctx ctx;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_ctx_open(&ctx, surv));
- TEST_NNG_FAIL(
- nng_ctx_getopt_int(ctx, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP);
- TEST_NNG_FAIL(
- nng_ctx_getopt_int(ctx, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP);
- TEST_NNG_PASS(nng_ctx_close(ctx));
- TEST_NNG_PASS(nng_close(surv));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_ctx_open(&ctx, surv));
+ NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP);
+ NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP);
+ NUTS_PASS(nng_ctx_close(ctx));
+ NUTS_CLOSE(surv);
}
static void
@@ -454,25 +395,25 @@ test_surv_ctx_recv_nonblock(void)
nng_aio * aio;
nng_msg * msg;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_ctx_open(&ctx, surv));
- TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL));
- TEST_NNG_PASS(nng_msg_alloc(&msg, 0));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_ctx_open(&ctx, surv));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ NUTS_PASS(nng_msg_alloc(&msg, 0));
- TEST_NNG_PASS(testutil_marry(surv, resp));
+ NUTS_MARRY(surv, resp);
nng_aio_set_msg(aio, msg);
nng_ctx_send(ctx, aio);
nng_aio_wait(aio);
- TEST_NNG_PASS(nng_aio_result(aio));
+ NUTS_PASS(nng_aio_result(aio));
nng_aio_set_timeout(aio, 0); // Instant timeout
nng_ctx_recv(ctx, aio);
nng_aio_wait(aio);
- TEST_NNG_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT);
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT);
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
nng_aio_free(aio);
}
@@ -484,17 +425,17 @@ test_surv_ctx_send_nonblock(void)
nng_aio * aio;
nng_msg * msg;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_ctx_open(&ctx, surv));
- TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL));
- TEST_NNG_PASS(nng_msg_alloc(&msg, 0));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_ctx_open(&ctx, surv));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ NUTS_PASS(nng_msg_alloc(&msg, 0));
nng_aio_set_msg(aio, msg);
nng_aio_set_timeout(aio, 0); // Instant timeout
nng_ctx_send(ctx, aio);
nng_aio_wait(aio);
- TEST_NNG_PASS(nng_aio_result(aio)); // We never block
- TEST_NNG_PASS(nng_close(surv));
+ NUTS_PASS(nng_aio_result(aio)); // We never block
+ NUTS_CLOSE(surv);
nng_aio_free(aio);
}
@@ -504,16 +445,16 @@ test_surv_send_best_effort(void)
nng_socket surv;
nng_socket resp;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(testutil_marry(surv, resp));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_MARRY(surv, resp);
for (int i = 0; i < 200; i++) {
- TEST_NNG_SEND_STR(surv, "junk");
+ NUTS_SEND(surv, "junk");
}
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
static void
@@ -524,23 +465,23 @@ test_surv_survey_timeout(void)
char buf[16];
size_t sz;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, 100));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50));
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, 100));
- TEST_NNG_PASS(testutil_marry(surv, resp));
+ NUTS_MARRY(surv, resp);
- TEST_NNG_SEND_STR(surv, "hello");
- TEST_NNG_RECV_STR(resp, "hello");
+ NUTS_SEND(surv, "hello");
+ NUTS_RECV(resp, "hello");
sz = sizeof(buf);
- TEST_NNG_FAIL(nng_recv(surv, buf, &sz, 0), NNG_ETIMEDOUT);
- TEST_NNG_SEND_STR(resp, "world");
- TEST_NNG_FAIL(nng_recv(surv, buf, &sz, 0), NNG_ESTATE);
+ NUTS_FAIL(nng_recv(surv, buf, &sz, 0), NNG_ETIMEDOUT);
+ NUTS_SEND(resp, "world");
+ NUTS_FAIL(nng_recv(surv, buf, &sz, 0), NNG_ESTATE);
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
}
static void
@@ -552,23 +493,23 @@ test_surv_ctx_recv_close_socket(void)
nng_aio * aio;
nng_msg * m;
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(nng_ctx_open(&ctx, surv));
- TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL));
- TEST_NNG_PASS(testutil_marry(surv, resp));
- TEST_NNG_PASS(nng_msg_alloc(&m, 0));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_ctx_open(&ctx, surv));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ NUTS_MARRY(surv, resp);
+ NUTS_PASS(nng_msg_alloc(&m, 0));
nng_aio_set_msg(aio, m);
nng_ctx_send(ctx, aio);
nng_aio_wait(aio);
- TEST_NNG_PASS(nng_aio_result(aio));
+ NUTS_PASS(nng_aio_result(aio));
nng_ctx_recv(ctx, aio);
nng_close(surv);
- TEST_NNG_FAIL(nng_aio_result(aio), NNG_ECLOSED);
+ NUTS_FAIL(nng_aio_result(aio), NNG_ECLOSED);
nng_aio_free(aio);
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(resp);
}
static void
@@ -581,52 +522,52 @@ test_surv_context_multi(void)
nng_msg * m;
int cnt = sizeof(c) / sizeof(c[0]);
- TEST_NNG_PASS(nng_surveyor0_open(&surv));
- TEST_NNG_PASS(nng_respondent0_open(&resp));
- TEST_NNG_PASS(testutil_marry(surv, resp));
- TEST_NNG_PASS(nng_setopt_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 200));
- TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ NUTS_PASS(nng_surveyor0_open(&surv));
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_MARRY(surv, resp);
+ NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 200));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
for (int i = 0; i < cnt; i++) {
- TEST_NNG_PASS(nng_ctx_open(&c[i], surv));
+ NUTS_PASS(nng_ctx_open(&c[i], surv));
}
for (int i = 0; i < cnt; i++) {
- TEST_NNG_PASS(nng_msg_alloc(&m, 0));
- TEST_NNG_PASS(nng_msg_append_u32(m, i));
+ NUTS_PASS(nng_msg_alloc(&m, 0));
+ NUTS_PASS(nng_msg_append_u32(m, i));
nng_aio_set_msg(aio, m);
nng_ctx_send(c[i], aio);
nng_aio_wait(aio);
- TEST_NNG_PASS(nng_aio_result(aio));
+ NUTS_PASS(nng_aio_result(aio));
}
for (int i = 0; i < cnt; i++) {
- TEST_NNG_PASS(nng_recvmsg(resp, &m, 0));
- TEST_NNG_PASS(nng_sendmsg(resp, m, 0));
+ NUTS_PASS(nng_recvmsg(resp, &m, 0));
+ NUTS_PASS(nng_sendmsg(resp, m, 0));
}
for (int i = cnt - 1; i >= 0; i--) {
uint32_t x;
nng_ctx_recv(c[i], aio);
nng_aio_wait(aio);
- TEST_NNG_PASS(nng_aio_result(aio));
+ NUTS_PASS(nng_aio_result(aio));
m = nng_aio_get_msg(aio);
TEST_ASSERT(m != NULL);
- TEST_NNG_PASS(nng_msg_trim_u32(m, &x));
- TEST_CHECK(x == (uint32_t)i);
+ NUTS_PASS(nng_msg_trim_u32(m, &x));
+ NUTS_TRUE(x == (uint32_t) i);
nng_msg_free(m);
}
for (int i = 0; i < cnt; i++) {
nng_ctx_recv(c[i], aio);
nng_aio_wait(aio);
- TEST_CHECK(nng_aio_result(aio) != 0);
+ NUTS_TRUE(nng_aio_result(aio) != 0);
}
for (int i = 0; i < cnt; i++) {
nng_ctx_close(c[i]);
}
- TEST_NNG_PASS(nng_close(surv));
- TEST_NNG_PASS(nng_close(resp));
+ NUTS_CLOSE(surv);
+ NUTS_CLOSE(resp);
nng_aio_free(aio);
}
@@ -636,28 +577,27 @@ test_surv_validate_peer(void)
nng_socket s1, s2;
nng_stat * stats;
nng_stat * reject;
- char addr[64];
-
- testutil_scratch_addr("inproc", sizeof(addr), addr);
+ char * addr;
- TEST_NNG_PASS(nng_surveyor0_open(&s1));
- TEST_NNG_PASS(nng_surveyor0_open(&s2));
+ NUTS_ADDR(addr, "inproc");
+ NUTS_PASS(nng_surveyor0_open(&s1));
+ NUTS_PASS(nng_surveyor0_open(&s2));
- TEST_NNG_PASS(nng_listen(s1, addr, NULL, 0));
- TEST_NNG_PASS(nng_dial(s2, addr, NULL, NNG_FLAG_NONBLOCK));
+ NUTS_PASS(nng_listen(s1, addr, NULL, 0));
+ NUTS_PASS(nng_dial(s2, addr, NULL, NNG_FLAG_NONBLOCK));
- testutil_sleep(100);
- TEST_NNG_PASS(nng_stats_get(&stats));
+ NUTS_SLEEP(100);
+ NUTS_PASS(nng_stats_get(&stats));
- TEST_CHECK(stats != NULL);
- TEST_CHECK((reject = nng_stat_find_socket(stats, s1)) != NULL);
- TEST_CHECK((reject = nng_stat_find(reject, "reject")) != NULL);
+ NUTS_TRUE(stats != NULL);
+ NUTS_TRUE((reject = nng_stat_find_socket(stats, s1)) != NULL);
+ NUTS_TRUE((reject = nng_stat_find(reject, "reject")) != NULL);
- TEST_CHECK(nng_stat_type(reject) == NNG_STAT_COUNTER);
- TEST_CHECK(nng_stat_value(reject) > 0);
+ NUTS_TRUE(nng_stat_type(reject) == NNG_STAT_COUNTER);
+ NUTS_TRUE(nng_stat_value(reject) > 0);
- TEST_NNG_PASS(nng_close(s1));
- TEST_NNG_PASS(nng_close(s2));
+ NUTS_PASS(nng_close(s1));
+ NUTS_PASS(nng_close(s2));
nng_stats_free(stats);
}