aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-01-12 16:11:19 -0800
committerGarrett D'Amore <garrett@damore.org>2020-01-12 23:03:06 -0800
commit7b4a0a996aa6ed3e8fbbd9fd0e28811725707605 (patch)
treec06211c9972d2b311116c8b4fee536896f38b394 /tests
parent4299a5b4edc59753a6ec857fabedadf1504c4243 (diff)
downloadnng-7b4a0a996aa6ed3e8fbbd9fd0e28811725707605.tar.gz
nng-7b4a0a996aa6ed3e8fbbd9fd0e28811725707605.tar.bz2
nng-7b4a0a996aa6ed3e8fbbd9fd0e28811725707605.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/pubsub.c7
-rw-r--r--tests/testutil.h22
2 files changed, 12 insertions, 17 deletions
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