26#include <freeradius-devel/util/token.h>
52 size_t len = strlen(
in);
56 *base = mmap(NULL, pagesz * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
57 if (*base == MAP_FAILED)
return NULL;
59 if (mprotect(*base + pagesz, pagesz, PROT_NONE) < 0)
return NULL;
61 p = *base + pagesz - (
len + 1);
62 memcpy(p,
in,
len + 1);
157#define TEST_PARSE(_result, _token, _buf, _used) do { \
158 TEST_CHECK((_result).token == (_token)); \
159 TEST_MSG("token: got %u, expected %u", (_result).token, (fr_token_t)(_token)); \
160 TEST_CHECK(strcmp((_result).buf, (_buf)) == 0); \
161 TEST_MSG("buf: got \"%s\", expected \"%s\"", (_result).buf, (_buf)); \
162 TEST_CHECK((_result).used == (size_t) (_used)); \
163 TEST_MSG("used: got %zu, expected %zu", (_result).used, (size_t) (_used)); \
332 token =
gettoken(&p, buf,
sizeof(buf),
true);
344 token =
gettoken(&p, buf,
sizeof(buf),
true);
436 char const *p = NULL;
#define TEST_ASSERT(cond)
Common initialisation for acutest binaries.
static size_t test_page_size(void)
Return the system page size, aborting the test if sysconf() fails.
char const * fr_token_name(int token)
fr_token_t gettoken(char const **ptr, char *buf, int buflen, bool unescape)
char const * fr_token_to_enum_str(fr_token_t t)
Return the source-identifier name for a token (e.g.
fr_token_t getop(char const **ptr)
fr_token_t getstring(char const **ptr, char *buf, int buflen, bool unescape)
int getword(char const **ptr, char *buf, int buflen, bool unescape)
fr_token_t fr_token_from_quote_enum_str(char const *s, fr_token_t dflt)
Look up a quote token by its source-identifier name.
@ T_SOLIDUS_QUOTED_STRING
static void test_gettoken_unescape(void)
gettoken() turns escape sequences into the characters the sequences name
static void test_getstring_null(void)
getstring() rejects a NULL pointer rather than following the pointer
static void test_token_name(void)
fr_token_name() names the tokens which the tokenizer matches as tokens
static void test_gettoken_truncation(void)
An input longer than the output buffer stops at the end of the output buffer.
static void test_token_from_quote_enum_str(void)
fr_token_from_quote_enum_str() turns an enumeration name back into a token
size_t used
how many bytes of the input the parse consumed.
static void test_gettoken_delimiters(void)
gettoken() splits on the tokens in the token table
static void test_getop_operators(void)
getop() accepts an assignment or comparison operator and rejects everything else
static parse_result_t test_getstring(char const *in, bool unescape)
Run getstring() over a guarded copy of the input.
static void test_gettoken_no_unescape(void)
Without unescaping, gettoken() keeps the backslash.
fr_token_t token
what the parse function returned.
static void test_getword_no_delimiters(void)
getword() reads to whitespace, and ignores the tokens which split gettoken()
static void test_triple_quote(void)
A triple-quoted string keeps every character between the delimiters.
static void guard_free(char *base)
static parse_result_t test_gettoken(char const *in, bool unescape)
Run gettoken() over a guarded copy of the input.
static void test_gettoken_quotes(void)
Each quote character produces its own token type.
static char * guard_alloc(char **base, char const *in)
Copy a string so that the terminating NUL is the last readable byte.
#define TEST_PARSE(_result, _token, _buf, _used)
static void test_gettoken_unterminated(void)
A string which never ends is an error, and the input pointer does not move.
char buf[256]
what the parse function wrote.
static parse_result_t test_getword(char const *in, bool unescape)
Run getword() over a guarded copy of the input.
static void test_token_to_enum_str(void)
fr_token_to_enum_str() names a token with the name of the C enumeration value
static void test_getstring_quoting(void)
getstring() reads a quoted string as a string, and anything else as a word
static parse_result_t test_getop(char const *in)
Run getop() over a guarded copy of the input.
Where a parse ran, and what the parse produced.
static fr_sbuff_err_t char size_t fr_sbuff_t * in
static fr_sbuff_err_t char size_t * len