25# define TEST_INIT test_init()
27#include <freeradius-devel/util/test/acutest.h>
28#include <freeradius-devel/util/test/acutest_helpers.h>
29#include <freeradius-devel/util/dict_test.h>
30#include <freeradius-devel/server/tmpl.h>
31#include <freeradius-devel/server/tmpl_dcursor.h>
32#include <freeradius-devel/server/pair.h>
83 .dict_def = test_dict, \
84 .list_def = request_attr_request, \
175 "Test-Nested-Top-TLV-0.Child-TLV.Leaf-String",
test_rules());
195 .allow_unresolved =
true,
215 TEST_MSG(
"Expected negative slen for invalid attribute, got %zd", slen);
228 .allow_unresolved =
false,
234 TEST_MSG(
"Expected no data when no input, got slen=%zd", slen);
304 .allow_unresolved =
true,
372 box.vb_ip.af = AF_INET;
373 box.vb_ip.prefix = 32;
374 box.vb_ip.addr.v4.s_addr = htonl(INADDR_LOOPBACK);
477 TEST_MSG(
"Expected failure casting 'not_a_number' to uint32");
563 fr_value_box_list_t
out;
568 fr_value_box_list_init(&
out);
581 result = fr_value_box_list_head(&
out);
587 fr_value_box_list_talloc_free(&
out);
595 fr_value_box_list_t
out;
602 fr_value_box_list_init(&
out);
617 result = fr_value_box_list_head(&
out);
620 TEST_CHECK(strcmp(result->vb_strvalue,
"hello") == 0);
623 fr_value_box_list_talloc_free(&
out);
631 fr_value_box_list_t
out;
637 fr_value_box_list_init(&
out);
649 result = fr_value_box_list_head(&
out);
651 TEST_MSG(
"Expected empty result list for missing attribute");
654 fr_value_box_list_talloc_free(&
out);
662 fr_value_box_list_t
out;
669 fr_value_box_list_init(&
out);
685 result = fr_value_box_list_head(&
out);
690 result = fr_value_box_list_next(&
out, result);
695 fr_value_box_list_talloc_free(&
out);
703 fr_value_box_list_t
out;
710 fr_value_box_list_init(&
out);
726 result = fr_value_box_list_head(&
out);
730 TEST_MSG(
"Expected count=2, got %" PRIu32, result->vb_uint32);
733 fr_value_box_list_talloc_free(&
out);
806 TEST_MSG(
"Expected 0 (found existing), got %d", ret);
828 TEST_MSG(
"Expected 1 (created new), got %d", ret);
830 TEST_MSG(
"Expected non-NULL vp from find_or_add");
855 TEST_CHECK(strcmp(str,
"Test-String-0") == 0);
856 TEST_MSG(
"Expected 'Test-String-0', got '%s'", str);
883 TEST_MSG(
"Expected 'hello', got '%s'", str);
910 TEST_MSG(
"Expected '42', got '%s'", str);
941 TEST_MSG(
"Expected \"'hello'\", got '%s'", str);
956 tmpl_t *unresolved_vpt = NULL;
1013 TEST_MSG(
"Expected error for empty attr ref '&', got slen=%zd", slen);
1015 TEST_MSG(
"Expected non-zero error code, got %d",
err);
1027 .allow_unresolved =
false,
1033 TEST_MSG(
"Expected error when unresolved not allowed, got slen=%zd", slen);
1100DIAG_ON(declaration-after-statement)
#define TEST_ASSERT(cond)
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
fr_dict_attr_t const * fr_dict_attr_test_nested_leaf_string
fr_dict_attr_t const * fr_dict_attr_test_int32
fr_dict_attr_t const * fr_dict_attr_test_string
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_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
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.
Optional arguments for initialising requests.
#define FR_SBUFF_IN_STR(_start)
#define pair_append_request(_attr, _da)
Allocate and append a fr_pair_t to the request list.
int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt))
Returns the first VP matching a tmpl_t.
static int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
Return the last attribute reference's attribute number.
#define tmpl_is_attr_unresolved(vpt)
static fr_slen_t tmpl_aprint_quoted(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt) 1(tmpl_print_quoted
#define tmpl_value(_tmpl)
int tmpl_afrom_value_box(TALLOC_CTX *ctx, tmpl_t **out, fr_value_box_t *data, bool steal)
Create a tmpl_t from a fr_value_box_t.
#define tmpl_is_xlat_unresolved(vpt)
#define tmpl_is_attr(vpt)
static fr_slen_t tmpl_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules) 1(tmpl_print
ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, char const *name, tmpl_rules_t const *rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
#define tmpl_contains_attr(vpt)
int tmpl_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Gets the value of a tmpl.
tmpl_t * tmpl_copy(TALLOC_CTX *ctx, tmpl_t const *in)
Copy a tmpl.
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
int tmpl_cast_in_place(tmpl_t *vpt, fr_type_t type, fr_dict_attr_t const *enumv))
Convert tmpl_t of type TMPL_TYPE_DATA_UNRESOLVED or TMPL_TYPE_DATA to TMPL_TYPE_DATA of type specifie...
#define tmpl_is_data(vpt)
static size_t tmpl_attr_num_elements(tmpl_t const *vpt)
The number of attribute references contained within a tmpl.
#define tmpl_value_type(_tmpl)
@ TMPL_ATTR_ERROR_NONE
No error.
#define tmpl_is_data_unresolved(vpt)
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt)
Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one.
#define tmpl_needs_resolving(vpt)
Optional arguments passed to vp_tmpl functions.
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Stores an attribute, a value and various bits of other data.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
static void test_eval_attr_found(void)
static void test_eval_attr_missing(void)
static void test_cast_unresolved_to_uint32(void)
static void test_parse_attr_missing(void)
static void test_parse_double_quoted_literal(void)
static void test_cast_uint32_to_uint64(void)
static TALLOC_CTX * autofree
static request_t * request_fake_alloc(void)
static void test_parse_attr_empty_ref(void)
static void test_from_value_box_ipaddr(void)
static void test_parse_attr_invalid(void)
static void test_type_checking(void)
static void test_parse_attr_simple(void)
static void test_parse_attr_last(void)
static void test_cast_invalid(void)
static void test_copy_attr(void)
static void test_from_value_box_uint32(void)
static void test_parse_attr_unresolved_disallowed(void)
static void test_parse_attr_nested(void)
static void test_find_or_add_existing(void)
static void test_copy_data_unresolved(void)
static void test_parse_attr_index(void)
static void test_print_data_string(void)
static fr_dict_t * test_dict
static void test_print_data_uint32(void)
static void test_print_quoted(void)
static void test_parse_attr_emptystring(void)
static void test_parse_attr_all(void)
static void test_copy_data(void)
static void test_eval_attr_count(void)
static void test_parse_bareword_attr(void)
static void test_eval_data(void)
static void test_parse_attr_count(void)
#define test_rules()
Default tmpl rules for tests.
static void test_find_or_add_new(void)
static void test_find_vp_found(void)
static void test_from_value_box_string(void)
static void test_find_vp_missing(void)
static void test_parse_double_quoted_xlat(void)
static void test_init(void)
Global initialisation.
static void test_print_attr(void)
static void test_parse_single_quoted(void)
static void test_eval_attr_multiple(void)
static void test_cast_unresolved_to_string(void)
char const * fr_strerror(void)
Get the last library error.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
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
void fr_value_box_strdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a box, but don't copy it.
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
static size_t char ** out