3 # define TEST_INIT test_init()
4 # define TEST_FINI test_free()
6 #include <freeradius-devel/util/acutest.h>
7 #include <freeradius-devel/util/acutest_helpers.h>
8 #include <freeradius-devel/util/dict_test.h>
9 #include <freeradius-devel/server/tmpl_dcursor.h>
10 #include <freeradius-devel/server/pair.h>
16 DIAG_OFF(declaration-after-statement)
62 #define pair_defs(_x) \
63 fr_pair_t *int32_vp ## _x; \
64 fr_pair_t *string_vp ## _x; \
65 fr_pair_t *group_vp ## _x; \
66 fr_pair_t *child_vp ## _x; \
67 fr_pair_t *top_vp ## _x; \
68 fr_pair_t *mid_vp ## _x; \
69 fr_pair_t *leaf_string_vp ## _x; \
70 fr_pair_t *leaf_int32_vp ## _x
72 #define pair_defs_thin(_x) \
73 fr_pair_t *int32_vp ## _x; \
74 fr_pair_t *group_vp ## _x; \
75 fr_pair_t *top_vp ## _x; \
76 fr_pair_t *mid_vp ## _x; \
77 fr_pair_t *leaf_int32_vp ## _x
79 #define pair_populate(_x) do { \
80 pair_append_request(&int32_vp ## _x, fr_dict_attr_test_int32); \
81 pair_append_request(&string_vp ## _x, fr_dict_attr_test_string); \
82 pair_append_request(&group_vp ## _x, fr_dict_attr_test_group); \
83 fr_pair_append_by_da(group_vp ## _x, &child_vp ## _x, &group_vp ## _x->children, fr_dict_attr_test_int16); \
84 pair_append_request(&top_vp ## _x, fr_dict_attr_test_nested_top_tlv); \
85 fr_pair_append_by_da(top_vp ## _x, &mid_vp ## _x, &top_vp ## _x->children, fr_dict_attr_test_nested_child_tlv); \
86 fr_pair_append_by_da(mid_vp ## _x, &leaf_string_vp ## _x, &mid_vp ## _x->children, fr_dict_attr_test_nested_leaf_string); \
87 fr_pair_append_by_da(mid_vp ## _x, &leaf_int32_vp ## _x, &mid_vp ## _x->children, fr_dict_attr_test_nested_leaf_int32); \
90 #define pair_populate_thin(_x) do { \
91 pair_append_request(&int32_vp ## _x, fr_dict_attr_test_int32); \
92 pair_append_request(&group_vp ## _x, fr_dict_attr_test_group); \
93 pair_append_request(&top_vp ## _x, fr_dict_attr_test_nested_top_tlv); \
94 fr_pair_append_by_da(top_vp ## _x, &mid_vp ## _x, &top_vp ## _x->children, fr_dict_attr_test_nested_child_tlv); \
95 fr_pair_append_by_da(mid_vp ## _x, &leaf_int32_vp ## _x, &mid_vp ## _x->children, fr_dict_attr_test_nested_leaf_int32); \
118 #define test_cursor() &vars.cursor
119 #define test_vp() vars.vp
120 #define test_vp_p() &vars.vp
121 #define test_vp_set(_vp) vars.vp = _vp
126 #define common_vars \
127 tmpl_dcursor_vars_t vars; \
128 request_t *request = request_fake_alloc()
137 static inline CC_HINT(always_inline)
152 *vp_out =
tmpl_dcursor_init(&vars->err, NULL, &vars->cc, &vars->cursor, request, vars->vpt);
156 #define tmpl_setup_and_cursor_init(_vp_out, _ref) \
157 if (_tmpl_setup_and_cursor_init(_vp_out, &vars, request, _ref)) return
166 static inline CC_HINT(always_inline)
185 #define tmpl_setup_and_cursor_build_init(_vp_out, _ref) \
186 if (_tmpl_setup_and_cursor_build_init(_vp_out, &vars, request, _ref)) return
192 debug_attr_list(&request->request_pairs, 0); \
193 vars.vp = fr_dcursor_next(test_cursor()); \
194 TEST_CHECK_PAIR(vars.vp, NULL); \
195 TEST_MSG("Cursor should've been empty (i.e. returned NULL) at end of test"); \
196 tmpl_dcursor_clear(&vars.cc); \
197 TEST_CHECK_RET(talloc_free(vars.vpt), 0); \
198 TEST_CHECK_RET(talloc_free(request), 0)
204 #define build_test_end \
205 debug_attr_list(&request->request_pairs, 0); \
206 test_vp_set(fr_dcursor_next(test_cursor())); \
207 TEST_CHECK_PAIR(test_vp(), NULL); \
208 tmpl_dcursor_clear(&vars.cc)
214 switch (
vp->vp_type) {
236 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
251 TEST_CHECK_PAIR(
test_vp(), NULL);
266 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
281 TEST_CHECK_PAIR(
test_vp(), NULL);
296 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
313 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
330 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
347 TEST_CHECK_PAIR(
test_vp(), NULL);
365 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
368 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
385 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
402 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
405 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
420 TEST_CHECK_PAIR(
test_vp(), child_vp1);
435 TEST_CHECK_PAIR(
test_vp(), NULL);
450 TEST_CHECK_PAIR(
test_vp(), child_vp1);
465 TEST_CHECK_PAIR(
test_vp(), NULL);
482 TEST_CHECK_PAIR(
test_vp(), child_vp1);
499 TEST_CHECK_PAIR(
test_vp(), child_vp2);
516 TEST_CHECK_PAIR(
test_vp(), child_vp1);
519 TEST_CHECK_PAIR(
test_vp(), child_vp2);
536 TEST_CHECK_PAIR(
test_vp(), child_vp2);
553 TEST_CHECK_PAIR(
test_vp(), NULL);
568 TEST_CHECK_PAIR(
test_vp(), leaf_string_vp1);
583 TEST_CHECK_PAIR(
test_vp(), NULL);
598 TEST_CHECK_PAIR(
test_vp(), leaf_string_vp1);
612 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp1);
626 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp1);
629 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp2);
643 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp2);
656 TEST_CHECK_PAIR_NEQ(inserted, NULL);
660 TEST_CHECK_PAIR(
test_vp(), inserted);
673 TEST_CHECK_PAIR_NEQ(inserted, NULL);
677 TEST_CHECK_PAIR(
test_vp(), inserted);
688 TEST_CHECK_PAIR_NEQ(inserted, NULL);
692 TEST_CHECK_PAIR(
test_vp(), inserted);
707 TEST_CHECK_PAIR_NEQ(inserted, NULL);
710 TEST_CHECK_PAIR_NEQ(second, NULL);
711 TEST_CHECK_PAIR_NEQ(second, inserted);
715 TEST_CHECK_PAIR(
test_vp(), inserted);
717 TEST_CHECK_PAIR(
test_vp(), second);
730 TEST_CHECK_PAIR_NEQ(inserted, NULL);
734 TEST_CHECK_PAIR(
test_vp(), inserted);
745 TEST_CHECK_PAIR_NEQ(inserted, NULL);
749 TEST_CHECK_PAIR(
test_vp(), inserted);
764 TEST_CHECK_PAIR_NEQ(inserted, NULL);
765 TEST_CHECK_PAIR_NEQ(inserted, leaf_string_vp1);
769 TEST_CHECK_PAIR(
test_vp(), inserted);
780 TEST_CHECK_PAIR(inserted, NULL);
784 TEST_CHECK_PAIR(
test_vp(), NULL);
795 TEST_CHECK_PAIR(inserted, NULL);
799 TEST_CHECK_PAIR(
test_vp(), NULL);
845 DIAG_ON(declaration-after-statement)
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs)
Initialise a test dictionary and add our test_defs to it.
fr_packet_t * fr_packet_alloc(TALLOC_CTX *ctx, bool new_vector)
Allocate a new fr_packet_t.
fr_dict_attr_t const * request_attr_request
void request_global_free(void)
int request_global_init(void)
#define request_local_alloc_external(_ctx, _args)
Allocate a new external request outside of the request pool.
#define FR_SBUFF_IN(_start, _len_or_end)
ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
Optional arguments passed to vp_tmpl functions.
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
fr_pair_t * tmpl_dcursor_pair_build(fr_pair_t *parent, fr_dcursor_t *cursor, fr_dict_attr_t const *da, UNUSED void *uctx)
Simple pair building callback for use with tmpl_dcursors.
#define tmpl_dcursor_build_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx)
#define tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt)
Maintains state between cursor calls.
static void test_level_3_build_entire(void)
static void test_level_2_two_last(void)
#define pair_populate(_x)
static void test_level_3_two(void)
#define tmpl_setup_and_cursor_build_init(_vp_out, _ref)
static TALLOC_CTX * autofree
static void test_level_3_two_last(void)
static int _tmpl_setup_and_cursor_build_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, request_t *request, char const *ref)
Initialise a tmpl using the _attr_str string, and return the first pair.
static void test_level_2_two_missing(void)
static void test_level_1_build(void)
static void test_level_1_two_all(void)
static void test_level_1_two_third(void)
static void test_level_3_one_all(void)
static void test_level_2_build_intermediate(void)
#define pair_populate_thin(_x)
#define pair_defs_thin(_x)
static void test_level_2_two_second(void)
static void test_level_1_two_second(void)
static int _tmpl_setup_and_cursor_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, request_t *request, char const *ref)
Initialise a tmpl using the _attr_str string, and return the first pair.
static void test_level_1_two_count(void)
static void test_level_1_one_second(void)
static void test_level_1_one(void)
static void debug_attr_list(fr_pair_list_t *list, int indent)
static void test_free(void)
static void test_level_2_build_leaf(void)
static void test_level_3_build_invalid2(void)
static fr_dict_t * test_dict
static void test_level_3_one_second(void)
static void test_level_2_two(void)
static void test_level_1_one_last(void)
static void test_level_2_one_missing(void)
static void test_level_3_build_partial(void)
static void test_level_2_one(void)
static void test_level_3_two_all(void)
static void test_level_1_two(void)
static void test_level_1_one_all(void)
#define tmpl_setup_and_cursor_init(_vp_out, _ref)
static void test_init(void)
Global initialisation.
static void test_level_1_one_missing(void)
static void test_level_3_one(void)
static void test_level_2_one_all(void)
static void test_level_2_build_multi(void)
static void test_level_1_two_last(void)
static void test_level_2_one_second(void)
static void test_level_2_two_all(void)
static void test_level_3_build_invalid1(void)
static request_t * request_fake_alloc(void)
static void test_level_3_build_leaf(void)
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
char const * fr_strerror(void)
Get the last library error.
#define FR_TYPE_STRUCTURAL
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
#define RADIUSD_MAGIC_NUMBER