-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ADD [exchange_client] Add exchange client UT
Signed-off-by: Moi Ran <maoyi.ran@emqx.io>
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "nng/nng.h" | ||
#include "core/nng_impl.h" | ||
#include "nng/exchange/exchange_client.h" | ||
#include "core/defs.h" | ||
#include <nuts.h> | ||
|
||
#define UNUSED(x) ((void) x) | ||
|
||
static int match_cb(void *msg) | ||
{ | ||
UNUSED(msg); | ||
return 0; | ||
} | ||
|
||
static int target_cb(void *msg) | ||
{ | ||
UNUSED(msg); | ||
return 0; | ||
} | ||
|
||
void test_exchange_client(void) | ||
{ | ||
nng_socket sock; | ||
exchange_t *ex; | ||
producer_t *p; | ||
|
||
NUTS_TRUE(nng_exchange_client_open(&sock) == 0); | ||
|
||
NUTS_TRUE(exchange_init(&ex, "exchange1") == 0); | ||
NUTS_TRUE(ex != NULL); | ||
|
||
|
||
NUTS_TRUE(producer_init(&p, match_cb, target_cb) == 0); | ||
NUTS_TRUE(p != NULL); | ||
NUTS_TRUE(exchange_add_prod(ex, p) == 0); | ||
|
||
nng_socket_set_ptr(sock, NNG_OPT_EXCHANGE_ADD, ex); | ||
|
||
int msg = 1; | ||
nng_sendmsg(sock, (void *)&msg, NNG_FLAG_NONBLOCK); | ||
|
||
nng_msleep(200); | ||
|
||
return; | ||
} | ||
|
||
NUTS_TESTS = { | ||
{ "Exchange client test", test_exchange_client }, | ||
{ NULL, NULL }, | ||
}; |