The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
acutest_helpers.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/** Type specific TEST_CHECK macros for acutest
19 *
20 * @file src/lib/util/test//test/acutest_helpers.h
21 *
22 * @copyright 2020 Arran Cudbard-Bell
23 */
24RCSIDH(acutest_helpers_h, "$Id: d0cb3f0b6612e0ea07503ff0943e8a900e0ec37d $")
25
26#include <unistd.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#define TEST_CHECK_LEN(_got, _exp) \
33do { \
34 size_t _our_got = (_got); \
35 TEST_CHECK_(_exp == _our_got, "%s", #_got); \
36 TEST_MSG("Expected length : %zu", (size_t) (_exp)); \
37 TEST_MSG("Got length : %zu", (size_t) (_our_got)); \
38} while(0)
39
40#define TEST_CHECK_SLEN(_got, _exp) \
41do { \
42 ssize_t _our_got = (_got); \
43 TEST_CHECK_(_exp == _our_got, "%s", #_got); \
44 TEST_MSG("Expected length : %zd", (ssize_t) (_exp)); \
45 TEST_MSG("Got length : %zd", (ssize_t) (_our_got)); \
46} while(0)
47
48#define TEST_CHECK_SLEN_RETURN(_got, _exp) \
49do { \
50 ssize_t _our_got = (_got); \
51 TEST_CHECK_(_exp == _our_got, "%s", #_got); \
52 TEST_MSG("Expected length : %zd", (ssize_t) (_exp)); \
53 TEST_MSG("Got length : %zd", (ssize_t) (_our_got)); \
54 if (_exp != _our_got) return; \
55} while(0)
56
57#define TEST_CHECK_RET(_got, _exp) \
58do { \
59 int _our_got = (_got); \
60 TEST_CHECK_(_exp == _our_got, "%s", #_got); \
61 TEST_MSG("Expected ret : %"PRId64, (int64_t) (_exp)); \
62 TEST_MSG("Got ret : %"PRId64, (int64_t) (_our_got)); \
63} while(0)
64
65#define TEST_CHECK_STRCMP(_got, _exp) \
66do { \
67 char const *_our_got = (_got); \
68 TEST_CHECK_(((_exp) != NULL) && ((_got) != NULL) && (strcmp(_exp, _our_got) == 0), "%s", #_got); \
69 TEST_MSG("Expected : \"%s\"", _exp); \
70 TEST_MSG("Got : \"%s\"", _our_got); \
71} while(0)
72
73/** Return the system page size, aborting the test if sysconf() fails
74 *
75 * The upper bound means callers can map a small multiple of the page size
76 * without the length overflowing.
77 *
78 * @return the page size in bytes.
79 */
80static inline size_t test_page_size(void)
81{
82 long sc_page_size = sysconf(_SC_PAGESIZE);
83
84 TEST_ASSERT(sc_page_size > 0);
85 TEST_ASSERT(sc_page_size <= (1L << 30));
86
87 return (size_t)sc_page_size;
88}
89
90#ifdef __cplusplus
91}
92#endif
#define TEST_ASSERT(cond)
Definition acutest.h:125
static size_t test_page_size(void)
Return the system page size, aborting the test if sysconf() fails.
#define RCSIDH(h, id)
Definition build.h:561