summaryrefslogtreecommitdiffstats
path: root/tests/utests/schema/test_printer_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utests/schema/test_printer_tree.c')
-rw-r--r--tests/utests/schema/test_printer_tree.c119
1 files changed, 118 insertions, 1 deletions
diff --git a/tests/utests/schema/test_printer_tree.c b/tests/utests/schema/test_printer_tree.c
index c076ece..40fb15f 100644
--- a/tests/utests/schema/test_printer_tree.c
+++ b/tests/utests/schema/test_printer_tree.c
@@ -1574,6 +1574,7 @@ print_compiled_node(void **state)
" yang-version 1.1;\n"
" namespace \"x:y\";\n"
" prefix x;\n"
+ "\n"
" container g {\n"
" leaf a {\n"
" type string;\n"
@@ -1586,6 +1587,12 @@ print_compiled_node(void **state)
" leaf c {\n"
" type string;\n"
" }\n"
+ " list l {\n"
+ " key \"ip\";\n"
+ " leaf ip {\n"
+ " type string;\n"
+ " }\n"
+ " }\n"
" }\n"
" }\n"
"}\n";
@@ -1610,13 +1617,31 @@ print_compiled_node(void **state)
ly_out_reset(UTEST_OUT);
+ /* pyang -f tree --tree-path /g/h/l */
+ expect =
+ "module: a26\n"
+ " +--rw g\n"
+ " +--rw h\n"
+ " +--rw l* [ip]\n"
+ " +--rw ip string\n";
+
+ node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h/l", 0);
+ CHECK_POINTER(node, 1);
+ assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
+ assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
+ assert_string_equal(printed, expect);
+
+ ly_out_reset(UTEST_OUT);
+
/* pyang -f tree --tree-path /g/h */
expect =
"module: a26\n"
" +--rw g\n"
" +--rw h\n"
" +--rw b string\n"
- " +--rw c? string\n";
+ " +--rw c? string\n"
+ " +--rw l* [ip]\n"
+ " +--rw ip string\n";
node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
CHECK_POINTER(node, 1);
@@ -1643,6 +1668,59 @@ print_compiled_node(void **state)
TEST_LOCAL_TEARDOWN;
}
+static void
+print_compiled_node_augment(void **state)
+{
+ TEST_LOCAL_SETUP;
+ const struct lysc_node *node;
+
+ orig =
+ "module b26xx {\n"
+ " yang-version 1.1;\n"
+ " namespace \"xx:y\";\n"
+ " prefix xx;\n"
+ " container c;\n"
+ "}\n";
+
+ UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
+
+ /* module with import statement */
+ orig =
+ "module b26 {\n"
+ " yang-version 1.1;\n"
+ " namespace \"x:y\";\n"
+ " prefix x;\n"
+ "\n"
+ " import b26xx {\n"
+ " prefix xx;\n"
+ " }\n"
+ "\n"
+ " augment \"/xx:c\" {\n"
+ " container e;\n"
+ " }\n"
+ "}\n";
+
+ UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
+
+ /* pyang -f tree --tree-path /c/e ... but prefixes modified */
+ expect =
+ "module: b26\n"
+ " +--rw xx:c\n"
+ " +--rw e\n";
+
+ /* using lysc tree */
+ ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
+ node = lys_find_path(UTEST_LYCTX, NULL, "/b26xx:c/b26:e", 0);
+ CHECK_POINTER(node, 1);
+ assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
+ assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
+ assert_string_equal(printed, expect);
+ ly_out_reset(UTEST_OUT);
+ ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
+
+ TEST_LOCAL_TEARDOWN;
+}
+
static LY_ERR
local_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,
@@ -2365,6 +2443,43 @@ structure(void **state)
TEST_LOCAL_TEARDOWN;
}
+static void
+annotation(void **state)
+{
+ TEST_LOCAL_SETUP;
+
+ orig =
+ "module ann {\n"
+ " yang-version 1.1;\n"
+ " namespace \"urn:example:ann\";\n"
+ " prefix an;\n"
+ "\n"
+ " import ietf-yang-metadata {\n"
+ " prefix md;\n"
+ " }\n"
+ "\n"
+ " leaf lf1 {\n"
+ " type string;\n"
+ " }\n"
+ " md:annotation avalue {\n"
+ " type string;\n"
+ " }\n"
+ "}\n";
+
+ expect =
+ "module: ann\n"
+ " +--rw lf1? string\n";
+
+ /* annotation is ignored without error message */
+ UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
+ TEST_LOCAL_PRINT(mod, 72);
+ assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
+ assert_string_equal(printed, expect);
+ ly_out_reset(UTEST_OUT);
+
+ TEST_LOCAL_TEARDOWN;
+}
+
int
main(void)
{
@@ -2395,10 +2510,12 @@ main(void)
UTEST(transition_between_rpc_and_notif),
UTEST(local_augment),
UTEST(print_compiled_node),
+ UTEST(print_compiled_node_augment),
UTEST(print_parsed_submodule),
UTEST(yang_data),
UTEST(mount_point),
UTEST(structure),
+ UTEST(annotation),
};
return cmocka_run_group_tests(tests, NULL, NULL);