The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Macros | Functions | Variables
sbuff_tests.c File Reference

Tests for a generic string buffer structure for string printing and parsing. More...

#include "acutest_common_init.h"
#include "acutest_helpers.h"
#include <freeradius-devel/util/sbuff.h>
+ Include dependency graph for sbuff_tests.c:

Go to the source code of this file.

Macros

#define PATTERN_LEN   (sizeof(PATTERN) - 1)
 
#define TEST_SBUFF_LEN(_sbuff, _num)
 
#define TEST_SBUFF_USED(_sbuff, _num)
 

Functions

static void test_adv_past_allowed (void)
 
static void test_adv_past_str (void)
 
static void test_adv_past_strcase (void)
 
static void test_adv_past_whitespace (void)
 
static void test_adv_to_chr (void)
 
static void test_adv_to_str (void)
 
static void test_adv_to_strcase (void)
 
static void test_adv_to_utf8 (void)
 
static void test_adv_until (void)
 
static void test_bstrncpy (void)
 
static void test_bstrncpy_allowed (void)
 
static void test_bstrncpy_exact (void)
 
static void test_bstrncpy_until (void)
 
static void test_eof_terminal (void)
 
static void test_file_extend (void)
 
static void test_file_extend_error (void)
 A read error on the file backing an sbuff is reported, not treated as the end of the input.
 
static void test_file_extend_max (void)
 
static void test_is_char (void)
 
static void test_marker_update_end (void)
 
static void test_marker_update_end_after_shift (void)
 Check that the budget is measured with fr_sbuff_used_total(), not fr_sbuff_used()
 
static void test_next_if_char (void)
 
static void test_next_unless_char (void)
 
static void test_no_advance (void)
 
static void test_out_bool (void)
 
static void test_out_float (void)
 
static void test_out_int (void)
 
static void test_out_uint (void)
 
static void test_parse_init (void)
 
static void test_shift_used_accounting (void)
 
static void test_talloc_extend (void)
 
static void test_talloc_extend_init_zero (void)
 
static void test_talloc_extend_multi_level (void)
 
static void test_talloc_extend_with_marker (void)
 
static void test_talloc_extend_with_shift (void)
 
static void test_terminal_merge (void)
 
static void test_terminal_search_at_end_no_overrun (void)
 
static void test_terminal_search_past_visible_end (void)
 
static void test_unescape_multi_char_terminals (void)
 
static void test_unescape_until (void)
 
static void test_unescape_until_escape_bounds (void)
 Check that a hex or octal escape sequence cannot consume more input than "len" allows.
 

Variables

static bool allow_lowercase_and_space [SBUFF_CHAR_CLASS]
 
static bool allow_lowercase_and_space_no_t [SBUFF_CHAR_CLASS]
 
 TEST_LIST
 

Detailed Description

Tests for a generic string buffer structure for string printing and parsing.

Definition in file sbuff_tests.c.

Macro Definition Documentation

◆ PATTERN_LEN

#define PATTERN_LEN   (sizeof(PATTERN) - 1)

◆ TEST_SBUFF_LEN

#define TEST_SBUFF_LEN (   _sbuff,
  _num 
)
Value:
do { \
size_t _len; \
_len = talloc_array_length((_sbuff)->buff); \
TEST_CHECK(_len == (size_t)_num); \
TEST_MSG("Expected length : %zu", (size_t)_num); \
TEST_MSG("Got length : %zu", _len); \
} while(0)
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:37

Definition at line 28 of file sbuff_tests.c.

◆ TEST_SBUFF_USED

#define TEST_SBUFF_USED (   _sbuff,
  _num 
)
Value:
do { \
size_t _len; \
_len = fr_sbuff_used(_sbuff); \
TEST_CHECK(_len == (size_t)_num); \
TEST_MSG("Expected length : %zu", (size_t)_num); \
TEST_MSG("Got length : %zu", _len); \
} while(0)
#define fr_sbuff_used(_sbuff_or_marker)

Definition at line 37 of file sbuff_tests.c.

Function Documentation

◆ test_adv_past_allowed()

static void test_adv_past_allowed ( void  )
static

Definition at line 1943 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_past_str()

static void test_adv_past_str ( void  )
static

Definition at line 1845 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_past_strcase()

static void test_adv_past_strcase ( void  )
static

Definition at line 1876 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_past_whitespace()

static void test_adv_past_whitespace ( void  )
static

Definition at line 1907 of file sbuff_tests.c.

◆ test_adv_to_chr()

static void test_adv_to_chr ( void  )
static

Definition at line 2077 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_to_str()

static void test_adv_to_str ( void  )
static

Definition at line 2122 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_to_strcase()

static void test_adv_to_strcase ( void  )
static

Definition at line 2183 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_to_utf8()

static void test_adv_to_utf8 ( void  )
static

Definition at line 2017 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_adv_until()

static void test_adv_until ( void  )
static

Definition at line 1981 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_bstrncpy()

static void test_bstrncpy ( void  )
static

Definition at line 173 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_bstrncpy_allowed()

static void test_bstrncpy_allowed ( void  )
static

Definition at line 257 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_bstrncpy_exact()

static void test_bstrncpy_exact ( void  )
static

Definition at line 102 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_bstrncpy_until()

static void test_bstrncpy_until ( void  )
static

Definition at line 356 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_eof_terminal()

static void test_eof_terminal ( void  )
static

Definition at line 950 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_file_extend()

static void test_file_extend ( void  )
static

Definition at line 1596 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_file_extend_error()

static void test_file_extend_error ( void  )
static

A read error on the file backing an sbuff is reported, not treated as the end of the input.

Reading from a stream opened for writing fails, which sets the stream's error indicator without reaching EOF.

Definition at line 1700 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_file_extend_max()

static void test_file_extend_max ( void  )
static

Definition at line 1668 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_is_char()

static void test_is_char ( void  )
static

Definition at line 73 of file sbuff_tests.c.

◆ test_marker_update_end()

static void test_marker_update_end ( void  )
static

Definition at line 1407 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_marker_update_end_after_shift()

static void test_marker_update_end_after_shift ( void  )
static

Check that the budget is measured with fr_sbuff_used_total(), not fr_sbuff_used()

fr_sbuff_shift() moves data out of the buffer and adds the amount which fr_sbuff_start() can no longer account for to fr_sbuff_shifted(). So fr_sbuff_used_total() does not change across a shift, while fr_sbuff_used() shrinks. See test_shift_used_accounting().

fr_sbuff_out_unescape_until() re-runs fr_sbuff_marker_update_end() after every extension, and an extension is exactly when a shift happens. Measuring the budget with fr_sbuff_used() would therefore reset the budget on every shift, and the operation could copy more than it was allowed to.

The budget below is larger than fr_sbuff_used() but smaller than fr_sbuff_used_total(), so the two accessors give different answers.

Definition at line 1535 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_next_if_char()

static void test_next_if_char ( void  )
static

Definition at line 2244 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_next_unless_char()

static void test_next_unless_char ( void  )
static

Definition at line 2267 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_no_advance()

static void test_no_advance ( void  )
static

Definition at line 1118 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_out_bool()

static void test_out_bool ( void  )
static

Definition at line 1816 of file sbuff_tests.c.

◆ test_out_float()

static void test_out_float ( void  )
static

Definition at line 1795 of file sbuff_tests.c.

◆ test_out_int()

static void test_out_int ( void  )
static

Definition at line 1733 of file sbuff_tests.c.

◆ test_out_uint()

static void test_out_uint ( void  )
static

Definition at line 1766 of file sbuff_tests.c.

◆ test_parse_init()

static void test_parse_init ( void  )
static

Definition at line 46 of file sbuff_tests.c.

◆ test_shift_used_accounting()

static void test_shift_used_accounting ( void  )
static

Definition at line 1351 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_talloc_extend()

static void test_talloc_extend ( void  )
static

Definition at line 1133 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_talloc_extend_init_zero()

static void test_talloc_extend_init_zero ( void  )
static

Definition at line 1213 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_talloc_extend_multi_level()

static void test_talloc_extend_multi_level ( void  )
static

Definition at line 1244 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_talloc_extend_with_marker()

static void test_talloc_extend_with_marker ( void  )
static

Definition at line 1277 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_talloc_extend_with_shift()

static void test_talloc_extend_with_shift ( void  )
static

Definition at line 1326 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_terminal_merge()

static void test_terminal_merge ( void  )
static

Definition at line 1054 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_terminal_search_at_end_no_overrun()

static void test_terminal_search_at_end_no_overrun ( void  )
static

Definition at line 1027 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_terminal_search_past_visible_end()

static void test_terminal_search_past_visible_end ( void  )
static

Definition at line 997 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_unescape_multi_char_terminals()

static void test_unescape_multi_char_terminals ( void  )
static

Definition at line 911 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_unescape_until()

static void test_unescape_until ( void  )
static

Definition at line 460 of file sbuff_tests.c.

+ Here is the call graph for this function:

◆ test_unescape_until_escape_bounds()

static void test_unescape_until_escape_bounds ( void  )
static

Check that a hex or octal escape sequence cannot consume more input than "len" allows.

fr_sbuff_out_unescape_until() bounds the input it consumes with a marker placed "len" bytes ahead of the start. The escape sequences are the one place where the input is advanced by more than a byte at a time, so they are the one place where the marker can be stepped over.

An escape sequence which does not fit within "len" is not a complete escape sequence, and is copied out as-is. That is the same thing which happens to an incomplete escape sequence at the end of the input.

Definition at line 788 of file sbuff_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ allow_lowercase_and_space

bool allow_lowercase_and_space[SBUFF_CHAR_CLASS]
static
Initial value:
= {
['a'] = true, ['b'] = true, ['c'] = true, ['d'] = true, ['e'] = true,
['f'] = true, ['g'] = true, ['h'] = true, ['i'] = true, ['j'] = true,
['k'] = true, ['l'] = true, ['m'] = true, ['n'] = true, ['o'] = true,
['p'] = true, ['q'] = true, ['r'] = true, ['s'] = true, ['t'] = true,
['u'] = true, ['v'] = true, ['w'] = true, ['x'] = true, ['y'] = true,
['z'] = true, [' '] = true
}

Definition at line 239 of file sbuff_tests.c.

◆ allow_lowercase_and_space_no_t

bool allow_lowercase_and_space_no_t[SBUFF_CHAR_CLASS]
static
Initial value:
= {
['a'] = true, ['b'] = true, ['c'] = true, ['d'] = true, ['e'] = true,
['f'] = true, ['g'] = true, ['h'] = true, ['i'] = true, ['j'] = true,
['k'] = true, ['l'] = true, ['m'] = true, ['n'] = true, ['o'] = true,
['p'] = true, ['q'] = true, ['r'] = true, ['s'] = true, ['t'] = false,
['u'] = true, ['v'] = true, ['w'] = true, ['x'] = true, ['y'] = true,
['z'] = true, [' '] = true
}

Definition at line 248 of file sbuff_tests.c.

◆ TEST_LIST

TEST_LIST

Definition at line 2290 of file sbuff_tests.c.