blob: 818a782173f73db8f703277e7f321bdfb498b3e6 [file] [log] [blame]
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001/**
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ša56ca9e42020-09-08 18:42:00 +020015#define _UTEST_MAIN_
Radek Krejcib4ac5a92020-11-23 17:54:33 +010016#include "utests.h"
Michal Vaskoe893ddd2020-06-23 13:35:20 +020017
Radek Iša56ca9e42020-09-08 18:42:00 +020018#include "libyang.h"
19
Michal Vasko58d89e92023-05-23 09:56:19 +020020#define CHECK_PARSE_LYD(INPUT, OUTPUT) \
21 CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, OUTPUT)
Radek Iša56ca9e42020-09-08 18:42:00 +020022
Michal Vasko58d89e92023-05-23 09:56:19 +020023#define CHECK_LYD_STRING(INPUT, TEXT) \
24 CHECK_LYD_STRING_PARAM(INPUT, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS)
Radek Iša56ca9e42020-09-08 18:42:00 +020025
Michal Vasko58d89e92023-05-23 09:56:19 +020026#define CHECK_PARSE_LYD_DIFF(INPUT_1, INPUT_2, OUT_DIFF) \
27 assert_int_equal(LY_SUCCESS, lyd_diff_siblings(INPUT_1, INPUT_2, 0, &OUT_DIFF));\
28 assert_non_null(OUT_DIFF)
Radek Iša56ca9e42020-09-08 18:42:00 +020029
Michal Vasko5da938a2022-03-01 09:19:02 +010030#define TEST_DIFF_3(XML1, XML2, XML3, DIFF1, DIFF2, MERGE) \
31 { \
32 struct lyd_node *data1;\
33 struct lyd_node *data2;\
34 struct lyd_node *data3;\
Michal Vasko2bf4af42023-01-04 12:08:38 +010035 /*create*/\
Michal Vasko5da938a2022-03-01 09:19:02 +010036 CHECK_PARSE_LYD(XML1, data1);\
37 CHECK_PARSE_LYD(XML2, data2);\
38 CHECK_PARSE_LYD(XML3, data3);\
Michal Vasko2bf4af42023-01-04 12:08:38 +010039 /* diff1 */ \
Michal Vasko5da938a2022-03-01 09:19:02 +010040 struct lyd_node *diff1;\
41 CHECK_PARSE_LYD_DIFF(data1, data2, diff1); \
42 CHECK_LYD_STRING(diff1, DIFF1); \
43 assert_int_equal(lyd_diff_apply_all(&data1, diff1), LY_SUCCESS); \
44 CHECK_LYD(data1, data2); \
Michal Vasko2bf4af42023-01-04 12:08:38 +010045 /* diff2 */ \
Michal Vasko5da938a2022-03-01 09:19:02 +010046 struct lyd_node *diff2;\
47 CHECK_PARSE_LYD_DIFF(data2, data3, diff2); \
48 CHECK_LYD_STRING(diff2, DIFF2); \
49 assert_int_equal(lyd_diff_apply_all(&data2, diff2), LY_SUCCESS);\
50 CHECK_LYD(data2, data3);\
Michal Vasko2bf4af42023-01-04 12:08:38 +010051 /* merge */ \
Michal Vasko5da938a2022-03-01 09:19:02 +010052 assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS);\
53 CHECK_LYD_STRING(diff1, MERGE); \
Michal Vasko2bf4af42023-01-04 12:08:38 +010054 /* cleanup */ \
Michal Vasko5da938a2022-03-01 09:19:02 +010055 lyd_free_all(data1);\
56 lyd_free_all(data2);\
57 lyd_free_all(data3);\
58 lyd_free_all(diff1);\
59 lyd_free_all(diff2);\
60 }
Radek Iša56ca9e42020-09-08 18:42:00 +020061
Michal Vasko17d0c5c2021-11-01 11:31:11 +010062const char *schema1 =
Radek Iša56ca9e42020-09-08 18:42:00 +020063 "module defaults {\n"
64 " yang-version 1.1;\n"
65 " namespace \"urn:libyang:tests:defaults\";\n"
66 " prefix df;\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020067 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020068 " feature unhide;\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020069 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020070 " typedef defint32 {\n"
71 " type int32;\n"
72 " default \"42\";\n"
73 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020074 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020075 " leaf hiddenleaf {\n"
76 " if-feature \"unhide\";\n"
77 " type int32;\n"
78 " default \"42\";\n"
79 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020080 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020081 " container df {\n"
82 " leaf foo {\n"
83 " type defint32;\n"
84 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020085 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020086 " leaf hiddenleaf {\n"
87 " if-feature \"unhide\";\n"
88 " type int32;\n"
89 " default \"42\";\n"
90 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020091 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020092 " container bar {\n"
93 " presence \"\";\n"
94 " leaf hi {\n"
95 " type int32;\n"
96 " default \"42\";\n"
97 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +020098 ""
Radek Iša56ca9e42020-09-08 18:42:00 +020099 " leaf ho {\n"
100 " type int32;\n"
101 " mandatory true;\n"
102 " }\n"
103 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200104 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200105 " leaf-list llist {\n"
106 " type defint32;\n"
107 " ordered-by user;\n"
108 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200109 ""
Michal Vaskoe78faec2021-04-08 17:24:43 +0200110 " list ul {\n"
111 " key \"l1\";\n"
112 " ordered-by user;\n"
113 " leaf l1 {\n"
114 " type string;\n"
115 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200116 ""
Michal Vaskoe78faec2021-04-08 17:24:43 +0200117 " leaf l2 {\n"
118 " type int32;\n"
119 " }\n"
120 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200121 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200122 " leaf-list dllist {\n"
123 " type uint8;\n"
124 " default \"1\";\n"
125 " default \"2\";\n"
126 " default \"3\";\n"
127 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200128 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200129 " list list {\n"
130 " key \"name\";\n"
131 " leaf name {\n"
132 " type string;\n"
133 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200134 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200135 " leaf value {\n"
136 " type int32;\n"
137 " default \"42\";\n"
138 " }\n"
Michal Vasko17d0c5c2021-11-01 11:31:11 +0100139 " list list2 {\n"
140 " key \"name2\";\n"
141 " leaf name2 {\n"
142 " type string;\n"
143 " }\n"
144 " leaf value2 {\n"
145 " type int32;\n"
146 " }\n"
147 " }\n"
148 " }\n";
149const char *schema2 =
Radek Iša56ca9e42020-09-08 18:42:00 +0200150 " choice select {\n"
151 " default \"a\";\n"
152 " case a {\n"
153 " choice a {\n"
154 " leaf a1 {\n"
155 " type int32;\n"
156 " default \"42\";\n"
157 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200158 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200159 " leaf a2 {\n"
160 " type int32;\n"
161 " default \"24\";\n"
162 " }\n"
163 " }\n"
164 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200165 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200166 " leaf b {\n"
167 " type string;\n"
168 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200169 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200170 " container c {\n"
171 " presence \"\";\n"
172 " leaf x {\n"
173 " type int32;\n"
174 " default \"42\";\n"
175 " }\n"
176 " }\n"
177 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200178 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200179 " choice select2 {\n"
180 " default \"s2b\";\n"
181 " leaf s2a {\n"
182 " type int32;\n"
183 " default \"42\";\n"
184 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200185 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200186 " case s2b {\n"
187 " choice s2b {\n"
188 " default \"b1\";\n"
189 " case b1 {\n"
190 " leaf b1_1 {\n"
191 " type int32;\n"
192 " default \"42\";\n"
193 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200194 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200195 " leaf b1_2 {\n"
196 " type string;\n"
197 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200198 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200199 " leaf b1_status {\n"
200 " type int32;\n"
201 " default \"42\";\n"
202 " config false;\n"
203 " }\n"
204 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200205 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200206 " leaf b2 {\n"
207 " type int32;\n"
208 " default \"42\";\n"
209 " }\n"
210 " }\n"
211 " }\n"
212 " }\n"
Michal Vaskoe78faec2021-04-08 17:24:43 +0200213 " list kl {\n"
214 " config \"false\";\n"
215 " leaf l1 {\n"
216 " type string;\n"
217 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200218 ""
Michal Vaskoe78faec2021-04-08 17:24:43 +0200219 " leaf l2 {\n"
220 " type int32;\n"
221 " }\n"
222 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200223 ""
Michal Vaskoe78faec2021-04-08 17:24:43 +0200224 " leaf-list kll {\n"
225 " config \"false\";\n"
226 " type string;\n"
227 " }\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200228 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200229 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200230 " container hidden {\n"
231 " leaf foo {\n"
232 " type int32;\n"
233 " default \"42\";\n"
234 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200235 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200236 " leaf baz {\n"
237 " type int32;\n"
238 " default \"42\";\n"
239 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200240 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200241 " leaf papa {\n"
242 " type int32;\n"
243 " default \"42\";\n"
244 " config false;\n"
245 " }\n"
246 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200247 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200248 " rpc rpc1 {\n"
249 " input {\n"
250 " leaf inleaf1 {\n"
251 " type string;\n"
252 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200253 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200254 " leaf inleaf2 {\n"
255 " type string;\n"
256 " default \"def1\";\n"
257 " }\n"
258 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200259 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200260 " output {\n"
261 " leaf outleaf1 {\n"
262 " type string;\n"
263 " default \"def2\";\n"
264 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200265 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200266 " leaf outleaf2 {\n"
267 " type string;\n"
268 " }\n"
269 " }\n"
270 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200271 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200272 " notification notif {\n"
273 " leaf ntfleaf1 {\n"
274 " type string;\n"
275 " default \"def3\";\n"
276 " }\n"
Michal Vasko22e0f3a2021-09-22 12:19:23 +0200277 ""
Radek Iša56ca9e42020-09-08 18:42:00 +0200278 " leaf ntfleaf2 {\n"
279 " type string;\n"
280 " }\n"
281 " }\n"
282 "}\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200283
284static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200285setup(void **state)
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200286{
Michal Vasko17d0c5c2021-11-01 11:31:11 +0100287 char *schema;
288
Radek Iša56ca9e42020-09-08 18:42:00 +0200289 UTEST_SETUP;
Michal Vasko17d0c5c2021-11-01 11:31:11 +0100290
291 /* create one schema, longer than 4095 chars */
292 schema = malloc(strlen(schema1) + strlen(schema2) + 1);
293 strcpy(schema, schema1);
294 strcat(schema, schema2);
295
Radek Iša56ca9e42020-09-08 18:42:00 +0200296 UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
Michal Vasko17d0c5c2021-11-01 11:31:11 +0100297 free(schema);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200298
299 return 0;
300}
301
302static void
303test_invalid(void **state)
304{
Radek Iša56ca9e42020-09-08 18:42:00 +0200305 (void) state;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200306 const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\"><foo>42</foo></df>";
307
Radek Iša56ca9e42020-09-08 18:42:00 +0200308 struct lyd_node *model_1;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200309
Radek Iša56ca9e42020-09-08 18:42:00 +0200310 CHECK_PARSE_LYD(xml, model_1);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200311
Radek Iša56ca9e42020-09-08 18:42:00 +0200312 struct lyd_node *diff = NULL;
313
314 assert_int_equal(lyd_diff_siblings(model_1, lyd_child(model_1), 0, &diff), LY_EINVAL);
Michal Vasko62af3692023-02-09 14:00:09 +0100315 CHECK_LOG_CTX("Invalid arguments - cannot create diff for unrelated data (lyd_diff()).", NULL);
316
Michal Vasko3a41dff2020-07-15 14:30:28 +0200317 assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, NULL), LY_EINVAL);
Radek Iša56ca9e42020-09-08 18:42:00 +0200318
319 lyd_free_all(model_1);
320 lyd_free_all(diff);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200321}
322
323static void
324test_same(void **state)
325{
Radek Iša56ca9e42020-09-08 18:42:00 +0200326 (void) state;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100327 const char *xml =
328 "<nacm xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-acm\">\n"
329 " <enable-nacm>true</enable-nacm>\n"
330 " <read-default>permit</read-default>\n"
331 " <write-default>deny</write-default>\n"
332 " <exec-default>permit</exec-default>\n"
333 " <enable-external-groups>true</enable-external-groups>\n"
334 "</nacm><df xmlns=\"urn:libyang:tests:defaults\">\n"
335 " <foo>42</foo><b1_1>42</b1_1>\n"
336 "</df><hidden xmlns=\"urn:libyang:tests:defaults\">\n"
337 " <foo>42</foo><baz>42</baz></hidden>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200338
Radek Iša56ca9e42020-09-08 18:42:00 +0200339 struct lyd_node *model_1;
340 struct lyd_node *model_2;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200341
Radek Iša56ca9e42020-09-08 18:42:00 +0200342 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
343 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-acm", "2018-02-14", NULL));
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200344
Radek Iša56ca9e42020-09-08 18:42:00 +0200345 CHECK_PARSE_LYD(xml, model_1);
346 CHECK_PARSE_LYD(xml, model_2);
347
348 struct lyd_node *diff = NULL;
349
350 assert_int_equal(lyd_diff_siblings(model_1, model_2, 0, &diff), LY_SUCCESS);
351 assert_null(diff);
352 assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS);
353 CHECK_LYD(model_1, model_2);
354
355 lyd_free_all(model_1);
356 lyd_free_all(model_2);
357 lyd_free_all(diff);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200358}
359
360static void
361test_empty1(void **state)
362{
Radek Iša56ca9e42020-09-08 18:42:00 +0200363 (void) state;
364 const char *xml_in =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100365 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
366 " <foo>42</foo>\n"
367 " <b1_1>42</b1_1>\n"
368 "</df>\n"
369 "<hidden xmlns=\"urn:libyang:tests:defaults\">\n"
370 " <foo>42</foo>\n"
371 " <baz>42</baz>\n"
372 "</hidden>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200373
Radek Iša56ca9e42020-09-08 18:42:00 +0200374 struct lyd_node *model_1 = NULL;
375 struct lyd_node *model_2;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200376
Radek Iša56ca9e42020-09-08 18:42:00 +0200377 CHECK_PARSE_LYD(xml_in, model_2);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200378
Radek Iša56ca9e42020-09-08 18:42:00 +0200379 struct lyd_node *diff;
380
381 CHECK_PARSE_LYD_DIFF(model_1, model_2, diff);
382 CHECK_LYD_STRING(diff,
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100383 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
384 " <foo>42</foo>\n"
385 " <b1_1>42</b1_1>\n"
386 "</df>\n"
387 "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
388 " <foo>42</foo>\n"
389 " <baz>42</baz>\n"
390 "</hidden>\n");
Radek Iša56ca9e42020-09-08 18:42:00 +0200391 assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS);
392 CHECK_LYD(model_1, model_2);
393
394 lyd_free_all(model_1);
395 lyd_free_all(model_2);
396 lyd_free_all(diff);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200397}
398
399static void
400test_empty2(void **state)
401{
Radek Iša56ca9e42020-09-08 18:42:00 +0200402 (void) state;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100403 const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
404 " <foo>42</foo>\n"
405 " <b1_1>42</b1_1>\n"
406 "</df><hidden xmlns=\"urn:libyang:tests:defaults\">\n"
407 " <foo>42</foo>\n"
408 " <baz>42</baz>\n"
409 "</hidden>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200410
Radek Iša56ca9e42020-09-08 18:42:00 +0200411 struct lyd_node *model_1;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200412
Radek Iša56ca9e42020-09-08 18:42:00 +0200413 CHECK_PARSE_LYD(xml, model_1);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200414
Radek Iša56ca9e42020-09-08 18:42:00 +0200415 struct lyd_node *diff;
416
417 CHECK_PARSE_LYD_DIFF(model_1, NULL, diff);
418 CHECK_LYD_STRING(diff,
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100419 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n"
420 " <foo>42</foo>\n"
421 " <b1_1>42</b1_1>\n"
422 "</df>\n"
423 "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n"
424 " <foo>42</foo>\n"
425 " <baz>42</baz>\n"
426 "</hidden>\n");
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200427
Radek Iša56ca9e42020-09-08 18:42:00 +0200428 assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS);
429 assert_ptr_equal(model_1, NULL);
430
431 lyd_free_all(diff);
432 lyd_free_all(model_1);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200433}
434
435static void
436test_empty_nested(void **state)
437{
Radek Iša56ca9e42020-09-08 18:42:00 +0200438 (void) state;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200439 const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\"><foo>42</foo></df>";
440
Radek Iša56ca9e42020-09-08 18:42:00 +0200441 struct lyd_node *model_1;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200442
Radek Iša56ca9e42020-09-08 18:42:00 +0200443 CHECK_PARSE_LYD(xml, model_1);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200444
Radek Iša56ca9e42020-09-08 18:42:00 +0200445 struct lyd_node *diff = NULL;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200446
Radek Iša56ca9e42020-09-08 18:42:00 +0200447 assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, &diff), LY_SUCCESS);
448 assert_null(diff);
449
450 struct lyd_node *diff1;
451
452 CHECK_PARSE_LYD_DIFF(NULL, lyd_child(model_1), diff1);
453 CHECK_LYD_STRING(diff1,
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100454 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
455 " <foo yang:operation=\"create\">42</foo>\n"
456 "</df>\n");
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200457
Radek Iša56ca9e42020-09-08 18:42:00 +0200458 struct lyd_node *diff2;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200459
Radek Iša56ca9e42020-09-08 18:42:00 +0200460 CHECK_PARSE_LYD_DIFF(lyd_child(model_1), NULL, diff2);
461 CHECK_LYD_STRING(diff2,
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100462 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
463 " <foo yang:operation=\"delete\">42</foo>\n"
464 "</df>\n");
Radek Iša56ca9e42020-09-08 18:42:00 +0200465
466 lyd_free_all(model_1);
467 lyd_free_all(diff1);
468 lyd_free_all(diff2);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200469}
470
471static void
Michal Vasko17d0c5c2021-11-01 11:31:11 +0100472test_delete_merge(void **state)
473{
474 (void) state;
475 struct lyd_node *diff1, *diff2;
476 const char *xml1 =
477 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
478 " <list>\n"
479 " <name>a</name>\n"
480 " <list2 yang:operation=\"delete\">\n"
481 " <name2>a</name2>\n"
482 " </list2>\n"
483 " </list>\n"
484 "</df>\n";
485 const char *xml2 =
486 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
487 " <list yang:operation=\"delete\">\n"
488 " <name>a</name>\n"
489 " </list>\n"
490 "</df>\n";
491 const char *xml_merge =
492 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
493 " <list yang:operation=\"delete\">\n"
494 " <name>a</name>\n"
495 " <list2 yang:operation=\"delete\">\n"
496 " <name2>a</name2>\n"
497 " </list2>\n"
498 " </list>\n"
499 "</df>\n";
500
501 CHECK_PARSE_LYD(xml1, diff1);
502 CHECK_PARSE_LYD(xml2, diff2);
503
504 assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS);
505 CHECK_LYD_STRING(diff1, xml_merge);
506
507 lyd_free_all(diff1);
508 lyd_free_all(diff2);
509}
510
511static void
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200512test_leaf(void **state)
513{
Radek Iša56ca9e42020-09-08 18:42:00 +0200514 (void) state;
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200515 const char *xml1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100516 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
517 " <foo>42</foo>\n"
518 "</df>\n"
519 "<hidden xmlns=\"urn:libyang:tests:defaults\">\n"
520 " <foo>42</foo>\n"
521 " <baz>42</baz>\n"
522 "</hidden>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200523 const char *xml2 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100524 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
525 " <foo>41</foo>\n"
526 " <b1_1>42</b1_1>\n"
527 "</df>\n";
Michal Vaskoe6323f62020-07-09 15:49:02 +0200528 const char *xml3 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100529 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
530 " <foo>40</foo>\n"
531 "</df>\n"
532 "<hidden xmlns=\"urn:libyang:tests:defaults\">\n"
533 " <foo>40</foo>\n"
534 "</hidden>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +0200535 const char *out_diff_1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100536 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
537 " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"42\">41</foo>\n"
538 " <b1_1 yang:operation=\"create\">42</b1_1>\n"
539 "</df>\n"
540 "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n"
541 " <foo>42</foo>\n"
542 " <baz>42</baz>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200543 "</hidden>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200544
Radek Iša56ca9e42020-09-08 18:42:00 +0200545 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 Krejcib4ac5a92020-11-23 17:54:33 +0100546 " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"41\">40</foo>\n"
547 " <b1_1 yang:operation=\"delete\">42</b1_1>\n"
548 "</df>\n"
549 "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
550 " <foo>40</foo>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200551 "</hidden>\n";
Michal Vaskoe6323f62020-07-09 15:49:02 +0200552
Radek Iša56ca9e42020-09-08 18:42:00 +0200553 const char *out_merge =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100554 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
555 " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"42\">40</foo>\n"
556 "</df>\n"
557 "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
558 " <foo yang:operation=\"replace\" yang:orig-value=\"42\" yang:orig-default=\"false\">40</foo>\n"
559 " <baz yang:operation=\"delete\">42</baz>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200560 "</hidden>\n";
561
562 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200563}
564
565static void
566test_list(void **state)
567{
Radek Iša56ca9e42020-09-08 18:42:00 +0200568 (void) state;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100569 const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
570 " <list>\n"
571 " <name>a</name>\n"
572 " <value>1</value>\n"
573 " </list>\n"
574 " <list>\n"
575 " <name>b</name>\n"
576 " <value>2</value>\n"
577 " </list>\n"
578 "</df>\n";
579 const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
580 " <list>\n"
581 " <name>b</name>\n"
582 " <value>-2</value>\n"
583 " </list>\n"
584 " <list>\n"
585 " <name>c</name>\n"
586 " <value>3</value>\n"
587 " </list>\n"
588 "</df>\n";
589 const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
590 " <list>\n"
591 " <name>b</name>\n"
592 " <value>-2</value>\n"
593 " </list>\n"
594 " <list>\n"
595 " <name>a</name>\n"
596 " <value>2</value>\n"
597 " </list>\n"
598 "</df>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200599
Radek Iša56ca9e42020-09-08 18:42:00 +0200600 const char *out_diff_1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100601 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
602 " <list yang:operation=\"delete\">\n"
603 " <name>a</name>\n"
604 " <value>1</value>\n"
605 " </list>\n"
606 " <list yang:operation=\"none\">\n"
607 " <name>b</name>\n"
608 " <value yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\">-2</value>\n"
609 " </list>\n"
610 " <list yang:operation=\"create\">\n"
611 " <name>c</name>\n"
612 " <value>3</value>\n"
613 " </list>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200614 "</df>\n";
615 const char *out_diff_2 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100616 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
617 " <list yang:operation=\"delete\">\n"
618 " <name>c</name>\n"
619 " <value>3</value>\n"
620 " </list>\n"
621 " <list yang:operation=\"create\">\n"
622 " <name>a</name>\n"
623 " <value>2</value>\n"
624 " </list>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200625 "</df>\n";
626 const char *out_merge =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100627 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
628 " <list yang:operation=\"none\">\n"
629 " <name>a</name>\n"
630 " <value yang:operation=\"replace\" yang:orig-value=\"1\" yang:orig-default=\"false\">2</value>\n"
631 " </list>\n"
632 " <list yang:operation=\"none\">\n"
633 " <name>b</name>\n"
634 " <value yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\">-2</value>\n"
635 " </list>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200636 "</df>\n";
637
638 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200639}
640
641static void
Michal Vasko58d89e92023-05-23 09:56:19 +0200642test_nested_list(void **state)
643{
644 struct lyd_node *data1, *data2, *diff;
645 const char *xml1, *xml2;
646
647 (void) state;
648
649 xml1 =
650 "<df xmlns=\"urn:libyang:tests:defaults\">"
651 " <list>"
652 " <name>n1</name>"
653 " <value>25</value>"
654 " <list2>"
655 " <name2>n22</name2>"
656 " <value2>26</value2>"
657 " </list2>"
658 " </list>"
659 " <list>"
660 " <name>n2</name>"
661 " <value>25</value>"
662 " <list2>"
663 " <name2>n22</name2>"
664 " <value2>26</value2>"
665 " </list2>"
666 " </list>"
667 " <list>"
668 " <name>n3</name>"
669 " <value>25</value>"
670 " <list2>"
671 " <name2>n22</name2>"
672 " <value2>26</value2>"
673 " </list2>"
674 " </list>"
675 " <list>"
676 " <name>n4</name>"
677 " <value>25</value>"
678 " <list2>"
679 " <name2>n22</name2>"
680 " <value2>26</value2>"
681 " </list2>"
682 " </list>"
683 " <list>"
684 " <name>n0</name>"
685 " <value>26</value>"
686 " <list2>"
687 " <name2>n22</name2>"
688 " <value2>26</value2>"
689 " </list2>"
690 " <list2>"
691 " <name2>n23</name2>"
692 " <value2>26</value2>"
693 " </list2>"
694 " </list>"
695 "</df>";
696 xml2 =
697 "<df xmlns=\"urn:libyang:tests:defaults\">"
698 " <list>"
699 " <name>n0</name>"
700 " <value>30</value>"
701 " <list2>"
702 " <name2>n23</name2>"
703 " <value2>26</value2>"
704 " </list2>"
705 " </list>"
706 "</df>";
707
708 CHECK_PARSE_LYD(xml1, data1);
709 CHECK_PARSE_LYD(xml2, data2);
710 CHECK_PARSE_LYD_DIFF(data1, data2, diff);
711
712 CHECK_LYD_STRING(diff,
713 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
714 " <list yang:operation=\"delete\">\n"
715 " <name>n1</name>\n"
716 " <value>25</value>\n"
717 " <list2>\n"
718 " <name2>n22</name2>\n"
719 " <value2>26</value2>\n"
720 " </list2>\n"
721 " </list>\n"
722 " <list yang:operation=\"delete\">\n"
723 " <name>n2</name>\n"
724 " <value>25</value>\n"
725 " <list2>\n"
726 " <name2>n22</name2>\n"
727 " <value2>26</value2>\n"
728 " </list2>\n"
729 " </list>\n"
730 " <list yang:operation=\"delete\">\n"
731 " <name>n3</name>\n"
732 " <value>25</value>\n"
733 " <list2>\n"
734 " <name2>n22</name2>\n"
735 " <value2>26</value2>\n"
736 " </list2>\n"
737 " </list>\n"
738 " <list yang:operation=\"delete\">\n"
739 " <name>n4</name>\n"
740 " <value>25</value>\n"
741 " <list2>\n"
742 " <name2>n22</name2>\n"
743 " <value2>26</value2>\n"
744 " </list2>\n"
745 " </list>\n"
746 " <list yang:operation=\"none\">\n"
747 " <name>n0</name>\n"
748 " <value yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"26\">30</value>\n"
749 " <list2 yang:operation=\"delete\">\n"
750 " <name2>n22</name2>\n"
751 " <value2>26</value2>\n"
752 " </list2>\n"
753 " </list>\n"
754 "</df>\n");
755
756 lyd_free_all(data1);
757 lyd_free_all(data2);
758 lyd_free_all(diff);
759}
760
761static void
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200762test_userord_llist(void **state)
763{
Radek Iša56ca9e42020-09-08 18:42:00 +0200764 (void) state;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100765 const char *xml1 =
766 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
767 " <llist>1</llist>\n"
768 " <llist>2</llist>\n"
769 " <llist>3</llist>\n"
770 " <llist>4</llist>\n"
771 " <llist>5</llist>\n"
772 "</df>\n";
773 const char *xml2 =
774 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
775 " <llist>1</llist>\n"
776 " <llist>4</llist>\n"
777 " <llist>3</llist>\n"
778 " <llist>2</llist>\n"
779 " <llist>5</llist>\n"
780 "</df>\n";
781 const char *xml3 =
782 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
783 " <llist>5</llist>\n"
784 " <llist>4</llist>\n"
785 " <llist>3</llist>\n"
786 " <llist>2</llist>\n"
787 "</df>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200788
Radek Iša56ca9e42020-09-08 18:42:00 +0200789 const char *out_diff_1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100790 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
791 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"1\">4</llist>\n"
792 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"4\">3</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200793 "</df>\n";
794 const char *out_diff_2 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100795 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
796 " <llist yang:operation=\"delete\" yang:orig-value=\"\">1</llist>\n"
797 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\">5</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200798 "</df>\n";
799 const char *out_merge =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100800 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
801 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"1\">4</llist>\n"
802 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"4\">3</llist>\n"
803 " <llist yang:orig-value=\"\" yang:operation=\"delete\">1</llist>\n"
804 " <llist yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\" yang:operation=\"replace\">5</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200805 "</df>\n";
806
807 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200808}
809
810static void
811test_userord_llist2(void **state)
812{
Radek Iša56ca9e42020-09-08 18:42:00 +0200813 (void) state;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100814 const char *xml1 =
815 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
816 " <llist>1</llist>\n"
817 " <list><name>a</name><value>1</value></list>\n"
818 " <llist>2</llist>\n"
819 " <llist>3</llist>\n"
820 " <llist>4</llist>\n"
821 "</df>\n";
822 const char *xml2 =
823 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
824 " <llist>1</llist>\n"
825 " <list><name>a</name><value>1</value></list>\n"
826 " <llist>2</llist>\n"
827 " <llist>4</llist>\n"
828 " <llist>3</llist>\n"
829 "</df>\n";
830 const char *xml3 =
831 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
832 " <llist>4</llist>\n"
833 " <llist>1</llist>\n"
834 " <list><name>a</name><value>1</value></list>\n"
835 " <llist>3</llist>\n"
836 "</df>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200837
Radek Iša56ca9e42020-09-08 18:42:00 +0200838 const char *out_diff_1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100839 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
840 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"2\">4</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200841 "</df>\n";
842 const char *out_diff_2 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100843 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
844 " <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n"
845 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">4</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200846 "</df>\n";
847 const char *out_merge =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100848 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
849 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\">4</llist>\n"
850 " <llist yang:orig-value=\"1\" yang:operation=\"delete\">2</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200851 "</df>\n";
852
853 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200854}
855
856static void
857test_userord_mix(void **state)
858{
Radek Iša56ca9e42020-09-08 18:42:00 +0200859 (void) state;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100860 const char *xml1 =
861 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
862 " <llist>1</llist>\n"
863 " <llist>2</llist>\n"
864 " <llist>3</llist>\n"
865 "</df>\n";
866 const char *xml2 =
867 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
868 " <llist>3</llist>\n"
869 " <llist>1</llist>\n"
870 "</df>\n";
871 const char *xml3 =
872 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
873 " <llist>1</llist>\n"
874 " <llist>4</llist>\n"
875 " <llist>3</llist>\n"
876 "</df>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200877
Radek Iša56ca9e42020-09-08 18:42:00 +0200878 const char *out_diff_1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100879 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
880 " <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n"
881 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">3</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200882 "</df>\n";
883 const char *out_diff_2 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100884 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
885 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\">1</llist>\n"
886 " <llist yang:operation=\"create\" yang:value=\"1\">4</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200887 "</df>\n";
888 const char *out_merge =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100889 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
890 " <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n"
891 " <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">3</llist>\n"
892 " <llist yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\" yang:operation=\"replace\">1</llist>\n"
893 " <llist yang:value=\"1\" yang:operation=\"create\">4</llist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200894 "</df>\n";
895
896 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
Michal Vaskoe893ddd2020-06-23 13:35:20 +0200897}
898
899static void
Michal Vaskoe78faec2021-04-08 17:24:43 +0200900test_userord_list(void **state)
901{
902 (void) state;
903 const char *xml1 =
904 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
905 " <ul>\n"
906 " <l1>a</l1>\n"
907 " <l2>1</l2>\n"
908 " </ul>\n"
909 " <ul>\n"
910 " <l1>b</l1>\n"
911 " <l2>2</l2>\n"
912 " </ul>\n"
913 " <ul>\n"
914 " <l1>c</l1>\n"
915 " <l2>3</l2>\n"
916 " </ul>\n"
917 "</df>\n";
918 const char *xml2 =
919 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
920 " <ul>\n"
921 " <l1>a</l1>\n"
922 " <l2>11</l2>\n"
923 " </ul>\n"
924 " <ul>\n"
925 " <l1>c</l1>\n"
926 " <l2>3</l2>\n"
927 " </ul>\n"
928 "</df>\n";
929 const char *xml3 =
930 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
931 " <ul>\n"
932 " <l1>c</l1>\n"
933 " <l2>33</l2>\n"
934 " </ul>\n"
935 " <ul>\n"
936 " <l1>b</l1>\n"
937 " <l2>2</l2>\n"
938 " </ul>\n"
939 "</df>\n";
940
941 const char *out_diff_1 =
942 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
943 " <ul>\n"
944 " <l1>a</l1>\n"
945 " <l2 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\">11</l2>\n"
946 " </ul>\n"
947 " <ul yang:operation=\"delete\" yang:orig-key=\"[l1='a']\">\n"
948 " <l1>b</l1>\n"
949 " <l2>2</l2>\n"
950 " </ul>\n"
951 "</df>\n";
952 const char *out_diff_2 =
953 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
954 " <ul yang:operation=\"delete\" yang:orig-key=\"\">\n"
955 " <l1>a</l1>\n"
956 " <l2>11</l2>\n"
957 " </ul>\n"
958 " <ul yang:operation=\"none\">\n"
959 " <l1>c</l1>\n"
960 " <l2 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\">33</l2>\n"
961 " </ul>\n"
962 " <ul yang:operation=\"create\" yang:key=\"[l1='c']\">\n"
963 " <l1>b</l1>\n"
964 " <l2>2</l2>\n"
965 " </ul>\n"
966 "</df>\n";
967 const char *out_merge =
968 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
969 " <ul yang:operation=\"delete\">\n"
970 " <l1>a</l1>\n"
971 " <l2 yang:operation=\"delete\">1</l2>\n"
972 " </ul>\n"
973 " <ul yang:orig-key=\"[l1='a']\" yang:operation=\"replace\" yang:key=\"[l1='c']\">\n"
974 " <l1>b</l1>\n"
975 " </ul>\n"
976 " <ul yang:operation=\"none\">\n"
977 " <l1>c</l1>\n"
978 " <l2 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\">33</l2>\n"
979 " </ul>\n"
980 "</df>\n";
981
982 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
983}
984
985static void
Michal Vasko5da938a2022-03-01 09:19:02 +0100986test_userord_list2(void **state)
987{
988 (void) state;
989 const char *xml1 =
990 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
991 " <ul>\n"
992 " <l1>d</l1>\n"
993 " <l2>4</l2>\n"
994 " </ul>\n"
995 "</df>\n";
996 const char *xml2 =
997 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
998 " <ul>\n"
999 " <l1>c</l1>\n"
1000 " <l2>3</l2>\n"
1001 " </ul>\n"
1002 " <ul>\n"
1003 " <l1>d</l1>\n"
1004 " <l2>4</l2>\n"
1005 " </ul>\n"
1006 "</df>\n";
1007 const char *xml3 =
1008 "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1009 " <ul>\n"
1010 " <l1>a</l1>\n"
1011 " <l2>1</l2>\n"
1012 " </ul>\n"
1013 " <ul>\n"
1014 " <l1>b</l1>\n"
1015 " <l2>2</l2>\n"
1016 " </ul>\n"
1017 " <ul>\n"
1018 " <l1>c</l1>\n"
1019 " <l2>3</l2>\n"
1020 " </ul>\n"
1021 " <ul>\n"
1022 " <l1>d</l1>\n"
1023 " <l2>4</l2>\n"
1024 " </ul>\n"
1025 "</df>\n";
1026
1027 const char *out_diff_1 =
1028 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1029 " <ul yang:operation=\"create\" yang:key=\"\">\n"
1030 " <l1>c</l1>\n"
1031 " <l2>3</l2>\n"
1032 " </ul>\n"
1033 "</df>\n";
1034 const char *out_diff_2 =
1035 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1036 " <ul yang:operation=\"create\" yang:key=\"\">\n"
1037 " <l1>a</l1>\n"
1038 " <l2>1</l2>\n"
1039 " </ul>\n"
1040 " <ul yang:operation=\"create\" yang:key=\"[l1='a']\">\n"
1041 " <l1>b</l1>\n"
1042 " <l2>2</l2>\n"
1043 " </ul>\n"
1044 "</df>\n";
1045 const char *out_merge =
1046 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1047 " <ul yang:operation=\"create\" yang:key=\"\">\n"
1048 " <l1>c</l1>\n"
1049 " <l2>3</l2>\n"
1050 " </ul>\n"
1051 " <ul yang:key=\"\" yang:operation=\"create\">\n"
1052 " <l1>a</l1>\n"
1053 " <l2>1</l2>\n"
1054 " </ul>\n"
1055 " <ul yang:key=\"[l1='a']\" yang:operation=\"create\">\n"
1056 " <l1>b</l1>\n"
1057 " <l2>2</l2>\n"
1058 " </ul>\n"
1059 "</df>\n";
1060
1061 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
1062}
1063
1064static void
Michal Vaskoe78faec2021-04-08 17:24:43 +02001065test_keyless_list(void **state)
1066{
1067 (void) state;
1068 const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1069 " <kl>\n"
1070 " <l1>a</l1>\n"
1071 " <l2>1</l2>\n"
1072 " </kl>\n"
1073 " <kl>\n"
1074 " <l1>b</l1>\n"
1075 " <l2>2</l2>\n"
1076 " </kl>\n"
1077 " <kl>\n"
1078 " <l1>c</l1>\n"
1079 " <l2>3</l2>\n"
1080 " </kl>\n"
1081 "</df>\n";
1082 const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1083 " <kl>\n"
1084 " <l1>b</l1>\n"
1085 " <l2>2</l2>\n"
1086 " </kl>\n"
1087 " <kl>\n"
1088 " <l1>a</l1>\n"
1089 " <l2>1</l2>\n"
1090 " </kl>\n"
1091 " <kl>\n"
1092 " <l1>a</l1>\n"
1093 " <l2>1</l2>\n"
1094 " </kl>\n"
1095 "</df>\n";
1096 const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1097 " <kl>\n"
1098 " <l1>c</l1>\n"
1099 " </kl>\n"
1100 " <kl>\n"
1101 " <l2>4</l2>\n"
1102 " </kl>\n"
1103 " <kl>\n"
1104 " <l1>e</l1>\n"
1105 " <l2>5</l2>\n"
1106 " </kl>\n"
1107 " <kl>\n"
1108 " <l1>f</l1>\n"
1109 " <l2>6</l2>\n"
1110 " </kl>\n"
1111 "</df>\n";
1112
1113 const char *out_diff_1 =
1114 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1115 " <kl yang:operation=\"delete\" yang:orig-position=\"2\">\n"
1116 " <l1>c</l1>\n"
1117 " <l2>3</l2>\n"
1118 " </kl>\n"
1119 " <kl yang:operation=\"replace\" yang:position=\"\" yang:orig-position=\"1\">\n"
1120 " <l1>b</l1>\n"
1121 " <l2>2</l2>\n"
1122 " </kl>\n"
1123 " <kl yang:operation=\"create\" yang:position=\"2\">\n"
1124 " <l1>a</l1>\n"
1125 " <l2>1</l2>\n"
1126 " </kl>\n"
1127 "</df>\n";
1128 const char *out_diff_2 =
1129 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1130 " <kl yang:operation=\"delete\" yang:orig-position=\"\">\n"
1131 " <l1>b</l1>\n"
1132 " <l2>2</l2>\n"
1133 " </kl>\n"
1134 " <kl yang:operation=\"delete\" yang:orig-position=\"\">\n"
1135 " <l1>a</l1>\n"
1136 " <l2>1</l2>\n"
1137 " </kl>\n"
1138 " <kl yang:operation=\"delete\" yang:orig-position=\"\">\n"
1139 " <l1>a</l1>\n"
1140 " <l2>1</l2>\n"
1141 " </kl>\n"
1142 " <kl yang:operation=\"create\" yang:position=\"\">\n"
1143 " <l1>c</l1>\n"
1144 " </kl>\n"
1145 " <kl yang:operation=\"create\" yang:position=\"1\">\n"
1146 " <l2>4</l2>\n"
1147 " </kl>\n"
1148 " <kl yang:operation=\"create\" yang:position=\"2\">\n"
1149 " <l1>e</l1>\n"
1150 " <l2>5</l2>\n"
1151 " </kl>\n"
1152 " <kl yang:operation=\"create\" yang:position=\"3\">\n"
1153 " <l1>f</l1>\n"
1154 " <l2>6</l2>\n"
1155 " </kl>\n"
1156 "</df>\n";
1157 const char *out_merge =
1158 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1159 " <kl yang:operation=\"delete\" yang:orig-position=\"2\">\n"
1160 " <l1>c</l1>\n"
1161 " <l2>3</l2>\n"
1162 " </kl>\n"
1163 " <kl yang:orig-position=\"1\" yang:operation=\"delete\">\n"
1164 " <l1>b</l1>\n"
1165 " <l2>2</l2>\n"
1166 " </kl>\n"
1167 " <kl yang:orig-position=\"\" yang:operation=\"delete\">\n"
1168 " <l1>a</l1>\n"
1169 " <l2>1</l2>\n"
1170 " </kl>\n"
1171 " <kl yang:position=\"\" yang:operation=\"create\">\n"
1172 " <l1>c</l1>\n"
1173 " </kl>\n"
1174 " <kl yang:position=\"1\" yang:operation=\"create\">\n"
1175 " <l2>4</l2>\n"
1176 " </kl>\n"
1177 " <kl yang:position=\"2\" yang:operation=\"create\">\n"
1178 " <l1>e</l1>\n"
1179 " <l2>5</l2>\n"
1180 " </kl>\n"
1181 " <kl yang:position=\"3\" yang:operation=\"create\">\n"
1182 " <l1>f</l1>\n"
1183 " <l2>6</l2>\n"
1184 " </kl>\n"
1185 "</df>\n";
1186
1187 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
1188}
1189
1190static void
1191test_state_llist(void **state)
1192{
1193 (void) state;
1194 const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1195 " <kll>a</kll>\n"
1196 " <kll>b</kll>\n"
1197 " <kll>c</kll>\n"
1198 "</df>\n";
1199 const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1200 " <kll>b</kll>\n"
1201 " <kll>c</kll>\n"
1202 " <kll>a</kll>\n"
1203 " <kll>a</kll>\n"
1204 " <kll>a</kll>\n"
1205 "</df>\n";
1206 const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1207 " <kll>a</kll>\n"
1208 " <kll>d</kll>\n"
1209 " <kll>a</kll>\n"
1210 "</df>\n";
1211
1212 const char *out_diff_1 =
1213 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1214 " <kll yang:operation=\"replace\" yang:orig-default=\"false\" yang:position=\"\" yang:orig-position=\"1\">b</kll>\n"
1215 " <kll yang:operation=\"replace\" yang:orig-default=\"false\" yang:position=\"1\" yang:orig-position=\"2\">c</kll>\n"
1216 " <kll yang:operation=\"create\" yang:position=\"3\">a</kll>\n"
1217 " <kll yang:operation=\"create\" yang:position=\"4\">a</kll>\n"
1218 "</df>\n";
1219 const char *out_diff_2 =
1220 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1221 " <kll yang:operation=\"delete\" yang:orig-position=\"\">b</kll>\n"
1222 " <kll yang:operation=\"delete\" yang:orig-position=\"\">c</kll>\n"
1223 " <kll yang:operation=\"delete\" yang:orig-position=\"2\">a</kll>\n"
1224 " <kll yang:operation=\"create\" yang:position=\"1\">d</kll>\n"
1225 "</df>\n";
1226 const char *out_merge =
1227 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1228 " <kll yang:orig-default=\"false\" yang:orig-position=\"1\" yang:operation=\"delete\">b</kll>\n"
1229 " <kll yang:orig-default=\"false\" yang:orig-position=\"2\" yang:operation=\"delete\">c</kll>\n"
1230 " <kll yang:operation=\"create\" yang:position=\"4\">a</kll>\n"
1231 " <kll yang:position=\"1\" yang:operation=\"create\">d</kll>\n"
1232 "</df>\n";
1233
1234 TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
1235}
1236
1237static void
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001238test_wd(void **state)
1239{
Radek Iša56ca9e42020-09-08 18:42:00 +02001240 (void) state;
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001241 const struct lys_module *mod;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001242 const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1243 " <foo>41</foo>\n"
1244 " <dllist>4</dllist>\n"
1245 "</df>\n";
1246 const char *xml3 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
1247 " <foo>42</foo>\n"
1248 " <dllist>4</dllist>\n"
1249 " <dllist>1</dllist>\n"
1250 "</df>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001251
Radek Iša56ca9e42020-09-08 18:42:00 +02001252 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "defaults");
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001253 assert_non_null(mod);
1254
Radek Iša56ca9e42020-09-08 18:42:00 +02001255 struct lyd_node *model_1 = NULL;
1256
1257 assert_int_equal(lyd_validate_module(&model_1, mod, 0, NULL), LY_SUCCESS);
1258 assert_ptr_not_equal(model_1, NULL);
1259
1260 struct lyd_node *model_2;
1261 struct lyd_node *model_3;
1262
1263 CHECK_PARSE_LYD_PARAM(xml2, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, model_2);
1264 CHECK_PARSE_LYD_PARAM(xml3, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, model_3);
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001265
Michal Vaskoe6323f62020-07-09 15:49:02 +02001266 /* diff1 */
Radek Iša56ca9e42020-09-08 18:42:00 +02001267 struct lyd_node *diff1 = NULL;
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001268
Radek Iša56ca9e42020-09-08 18:42:00 +02001269 assert_int_equal(lyd_diff_siblings(model_1, model_2, LYD_DIFF_DEFAULTS, &diff1), LY_SUCCESS);
1270 assert_non_null(diff1);
1271
1272 const char *diff1_out_1 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001273 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1274 " <foo yang:operation=\"replace\" yang:orig-default=\"true\" yang:orig-value=\"42\">41</foo>\n"
1275 " <dllist yang:operation=\"delete\">1</dllist>\n"
1276 " <dllist yang:operation=\"delete\">2</dllist>\n"
1277 " <dllist yang:operation=\"delete\">3</dllist>\n"
1278 " <dllist yang:operation=\"create\">4</dllist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +02001279 "</df>\n";
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001280
Radek Iša56ca9e42020-09-08 18:42:00 +02001281 CHECK_LYD_STRING_PARAM(diff1, diff1_out_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
1282 assert_int_equal(lyd_diff_apply_all(&model_1, diff1), LY_SUCCESS);
1283 CHECK_LYD(model_1, model_2);
Michal Vaskoe6323f62020-07-09 15:49:02 +02001284
1285 /* diff2 */
Radek Iša56ca9e42020-09-08 18:42:00 +02001286 struct lyd_node *diff2;
Michal Vaskoe6323f62020-07-09 15:49:02 +02001287
Radek Iša56ca9e42020-09-08 18:42:00 +02001288 assert_int_equal(lyd_diff_siblings(model_2, model_3, LYD_DIFF_DEFAULTS, &diff2), LY_SUCCESS);
1289 assert_non_null(diff2);
1290 CHECK_LYD_STRING(diff2,
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001291 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1292 " <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"41\">42</foo>\n"
1293 " <dllist yang:operation=\"create\">1</dllist>\n"
1294 "</df>\n");
Michal Vaskoe6323f62020-07-09 15:49:02 +02001295
Radek Iša56ca9e42020-09-08 18:42:00 +02001296 assert_int_equal(lyd_diff_apply_all(&model_2, diff2), LY_SUCCESS);
1297 CHECK_LYD(model_2, model_3);
Michal Vaskoe6323f62020-07-09 15:49:02 +02001298
1299 /* merge */
Radek Iša56ca9e42020-09-08 18:42:00 +02001300 assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS);
Michal Vaskoe6323f62020-07-09 15:49:02 +02001301
Radek Iša56ca9e42020-09-08 18:42:00 +02001302 const char *diff1_out_2 =
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001303 "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
1304 " <foo yang:orig-default=\"true\" yang:operation=\"none\">42</foo>\n"
1305 " <dllist yang:operation=\"none\" yang:orig-default=\"true\">1</dllist>\n"
1306 " <dllist yang:operation=\"delete\">2</dllist>\n"
1307 " <dllist yang:operation=\"delete\">3</dllist>\n"
1308 " <dllist yang:operation=\"create\">4</dllist>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +02001309 "</df>\n";
1310
1311 CHECK_LYD_STRING_PARAM(diff1, diff1_out_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
1312
1313 lyd_free_all(model_1);
1314 lyd_free_all(model_2);
1315 lyd_free_all(model_3);
1316 lyd_free_all(diff1);
1317 lyd_free_all(diff2);
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001318}
1319
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001320int
1321main(void)
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001322{
1323 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +02001324 UTEST(test_invalid, setup),
1325 UTEST(test_same, setup),
1326 UTEST(test_empty1, setup),
1327 UTEST(test_empty2, setup),
1328 UTEST(test_empty_nested, setup),
Michal Vasko17d0c5c2021-11-01 11:31:11 +01001329 UTEST(test_delete_merge, setup),
Radek Iša56ca9e42020-09-08 18:42:00 +02001330 UTEST(test_leaf, setup),
1331 UTEST(test_list, setup),
Michal Vasko58d89e92023-05-23 09:56:19 +02001332 UTEST(test_nested_list, setup),
Radek Iša56ca9e42020-09-08 18:42:00 +02001333 UTEST(test_userord_llist, setup),
1334 UTEST(test_userord_llist2, setup),
1335 UTEST(test_userord_mix, setup),
Michal Vaskoe78faec2021-04-08 17:24:43 +02001336 UTEST(test_userord_list, setup),
Michal Vasko5da938a2022-03-01 09:19:02 +01001337 UTEST(test_userord_list2, setup),
Michal Vaskoe78faec2021-04-08 17:24:43 +02001338 UTEST(test_keyless_list, setup),
1339 UTEST(test_state_llist, setup),
Radek Iša56ca9e42020-09-08 18:42:00 +02001340 UTEST(test_wd, setup),
Michal Vaskoe893ddd2020-06-23 13:35:20 +02001341 };
1342
1343 return cmocka_run_group_tests(tests, NULL, NULL);
1344}