diff options
Diffstat (limited to 'tests/reqrep.c')
| -rw-r--r-- | tests/reqrep.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/reqrep.c b/tests/reqrep.c index 9c45d2d4..4322edda 100644 --- a/tests/reqrep.c +++ b/tests/reqrep.c @@ -32,6 +32,12 @@ Main({ So(nng_protocol(req) == NNG_PROTO_REQ); So(nng_peer(req) == NNG_PROTO_REP); }) + + Convey("Recv with no send fails", { + nng_msg *msg; + rv = nng_recvmsg(req, &msg, 0); + So(rv == NNG_ESTATE); + }) }) Convey("We can create a REP socket", { @@ -48,6 +54,15 @@ Main({ So(nng_protocol(rep) == NNG_PROTO_REP); So(nng_peer(rep) == NNG_PROTO_REQ); }) + + Convey("Send with no recv fails", { + nng_msg *msg; + rv = nng_msg_alloc(&msg, 0); + So(rv == 0); + rv = nng_sendmsg(rep, msg, 0); + So(rv == NNG_ESTATE); + nng_msg_free(msg); + }) }) Convey("We can create a linked REQ/REP pair", { @@ -72,6 +87,35 @@ Main({ rv = nng_dial(req, addr, NULL, NNG_FLAG_SYNCH); So(rv == 0); + + Convey("They can REQ/REP exchange", { + nng_msg *ping; + nng_msg *pong; + char *body; + size_t len; + + So(nng_msg_alloc(&ping, 0) == 0); + So(nng_msg_append(ping, "ping", 5) == 0); + body = nng_msg_body(ping, &len); + So(len == 5); + So(memcmp(body, "ping", 5) == 0); + So(nng_sendmsg(req, ping, 0) == 0); + pong = NULL; + So(nng_recvmsg(rep, &pong, 0) == 0); + So(pong != NULL); + body = nng_msg_body(pong, &len); + So(len == 5); + So(memcmp(body, "ping", 5) == 0); + nng_msg_trim(pong, 5); + So(nng_msg_append(pong, "pong", 5) == 0); + So(nng_sendmsg(rep, pong, 0) == 0); + ping = 0; + So(nng_recvmsg(req, &ping, 0) == 0); + So(ping != NULL); + body = nng_msg_body(ping, &len); + So(len == 5); + So(memcmp(body, "pong", 5) == 0); + }) }) }) }) |
