blob: e678cbf14e91b103f46d0da250e78a265c61f0cb [file] [log] [blame]
aPiecek20ddf8b2021-01-08 11:50:37 +01001/*
2 * @file test_printer_tree.c
3 * @author: Adam Piecek <piecek@cesnet.cz>
4 * @brief unit tests for functions from printer_tree.c
5 *
6 * Copyright (c) 2019-2021 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14#define _UTEST_MAIN_
15#include "utests.h"
16
17#include "common.h"
18#include "context.h"
19#include "out.h"
20#include "printer_schema.h"
21#include "tree_schema.h"
22
23#define TEST_LOCAL_SETUP \
24 char *printed; \
aPiecek20ddf8b2021-01-08 11:50:37 +010025 const struct lys_module *mod; \
26 const char *orig; \
aPieceke376b922021-04-19 08:08:14 +020027 const char *expect; \
28 assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +010029
aPieceke376b922021-04-19 08:08:14 +020030#define TEST_LOCAL_PRINT(MOD, LINE_LENGTH) \
31 assert_int_equal(LY_SUCCESS, lys_print_module(UTEST_OUT, MOD, LYS_OUT_TREE, LINE_LENGTH, 0));
aPiecek20ddf8b2021-01-08 11:50:37 +010032
33#define TEST_LOCAL_TEARDOWN \
aPieceke376b922021-04-19 08:08:14 +020034 ly_out_free(UTEST_OUT, NULL, 1);
aPiecek20ddf8b2021-01-08 11:50:37 +010035
36static void
37base_sections(void **state)
38{
39 TEST_LOCAL_SETUP;
aPiecekdc8fd572021-04-19 10:47:23 +020040
41 orig =
42 "module a01xx {\n"
43 " yang-version 1.1;\n"
44 " namespace \"xx:y\";\n"
45 " prefix xx;\n"
46 " container c;\n"
47 " container d;\n"
48 "}\n";
49
50 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
51
52 /* module with import statement */
aPiecek20ddf8b2021-01-08 11:50:37 +010053 orig =
54 "module a01 {\n"
55 " yang-version 1.1;\n"
56 " namespace \"x:y\";\n"
57 " prefix x;\n"
58 "\n"
aPiecekdc8fd572021-04-19 10:47:23 +020059 " import a01xx {\n"
60 " prefix xx;\n"
61 " }\n"
62 "\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010063 " grouping g1;\n"
64 "\n"
65 " grouping g2;\n"
aPiecekdc8fd572021-04-19 10:47:23 +020066 " container g;\n"
67 " augment \"/xx:c\" {\n"
68 " container e;\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010069 " }\n"
aPiecekdc8fd572021-04-19 10:47:23 +020070 " augment \"/xx:d\" {\n"
71 " container f;\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010072 " }\n"
73 " rpc rpc1;\n"
74 " rpc rpc2;\n"
75 " notification n1;\n"
76 " notification n2;\n"
77 "}\n";
78
aPiecekdc8fd572021-04-19 10:47:23 +020079 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
80
81 /* from pyang */
aPiecek20ddf8b2021-01-08 11:50:37 +010082 expect =
83 "module: a01\n"
aPiecekdc8fd572021-04-19 10:47:23 +020084 " +--rw g\n"
85 "\n"
86 " augment /xx:c:\n"
87 " +--rw e\n"
88 " augment /xx:d:\n"
89 " +--rw f\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010090 "\n"
91 " rpcs:\n"
92 " +---x rpc1\n"
93 " +---x rpc2\n"
94 "\n"
95 " notifications:\n"
96 " +---n n1\n"
aPiecekdc8fd572021-04-19 10:47:23 +020097 " +---n n2\n"
98 "\n"
99 " grouping g1\n"
100 " grouping g2\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100101
aPieceke376b922021-04-19 08:08:14 +0200102 TEST_LOCAL_PRINT(mod, 72);
103 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100104 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200105
106 ly_out_reset(UTEST_OUT);
107
108 /* from pyang */
109 expect =
110 "module: a01\n"
111 " +--rw g\n"
112 "\n"
113 " augment /xx:c:\n"
114 " +--rw e\n"
115 " augment /xx:d:\n"
116 " +--rw f\n"
117 "\n"
118 " rpcs:\n"
119 " +---x rpc1\n"
120 " +---x rpc2\n"
121 "\n"
122 " notifications:\n"
123 " +---n n1\n"
124 " +---n n2\n";
125
126 /* using lysc tree */
127 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
128 TEST_LOCAL_PRINT(mod, 72);
129 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
130 assert_string_equal(printed, expect);
131 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
132
aPiecek20ddf8b2021-01-08 11:50:37 +0100133 TEST_LOCAL_TEARDOWN;
134}
135
136static void
137node_status(void **state)
138{
139 TEST_LOCAL_SETUP;
140 orig =
141 "module a02 {\n"
142 " yang-version 1.1;\n"
143 " namespace \"x:y\";\n"
144 " prefix x;\n"
145 " container l {\n"
146 " status current;\n"
147 " }\n"
148 " container m {\n"
149 " status deprecated;\n"
150 " }\n"
151 " container n {\n"
152 " status obsolete;\n"
153 " }\n"
154 "}\n";
155
156 /* from pyang */
157 expect =
158 "module: a02\n"
159 " +--rw l\n"
160 " x--rw m\n"
161 " o--rw n\n";
162
aPieceke376b922021-04-19 08:08:14 +0200163 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
164 TEST_LOCAL_PRINT(mod, 72);
165 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100166 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200167
168 ly_out_reset(UTEST_OUT);
169 /* using lysc tree */
170 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
171 TEST_LOCAL_PRINT(mod, 72);
172 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
173 assert_string_equal(printed, expect);
174 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
175
aPiecek20ddf8b2021-01-08 11:50:37 +0100176 TEST_LOCAL_TEARDOWN;
177}
178
179static void
180node_config_flags(void **state)
181{
182 TEST_LOCAL_SETUP;
183 orig =
184 "module a03 {\n"
185 " yang-version 1.1;\n"
186 " namespace \"x:y\";\n"
187 " prefix x;\n"
188 " container l {\n"
189 " config true;\n"
190 " }\n"
191 " container m {\n"
192 " config false;\n"
193 " }\n"
194 "}\n";
195
196 /* from pyang */
197 expect =
198 "module: a03\n"
199 " +--rw l\n"
200 " +--ro m\n";
201
aPieceke376b922021-04-19 08:08:14 +0200202 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
203 TEST_LOCAL_PRINT(mod, 72);
204 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100205 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200206
207 ly_out_reset(UTEST_OUT);
208 /* using lysc tree */
209 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
210 TEST_LOCAL_PRINT(mod, 72);
211 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
212 assert_string_equal(printed, expect);
213 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
214
aPiecek20ddf8b2021-01-08 11:50:37 +0100215 TEST_LOCAL_TEARDOWN;
216}
217
218static void
219node_rpcs_flags(void **state)
220{
221 TEST_LOCAL_SETUP;
222 orig =
223 "module a04 {\n"
224 " yang-version 1.1;\n"
225 " namespace \"x:y\";\n"
226 " prefix x;\n"
227 " container cont {\n"
228 " action rpc1 {\n"
229 "\n"
230 " input {\n"
231 " leaf in {\n"
232 " type string;\n"
233 " }\n"
234 " }\n"
aPiecek9e505922021-04-19 13:45:08 +0200235 "\n"
236 " output {\n"
237 " leaf out {\n"
238 " type string;\n"
239 " }\n"
240 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100241 " }\n"
242 " }\n"
243 "}\n";
244
245 /* from pyang */
246 expect =
247 "module: a04\n"
248 " +--rw cont\n"
249 " +---x rpc1\n"
250 " +---w input\n"
aPiecek9e505922021-04-19 13:45:08 +0200251 " | +---w in? string\n"
252 " +--ro output\n"
253 " +--ro out? string\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100254
aPieceke376b922021-04-19 08:08:14 +0200255 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
256 TEST_LOCAL_PRINT(mod, 72);
257 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100258 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200259
260 ly_out_reset(UTEST_OUT);
261 /* using lysc tree */
262 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
263 TEST_LOCAL_PRINT(mod, 72);
264 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
265 assert_string_equal(printed, expect);
266 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
267
aPiecek20ddf8b2021-01-08 11:50:37 +0100268 TEST_LOCAL_TEARDOWN;
269}
270
271static void
272node_grouping_flags(void **state)
273{
274 TEST_LOCAL_SETUP;
275 orig =
276 "module a05 {\n"
277 " yang-version 1.1;\n"
278 " namespace \"x:y\";\n"
279 " prefix x;\n"
280 "\n"
281 " grouping g {\n"
aPiecekdc8fd572021-04-19 10:47:23 +0200282 " leaf a {\n"
283 " type string;\n"
284 " config true;\n"
285 " }\n"
286 " leaf b {\n"
287 " type string;\n"
288 " config false;\n"
289 " }\n"
290 " leaf c {\n"
291 " type string;\n"
292 " }\n"
293 " container d {\n"
294 " config false;\n"
295 " leaf e {\n"
296 " type string;\n"
297 " }\n"
298 " }\n"
299 " container f {\n"
300 " leaf g {\n"
301 " type string;\n"
302 " }\n"
303 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100304 " }\n"
305 " container d {\n"
306 " uses g;\n"
307 " }\n"
308 "}\n";
309
aPiecekdc8fd572021-04-19 10:47:23 +0200310 /* from yanglint1 */
aPiecek20ddf8b2021-01-08 11:50:37 +0100311 expect =
312 "module: a05\n"
313 " +--rw d\n"
314 " +---u g\n"
315 "\n"
316 " grouping g:\n"
aPiecekdc8fd572021-04-19 10:47:23 +0200317 " +--rw a? string\n"
318 " +--ro b? string\n"
319 " +---- c? string\n"
320 " +--ro d\n"
321 " | +--ro e? string\n"
322 " +---- f\n"
323 " +---- g? string\n";
324
aPieceke376b922021-04-19 08:08:14 +0200325 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
326 TEST_LOCAL_PRINT(mod, 72);
327 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100328 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200329
330 /* from pyang */
331 expect =
332 "module: a05\n"
333 " +--rw d\n"
334 " +--rw a? string\n"
335 " +--ro b? string\n"
336 " +--rw c? string\n"
337 " +--ro d\n"
338 " | +--ro e? string\n"
339 " +--rw f\n"
340 " +--rw g? string\n";
341
342 ly_out_reset(UTEST_OUT);
343 /* using lysc tree */
344 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
345 TEST_LOCAL_PRINT(mod, 72);
346 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
347 assert_string_equal(printed, expect);
348 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
349
aPiecek20ddf8b2021-01-08 11:50:37 +0100350 TEST_LOCAL_TEARDOWN;
351}
352
353static void
354notif_inside_container(void **state)
355{
356 TEST_LOCAL_SETUP;
357 orig =
358 "module a06 {\n"
359 " yang-version 1.1;\n"
360 " namespace \"x:y\";\n"
361 " prefix x;\n"
362 " container c {\n"
363 " notification notif;\n"
364 " }\n"
365 "}\n";
366
367 /* from pyang */
368 expect =
369 "module: a06\n"
370 " +--rw c\n"
371 " +---n notif\n";
372
aPieceke376b922021-04-19 08:08:14 +0200373 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
374 TEST_LOCAL_PRINT(mod, 72);
375 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100376 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200377
378 ly_out_reset(UTEST_OUT);
379 /* using lysc tree */
380 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
381 TEST_LOCAL_PRINT(mod, 72);
382 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
383 assert_string_equal(printed, expect);
384 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
385
aPiecek20ddf8b2021-01-08 11:50:37 +0100386 TEST_LOCAL_TEARDOWN;
387}
388
389static void
390node_choice(void **state)
391{
392 TEST_LOCAL_SETUP;
393 orig =
394 "module a07 {\n"
395 " yang-version 1.1;\n"
396 " namespace \"x:y\";\n"
397 " prefix x;\n"
398 " choice my_choice;\n"
399 "}\n";
400
401 /* from pyang */
402 expect =
403 "module: a07\n"
404 " +--rw (my_choice)?\n";
405
aPieceke376b922021-04-19 08:08:14 +0200406 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
407 TEST_LOCAL_PRINT(mod, 72);
408 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100409 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200410
411 ly_out_reset(UTEST_OUT);
412 /* using lysc tree */
413 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
414 TEST_LOCAL_PRINT(mod, 72);
415 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
416 assert_string_equal(printed, expect);
417 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
418
aPiecek20ddf8b2021-01-08 11:50:37 +0100419 TEST_LOCAL_TEARDOWN;
420}
421
422static void
423node_case(void **state)
424{
425 TEST_LOCAL_SETUP;
426 orig =
427 "module a08 {\n"
428 " yang-version 1.1;\n"
429 " namespace \"x:y\";\n"
430 " prefix x;\n"
aPiecek7a28e2f2021-05-21 07:27:03 +0200431 "\n"
432 " feature foo;\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100433 " choice my_choice {\n"
434 " case my_case;\n"
435 " }\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200436 " choice shorthand {\n"
aPiecek7a28e2f2021-05-21 07:27:03 +0200437 " container cont1 {\n"
438 " if-feature \"foo\";\n"
aPiecekaa320c92021-05-21 07:34:24 +0200439 " status obsolete;\n"
aPiecek7a28e2f2021-05-21 07:27:03 +0200440 " }\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200441 " container cont2 {\n"
442 " container cont3;\n"
443 " }\n"
444 " }\n"
445 " container top {\n"
446 " choice shorthand1 {\n"
447 " container cont1;\n"
448 " }\n"
449 " choice shorthand2 {\n"
450 " container cont2 {\n"
451 " container cont3;\n"
452 " }\n"
453 " }\n"
454 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100455 "}\n";
456
457 /* from pyang */
458 expect =
459 "module: a08\n"
460 " +--rw (my_choice)?\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200461 " | +--:(my_case)\n"
462 " +--rw (shorthand)?\n"
aPiecekaa320c92021-05-21 07:34:24 +0200463 " | o--:(cont1)\n"
464 " | | o--rw cont1 {foo}?\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200465 " | +--:(cont2)\n"
466 " | +--rw cont2\n"
467 " | +--rw cont3\n"
468 " +--rw top\n"
469 " +--rw (shorthand1)?\n"
470 " | +--:(cont1)\n"
471 " | +--rw cont1\n"
472 " +--rw (shorthand2)?\n"
473 " +--:(cont2)\n"
474 " +--rw cont2\n"
475 " +--rw cont3\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100476
aPiecek7a28e2f2021-05-21 07:27:03 +0200477 const char *feats[] = {"foo", NULL};
478
479 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
aPieceke376b922021-04-19 08:08:14 +0200480 TEST_LOCAL_PRINT(mod, 72);
481 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100482 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200483
484 ly_out_reset(UTEST_OUT);
485 /* using lysc tree */
486 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
487 TEST_LOCAL_PRINT(mod, 72);
488 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
489 assert_string_equal(printed, expect);
490 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
491
aPiecek20ddf8b2021-01-08 11:50:37 +0100492 TEST_LOCAL_TEARDOWN;
493}
494
495static void
496optional_opts(void **state)
497{
498 TEST_LOCAL_SETUP;
499 /* throws libyang warn: Use of anydata to define configuration data is not recommended... */
500 orig =
501 "module a09 {\n"
502 " yang-version 1.1;\n"
503 " namespace \"x:y\";\n"
504 " prefix x;\n"
505 " leaf l1 {\n"
506 " type string;\n"
507 " mandatory true;\n"
508 " }\n"
509 " leaf l2 {\n"
510 " type string;\n"
511 " mandatory false;\n"
512 " }\n"
513 " choice c1 {\n"
514 " mandatory true;\n"
515 " }\n"
516 " choice c2 {\n"
517 " mandatory false;\n"
518 " }\n"
519 " anydata a1 {\n"
520 " mandatory true;\n"
521 " }\n"
522 " anydata a2 {\n"
523 " mandatory false;\n"
524 " }\n"
525 " anyxml x1 {\n"
526 " mandatory true;\n"
527 " }\n"
528 " anyxml x2 {\n"
529 " mandatory false;\n"
530 " }\n"
531 "}\n";
532
533 /* from yanglint 1 */
534 expect =
535 "module: a09\n"
536 " +--rw l1 string\n"
537 " +--rw l2? string\n"
538 " +--rw (c1)\n"
539 " +--rw (c2)?\n"
540 " +--rw a1 anydata\n"
541 " +--rw a2? anydata\n"
542 " +--rw x1 anyxml\n"
543 " +--rw x2? anyxml\n";
544
aPieceke376b922021-04-19 08:08:14 +0200545 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
546 TEST_LOCAL_PRINT(mod, 72);
547 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100548 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200549
550 ly_out_reset(UTEST_OUT);
551 /* using lysc tree */
552 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
553 TEST_LOCAL_PRINT(mod, 72);
554 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
555 assert_string_equal(printed, expect);
556 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
557
aPiecek20ddf8b2021-01-08 11:50:37 +0100558 TEST_LOCAL_TEARDOWN;
559}
560
561static void
562presence_container(void **state)
563{
564 TEST_LOCAL_SETUP;
565 orig =
566 "module a10 {\n"
567 " yang-version 1.1;\n"
568 " namespace \"x:y\";\n"
569 " prefix x;\n"
570 " container c;\n"
571 " container d {\n"
572 " presence \"str1\";\n"
573 " }\n"
574 "}\n";
575
576 /* from pyang */
577 expect =
578 "module: a10\n"
579 " +--rw c\n"
580 " +--rw d!\n";
581
aPieceke376b922021-04-19 08:08:14 +0200582 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
583 TEST_LOCAL_PRINT(mod, 72);
584 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100585 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200586
587 ly_out_reset(UTEST_OUT);
588 /* using lysc tree */
589 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
590 TEST_LOCAL_PRINT(mod, 72);
591 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
592 assert_string_equal(printed, expect);
593 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
594
aPiecek20ddf8b2021-01-08 11:50:37 +0100595 TEST_LOCAL_TEARDOWN;
596}
597
598static void
599node_keys(void **state)
600{
601 TEST_LOCAL_SETUP;
602 orig =
603 "module a11 {\n"
604 " yang-version 1.1;\n"
605 " namespace \"x:y\";\n"
606 " prefix x;\n"
607 " list l1 {\n"
608 " key \"a\";\n"
609 " leaf a {\n"
610 " type string;\n"
611 " }\n"
612 " }\n"
613 " list l2 {\n"
614 " key \"a b\";\n"
615 " leaf a {\n"
616 " type string;\n"
617 " }\n"
618 " leaf b {\n"
619 " type string;\n"
620 " }\n"
621 " }\n"
622 " leaf-list ll {\n"
623 " type string;\n"
624 " }\n"
625 "}\n";
626
627 /* from pyang */
628 expect =
629 "module: a11\n"
630 " +--rw l1* [a]\n"
631 " | +--rw a string\n"
632 " +--rw l2* [a b]\n"
633 " | +--rw a string\n"
634 " | +--rw b string\n"
635 " +--rw ll* string\n";
636
aPieceke376b922021-04-19 08:08:14 +0200637 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
638 TEST_LOCAL_PRINT(mod, 72);
639 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100640 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200641
642 ly_out_reset(UTEST_OUT);
643 /* using lysc tree */
644 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
645 TEST_LOCAL_PRINT(mod, 72);
646 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
647 assert_string_equal(printed, expect);
648 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
649
aPiecek20ddf8b2021-01-08 11:50:37 +0100650 TEST_LOCAL_TEARDOWN;
651}
652
653static void
654node_type_target(void **state)
655{
656 TEST_LOCAL_SETUP;
657 orig =
658 "module a12 {\n"
659 " yang-version 1.1;\n"
660 " namespace \"x:y\";\n"
661 " prefix x;\n"
662 " leaf a {\n"
663 " type leafref {\n"
664 " path \"/x:b\";\n"
665 " }\n"
666 " }\n"
667 " leaf b {\n"
668 " type string;\n"
669 " }\n"
670 "}\n";
671
672 /* from yanglint 1 */
673 expect =
674 "module: a12\n"
675 " +--rw a? -> /x:b\n"
676 " +--rw b? string\n";
677
aPieceke376b922021-04-19 08:08:14 +0200678 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
679 TEST_LOCAL_PRINT(mod, 72);
680 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100681 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200682
683 ly_out_reset(UTEST_OUT);
684 /* using lysc tree */
685 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
686 TEST_LOCAL_PRINT(mod, 72);
687 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
688 assert_string_equal(printed, expect);
689 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
690
aPiecek20ddf8b2021-01-08 11:50:37 +0100691 TEST_LOCAL_TEARDOWN;
692}
693
694static void
695node_type_leafref(void **state)
696{
697 TEST_LOCAL_SETUP;
698 orig =
699 "module a13 {\n"
700 " yang-version 1.1;\n"
701 " namespace \"x:y\";\n"
702 " prefix x;\n"
703 " leaf pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters {\n"
704 " type string;\n"
705 " }\n"
706 " leaf a {\n"
707 " type leafref {\n"
708 " path \"/x:pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters\";\n"
709 " }\n"
710 " }\n"
711 "}\n";
712
713 /* yanglint --tree-no-leafref-target --tree-line-length=72 */
714 expect =
715 "module: a13\n"
716 " +--rw pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters?\n"
717 " | string\n"
718 " +--rw a?\n"
719 " leafref\n";
720
aPieceke376b922021-04-19 08:08:14 +0200721 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
722 TEST_LOCAL_PRINT(mod, 72);
723 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100724 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200725
726 ly_out_reset(UTEST_OUT);
727 /* using lysc tree */
728 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
729 TEST_LOCAL_PRINT(mod, 72);
730 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
731 assert_string_equal(printed, expect);
732 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
733
aPiecek20ddf8b2021-01-08 11:50:37 +0100734 TEST_LOCAL_TEARDOWN;
735}
736
737static void
738node_iffeatures(void **state)
739{
740 TEST_LOCAL_SETUP;
741 orig =
742 "module a14 {\n"
743 " yang-version 1.1;\n"
744 " namespace \"x:y\";\n"
745 " prefix x;\n"
746 "\n"
747 " feature foo;\n"
748 "\n"
749 " feature bar;\n"
750 " container c {\n"
751 " if-feature \"foo or bar\";\n"
752 " }\n"
753 "}\n";
754
755 /* from pyang */
756 expect =
757 "module: a14\n"
758 " +--rw c {foo or bar}?\n";
759
aPieceke376b922021-04-19 08:08:14 +0200760 const char *feats[] = {"foo", NULL};
761
762 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
763 TEST_LOCAL_PRINT(mod, 72);
764 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100765 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200766
767 ly_out_reset(UTEST_OUT);
768 /* using lysc tree */
769 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
770 TEST_LOCAL_PRINT(mod, 72);
771 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
772 assert_string_equal(printed, expect);
773 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
774
aPiecek20ddf8b2021-01-08 11:50:37 +0100775 TEST_LOCAL_TEARDOWN;
776}
777
778static void
779indent_wrapper(void **state)
780{
781 TEST_LOCAL_SETUP;
782 orig =
783 "module a15 {\n"
784 " yang-version 1.1;\n"
785 " namespace \"x:y\";\n"
786 " prefix x;\n"
787 " container a {\n"
788 " container b;\n"
789 " }\n"
790 " container c {\n"
791 " container d {\n"
792 " container e;\n"
793 " }\n"
794 " container f {\n"
795 " container g;\n"
796 " }\n"
797 " }\n"
798 " container h;\n"
799 " container i {\n"
800 " container j;\n"
801 " container k;\n"
802 " }\n"
803 "}\n";
804
805 /* from pyang */
806 expect =
807 "module: a15\n"
808 " +--rw a\n"
809 " | +--rw b\n"
810 " +--rw c\n"
811 " | +--rw d\n"
812 " | | +--rw e\n"
813 " | +--rw f\n"
814 " | +--rw g\n"
815 " +--rw h\n"
816 " +--rw i\n"
817 " +--rw j\n"
818 " +--rw k\n";
819
aPieceke376b922021-04-19 08:08:14 +0200820 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
821 TEST_LOCAL_PRINT(mod, 72);
822 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100823 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200824
825 ly_out_reset(UTEST_OUT);
826 /* using lysc tree */
827 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
828 TEST_LOCAL_PRINT(mod, 72);
829 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
830 assert_string_equal(printed, expect);
831 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
832
aPiecek20ddf8b2021-01-08 11:50:37 +0100833 TEST_LOCAL_TEARDOWN;
834}
835
836static void
837line_length_twiddling(void **state)
838{
839 TEST_LOCAL_SETUP;
840 /* node_fits_tight */
841
842 orig =
843 "module a16 {\n"
844 " yang-version 1.1;\n"
845 " namespace \"x:y\";\n"
846 " prefix x;\n"
847 "\n"
848 " feature f;\n"
849 "\n"
850 " typedef some-long-type {\n"
851 " type string;\n"
852 " }\n"
853 " list my-list-name {\n"
854 " key \"key\";\n"
855 " leaf key {\n"
856 " type string;\n"
857 " }\n"
858 " leaf nod-leaf {\n"
859 " if-feature \"f\";\n"
860 " type some-long-type;\n"
861 " }\n"
862 " leaf nos-leaf {\n"
863 " if-feature \"f\";\n"
864 " type int32;\n"
865 " }\n"
866 " }\n"
867 "}\n";
868
869 /* pyang --tree-line-length 42 */
870 expect =
871 "module: a16\n"
872 " +--rw my-list-name* [key]\n"
873 " +--rw key string\n"
874 " +--rw nod-leaf? some-long-type {f}?\n"
875 " +--rw nos-leaf? int32 {f}?\n";
876
aPieceke376b922021-04-19 08:08:14 +0200877 const char *feats[] = {"f", NULL};
878
879 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
880 TEST_LOCAL_PRINT(mod, 42);
881 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100882 assert_string_equal(printed, expect);
883
aPieceke376b922021-04-19 08:08:14 +0200884 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200885 /* using lysc tree */
886 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
887 TEST_LOCAL_PRINT(mod, 42);
888 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
889 assert_string_equal(printed, expect);
890 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
891
892 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100893 /* break_before_iffeature */
894
895 /* pyang --tree-line-length 41 */
896 expect =
897 "module: a16\n"
898 " +--rw my-list-name* [key]\n"
899 " +--rw key string\n"
900 " +--rw nod-leaf? some-long-type\n"
901 " | {f}?\n"
902 " +--rw nos-leaf? int32 {f}?\n";
903
aPieceke376b922021-04-19 08:08:14 +0200904 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
905 TEST_LOCAL_PRINT(mod, 41);
906 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100907 assert_string_equal(printed, expect);
908
aPieceke376b922021-04-19 08:08:14 +0200909 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200910 /* using lysc tree */
911 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
912 TEST_LOCAL_PRINT(mod, 41);
913 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
914 assert_string_equal(printed, expect);
915 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
916
917 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100918 /* break_before_type */
919
920 /* pyang --tree-line-length 29 */
921 expect =
922 "module: a16\n"
923 " +--rw my-list-name* [key]\n"
924 " +--rw key string\n"
925 " +--rw nod-leaf?\n"
926 " | some-long-type\n"
927 " | {f}?\n"
928 " +--rw nos-leaf? int32\n"
929 " {f}?\n";
930
aPieceke376b922021-04-19 08:08:14 +0200931 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
932 TEST_LOCAL_PRINT(mod, 29);
933 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100934 assert_string_equal(printed, expect);
935
aPieceke376b922021-04-19 08:08:14 +0200936 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200937 /* using lysc tree */
938 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
939 TEST_LOCAL_PRINT(mod, 29);
940 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
941 assert_string_equal(printed, expect);
942 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
943
944 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100945 /* break_before_keys */
946
947 /* pyang --tree-line-length 23 */
948 expect =
949 "module: a16\n"
950 " +--rw my-list-name*\n"
951 " [key]\n"
952 " +--rw key\n"
953 " | string\n"
954 " +--rw nod-leaf?\n"
955 " | some-long-type\n"
956 " | {f}?\n"
957 " +--rw nos-leaf?\n"
958 " int32 {f}?\n";
959
aPieceke376b922021-04-19 08:08:14 +0200960 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
961 TEST_LOCAL_PRINT(mod, 23);
962 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100963 assert_string_equal(printed, expect);
964
aPieceke376b922021-04-19 08:08:14 +0200965 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200966 /* using lysc tree */
967 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
968 TEST_LOCAL_PRINT(mod, 23);
969 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
970 assert_string_equal(printed, expect);
971 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
972
973 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100974 /* every_node_name_is_too_long */
975
976 /* pyang --tree-line-length 14 */
977 expect =
978 "module: a16\n"
979 " +--rw my-list-name*\n"
980 " [key]\n"
981 " +--rw key\n"
982 " | string\n"
983 " +--rw nod-leaf?\n"
984 " | some-long-type\n"
985 " | {f}?\n"
986 " +--rw nos-leaf?\n"
987 " int32\n"
988 " {f}?\n";
989
aPieceke376b922021-04-19 08:08:14 +0200990 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
991 TEST_LOCAL_PRINT(mod, 14);
992 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100993 assert_string_equal(printed, expect);
994
aPiecek9e505922021-04-19 13:45:08 +0200995 ly_out_reset(UTEST_OUT);
996 /* using lysc tree */
997 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
998 TEST_LOCAL_PRINT(mod, 14);
999 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1000 assert_string_equal(printed, expect);
1001 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1002
aPiecek20ddf8b2021-01-08 11:50:37 +01001003 TEST_LOCAL_TEARDOWN;
1004}
1005
1006static void
1007break_before_leafref(void **state)
1008{
1009 TEST_LOCAL_SETUP;
1010 orig =
1011 "module a17 {\n"
1012 " yang-version 1.1;\n"
1013 " namespace \"x:y\";\n"
1014 " prefix x;\n"
1015 " leaf e {\n"
1016 " type string;\n"
1017 " }\n"
1018 " leaf abcd {\n"
1019 " type leafref {\n"
1020 " path \"/x:e\";\n"
1021 " }\n"
1022 " }\n"
1023 "}\n";
1024
1025 /* yanglint --tree-line-length 14 */
1026 expect =
1027 "module: a17\n"
1028 " +--rw e?\n"
1029 " | string\n"
1030 " +--rw abcd?\n"
1031 " -> /x:e\n";
1032
aPieceke376b922021-04-19 08:08:14 +02001033 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1034 TEST_LOCAL_PRINT(mod, 14);
1035 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001036 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001037
1038 ly_out_reset(UTEST_OUT);
1039 /* using lysc tree */
1040 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1041 TEST_LOCAL_PRINT(mod, 14);
1042 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1043 assert_string_equal(printed, expect);
1044 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1045
aPiecek20ddf8b2021-01-08 11:50:37 +01001046 TEST_LOCAL_TEARDOWN;
1047}
1048
1049static void
1050break_before_leafref_and_iffeature(void **state)
1051{
1052 TEST_LOCAL_SETUP;
1053 orig =
1054 "module a18 {\n"
1055 " yang-version 1.1;\n"
1056 " namespace \"x:y\";\n"
1057 " prefix x;\n"
1058 "\n"
1059 " feature f;\n"
1060 " leaf some-long-id {\n"
1061 " type string;\n"
1062 " }\n"
1063 " leaf a {\n"
1064 " if-feature \"f\";\n"
1065 " type leafref {\n"
1066 " path \"/x:some-long-id\";\n"
1067 " }\n"
1068 " }\n"
1069 "}\n";
1070
1071 /* yanglint --tree-no-leafref-target --tree-line-length=20 */
1072 expect =
1073 "module: a18\n"
1074 " +--rw some-long-id?\n"
1075 " | string\n"
1076 " +--rw a?\n"
1077 " leafref\n"
1078 " {f}?\n";
1079
aPieceke376b922021-04-19 08:08:14 +02001080 const char *feats[] = {"f", NULL};
1081
1082 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
1083 TEST_LOCAL_PRINT(mod, 20);
1084 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001085 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001086
1087 ly_out_reset(UTEST_OUT);
1088 /* using lysc tree */
1089 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1090 TEST_LOCAL_PRINT(mod, 20);
1091 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1092 assert_string_equal(printed, expect);
1093 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1094
aPiecek20ddf8b2021-01-08 11:50:37 +01001095 TEST_LOCAL_TEARDOWN;
1096}
1097
1098static void
1099basic_unified_indent_before_type(void **state)
1100{
1101 TEST_LOCAL_SETUP;
1102 orig =
1103 "module a19 {\n"
1104 " yang-version 1.1;\n"
1105 " namespace \"x:y\";\n"
1106 " prefix x;\n"
1107 "\n"
1108 " typedef longType {\n"
1109 " type string;\n"
1110 " }\n"
1111 " container A {\n"
1112 " leaf Bnode {\n"
1113 " type int8;\n"
1114 " }\n"
1115 " leaf Cnode {\n"
1116 " type int8;\n"
1117 " mandatory true;\n"
1118 " }\n"
1119 " leaf Dnode {\n"
1120 " type int8;\n"
1121 " mandatory true;\n"
1122 " }\n"
1123 " leaf E {\n"
1124 " type longType;\n"
1125 " mandatory true;\n"
1126 " }\n"
1127 " leaf G {\n"
1128 " type int8;\n"
1129 " }\n"
1130 " }\n"
1131 "}\n";
1132
1133 /* from pyang */
1134 expect =
1135 "module: a19\n"
1136 " +--rw A\n"
1137 " +--rw Bnode? int8\n"
1138 " +--rw Cnode int8\n"
1139 " +--rw Dnode int8\n"
1140 " +--rw E longType\n"
1141 " +--rw G? int8\n";
1142
aPieceke376b922021-04-19 08:08:14 +02001143 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1144 TEST_LOCAL_PRINT(mod, 72);
1145 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001146 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001147
1148 ly_out_reset(UTEST_OUT);
1149 /* using lysc tree */
1150 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1151 TEST_LOCAL_PRINT(mod, 72);
1152 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1153 assert_string_equal(printed, expect);
1154 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1155
aPiecek20ddf8b2021-01-08 11:50:37 +01001156 TEST_LOCAL_TEARDOWN;
1157}
1158
1159static void
1160twiddling_unified_indent_before_type(void **state)
1161{
1162 TEST_LOCAL_SETUP;
1163 /* basic_functionality */
1164
1165 orig =
1166 "module a20 {\n"
1167 " yang-version 1.1;\n"
1168 " namespace \"x:y\";\n"
1169 " prefix x;\n"
1170 "\n"
1171 " typedef longType {\n"
1172 " type string;\n"
1173 " }\n"
1174 " container A {\n"
1175 " leaf Bnode {\n"
1176 " type int8;\n"
1177 " }\n"
1178 " leaf CnodeIsBigger {\n"
1179 " type int8;\n"
1180 " mandatory true;\n"
1181 " }\n"
1182 " leaf Dnode {\n"
1183 " type int8;\n"
1184 " mandatory true;\n"
1185 " }\n"
1186 " leaf E {\n"
1187 " type longType;\n"
1188 " mandatory true;\n"
1189 " }\n"
1190 " leaf G {\n"
1191 " type int8;\n"
1192 " }\n"
1193 " }\n"
1194 "}\n";
1195
1196 /* pyang --tree-line-length 36 */
1197 expect =
1198 "module: a20\n"
1199 " +--rw A\n"
1200 " +--rw Bnode? int8\n"
1201 " +--rw CnodeIsBigger int8\n"
1202 " +--rw Dnode int8\n"
1203 " +--rw E longType\n"
1204 " +--rw G? int8\n";
1205
aPieceke376b922021-04-19 08:08:14 +02001206 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1207 TEST_LOCAL_PRINT(mod, 36);
1208 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001209 assert_string_equal(printed, expect);
1210
aPieceke376b922021-04-19 08:08:14 +02001211 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +02001212 /* using lysc tree */
1213 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1214 TEST_LOCAL_PRINT(mod, 36);
1215 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1216 assert_string_equal(printed, expect);
1217 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1218
1219 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +01001220 /* unified_indent_before_type_long_node_name */
1221
1222 /* pyang --tree-line-length 32 */
1223 expect =
1224 "module: a20\n"
1225 " +--rw A\n"
1226 " +--rw Bnode? int8\n"
1227 " +--rw CnodeIsBigger int8\n"
1228 " +--rw Dnode int8\n"
1229 " +--rw E\n"
1230 " | longType\n"
1231 " +--rw G? int8\n";
1232
aPieceke376b922021-04-19 08:08:14 +02001233 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1234 TEST_LOCAL_PRINT(mod, 32);
1235 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001236 assert_string_equal(printed, expect);
1237
aPieceke376b922021-04-19 08:08:14 +02001238 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +02001239 /* using lysc tree */
1240 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1241 TEST_LOCAL_PRINT(mod, 32);
1242 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1243 assert_string_equal(printed, expect);
1244 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1245
1246 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +01001247 /* unified_indent_before_type_long_node_type */
1248
1249 /* pyang --tree-line-length 31 */
1250 expect =
1251 "module: a20\n"
1252 " +--rw A\n"
1253 " +--rw Bnode?\n"
1254 " | int8\n"
1255 " +--rw CnodeIsBigger\n"
1256 " | int8\n"
1257 " +--rw Dnode\n"
1258 " | int8\n"
1259 " +--rw E\n"
1260 " | longType\n"
1261 " +--rw G?\n"
1262 " int8\n";
1263
aPieceke376b922021-04-19 08:08:14 +02001264 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1265 TEST_LOCAL_PRINT(mod, 31);
1266 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001267 assert_string_equal(printed, expect);
1268
aPiecek9e505922021-04-19 13:45:08 +02001269 ly_out_reset(UTEST_OUT);
1270 /* using lysc tree */
1271 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1272 TEST_LOCAL_PRINT(mod, 31);
1273 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1274 assert_string_equal(printed, expect);
1275 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1276
aPiecek20ddf8b2021-01-08 11:50:37 +01001277 TEST_LOCAL_TEARDOWN;
1278}
1279
1280static void
1281inheritance_of_config_flag(void **state)
1282{
1283 TEST_LOCAL_SETUP;
1284 orig =
1285 "module a21 {\n"
1286 " yang-version 1.1;\n"
1287 " namespace \"x:y\";\n"
1288 " prefix x;\n"
1289 " container a {\n"
1290 " config false;\n"
1291 " leaf b {\n"
1292 " type string;\n"
1293 " }\n"
1294 " }\n"
1295 "}\n";
1296
1297 /* from pyang */
1298 expect =
1299 "module: a21\n"
1300 " +--ro a\n"
1301 " +--ro b? string\n";
1302
aPieceke376b922021-04-19 08:08:14 +02001303 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1304 TEST_LOCAL_PRINT(mod, 72);
1305 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001306 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001307
1308 ly_out_reset(UTEST_OUT);
1309 /* using lysc tree */
1310 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1311 TEST_LOCAL_PRINT(mod, 72);
1312 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1313 assert_string_equal(printed, expect);
1314 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1315
aPiecek20ddf8b2021-01-08 11:50:37 +01001316 TEST_LOCAL_TEARDOWN;
1317}
1318
1319static void
1320inheritance_of_status_flag(void **state)
1321{
1322 TEST_LOCAL_SETUP;
1323 /* throws libyang warn: Missing explicit "..." status that was already specified in parent, inheriting. */
1324 orig =
1325 "module a22 {\n"
1326 " yang-version 1.1;\n"
1327 " namespace \"x:y\";\n"
1328 " prefix x;\n"
1329 " container a {\n"
1330 " status current;\n"
1331 " container b {\n"
1332 " status deprecated;\n"
1333 " leaf f {\n"
1334 " type string;\n"
1335 " }\n"
1336 " }\n"
1337 " container c {\n"
1338 " status obsolete;\n"
1339 " leaf g {\n"
1340 " type string;\n"
1341 " }\n"
1342 " }\n"
1343 " }\n"
1344 " container d {\n"
1345 " status deprecated;\n"
1346 " container h {\n"
1347 " status obsolete;\n"
1348 " leaf e {\n"
1349 " type string;\n"
1350 " }\n"
1351 " }\n"
1352 " }\n"
1353 "}\n";
1354
1355 /* from yanglint 1 */
1356 expect =
1357 "module: a22\n"
1358 " +--rw a\n"
1359 " | x--rw b\n"
1360 " | | x--rw f? string\n"
1361 " | o--rw c\n"
1362 " | o--rw g? string\n"
1363 " x--rw d\n"
1364 " o--rw h\n"
1365 " o--rw e? string\n";
1366
aPieceke376b922021-04-19 08:08:14 +02001367 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1368 TEST_LOCAL_PRINT(mod, 72);
1369 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001370 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001371
1372 ly_out_reset(UTEST_OUT);
1373 /* using lysc tree */
1374 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1375 TEST_LOCAL_PRINT(mod, 72);
1376 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1377 assert_string_equal(printed, expect);
1378 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1379
aPiecek20ddf8b2021-01-08 11:50:37 +01001380 TEST_LOCAL_TEARDOWN;
1381}
1382
1383static void
1384key_leaf_is_always_mandatory_true(void **state)
1385{
1386 TEST_LOCAL_SETUP;
1387 orig =
1388 "module a23 {\n"
1389 " yang-version 1.1;\n"
1390 " namespace \"x:y\";\n"
1391 " prefix x;\n"
1392 " list a {\n"
1393 " key \"k1\";\n"
1394 " list b {\n"
1395 " key \"k2\";\n"
1396 " leaf k1 {\n"
1397 " type string;\n"
1398 " }\n"
1399 " leaf k2 {\n"
1400 " type string;\n"
1401 " }\n"
1402 " }\n"
1403 " leaf k1 {\n"
1404 " type string;\n"
1405 " }\n"
1406 " }\n"
1407 "}\n";
1408
1409 /* from pyang */
1410 expect =
1411 "module: a23\n"
1412 " +--rw a* [k1]\n"
1413 " +--rw b* [k2]\n"
1414 " | +--rw k1? string\n"
1415 " | +--rw k2 string\n"
1416 " +--rw k1 string\n";
1417
aPieceke376b922021-04-19 08:08:14 +02001418 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1419 TEST_LOCAL_PRINT(mod, 72);
1420 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001421 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001422
1423 ly_out_reset(UTEST_OUT);
1424
1425 /* from pyang but with some swapped lines */
1426 expect =
1427 "module: a23\n"
1428 " +--rw a* [k1]\n"
1429 " +--rw k1 string\n"
1430 " +--rw b* [k2]\n"
1431 " +--rw k2 string\n"
1432 " +--rw k1? string\n";
1433
1434 /* using lysc tree */
1435 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1436 TEST_LOCAL_PRINT(mod, 72);
1437 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1438 assert_string_equal(printed, expect);
1439 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1440
aPiecek20ddf8b2021-01-08 11:50:37 +01001441 TEST_LOCAL_TEARDOWN;
1442}
1443
1444static void
1445transition_between_rpc_and_notif(void **state)
1446{
1447 TEST_LOCAL_SETUP;
1448 orig =
1449 "module a24 {\n"
1450 " yang-version 1.1;\n"
1451 " namespace \"x:y\";\n"
1452 " prefix x;\n"
1453 " container top {\n"
aPiecek9e505922021-04-19 13:45:08 +02001454 " leaf g {\n"
1455 " type string;\n"
1456 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +01001457 " action rpc1 {\n"
1458 "\n"
1459 " input {\n"
1460 " leaf in {\n"
1461 " type string;\n"
1462 " }\n"
1463 " }\n"
1464 " }\n"
1465 " action rpc2 {\n"
1466 "\n"
1467 " input {\n"
1468 " leaf in {\n"
1469 " type string;\n"
1470 " }\n"
1471 " }\n"
1472 "\n"
1473 " output {\n"
1474 " leaf out {\n"
1475 " type string;\n"
1476 " }\n"
1477 " }\n"
1478 " }\n"
1479 " notification n1;\n"
1480 " notification n2;\n"
1481 " }\n"
1482 "}\n";
1483
aPiecekb352de72021-05-21 09:04:04 +02001484 /* from pyang */
aPiecek20ddf8b2021-01-08 11:50:37 +01001485 expect =
1486 "module: a24\n"
1487 " +--rw top\n"
aPiecek9e505922021-04-19 13:45:08 +02001488 " +--rw g? string\n"
aPiecek20ddf8b2021-01-08 11:50:37 +01001489 " +---x rpc1\n"
1490 " | +---w input\n"
1491 " | +---w in? string\n"
1492 " +---x rpc2\n"
1493 " | +---w input\n"
1494 " | | +---w in? string\n"
1495 " | +--ro output\n"
1496 " | +--ro out? string\n"
1497 " +---n n1\n"
1498 " +---n n2\n";
1499
aPieceke376b922021-04-19 08:08:14 +02001500 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1501 TEST_LOCAL_PRINT(mod, 72);
1502 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001503 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001504
1505 ly_out_reset(UTEST_OUT);
1506 /* using lysc tree */
1507 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1508 TEST_LOCAL_PRINT(mod, 72);
1509 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1510 assert_string_equal(printed, expect);
1511 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1512
1513 TEST_LOCAL_TEARDOWN;
1514}
1515
1516static void
1517local_augment(void **state)
1518{
1519 TEST_LOCAL_SETUP;
1520
1521 orig =
1522 "module a25 {\n"
1523 " yang-version 1.1;\n"
1524 " namespace \"x:y\";\n"
1525 " prefix x;\n"
1526 " container g;\n"
1527 " augment \"/x:g\" {\n"
1528 " container e;\n"
1529 " }\n"
1530 "}\n";
1531
1532 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1533
1534 /* from pyang */
1535 expect =
1536 "module: a25\n"
1537 " +--rw g\n"
1538 " +--rw e\n";
1539
1540 /* using lysc tree */
1541 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1542 TEST_LOCAL_PRINT(mod, 72);
1543 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1544 assert_string_equal(printed, expect);
1545 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1546
aPiecek20ddf8b2021-01-08 11:50:37 +01001547 TEST_LOCAL_TEARDOWN;
1548}
1549
aPiecek7745b282021-04-20 13:54:52 +02001550static void
1551print_compiled_node(void **state)
1552{
1553 TEST_LOCAL_SETUP;
1554 const struct lysc_node *node;
1555
1556 orig =
1557 "module a26 {\n"
1558 " yang-version 1.1;\n"
1559 " namespace \"x:y\";\n"
1560 " prefix x;\n"
1561 " container g {\n"
1562 " leaf a {\n"
1563 " type string;\n"
1564 " }\n"
1565 " container h {\n"
1566 " leaf b {\n"
1567 " type string;\n"
1568 " mandatory true;\n"
1569 " }\n"
1570 " leaf c {\n"
1571 " type string;\n"
1572 " }\n"
1573 " }\n"
1574 " }\n"
1575 "}\n";
1576
1577 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1578
1579 /* pyang -f tree --tree-path /g/h/c */
1580 expect =
1581 "module: a26\n"
1582 " +--rw g\n"
1583 " +--rw h\n"
1584 " +--rw c? string\n";
1585
1586 /* using lysc tree */
1587 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1588
1589 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h/c", 0);
1590 CHECK_POINTER(node, 1);
1591 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
1592 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1593 assert_string_equal(printed, expect);
1594
1595 ly_out_reset(UTEST_OUT);
1596
1597 /* pyang -f tree --tree-path /g/h */
1598 expect =
1599 "module: a26\n"
1600 " +--rw g\n"
1601 " +--rw h\n"
1602 " +--rw b string\n"
1603 " +--rw c? string\n";
1604
1605 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
1606 CHECK_POINTER(node, 1);
1607 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
1608 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1609 assert_string_equal(printed, expect);
1610
1611 ly_out_reset(UTEST_OUT);
1612
1613 /* pyang whose output is adjusted manually */
1614 expect =
1615 "module: a26\n"
1616 " +--rw g\n"
1617 " +--rw h\n";
1618
1619 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
1620 CHECK_POINTER(node, 1);
1621 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, LYS_PRINT_NO_SUBSTMT));
1622 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1623 assert_string_equal(printed, expect);
1624
1625 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1626
1627 TEST_LOCAL_TEARDOWN;
1628}
1629
aPiecekaecf7512021-04-21 08:34:35 +02001630static LY_ERR
1631local_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
1632 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
1633 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
1634{
1635 *module_data = user_data;
1636 *format = LYS_IN_YANG;
1637 *free_module_data = NULL;
1638 return LY_SUCCESS;
1639}
1640
1641static void
1642print_parsed_submodule(void **state)
1643{
1644 TEST_LOCAL_SETUP;
1645
1646 orig = "module a27 {\n"
1647 " yang-version 1.1;\n"
1648 " namespace \"x:y\";\n"
1649 " prefix x;\n"
1650 "\n"
1651 " include \"a27-sub\";\n"
1652 "}\n";
1653
1654 char *submodule =
1655 "submodule a27-sub {\n"
1656 " yang-version 1.1;\n"
1657 " belongs-to a27 {\n"
1658 " prefix x;\n"
1659 " }\n"
1660 "\n"
1661 " container h {\n"
1662 " leaf b {\n"
1663 " type string;\n"
1664 " }\n"
1665 " }\n"
1666 "}\n";
1667
1668 /* edited pyang output */
1669 expect =
1670 "submodule: a27-sub\n"
1671 " +--rw h\n"
1672 " +--rw b? string\n";
1673
1674 ly_ctx_set_module_imp_clb(UTEST_LYCTX, local_imp_clb, submodule);
1675 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1676 assert_int_equal(LY_SUCCESS, lys_print_submodule(UTEST_OUT, mod->parsed->includes[0].submodule, LYS_OUT_TREE, 72, 0));
1677 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1678 assert_string_equal(printed, expect);
1679
1680 TEST_LOCAL_TEARDOWN;
1681}
1682
aPiecekb8e43f12021-04-23 12:52:22 +02001683static void
1684yang_data(void **state)
1685{
1686 TEST_LOCAL_SETUP;
1687
1688 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
1689 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-restconf", "2017-01-26", NULL));
1690
1691 orig =
1692 "module a28 {\n"
1693 " yang-version 1.1;\n"
1694 " namespace \"x:y\";\n"
1695 " prefix x;\n"
1696 "\n"
1697 " import ietf-restconf {\n"
1698 " prefix rc;\n"
1699 " revision-date 2017-01-26;\n"
1700 " }\n"
1701 "\n"
1702 " rc:yang-data \"tmp1\" {\n"
1703 " container cont1 {\n"
1704 " leaf lf {\n"
1705 " type string;\n"
1706 " }\n"
1707 " list l2 {\n"
1708 " key\n"
1709 " \"a b\";\n"
1710 " leaf a {\n"
1711 " type string;\n"
1712 " }\n"
1713 " leaf b {\n"
1714 " type string;\n"
1715 " }\n"
1716 " }\n"
1717 " }\n"
1718 " }\n"
1719 " rc:yang-data \"tmp2\" {\n"
1720 " container con2 {\n"
1721 " leaf lf {\n"
1722 " type string;\n"
1723 " }\n"
1724 " }\n"
1725 " }\n"
1726 " rc:yang-data \"tmp3\" {\n"
1727 " uses g1;\n"
1728 " uses g2;\n"
1729 " }\n"
1730 " rc:yang-data \"tmp4\" {\n"
1731 " choice x {\n"
1732 " case a {\n"
1733 " container z;\n"
1734 " }\n"
1735 " case b {\n"
1736 " container y;\n"
1737 " }\n"
1738 " }\n"
1739 " }\n"
1740 "\n"
1741 " grouping g1 {\n"
1742 " description\n"
1743 " \"Some Text\";\n"
1744 " }\n"
1745 "\n"
1746 " grouping g2 {\n"
1747 " container cont3;\n"
1748 " }\n"
1749 " container mont;\n"
1750 "}\n";
1751
aPiecekb352de72021-05-21 09:04:04 +02001752 /* from pyang (--tree-print-yang-data --tree-print-groupings -p "...")
1753 * but with these adjustments:
aPiecekb8e43f12021-04-23 12:52:22 +02001754 * - <flags> is always '--' for yang-data nodes
1755 * - yang-data tmp3 has two 'uses' nodes
1756 * - grouping g2 has ':' character at the end
1757 */
1758 expect =
1759 "module: a28\n"
1760 " +--rw mont\n"
1761 "\n"
1762 " grouping g1\n"
1763 " grouping g2:\n"
1764 " +---- cont3\n"
1765 "\n"
1766 " yang-data tmp1:\n"
1767 " +---- cont1\n"
1768 " +---- lf? string\n"
1769 " +---- l2* [a b]\n"
1770 " +---- a string\n"
1771 " +---- b string\n"
1772 " yang-data tmp2:\n"
1773 " +---- con2\n"
1774 " +---- lf? string\n"
1775 " yang-data tmp3:\n"
1776 " +---u g1\n"
1777 " +---u g2\n"
1778 " yang-data tmp4:\n"
1779 " +---- (x)?\n"
1780 " +--:(a)\n"
1781 " | +---- z\n"
1782 " +--:(b)\n"
1783 " +---- y\n";
1784
1785 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1786 TEST_LOCAL_PRINT(mod, 72);
1787 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1788 assert_string_equal(printed, expect);
1789
1790 ly_out_reset(UTEST_OUT);
1791
aPiecekb352de72021-05-21 09:04:04 +02001792 /* from pyang (--tree-print-yang-data -p "...")
1793 * but with these adjustments:
aPiecekb8e43f12021-04-23 12:52:22 +02001794 * <flags> is always '--' for yang-data nodes
1795 */
1796 expect =
1797 "module: a28\n"
1798 " +--rw mont\n"
1799 "\n"
1800 " yang-data tmp1:\n"
1801 " +---- cont1\n"
1802 " +---- lf? string\n"
1803 " +---- l2* [a b]\n"
1804 " +---- a string\n"
1805 " +---- b string\n"
1806 " yang-data tmp2:\n"
1807 " +---- con2\n"
1808 " +---- lf? string\n"
1809 " yang-data tmp3:\n"
1810 " +---- cont3\n"
1811 " yang-data tmp4:\n"
1812 " +---- (x)?\n"
1813 " +--:(a)\n"
1814 " | +---- z\n"
1815 " +--:(b)\n"
1816 " +---- y\n";
1817
1818 /* using lysc tree */
1819 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1820 TEST_LOCAL_PRINT(mod, 72);
1821 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1822 assert_string_equal(printed, expect);
1823 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1824
1825 TEST_LOCAL_TEARDOWN;
1826}
1827
aPiecek20ddf8b2021-01-08 11:50:37 +01001828int
1829main(void)
1830{
1831 const struct CMUnitTest tests[] = {
1832 UTEST(base_sections),
1833 UTEST(node_status),
1834 UTEST(node_config_flags),
1835 UTEST(node_rpcs_flags),
1836 UTEST(node_grouping_flags),
1837 UTEST(notif_inside_container),
1838 UTEST(node_choice),
1839 UTEST(node_case),
1840 UTEST(optional_opts),
1841 UTEST(presence_container),
1842 UTEST(node_keys),
1843 UTEST(node_type_target),
1844 UTEST(node_type_leafref),
1845 UTEST(node_iffeatures),
1846 UTEST(indent_wrapper),
1847 UTEST(line_length_twiddling),
1848 UTEST(break_before_leafref),
1849 UTEST(break_before_leafref_and_iffeature),
1850 UTEST(basic_unified_indent_before_type),
1851 UTEST(twiddling_unified_indent_before_type),
1852 UTEST(inheritance_of_config_flag),
1853 UTEST(inheritance_of_status_flag),
1854 UTEST(key_leaf_is_always_mandatory_true),
1855 UTEST(transition_between_rpc_and_notif),
aPiecek9e505922021-04-19 13:45:08 +02001856 UTEST(local_augment),
aPiecek7745b282021-04-20 13:54:52 +02001857 UTEST(print_compiled_node),
aPiecekaecf7512021-04-21 08:34:35 +02001858 UTEST(print_parsed_submodule),
aPiecekb8e43f12021-04-23 12:52:22 +02001859 UTEST(yang_data),
aPiecek20ddf8b2021-01-08 11:50:37 +01001860 };
1861
1862 return cmocka_run_group_tests(tests, NULL, NULL);
1863}