static TALLOC_CTX *autofree;
static fr_dict_t *test_dict;
+DIAG_OFF(declaration-after-statement)
/** Global initialisation
*/
* be other top level attributes.
*/
+typedef struct {
+ fr_dcursor_t cursor;
+ tmpl_dcursor_ctx_t cc;
+ int err;
+ tmpl_t *vpt;
+ fr_pair_t *vp;
+} tmpl_dcursor_vars_t;
+
+#define test_cursor() &vars.cursor
+#define test_vp() vars.vp
+#define test_vp_p() &vars.vp
+#define test_vp_set(_vp) vars.vp = _vp
+
/*
* Variables used in all tests
*/
#define common_vars \
- request_t *request = request_fake_alloc(); \
- fr_dcursor_t cursor; \
- tmpl_dcursor_ctx_t cc; \
- int err; \
- tmpl_t *vpt; \
- fr_pair_t *vp
+ tmpl_dcursor_vars_t vars; \
+ request_t *request = request_fake_alloc();
/** Initialise a tmpl using the _attr_str string, and return the first pair
*
- * @param[out] _out The first pair found.
- * @param[in] _attr_str Attribute reference string.
+ * @param[in,out] vars test variables
+ * @param[in] request the current request.
+ * @param[in] ref Attribute reference string.
*/
-#define tmpl_setup_and_cursor_init(_out, _attr_str) \
-do { \
- char const *ref = _attr_str; \
- tmpl_afrom_attr_substr(autofree, NULL, &vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){.attr = {.dict_def = test_dict}}); \
- TEST_CHECK(vpt != NULL); \
- TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror()); \
- *(_out) = tmpl_dcursor_init(&err, NULL, &cc, &cursor, request, vpt); \
-} while (0)
-
-/** Initialise a tmpl using the _attr_str string, and build out the first pair
+static inline CC_HINT(always_inline)
+int _tmpl_setup_and_cursor_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, request_t *request, char const *ref)
+{
+ tmpl_afrom_attr_substr(autofree, NULL, &vars->vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){.attr = {.dict_def = test_dict}});
+ TEST_CHECK(vars->vpt!= NULL);
+ TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror());
+ if (!vars->vpt) {
+ *vp_out = NULL;
+ return -1;
+ }
+
+ *vp_out = tmpl_dcursor_init(&vars->err, NULL, &vars->cc, &vars->cursor, request, vars->vpt);
+ return 0;
+}
+
+#define tmpl_setup_and_cursor_init(_vp_out, _ref) \
+ if (_tmpl_setup_and_cursor_init(_vp_out, &vars, request, _ref)) return;
+
+/** Initialise a tmpl using the _attr_str string, and return the first pair
*
- * @param[out] _out The first pair allocated.
- * @param[in] _attr_str Attribute reference string.
+ * @param[in,out] vars test variables
+ * @param[in] request the current request.
+ * @param[in] ref Attribute reference string.
*/
-#define tmpl_setup_and_cursor_build_init(_out, _attr_str) \
-do { \
- char const *ref = _attr_str; \
- tmpl_afrom_attr_substr(autofree, NULL, &vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){.attr = {.dict_def = test_dict}}); \
- *(_out) = tmpl_dcursor_build_init(&err, autofree, &cc, &cursor, request, vpt, &tmpl_dcursor_pair_build, NULL); \
-} while (0)
+static inline CC_HINT(always_inline)
+int _tmpl_setup_and_cursor_build_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, request_t *request, char const *ref)
+{
+ tmpl_afrom_attr_substr(autofree, NULL, &vars->vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){.attr = {.dict_def = test_dict}});
+ TEST_CHECK(vars->vpt!= NULL);
+ TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror());
+ if (!vars->vpt) {
+ *vp_out = NULL;
+ return -1;
+ }
+
+ *vp_out = tmpl_dcursor_build_init(&vars->err, autofree, &vars->cc, &vars->cursor, request, vars->vpt, &tmpl_dcursor_pair_build, NULL);
+ return 0;
+}
+
+#define tmpl_setup_and_cursor_build_init(_vp_out, _ref) \
+ if (_tmpl_setup_and_cursor_build_init(_vp_out, &vars, request, _ref)) return;
/*
* How every test ends
*/
#define test_end \
debug_attr_list(&request->request_pairs, 0); \
- vp = fr_dcursor_next(&cursor); \
- TEST_CHECK_PAIR(vp, NULL); \
+ vars.vp = fr_dcursor_next(test_cursor()); \
+ TEST_CHECK_PAIR(vars.vp, NULL); \
TEST_MSG("Cursor should've been empty (i.e. returned NULL) at end of test"); \
- tmpl_dcursor_clear(&cc); \
- TEST_CHECK_RET(talloc_free(vpt), 0); \
+ tmpl_dcursor_clear(&vars.cc); \
+ TEST_CHECK_RET(talloc_free(vars.vpt), 0); \
TEST_CHECK_RET(talloc_free(request), 0)
/*
*/
#define build_test_end \
debug_attr_list(&request->request_pairs, 0); \
- vp = fr_dcursor_next(&cursor); \
- TEST_CHECK_PAIR(vp, NULL); \
- tmpl_dcursor_clear(&cc)
+ test_vp_set(fr_dcursor_next(test_cursor())); \
+ TEST_CHECK_PAIR(test_vp(), NULL); \
+ tmpl_dcursor_clear(&vars.cc)
static void debug_attr_list(fr_pair_list_t *list, int indent)
{
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0");
- TEST_CHECK_PAIR(vp, int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0");
+ TEST_CHECK_PAIR(test_vp(), int32_vp1);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[1]");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[1]");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[*]");
- TEST_CHECK_PAIR(vp, int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[*]");
+ TEST_CHECK_PAIR(test_vp(), int32_vp1);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int16-0");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[n]");
- TEST_CHECK_PAIR(vp, int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[n]");
+ TEST_CHECK_PAIR(test_vp(), int32_vp1);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0");
- TEST_CHECK_PAIR(vp, int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0");
+ TEST_CHECK_PAIR(test_vp(), int32_vp1);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[1]");
- TEST_CHECK_PAIR(vp, int32_vp2);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[1]");
+ TEST_CHECK_PAIR(test_vp(), int32_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[2]");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[2]");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[*]");
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[*]");
- TEST_CHECK_PAIR(vp, int32_vp1);
+ TEST_CHECK_PAIR(test_vp(), int32_vp1);
- vp = fr_dcursor_next(&cursor);
- TEST_CHECK_PAIR(vp, int32_vp2);
+ test_vp_set(fr_dcursor_next(test_cursor()));
+ TEST_CHECK_PAIR(test_vp(), int32_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[n]");
- TEST_CHECK_PAIR(vp, int32_vp2);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[n]");
+ TEST_CHECK_PAIR(test_vp(), int32_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Int32-0[#]");
- TEST_CHECK_PAIR(vp, int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int32-0[#]");
+ TEST_CHECK_PAIR(test_vp(), int32_vp1);
- vp = fr_dcursor_next(&cursor);
- TEST_CHECK_PAIR(vp, int32_vp2);
+ test_vp_set(fr_dcursor_next(test_cursor()));
+ TEST_CHECK_PAIR(test_vp(), int32_vp2);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int16-0");
- TEST_CHECK_PAIR(vp, child_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), child_vp1);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int16-0[1]");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int16-0[1]");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int16-0[*]");
- TEST_CHECK_PAIR(vp, child_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int16-0[*]");
+ TEST_CHECK_PAIR(test_vp(), child_vp1);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int32-0");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int32-0");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int16-0");
- TEST_CHECK_PAIR(vp, child_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), child_vp1);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0[1].Test-Int16-0");
- TEST_CHECK_PAIR(vp, child_vp2);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0[1].Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), child_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0[*].Test-Int16-0");
- TEST_CHECK_PAIR(vp, child_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0[*].Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), child_vp1);
- vp = fr_dcursor_next(&cursor);
- TEST_CHECK_PAIR(vp, child_vp2);
+ test_vp_set(fr_dcursor_next(test_cursor()));
+ TEST_CHECK_PAIR(test_vp(), child_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0[n].Test-Int16-0");
- TEST_CHECK_PAIR(vp, child_vp2);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0[n].Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), child_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0[*].Test-Int32-0");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0[*].Test-Int32-0");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[0].Child-TLV[0].Leaf-String");
- TEST_CHECK_PAIR(vp, leaf_string_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[0].Child-TLV[0].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), leaf_string_vp1);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[0].Child-TLV[1].Leaf-String");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[0].Child-TLV[1].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
pair_defs(1);
pair_populate(1);
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[0].Child-TLV[*].Leaf-String");
- TEST_CHECK_PAIR(vp, leaf_string_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[0].Child-TLV[*].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), leaf_string_vp1);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[0].Child-TLV[0].Leaf-Int32");
- TEST_CHECK_PAIR(vp, leaf_int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[0].Child-TLV[0].Leaf-Int32");
+ TEST_CHECK_PAIR(test_vp(), leaf_int32_vp1);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[*].Child-TLV[*].Leaf-Int32");
- TEST_CHECK_PAIR(vp, leaf_int32_vp1);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[*].Child-TLV[*].Leaf-Int32");
+ TEST_CHECK_PAIR(test_vp(), leaf_int32_vp1);
- vp = fr_dcursor_next(&cursor);
- TEST_CHECK_PAIR(vp, leaf_int32_vp2);
+ test_vp_set(fr_dcursor_next(test_cursor()));
+ TEST_CHECK_PAIR(test_vp(), leaf_int32_vp2);
test_end;
}
pair_populate(1);
pair_populate(2);
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[n].Child-TLV[n].Leaf-Int32[n]");
- TEST_CHECK_PAIR(vp, leaf_int32_vp2);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[n].Child-TLV[n].Leaf-Int32[n]");
+ TEST_CHECK_PAIR(test_vp(), leaf_int32_vp2);
test_end;
}
TEST_CHECK_PAIR_NEQ(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Int16-0");
- TEST_CHECK_PAIR(vp, inserted);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), inserted);
test_end;
}
TEST_CHECK_PAIR_NEQ(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int32-0");
- TEST_CHECK_PAIR(vp, inserted);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int32-0");
+ TEST_CHECK_PAIR(test_vp(), inserted);
test_end;
}
TEST_CHECK_PAIR_NEQ(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Int16-0");
- TEST_CHECK_PAIR(vp, inserted);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Int16-0");
+ TEST_CHECK_PAIR(test_vp(), inserted);
test_end;
}
tmpl_setup_and_cursor_build_init(&inserted, "&Test-Group-0[*].Test-Int32-0");
TEST_CHECK_PAIR_NEQ(inserted, NULL);
- second = fr_dcursor_next(&cursor);
+ second = fr_dcursor_next(test_cursor());
TEST_CHECK_PAIR_NEQ(second, NULL);
TEST_CHECK_PAIR_NEQ(second, inserted);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0[*].Test-Int32-0");
- TEST_CHECK_PAIR(vp, inserted);
- vp = fr_dcursor_next(&cursor);
- TEST_CHECK_PAIR(vp, second);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0[*].Test-Int32-0");
+ TEST_CHECK_PAIR(test_vp(), inserted);
+ test_vp_set(fr_dcursor_next(test_cursor()));
+ TEST_CHECK_PAIR(test_vp(), second);
test_end;
}
TEST_CHECK_PAIR_NEQ(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Group-0.Test-Group-0.Test-String-0");
- TEST_CHECK_PAIR(vp, inserted);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Group-0.Test-Group-0.Test-String-0");
+ TEST_CHECK_PAIR(test_vp(), inserted);
test_end;
}
TEST_CHECK_PAIR_NEQ(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[0].Child-TLV[0].Leaf-String");
- TEST_CHECK_PAIR(vp, inserted);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[0].Child-TLV[0].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), inserted);
test_end;
}
TEST_CHECK_PAIR_NEQ(inserted, leaf_string_vp1);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[1].Child-TLV[0].Leaf-String");
- TEST_CHECK_PAIR(vp, inserted);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[1].Child-TLV[0].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), inserted);
test_end;
}
TEST_CHECK_PAIR(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[3].Child-TLV[0].Leaf-String");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[3].Child-TLV[0].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
TEST_CHECK_PAIR(inserted, NULL);
build_test_end;
- tmpl_setup_and_cursor_init(&vp, "&Test-Nested-Top-TLV-0[*].Child-TLV[0].Leaf-String");
- TEST_CHECK_PAIR(vp, NULL);
+ tmpl_setup_and_cursor_init(test_vp_p(), "&Test-Nested-Top-TLV-0[*].Child-TLV[0].Leaf-String");
+ TEST_CHECK_PAIR(test_vp(), NULL);
test_end;
}
{ NULL }
};
+
+DIAG_ON(declaration-after-statement)