diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-04 10:43:14 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-04 10:43:14 -0800 |
| commit | 4e8b4ec4396f13665dccc03363c1378cabaefeb4 (patch) | |
| tree | 83639eaa3ba2b94ad517230e3127755c15398c36 /tests | |
| parent | 1d650869f32c56f6d49d898c38f7525191a60bd1 (diff) | |
| download | nng-4e8b4ec4396f13665dccc03363c1378cabaefeb4.tar.gz nng-4e8b4ec4396f13665dccc03363c1378cabaefeb4.tar.bz2 nng-4e8b4ec4396f13665dccc03363c1378cabaefeb4.zip | |
Starting a common transport testing framework.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | tests/inproc.c | 18 | ||||
| -rw-r--r-- | tests/tcp.c | 18 | ||||
| -rw-r--r-- | tests/trantest.h | 82 |
4 files changed, 120 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a63e8fc2..0300a046 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,7 +53,9 @@ else () endif () add_nng_test(idhash 5) +add_nng_test(inproc 5) add_nng_test(list 5) add_nng_test(platform 5) add_nng_test(reqrep 5) add_nng_test(sock 5) +add_nng_test(tcp 5) diff --git a/tests/inproc.c b/tests/inproc.c new file mode 100644 index 00000000..065b604b --- /dev/null +++ b/tests/inproc.c @@ -0,0 +1,18 @@ +// +// 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 "trantest.h" + + +// Inproc tests. + +TestMain("Inproc Transport", { + trantest_test_all("inproc://TEST"); +}) diff --git a/tests/tcp.c b/tests/tcp.c new file mode 100644 index 00000000..b8795c09 --- /dev/null +++ b/tests/tcp.c @@ -0,0 +1,18 @@ +// +// 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 "trantest.h" + + +// Inproc tests. + +TestMain("TCP Transport", { + trantest_test_all("tcp://127.0.0.1:4450"); +}) diff --git a/tests/trantest.h b/tests/trantest.h new file mode 100644 index 00000000..a38db4b0 --- /dev/null +++ b/tests/trantest.h @@ -0,0 +1,82 @@ +// +// 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 "core/nng_impl.h" +#include <string.h> + +// Transport common tests. By making a common test framework for transports, +// we can avoid rewriting the same tests for each new transport. Include this +// file once in your test code. The test framework uses the REQ/REP protocol +// for comms. + +typedef struct { + char addr[NNG_MAXADDRLEN+1]; + nng_socket *reqsock; + nng_socket *repsock; + nni_tran *tran; +} trantest; + +void +trantest_init(trantest *tt, const char *addr) +{ + snprintf(tt->addr, sizeof (tt->addr), "%s", addr); + tt->tran = nni_tran_find(addr); + So(tt->tran != NULL); + So(nng_open(&tt->reqsock, NNG_PROTO_REQ) == 0); + So(nng_open(&tt->repsock, NNG_PROTO_REP) == 0); +} + +void +trantest_fini(trantest *tt) +{ + nng_close(tt->reqsock); + nng_close(tt->repsock); +} + +void +trantest_scheme(trantest *tt) +{ + Convey("Scheme is correct", { + int l = strlen(tt->tran->tran_scheme); + So(strncmp(tt->addr, tt->tran->tran_scheme, l) == 0); + So(strncmp(tt->addr + l, "://", 3) == 0); + }) +} + +void +trantest_conn_refused(trantest *tt) +{ + Convey("Connection refused works", { + nng_endpoint *ep = NULL; + + So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == NNG_ECONNREFUSED); + So(ep == NULL); + So(nng_dial(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) == NNG_ECONNREFUSED); + So(ep == NULL); + }) +} + +void +trantest_test_all(const char *addr) +{ + trantest tt; + + Convey("Given transport", { + trantest_init(&tt, addr); + + Reset({ + trantest_fini(&tt); + }) + + trantest_scheme(&tt); + trantest_conn_refused(&tt); + }) +}
\ No newline at end of file |
