26#include <freeradius-devel/util/calc.h>
59 TEST_MSG(
"Expected 30, got %u", dst.vb_uint32);
73 TEST_MSG(
"Expected 20, got %u", dst.vb_uint32);
87 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
101 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
115 TEST_MSG(
"Expected 2, got %u", dst.vb_uint32);
129 TEST_MSG(
"Expected 0x0f, got 0x%x", dst.vb_uint32);
143 TEST_MSG(
"Expected 0xff, got 0x%x", dst.vb_uint32);
157 TEST_MSG(
"Expected 0xf0, got 0x%x", dst.vb_uint32);
172 TEST_MSG(
"Expected 0x100, got 0x%" PRIx64, dst.vb_uint64);
178 TEST_MSG(
"Expected 0x01, got 0x%x", dst.vb_uint32);
212 TEST_MSG(
"Expected 150, got %u", dst.vb_uint8);
242 TEST_MSG(
"Expected 20, got %d", dst.vb_int32);
256 TEST_MSG(
"Expected -20, got %d", dst.vb_int32);
270 TEST_MSG(
"Expected -42, got %d", dst.vb_int32);
284 TEST_MSG(
"Expected -7, got %d", dst.vb_int32);
403 TEST_MSG(
"Expected 4.0, got %f", dst.vb_float64);
417 TEST_MSG(
"Expected 6.5, got %f", dst.vb_float64);
431 TEST_MSG(
"Expected 21.0, got %f", dst.vb_float64);
444 TEST_CHECK((dst.vb_float64 > 3.14) && (dst.vb_float64 < 3.15));
445 TEST_MSG(
"Expected ~3.14, got %f", dst.vb_float64);
470 TEST_CHECK((dst.vb_float64 > 1.49) && (dst.vb_float64 < 1.51));
471 TEST_MSG(
"Expected ~1.5, got %f", dst.vb_float64);
488 TEST_MSG(
"Expected 4.0, got %f", (
double)dst.vb_float32);
518 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello world") == 0);
519 TEST_MSG(
"Expected 'hello world', got '%s'", dst.vb_strvalue);
538 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello ") == 0);
539 TEST_MSG(
"Expected 'hello ', got '%s'", dst.vb_strvalue);
577 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello world") == 0);
578 TEST_MSG(
"Expected 'hello world', got '%s'", dst.vb_strvalue);
596 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello") == 0);
597 TEST_MSG(
"Expected 'hello', got '%s'", dst.vb_strvalue);
614 TEST_CHECK(strcmp(dst.vb_strvalue,
"world") == 0);
615 TEST_MSG(
"Expected 'world', got '%s'", dst.vb_strvalue);
637 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02\x03\x04", 4) == 0);
657 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02", 2) == 0);
677 TEST_CHECK(memcmp(dst.vb_octets,
"\x0f\x0f", 2) == 0);
697 TEST_CHECK(memcmp(dst.vb_octets,
"\xff\xff", 2) == 0);
717 TEST_CHECK(memcmp(dst.vb_octets,
"\xf0\x0f", 2) == 0);
756 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02", 2) == 0);
774 TEST_CHECK(memcmp(dst.vb_octets,
"\x03\x04", 2) == 0);
921 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
934 TEST_MSG(
"Expected 0xf0, got 0x%02x", dst.vb_uint8);
947 TEST_MSG(
"Expected -42, got %d", dst.vb_int32);
979 TEST_MSG(
"Expected 15, got %u", dst.vb_uint32);
992 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
1005 TEST_MSG(
"Expected 99, got %u", dst.vb_uint32);
1033 TEST_MSG(
"Expected 30, got %u", dst.vb_uint32);
1049 TEST_MSG(
"Expected 30, got %" PRIu64, dst.vb_uint64);
1153 TEST_MSG(
"Expected 3000, got %u", dst.vb_uint16);
1178 fr_value_box(&a, (uint64_t) 0xff00ff00ff00ff00ULL,
false);
1179 fr_value_box(&b, (uint64_t) 0x0f0f0f0f0f0f0f0fULL,
false);
1182 TEST_CHECK(dst.vb_uint64 == 0x0f000f000f000f00ULL);
1183 TEST_MSG(
"Expected 0x0f000f000f000f00, got 0x%" PRIx64, dst.vb_uint64);
1192 fr_value_box(&a, (uint64_t) 0xf0f0f0f000000000ULL,
false);
1193 fr_value_box(&b, (uint64_t) 0x000000000f0f0f0fULL,
false);
1196 TEST_CHECK(dst.vb_uint64 == 0xf0f0f0f00f0f0f0fULL);
1197 TEST_MSG(
"Expected 0xf0f0f0f00f0f0f0f, got 0x%" PRIx64, dst.vb_uint64);
1206 fr_value_box(&a, (uint64_t) 0xffffffffffffffffULL,
false);
1207 fr_value_box(&b, (uint64_t) 0x0f0f0f0f0f0f0f0fULL,
false);
1210 TEST_CHECK(dst.vb_uint64 == 0xf0f0f0f0f0f0f0f0ULL);
1211 TEST_MSG(
"Expected 0xf0f0f0f0f0f0f0f0, got 0x%" PRIx64, dst.vb_uint64);
1226 TEST_MSG(
"Expected 0x10000, got 0x%" PRIx64, dst.vb_uint64);
1231 TEST_MSG(
"Expected 0x01, got 0x%" PRIx64, dst.vb_uint64);
1258 TEST_MSG(
"Expected 2, got %" PRIu64, dst.vb_uint64);
1272 TEST_MSG(
"Expected 14, got %" PRIu64, dst.vb_uint64);
1302 TEST_MSG(
"Expected 50, got %d", dst.vb_int8);
1316 TEST_MSG(
"Expected -50, got %d", dst.vb_int8);
1333 TEST_MSG(
"Expected 1000, got %d", dst.vb_int16);
1350 TEST_MSG(
"Expected -2, got %d", dst.vb_int32);
1367 TEST_MSG(
"Expected 0x00ff, got 0x%" PRIx64, dst.vb_int64);
1381 TEST_MSG(
"Expected 0xf00f, got 0x%" PRIx64, dst.vb_int64);
1395 TEST_MSG(
"Expected 0xf0f0, got 0x%" PRIx64, dst.vb_int64);
1410 TEST_MSG(
"Expected 0x1000, got 0x%" PRIx64, dst.vb_int64);
1415 TEST_MSG(
"Expected 0x10, got 0x%" PRIx64, dst.vb_int64);
1442 TEST_MSG(
"Expected 2, got %" PRId64, dst.vb_int64);
1459 TEST_MSG(
"Expected 6.5, got %f", (
double)dst.vb_float32);
1473 TEST_MSG(
"Expected 21.0, got %f", (
double)dst.vb_float32);
1487 TEST_MSG(
"Expected 3.0, got %f", (
double)dst.vb_float32);
1500 TEST_CHECK((dst.vb_float32 > 1.49f) && (dst.vb_float32 < 1.51f));
1501 TEST_MSG(
"Expected ~1.5, got %f", (
double)dst.vb_float32);
1611 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello") == 0);
1612 TEST_MSG(
"Expected 'hello', got '%s'", dst.vb_strvalue);
1700 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
1713 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
1726 TEST_MSG(
"Expected 0x0f, got 0x%x", dst.vb_uint32);
1739 TEST_MSG(
"Expected 0xff, got 0x%x", dst.vb_uint32);
1752 TEST_MSG(
"Expected 0xf0, got 0x%x", dst.vb_uint32);
1765 TEST_MSG(
"Expected 0x10, got 0x%x", dst.vb_uint32);
1778 TEST_MSG(
"Expected 0x100, got 0x%x", dst.vb_uint32);
1794 TEST_MSG(
"Expected 0xff00, got 0x%04x", dst.vb_uint16);
1807 TEST_MSG(
"Expected 0xffff0000, got 0x%08x", dst.vb_uint32);
1820 TEST_MSG(
"Expected UINT64_MAX, got 0x%" PRIx64, dst.vb_uint64);
1833 TEST_MSG(
"Expected -1, got %d", dst.vb_int32);
1845 TEST_CHECK((dst.vb_float64 > -3.15) && (dst.vb_float64 < -3.13));
1846 TEST_MSG(
"Expected -3.14, got %f", dst.vb_float64);
1859 TEST_MSG(
"Expected 255, got %u", dst.vb_uint8);
1885 src.vb_bool =
false;
1900 TEST_MSG(
"Expected 0, got %" PRId64, dst.vb_int64);
1913 TEST_MSG(
"Expected 3.5, got %f", dst.vb_float64);
1931 TEST_MSG(
"Expected 20, got %" PRIu64, dst.vb_uint64);
1950 TEST_MSG(
"Expected 256, got %" PRIu64, dst.vb_uint64);
1969 TEST_MSG(
"Expected 7, got %" PRId64, dst.vb_int64);
1987 TEST_MSG(
"Expected tainted to be true when b is tainted");
2001 TEST_MSG(
"Expected tainted to be false when neither is tainted");
2015 a.vb_ip.af = AF_INET;
2016 a.vb_ipv4addr = htonl(0x0a000000);
2017 a.vb_ip.prefix = 24;
2033 a.vb_ip.af = AF_INET;
2034 a.vb_ipv4addr = htonl(0xc0a80164);
2035 a.vb_ip.prefix = 32;
2039 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80164);
2050 a.vb_ip.af = AF_INET;
2051 a.vb_ipv4addr = htonl(0xc0a80164);
2052 a.vb_ip.prefix = 32;
2076 TEST_MSG(
"Expected 0x10, got 0x%x", dst.vb_uint32);
2117 a.vb_ip.af = AF_INET;
2118 a.vb_ipv4addr = htonl(0xc0a80000);
2119 a.vb_ip.prefix = 24;
2123 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80001);
2124 TEST_MSG(
"Expected 192.168.0.1, got 0x%08x", ntohl(dst.vb_ipv4addr));
2138 a.vb_ip.af = AF_INET;
2139 a.vb_ipv4addr = htonl(0xc0a80164);
2140 a.vb_ip.prefix = 32;
2144 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80100);
2146 TEST_MSG(
"Expected prefix 24, got %u", dst.vb_ip.prefix);
2164 TEST_MSG(
"Expected tainted to be true");
int fr_value_calc_assignment_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_token_t op, fr_value_box_t const *src)
Calculate DST OP SRC.
int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint, fr_value_box_t const *a, fr_token_t op, fr_value_box_t const *b)
Calculate DST = A OP B.
int fr_value_calc_unary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_token_t op, fr_value_box_t const *src)
Calculate unary operations.
static void test_assign_xor(void)
static void test_unary_complement_uint16(void)
static void test_tainted_propagation(void)
static void test_float64_mod(void)
static void test_uint32_xor(void)
static void test_octets_and(void)
static void test_unary_complement(void)
static void test_assign_sub(void)
static void test_uint64_overflow(void)
static void test_uint64_mod(void)
static void test_ipv4_prefix_add_overflow(void)
static void test_uint64_xor(void)
static void test_assign_or(void)
static void test_uint32_div_zero(void)
static void test_ipv4_addr_and_mask(void)
static void test_uint64_mul_overflow(void)
static void test_int64_div_zero(void)
static void test_uint32_sub(void)
static void test_unary_increment_int64(void)
static void test_ipv4_addr_and_all_ones(void)
static void test_uint64_div(void)
static void test_unary_not(void)
static void test_auto_type_hint_lshift(void)
static void test_bool_mul(void)
static void test_float32_mod_zero(void)
static TALLOC_CTX * autofree
static void test_string_rshift_too_large(void)
static void test_auto_type_hint(void)
static void test_octets_lshift(void)
static void test_int16_add(void)
static void test_uint32_and(void)
static void test_ipv4_addr_and_zero(void)
static void test_assign_self(void)
static void test_int8_sub(void)
static void test_mixed_uint8_uint32(void)
static void test_mixed_uint32_int32(void)
static void test_cmp_ge(void)
static void test_uint32_or(void)
static void test_string_add_empty(void)
static void test_unary_complement_int32(void)
static void test_int32_mul(void)
static void test_uint8_add(void)
static void test_tainted_from_b(void)
static void test_tainted_neither(void)
static void test_uint32_shift(void)
static void test_assign_and(void)
static void test_uint32_add(void)
static void test_bool_sub(void)
static void test_assign_lshift(void)
static void test_octets_sub_too_long(void)
static void test_int32_mod(void)
static void test_uint32_div(void)
static void test_assign_mul(void)
static void test_octets_rshift_too_large(void)
static void test_float64_mul(void)
static void test_float32_sub(void)
static void test_assign_add(void)
static void test_auto_type_hint_sub(void)
static void test_uint64_or(void)
static void test_string_sub_too_long(void)
static void test_string_xor_prepend(void)
static void test_uint32_mul(void)
static void test_cmp_ne(void)
static void test_assign_div(void)
static void test_uint16_add(void)
static void test_assign_rshift(void)
static void test_uint8_overflow(void)
static void test_bool_and(void)
static void test_cmp_eq_type(void)
static void test_float32_add(void)
static void test_uint64_shift(void)
static void test_float64_sub(void)
static void test_float64_mod_zero(void)
static void test_cmp_gt(void)
static void test_uint64_underflow(void)
static void test_int32_sub(void)
static void test_unary_negate_float64(void)
static void test_string_add(void)
static void test_string_lshift(void)
static void test_float64_div_zero(void)
static void test_unary_not_bool(void)
static void test_float32_mod(void)
static void test_bool_xor(void)
static void test_cmp_different_types(void)
static void test_cmp_eq(void)
static void test_string_sub_not_suffix(void)
static void test_cmp_string(void)
static void test_octets_or(void)
static void test_octets_xor(void)
static void test_string_sub(void)
static void test_unary_complement_uint64(void)
static void test_float64_div(void)
static void test_cmp_le(void)
static void test_int32_div(void)
static void test_unary_complement_uint32(void)
static void test_uint16_overflow(void)
static void test_octets_length_mismatch(void)
static void test_float32_mul(void)
static void test_int8_add(void)
static void test_cmp_lt(void)
static void test_int64_underflow(void)
static void test_int64_xor(void)
static void test_unary_increment(void)
static void test_int64_or(void)
static void test_assign_set(void)
static void test_unary_increment_float64(void)
static void test_bool_add(void)
static void test_float32_div_zero(void)
static void test_int64_overflow(void)
static void test_init(void)
static void test_octets_add(void)
static void test_int64_shift_too_large(void)
static void test_bool_or(void)
static void test_uint64_div_zero(void)
static void test_auto_type_hint_rshift(void)
static void test_uint64_and(void)
static void test_float64_add(void)
static void test_uint64_shift_too_large(void)
static void test_unary_negate(void)
static void test_uint32_mod(void)
static void test_octets_sub_not_suffix(void)
static void test_ipv4_prefix_add(void)
static void test_octets_sub(void)
static void test_unary_increment_uint8(void)
static void test_int32_add(void)
static void test_string_rshift(void)
static void test_float32_div(void)
static void test_octets_lshift_too_large(void)
static void test_string_lshift_too_large(void)
static void test_int64_mod(void)
static void test_unary_increment_overflow(void)
static void test_octets_rshift(void)
static void test_int64_and(void)
static void test_int64_shift(void)
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_FLOAT64
Double precision floating point.
#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
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.
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.
#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_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.