blob: 3688faabe3a58eb2664e5bffe52c1f9ab01c9b98 [file] [log] [blame]
FredGand944bdc2019-11-05 21:57:07 +08001/*
2 * @file test_printer_yin.c
3 * @author: Fred Gan <ganshaolong@vip.qq.com>
4 * @brief unit tests for functions from printer_yin.c
5 *
6 * Copyright (c) 2019 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
Michal Vasko7c8439f2020-08-05 13:25:19 +020015#include "common.h"
Radek Krejci70593c12020-06-13 20:48:09 +020016#include "context.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020017#include "out.h"
Radek Krejci70593c12020-06-13 20:48:09 +020018#include "printer_schema.h"
Michal Vasko7c8439f2020-08-05 13:25:19 +020019#include "tree_schema.h"
Radek Krejcib4ac5a92020-11-23 17:54:33 +010020#include "utests.h"
FredGand944bdc2019-11-05 21:57:07 +080021
22#define BUFSIZE 1024
23char logbuf[BUFSIZE] = {0};
24int store = -1; /* negative for infinite logging, positive for limited logging */
25
26/* set to 0 to printing error messages to stderr instead of checking them in code */
27#define ENABLE_LOGGER_CHECKING 1
28
29#if ENABLE_LOGGER_CHECKING
30static void
31logger(LY_LOG_LEVEL level, const char *msg, const char *path)
32{
33 (void) level; /* unused */
34 if (store) {
35 if (path && path[0]) {
36 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
37 } else {
38 strncpy(logbuf, msg, BUFSIZE - 1);
39 }
40 if (store > 0) {
41 --store;
42 }
43 }
44}
Radek Krejcib4ac5a92020-11-23 17:54:33 +010045
FredGand944bdc2019-11-05 21:57:07 +080046#endif
47
48static int
49logger_setup(void **state)
50{
51 (void) state; /* unused */
52#if ENABLE_LOGGER_CHECKING
53 ly_set_log_clb(logger, 1);
54#endif
55 return 0;
56}
57
58static int
59logger_teardown(void **state)
60{
61 (void) state; /* unused */
62#if ENABLE_LOGGER_CHECKING
63 if (*state) {
64 fprintf(stderr, "%s\n", logbuf);
65 }
66#endif
67 return 0;
68}
69
70void
71logbuf_clean(void)
72{
73 logbuf[0] = '\0';
74}
75
76#if ENABLE_LOGGER_CHECKING
77# define logbuf_assert(str) assert_string_equal(logbuf, str)
78#else
79# define logbuf_assert(str)
80#endif
81
FredGand944bdc2019-11-05 21:57:07 +080082static void
83test_module(void **state)
84{
85 *state = test_module;
86
87 struct ly_ctx *ctx = {0};
88 const struct lys_module *mod;
89
Radek Krejcib4ac5a92020-11-23 17:54:33 +010090 const char *orig =
FredGand944bdc2019-11-05 21:57:07 +080091 "module all {\n"
92 " yang-version 1.1;\n"
93 " namespace \"urn:all\";\n"
94 " prefix all_mod;\n\n"
95 " import ietf-yang-types {\n"
96 " prefix yt;\n"
97 " revision-date 2013-07-15;\n"
98 " description\n"
99 " \"YANG types\";\n"
100 " reference\n"
101 " \"RFC reference\";\n"
102 " }\n\n"
103 " feature feat1 {\n"
104 " if-feature \"feat2\";\n"
105 " status obsolete;\n"
106 " }\n\n"
107 " feature feat2;\n"
108 " feature feat3;\n\n"
109 " identity ident2 {\n"
110 " base ident1;\n"
111 " }\n\n"
112 " identity ident1;\n\n"
113 " typedef tdef1 {\n"
114 " type tdef2 {\n"
115 " length \"3..9 | 30..40\";\n"
116 " pattern \"[ac]*\";\n"
117 " }\n"
118 " units \"none\";\n"
119 " default \"aaa\";\n"
120 " }\n\n"
121 " typedef tdef2 {\n"
122 " type string {\n"
123 " length \"2..10 | 20..50\";\n"
124 " pattern \"[ab]*\";\n"
125 " }\n"
126 " }\n\n"
127 " grouping group1 {\n"
128 " leaf leaf1 {\n"
129 " type int8;\n"
130 " }\n"
131 " }\n\n"
132 " container cont1 {\n"
133 " leaf leaf2 {\n"
134 " if-feature \"feat1\";\n"
135 " type int16;\n"
136 " status obsolete;\n"
137 " }\n\n"
138 " uses group1 {\n"
139 " if-feature \"feat2\";\n"
140 " refine \"leaf1\" {\n"
141 " if-feature \"feat3\";\n"
142 " must \"24 - 4 = number('20')\";\n"
143 " default \"25\";\n"
144 " config true;\n"
145 " mandatory false;\n"
146 " description\n"
147 " \"dsc\";\n"
148 " reference\n"
149 " \"none\";\n"
150 " }\n"
151 " }\n\n"
152 " leaf leaf3 {\n"
153 " type int32;\n"
154 " }\n\n"
155 " leaf leaf4 {\n"
156 " type int64 {\n"
157 " range \"1000 .. 50000\" {\n"
158 " error-message\n"
159 " \"Special error message.\";\n"
160 " error-app-tag \"special-tag\";\n"
161 " }\n"
162 " }\n"
163 " }\n\n"
164 " leaf leaf5 {\n"
165 " type uint8;\n"
166 " }\n\n"
167 " leaf leaf6 {\n"
168 " type uint16;\n"
169 " }\n\n"
170 " leaf leaf7 {\n"
171 " type uint32;\n"
172 " }\n\n"
173 " leaf leaf8 {\n"
174 " type uint64;\n"
175 " }\n\n"
176 " choice choic1 {\n"
177 " default \"leaf9b\";\n"
178 " leaf leaf9a {\n"
179 " type decimal64 {\n"
180 " fraction-digits 9;\n"
181 " }\n"
182 " }\n\n"
183 " leaf leaf9b {\n"
184 " type boolean;\n"
185 " default \"false\";\n"
186 " }\n"
187 " }\n\n"
188 " leaf leaf10 {\n"
189 " type boolean;\n"
190 " }\n\n"
191 " leaf leaf11 {\n"
192 " type enumeration {\n"
193 " enum \"one\";\n"
194 " enum \"two\";\n"
195 " enum \"five\" {\n"
196 " value 5;\n"
197 " }\n"
198 " }\n"
199 " }\n\n"
200 " leaf leaf12 {\n"
201 " type bits {\n"
202 " bit flag0 {\n"
203 " position 0;\n"
204 " }\n"
205 " bit flag1;\n"
206 " bit flag2 {\n"
207 " position 2;\n"
208 " }\n"
209 " bit flag3 {\n"
210 " position 3;\n"
211 " }\n"
212 " }\n"
213 " default \"flag0 flag3\";\n"
214 " }\n\n"
215 " leaf leaf13 {\n"
216 " type binary;\n"
217 " }\n\n"
218 " leaf leaf14 {\n"
219 " type leafref {\n"
220 " path \"/cont1/leaf17\";\n"
221 " }\n"
222 " }\n\n"
223 " leaf leaf15 {\n"
224 " type empty;\n"
225 " }\n\n"
226 " leaf leaf16 {\n"
227 " type union {\n"
228 " type instance-identifier {\n"
229 " require-instance true;\n"
230 " }\n"
231 " type int8;\n"
232 " }\n"
233 " }\n\n"
234 " list list1 {\n"
235 " key \"leaf18\";\n"
236 " unique \"leaf19\";\n"
237 " min-elements 1;\n"
238 " max-elements 20;\n"
239 " leaf leaf18 {\n"
240 " type string;\n"
241 " }\n\n"
242 " leaf leaf19 {\n"
243 " type uint32;\n"
244 " }\n\n"
245 " anyxml axml1;\n"
246 " anydata adata1;\n\n"
247 " action act1 {\n"
248 " input {\n"
249 " leaf leaf24 {\n"
250 " type string;\n"
251 " }\n"
252 " }\n\n"
253 " output {\n"
254 " leaf leaf25 {\n"
255 " type string;\n"
256 " }\n"
257 " }\n"
258 " }\n\n"
259 " notification notif1 {\n"
260 " leaf leaf26 {\n"
261 " type string;\n"
262 " }\n"
263 " }\n"
264 " }\n\n"
265 " leaf-list llist1 {\n"
266 " type tdef1;\n"
267 " ordered-by user;\n"
268 " }\n\n"
269 " list list2 {\n"
270 " key \"leaf27 leaf28\";\n"
271 " leaf leaf27 {\n"
272 " type uint8;\n"
273 " }\n\n"
274 " leaf leaf28 {\n"
275 " type uint8;\n"
276 " }\n"
277 " }\n\n"
278 " leaf leaf29 {\n"
279 " type instance-identifier;\n"
280 " }\n\n"
281 " container must-deviations-container {\n"
282 " presence \"Allows deviations on the leaf\";\n"
283 " leaf leaf30 {\n"
284 " type string;\n"
285 " }\n"
286 " }\n\n"
287 " leaf leaf23 {\n"
288 " type empty;\n"
289 " }\n"
290 " }\n\n"
291 " augment \"/cont1\" {\n"
292 " leaf leaf17 {\n"
293 " type string;\n"
294 " }\n"
295 " }\n\n"
296 " rpc rpc1 {\n"
297 " input {\n"
298 " leaf leaf20 {\n"
299 " type tdef1;\n"
300 " }\n"
301 " }\n\n"
302 " output {\n"
303 " container cont2 {\n"
304 " leaf leaf21 {\n"
305 " type empty;\n"
306 " }\n"
307 " }\n"
308 " }\n"
309 " }\n\n"
310 " container test-when {\n"
311 " leaf when-check {\n"
312 " type boolean;\n"
313 " }\n\n"
314 " leaf gated-data {\n"
315 " when \"../when-check = 'true'\";\n"
316 " type uint16;\n"
317 " }\n"
318 " }\n\n"
319 " extension c-define {\n"
320 " description\n"
321 " \"Takes as an argument a name string.\n"
322 " Makes the code generator use the given name\n"
323 " in the #define.\";\n"
324 " argument \"name\";\n"
325 " }\n"
326 "}\n";
327
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100328 const char *ori_res =
FredGand944bdc2019-11-05 21:57:07 +0800329 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
330 "<module name=\"all\"\n"
331 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
332 " xmlns:all_mod=\"urn:all\"\n"
333 " xmlns:yt=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">\n"
334 " <yang-version value=\"1.1\"/>\n"
335 " <namespace uri=\"urn:all\"/>\n"
336 " <prefix value=\"all_mod\"/>\n"
337 " <import module=\"ietf-yang-types\">\n"
338 " <prefix value=\"yt\"/>\n"
339 " <revision-date date=\"2013-07-15\"/>\n"
340 " <description>\n"
341 " <text>YANG types</text>\n"
342 " </description>\n"
343 " <reference>\n"
344 " <text>RFC reference</text>\n"
345 " </reference>\n"
346 " </import>\n\n"
347 " <extension name=\"c-define\">\n"
348 " <argument name=\"name\"/>\n"
349 " <description>\n"
350 " <text>Takes as an argument a name string.\n"
351 "Makes the code generator use the given name\n"
352 "in the #define.</text>\n"
353 " </description>\n"
354 " </extension>\n"
355 " <feature name=\"feat1\">\n"
356 " <if-feature name=\"feat2\"/>\n"
357 " <status value=\"obsolete\"/>\n"
358 " </feature>\n"
359 " <feature name=\"feat2\"/>\n"
360 " <feature name=\"feat3\"/>\n"
361 " <identity name=\"ident2\">\n"
362 " <base name=\"ident1\"/>\n"
363 " </identity>\n"
364 " <identity name=\"ident1\"/>\n"
365 " <typedef name=\"tdef1\">\n"
366 " <type name=\"tdef2\">\n"
367 " <length value=\"3..9 | 30..40\"/>\n"
368 " <pattern value=\"[ac]*\"/>\n"
369 " </type>\n"
370 " <units name=\"none\"/>\n"
371 " <default value=\"aaa\"/>\n"
372 " </typedef>\n"
373 " <typedef name=\"tdef2\">\n"
374 " <type name=\"string\">\n"
375 " <length value=\"2..10 | 20..50\"/>\n"
376 " <pattern value=\"[ab]*\"/>\n"
377 " </type>\n"
378 " </typedef>\n"
379 " <grouping name=\"group1\">\n"
380 " <leaf name=\"leaf1\">\n"
381 " <type name=\"int8\"/>\n"
382 " </leaf>\n"
383 " </grouping>\n"
384 " <container name=\"cont1\">\n"
385 " <leaf name=\"leaf2\">\n"
386 " <if-feature name=\"feat1\"/>\n"
387 " <type name=\"int16\"/>\n"
388 " <status value=\"obsolete\"/>\n"
389 " </leaf>\n"
390 " <uses name=\"group1\">\n"
391 " <if-feature name=\"feat2\"/>\n"
392 " <refine target-node=\"leaf1\">\n"
393 " <if-feature name=\"feat3\"/>\n"
394 " <must condition=\"24 - 4 = number('20')\"/>\n"
395 " <default value=\"25\"/>\n"
396 " <config value=\"true\"/>\n"
397 " <mandatory value=\"false\"/>\n"
398 " <description>\n"
399 " <text>dsc</text>\n"
400 " </description>\n"
401 " <reference>\n"
402 " <text>none</text>\n"
403 " </reference>\n"
404 " </refine>\n"
405 " </uses>\n"
406 " <leaf name=\"leaf3\">\n"
407 " <type name=\"int32\"/>\n"
408 " </leaf>\n"
409 " <leaf name=\"leaf4\">\n"
410 " <type name=\"int64\">\n"
411 " <range value=\"1000 .. 50000\">\n"
412 " <error-message>\n"
413 " <value>Special error message.</value>\n"
414 " </error-message>\n"
415 " <error-app-tag value=\"special-tag\"/>\n"
416 " </range>\n"
417 " </type>\n"
418 " </leaf>\n"
419 " <leaf name=\"leaf5\">\n"
420 " <type name=\"uint8\"/>\n"
421 " </leaf>\n"
422 " <leaf name=\"leaf6\">\n"
423 " <type name=\"uint16\"/>\n"
424 " </leaf>\n"
425 " <leaf name=\"leaf7\">\n"
426 " <type name=\"uint32\"/>\n"
427 " </leaf>\n"
428 " <leaf name=\"leaf8\">\n"
429 " <type name=\"uint64\"/>\n"
430 " </leaf>\n"
431 " <choice name=\"choic1\">\n"
432 " <default value=\"leaf9b\"/>\n"
433 " <leaf name=\"leaf9a\">\n"
434 " <type name=\"decimal64\">\n"
435 " <fraction-digits value=\"9\"/>\n"
436 " </type>\n"
437 " </leaf>\n"
438 " <leaf name=\"leaf9b\">\n"
439 " <type name=\"boolean\"/>\n"
440 " <default value=\"false\"/>\n"
441 " </leaf>\n"
442 " </choice>\n"
443 " <leaf name=\"leaf10\">\n"
444 " <type name=\"boolean\"/>\n"
445 " </leaf>\n"
446 " <leaf name=\"leaf11\">\n"
447 " <type name=\"enumeration\">\n"
448 " <enum name=\"one\"/>\n"
449 " <enum name=\"two\"/>\n"
450 " <enum name=\"five\">\n"
451 " <value value=\"5\"/>\n"
452 " </enum>\n"
453 " </type>\n"
454 " </leaf>\n"
455 " <leaf name=\"leaf12\">\n"
456 " <type name=\"bits\">\n"
457 " <bit name=\"flag0\">\n"
458 " <position value=\"0\"/>\n"
459 " </bit>\n"
460 " <bit name=\"flag1\"/>\n"
461 " <bit name=\"flag2\">\n"
462 " <position value=\"2\"/>\n"
463 " </bit>\n"
464 " <bit name=\"flag3\">\n"
465 " <position value=\"3\"/>\n"
466 " </bit>\n"
467 " </type>\n"
468 " <default value=\"flag0 flag3\"/>\n"
469 " </leaf>\n"
470 " <leaf name=\"leaf13\">\n"
471 " <type name=\"binary\"/>\n"
472 " </leaf>\n"
473 " <leaf name=\"leaf14\">\n"
474 " <type name=\"leafref\">\n"
475 " <path value=\"/cont1/leaf17\"/>\n"
476 " </type>\n"
477 " </leaf>\n"
478 " <leaf name=\"leaf15\">\n"
479 " <type name=\"empty\"/>\n"
480 " </leaf>\n"
481 " <leaf name=\"leaf16\">\n"
482 " <type name=\"union\">\n"
483 " <type name=\"instance-identifier\">\n"
484 " <require-instance value=\"true\"/>\n"
485 " </type>\n"
486 " <type name=\"int8\"/>\n"
487 " </type>\n"
488 " </leaf>\n"
489 " <list name=\"list1\">\n"
490 " <key value=\"leaf18\"/>\n"
491 " <unique tag=\"leaf19\"/>\n"
492 " <min-elements value=\"1\"/>\n"
493 " <max-elements value=\"20\"/>\n"
494 " <leaf name=\"leaf18\">\n"
495 " <type name=\"string\"/>\n"
496 " </leaf>\n"
497 " <leaf name=\"leaf19\">\n"
498 " <type name=\"uint32\"/>\n"
499 " </leaf>\n"
500 " <anyxml name=\"axml1\"/>\n"
501 " <anydata name=\"adata1\"/>\n"
502 " <action name=\"act1\">\n"
503 " <input>\n"
504 " <leaf name=\"leaf24\">\n"
505 " <type name=\"string\"/>\n"
506 " </leaf>\n"
507 " </input>\n"
508 " <output>\n"
509 " <leaf name=\"leaf25\">\n"
510 " <type name=\"string\"/>\n"
511 " </leaf>\n"
512 " </output>\n"
513 " </action>\n"
514 " <notification name=\"notif1\">\n"
515 " <leaf name=\"leaf26\">\n"
516 " <type name=\"string\"/>\n"
517 " </leaf>\n"
518 " </notification>\n"
519 " </list>\n"
520 " <leaf-list name=\"llist1\">\n"
521 " <type name=\"tdef1\"/>\n"
522 " <ordered-by value=\"user\"/>\n"
523 " </leaf-list>\n"
524 " <list name=\"list2\">\n"
525 " <key value=\"leaf27 leaf28\"/>\n"
526 " <leaf name=\"leaf27\">\n"
527 " <type name=\"uint8\"/>\n"
528 " </leaf>\n"
529 " <leaf name=\"leaf28\">\n"
530 " <type name=\"uint8\"/>\n"
531 " </leaf>\n"
532 " </list>\n"
533 " <leaf name=\"leaf29\">\n"
534 " <type name=\"instance-identifier\"/>\n"
535 " </leaf>\n"
536 " <container name=\"must-deviations-container\">\n"
537 " <presence value=\"Allows deviations on the leaf\"/>\n"
538 " <leaf name=\"leaf30\">\n"
539 " <type name=\"string\"/>\n"
540 " </leaf>\n"
541 " </container>\n"
542 " <leaf name=\"leaf23\">\n"
543 " <type name=\"empty\"/>\n"
544 " </leaf>\n"
545 " </container>\n"
546 " <container name=\"test-when\">\n"
547 " <leaf name=\"when-check\">\n"
548 " <type name=\"boolean\"/>\n"
549 " </leaf>\n"
550 " <leaf name=\"gated-data\">\n"
551 " <when condition=\"../when-check = 'true'\"/>\n"
552 " <type name=\"uint16\"/>\n"
553 " </leaf>\n"
554 " </container>\n"
555 " <augment target-node=\"/cont1\">\n"
556 " <leaf name=\"leaf17\">\n"
557 " <type name=\"string\"/>\n"
558 " </leaf>\n"
559 " </augment>\n"
560 " <rpc name=\"rpc1\">\n"
561 " <input>\n"
562 " <leaf name=\"leaf20\">\n"
563 " <type name=\"tdef1\"/>\n"
564 " </leaf>\n"
565 " </input>\n"
566 " <output>\n"
567 " <container name=\"cont2\">\n"
568 " <leaf name=\"leaf21\">\n"
569 " <type name=\"empty\"/>\n"
570 " </leaf>\n"
571 " </container>\n"
572 " </output>\n"
573 " </rpc>\n"
574 "</module>\n";
575
Radek Krejcia5bba312020-01-09 15:41:20 +0100576 char *printed;
Radek Krejci241f6b52020-05-21 18:13:49 +0200577 struct ly_out *out;
Radek Krejcia5bba312020-01-09 15:41:20 +0100578
Radek Krejci84ce7b12020-06-11 17:28:25 +0200579 assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
FredGand944bdc2019-11-05 21:57:07 +0800580 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
581
Michal Vasko3a41dff2020-07-15 14:30:28 +0200582 assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
Michal Vasko7c8439f2020-08-05 13:25:19 +0200583 assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YIN, 0, 0));
Michal Vasko63f3d842020-07-08 10:10:14 +0200584 assert_int_equal(strlen(ori_res), ly_out_printed(out));
FredGand944bdc2019-11-05 21:57:07 +0800585 assert_string_equal(printed, ori_res);
Radek Krejcia5bba312020-01-09 15:41:20 +0100586
Michal Vasko7c8439f2020-08-05 13:25:19 +0200587 *state = NULL;
588 ly_out_free(out, NULL, 1);
589 ly_ctx_destroy(ctx, NULL);
590}
FredGand944bdc2019-11-05 21:57:07 +0800591
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100592static LY_ERR
593test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
594 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
595 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
Michal Vasko7c8439f2020-08-05 13:25:19 +0200596{
597 *module_data = user_data;
598 *format = LYS_IN_YIN;
599 *free_module_data = NULL;
600 return LY_SUCCESS;
601}
602
603static void
604test_submodule(void **state)
605{
606 *state = test_module;
607
608 struct ly_ctx *ctx = {0};
609 const struct lys_module *mod;
610
611 const char *mod_yin =
612 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
613 "<module name=\"a\"\n"
614 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
615 " xmlns:a_mod=\"urn:a\">\n"
616 " <yang-version value=\"1.1\"/>\n"
617 " <namespace uri=\"urn:a\"/>\n"
618 " <prefix value=\"a_mod\"/>\n"
619 " <include module=\"a-sub\"/>\n"
620 "</module>\n";
621
622 char *submod_yin =
623 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
624 "<submodule name=\"a-sub\"\n"
625 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
626 " xmlns:a_mod=\"urn:a\"\n"
627 " xmlns:yt=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">\n"
628 " <yang-version value=\"1.1\"/>\n"
629 " <belongs-to module=\"a\">\n"
630 " <prefix value=\"a_mod\"/>\n"
631 " </belongs-to>\n"
632 " <import module=\"ietf-yang-types\">\n"
633 " <prefix value=\"yt\"/>\n"
634 " <revision-date date=\"2013-07-15\"/>\n"
635 " </import>\n\n"
636 " <description>\n"
637 " <text>YANG types</text>\n"
638 " </description>\n"
639 " <reference>\n"
640 " <text>RFC reference</text>\n"
641 " </reference>\n"
642 "</submodule>\n";
643
644 char *printed;
645 struct ly_out *out;
646
647 assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
648 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
649
650 ly_ctx_set_module_imp_clb(ctx, test_imp_clb, submod_yin);
651 assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, mod_yin, LYS_IN_YIN, &mod));
652 assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod, mod->parsed->includes[0].submodule, LYS_OUT_YIN, 0, 0));
653 assert_int_equal(strlen(submod_yin), ly_out_printed(out));
654 assert_string_equal(printed, submod_yin);
Radek Krejcia5bba312020-01-09 15:41:20 +0100655
FredGand944bdc2019-11-05 21:57:07 +0800656 *state = NULL;
Michal Vasko7c8439f2020-08-05 13:25:19 +0200657 ly_out_free(out, NULL, 1);
FredGand944bdc2019-11-05 21:57:07 +0800658 ly_ctx_destroy(ctx, NULL);
659}
660
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100661int
662main(void)
FredGand944bdc2019-11-05 21:57:07 +0800663{
664 const struct CMUnitTest tests[] = {
665 cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
Michal Vasko7c8439f2020-08-05 13:25:19 +0200666 cmocka_unit_test_setup_teardown(test_submodule, logger_setup, logger_teardown),
FredGand944bdc2019-11-05 21:57:07 +0800667 };
668
669 return cmocka_run_group_tests(tests, NULL, NULL);
670}