From 9ec90c37d4e8ed4b1964b37f2093aa6ff3d7469c Mon Sep 17 00:00:00 2001 From: Brad House Date: Sat, 15 Feb 2025 11:29:52 -0500 Subject: [PATCH] start to bring up testing --- tests/utests/schema/test_schema.c | 108 ++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c index cba2b2d45..5e542a920 100644 --- a/tests/utests/schema/test_schema.c +++ b/tests/utests/schema/test_schema.c @@ -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