diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:23:18 +0000 |
commit | 16527d165de55f2727f55b752b30d44a7e61e927 (patch) | |
tree | 0840ee6e0e109a9e85f0d80ff36f92587c6a5538 /tests/utests/data/test_tree_data.c | |
parent | Releasing progress-linux version 2.1.30-2.1~progress7.99u1. (diff) | |
download | libyang2-16527d165de55f2727f55b752b30d44a7e61e927.tar.xz libyang2-16527d165de55f2727f55b752b30d44a7e61e927.zip |
Merging upstream version 2.1.148.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/utests/data/test_tree_data.c')
-rw-r--r-- | tests/utests/data/test_tree_data.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/tests/utests/data/test_tree_data.c b/tests/utests/data/test_tree_data.c index 27dba42..494fdf3 100644 --- a/tests/utests/data/test_tree_data.c +++ b/tests/utests/data/test_tree_data.c @@ -1,9 +1,9 @@ /** * @file test_tree_data.c - * @author: Radek Krejci <rkrejci@cesnet.cz> - * @brief unit tests for functions from tress_data.c + * @author Radek Krejci <rkrejci@cesnet.cz> + * @brief unit tests for functions from tree_data.c * - * Copyright (c) 2018-2019 CESNET, z.s.p.o. + * Copyright (c) 2018-2023 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -100,7 +100,7 @@ test_compare(void **state) data2 = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); - assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, 0)); + assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, LYD_COMPARE_FULL_RECURSION)); assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next->next, tree2->next, 0)); lyd_free_all(tree1); lyd_free_all(tree2); @@ -145,6 +145,14 @@ test_compare(void **state) assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); lyd_free_all(tree1); lyd_free_all(tree2); + + data1 = "<c xmlns=\"urn:tests:a\"><x>c</x><x>a</x><x>b</x></c>"; + data2 = "<c xmlns=\"urn:tests:a\"><x>a</x><x>b</x><x>c</x></c>"; + CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); + CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); + assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); + lyd_free_all(tree1); + lyd_free_all(tree2); } static void @@ -196,7 +204,7 @@ test_compare_diff_ctx(void **state) data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); - assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); + assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); lyd_free_all(tree1); lyd_free_all(tree2); @@ -210,7 +218,7 @@ test_compare_diff_ctx(void **state) data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); - assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); + assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); lyd_free_all(tree1); lyd_free_all(tree2); @@ -329,8 +337,7 @@ test_dup(void **state) data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); - assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)((struct lyd_node_inner *)tree1->next)->child)->child, NULL, - LYD_DUP_WITH_PARENTS, &tree2)); + assert_int_equal(LY_SUCCESS, lyd_dup_single(lyd_child(lyd_child(tree1->next)), NULL, LYD_DUP_WITH_PARENTS, &tree2)); int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM; CHECK_LYSC_NODE(tree2->schema, NULL, 0, flag, 1, "x", 1, LYS_LEAF, 1, 0, NULL, 0); @@ -352,8 +359,8 @@ test_dup(void **state) data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, 0, &tree2)); - assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)((struct lyd_node_inner *)tree1->next)->child)->child, - (struct lyd_node_inner *)tree2, LYD_DUP_WITH_PARENTS, NULL)); + assert_int_equal(LY_SUCCESS, lyd_dup_single(lyd_child(lyd_child(tree1->next)), (struct lyd_node_inner *)tree2, + LYD_DUP_WITH_PARENTS, NULL)); assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2, LYD_COMPARE_FULL_RECURSION)); lyd_free_all(tree1); lyd_free_all(tree2); @@ -363,6 +370,8 @@ test_dup(void **state) CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); assert_int_equal(LY_EINVAL, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev, (struct lyd_node_inner *)tree1->next, LYD_DUP_WITH_PARENTS, NULL)); + CHECK_LOG_CTX("None of the duplicated node \"c\" schema parents match the provided parent \"c\".", + NULL); lyd_free_all(tree1); } @@ -488,6 +497,11 @@ test_find_path(void **state) assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/nexthop[gateway='10.0.0.1']", 0, NULL)); assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/nexthop[gateway='2100::1']", 0, NULL)); assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/pref[.='fc00::/64']", 0, NULL)); + + assert_int_equal(LY_EVALID, lyd_find_path(root, "/cont", 0, NULL)); + CHECK_LOG_CTX("Prefix missing for \"cont\" in path.", "Schema location \"/c:cont\"."); + assert_int_equal(LY_SUCCESS, lyd_find_path(root, "nexthop[gateway='2100::1']", 0, NULL)); + lyd_free_all(root); } @@ -525,6 +539,7 @@ test_data_hash(void **state) /* The run must not crash due to the assert that checks the hash. */ CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); + CHECK_LOG_CTX("Duplicate instance of \"ll\".", "Data location \"/test-data-hash:c/ll[.='']\", line number 1."); lyd_free_all(tree); } |