diff options
Diffstat (limited to 'tests/pubsub.c')
| -rw-r--r-- | tests/pubsub.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/tests/pubsub.c b/tests/pubsub.c index a8209a7d..796d951e 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -10,6 +10,9 @@ #include "convey.h" #include "nng.h" +#include "protocol/pubsub0/pub.h" +#include "protocol/pubsub0/sub.h" +#include "stubs.h" #include <string.h> @@ -34,6 +37,16 @@ TestMain("PUB/SUB pattern", { nng_msg *msg; So(nng_recvmsg(pub, &msg, 0) == NNG_ENOTSUP); }); + + Convey("It cannot subscribe", { + So(nng_setopt(pub, NNG_OPT_SUB_SUBSCRIBE, "", 0) == + NNG_ENOTSUP); + }); + + Convey("It cannot unsubscribe", { + So(nng_setopt(pub, NNG_OPT_SUB_UNSUBSCRIBE, "", 0) == + NNG_ENOTSUP); + }); }); Convey("We can create a SUB socket", { @@ -48,6 +61,23 @@ TestMain("PUB/SUB pattern", { So(nng_sendmsg(sub, msg, 0) == NNG_ENOTSUP); nng_msg_free(msg); }); + + Convey("It can subscribe", { + So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "ABC", 3) == + 0); + So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "", 0) == 0); + Convey("And it can unsubscribe", { + So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, + "ABC", 3) == 0); + So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "", + 0) == 0); + + So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "", + 0) == NNG_ENOENT); + So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, + "HELLO", 0) == NNG_ENOENT); + }); + }); }); Convey("We can create a linked PUB/SUB pair", { @@ -73,28 +103,6 @@ TestMain("PUB/SUB pattern", { nng_msleep(20); // give time for connecting threads - Convey("Sub can subscribe", { - So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "ABC", 3) == - 0); - So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "", 0) == 0); - Convey("Unsubscribe works", { - So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, - "ABC", 3) == 0); - So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "", - 0) == 0); - - So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, "", - 0) == NNG_ENOENT); - So(nng_setopt(sub, NNG_OPT_SUB_UNSUBSCRIBE, - "HELLO", 0) == NNG_ENOENT); - }); - }); - - Convey("Pub cannot subscribe", { - So(nng_setopt(pub, NNG_OPT_SUB_SUBSCRIBE, "", 0) == - NNG_ENOTSUP); - }); - Convey("Subs can receive from pubs", { nng_msg *msg; |
