2 # define TEST_INIT test_init()
4 #include <freeradius-devel/util/acutest.h>
5 #include <freeradius-devel/util/acutest_helpers.h>
6 #include <freeradius-devel/util/dict_test.h>
7 #include <freeradius-devel/server/tmpl_dcursor.h>
8 #include <freeradius-devel/server/pair.h>
14 DIAG_OFF(declaration-after-statement)
55 #define pair_defs(_x) \
56 fr_pair_t *int32_vp ## _x; \
57 fr_pair_t *string_vp ## _x; \
58 fr_pair_t *group_vp ## _x; \
59 fr_pair_t *child_vp ## _x; \
60 fr_pair_t *top_vp ## _x; \
61 fr_pair_t *mid_vp ## _x; \
62 fr_pair_t *leaf_string_vp ## _x; \
63 fr_pair_t *leaf_int32_vp ## _x
65 #define pair_defs_thin(_x) \
66 fr_pair_t *int32_vp ## _x; \
67 fr_pair_t *group_vp ## _x; \
68 fr_pair_t *top_vp ## _x; \
69 fr_pair_t *mid_vp ## _x; \
70 fr_pair_t *leaf_int32_vp ## _x
72 #define pair_populate(_x) do { \
73 pair_append_request(&int32_vp ## _x, fr_dict_attr_test_int32); \
74 pair_append_request(&string_vp ## _x, fr_dict_attr_test_string); \
75 pair_append_request(&group_vp ## _x, fr_dict_attr_test_group); \
76 fr_pair_append_by_da(group_vp ## _x, &child_vp ## _x, &group_vp ## _x->children, fr_dict_attr_test_int16); \
77 pair_append_request(&top_vp ## _x, fr_dict_attr_test_nested_top_tlv); \
78 fr_pair_append_by_da(top_vp ## _x, &mid_vp ## _x, &top_vp ## _x->children, fr_dict_attr_test_nested_child_tlv); \
79 fr_pair_append_by_da(mid_vp ## _x, &leaf_string_vp ## _x, &mid_vp ## _x->children, fr_dict_attr_test_nested_leaf_string); \
80 fr_pair_append_by_da(mid_vp ## _x, &leaf_int32_vp ## _x, &mid_vp ## _x->children, fr_dict_attr_test_nested_leaf_int32); \
83 #define pair_populate_thin(_x) do { \
84 pair_append_request(&int32_vp ## _x, fr_dict_attr_test_int32); \
85 pair_append_request(&group_vp ## _x, fr_dict_attr_test_group); \
86 pair_append_request(&top_vp ## _x, fr_dict_attr_test_nested_top_tlv); \
87 fr_pair_append_by_da(top_vp ## _x, &mid_vp ## _x, &top_vp ## _x->children, fr_dict_attr_test_nested_child_tlv); \
88 fr_pair_append_by_da(mid_vp ## _x, &leaf_int32_vp ## _x, &mid_vp ## _x->children, fr_dict_attr_test_nested_leaf_int32); \
111 #define test_cursor() &vars.cursor
112 #define test_vp() vars.vp
113 #define test_vp_p() &vars.vp
114 #define test_vp_set(_vp) vars.vp = _vp
119 #define common_vars \
120 tmpl_dcursor_vars_t vars; \
121 request_t *request = request_fake_alloc()
130 static inline CC_HINT(always_inline)
145 *vp_out =
tmpl_dcursor_init(&vars->err, NULL, &vars->cc, &vars->cursor, request, vars->vpt);
149 #define tmpl_setup_and_cursor_init(_vp_out, _ref) \
150 if (_tmpl_setup_and_cursor_init(_vp_out, &vars, request, _ref)) return
159 static inline CC_HINT(always_inline)
178 #define tmpl_setup_and_cursor_build_init(_vp_out, _ref) \
179 if (_tmpl_setup_and_cursor_build_init(_vp_out, &vars, request, _ref)) return
185 debug_attr_list(&request->request_pairs, 0); \
186 vars.vp = fr_dcursor_next(test_cursor()); \
187 TEST_CHECK_PAIR(vars.vp, NULL); \
188 TEST_MSG("Cursor should've been empty (i.e. returned NULL) at end of test"); \
189 tmpl_dcursor_clear(&vars.cc); \
190 TEST_CHECK_RET(talloc_free(vars.vpt), 0); \
191 TEST_CHECK_RET(talloc_free(request), 0)
197 #define build_test_end \
198 debug_attr_list(&request->request_pairs, 0); \
199 test_vp_set(fr_dcursor_next(test_cursor())); \
200 TEST_CHECK_PAIR(test_vp(), NULL); \
201 tmpl_dcursor_clear(&vars.cc)
207 switch (
vp->vp_type) {
229 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
244 TEST_CHECK_PAIR(
test_vp(), NULL);
259 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
274 TEST_CHECK_PAIR(
test_vp(), NULL);
289 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
306 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
323 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
340 TEST_CHECK_PAIR(
test_vp(), NULL);
358 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
361 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
378 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
395 TEST_CHECK_PAIR(
test_vp(), int32_vp1);
398 TEST_CHECK_PAIR(
test_vp(), int32_vp2);
413 TEST_CHECK_PAIR(
test_vp(), child_vp1);
428 TEST_CHECK_PAIR(
test_vp(), NULL);
443 TEST_CHECK_PAIR(
test_vp(), child_vp1);
458 TEST_CHECK_PAIR(
test_vp(), NULL);
475 TEST_CHECK_PAIR(
test_vp(), child_vp1);
492 TEST_CHECK_PAIR(
test_vp(), child_vp2);
509 TEST_CHECK_PAIR(
test_vp(), child_vp1);
512 TEST_CHECK_PAIR(
test_vp(), child_vp2);
529 TEST_CHECK_PAIR(
test_vp(), child_vp2);
546 TEST_CHECK_PAIR(
test_vp(), NULL);
561 TEST_CHECK_PAIR(
test_vp(), leaf_string_vp1);
576 TEST_CHECK_PAIR(
test_vp(), NULL);
591 TEST_CHECK_PAIR(
test_vp(), leaf_string_vp1);
605 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp1);
619 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp1);
622 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp2);
636 TEST_CHECK_PAIR(
test_vp(), leaf_int32_vp2);
649 TEST_CHECK_PAIR_NEQ(inserted, NULL);
653 TEST_CHECK_PAIR(
test_vp(), inserted);
666 TEST_CHECK_PAIR_NEQ(inserted, NULL);
670 TEST_CHECK_PAIR(
test_vp(), inserted);
681 TEST_CHECK_PAIR_NEQ(inserted, NULL);
685 TEST_CHECK_PAIR(
test_vp(), inserted);
700 TEST_CHECK_PAIR_NEQ(inserted, NULL);
703 TEST_CHECK_PAIR_NEQ(second, NULL);
704 TEST_CHECK_PAIR_NEQ(second, inserted);
708 TEST_CHECK_PAIR(
test_vp(), inserted);
710 TEST_CHECK_PAIR(
test_vp(), second);
723 TEST_CHECK_PAIR_NEQ(inserted, NULL);
727 TEST_CHECK_PAIR(
test_vp(), inserted);
738 TEST_CHECK_PAIR_NEQ(inserted, NULL);
742 TEST_CHECK_PAIR(
test_vp(), inserted);
757 TEST_CHECK_PAIR_NEQ(inserted, NULL);
758 TEST_CHECK_PAIR_NEQ(inserted, leaf_string_vp1);
762 TEST_CHECK_PAIR(
test_vp(), inserted);
773 TEST_CHECK_PAIR(inserted, NULL);
777 TEST_CHECK_PAIR(
test_vp(), NULL);
788 TEST_CHECK_PAIR(inserted, NULL);
792 TEST_CHECK_PAIR(
test_vp(), NULL);
838 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
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_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