aboutsummaryrefslogtreecommitdiff
path: root/tests/bufsz.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-16 20:44:29 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-18 21:05:16 -0800
commitb826bfc171d90f8bde7bd672c0ac14201b8b2742 (patch)
tree5c416487f24104e6305a797af31c5e8b1aab99d1 /tests/bufsz.c
parentcda4885676f009e2e7f2ad5e6c52743efc8b8924 (diff)
downloadnng-b826bfc171d90f8bde7bd672c0ac14201b8b2742.tar.gz
nng-b826bfc171d90f8bde7bd672c0ac14201b8b2742.tar.bz2
nng-b826bfc171d90f8bde7bd672c0ac14201b8b2742.zip
Work for test refactoring.
There are a few major areas in this change. * CMake options are now located in a common cmake/NNGOptions.cmake file. This should make it easier for folks to figure out what the options are, and how they are used. * Tests are now scoped with their directory name, which should avoid possible name collisions with test names. * A number of tests have been either moved or incorporated into the newer testutil/acutest framework. We are moving away from my old c-convey framework to something easier to debug. * We use CMake directories a bit more extensively leading to a much cleaner CMake structure. It's not complete, but a big step in the right direction, and a preview of future work. * Tests are now run with verbose flags, so we get more test results in the CI/CD logs.
Diffstat (limited to 'tests/bufsz.c')
-rw-r--r--tests/bufsz.c116
1 files changed, 0 insertions, 116 deletions
diff --git a/tests/bufsz.c b/tests/bufsz.c
deleted file mode 100644
index 4f62905d..00000000
--- a/tests/bufsz.c
+++ /dev/null
@@ -1,116 +0,0 @@
-//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
-//
-// 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.
-//
-
-
-#include <nng/nng.h>
-#include <nng/protocol/pair1/pair.h>
-#include <nng/supplemental/util/platform.h>
-
-#include <nng/compat/nanomsg/nn.h>
-
-#include "acutest.h"
-
-void
-test_buffer_options(void)
-{
- nng_socket s1;
- int val;
- size_t sz;
- char * opt;
-
- char *cases[] = {
- NNG_OPT_RECVBUF,
- NNG_OPT_SENDBUF,
- NULL,
- };
-
- TEST_CHECK(nng_pair1_open(&s1) == 0);
- for (int i = 0; (opt = cases[i]) != NULL; i++) {
-
- TEST_CASE(opt);
-
- // Can't receive a size into zero bytes.
- sz = 0;
- TEST_CHECK(nng_getopt(s1, opt, &val, &sz) == NNG_EINVAL);
-
- // Can set a valid size
- TEST_CHECK(nng_setopt_int(s1, opt, 1234) == 0);
- TEST_CHECK(nng_getopt_int(s1, opt, &val) == 0);
- TEST_CHECK(val == 1234);
-
- val = 0;
- sz = sizeof(val);
- TEST_CHECK(nng_getopt(s1, opt, &val, &sz) == 0);
- TEST_CHECK(val == 1234);
- TEST_CHECK(sz == sizeof(val));
-
- // Can't set a negative size
- TEST_CHECK(nng_setopt_int(s1, opt, -5) == NNG_EINVAL);
-
- // Can't pass a buf too small for size
- sz = sizeof(val) - 1;
- val = 1;
- TEST_CHECK(nng_setopt(s1, opt, &val, sz) == NNG_EINVAL);
- // Buffer sizes are limited to sane levels
- TEST_CHECK(nng_setopt_int(s1, opt, 0x100000) == NNG_EINVAL);
- }
- TEST_CHECK(nng_close(s1) == 0);
-}
-
-void
-test_buffer_legacy(void)
-{
- nng_socket s1;
- char * opt;
-
- char *cases[] = {
- NNG_OPT_RECVBUF,
- NNG_OPT_SENDBUF,
- NULL,
- };
- int legacy[] = {
- NN_RCVBUF,
- NN_SNDBUF,
- };
-
- TEST_CHECK(nng_pair1_open(&s1) == 0);
- for (int i = 0; (opt = cases[i]) != NULL; i++) {
- int cnt;
- int os = (int) s1.id;
- size_t sz;
- int nnopt = legacy[i];
-
- TEST_CASE(opt);
-
- sz = sizeof(cnt);
- TEST_CHECK(nng_setopt_int(s1, opt, 10) == 0);
- TEST_CHECK(
- nn_getsockopt(os, NN_SOL_SOCKET, nnopt, &cnt, &sz) == 0);
- TEST_CHECK(cnt == 10240); // 1k multiple
-
- cnt = 1;
- TEST_CHECK(
- nn_setsockopt(os, NN_SOL_SOCKET, nnopt, &cnt, sz) == 0);
- TEST_CHECK(nn_getsockopt(os, NN_SOL_SOCKET, nnopt, &cnt, &sz) == 0);
- TEST_CHECK(cnt == 1024); // round up!
- TEST_CHECK(nng_getopt_int(s1, opt, &cnt) == 0);
- TEST_CHECK(cnt == 1);
-
- TEST_CHECK(nn_setsockopt(os, NN_SOL_SOCKET, nnopt, &cnt, 100) == -1);
- TEST_CHECK(nn_errno() == EINVAL);
- }
- TEST_CHECK(nng_close(s1) == 0);
-}
-
-TEST_LIST = {
- { "buffer options", test_buffer_options },
- { "buffer legacy", test_buffer_legacy },
- { NULL, NULL },
-};