blob: bf141fe0b38c08a29ae6ec7e4ccdb623b92c3b5f [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;
aPiecek34fa3772021-05-21 12:35:46 +020040 const struct lys_module *modxx;
aPiecekdc8fd572021-04-19 10:47:23 +020041
42 orig =
43 "module a01xx {\n"
44 " yang-version 1.1;\n"
45 " namespace \"xx:y\";\n"
46 " prefix xx;\n"
47 " container c;\n"
48 " container d;\n"
49 "}\n";
50
aPiecek34fa3772021-05-21 12:35:46 +020051 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &modxx);
aPiecekdc8fd572021-04-19 10:47:23 +020052
53 /* module with import statement */
aPiecek20ddf8b2021-01-08 11:50:37 +010054 orig =
55 "module a01 {\n"
56 " yang-version 1.1;\n"
57 " namespace \"x:y\";\n"
58 " prefix x;\n"
59 "\n"
aPiecekdc8fd572021-04-19 10:47:23 +020060 " import a01xx {\n"
61 " prefix xx;\n"
62 " }\n"
63 "\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010064 " grouping g1;\n"
65 "\n"
66 " grouping g2;\n"
aPiecekdc8fd572021-04-19 10:47:23 +020067 " container g;\n"
68 " augment \"/xx:c\" {\n"
69 " container e;\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010070 " }\n"
aPiecekdc8fd572021-04-19 10:47:23 +020071 " augment \"/xx:d\" {\n"
72 " container f;\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010073 " }\n"
74 " rpc rpc1;\n"
75 " rpc rpc2;\n"
76 " notification n1;\n"
77 " notification n2;\n"
78 "}\n";
79
aPiecekdc8fd572021-04-19 10:47:23 +020080 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
81
82 /* from pyang */
aPiecek20ddf8b2021-01-08 11:50:37 +010083 expect =
84 "module: a01\n"
aPiecekdc8fd572021-04-19 10:47:23 +020085 " +--rw g\n"
86 "\n"
87 " augment /xx:c:\n"
88 " +--rw e\n"
89 " augment /xx:d:\n"
90 " +--rw f\n"
aPiecek20ddf8b2021-01-08 11:50:37 +010091 "\n"
92 " rpcs:\n"
93 " +---x rpc1\n"
94 " +---x rpc2\n"
95 "\n"
96 " notifications:\n"
97 " +---n n1\n"
aPiecekdc8fd572021-04-19 10:47:23 +020098 " +---n n2\n"
99 "\n"
100 " grouping g1\n"
101 " grouping g2\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100102
aPieceke376b922021-04-19 08:08:14 +0200103 TEST_LOCAL_PRINT(mod, 72);
104 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100105 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200106
107 ly_out_reset(UTEST_OUT);
108
109 /* from pyang */
110 expect =
111 "module: a01\n"
112 " +--rw g\n"
113 "\n"
114 " augment /xx:c:\n"
115 " +--rw e\n"
116 " augment /xx:d:\n"
117 " +--rw f\n"
118 "\n"
119 " rpcs:\n"
120 " +---x rpc1\n"
121 " +---x rpc2\n"
122 "\n"
123 " notifications:\n"
124 " +---n n1\n"
125 " +---n n2\n";
126
127 /* using lysc tree */
128 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
129 TEST_LOCAL_PRINT(mod, 72);
130 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
131 assert_string_equal(printed, expect);
aPiecek34fa3772021-05-21 12:35:46 +0200132
133 ly_out_reset(UTEST_OUT);
134
135 /* from pyang */
136 expect =
137 "module: a01xx\n"
138 " +--rw c\n"
139 " | +--rw x:e\n"
140 " +--rw d\n"
141 " +--rw x:f\n";
142
143 TEST_LOCAL_PRINT(modxx, 72);
144 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
145 assert_string_equal(printed, expect);
146
aPiecek9e505922021-04-19 13:45:08 +0200147 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
148
aPiecek20ddf8b2021-01-08 11:50:37 +0100149 TEST_LOCAL_TEARDOWN;
150}
151
152static void
153node_status(void **state)
154{
155 TEST_LOCAL_SETUP;
156 orig =
157 "module a02 {\n"
158 " yang-version 1.1;\n"
159 " namespace \"x:y\";\n"
160 " prefix x;\n"
161 " container l {\n"
162 " status current;\n"
163 " }\n"
164 " container m {\n"
165 " status deprecated;\n"
166 " }\n"
167 " container n {\n"
168 " status obsolete;\n"
169 " }\n"
170 "}\n";
171
172 /* from pyang */
173 expect =
174 "module: a02\n"
175 " +--rw l\n"
176 " x--rw m\n"
177 " o--rw n\n";
178
aPieceke376b922021-04-19 08:08:14 +0200179 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
180 TEST_LOCAL_PRINT(mod, 72);
181 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100182 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200183
184 ly_out_reset(UTEST_OUT);
185 /* using lysc tree */
186 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
187 TEST_LOCAL_PRINT(mod, 72);
188 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
189 assert_string_equal(printed, expect);
190 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
191
aPiecek20ddf8b2021-01-08 11:50:37 +0100192 TEST_LOCAL_TEARDOWN;
193}
194
195static void
196node_config_flags(void **state)
197{
198 TEST_LOCAL_SETUP;
199 orig =
200 "module a03 {\n"
201 " yang-version 1.1;\n"
202 " namespace \"x:y\";\n"
203 " prefix x;\n"
204 " container l {\n"
205 " config true;\n"
206 " }\n"
207 " container m {\n"
208 " config false;\n"
209 " }\n"
210 "}\n";
211
212 /* from pyang */
213 expect =
214 "module: a03\n"
215 " +--rw l\n"
216 " +--ro m\n";
217
aPieceke376b922021-04-19 08:08:14 +0200218 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
219 TEST_LOCAL_PRINT(mod, 72);
220 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100221 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200222
223 ly_out_reset(UTEST_OUT);
224 /* using lysc tree */
225 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
226 TEST_LOCAL_PRINT(mod, 72);
227 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
228 assert_string_equal(printed, expect);
229 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
230
aPiecek20ddf8b2021-01-08 11:50:37 +0100231 TEST_LOCAL_TEARDOWN;
232}
233
234static void
235node_rpcs_flags(void **state)
236{
237 TEST_LOCAL_SETUP;
238 orig =
239 "module a04 {\n"
240 " yang-version 1.1;\n"
241 " namespace \"x:y\";\n"
242 " prefix x;\n"
243 " container cont {\n"
244 " action rpc1 {\n"
245 "\n"
246 " input {\n"
247 " leaf in {\n"
248 " type string;\n"
249 " }\n"
250 " }\n"
aPiecek9e505922021-04-19 13:45:08 +0200251 "\n"
252 " output {\n"
253 " leaf out {\n"
254 " type string;\n"
255 " }\n"
256 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100257 " }\n"
258 " }\n"
259 "}\n";
260
261 /* from pyang */
262 expect =
263 "module: a04\n"
264 " +--rw cont\n"
265 " +---x rpc1\n"
266 " +---w input\n"
aPiecek9e505922021-04-19 13:45:08 +0200267 " | +---w in? string\n"
268 " +--ro output\n"
269 " +--ro out? string\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100270
aPieceke376b922021-04-19 08:08:14 +0200271 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
272 TEST_LOCAL_PRINT(mod, 72);
273 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100274 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200275
276 ly_out_reset(UTEST_OUT);
277 /* using lysc tree */
278 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
279 TEST_LOCAL_PRINT(mod, 72);
280 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
281 assert_string_equal(printed, expect);
282 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
283
aPiecek20ddf8b2021-01-08 11:50:37 +0100284 TEST_LOCAL_TEARDOWN;
285}
286
287static void
288node_grouping_flags(void **state)
289{
290 TEST_LOCAL_SETUP;
291 orig =
292 "module a05 {\n"
293 " yang-version 1.1;\n"
294 " namespace \"x:y\";\n"
295 " prefix x;\n"
296 "\n"
297 " grouping g {\n"
aPiecekdc8fd572021-04-19 10:47:23 +0200298 " leaf a {\n"
299 " type string;\n"
300 " config true;\n"
301 " }\n"
302 " leaf b {\n"
303 " type string;\n"
304 " config false;\n"
305 " }\n"
306 " leaf c {\n"
307 " type string;\n"
308 " }\n"
309 " container d {\n"
310 " config false;\n"
311 " leaf e {\n"
312 " type string;\n"
313 " }\n"
314 " }\n"
315 " container f {\n"
316 " leaf g {\n"
317 " type string;\n"
318 " }\n"
319 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100320 " }\n"
321 " container d {\n"
322 " uses g;\n"
323 " }\n"
324 "}\n";
325
aPiecekdc8fd572021-04-19 10:47:23 +0200326 /* from yanglint1 */
aPiecek20ddf8b2021-01-08 11:50:37 +0100327 expect =
328 "module: a05\n"
329 " +--rw d\n"
330 " +---u g\n"
331 "\n"
332 " grouping g:\n"
aPiecekdc8fd572021-04-19 10:47:23 +0200333 " +--rw a? string\n"
334 " +--ro b? string\n"
335 " +---- c? string\n"
336 " +--ro d\n"
337 " | +--ro e? string\n"
338 " +---- f\n"
339 " +---- g? string\n";
340
aPieceke376b922021-04-19 08:08:14 +0200341 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
342 TEST_LOCAL_PRINT(mod, 72);
343 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100344 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200345
346 /* from pyang */
347 expect =
348 "module: a05\n"
349 " +--rw d\n"
350 " +--rw a? string\n"
351 " +--ro b? string\n"
352 " +--rw c? string\n"
353 " +--ro d\n"
354 " | +--ro e? string\n"
355 " +--rw f\n"
356 " +--rw g? string\n";
357
358 ly_out_reset(UTEST_OUT);
359 /* using lysc tree */
360 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
361 TEST_LOCAL_PRINT(mod, 72);
362 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
363 assert_string_equal(printed, expect);
364 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
365
aPiecek20ddf8b2021-01-08 11:50:37 +0100366 TEST_LOCAL_TEARDOWN;
367}
368
369static void
370notif_inside_container(void **state)
371{
372 TEST_LOCAL_SETUP;
373 orig =
374 "module a06 {\n"
375 " yang-version 1.1;\n"
376 " namespace \"x:y\";\n"
377 " prefix x;\n"
378 " container c {\n"
379 " notification notif;\n"
380 " }\n"
381 "}\n";
382
383 /* from pyang */
384 expect =
385 "module: a06\n"
386 " +--rw c\n"
387 " +---n notif\n";
388
aPieceke376b922021-04-19 08:08:14 +0200389 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
390 TEST_LOCAL_PRINT(mod, 72);
391 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100392 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200393
394 ly_out_reset(UTEST_OUT);
395 /* using lysc tree */
396 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
397 TEST_LOCAL_PRINT(mod, 72);
398 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
399 assert_string_equal(printed, expect);
400 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
401
aPiecek20ddf8b2021-01-08 11:50:37 +0100402 TEST_LOCAL_TEARDOWN;
403}
404
405static void
406node_choice(void **state)
407{
408 TEST_LOCAL_SETUP;
409 orig =
410 "module a07 {\n"
411 " yang-version 1.1;\n"
412 " namespace \"x:y\";\n"
413 " prefix x;\n"
414 " choice my_choice;\n"
415 "}\n";
416
417 /* from pyang */
418 expect =
419 "module: a07\n"
420 " +--rw (my_choice)?\n";
421
aPieceke376b922021-04-19 08:08:14 +0200422 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
423 TEST_LOCAL_PRINT(mod, 72);
424 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100425 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200426
427 ly_out_reset(UTEST_OUT);
428 /* using lysc tree */
429 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
430 TEST_LOCAL_PRINT(mod, 72);
431 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
432 assert_string_equal(printed, expect);
433 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
434
aPiecek20ddf8b2021-01-08 11:50:37 +0100435 TEST_LOCAL_TEARDOWN;
436}
437
438static void
439node_case(void **state)
440{
441 TEST_LOCAL_SETUP;
442 orig =
443 "module a08 {\n"
444 " yang-version 1.1;\n"
445 " namespace \"x:y\";\n"
446 " prefix x;\n"
aPiecek7a28e2f2021-05-21 07:27:03 +0200447 "\n"
448 " feature foo;\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100449 " choice my_choice {\n"
450 " case my_case;\n"
451 " }\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200452 " choice shorthand {\n"
aPiecek7a28e2f2021-05-21 07:27:03 +0200453 " container cont1 {\n"
454 " if-feature \"foo\";\n"
aPiecekaa320c92021-05-21 07:34:24 +0200455 " status obsolete;\n"
aPiecek7a28e2f2021-05-21 07:27:03 +0200456 " }\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200457 " container cont2 {\n"
458 " container cont3;\n"
459 " }\n"
460 " }\n"
461 " container top {\n"
462 " choice shorthand1 {\n"
463 " container cont1;\n"
464 " }\n"
465 " choice shorthand2 {\n"
466 " container cont2 {\n"
467 " container cont3;\n"
468 " }\n"
469 " }\n"
470 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +0100471 "}\n";
472
473 /* from pyang */
474 expect =
475 "module: a08\n"
476 " +--rw (my_choice)?\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200477 " | +--:(my_case)\n"
478 " +--rw (shorthand)?\n"
aPiecekaa320c92021-05-21 07:34:24 +0200479 " | o--:(cont1)\n"
480 " | | o--rw cont1 {foo}?\n"
aPiecek082c7dc2021-05-20 08:55:07 +0200481 " | +--:(cont2)\n"
482 " | +--rw cont2\n"
483 " | +--rw cont3\n"
484 " +--rw top\n"
485 " +--rw (shorthand1)?\n"
486 " | +--:(cont1)\n"
487 " | +--rw cont1\n"
488 " +--rw (shorthand2)?\n"
489 " +--:(cont2)\n"
490 " +--rw cont2\n"
491 " +--rw cont3\n";
aPiecek20ddf8b2021-01-08 11:50:37 +0100492
aPiecek7a28e2f2021-05-21 07:27:03 +0200493 const char *feats[] = {"foo", NULL};
494
495 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
aPieceke376b922021-04-19 08:08:14 +0200496 TEST_LOCAL_PRINT(mod, 72);
497 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100498 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200499
500 ly_out_reset(UTEST_OUT);
501 /* using lysc tree */
502 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
503 TEST_LOCAL_PRINT(mod, 72);
504 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
505 assert_string_equal(printed, expect);
506 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
507
aPiecek20ddf8b2021-01-08 11:50:37 +0100508 TEST_LOCAL_TEARDOWN;
509}
510
511static void
512optional_opts(void **state)
513{
514 TEST_LOCAL_SETUP;
515 /* throws libyang warn: Use of anydata to define configuration data is not recommended... */
516 orig =
517 "module a09 {\n"
518 " yang-version 1.1;\n"
519 " namespace \"x:y\";\n"
520 " prefix x;\n"
521 " leaf l1 {\n"
522 " type string;\n"
523 " mandatory true;\n"
524 " }\n"
525 " leaf l2 {\n"
526 " type string;\n"
527 " mandatory false;\n"
528 " }\n"
529 " choice c1 {\n"
530 " mandatory true;\n"
531 " }\n"
532 " choice c2 {\n"
533 " mandatory false;\n"
534 " }\n"
535 " anydata a1 {\n"
536 " mandatory true;\n"
537 " }\n"
538 " anydata a2 {\n"
539 " mandatory false;\n"
540 " }\n"
541 " anyxml x1 {\n"
542 " mandatory true;\n"
543 " }\n"
544 " anyxml x2 {\n"
545 " mandatory false;\n"
546 " }\n"
547 "}\n";
548
549 /* from yanglint 1 */
550 expect =
551 "module: a09\n"
552 " +--rw l1 string\n"
553 " +--rw l2? string\n"
554 " +--rw (c1)\n"
555 " +--rw (c2)?\n"
556 " +--rw a1 anydata\n"
557 " +--rw a2? anydata\n"
558 " +--rw x1 anyxml\n"
559 " +--rw x2? anyxml\n";
560
aPieceke376b922021-04-19 08:08:14 +0200561 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
562 TEST_LOCAL_PRINT(mod, 72);
563 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100564 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200565
566 ly_out_reset(UTEST_OUT);
567 /* using lysc tree */
568 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
569 TEST_LOCAL_PRINT(mod, 72);
570 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
571 assert_string_equal(printed, expect);
572 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
573
aPiecek20ddf8b2021-01-08 11:50:37 +0100574 TEST_LOCAL_TEARDOWN;
575}
576
577static void
578presence_container(void **state)
579{
580 TEST_LOCAL_SETUP;
581 orig =
582 "module a10 {\n"
583 " yang-version 1.1;\n"
584 " namespace \"x:y\";\n"
585 " prefix x;\n"
586 " container c;\n"
587 " container d {\n"
588 " presence \"str1\";\n"
589 " }\n"
590 "}\n";
591
592 /* from pyang */
593 expect =
594 "module: a10\n"
595 " +--rw c\n"
596 " +--rw d!\n";
597
aPieceke376b922021-04-19 08:08:14 +0200598 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
599 TEST_LOCAL_PRINT(mod, 72);
600 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100601 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200602
603 ly_out_reset(UTEST_OUT);
604 /* using lysc tree */
605 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
606 TEST_LOCAL_PRINT(mod, 72);
607 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
608 assert_string_equal(printed, expect);
609 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
610
aPiecek20ddf8b2021-01-08 11:50:37 +0100611 TEST_LOCAL_TEARDOWN;
612}
613
614static void
615node_keys(void **state)
616{
617 TEST_LOCAL_SETUP;
618 orig =
619 "module a11 {\n"
620 " yang-version 1.1;\n"
621 " namespace \"x:y\";\n"
622 " prefix x;\n"
623 " list l1 {\n"
624 " key \"a\";\n"
625 " leaf a {\n"
626 " type string;\n"
627 " }\n"
628 " }\n"
629 " list l2 {\n"
630 " key \"a b\";\n"
631 " leaf a {\n"
632 " type string;\n"
633 " }\n"
634 " leaf b {\n"
635 " type string;\n"
636 " }\n"
637 " }\n"
638 " leaf-list ll {\n"
639 " type string;\n"
640 " }\n"
641 "}\n";
642
643 /* from pyang */
644 expect =
645 "module: a11\n"
646 " +--rw l1* [a]\n"
647 " | +--rw a string\n"
648 " +--rw l2* [a b]\n"
649 " | +--rw a string\n"
650 " | +--rw b string\n"
651 " +--rw ll* string\n";
652
aPieceke376b922021-04-19 08:08:14 +0200653 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
654 TEST_LOCAL_PRINT(mod, 72);
655 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100656 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200657
658 ly_out_reset(UTEST_OUT);
659 /* using lysc tree */
660 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
661 TEST_LOCAL_PRINT(mod, 72);
662 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
663 assert_string_equal(printed, expect);
664 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
665
aPiecek20ddf8b2021-01-08 11:50:37 +0100666 TEST_LOCAL_TEARDOWN;
667}
668
669static void
670node_type_target(void **state)
671{
672 TEST_LOCAL_SETUP;
673 orig =
674 "module a12 {\n"
675 " yang-version 1.1;\n"
676 " namespace \"x:y\";\n"
677 " prefix x;\n"
678 " leaf a {\n"
679 " type leafref {\n"
680 " path \"/x:b\";\n"
681 " }\n"
682 " }\n"
683 " leaf b {\n"
684 " type string;\n"
685 " }\n"
686 "}\n";
687
688 /* from yanglint 1 */
689 expect =
690 "module: a12\n"
691 " +--rw a? -> /x:b\n"
692 " +--rw b? string\n";
693
aPieceke376b922021-04-19 08:08:14 +0200694 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
695 TEST_LOCAL_PRINT(mod, 72);
696 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100697 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200698
699 ly_out_reset(UTEST_OUT);
700 /* using lysc tree */
701 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
702 TEST_LOCAL_PRINT(mod, 72);
703 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
704 assert_string_equal(printed, expect);
705 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
706
aPiecek20ddf8b2021-01-08 11:50:37 +0100707 TEST_LOCAL_TEARDOWN;
708}
709
710static void
711node_type_leafref(void **state)
712{
713 TEST_LOCAL_SETUP;
714 orig =
715 "module a13 {\n"
716 " yang-version 1.1;\n"
717 " namespace \"x:y\";\n"
718 " prefix x;\n"
719 " leaf pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters {\n"
720 " type string;\n"
721 " }\n"
722 " leaf a {\n"
723 " type leafref {\n"
724 " path \"/x:pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters\";\n"
725 " }\n"
726 " }\n"
727 "}\n";
728
729 /* yanglint --tree-no-leafref-target --tree-line-length=72 */
730 expect =
731 "module: a13\n"
732 " +--rw pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters?\n"
733 " | string\n"
734 " +--rw a?\n"
735 " leafref\n";
736
aPieceke376b922021-04-19 08:08:14 +0200737 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
738 TEST_LOCAL_PRINT(mod, 72);
739 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100740 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200741
742 ly_out_reset(UTEST_OUT);
743 /* using lysc tree */
744 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
745 TEST_LOCAL_PRINT(mod, 72);
746 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
747 assert_string_equal(printed, expect);
748 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
749
aPiecek20ddf8b2021-01-08 11:50:37 +0100750 TEST_LOCAL_TEARDOWN;
751}
752
753static void
754node_iffeatures(void **state)
755{
756 TEST_LOCAL_SETUP;
757 orig =
758 "module a14 {\n"
759 " yang-version 1.1;\n"
760 " namespace \"x:y\";\n"
761 " prefix x;\n"
762 "\n"
763 " feature foo;\n"
764 "\n"
765 " feature bar;\n"
766 " container c {\n"
767 " if-feature \"foo or bar\";\n"
768 " }\n"
769 "}\n";
770
771 /* from pyang */
772 expect =
773 "module: a14\n"
774 " +--rw c {foo or bar}?\n";
775
aPieceke376b922021-04-19 08:08:14 +0200776 const char *feats[] = {"foo", NULL};
777
778 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
779 TEST_LOCAL_PRINT(mod, 72);
780 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100781 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200782
783 ly_out_reset(UTEST_OUT);
784 /* using lysc tree */
785 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
786 TEST_LOCAL_PRINT(mod, 72);
787 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
788 assert_string_equal(printed, expect);
789 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
790
aPiecek20ddf8b2021-01-08 11:50:37 +0100791 TEST_LOCAL_TEARDOWN;
792}
793
794static void
795indent_wrapper(void **state)
796{
797 TEST_LOCAL_SETUP;
798 orig =
799 "module a15 {\n"
800 " yang-version 1.1;\n"
801 " namespace \"x:y\";\n"
802 " prefix x;\n"
803 " container a {\n"
804 " container b;\n"
805 " }\n"
806 " container c {\n"
807 " container d {\n"
808 " container e;\n"
809 " }\n"
810 " container f {\n"
811 " container g;\n"
812 " }\n"
813 " }\n"
814 " container h;\n"
815 " container i {\n"
816 " container j;\n"
817 " container k;\n"
818 " }\n"
819 "}\n";
820
821 /* from pyang */
822 expect =
823 "module: a15\n"
824 " +--rw a\n"
825 " | +--rw b\n"
826 " +--rw c\n"
827 " | +--rw d\n"
828 " | | +--rw e\n"
829 " | +--rw f\n"
830 " | +--rw g\n"
831 " +--rw h\n"
832 " +--rw i\n"
833 " +--rw j\n"
834 " +--rw k\n";
835
aPieceke376b922021-04-19 08:08:14 +0200836 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
837 TEST_LOCAL_PRINT(mod, 72);
838 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100839 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +0200840
841 ly_out_reset(UTEST_OUT);
842 /* using lysc tree */
843 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
844 TEST_LOCAL_PRINT(mod, 72);
845 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
846 assert_string_equal(printed, expect);
847 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
848
aPiecek20ddf8b2021-01-08 11:50:37 +0100849 TEST_LOCAL_TEARDOWN;
850}
851
852static void
853line_length_twiddling(void **state)
854{
855 TEST_LOCAL_SETUP;
856 /* node_fits_tight */
857
858 orig =
859 "module a16 {\n"
860 " yang-version 1.1;\n"
861 " namespace \"x:y\";\n"
862 " prefix x;\n"
863 "\n"
864 " feature f;\n"
865 "\n"
866 " typedef some-long-type {\n"
867 " type string;\n"
868 " }\n"
869 " list my-list-name {\n"
870 " key \"key\";\n"
871 " leaf key {\n"
872 " type string;\n"
873 " }\n"
874 " leaf nod-leaf {\n"
875 " if-feature \"f\";\n"
876 " type some-long-type;\n"
877 " }\n"
878 " leaf nos-leaf {\n"
879 " if-feature \"f\";\n"
880 " type int32;\n"
881 " }\n"
882 " }\n"
883 "}\n";
884
885 /* pyang --tree-line-length 42 */
886 expect =
887 "module: a16\n"
888 " +--rw my-list-name* [key]\n"
889 " +--rw key string\n"
890 " +--rw nod-leaf? some-long-type {f}?\n"
891 " +--rw nos-leaf? int32 {f}?\n";
892
aPieceke376b922021-04-19 08:08:14 +0200893 const char *feats[] = {"f", NULL};
894
895 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
896 TEST_LOCAL_PRINT(mod, 42);
897 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100898 assert_string_equal(printed, expect);
899
aPieceke376b922021-04-19 08:08:14 +0200900 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200901 /* using lysc tree */
902 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
903 TEST_LOCAL_PRINT(mod, 42);
904 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
905 assert_string_equal(printed, expect);
906 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
907
908 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100909 /* break_before_iffeature */
910
911 /* pyang --tree-line-length 41 */
912 expect =
913 "module: a16\n"
914 " +--rw my-list-name* [key]\n"
915 " +--rw key string\n"
916 " +--rw nod-leaf? some-long-type\n"
917 " | {f}?\n"
918 " +--rw nos-leaf? int32 {f}?\n";
919
aPieceke376b922021-04-19 08:08:14 +0200920 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
921 TEST_LOCAL_PRINT(mod, 41);
922 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100923 assert_string_equal(printed, expect);
924
aPieceke376b922021-04-19 08:08:14 +0200925 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200926 /* using lysc tree */
927 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
928 TEST_LOCAL_PRINT(mod, 41);
929 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
930 assert_string_equal(printed, expect);
931 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
932
933 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100934 /* break_before_type */
935
936 /* pyang --tree-line-length 29 */
937 expect =
938 "module: a16\n"
939 " +--rw my-list-name* [key]\n"
940 " +--rw key string\n"
941 " +--rw nod-leaf?\n"
942 " | some-long-type\n"
943 " | {f}?\n"
944 " +--rw nos-leaf? int32\n"
945 " {f}?\n";
946
aPieceke376b922021-04-19 08:08:14 +0200947 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
948 TEST_LOCAL_PRINT(mod, 29);
949 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100950 assert_string_equal(printed, expect);
951
aPieceke376b922021-04-19 08:08:14 +0200952 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200953 /* using lysc tree */
954 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
955 TEST_LOCAL_PRINT(mod, 29);
956 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
957 assert_string_equal(printed, expect);
958 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
959
960 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100961 /* break_before_keys */
962
963 /* pyang --tree-line-length 23 */
964 expect =
965 "module: a16\n"
966 " +--rw my-list-name*\n"
967 " [key]\n"
968 " +--rw key\n"
969 " | string\n"
970 " +--rw nod-leaf?\n"
971 " | some-long-type\n"
972 " | {f}?\n"
973 " +--rw nos-leaf?\n"
974 " int32 {f}?\n";
975
aPieceke376b922021-04-19 08:08:14 +0200976 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
977 TEST_LOCAL_PRINT(mod, 23);
978 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +0100979 assert_string_equal(printed, expect);
980
aPieceke376b922021-04-19 08:08:14 +0200981 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +0200982 /* using lysc tree */
983 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
984 TEST_LOCAL_PRINT(mod, 23);
985 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
986 assert_string_equal(printed, expect);
987 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
988
989 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +0100990 /* every_node_name_is_too_long */
991
992 /* pyang --tree-line-length 14 */
993 expect =
994 "module: a16\n"
995 " +--rw my-list-name*\n"
996 " [key]\n"
997 " +--rw key\n"
998 " | string\n"
999 " +--rw nod-leaf?\n"
1000 " | some-long-type\n"
1001 " | {f}?\n"
1002 " +--rw nos-leaf?\n"
1003 " int32\n"
1004 " {f}?\n";
1005
aPieceke376b922021-04-19 08:08:14 +02001006 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
1007 TEST_LOCAL_PRINT(mod, 14);
1008 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001009 assert_string_equal(printed, expect);
1010
aPiecek9e505922021-04-19 13:45:08 +02001011 ly_out_reset(UTEST_OUT);
1012 /* using lysc tree */
1013 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1014 TEST_LOCAL_PRINT(mod, 14);
1015 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1016 assert_string_equal(printed, expect);
1017 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1018
aPiecek20ddf8b2021-01-08 11:50:37 +01001019 TEST_LOCAL_TEARDOWN;
1020}
1021
1022static void
1023break_before_leafref(void **state)
1024{
1025 TEST_LOCAL_SETUP;
1026 orig =
1027 "module a17 {\n"
1028 " yang-version 1.1;\n"
1029 " namespace \"x:y\";\n"
1030 " prefix x;\n"
1031 " leaf e {\n"
1032 " type string;\n"
1033 " }\n"
1034 " leaf abcd {\n"
1035 " type leafref {\n"
1036 " path \"/x:e\";\n"
1037 " }\n"
1038 " }\n"
1039 "}\n";
1040
1041 /* yanglint --tree-line-length 14 */
1042 expect =
1043 "module: a17\n"
1044 " +--rw e?\n"
1045 " | string\n"
1046 " +--rw abcd?\n"
1047 " -> /x:e\n";
1048
aPieceke376b922021-04-19 08:08:14 +02001049 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1050 TEST_LOCAL_PRINT(mod, 14);
1051 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001052 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001053
1054 ly_out_reset(UTEST_OUT);
1055 /* using lysc tree */
1056 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1057 TEST_LOCAL_PRINT(mod, 14);
1058 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1059 assert_string_equal(printed, expect);
1060 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1061
aPiecek20ddf8b2021-01-08 11:50:37 +01001062 TEST_LOCAL_TEARDOWN;
1063}
1064
1065static void
1066break_before_leafref_and_iffeature(void **state)
1067{
1068 TEST_LOCAL_SETUP;
1069 orig =
1070 "module a18 {\n"
1071 " yang-version 1.1;\n"
1072 " namespace \"x:y\";\n"
1073 " prefix x;\n"
1074 "\n"
1075 " feature f;\n"
1076 " leaf some-long-id {\n"
1077 " type string;\n"
1078 " }\n"
1079 " leaf a {\n"
1080 " if-feature \"f\";\n"
1081 " type leafref {\n"
1082 " path \"/x:some-long-id\";\n"
1083 " }\n"
1084 " }\n"
1085 "}\n";
1086
1087 /* yanglint --tree-no-leafref-target --tree-line-length=20 */
1088 expect =
1089 "module: a18\n"
1090 " +--rw some-long-id?\n"
1091 " | string\n"
1092 " +--rw a?\n"
1093 " leafref\n"
1094 " {f}?\n";
1095
aPieceke376b922021-04-19 08:08:14 +02001096 const char *feats[] = {"f", NULL};
1097
1098 UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod);
1099 TEST_LOCAL_PRINT(mod, 20);
1100 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001101 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001102
1103 ly_out_reset(UTEST_OUT);
1104 /* using lysc tree */
1105 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1106 TEST_LOCAL_PRINT(mod, 20);
1107 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1108 assert_string_equal(printed, expect);
1109 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1110
aPiecek20ddf8b2021-01-08 11:50:37 +01001111 TEST_LOCAL_TEARDOWN;
1112}
1113
1114static void
1115basic_unified_indent_before_type(void **state)
1116{
1117 TEST_LOCAL_SETUP;
1118 orig =
1119 "module a19 {\n"
1120 " yang-version 1.1;\n"
1121 " namespace \"x:y\";\n"
1122 " prefix x;\n"
1123 "\n"
1124 " typedef longType {\n"
1125 " type string;\n"
1126 " }\n"
1127 " container A {\n"
1128 " leaf Bnode {\n"
1129 " type int8;\n"
1130 " }\n"
1131 " leaf Cnode {\n"
1132 " type int8;\n"
1133 " mandatory true;\n"
1134 " }\n"
1135 " leaf Dnode {\n"
1136 " type int8;\n"
1137 " mandatory true;\n"
1138 " }\n"
1139 " leaf E {\n"
1140 " type longType;\n"
1141 " mandatory true;\n"
1142 " }\n"
1143 " leaf G {\n"
1144 " type int8;\n"
1145 " }\n"
1146 " }\n"
1147 "}\n";
1148
1149 /* from pyang */
1150 expect =
1151 "module: a19\n"
1152 " +--rw A\n"
1153 " +--rw Bnode? int8\n"
1154 " +--rw Cnode int8\n"
1155 " +--rw Dnode int8\n"
1156 " +--rw E longType\n"
1157 " +--rw G? int8\n";
1158
aPieceke376b922021-04-19 08:08:14 +02001159 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1160 TEST_LOCAL_PRINT(mod, 72);
1161 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001162 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001163
1164 ly_out_reset(UTEST_OUT);
1165 /* using lysc tree */
1166 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1167 TEST_LOCAL_PRINT(mod, 72);
1168 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1169 assert_string_equal(printed, expect);
1170 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1171
aPiecek20ddf8b2021-01-08 11:50:37 +01001172 TEST_LOCAL_TEARDOWN;
1173}
1174
1175static void
1176twiddling_unified_indent_before_type(void **state)
1177{
1178 TEST_LOCAL_SETUP;
1179 /* basic_functionality */
1180
1181 orig =
1182 "module a20 {\n"
1183 " yang-version 1.1;\n"
1184 " namespace \"x:y\";\n"
1185 " prefix x;\n"
1186 "\n"
1187 " typedef longType {\n"
1188 " type string;\n"
1189 " }\n"
1190 " container A {\n"
1191 " leaf Bnode {\n"
1192 " type int8;\n"
1193 " }\n"
1194 " leaf CnodeIsBigger {\n"
1195 " type int8;\n"
1196 " mandatory true;\n"
1197 " }\n"
1198 " leaf Dnode {\n"
1199 " type int8;\n"
1200 " mandatory true;\n"
1201 " }\n"
1202 " leaf E {\n"
1203 " type longType;\n"
1204 " mandatory true;\n"
1205 " }\n"
1206 " leaf G {\n"
1207 " type int8;\n"
1208 " }\n"
1209 " }\n"
1210 "}\n";
1211
1212 /* pyang --tree-line-length 36 */
1213 expect =
1214 "module: a20\n"
1215 " +--rw A\n"
1216 " +--rw Bnode? int8\n"
1217 " +--rw CnodeIsBigger int8\n"
1218 " +--rw Dnode int8\n"
1219 " +--rw E longType\n"
1220 " +--rw G? int8\n";
1221
aPieceke376b922021-04-19 08:08:14 +02001222 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1223 TEST_LOCAL_PRINT(mod, 36);
1224 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001225 assert_string_equal(printed, expect);
1226
aPieceke376b922021-04-19 08:08:14 +02001227 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +02001228 /* using lysc tree */
1229 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1230 TEST_LOCAL_PRINT(mod, 36);
1231 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1232 assert_string_equal(printed, expect);
1233 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1234
1235 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +01001236 /* unified_indent_before_type_long_node_name */
1237
1238 /* pyang --tree-line-length 32 */
1239 expect =
1240 "module: a20\n"
1241 " +--rw A\n"
1242 " +--rw Bnode? int8\n"
1243 " +--rw CnodeIsBigger int8\n"
1244 " +--rw Dnode int8\n"
1245 " +--rw E\n"
1246 " | longType\n"
1247 " +--rw G? int8\n";
1248
aPieceke376b922021-04-19 08:08:14 +02001249 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1250 TEST_LOCAL_PRINT(mod, 32);
1251 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001252 assert_string_equal(printed, expect);
1253
aPieceke376b922021-04-19 08:08:14 +02001254 ly_out_reset(UTEST_OUT);
aPiecek9e505922021-04-19 13:45:08 +02001255 /* using lysc tree */
1256 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1257 TEST_LOCAL_PRINT(mod, 32);
1258 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1259 assert_string_equal(printed, expect);
1260 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1261
1262 ly_out_reset(UTEST_OUT);
aPiecek20ddf8b2021-01-08 11:50:37 +01001263 /* unified_indent_before_type_long_node_type */
1264
1265 /* pyang --tree-line-length 31 */
1266 expect =
1267 "module: a20\n"
1268 " +--rw A\n"
1269 " +--rw Bnode?\n"
1270 " | int8\n"
1271 " +--rw CnodeIsBigger\n"
1272 " | int8\n"
1273 " +--rw Dnode\n"
1274 " | int8\n"
1275 " +--rw E\n"
1276 " | longType\n"
1277 " +--rw G?\n"
1278 " int8\n";
1279
aPieceke376b922021-04-19 08:08:14 +02001280 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1281 TEST_LOCAL_PRINT(mod, 31);
1282 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001283 assert_string_equal(printed, expect);
1284
aPiecek9e505922021-04-19 13:45:08 +02001285 ly_out_reset(UTEST_OUT);
1286 /* using lysc tree */
1287 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1288 TEST_LOCAL_PRINT(mod, 31);
1289 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1290 assert_string_equal(printed, expect);
1291 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1292
aPiecek20ddf8b2021-01-08 11:50:37 +01001293 TEST_LOCAL_TEARDOWN;
1294}
1295
1296static void
1297inheritance_of_config_flag(void **state)
1298{
1299 TEST_LOCAL_SETUP;
1300 orig =
1301 "module a21 {\n"
1302 " yang-version 1.1;\n"
1303 " namespace \"x:y\";\n"
1304 " prefix x;\n"
1305 " container a {\n"
1306 " config false;\n"
1307 " leaf b {\n"
1308 " type string;\n"
1309 " }\n"
1310 " }\n"
1311 "}\n";
1312
1313 /* from pyang */
1314 expect =
1315 "module: a21\n"
1316 " +--ro a\n"
1317 " +--ro b? string\n";
1318
aPieceke376b922021-04-19 08:08:14 +02001319 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1320 TEST_LOCAL_PRINT(mod, 72);
1321 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001322 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001323
1324 ly_out_reset(UTEST_OUT);
1325 /* using lysc tree */
1326 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1327 TEST_LOCAL_PRINT(mod, 72);
1328 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1329 assert_string_equal(printed, expect);
1330 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1331
aPiecek20ddf8b2021-01-08 11:50:37 +01001332 TEST_LOCAL_TEARDOWN;
1333}
1334
1335static void
1336inheritance_of_status_flag(void **state)
1337{
1338 TEST_LOCAL_SETUP;
1339 /* throws libyang warn: Missing explicit "..." status that was already specified in parent, inheriting. */
1340 orig =
1341 "module a22 {\n"
1342 " yang-version 1.1;\n"
1343 " namespace \"x:y\";\n"
1344 " prefix x;\n"
1345 " container a {\n"
1346 " status current;\n"
1347 " container b {\n"
1348 " status deprecated;\n"
1349 " leaf f {\n"
1350 " type string;\n"
1351 " }\n"
1352 " }\n"
1353 " container c {\n"
1354 " status obsolete;\n"
1355 " leaf g {\n"
1356 " type string;\n"
1357 " }\n"
1358 " }\n"
1359 " }\n"
1360 " container d {\n"
1361 " status deprecated;\n"
1362 " container h {\n"
1363 " status obsolete;\n"
1364 " leaf e {\n"
1365 " type string;\n"
1366 " }\n"
1367 " }\n"
1368 " }\n"
1369 "}\n";
1370
1371 /* from yanglint 1 */
1372 expect =
1373 "module: a22\n"
1374 " +--rw a\n"
1375 " | x--rw b\n"
1376 " | | x--rw f? string\n"
1377 " | o--rw c\n"
1378 " | o--rw g? string\n"
1379 " x--rw d\n"
1380 " o--rw h\n"
1381 " o--rw e? string\n";
1382
aPieceke376b922021-04-19 08:08:14 +02001383 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1384 TEST_LOCAL_PRINT(mod, 72);
1385 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001386 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001387
1388 ly_out_reset(UTEST_OUT);
1389 /* using lysc tree */
1390 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1391 TEST_LOCAL_PRINT(mod, 72);
1392 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1393 assert_string_equal(printed, expect);
1394 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1395
aPiecek20ddf8b2021-01-08 11:50:37 +01001396 TEST_LOCAL_TEARDOWN;
1397}
1398
1399static void
1400key_leaf_is_always_mandatory_true(void **state)
1401{
1402 TEST_LOCAL_SETUP;
1403 orig =
1404 "module a23 {\n"
1405 " yang-version 1.1;\n"
1406 " namespace \"x:y\";\n"
1407 " prefix x;\n"
1408 " list a {\n"
1409 " key \"k1\";\n"
1410 " list b {\n"
1411 " key \"k2\";\n"
1412 " leaf k1 {\n"
1413 " type string;\n"
1414 " }\n"
1415 " leaf k2 {\n"
1416 " type string;\n"
1417 " }\n"
1418 " }\n"
1419 " leaf k1 {\n"
1420 " type string;\n"
1421 " }\n"
1422 " }\n"
1423 "}\n";
1424
1425 /* from pyang */
1426 expect =
1427 "module: a23\n"
1428 " +--rw a* [k1]\n"
1429 " +--rw b* [k2]\n"
1430 " | +--rw k1? string\n"
1431 " | +--rw k2 string\n"
1432 " +--rw k1 string\n";
1433
aPieceke376b922021-04-19 08:08:14 +02001434 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1435 TEST_LOCAL_PRINT(mod, 72);
1436 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001437 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001438
1439 ly_out_reset(UTEST_OUT);
1440
1441 /* from pyang but with some swapped lines */
1442 expect =
1443 "module: a23\n"
1444 " +--rw a* [k1]\n"
1445 " +--rw k1 string\n"
1446 " +--rw b* [k2]\n"
1447 " +--rw k2 string\n"
1448 " +--rw k1? string\n";
1449
1450 /* using lysc tree */
1451 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1452 TEST_LOCAL_PRINT(mod, 72);
1453 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1454 assert_string_equal(printed, expect);
1455 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1456
aPiecek20ddf8b2021-01-08 11:50:37 +01001457 TEST_LOCAL_TEARDOWN;
1458}
1459
1460static void
1461transition_between_rpc_and_notif(void **state)
1462{
1463 TEST_LOCAL_SETUP;
1464 orig =
1465 "module a24 {\n"
1466 " yang-version 1.1;\n"
1467 " namespace \"x:y\";\n"
1468 " prefix x;\n"
1469 " container top {\n"
aPiecek9e505922021-04-19 13:45:08 +02001470 " leaf g {\n"
1471 " type string;\n"
1472 " }\n"
aPiecek20ddf8b2021-01-08 11:50:37 +01001473 " action rpc1 {\n"
1474 "\n"
1475 " input {\n"
1476 " leaf in {\n"
1477 " type string;\n"
1478 " }\n"
1479 " }\n"
1480 " }\n"
1481 " action rpc2 {\n"
1482 "\n"
1483 " input {\n"
1484 " leaf in {\n"
1485 " type string;\n"
1486 " }\n"
1487 " }\n"
1488 "\n"
1489 " output {\n"
1490 " leaf out {\n"
1491 " type string;\n"
1492 " }\n"
1493 " }\n"
1494 " }\n"
1495 " notification n1;\n"
1496 " notification n2;\n"
1497 " }\n"
1498 "}\n";
1499
aPiecekb352de72021-05-21 09:04:04 +02001500 /* from pyang */
aPiecek20ddf8b2021-01-08 11:50:37 +01001501 expect =
1502 "module: a24\n"
1503 " +--rw top\n"
aPiecek9e505922021-04-19 13:45:08 +02001504 " +--rw g? string\n"
aPiecek20ddf8b2021-01-08 11:50:37 +01001505 " +---x rpc1\n"
1506 " | +---w input\n"
1507 " | +---w in? string\n"
1508 " +---x rpc2\n"
1509 " | +---w input\n"
1510 " | | +---w in? string\n"
1511 " | +--ro output\n"
1512 " | +--ro out? string\n"
1513 " +---n n1\n"
1514 " +---n n2\n";
1515
aPieceke376b922021-04-19 08:08:14 +02001516 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1517 TEST_LOCAL_PRINT(mod, 72);
1518 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
aPiecek20ddf8b2021-01-08 11:50:37 +01001519 assert_string_equal(printed, expect);
aPiecek9e505922021-04-19 13:45:08 +02001520
1521 ly_out_reset(UTEST_OUT);
1522 /* using lysc tree */
1523 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1524 TEST_LOCAL_PRINT(mod, 72);
1525 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1526 assert_string_equal(printed, expect);
1527 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1528
1529 TEST_LOCAL_TEARDOWN;
1530}
1531
1532static void
1533local_augment(void **state)
1534{
1535 TEST_LOCAL_SETUP;
1536
1537 orig =
1538 "module a25 {\n"
1539 " yang-version 1.1;\n"
1540 " namespace \"x:y\";\n"
1541 " prefix x;\n"
1542 " container g;\n"
1543 " augment \"/x:g\" {\n"
1544 " container e;\n"
1545 " }\n"
1546 "}\n";
1547
1548 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1549
1550 /* from pyang */
1551 expect =
1552 "module: a25\n"
1553 " +--rw g\n"
1554 " +--rw e\n";
1555
1556 /* using lysc tree */
1557 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1558 TEST_LOCAL_PRINT(mod, 72);
1559 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1560 assert_string_equal(printed, expect);
1561 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1562
aPiecek20ddf8b2021-01-08 11:50:37 +01001563 TEST_LOCAL_TEARDOWN;
1564}
1565
aPiecek7745b282021-04-20 13:54:52 +02001566static void
1567print_compiled_node(void **state)
1568{
1569 TEST_LOCAL_SETUP;
1570 const struct lysc_node *node;
1571
1572 orig =
1573 "module a26 {\n"
1574 " yang-version 1.1;\n"
1575 " namespace \"x:y\";\n"
1576 " prefix x;\n"
1577 " container g {\n"
1578 " leaf a {\n"
1579 " type string;\n"
1580 " }\n"
1581 " container h {\n"
1582 " leaf b {\n"
1583 " type string;\n"
1584 " mandatory true;\n"
1585 " }\n"
1586 " leaf c {\n"
1587 " type string;\n"
1588 " }\n"
1589 " }\n"
1590 " }\n"
1591 "}\n";
1592
1593 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1594
1595 /* pyang -f tree --tree-path /g/h/c */
1596 expect =
1597 "module: a26\n"
1598 " +--rw g\n"
1599 " +--rw h\n"
1600 " +--rw c? string\n";
1601
1602 /* using lysc tree */
1603 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1604
1605 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h/c", 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 -f tree --tree-path /g/h */
1614 expect =
1615 "module: a26\n"
1616 " +--rw g\n"
1617 " +--rw h\n"
1618 " +--rw b string\n"
1619 " +--rw c? string\n";
1620
1621 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
1622 CHECK_POINTER(node, 1);
1623 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0));
1624 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1625 assert_string_equal(printed, expect);
1626
1627 ly_out_reset(UTEST_OUT);
1628
1629 /* pyang whose output is adjusted manually */
1630 expect =
1631 "module: a26\n"
1632 " +--rw g\n"
1633 " +--rw h\n";
1634
1635 node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0);
1636 CHECK_POINTER(node, 1);
1637 assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, LYS_PRINT_NO_SUBSTMT));
1638 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1639 assert_string_equal(printed, expect);
1640
1641 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1642
1643 TEST_LOCAL_TEARDOWN;
1644}
1645
aPiecekaecf7512021-04-21 08:34:35 +02001646static LY_ERR
1647local_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
1648 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
1649 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
1650{
1651 *module_data = user_data;
1652 *format = LYS_IN_YANG;
1653 *free_module_data = NULL;
1654 return LY_SUCCESS;
1655}
1656
1657static void
1658print_parsed_submodule(void **state)
1659{
1660 TEST_LOCAL_SETUP;
1661
1662 orig = "module a27 {\n"
1663 " yang-version 1.1;\n"
1664 " namespace \"x:y\";\n"
1665 " prefix x;\n"
1666 "\n"
1667 " include \"a27-sub\";\n"
1668 "}\n";
1669
1670 char *submodule =
1671 "submodule a27-sub {\n"
1672 " yang-version 1.1;\n"
1673 " belongs-to a27 {\n"
1674 " prefix x;\n"
1675 " }\n"
1676 "\n"
1677 " container h {\n"
1678 " leaf b {\n"
1679 " type string;\n"
1680 " }\n"
1681 " }\n"
1682 "}\n";
1683
1684 /* edited pyang output */
1685 expect =
1686 "submodule: a27-sub\n"
1687 " +--rw h\n"
1688 " +--rw b? string\n";
1689
1690 ly_ctx_set_module_imp_clb(UTEST_LYCTX, local_imp_clb, submodule);
1691 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1692 assert_int_equal(LY_SUCCESS, lys_print_submodule(UTEST_OUT, mod->parsed->includes[0].submodule, LYS_OUT_TREE, 72, 0));
1693 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1694 assert_string_equal(printed, expect);
1695
1696 TEST_LOCAL_TEARDOWN;
1697}
1698
aPiecekb8e43f12021-04-23 12:52:22 +02001699static void
1700yang_data(void **state)
1701{
1702 TEST_LOCAL_SETUP;
1703
1704 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
1705 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-restconf", "2017-01-26", NULL));
1706
1707 orig =
1708 "module a28 {\n"
1709 " yang-version 1.1;\n"
1710 " namespace \"x:y\";\n"
1711 " prefix x;\n"
1712 "\n"
1713 " import ietf-restconf {\n"
1714 " prefix rc;\n"
1715 " revision-date 2017-01-26;\n"
1716 " }\n"
1717 "\n"
1718 " rc:yang-data \"tmp1\" {\n"
1719 " container cont1 {\n"
1720 " leaf lf {\n"
1721 " type string;\n"
1722 " }\n"
1723 " list l2 {\n"
1724 " key\n"
1725 " \"a b\";\n"
1726 " leaf a {\n"
1727 " type string;\n"
1728 " }\n"
1729 " leaf b {\n"
1730 " type string;\n"
1731 " }\n"
1732 " }\n"
1733 " }\n"
1734 " }\n"
1735 " rc:yang-data \"tmp2\" {\n"
1736 " container con2 {\n"
1737 " leaf lf {\n"
1738 " type string;\n"
1739 " }\n"
1740 " }\n"
1741 " }\n"
1742 " rc:yang-data \"tmp3\" {\n"
1743 " uses g1;\n"
1744 " uses g2;\n"
1745 " }\n"
1746 " rc:yang-data \"tmp4\" {\n"
1747 " choice x {\n"
1748 " case a {\n"
1749 " container z;\n"
1750 " }\n"
1751 " case b {\n"
1752 " container y;\n"
1753 " }\n"
1754 " }\n"
1755 " }\n"
1756 "\n"
1757 " grouping g1 {\n"
1758 " description\n"
1759 " \"Some Text\";\n"
1760 " }\n"
1761 "\n"
1762 " grouping g2 {\n"
1763 " container cont3;\n"
1764 " }\n"
1765 " container mont;\n"
1766 "}\n";
1767
aPiecekb352de72021-05-21 09:04:04 +02001768 /* from pyang (--tree-print-yang-data --tree-print-groupings -p "...")
1769 * but with these adjustments:
aPiecekb8e43f12021-04-23 12:52:22 +02001770 * - <flags> is always '--' for yang-data nodes
1771 * - yang-data tmp3 has two 'uses' nodes
1772 * - grouping g2 has ':' character at the end
1773 */
1774 expect =
1775 "module: a28\n"
1776 " +--rw mont\n"
1777 "\n"
1778 " grouping g1\n"
1779 " grouping g2:\n"
1780 " +---- cont3\n"
1781 "\n"
1782 " yang-data tmp1:\n"
1783 " +---- cont1\n"
1784 " +---- lf? string\n"
1785 " +---- l2* [a b]\n"
1786 " +---- a string\n"
1787 " +---- b string\n"
1788 " yang-data tmp2:\n"
1789 " +---- con2\n"
1790 " +---- lf? string\n"
1791 " yang-data tmp3:\n"
1792 " +---u g1\n"
1793 " +---u g2\n"
1794 " yang-data tmp4:\n"
1795 " +---- (x)?\n"
1796 " +--:(a)\n"
1797 " | +---- z\n"
1798 " +--:(b)\n"
1799 " +---- y\n";
1800
1801 UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
1802 TEST_LOCAL_PRINT(mod, 72);
1803 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1804 assert_string_equal(printed, expect);
1805
1806 ly_out_reset(UTEST_OUT);
1807
aPiecekb352de72021-05-21 09:04:04 +02001808 /* from pyang (--tree-print-yang-data -p "...")
1809 * but with these adjustments:
aPiecekb8e43f12021-04-23 12:52:22 +02001810 * <flags> is always '--' for yang-data nodes
1811 */
1812 expect =
1813 "module: a28\n"
1814 " +--rw mont\n"
1815 "\n"
1816 " yang-data tmp1:\n"
1817 " +---- cont1\n"
1818 " +---- lf? string\n"
1819 " +---- l2* [a b]\n"
1820 " +---- a string\n"
1821 " +---- b string\n"
1822 " yang-data tmp2:\n"
1823 " +---- con2\n"
1824 " +---- lf? string\n"
1825 " yang-data tmp3:\n"
1826 " +---- cont3\n"
1827 " yang-data tmp4:\n"
1828 " +---- (x)?\n"
1829 " +--:(a)\n"
1830 " | +---- z\n"
1831 " +--:(b)\n"
1832 " +---- y\n";
1833
1834 /* using lysc tree */
1835 ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1836 TEST_LOCAL_PRINT(mod, 72);
1837 assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT));
1838 assert_string_equal(printed, expect);
1839 ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED);
1840
1841 TEST_LOCAL_TEARDOWN;
1842}
1843
aPiecek20ddf8b2021-01-08 11:50:37 +01001844int
1845main(void)
1846{
1847 const struct CMUnitTest tests[] = {
1848 UTEST(base_sections),
1849 UTEST(node_status),
1850 UTEST(node_config_flags),
1851 UTEST(node_rpcs_flags),
1852 UTEST(node_grouping_flags),
1853 UTEST(notif_inside_container),
1854 UTEST(node_choice),
1855 UTEST(node_case),
1856 UTEST(optional_opts),
1857 UTEST(presence_container),
1858 UTEST(node_keys),
1859 UTEST(node_type_target),
1860 UTEST(node_type_leafref),
1861 UTEST(node_iffeatures),
1862 UTEST(indent_wrapper),
1863 UTEST(line_length_twiddling),
1864 UTEST(break_before_leafref),
1865 UTEST(break_before_leafref_and_iffeature),
1866 UTEST(basic_unified_indent_before_type),
1867 UTEST(twiddling_unified_indent_before_type),
1868 UTEST(inheritance_of_config_flag),
1869 UTEST(inheritance_of_status_flag),
1870 UTEST(key_leaf_is_always_mandatory_true),
1871 UTEST(transition_between_rpc_and_notif),
aPiecek9e505922021-04-19 13:45:08 +02001872 UTEST(local_augment),
aPiecek7745b282021-04-20 13:54:52 +02001873 UTEST(print_compiled_node),
aPiecekaecf7512021-04-21 08:34:35 +02001874 UTEST(print_parsed_submodule),
aPiecekb8e43f12021-04-23 12:52:22 +02001875 UTEST(yang_data),
aPiecek20ddf8b2021-01-08 11:50:37 +01001876 };
1877
1878 return cmocka_run_group_tests(tests, NULL, NULL);
1879}