From: Arran Cudbard-Bell Date: Wed, 21 Apr 2021 16:34:55 +0000 (-0500) Subject: Remove duplicate code from pair tests X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=beab6cce4762fe3ab49ea0e9dd62d850bb1c5503;p=thirdparty%2Ffreeradius-server.git Remove duplicate code from pair tests --- diff --git a/src/lib/server/pair_server_tests.c b/src/lib/server/pair_server_tests.c index 776b58ef038..146e892664c 100644 --- a/src/lib/server/pair_server_tests.c +++ b/src/lib/server/pair_server_tests.c @@ -24,7 +24,7 @@ /** * The 'TEST_INIT' macro provided by 'acutest.h' allowing to register a function to be called * before call the unit tests. Therefore, It calls the function ALL THE TIME causing an overhead. - * That is why we are initializing pair_tests_init() by "__attribute__((constructor));" reducing the + * That is why we are initializing test_init() by "__attribute__((constructor));" reducing the * test execution by 50% of the time. */ #define USE_CONSTRUCTOR @@ -33,17 +33,19 @@ * It should be declared before include the "acutest.h" */ #ifdef USE_CONSTRUCTOR -static void pair_tests_init(void) __attribute__((constructor)); +static void test_init(void) __attribute__((constructor)); #else -static void pair_tests_init(void); -# define TEST_INIT pair_tests_init() +static void test_init(void); +# define TEST_INIT test_init() #endif #include #include +#include #include #include +#include #include #include @@ -51,111 +53,17 @@ static void pair_tests_init(void); #include #ifdef HAVE_GPERFTOOLS_PROFILER_H -# include +# include #endif -static char const *dict_dir = "share/dictionary"; - -/* Set by pair_tests_init()*/ static TALLOC_CTX *autofree; -static fr_pair_list_t sample_pairs; - -typedef struct value { - char const *key; - fr_value_box_t val; -} fr_dict_adhoc_attr_value_t; - -typedef struct { - int attr; - fr_dict_attr_t const **parent; - fr_dict_attr_t const **da; - char const *name; - fr_type_t type; - void *values; -} fr_dict_adhoc_attr_t; - -#define FR_TEST_INTEGER 1 -#define FR_TEST_STRING 2 -#define FR_TEST_OCTETS 3 -#define FR_TEST_VALUES 4 -#define FR_TEST_TLV_ROOT 5 -#define FR_TEST_TLV_STRING 1 - -static fr_dict_t *dict_test; - -static fr_dict_attr_t const *attr_test_integer; -static fr_dict_attr_t const *attr_test_string; -static fr_dict_attr_t const *attr_test_octets; -static fr_dict_attr_t const *attr_test_values; -static fr_dict_attr_t const *attr_test_tlv_root; -static fr_dict_attr_t const *attr_test_tlv_string; - -static fr_dict_adhoc_attr_value_t attr_test_values_entries[] = { - { .key = "Tapioca123", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 123 } }, - { .key = "Tapioca321", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 321 } }, - { .key = NULL, }, -}; +static fr_pair_list_t test_pairs; +static fr_dict_t *test_dict; -static fr_dict_adhoc_attr_t test_dict_attrs[] = { - { .attr = FR_TEST_INTEGER, .parent = NULL, .da = &attr_test_integer, .name = "Test-Integer", .type = FR_TYPE_UINT32, }, - { .attr = FR_TEST_STRING, .parent = NULL, .da = &attr_test_string, .name = "Test-String", .type = FR_TYPE_STRING, }, - { .attr = FR_TEST_OCTETS, .parent = NULL, .da = &attr_test_octets, .name = "Test-Octets", .type = FR_TYPE_OCTETS, }, - { .attr = FR_TEST_VALUES, .parent = NULL, .da = &attr_test_values, .name = "Test-Values", .type = FR_TYPE_UINT32, .values = &attr_test_values_entries }, - { .attr = FR_TEST_TLV_ROOT, .parent = NULL, .da = &attr_test_tlv_root, .name = "Test-TLV-Root", .type = FR_TYPE_TLV, }, - { .attr = FR_TEST_TLV_STRING, .parent = &attr_test_tlv_root, .da = &attr_test_tlv_string, .name = "Test-TLV-String", .type = FR_TYPE_STRING, }, - { .attr = -1, .parent = NULL, .da = NULL, .name = NULL, .type = FR_TYPE_NULL } -}; -/* - * It will be called before of unit tests. +/** Global initialisation */ -static int load_attr_pairs(fr_pair_list_t *out) -{ - fr_dict_adhoc_attr_t *p; - - fr_pair_list_init(out); - - for (p = test_dict_attrs; - p->attr != -1; - p++) if (fr_pair_prepend_by_da(autofree, NULL, out, *p->da) < 0) return -1; - - return 0; -} - -static int init_adhoc_attrs(fr_dict_adhoc_attr_t *dict_adhoc) -{ - fr_dict_adhoc_attr_t *ctx; - fr_dict_attr_flags_t dict_flags = { - .is_root = true - }; - - for (ctx = dict_adhoc; - ctx->attr != -1; - ctx++) { - fr_dict_attr_t const *parent = ctx->parent ? *ctx->parent : fr_dict_root(dict_test); - fr_dict_attr_t const *attr; - - if (fr_dict_attr_add(dict_test, parent, ctx->name, ctx->attr, ctx->type, &dict_flags) < 0) return -1; - - attr = fr_dict_attr_by_name(NULL, parent, ctx->name); - if (!attr) return -1; - - /* Set the VALUES */ - if (ctx->values) { - fr_dict_adhoc_attr_value_t *v; - - for (v = ctx->values; - v->key != NULL; - v++) fr_dict_enum_add_name(fr_dict_attr_unconst(attr), v->key, &v->val, false, false); - } - - *ctx->da = attr; - } - - return 0; -} - -static void pair_tests_init(void) +static void test_init(void) { autofree = talloc_autofree_context(); if (!autofree) { @@ -169,26 +77,14 @@ static void pair_tests_init(void) */ if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error; - if (!fr_dict_global_ctx_init(autofree, dict_dir)) goto error; + if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error; - /* - * Initialise attributes that go in requests - */ - if (request_global_init() < 0) goto error; - - /* - * Set the root name of the dictionary - */ - dict_test = fr_dict_alloc("test", 666); - if (!dict_test) goto error; - - if (init_adhoc_attrs(test_dict_attrs) < 0) goto error; - - /* Initialize the "sample_pairs" list */ - fr_pair_list_init(&sample_pairs); - if (load_attr_pairs(&sample_pairs) < 0) goto error; + /* Initialize the "test_pairs" list */ + fr_pair_list_init(&test_pairs); + if (fr_pair_test_list_alloc(autofree, &test_pairs, NULL) < 0) goto error; + if (request_global_init() < 0) goto error; } static request_t *request_fake_alloc(void) @@ -219,7 +115,7 @@ static void test_pair_append_request(void) request_t *request = request_fake_alloc(); TEST_CASE("Add 'Test-Integer' in 'request_pairs' using pair_append_request()"); - TEST_CHECK(pair_append_request(&local_vp, attr_test_integer) == 0); + TEST_CHECK(pair_append_request(&local_vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); TEST_CHECK((vp = fr_pair_list_head(&request->request_pairs)) != NULL); @@ -228,7 +124,7 @@ static void test_pair_append_request(void) TEST_MSG("Set vp = 12345"); vp->vp_uint32 = 12345; TEST_CHECK(vp->vp_uint32 == 12345); - TEST_MSG("Expected %s == 12345", attr_test_integer->name); + TEST_MSG("Expected %s == 12345", fr_dict_attr_test_uint32->name); TEST_CHECK_RET(talloc_free(request), 0); } @@ -240,7 +136,7 @@ static void test_pair_append_reply(void) request_t *request = request_fake_alloc(); TEST_CASE("Add 'Test-Integer' in 'reply_pairs' using pair_append_reply()"); - TEST_CHECK(pair_append_reply(&local_vp, attr_test_integer) == 0); + TEST_CHECK(pair_append_reply(&local_vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); TEST_CHECK((vp = fr_pair_list_head(&request->reply_pairs)) != NULL); @@ -250,7 +146,7 @@ static void test_pair_append_reply(void) vp->vp_uint32 = 12345; TEST_CHECK(vp->vp_uint32 == 12345); - TEST_MSG("Expected %s == 12345", attr_test_integer->name); + TEST_MSG("Expected %s == 12345", fr_dict_attr_test_uint32->name); TEST_CHECK_RET(talloc_free(request), 0); } @@ -262,7 +158,7 @@ static void test_pair_append_control(void) request_t *request = request_fake_alloc(); TEST_CASE("Add 'Test-Integer' in 'control_pairs' using pair_append_control()"); - TEST_CHECK(pair_append_control(&local_vp, attr_test_integer) == 0); + TEST_CHECK(pair_append_control(&local_vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); TEST_CHECK((vp = fr_pair_list_head(&request->control_pairs)) != NULL); @@ -272,7 +168,7 @@ static void test_pair_append_control(void) vp->vp_uint32 = 12345; TEST_CHECK(vp->vp_uint32 == 12345); - TEST_MSG("Expected %s == 12345", attr_test_integer->name); + TEST_MSG("Expected %s == 12345", fr_dict_attr_test_uint32->name); TEST_CHECK_RET(talloc_free(request), 0); } @@ -284,7 +180,7 @@ static void test_pair_append_session_state(void) request_t *request = request_fake_alloc(); TEST_CASE("Add 'Test-Integer' in 'control_pairs' using pair_append_session_state()"); - TEST_CHECK(pair_append_session_state(&local_vp, attr_test_integer) == 0); + TEST_CHECK(pair_append_session_state(&local_vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); TEST_CHECK((vp = fr_pair_list_head(&request->session_state_pairs)) != NULL); @@ -294,7 +190,7 @@ static void test_pair_append_session_state(void) vp->vp_uint32 = 12345; TEST_CHECK(vp->vp_uint32 == 12345); - TEST_MSG("Expected %s == 12345", attr_test_integer->name); + TEST_MSG("Expected %s == 12345", fr_dict_attr_test_uint32->name); TEST_CHECK_RET(talloc_free(request), 0); } @@ -305,7 +201,7 @@ static void test_pair_update_request(void) request_t *request = request_fake_alloc(); TEST_CASE("Update 'Test-Integer' in 'request_pairs' using pair_update_request()"); - TEST_CHECK(pair_update_request(&vp, attr_test_integer) == 0); + TEST_CHECK(pair_update_request(&vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -313,8 +209,8 @@ static void test_pair_update_request(void) TEST_MSG("Set vp = 112233"); vp->vp_uint32 = 112233; - TEST_CASE("Expected attr_test_integer (vp->vp_uint32 == 112233)"); - TEST_CHECK((vp = fr_pair_find_by_da(&request->request_pairs, attr_test_integer)) != NULL); + TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 112233)"); + TEST_CHECK((vp = fr_pair_find_by_da(&request->request_pairs, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -334,7 +230,7 @@ static void test_pair_update_reply(void) request_t *request = request_fake_alloc(); TEST_CASE("Update 'Test-Integer' in 'reply_pairs' using pair_update_request()"); - TEST_CHECK(pair_update_reply(&vp, attr_test_integer) == 0); + TEST_CHECK(pair_update_reply(&vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -342,8 +238,8 @@ static void test_pair_update_reply(void) TEST_MSG("Set vp = 3333"); vp->vp_uint32 = 3333; - TEST_CASE("Expected attr_test_integer (vp->vp_uint32 == 3333)"); - TEST_CHECK((vp = fr_pair_find_by_da(&request->reply_pairs, attr_test_integer)) != NULL); + TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 3333)"); + TEST_CHECK((vp = fr_pair_find_by_da(&request->reply_pairs, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -359,7 +255,7 @@ static void test_pair_update_control(void) request_t *request = request_fake_alloc(); TEST_CASE("Update 'Test-Integer' in 'control_pairs' using pair_update_control()"); - TEST_CHECK(pair_update_control(&vp, attr_test_integer) == 0); + TEST_CHECK(pair_update_control(&vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -367,8 +263,8 @@ static void test_pair_update_control(void) TEST_MSG("Set vp = 44444"); vp->vp_uint32 = 44444; - TEST_CASE("Expected attr_test_integer (vp->vp_uint32 == 44444)"); - TEST_CHECK((vp = fr_pair_find_by_da(&request->control_pairs, attr_test_integer)) != NULL); + TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 44444)"); + TEST_CHECK((vp = fr_pair_find_by_da(&request->control_pairs, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -384,7 +280,7 @@ static void test_pair_update_session_state(void) request_t *request = request_fake_alloc(); TEST_CASE("Update 'Test-Integer' in 'state' using pair_update_session_state()"); - TEST_CHECK(pair_update_session_state(&vp, attr_test_integer) == 0); + TEST_CHECK(pair_update_session_state(&vp, fr_dict_attr_test_uint32) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -392,8 +288,8 @@ static void test_pair_update_session_state(void) TEST_MSG("Set vp = 7890"); vp->vp_uint32 = 7890; - TEST_CASE("Expected attr_test_integer (vp->vp_uint32 == 7890)"); - TEST_CHECK((vp = fr_pair_find_by_da(&request->session_state_pairs, attr_test_integer)) != NULL); + TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 7890)"); + TEST_CHECK((vp = fr_pair_find_by_da(&request->session_state_pairs, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -407,14 +303,14 @@ static void test_pair_delete_request(void) { request_t *request = request_fake_alloc(); - TEST_CASE("Copy 'sample_pairs' into 'request->request_pairs'"); - TEST_CHECK(fr_pair_list_copy(autofree, &request->request_pairs, &sample_pairs) > 0); + TEST_CASE("Copy 'test_pairs' into 'request->request_pairs'"); + TEST_CHECK(fr_pair_list_copy(autofree, &request->request_pairs, &test_pairs) > 0); TEST_CASE("Delete 'Test-Integer' in 'request->request_pairs' using pair_delete_request()"); - TEST_CHECK(pair_delete_request(attr_test_integer) > 0); + TEST_CHECK(pair_delete_request(fr_dict_attr_test_uint32) > 0); TEST_CASE("The 'Test-Integer' shouldn't exist in 'request->request_pairs'"); - TEST_CHECK(fr_pair_find_by_da(&request->request_pairs, attr_test_integer) == NULL); + TEST_CHECK(fr_pair_find_by_da(&request->request_pairs, fr_dict_attr_test_uint32) == NULL); TEST_CHECK_RET(talloc_free(request), 0); } @@ -423,14 +319,14 @@ static void test_pair_delete_reply(void) { request_t *request = request_fake_alloc(); - TEST_CASE("Copy 'sample_pairs' into 'request->reply_pairs'"); - TEST_CHECK(fr_pair_list_copy(autofree, &request->reply_pairs, &sample_pairs) > 0); + TEST_CASE("Copy 'test_pairs' into 'request->reply_pairs'"); + TEST_CHECK(fr_pair_list_copy(autofree, &request->reply_pairs, &test_pairs) > 0); TEST_CASE("Delete 'Test-Integer' in 'request->reply_pairs' using pair_delete_reply()"); - TEST_CHECK(pair_delete_reply(attr_test_integer) > 0); + TEST_CHECK(pair_delete_reply(fr_dict_attr_test_uint32) > 0); TEST_CASE("The 'Test-Integer' shouldn't exist in 'request->reply_pairs'"); - TEST_CHECK(fr_pair_find_by_da(&request->reply_pairs, attr_test_integer) == NULL); + TEST_CHECK(fr_pair_find_by_da(&request->reply_pairs, fr_dict_attr_test_uint32) == NULL); TEST_CHECK_RET(talloc_free(request), 0); } @@ -439,14 +335,14 @@ static void test_pair_delete_control(void) { request_t *request = request_fake_alloc(); - TEST_CASE("Copy 'sample_pairs' into 'request->control_pairs'"); - TEST_CHECK(fr_pair_list_copy(autofree, &request->control_pairs, &sample_pairs) > 0); + TEST_CASE("Copy 'test_pairs' into 'request->control_pairs'"); + TEST_CHECK(fr_pair_list_copy(autofree, &request->control_pairs, &test_pairs) > 0); TEST_CASE("Delete 'Test-Integer' in 'request->control_pairs' using pair_delete_control()"); - TEST_CHECK(pair_delete_control(attr_test_integer) > 0); + TEST_CHECK(pair_delete_control(fr_dict_attr_test_uint32) > 0); TEST_CASE("The 'Test-Integer' shouldn't exist in 'request->control_pairs'"); - TEST_CHECK(fr_pair_find_by_da(&request->control_pairs, attr_test_integer) == NULL); + TEST_CHECK(fr_pair_find_by_da(&request->control_pairs, fr_dict_attr_test_uint32) == NULL); TEST_CHECK_RET(talloc_free(request), 0); } @@ -455,14 +351,14 @@ static void test_pair_delete_session_state(void) { request_t *request = request_fake_alloc(); - TEST_CASE("Copy 'sample_pairs' into 'request->state'"); - TEST_CHECK(fr_pair_list_copy(autofree, &request->session_state_pairs, &sample_pairs) > 0); + TEST_CASE("Copy 'test_pairs' into 'request->state'"); + TEST_CHECK(fr_pair_list_copy(autofree, &request->session_state_pairs, &test_pairs) > 0); TEST_CASE("Delete 'Test-Integer' in 'request->state' using pair_delete_session_state()"); - TEST_CHECK(pair_delete_session_state(attr_test_integer) > 0); + TEST_CHECK(pair_delete_session_state(fr_dict_attr_test_uint32) > 0); TEST_CASE("The 'Test-Integer' shouldn't exist in 'request->state'"); - TEST_CHECK(fr_pair_find_by_da(&request->session_state_pairs, attr_test_integer) == NULL); + TEST_CHECK(fr_pair_find_by_da(&request->session_state_pairs, fr_dict_attr_test_uint32) == NULL); TEST_CHECK_RET(talloc_free(request), 0); } diff --git a/src/lib/util/dict_test.c b/src/lib/util/dict_test.c new file mode 100644 index 00000000000..c9fef1ae1a3 --- /dev/null +++ b/src/lib/util/dict_test.c @@ -0,0 +1,225 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** Common functions for test files which need to programatically create test dictionaries + * + * @file src/lib/util/dict_test.c + * + * @copyright 2021 The FreeRADIUS server project + */ + +#include +#include +#include "dict_test.h" + +fr_dict_t *fr_dict_test; + +fr_dict_attr_t const *fr_dict_attr_test_string; +fr_dict_attr_t const *fr_dict_attr_test_octets; + +fr_dict_attr_t const *fr_dict_attr_test_ipv4_addr; +fr_dict_attr_t const *fr_dict_attr_test_ipv4_prefix; + +fr_dict_attr_t const *fr_dict_attr_test_ipv6_addr; +fr_dict_attr_t const *fr_dict_attr_test_ipv6_prefix; + +fr_dict_attr_t const *fr_dict_attr_test_ifid; +fr_dict_attr_t const *fr_dict_attr_test_combo_ip_addr; +fr_dict_attr_t const *fr_dict_attr_test_combo_ip_prefix; +fr_dict_attr_t const *fr_dict_attr_test_ethernet; +fr_dict_attr_t const *fr_dict_attr_test_bool; + +fr_dict_attr_t const *fr_dict_attr_test_uint8; +fr_dict_attr_t const *fr_dict_attr_test_uint16; +fr_dict_attr_t const *fr_dict_attr_test_uint32; +fr_dict_attr_t const *fr_dict_attr_test_uint64; + +fr_dict_attr_t const *fr_dict_attr_test_int8; +fr_dict_attr_t const *fr_dict_attr_test_int16; +fr_dict_attr_t const *fr_dict_attr_test_int32; +fr_dict_attr_t const *fr_dict_attr_test_int64; + +fr_dict_attr_t const *fr_dict_attr_test_float32; +fr_dict_attr_t const *fr_dict_attr_test_float64; + +fr_dict_attr_t const *fr_dict_attr_test_date; + +fr_dict_attr_t const *fr_dict_attr_test_time_delta; + +fr_dict_attr_t const *fr_dict_attr_test_size; + +fr_dict_attr_t const *fr_dict_attr_test_tlv; +fr_dict_attr_t const *fr_dict_attr_test_tlv_string; + +fr_dict_attr_t const *fr_dict_attr_test_struct; +fr_dict_attr_t const *fr_dict_attr_test_struct_uint32; + +fr_dict_attr_t const *fr_dict_attr_test_vsa; +fr_dict_attr_t const *fr_dict_attr_test_vendor; +fr_dict_attr_t const *fr_dict_attr_test_vendor_string; + +fr_dict_attr_t const *fr_dict_attr_test_group; + +fr_dict_attr_t const *fr_dict_attr_test_enum; + +fr_dict_test_attr_t const fr_dict_test_attrs[] = { + /* + * Variable length + */ + { .attr = FR_TEST_ATTR_STRING, .da = &fr_dict_attr_test_string, .name = "Test-String", .type = FR_TYPE_STRING }, + { .attr = FR_TEST_ATTR_OCTETS, .da = &fr_dict_attr_test_octets, .name = "Test-Octets", .type = FR_TYPE_OCTETS }, + + /* + * Networking + */ + { .attr = FR_TEST_ATTR_IPV4_ADDR, .da = &fr_dict_attr_test_ipv4_addr, .name = "Test-IPv4-Addr", .type = FR_TYPE_IPV4_ADDR }, + { .attr = FR_TEST_ATTR_IPV4_PREFIX, .da = &fr_dict_attr_test_ipv4_prefix, .name = "Test-IPv4-Prefix", .type = FR_TYPE_IPV4_PREFIX }, + + { .attr = FR_TEST_ATTR_IPV6_ADDR, .da = &fr_dict_attr_test_ipv6_addr, .name = "Test-IPv6-Addr", .type = FR_TYPE_IPV6_ADDR }, + { .attr = FR_TEST_ATTR_IPV6_PREFIX, .da = &fr_dict_attr_test_ipv6_prefix, .name = "Test-IPv6-Prefix", .type = FR_TYPE_IPV6_PREFIX }, + + { .attr = FR_TEST_ATTR_IFID, .da = &fr_dict_attr_test_ifid, .name = "Test-IFID", .type = FR_TYPE_IFID }, + { .attr = FR_TEST_ATTR_ETHERNET, .da = &fr_dict_attr_test_ethernet, .name = "Test-Ethernet", .type = FR_TYPE_ETHERNET }, + + /* + * Numeric + */ + { .attr = FR_TEST_ATTR_UINT8, .da = &fr_dict_attr_test_uint8, .name = "Test-Uint8", .type = FR_TYPE_UINT8 }, + { .attr = FR_TEST_ATTR_UINT16, .da = &fr_dict_attr_test_uint16, .name = "Test-Uint16", .type = FR_TYPE_UINT16 }, + { .attr = FR_TEST_ATTR_UINT32, .da = &fr_dict_attr_test_uint32, .name = "Test-Uint32", .type = FR_TYPE_UINT32 }, + { .attr = FR_TEST_ATTR_UINT64, .da = &fr_dict_attr_test_uint64, .name = "Test-Uint64", .type = FR_TYPE_UINT64 }, + + { .attr = FR_TEST_ATTR_INT8, .da = &fr_dict_attr_test_int8, .name = "Test-Int8", .type = FR_TYPE_INT8 }, + { .attr = FR_TEST_ATTR_INT16, .da = &fr_dict_attr_test_int16, .name = "Test-Int16", .type = FR_TYPE_INT16 }, + { .attr = FR_TEST_ATTR_INT32, .da = &fr_dict_attr_test_int32, .name = "Test-Int32", .type = FR_TYPE_INT32 }, + { .attr = FR_TEST_ATTR_INT64, .da = &fr_dict_attr_test_int64, .name = "Test-Int64", .type = FR_TYPE_INT64 }, + + { .attr = FR_TEST_ATTR_FLOAT32, .da = &fr_dict_attr_test_float32, .name = "Test-Float32", .type = FR_TYPE_FLOAT32 }, + { .attr = FR_TEST_ATTR_FLOAT64, .da = &fr_dict_attr_test_float64, .name = "Test-Float64", .type = FR_TYPE_FLOAT64 }, + + { .attr = FR_TEST_ATTR_DATE, .da = &fr_dict_attr_test_date, .name = "Test-Date", .type = FR_TYPE_DATE }, + + { .attr = FR_TEST_ATTR_TIME_DELTA, .da = &fr_dict_attr_test_date, .name = "Test-Time-Delta", .type = FR_TYPE_TIME_DELTA }, + + { .attr = FR_TEST_ATTR_SIZE, .da = &fr_dict_attr_test_size, .name = "Test-Time-Size", .type = FR_TYPE_SIZE }, + + /* + * Grouping + */ + { .attr = FR_TEST_ATTR_TLV, .da = &fr_dict_attr_test_tlv, .name = "Test-TLV", .type = FR_TYPE_TLV }, + { .attr = FR_TEST_ATTR_TLV_STRING, .parent = &fr_dict_attr_test_tlv, .da = &fr_dict_attr_test_tlv_string, .name = "String", .type = FR_TYPE_STRING }, + + { .attr = FR_TEST_ATTR_STRUCT, .da = &fr_dict_attr_test_struct, .name = "Test-Struct", .type = FR_TYPE_STRUCT }, + { .attr = 1, .parent = &fr_dict_attr_test_struct, .da = &fr_dict_attr_test_struct_uint32, .name = "uint32", .type = FR_TYPE_UINT32 }, + + { .attr = FR_TEST_ATTR_VSA, .da = &fr_dict_attr_test_vsa, .name = "Test-VSA", .type = FR_TYPE_VSA }, + { .attr = FR_TEST_ATTR_VENDOR, .parent = &fr_dict_attr_test_vsa, .da = &fr_dict_attr_test_vendor, .name = "Test-Vendor", .type = FR_TYPE_VENDOR }, + { .attr = FR_TEST_ATTR_VENDOR_STRING, .parent = &fr_dict_attr_test_vendor, .da = &fr_dict_attr_test_vendor_string, .name = "String", .type = FR_TYPE_STRING }, + + { .attr = FR_TEST_ATTR_GROUP, .da = &fr_dict_attr_test_group, .name = "Test-Group", .type = FR_TYPE_GROUP }, + + /* + * Enumeration + */ + { .attr = FR_TEST_ATTR_ENUM, .da = &fr_dict_attr_test_enum, .name = "Test-Enum", .type = FR_TYPE_UINT32, + .values = (fr_dict_test_attr_value_t[]){ + { .key = "test123", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 123 } }, + { .key = "test321", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 321 } }, + { .key = NULL, }, + } + }, + { .attr = FR_TEST_ATTR_INVALID } +}; + +/** Add our test attributes to our test dictionary + * + * @param[in] dict Test dictionary to add. + * @param[in] test_defs Test attribute definitions to add. + * @return + * - 0 on success. + * - -1 on failure. + */ +static int dict_test_attrs_init(fr_dict_t *dict, fr_dict_test_attr_t const *test_defs) +{ + fr_dict_test_attr_t const *p; + fr_dict_attr_flags_t dict_flags = {}; + + for (p = test_defs; p->attr != FR_TEST_ATTR_INVALID; p++) { + fr_dict_attr_t const *parent = p->parent ? *p->parent : fr_dict_root(dict); + fr_dict_attr_t const *attr; + + if (fr_dict_attr_add(dict, parent, p->name, p->attr, p->type, &dict_flags) < 0) return -1; + + attr = fr_dict_attr_by_name(NULL, parent, p->name); + if (!attr) { + fr_strerror_printf("Failed adding test attribute \"%s\"", p->name); + return -1; + } + + /* Add the enumeration values */ + if (p->values) { + fr_dict_test_attr_value_t *v; + + for (v = p->values; + v->key != NULL; + v++) fr_dict_enum_add_name(fr_dict_attr_unconst(attr), v->key, &v->val, false, false); + } + + *p->da = attr; + } + + return 0; +} + +/** Initialise a test dictionary and add our test_defs to it + * + * @param[in] ctx to bind the global dictionary ctx lifetim to. + * @param[out] dict_p Where to write a pointer to our test dictionary. + * May be NULL. + * @param[in] test_defs Test attributes. If NULL will default to the + * default test attributes. + * @return + * - 0 on success. + * - -1 on failure. + */ +int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs) +{ + fr_dict_gctx_t const *our_dict_gctx; + fr_dict_t *dict; + + our_dict_gctx = fr_dict_global_ctx_init(ctx, "share/dictionary"); + if (!our_dict_gctx) return -1; + + if (!test_defs) test_defs = fr_dict_test_attrs; + + /* + * Set the root name of the dictionary + */ + dict = fr_dict_alloc("test", 42); + if (!dict) { + error: + fr_dict_global_ctx_free(our_dict_gctx); + return -1; + } + + if (dict_test_attrs_init(dict, test_defs) < 0) goto error; + + fr_dict_test = dict; + + if (dict_p) *dict_p = dict; + + return 0; +} diff --git a/src/lib/util/dict_test.h b/src/lib/util/dict_test.h new file mode 100644 index 00000000000..862ddf9c039 --- /dev/null +++ b/src/lib/util/dict_test.h @@ -0,0 +1,155 @@ +#pragma once +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** Functions to create test dictionaries for unit tests + * + * @file src/lib/util/dict_test.h + * + * @copyright 2021 The FreeRADIUS server project + */ +RCSIDH(dict_test_h, "$Id$") + +#ifdef __cplusplus +extern "C" { +#endif + +/** Test attribute numbers + */ +typedef enum { + FR_TEST_ATTR_INVALID = -1, + FR_TEST_ATTR_STRING = 1, + FR_TEST_ATTR_OCTETS, + + FR_TEST_ATTR_IPV4_ADDR, + FR_TEST_ATTR_IPV4_PREFIX, + FR_TEST_ATTR_IPV6_ADDR, + FR_TEST_ATTR_IPV6_PREFIX, + FR_TEST_ATTR_IFID, + FR_TEST_ATTR_COMBO_IP_ADDR, + FR_TEST_ATTR_COMBO_IP_PREFIX, + FR_TEST_ATTR_ETHERNET, + + FR_TEST_ATTR_BOOL, + + FR_TEST_ATTR_UINT8, + FR_TEST_ATTR_UINT16, + FR_TEST_ATTR_UINT32, + FR_TEST_ATTR_UINT64, + + + FR_TEST_ATTR_INT8, + FR_TEST_ATTR_INT16, + FR_TEST_ATTR_INT32, + FR_TEST_ATTR_INT64, + + FR_TEST_ATTR_FLOAT32, + FR_TEST_ATTR_FLOAT64, + + FR_TEST_ATTR_DATE, + + FR_TEST_ATTR_TIME_DELTA, + + FR_TEST_ATTR_SIZE, + + FR_TEST_ATTR_TLV, + FR_TEST_ATTR_TLV_STRING, + + FR_TEST_ATTR_STRUCT, + + FR_TEST_ATTR_VSA, + FR_TEST_ATTR_VENDOR, + FR_TEST_ATTR_VENDOR_STRING, + + FR_TEST_ATTR_GROUP, + + FR_TEST_ATTR_ENUM +} fr_dict_test_attr_number_t; + +/** Test enumeration values + */ +typedef struct value { + char const *key; //!< Enumeration name. + fr_value_box_t val; //!< Enumeration value +} fr_dict_test_attr_value_t; + +/** Test enumeration attributes + */ +typedef struct { + fr_dict_test_attr_number_t attr; //!< Attribute number to create. + fr_dict_attr_t const **parent; //!< The parent of this attribute. + fr_dict_attr_t const **da; //!< Where to write a pointer to this attribute. + char const *name; //!< What to call this attribute. + fr_type_t type; //!< What type the attribute. + fr_dict_test_attr_value_t *values; //!< Array of enumeration values to add to this attribute. +} fr_dict_test_attr_t; + +extern fr_dict_t *fr_dict_test; +extern fr_dict_attr_t const *fr_dict_attr_test_string; +extern fr_dict_attr_t const *fr_dict_attr_test_octets; + +extern fr_dict_attr_t const *fr_dict_attr_test_ipv4_addr; +extern fr_dict_attr_t const *fr_dict_attr_test_ipv4_prefix; + +extern fr_dict_attr_t const *fr_dict_attr_test_ipv6_addr; +extern fr_dict_attr_t const *fr_dict_attr_test_ipv6_prefix; + +extern fr_dict_attr_t const *fr_dict_attr_test_ifid; +extern fr_dict_attr_t const *fr_dict_attr_test_combo_ip_addr; +extern fr_dict_attr_t const *fr_dict_attr_test_combo_ip_prefix; +extern fr_dict_attr_t const *fr_dict_attr_test_ethernet; +extern fr_dict_attr_t const *fr_dict_attr_test_bool; + +extern fr_dict_attr_t const *fr_dict_attr_test_uint8; +extern fr_dict_attr_t const *fr_dict_attr_test_uint16; +extern fr_dict_attr_t const *fr_dict_attr_test_uint32; +extern fr_dict_attr_t const *fr_dict_attr_test_uint64; + +extern fr_dict_attr_t const *fr_dict_attr_test_int8; +extern fr_dict_attr_t const *fr_dict_attr_test_int16; +extern fr_dict_attr_t const *fr_dict_attr_test_int32; +extern fr_dict_attr_t const *fr_dict_attr_test_int64; + +extern fr_dict_attr_t const *fr_dict_attr_test_float32; +extern fr_dict_attr_t const *fr_dict_attr_test_float64; + +extern fr_dict_attr_t const *fr_dict_attr_test_date; + +extern fr_dict_attr_t const *fr_dict_attr_test_time_delta; + +extern fr_dict_attr_t const *fr_dict_attr_test_size; + +extern fr_dict_attr_t const *fr_dict_attr_test_tlv; +extern fr_dict_attr_t const *fr_dict_attr_test_tlv_string; + +extern fr_dict_attr_t const *fr_dict_attr_test_struct; +extern fr_dict_attr_t const *fr_dict_attr_test_struct_uint32; + +extern fr_dict_attr_t const *fr_dict_attr_test_vsa; +extern fr_dict_attr_t const *fr_dict_attr_test_vendor; +extern fr_dict_attr_t const *fr_dict_attr_test_vendor_string; + +extern fr_dict_attr_t const *fr_dict_attr_test_group; + +extern fr_dict_attr_t const *fr_dict_attr_test_enum; + +extern fr_dict_test_attr_t const fr_dict_test_attrs[]; + +int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs); + +#ifdef __cplusplus +} +#endif diff --git a/src/lib/util/dict_validate.c b/src/lib/util/dict_validate.c index d5311b772e9..11d5895c377 100644 --- a/src/lib/util/dict_validate.c +++ b/src/lib/util/dict_validate.c @@ -278,10 +278,12 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, case FR_TYPE_IPV4_ADDR: case FR_TYPE_UINT32: case FR_TYPE_INT32: + case FR_TYPE_FLOAT32: flags->length = 4; break; case FR_TYPE_UINT64: + case FR_TYPE_FLOAT64: flags->length = 8; break; @@ -417,7 +419,6 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, break; case FR_TYPE_NULL: - case FR_TYPE_FLOAT64: fr_strerror_printf("Attributes of type '%s' cannot be used in dictionaries", fr_table_str_by_value(fr_value_box_type_table, type, "?Unknown?")); return false; @@ -481,8 +482,9 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, sibling = fr_dict_attr_child_by_num(parent, (*attr) - 1); if (!sibling) { - fr_strerror_printf("Child %s of 'struct' type attribute %s MUST be numbered consecutively %u.", - name, parent->name, *attr); + fr_strerror_printf("Child \"%s\" of 'struct' ttribute \"%s\" MUST be " + "numbered consecutively %u.", + name, parent->name, *attr); return false; } diff --git a/src/lib/util/libfreeradius-util.mk b/src/lib/util/libfreeradius-util.mk index 7f94a5d20db..076222d0e6b 100644 --- a/src/lib/util/libfreeradius-util.mk +++ b/src/lib/util/libfreeradius-util.mk @@ -15,6 +15,7 @@ SOURCES := \ dict_ext.c \ dict_fixup.c \ dict_print.c \ + dict_test.c \ dict_tokenize.c \ dict_unknown.c \ dict_util.c \ diff --git a/src/lib/util/pair_legacy.c b/src/lib/util/pair_legacy.c index f43701cb0f9..4847ab5d04b 100644 --- a/src/lib/util/pair_legacy.c +++ b/src/lib/util/pair_legacy.c @@ -281,16 +281,18 @@ fr_pair_t *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t * static ssize_t fr_pair_list_afrom_substr(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, char const *buffer, char const *end, fr_pair_list_t *list, fr_token_t *token, int depth, fr_pair_t **relative_vp) { - fr_pair_list_t tmp_list; - fr_pair_t *vp = NULL; - fr_pair_t *my_relative_vp; - char const *p, *q, *next; - fr_token_t quote, last_token = T_INVALID; - fr_pair_t_RAW raw; - fr_dict_attr_t const *internal = fr_dict_root(fr_dict_internal()); - fr_pair_list_t *my_list; - TALLOC_CTX *my_ctx; - + fr_pair_list_t tmp_list; + fr_pair_t *vp = NULL; + fr_pair_t *my_relative_vp; + char const *p, *q, *next; + fr_token_t quote, last_token = T_INVALID; + fr_pair_t_RAW raw; + fr_dict_attr_t const *internal = NULL; + fr_pair_list_t *my_list; + TALLOC_CTX *my_ctx; + + if (fr_dict_internal()) internal = fr_dict_root(fr_dict_internal()); + if (!internal && !parent) return 0; if (internal == parent) internal = NULL; /* diff --git a/src/lib/util/pair_legacy_tests.c b/src/lib/util/pair_legacy_tests.c index e1f7bfea9d7..c2928afc437 100644 --- a/src/lib/util/pair_legacy_tests.c +++ b/src/lib/util/pair_legacy_tests.c @@ -33,138 +33,35 @@ * It should be declared before include the "acutest.h" */ #ifdef USE_CONSTRUCTOR -static void pair_tests_init(void) __attribute__((constructor)); +static void test_init(void) __attribute__((constructor)); #else -static void pair_tests_init(void); -# define TEST_INIT pair_tests_init() +static void test_init(void); +# define TEST_INIT test_init() #endif #include +#include +#include #include #include -#include +#include #include #include -#include - #ifdef HAVE_GPERFTOOLS_PROFILER_H # include #endif -static char const *dict_dir = "share/dictionary"; - -/* Set by pair_tests_init()*/ static TALLOC_CTX *autofree; -static fr_pair_list_t sample_pairs; -static char const *sample_string = "We love Tapioca!"; - -/* - * Needed by fr_dict_*() API - */ -#include "dict_priv.h" - -typedef struct value { - char const *key; - fr_value_box_t val; -} fr_dict_adhoc_attr_value_t; - -typedef struct { - int attr; - fr_dict_attr_t const **parent; - fr_dict_attr_t const **da; - char const *name; - fr_type_t type; - void *values; -} fr_dict_adhoc_attr_t; - -#define FR_TEST_INTEGER 1 -#define FR_TEST_STRING 2 -#define FR_TEST_OCTETS 3 -#define FR_TEST_VALUES 4 -#define FR_TEST_TLV_ROOT 5 -#define FR_TEST_TLV_STRING 1 - -static fr_dict_t *dict_test; -static fr_dict_t *dict_internal; - -static fr_dict_attr_t const *attr_test_integer; -static fr_dict_attr_t const *attr_test_string; -static fr_dict_attr_t const *attr_test_octets; -static fr_dict_attr_t const *attr_test_values; -static fr_dict_attr_t const *attr_test_tlv_root; -static fr_dict_attr_t const *attr_test_tlv_string; - -static fr_dict_adhoc_attr_value_t attr_test_values_entries[] = { - { .key = "Tapioca123", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 123 } }, - { .key = "Tapioca321", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 321 } }, - { .key = NULL, }, -}; +static fr_pair_list_t test_pairs; +static fr_dict_t *test_dict; -static fr_dict_adhoc_attr_t test_dict_attrs[] = { - { .attr = FR_TEST_INTEGER, .parent = NULL, .da = &attr_test_integer, .name = "Test-Integer", .type = FR_TYPE_UINT32, }, - { .attr = FR_TEST_STRING, .parent = NULL, .da = &attr_test_string, .name = "Test-String", .type = FR_TYPE_STRING, }, - { .attr = FR_TEST_OCTETS, .parent = NULL, .da = &attr_test_octets, .name = "Test-Octets", .type = FR_TYPE_OCTETS, }, - { .attr = FR_TEST_VALUES, .parent = NULL, .da = &attr_test_values, .name = "Test-Values", .type = FR_TYPE_UINT32, .values = &attr_test_values_entries }, - { .attr = FR_TEST_TLV_ROOT, .parent = NULL, .da = &attr_test_tlv_root, .name = "Test-TLV-Root", .type = FR_TYPE_TLV, }, - { .attr = FR_TEST_TLV_STRING, .parent = &attr_test_tlv_root, .da = &attr_test_tlv_string, .name = "Test-TLV-String", .type = FR_TYPE_STRING, }, - { .attr = -1, .parent = NULL, .da = NULL, .name = NULL, .type = FR_TYPE_NULL } -}; -/* - * It will be called before of unit tests. +/** Global initialisation */ -static int load_attr_pairs(fr_pair_list_t *out) -{ - fr_dict_adhoc_attr_t *p; - - fr_pair_list_init(out); - - for (p = test_dict_attrs; - p->attr != -1; - p++) if (fr_pair_prepend_by_da(autofree, NULL, out, *p->da) < 0) return -1; - - return 0; -} - -static int init_adhoc_attrs(fr_dict_adhoc_attr_t *dict_adhoc) -{ - fr_dict_adhoc_attr_t *ctx; - fr_dict_attr_flags_t dict_flags = { - .is_root = true - }; - - for (ctx = dict_adhoc; - ctx->attr != -1; - ctx++) { - fr_dict_attr_t const *parent = ctx->parent ? *ctx->parent : fr_dict_root(dict_test); - fr_dict_attr_t const *attr; - - if (fr_dict_attr_add(dict_test, parent, ctx->name, ctx->attr, ctx->type, &dict_flags) < 0) return -1; - - attr = fr_dict_attr_by_name(NULL, parent, ctx->name); - if (!attr) return -1; - - /* Set the VALUES */ - if (ctx->values) { - fr_dict_adhoc_attr_value_t *v; - - for (v = ctx->values; - v->key != NULL; - v++) fr_dict_enum_add_name(fr_dict_attr_unconst(attr), v->key, &v->val, false, false); - } - - *ctx->da = attr; - } - - return 0; -} - -static void pair_tests_init(void) +static void test_init(void) { - printf("Setup %s\n", __func__); - autofree = talloc_autofree_context(); if (!autofree) { error: @@ -177,21 +74,12 @@ static void pair_tests_init(void) */ if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error; - if (!fr_dict_global_ctx_init(autofree, dict_dir)) goto error; - - if (fr_dict_internal_afrom_file(&dict_internal, FR_DICTIONARY_INTERNAL_DIR, __FILE__) < 0) goto error; - - /* - * Set the root name of the dictionary - */ - dict_test = fr_dict_alloc("test", 666); - if (!dict_test) goto error; + if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error; - if (init_adhoc_attrs(test_dict_attrs) < 0) goto error; + /* Initialize the "test_pairs" list */ + fr_pair_list_init(&test_pairs); - /* Initialize the "sample_pairs" list */ - fr_pair_list_init(&sample_pairs); - if (load_attr_pairs(&sample_pairs) < 0) goto error; + if (fr_pair_test_list_alloc(autofree, &test_pairs, NULL) < 0) goto error; } /* @@ -206,13 +94,13 @@ static void test_fr_pair_make(void) fr_pair_list_init(&list); TEST_CASE("Creating 'vp' using fr_pair_make()"); - TEST_CHECK((vp = fr_pair_make(ctx, dict_test, &list, "Test-String", sample_string, T_DOUBLE_QUOTED_STRING)) != NULL); + TEST_CHECK((vp = fr_pair_make(ctx, test_dict, &list, "Test-String", test_string, T_DOUBLE_QUOTED_STRING)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, sample_string) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0); fr_pair_list_free(&list); } @@ -222,19 +110,19 @@ static void test_fr_pair_mark_xlat(void) fr_pair_t *vp; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); TEST_CASE("Marking 'vp' using fr_pair_mark_xlat()"); - TEST_CHECK(fr_pair_mark_xlat(vp, "Hello %{Test-Integer}") == 0); + TEST_CHECK(fr_pair_mark_xlat(vp, "Hello %{Test-Uint32}") == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Check (vp->xlat == 'Hello %{Test-Integer}')"); - TEST_CHECK(vp && strcmp(vp->xlat, "Hello %{Test-Integer}") == 0); + TEST_CASE("Check (vp->xlat == 'Hello %{Test-Uint32}')"); + TEST_CHECK(vp && strcmp(vp->xlat, "Hello %{Test-Uint32}") == 0); TEST_CHECK(vp && vp->type == VT_XLAT); talloc_free(vp); @@ -244,30 +132,30 @@ static void test_fr_pair_list_afrom_str(void) { fr_pair_t *vp; fr_pair_list_t list; - char const *buffer = "Test-Integer = 123, Test-String = \"Tapioca\""; + char const *buffer = "Test-Uint32 = 123, Test-String = \"Testing123\""; fr_pair_list_init(&list); TEST_CASE("Create 'vp' using fr_pair_list_afrom_str()"); - TEST_CHECK(fr_pair_list_afrom_str(autofree, dict_test, buffer, strlen(buffer), &list) == T_EOL); + TEST_CHECK(fr_pair_list_afrom_str(autofree, test_dict, buffer, strlen(buffer), &list) == T_EOL); - TEST_CASE("Looking for Test-Integer"); - TEST_CHECK((vp = fr_pair_find_by_da(&list, attr_test_integer)) != NULL); + TEST_CASE("Looking for Test-Uint32"); + TEST_CHECK((vp = fr_pair_find_by_da(&list, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Checking if (Test-Integer == 123)"); + TEST_CASE("Checking if (Test-Uint32 == 123)"); TEST_CHECK(vp && vp->vp_uint32 == 123); TEST_CASE("Looking for Test-String"); - TEST_CHECK((vp = fr_pair_find_by_da(&list, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&list, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Checking if (Test-String == 'Tapioca')"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, "Tapioca") == 0); + TEST_CASE("Checking if (Test-String == 'Testing123')"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, "Testing123") == 0); fr_pair_list_free(&list); } @@ -291,32 +179,32 @@ static void test_fr_pair_list_afrom_file(void) { fr_pair_t *vp; fr_pair_list_t list; - char const *buffer = "Test-Integer = 123\nTest-String = \"Tapioca\"\n"; + char const *buffer = "Test-Uint32 = 123\nTest-String = \"Testing123\"\n"; FILE *fp = open_buffer_as_file(buffer, strlen(buffer)); bool pfiledone; fr_pair_list_init(&list); TEST_CASE("Create 'vp' using fr_pair_list_afrom_file()"); - TEST_CHECK(fr_pair_list_afrom_file(autofree, dict_test, &list, fp, &pfiledone) == 0); + TEST_CHECK(fr_pair_list_afrom_file(autofree, test_dict, &list, fp, &pfiledone) == 0); - TEST_CASE("Looking for Test-Integer"); - TEST_CHECK((vp = fr_pair_find_by_da(&list, attr_test_integer)) != NULL); + TEST_CASE("Looking for Test-Uint32"); + TEST_CHECK((vp = fr_pair_find_by_da(&list, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Checking if (Test-Integer == 123)"); + TEST_CASE("Checking if (Test-Uint32 == 123)"); TEST_CHECK(vp && vp->vp_uint32 == 123); TEST_CASE("Looking for Test-String"); - TEST_CHECK((vp = fr_pair_find_by_da(&list, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&list, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Checking if (Test-String == 'Tapioca')"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, "Tapioca") == 0); + TEST_CASE("Checking if (Test-String == 'Testing123')"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, "Testing123") == 0); fr_pair_list_free(&list); @@ -328,40 +216,40 @@ static void test_fr_pair_list_move(void) fr_pair_t *vp; fr_pair_list_t old_list, new_list; bool pfiledone; - char const *fake_file = "Test-Integer = 123\nTest-String = \"Tapioca\"\n"; + char const *fake_file = "Test-Uint32 = 123\nTest-String = \"Testing123\"\n"; FILE *fp = open_buffer_as_file(fake_file, strlen(fake_file)); fr_pair_list_init(&old_list); fr_pair_list_init(&new_list); TEST_CASE("Create 'vp' using fr_pair_list_afrom_file()"); - TEST_CHECK(fr_pair_list_afrom_file(autofree, dict_test, &old_list, fp, &pfiledone) == 0); + TEST_CHECK(fr_pair_list_afrom_file(autofree, test_dict, &old_list, fp, &pfiledone) == 0); TEST_CHECK(pfiledone == true); TEST_CASE("Move pair from 'old_list' to 'old_list' using fr_pair_list_move()"); fr_pair_list_move(&new_list, &old_list); - TEST_CASE("Looking for Test-Integer"); - TEST_CHECK((vp = fr_pair_find_by_da(&new_list, attr_test_integer)) != NULL); + TEST_CASE("Looking for Test-Uint32"); + TEST_CHECK((vp = fr_pair_find_by_da(&new_list, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); TEST_CHECK(vp != NULL); - TEST_CASE("Checking if (Test-Integer == 123)"); + TEST_CASE("Checking if (Test-Uint32 == 123)"); TEST_CHECK(vp && vp->vp_uint32 == 123); TEST_CASE("Looking for Test-String"); - TEST_CHECK((vp = fr_pair_find_by_da(&new_list, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&new_list, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); TEST_CHECK(vp != NULL); - TEST_CASE("Checking if (Test-String == 'Tapioca')"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, "Tapioca") == 0); + TEST_CASE("Checking if (Test-String == 'Testing123')"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, "Testing123") == 0); fr_pair_list_free(&old_list); fr_pair_list_free(&new_list); diff --git a/src/lib/util/pair_list_perf_test.c b/src/lib/util/pair_list_perf_test.c index f5e44a78f3e..5fb5de03b69 100644 --- a/src/lib/util/pair_list_perf_test.c +++ b/src/lib/util/pair_list_perf_test.c @@ -47,26 +47,39 @@ static void fr_pair_list_perf_init(void); #endif #include "pair.c" +#include #include -typedef struct { - int attr; - fr_dict_attr_t const **parent; - fr_dict_attr_t const **da; - char const *name; - fr_type_t type; - void *values; -} fr_dict_adhoc_attr_t; - /* * Global variables */ -static fr_dict_t *dict; -static char const *dict_dir = "share/dictionary"; +static fr_dict_t *test_dict; static TALLOC_CTX *autofree; static int input_count = 0; -static char const *test_attrs = "Tmp-String-0 = \"goodbye\",Tmp-String-1 = \"wibble\",Tmp-Integer-0 = 542,Tmp-Integer-1 = 456,Tmp-IP-Address-0 = 192.168.1.1,Tmp-IP-Address-1 = 10.0.0.1,Tmp-Ethernet-0 = 11:22:33:44:55:66,Tmp-Ethernet-1 = ff:ee:dd:cc:bb:aa,Tmp-Date-0 = 959985459,Tmp-Date-1 = \"Jan 1 2020 00:00:00 UTC\",Tmp-Integer64-0 = 156453412,Tmp-Integer64-1 = 46456155,Tmp-Signed-0 = -4573,Tmp-Signed-1 = 45645,Tmp-Float-0 = 45.48,Tmp-Float-0 = 58.64,IP-Pool.Name = \"main\",IP-Pool.Action = Allocate"; +static char const *test_attrs = \ + "Test-String += \"goodbye\"," /* 1 */ + "Test-String += \"wibble\"," /* 2 */ + "Test-String += \"bob\"," /* 3 */ + "Test-String += \"rowlf\"," /* 4 */ + "Test-Octets += 0x0102030405060708," /* 5 */ + "Test-Octets += 0x0203040506070809," /* 6 */ + "Test-IPv4-Addr = 192.168.1.1," /* 7 */ + "Test-IPv4-Prefix = 192.168/16," /* 8 */ + "Test-IPv6-Addr = fd12:3456:789a:1::1," /* 8 */ + "Test-IPv6-Prefix = fd12:3456:789a:1::/64," /* 9 */ + "Test-Ethernet = 11:22:33:44:55:66," /* 10 */ + "Test-Uint8 = 255," /* 11 */ + "Test-Uint16 = 65535," /* 12 */ + "Test-Uint32 = 4294967295," /* 13 */ + "Test-Uint64 = 18446744073709551615," /* 14 */ + "Test-Int16 = -4573," /* 15 */ + "Test-Int32 = 45645," /* 16 */ + "Test-Int64 = 85645," /* 17 */ + "Test-Date += \"Jan 1 2020 00:00:00 UTC\"," /* 18 */ + "Test-TLV.String = \"nested\"," /* 19 */ + "Test-Struct.uint32 = 1234"; /* 20 */ + static fr_pair_t **source_vps; void fr_pair_list_perf_init(void) @@ -74,15 +87,26 @@ void fr_pair_list_perf_init(void) fr_pair_list_t input_vps; fr_pair_t *vp, *next; int i; - - fr_pair_list_init(&input_vps); - autofree = talloc_autofree_context(); - - TEST_ASSERT(fr_dict_global_ctx_init(autofree, dict_dir) != NULL); - - TEST_ASSERT(fr_dict_internal_afrom_file(&dict, FR_DICTIONARY_INTERNAL_DIR, __FILE__) == 0); - - TEST_ASSERT(fr_pair_list_afrom_str(autofree, dict, test_attrs, strlen(test_attrs), &input_vps) != T_INVALID); + fr_token_t ret; + + autofree = talloc_autofree_context(); + if (!autofree) { + error: + fr_perror("pair_list_perf_tests"); + fr_exit_now(EXIT_FAILURE); + } + + /* + * Mismatch between the binary and the libraries it depends on + */ + if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error; + + if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error; + + fr_pair_list_init(&input_vps); + ret = fr_pair_list_afrom_str(autofree, test_dict, test_attrs, strlen(test_attrs), &input_vps); + if (ret == T_INVALID) fr_perror("pair_list_perf_tests"); + TEST_ASSERT(ret != T_INVALID); fr_time_start(); diff --git a/src/lib/util/pair_test_helpers.h b/src/lib/util/pair_test_helpers.h new file mode 100644 index 00000000000..fe54b2ede92 --- /dev/null +++ b/src/lib/util/pair_test_helpers.h @@ -0,0 +1,59 @@ +#pragma once +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** Helper functions for pair tests + * + * @file src/lib/util/pair_test_helpers.h + * + * @copyright 2021 The FreeRADIUS server project + */ +RCSIDH(pair_test_h, "$Id$") + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +static char const *test_string = "We love testing!"; +static size_t test_string_len = 16; +static uint8_t test_octets[] = { + 0x53, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, + 0x20, 0x74, 0x65, 0x69, 0x74, 0x20, 0x41, + 0x63, 0x61, 0x64, 0x65, 0x6d, 0x79, 0x0a + }; + +static inline int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out, + fr_dict_test_attr_t const *test_defs) +{ + fr_dict_test_attr_t const *p; + + if (!test_defs) test_defs = fr_dict_test_attrs; + + fr_pair_list_init(out); + + for (p = test_defs; + p->attr != -1; + p++) if (fr_pair_prepend_by_da(ctx, NULL, out, *p->da) < 0) return -1; + + return 0; +} + +#ifdef __cplusplus +} +#endif diff --git a/src/lib/util/pair_tests.c b/src/lib/util/pair_tests.c index 0b570db2def..e38ca64baa9 100644 --- a/src/lib/util/pair_tests.c +++ b/src/lib/util/pair_tests.c @@ -24,7 +24,7 @@ /** * The 'TEST_INIT' macro provided by 'acutest.h' allowing to register a function to be called * before call the unit tests. Therefore, It calls the function ALL THE TIME causing an overhead. - * That is why we are initializing pair_tests_init() by "__attribute__((constructor));" reducing the + * That is why we are initializing test_init() by "__attribute__((constructor));" reducing the * test execution by 50% of the time. */ #define USE_CONSTRUCTOR @@ -33,147 +33,33 @@ * It should be declared before include the "acutest.h" */ #ifdef USE_CONSTRUCTOR -static void pair_tests_init(void) __attribute__((constructor)); +static void test_init(void) __attribute__((constructor)); #else -static void pair_tests_init(void); -# define TEST_INIT pair_tests_init() +static void test_init(void); +# define TEST_INIT test_init() #endif #include +#include +#include #include #include +#include #include #include -#include - #ifdef HAVE_GPERFTOOLS_PROFILER_H # include #endif -#define ARRAY_SIZE(x) ((sizeof(x)/sizeof(x[0]))) - -static char const *dict_dir = "share/dictionary"; - -/* Set by pair_tests_init()*/ static TALLOC_CTX *autofree; -static fr_pair_list_t sample_pairs; -static char const *sample_string = "We love Tapioca!"; -static size_t sample_string_len = 16; -static uint8_t sample_octets[] = { - 0x53, 0x63, 0x61, 0x6c, 0x64, 0x20, 0x52, - 0x65, 0x64, 0x64, 0x69, 0x74, 0x20, 0x41, - 0x63, 0x61, 0x64, 0x65, 0x6d, 0x79, 0x0a -}; +static fr_pair_list_t test_pairs; +static fr_dict_t *test_dict; -/* - * Needed by fr_dict_*() API +/** Global initialisation */ -#include "dict_priv.h" - -typedef struct value { - char const *key; - fr_value_box_t val; -} fr_dict_adhoc_attr_value_t; - -typedef struct { - int attr; - fr_dict_attr_t const **parent; - fr_dict_attr_t const **da; - char const *name; - fr_type_t type; - void *values; -} fr_dict_adhoc_attr_t; - -#define FR_TEST_INTEGER 1 -#define FR_TEST_STRING 2 -#define FR_TEST_OCTETS 3 -#define FR_TEST_VALUES 4 -#define FR_TEST_TLV_ROOT 5 -#define FR_TEST_TLV_STRING 1 -#define FR_TEST_DATE 6 -#define FR_TEST_IPV4_ADDR 7 - -static fr_dict_t *dict_test; - -static fr_dict_attr_t const *attr_test_integer; -static fr_dict_attr_t const *attr_test_octets; -static fr_dict_attr_t const *attr_test_string; -static fr_dict_attr_t const *attr_test_date; -static fr_dict_attr_t const *attr_test_ipv4_addr; -static fr_dict_attr_t const *attr_test_tlv_root; -static fr_dict_attr_t const *attr_test_tlv_string; -static fr_dict_attr_t const *attr_test_values; - -static fr_dict_adhoc_attr_value_t attr_test_values_entries[] = { - { .key = "Tapioca123", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 123 } }, - { .key = "Tapioca321", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 321 } }, - { .key = NULL, }, -}; - -static fr_dict_adhoc_attr_t test_dict_attrs[] = { - { .attr = FR_TEST_INTEGER, .parent = NULL, .da = &attr_test_integer, .name = "Test-Integer", .type = FR_TYPE_UINT32, }, - { .attr = FR_TEST_OCTETS, .parent = NULL, .da = &attr_test_octets, .name = "Test-Octets", .type = FR_TYPE_OCTETS, }, - { .attr = FR_TEST_STRING, .parent = NULL, .da = &attr_test_string, .name = "Test-String", .type = FR_TYPE_STRING, }, - { .attr = FR_TEST_DATE, .parent = NULL, .da = &attr_test_date, .name = "Test-Date", .type = FR_TYPE_DATE, }, - { .attr = FR_TEST_IPV4_ADDR, .parent = NULL, .da = &attr_test_ipv4_addr, .name = "Test-IPv4-Addr", .type = FR_TYPE_IPV4_ADDR, }, - { .attr = FR_TEST_TLV_ROOT, .parent = NULL, .da = &attr_test_tlv_root, .name = "Test-TLV-Root", .type = FR_TYPE_TLV, }, - { .attr = FR_TEST_TLV_STRING, .parent = &attr_test_tlv_root, .da = &attr_test_tlv_string, .name = "Test-TLV-String", .type = FR_TYPE_STRING, }, - { .attr = FR_TEST_VALUES, .parent = NULL, .da = &attr_test_values, .name = "Test-Values", .type = FR_TYPE_UINT32, .values = &attr_test_values_entries }, - { .attr = -1, .parent = NULL, .da = NULL, .name = NULL, .type = FR_TYPE_NULL } -}; - -/* - * It will be called before of unit tests. - */ -static int load_attr_pairs(fr_pair_list_t *out) -{ - fr_dict_adhoc_attr_t *p; - - fr_pair_list_init(out); - - for (p = test_dict_attrs; - p->attr != -1; - p++) if (fr_pair_prepend_by_da(autofree, NULL, out, *p->da) < 0) return -1; - - return 0; -} - -static int init_adhoc_attrs(fr_dict_adhoc_attr_t *dict_adhoc) -{ - fr_dict_adhoc_attr_t *ctx; - fr_dict_attr_flags_t dict_flags = { - .is_root = true - }; - - for (ctx = dict_adhoc; - ctx->attr != -1; - ctx++) { - fr_dict_attr_t const *parent = ctx->parent ? *ctx->parent : fr_dict_root(dict_test); - fr_dict_attr_t const *attr; - - if (fr_dict_attr_add(dict_test, parent, ctx->name, ctx->attr, ctx->type, &dict_flags) < 0) return -1; - - attr = fr_dict_attr_by_name(NULL, parent, ctx->name); - if (!attr) return -1; - - /* Set the VALUES */ - if (ctx->values) { - fr_dict_adhoc_attr_value_t *v; - - for (v = ctx->values; - v->key != NULL; - v++) fr_dict_enum_add_name(fr_dict_attr_unconst(attr), v->key, &v->val, false, false); - } - - *ctx->da = attr; - } - - return 0; -} - -static void pair_tests_init(void) +static void test_init(void) { autofree = talloc_autofree_context(); if (!autofree) { @@ -187,19 +73,12 @@ static void pair_tests_init(void) */ if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error; - if (!fr_dict_global_ctx_init(autofree, dict_dir)) goto error; + if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error; - /* - * Set the root name of the dictionary - */ - dict_test = fr_dict_alloc("test", 666); - if (!dict_test) goto error; + /* Initialize the "test_pairs" list */ + fr_pair_list_init(&test_pairs); - if (init_adhoc_attrs(test_dict_attrs) < 0) goto error; - - /* Initialize the "sample_pairs" list */ - fr_pair_list_init(&sample_pairs); - if (load_attr_pairs(&sample_pairs) < 0) goto error; + if (fr_pair_test_list_alloc(autofree, &test_pairs, NULL) < 0) goto error; } /* @@ -210,15 +89,15 @@ static void test_fr_pair_afrom_da(void) fr_pair_t *vp; TEST_CASE("Allocation using fr_pair_afrom_da"); - TEST_CHECK((vp = fr_pair_afrom_da(autofree, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_string)) != NULL); - TEST_CHECK(fr_pair_value_from_str(vp, sample_string, strlen(sample_string), '"', false) == 0); + TEST_CHECK(fr_pair_value_from_str(vp, test_string, strlen(test_string), '"', false) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, sample_string) == 0); - TEST_MSG("Expected vp->vp_strvalue == sample_string"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0); + TEST_MSG("Expected vp->vp_strvalue == test_string"); talloc_free(vp); } @@ -226,15 +105,15 @@ static void test_fr_pair_afrom_da(void) static void test_fr_pair_afrom_child_num(void) { fr_pair_t *vp; - unsigned int attr = FR_MODULE_RETURN_CODE; + unsigned int attr = FR_TEST_ATTR_STRING; TEST_CASE("Allocation using fr_pair_afrom_child_num"); - TEST_CHECK((vp = fr_pair_afrom_child_num(autofree, fr_dict_root(dict_test), attr)) != NULL); + TEST_CHECK((vp = fr_pair_afrom_child_num(autofree, fr_dict_root(test_dict), attr)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CHECK(vp && vp->da->attr == FR_MODULE_RETURN_CODE); + TEST_CHECK(vp && vp->da->attr == FR_TEST_ATTR_STRING); TEST_MSG("Expected attr(%d) == vp->da->attr(%d)", attr, vp->da->attr); talloc_free(vp); @@ -245,7 +124,7 @@ static void test_fr_pair_copy(void) fr_pair_t *vp, *copy; TEST_CASE("Allocation using fr_pair_copy"); - TEST_CHECK((vp = fr_pair_afrom_da(autofree, attr_test_integer)) != NULL); + TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -270,7 +149,7 @@ static void test_fr_pair_steal(void) TALLOC_CTX *ctx = talloc_null_ctx(); TEST_CASE("Allocate a new attribute fr_pair_afrom_da"); - TEST_CHECK((vp = fr_pair_afrom_da(ctx, attr_test_integer)) != NULL); + TEST_CHECK((vp = fr_pair_afrom_da(ctx, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -287,7 +166,7 @@ static void test_fr_pair_to_unknown(void) fr_pair_t *vp; TEST_CASE("Allocate a new attribute fr_pair_afrom_da"); - TEST_CHECK((vp = fr_pair_afrom_da(autofree, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -304,9 +183,9 @@ static void test_fr_dcursor_iter_by_da_init(void) fr_pair_t *vp, *needle; fr_dcursor_t cursor; - TEST_CASE("Searching for attr_test_integer using fr_dcursor_iter_by_da_init()"); + TEST_CASE("Searching for fr_dict_attr_test_uint32 using fr_dcursor_iter_by_da_init()"); needle = NULL; - for (vp = fr_dcursor_iter_by_da_init(&cursor, &sample_pairs, attr_test_integer); + for (vp = fr_dcursor_iter_by_da_init(&cursor, &test_pairs, fr_dict_attr_test_uint32); vp; vp = fr_dcursor_next(&cursor)) { if (!needle) { @@ -319,8 +198,8 @@ static void test_fr_dcursor_iter_by_da_init(void) TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(needle); - TEST_CASE("Expected (needle->da == attr_test_integer)"); - TEST_CHECK(needle && needle->da == attr_test_integer); + TEST_CASE("Expected (needle->da == fr_dict_attr_test_uint32)"); + TEST_CHECK(needle && needle->da == fr_dict_attr_test_uint32); } static void test_fr_dcursor_iter_by_ancestor_init(void) @@ -328,13 +207,13 @@ static void test_fr_dcursor_iter_by_ancestor_init(void) fr_pair_t *vp, *needle; fr_dcursor_t cursor; - TEST_CASE("Searching for attr_test_tlv_string as ascend of attr_test_tlv_root using fr_dcursor_iter_by_ancestor_init()"); + TEST_CASE("Searching for fr_dict_attr_test_tlv_string as ascend of fr_dict_attr_test_tlv using fr_dcursor_iter_by_ancestor_init()"); needle = NULL; - for (vp = fr_dcursor_iter_by_ancestor_init(&cursor, &sample_pairs, attr_test_tlv_root); + for (vp = fr_dcursor_iter_by_ancestor_init(&cursor, &test_pairs, fr_dict_attr_test_tlv); vp; vp = fr_dcursor_next(&cursor)) { TEST_CHECK(vp != NULL); - if (vp->da == attr_test_tlv_string) { + if (vp->da == fr_dict_attr_test_tlv_string) { needle = vp; continue; } @@ -343,36 +222,36 @@ static void test_fr_dcursor_iter_by_ancestor_init(void) TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(needle); - TEST_CASE("Expected (needle->da == attr_test_tlv_string)"); - TEST_CHECK(needle && needle->da == attr_test_tlv_string); + TEST_CASE("Expected (needle->da == fr_dict_attr_test_tlv_string)"); + TEST_CHECK(needle && needle->da == fr_dict_attr_test_tlv_string); } static void test_fr_pair_find_by_da(void) { fr_pair_t *vp; - TEST_CASE("Search for attr_test_tlv_string using fr_pair_find_by_da()"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_tlv_string)) != NULL); + TEST_CASE("Search for fr_dict_attr_test_tlv_string using fr_pair_find_by_da()"); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_tlv_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Expected (vp->da == attr_test_tlv_string)"); - TEST_CHECK(vp && vp->da == attr_test_tlv_string); + TEST_CASE("Expected (vp->da == fr_dict_attr_test_tlv_string)"); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_tlv_string); } static void test_fr_pair_find_by_child_num(void) { fr_pair_t *vp; - TEST_CASE("Search for FR_TEST_STRING using fr_pair_find_by_child_num()"); - TEST_CHECK((vp = fr_pair_find_by_child_num(&sample_pairs, fr_dict_root(dict_test), FR_TEST_STRING)) != NULL); + TEST_CASE("Search for FR_TEST_ATTR_STRING using fr_pair_find_by_child_num()"); + TEST_CHECK((vp = fr_pair_find_by_child_num(&test_pairs, fr_dict_root(test_dict), FR_TEST_ATTR_STRING)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Expected (vp->da == attr_test_string)"); - TEST_CHECK(vp && vp->da == attr_test_string); + TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)"); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_string); } static void test_fr_pair_append(void) @@ -386,9 +265,9 @@ static void test_fr_pair_append(void) fr_pair_list_init(&local_pairs); - fr_pair_append(&local_pairs, fr_pair_afrom_da(autofree, attr_test_octets)); - fr_pair_append(&local_pairs, fr_pair_afrom_da(autofree, attr_test_integer)); - fr_pair_append(&local_pairs, fr_pair_afrom_da(autofree, attr_test_tlv_root)); + fr_pair_append(&local_pairs, fr_pair_afrom_da(autofree, fr_dict_attr_test_octets)); + fr_pair_append(&local_pairs, fr_pair_afrom_da(autofree, fr_dict_attr_test_uint32)); + fr_pair_append(&local_pairs, fr_pair_afrom_da(autofree, fr_dict_attr_test_tlv)); /* lets' count */ for (vp = fr_dcursor_init(&cursor, &local_pairs); @@ -403,14 +282,14 @@ static void test_fr_pair_append(void) static void test_fr_pair_delete_by_child_num(void) { - TEST_CASE("Delete attr_test_string using fr_pair_delete_by_child_num()"); - fr_pair_delete_by_child_num(&sample_pairs, fr_dict_root(dict_test), FR_TEST_STRING); + TEST_CASE("Delete fr_dict_attr_test_string using fr_pair_delete_by_child_num()"); + fr_pair_delete_by_child_num(&test_pairs, fr_dict_root(test_dict), FR_TEST_ATTR_STRING); - TEST_CASE("The attr_test_string shouldn't exist in 'sample_pairs'"); - TEST_CHECK(fr_pair_find_by_child_num(&sample_pairs, fr_dict_root(dict_test), FR_TEST_STRING) == NULL); + TEST_CASE("The fr_dict_attr_test_string shouldn't exist in 'test_pairs'"); + TEST_CHECK(fr_pair_find_by_child_num(&test_pairs, fr_dict_root(test_dict), FR_TEST_ATTR_STRING) == NULL); - TEST_CASE("Add attr_test_string back into 'sample_pairs'"); - TEST_CHECK(fr_pair_prepend_by_da(autofree, NULL, &sample_pairs, attr_test_string) == 0); + TEST_CASE("Add fr_dict_attr_test_string back into 'test_pairs'"); + TEST_CHECK(fr_pair_prepend_by_da(autofree, NULL, &test_pairs, fr_dict_attr_test_string) == 0); } static void test_fr_pair_prepend_by_da(void) @@ -423,14 +302,14 @@ static void test_fr_pair_prepend_by_da(void) fr_pair_list_init(&local_pairs); TEST_CASE("Add using fr_pair_prepend_by_da()"); - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_string) == 0); + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_string) == 0); /* lets' count */ for (vp = fr_dcursor_init(&cursor, &local_pairs); vp; vp = fr_dcursor_next(&cursor)) { - TEST_CASE("Expected (vp->da == attr_test_string)"); - TEST_CHECK(vp->da == attr_test_string); + TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)"); + TEST_CHECK(vp->da == fr_dict_attr_test_string); } fr_pair_list_free(&local_pairs); @@ -441,11 +320,11 @@ static void test_fr_pair_update_by_da(void) fr_pair_t *vp; TEST_CASE("Update Add using fr_pair_prepend_by_da()"); - TEST_CHECK(fr_pair_update_by_da(autofree, &vp, &sample_pairs, attr_test_integer) == 1); /* attribute already exist */ + TEST_CHECK(fr_pair_update_by_da(autofree, &vp, &test_pairs, fr_dict_attr_test_uint32) == 1); /* attribute already exist */ vp->vp_uint32 = 54321; - TEST_CASE("Expected attr_test_integer (vp->vp_uint32 == 54321)"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_integer)) != NULL); + TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 54321)"); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -456,29 +335,29 @@ static void test_fr_pair_update_by_da(void) static void test_fr_pair_delete_by_da(void) { - TEST_CASE("Delete attr_test_string using fr_pair_delete_by_da()"); - TEST_CHECK(fr_pair_delete_by_da(&sample_pairs, attr_test_string) == 1); + TEST_CASE("Delete fr_dict_attr_test_string using fr_pair_delete_by_da()"); + TEST_CHECK(fr_pair_delete_by_da(&test_pairs, fr_dict_attr_test_string) == 1); - TEST_CASE("The attr_test_string shouldn't exist in 'sample_pairs'"); - TEST_CHECK(fr_pair_find_by_da(&sample_pairs, attr_test_string) == NULL); + TEST_CASE("The fr_dict_attr_test_string shouldn't exist in 'test_pairs'"); + TEST_CHECK(fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string) == NULL); - TEST_CASE("Add attr_test_string back into 'sample_pairs'"); - TEST_CHECK(fr_pair_prepend_by_da(autofree, NULL, &sample_pairs, attr_test_string) == 0); + TEST_CASE("Add fr_dict_attr_test_string back into 'test_pairs'"); + TEST_CHECK(fr_pair_prepend_by_da(autofree, NULL, &test_pairs, fr_dict_attr_test_string) == 0); } static void test_fr_pair_delete(void) { fr_pair_t *vp; - TEST_CASE("Delete attr_test_string using fr_pair_delete()"); - TEST_CHECK((vp = fr_pair_find_by_child_num(&sample_pairs, fr_dict_root(dict_test), FR_TEST_STRING)) != NULL); - fr_pair_delete(&sample_pairs, vp); + TEST_CASE("Delete fr_dict_attr_test_string using fr_pair_delete()"); + TEST_CHECK((vp = fr_pair_find_by_child_num(&test_pairs, fr_dict_root(test_dict), FR_TEST_ATTR_STRING)) != NULL); + fr_pair_delete(&test_pairs, vp); - TEST_CASE("The attr_test_string shouldn't exist in 'sample_pairs'"); - TEST_CHECK((vp = fr_pair_find_by_child_num(&sample_pairs, fr_dict_root(dict_test), FR_TEST_STRING)) == NULL); + TEST_CASE("The fr_dict_attr_test_string shouldn't exist in 'test_pairs'"); + TEST_CHECK((vp = fr_pair_find_by_child_num(&test_pairs, fr_dict_root(test_dict), FR_TEST_ATTR_STRING)) == NULL); - TEST_CASE("Add attr_test_string back into 'sample_pairs'"); - TEST_CHECK(fr_pair_prepend_by_da(autofree, NULL, &sample_pairs, attr_test_string) == 0); + TEST_CASE("Add fr_dict_attr_test_string back into 'test_pairs'"); + TEST_CHECK(fr_pair_prepend_by_da(autofree, NULL, &test_pairs, fr_dict_attr_test_string) == 0); } static void test_fr_pair_cmp(void) @@ -486,7 +365,7 @@ static void test_fr_pair_cmp(void) fr_pair_t *vp1, *vp2; TEST_CASE("Create the vp1 'Test-Integer = 123'"); - TEST_CHECK((vp1 = fr_pair_afrom_da(autofree, attr_test_integer)) != NULL); + TEST_CHECK((vp1 = fr_pair_afrom_da(autofree, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp1); @@ -495,7 +374,7 @@ static void test_fr_pair_cmp(void) vp1->vp_uint32 = 123; TEST_CASE("Create the vp2 'Test-Integer = 321'"); - TEST_CHECK((vp2 = fr_pair_afrom_da(autofree, attr_test_integer)) != NULL); + TEST_CHECK((vp2 = fr_pair_afrom_da(autofree, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp2); @@ -515,10 +394,10 @@ static void test_fr_pair_list_cmp(void) fr_pair_list_init(&local_pairs2); TEST_CASE("Create 'local_pairs1'"); - TEST_CHECK(load_attr_pairs(&local_pairs1) == 0); + TEST_CHECK(fr_pair_test_list_alloc(autofree, &local_pairs1, NULL) == 0); TEST_CASE("Create 'local_pairs2'"); - TEST_CHECK(load_attr_pairs(&local_pairs2) == 0); + TEST_CHECK(fr_pair_test_list_alloc(autofree, &local_pairs2, NULL) == 0); TEST_CASE("Check if 'local_pairs1' == 'local_pairs2' using fr_pair_list_cmp()"); TEST_CHECK(fr_pair_list_cmp(&local_pairs1, &local_pairs2) == 0); @@ -533,11 +412,11 @@ static void test_fr_pair_list_copy(void) fr_pair_list_init(&local_pairs); - TEST_CASE("Copy 'sample_pairs' into 'local_pairs'"); - TEST_CHECK(fr_pair_list_copy(autofree, &local_pairs, &sample_pairs) > 0); + TEST_CASE("Copy 'test_pairs' into 'local_pairs'"); + TEST_CHECK(fr_pair_list_copy(autofree, &local_pairs, &test_pairs) > 0); - TEST_CASE("Check if 'local_pairs' == 'sample_pairs' using fr_pair_list_cmp()"); - TEST_CHECK(fr_pair_list_cmp(&local_pairs, &sample_pairs) == 0); + TEST_CASE("Check if 'local_pairs' == 'test_pairs' using fr_pair_list_cmp()"); + TEST_CHECK(fr_pair_list_cmp(&local_pairs, &test_pairs) == 0); fr_pair_list_free(&local_pairs); } @@ -550,18 +429,18 @@ static void test_fr_pair_list_copy_by_da(void) fr_pair_list_init(&local_pairs); - TEST_CASE("Copy 'sample_pairs' into 'local_pairs'"); - TEST_CHECK(fr_pair_list_copy_by_da(autofree, &local_pairs, &sample_pairs, attr_test_string, 0) > 0); + TEST_CASE("Copy 'test_pairs' into 'local_pairs'"); + TEST_CHECK(fr_pair_list_copy_by_da(autofree, &local_pairs, &test_pairs, fr_dict_attr_test_string, 0) > 0); - TEST_CASE("The 'local_pairs' should have only attr_test_string"); + TEST_CASE("The 'local_pairs' should have only fr_dict_attr_test_string"); for (vp = fr_dcursor_init(&cursor, &local_pairs); vp; vp = fr_dcursor_next(&cursor)) { TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Expected (vp->da == attr_test_string)"); - TEST_CHECK(vp->da == attr_test_string); + TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)"); + TEST_CHECK(vp->da == fr_dict_attr_test_string); } fr_pair_list_free(&local_pairs); @@ -575,17 +454,17 @@ static void test_fr_pair_list_copy_by_ancestor(void) fr_pair_list_init(&local_pairs); - TEST_CASE("Copy 'sample_pairs' into 'local_pairs'"); - TEST_CHECK(fr_pair_list_copy_by_ancestor(autofree, &local_pairs, &sample_pairs, attr_test_tlv_root, 0) > 0); + TEST_CASE("Copy 'test_pairs' into 'local_pairs'"); + TEST_CHECK(fr_pair_list_copy_by_ancestor(autofree, &local_pairs, &test_pairs, fr_dict_attr_test_tlv, 0) > 0); - TEST_CASE("The 'local_pairs' should have only attr_test_tlv_string (ancestor of 'Test-TLV-Root'"); + TEST_CASE("The 'local_pairs' should have only fr_dict_attr_test_tlv_string (ancestor of 'Test-TLV-Root'"); for (vp = fr_dcursor_init(&cursor, &local_pairs); vp; vp = fr_dcursor_next(&cursor)) { TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - if (vp->da == attr_test_tlv_string) { + if (vp->da == fr_dict_attr_test_tlv_string) { needle = vp; break; } @@ -594,8 +473,8 @@ static void test_fr_pair_list_copy_by_ancestor(void) TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(needle); - TEST_CASE("Expected (needle->da == attr_test_tlv_string)"); - TEST_CHECK(needle && needle->da == attr_test_tlv_string); + TEST_CASE("Expected (needle->da == fr_dict_attr_test_tlv_string)"); + TEST_CHECK(needle && needle->da == fr_dict_attr_test_tlv_string); fr_pair_list_free(&local_pairs); } @@ -610,35 +489,43 @@ static void test_fr_pair_list_sort(void) TEST_CASE("Create 'local_pairs' with 3 attributes not ordered"); fr_pair_list_init(&local_pairs); - TEST_CASE("Add attr_test_string back into 'local_pairs'"); - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_date) == 0); - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_ipv4_addr) == 0); - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_octets) == 0); - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_integer) == 0); - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_values) == 0); // It will be go to the tail - TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, attr_test_string) == 0); + TEST_CASE("Add fr_dict_attr_test_string back into 'local_pairs'"); + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_date) == 0); + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_ipv4_addr) == 0); + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_octets) == 0); + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_uint32) == 0); + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_enum) == 0); // It will be go to the tail + TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_string) == 0); + /* + * FIXME - This test doesn't check for intra-type stability + */ TEST_CASE("Sorting 'local_pairs' by fr_pair_list_sort(local_pairs, fr_pair_cmp_by_da)"); fr_pair_list_sort(&local_pairs, fr_pair_cmp_by_da); - TEST_CASE("1st (da == attr_test_integer)"); + + TEST_CASE("1st (da == fr_dict_attr_test_string)"); TEST_CHECK((vp = fr_dcursor_init(&cursor, &local_pairs)) != NULL); - TEST_CHECK(vp && vp->da == attr_test_integer); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_string); + + TEST_CASE("2nd (da == fr_dict_attr_test_octets)"); + TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_octets); - TEST_CASE("2st (da == attr_test_octets)"); + TEST_CASE("3rd (da == fr_dict_attr_test_ipv4_addr)"); TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL); - TEST_CHECK(vp && vp->da == attr_test_octets); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_ipv4_addr); - TEST_CASE("3st (da == attr_test_string)"); + TEST_CASE("4th (da == fr_dict_attr_test_uint32)"); TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL); - TEST_CHECK(vp && vp->da == attr_test_string); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_uint32); - TEST_CASE("4th (da == attr_test_date)"); + TEST_CASE("5th (da == fr_dict_attr_test_date)"); TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL); - TEST_CHECK(vp && vp->da == attr_test_date); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_date); - TEST_CASE("5th (da == attr_test_ipv4_addr)"); + TEST_CASE("6th (da == fr_dict_attr_test_enum)"); TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL); - TEST_CHECK(vp && vp->da == attr_test_ipv4_addr); + TEST_CHECK(vp && vp->da == fr_dict_attr_test_enum); fr_pair_list_free(&local_pairs); } @@ -648,7 +535,7 @@ static void test_fr_pair_value_copy(void) fr_pair_t *vp1, vp2; TEST_CASE("Create 'vp1' with Test-Integer = 123"); - TEST_CHECK((vp1 = fr_pair_find_by_da(&sample_pairs, attr_test_integer)) != NULL); + TEST_CHECK((vp1 = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_uint32)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp1); @@ -667,19 +554,19 @@ static void test_fr_pair_value_from_str(void) fr_pair_t *vp; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Convert 'sample_string' value to attribute value using fr_pair_value_from_str()"); - TEST_CHECK(fr_pair_value_from_str(vp, sample_string, strlen(sample_string), '"', false) == 0); + TEST_CASE("Convert 'test_string' value to attribute value using fr_pair_value_from_str()"); + TEST_CHECK(fr_pair_value_from_str(vp, test_string, strlen(test_string), '"', false) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, sample_string) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0); } static void test_fr_pair_value_strdup(void) @@ -687,45 +574,45 @@ static void test_fr_pair_value_strdup(void) fr_pair_t *vp; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_strdup()"); - TEST_CHECK(fr_pair_value_strdup(vp, sample_string) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup()"); + TEST_CHECK(fr_pair_value_strdup(vp, test_string) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, sample_string) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0); } static void test_fr_pair_value_strdup_shallow(void) { fr_pair_t *vp; - char *copy_sample_string; + char *copy_test_string; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_string = talloc_strdup(vp, sample_string); - talloc_set_type(copy_sample_string, char); + copy_test_string = talloc_strdup(vp, test_string); + talloc_set_type(copy_test_string, char); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_strdup_shallow()"); - TEST_CHECK(fr_pair_value_strdup_shallow(vp, copy_sample_string, true) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()"); + TEST_CHECK(fr_pair_value_strdup_shallow(vp, copy_test_string, true) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Check (vp->vp_string == copy_sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, sample_string, strlen(copy_sample_string)) == 0); + TEST_CASE("Check (vp->vp_string == copy_test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, strlen(copy_test_string)) == 0); - talloc_free(copy_sample_string); + talloc_free(copy_test_string); } static void test_fr_pair_value_strtrim(void) @@ -733,13 +620,13 @@ static void test_fr_pair_value_strtrim(void) fr_pair_t *vp; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_strdup_shallow()"); - TEST_CHECK(fr_pair_value_strdup(vp, sample_string) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()"); + TEST_CHECK(fr_pair_value_strdup(vp, test_string) == 0); TEST_CASE("Trim the length of the string buffer using fr_pair_value_strtrim()"); TEST_CHECK(fr_pair_value_strtrim(vp) == 0); @@ -747,8 +634,8 @@ static void test_fr_pair_value_strtrim(void) TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, sample_string) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0); } static void test_fr_pair_value_aprintf(void) @@ -760,7 +647,7 @@ static void test_fr_pair_value_aprintf(void) snprintf(fmt_test, sizeof(fmt_test), "Now is %ld", (long)now); TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -781,25 +668,25 @@ static void test_fr_pair_value_bstr_alloc(void) char *out = NULL; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); TEST_CASE("Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()"); - TEST_CHECK(fr_pair_value_bstr_alloc(vp, &out, sample_string_len, false) == 0); + TEST_CHECK(fr_pair_value_bstr_alloc(vp, &out, test_string_len, false) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy 'sample_string' to the pre-allocated pointer"); - TEST_CHECK(strlcpy(out, sample_string, sample_string_len) == sample_string_len); + TEST_CASE("Copy 'test_string' to the pre-allocated pointer"); + TEST_CHECK(strlcpy(out, test_string, test_string_len) == test_string_len); - TEST_CASE("Check (out == sample_string)"); - TEST_CHECK(memcmp(out, sample_string, sample_string_len-1) == 0); + TEST_CASE("Check (out == test_string)"); + TEST_CHECK(memcmp(out, test_string, test_string_len-1) == 0); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && memcmp(vp->vp_strvalue, sample_string, sample_string_len-1) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && memcmp(vp->vp_strvalue, test_string, test_string_len-1) == 0); } static void test_fr_pair_value_bstr_realloc(void) @@ -808,7 +695,7 @@ static void test_fr_pair_value_bstr_realloc(void) char *out = NULL; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -816,20 +703,20 @@ static void test_fr_pair_value_bstr_realloc(void) TEST_CASE("Pre-allocate 1 byte of memory buffer using fr_pair_value_bstr_alloc()"); TEST_CHECK(fr_pair_value_bstr_alloc(vp, &out, 1, false) == 0); - TEST_CASE("Re-allocate (sample_string_len-1) byte of memory buffer using fr_pair_value_bstr_realloc()"); - TEST_CHECK(fr_pair_value_bstr_realloc(vp, &out, (sample_string_len - 1)) == 0); + TEST_CASE("Re-allocate (test_string_len-1) byte of memory buffer using fr_pair_value_bstr_realloc()"); + TEST_CHECK(fr_pair_value_bstr_realloc(vp, &out, (test_string_len - 1)) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy 'sample_string' to the pre-allocated pointer"); - TEST_CHECK(strlcpy(out, sample_string, sample_string_len) == sample_string_len); + TEST_CASE("Copy 'test_string' to the pre-allocated pointer"); + TEST_CHECK(strlcpy(out, test_string, test_string_len) == test_string_len); - TEST_CASE("Check (out == sample_string)"); - TEST_CHECK(memcmp(out, sample_string, sample_string_len-1) == 0); + TEST_CASE("Check (out == test_string)"); + TEST_CHECK(memcmp(out, test_string, test_string_len-1) == 0); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && memcmp(vp->vp_strvalue, sample_string, sample_string_len-1) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && memcmp(vp->vp_strvalue, test_string, test_string_len-1) == 0); } static void test_fr_pair_value_bstrndup(void) @@ -837,148 +724,148 @@ static void test_fr_pair_value_bstrndup(void) fr_pair_t *vp; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_bstrndup()"); - TEST_CHECK(fr_pair_value_bstrndup(vp, sample_string, sample_string_len-1, false) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()"); + TEST_CHECK(fr_pair_value_bstrndup(vp, test_string, test_string_len-1, false) == 0); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && memcmp(vp->vp_strvalue, sample_string, sample_string_len-1) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && memcmp(vp->vp_strvalue, test_string, test_string_len-1) == 0); } static void test_fr_pair_value_bstrdup_buffer(void) { fr_pair_t *vp; - char *copy_sample_string; + char *copy_test_string; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_string = talloc_strdup(vp, sample_string); - talloc_set_type(copy_sample_string, char); + copy_test_string = talloc_strdup(vp, test_string); + talloc_set_type(copy_test_string, char); - TEST_CASE("Copy content of 'copy_sample_string' to attribute value using fr_pair_value_bstrdup_buffer()"); - TEST_CHECK(fr_pair_value_bstrdup_buffer(vp, copy_sample_string, false) == 0); + TEST_CASE("Copy content of 'copy_test_string' to attribute value using fr_pair_value_bstrdup_buffer()"); + TEST_CHECK(fr_pair_value_bstrdup_buffer(vp, copy_test_string, false) == 0); - TEST_CASE("Check (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strcmp(vp->vp_strvalue, copy_sample_string) == 0); + TEST_CASE("Check (vp->vp_string == test_string)"); + TEST_CHECK(vp && strcmp(vp->vp_strvalue, copy_test_string) == 0); - talloc_free(copy_sample_string); + talloc_free(copy_test_string); } static void test_fr_pair_value_bstrndup_shallow(void) { fr_pair_t *vp; - char *copy_sample_string; + char *copy_test_string; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_string = talloc_strdup(vp, sample_string); - talloc_set_type(copy_sample_string, char); + copy_test_string = talloc_strdup(vp, test_string); + talloc_set_type(copy_test_string, char); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_bstrndup_shallow()"); - TEST_CHECK(fr_pair_value_bstrndup_shallow(vp, copy_sample_string, strlen(copy_sample_string), true) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup_shallow()"); + TEST_CHECK(fr_pair_value_bstrndup_shallow(vp, copy_test_string, strlen(copy_test_string), true) == 0); - TEST_CASE("Check (vp->vp_string == copy_sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, sample_string, sample_string_len) == 0); + TEST_CASE("Check (vp->vp_string == copy_test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0); - talloc_free(copy_sample_string); + talloc_free(copy_test_string); } static void test_fr_pair_value_bstrdup_buffer_shallow(void) { fr_pair_t *vp; - char *copy_sample_string; + char *copy_test_string; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_string = talloc_strdup(vp, sample_string); - talloc_set_type(copy_sample_string, char); + copy_test_string = talloc_strdup(vp, test_string); + talloc_set_type(copy_test_string, char); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_bstrdup_buffer_shallow()"); - TEST_CHECK(fr_pair_value_bstrdup_buffer_shallow(vp, copy_sample_string, true) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrdup_buffer_shallow()"); + TEST_CHECK(fr_pair_value_bstrdup_buffer_shallow(vp, copy_test_string, true) == 0); - TEST_CASE("Check (vp->vp_string == copy_sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, sample_string, sample_string_len) == 0); + TEST_CASE("Check (vp->vp_string == copy_test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0); - talloc_free(copy_sample_string); + talloc_free(copy_test_string); } static void test_fr_pair_value_bstrn_append(void) { fr_pair_t *vp; - char *copy_sample_string; + char *copy_test_string; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_string = talloc_strdup(vp, sample_string); - talloc_set_type(copy_sample_string, char); + copy_test_string = talloc_strdup(vp, test_string); + talloc_set_type(copy_test_string, char); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_bstrndup()"); - TEST_CHECK(fr_pair_value_bstrndup(vp, sample_string, sample_string_len, false) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()"); + TEST_CHECK(fr_pair_value_bstrndup(vp, test_string, test_string_len, false) == 0); - TEST_CASE("Append the 'copy_sample_string' value using fr_pair_value_bstrn_append()"); - TEST_CHECK(fr_pair_value_bstrn_append(vp, copy_sample_string, sample_string_len, true) == 0); + TEST_CASE("Append the 'copy_test_string' value using fr_pair_value_bstrn_append()"); + TEST_CHECK(fr_pair_value_bstrn_append(vp, copy_test_string, test_string_len, true) == 0); // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, sample_string, sample_string_len) == 0); + TEST_CASE("Check 1. part (vp->vp_string == test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0); - TEST_CASE("Check 2. part ((vp->vp_string+sample_string_len) == sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue+sample_string_len, sample_string, sample_string_len) == 0); + TEST_CASE("Check 2. part ((vp->vp_string+test_string_len) == test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue+test_string_len, test_string, test_string_len) == 0); - talloc_free(copy_sample_string); + talloc_free(copy_test_string); } static void test_fr_pair_value_bstr_append_buffer(void) { fr_pair_t *vp; - char *copy_sample_string; + char *copy_test_string; TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_string)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_string)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_string = talloc_strdup(vp, sample_string); - talloc_set_type(copy_sample_string, char); + copy_test_string = talloc_strdup(vp, test_string); + talloc_set_type(copy_test_string, char); - TEST_CASE("Copy content of 'sample_string' to attribute value using fr_pair_value_bstrndup()"); - TEST_CHECK(fr_pair_value_bstrndup(vp, sample_string, sample_string_len, false) == 0); + TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()"); + TEST_CHECK(fr_pair_value_bstrndup(vp, test_string, test_string_len, false) == 0); - TEST_CASE("Append the 'copy_sample_string' value using fr_pair_value_bstr_append_buffer()"); - TEST_CHECK(fr_pair_value_bstr_append_buffer(vp, copy_sample_string, true) == 0); + TEST_CASE("Append the 'copy_test_string' value using fr_pair_value_bstr_append_buffer()"); + TEST_CHECK(fr_pair_value_bstr_append_buffer(vp, copy_test_string, true) == 0); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_string == sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, sample_string, sample_string_len) == 0); + TEST_CASE("Check 1. part (vp->vp_string == test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0); - TEST_CASE("Check 2. part ((vp->vp_string+sample_string_len) == sample_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue+sample_string_len, sample_string, sample_string_len) == 0); + TEST_CASE("Check 2. part ((vp->vp_string+test_string_len) == test_string)"); + TEST_CHECK(vp && strncmp(vp->vp_strvalue+test_string_len, test_string, test_string_len) == 0); - talloc_free(copy_sample_string); + talloc_free(copy_test_string); } static void test_fr_pair_value_mem_alloc(void) @@ -987,22 +874,22 @@ static void test_fr_pair_value_mem_alloc(void) uint8_t *out; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); TEST_CASE("Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()"); - TEST_CHECK(fr_pair_value_mem_alloc(vp, &out, ARRAY_SIZE(sample_octets), false) == 0); + TEST_CHECK(fr_pair_value_mem_alloc(vp, &out, NUM_ELEMENTS(test_octets), false) == 0); - TEST_CASE("Copy 'sample_octets' to the pre-allocated pointer"); - TEST_CHECK(memcpy(out, sample_octets, ARRAY_SIZE(sample_octets)) != NULL); + TEST_CASE("Copy 'test_octets' to the pre-allocated pointer"); + TEST_CHECK(memcpy(out, test_octets, NUM_ELEMENTS(test_octets)) != NULL); - TEST_CASE("Check (out == sample_octets)"); - TEST_CHECK(memcmp(out, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check (out == test_octets)"); + TEST_CHECK(memcmp(out, test_octets, NUM_ELEMENTS(test_octets)) == 0); - TEST_CASE("Check (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); } static void test_fr_pair_value_mem_realloc(void) @@ -1011,36 +898,36 @@ static void test_fr_pair_value_mem_realloc(void) uint8_t *out; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); TEST_CASE("Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()"); - TEST_CHECK(fr_pair_value_mem_alloc(vp, &out, ARRAY_SIZE(sample_octets), false) == 0); + TEST_CHECK(fr_pair_value_mem_alloc(vp, &out, NUM_ELEMENTS(test_octets), false) == 0); - TEST_CASE("Copy 'sample_octets' to the pre-allocated pointer"); - TEST_CHECK(memcpy(out, sample_octets, ARRAY_SIZE(sample_octets)) != NULL); + TEST_CASE("Copy 'test_octets' to the pre-allocated pointer"); + TEST_CHECK(memcpy(out, test_octets, NUM_ELEMENTS(test_octets)) != NULL); - TEST_CASE("Realloc pre-allocated pointer to fit extra 'sample_octets' copy"); - TEST_CHECK(fr_pair_value_mem_realloc(vp, &out, ARRAY_SIZE(sample_octets)*2) == 0); + TEST_CASE("Realloc pre-allocated pointer to fit extra 'test_octets' copy"); + TEST_CHECK(fr_pair_value_mem_realloc(vp, &out, NUM_ELEMENTS(test_octets)*2) == 0); - TEST_CASE("Copy 'sample_octets' into the tail"); - TEST_CHECK(memcpy(out+ARRAY_SIZE(sample_octets), sample_octets, ARRAY_SIZE(sample_octets)) != NULL); + TEST_CASE("Copy 'test_octets' into the tail"); + TEST_CHECK(memcpy(out+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) != NULL); - TEST_CASE("Check first chunk (out == sample_octets)"); - TEST_CHECK(memcmp(out, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check first chunk (out == test_octets)"); + TEST_CHECK(memcmp(out, test_octets, NUM_ELEMENTS(test_octets)) == 0); TEST_CHECK(vp != NULL); - TEST_CASE("Check first chunk (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check first chunk (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - TEST_CASE("Check second chunk (out+ARRAY_SIZE(sample_octets) == sample_octets)"); - TEST_CHECK(memcmp(out+ARRAY_SIZE(sample_octets), sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check second chunk (out+NUM_ELEMENTS(test_octets) == test_octets)"); + TEST_CHECK(memcmp(out+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) == 0); - TEST_CASE("Check second chunk (vp->vp_octets+ARRAY_SIZE(sample_octets) == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets+ARRAY_SIZE(sample_octets), sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check second chunk (vp->vp_octets+NUM_ELEMENTS(test_octets) == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) == 0); } static void test_fr_pair_value_memdup(void) @@ -1048,85 +935,85 @@ static void test_fr_pair_value_memdup(void) fr_pair_t *vp; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy content of 'sample_octets' to attribute value using fr_pair_value_memdup()"); - TEST_CHECK(fr_pair_value_memdup(vp, sample_octets, ARRAY_SIZE(sample_octets), false) == 0); + TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup()"); + TEST_CHECK(fr_pair_value_memdup(vp, test_octets, NUM_ELEMENTS(test_octets), false) == 0); - TEST_CASE("Check (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); } static void test_fr_pair_value_memdup_buffer(void) { fr_pair_t *vp; - uint8_t *copy_sample_octets; + uint8_t *copy_test_octets; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_octets = talloc_memdup(vp, sample_octets, ARRAY_SIZE(sample_octets)); - talloc_set_type(copy_sample_octets, uint8_t); + copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets)); + talloc_set_type(copy_test_octets, uint8_t); - TEST_CASE("Copy content of 'sample_octets' to attribute value using fr_pair_value_memdup_buffer()"); - TEST_CHECK(fr_pair_value_memdup_buffer(vp, copy_sample_octets, true) == 0); + TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_buffer()"); + TEST_CHECK(fr_pair_value_memdup_buffer(vp, copy_test_octets, true) == 0); - TEST_CASE("Check (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - talloc_free(copy_sample_octets); + talloc_free(copy_test_octets); } static void test_fr_pair_value_memdup_shallow(void) { fr_pair_t *vp; - uint8_t *copy_sample_octets; + uint8_t *copy_test_octets; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_octets = talloc_memdup(vp, sample_octets, ARRAY_SIZE(sample_octets)); - talloc_set_type(copy_sample_octets, uint8_t); + copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets)); + talloc_set_type(copy_test_octets, uint8_t); - TEST_CASE("Copy content of 'sample_octets' to attribute value using fr_pair_value_memdup_shallow()"); - TEST_CHECK(fr_pair_value_memdup_shallow(vp, copy_sample_octets, ARRAY_SIZE(sample_octets), true) == 0); + TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_shallow()"); + TEST_CHECK(fr_pair_value_memdup_shallow(vp, copy_test_octets, NUM_ELEMENTS(test_octets), true) == 0); - TEST_CASE("Check (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - talloc_free(copy_sample_octets); + talloc_free(copy_test_octets); } static void test_fr_pair_value_memdup_buffer_shallow(void) { fr_pair_t *vp; - uint8_t *copy_sample_octets; + uint8_t *copy_test_octets; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_octets = talloc_memdup(vp, sample_octets, ARRAY_SIZE(sample_octets)); - talloc_set_type(copy_sample_octets, uint8_t); + copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets)); + talloc_set_type(copy_test_octets, uint8_t); - TEST_CASE("Copy content of 'sample_octets' to attribute value using fr_pair_value_memdup_buffer_shallow()"); - TEST_CHECK(fr_pair_value_memdup_buffer_shallow(vp, copy_sample_octets, true) == 0); + TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_buffer_shallow()"); + TEST_CHECK(fr_pair_value_memdup_buffer_shallow(vp, copy_test_octets, true) == 0); - TEST_CASE("Check (vp->vp_octets == copy_sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check (vp->vp_octets == copy_test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - talloc_free(copy_sample_octets); + talloc_free(copy_test_octets); } static void test_fr_pair_value_mem_append(void) @@ -1134,53 +1021,53 @@ static void test_fr_pair_value_mem_append(void) fr_pair_t *vp; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - TEST_CASE("Copy content of 'sample_octets' to attribute value using fr_pair_value_memdup()"); - TEST_CHECK(fr_pair_value_memdup(vp, sample_octets, ARRAY_SIZE(sample_octets), false) == 0); + TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup()"); + TEST_CHECK(fr_pair_value_memdup(vp, test_octets, NUM_ELEMENTS(test_octets), false) == 0); - TEST_CASE("Append the 'sample_octets' value using fr_pair_value_mem_append()"); - TEST_CHECK(fr_pair_value_mem_append(vp, sample_octets, ARRAY_SIZE(sample_octets), true) == 0); + TEST_CASE("Append the 'test_octets' value using fr_pair_value_mem_append()"); + TEST_CHECK(fr_pair_value_mem_append(vp, test_octets, NUM_ELEMENTS(test_octets), true) == 0); // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check 1. part (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - TEST_CASE("Check 2. part ((vp->vp_string+ARRAY_SIZE(sample_octets)) == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets+ARRAY_SIZE(sample_octets), sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check 2. part ((vp->vp_string+NUM_ELEMENTS(test_octets)) == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) == 0); } static void test_fr_pair_value_mem_append_buffer(void) { fr_pair_t *vp; - uint8_t *copy_sample_octets; + uint8_t *copy_test_octets; TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_octets)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_octets)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); - copy_sample_octets = talloc_memdup(vp, sample_octets, ARRAY_SIZE(sample_octets)); - talloc_set_type(copy_sample_octets, uint8_t); + copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets)); + talloc_set_type(copy_test_octets, uint8_t); - TEST_CASE("Copy content of 'copy_sample_octets' to attribute value using fr_pair_value_memdup()"); - TEST_CHECK(fr_pair_value_memdup(vp, copy_sample_octets, ARRAY_SIZE(sample_octets), false) == 0); + TEST_CASE("Copy content of 'copy_test_octets' to attribute value using fr_pair_value_memdup()"); + TEST_CHECK(fr_pair_value_memdup(vp, copy_test_octets, NUM_ELEMENTS(test_octets), false) == 0); - TEST_CASE("Append the 'copy_sample_octets' value using fr_pair_value_mem_append_buffer()"); - TEST_CHECK(fr_pair_value_mem_append_buffer(vp, copy_sample_octets, true) == 0); + TEST_CASE("Append the 'copy_test_octets' value using fr_pair_value_mem_append_buffer()"); + TEST_CHECK(fr_pair_value_mem_append_buffer(vp, copy_test_octets, true) == 0); // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_octets == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check 1. part (vp->vp_octets == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - TEST_CASE("Check 2. part ((vp->vp_string+ARRAY_SIZE(sample_octets)) == sample_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets+ARRAY_SIZE(sample_octets), sample_octets, ARRAY_SIZE(sample_octets)) == 0); + TEST_CASE("Check 2. part ((vp->vp_string+NUM_ELEMENTS(test_octets)) == test_octets)"); + TEST_CHECK(vp && memcmp(vp->vp_octets+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) == 0); - talloc_free(copy_sample_octets); + talloc_free(copy_test_octets); } static void test_fr_pair_value_enum(void) @@ -1190,7 +1077,7 @@ static void test_fr_pair_value_enum(void) char buf[20]; TEST_CASE("Find 'Test-Values'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_values)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_enum)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp); @@ -1202,8 +1089,8 @@ static void test_fr_pair_value_enum(void) TEST_CHECK((var = fr_pair_value_enum(vp, buf)) != NULL); TEST_MSG("Checking fr_pair_value_enum()"); - TEST_CHECK(var && strcmp(var, "Tapioca123") == 0); - TEST_MSG("Expected var == 'Tapioca123'"); + TEST_CHECK(var && strcmp(var, "test123") == 0); + TEST_MSG("Expected var == 'test123'"); } static void test_fr_pair_value_enum_box(void) @@ -1212,7 +1099,7 @@ static void test_fr_pair_value_enum_box(void) fr_value_box_t const *vb; TEST_CASE("Find 'Test-Values'"); - TEST_CHECK((vp = fr_pair_find_by_da(&sample_pairs, attr_test_values)) != NULL); + TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, fr_dict_attr_test_enum)) != NULL); TEST_CASE("Validating VP_VERIFY()"); VP_VERIFY(vp);