Skip to content

Commit

Permalink
* ADD [exchange_client] Add exchange client UT
Browse files Browse the repository at this point in the history
Signed-off-by: Moi Ran <maoyi.ran@emqx.io>
  • Loading branch information
RanMaoyi committed Nov 24, 2023
1 parent f90ec45 commit 6981890
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/mqtt/protocol/exchange/exchange_client_test.c
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 },
};

0 comments on commit 6981890

Please sign in to comment.