From 769f9a2b66aca629eb4dd240a072849a48aa300f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 21 Jan 2017 22:05:55 -0800 Subject: Whoops, forgot to add the pipe implementations to git!! --- tests/CMakeLists.txt | 1 + tests/pollfd.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/pollfd.c (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f6751566..2b7a816e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -64,6 +64,7 @@ add_nng_test(list 5) add_nng_test(platform 5) add_nng_test(reqrep 5) add_nng_test(pipeline 5) +add_nng_test(pollfd 5) add_nng_test(pubsub 5) add_nng_test(sock 5) add_nng_test(survey 5) diff --git a/tests/pollfd.c b/tests/pollfd.c new file mode 100644 index 00000000..899547c6 --- /dev/null +++ b/tests/pollfd.c @@ -0,0 +1,56 @@ +// +// Copyright 2017 Garrett D'Amore +// +// 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" + +#ifdef _WIN32 +#include +#include +#else +#include +#define INVALID_SOCKET -1 +#endif + +// Inproc tests. + +TestMain("Poll FDs", { + + Convey("Given a connected pair of sockets", { + nng_socket s1; + nng_socket s2; + + So(nng_open(&s1, NNG_PROTO_PAIR) == 0); + So(nng_open(&s2, NNG_PROTO_PAIR) == 0); + Reset({ + nng_close(s1); + nng_close(s2); + }) + So(nng_listen(s1, "inproc://yeahbaby", NULL, 0) == 0); + So(nng_dial(s2, "inproc://yeahbaby", NULL, NNG_FLAG_SYNCH) == 0); + + Convey("We can get a recv FD", { + int fd; + size_t sz; + + sz = sizeof (fd); + So(nng_getopt(s1, NNG_OPT_RECVFD, &fd, &sz) == 0); + So(fd != INVALID_SOCKET); + }) + + Convey("We can get a send FD", { + int fd; + size_t sz; + + sz = sizeof (fd); + So(nng_getopt(s1, NNG_OPT_SENDFD, &fd, &sz) == 0); + So(fd != INVALID_SOCKET); + }) + }) +}) -- cgit v1.2.3-70-g09d2