From a5807e45b1badfb5d0cb4f697e1873a8ece59a30 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 3 Nov 2024 01:24:38 -0700 Subject: Add some more tests for sub coverage. --- src/sp/protocol/pubsub0/sub_test.c | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/sp/protocol') diff --git a/src/sp/protocol/pubsub0/sub_test.c b/src/sp/protocol/pubsub0/sub_test.c index 9929de64..d0a441ce 100644 --- a/src/sp/protocol/pubsub0/sub_test.c +++ b/src/sp/protocol/pubsub0/sub_test.c @@ -8,6 +8,7 @@ // #include "nng/nng.h" +#include "nng/protocol/pubsub0/sub.h" #include static void @@ -546,6 +547,10 @@ test_sub_multi_context(void) nng_aio_wait(aio2); NUTS_FAIL(nng_aio_result(aio1), NNG_ETIMEDOUT); NUTS_FAIL(nng_aio_result(aio2), NNG_ETIMEDOUT); + + NUTS_PASS(nng_sub0_ctx_unsubscribe(c2, "two", 3)); + NUTS_PASS(nng_sub0_ctx_unsubscribe(c2, "all", 3)); + NUTS_CLOSE(sub); NUTS_CLOSE(pub); nng_aio_free(aio1); @@ -564,6 +569,38 @@ test_sub_cooked(void) NUTS_CLOSE(s); } +static void +test_sub_wrong_protocol(void) +{ +#ifdef NNG_HAVE_REQ0 + nng_socket s; + nng_ctx c; + + NUTS_PASS(nng_req0_open(&s)); + NUTS_PASS(nng_ctx_open(&c, s)); + NUTS_FAIL(nng_sub0_socket_subscribe(s, NULL, 0), NNG_ENOTSUP); + NUTS_FAIL(nng_sub0_socket_unsubscribe(s, NULL, 0), NNG_ENOTSUP); + NUTS_FAIL(nng_sub0_ctx_subscribe(c, NULL, 0), NNG_ENOTSUP); + NUTS_FAIL(nng_sub0_ctx_unsubscribe(c, NULL, 0), NNG_ENOTSUP); + NUTS_CLOSE(s); +#endif +} + +static void +test_sub_closed_socket(void) +{ + nng_socket s; + nng_ctx c; + + NUTS_PASS(nng_sub0_open(&s)); + NUTS_PASS(nng_ctx_open(&c, s)); + NUTS_CLOSE(s); + NUTS_FAIL(nng_sub0_socket_subscribe(s, NULL, 0), NNG_ECLOSED); + NUTS_FAIL(nng_sub0_socket_unsubscribe(s, NULL, 0), NNG_ECLOSED); + NUTS_FAIL(nng_sub0_ctx_subscribe(c, NULL, 0), NNG_ECLOSED); + NUTS_FAIL(nng_sub0_ctx_unsubscribe(c, NULL, 0), NNG_ECLOSED); +} + TEST_LIST = { { "sub identity", test_sub_identity }, { "sub cannot send", test_sub_cannot_send }, @@ -586,5 +623,7 @@ TEST_LIST = { { "sub filter", test_sub_filter }, { "sub multi context", test_sub_multi_context }, { "sub cooked", test_sub_cooked }, + { "sub wrong protocol", test_sub_wrong_protocol }, + { "sub closed socket", test_sub_closed_socket }, { NULL, NULL }, }; -- cgit v1.2.3-70-g09d2