26#include <freeradius-devel/util/value.h>
289 TEST_MSG(
"Expected 12345, got %u", dst.vb_uint32);
414 TEST_CHECK(dst.vb_strvalue != src.vb_strvalue);
430 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02\x03", 3) == 0);
456#define SAFE_FOR_X ((fr_value_box_safe_for_t) 0x1000)
457#define SAFE_FOR_Y ((fr_value_box_safe_for_t) 0x2000)
485 TEST_MSG(
"Expected safe_for %#lx, got %#lx", (
unsigned long)
SAFE_FOR_X, (
unsigned long) dst.vb_safefor);
502 TEST_MSG(
"Expected safe_for %#lx, got %#lx", (
unsigned long)
SAFE_FOR_X, (
unsigned long) dst.vb_safefor);
519 TEST_MSG(
"Expected safe_for NONE, got %#lx", (
unsigned long) dst.vb_safefor);
530 fr_value_box_list_init(list);
531 for (i = 0; i < num; i++) {
538 fr_value_box_list_insert_tail(list, vb);
547 fr_value_box_list_t list;
558 TEST_MSG(
"Expected safe_for %#lx, got %#lx", (
unsigned long) expect, (
unsigned long)
out.vb_safefor);
617 fr_value_box_list_t list;
621 head = fr_value_box_list_head(&list);
627 TEST_MSG(
"Expected safe_for %#lx, got %#lx", (
unsigned long)
SAFE_FOR_X, (
unsigned long)
head->vb_safefor);
629 fr_value_box_list_talloc_free(&list);
637 fr_value_box_list_t list;
645 fr_value_box_list_talloc_free(&list);
652 fr_value_box_list_talloc_free(&list);
654 TEST_CASE(
"Group children are merged, the group box itself is not");
655 fr_value_box_list_init(&list);
659 fr_value_box_list_insert_tail(&list, group);
663 fr_value_box_list_talloc_free(&list);
700 TEST_CHECK(memcmp(vb.vb_strvalue,
"hello\0world", 11) == 0);
818 TEST_MSG(
"Expected 42, got %u", vb.vb_uint32);
828 TEST_MSG(
"Expected 0 (wrap), got %u", vb.vb_uint8);
838 TEST_MSG(
"Expected 0, got %d", vb.vb_int32);
932 TEST_MSG(
"Expected 0x12345678, got 0x%08x", dst.vb_uint32);
942 fr_value_box(&src, (uint64_t) 0x0102030405060708ULL,
false);
957 TEST_CHECK(dst.vb_uint64 == 0x0102030405060708ULL);
1037 fr_sbuff_terminate(&sbuff);
1050 fr_sbuff_terminate(&sbuff);
1063 fr_sbuff_terminate(&sbuff);
1078 fr_sbuff_terminate(&sbuff);
1084 fr_sbuff_terminate(&sbuff);
1097 fr_sbuff_terminate(&sbuff);
1111 "12345", strlen(
"12345"), NULL) > 0);
1114 TEST_MSG(
"Expected 12345, got %u", vb.vb_uint32);
1122 "-42", strlen(
"-42"), NULL) > 0);
1125 TEST_MSG(
"Expected -42, got %d", vb.vb_int32);
1133 "yes", strlen(
"yes"), NULL) > 0);
1143 "3.14", strlen(
"3.14"), NULL) > 0);
1145 TEST_CHECK((vb.vb_float64 > 3.13) && (vb.vb_float64 < 3.15));
1146 TEST_MSG(
"Expected ~3.14, got %f", vb.vb_float64);
1154 "0xdeadbeef", strlen(
"0xdeadbeef"), NULL) > 0);
1157 TEST_CHECK(memcmp(vb.vb_octets,
"\xde\xad\xbe\xef", 4) == 0);
1167 "hello world", strlen(
"hello world"), NULL) > 0);
1186 fr_sbuff_terminate(&sbuff);
1202 fr_sbuff_terminate(&sbuff);
1218 fr_sbuff_terminate(&sbuff);
1273 TEST_CASE(
"Replacing a string value copies the new bytes and keeps the flags");
1278 old = vb->vb_strvalue;
1283 TEST_CHECK(memcmp(vb->vb_strvalue,
"af\0ter", 6) == 0);
1288 TEST_CASE(
"Replacing from an aliased source copies before freeing");
1291 TEST_CHECK(memcmp(vb->vb_strvalue,
"\0ter", 4) == 0);
1300 TEST_CASE(
"String with escapable characters and an embedded NUL");
1307 TEST_CHECK(memcmp(vb->vb_strvalue,
"a%25b\0c", 7) == 0);
1318 TEST_CASE(
"String with nothing to escape is copied as is");
1334 TEST_CASE(
"Non-string input is cast to a string before escaping");
1337 vb->vb_uint32 = 100;
static int const char char buffer[256]
#define TEST_ASSERT(cond)
Common initialisation for acutest binaries.
#define TEST_CHECK_LEN(_got, _exp)
#define TEST_CHECK_RET(_got, _exp)
#define TEST_CHECK_STRCMP(_got, _exp)
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
@ FR_TYPE_FLOAT64
Double precision floating point.
@ CMP_ERR
comparison failed
#define FR_SBUFF_IN_CHAR_RETURN(_sbuff,...)
#define fr_sbuff_set(_dst, _src)
#define fr_sbuff_current(_sbuff_or_marker)
#define FR_SBUFF_IN_STRCPY_LITERAL_RETURN(_sbuff, _str)
#define fr_sbuff_extend(_sbuff_or_marker)
#define FR_SBUFF_SET_RETURN(_dst, _src)
#define FR_SBUFF(_sbuff_or_marker)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define FR_SBUFF_OUT(_start, _len_or_end)
fr_aka_sim_id_type_t type
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
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
fr_cmp_ret_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
fr_slen_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules)
size_t fr_value_box_network_length(fr_value_box_t const *value)
Get the size of the value held by the fr_value_box_t.
uint32_t fr_value_box_hash(fr_value_box_t const *vb)
Hash the contents of a value box.
ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules)
Print one boxed value to a string.
ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted)
Decode a fr_value_box_t from serialized binary data.
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
int fr_value_box_asprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt,...)
Print a formatted string using our internal printf wrapper and assign it to a value box.
int fr_value_box_escape_in_place_func(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_sbuff_escape_func_t escape)
Escape a value box in place using an sbuff escape function.
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
int fr_value_box_cmp_op(fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
Compare two attributes using an operator.
int fr_value_box_bstrndup_replace(TALLOC_CTX *ctx, fr_value_box_t *vb, char const *src, ssize_t len)
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a copy of a ...
uint64_t fr_value_box_as_uint64(fr_value_box_t const *vb)
Return a uint64_t from a fr_value_box_t.
bool fr_value_box_is_truthy(fr_value_box_t const *in)
Check truthiness of values.
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv)
Convert one type of fr_value_box_t to another in place.
void fr_value_box_increment(fr_value_box_t *vb)
Increment a boxed value.
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value)
Encode a single value box, serializing its contents in generic network format.
void fr_value_box_list_safety_merge(fr_value_box_t *out, fr_value_box_list_t const *list)
Set the safety of out to the most restrictive safety of any leaf box in a list.
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted)
Copy a buffer to a fr_value_box_t.
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size)
Concatenate a list of value boxes.
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
#define fr_value_box_mark_safe_for(_box, _safe_for)
#define fr_value_box_is_safe_for_only(_box, _safe_for)
#define fr_value_box_init_null(_vb)
Initialise an empty/null box that will be filled later.
#define fr_value_box(_box, _var, _tainted)
Automagically fill in a box, determining the value type from the type of the C variable.
#define FR_VALUE_BOX_SAFE_FOR_NONE
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
static size_t char ** out
#define FR_VALUE_BOX_SAFE_FOR_ANY
static void test_clear(void)
static void test_escape_in_place_func_cast(void)
static void test_cmp_int32(void)
static void test_strdup(void)
static void test_copy_string(void)
static void test_tainted_flag(void)
static void test_from_str_int32(void)
static void test_cast_uint32_to_string_clears_safe_for(void)
static void test_cmp_op_ge(void)
static void test_cmp_uint32_equal(void)
static void test_cmp_op_ne(void)
static void test_concat_x_y_is_none(void)
static void test_cmp_octets_length(void)
static void safe_for_list_build(fr_value_box_list_t *list, fr_value_box_safe_for_t const tokens[], size_t num)
Build a list of single character string boxes, each marked with the matching token.
static void test_concat_x_none_is_none(void)
static void test_round_trip_network_uint32(void)
static void test_network_int32(void)
static void test_cast_uint32_to_uint64(void)
static void test_as_uint64(void)
static void test_from_str_float64(void)
static void test_from_str_string(void)
static void test_print_octets(void)
static void test_network_uint32(void)
static TALLOC_CTX * autofree
static void test_round_trip_uint32(void)
static void test_copy_uint32(void)
static void test_print_string(void)
static void test_round_trip_int64(void)
static void test_asprintf(void)
static void test_print_uint32(void)
static void test_network_uint64(void)
static void test_network_length(void)
static void test_concat_into_head_x_x_is_x(void)
The list head doubles as the output box.
static void test_cast_uint32_to_string(void)
static void test_cast_octets_to_string_preserves_safe_for(void)
static void test_bstrndup(void)
static void test_print_int32_negative(void)
static void test_increment_uint32(void)
static void test_concat_any_x_is_x(void)
static void test_bstrndup_replace(void)
static void test_cast_int32_to_int64(void)
static void test_round_trip_bool(void)
static void test_cast_in_place_uint32_to_string(void)
static void test_list_safety_merge(void)
static void test_increment_uint8_overflow(void)
static void test_truthy_bool(void)
static void test_hash_different_values(void)
static void test_cast_uint8_to_uint32(void)
static void test_escape_in_place_func_string(void)
static void test_cmp_op_lt(void)
static void test_cast_same_type(void)
static void test_cmp_octets(void)
static void test_copy_preserves_safe_for(void)
static void test_cast_bool_to_uint32(void)
static void test_escape_in_place_func_unchanged(void)
static void test_from_str_bool(void)
static void test_concat_x_any_is_x(void)
static void test_concat_octets_x_x_is_x(void)
static void test_cmp_op_eq(void)
static void test_cast_in_place_uint32_to_uint64(void)
static void test_cast_uint32_to_bool(void)
static void test_copy_preserves_tainted(void)
static void test_cmp_different_types(void)
static void test_concat_any_any_is_any(void)
static void test_concat_x_x_is_x(void)
static void test_cmp_string(void)
static void test_hash_same_values(void)
static fr_slen_t test_percent_escape(fr_sbuff_t *out, fr_sbuff_t *in)
Escape function for the in-place escape tests, writes '' as "%25".
static void test_cmp_float64(void)
static void test_truthy_octets(void)
static void test_from_str_octets(void)
static void test_cast_string_to_uint32(void)
static void test_clear_string(void)
static void test_init(void)
static void test_hash_string(void)
static void test_cmp_op_le(void)
static void test_truthy_uint32(void)
static void test_memdup(void)
static void test_increment_int32(void)
static void test_cmp_op_gt(void)
static void safe_for_concat_check(fr_type_t type, fr_value_box_safe_for_t const tokens[], size_t num, fr_value_box_safe_for_t expect)
Concatenate a list into a separate output box and check the resulting safe_for.
static void test_print_bool(void)
static void test_truthy_string(void)
static void test_cmp_bool(void)
static void test_cmp_uint32_less(void)
static void test_cast_string_to_octets_preserves_safe_for(void)
static void test_copy_octets(void)
static void test_from_str_uint32(void)
static void test_network_bool(void)