Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 1 | /** |
aPiecek | 023f83a | 2021-05-11 07:37:03 +0200 | [diff] [blame] | 2 | * @file test_tree_data.c |
Michal Vasko | ee9b948 | 2023-06-19 13:17:48 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from tree_data.c |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 5 | * |
Michal Vasko | ee9b948 | 2023-06-19 13:17:48 +0200 | [diff] [blame] | 6 | * Copyright (c) 2018-2023 CESNET, z.s.p.o. |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #define _UTEST_MAIN_ |
| 15 | #include "utests.h" |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 16 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 17 | #include "libyang.h" |
Michal Vasko | 8f702ee | 2024-02-20 15:44:24 +0100 | [diff] [blame] | 18 | #include "ly_common.h" |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 19 | #include "path.h" |
| 20 | #include "xpath.h" |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 21 | |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 22 | static int |
| 23 | setup(void **state) |
| 24 | { |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 25 | const char *schema1 = "module a {namespace urn:tests:a;prefix a;yang-version 1.1;" |
| 26 | "revision 2014-05-08;" |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 27 | "leaf bar {type string;}" |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 28 | "list l1 { key \"a b\"; leaf a {type string;} leaf b {type string;} leaf c {type string;}}" |
| 29 | "leaf foo { type string;}" |
| 30 | "leaf-list ll { type string;}" |
| 31 | "container c {leaf-list x {type string;}}" |
| 32 | "anydata any {config false;}" |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 33 | "list l2 {config false;" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 34 | " container c{leaf x {type string;} leaf-list d {type string;}}" |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 35 | "}}"; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 36 | |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 37 | const char *schema2 = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 38 | "revision 2014-05-08;" |
| 39 | "list l2 {config false;" |
| 40 | " container c{leaf x {type string;}}}" |
| 41 | "anydata any {config false;}" |
| 42 | "}"; |
| 43 | |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 44 | const char *schema3 = "module c {yang-version 1.1; namespace \"http://example.com/main\";prefix m;" |
| 45 | "import \"ietf-inet-types\" {prefix inet;}" |
| 46 | "typedef optional-ip-address {type union {" |
| 47 | " type inet:ip-address;" |
Michal Vasko | 4fd9192 | 2021-09-15 08:51:06 +0200 | [diff] [blame] | 48 | " type string;" |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 49 | "}}" |
| 50 | "container cont {" |
| 51 | " list nexthop {min-elements 1; key \"gateway\";" |
| 52 | " leaf gateway {type optional-ip-address;}" |
| 53 | " }" |
Michal Vasko | 15dc9fa | 2021-05-03 14:33:05 +0200 | [diff] [blame] | 54 | " leaf-list pref {type inet:ipv6-prefix;}" |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 55 | "}}"; |
| 56 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 57 | UTEST_SETUP; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 58 | |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 59 | UTEST_ADD_MODULE(schema1, LYS_IN_YANG, NULL, NULL); |
| 60 | UTEST_ADD_MODULE(schema2, LYS_IN_YANG, NULL, NULL); |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 61 | UTEST_ADD_MODULE(schema3, LYS_IN_YANG, NULL, NULL); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 66 | #define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \ |
| 67 | CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE) |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 68 | |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 69 | #define CHECK_PARSE_LYD_PARAM_CTX(CTX, INPUT, PARSE_OPTION, OUT_NODE) \ |
| 70 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(CTX, INPUT, LYD_XML, PARSE_OPTION, LYD_VALIDATE_PRESENT, &OUT_NODE)); \ |
| 71 | assert_non_null(OUT_NODE); |
| 72 | |
| 73 | #define RECREATE_CTX_WITH_MODULE(CTX, MODULE) \ |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 74 | ly_ctx_destroy(CTX); \ |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 75 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &CTX)); \ |
| 76 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(MODULE, &_UC->in)); \ |
| 77 | assert_int_equal(LY_SUCCESS, lys_parse(CTX, _UC->in, LYS_IN_YANG, NULL, NULL)); \ |
| 78 | ly_in_free(_UC->in, 0); |
| 79 | |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 80 | static void |
| 81 | test_compare(void **state) |
| 82 | { |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 83 | struct lyd_node *tree1, *tree2; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 84 | const char *data1; |
| 85 | const char *data2; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 86 | |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 87 | assert_int_equal(LY_SUCCESS, lyd_compare_single(NULL, NULL, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 88 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 89 | data1 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>"; |
| 90 | data2 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>y</c></l1>"; |
| 91 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 92 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 93 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 94 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 95 | assert_int_equal(LY_ENOT, lyd_compare_single(((struct lyd_node_inner *)tree1)->child, tree2, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 96 | lyd_free_all(tree1); |
| 97 | lyd_free_all(tree2); |
| 98 | |
| 99 | data1 = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
| 100 | data2 = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 101 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 102 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | ee9b948 | 2023-06-19 13:17:48 +0200 | [diff] [blame] | 103 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, LYD_COMPARE_FULL_RECURSION)); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 104 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next->next, tree2->next, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 105 | lyd_free_all(tree1); |
| 106 | lyd_free_all(tree2); |
| 107 | |
| 108 | data1 = "<ll xmlns=\"urn:tests:a\">a</ll><ll xmlns=\"urn:tests:a\">b</ll>"; |
| 109 | data2 = "<ll xmlns=\"urn:tests:a\">b</ll>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 110 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 111 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 112 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 113 | assert_int_equal(LY_ENOT, lyd_compare_single(NULL, tree2, 0)); |
| 114 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, NULL, 0)); |
| 115 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 116 | lyd_free_all(tree1); |
| 117 | lyd_free_all(tree2); |
| 118 | |
| 119 | data1 = "<c xmlns=\"urn:tests:a\"><x>x</x></c>"; |
| 120 | data2 = "<c xmlns=\"urn:tests:a\"><x>y</x></c>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 121 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 122 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 123 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 124 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 125 | lyd_free_all(tree1); |
| 126 | lyd_free_all(tree2); |
| 127 | |
| 128 | data1 = "<c xmlns=\"urn:tests:a\"><x>x</x></c>"; |
| 129 | data2 = "<c xmlns=\"urn:tests:a\"><x>x</x><x>y</x></c>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 130 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 131 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 132 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 133 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 134 | lyd_free_all(tree1); |
| 135 | lyd_free_all(tree2); |
| 136 | |
| 137 | data1 = "<any xmlns=\"urn:tests:a\"><x>x</x></any>"; |
| 138 | data2 = "<any xmlns=\"urn:tests:a\"><x>x</x><x>y</x></any>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 139 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 140 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 141 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 142 | lyd_free_all(tree1); |
| 143 | data1 = "<any xmlns=\"urn:tests:a\"><x>x</x><x>y</x></any>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 144 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 145 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 146 | lyd_free_all(tree1); |
| 147 | lyd_free_all(tree2); |
Michal Vasko | f277d36 | 2023-04-24 09:08:31 +0200 | [diff] [blame] | 148 | |
| 149 | data1 = "<c xmlns=\"urn:tests:a\"><x>c</x><x>a</x><x>b</x></c>"; |
| 150 | data2 = "<c xmlns=\"urn:tests:a\"><x>a</x><x>b</x><x>c</x></c>"; |
| 151 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 152 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
| 153 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
| 154 | lyd_free_all(tree1); |
| 155 | lyd_free_all(tree2); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 158 | static void |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 159 | test_compare_diff_ctx(void **state) |
| 160 | { |
| 161 | struct lyd_node *tree1, *tree2; |
| 162 | const char *data1, *data2; |
| 163 | struct ly_ctx *ctx2 = NULL; |
| 164 | const char *module; |
| 165 | |
| 166 | /* create second context with the same schema */ |
| 167 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 168 | "revision 2014-05-08;" |
| 169 | "list l2 {config false;" |
| 170 | " container c{leaf x {type string;}}" |
| 171 | "}}"; |
| 172 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 173 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 174 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 175 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 176 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 177 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
| 178 | lyd_free_all(tree1); |
| 179 | lyd_free_all(tree2); |
| 180 | |
| 181 | /* recreate second context with schema that has a different name */ |
| 182 | module = "module c {namespace urn:tests:c;prefix c;yang-version 1.1;" |
| 183 | "revision 2014-05-08;" |
| 184 | "list l2 {config false;" |
| 185 | " container c{leaf x {type string;}}" |
| 186 | "}}"; |
| 187 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 188 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 189 | data2 = "<l2 xmlns=\"urn:tests:c\"><c><x>b</x></c></l2>"; |
| 190 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 191 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 192 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 193 | lyd_free_all(tree1); |
| 194 | lyd_free_all(tree2); |
| 195 | |
| 196 | /* recreate second context with schema that has a different revision */ |
| 197 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 198 | "revision 2015-05-08;" |
| 199 | "list l2 {config false;" |
| 200 | " container c{leaf x {type string;}}" |
| 201 | "}}"; |
| 202 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 203 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 204 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 205 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 206 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
Michal Vasko | 5d49f94 | 2023-02-14 10:02:36 +0100 | [diff] [blame] | 207 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 208 | lyd_free_all(tree1); |
| 209 | lyd_free_all(tree2); |
| 210 | |
| 211 | /* recreate second context with schema that has no revision */ |
| 212 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 213 | "list l2 {config false;" |
| 214 | " container c{leaf x {type string;}}" |
| 215 | "}}"; |
| 216 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 217 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 218 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 219 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 220 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
Michal Vasko | 5d49f94 | 2023-02-14 10:02:36 +0100 | [diff] [blame] | 221 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 222 | lyd_free_all(tree1); |
| 223 | lyd_free_all(tree2); |
| 224 | |
| 225 | /* recreate second context with schema that has a different parent nodetype */ |
| 226 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 227 | "revision 2014-05-08;" |
| 228 | "container l2 {config false;" |
| 229 | " container c{leaf x {type string;}}" |
| 230 | "}}"; |
| 231 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 232 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 233 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 234 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 235 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 236 | assert_int_equal(LY_ENOT, lyd_compare_single(lyd_child(lyd_child(tree1)), lyd_child(lyd_child(tree2)), 0)); |
| 237 | lyd_free_all(tree1); |
| 238 | lyd_free_all(tree2); |
| 239 | |
| 240 | /* recreate second context with the same opaq data nodes */ |
| 241 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 242 | "revision 2014-05-08;" |
| 243 | "anydata any {config false;}" |
| 244 | "}"; |
| 245 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 246 | data1 = "<any xmlns=\"urn:tests:b\" xmlns:aa=\"urn:tests:b\"><x>aa:x</x></any>"; |
| 247 | data2 = "<any xmlns=\"urn:tests:b\" xmlns:bb=\"urn:tests:b\"><x>bb:x</x></any>"; |
| 248 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, LYD_PARSE_ONLY, tree1); |
| 249 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, LYD_PARSE_ONLY, tree2); |
| 250 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 251 | lyd_free_all(tree1); |
| 252 | lyd_free_all(tree2); |
| 253 | |
| 254 | /* recreate second context with the different opaq data node value */ |
| 255 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 256 | "revision 2014-05-08;" |
| 257 | "anydata any {config false;}" |
| 258 | "}"; |
| 259 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 260 | data1 = "<any xmlns=\"urn:tests:b\" xmlns:aa=\"urn:tests:b\"><x>aa:x</x></any>"; |
| 261 | data2 = "<any xmlns=\"urn:tests:b\" xmlns:bb=\"urn:tests:b\"><x>bb:y</x></any>"; |
| 262 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, LYD_PARSE_ONLY, tree1); |
| 263 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, LYD_PARSE_ONLY, tree2); |
| 264 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 265 | lyd_free_all(tree1); |
| 266 | lyd_free_all(tree2); |
| 267 | |
| 268 | /* recreate second context with the wrong prefix in opaq data node value */ |
| 269 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 270 | "revision 2014-05-08;" |
| 271 | "anydata any {config false;}" |
| 272 | "}"; |
| 273 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 274 | data1 = "<any xmlns=\"urn:tests:b\" xmlns:aa=\"urn:tests:b\"><x>aa:x</x></any>"; |
| 275 | data2 = "<any xmlns=\"urn:tests:b\" xmlns:bb=\"urn:tests:b\"><x>cc:x</x></any>"; |
| 276 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, LYD_PARSE_ONLY, tree1); |
| 277 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, LYD_PARSE_ONLY, tree2); |
| 278 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 279 | lyd_free_all(tree1); |
| 280 | lyd_free_all(tree2); |
| 281 | |
| 282 | /* clean up */ |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 283 | ly_ctx_destroy(ctx2); |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 284 | _UC->in = NULL; |
| 285 | } |
| 286 | |
| 287 | static void |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 288 | test_dup(void **state) |
| 289 | { |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 290 | struct lyd_node *tree1, *tree2; |
| 291 | const char *result; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 292 | const char *data; |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 293 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 294 | data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>"; |
| 295 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 296 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, LYD_DUP_RECURSIVE, &tree2)); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 297 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 298 | lyd_free_all(tree1); |
| 299 | lyd_free_all(tree2); |
| 300 | |
| 301 | data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>"; |
| 302 | result = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b></l1>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 303 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 304 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 305 | lyd_free_all(tree1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 306 | CHECK_PARSE_LYD(result, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 307 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 308 | lyd_free_all(tree1); |
| 309 | lyd_free_all(tree2); |
| 310 | |
| 311 | data = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
| 312 | result = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 313 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 314 | assert_int_equal(LY_SUCCESS, lyd_dup_siblings(tree1, NULL, LYD_DUP_RECURSIVE, &tree2)); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 315 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2->next, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 316 | lyd_free_all(tree2); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 317 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, LYD_DUP_RECURSIVE, &tree2)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 318 | lyd_free_all(tree1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 319 | CHECK_PARSE_LYD(result, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 320 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 321 | lyd_free_all(tree2); |
| 322 | |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 323 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, 0, &tree2)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 324 | lyd_free_all(tree1); |
| 325 | result = "<l2 xmlns=\"urn:tests:a\"/>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 326 | CHECK_PARSE_LYD_PARAM(result, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree1); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 327 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 328 | lyd_free_all(tree1); |
| 329 | lyd_free_all(tree2); |
| 330 | |
| 331 | data = "<any xmlns=\"urn:tests:a\"><c><a>a</a></c></any>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 332 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 333 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2)); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 334 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 335 | lyd_free_all(tree1); |
| 336 | lyd_free_all(tree2); |
| 337 | |
| 338 | data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 339 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | eaef7c9 | 2023-10-17 10:06:15 +0200 | [diff] [blame] | 340 | assert_int_equal(LY_SUCCESS, lyd_dup_single(lyd_child(lyd_child(tree1->next)), NULL, LYD_DUP_WITH_PARENTS, &tree2)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 341 | int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM; |
| 342 | |
| 343 | CHECK_LYSC_NODE(tree2->schema, NULL, 0, flag, 1, "x", 1, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 344 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, (struct lyd_node *)tree2->parent->parent, |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 345 | LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 346 | lyd_free_all(tree1); |
| 347 | lyd_free_all(tree2); |
| 348 | |
| 349 | data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>c</c></l1>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 350 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 351 | assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev, NULL, |
| 352 | LYD_DUP_WITH_PARENTS, &tree2)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 353 | flag = LYS_CONFIG_W | LYS_SET_ENUM; |
| 354 | CHECK_LYSC_NODE(tree2->schema, NULL, 0, flag, 1, "c", 0, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 355 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, (struct lyd_node *)tree2->parent, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 356 | lyd_free_all(tree1); |
| 357 | lyd_free_all(tree2); |
| 358 | |
| 359 | data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 360 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 361 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, 0, &tree2)); |
Michal Vasko | eaef7c9 | 2023-10-17 10:06:15 +0200 | [diff] [blame] | 362 | assert_int_equal(LY_SUCCESS, lyd_dup_single(lyd_child(lyd_child(tree1->next)), (struct lyd_node_inner *)tree2, |
| 363 | LYD_DUP_WITH_PARENTS, NULL)); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 364 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2, LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 365 | lyd_free_all(tree1); |
| 366 | lyd_free_all(tree2); |
| 367 | |
| 368 | /* invalid */ |
| 369 | data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>c</c></l1><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 370 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 371 | assert_int_equal(LY_EINVAL, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev, |
| 372 | (struct lyd_node_inner *)tree1->next, LYD_DUP_WITH_PARENTS, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 373 | CHECK_LOG_CTX("None of the duplicated node \"c\" schema parents match the provided parent \"c\".", NULL, 0); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 374 | lyd_free_all(tree1); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 377 | static void |
| 378 | test_target(void **state) |
| 379 | { |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 380 | const struct lyd_node_term *term; |
| 381 | struct lyd_node *tree; |
| 382 | struct lyxp_expr *exp; |
| 383 | struct ly_path *path; |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 384 | const char *path_str = "/a:l2[2]/c/d[3]"; |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 385 | const char *data = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 386 | "<l2 xmlns=\"urn:tests:a\"><c>" |
| 387 | " <d>a</d>" |
| 388 | " </c></l2>" |
| 389 | "<l2 xmlns=\"urn:tests:a\"><c>" |
| 390 | " <d>a</d>" |
| 391 | " <d>b</d>" |
| 392 | " <d>b</d>" |
| 393 | " <d>c</d>" |
| 394 | "</c></l2>" |
| 395 | "<l2 xmlns=\"urn:tests:a\"><c>" |
| 396 | "</c></l2>"; |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 397 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 398 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Michal Vasko | ed725d7 | 2021-06-23 12:03:45 +0200 | [diff] [blame] | 399 | assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path_str, strlen(path_str), 0, LY_PATH_BEGIN_EITHER, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 400 | LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_SIMPLE, &exp)); |
Michal Vasko | ed725d7 | 2021-06-23 12:03:45 +0200 | [diff] [blame] | 401 | assert_int_equal(LY_SUCCESS, ly_path_compile(UTEST_LYCTX, NULL, NULL, NULL, exp, LY_PATH_OPER_INPUT, |
Michal Vasko | 0884d21 | 2021-10-14 09:21:46 +0200 | [diff] [blame] | 402 | LY_PATH_TARGET_SINGLE, 1, LY_VALUE_JSON, NULL, &path)); |
Michal Vasko | 7ee42f3 | 2024-01-22 11:34:21 +0100 | [diff] [blame] | 403 | assert_int_equal(LY_SUCCESS, lyd_find_target(path, tree, (struct lyd_node **)&term)); |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 404 | |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 405 | const int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM | LYS_ORDBY_USER; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 406 | |
| 407 | CHECK_LYSC_NODE(term->schema, NULL, 0, flag, 1, "d", 0, LYS_LEAFLIST, 1, 0, NULL, 0); |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 408 | assert_string_equal(lyd_get_value(&term->node), "b"); |
| 409 | assert_string_equal(lyd_get_value(term->prev), "b"); |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 410 | |
| 411 | lyd_free_all(tree); |
Michal Vasko | 5939112 | 2024-08-16 15:38:02 +0200 | [diff] [blame] | 412 | ly_path_free(UTEST_LYCTX, path); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 413 | lyxp_expr_free(UTEST_LYCTX, exp); |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 416 | static void |
| 417 | test_list_pos(void **state) |
| 418 | { |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 419 | const char *data; |
| 420 | struct lyd_node *tree; |
| 421 | |
| 422 | data = "<bar xmlns=\"urn:tests:a\">test</bar>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 423 | "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b></l1>" |
| 424 | "<l1 xmlns=\"urn:tests:a\"><a>two</a><b>two</b></l1>" |
| 425 | "<foo xmlns=\"urn:tests:a\">test</foo>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 426 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 427 | assert_int_equal(0, lyd_list_pos(tree)); |
| 428 | assert_int_equal(1, lyd_list_pos(tree->next)); |
| 429 | assert_int_equal(2, lyd_list_pos(tree->next->next)); |
| 430 | assert_int_equal(0, lyd_list_pos(tree->next->next->next)); |
| 431 | lyd_free_all(tree); |
| 432 | |
| 433 | data = "<ll xmlns=\"urn:tests:a\">one</ll>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 434 | "<ll xmlns=\"urn:tests:a\">two</ll>" |
| 435 | "<ll xmlns=\"urn:tests:a\">three</ll>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 436 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 437 | assert_int_equal(1, lyd_list_pos(tree)); |
| 438 | assert_int_equal(2, lyd_list_pos(tree->next)); |
| 439 | assert_int_equal(3, lyd_list_pos(tree->next->next)); |
| 440 | lyd_free_all(tree); |
| 441 | |
| 442 | data = "<ll xmlns=\"urn:tests:a\">one</ll>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 443 | "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b></l1>" |
| 444 | "<ll xmlns=\"urn:tests:a\">two</ll>" |
| 445 | "<l1 xmlns=\"urn:tests:a\"><a>two</a><b>two</b></l1>" |
| 446 | "<ll xmlns=\"urn:tests:a\">three</ll>" |
| 447 | "<l1 xmlns=\"urn:tests:a\"><a>three</a><b>three</b></l1>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 448 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 449 | assert_string_equal("l1", tree->schema->name); |
| 450 | assert_int_equal(1, lyd_list_pos(tree)); |
| 451 | assert_int_equal(2, lyd_list_pos(tree->next)); |
| 452 | assert_int_equal(3, lyd_list_pos(tree->next->next)); |
| 453 | assert_string_equal("ll", tree->next->next->next->schema->name); |
| 454 | assert_int_equal(1, lyd_list_pos(tree->next->next->next)); |
| 455 | assert_int_equal(2, lyd_list_pos(tree->next->next->next->next)); |
| 456 | assert_int_equal(3, lyd_list_pos(tree->next->next->next->next->next)); |
| 457 | lyd_free_all(tree); |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 458 | } |
| 459 | |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 460 | static void |
| 461 | test_first_sibling(void **state) |
| 462 | { |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 463 | const char *data; |
| 464 | struct lyd_node *tree; |
| 465 | struct lyd_node_inner *parent; |
| 466 | |
| 467 | data = "<bar xmlns=\"urn:tests:a\">test</bar>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 468 | "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>one</c></l1>" |
| 469 | "<foo xmlns=\"urn:tests:a\">test</foo>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 470 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 471 | assert_ptr_equal(tree, lyd_first_sibling(tree->next)); |
| 472 | assert_ptr_equal(tree, lyd_first_sibling(tree)); |
| 473 | assert_ptr_equal(tree, lyd_first_sibling(tree->prev)); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 474 | parent = (struct lyd_node_inner *)tree->next; |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 475 | assert_int_equal(LYS_LIST, parent->schema->nodetype); |
| 476 | assert_ptr_equal(parent->child, lyd_first_sibling(parent->child->next)); |
| 477 | assert_ptr_equal(parent->child, lyd_first_sibling(parent->child)); |
| 478 | assert_ptr_equal(parent->child, lyd_first_sibling(parent->child->prev)); |
| 479 | lyd_free_all(tree); |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 482 | static void |
| 483 | test_find_path(void **state) |
| 484 | { |
| 485 | struct lyd_node *root; |
| 486 | const struct lys_module *mod; |
| 487 | |
| 488 | mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "c"); |
| 489 | assert_non_null(mod); |
| 490 | |
| 491 | assert_int_equal(LY_SUCCESS, lyd_new_inner(NULL, mod, "cont", 0, &root)); |
| 492 | assert_int_equal(LY_SUCCESS, lyd_new_path(root, NULL, "/c:cont/nexthop[gateway='10.0.0.1']", NULL, LYD_NEW_PATH_UPDATE, NULL)); |
| 493 | assert_int_equal(LY_SUCCESS, lyd_new_path(root, NULL, "/c:cont/nexthop[gateway='2100::1']", NULL, LYD_NEW_PATH_UPDATE, NULL)); |
Michal Vasko | 15dc9fa | 2021-05-03 14:33:05 +0200 | [diff] [blame] | 494 | assert_int_equal(LY_SUCCESS, lyd_new_path(root, NULL, "/c:cont/pref[.='fc00::/64']", NULL, 0, NULL)); |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 495 | |
| 496 | assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/nexthop[gateway='10.0.0.1']", 0, NULL)); |
| 497 | assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/nexthop[gateway='2100::1']", 0, NULL)); |
Michal Vasko | 15dc9fa | 2021-05-03 14:33:05 +0200 | [diff] [blame] | 498 | assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/pref[.='fc00::/64']", 0, NULL)); |
Michal Vasko | 32ca49b | 2023-02-17 15:11:35 +0100 | [diff] [blame] | 499 | |
| 500 | assert_int_equal(LY_EVALID, lyd_find_path(root, "/cont", 0, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 501 | CHECK_LOG_CTX("Prefix missing for \"cont\" in path.", "/c:cont", 0); |
Michal Vasko | 32ca49b | 2023-02-17 15:11:35 +0100 | [diff] [blame] | 502 | assert_int_equal(LY_SUCCESS, lyd_find_path(root, "nexthop[gateway='2100::1']", 0, NULL)); |
| 503 | |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 504 | lyd_free_all(root); |
| 505 | } |
| 506 | |
aPiecek | 4f07c3e | 2021-06-11 10:53:07 +0200 | [diff] [blame] | 507 | static void |
| 508 | test_data_hash(void **state) |
| 509 | { |
| 510 | struct lyd_node *tree; |
| 511 | const char *schema, *data; |
| 512 | |
| 513 | schema = |
| 514 | "module test-data-hash {" |
| 515 | " yang-version 1.1;" |
| 516 | " namespace \"urn:tests:tdh\";" |
| 517 | " prefix t;" |
| 518 | " container c {" |
| 519 | " leaf-list ll {" |
| 520 | " type string;" |
| 521 | " }" |
| 522 | " }" |
| 523 | "}"; |
| 524 | |
| 525 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); |
| 526 | |
| 527 | /* The number of <ll/> must be greater or equal to LYD_HT_MIN_ITEMS |
| 528 | * for the correct test run. It should guarantee the creation of a hash table. |
| 529 | */ |
| 530 | assert_true(LYD_HT_MIN_ITEMS <= 4); |
| 531 | data = |
| 532 | "<c xmlns='urn:tests:tdh'>" |
| 533 | " <ll/>" |
| 534 | " <ll/>" |
| 535 | " <ll/>" |
| 536 | " <ll/>" |
| 537 | "</c>"; |
| 538 | |
| 539 | /* The run must not crash due to the assert that checks the hash. */ |
| 540 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 541 | CHECK_LOG_CTX("Duplicate instance of \"ll\".", "/test-data-hash:c/ll[.='']", 1); |
aPiecek | 4f07c3e | 2021-06-11 10:53:07 +0200 | [diff] [blame] | 542 | lyd_free_all(tree); |
| 543 | } |
| 544 | |
aPiecek | df23eee | 2021-10-07 12:21:50 +0200 | [diff] [blame] | 545 | static void |
| 546 | test_lyxp_vars(void **UNUSED(state)) |
| 547 | { |
| 548 | struct lyxp_var *vars; |
| 549 | |
| 550 | /* Test free. */ |
| 551 | vars = NULL; |
| 552 | lyxp_vars_free(vars); |
| 553 | |
| 554 | /* Bad arguments for lyxp_vars_add(). */ |
| 555 | assert_int_equal(LY_EINVAL, lyxp_vars_set(NULL, "var1", "val1")); |
| 556 | assert_int_equal(LY_EINVAL, lyxp_vars_set(&vars, NULL, "val1")); |
| 557 | assert_int_equal(LY_EINVAL, lyxp_vars_set(&vars, "var1", NULL)); |
| 558 | lyxp_vars_free(vars); |
| 559 | vars = NULL; |
| 560 | |
| 561 | /* Add one item. */ |
| 562 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var1", "val1")); |
| 563 | assert_int_equal(LY_ARRAY_COUNT(vars), 1); |
| 564 | assert_string_equal(vars[0].name, "var1"); |
| 565 | assert_string_equal(vars[0].value, "val1"); |
| 566 | lyxp_vars_free(vars); |
| 567 | vars = NULL; |
| 568 | |
| 569 | /* Add three items. */ |
| 570 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var1", "val1")); |
| 571 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var2", "val2")); |
| 572 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var3", "val3")); |
| 573 | assert_int_equal(LY_ARRAY_COUNT(vars), 3); |
| 574 | assert_string_equal(vars[0].name, "var1"); |
| 575 | assert_string_equal(vars[0].value, "val1"); |
| 576 | assert_string_equal(vars[1].name, "var2"); |
| 577 | assert_string_equal(vars[1].value, "val2"); |
| 578 | assert_string_equal(vars[2].name, "var3"); |
| 579 | assert_string_equal(vars[2].value, "val3"); |
| 580 | lyxp_vars_free(vars); |
| 581 | vars = NULL; |
| 582 | |
| 583 | /* Change value of a variable. */ |
| 584 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var1", "val1")); |
| 585 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var2", "val2")); |
| 586 | assert_int_equal(LY_SUCCESS, lyxp_vars_set(&vars, "var1", "new_value")); |
| 587 | assert_string_equal(vars[0].name, "var1"); |
| 588 | assert_string_equal(vars[0].value, "new_value"); |
| 589 | assert_string_equal(vars[1].name, "var2"); |
| 590 | assert_string_equal(vars[1].value, "val2"); |
| 591 | lyxp_vars_free(vars); |
| 592 | vars = NULL; |
| 593 | } |
| 594 | |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 595 | static void |
| 596 | test_data_leafref_nodes(void **state) |
| 597 | { |
| 598 | struct lyd_node *tree, *iter; |
Michal Vasko | 17d9cea | 2024-02-09 13:48:40 +0100 | [diff] [blame] | 599 | struct lyd_node_term *target_node = NULL, *leafref_node; |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 600 | const struct lyd_leafref_links_rec *rec; |
| 601 | const char *schema, *data, *value; |
| 602 | |
| 603 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_LEAFREF_LINKING); |
| 604 | |
| 605 | schema = |
| 606 | "module test-data-hash {" |
| 607 | " yang-version 1.1;" |
| 608 | " namespace \"urn:tests:tdh\";" |
| 609 | " prefix t;" |
| 610 | " leaf-list ll {" |
| 611 | " type string;" |
| 612 | " }" |
| 613 | " container c1 {" |
| 614 | " leaf ref1 {" |
| 615 | " type leafref {" |
| 616 | " path \"../../ll\";" |
| 617 | " }" |
| 618 | " }" |
| 619 | " }" |
| 620 | " leaf ref2 {" |
| 621 | " type leafref {" |
| 622 | " path \"../ll\";" |
| 623 | " }" |
| 624 | " }" |
| 625 | "}"; |
| 626 | |
| 627 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); |
| 628 | |
| 629 | data = |
| 630 | "{" |
| 631 | " \"test-data-hash:ll\": [\"qwe\", \"asd\"]," |
| 632 | " \"test-data-hash:c1\": { \"ref1\": \"qwe\"}," |
| 633 | " \"test-data-hash:ref2\": \"asd\"" |
| 634 | "}"; |
| 635 | |
| 636 | /* The run must not crash due to the assert that checks the hash. */ |
| 637 | CHECK_PARSE_LYD_PARAM(data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); |
| 638 | LY_LIST_FOR(tree, iter) { |
| 639 | if (strcmp(iter->schema->name, "ll") == 0) { |
| 640 | value = lyd_get_value(iter); |
| 641 | if (strcmp(value, "asd") == 0) { |
| 642 | target_node = (struct lyd_node_term *)iter; |
| 643 | } |
| 644 | } |
| 645 | if (strcmp(iter->schema->name, "ref2") == 0) { |
| 646 | leafref_node = (struct lyd_node_term *)iter; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | /* verify state after leafref plugin validation */ |
| 651 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node, &rec)); |
| 652 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 653 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 654 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(leafref_node, &rec)); |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 655 | assert_int_equal(1, LY_ARRAY_COUNT(rec->target_nodes)); |
| 656 | assert_ptr_equal(rec->target_nodes[0], target_node); |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 657 | /* value modification of target */ |
| 658 | assert_int_equal(LY_SUCCESS, lyd_change_term((struct lyd_node *)target_node, "ASD")); |
| 659 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(target_node, &rec)); |
| 660 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(leafref_node, &rec)); |
| 661 | /* change back to original value */ |
| 662 | assert_int_equal(LY_SUCCESS, lyd_change_term((struct lyd_node *)target_node, "asd")); |
| 663 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(target_node, &rec)); |
| 664 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(leafref_node, &rec)); |
| 665 | /* linking the whole tree again */ |
| 666 | assert_int_equal(LY_SUCCESS, lyd_leafref_link_node_tree(tree)); |
| 667 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node, &rec)); |
| 668 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 669 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 670 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(leafref_node, &rec)); |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 671 | assert_int_equal(1, LY_ARRAY_COUNT(rec->target_nodes)); |
| 672 | assert_ptr_equal(rec->target_nodes[0], target_node); |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 673 | /* value modification of leafref */ |
| 674 | assert_int_equal(LY_SUCCESS, lyd_change_term((struct lyd_node *)leafref_node, "qwe")); |
| 675 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(target_node, &rec)); |
| 676 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(leafref_node, &rec)); |
| 677 | assert_int_equal(LY_SUCCESS, lyd_change_term((struct lyd_node *)leafref_node, "asd")); |
| 678 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(target_node, &rec)); |
| 679 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(leafref_node, &rec)); |
| 680 | /* linking the whole tree again */ |
| 681 | assert_int_equal(LY_SUCCESS, lyd_leafref_link_node_tree(tree)); |
| 682 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node, &rec)); |
| 683 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 684 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 685 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(leafref_node, &rec)); |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 686 | assert_int_equal(1, LY_ARRAY_COUNT(rec->target_nodes)); |
| 687 | assert_ptr_equal(rec->target_nodes[0], target_node); |
| 688 | /* freeing whole tree */ |
| 689 | lyd_free_all(tree); |
| 690 | } |
| 691 | |
| 692 | static void |
| 693 | test_data_leafref_nodes2(void **state) |
| 694 | { |
| 695 | struct lyd_node *tree, *iter; |
| 696 | const char *schema, *data; |
Michal Vasko | 17d9cea | 2024-02-09 13:48:40 +0100 | [diff] [blame] | 697 | struct lyd_node_term *leafref_node = NULL; |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 698 | const struct lyd_node_term *target_node1, *target_node2; |
| 699 | const struct lyd_leafref_links_rec *rec; |
| 700 | |
| 701 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_LEAFREF_LINKING); |
| 702 | |
| 703 | schema = |
| 704 | "module test-data-hash {" |
| 705 | " yang-version 1.1;" |
| 706 | " namespace \"urn:tests:tdh\";" |
| 707 | " prefix t;" |
| 708 | " list l1 {" |
| 709 | " key \"l1 l2\";" |
| 710 | " leaf l1 {" |
| 711 | " type string;" |
| 712 | " }" |
| 713 | " leaf l2 {" |
| 714 | " type string;" |
| 715 | " }" |
| 716 | " }" |
| 717 | " leaf ref1 {" |
| 718 | " type leafref {" |
| 719 | " path \"../l1/l1\";" |
| 720 | " }" |
| 721 | " }" |
| 722 | " leaf-list ll1 {" |
| 723 | " type string;" |
| 724 | " config false;" |
| 725 | " }" |
| 726 | " leaf ref2 {" |
| 727 | " type leafref {" |
| 728 | " path \"../ll1\";" |
| 729 | " }" |
| 730 | " config false;" |
| 731 | " }" |
| 732 | "}"; |
| 733 | |
| 734 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); |
| 735 | |
| 736 | data = |
| 737 | "{" |
| 738 | " \"test-data-hash:l1\": [" |
| 739 | " {\"l1\": \"A\", \"l2\": \"B\"}," |
| 740 | " {\"l1\": \"A\", \"l2\": \"C\"}" |
| 741 | " ]," |
| 742 | " \"test-data-hash:ref1\": \"A\"," |
| 743 | " \"test-data-hash:ll1\": [\"asd\", \"qwe\", \"asd\"]," |
| 744 | " \"test-data-hash:ref2\": \"asd\"" |
| 745 | "}"; |
| 746 | |
| 747 | /* The run must not crash due to the assert that checks the hash. */ |
| 748 | CHECK_PARSE_LYD_PARAM(data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); |
| 749 | LY_LIST_FOR(tree, iter) { |
| 750 | if (strcmp(iter->schema->name, "ref1") == 0) { |
| 751 | leafref_node = (struct lyd_node_term *)iter; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | /* verify state after leafref plugin validation */ |
| 756 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(leafref_node, &rec)); |
| 757 | assert_int_equal(2, LY_ARRAY_COUNT(rec->target_nodes)); |
| 758 | target_node1 = rec->target_nodes[0]; |
| 759 | target_node2 = rec->target_nodes[1]; |
| 760 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node1, &rec)); |
| 761 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
| 762 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
| 763 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node2, &rec)); |
| 764 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
| 765 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
| 766 | /* value modification of leafref to remove all links*/ |
| 767 | assert_int_equal(LY_SUCCESS, lyd_change_term((struct lyd_node *)leafref_node, "qwe")); |
| 768 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(leafref_node, &rec)); |
| 769 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(target_node1, &rec)); |
| 770 | assert_int_equal(LY_ENOTFOUND, lyd_leafref_get_links(target_node2, &rec)); |
| 771 | /* linking the whole tree again */ |
| 772 | assert_int_equal(LY_SUCCESS, lyd_change_term((struct lyd_node *)leafref_node, "A")); |
| 773 | assert_int_equal(LY_SUCCESS, lyd_leafref_link_node_tree(tree)); |
| 774 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(leafref_node, &rec)); |
| 775 | assert_int_equal(2, LY_ARRAY_COUNT(rec->target_nodes)); |
| 776 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node1, &rec)); |
| 777 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
| 778 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
| 779 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node2, &rec)); |
| 780 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
| 781 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
| 782 | |
| 783 | /* verify duplicated value in leaf-list */ |
| 784 | LY_LIST_FOR(tree, iter) { |
| 785 | if (strcmp(iter->schema->name, "ref2") == 0) { |
| 786 | leafref_node = (struct lyd_node_term *)iter; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(leafref_node, &rec)); |
| 791 | assert_int_equal(2, LY_ARRAY_COUNT(rec->target_nodes)); |
| 792 | target_node1 = rec->target_nodes[0]; |
| 793 | target_node2 = rec->target_nodes[1]; |
| 794 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node1, &rec)); |
| 795 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
| 796 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
| 797 | assert_int_equal(LY_SUCCESS, lyd_leafref_get_links(target_node2, &rec)); |
| 798 | assert_int_equal(1, LY_ARRAY_COUNT(rec->leafref_nodes)); |
| 799 | assert_ptr_equal(rec->leafref_nodes[0], leafref_node); |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 800 | /* freeing whole tree */ |
| 801 | lyd_free_all(tree); |
| 802 | } |
| 803 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 804 | int |
| 805 | main(void) |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 806 | { |
| 807 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 808 | UTEST(test_compare, setup), |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 809 | UTEST(test_compare_diff_ctx, setup), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 810 | UTEST(test_dup, setup), |
| 811 | UTEST(test_target, setup), |
| 812 | UTEST(test_list_pos, setup), |
| 813 | UTEST(test_first_sibling, setup), |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame] | 814 | UTEST(test_find_path, setup), |
aPiecek | 4f07c3e | 2021-06-11 10:53:07 +0200 | [diff] [blame] | 815 | UTEST(test_data_hash, setup), |
aPiecek | df23eee | 2021-10-07 12:21:50 +0200 | [diff] [blame] | 816 | UTEST(test_lyxp_vars), |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 817 | UTEST(test_data_leafref_nodes), |
steweg | 6738895 | 2024-01-25 12:14:50 +0100 | [diff] [blame] | 818 | UTEST(test_data_leafref_nodes2), |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 819 | }; |
| 820 | |
| 821 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 822 | } |