Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 2 | * @file test_tree_schema.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from tress_data.c |
| 5 | * |
| 6 | * Copyright (c) 2018-2019 CESNET, z.s.p.o. |
| 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 | |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 17 | #include "common.h" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 18 | #include "libyang.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;" |
| 48 | " type string {pattern \"\";}" |
| 49 | "}}" |
| 50 | "container cont {" |
| 51 | " list nexthop {min-elements 1; key \"gateway\";" |
| 52 | " leaf gateway {type optional-ip-address;}" |
| 53 | " }" |
| 54 | "}}"; |
| 55 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 56 | UTEST_SETUP; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 57 | |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 58 | UTEST_ADD_MODULE(schema1, LYS_IN_YANG, NULL, NULL); |
| 59 | UTEST_ADD_MODULE(schema2, LYS_IN_YANG, NULL, NULL); |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame^] | 60 | UTEST_ADD_MODULE(schema3, LYS_IN_YANG, NULL, NULL); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 65 | #define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \ |
| 66 | 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] | 67 | |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 68 | #define CHECK_PARSE_LYD_PARAM_CTX(CTX, INPUT, PARSE_OPTION, OUT_NODE) \ |
| 69 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(CTX, INPUT, LYD_XML, PARSE_OPTION, LYD_VALIDATE_PRESENT, &OUT_NODE)); \ |
| 70 | assert_non_null(OUT_NODE); |
| 71 | |
| 72 | #define RECREATE_CTX_WITH_MODULE(CTX, MODULE) \ |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 73 | ly_ctx_destroy(CTX); \ |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 74 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &CTX)); \ |
| 75 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(MODULE, &_UC->in)); \ |
| 76 | assert_int_equal(LY_SUCCESS, lys_parse(CTX, _UC->in, LYS_IN_YANG, NULL, NULL)); \ |
| 77 | ly_in_free(_UC->in, 0); |
| 78 | |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 79 | static void |
| 80 | test_compare(void **state) |
| 81 | { |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 82 | struct lyd_node *tree1, *tree2; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 83 | const char *data1; |
| 84 | const char *data2; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 85 | |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 86 | assert_int_equal(LY_SUCCESS, lyd_compare_single(NULL, NULL, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 87 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 88 | data1 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>"; |
| 89 | data2 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>y</c></l1>"; |
| 90 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 91 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 92 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 93 | 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] | 94 | 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] | 95 | lyd_free_all(tree1); |
| 96 | lyd_free_all(tree2); |
| 97 | |
| 98 | data1 = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
| 99 | 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] | 100 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 101 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 102 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, 0)); |
| 103 | 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] | 104 | lyd_free_all(tree1); |
| 105 | lyd_free_all(tree2); |
| 106 | |
| 107 | data1 = "<ll xmlns=\"urn:tests:a\">a</ll><ll xmlns=\"urn:tests:a\">b</ll>"; |
| 108 | data2 = "<ll xmlns=\"urn:tests:a\">b</ll>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 109 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 110 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 111 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 112 | assert_int_equal(LY_ENOT, lyd_compare_single(NULL, tree2, 0)); |
| 113 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, NULL, 0)); |
| 114 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 115 | lyd_free_all(tree1); |
| 116 | lyd_free_all(tree2); |
| 117 | |
| 118 | data1 = "<c xmlns=\"urn:tests:a\"><x>x</x></c>"; |
| 119 | data2 = "<c xmlns=\"urn:tests:a\"><x>y</x></c>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 120 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 121 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 122 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 123 | 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] | 124 | lyd_free_all(tree1); |
| 125 | lyd_free_all(tree2); |
| 126 | |
| 127 | data1 = "<c xmlns=\"urn:tests:a\"><x>x</x></c>"; |
| 128 | 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] | 129 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 130 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 131 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 132 | 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] | 133 | lyd_free_all(tree1); |
| 134 | lyd_free_all(tree2); |
| 135 | |
| 136 | data1 = "<any xmlns=\"urn:tests:a\"><x>x</x></any>"; |
| 137 | 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] | 138 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
| 139 | CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 140 | 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] | 141 | lyd_free_all(tree1); |
| 142 | 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] | 143 | CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 144 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 145 | lyd_free_all(tree1); |
| 146 | lyd_free_all(tree2); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 149 | static void |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 150 | test_compare_diff_ctx(void **state) |
| 151 | { |
| 152 | struct lyd_node *tree1, *tree2; |
| 153 | const char *data1, *data2; |
| 154 | struct ly_ctx *ctx2 = NULL; |
| 155 | const char *module; |
| 156 | |
| 157 | /* create second context with the same schema */ |
| 158 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 159 | "revision 2014-05-08;" |
| 160 | "list l2 {config false;" |
| 161 | " container c{leaf x {type string;}}" |
| 162 | "}}"; |
| 163 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 164 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 165 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 166 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 167 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 168 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION)); |
| 169 | lyd_free_all(tree1); |
| 170 | lyd_free_all(tree2); |
| 171 | |
| 172 | /* recreate second context with schema that has a different name */ |
| 173 | module = "module c {namespace urn:tests:c;prefix c;yang-version 1.1;" |
| 174 | "revision 2014-05-08;" |
| 175 | "list l2 {config false;" |
| 176 | " container c{leaf x {type string;}}" |
| 177 | "}}"; |
| 178 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 179 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 180 | data2 = "<l2 xmlns=\"urn:tests:c\"><c><x>b</x></c></l2>"; |
| 181 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 182 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 183 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 184 | lyd_free_all(tree1); |
| 185 | lyd_free_all(tree2); |
| 186 | |
| 187 | /* recreate second context with schema that has a different revision */ |
| 188 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 189 | "revision 2015-05-08;" |
| 190 | "list l2 {config false;" |
| 191 | " container c{leaf x {type string;}}" |
| 192 | "}}"; |
| 193 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 194 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 195 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 196 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 197 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 198 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 199 | lyd_free_all(tree1); |
| 200 | lyd_free_all(tree2); |
| 201 | |
| 202 | /* recreate second context with schema that has no revision */ |
| 203 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 204 | "list l2 {config false;" |
| 205 | " container c{leaf x {type string;}}" |
| 206 | "}}"; |
| 207 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 208 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 209 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 210 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 211 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 212 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 213 | lyd_free_all(tree1); |
| 214 | lyd_free_all(tree2); |
| 215 | |
| 216 | /* recreate second context with schema that has a different parent nodetype */ |
| 217 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 218 | "revision 2014-05-08;" |
| 219 | "container l2 {config false;" |
| 220 | " container c{leaf x {type string;}}" |
| 221 | "}}"; |
| 222 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 223 | data1 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 224 | data2 = "<l2 xmlns=\"urn:tests:b\"><c><x>b</x></c></l2>"; |
| 225 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, 0, tree1); |
| 226 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, 0, tree2); |
| 227 | assert_int_equal(LY_ENOT, lyd_compare_single(lyd_child(lyd_child(tree1)), lyd_child(lyd_child(tree2)), 0)); |
| 228 | lyd_free_all(tree1); |
| 229 | lyd_free_all(tree2); |
| 230 | |
| 231 | /* recreate second context with the same opaq data nodes */ |
| 232 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 233 | "revision 2014-05-08;" |
| 234 | "anydata any {config false;}" |
| 235 | "}"; |
| 236 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 237 | data1 = "<any xmlns=\"urn:tests:b\" xmlns:aa=\"urn:tests:b\"><x>aa:x</x></any>"; |
| 238 | data2 = "<any xmlns=\"urn:tests:b\" xmlns:bb=\"urn:tests:b\"><x>bb:x</x></any>"; |
| 239 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, LYD_PARSE_ONLY, tree1); |
| 240 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, LYD_PARSE_ONLY, tree2); |
| 241 | assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0)); |
| 242 | lyd_free_all(tree1); |
| 243 | lyd_free_all(tree2); |
| 244 | |
| 245 | /* recreate second context with the different opaq data node value */ |
| 246 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 247 | "revision 2014-05-08;" |
| 248 | "anydata any {config false;}" |
| 249 | "}"; |
| 250 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 251 | data1 = "<any xmlns=\"urn:tests:b\" xmlns:aa=\"urn:tests:b\"><x>aa:x</x></any>"; |
| 252 | data2 = "<any xmlns=\"urn:tests:b\" xmlns:bb=\"urn:tests:b\"><x>bb:y</x></any>"; |
| 253 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, LYD_PARSE_ONLY, tree1); |
| 254 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, LYD_PARSE_ONLY, tree2); |
| 255 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 256 | lyd_free_all(tree1); |
| 257 | lyd_free_all(tree2); |
| 258 | |
| 259 | /* recreate second context with the wrong prefix in opaq data node value */ |
| 260 | module = "module b {namespace urn:tests:b;prefix b;yang-version 1.1;" |
| 261 | "revision 2014-05-08;" |
| 262 | "anydata any {config false;}" |
| 263 | "}"; |
| 264 | RECREATE_CTX_WITH_MODULE(ctx2, module); |
| 265 | data1 = "<any xmlns=\"urn:tests:b\" xmlns:aa=\"urn:tests:b\"><x>aa:x</x></any>"; |
| 266 | data2 = "<any xmlns=\"urn:tests:b\" xmlns:bb=\"urn:tests:b\"><x>cc:x</x></any>"; |
| 267 | CHECK_PARSE_LYD_PARAM_CTX(UTEST_LYCTX, data1, LYD_PARSE_ONLY, tree1); |
| 268 | CHECK_PARSE_LYD_PARAM_CTX(ctx2, data2, LYD_PARSE_ONLY, tree2); |
| 269 | assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0)); |
| 270 | lyd_free_all(tree1); |
| 271 | lyd_free_all(tree2); |
| 272 | |
| 273 | /* clean up */ |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 274 | ly_ctx_destroy(ctx2); |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 275 | _UC->in = NULL; |
| 276 | } |
| 277 | |
| 278 | static void |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 279 | test_dup(void **state) |
| 280 | { |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 281 | struct lyd_node *tree1, *tree2; |
| 282 | const char *result; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 283 | const char *data; |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 284 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 285 | data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>"; |
| 286 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 287 | 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] | 288 | 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] | 289 | lyd_free_all(tree1); |
| 290 | lyd_free_all(tree2); |
| 291 | |
| 292 | data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>"; |
| 293 | 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] | 294 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 295 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 296 | lyd_free_all(tree1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 297 | CHECK_PARSE_LYD(result, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 298 | 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] | 299 | lyd_free_all(tree1); |
| 300 | lyd_free_all(tree2); |
| 301 | |
| 302 | data = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>"; |
| 303 | 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] | 304 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 305 | 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] | 306 | 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] | 307 | lyd_free_all(tree2); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 308 | 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] | 309 | lyd_free_all(tree1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 310 | CHECK_PARSE_LYD(result, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 311 | 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] | 312 | lyd_free_all(tree2); |
| 313 | |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 314 | 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] | 315 | lyd_free_all(tree1); |
| 316 | result = "<l2 xmlns=\"urn:tests:a\"/>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 317 | 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] | 318 | 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] | 319 | lyd_free_all(tree1); |
| 320 | lyd_free_all(tree2); |
| 321 | |
| 322 | 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] | 323 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 324 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2)); |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 325 | 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] | 326 | lyd_free_all(tree1); |
| 327 | lyd_free_all(tree2); |
| 328 | |
| 329 | 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] | 330 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 331 | assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)((struct lyd_node_inner *)tree1->next)->child)->child, NULL, |
| 332 | LYD_DUP_WITH_PARENTS, &tree2)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 333 | int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM; |
| 334 | |
| 335 | 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] | 336 | 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] | 337 | LYD_COMPARE_FULL_RECURSION)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 338 | lyd_free_all(tree1); |
| 339 | lyd_free_all(tree2); |
| 340 | |
| 341 | 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] | 342 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 343 | assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev, NULL, |
| 344 | LYD_DUP_WITH_PARENTS, &tree2)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 345 | flag = LYS_CONFIG_W | LYS_SET_ENUM; |
| 346 | 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] | 347 | 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] | 348 | lyd_free_all(tree1); |
| 349 | lyd_free_all(tree2); |
| 350 | |
| 351 | 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] | 352 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 353 | assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, 0, &tree2)); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 354 | assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)((struct lyd_node_inner *)tree1->next)->child)->child, |
| 355 | (struct lyd_node_inner *)tree2, LYD_DUP_WITH_PARENTS, NULL)); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 356 | 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] | 357 | lyd_free_all(tree1); |
| 358 | lyd_free_all(tree2); |
| 359 | |
| 360 | /* invalid */ |
| 361 | 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] | 362 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 363 | assert_int_equal(LY_EINVAL, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev, |
| 364 | (struct lyd_node_inner *)tree1->next, LYD_DUP_WITH_PARENTS, NULL)); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 365 | lyd_free_all(tree1); |
Radek Krejci | 22ebdba | 2019-07-25 13:59:43 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 368 | static void |
| 369 | test_target(void **state) |
| 370 | { |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 371 | const struct lyd_node_term *term; |
| 372 | struct lyd_node *tree; |
| 373 | struct lyxp_expr *exp; |
| 374 | struct ly_path *path; |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 375 | const char *path_str = "/a:l2[2]/c/d[3]"; |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 376 | const char *data = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 377 | "<l2 xmlns=\"urn:tests:a\"><c>" |
| 378 | " <d>a</d>" |
| 379 | " </c></l2>" |
| 380 | "<l2 xmlns=\"urn:tests:a\"><c>" |
| 381 | " <d>a</d>" |
| 382 | " <d>b</d>" |
| 383 | " <d>b</d>" |
| 384 | " <d>c</d>" |
| 385 | "</c></l2>" |
| 386 | "<l2 xmlns=\"urn:tests:a\"><c>" |
| 387 | "</c></l2>"; |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 388 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 389 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 390 | assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path_str, strlen(path_str), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_FALSE, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 391 | LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_SIMPLE, &exp)); |
Radek Krejci | d5d3743 | 2021-03-12 13:46:40 +0100 | [diff] [blame] | 392 | assert_int_equal(LY_SUCCESS, ly_path_compile(UTEST_LYCTX, NULL, NULL, NULL, exp, LY_PATH_LREF_FALSE, LY_PATH_OPER_INPUT, |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 393 | LY_PATH_TARGET_SINGLE, LY_VALUE_JSON, NULL, NULL, &path)); |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 394 | term = lyd_target(path, tree); |
| 395 | |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 396 | 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] | 397 | |
| 398 | 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] | 399 | assert_string_equal(lyd_get_value(&term->node), "b"); |
| 400 | assert_string_equal(lyd_get_value(term->prev), "b"); |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 401 | |
| 402 | lyd_free_all(tree); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 403 | ly_path_free(UTEST_LYCTX, path); |
| 404 | lyxp_expr_free(UTEST_LYCTX, exp); |
Michal Vasko | 38c2ba7 | 2020-07-27 14:46:59 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 407 | static void |
| 408 | test_list_pos(void **state) |
| 409 | { |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 410 | const char *data; |
| 411 | struct lyd_node *tree; |
| 412 | |
| 413 | data = "<bar xmlns=\"urn:tests:a\">test</bar>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 414 | "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b></l1>" |
| 415 | "<l1 xmlns=\"urn:tests:a\"><a>two</a><b>two</b></l1>" |
| 416 | "<foo xmlns=\"urn:tests:a\">test</foo>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 417 | 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] | 418 | assert_int_equal(0, lyd_list_pos(tree)); |
| 419 | assert_int_equal(1, lyd_list_pos(tree->next)); |
| 420 | assert_int_equal(2, lyd_list_pos(tree->next->next)); |
| 421 | assert_int_equal(0, lyd_list_pos(tree->next->next->next)); |
| 422 | lyd_free_all(tree); |
| 423 | |
| 424 | data = "<ll xmlns=\"urn:tests:a\">one</ll>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 425 | "<ll xmlns=\"urn:tests:a\">two</ll>" |
| 426 | "<ll xmlns=\"urn:tests:a\">three</ll>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 427 | 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] | 428 | assert_int_equal(1, lyd_list_pos(tree)); |
| 429 | assert_int_equal(2, lyd_list_pos(tree->next)); |
| 430 | assert_int_equal(3, lyd_list_pos(tree->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 | "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b></l1>" |
| 435 | "<ll xmlns=\"urn:tests:a\">two</ll>" |
| 436 | "<l1 xmlns=\"urn:tests:a\"><a>two</a><b>two</b></l1>" |
| 437 | "<ll xmlns=\"urn:tests:a\">three</ll>" |
| 438 | "<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] | 439 | 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] | 440 | assert_string_equal("l1", tree->schema->name); |
| 441 | assert_int_equal(1, lyd_list_pos(tree)); |
| 442 | assert_int_equal(2, lyd_list_pos(tree->next)); |
| 443 | assert_int_equal(3, lyd_list_pos(tree->next->next)); |
| 444 | assert_string_equal("ll", tree->next->next->next->schema->name); |
| 445 | assert_int_equal(1, lyd_list_pos(tree->next->next->next)); |
| 446 | assert_int_equal(2, lyd_list_pos(tree->next->next->next->next)); |
| 447 | assert_int_equal(3, lyd_list_pos(tree->next->next->next->next->next)); |
| 448 | lyd_free_all(tree); |
Radek Krejci | ca98914 | 2020-11-05 11:32:22 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 451 | static void |
| 452 | test_first_sibling(void **state) |
| 453 | { |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 454 | const char *data; |
| 455 | struct lyd_node *tree; |
| 456 | struct lyd_node_inner *parent; |
| 457 | |
| 458 | data = "<bar xmlns=\"urn:tests:a\">test</bar>" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 459 | "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>one</c></l1>" |
| 460 | "<foo xmlns=\"urn:tests:a\">test</foo>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 461 | 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] | 462 | assert_ptr_equal(tree, lyd_first_sibling(tree->next)); |
| 463 | assert_ptr_equal(tree, lyd_first_sibling(tree)); |
| 464 | assert_ptr_equal(tree, lyd_first_sibling(tree->prev)); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 465 | parent = (struct lyd_node_inner *)tree->next; |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 466 | assert_int_equal(LYS_LIST, parent->schema->nodetype); |
| 467 | assert_ptr_equal(parent->child, lyd_first_sibling(parent->child->next)); |
| 468 | assert_ptr_equal(parent->child, lyd_first_sibling(parent->child)); |
| 469 | assert_ptr_equal(parent->child, lyd_first_sibling(parent->child->prev)); |
| 470 | lyd_free_all(tree); |
Radek Krejci | 4233f9b | 2020-11-05 12:38:35 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame^] | 473 | static void |
| 474 | test_find_path(void **state) |
| 475 | { |
| 476 | struct lyd_node *root; |
| 477 | const struct lys_module *mod; |
| 478 | |
| 479 | mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "c"); |
| 480 | assert_non_null(mod); |
| 481 | |
| 482 | assert_int_equal(LY_SUCCESS, lyd_new_inner(NULL, mod, "cont", 0, &root)); |
| 483 | assert_int_equal(LY_SUCCESS, lyd_new_path(root, NULL, "/c:cont/nexthop[gateway='10.0.0.1']", NULL, LYD_NEW_PATH_UPDATE, NULL)); |
| 484 | assert_int_equal(LY_SUCCESS, lyd_new_path(root, NULL, "/c:cont/nexthop[gateway='2100::1']", NULL, LYD_NEW_PATH_UPDATE, NULL)); |
| 485 | |
| 486 | assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/nexthop[gateway='10.0.0.1']", 0, NULL)); |
| 487 | assert_int_equal(LY_SUCCESS, lyd_find_path(root, "/c:cont/nexthop[gateway='2100::1']", 0, NULL)); |
| 488 | lyd_free_all(root); |
| 489 | } |
| 490 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 491 | int |
| 492 | main(void) |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 493 | { |
| 494 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 495 | UTEST(test_compare, setup), |
aPiecek | 2425220 | 2021-03-30 12:23:32 +0200 | [diff] [blame] | 496 | UTEST(test_compare_diff_ctx, setup), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 497 | UTEST(test_dup, setup), |
| 498 | UTEST(test_target, setup), |
| 499 | UTEST(test_list_pos, setup), |
| 500 | UTEST(test_first_sibling, setup), |
Michal Vasko | 6b669ff | 2021-04-30 16:25:36 +0200 | [diff] [blame^] | 501 | UTEST(test_find_path, setup), |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 502 | }; |
| 503 | |
| 504 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 505 | } |