blob: 6b42d841cee303afa657ff2397abb24a80e658d9 [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"
431 " choice my_choice {\n"
432 " case my_case;\n"
433 " }\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200434 " choice shorthand {\n"
435 " container cont1;\n"
436 " container cont2 {\n"
437 " container cont3;\n"
438 " }\n"
439 " }\n"
440 " container top {\n"
441 " choice shorthand1 {\n"
442 " container cont1;\n"
443 " }\n"
444 " choice shorthand2 {\n"
445 " container cont2 {\n"
446 " container cont3;\n"
447 " }\n"
448 " }\n"
449 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100450 "}\n";
451
452 /* from pyang */
453 expect =
454 "module: a08\n"
455 " +--rw (my_choice)?\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200456 " | +--:(my_case)\n"
457 " +--rw (shorthand)?\n"
458 " | +--:(cont1)\n"
459 " | | +--rw cont1\n"
460 " | +--:(cont2)\n"
461 " | +--rw cont2\n"
462 " | +--rw cont3\n"
463 " +--rw top\n"
464 " +--rw (shorthand1)?\n"
465 " | +--:(cont1)\n"
466 " | +--rw cont1\n"
467 " +--rw (shorthand2)?\n"
468 " +--:(cont2)\n"
469 " +--rw cont2\n"
470 " +--rw cont3\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100471
aPieceke376b922021-04-19 08:08:14 +0200472 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
473 TEST_LOCAL_PRINT(mod, 72);
474 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100475 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200476
477 ly_out_reset(UTEST_OUT);
478 /* using lysc tree */
479 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
480 TEST_LOCAL_PRINT(mod, 72);
481 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
482 assert_string_equal(printed, expect);
483 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
484
aPiecek20ddf8b2021-01-08 11:50:37 +0100485 TEST_LOCAL_TEARDOWN;
486}
487
488static void
489optional_opts(void **state)
490{
491 TEST_LOCAL_SETUP;
492 /* throws libyang warn: Use of anydata to define configuration data is not recommended... */
493 orig =
494 "module a09 {\n"
495 " yang-version 1.1;\n"
496 " namespace \"x:y\";\n"
497 " prefix x;\n"
498 " leaf l1 {\n"
499 " type string;\n"
500 " mandatory true;\n"
501 " }\n"
502 " leaf l2 {\n"
503 " type string;\n"
504 " mandatory false;\n"
505 " }\n"
506 " choice c1 {\n"
507 " mandatory true;\n"
508 " }\n"
509 " choice c2 {\n"
510 " mandatory false;\n"
511 " }\n"
512 " anydata a1 {\n"
513 " mandatory true;\n"
514 " }\n"
515 " anydata a2 {\n"
516 " mandatory false;\n"
517 " }\n"
518 " anyxml x1 {\n"
519 " mandatory true;\n"
520 " }\n"
521 " anyxml x2 {\n"
522 " mandatory false;\n"
523 " }\n"
524 "}\n";
525
526 /* from yanglint 1 */
527 expect =
528 "module: a09\n"
529 " +--rw l1 string\n"
530 " +--rw l2? string\n"
531 " +--rw (c1)\n"
532 " +--rw (c2)?\n"
533 " +--rw a1 anydata\n"
534 " +--rw a2? anydata\n"
535 " +--rw x1 anyxml\n"
536 " +--rw x2? anyxml\n";
537
aPieceke376b922021-04-19 08:08:14 +0200538 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
539 TEST_LOCAL_PRINT(mod, 72);
540 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100541 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200542
543 ly_out_reset(UTEST_OUT);
544 /* using lysc tree */
545 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
546 TEST_LOCAL_PRINT(mod, 72);
547 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
548 assert_string_equal(printed, expect);
549 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
550
aPiecek20ddf8b2021-01-08 11:50:37 +0100551 TEST_LOCAL_TEARDOWN;
552}
553
554static void
555presence_container(void **state)
556{
557 TEST_LOCAL_SETUP;
558 orig =
559 "module a10 {\n"
560 " yang-version 1.1;\n"
561 " namespace \"x:y\";\n"
562 " prefix x;\n"
563 " container c;\n"
564 " container d {\n"
565 " presence \"str1\";\n"
566 " }\n"
567 "}\n";
568
569 /* from pyang */
570 expect =
571 "module: a10\n"
572 " +--rw c\n"
573 " +--rw d!\n";
574
aPieceke376b922021-04-19 08:08:14 +0200575 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
576 TEST_LOCAL_PRINT(mod, 72);
577 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100578 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200579
580 ly_out_reset(UTEST_OUT);
581 /* using lysc tree */
582 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
583 TEST_LOCAL_PRINT(mod, 72);
584 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
585 assert_string_equal(printed, expect);
586 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
587
aPiecek20ddf8b2021-01-08 11:50:37 +0100588 TEST_LOCAL_TEARDOWN;
589}
590
591static void
592node_keys(void **state)
593{
594 TEST_LOCAL_SETUP;
595 orig =
596 "module a11 {\n"
597 " yang-version 1.1;\n"
598 " namespace \"x:y\";\n"
599 " prefix x;\n"
600 " list l1 {\n"
601 " key \"a\";\n"
602 " leaf a {\n"
603 " type string;\n"
604 " }\n"
605 " }\n"
606 " list l2 {\n"
607 " key \"a b\";\n"
608 " leaf a {\n"
609 " type string;\n"
610 " }\n"
611 " leaf b {\n"
612 " type string;\n"
613 " }\n"
614 " }\n"
615 " leaf-list ll {\n"
616 " type string;\n"
617 " }\n"
618 "}\n";
619
620 /* from pyang */
621 expect =
622 "module: a11\n"
623 " +--rw l1* [a]\n"
624 " | +--rw a string\n"
625 " +--rw l2* [a b]\n"
626 " | +--rw a string\n"
627 " | +--rw b string\n"
628 " +--rw ll* string\n";
629
aPieceke376b922021-04-19 08:08:14 +0200630 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
631 TEST_LOCAL_PRINT(mod, 72);
632 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100633 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200634
635 ly_out_reset(UTEST_OUT);
636 /* using lysc tree */
637 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
638 TEST_LOCAL_PRINT(mod, 72);
639 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
640 assert_string_equal(printed, expect);
641 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
642
aPiecek20ddf8b2021-01-08 11:50:37 +0100643 TEST_LOCAL_TEARDOWN;
644}
645
646static void
647node_type_target(void **state)
648{
649 TEST_LOCAL_SETUP;
650 orig =
651 "module a12 {\n"
652 " yang-version 1.1;\n"
653 " namespace \"x:y\";\n"
654 " prefix x;\n"
655 " leaf a {\n"
656 " type leafref {\n"
657 " path \"/x:b\";\n"
658 " }\n"
659 " }\n"
660 " leaf b {\n"
661 " type string;\n"
662 " }\n"
663 "}\n";
664
665 /* from yanglint 1 */
666 expect =
667 "module: a12\n"
668 " +--rw a? -> /x:b\n"
669 " +--rw b? string\n";
670
aPieceke376b922021-04-19 08:08:14 +0200671 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
672 TEST_LOCAL_PRINT(mod, 72);
673 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100674 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200675
676 ly_out_reset(UTEST_OUT);
677 /* using lysc tree */
678 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
679 TEST_LOCAL_PRINT(mod, 72);
680 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
681 assert_string_equal(printed, expect);
682 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
683
aPiecek20ddf8b2021-01-08 11:50:37 +0100684 TEST_LOCAL_TEARDOWN;
685}
686
687static void
688node_type_leafref(void **state)
689{
690 TEST_LOCAL_SETUP;
691 orig =
692 "module a13 {\n"
693 " yang-version 1.1;\n"
694 " namespace \"x:y\";\n"
695 " prefix x;\n"
696 " leaf pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters {\n"
697 " type string;\n"
698 " }\n"
699 " leaf a {\n"
700 " type leafref {\n"
701 " path \"/x:pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters\";\n"
702 " }\n"
703 " }\n"
704 "}\n";
705
706 /* yanglint --tree-no-leafref-target --tree-line-length=72 */
707 expect =
708 "module: a13\n"
709 " +--rw pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters?\n"
710 " | string\n"
711 " +--rw a?\n"
712 " leafref\n";
713
aPieceke376b922021-04-19 08:08:14 +0200714 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
715 TEST_LOCAL_PRINT(mod, 72);
716 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100717 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200718
719 ly_out_reset(UTEST_OUT);
720 /* using lysc tree */
721 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
722 TEST_LOCAL_PRINT(mod, 72);
723 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
724 assert_string_equal(printed, expect);
725 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
726
aPiecek20ddf8b2021-01-08 11:50:37 +0100727 TEST_LOCAL_TEARDOWN;
728}
729
730static void
731node_iffeatures(void **state)
732{
733 TEST_LOCAL_SETUP;
734 orig =
735 "module a14 {\n"
736 " yang-version 1.1;\n"
737 " namespace \"x:y\";\n"
738 " prefix x;\n"
739 "\n"
740 " feature foo;\n"
741 "\n"
742 " feature bar;\n"
743 " container c {\n"
744 " if-feature \"foo or bar\";\n"
745 " }\n"
746 "}\n";
747
748 /* from pyang */
749 expect =
750 "module: a14\n"
751 " +--rw c {foo or bar}?\n";
752
aPieceke376b922021-04-19 08:08:14 +0200753 const char *feats[] = {"foo", NULL};
754
755 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
756 TEST_LOCAL_PRINT(mod, 72);
757 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100758 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200759
760 ly_out_reset(UTEST_OUT);
761 /* using lysc tree */
762 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
763 TEST_LOCAL_PRINT(mod, 72);
764 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
765 assert_string_equal(printed, expect);
766 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
767
aPiecek20ddf8b2021-01-08 11:50:37 +0100768 TEST_LOCAL_TEARDOWN;
769}
770
771static void
772indent_wrapper(void **state)
773{
774 TEST_LOCAL_SETUP;
775 orig =
776 "module a15 {\n"
777 " yang-version 1.1;\n"
778 " namespace \"x:y\";\n"
779 " prefix x;\n"
780 " container a {\n"
781 " container b;\n"
782 " }\n"
783 " container c {\n"
784 " container d {\n"
785 " container e;\n"
786 " }\n"
787 " container f {\n"
788 " container g;\n"
789 " }\n"
790 " }\n"
791 " container h;\n"
792 " container i {\n"
793 " container j;\n"
794 " container k;\n"
795 " }\n"
796 "}\n";
797
798 /* from pyang */
799 expect =
800 "module: a15\n"
801 " +--rw a\n"
802 " | +--rw b\n"
803 " +--rw c\n"
804 " | +--rw d\n"
805 " | | +--rw e\n"
806 " | +--rw f\n"
807 " | +--rw g\n"
808 " +--rw h\n"
809 " +--rw i\n"
810 " +--rw j\n"
811 " +--rw k\n";
812
aPieceke376b922021-04-19 08:08:14 +0200813 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
814 TEST_LOCAL_PRINT(mod, 72);
815 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100816 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200817
818 ly_out_reset(UTEST_OUT);
819 /* using lysc tree */
820 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
821 TEST_LOCAL_PRINT(mod, 72);
822 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
823 assert_string_equal(printed, expect);
824 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
825
aPiecek20ddf8b2021-01-08 11:50:37 +0100826 TEST_LOCAL_TEARDOWN;
827}
828
829static void
830line_length_twiddling(void **state)
831{
832 TEST_LOCAL_SETUP;
833 /* node_fits_tight */
834
835 orig =
836 "module a16 {\n"
837 " yang-version 1.1;\n"
838 " namespace \"x:y\";\n"
839 " prefix x;\n"
840 "\n"
841 " feature f;\n"
842 "\n"
843 " typedef some-long-type {\n"
844 " type string;\n"
845 " }\n"
846 " list my-list-name {\n"
847 " key \"key\";\n"
848 " leaf key {\n"
849 " type string;\n"
850 " }\n"
851 " leaf nod-leaf {\n"
852 " if-feature \"f\";\n"
853 " type some-long-type;\n"
854 " }\n"
855 " leaf nos-leaf {\n"
856 " if-feature \"f\";\n"
857 " type int32;\n"
858 " }\n"
859 " }\n"
860 "}\n";
861
862 /* pyang --tree-line-length 42 */
863 expect =
864 "module: a16\n"
865 " +--rw my-list-name* [key]\n"
866 " +--rw key string\n"
867 " +--rw nod-leaf? some-long-type {f}?\n"
868 " +--rw nos-leaf? int32 {f}?\n";
869
aPieceke376b922021-04-19 08:08:14 +0200870 const char *feats[] = {"f", NULL};
871
872 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
873 TEST_LOCAL_PRINT(mod, 42);
874 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100875 assert_string_equal(printed, expect);
876
aPieceke376b922021-04-19 08:08:14 +0200877 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200878 /* using lysc tree */
879 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
880 TEST_LOCAL_PRINT(mod, 42);
881 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
882 assert_string_equal(printed, expect);
883 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
884
885 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100886 /* break_before_iffeature */
887
888 /* pyang --tree-line-length 41 */
889 expect =
890 "module: a16\n"
891 " +--rw my-list-name* [key]\n"
892 " +--rw key string\n"
893 " +--rw nod-leaf? some-long-type\n"
894 " | {f}?\n"
895 " +--rw nos-leaf? int32 {f}?\n";
896
aPieceke376b922021-04-19 08:08:14 +0200897 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
898 TEST_LOCAL_PRINT(mod, 41);
899 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100900 assert_string_equal(printed, expect);
901
aPieceke376b922021-04-19 08:08:14 +0200902 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200903 /* using lysc tree */
904 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
905 TEST_LOCAL_PRINT(mod, 41);
906 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
907 assert_string_equal(printed, expect);
908 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
909
910 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100911 /* break_before_type */
912
913 /* pyang --tree-line-length 29 */
914 expect =
915 "module: a16\n"
916 " +--rw my-list-name* [key]\n"
917 " +--rw key string\n"
918 " +--rw nod-leaf?\n"
919 " | some-long-type\n"
920 " | {f}?\n"
921 " +--rw nos-leaf? int32\n"
922 " {f}?\n";
923
aPieceke376b922021-04-19 08:08:14 +0200924 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
925 TEST_LOCAL_PRINT(mod, 29);
926 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100927 assert_string_equal(printed, expect);
928
aPieceke376b922021-04-19 08:08:14 +0200929 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200930 /* using lysc tree */
931 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
932 TEST_LOCAL_PRINT(mod, 29);
933 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
934 assert_string_equal(printed, expect);
935 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
936
937 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100938 /* break_before_keys */
939
940 /* pyang --tree-line-length 23 */
941 expect =
942 "module: a16\n"
943 " +--rw my-list-name*\n"
944 " [key]\n"
945 " +--rw key\n"
946 " | string\n"
947 " +--rw nod-leaf?\n"
948 " | some-long-type\n"
949 " | {f}?\n"
950 " +--rw nos-leaf?\n"
951 " int32 {f}?\n";
952
aPieceke376b922021-04-19 08:08:14 +0200953 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
954 TEST_LOCAL_PRINT(mod, 23);
955 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100956 assert_string_equal(printed, expect);
957
aPieceke376b922021-04-19 08:08:14 +0200958 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200959 /* using lysc tree */
960 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
961 TEST_LOCAL_PRINT(mod, 23);
962 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
963 assert_string_equal(printed, expect);
964 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
965
966 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100967 /* every_node_name_is_too_long */
968
969 /* pyang --tree-line-length 14 */
970 expect =
971 "module: a16\n"
972 " +--rw my-list-name*\n"
973 " [key]\n"
974 " +--rw key\n"
975 " | string\n"
976 " +--rw nod-leaf?\n"
977 " | some-long-type\n"
978 " | {f}?\n"
979 " +--rw nos-leaf?\n"
980 " int32\n"
981 " {f}?\n";
982
aPieceke376b922021-04-19 08:08:14 +0200983 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
984 TEST_LOCAL_PRINT(mod, 14);
985 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100986 assert_string_equal(printed, expect);
987
aPiecek9e505922021-04-19 13:45:08 +0200988 ly_out_reset(UTEST_OUT);
989 /* using lysc tree */
990 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
991 TEST_LOCAL_PRINT(mod, 14);
992 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
993 assert_string_equal(printed, expect);
994 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
995
aPiecek20ddf8b2021-01-08 11:50:37 +0100996 TEST_LOCAL_TEARDOWN;
997}
998
999static void
1000break_before_leafref(void **state)
1001{
1002 TEST_LOCAL_SETUP;
1003 orig =
1004 "module a17 {\n"
1005 " yang-version 1.1;\n"
1006 " namespace \"x:y\";\n"
1007 " prefix x;\n"
1008 " leaf e {\n"
1009 " type string;\n"
1010 " }\n"
1011 " leaf abcd {\n"
1012 " type leafref {\n"
1013 " path \"/x:e\";\n"
1014 " }\n"
1015 " }\n"
1016 "}\n";
1017
1018 /* yanglint --tree-line-length 14 */
1019 expect =
1020 "module: a17\n"
1021 " +--rw e?\n"
1022 " | string\n"
1023 " +--rw abcd?\n"
1024 " -> /x:e\n";
1025
aPieceke376b922021-04-19 08:08:14 +02001026 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1027 TEST_LOCAL_PRINT(mod, 14);
1028 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001029 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001030
1031 ly_out_reset(UTEST_OUT);
1032 /* using lysc tree */
1033 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1034 TEST_LOCAL_PRINT(mod, 14);
1035 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1036 assert_string_equal(printed, expect);
1037 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1038
aPiecek20ddf8b2021-01-08 11:50:37 +01001039 TEST_LOCAL_TEARDOWN;
1040}
1041
1042static void
1043break_before_leafref_and_iffeature(void **state)
1044{
1045 TEST_LOCAL_SETUP;
1046 orig =
1047 "module a18 {\n"
1048 " yang-version 1.1;\n"
1049 " namespace \"x:y\";\n"
1050 " prefix x;\n"
1051 "\n"
1052 " feature f;\n"
1053 " leaf some-long-id {\n"
1054 " type string;\n"
1055 " }\n"
1056 " leaf a {\n"
1057 " if-feature \"f\";\n"
1058 " type leafref {\n"
1059 " path \"/x:some-long-id\";\n"
1060 " }\n"
1061 " }\n"
1062 "}\n";
1063
1064 /* yanglint --tree-no-leafref-target --tree-line-length=20 */
1065 expect =
1066 "module: a18\n"
1067 " +--rw some-long-id?\n"
1068 " | string\n"
1069 " +--rw a?\n"
1070 " leafref\n"
1071 " {f}?\n";
1072
aPieceke376b922021-04-19 08:08:14 +02001073 const char *feats[] = {"f", NULL};
1074
1075 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
1076 TEST_LOCAL_PRINT(mod, 20);
1077 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001078 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001079
1080 ly_out_reset(UTEST_OUT);
1081 /* using lysc tree */
1082 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1083 TEST_LOCAL_PRINT(mod, 20);
1084 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1085 assert_string_equal(printed, expect);
1086 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1087
aPiecek20ddf8b2021-01-08 11:50:37 +01001088 TEST_LOCAL_TEARDOWN;
1089}
1090
1091static void
1092basic_unified_indent_before_type(void **state)
1093{
1094 TEST_LOCAL_SETUP;
1095 orig =
1096 "module a19 {\n"
1097 " yang-version 1.1;\n"
1098 " namespace \"x:y\";\n"
1099 " prefix x;\n"
1100 "\n"
1101 " typedef longType {\n"
1102 " type string;\n"
1103 " }\n"
1104 " container A {\n"
1105 " leaf Bnode {\n"
1106 " type int8;\n"
1107 " }\n"
1108 " leaf Cnode {\n"
1109 " type int8;\n"
1110 " mandatory true;\n"
1111 " }\n"
1112 " leaf Dnode {\n"
1113 " type int8;\n"
1114 " mandatory true;\n"
1115 " }\n"
1116 " leaf E {\n"
1117 " type longType;\n"
1118 " mandatory true;\n"
1119 " }\n"
1120 " leaf G {\n"
1121 " type int8;\n"
1122 " }\n"
1123 " }\n"
1124 "}\n";
1125
1126 /* from pyang */
1127 expect =
1128 "module: a19\n"
1129 " +--rw A\n"
1130 " +--rw Bnode? int8\n"
1131 " +--rw Cnode int8\n"
1132 " +--rw Dnode int8\n"
1133 " +--rw E longType\n"
1134 " +--rw G? int8\n";
1135
aPieceke376b922021-04-19 08:08:14 +02001136 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1137 TEST_LOCAL_PRINT(mod, 72);
1138 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001139 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001140
1141 ly_out_reset(UTEST_OUT);
1142 /* using lysc tree */
1143 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1144 TEST_LOCAL_PRINT(mod, 72);
1145 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1146 assert_string_equal(printed, expect);
1147 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1148
aPiecek20ddf8b2021-01-08 11:50:37 +01001149 TEST_LOCAL_TEARDOWN;
1150}
1151
1152static void
1153twiddling_unified_indent_before_type(void **state)
1154{
1155 TEST_LOCAL_SETUP;
1156 /* basic_functionality */
1157
1158 orig =
1159 "module a20 {\n"
1160 " yang-version 1.1;\n"
1161 " namespace \"x:y\";\n"
1162 " prefix x;\n"
1163 "\n"
1164 " typedef longType {\n"
1165 " type string;\n"
1166 " }\n"
1167 " container A {\n"
1168 " leaf Bnode {\n"
1169 " type int8;\n"
1170 " }\n"
1171 " leaf CnodeIsBigger {\n"
1172 " type int8;\n"
1173 " mandatory true;\n"
1174 " }\n"
1175 " leaf Dnode {\n"
1176 " type int8;\n"
1177 " mandatory true;\n"
1178 " }\n"
1179 " leaf E {\n"
1180 " type longType;\n"
1181 " mandatory true;\n"
1182 " }\n"
1183 " leaf G {\n"
1184 " type int8;\n"
1185 " }\n"
1186 " }\n"
1187 "}\n";
1188
1189 /* pyang --tree-line-length 36 */
1190 expect =
1191 "module: a20\n"
1192 " +--rw A\n"
1193 " +--rw Bnode? int8\n"
1194 " +--rw CnodeIsBigger int8\n"
1195 " +--rw Dnode int8\n"
1196 " +--rw E longType\n"
1197 " +--rw G? int8\n";
1198
aPieceke376b922021-04-19 08:08:14 +02001199 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1200 TEST_LOCAL_PRINT(mod, 36);
1201 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001202 assert_string_equal(printed, expect);
1203
aPieceke376b922021-04-19 08:08:14 +02001204 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +02001205 /* using lysc tree */
1206 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1207 TEST_LOCAL_PRINT(mod, 36);
1208 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1209 assert_string_equal(printed, expect);
1210 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1211
1212 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +01001213 /* unified_indent_before_type_long_node_name */
1214
1215 /* pyang --tree-line-length 32 */
1216 expect =
1217 "module: a20\n"
1218 " +--rw A\n"
1219 " +--rw Bnode? int8\n"
1220 " +--rw CnodeIsBigger int8\n"
1221 " +--rw Dnode int8\n"
1222 " +--rw E\n"
1223 " | longType\n"
1224 " +--rw G? int8\n";
1225
aPieceke376b922021-04-19 08:08:14 +02001226 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1227 TEST_LOCAL_PRINT(mod, 32);
1228 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001229 assert_string_equal(printed, expect);
1230
aPieceke376b922021-04-19 08:08:14 +02001231 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +02001232 /* using lysc tree */
1233 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1234 TEST_LOCAL_PRINT(mod, 32);
1235 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1236 assert_string_equal(printed, expect);
1237 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1238
1239 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +01001240 /* unified_indent_before_type_long_node_type */
1241
1242 /* pyang --tree-line-length 31 */
1243 expect =
1244 "module: a20\n"
1245 " +--rw A\n"
1246 " +--rw Bnode?\n"
1247 " | int8\n"
1248 " +--rw CnodeIsBigger\n"
1249 " | int8\n"
1250 " +--rw Dnode\n"
1251 " | int8\n"
1252 " +--rw E\n"
1253 " | longType\n"
1254 " +--rw G?\n"
1255 " int8\n";
1256
aPieceke376b922021-04-19 08:08:14 +02001257 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1258 TEST_LOCAL_PRINT(mod, 31);
1259 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001260 assert_string_equal(printed, expect);
1261
aPiecek9e505922021-04-19 13:45:08 +02001262 ly_out_reset(UTEST_OUT);
1263 /* using lysc tree */
1264 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1265 TEST_LOCAL_PRINT(mod, 31);
1266 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1267 assert_string_equal(printed, expect);
1268 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1269
aPiecek20ddf8b2021-01-08 11:50:37 +01001270 TEST_LOCAL_TEARDOWN;
1271}
1272
1273static void
1274inheritance_of_config_flag(void **state)
1275{
1276 TEST_LOCAL_SETUP;
1277 orig =
1278 "module a21 {\n"
1279 " yang-version 1.1;\n"
1280 " namespace \"x:y\";\n"
1281 " prefix x;\n"
1282 " container a {\n"
1283 " config false;\n"
1284 " leaf b {\n"
1285 " type string;\n"
1286 " }\n"
1287 " }\n"
1288 "}\n";
1289
1290 /* from pyang */
1291 expect =
1292 "module: a21\n"
1293 " +--ro a\n"
1294 " +--ro b? string\n";
1295
aPieceke376b922021-04-19 08:08:14 +02001296 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1297 TEST_LOCAL_PRINT(mod, 72);
1298 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001299 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001300
1301 ly_out_reset(UTEST_OUT);
1302 /* using lysc tree */
1303 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1304 TEST_LOCAL_PRINT(mod, 72);
1305 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1306 assert_string_equal(printed, expect);
1307 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1308
aPiecek20ddf8b2021-01-08 11:50:37 +01001309 TEST_LOCAL_TEARDOWN;
1310}
1311
1312static void
1313inheritance_of_status_flag(void **state)
1314{
1315 TEST_LOCAL_SETUP;
1316 /* throws libyang warn: Missing explicit "..." status that was already specified in parent, inheriting. */
1317 orig =
1318 "module a22 {\n"
1319 " yang-version 1.1;\n"
1320 " namespace \"x:y\";\n"
1321 " prefix x;\n"
1322 " container a {\n"
1323 " status current;\n"
1324 " container b {\n"
1325 " status deprecated;\n"
1326 " leaf f {\n"
1327 " type string;\n"
1328 " }\n"
1329 " }\n"
1330 " container c {\n"
1331 " status obsolete;\n"
1332 " leaf g {\n"
1333 " type string;\n"
1334 " }\n"
1335 " }\n"
1336 " }\n"
1337 " container d {\n"
1338 " status deprecated;\n"
1339 " container h {\n"
1340 " status obsolete;\n"
1341 " leaf e {\n"
1342 " type string;\n"
1343 " }\n"
1344 " }\n"
1345 " }\n"
1346 "}\n";
1347
1348 /* from yanglint 1 */
1349 expect =
1350 "module: a22\n"
1351 " +--rw a\n"
1352 " | x--rw b\n"
1353 " | | x--rw f? string\n"
1354 " | o--rw c\n"
1355 " | o--rw g? string\n"
1356 " x--rw d\n"
1357 " o--rw h\n"
1358 " o--rw e? string\n";
1359
aPieceke376b922021-04-19 08:08:14 +02001360 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1361 TEST_LOCAL_PRINT(mod, 72);
1362 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001363 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001364
1365 ly_out_reset(UTEST_OUT);
1366 /* using lysc tree */
1367 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1368 TEST_LOCAL_PRINT(mod, 72);
1369 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1370 assert_string_equal(printed, expect);
1371 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1372
aPiecek20ddf8b2021-01-08 11:50:37 +01001373 TEST_LOCAL_TEARDOWN;
1374}
1375
1376static void
1377key_leaf_is_always_mandatory_true(void **state)
1378{
1379 TEST_LOCAL_SETUP;
1380 orig =
1381 "module a23 {\n"
1382 " yang-version 1.1;\n"
1383 " namespace \"x:y\";\n"
1384 " prefix x;\n"
1385 " list a {\n"
1386 " key \"k1\";\n"
1387 " list b {\n"
1388 " key \"k2\";\n"
1389 " leaf k1 {\n"
1390 " type string;\n"
1391 " }\n"
1392 " leaf k2 {\n"
1393 " type string;\n"
1394 " }\n"
1395 " }\n"
1396 " leaf k1 {\n"
1397 " type string;\n"
1398 " }\n"
1399 " }\n"
1400 "}\n";
1401
1402 /* from pyang */
1403 expect =
1404 "module: a23\n"
1405 " +--rw a* [k1]\n"
1406 " +--rw b* [k2]\n"
1407 " | +--rw k1? string\n"
1408 " | +--rw k2 string\n"
1409 " +--rw k1 string\n";
1410
aPieceke376b922021-04-19 08:08:14 +02001411 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1412 TEST_LOCAL_PRINT(mod, 72);
1413 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001414 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001415
1416 ly_out_reset(UTEST_OUT);
1417
1418 /* from pyang but with some swapped lines */
1419 expect =
1420 "module: a23\n"
1421 " +--rw a* [k1]\n"
1422 " +--rw k1 string\n"
1423 " +--rw b* [k2]\n"
1424 " +--rw k2 string\n"
1425 " +--rw k1? string\n";
1426
1427 /* using lysc tree */
1428 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1429 TEST_LOCAL_PRINT(mod, 72);
1430 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1431 assert_string_equal(printed, expect);
1432 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1433
aPiecek20ddf8b2021-01-08 11:50:37 +01001434 TEST_LOCAL_TEARDOWN;
1435}
1436
1437static void
1438transition_between_rpc_and_notif(void **state)
1439{
1440 TEST_LOCAL_SETUP;
1441 orig =
1442 "module a24 {\n"
1443 " yang-version 1.1;\n"
1444 " namespace \"x:y\";\n"
1445 " prefix x;\n"
1446 " container top {\n"
aPiecek9e505922021-04-19 13:45:08 +02001447 " leaf g {\n"
1448 " type string;\n"
1449 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +01001450 " action rpc1 {\n"
1451 "\n"
1452 " input {\n"
1453 " leaf in {\n"
1454 " type string;\n"
1455 " }\n"
1456 " }\n"
1457 " }\n"
1458 " action rpc2 {\n"
1459 "\n"
1460 " input {\n"
1461 " leaf in {\n"
1462 " type string;\n"
1463 " }\n"
1464 " }\n"
1465 "\n"
1466 " output {\n"
1467 " leaf out {\n"
1468 " type string;\n"
1469 " }\n"
1470 " }\n"
1471 " }\n"
1472 " notification n1;\n"
1473 " notification n2;\n"
1474 " }\n"
1475 "}\n";
1476
1477 /* from pyang but edited -> n1 node is moved to n2 */
1478 expect =
1479 "module: a24\n"
1480 " +--rw top\n"
aPiecek9e505922021-04-19 13:45:08 +02001481 " +--rw g? string\n"
aPiecek20ddf8b2021-01-08 11:50:37 +01001482 " +---x rpc1\n"
1483 " | +---w input\n"
1484 " | +---w in? string\n"
1485 " +---x rpc2\n"
1486 " | +---w input\n"
1487 " | | +---w in? string\n"
1488 " | +--ro output\n"
1489 " | +--ro out? string\n"
1490 " +---n n1\n"
1491 " +---n n2\n";
1492
aPieceke376b922021-04-19 08:08:14 +02001493 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1494 TEST_LOCAL_PRINT(mod, 72);
1495 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001496 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001497
1498 ly_out_reset(UTEST_OUT);
1499 /* using lysc tree */
1500 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1501 TEST_LOCAL_PRINT(mod, 72);
1502 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1503 assert_string_equal(printed, expect);
1504 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1505
1506 TEST_LOCAL_TEARDOWN;
1507}
1508
1509static void
1510local_augment(void **state)
1511{
1512 TEST_LOCAL_SETUP;
1513
1514 orig =
1515 "module a25 {\n"
1516 " yang-version 1.1;\n"
1517 " namespace \"x:y\";\n"
1518 " prefix x;\n"
1519 " container g;\n"
1520 " augment \"/x:g\" {\n"
1521 " container e;\n"
1522 " }\n"
1523 "}\n";
1524
1525 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1526
1527 /* from pyang */
1528 expect =
1529 "module: a25\n"
1530 " +--rw g\n"
1531 " +--rw e\n";
1532
1533 /* using lysc tree */
1534 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1535 TEST_LOCAL_PRINT(mod, 72);
1536 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1537 assert_string_equal(printed, expect);
1538 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1539
aPiecek20ddf8b2021-01-08 11:50:37 +01001540 TEST_LOCAL_TEARDOWN;
1541}
1542
aPiecek7745b282021-04-20 13:54:52 +02001543static void
1544print_compiled_node(void **state)
1545{
1546 TEST_LOCAL_SETUP;
1547 const struct lysc_node *node;
1548
1549 orig =
1550 "module a26 {\n"
1551 " yang-version 1.1;\n"
1552 " namespace \"x:y\";\n"
1553 " prefix x;\n"
1554 " container g {\n"
1555 " leaf a {\n"
1556 " type string;\n"
1557 " }\n"
1558 " container h {\n"
1559 " leaf b {\n"
1560 " type string;\n"
1561 " mandatory true;\n"
1562 " }\n"
1563 " leaf c {\n"
1564 " type string;\n"
1565 " }\n"
1566 " }\n"
1567 " }\n"
1568 "}\n";
1569
1570 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1571
1572 /* pyang -f tree --tree-path /g/h/c */
1573 expect =
1574 "module: a26\n"
1575 " +--rw g\n"
1576 " +--rw h\n"
1577 " +--rw c? string\n";
1578
1579 /* using lysc tree */
1580 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1581
1582 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h/c", 0);
1583 CHECK_POINTER(node, 1);
1584 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
1585 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1586 assert_string_equal(printed, expect);
1587
1588 ly_out_reset(UTEST_OUT);
1589
1590 /* pyang -f tree --tree-path /g/h */
1591 expect =
1592 "module: a26\n"
1593 " +--rw g\n"
1594 " +--rw h\n"
1595 " +--rw b string\n"
1596 " +--rw c? string\n";
1597
1598 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
1599 CHECK_POINTER(node, 1);
1600 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
1601 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1602 assert_string_equal(printed, expect);
1603
1604 ly_out_reset(UTEST_OUT);
1605
1606 /* pyang whose output is adjusted manually */
1607 expect =
1608 "module: a26\n"
1609 " +--rw g\n"
1610 " +--rw h\n";
1611
1612 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
1613 CHECK_POINTER(node, 1);
1614 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, LYS_PRINT_NO_SUBSTMT));
1615 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1616 assert_string_equal(printed, expect);
1617
1618 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1619
1620 TEST_LOCAL_TEARDOWN;
1621}
1622
aPiecekaecf7512021-04-21 08:34:35 +02001623static LY_ERR
1624local_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
1625 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
1626 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
1627{
1628 *module_data = user_data;
1629 *format = LYS_IN_YANG;
1630 *free_module_data = NULL;
1631 return LY_SUCCESS;
1632}
1633
1634static void
1635print_parsed_submodule(void **state)
1636{
1637 TEST_LOCAL_SETUP;
1638
1639 orig = "module a27 {\n"
1640 " yang-version 1.1;\n"
1641 " namespace \"x:y\";\n"
1642 " prefix x;\n"
1643 "\n"
1644 " include \"a27-sub\";\n"
1645 "}\n";
1646
1647 char *submodule =
1648 "submodule a27-sub {\n"
1649 " yang-version 1.1;\n"
1650 " belongs-to a27 {\n"
1651 " prefix x;\n"
1652 " }\n"
1653 "\n"
1654 " container h {\n"
1655 " leaf b {\n"
1656 " type string;\n"
1657 " }\n"
1658 " }\n"
1659 "}\n";
1660
1661 /* edited pyang output */
1662 expect =
1663 "submodule: a27-sub\n"
1664 " +--rw h\n"
1665 " +--rw b? string\n";
1666
1667 ly_ctx_set_module_imp_clb(UTEST_LYCTX, local_imp_clb, submodule);
1668 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1669 assert_int_equal(LY_SUCCESS, lys_print_submodule(UTEST_OUT, mod->parsed->includes[0].submodule, LYS_OUT_TREE, 72, 0));
1670 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1671 assert_string_equal(printed, expect);
1672
1673 TEST_LOCAL_TEARDOWN;
1674}
1675
aPiecekb8e43f12021-04-23 12:52:22 +02001676static void
1677yang_data(void **state)
1678{
1679 TEST_LOCAL_SETUP;
1680
1681 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
1682 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-restconf", "2017-01-26", NULL));
1683
1684 orig =
1685 "module a28 {\n"
1686 " yang-version 1.1;\n"
1687 " namespace \"x:y\";\n"
1688 " prefix x;\n"
1689 "\n"
1690 " import ietf-restconf {\n"
1691 " prefix rc;\n"
1692 " revision-date 2017-01-26;\n"
1693 " }\n"
1694 "\n"
1695 " rc:yang-data \"tmp1\" {\n"
1696 " container cont1 {\n"
1697 " leaf lf {\n"
1698 " type string;\n"
1699 " }\n"
1700 " list l2 {\n"
1701 " key\n"
1702 " \"a b\";\n"
1703 " leaf a {\n"
1704 " type string;\n"
1705 " }\n"
1706 " leaf b {\n"
1707 " type string;\n"
1708 " }\n"
1709 " }\n"
1710 " }\n"
1711 " }\n"
1712 " rc:yang-data \"tmp2\" {\n"
1713 " container con2 {\n"
1714 " leaf lf {\n"
1715 " type string;\n"
1716 " }\n"
1717 " }\n"
1718 " }\n"
1719 " rc:yang-data \"tmp3\" {\n"
1720 " uses g1;\n"
1721 " uses g2;\n"
1722 " }\n"
1723 " rc:yang-data \"tmp4\" {\n"
1724 " choice x {\n"
1725 " case a {\n"
1726 " container z;\n"
1727 " }\n"
1728 " case b {\n"
1729 " container y;\n"
1730 " }\n"
1731 " }\n"
1732 " }\n"
1733 "\n"
1734 " grouping g1 {\n"
1735 " description\n"
1736 " \"Some Text\";\n"
1737 " }\n"
1738 "\n"
1739 " grouping g2 {\n"
1740 " container cont3;\n"
1741 " }\n"
1742 " container mont;\n"
1743 "}\n";
1744
1745 /* from pyang but with these adjustments:
1746 * - <flags> is always '--' for yang-data nodes
1747 * - yang-data tmp3 has two 'uses' nodes
1748 * - grouping g2 has ':' character at the end
1749 */
1750 expect =
1751 "module: a28\n"
1752 " +--rw mont\n"
1753 "\n"
1754 " grouping g1\n"
1755 " grouping g2:\n"
1756 " +---- cont3\n"
1757 "\n"
1758 " yang-data tmp1:\n"
1759 " +---- cont1\n"
1760 " +---- lf? string\n"
1761 " +---- l2* [a b]\n"
1762 " +---- a string\n"
1763 " +---- b string\n"
1764 " yang-data tmp2:\n"
1765 " +---- con2\n"
1766 " +---- lf? string\n"
1767 " yang-data tmp3:\n"
1768 " +---u g1\n"
1769 " +---u g2\n"
1770 " yang-data tmp4:\n"
1771 " +---- (x)?\n"
1772 " +--:(a)\n"
1773 " | +---- z\n"
1774 " +--:(b)\n"
1775 " +---- y\n";
1776
1777 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1778 TEST_LOCAL_PRINT(mod, 72);
1779 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1780 assert_string_equal(printed, expect);
1781
1782 ly_out_reset(UTEST_OUT);
1783
1784 /* from pyang but with these adjustments:
1785 * <flags> is always '--' for yang-data nodes
1786 */
1787 expect =
1788 "module: a28\n"
1789 " +--rw mont\n"
1790 "\n"
1791 " yang-data tmp1:\n"
1792 " +---- cont1\n"
1793 " +---- lf? string\n"
1794 " +---- l2* [a b]\n"
1795 " +---- a string\n"
1796 " +---- b string\n"
1797 " yang-data tmp2:\n"
1798 " +---- con2\n"
1799 " +---- lf? string\n"
1800 " yang-data tmp3:\n"
1801 " +---- cont3\n"
1802 " yang-data tmp4:\n"
1803 " +---- (x)?\n"
1804 " +--:(a)\n"
1805 " | +---- z\n"
1806 " +--:(b)\n"
1807 " +---- y\n";
1808
1809 /* using lysc tree */
1810 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1811 TEST_LOCAL_PRINT(mod, 72);
1812 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1813 assert_string_equal(printed, expect);
1814 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1815
1816 TEST_LOCAL_TEARDOWN;
1817}
1818
aPiecek20ddf8b2021-01-08 11:50:37 +01001819int
1820main(void)
1821{
1822 const struct CMUnitTest tests[] = {
1823 UTEST(base_sections),
1824 UTEST(node_status),
1825 UTEST(node_config_flags),
1826 UTEST(node_rpcs_flags),
1827 UTEST(node_grouping_flags),
1828 UTEST(notif_inside_container),
1829 UTEST(node_choice),
1830 UTEST(node_case),
1831 UTEST(optional_opts),
1832 UTEST(presence_container),
1833 UTEST(node_keys),
1834 UTEST(node_type_target),
1835 UTEST(node_type_leafref),
1836 UTEST(node_iffeatures),
1837 UTEST(indent_wrapper),
1838 UTEST(line_length_twiddling),
1839 UTEST(break_before_leafref),
1840 UTEST(break_before_leafref_and_iffeature),
1841 UTEST(basic_unified_indent_before_type),
1842 UTEST(twiddling_unified_indent_before_type),
1843 UTEST(inheritance_of_config_flag),
1844 UTEST(inheritance_of_status_flag),
1845 UTEST(key_leaf_is_always_mandatory_true),
1846 UTEST(transition_between_rpc_and_notif),
aPiecek9e505922021-04-19 13:45:08 +02001847 UTEST(local_augment),
aPiecek7745b282021-04-20 13:54:52 +02001848 UTEST(print_compiled_node),
aPiecekaecf7512021-04-21 08:34:35 +02001849 UTEST(print_parsed_submodule),
aPiecekb8e43f12021-04-23 12:52:22 +02001850 UTEST(yang_data),
aPiecek20ddf8b2021-01-08 11:50:37 +01001851 };
1852
1853 return cmocka_run_group_tests(tests, NULL, NULL);
1854}