Skip to content

Commit

Permalink
start to bring up testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh352 committed Feb 15, 2025
1 parent 8b34ca4 commit 9ec90c3
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions tests/utests/schema/test_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,113 @@ test_lysc_path(void **state)
free(path);
}

static void
test_lysc_backlinks(void **state)
{
const char *expect1[] = {
"/b:my_extref_list/my_extref",
"/a:refstr",
"/a:refnum",
"/b:my_extref_list/my_extref_union",
NULL
};
const char *expect2[] = {
"/b:my_extref_list/my_extref",
"/a:refstr",
"/b:my_extref_list/my_extref_union",
NULL
};
const char *expect3[] = {
"/b:my_extref_list/my_extref",
"/a:refstr",
"/a:refnum",
"/b:my_extref_list/my_extref_union",
NULL
};
struct {
const char *match_path;
ly_bool match_ancestors;
const char **expected_paths;
} tests[] = {
{ NULL, 0, expect1 },
{ "/a:my_list/my_leaf_string", 0, expect2 },
{ "/a:my_list/", 1, expect3 }
};
const char *str;
size_t i;

str = "module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" list my_list {\n"
" key my_leaf_string;\n"
" leaf my_leaf_string {\n"
" type string;\n"
" }\n"
" leaf my_leaf_number {\n"
" type uint32;\n"
" }\n"
" }\n"
" leaf refstr {\n"
" type leafref {\n"
" path \"../my_list/my_leaf_string\";\n"
" }\n"
" }\n"
" leaf refnum {\n"
" type leafref {\n"
" path \"../my_list/my_leaf_number\";\n"
" }\n"
" }\n"
"}\n";

assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
CHECK_LOG_CTX(NULL, NULL, 0);

str = "module b {\n"
" urn:b;\n"
" import a {\n"
" prefix a;\n"
" }\n"
" list my_extref_list {\n"
" key my_leaf_string;\n"
" leaf my_leaf_string {\n"
" type string;\n"
" }\n"
" leaf my_extref {\n"
" type leafref {\n"
" path \"/a:my_list/a:my_leaf_string\";\n"
" }\n"
" }\n"
" leaf my_extref_union {\n"
" type union {\n"
" type leafref {\n"
" path \"/a:my_list/a:my_leaf_string\";\n"
" }\n"
" type leafref {\n"
" path \"/a:my_list/a:my_leaf_number\";\n"
" }\n"
" type uint32;\n"
" }\n"
" }\n"
"}\n";
assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
CHECK_LOG_CTX(NULL, NULL, 0);

for (i=0; i<sizeof(tests)/sizeof(*tests); i++) {
const struct lysc_node *node = NULL;
struct ly_set *set = NULL;

if (tests[i].match_path) {
assert_non_null(lys_find_path(UTEST_LYCTX, NULL, tests[i].match_path, 0));
}

assert_int_equal(lys_find_backlinks(UTEST_LYCTX, node, tests[i].match_ancestors, &set), LY_SUCCESS);

/* XXX: Match paths */
ly_set_free(set, NULL);
}
}

int
main(void)
{
Expand All @@ -1909,6 +2016,7 @@ main(void)
UTEST(test_extension_compile),
UTEST(test_ext_recursive),
UTEST(test_lysc_path),
UTEST(test_lysc_backlinks)
};

return cmocka_run_group_tests(tests, NULL, NULL);
Expand Down

0 comments on commit 9ec90c3

Please sign in to comment.