aboutsummaryrefslogtreecommitdiff
path: root/tests/pubsubpollfd.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-01-13 17:27:39 -0800
committerGarrett D'Amore <garrett@damore.org>2020-01-13 17:27:39 -0800
commit01247035ba347af651719864f0b95ee06b561e53 (patch)
tree3da7ad6a740e7a189ed6d247cfb5c7b63dd4a76c /tests/pubsubpollfd.c
parent1f7c978359296c237e4e0e3cbb7f0592a408c3b6 (diff)
downloadnng-01247035ba347af651719864f0b95ee06b561e53.tar.gz
nng-01247035ba347af651719864f0b95ee06b561e53.tar.bz2
nng-01247035ba347af651719864f0b95ee06b561e53.zip
Remove the old PUB/SUB tests.
The new tests are more exhaustive, and cover everything. We also added a case for testing that posting messages that we didn't subscribe too doesn't raise the pollable flag.
Diffstat (limited to 'tests/pubsubpollfd.c')
-rw-r--r--tests/pubsubpollfd.c125
1 files changed, 0 insertions, 125 deletions
diff --git a/tests/pubsubpollfd.c b/tests/pubsubpollfd.c
deleted file mode 100644
index 6a41d5f9..00000000
--- a/tests/pubsubpollfd.c
+++ /dev/null
@@ -1,125 +0,0 @@
-//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
-// Copyright 2019 Behrooze Sirang <behrooze@gmail.com>
-//
-// 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 <string.h>
-
-#ifndef _WIN32
-#include <poll.h>
-#include <unistd.h>
-#define INVALID_SOCKET -1
-#else
-
-#define poll WSAPoll
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-
-#include <windows.h>
-#include <winsock2.h>
-
-#include <mswsock.h>
-#include <ws2tcpip.h>
-
-#endif
-
-#include <nng/nng.h>
-#include <nng/protocol/pubsub0/sub.h>
-#include <nng/protocol/pubsub0/pub.h>
-#include <nng/supplemental/util/platform.h>
-
-#include "convey.h"
-#include "stubs.h"
-
-TestMain("PUBSUB pollable", {
- Convey("Given a connected pair of sockets", {
- nng_socket s1;
- nng_socket s2;
-
- So(nng_pub0_open(&s1) == 0);
- So(nng_sub0_open(&s2) == 0);
- Reset({
- nng_close(s1);
- nng_close(s2);
- });
- So(nng_listen(s1, "inproc://yeahbaby", NULL, 0) == 0);
- So(nng_dial(s2, "inproc://yeahbaby", NULL, 0) == 0);
- So(nng_setopt(s2, NNG_OPT_SUB_SUBSCRIBE, "foo", 3) == 0);
- nng_msleep(50);
-
- Convey("We can get a recv FD", {
- int fd;
- size_t sz;
-
- sz = sizeof(fd);
- So(nng_getopt(s2, NNG_OPT_RECVFD, &fd, &sz) == 0);
- So(fd != (int) INVALID_SOCKET);
-
- Convey("And it is always the same fd", {
- int fd2;
- sz = sizeof(fd2);
- So(nng_getopt(s2, NNG_OPT_RECVFD, &fd2, &sz) ==
- 0);
- So(fd2 == fd);
- });
-
- Convey("And they start non pollable", {
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
- So(poll(&pfd, 1, 0) == 0);
- So(pfd.revents == 0);
- });
-
- Convey("But if we write to subscribed topic they are pollable", {
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
- So(nng_send(s1, "foo:kick", 8, 0) == 0);
- So(poll(&pfd, 1, 100) == 1);
- So((pfd.revents & POLLIN) != 0);
- });
- Convey("And if the topic doesn't match, it is not pollable", {
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
- So(nng_send(s1, "bar:kick", 8, 100) == 0);
- So(poll(&pfd, 1, 0) == 0);
- });
- });
-
- 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 != (int) INVALID_SOCKET);
- So(nng_send(s1, "oops", 4, 0) == 0);
- });
-
- Convey("Must have a big enough size", {
- int fd;
- size_t sz;
- sz = 1;
- So(nng_getopt(s2, NNG_OPT_RECVFD, &fd, &sz) ==
- NNG_EINVAL);
- sz = 128;
- So(nng_getopt(s2, NNG_OPT_RECVFD, &fd, &sz) == 0);
- So(sz == sizeof(fd));
- });
- });
-})