Skip to content

Commit

Permalink
tests: start using nng_err in NUTS
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jan 12, 2025
1 parent 9368d35 commit d6de9be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/testing/marry.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ married(nng_pipe p, nng_pipe_ev ev, void *arg)
nng_mtx_unlock(notice->mx);
}

int
nng_err
nuts_marry(nng_socket s1, nng_socket s2)
{
return (nuts_marry_ex(s1, s2, NULL, NULL, NULL));
Expand Down Expand Up @@ -301,13 +301,13 @@ replace_port_zero(const char *addr, char *buf, int port)
buf[j] = '\0';
}

int
nng_err
nuts_marry_ex(
nng_socket s1, nng_socket s2, const char *url, nng_pipe *p1, nng_pipe *p2)
{
struct marriage_notice note;
nng_time timeout;
int rv;
nng_err rv;
char addr[64];
nng_listener l;
int port;
Expand Down Expand Up @@ -358,7 +358,7 @@ nuts_marry_ex(
}
} else if (rv == NNG_ENOTSUP) {
url = "tcp://127.0.0.1:0";
rv = 0;
rv = NNG_OK;
} else {
return (rv);
}
Expand Down
24 changes: 12 additions & 12 deletions src/testing/nuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ extern void nuts_scratch_addr_zero(const char *, size_t, char *);
// nuts_marry connects two sockets using inproc. It uses socket
// pipe hooks to ensure that it does not return before both sockets
// are fully connected.
extern int nuts_marry(nng_socket, nng_socket);
extern nng_err nuts_marry(nng_socket, nng_socket);

// nuts_marry_ex is like nuts_marry, but returns the pipes that
// were connected, and includes an optional URL. The pipe pointers and the
// URL may be NULL if not needed. If a port number is part of the URL
// and is zero (i.e. if the URL contains :0) then listen is done first,
// and the actual bound port will be used for the client.
extern int nuts_marry_ex(
extern nng_err nuts_marry_ex(
nng_socket, nng_socket, const char *, nng_pipe *, nng_pipe *);

// nuts_stream_send_start and nuts_stream_recv_start are used
Expand Down Expand Up @@ -208,21 +208,21 @@ extern const char *nuts_ecdsa_client_crt;
// did not.
#define NUTS_PASS(cond) \
do { \
int result_ = (cond); \
TEST_ASSERT_(result_ == 0, \
nng_err result_ = (nng_err) (cond); \
TEST_ASSERT_(result_ == NNG_OK, \
"%s: expected success, got %s (%d)", #cond, \
nng_strerror(result_), result_); \
} while (0)

// NUTS_FAIL tests for a specific NNG error code.
#define NUTS_FAIL(cond, expect) \
do { \
int result_ = (cond); \
TEST_CHECK_(result_ == (expect), "%s fails with %s", #cond, \
nng_strerror(expect)); \
TEST_MSG("%s: expected %s (%d), got %s (%d)", #cond, \
nng_strerror(expect), expect, nng_strerror(result_), \
result_); \
#define NUTS_FAIL(cond, expect) \
do { \
nng_err result_ = (cond); \
TEST_CHECK_(result_ == (nng_err) (expect), \
"%s fails with %s", #cond, nng_strerror(expect)); \
TEST_MSG("%s: expected %s (%d), got %s (%d)", #cond, \
nng_strerror(expect), expect, nng_strerror(result_), \
result_); \
} while (0)

#define NUTS_SEND(sock, string) \
Expand Down

0 comments on commit d6de9be

Please sign in to comment.