26#include <freeradius-devel/util/calc.h>
27#include <freeradius-devel/util/value.h>
60 TEST_MSG(
"Expected 30, got %u", dst.vb_uint32);
74 TEST_MSG(
"Expected 20, got %u", dst.vb_uint32);
88 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
102 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
116 TEST_MSG(
"Expected 2, got %u", dst.vb_uint32);
130 TEST_MSG(
"Expected 0x0f, got 0x%x", dst.vb_uint32);
144 TEST_MSG(
"Expected 0xff, got 0x%x", dst.vb_uint32);
158 TEST_MSG(
"Expected 0xf0, got 0x%x", dst.vb_uint32);
173 TEST_MSG(
"Expected 0x100, got 0x%" PRIx64, dst.vb_uint64);
179 TEST_MSG(
"Expected 0x01, got 0x%x", dst.vb_uint32);
213 TEST_MSG(
"Expected 150, got %u", dst.vb_uint8);
243 TEST_MSG(
"Expected 20, got %d", dst.vb_int32);
257 TEST_MSG(
"Expected -20, got %d", dst.vb_int32);
271 TEST_MSG(
"Expected -42, got %d", dst.vb_int32);
285 TEST_MSG(
"Expected -7, got %d", dst.vb_int32);
404 TEST_MSG(
"Expected 4.0, got %f", dst.vb_float64);
418 TEST_MSG(
"Expected 6.5, got %f", dst.vb_float64);
432 TEST_MSG(
"Expected 21.0, got %f", dst.vb_float64);
445 TEST_CHECK((dst.vb_float64 > 3.14) && (dst.vb_float64 < 3.15));
446 TEST_MSG(
"Expected ~3.14, got %f", dst.vb_float64);
471 TEST_CHECK((dst.vb_float64 > 1.49) && (dst.vb_float64 < 1.51));
472 TEST_MSG(
"Expected ~1.5, got %f", dst.vb_float64);
489 TEST_MSG(
"Expected 4.0, got %f", (
double)dst.vb_float32);
519 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello world") == 0);
520 TEST_MSG(
"Expected 'hello world', got '%s'", dst.vb_strvalue);
539 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello ") == 0);
540 TEST_MSG(
"Expected 'hello ', got '%s'", dst.vb_strvalue);
578 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello world") == 0);
579 TEST_MSG(
"Expected 'hello world', got '%s'", dst.vb_strvalue);
597 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello") == 0);
598 TEST_MSG(
"Expected 'hello', got '%s'", dst.vb_strvalue);
615 TEST_CHECK(strcmp(dst.vb_strvalue,
"world") == 0);
616 TEST_MSG(
"Expected 'world', got '%s'", dst.vb_strvalue);
638 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02\x03\x04", 4) == 0);
658 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02", 2) == 0);
678 TEST_CHECK(memcmp(dst.vb_octets,
"\x0f\x0f", 2) == 0);
698 TEST_CHECK(memcmp(dst.vb_octets,
"\xff\xff", 2) == 0);
718 TEST_CHECK(memcmp(dst.vb_octets,
"\xf0\x0f", 2) == 0);
757 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02", 2) == 0);
775 TEST_CHECK(memcmp(dst.vb_octets,
"\x03\x04", 2) == 0);
922 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
935 TEST_MSG(
"Expected 0xf0, got 0x%02x", dst.vb_uint8);
948 TEST_MSG(
"Expected -42, got %d", dst.vb_int32);
980 TEST_MSG(
"Expected 15, got %u", dst.vb_uint32);
993 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
1006 TEST_MSG(
"Expected 99, got %u", dst.vb_uint32);
1034 TEST_MSG(
"Expected 30, got %u", dst.vb_uint32);
1050 TEST_MSG(
"Expected 30, got %" PRIu64, dst.vb_uint64);
1154 TEST_MSG(
"Expected 3000, got %u", dst.vb_uint16);
1179 fr_value_box(&a, (uint64_t) 0xff00ff00ff00ff00ULL,
false);
1180 fr_value_box(&b, (uint64_t) 0x0f0f0f0f0f0f0f0fULL,
false);
1183 TEST_CHECK(dst.vb_uint64 == 0x0f000f000f000f00ULL);
1184 TEST_MSG(
"Expected 0x0f000f000f000f00, got 0x%" PRIx64, dst.vb_uint64);
1193 fr_value_box(&a, (uint64_t) 0xf0f0f0f000000000ULL,
false);
1194 fr_value_box(&b, (uint64_t) 0x000000000f0f0f0fULL,
false);
1197 TEST_CHECK(dst.vb_uint64 == 0xf0f0f0f00f0f0f0fULL);
1198 TEST_MSG(
"Expected 0xf0f0f0f00f0f0f0f, got 0x%" PRIx64, dst.vb_uint64);
1207 fr_value_box(&a, (uint64_t) 0xffffffffffffffffULL,
false);
1208 fr_value_box(&b, (uint64_t) 0x0f0f0f0f0f0f0f0fULL,
false);
1211 TEST_CHECK(dst.vb_uint64 == 0xf0f0f0f0f0f0f0f0ULL);
1212 TEST_MSG(
"Expected 0xf0f0f0f0f0f0f0f0, got 0x%" PRIx64, dst.vb_uint64);
1227 TEST_MSG(
"Expected 0x10000, got 0x%" PRIx64, dst.vb_uint64);
1232 TEST_MSG(
"Expected 0x01, got 0x%" PRIx64, dst.vb_uint64);
1259 TEST_MSG(
"Expected 2, got %" PRIu64, dst.vb_uint64);
1273 TEST_MSG(
"Expected 14, got %" PRIu64, dst.vb_uint64);
1303 TEST_MSG(
"Expected 50, got %d", dst.vb_int8);
1317 TEST_MSG(
"Expected -50, got %d", dst.vb_int8);
1334 TEST_MSG(
"Expected 1000, got %d", dst.vb_int16);
1351 TEST_MSG(
"Expected -2, got %d", dst.vb_int32);
1368 TEST_MSG(
"Expected 0x00ff, got 0x%" PRIx64, dst.vb_int64);
1382 TEST_MSG(
"Expected 0xf00f, got 0x%" PRIx64, dst.vb_int64);
1396 TEST_MSG(
"Expected 0xf0f0, got 0x%" PRIx64, dst.vb_int64);
1411 TEST_MSG(
"Expected 0x1000, got 0x%" PRIx64, dst.vb_int64);
1416 TEST_MSG(
"Expected 0x10, got 0x%" PRIx64, dst.vb_int64);
1443 TEST_MSG(
"Expected 2, got %" PRId64, dst.vb_int64);
1460 TEST_MSG(
"Expected 6.5, got %f", (
double)dst.vb_float32);
1474 TEST_MSG(
"Expected 21.0, got %f", (
double)dst.vb_float32);
1488 TEST_MSG(
"Expected 3.0, got %f", (
double)dst.vb_float32);
1501 TEST_CHECK((dst.vb_float32 > 1.49f) && (dst.vb_float32 < 1.51f));
1502 TEST_MSG(
"Expected ~1.5, got %f", (
double)dst.vb_float32);
1612 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello") == 0);
1613 TEST_MSG(
"Expected 'hello', got '%s'", dst.vb_strvalue);
1701 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
1714 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
1727 TEST_MSG(
"Expected 0x0f, got 0x%x", dst.vb_uint32);
1740 TEST_MSG(
"Expected 0xff, got 0x%x", dst.vb_uint32);
1753 TEST_MSG(
"Expected 0xf0, got 0x%x", dst.vb_uint32);
1766 TEST_MSG(
"Expected 0x10, got 0x%x", dst.vb_uint32);
1779 TEST_MSG(
"Expected 0x100, got 0x%x", dst.vb_uint32);
1795 TEST_MSG(
"Expected 0xff00, got 0x%04x", dst.vb_uint16);
1808 TEST_MSG(
"Expected 0xffff0000, got 0x%08x", dst.vb_uint32);
1821 TEST_MSG(
"Expected UINT64_MAX, got 0x%" PRIx64, dst.vb_uint64);
1834 TEST_MSG(
"Expected -1, got %d", dst.vb_int32);
1846 TEST_CHECK((dst.vb_float64 > -3.15) && (dst.vb_float64 < -3.13));
1847 TEST_MSG(
"Expected -3.14, got %f", dst.vb_float64);
1860 TEST_MSG(
"Expected 255, got %u", dst.vb_uint8);
1886 src.vb_bool =
false;
1901 TEST_MSG(
"Expected 0, got %" PRId64, dst.vb_int64);
1914 TEST_MSG(
"Expected 3.5, got %f", dst.vb_float64);
1932 TEST_MSG(
"Expected 20, got %" PRIu64, dst.vb_uint64);
1951 TEST_MSG(
"Expected 256, got %" PRIu64, dst.vb_uint64);
1970 TEST_MSG(
"Expected 7, got %" PRId64, dst.vb_int64);
1988 TEST_MSG(
"Expected tainted to be true when b is tainted");
2002 TEST_MSG(
"Expected tainted to be false when neither is tainted");
2016 a.vb_ip.af = AF_INET;
2017 a.vb_ipv4addr = htonl(0x0a000000);
2018 a.vb_ip.prefix = 24;
2034 a.vb_ip.af = AF_INET;
2035 a.vb_ipv4addr = htonl(0xc0a80164);
2036 a.vb_ip.prefix = 32;
2040 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80164);
2051 a.vb_ip.af = AF_INET;
2052 a.vb_ipv4addr = htonl(0xc0a80164);
2053 a.vb_ip.prefix = 32;
2077 TEST_MSG(
"Expected 0x10, got 0x%x", dst.vb_uint32);
2118 a.vb_ip.af = AF_INET;
2119 a.vb_ipv4addr = htonl(0xc0a80000);
2120 a.vb_ip.prefix = 24;
2124 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80001);
2125 TEST_MSG(
"Expected 192.168.0.1, got 0x%08x", ntohl(dst.vb_ipv4addr));
2139 a.vb_ip.af = AF_INET;
2140 a.vb_ipv4addr = htonl(0xc0a80164);
2141 a.vb_ip.prefix = 32;
2145 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80100);
2147 TEST_MSG(
"Expected prefix 24, got %u", dst.vb_ip.prefix);
2165 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.