aboutsummaryrefslogtreecommitdiff
path: root/src/core/buf_size_test.c
blob: 93fbe04f9177be3ba7eb0c200be9504c76e83a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Copyright 2025 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 "../testing/nuts.h"

void
test_buffer_options(void)
{
	nng_socket s1;
	int        val;
	char      *opt;

	char *cases[] = {
		NNG_OPT_RECVBUF,
		NNG_OPT_SENDBUF,
		NULL,
	};

	NUTS_PASS(nng_pair1_open(&s1));
	for (int i = 0; (opt = cases[i]) != NULL; i++) {

		NUTS_CASE(opt);

		// Can set a valid size
		NUTS_PASS(nng_socket_set_int(s1, opt, 1234));
		NUTS_PASS(nng_socket_get_int(s1, opt, &val));
		NUTS_TRUE(val == 1234);

		// Can't set a negative size
		NUTS_FAIL(nng_socket_set_int(s1, opt, -5), NNG_EINVAL);

		// Buffer sizes are limited to sane levels
		NUTS_FAIL(nng_socket_set_int(s1, opt, 0x100000), NNG_EINVAL);
	}
	NUTS_CLOSE(s1);
}

NUTS_TESTS = {
	{ "buffer options", test_buffer_options },
	{ NULL, NULL },
};