Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file test_diff.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 5 | * @brief tests for lyd_diff() |
| 6 | * |
| 7 | * Copyright (c) 2020 CESNET, z.s.p.o. |
| 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 15 | #define _UTEST_MAIN_ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 16 | #include "utests.h" |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 17 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 18 | #include "libyang.h" |
| 19 | |
| 20 | #define CHECK_PARSE_LYD(INPUT, MODEL) \ |
| 21 | CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, MODEL) |
| 22 | |
| 23 | #define CHECK_LYD_STRING(IN_MODEL, TEXT) \ |
| 24 | CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS) |
| 25 | |
| 26 | #define CHECK_PARSE_LYD_DIFF(INPUT_1, INPUT_2, OUT_MODEL) \ |
| 27 | assert_int_equal(LY_SUCCESS, lyd_diff_siblings(INPUT_1, INPUT_2, 0, &OUT_MODEL));\ |
| 28 | assert_non_null(OUT_MODEL) |
| 29 | |
| 30 | #define TEST_DIFF_3(XML_1, XML_2, XML_3, DIFF_1, DIFF_2, MERGE) \ |
| 31 | { \ |
| 32 | /*decladation*/\ |
| 33 | struct lyd_node *model_1;\ |
| 34 | struct lyd_node *model_2;\ |
| 35 | struct lyd_node *model_3;\ |
| 36 | /*create*/\ |
| 37 | CHECK_PARSE_LYD(XML_1, model_1);\ |
| 38 | CHECK_PARSE_LYD(XML_2, model_2);\ |
| 39 | CHECK_PARSE_LYD(XML_3, model_3);\ |
| 40 | /* diff1 */ \ |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 41 | struct lyd_node *diff1;\ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 42 | CHECK_PARSE_LYD_DIFF(model_1, model_2, diff1); \ |
| 43 | CHECK_LYD_STRING(diff1, DIFF_1); \ |
| 44 | assert_int_equal(lyd_diff_apply_all(&model_1, diff1), LY_SUCCESS); \ |
| 45 | CHECK_LYD(model_1, model_2); \ |
| 46 | /* diff2 */ \ |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 47 | struct lyd_node *diff2;\ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 48 | CHECK_PARSE_LYD_DIFF(model_2, model_3, diff2); \ |
| 49 | CHECK_LYD_STRING(diff2, DIFF_2); \ |
| 50 | assert_int_equal(lyd_diff_apply_all(&model_2, diff2), LY_SUCCESS);\ |
| 51 | CHECK_LYD(model_2, model_3);\ |
| 52 | /* merge */ \ |
| 53 | assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS);\ |
| 54 | CHECK_LYD_STRING(diff1, MERGE); \ |
| 55 | /* CREAR ENV */ \ |
| 56 | lyd_free_all(model_1);\ |
| 57 | lyd_free_all(model_2);\ |
| 58 | lyd_free_all(model_3);\ |
| 59 | lyd_free_all(diff1);\ |
| 60 | lyd_free_all(diff2);\ |
| 61 | } |
| 62 | |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 63 | const char *schema1 = |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 64 | "module defaults {\n" |
| 65 | " yang-version 1.1;\n" |
| 66 | " namespace \"urn:libyang:tests:defaults\";\n" |
| 67 | " prefix df;\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 68 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 69 | " feature unhide;\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 70 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 71 | " typedef defint32 {\n" |
| 72 | " type int32;\n" |
| 73 | " default \"42\";\n" |
| 74 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 75 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 76 | " leaf hiddenleaf {\n" |
| 77 | " if-feature \"unhide\";\n" |
| 78 | " type int32;\n" |
| 79 | " default \"42\";\n" |
| 80 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 81 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 82 | " container df {\n" |
| 83 | " leaf foo {\n" |
| 84 | " type defint32;\n" |
| 85 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 86 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 87 | " leaf hiddenleaf {\n" |
| 88 | " if-feature \"unhide\";\n" |
| 89 | " type int32;\n" |
| 90 | " default \"42\";\n" |
| 91 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 92 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 93 | " container bar {\n" |
| 94 | " presence \"\";\n" |
| 95 | " leaf hi {\n" |
| 96 | " type int32;\n" |
| 97 | " default \"42\";\n" |
| 98 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 99 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 100 | " leaf ho {\n" |
| 101 | " type int32;\n" |
| 102 | " mandatory true;\n" |
| 103 | " }\n" |
| 104 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 105 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 106 | " leaf-list llist {\n" |
| 107 | " type defint32;\n" |
| 108 | " ordered-by user;\n" |
| 109 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 110 | "" |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 111 | " list ul {\n" |
| 112 | " key \"l1\";\n" |
| 113 | " ordered-by user;\n" |
| 114 | " leaf l1 {\n" |
| 115 | " type string;\n" |
| 116 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 117 | "" |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 118 | " leaf l2 {\n" |
| 119 | " type int32;\n" |
| 120 | " }\n" |
| 121 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 122 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 123 | " leaf-list dllist {\n" |
| 124 | " type uint8;\n" |
| 125 | " default \"1\";\n" |
| 126 | " default \"2\";\n" |
| 127 | " default \"3\";\n" |
| 128 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 129 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 130 | " list list {\n" |
| 131 | " key \"name\";\n" |
| 132 | " leaf name {\n" |
| 133 | " type string;\n" |
| 134 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 135 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 136 | " leaf value {\n" |
| 137 | " type int32;\n" |
| 138 | " default \"42\";\n" |
| 139 | " }\n" |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 140 | " list list2 {\n" |
| 141 | " key \"name2\";\n" |
| 142 | " leaf name2 {\n" |
| 143 | " type string;\n" |
| 144 | " }\n" |
| 145 | " leaf value2 {\n" |
| 146 | " type int32;\n" |
| 147 | " }\n" |
| 148 | " }\n" |
| 149 | " }\n"; |
| 150 | const char *schema2 = |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 151 | " choice select {\n" |
| 152 | " default \"a\";\n" |
| 153 | " case a {\n" |
| 154 | " choice a {\n" |
| 155 | " leaf a1 {\n" |
| 156 | " type int32;\n" |
| 157 | " default \"42\";\n" |
| 158 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 159 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 160 | " leaf a2 {\n" |
| 161 | " type int32;\n" |
| 162 | " default \"24\";\n" |
| 163 | " }\n" |
| 164 | " }\n" |
| 165 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 166 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 167 | " leaf b {\n" |
| 168 | " type string;\n" |
| 169 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 170 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 171 | " container c {\n" |
| 172 | " presence \"\";\n" |
| 173 | " leaf x {\n" |
| 174 | " type int32;\n" |
| 175 | " default \"42\";\n" |
| 176 | " }\n" |
| 177 | " }\n" |
| 178 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 179 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 180 | " choice select2 {\n" |
| 181 | " default \"s2b\";\n" |
| 182 | " leaf s2a {\n" |
| 183 | " type int32;\n" |
| 184 | " default \"42\";\n" |
| 185 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 186 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 187 | " case s2b {\n" |
| 188 | " choice s2b {\n" |
| 189 | " default \"b1\";\n" |
| 190 | " case b1 {\n" |
| 191 | " leaf b1_1 {\n" |
| 192 | " type int32;\n" |
| 193 | " default \"42\";\n" |
| 194 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 195 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 196 | " leaf b1_2 {\n" |
| 197 | " type string;\n" |
| 198 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 199 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 200 | " leaf b1_status {\n" |
| 201 | " type int32;\n" |
| 202 | " default \"42\";\n" |
| 203 | " config false;\n" |
| 204 | " }\n" |
| 205 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 206 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 207 | " leaf b2 {\n" |
| 208 | " type int32;\n" |
| 209 | " default \"42\";\n" |
| 210 | " }\n" |
| 211 | " }\n" |
| 212 | " }\n" |
| 213 | " }\n" |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 214 | " list kl {\n" |
| 215 | " config \"false\";\n" |
| 216 | " leaf l1 {\n" |
| 217 | " type string;\n" |
| 218 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 219 | "" |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 220 | " leaf l2 {\n" |
| 221 | " type int32;\n" |
| 222 | " }\n" |
| 223 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 224 | "" |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 225 | " leaf-list kll {\n" |
| 226 | " config \"false\";\n" |
| 227 | " type string;\n" |
| 228 | " }\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 229 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 230 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 231 | " container hidden {\n" |
| 232 | " leaf foo {\n" |
| 233 | " type int32;\n" |
| 234 | " default \"42\";\n" |
| 235 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 236 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 237 | " leaf baz {\n" |
| 238 | " type int32;\n" |
| 239 | " default \"42\";\n" |
| 240 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 241 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 242 | " leaf papa {\n" |
| 243 | " type int32;\n" |
| 244 | " default \"42\";\n" |
| 245 | " config false;\n" |
| 246 | " }\n" |
| 247 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 248 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 249 | " rpc rpc1 {\n" |
| 250 | " input {\n" |
| 251 | " leaf inleaf1 {\n" |
| 252 | " type string;\n" |
| 253 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 254 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 255 | " leaf inleaf2 {\n" |
| 256 | " type string;\n" |
| 257 | " default \"def1\";\n" |
| 258 | " }\n" |
| 259 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 260 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 261 | " output {\n" |
| 262 | " leaf outleaf1 {\n" |
| 263 | " type string;\n" |
| 264 | " default \"def2\";\n" |
| 265 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 266 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 267 | " leaf outleaf2 {\n" |
| 268 | " type string;\n" |
| 269 | " }\n" |
| 270 | " }\n" |
| 271 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 272 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 273 | " notification notif {\n" |
| 274 | " leaf ntfleaf1 {\n" |
| 275 | " type string;\n" |
| 276 | " default \"def3\";\n" |
| 277 | " }\n" |
Michal Vasko | 22e0f3a | 2021-09-22 12:19:23 +0200 | [diff] [blame] | 278 | "" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 279 | " leaf ntfleaf2 {\n" |
| 280 | " type string;\n" |
| 281 | " }\n" |
| 282 | " }\n" |
| 283 | "}\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 284 | |
| 285 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 286 | setup(void **state) |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 287 | { |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 288 | char *schema; |
| 289 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 290 | UTEST_SETUP; |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 291 | |
| 292 | /* create one schema, longer than 4095 chars */ |
| 293 | schema = malloc(strlen(schema1) + strlen(schema2) + 1); |
| 294 | strcpy(schema, schema1); |
| 295 | strcat(schema, schema2); |
| 296 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 297 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 298 | free(schema); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static void |
| 304 | test_invalid(void **state) |
| 305 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 306 | (void) state; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 307 | const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\"><foo>42</foo></df>"; |
| 308 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 309 | struct lyd_node *model_1; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 310 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 311 | CHECK_PARSE_LYD(xml, model_1); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 312 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 313 | struct lyd_node *diff = NULL; |
| 314 | |
| 315 | assert_int_equal(lyd_diff_siblings(model_1, lyd_child(model_1), 0, &diff), LY_EINVAL); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 316 | assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, NULL), LY_EINVAL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 317 | |
| 318 | lyd_free_all(model_1); |
| 319 | lyd_free_all(diff); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static void |
| 323 | test_same(void **state) |
| 324 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 325 | (void) state; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 326 | const char *xml = |
| 327 | "<nacm xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-acm\">\n" |
| 328 | " <enable-nacm>true</enable-nacm>\n" |
| 329 | " <read-default>permit</read-default>\n" |
| 330 | " <write-default>deny</write-default>\n" |
| 331 | " <exec-default>permit</exec-default>\n" |
| 332 | " <enable-external-groups>true</enable-external-groups>\n" |
| 333 | "</nacm><df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 334 | " <foo>42</foo><b1_1>42</b1_1>\n" |
| 335 | "</df><hidden xmlns=\"urn:libyang:tests:defaults\">\n" |
| 336 | " <foo>42</foo><baz>42</baz></hidden>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 337 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 338 | struct lyd_node *model_1; |
| 339 | struct lyd_node *model_2; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 340 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 341 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG)); |
| 342 | assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-acm", "2018-02-14", NULL)); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 343 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 344 | CHECK_PARSE_LYD(xml, model_1); |
| 345 | CHECK_PARSE_LYD(xml, model_2); |
| 346 | |
| 347 | struct lyd_node *diff = NULL; |
| 348 | |
| 349 | assert_int_equal(lyd_diff_siblings(model_1, model_2, 0, &diff), LY_SUCCESS); |
| 350 | assert_null(diff); |
| 351 | assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS); |
| 352 | CHECK_LYD(model_1, model_2); |
| 353 | |
| 354 | lyd_free_all(model_1); |
| 355 | lyd_free_all(model_2); |
| 356 | lyd_free_all(diff); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static void |
| 360 | test_empty1(void **state) |
| 361 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 362 | (void) state; |
| 363 | const char *xml_in = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 364 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 365 | " <foo>42</foo>\n" |
| 366 | " <b1_1>42</b1_1>\n" |
| 367 | "</df>\n" |
| 368 | "<hidden xmlns=\"urn:libyang:tests:defaults\">\n" |
| 369 | " <foo>42</foo>\n" |
| 370 | " <baz>42</baz>\n" |
| 371 | "</hidden>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 372 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 373 | struct lyd_node *model_1 = NULL; |
| 374 | struct lyd_node *model_2; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 375 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 376 | CHECK_PARSE_LYD(xml_in, model_2); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 377 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 378 | struct lyd_node *diff; |
| 379 | |
| 380 | CHECK_PARSE_LYD_DIFF(model_1, model_2, diff); |
| 381 | CHECK_LYD_STRING(diff, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 382 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n" |
| 383 | " <foo>42</foo>\n" |
| 384 | " <b1_1>42</b1_1>\n" |
| 385 | "</df>\n" |
| 386 | "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n" |
| 387 | " <foo>42</foo>\n" |
| 388 | " <baz>42</baz>\n" |
| 389 | "</hidden>\n"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 390 | assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS); |
| 391 | CHECK_LYD(model_1, model_2); |
| 392 | |
| 393 | lyd_free_all(model_1); |
| 394 | lyd_free_all(model_2); |
| 395 | lyd_free_all(diff); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static void |
| 399 | test_empty2(void **state) |
| 400 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 401 | (void) state; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 402 | const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 403 | " <foo>42</foo>\n" |
| 404 | " <b1_1>42</b1_1>\n" |
| 405 | "</df><hidden xmlns=\"urn:libyang:tests:defaults\">\n" |
| 406 | " <foo>42</foo>\n" |
| 407 | " <baz>42</baz>\n" |
| 408 | "</hidden>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 409 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 410 | struct lyd_node *model_1; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 411 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 412 | CHECK_PARSE_LYD(xml, model_1); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 413 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 414 | struct lyd_node *diff; |
| 415 | |
| 416 | CHECK_PARSE_LYD_DIFF(model_1, NULL, diff); |
| 417 | CHECK_LYD_STRING(diff, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 418 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n" |
| 419 | " <foo>42</foo>\n" |
| 420 | " <b1_1>42</b1_1>\n" |
| 421 | "</df>\n" |
| 422 | "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n" |
| 423 | " <foo>42</foo>\n" |
| 424 | " <baz>42</baz>\n" |
| 425 | "</hidden>\n"); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 426 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 427 | assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS); |
| 428 | assert_ptr_equal(model_1, NULL); |
| 429 | |
| 430 | lyd_free_all(diff); |
| 431 | lyd_free_all(model_1); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void |
| 435 | test_empty_nested(void **state) |
| 436 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 437 | (void) state; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 438 | const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\"><foo>42</foo></df>"; |
| 439 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 440 | struct lyd_node *model_1; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 441 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 442 | CHECK_PARSE_LYD(xml, model_1); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 443 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 444 | struct lyd_node *diff = NULL; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 445 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 446 | assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, &diff), LY_SUCCESS); |
| 447 | assert_null(diff); |
| 448 | |
| 449 | struct lyd_node *diff1; |
| 450 | |
| 451 | CHECK_PARSE_LYD_DIFF(NULL, lyd_child(model_1), diff1); |
| 452 | CHECK_LYD_STRING(diff1, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 453 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 454 | " <foo yang:operation=\"create\">42</foo>\n" |
| 455 | "</df>\n"); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 456 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 457 | struct lyd_node *diff2; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 458 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 459 | CHECK_PARSE_LYD_DIFF(lyd_child(model_1), NULL, diff2); |
| 460 | CHECK_LYD_STRING(diff2, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 461 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 462 | " <foo yang:operation=\"delete\">42</foo>\n" |
| 463 | "</df>\n"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 464 | |
| 465 | lyd_free_all(model_1); |
| 466 | lyd_free_all(diff1); |
| 467 | lyd_free_all(diff2); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static void |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 471 | test_delete_merge(void **state) |
| 472 | { |
| 473 | (void) state; |
| 474 | struct lyd_node *diff1, *diff2; |
| 475 | const char *xml1 = |
| 476 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 477 | " <list>\n" |
| 478 | " <name>a</name>\n" |
| 479 | " <list2 yang:operation=\"delete\">\n" |
| 480 | " <name2>a</name2>\n" |
| 481 | " </list2>\n" |
| 482 | " </list>\n" |
| 483 | "</df>\n"; |
| 484 | const char *xml2 = |
| 485 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 486 | " <list yang:operation=\"delete\">\n" |
| 487 | " <name>a</name>\n" |
| 488 | " </list>\n" |
| 489 | "</df>\n"; |
| 490 | const char *xml_merge = |
| 491 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 492 | " <list yang:operation=\"delete\">\n" |
| 493 | " <name>a</name>\n" |
| 494 | " <list2 yang:operation=\"delete\">\n" |
| 495 | " <name2>a</name2>\n" |
| 496 | " </list2>\n" |
| 497 | " </list>\n" |
| 498 | "</df>\n"; |
| 499 | |
| 500 | CHECK_PARSE_LYD(xml1, diff1); |
| 501 | CHECK_PARSE_LYD(xml2, diff2); |
| 502 | |
| 503 | assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS); |
| 504 | CHECK_LYD_STRING(diff1, xml_merge); |
| 505 | |
| 506 | lyd_free_all(diff1); |
| 507 | lyd_free_all(diff2); |
| 508 | } |
| 509 | |
| 510 | static void |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 511 | test_leaf(void **state) |
| 512 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 513 | (void) state; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 514 | const char *xml1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 515 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 516 | " <foo>42</foo>\n" |
| 517 | "</df>\n" |
| 518 | "<hidden xmlns=\"urn:libyang:tests:defaults\">\n" |
| 519 | " <foo>42</foo>\n" |
| 520 | " <baz>42</baz>\n" |
| 521 | "</hidden>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 522 | const char *xml2 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 523 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 524 | " <foo>41</foo>\n" |
| 525 | " <b1_1>42</b1_1>\n" |
| 526 | "</df>\n"; |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 527 | const char *xml3 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 528 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 529 | " <foo>40</foo>\n" |
| 530 | "</df>\n" |
| 531 | "<hidden xmlns=\"urn:libyang:tests:defaults\">\n" |
| 532 | " <foo>40</foo>\n" |
| 533 | "</hidden>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 534 | const char *out_diff_1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 535 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 536 | " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"42\">41</foo>\n" |
| 537 | " <b1_1 yang:operation=\"create\">42</b1_1>\n" |
| 538 | "</df>\n" |
| 539 | "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n" |
| 540 | " <foo>42</foo>\n" |
| 541 | " <baz>42</baz>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 542 | "</hidden>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 543 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 544 | const char *out_diff_2 = "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 545 | " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"41\">40</foo>\n" |
| 546 | " <b1_1 yang:operation=\"delete\">42</b1_1>\n" |
| 547 | "</df>\n" |
| 548 | "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n" |
| 549 | " <foo>40</foo>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 550 | "</hidden>\n"; |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 551 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 552 | const char *out_merge = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 553 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 554 | " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"42\">40</foo>\n" |
| 555 | "</df>\n" |
| 556 | "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 557 | " <foo yang:operation=\"replace\" yang:orig-value=\"42\" yang:orig-default=\"false\">40</foo>\n" |
| 558 | " <baz yang:operation=\"delete\">42</baz>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 559 | "</hidden>\n"; |
| 560 | |
| 561 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static void |
| 565 | test_list(void **state) |
| 566 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 567 | (void) state; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 568 | const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 569 | " <list>\n" |
| 570 | " <name>a</name>\n" |
| 571 | " <value>1</value>\n" |
| 572 | " </list>\n" |
| 573 | " <list>\n" |
| 574 | " <name>b</name>\n" |
| 575 | " <value>2</value>\n" |
| 576 | " </list>\n" |
| 577 | "</df>\n"; |
| 578 | const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 579 | " <list>\n" |
| 580 | " <name>b</name>\n" |
| 581 | " <value>-2</value>\n" |
| 582 | " </list>\n" |
| 583 | " <list>\n" |
| 584 | " <name>c</name>\n" |
| 585 | " <value>3</value>\n" |
| 586 | " </list>\n" |
| 587 | "</df>\n"; |
| 588 | const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 589 | " <list>\n" |
| 590 | " <name>b</name>\n" |
| 591 | " <value>-2</value>\n" |
| 592 | " </list>\n" |
| 593 | " <list>\n" |
| 594 | " <name>a</name>\n" |
| 595 | " <value>2</value>\n" |
| 596 | " </list>\n" |
| 597 | "</df>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 598 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 599 | const char *out_diff_1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 600 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 601 | " <list yang:operation=\"delete\">\n" |
| 602 | " <name>a</name>\n" |
| 603 | " <value>1</value>\n" |
| 604 | " </list>\n" |
| 605 | " <list yang:operation=\"none\">\n" |
| 606 | " <name>b</name>\n" |
| 607 | " <value yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\">-2</value>\n" |
| 608 | " </list>\n" |
| 609 | " <list yang:operation=\"create\">\n" |
| 610 | " <name>c</name>\n" |
| 611 | " <value>3</value>\n" |
| 612 | " </list>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 613 | "</df>\n"; |
| 614 | const char *out_diff_2 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 615 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 616 | " <list yang:operation=\"delete\">\n" |
| 617 | " <name>c</name>\n" |
| 618 | " <value>3</value>\n" |
| 619 | " </list>\n" |
| 620 | " <list yang:operation=\"create\">\n" |
| 621 | " <name>a</name>\n" |
| 622 | " <value>2</value>\n" |
| 623 | " </list>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 624 | "</df>\n"; |
| 625 | const char *out_merge = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 626 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 627 | " <list yang:operation=\"none\">\n" |
| 628 | " <name>a</name>\n" |
| 629 | " <value yang:operation=\"replace\" yang:orig-value=\"1\" yang:orig-default=\"false\">2</value>\n" |
| 630 | " </list>\n" |
| 631 | " <list yang:operation=\"none\">\n" |
| 632 | " <name>b</name>\n" |
| 633 | " <value yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\">-2</value>\n" |
| 634 | " </list>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 635 | "</df>\n"; |
| 636 | |
| 637 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static void |
| 641 | test_userord_llist(void **state) |
| 642 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 643 | (void) state; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 644 | const char *xml1 = |
| 645 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 646 | " <llist>1</llist>\n" |
| 647 | " <llist>2</llist>\n" |
| 648 | " <llist>3</llist>\n" |
| 649 | " <llist>4</llist>\n" |
| 650 | " <llist>5</llist>\n" |
| 651 | "</df>\n"; |
| 652 | const char *xml2 = |
| 653 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 654 | " <llist>1</llist>\n" |
| 655 | " <llist>4</llist>\n" |
| 656 | " <llist>3</llist>\n" |
| 657 | " <llist>2</llist>\n" |
| 658 | " <llist>5</llist>\n" |
| 659 | "</df>\n"; |
| 660 | const char *xml3 = |
| 661 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 662 | " <llist>5</llist>\n" |
| 663 | " <llist>4</llist>\n" |
| 664 | " <llist>3</llist>\n" |
| 665 | " <llist>2</llist>\n" |
| 666 | "</df>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 667 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 668 | const char *out_diff_1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 669 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 670 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"1\">4</llist>\n" |
| 671 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"4\">3</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 672 | "</df>\n"; |
| 673 | const char *out_diff_2 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 674 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 675 | " <llist yang:operation=\"delete\" yang:orig-value=\"\">1</llist>\n" |
| 676 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\">5</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 677 | "</df>\n"; |
| 678 | const char *out_merge = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 679 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 680 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"1\">4</llist>\n" |
| 681 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"4\">3</llist>\n" |
| 682 | " <llist yang:orig-value=\"\" yang:operation=\"delete\">1</llist>\n" |
| 683 | " <llist yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\" yang:operation=\"replace\">5</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 684 | "</df>\n"; |
| 685 | |
| 686 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static void |
| 690 | test_userord_llist2(void **state) |
| 691 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 692 | (void) state; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 693 | const char *xml1 = |
| 694 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 695 | " <llist>1</llist>\n" |
| 696 | " <list><name>a</name><value>1</value></list>\n" |
| 697 | " <llist>2</llist>\n" |
| 698 | " <llist>3</llist>\n" |
| 699 | " <llist>4</llist>\n" |
| 700 | "</df>\n"; |
| 701 | const char *xml2 = |
| 702 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 703 | " <llist>1</llist>\n" |
| 704 | " <list><name>a</name><value>1</value></list>\n" |
| 705 | " <llist>2</llist>\n" |
| 706 | " <llist>4</llist>\n" |
| 707 | " <llist>3</llist>\n" |
| 708 | "</df>\n"; |
| 709 | const char *xml3 = |
| 710 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 711 | " <llist>4</llist>\n" |
| 712 | " <llist>1</llist>\n" |
| 713 | " <list><name>a</name><value>1</value></list>\n" |
| 714 | " <llist>3</llist>\n" |
| 715 | "</df>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 716 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 717 | const char *out_diff_1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 718 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 719 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"2\">4</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 720 | "</df>\n"; |
| 721 | const char *out_diff_2 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 722 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 723 | " <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n" |
| 724 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">4</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 725 | "</df>\n"; |
| 726 | const char *out_merge = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 727 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 728 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\">4</llist>\n" |
| 729 | " <llist yang:orig-value=\"1\" yang:operation=\"delete\">2</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 730 | "</df>\n"; |
| 731 | |
| 732 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | static void |
| 736 | test_userord_mix(void **state) |
| 737 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 738 | (void) state; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 739 | const char *xml1 = |
| 740 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 741 | " <llist>1</llist>\n" |
| 742 | " <llist>2</llist>\n" |
| 743 | " <llist>3</llist>\n" |
| 744 | "</df>\n"; |
| 745 | const char *xml2 = |
| 746 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 747 | " <llist>3</llist>\n" |
| 748 | " <llist>1</llist>\n" |
| 749 | "</df>\n"; |
| 750 | const char *xml3 = |
| 751 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 752 | " <llist>1</llist>\n" |
| 753 | " <llist>4</llist>\n" |
| 754 | " <llist>3</llist>\n" |
| 755 | "</df>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 756 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 757 | const char *out_diff_1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 758 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 759 | " <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n" |
| 760 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">3</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 761 | "</df>\n"; |
| 762 | const char *out_diff_2 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 763 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 764 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\">1</llist>\n" |
| 765 | " <llist yang:operation=\"create\" yang:value=\"1\">4</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 766 | "</df>\n"; |
| 767 | const char *out_merge = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 768 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 769 | " <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n" |
| 770 | " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">3</llist>\n" |
| 771 | " <llist yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\" yang:operation=\"replace\">1</llist>\n" |
| 772 | " <llist yang:value=\"1\" yang:operation=\"create\">4</llist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 773 | "</df>\n"; |
| 774 | |
| 775 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | static void |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 779 | test_userord_list(void **state) |
| 780 | { |
| 781 | (void) state; |
| 782 | const char *xml1 = |
| 783 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 784 | " <ul>\n" |
| 785 | " <l1>a</l1>\n" |
| 786 | " <l2>1</l2>\n" |
| 787 | " </ul>\n" |
| 788 | " <ul>\n" |
| 789 | " <l1>b</l1>\n" |
| 790 | " <l2>2</l2>\n" |
| 791 | " </ul>\n" |
| 792 | " <ul>\n" |
| 793 | " <l1>c</l1>\n" |
| 794 | " <l2>3</l2>\n" |
| 795 | " </ul>\n" |
| 796 | "</df>\n"; |
| 797 | const char *xml2 = |
| 798 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 799 | " <ul>\n" |
| 800 | " <l1>a</l1>\n" |
| 801 | " <l2>11</l2>\n" |
| 802 | " </ul>\n" |
| 803 | " <ul>\n" |
| 804 | " <l1>c</l1>\n" |
| 805 | " <l2>3</l2>\n" |
| 806 | " </ul>\n" |
| 807 | "</df>\n"; |
| 808 | const char *xml3 = |
| 809 | "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 810 | " <ul>\n" |
| 811 | " <l1>c</l1>\n" |
| 812 | " <l2>33</l2>\n" |
| 813 | " </ul>\n" |
| 814 | " <ul>\n" |
| 815 | " <l1>b</l1>\n" |
| 816 | " <l2>2</l2>\n" |
| 817 | " </ul>\n" |
| 818 | "</df>\n"; |
| 819 | |
| 820 | const char *out_diff_1 = |
| 821 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 822 | " <ul>\n" |
| 823 | " <l1>a</l1>\n" |
| 824 | " <l2 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\">11</l2>\n" |
| 825 | " </ul>\n" |
| 826 | " <ul yang:operation=\"delete\" yang:orig-key=\"[l1='a']\">\n" |
| 827 | " <l1>b</l1>\n" |
| 828 | " <l2>2</l2>\n" |
| 829 | " </ul>\n" |
| 830 | "</df>\n"; |
| 831 | const char *out_diff_2 = |
| 832 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 833 | " <ul yang:operation=\"delete\" yang:orig-key=\"\">\n" |
| 834 | " <l1>a</l1>\n" |
| 835 | " <l2>11</l2>\n" |
| 836 | " </ul>\n" |
| 837 | " <ul yang:operation=\"none\">\n" |
| 838 | " <l1>c</l1>\n" |
| 839 | " <l2 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\">33</l2>\n" |
| 840 | " </ul>\n" |
| 841 | " <ul yang:operation=\"create\" yang:key=\"[l1='c']\">\n" |
| 842 | " <l1>b</l1>\n" |
| 843 | " <l2>2</l2>\n" |
| 844 | " </ul>\n" |
| 845 | "</df>\n"; |
| 846 | const char *out_merge = |
| 847 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 848 | " <ul yang:operation=\"delete\">\n" |
| 849 | " <l1>a</l1>\n" |
| 850 | " <l2 yang:operation=\"delete\">1</l2>\n" |
| 851 | " </ul>\n" |
| 852 | " <ul yang:orig-key=\"[l1='a']\" yang:operation=\"replace\" yang:key=\"[l1='c']\">\n" |
| 853 | " <l1>b</l1>\n" |
| 854 | " </ul>\n" |
| 855 | " <ul yang:operation=\"none\">\n" |
| 856 | " <l1>c</l1>\n" |
| 857 | " <l2 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\">33</l2>\n" |
| 858 | " </ul>\n" |
| 859 | "</df>\n"; |
| 860 | |
| 861 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
| 862 | } |
| 863 | |
| 864 | static void |
| 865 | test_keyless_list(void **state) |
| 866 | { |
| 867 | (void) state; |
| 868 | const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 869 | " <kl>\n" |
| 870 | " <l1>a</l1>\n" |
| 871 | " <l2>1</l2>\n" |
| 872 | " </kl>\n" |
| 873 | " <kl>\n" |
| 874 | " <l1>b</l1>\n" |
| 875 | " <l2>2</l2>\n" |
| 876 | " </kl>\n" |
| 877 | " <kl>\n" |
| 878 | " <l1>c</l1>\n" |
| 879 | " <l2>3</l2>\n" |
| 880 | " </kl>\n" |
| 881 | "</df>\n"; |
| 882 | const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 883 | " <kl>\n" |
| 884 | " <l1>b</l1>\n" |
| 885 | " <l2>2</l2>\n" |
| 886 | " </kl>\n" |
| 887 | " <kl>\n" |
| 888 | " <l1>a</l1>\n" |
| 889 | " <l2>1</l2>\n" |
| 890 | " </kl>\n" |
| 891 | " <kl>\n" |
| 892 | " <l1>a</l1>\n" |
| 893 | " <l2>1</l2>\n" |
| 894 | " </kl>\n" |
| 895 | "</df>\n"; |
| 896 | const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 897 | " <kl>\n" |
| 898 | " <l1>c</l1>\n" |
| 899 | " </kl>\n" |
| 900 | " <kl>\n" |
| 901 | " <l2>4</l2>\n" |
| 902 | " </kl>\n" |
| 903 | " <kl>\n" |
| 904 | " <l1>e</l1>\n" |
| 905 | " <l2>5</l2>\n" |
| 906 | " </kl>\n" |
| 907 | " <kl>\n" |
| 908 | " <l1>f</l1>\n" |
| 909 | " <l2>6</l2>\n" |
| 910 | " </kl>\n" |
| 911 | "</df>\n"; |
| 912 | |
| 913 | const char *out_diff_1 = |
| 914 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 915 | " <kl yang:operation=\"delete\" yang:orig-position=\"2\">\n" |
| 916 | " <l1>c</l1>\n" |
| 917 | " <l2>3</l2>\n" |
| 918 | " </kl>\n" |
| 919 | " <kl yang:operation=\"replace\" yang:position=\"\" yang:orig-position=\"1\">\n" |
| 920 | " <l1>b</l1>\n" |
| 921 | " <l2>2</l2>\n" |
| 922 | " </kl>\n" |
| 923 | " <kl yang:operation=\"create\" yang:position=\"2\">\n" |
| 924 | " <l1>a</l1>\n" |
| 925 | " <l2>1</l2>\n" |
| 926 | " </kl>\n" |
| 927 | "</df>\n"; |
| 928 | const char *out_diff_2 = |
| 929 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 930 | " <kl yang:operation=\"delete\" yang:orig-position=\"\">\n" |
| 931 | " <l1>b</l1>\n" |
| 932 | " <l2>2</l2>\n" |
| 933 | " </kl>\n" |
| 934 | " <kl yang:operation=\"delete\" yang:orig-position=\"\">\n" |
| 935 | " <l1>a</l1>\n" |
| 936 | " <l2>1</l2>\n" |
| 937 | " </kl>\n" |
| 938 | " <kl yang:operation=\"delete\" yang:orig-position=\"\">\n" |
| 939 | " <l1>a</l1>\n" |
| 940 | " <l2>1</l2>\n" |
| 941 | " </kl>\n" |
| 942 | " <kl yang:operation=\"create\" yang:position=\"\">\n" |
| 943 | " <l1>c</l1>\n" |
| 944 | " </kl>\n" |
| 945 | " <kl yang:operation=\"create\" yang:position=\"1\">\n" |
| 946 | " <l2>4</l2>\n" |
| 947 | " </kl>\n" |
| 948 | " <kl yang:operation=\"create\" yang:position=\"2\">\n" |
| 949 | " <l1>e</l1>\n" |
| 950 | " <l2>5</l2>\n" |
| 951 | " </kl>\n" |
| 952 | " <kl yang:operation=\"create\" yang:position=\"3\">\n" |
| 953 | " <l1>f</l1>\n" |
| 954 | " <l2>6</l2>\n" |
| 955 | " </kl>\n" |
| 956 | "</df>\n"; |
| 957 | const char *out_merge = |
| 958 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 959 | " <kl yang:operation=\"delete\" yang:orig-position=\"2\">\n" |
| 960 | " <l1>c</l1>\n" |
| 961 | " <l2>3</l2>\n" |
| 962 | " </kl>\n" |
| 963 | " <kl yang:orig-position=\"1\" yang:operation=\"delete\">\n" |
| 964 | " <l1>b</l1>\n" |
| 965 | " <l2>2</l2>\n" |
| 966 | " </kl>\n" |
| 967 | " <kl yang:orig-position=\"\" yang:operation=\"delete\">\n" |
| 968 | " <l1>a</l1>\n" |
| 969 | " <l2>1</l2>\n" |
| 970 | " </kl>\n" |
| 971 | " <kl yang:position=\"\" yang:operation=\"create\">\n" |
| 972 | " <l1>c</l1>\n" |
| 973 | " </kl>\n" |
| 974 | " <kl yang:position=\"1\" yang:operation=\"create\">\n" |
| 975 | " <l2>4</l2>\n" |
| 976 | " </kl>\n" |
| 977 | " <kl yang:position=\"2\" yang:operation=\"create\">\n" |
| 978 | " <l1>e</l1>\n" |
| 979 | " <l2>5</l2>\n" |
| 980 | " </kl>\n" |
| 981 | " <kl yang:position=\"3\" yang:operation=\"create\">\n" |
| 982 | " <l1>f</l1>\n" |
| 983 | " <l2>6</l2>\n" |
| 984 | " </kl>\n" |
| 985 | "</df>\n"; |
| 986 | |
| 987 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
| 988 | } |
| 989 | |
| 990 | static void |
| 991 | test_state_llist(void **state) |
| 992 | { |
| 993 | (void) state; |
| 994 | const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 995 | " <kll>a</kll>\n" |
| 996 | " <kll>b</kll>\n" |
| 997 | " <kll>c</kll>\n" |
| 998 | "</df>\n"; |
| 999 | const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 1000 | " <kll>b</kll>\n" |
| 1001 | " <kll>c</kll>\n" |
| 1002 | " <kll>a</kll>\n" |
| 1003 | " <kll>a</kll>\n" |
| 1004 | " <kll>a</kll>\n" |
| 1005 | "</df>\n"; |
| 1006 | const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 1007 | " <kll>a</kll>\n" |
| 1008 | " <kll>d</kll>\n" |
| 1009 | " <kll>a</kll>\n" |
| 1010 | "</df>\n"; |
| 1011 | |
| 1012 | const char *out_diff_1 = |
| 1013 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 1014 | " <kll yang:operation=\"replace\" yang:orig-default=\"false\" yang:position=\"\" yang:orig-position=\"1\">b</kll>\n" |
| 1015 | " <kll yang:operation=\"replace\" yang:orig-default=\"false\" yang:position=\"1\" yang:orig-position=\"2\">c</kll>\n" |
| 1016 | " <kll yang:operation=\"create\" yang:position=\"3\">a</kll>\n" |
| 1017 | " <kll yang:operation=\"create\" yang:position=\"4\">a</kll>\n" |
| 1018 | "</df>\n"; |
| 1019 | const char *out_diff_2 = |
| 1020 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 1021 | " <kll yang:operation=\"delete\" yang:orig-position=\"\">b</kll>\n" |
| 1022 | " <kll yang:operation=\"delete\" yang:orig-position=\"\">c</kll>\n" |
| 1023 | " <kll yang:operation=\"delete\" yang:orig-position=\"2\">a</kll>\n" |
| 1024 | " <kll yang:operation=\"create\" yang:position=\"1\">d</kll>\n" |
| 1025 | "</df>\n"; |
| 1026 | const char *out_merge = |
| 1027 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 1028 | " <kll yang:orig-default=\"false\" yang:orig-position=\"1\" yang:operation=\"delete\">b</kll>\n" |
| 1029 | " <kll yang:orig-default=\"false\" yang:orig-position=\"2\" yang:operation=\"delete\">c</kll>\n" |
| 1030 | " <kll yang:operation=\"create\" yang:position=\"4\">a</kll>\n" |
| 1031 | " <kll yang:position=\"1\" yang:operation=\"create\">d</kll>\n" |
| 1032 | "</df>\n"; |
| 1033 | |
| 1034 | TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge); |
| 1035 | } |
| 1036 | |
| 1037 | static void |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1038 | test_wd(void **state) |
| 1039 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1040 | (void) state; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1041 | const struct lys_module *mod; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1042 | const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 1043 | " <foo>41</foo>\n" |
| 1044 | " <dllist>4</dllist>\n" |
| 1045 | "</df>\n"; |
| 1046 | const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n" |
| 1047 | " <foo>42</foo>\n" |
| 1048 | " <dllist>4</dllist>\n" |
| 1049 | " <dllist>1</dllist>\n" |
| 1050 | "</df>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1051 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1052 | mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "defaults"); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1053 | assert_non_null(mod); |
| 1054 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1055 | struct lyd_node *model_1 = NULL; |
| 1056 | |
| 1057 | assert_int_equal(lyd_validate_module(&model_1, mod, 0, NULL), LY_SUCCESS); |
| 1058 | assert_ptr_not_equal(model_1, NULL); |
| 1059 | |
| 1060 | struct lyd_node *model_2; |
| 1061 | struct lyd_node *model_3; |
| 1062 | |
| 1063 | CHECK_PARSE_LYD_PARAM(xml2, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, model_2); |
| 1064 | CHECK_PARSE_LYD_PARAM(xml3, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, model_3); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1065 | |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 1066 | /* diff1 */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1067 | struct lyd_node *diff1 = NULL; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1068 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1069 | assert_int_equal(lyd_diff_siblings(model_1, model_2, LYD_DIFF_DEFAULTS, &diff1), LY_SUCCESS); |
| 1070 | assert_non_null(diff1); |
| 1071 | |
| 1072 | const char *diff1_out_1 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1073 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 1074 | " <foo yang:operation=\"replace\" yang:orig-default=\"true\" yang:orig-value=\"42\">41</foo>\n" |
| 1075 | " <dllist yang:operation=\"delete\">1</dllist>\n" |
| 1076 | " <dllist yang:operation=\"delete\">2</dllist>\n" |
| 1077 | " <dllist yang:operation=\"delete\">3</dllist>\n" |
| 1078 | " <dllist yang:operation=\"create\">4</dllist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1079 | "</df>\n"; |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1080 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1081 | CHECK_LYD_STRING_PARAM(diff1, diff1_out_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL); |
| 1082 | assert_int_equal(lyd_diff_apply_all(&model_1, diff1), LY_SUCCESS); |
| 1083 | CHECK_LYD(model_1, model_2); |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 1084 | |
| 1085 | /* diff2 */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1086 | struct lyd_node *diff2; |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 1087 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1088 | assert_int_equal(lyd_diff_siblings(model_2, model_3, LYD_DIFF_DEFAULTS, &diff2), LY_SUCCESS); |
| 1089 | assert_non_null(diff2); |
| 1090 | CHECK_LYD_STRING(diff2, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1091 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 1092 | " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"41\">42</foo>\n" |
| 1093 | " <dllist yang:operation=\"create\">1</dllist>\n" |
| 1094 | "</df>\n"); |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 1095 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1096 | assert_int_equal(lyd_diff_apply_all(&model_2, diff2), LY_SUCCESS); |
| 1097 | CHECK_LYD(model_2, model_3); |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 1098 | |
| 1099 | /* merge */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1100 | assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS); |
Michal Vasko | e6323f6 | 2020-07-09 15:49:02 +0200 | [diff] [blame] | 1101 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1102 | const char *diff1_out_2 = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1103 | "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n" |
| 1104 | " <foo yang:orig-default=\"true\" yang:operation=\"none\">42</foo>\n" |
| 1105 | " <dllist yang:operation=\"none\" yang:orig-default=\"true\">1</dllist>\n" |
| 1106 | " <dllist yang:operation=\"delete\">2</dllist>\n" |
| 1107 | " <dllist yang:operation=\"delete\">3</dllist>\n" |
| 1108 | " <dllist yang:operation=\"create\">4</dllist>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1109 | "</df>\n"; |
| 1110 | |
| 1111 | CHECK_LYD_STRING_PARAM(diff1, diff1_out_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL); |
| 1112 | |
| 1113 | lyd_free_all(model_1); |
| 1114 | lyd_free_all(model_2); |
| 1115 | lyd_free_all(model_3); |
| 1116 | lyd_free_all(diff1); |
| 1117 | lyd_free_all(diff2); |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1120 | int |
| 1121 | main(void) |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1122 | { |
| 1123 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1124 | UTEST(test_invalid, setup), |
| 1125 | UTEST(test_same, setup), |
| 1126 | UTEST(test_empty1, setup), |
| 1127 | UTEST(test_empty2, setup), |
| 1128 | UTEST(test_empty_nested, setup), |
Michal Vasko | 17d0c5c | 2021-11-01 11:31:11 +0100 | [diff] [blame] | 1129 | UTEST(test_delete_merge, setup), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1130 | UTEST(test_leaf, setup), |
| 1131 | UTEST(test_list, setup), |
| 1132 | UTEST(test_userord_llist, setup), |
| 1133 | UTEST(test_userord_llist2, setup), |
| 1134 | UTEST(test_userord_mix, setup), |
Michal Vasko | e78faec | 2021-04-08 17:24:43 +0200 | [diff] [blame] | 1135 | UTEST(test_userord_list, setup), |
| 1136 | UTEST(test_keyless_list, setup), |
| 1137 | UTEST(test_state_llist, setup), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1138 | UTEST(test_wd, setup), |
Michal Vasko | e893ddd | 2020-06-23 13:35:20 +0200 | [diff] [blame] | 1139 | }; |
| 1140 | |
| 1141 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 1142 | } |