Merging upstream version 3.12.2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
6375ddbe5b
commit
580fa3f55c
66 changed files with 4041 additions and 2142 deletions
|
@ -276,10 +276,32 @@ test_options(void **state)
|
|||
}
|
||||
|
||||
static LY_ERR
|
||||
test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
|
||||
const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
|
||||
const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
|
||||
test_imp_clb(const char *mod_name, const char *UNUSED(mod_rev), const char *submod_name, const char *UNUSED(sub_rev),
|
||||
void *user_data, LYS_INFORMAT *format, const char **module_data, void (**free_module_data)(void *model_data,
|
||||
void *user_data))
|
||||
{
|
||||
const char *name;
|
||||
|
||||
if (submod_name) {
|
||||
if (strncmp(user_data, "submodule", 9)) {
|
||||
return LY_ENOTFOUND;
|
||||
}
|
||||
|
||||
name = ((char *)user_data) + 10;
|
||||
if (strncmp(name, submod_name, strlen(submod_name)) || (name[strlen(submod_name)] != ' ')) {
|
||||
return LY_ENOTFOUND;
|
||||
}
|
||||
} else {
|
||||
if (strncmp(user_data, "module", 6)) {
|
||||
return LY_ENOTFOUND;
|
||||
}
|
||||
|
||||
name = ((char *)user_data) + 7;
|
||||
if (strncmp(name, mod_name, strlen(mod_name)) || (name[strlen(mod_name)] != ' ')) {
|
||||
return LY_ENOTFOUND;
|
||||
}
|
||||
}
|
||||
|
||||
*module_data = user_data;
|
||||
*format = LYS_IN_YANG;
|
||||
*free_module_data = NULL;
|
||||
|
@ -305,7 +327,7 @@ test_models(void **state)
|
|||
assert_int_equal(UTEST_LYCTX->change_count, ly_ctx_get_change_count(UTEST_LYCTX));
|
||||
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
|
||||
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, 4, NULL, NULL, &unres.creating, &mod1));
|
||||
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, 4, NULL, &unres.creating, &mod1));
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
CHECK_LOG_CTX("Invalid schema input format.", NULL, 0);
|
||||
|
@ -324,17 +346,17 @@ test_models(void **state)
|
|||
/* name collision of module and submodule */
|
||||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-30;}");
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;include y;}", &in));
|
||||
assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
|
||||
assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod1));
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
CHECK_LOG_CTX("Parsing module \"y\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Name collision between module and submodule of name \"y\".", NULL, 1);
|
||||
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", &in));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod1));
|
||||
ly_in_free(in, 0);
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
|
||||
assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
|
||||
assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod1));
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
CHECK_LOG_CTX("Parsing module \"y\" failed.", NULL, 0);
|
||||
|
@ -342,19 +364,18 @@ test_models(void **state)
|
|||
|
||||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule y {belongs-to b {prefix b;}}");
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module b {namespace urn:b;prefix b;include y;}", &in));
|
||||
assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
|
||||
assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod1));
|
||||
lys_unres_glob_revert(UTEST_LYCTX, &unres);
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
CHECK_LOG_CTX("Parsing module \"b\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Including \"y\" submodule into \"b\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing submodule failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing submodule \"y\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Name collision between submodules of name \"y\".", NULL, 1);
|
||||
|
||||
/* selecting correct revision of the submodules */
|
||||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-31;}");
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", &in));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod2));
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
assert_string_equal("2018-10-31", mod2->parsed->includes[0].submodule->revs[0].date);
|
||||
|
@ -490,17 +511,17 @@ test_get_models(void **state)
|
|||
/* select module by revision */
|
||||
assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, &mod));
|
||||
/* invalid attempts - implementing module of the same name and inserting the same module */
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, &unres.creating, &mod2));
|
||||
assert_int_equal(LY_EDENIED, lys_implement(mod2, NULL, &unres));
|
||||
CHECK_LOG_CTX("Module \"a@2018-10-24\" is already implemented in revision \"2018-10-23\".", NULL, 0);
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_reset(in1);
|
||||
/* it is already there, fine */
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres.creating, NULL));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, &unres.creating, NULL));
|
||||
/* insert the second module only as imported, not implemented */
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_reset(in2);
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, &unres.creating, &mod2));
|
||||
lys_unres_glob_erase(&unres);
|
||||
assert_non_null(mod2);
|
||||
assert_ptr_not_equal(mod, mod2);
|
||||
|
@ -509,7 +530,7 @@ test_get_models(void **state)
|
|||
mod2 = ly_ctx_get_module_latest_ns(UTEST_LYCTX, mod->ns);
|
||||
assert_ptr_equal(mod, mod2);
|
||||
/* work with module with no revision */
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in0, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in0, LYS_IN_YANG, NULL, &unres.creating, &mod));
|
||||
lys_unres_glob_erase(&unres);
|
||||
assert_ptr_equal(mod, ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
|
||||
assert_ptr_not_equal(mod, ly_ctx_get_module_latest(UTEST_LYCTX, "a"));
|
||||
|
@ -517,7 +538,7 @@ test_get_models(void **state)
|
|||
str1 = "submodule b {belongs-to a {prefix a;}}";
|
||||
ly_in_free(in1, 0);
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
|
||||
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
|
||||
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, &unres.creating, &mod));
|
||||
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL, 0);
|
||||
lys_unres_glob_erase(&unres);
|
||||
|
||||
|
@ -540,7 +561,7 @@ test_ylmem(void **state)
|
|||
" <name>complete</name>\n"\
|
||||
" <module>\n"\
|
||||
" <name>yang</name>\n"\
|
||||
" <revision>2022-06-16</revision>\n"\
|
||||
" <revision>2025-01-29</revision>\n"\
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"\
|
||||
" </module>\n"\
|
||||
" <module>\n"\
|
||||
|
@ -587,7 +608,7 @@ test_ylmem(void **state)
|
|||
" </module>\n"\
|
||||
" <module>\n"\
|
||||
" <name>yang</name>\n"\
|
||||
" <revision>2022-06-16</revision>\n"\
|
||||
" <revision>2025-01-29</revision>\n"\
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"\
|
||||
" <conformance-type>implement</conformance-type>\n"\
|
||||
" </module>\n"\
|
||||
|
@ -740,7 +761,7 @@ test_ylmem(void **state)
|
|||
" <name>complete</name>\n"
|
||||
" <module>\n"
|
||||
" <name>yang</name>\n"
|
||||
" <revision>2022-06-16</revision>\n"
|
||||
" <revision>2025-01-29</revision>\n"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"
|
||||
" </module>\n"
|
||||
DATA_YANG_BASE_IMPORTS
|
||||
|
@ -978,7 +999,7 @@ test_set_priv_parsed(void **state)
|
|||
ly_ctx_destroy(UTEST_LYCTX);
|
||||
const char *feats[] = {"f1", NULL};
|
||||
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_SET_PRIV_PARSED, &UTEST_LYCTX));
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD | LY_CTX_SET_PRIV_PARSED, &UTEST_LYCTX));
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
|
||||
assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-restconf", "2017-01-26", NULL));
|
||||
UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, feats, NULL);
|
||||
|
@ -1054,7 +1075,7 @@ test_explicit_compile(void **state)
|
|||
ly_ctx_destroy(UTEST_LYCTX);
|
||||
const char *feats[] = {"f1", NULL};
|
||||
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_EXPLICIT_COMPILE, &UTEST_LYCTX));
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD | LY_CTX_EXPLICIT_COMPILE, &UTEST_LYCTX));
|
||||
UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, NULL, &mod);
|
||||
UTEST_ADD_MODULE(schema_b, LYS_IN_YANG, NULL, NULL);
|
||||
UTEST_ADD_MODULE(schema_c, LYS_IN_YANG, NULL, NULL);
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
#define CHECK_LYD_STRING(INPUT, TEXT) \
|
||||
CHECK_LYD_STRING_PARAM(INPUT, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS)
|
||||
|
||||
#define CHECK_PARSE_LYD_DIFF(INPUT_1, INPUT_2, OUT_DIFF) \
|
||||
assert_int_equal(LY_SUCCESS, lyd_diff_siblings(INPUT_1, INPUT_2, 0, &OUT_DIFF));\
|
||||
#define CHECK_PARSE_LYD_DIFF(INPUT_1, INPUT_2, OPTS, OUT_DIFF) \
|
||||
assert_int_equal(LY_SUCCESS, lyd_diff_siblings(INPUT_1, INPUT_2, OPTS, &OUT_DIFF));\
|
||||
assert_non_null(OUT_DIFF)
|
||||
|
||||
#define TEST_DIFF_3(XML1, XML2, XML3, DIFF1, DIFF2, MERGE) \
|
||||
#define TEST_DIFF_3(XML1, XML2, XML3, OPTS, DIFF1, DIFF2, MERGE) \
|
||||
{ \
|
||||
struct lyd_node *data1;\
|
||||
struct lyd_node *data2;\
|
||||
|
@ -38,13 +38,13 @@
|
|||
CHECK_PARSE_LYD(XML3, data3);\
|
||||
/* diff1 */ \
|
||||
struct lyd_node *diff1;\
|
||||
CHECK_PARSE_LYD_DIFF(data1, data2, diff1); \
|
||||
CHECK_PARSE_LYD_DIFF(data1, data2, OPTS, diff1); \
|
||||
CHECK_LYD_STRING(diff1, DIFF1); \
|
||||
assert_int_equal(lyd_diff_apply_all(&data1, diff1), LY_SUCCESS); \
|
||||
CHECK_LYD(data1, data2); \
|
||||
/* diff2 */ \
|
||||
struct lyd_node *diff2;\
|
||||
CHECK_PARSE_LYD_DIFF(data2, data3, diff2); \
|
||||
CHECK_PARSE_LYD_DIFF(data2, data3, OPTS, diff2); \
|
||||
CHECK_LYD_STRING(diff2, DIFF2); \
|
||||
assert_int_equal(lyd_diff_apply_all(&data2, diff2), LY_SUCCESS);\
|
||||
CHECK_LYD(data2, data3);\
|
||||
|
@ -59,248 +59,104 @@
|
|||
lyd_free_all(diff2);\
|
||||
}
|
||||
|
||||
const char *schema1 =
|
||||
"module defaults {\n"
|
||||
" yang-version 1.1;\n"
|
||||
" namespace \"urn:libyang:tests:defaults\";\n"
|
||||
" prefix df;\n"
|
||||
const char *schema =
|
||||
"module defaults {"
|
||||
"yang-version 1.1;"
|
||||
"namespace \"urn:libyang:tests:defaults\";"
|
||||
"prefix df;"
|
||||
""
|
||||
" feature unhide;\n"
|
||||
"import ietf-yang-metadata {prefix md;}"
|
||||
""
|
||||
" typedef defint32 {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
"feature unhide;"
|
||||
""
|
||||
" leaf hiddenleaf {\n"
|
||||
" if-feature \"unhide\";\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
"md:annotation my-meta {type string;}"
|
||||
"md:annotation my-meta2 {type string;}"
|
||||
""
|
||||
" container df {\n"
|
||||
" leaf foo {\n"
|
||||
" type defint32;\n"
|
||||
" }\n"
|
||||
"typedef defint32 {type int32; default \"42\";}"
|
||||
""
|
||||
" leaf hiddenleaf {\n"
|
||||
" if-feature \"unhide\";\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" container bar {\n"
|
||||
" presence \"\";\n"
|
||||
" leaf hi {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf ho {\n"
|
||||
" type int32;\n"
|
||||
" mandatory true;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf-list llist {\n"
|
||||
" type defint32;\n"
|
||||
" ordered-by user;\n"
|
||||
" }\n"
|
||||
""
|
||||
" list ul {\n"
|
||||
" key \"l1\";\n"
|
||||
" ordered-by user;\n"
|
||||
" leaf l1 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf l2 {\n"
|
||||
" type int32;\n"
|
||||
" }\n"
|
||||
""
|
||||
" container cont {\n"
|
||||
" leaf l3 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf-list dllist {\n"
|
||||
" type uint8;\n"
|
||||
" default \"1\";\n"
|
||||
" default \"2\";\n"
|
||||
" default \"3\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" list list {\n"
|
||||
" key \"name\";\n"
|
||||
" leaf name {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf value {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
" list list2 {\n"
|
||||
" key \"name2\";\n"
|
||||
" leaf name2 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
" leaf value2 {\n"
|
||||
" type int32;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n";
|
||||
const char *schema2 =
|
||||
" choice select {\n"
|
||||
" default \"a\";\n"
|
||||
" case a {\n"
|
||||
" choice a {\n"
|
||||
" leaf a1 {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf a2 {\n"
|
||||
" type int32;\n"
|
||||
" default \"24\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf b {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
""
|
||||
" container c {\n"
|
||||
" presence \"\";\n"
|
||||
" leaf x {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" choice select2 {\n"
|
||||
" default \"s2b\";\n"
|
||||
" leaf s2a {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" case s2b {\n"
|
||||
" choice s2b {\n"
|
||||
" default \"b1\";\n"
|
||||
" case b1 {\n"
|
||||
" leaf b1_1 {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf b1_2 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf b1_status {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" config false;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf b2 {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" list kl {\n"
|
||||
" config \"false\";\n"
|
||||
" leaf l1 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf l2 {\n"
|
||||
" type int32;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf-list kll {\n"
|
||||
" config \"false\";\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" container hidden {\n"
|
||||
" leaf foo {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf baz {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf papa {\n"
|
||||
" type int32;\n"
|
||||
" default \"42\";\n"
|
||||
" config false;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" rpc rpc1 {\n"
|
||||
" input {\n"
|
||||
" leaf inleaf1 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf inleaf2 {\n"
|
||||
" type string;\n"
|
||||
" default \"def1\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" output {\n"
|
||||
" leaf outleaf1 {\n"
|
||||
" type string;\n"
|
||||
" default \"def2\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf outleaf2 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
""
|
||||
" notification notif {\n"
|
||||
" leaf ntfleaf1 {\n"
|
||||
" type string;\n"
|
||||
" default \"def3\";\n"
|
||||
" }\n"
|
||||
""
|
||||
" leaf ntfleaf2 {\n"
|
||||
" type string;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
"leaf hiddenleaf {if-feature \"unhide\"; type int32; default \"42\";}"
|
||||
"container df {"
|
||||
" leaf foo {type defint32; }"
|
||||
" leaf hiddenleaf {if-feature \"unhide\"; type int32; default \"42\";}"
|
||||
" container bar { presence \"\";"
|
||||
" leaf hi {type int32; default \"42\";}"
|
||||
" leaf ho {type int32; mandatory true;}"
|
||||
" }"
|
||||
" leaf-list llist {type defint32; ordered-by user;}"
|
||||
" list ul {key \"l1\"; ordered-by user;"
|
||||
" leaf l1 {type string;}"
|
||||
" leaf l2 {type int32;}"
|
||||
" container cont {"
|
||||
" leaf l3 {type string;}"
|
||||
" }"
|
||||
" }"
|
||||
" leaf-list dllist {type uint8; default \"1\"; default \"2\"; default \"3\";}"
|
||||
" list list {key \"name\";"
|
||||
" leaf name {type string;}"
|
||||
" leaf value {type int32; default \"42\";}"
|
||||
" list list2 {key \"name2\";"
|
||||
" leaf name2 {type string;}"
|
||||
" leaf value2 {type int32;}"
|
||||
" }"
|
||||
" }"
|
||||
" choice select {default \"a\";"
|
||||
" case a {"
|
||||
" choice a {"
|
||||
" leaf a1 {type int32; default \"42\";}"
|
||||
" leaf a2 {type int32; default \"24\";}"
|
||||
" }"
|
||||
" }"
|
||||
" leaf b {type string;}"
|
||||
" container c {presence \"\";"
|
||||
" leaf x {type int32; default \"42\";}"
|
||||
" }"
|
||||
" }"
|
||||
" choice select2 {default \"s2b\";"
|
||||
" leaf s2a {type int32; default \"42\";}"
|
||||
" case s2b {"
|
||||
" choice s2b {default \"b1\";"
|
||||
" case b1 {"
|
||||
" leaf b1_1 {type int32; default \"42\";}"
|
||||
" leaf b1_2 {type string;}"
|
||||
" leaf b1_status {type int32; default \"42\"; config false;}"
|
||||
" }"
|
||||
" leaf b2 {type int32; default \"42\";}"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" list kl {config \"false\";"
|
||||
" leaf l1 {type string;}"
|
||||
" leaf l2 {type int32;}"
|
||||
" }"
|
||||
" leaf-list kll {config \"false\"; type string;}"
|
||||
"}"
|
||||
"container hidden {"
|
||||
" leaf foo {type int32; default \"42\";}"
|
||||
" leaf baz {type int32; default \"42\";}"
|
||||
" leaf papa {type int32; default \"42\"; config false;}"
|
||||
"}"
|
||||
"rpc rpc1 {"
|
||||
" input {"
|
||||
" leaf inleaf1 {type string;}"
|
||||
" leaf inleaf2 {type string; default \"def1\";}"
|
||||
" }"
|
||||
" output {"
|
||||
" leaf outleaf1 {type string; default \"def2\";}"
|
||||
" leaf outleaf2 {type string;}"
|
||||
" }"
|
||||
"}"
|
||||
"notification notif {"
|
||||
" leaf ntfleaf1 {type string; default \"def3\";}"
|
||||
" leaf ntfleaf2 {type string;}"
|
||||
"}"
|
||||
"}";
|
||||
|
||||
static int
|
||||
setup(void **state)
|
||||
{
|
||||
char *schema;
|
||||
|
||||
UTEST_SETUP;
|
||||
|
||||
/* create one schema, longer than 4095 chars */
|
||||
schema = malloc(strlen(schema1) + strlen(schema2) + 1);
|
||||
strcpy(schema, schema1);
|
||||
strcat(schema, schema2);
|
||||
|
||||
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
|
||||
free(schema);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -384,7 +240,7 @@ test_empty1(void **state)
|
|||
|
||||
struct lyd_node *diff;
|
||||
|
||||
CHECK_PARSE_LYD_DIFF(model_1, model_2, diff);
|
||||
CHECK_PARSE_LYD_DIFF(model_1, model_2, 0, diff);
|
||||
CHECK_LYD_STRING(diff,
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
|
||||
" <foo>42</foo>\n"
|
||||
|
@ -420,7 +276,7 @@ test_empty2(void **state)
|
|||
|
||||
struct lyd_node *diff;
|
||||
|
||||
CHECK_PARSE_LYD_DIFF(model_1, NULL, diff);
|
||||
CHECK_PARSE_LYD_DIFF(model_1, NULL, 0, diff);
|
||||
CHECK_LYD_STRING(diff,
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n"
|
||||
" <foo>42</foo>\n"
|
||||
|
@ -455,7 +311,7 @@ test_empty_nested(void **state)
|
|||
|
||||
struct lyd_node *diff1;
|
||||
|
||||
CHECK_PARSE_LYD_DIFF(NULL, lyd_child(model_1), diff1);
|
||||
CHECK_PARSE_LYD_DIFF(NULL, lyd_child(model_1), 0, diff1);
|
||||
CHECK_LYD_STRING(diff1,
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
|
||||
" <foo yang:operation=\"create\">42</foo>\n"
|
||||
|
@ -463,7 +319,7 @@ test_empty_nested(void **state)
|
|||
|
||||
struct lyd_node *diff2;
|
||||
|
||||
CHECK_PARSE_LYD_DIFF(lyd_child(model_1), NULL, diff2);
|
||||
CHECK_PARSE_LYD_DIFF(lyd_child(model_1), NULL, 0, diff2);
|
||||
CHECK_LYD_STRING(diff2,
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
|
||||
" <foo yang:operation=\"delete\">42</foo>\n"
|
||||
|
@ -565,7 +421,7 @@ test_leaf(void **state)
|
|||
" <baz yang:operation=\"delete\">42</baz>\n"
|
||||
"</hidden>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -641,7 +497,7 @@ test_list(void **state)
|
|||
" </list>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -713,7 +569,7 @@ test_nested_list(void **state)
|
|||
|
||||
CHECK_PARSE_LYD(xml1, data1);
|
||||
CHECK_PARSE_LYD(xml2, data2);
|
||||
CHECK_PARSE_LYD_DIFF(data1, data2, diff);
|
||||
CHECK_PARSE_LYD_DIFF(data1, data2, 0, diff);
|
||||
|
||||
CHECK_LYD_STRING(diff,
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
|
||||
|
@ -810,7 +666,7 @@ test_userord_llist(void **state)
|
|||
" <llist yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\" yang:operation=\"replace\">5</llist>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -856,7 +712,7 @@ test_userord_llist2(void **state)
|
|||
" <llist yang:orig-value=\"1\" yang:operation=\"delete\">2</llist>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -899,7 +755,7 @@ test_userord_mix(void **state)
|
|||
" <llist yang:value=\"1\" yang:operation=\"create\">4</llist>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -985,7 +841,7 @@ test_userord_list(void **state)
|
|||
" </ul>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1064,7 +920,7 @@ test_userord_list2(void **state)
|
|||
" </ul>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1176,7 +1032,7 @@ test_userord_list3(void **state)
|
|||
" </ul>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1302,7 +1158,7 @@ test_keyless_list(void **state)
|
|||
" </kl>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1349,7 +1205,7 @@ test_state_llist(void **state)
|
|||
" <kll yang:position=\"1\" yang:operation=\"create\">d</kll>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
|
||||
TEST_DIFF_3(xml1, xml2, xml3, 0, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1435,6 +1291,89 @@ test_wd(void **state)
|
|||
lyd_free_all(diff2);
|
||||
}
|
||||
|
||||
static void
|
||||
test_metadata(void **state)
|
||||
{
|
||||
(void) state;
|
||||
const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:df=\"urn:libyang:tests:defaults\">\n"
|
||||
" <list df:my-meta=\"val1\">\n"
|
||||
" <name>a</name>\n"
|
||||
" <value df:my-meta2=\"val2\">1</value>\n"
|
||||
" </list>\n"
|
||||
" <list>\n"
|
||||
" <name df:my-meta=\"val10\">b</name>\n"
|
||||
" <value df:my-meta=\"repeated\" df:my-meta=\"repeated\">2</value>\n"
|
||||
" </list>\n"
|
||||
"</df>\n";
|
||||
const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:df=\"urn:libyang:tests:defaults\">\n"
|
||||
" <list>\n"
|
||||
" <name>b</name>\n"
|
||||
" <value df:my-meta=\"repeated\">2</value>\n"
|
||||
" </list>\n"
|
||||
" <list>\n"
|
||||
" <name df:my-meta2=\"val22\">c</name>\n"
|
||||
" <value df:my-meta2=\"val23\">3</value>\n"
|
||||
" </list>\n"
|
||||
"</df>\n";
|
||||
const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:df=\"urn:libyang:tests:defaults\" df:my-meta=\"top\">\n"
|
||||
" <list>\n"
|
||||
" <name>b</name>\n"
|
||||
" <value df:my-meta=\"repeated\" df:my-meta=\"new\">2</value>\n"
|
||||
" </list>\n"
|
||||
" <list>\n"
|
||||
" <name df:my-meta=\"val22\">c</name>\n"
|
||||
" <value df:my-meta2=\"val23\">3</value>\n"
|
||||
" </list>\n"
|
||||
"</df>\n";
|
||||
|
||||
const char *out_diff_1 =
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
|
||||
" <list yang:operation=\"delete\" yang:meta-delete=\"defaults:my-meta=val1\">\n"
|
||||
" <name>a</name>\n"
|
||||
" <value yang:meta-delete=\"defaults:my-meta2=val2\">1</value>\n"
|
||||
" </list>\n"
|
||||
" <list>\n"
|
||||
" <name yang:meta-delete=\"defaults:my-meta=val10\">b</name>\n"
|
||||
" <value yang:orig-default=\"false\" yang:meta-delete=\"defaults:my-meta=repeated\">2</value>\n"
|
||||
" </list>\n"
|
||||
" <list yang:operation=\"create\">\n"
|
||||
" <name yang:meta-create=\"defaults:my-meta2=val22\">c</name>\n"
|
||||
" <value yang:meta-create=\"defaults:my-meta2=val23\">3</value>\n"
|
||||
" </list>\n"
|
||||
"</df>\n";
|
||||
const char *out_diff_2 =
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\" "
|
||||
"yang:meta-create=\"defaults:my-meta=top\">\n"
|
||||
" <list>\n"
|
||||
" <name>b</name>\n"
|
||||
" <value yang:orig-default=\"false\" yang:meta-create=\"defaults:my-meta=new\">2</value>\n"
|
||||
" </list>\n"
|
||||
" <list>\n"
|
||||
" <name yang:meta-delete=\"defaults:my-meta2=val22\" yang:meta-create=\"defaults:my-meta=val22\">c</name>\n"
|
||||
" <value yang:operation=\"none\">3</value>\n"
|
||||
" </list>\n"
|
||||
"</df>\n";
|
||||
const char *out_merge =
|
||||
"<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\" "
|
||||
"yang:meta-create=\"defaults:my-meta=top\">\n"
|
||||
" <list yang:operation=\"delete\" yang:meta-delete=\"defaults:my-meta=val1\">\n"
|
||||
" <name>a</name>\n"
|
||||
" <value yang:meta-delete=\"defaults:my-meta2=val2\">1</value>\n"
|
||||
" </list>\n"
|
||||
" <list>\n"
|
||||
" <name yang:meta-delete=\"defaults:my-meta=val10\">b</name>\n"
|
||||
" <value yang:orig-default=\"false\" yang:meta-delete=\"defaults:my-meta=repeated\" "
|
||||
"yang:meta-create=\"defaults:my-meta=new\">2</value>\n"
|
||||
" </list>\n"
|
||||
" <list yang:operation=\"create\">\n"
|
||||
" <name yang:meta-create=\"defaults:my-meta=val22\">c</name>\n"
|
||||
" <value yang:meta-create=\"defaults:my-meta2=val23\">3</value>\n"
|
||||
" </list>\n"
|
||||
"</df>\n";
|
||||
|
||||
TEST_DIFF_3(xml1, xml2, xml3, LYD_DIFF_META, out_diff_1, out_diff_2, out_merge);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
@ -1457,6 +1396,7 @@ main(void)
|
|||
UTEST(test_keyless_list, setup),
|
||||
UTEST(test_state_llist, setup),
|
||||
UTEST(test_wd, setup),
|
||||
UTEST(test_metadata, setup),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
|
|
@ -279,7 +279,7 @@ test_path(void **state)
|
|||
|
||||
lyd_free_tree(root);
|
||||
|
||||
/* try LYD_NEWOPT_OPAQ */
|
||||
/* try LYD_NEW_PATH_OPAQ */
|
||||
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:l1", NULL, 0, 0, 0, NULL, NULL);
|
||||
assert_int_equal(ret, LY_EINVAL);
|
||||
CHECK_LOG_CTX("Predicate missing for list \"l1\" in path \"/a:l1\".", "/a:l1", 0);
|
||||
|
@ -424,7 +424,6 @@ test_path(void **state)
|
|||
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:any", "<elem>val</elem>", 0, LYD_ANYDATA_XML, 0, &root, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
assert_non_null(root);
|
||||
|
||||
lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"<any xmlns=\"urn:tests:a\">\n"
|
||||
|
@ -445,7 +444,6 @@ test_path(void **state)
|
|||
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", "<a/><b/><c/>", 0, LYD_ANYDATA_XML, 0, &root, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
assert_non_null(root);
|
||||
|
||||
lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"<anyx xmlns=\"urn:tests:a\">\n"
|
||||
|
@ -466,10 +464,44 @@ test_path(void **state)
|
|||
free(str);
|
||||
lyd_free_siblings(root);
|
||||
|
||||
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", "<a/><b/><c/>", 0, LYD_ANYDATA_XML, 0, &root, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
assert_non_null(root);
|
||||
ret = lyd_new_path2(root, NULL, "/a:anyx", "[10,11,12]", 0, LYD_ANYDATA_JSON, LYD_NEW_PATH_UPDATE, NULL, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"<anyx xmlns=\"urn:tests:a\">[10,11,12]</anyx>\n");
|
||||
free(str);
|
||||
lyd_print_mem(&str, root, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"{\n"
|
||||
" \"a:anyx\": [10,11,12]\n"
|
||||
"}\n");
|
||||
free(str);
|
||||
lyd_free_siblings(root);
|
||||
|
||||
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", "<a/><b/><c/>", 0, LYD_ANYDATA_XML, 0, &root, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
assert_non_null(root);
|
||||
ret = lyd_new_path2(root, NULL, "/a:anyx", strdup("[10,11,12]"), 0, LYD_ANYDATA_JSON,
|
||||
LYD_NEW_PATH_UPDATE | LYD_NEW_ANY_USE_VALUE, NULL, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"<anyx xmlns=\"urn:tests:a\">[10,11,12]</anyx>\n");
|
||||
free(str);
|
||||
lyd_print_mem(&str, root, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"{\n"
|
||||
" \"a:anyx\": [10,11,12]\n"
|
||||
"}\n");
|
||||
free(str);
|
||||
lyd_free_siblings(root);
|
||||
|
||||
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", "{\"a\":[null],\"b\":[null],\"c\":[null]}", 0, LYD_ANYDATA_JSON, 0, &root, NULL);
|
||||
assert_int_equal(ret, LY_SUCCESS);
|
||||
assert_non_null(root);
|
||||
|
||||
lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_WITHSIBLINGS);
|
||||
assert_string_equal(str,
|
||||
"<anyx xmlns=\"urn:tests:a\">\n"
|
||||
|
|
|
@ -168,6 +168,21 @@ test_leaf(void **state)
|
|||
PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, "Invalid non-string-encoded string value \"\".", "/a:foo", 1);
|
||||
CHECK_PARSE_LYD(data, LYD_PARSE_JSON_NULL, LYD_VALIDATE_PRESENT, tree);
|
||||
assert_null(tree);
|
||||
|
||||
/* validate integer in quotes errors out by default */
|
||||
data = "{\"a:foo3\":\"1234\"}";
|
||||
PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
|
||||
"Invalid non-number-encoded uint32 value \"1234\".", "/a:foo3", 1);
|
||||
|
||||
/* validate integers are parsed correctly */
|
||||
data = "{\"a:foo3\":1234}";
|
||||
CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
|
||||
lyd_free_all(tree);
|
||||
|
||||
/* validate LYD_PARSE_JSON_STRING_DATATYPES parser flag allows integers in quotes */
|
||||
data = "{\"a:foo3\":\"1234\"}";
|
||||
CHECK_PARSE_LYD(data, LYD_PARSE_JSON_STRING_DATATYPES, LYD_VALIDATE_PRESENT, tree);
|
||||
lyd_free_all(tree);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -920,6 +935,25 @@ test_metadata(void **state)
|
|||
CHECK_LOG_CTX("Invalid non-number-encoded int8 value \"value\".", "/a:c/x/@a:hint", 1);
|
||||
}
|
||||
|
||||
static void
|
||||
test_parent(void **state)
|
||||
{
|
||||
const char *data;
|
||||
struct lyd_node *tree;
|
||||
struct ly_in *in;
|
||||
|
||||
/* create the parent */
|
||||
assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX, "/a:l1[a='vala'][b='valb'][c='25']", NULL, 0, &tree));
|
||||
|
||||
/* parse nested data */
|
||||
data = "{\"cont\":{\"e\":false}}";
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
|
||||
assert_int_equal(LY_SUCCESS, lyd_parse_data(NULL, tree, in, LYD_JSON, 0, LYD_VALIDATE_PRESENT, NULL));
|
||||
|
||||
ly_in_free(in, 0);
|
||||
lyd_free_tree(tree);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
@ -939,6 +973,7 @@ main(void)
|
|||
UTEST(test_restconf_notification, setup),
|
||||
UTEST(test_restconf_reply, setup),
|
||||
UTEST(test_metadata, setup),
|
||||
UTEST(test_parent, setup),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
|
|
@ -722,6 +722,8 @@ test_netconf_reply_or_notification(void **state)
|
|||
struct ly_in *in;
|
||||
struct lyd_node *action, *tree, *op, *op2;
|
||||
|
||||
assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", NULL)));
|
||||
|
||||
/* parse the action */
|
||||
data = "<c xmlns=\"urn:tests:a\">\n"
|
||||
" <act>\n"
|
||||
|
@ -817,6 +819,7 @@ test_netconf_reply_or_notification(void **state)
|
|||
" <error-type>rpc</error-type>\n"
|
||||
" <error-tag>missing-attribute</error-tag>\n"
|
||||
" <error-severity>error</error-severity>\n"
|
||||
" <error-path xmlns:a=\"urn:tests:a\">/a:c/a:x</error-path>\n"
|
||||
" <error-info>\n"
|
||||
" <bad-attribute>message-id</bad-attribute>\n"
|
||||
" <bad-element>rpc</bad-element>\n"
|
||||
|
@ -828,8 +831,6 @@ test_netconf_reply_or_notification(void **state)
|
|||
ly_in_free(in, 0);
|
||||
|
||||
CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, "");
|
||||
CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 1, LY_VALUE_XML, "rpc-error", 0, 0, 0, 0, "");
|
||||
|
||||
CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
|
||||
|
||||
lyd_free_all(tree);
|
||||
|
|
|
@ -277,12 +277,12 @@ test_minmax(void **state)
|
|||
CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:c\">mate</l>"
|
||||
"<d xmlns=\"urn:tests:c\"/>",
|
||||
LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
|
||||
CHECK_LOG_CTX_APPTAG("Too few \"l\" instances.", "/c:choic/b/l", 0, "too-few-elements");
|
||||
CHECK_LOG_CTX_APPTAG("Too few \"l\" instances.", "/c:l[.='mate']", 0, "too-few-elements");
|
||||
|
||||
CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:c\">val1</l>"
|
||||
"<l xmlns=\"urn:tests:c\">val2</l>",
|
||||
LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
|
||||
CHECK_LOG_CTX_APPTAG("Too few \"l\" instances.", "/c:choic/b/l", 0, "too-few-elements");
|
||||
CHECK_LOG_CTX_APPTAG("Too few \"l\" instances.", "/c:l[.='val2']", 0, "too-few-elements");
|
||||
|
||||
LYD_TREE_CREATE("<l xmlns=\"urn:tests:c\">val1</l>"
|
||||
"<l xmlns=\"urn:tests:c\">val2</l>"
|
||||
|
@ -1259,7 +1259,7 @@ test_multi_error(void **state)
|
|||
CHECK_PARSE_LYD_PARAM(data, LYD_JSON, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree);
|
||||
assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_MULTI_ERROR, NULL));
|
||||
lyd_free_tree(tree);
|
||||
CHECK_LOG_CTX_APPTAG("Too few \"ll\" instances.", "/ii:cont/ll", 0, "too-few-elements");
|
||||
CHECK_LOG_CTX_APPTAG("Too few \"ll\" instances.", "/ii:cont/ll[.='25']", 0, "too-few-elements");
|
||||
CHECK_LOG_CTX_APPTAG("l leaf is not left", "/ii:cont/l3", 0, "not-left");
|
||||
CHECK_LOG_CTX_APPTAG("Must condition \"../l = 'right'\" not satisfied.", "/ii:cont/l2", 0, "must-violation");
|
||||
CHECK_LOG_CTX_APPTAG("Duplicate instance of \"l\".", "/ii:cont/l", 0, NULL);
|
||||
|
|
|
@ -20,32 +20,32 @@
|
|||
|
||||
void **glob_state;
|
||||
|
||||
const char *glob_schema =
|
||||
"module sm {yang-version 1.1;namespace \"urn:sm\";prefix \"sm\";"
|
||||
"import ietf-yang-schema-mount {prefix yangmnt;}"
|
||||
"import ietf-interfaces {prefix if;}"
|
||||
"container root {yangmnt:mount-point \"root\";}"
|
||||
"container root2 {yangmnt:mount-point \"root\";}"
|
||||
"container root3 {"
|
||||
" list ls { key name; leaf name {type string;}"
|
||||
" yangmnt:mount-point \"mnt-root\";"
|
||||
" }"
|
||||
"}"
|
||||
"container root4 {config false; yangmnt:mount-point \"root\";}"
|
||||
"leaf target{type string;}"
|
||||
"augment /if:interfaces/if:interface {"
|
||||
" leaf sm-name {type leafref {path \"/sm:target\";}}"
|
||||
"}"
|
||||
"}";
|
||||
|
||||
static int
|
||||
setup(void **state)
|
||||
{
|
||||
const char *schema =
|
||||
"module sm {yang-version 1.1;namespace \"urn:sm\";prefix \"sm\";"
|
||||
"import ietf-yang-schema-mount {prefix yangmnt;}"
|
||||
"import ietf-interfaces {prefix if;}"
|
||||
"container root {yangmnt:mount-point \"root\";}"
|
||||
"container root2 {yangmnt:mount-point \"root\";}"
|
||||
"container root3 {"
|
||||
" list ls { key name; leaf name {type string;}"
|
||||
" yangmnt:mount-point \"mnt-root\";"
|
||||
" }"
|
||||
"}"
|
||||
"container root4 {config false; yangmnt:mount-point \"root\";}"
|
||||
"leaf target{type string;}"
|
||||
"augment /if:interfaces/if:interface {"
|
||||
" leaf sm-name {type leafref {path \"/sm:target\";}}"
|
||||
"}"
|
||||
"}";
|
||||
|
||||
UTEST_SETUP;
|
||||
glob_state = state;
|
||||
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, glob_schema, LYS_IN_YANG, NULL));
|
||||
assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "iana-if-type", NULL, NULL));
|
||||
|
||||
return 0;
|
||||
|
@ -1193,6 +1193,156 @@ test_parse_shared_parent_ref(void **state)
|
|||
lyd_free_siblings(data);
|
||||
}
|
||||
|
||||
static void
|
||||
test_dup_shared(void **state)
|
||||
{
|
||||
struct ly_ctx *ctx2;
|
||||
const char *ext_data, *xml;
|
||||
struct ly_set *set;
|
||||
struct lyd_node *data, *node, *dup;
|
||||
uint32_t diff_opts;
|
||||
|
||||
ext_data = "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
|
||||
" xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
|
||||
" <module-set>"
|
||||
" <name>test-set</name>"
|
||||
" <module>"
|
||||
" <name>ietf-datastores</name>"
|
||||
" <revision>2018-02-14</revision>"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
|
||||
" </module>"
|
||||
" <module>"
|
||||
" <name>ietf-yang-library</name>"
|
||||
" <revision>2019-01-04</revision>"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
|
||||
" </module>"
|
||||
" <module>"
|
||||
" <name>ietf-yang-schema-mount</name>"
|
||||
" <revision>2019-01-14</revision>"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
|
||||
" </module>"
|
||||
" <module>"
|
||||
" <name>ietf-interfaces</name>"
|
||||
" <revision>2014-05-08</revision>"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
|
||||
" </module>"
|
||||
" <module>"
|
||||
" <name>iana-if-type</name>"
|
||||
" <revision>2014-05-08</revision>"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
|
||||
" </module>"
|
||||
" <import-only-module>"
|
||||
" <name>ietf-yang-types</name>"
|
||||
" <revision>2013-07-15</revision>"
|
||||
" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
|
||||
" </import-only-module>"
|
||||
" </module-set>"
|
||||
" <schema>"
|
||||
" <name>test-schema</name>"
|
||||
" <module-set>test-set</module-set>"
|
||||
" </schema>"
|
||||
" <datastore>"
|
||||
" <name>ds:running</name>"
|
||||
" <schema>test-schema</schema>"
|
||||
" </datastore>"
|
||||
" <datastore>"
|
||||
" <name>ds:operational</name>"
|
||||
" <schema>test-schema</schema>"
|
||||
" </datastore>"
|
||||
" <content-id>1</content-id>"
|
||||
"</yang-library>"
|
||||
"<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
|
||||
" <module-set-id>1</module-set-id>"
|
||||
"</modules-state>"
|
||||
"<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
|
||||
" <mount-point>"
|
||||
" <module>sm</module>"
|
||||
" <label>mnt-root</label>"
|
||||
" <shared-schema/>"
|
||||
" </mount-point>"
|
||||
"</schema-mounts>";
|
||||
xml =
|
||||
"<root3 xmlns=\"urn:sm\">\n"
|
||||
" <ls>\n"
|
||||
" <name>ls1</name>\n"
|
||||
" <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
|
||||
" <interface>\n"
|
||||
" <name>if1</name>\n"
|
||||
" <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
|
||||
" </interface>\n"
|
||||
" </interfaces>\n"
|
||||
" </ls>\n"
|
||||
" <ls>\n"
|
||||
" <name>ls2</name>\n"
|
||||
" <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
|
||||
" <interface>\n"
|
||||
" <name>if2</name>\n"
|
||||
" <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
|
||||
" <oper-status>not-present</oper-status>\n"
|
||||
" <statistics>\n"
|
||||
" <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
|
||||
" </statistics>\n"
|
||||
" </interface>\n"
|
||||
" </interfaces-state>\n"
|
||||
" </ls>\n"
|
||||
"</root3>\n";
|
||||
|
||||
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, (void *)ext_data);
|
||||
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
|
||||
|
||||
diff_opts = LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_RECURSIVE | LYD_DUP_NO_LYDS;
|
||||
|
||||
/* dup to the same context */
|
||||
assert_int_equal(LY_SUCCESS, lyd_find_xpath(data,
|
||||
"/sm:root3/ls[name='ls1']/ietf-interfaces:interfaces/interface[name='if1']", &set));
|
||||
assert_int_equal(1, set->count);
|
||||
node = set->dnodes[0];
|
||||
ly_set_free(set, NULL);
|
||||
assert_int_equal(LY_SUCCESS, lyd_dup_single(node, NULL, diff_opts, &dup));
|
||||
|
||||
while (dup->parent) {
|
||||
dup = lyd_parent(dup);
|
||||
}
|
||||
assert_int_equal(LY_SUCCESS, lyd_find_xpath(data,
|
||||
"/sm:root3/ls[name='ls2']/ietf-interfaces:interfaces-state/interface[name='if2']", &set));
|
||||
assert_int_equal(1, set->count);
|
||||
node = set->dnodes[0];
|
||||
ly_set_free(set, NULL);
|
||||
assert_int_equal(LY_SUCCESS, lyd_dup_single_to_ctx(node, LYD_CTX(data), (struct lyd_node_inner *)dup, diff_opts, NULL));
|
||||
|
||||
lyd_free_siblings(dup);
|
||||
|
||||
/* dup to another context */
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD, &ctx2));
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx2, TESTS_DIR_MODULES_YANG));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx2, glob_schema, LYS_IN_YANG, NULL));
|
||||
assert_non_null(ly_ctx_load_module(ctx2, "iana-if-type", NULL, NULL));
|
||||
ly_ctx_set_ext_data_clb(ctx2, test_ext_data_clb, (void *)ext_data);
|
||||
|
||||
assert_int_equal(LY_SUCCESS, lyd_find_xpath(data,
|
||||
"/sm:root3/ls[name='ls1']/ietf-interfaces:interfaces/interface[name='if1']", &set));
|
||||
assert_int_equal(1, set->count);
|
||||
node = set->dnodes[0];
|
||||
ly_set_free(set, NULL);
|
||||
assert_int_equal(LY_SUCCESS, lyd_dup_single_to_ctx(node, ctx2, NULL, diff_opts, &dup));
|
||||
|
||||
while (dup->parent) {
|
||||
dup = lyd_parent(dup);
|
||||
}
|
||||
assert_int_equal(LY_SUCCESS, lyd_find_xpath(data,
|
||||
"/sm:root3/ls[name='ls2']/ietf-interfaces:interfaces-state/interface[name='if2']", &set));
|
||||
assert_int_equal(1, set->count);
|
||||
node = set->dnodes[0];
|
||||
ly_set_free(set, NULL);
|
||||
assert_int_equal(LY_SUCCESS, lyd_dup_single_to_ctx(node, ctx2, (struct lyd_node_inner *)dup, diff_opts, NULL));
|
||||
|
||||
lyd_free_siblings(dup);
|
||||
|
||||
/* cleanup */
|
||||
ly_ctx_destroy(ctx2);
|
||||
lyd_free_siblings(data);
|
||||
}
|
||||
|
||||
static void
|
||||
test_parse_config(void **state)
|
||||
{
|
||||
|
@ -1648,6 +1798,7 @@ main(void)
|
|||
UTEST(test_parse_inline, setup),
|
||||
UTEST(test_parse_shared, setup),
|
||||
UTEST(test_parse_shared_parent_ref, setup),
|
||||
UTEST(test_dup_shared, setup),
|
||||
UTEST(test_parse_config, setup),
|
||||
UTEST(test_new, setup),
|
||||
UTEST(test_lys_getnext, setup),
|
||||
|
|
|
@ -1051,7 +1051,7 @@ test_xml(void **state)
|
|||
"</user>";
|
||||
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
|
||||
assert_null(tree);
|
||||
CHECK_LOG_CTX("Too few \"user\" instances.", "/T2:user", 0);
|
||||
CHECK_LOG_CTX("Too few \"user\" instances.", "/T2:user[uid='1']", 0);
|
||||
|
||||
data =
|
||||
"<user xmlns=\"urn:tests:T2\">"
|
||||
|
@ -1347,7 +1347,7 @@ test_json(void **state)
|
|||
"]}";
|
||||
CHECK_PARSE_LYD_PARAM(data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
|
||||
assert_null(tree);
|
||||
CHECK_LOG_CTX("Too few \"user\" instances.", "/T2:user", 0);
|
||||
CHECK_LOG_CTX("Too few \"user\" instances.", "/T2:user[uid='4']", 0);
|
||||
|
||||
data =
|
||||
"{\"T2:user\": ["
|
||||
|
|
|
@ -1045,11 +1045,7 @@ test_includes(void **state)
|
|||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
|
||||
mod = ly_ctx_load_module(UTEST_LYCTX, "main_b", NULL, NULL);
|
||||
assert_null(mod);
|
||||
CHECK_LOG_CTX("Loading \"main_b\" module failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Data model \"main_b\" not found in local searchdirs.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing module \"main_b\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Including \"sub_b_one\" submodule into \"main_b\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Data model \"sub_b_one\" not found in local searchdirs.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing submodule \"sub_b_one\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("YANG 1.1 requires all submodules to be included from main module. But submodule \"sub_b_one\" includes "
|
||||
"submodule \"sub_b_two\" which is not included by main module \"main_b\".", NULL, 0);
|
||||
|
@ -1479,7 +1475,7 @@ test_extension_argument(void **state)
|
|||
|
||||
/* context reset */
|
||||
ly_ctx_destroy(UTEST_LYCTX);
|
||||
ly_ctx_new(NULL, 0, &UTEST_LYCTX);
|
||||
ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD, &UTEST_LYCTX);
|
||||
|
||||
/* from YIN */
|
||||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yin);
|
||||
|
@ -1581,7 +1577,7 @@ test_extension_argument_element(void **state)
|
|||
|
||||
/* context reset */
|
||||
ly_ctx_destroy(UTEST_LYCTX);
|
||||
ly_ctx_new(NULL, 0, &UTEST_LYCTX);
|
||||
ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD, &UTEST_LYCTX);
|
||||
|
||||
/* from YIN */
|
||||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yin);
|
||||
|
@ -1853,7 +1849,7 @@ test_ext_recursive(void **state)
|
|||
|
||||
/* context reset */
|
||||
ly_ctx_destroy(UTEST_LYCTX);
|
||||
ly_ctx_new(NULL, 0, &UTEST_LYCTX);
|
||||
ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD, &UTEST_LYCTX);
|
||||
|
||||
/* from YIN */
|
||||
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_imp_yin);
|
||||
|
@ -1887,6 +1883,225 @@ test_lysc_path(void **state)
|
|||
free(path);
|
||||
}
|
||||
|
||||
/* TEST */
|
||||
static ly_bool
|
||||
compare_str_nodeset(struct ly_set *expected, struct ly_set *received)
|
||||
{
|
||||
ly_bool is_error = 0;
|
||||
size_t r;
|
||||
size_t e;
|
||||
|
||||
for (e = 0; expected && e < expected->count; e++) {
|
||||
const char *epath = expected->objs[e];
|
||||
ly_bool found = 0;
|
||||
|
||||
for (r = 0; received && (r < received->count); r++) {
|
||||
const char *rpath = received->objs[r];
|
||||
|
||||
if (!strcmp(epath, rpath)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
fprintf(stderr, "< %s\n", epath);
|
||||
is_error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the count was equal and there was no error, no need to scan again */
|
||||
if (expected && received && (expected->count == received->count) && !is_error) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (r = 0; received && (r < received->count); r++) {
|
||||
ly_bool found = 0;
|
||||
const char *rpath = received->objs[r];
|
||||
|
||||
for (e = 0; expected && (e < expected->count) && !found; e++) {
|
||||
char *epath = expected->objs[e];
|
||||
|
||||
if (!strcmp(epath, rpath)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
fprintf(stderr, "> %s\n", rpath);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ly_set *
|
||||
strlist_to_pathset(const char **pathlist)
|
||||
{
|
||||
struct ly_set *set = NULL;
|
||||
uint32_t i;
|
||||
|
||||
if (!pathlist || !pathlist[0]) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ly_set_new(&set);
|
||||
|
||||
for (i = 0; pathlist[i]; i++) {
|
||||
ly_set_add(set, pathlist[i], 0, NULL);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
static struct ly_set *
|
||||
lysc_nodeset_to_pathset(struct ly_set *nodeset)
|
||||
{
|
||||
struct ly_set *set = NULL;
|
||||
uint32_t i;
|
||||
|
||||
if (!nodeset || !nodeset->count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ly_set_new(&set);
|
||||
|
||||
for (i = 0; i < nodeset->count; i++) {
|
||||
char *path = lysc_path(nodeset->snodes[i], LYSC_PATH_DATA, NULL, 0);
|
||||
|
||||
ly_set_add(set, path, 0, NULL);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
static void
|
||||
test_lysc_backlinks(void **state)
|
||||
{
|
||||
const char *expect1[] = {
|
||||
/* Built-ins, not sure how to exclude those when not limiting by
|
||||
* path */
|
||||
"/ietf-yang-library:yang-library/module-set/module/deviation",
|
||||
"/ietf-yang-library:yang-library/schema/module-set",
|
||||
"/ietf-yang-library:yang-library/datastore/schema",
|
||||
"/ietf-yang-library:yang-library-update/content-id",
|
||||
"/ietf-yang-library:yang-library-change/module-set-id",
|
||||
/* Normal expected */
|
||||
"/b:my_extref_list/my_extref",
|
||||
"/a:refstr",
|
||||
"/a:refnum",
|
||||
"/b:my_extref_union",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *expect2[] = {
|
||||
"/b:my_extref_list/my_extref",
|
||||
"/a:refstr",
|
||||
"/b:my_extref_union",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *expect3[] = {
|
||||
"/b:my_extref_list/my_extref",
|
||||
"/a:refstr",
|
||||
"/a:refnum",
|
||||
"/b: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;
|
||||
uint32_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"
|
||||
" namespace urn:b;\n"
|
||||
" prefix 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"
|
||||
" }\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, *expected = NULL, *received = NULL;
|
||||
|
||||
if (tests[i].match_path) {
|
||||
node = lys_find_path(UTEST_LYCTX, NULL, tests[i].match_path, 0);
|
||||
assert_non_null(node);
|
||||
}
|
||||
|
||||
assert_int_equal(LY_SUCCESS, lysc_node_lref_backlinks(UTEST_LYCTX, node, tests[i].match_ancestors, &set));
|
||||
|
||||
expected = strlist_to_pathset(tests[i].expected_paths);
|
||||
received = lysc_nodeset_to_pathset(set);
|
||||
assert_int_equal(1, compare_str_nodeset(expected, received));
|
||||
|
||||
ly_set_free(expected, NULL);
|
||||
ly_set_free(received, free);
|
||||
ly_set_free(set, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
@ -1909,6 +2124,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);
|
||||
|
|
|
@ -78,7 +78,7 @@ test_module(void **state)
|
|||
str = "module test {namespace urn:test; prefix t;"
|
||||
"feature f1;feature f2 {if-feature f1;}}";
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
|
||||
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod));
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
assert_int_equal(0, mod->implemented);
|
||||
|
@ -104,7 +104,7 @@ test_module(void **state)
|
|||
/* submodules cannot be compiled directly */
|
||||
str = "submodule test {belongs-to xxx {prefix x;}}";
|
||||
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
|
||||
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, NULL));
|
||||
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, NULL));
|
||||
lys_unres_glob_erase(&unres);
|
||||
ly_in_free(in, 0);
|
||||
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL, 0);
|
||||
|
|
|
@ -886,18 +886,16 @@ test_module(void **state)
|
|||
/* include */
|
||||
ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
|
||||
in.current = "module" SCHEMA_BEGINNING "include xxx;}";
|
||||
assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
|
||||
assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EINVAL);
|
||||
CHECK_LOG_CTX("Parsing module \"name\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Including \"xxx\" submodule into \"name\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Data model \"xxx\" not found in local searchdirs.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing submodule failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing submodule \"xxx\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL, 0);
|
||||
|
||||
ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
|
||||
in.current = "module" SCHEMA_BEGINNING "include xxx;}";
|
||||
assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
|
||||
CHECK_LOG_CTX("Parsing module \"name\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Including \"xxx\" submodule into \"name\" failed.", NULL, 0);
|
||||
CHECK_LOG_CTX("Parsing submodule \"xxx\" failed.", NULL, 0);
|
||||
UTEST_LOG_CTX_CLEAN;
|
||||
|
||||
ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
|
||||
|
|
|
@ -111,11 +111,11 @@ test_schema_yang(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 5);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, 0, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, 0, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 11, NULL, 0, 0, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[4]), 4294967295, NULL, 0, 0, "last", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, LYS_STATUS_CURR, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, LYS_STATUS_CURR, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 11, NULL, 0, LYS_STATUS_CURR, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[4]), 4294967295, NULL, 0, LYS_STATUS_CURR, "last", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 5, 0, 0, 0, 0x02, 0, 0, "bits", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -128,10 +128,10 @@ test_schema_yang(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 4);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, 0, "_two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, 0, "_ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, 0, "_ten-one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, 0, "ten_end...", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, LYS_STATUS_CURR, "_two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, LYS_STATUS_CURR, "_ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, LYS_STATUS_CURR, "_ten-one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, LYS_STATUS_CURR, "ten_end...", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 4, 0, 0, 0, 0x02, 0, 0, "bits", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -146,10 +146,10 @@ test_schema_yang(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 4);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, 0, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, 0, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, 0, "twelve", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, LYS_STATUS_CURR, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, LYS_STATUS_CURR, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, LYS_STATUS_CURR, "twelve", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 0, 0, 0, 0, 0, 0, 0, "my_type", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -164,8 +164,8 @@ test_schema_yang(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 2);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, 0, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, LYS_STATUS_CURR, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 2, 0, 0, 0, 0x02, 0, 0, "my_type", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -281,9 +281,9 @@ test_schema_yang(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 3);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, 0, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, 0, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, 0, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, LYS_STATUS_CURR, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, LYS_STATUS_CURR, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, LYS_STATUS_CURR, "eleven", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 4, 0, 0, 0, 0x02, 0, 0, "bits", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -300,10 +300,10 @@ test_schema_yang(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 4);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, 0, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, 0, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 11, NULL, 0, 0, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, LYS_STATUS_CURR, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, LYS_STATUS_CURR, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 11, NULL, 0, LYS_STATUS_CURR, "eleven", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 4, 0, 0, 0, 0x02, 0, 0, "bits", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -331,11 +331,11 @@ test_schema_yin(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 5);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, 0, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, 0, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 11, NULL, 0, 0, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[4]), 4294967295, NULL, 0, 0, "last", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 0, NULL, 0, LYS_STATUS_CURR, "zero", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 1, NULL, 0, LYS_STATUS_CURR, "one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 11, NULL, 0, LYS_STATUS_CURR, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[4]), 4294967295, NULL, 0, LYS_STATUS_CURR, "last", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 5, 0, 0, 0, 0x02, 0, 0, "bits", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -351,10 +351,10 @@ test_schema_yin(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 4);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, 0, "_two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, 0, "_ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, 0, "_ten-one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, 0, "ten_end...", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, LYS_STATUS_CURR, "_two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, LYS_STATUS_CURR, "_ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, LYS_STATUS_CURR, "_ten-one", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, LYS_STATUS_CURR, "ten_end...", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 4, 0, 0, 0, 0x02, 0, 0, "bits", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -373,10 +373,10 @@ test_schema_yin(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 4);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, 0, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, 0, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, 0, "twelve", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, LYS_STATUS_CURR, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[2]), 11, NULL, 0, LYS_STATUS_CURR, "eleven", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[3]), 12, NULL, 0, LYS_STATUS_CURR, "twelve", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 0, 0, 0, 0, 0, 0, 0, "my_type", 0, 0, 1, 0, 0, 0);
|
||||
|
@ -396,8 +396,8 @@ test_schema_yin(void **state)
|
|||
CHECK_LYSC_NODE_LEAF(lysc_leaf, NULL, 0, 0x5, 1, "port", 0, 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
lysc_type = (struct lysc_type_bits *) lysc_leaf->type;
|
||||
CHECK_LYSC_TYPE_BITS(lysc_type, 0, 2);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, 0, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, 0, "ten", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[0]), 2, NULL, 0, LYS_STATUS_CURR, "two", NULL);
|
||||
CHECK_LYSC_TYPE_BITENUM_ITEM(&(lysc_type->bits[1]), 10, NULL, 0, LYS_STATUS_CURR, "ten", NULL);
|
||||
lysp_leaf = (void *)mod->parsed->data;
|
||||
CHECK_LYSP_NODE_LEAF(lysp_leaf, NULL, 0, 0x0, 0, "port", 0, 0, NULL, 0, 0, NULL, NULL);
|
||||
CHECK_LYSP_TYPE(&(lysp_leaf->type), 0, 2, 0, 0, 0, 0x02, 0, 0, "my_type", 0, 0, 1, 0, 0, 0);
|
||||
|
|
|
@ -200,7 +200,7 @@ test_data_xml(void **state)
|
|||
|
||||
TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"/>",
|
||||
"defs", "xmlns:m=\"urn:tests:mod\"", "l1", "[1]", LY_EVALID);
|
||||
CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error: Unexpected XPath token \"[\" (\"[1]\"), expected \"Operator(Path)\".",
|
||||
CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error: XPath \"[1]\" was expected to be absolute.",
|
||||
"/defs:l1", 1);
|
||||
|
||||
TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"><l2/></cont>",
|
||||
|
|
|
@ -294,7 +294,7 @@ test_xpath_invalid_schema(void **state)
|
|||
"leaf r1 {type leafref {path \"deref(../l1)/../l2/t2\";}}");
|
||||
|
||||
UTEST_INVALID_MODULE(schema1, LYS_IN_YANG, NULL, LY_EVALID)
|
||||
CHECK_LOG_CTX("The deref function target node \"l1\" is not leaf nor leaflist", "/xp_test:r1", 0);
|
||||
CHECK_LOG_CTX("Deref function target node \"l1\" is not leaf nor leaflist.", "/xp_test:r1", 0);
|
||||
|
||||
schema2 = MODULE_CREATE_YANG("xp_test",
|
||||
"list l1 {key t1;"
|
||||
|
@ -307,7 +307,7 @@ test_xpath_invalid_schema(void **state)
|
|||
"leaf r2 {type leafref {path \"deref(../r1)/../l2/t2\";}}");
|
||||
|
||||
UTEST_INVALID_MODULE(schema2, LYS_IN_YANG, NULL, LY_EVALID)
|
||||
CHECK_LOG_CTX("The deref function target node \"r1\" is not leafref", "/xp_test:r2", 0);
|
||||
CHECK_LOG_CTX("Deref function target node \"r1\" is not leafref.", "/xp_test:r2", 0);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -105,8 +105,8 @@ test_data_xml(void **state)
|
|||
TEST_ERROR_XML2("",
|
||||
"defs", "", "un1", "123456789012345678901", LY_EVALID);
|
||||
CHECK_LOG_CTX("Invalid union value \"123456789012345678901\" - no matching subtype found:\n"
|
||||
" libyang 2 - leafref, version 1: Invalid type int8 value \"123456789012345678901\".\n"
|
||||
" libyang 2 - leafref, version 1: Invalid type int64 value \"123456789012345678901\".\n"
|
||||
" libyang 2 - leafref, version 1: Invalid leafref value \"123456789012345678901\" - no target instance \"/int8\" with the same value.\n"
|
||||
" libyang 2 - leafref, version 1: Invalid leafref value \"123456789012345678901\" - no target instance \"/int64\" with the same value.\n"
|
||||
" libyang 2 - identityref, version 1: Invalid identityref \"123456789012345678901\" value - identity not found in module \"defs\".\n"
|
||||
" libyang 2 - instance-identifier, version 1: Invalid instance-identifier \"123456789012345678901\" value - syntax error.\n"
|
||||
" libyang 2 - string, version 1: Unsatisfied length - string \"123456789012345678901\" length is not allowed.\n",
|
||||
|
@ -295,7 +295,8 @@ test_validation(void **state)
|
|||
assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
|
||||
CHECK_LOG_CTX("Invalid LYB union value - no matching subtype found:\n"
|
||||
" libyang 2 - leafref, version 1: Invalid leafref value \"one\" - no target instance \"../../a/name\" with the same value.\n"
|
||||
" libyang 2 - leafref, version 1: Invalid type uint32 value \"one\".\n", "/lref:test/community[name='test']/view", 0);
|
||||
" libyang 2 - leafref, version 1: Invalid leafref value \"one\" - no target instance \"../../b/name\" with the same value.\n",
|
||||
"/lref:test/community[name='test']/view", 0);
|
||||
|
||||
lyd_free_all(tree);
|
||||
}
|
||||
|
|
|
@ -161,7 +161,8 @@ struct utest_context {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Compare two lyd_node structure. Macro print lyd_node structure into string and then compare string. Print function use these two parameters. LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK;
|
||||
* @brief Compare two lyd_node structure. Macro print lyd_node structure into string and then compare string.
|
||||
*
|
||||
* @param[in] NODE_1 pointer to lyd_node
|
||||
* @param[in] NODE_2 pointer to lyd_node
|
||||
*/
|
||||
|
@ -169,8 +170,8 @@ struct utest_context {
|
|||
{ \
|
||||
char *str1; \
|
||||
char *str2; \
|
||||
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
|
||||
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
|
||||
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS)); \
|
||||
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS)); \
|
||||
assert_non_null(str1); \
|
||||
assert_non_null(str2); \
|
||||
assert_string_equal(str1, str2); \
|
||||
|
@ -1315,7 +1316,7 @@ utest_setup(void **state)
|
|||
*state = current_utest_context;
|
||||
|
||||
/* libyang context */
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, ¤t_utest_context->ctx));
|
||||
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIR_CWD, ¤t_utest_context->ctx));
|
||||
|
||||
/* backup timezone, if any */
|
||||
cur_tz = getenv("TZ");
|
||||
|
@ -1325,6 +1326,8 @@ utest_setup(void **state)
|
|||
|
||||
/* set CET */
|
||||
setenv("TZ", "CET+02:00", 1);
|
||||
/* call tzset explicitly, to update the tzname, timezone and daylight global variables */
|
||||
tzset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue