24#define TEST_GLOBAL_INIT test_init()
29#include <freeradius-devel/util/calc.h>
61 TEST_MSG(
"Expected 30, got %u", dst.vb_uint32);
75 TEST_MSG(
"Expected 20, got %u", dst.vb_uint32);
89 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
103 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
117 TEST_MSG(
"Expected 2, got %u", dst.vb_uint32);
131 TEST_MSG(
"Expected 0x0f, got 0x%x", dst.vb_uint32);
145 TEST_MSG(
"Expected 0xff, got 0x%x", dst.vb_uint32);
159 TEST_MSG(
"Expected 0xf0, got 0x%x", dst.vb_uint32);
174 TEST_MSG(
"Expected 0x100, got 0x%" PRIx64, dst.vb_uint64);
180 TEST_MSG(
"Expected 0x01, got 0x%x", dst.vb_uint32);
214 TEST_MSG(
"Expected 150, got %u", dst.vb_uint8);
244 TEST_MSG(
"Expected 20, got %d", dst.vb_int32);
258 TEST_MSG(
"Expected -20, got %d", dst.vb_int32);
272 TEST_MSG(
"Expected -42, got %d", dst.vb_int32);
286 TEST_MSG(
"Expected -7, got %d", dst.vb_int32);
405 TEST_MSG(
"Expected 4.0, got %f", dst.vb_float64);
419 TEST_MSG(
"Expected 6.5, got %f", dst.vb_float64);
433 TEST_MSG(
"Expected 21.0, got %f", dst.vb_float64);
446 TEST_CHECK((dst.vb_float64 > 3.14) && (dst.vb_float64 < 3.15));
447 TEST_MSG(
"Expected ~3.14, got %f", dst.vb_float64);
472 TEST_CHECK((dst.vb_float64 > 1.49) && (dst.vb_float64 < 1.51));
473 TEST_MSG(
"Expected ~1.5, got %f", dst.vb_float64);
490 TEST_MSG(
"Expected 4.0, got %f", (
double)dst.vb_float32);
520 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello world") == 0);
521 TEST_MSG(
"Expected 'hello world', got '%s'", dst.vb_strvalue);
540 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello ") == 0);
541 TEST_MSG(
"Expected 'hello ', got '%s'", dst.vb_strvalue);
579 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello world") == 0);
580 TEST_MSG(
"Expected 'hello world', got '%s'", dst.vb_strvalue);
598 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello") == 0);
599 TEST_MSG(
"Expected 'hello', got '%s'", dst.vb_strvalue);
616 TEST_CHECK(strcmp(dst.vb_strvalue,
"world") == 0);
617 TEST_MSG(
"Expected 'world', got '%s'", dst.vb_strvalue);
639 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02\x03\x04", 4) == 0);
659 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02", 2) == 0);
679 TEST_CHECK(memcmp(dst.vb_octets,
"\x0f\x0f", 2) == 0);
699 TEST_CHECK(memcmp(dst.vb_octets,
"\xff\xff", 2) == 0);
719 TEST_CHECK(memcmp(dst.vb_octets,
"\xf0\x0f", 2) == 0);
758 TEST_CHECK(memcmp(dst.vb_octets,
"\x01\x02", 2) == 0);
776 TEST_CHECK(memcmp(dst.vb_octets,
"\x03\x04", 2) == 0);
923 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
936 TEST_MSG(
"Expected 0xf0, got 0x%02x", dst.vb_uint8);
949 TEST_MSG(
"Expected -42, got %d", dst.vb_int32);
981 TEST_MSG(
"Expected 15, got %u", dst.vb_uint32);
994 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
1007 TEST_MSG(
"Expected 99, got %u", dst.vb_uint32);
1035 TEST_MSG(
"Expected 30, got %u", dst.vb_uint32);
1051 TEST_MSG(
"Expected 30, got %" PRIu64, dst.vb_uint64);
1155 TEST_MSG(
"Expected 3000, got %u", dst.vb_uint16);
1180 fr_value_box(&a, (uint64_t) 0xff00ff00ff00ff00ULL,
false);
1181 fr_value_box(&b, (uint64_t) 0x0f0f0f0f0f0f0f0fULL,
false);
1184 TEST_CHECK(dst.vb_uint64 == 0x0f000f000f000f00ULL);
1185 TEST_MSG(
"Expected 0x0f000f000f000f00, got 0x%" PRIx64, dst.vb_uint64);
1194 fr_value_box(&a, (uint64_t) 0xf0f0f0f000000000ULL,
false);
1195 fr_value_box(&b, (uint64_t) 0x000000000f0f0f0fULL,
false);
1198 TEST_CHECK(dst.vb_uint64 == 0xf0f0f0f00f0f0f0fULL);
1199 TEST_MSG(
"Expected 0xf0f0f0f00f0f0f0f, got 0x%" PRIx64, dst.vb_uint64);
1208 fr_value_box(&a, (uint64_t) 0xffffffffffffffffULL,
false);
1209 fr_value_box(&b, (uint64_t) 0x0f0f0f0f0f0f0f0fULL,
false);
1212 TEST_CHECK(dst.vb_uint64 == 0xf0f0f0f0f0f0f0f0ULL);
1213 TEST_MSG(
"Expected 0xf0f0f0f0f0f0f0f0, got 0x%" PRIx64, dst.vb_uint64);
1228 TEST_MSG(
"Expected 0x10000, got 0x%" PRIx64, dst.vb_uint64);
1233 TEST_MSG(
"Expected 0x01, got 0x%" PRIx64, dst.vb_uint64);
1260 TEST_MSG(
"Expected 2, got %" PRIu64, dst.vb_uint64);
1274 TEST_MSG(
"Expected 14, got %" PRIu64, dst.vb_uint64);
1304 TEST_MSG(
"Expected 50, got %d", dst.vb_int8);
1318 TEST_MSG(
"Expected -50, got %d", dst.vb_int8);
1335 TEST_MSG(
"Expected 1000, got %d", dst.vb_int16);
1352 TEST_MSG(
"Expected -2, got %d", dst.vb_int32);
1369 TEST_MSG(
"Expected 0x00ff, got 0x%" PRIx64, (uint64_t)dst.vb_int64);
1383 TEST_MSG(
"Expected 0xf00f, got 0x%" PRIx64, (uint64_t)dst.vb_int64);
1397 TEST_MSG(
"Expected 0xf0f0, got 0x%" PRIx64, (uint64_t)dst.vb_int64);
1412 TEST_MSG(
"Expected 0x1000, got 0x%" PRIx64, (uint64_t)dst.vb_int64);
1417 TEST_MSG(
"Expected 0x10, got 0x%" PRIx64, (uint64_t)dst.vb_int64);
1444 TEST_MSG(
"Expected 2, got %" PRId64, dst.vb_int64);
1461 TEST_MSG(
"Expected 6.5, got %f", (
double)dst.vb_float32);
1475 TEST_MSG(
"Expected 21.0, got %f", (
double)dst.vb_float32);
1489 TEST_MSG(
"Expected 3.0, got %f", (
double)dst.vb_float32);
1502 TEST_CHECK((dst.vb_float32 > 1.49f) && (dst.vb_float32 < 1.51f));
1503 TEST_MSG(
"Expected ~1.5, got %f", (
double)dst.vb_float32);
1613 TEST_CHECK(strcmp(dst.vb_strvalue,
"hello") == 0);
1614 TEST_MSG(
"Expected 'hello', got '%s'", dst.vb_strvalue);
1702 TEST_MSG(
"Expected 42, got %u", dst.vb_uint32);
1715 TEST_MSG(
"Expected 7, got %u", dst.vb_uint32);
1728 TEST_MSG(
"Expected 0x0f, got 0x%x", dst.vb_uint32);
1741 TEST_MSG(
"Expected 0xff, got 0x%x", dst.vb_uint32);
1754 TEST_MSG(
"Expected 0xf0, got 0x%x", dst.vb_uint32);
1767 TEST_MSG(
"Expected 0x10, got 0x%x", dst.vb_uint32);
1780 TEST_MSG(
"Expected 0x100, got 0x%x", dst.vb_uint32);
1796 TEST_MSG(
"Expected 0xff00, got 0x%04x", dst.vb_uint16);
1809 TEST_MSG(
"Expected 0xffff0000, got 0x%08x", dst.vb_uint32);
1822 TEST_MSG(
"Expected UINT64_MAX, got 0x%" PRIx64, dst.vb_uint64);
1835 TEST_MSG(
"Expected -1, got %d", dst.vb_int32);
1847 TEST_CHECK((dst.vb_float64 > -3.15) && (dst.vb_float64 < -3.13));
1848 TEST_MSG(
"Expected -3.14, got %f", dst.vb_float64);
1861 TEST_MSG(
"Expected 255, got %u", dst.vb_uint8);
1887 src.vb_bool =
false;
1902 TEST_MSG(
"Expected 0, got %" PRId64, dst.vb_int64);
1915 TEST_MSG(
"Expected 3.5, got %f", dst.vb_float64);
1933 TEST_MSG(
"Expected 20, got %" PRIu64, dst.vb_uint64);
1952 TEST_MSG(
"Expected 256, got %" PRIu64, dst.vb_uint64);
1971 TEST_MSG(
"Expected 7, got %" PRId64, dst.vb_int64);
1989 TEST_MSG(
"Expected tainted to be true when b is tainted");
2003 TEST_MSG(
"Expected tainted to be false when neither is tainted");
2017 a.vb_ip.af = AF_INET;
2018 a.vb_ipv4addr = htonl(0x0a000000);
2019 a.vb_ip.prefix = 24;
2035 a.vb_ip.af = AF_INET;
2036 a.vb_ipv4addr = htonl(0xc0a80164);
2037 a.vb_ip.prefix = 32;
2041 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80164);
2052 a.vb_ip.af = AF_INET;
2053 a.vb_ipv4addr = htonl(0xc0a80164);
2054 a.vb_ip.prefix = 32;
2078 TEST_MSG(
"Expected 0x10, got 0x%x", dst.vb_uint32);
2119 a.vb_ip.af = AF_INET;
2120 a.vb_ipv4addr = htonl(0xc0a80000);
2121 a.vb_ip.prefix = 24;
2125 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80001);
2126 TEST_MSG(
"Expected 192.168.0.1, got 0x%08x", ntohl(dst.vb_ipv4addr));
2140 a.vb_ip.af = AF_INET;
2141 a.vb_ipv4addr = htonl(0xc0a80164);
2142 a.vb_ip.prefix = 32;
2146 TEST_CHECK(ntohl(dst.vb_ipv4addr) == 0xc0a80100);
2148 TEST_MSG(
"Expected prefix 24, got %u", dst.vb_ip.prefix);
2166 TEST_MSG(
"Expected tainted to be true");
Common initialisation for acutest binaries.
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.