diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-02 14:37:42 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-02 14:37:42 -0800 |
| commit | ec2b1275153487fda661942d9b98aab2567b612e (patch) | |
| tree | 4e1457b1bbf57341ea569013892550a988457e09 /tests | |
| parent | b6374f9d9b07c929522066f27ed9a7a05c6bb23b (diff) | |
| download | nng-ec2b1275153487fda661942d9b98aab2567b612e.tar.gz nng-ec2b1275153487fda661942d9b98aab2567b612e.tar.bz2 nng-ec2b1275153487fda661942d9b98aab2567b612e.zip | |
Begin testing REQ/REP.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/reqrep.c | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0a225c7e..a63e8fc2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -55,4 +55,5 @@ endif () add_nng_test(idhash 5) add_nng_test(list 5) add_nng_test(platform 5) +add_nng_test(reqrep 5) add_nng_test(sock 5) diff --git a/tests/reqrep.c b/tests/reqrep.c new file mode 100644 index 00000000..9c45d2d4 --- /dev/null +++ b/tests/reqrep.c @@ -0,0 +1,77 @@ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "convey.h" +#include "nng.h" + +#include <string.h> + +Main({ + int rv; + const char *addr = "inproc://test"; + + Test("REQ/REP pattern", { + Convey("We can create a REQ socket", { + nng_socket *req; + + rv = nng_open(&req, NNG_PROTO_REQ); + So(rv == 0); + So(req != NULL); + + Reset({ + nng_close(req); + }) + + Convey("Protocols match", { + So(nng_protocol(req) == NNG_PROTO_REQ); + So(nng_peer(req) == NNG_PROTO_REP); + }) + }) + + Convey("We can create a REP socket", { + nng_socket *rep; + rv = nng_open(&rep, NNG_PROTO_REP); + So(rv == 0); + So(rep != NULL); + + Reset({ + nng_close(rep); + }) + + Convey("Protocols match", { + So(nng_protocol(rep) == NNG_PROTO_REP); + So(nng_peer(rep) == NNG_PROTO_REQ); + }) + }) + + Convey("We can create a linked REQ/REP pair", { + nng_socket *req; + nng_socket *rep; + + rv = nng_open(&rep, NNG_PROTO_REP); + So(rv == 0); + So(rep != NULL); + + rv = nng_open(&req, NNG_PROTO_REQ); + So(rv == 0); + So(req != NULL); + + Reset({ + nng_close(rep); + nng_close(req); + }) + + rv = nng_listen(rep, addr, NULL, NNG_FLAG_SYNCH); + So(rv == 0); + + rv = nng_dial(req, addr, NULL, NNG_FLAG_SYNCH); + So(rv == 0); + }) + }) +}) |
