From 7b4a0a996aa6ed3e8fbbd9fd0e28811725707605 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 12 Jan 2020 16:11:19 -0800 Subject: Add PUB/SUB test suite. This gets near 100% coverage of the PUB/SUB protocols. The remaining uncovered bits will need to have a mock protocol that runs slower, so that we can inject both back pressure, and also so that we can inject "erroroneous" messages. --- tests/pubsub.c | 7 ------- tests/testutil.h | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/pubsub.c b/tests/pubsub.c index 68b7e3a4..14bd20fc 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -57,13 +57,6 @@ TestMain("PUB/SUB pattern", { Reset({ nng_close(sub); }); - 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("It can subscribe", { So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "ABC", 3) == 0); diff --git a/tests/testutil.h b/tests/testutil.h index 16e665f2..f28fed5c 100644 --- a/tests/testutil.h +++ b/tests/testutil.h @@ -77,16 +77,18 @@ extern int testutil_marry_ex(nng_socket, nng_socket, nng_pipe *, nng_pipe *); #define TEST_NNG_SEND_STR(sock, string) \ TEST_NNG_PASS(nng_send(sock, string, strlen(string) + 1, 0)) -#define TEST_NNG_RECV_STR(sock, string) \ - do { \ - char * buf_; \ - size_t sz_; \ - int rv_ = nng_recv(sock, &buf_, &sz_, NNG_FLAG_ALLOC); \ - TEST_CHECK_( \ - rv_ == 0, "nng_recv (%d %s)", rv_, nng_strerror(rv_)); \ - TEST_CHECK(sz_ == strlen(string) + 1); \ - TEST_CHECK(strcmp(string, buf_) == 0); \ - nng_free(buf_, sz_); \ +#define TEST_NNG_RECV_STR(sock, string) \ + do { \ + char buf_[64]; \ + size_t sz_ = sizeof(buf_); \ + int rv_ = nng_recv(sock, &buf_, &sz_, 0); \ + TEST_CHECK_( \ + rv_ == 0, "nng_recv (%d %s)", rv_, nng_strerror(rv_)); \ + TEST_CHECK_(sz_ == strlen(string) + 1, "length %d want %d", \ + sz_, strlen(string) + 1); \ + buf_[sizeof(buf_) - 1] = '\0'; \ + TEST_CHECK_( \ + strcmp(string, buf_) == 0, "%s == %s", string, buf_); \ } while (0) #ifdef __cplusplus -- cgit v1.2.3-70-g09d2