![]() |
The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
|
Tests for the configuration file tokenizer. More...
#include "acutest_common_init.h"#include "acutest_helpers.h"#include <freeradius-devel/util/token.h>#include <sys/mman.h>
Include dependency graph for token_tests.c:Go to the source code of this file.
Data Structures | |
| struct | parse_result_t |
| Where a parse ran, and what the parse produced. More... | |
Macros | |
| #define | TEST_PARSE(_result, _token, _buf, _used) |
Functions | |
| static char * | guard_alloc (char **base, char const *in) |
| Copy a string so that the terminating NUL is the last readable byte. | |
| static void | guard_free (char *base) |
| static parse_result_t | test_getop (char const *in) |
| Run getop() over a guarded copy of the input. | |
| 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_getstring_null (void) |
| getstring() rejects a NULL pointer rather than following the pointer | |
| 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_gettoken (char const *in, bool unescape) |
| Run gettoken() over a guarded copy of the input. | |
| static void | test_gettoken_delimiters (void) |
| gettoken() splits on the tokens in the token table | |
| static void | test_gettoken_no_unescape (void) |
| Without unescaping, gettoken() keeps the backslash. | |
| static void | test_gettoken_quotes (void) |
| Each quote character produces its own token type. | |
| static void | test_gettoken_truncation (void) |
| An input longer than the output buffer stops at the end of the output buffer. | |
| static void | test_gettoken_unescape (void) |
| gettoken() turns escape sequences into the characters the sequences name | |
| static void | test_gettoken_unterminated (void) |
| A string which never ends is an error, and the input pointer does not move. | |
| static parse_result_t | test_getword (char const *in, bool unescape) |
| Run getword() over a guarded copy of the input. | |
| static void | test_getword_no_delimiters (void) |
| getword() reads to whitespace, and ignores the tokens which split gettoken() | |
| static void | test_token_from_quote_enum_str (void) |
| fr_token_from_quote_enum_str() turns an enumeration name back into a token | |
| static void | test_token_name (void) |
| fr_token_name() names the tokens which the tokenizer matches as tokens | |
| 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_triple_quote (void) |
| A triple-quoted string keeps every character between the delimiters. | |
Variables | |
| TEST_LIST | |
Tests for the configuration file tokenizer.
Definition in file token_tests.c.
| struct parse_result_t |
Where a parse ran, and what the parse produced.
Definition at line 33 of file token_tests.c.
| Data Fields | ||
|---|---|---|
| char | buf[256] | what the parse function wrote. |
| fr_token_t | token | what the parse function returned. |
| size_t | used | how many bytes of the input the parse consumed. |
| #define TEST_PARSE | ( | _result, | |
| _token, | |||
| _buf, | |||
| _used | |||
| ) |
Definition at line 157 of file token_tests.c.
|
static |
Copy a string so that the terminating NUL is the last readable byte.
A read past the NUL lands on an unreadable page and faults, rather than returning whatever byte happens to follow the string. Every parse in this file runs against a guarded copy, because a tokenizer which reads one byte too far produces the right answer on almost every run and the wrong answer on the rest.
| [out] | base | start of the mapping, to pass to guard_free(). |
| [in] | in | to copy. |
Definition at line 50 of file token_tests.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 67 of file token_tests.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Run getop() over a guarded copy of the input.
Definition at line 139 of file token_tests.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
getop() accepts an assignment or comparison operator and rejects everything else
Definition at line 390 of file token_tests.c.
Here is the call graph for this function:
|
static |
Run getstring() over a guarded copy of the input.
Definition at line 118 of file token_tests.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
getstring() rejects a NULL pointer rather than following the pointer
Definition at line 433 of file token_tests.c.
Here is the call graph for this function:
|
static |
getstring() reads a quoted string as a string, and anything else as a word
Definition at line 414 of file token_tests.c.
Here is the call graph for this function:
|
static |
Run gettoken() over a guarded copy of the input.
Definition at line 75 of file token_tests.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
gettoken() splits on the tokens in the token table
Definition at line 198 of file token_tests.c.
Here is the call graph for this function:
|
static |
Without unescaping, gettoken() keeps the backslash.
The one exception is a backslash in front of the quote character, which the tokenizer still has to remove so that the quote does not end the string.
Definition at line 287 of file token_tests.c.
Here is the call graph for this function:
|
static |
Each quote character produces its own token type.
Definition at line 232 of file token_tests.c.
Here is the call graph for this function:
|
static |
An input longer than the output buffer stops at the end of the output buffer.
Definition at line 319 of file token_tests.c.
Here is the call graph for this function:
|
static |
gettoken() turns escape sequences into the characters the sequences name
Definition at line 252 of file token_tests.c.
Here is the call graph for this function:
|
static |
A string which never ends is an error, and the input pointer does not move.
Definition at line 298 of file token_tests.c.
Here is the call graph for this function:
|
static |
Run getword() over a guarded copy of the input.
getword() returns 0 at end of line and 1 otherwise, so the rcode goes in token.
Definition at line 97 of file token_tests.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
getword() reads to whitespace, and ignores the tokens which split gettoken()
Definition at line 353 of file token_tests.c.
Here is the call graph for this function:
|
static |
fr_token_from_quote_enum_str() turns an enumeration name back into a token
Definition at line 474 of file token_tests.c.
Here is the call graph for this function:
|
static |
fr_token_name() names the tokens which the tokenizer matches as tokens
The word and string tokens are not in that table, so fr_token_name() does not name the word and string tokens. Use fr_token_to_enum_str() for those.
Definition at line 450 of file token_tests.c.
Here is the call graph for this function:
|
static |
fr_token_to_enum_str() names a token with the name of the C enumeration value
Definition at line 464 of file token_tests.c.
Here is the call graph for this function:
|
static |
A triple-quoted string keeps every character between the delimiters.
Skipping three characters for the opening delimiter and then one more ate the first character of the content. For an input of three quotes and nothing else, the same extra skip stepped past the terminating NUL.
Definition at line 172 of file token_tests.c.
Here is the call graph for this function:| TEST_LIST |
Definition at line 495 of file token_tests.c.
1.9.8