aboutsummaryrefslogtreecommitdiff
path: root/src/compat
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2021-01-03 10:35:06 -0800
committerGitHub <noreply@github.com>2021-01-03 10:35:06 -0800
commit9c6ac231b8b7d0c597a4010135edb14b8513e3f6 (patch)
treeadfad0200b03da6cb176f5f3c6045407c8f96b29 /src/compat
parentd5814d58496ff1fbbb2e6727ff8bffe78204223c (diff)
downloadnng-9c6ac231b8b7d0c597a4010135edb14b8513e3f6.tar.gz
nng-9c6ac231b8b7d0c597a4010135edb14b8513e3f6.tar.bz2
nng-9c6ac231b8b7d0c597a4010135edb14b8513e3f6.zip
fixes #1398 integrate new acutest.h (#1400)
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/nanomsg/compat_tcp_test.c98
-rw-r--r--src/compat/nanomsg/nuts_compat.h (renamed from src/compat/nanomsg/compat_testutil.h)43
2 files changed, 70 insertions, 71 deletions
diff --git a/src/compat/nanomsg/compat_tcp_test.c b/src/compat/nanomsg/compat_tcp_test.c
index ae4193b7..d090463f 100644
--- a/src/compat/nanomsg/compat_tcp_test.c
+++ b/src/compat/nanomsg/compat_tcp_test.c
@@ -30,7 +30,7 @@
#include <nng/compat/nanomsg/pair.h>
#include <nng/compat/nanomsg/tcp.h>
-#include "compat_testutil.h"
+#include "nuts_compat.h"
#include <nuts.h>
@@ -54,9 +54,9 @@ test_connect_and_close(void)
char *addr;
NUTS_ADDR(addr, "tcp");
- TEST_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR)) >= 0);
- TEST_NN_PASS(nn_connect(sc, addr));
- TEST_NN_PASS(nn_close(sc));
+ NUTS_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR)) >= 0);
+ NUTS_NN_PASS(nn_connect(sc, addr));
+ NUTS_NN_PASS(nn_close(sc));
}
void
@@ -70,10 +70,10 @@ test_bind_and_connect(void)
NUTS_TRUE((sc = nn_socket(AF_SP, NN_PAIR)) >= 0);
NUTS_TRUE(sb != sc);
- TEST_NN_MARRY_EX(sb, sc, addr, p1, p2);
+ NUTS_NN_MARRY_EX(sb, sc, addr, p1, p2);
- TEST_NN_PASS(nn_close(sb));
- TEST_NN_PASS(nn_close(sc));
+ NUTS_NN_PASS(nn_close(sb));
+ NUTS_NN_PASS(nn_close(sc));
}
void
@@ -82,15 +82,15 @@ test_bad_addresses(void)
int s;
NUTS_TRUE((s = nn_socket(AF_SP, NN_PAIR)) >= 0);
- TEST_NN_FAIL(nn_connect(s, "tcp://*:"), EINVAL);
- TEST_NN_FAIL(nn_connect(s, "tcp://*:1000000"), EINVAL);
- TEST_NN_FAIL(nn_connect(s, "tcp://*:some_port"), EINVAL);
- TEST_NN_FAIL(nn_connect(s, "tcp://127.0.0.1"), EINVAL);
- TEST_NN_FAIL(nn_connect(s, "tcp://:5555"), EINVAL);
- TEST_NN_FAIL(nn_connect(s, "tcp://abc.123.---.#:5555"), EINVAL);
+ NUTS_NN_FAIL(nn_connect(s, "tcp://*:"), EINVAL);
+ NUTS_NN_FAIL(nn_connect(s, "tcp://*:1000000"), EINVAL);
+ NUTS_NN_FAIL(nn_connect(s, "tcp://*:some_port"), EINVAL);
+ NUTS_NN_FAIL(nn_connect(s, "tcp://127.0.0.1"), EINVAL);
+ NUTS_NN_FAIL(nn_connect(s, "tcp://:5555"), EINVAL);
+ NUTS_NN_FAIL(nn_connect(s, "tcp://abc.123.---.#:5555"), EINVAL);
- TEST_NN_FAIL(nn_bind(s, "tcp://127.0.0.1:1000000"), EINVAL);
- TEST_NN_PASS(nn_close(s));
+ NUTS_NN_FAIL(nn_bind(s, "tcp://127.0.0.1:1000000"), EINVAL);
+ NUTS_NN_PASS(nn_close(s));
}
void
@@ -102,21 +102,21 @@ test_no_delay(void)
NUTS_TRUE((s = nn_socket(AF_SP, NN_PAIR)) >= 0);
sz = sizeof(opt);
- TEST_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz));
+ NUTS_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz));
NUTS_TRUE(sz == sizeof(opt));
NUTS_TRUE(opt == 0);
opt = 2;
- TEST_NN_FAIL(
+ NUTS_NN_FAIL(
nn_setsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, sz), EINVAL);
opt = 1;
- TEST_NN_PASS(nn_setsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, sz));
+ NUTS_NN_PASS(nn_setsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, sz));
opt = 3;
- TEST_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz));
+ NUTS_NN_PASS(nn_getsockopt(s, NN_TCP, NN_TCP_NODELAY, &opt, &sz));
NUTS_TRUE(sz == sizeof(opt));
NUTS_TRUE(opt == 1);
- TEST_NN_PASS(nn_close(s));
+ NUTS_NN_PASS(nn_close(s));
}
void
@@ -126,10 +126,10 @@ test_ping_pong(void)
char *addr;
NUTS_ADDR(addr, "tcp");
- TEST_NN_PASS((sb = nn_socket(AF_SP, NN_PAIR)));
- TEST_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR)));
+ NUTS_NN_PASS((sb = nn_socket(AF_SP, NN_PAIR)));
+ NUTS_NN_PASS((sc = nn_socket(AF_SP, NN_PAIR)));
NUTS_TRUE(sb != sc);
- TEST_NN_MARRY_EX(sc, sb, addr, p1, p2);
+ NUTS_NN_MARRY_EX(sc, sb, addr, p1, p2);
NUTS_TRUE(p1 >= 0);
NUTS_TRUE(p2 >= 0);
@@ -138,19 +138,19 @@ test_ping_pong(void)
char buf[4];
int n;
- TEST_NN_PASS(nn_send(sc, "ABC", 3, 0));
- TEST_NN_PASS(n = nn_recv(sb, buf, 4, 0));
+ NUTS_NN_PASS(nn_send(sc, "ABC", 3, 0));
+ NUTS_NN_PASS(n = nn_recv(sb, buf, 4, 0));
NUTS_TRUE(n == 3);
NUTS_TRUE(memcmp(buf, "ABC", 3) == 0);
- TEST_NN_PASS(nn_send(sb, "DEF", 3, 0));
- TEST_NN_PASS(n = nn_recv(sc, buf, 4, 0));
+ NUTS_NN_PASS(nn_send(sb, "DEF", 3, 0));
+ NUTS_NN_PASS(n = nn_recv(sc, buf, 4, 0));
NUTS_TRUE(n == 3);
NUTS_TRUE(memcmp(buf, "DEF", 3) == 0);
}
- TEST_NN_PASS(nn_close(sb));
- TEST_NN_PASS(nn_close(sc));
+ NUTS_NN_PASS(nn_close(sb));
+ NUTS_NN_PASS(nn_close(sc));
}
void
@@ -166,14 +166,14 @@ test_pair_reject(void)
NUTS_TRUE((sd = nn_socket(AF_SP, NN_PAIR)) >= 0);
NUTS_TRUE(sb != sc);
- TEST_NN_MARRY_EX(sc, sb, addr, p1, p2);
+ NUTS_NN_MARRY_EX(sc, sb, addr, p1, p2);
NUTS_TRUE(nn_connect(sd, addr) >= 0);
NUTS_SLEEP(200);
- TEST_NN_PASS(nn_close(sb));
- TEST_NN_PASS(nn_close(sc));
- TEST_NN_PASS(nn_close(sd));
+ NUTS_NN_PASS(nn_close(sb));
+ NUTS_NN_PASS(nn_close(sc));
+ NUTS_NN_PASS(nn_close(sd));
}
void
@@ -186,11 +186,11 @@ test_addr_in_use(void)
NUTS_TRUE((sb = nn_socket(AF_SP, NN_PAIR)) >= 0);
NUTS_TRUE((sc = nn_socket(AF_SP, NN_PAIR)) >= 0);
NUTS_TRUE(sb != sc);
- TEST_NN_PASS(nn_bind(sb, addr));
- TEST_NN_FAIL(nn_bind(sc, addr), EADDRINUSE);
+ NUTS_NN_PASS(nn_bind(sb, addr));
+ NUTS_NN_FAIL(nn_bind(sc, addr), EADDRINUSE);
- TEST_NN_PASS(nn_close(sb));
- TEST_NN_PASS(nn_close(sc));
+ NUTS_NN_PASS(nn_close(sb));
+ NUTS_NN_PASS(nn_close(sc));
}
void
@@ -210,40 +210,40 @@ test_max_recv_size(void)
NUTS_TRUE(sb != sc);
opt = 100;
sz = sizeof(opt);
- TEST_NN_PASS(nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sz));
+ NUTS_NN_PASS(nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sz));
/* Test that NN_RCVMAXSIZE can be -1, but not lower */
sz = sizeof(opt);
opt = -1;
- TEST_NN_PASS(
+ NUTS_NN_PASS(
nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sz));
opt = -2;
- TEST_NN_FAIL(
+ NUTS_NN_FAIL(
nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sz), EINVAL);
opt = 4;
- TEST_NN_PASS(
+ NUTS_NN_PASS(
nn_setsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sz));
opt = -5;
- TEST_NN_PASS(
+ NUTS_NN_PASS(
nn_getsockopt(sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, &sz));
NUTS_TRUE(opt == 4);
NUTS_TRUE(sz == sizeof(opt));
- TEST_NN_MARRY_EX(sc, sb, addr, p1, p2);
+ NUTS_NN_MARRY_EX(sc, sb, addr, p1, p2);
- TEST_NN_PASS(nn_send(sc, "ABC", 4, 0));
- TEST_NN_PASS(nn_send(sc, "012345", 6, 0));
+ NUTS_NN_PASS(nn_send(sc, "ABC", 4, 0));
+ NUTS_NN_PASS(nn_send(sc, "012345", 6, 0));
- TEST_NN_PASS(n = nn_recv(sb, buf, sizeof(buf), 0));
+ NUTS_NN_PASS(n = nn_recv(sb, buf, sizeof(buf), 0));
NUTS_TRUE(n == 4);
NUTS_TRUE(strcmp(buf, "ABC") == 0);
- TEST_NN_FAIL(nn_recv(sb, buf, sizeof(buf), 0), ETIMEDOUT);
+ NUTS_NN_FAIL(nn_recv(sb, buf, sizeof(buf), 0), ETIMEDOUT);
- TEST_NN_PASS(nn_close(sb));
- TEST_NN_PASS(nn_close(sc));
+ NUTS_NN_PASS(nn_close(sb));
+ NUTS_NN_PASS(nn_close(sc));
}
TEST_LIST = {
diff --git a/src/compat/nanomsg/compat_testutil.h b/src/compat/nanomsg/nuts_compat.h
index e0612adb..d7bd56e7 100644
--- a/src/compat/nanomsg/compat_testutil.h
+++ b/src/compat/nanomsg/nuts_compat.h
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -7,8 +7,8 @@
// found online at https://opensource.org/licenses/MIT.
//
-#ifndef COMPAT_TESTUTIL_H
-#define COMPAT_TESTUTIL_H
+#ifndef NUTS_COMPAT_H
+#define NUTS_COMPAT_H
#include <stdbool.h>
#include <stdint.h>
@@ -20,9 +20,8 @@
extern "C" {
#endif
-// TEST_NNG_PASS tests for NNG success. It reports the failure if it
-// did not.
-#define TEST_NN_PASS(cond) \
+// NUTS_NN_PASS tests for NN success. It reports the failure if it did not.
+#define NUTS_NN_PASS(cond) \
do { \
int result_ = (cond); \
TEST_CHECK_(result_ >= 0, "%s succeeds", #cond); \
@@ -30,22 +29,22 @@ extern "C" {
nn_strerror(errno), errno); \
} while (0)
-#define TEST_NN_FAIL(cond, expect) \
- do { \
- int result_ = (cond); \
- int err_ = errno; \
- TEST_CHECK_(result_ < 0, "%s did not succeed", #cond); \
- TEST_CHECK_( \
- err_ = expect, "%s fails with %s", #cond, #expect); \
- TEST_MSG("%s: expected %s, got %s (%d)", #cond, #expect, \
- expect, nng_strerror(err_), result_); \
+#define NUTS_NN_FAIL(cond, expect) \
+ do { \
+ int result_ = (cond); \
+ int err_ = errno; \
+ TEST_CHECK_(result_ < 0, "%s did not succeed", #cond); \
+ TEST_CHECK_( \
+ err_ == (expect), "%s fails with %s", #cond, #expect); \
+ TEST_MSG("%s: expected %s, got %d / %d (%s)", #cond, #expect, \
+ result_, (expect), nng_strerror(err_)); \
} while (0)
// These macros use some details of the socket and pipe which are not public.
// We do that to facilitate testing. Don't rely on this equivalence in your
// own application code.
-#define TEST_NN_MARRY(s1, s2) \
+#define NUTS_NN_MARRY(s1, s2) \
do { \
nng_socket s1_, s2_; \
s1_.id = s1; \
@@ -54,21 +53,21 @@ extern "C" {
NUTS_MARRY(s1_, s2_); \
} while (0)
-#define TEST_NN_MARRY_EX(s1, s2, url, p1, p2) \
+#define NUTS_NN_MARRY_EX(s1, s2, url, p1, p2) \
do { \
nng_socket s1_, s2_; \
nng_pipe p1_, p2_; \
s1_.id = s1; \
s2_.id = s2; \
NUTS_MARRY_EX(s1_, s2_, url, &p1_, &p2_); \
- p1 = p1_.id; \
- p2 = p2_.id; \
- NUTS_TRUE(p1 >= 0); \
- NUTS_TRUE(p2 >= 0); \
+ (p1) = p1_.id; \
+ (p2) = p2_.id; \
+ NUTS_TRUE((p1) >= 0); \
+ NUTS_TRUE((p2) >= 0); \
} while (0)
#ifdef __cplusplus
};
#endif
-#endif // COMPAT_TESTUTIL_H
+#endif // NUTS_COMPAT