diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-12-29 16:50:32 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-12-29 20:51:33 -0800 |
| commit | 0cf84675edef0290a74dfd1e289c0b9e1bb3fb5c (patch) | |
| tree | a637989cb4da9bf7523d450acf618a64d3f10a0a /src/compat/nanomsg/compat_testutil.h | |
| parent | b4d3ff2d460607ba8e1b351233cb6cbe9f031264 (diff) | |
| download | nng-0cf84675edef0290a74dfd1e289c0b9e1bb3fb5c.tar.gz nng-0cf84675edef0290a74dfd1e289c0b9e1bb3fb5c.tar.bz2 nng-0cf84675edef0290a74dfd1e289c0b9e1bb3fb5c.zip | |
fixes #1059 compat_tcp test sometimes times out
Diffstat (limited to 'src/compat/nanomsg/compat_testutil.h')
| -rw-r--r-- | src/compat/nanomsg/compat_testutil.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/compat/nanomsg/compat_testutil.h b/src/compat/nanomsg/compat_testutil.h new file mode 100644 index 00000000..afd75c34 --- /dev/null +++ b/src/compat/nanomsg/compat_testutil.h @@ -0,0 +1,48 @@ +// +// Copyright 2019 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 +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#ifndef COMPAT_TESTUTIL_H +#define COMPAT_TESTUTIL_H + +#include <stdbool.h> +#include <stdint.h> + +// The following headers are provided for test code convenience. +#include <nng/nng.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// TEST_NNG_PASS tests for NNG success. It reports the failure if it +// did not. +#define TEST_NN_PASS(cond) \ + do { \ + int result_ = (cond); \ + TEST_CHECK_(result_ >= 0, "%s succeeds", #cond); \ + TEST_MSG("%s: expected success, got %s (%d)", #cond, \ + 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_); \ + } while (0) + +#ifdef __cplusplus +}; +#endif + +#endif // COMPAT_TESTUTIL_H |
