blob: ebb69cb8157980affb6a71fdf4f00f74cf85d3b1 [file] [log] [blame]
Michal Vasko60ea6352020-06-29 13:39:39 +02001/**
2 * @file test_lyb.c
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief Cmocka tests for LYB binary data format.
5 *
6 * Copyright (c) 2020 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
15#include <inttypes.h>
16#include <setjmp.h>
17#include <stdarg.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <cmocka.h>
22
23#include "hash_table.h"
24#include "libyang.h"
25#include "tests/config.h"
26
27struct state {
28 struct ly_ctx *ctx;
29 struct lyd_node *dt1, *dt2;
30 char *mem;
31};
32
33static void
34check_data_tree_next(struct lyd_node **start, struct lyd_node **next, struct lyd_node **elem)
35{
36 if (*elem) {
37 goto loop_next;
38 }
39
40loop_begin:
Michal Vasko56daf732020-08-10 10:57:18 +020041 /* LYD_TREE_DFS_BEGIN */
42 for (*elem = *next = *start; *elem; *elem = *next) {
Michal Vasko60ea6352020-06-29 13:39:39 +020043 return;
44loop_next:
Michal Vasko56daf732020-08-10 10:57:18 +020045 /* LYD_TREE_DFS_END */
46
47 /* select element for the next run - children first */
48 *next = lyd_node_children(*elem, 0);
49 if (!*next) {
50 /* no children */
51 if (*elem == *start) {
52 /* we are done, (START) has no children */
53 break;
54 }
55 /* try siblings */
56 *next = (*elem)->next;
57 }
58 while (!*next) {
59 /* parent is already processed, go to its sibling */
60 *elem = (struct lyd_node *)(*elem)->parent;
61 /* no siblings, go back through parents */
62 if ((*elem)->parent == (*start)->parent) {
63 /* we are done, no next element to process */
64 break;
65 }
66 *next = (*elem)->next;
67 }
Michal Vasko60ea6352020-06-29 13:39:39 +020068 }
69
70 if (!*next) {
71 /* top-level siblings */
72 *start = (*start)->next;
73 if (!(*start)) {
74 *elem = NULL;
75 return;
76 }
77 goto loop_begin;
78 }
79
80 return;
81}
82
83static void
84check_data_tree(struct lyd_node *root1, struct lyd_node *root2)
85{
86 struct lyd_node *next1, *next2, *elem1 = NULL, *elem2 = NULL, *iter;
87 struct lyd_meta *meta1, *meta2;
88 struct lyd_node_inner *in1, *in2;
89 uint32_t i1, i2;
90
91 for (check_data_tree_next(&root1, &next1, &elem1), check_data_tree_next(&root2, &next2, &elem2);
92 elem1 && elem2;
93 check_data_tree_next(&root1, &next1, &elem1), check_data_tree_next(&root2, &next2, &elem2)) {
94
95 if (elem1->schema != elem2->schema) {
96 fprintf(stderr, "Schema mismatch (\"%s\" and \"%s\").\n", elem1->schema->name, elem2->schema->name);
97 fail();
98 }
99
100 /* check common data node attributes */
101 if (elem1->flags != elem2->flags) {
102 fprintf(stderr, "\"%s\": flags mismatch (\"%u\" and \"%u\").\n", elem1->schema->name, elem1->flags, elem2->flags);
103 fail();
104 }
105
106 /* check data node attributes */
107 for (meta1 = elem1->meta, meta2 = elem2->meta; meta1 && meta2; meta1 = meta1->next, meta2 = meta2->next) {
108 if (meta1->annotation != meta2->annotation) {
109 fprintf(stderr, "\"%s\": meta annotation mismatch.\n", elem1->schema->name);
110 fail();
111 }
112 if (strcmp(meta1->name, meta2->name)) {
113 fprintf(stderr, "\"%s\": meta name mismatch (\"%s\" and \"%s\").\n", elem1->schema->name, meta1->name, meta2->name);
114 fail();
115 }
116 if (lyd_compare_meta(meta1, meta2)) {
117 fprintf(stderr, "\"%s\": meta value mismatch.\n", elem1->schema->name);
118 fail();
119 }
120 }
121 if (meta1) {
122 fprintf(stderr, "\"%s\": meta mismatch (\"%s\" and \"NULL\").\n", elem1->schema->name, meta1->name);
123 fail();
124 }
125 if (meta2) {
126 fprintf(stderr, "\"%s\": meta mismatch (\"NULL\" and \"%s\").\n", elem1->schema->name, meta2->name);
127 fail();
128 }
129
130 /* check specific data node attributes */
131 switch (elem1->schema->nodetype) {
132 case LYS_CONTAINER:
133 case LYS_LIST:
134 case LYS_RPC:
135 case LYS_ACTION:
136 case LYS_NOTIF:
137 in1 = (struct lyd_node_inner *)elem1;
138 in2 = (struct lyd_node_inner *)elem2;
139
140 i1 = 0;
141 LY_LIST_FOR(in1->child, iter) {
142 ++i1;
143 }
144
145 i2 = 0;
146 LY_LIST_FOR(in2->child, iter) {
147 ++i2;
148 }
149
150 if (i1 != i2) {
151 fprintf(stderr, "\"%s\": child count mismatch (%u and %u).\n", elem1->schema->name, i1, i2);
152 fail();
153 }
154
155 if (i1 >= LYD_HT_MIN_ITEMS) {
156 if (!in1->children_ht || !in2->children_ht) {
157 fprintf(stderr, "\"%s\": missing hash table (%p and %p).\n", elem1->schema->name, in1->children_ht,
158 in2->children_ht);
159 fail();
160 }
161
162 LY_LIST_FOR(in1->child, iter) {
163 if (lyht_find(in1->children_ht, &iter, iter->hash, NULL)) {
164 fprintf(stderr, "\"%s\": missing child \"%s\" in the hash table 1.\n", elem1->schema->name, iter->schema->name);
165 fail();
166 }
167 }
168 LY_LIST_FOR(in2->child, iter) {
169 if (lyht_find(in2->children_ht, &iter, iter->hash, NULL)) {
170 fprintf(stderr, "\"%s\": missing child \"%s\" in the hash table 2.\n", elem1->schema->name, iter->schema->name);
171 fail();
172 }
173 }
174 }
175 break;
176 case LYS_LEAF:
177 case LYS_LEAFLIST:
178 case LYS_ANYDATA:
179 case LYS_ANYXML:
Michal Vasko8f359bf2020-07-28 10:41:15 +0200180 if (lyd_compare_single(elem1, elem2, 0)) {
Michal Vasko60ea6352020-06-29 13:39:39 +0200181 fprintf(stderr, "\"%s\": value mismatch.\n", elem1->schema->name);
182 fail();
183 }
184 break;
185 default:
186 fprintf(stderr, "Unexpected data node type.\n");
187 fail();
188 }
189
190 if (!elem1->hash) {
191 fprintf(stderr, "\"%s\": hash not calculated.\n", elem1->schema->name);
192 fail();
193 }
194 if (elem1->hash != elem2->hash) {
195 fprintf(stderr, "\"%s\": hashes do not match (%u and %u).\n", elem1->schema->name, elem1->hash, elem2->hash);
196 fail();
197 }
198 }
199
200 if (elem1) {
201 fprintf(stderr, "Schema mismatch (\"%s\" and \"NULL\").\n", elem1->schema->name);
202 fail();
203 }
204 if (elem2) {
205 fprintf(stderr, "Schema mismatch (\"NULL\" and \"%s\").\n", elem2->schema->name);
206 fail();
207 }
208}
209
210static int
211setup_f(void **state)
212{
213 struct state *st;
214
215 (*state) = st = calloc(1, sizeof *st);
216 assert_non_null(st);
217
218 /* libyang context */
219 assert_int_equal(ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &st->ctx), LY_SUCCESS);
220
221 return 0;
222}
223
224static int
225teardown_f(void **state)
226{
227 struct state *st = (*state);
228
229 lyd_free_siblings(st->dt1);
230 lyd_free_siblings(st->dt2);
231 ly_ctx_destroy(st->ctx, NULL);
232 free(st->mem);
233 free(st);
234 (*state) = NULL;
235
236 return 0;
237}
238
239static void
240test_ietf_interfaces(void **state)
241{
242 struct state *st = (*state);
243 int ret;
244 const char *data_xml =
245 "<interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">"
246 "<interface>"
247 "<name>eth0</name>"
248 "<description>Ethernet 0</description>"
249 "<type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>"
250 "<enabled>true</enabled>"
251 "<ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">"
252 "<enabled>true</enabled>"
253 "<mtu>1500</mtu>"
254 "<address>"
255 "<ip>192.168.2.100</ip>"
256 "<prefix-length>24</prefix-length>"
257 "</address>"
258 "</ipv4>"
259 "</interface>"
260 "<interface>"
261 "<name>eth1</name>"
262 "<description>Ethernet 1</description>"
263 "<type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>"
264 "<enabled>true</enabled>"
265 "<ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">"
266 "<enabled>true</enabled>"
267 "<mtu>1500</mtu>"
268 "<address>"
269 "<ip>10.10.1.5</ip>"
270 "<prefix-length>16</prefix-length>"
271 "</address>"
272 "</ipv4>"
273 "</interface>"
274 "<interface>"
275 "<name>gigaeth0</name>"
276 "<description>GigabitEthernet 0</description>"
277 "<type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>"
278 "<enabled>false</enabled>"
279 "</interface>"
280 "</interfaces>";
281
282
283 assert_non_null(ly_ctx_load_module(st->ctx, "ietf-ip", NULL));
284 assert_non_null(ly_ctx_load_module(st->ctx, "iana-if-type", NULL));
285
Radek Krejci7931b192020-06-25 17:05:03 +0200286 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
Michal Vasko60ea6352020-06-29 13:39:39 +0200287 assert_ptr_not_equal(st->dt1, NULL);
288
Radek Krejci7931b192020-06-25 17:05:03 +0200289 ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS);
Michal Vasko60ea6352020-06-29 13:39:39 +0200290 assert_int_equal(ret, 0);
291
Radek Krejci7931b192020-06-25 17:05:03 +0200292 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2));
Michal Vasko60ea6352020-06-29 13:39:39 +0200293 assert_ptr_not_equal(st->dt2, NULL);
294
295 check_data_tree(st->dt1, st->dt2);
296}
297
298static void
299test_origin(void **state)
300{
301 struct state *st = (*state);
302 int ret;
303 const char *origin_yang =
304 "module test-origin {"
305 " namespace \"urn:test-origin\";"
306 " prefix to;"
307 " import ietf-origin {"
308 " prefix or;"
309 " }"
310 ""
311 " container cont {"
312 " leaf leaf1 {"
313 " type string;"
314 " }"
315 " leaf leaf2 {"
316 " type string;"
317 " }"
318 " leaf leaf3 {"
319 " type uint8;"
320 " }"
321 " }"
322 "}";
323 const char *data_xml =
324 "<cont xmlns=\"urn:test-origin\">"
325 "<leaf1 xmlns:or=\"urn:ietf:params:xml:ns:yang:ietf-origin\" or:origin=\"or:default\">value1</leaf1>"
326 "<leaf2>value2</leaf2>"
327 "<leaf3 xmlns:or=\"urn:ietf:params:xml:ns:yang:ietf-origin\" or:origin=\"or:system\">125</leaf3>"
328 "</cont>";
329
Michal Vasko3a41dff2020-07-15 14:30:28 +0200330 assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, origin_yang, LYS_IN_YANG, NULL));
Michal Vasko60ea6352020-06-29 13:39:39 +0200331 lys_set_implemented(ly_ctx_get_module_latest(st->ctx, "ietf-origin"));
332
Radek Krejci7931b192020-06-25 17:05:03 +0200333 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
Michal Vasko60ea6352020-06-29 13:39:39 +0200334 assert_ptr_not_equal(st->dt1, NULL);
335
Radek Krejci7931b192020-06-25 17:05:03 +0200336 ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS);
Michal Vasko60ea6352020-06-29 13:39:39 +0200337 assert_int_equal(ret, 0);
338
Radek Krejci7931b192020-06-25 17:05:03 +0200339 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2));
Michal Vasko60ea6352020-06-29 13:39:39 +0200340 assert_ptr_not_equal(st->dt2, NULL);
341
342 check_data_tree(st->dt1, st->dt2);
343}
344
345static void
346test_statements(void **state)
347{
348 struct state *st = (*state);
349 int ret;
350 const char *links_yang =
351 "module links {"
352 "yang-version 1.1;"
353 "namespace \"urn:module2\";"
354 "prefix mod2;"
355
356 "identity just-another-identity {"
357
358 "}"
359
360 "leaf one-leaf {"
361 "type string;"
362 "}"
363
364 "list list-for-augment {"
365 "key keyleaf;"
366
367 "leaf keyleaf {"
368 "type string;"
369 "}"
370
371 "leaf just-leaf {"
372 "type int32;"
373 "}"
374 "}"
375
376 "leaf rleaf {"
377 "type string;"
378 "}"
379
380 "leaf-list llist {"
381 "type string;"
382 "min-elements 0;"
383 "max-elements 100;"
384 "ordered-by user;"
385 "}"
386
387 "grouping rgroup {"
388 "leaf rg1 {"
389 "type string;"
390 "}"
391
392 "leaf rg2 {"
393 "type string;"
394 "}"
395 "}"
396 "}";
397
398 const char *statements_yang =
399 "module statements {"
400 "namespace \"urn:module\";"
401 "prefix mod;"
402 "yang-version 1.1;"
403
404 "import links {"
405 "prefix mod2;"
406 "}"
407
408 "identity random-identity {"
409 "base \"mod2:just-another-identity\";"
410 "base \"another-identity\";"
411 "}"
412
413 "identity another-identity {"
414 "base \"mod2:just-another-identity\";"
415 "}"
416
417 "typedef percent {"
418 "type uint8 {"
419 "range \"0 .. 100\";"
420 "}"
421 "units percent;"
422 "}"
423
424 "container ice-cream-shop {"
425 "container employees {"
426 "list employee {"
427 "config true;"
428 "key id;"
429 "unique name;"
430 "min-elements 0;"
431 "max-elements 100;"
432
433 "leaf id {"
434 "type uint64;"
435 "mandatory true;"
436 "}"
437
438 "leaf name {"
439 "type string;"
440 "}"
441
442 "leaf age {"
443 "type uint32;"
444 "}"
445 "}"
446 "}"
447 "}"
448
449 "container random {"
450 "choice switch {"
451 "case a {"
452 "leaf aleaf {"
453 "type string;"
454 "default aaa;"
455 "}"
456 "}"
457
458 "case c {"
459 "leaf cleaf {"
460 "type string;"
461 "}"
462 "}"
463 "}"
464
465 "anyxml xml-data;"
466 "anydata any-data;"
467 "leaf-list leaflist {"
468 "type string;"
469 "min-elements 0;"
470 "max-elements 20;"
471 "ordered-by system;"
472 "}"
473
474 "grouping group {"
475 "leaf g1 {"
476 "mandatory false;"
477 "type percent;"
478 "}"
479
480 "leaf g2 {"
481 "type string;"
482 "}"
483 "}"
484
485 "uses group;"
486 "uses mod2:rgroup;"
487
488 "leaf lref {"
489 "type leafref {"
490 "path \"/mod2:one-leaf\";"
491 "}"
492 "}"
493
494 "leaf iref {"
495 "type identityref {"
496 "base \"mod2:just-another-identity\";"
497 "}"
498 "}"
499 "}"
500
501 "augment \"/random\" {"
502 "leaf aug-leaf {"
503 "type string;"
504 "}"
505 "}"
506 "}";
507
508 const char *data_xml =
509 "<ice-cream-shop xmlns=\"urn:module\">"
510 "<employees>"
511 "<employee>"
512 "<id>0</id>"
513 "<name>John Doe</name>"
514 "<age>28</age>"
515 "</employee>"
516 "<employee>"
517 "<id>1</id>"
518 "<name>Dohn Joe</name>"
519 "<age>20</age>"
520 "</employee>"
521 "</employees>"
522 "</ice-cream-shop>"
523 "<one-leaf xmlns=\"urn:module2\">reference leaf</one-leaf>"
524 "<random xmlns=\"urn:module\">"
525 "<aleaf>string</aleaf>"
526 "<xml-data><anyxml>data</anyxml></xml-data>"
527 "<any-data><data>any data</data></any-data>"
528 "<leaflist>l0</leaflist>"
529 "<leaflist>l1</leaflist>"
530 "<leaflist>l2</leaflist>"
531 "<g1>40</g1>"
532 "<g2>string</g2>"
533 "<aug-leaf>string</aug-leaf>"
534 "<rg1>string</rg1>"
535 "<rg2>string</rg2>"
536 "<lref>reference leaf</lref>"
537 "<iref>random-identity</iref>"
538 "</random>";
539
Michal Vasko3a41dff2020-07-15 14:30:28 +0200540 assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, links_yang, LYS_IN_YANG, NULL));
541 assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, statements_yang, LYS_IN_YANG, NULL));
Michal Vasko60ea6352020-06-29 13:39:39 +0200542
Radek Krejci7931b192020-06-25 17:05:03 +0200543 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
Michal Vasko60ea6352020-06-29 13:39:39 +0200544 assert_ptr_not_equal(st->dt1, NULL);
545
Radek Krejci7931b192020-06-25 17:05:03 +0200546 ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS);
Michal Vasko60ea6352020-06-29 13:39:39 +0200547 assert_int_equal(ret, 0);
548
Radek Krejci7931b192020-06-25 17:05:03 +0200549 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2));
Michal Vasko60ea6352020-06-29 13:39:39 +0200550 assert_ptr_not_equal(st->dt2, NULL);
551
552 check_data_tree(st->dt1, st->dt2);
553}
554
555// static void
556// test_types(void **state)
557// {
558// struct state *st = (*state);
559// int ret;
560//
561// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
562// assert_non_null(ly_ctx_load_module(st->ctx, "types", NULL));
563//
564// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/types.xml", LYD_XML, LYD_OPT_CONFIG);
565// assert_ptr_not_equal(st->dt1, NULL);
566//
567// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
568// assert_int_equal(ret, 0);
569//
570// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
571// assert_ptr_not_equal(st->dt2, NULL);
572//
573// check_data_tree(st->dt1, st->dt2);
574// }
575//
576// static void
577// test_annotations(void **state)
578// {
579// struct state *st = (*state);
580// int ret;
581//
582// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
583// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
584//
585// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/annotations.xml", LYD_XML, LYD_OPT_CONFIG);
586// assert_ptr_not_equal(st->dt1, NULL);
587//
588// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
589// assert_int_equal(ret, 0);
590//
591// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
592// assert_ptr_not_equal(st->dt2, NULL);
593//
594// check_data_tree(st->dt1, st->dt2);
595// }
596//
597// static void
598// test_similar_annot_names(void **state)
599// {
600// struct state *st = (*state);
601// int ret;
602//
603// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
604// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
605//
606// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/similar-annot-names.xml", LYD_XML, LYD_OPT_CONFIG);
607// assert_ptr_not_equal(st->dt1, NULL);
608//
609// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
610// assert_int_equal(ret, 0);
611//
612// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
613// assert_ptr_not_equal(st->dt2, NULL);
614//
615// check_data_tree(st->dt1, st->dt2);
616// }
617//
618// static void
619// test_many_child_annot(void **state)
620// {
621// struct state *st = (*state);
622// int ret;
623//
624// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
625// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
626//
627// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/many-childs-annot.xml", LYD_XML, LYD_OPT_CONFIG);
628// assert_ptr_not_equal(st->dt1, NULL);
629//
630// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
631// assert_int_equal(ret, 0);
632//
633// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
634// assert_ptr_not_equal(st->dt2, NULL);
635//
636// check_data_tree(st->dt1, st->dt2);
637// }
638//
639// static void
640// test_union(void **state)
641// {
642// struct state *st = (*state);
643// int ret;
644//
645// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
646// assert_non_null(ly_ctx_load_module(st->ctx, "union", NULL));
647//
648// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/union.xml", LYD_XML, LYD_OPT_CONFIG);
649// assert_ptr_not_equal(st->dt1, NULL);
650//
651// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
652// assert_int_equal(ret, 0);
653//
654// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
655// assert_ptr_not_equal(st->dt2, NULL);
656//
657// check_data_tree(st->dt1, st->dt2);
658// }
659//
660// static void
661// test_union2(void **state)
662// {
663// struct state *st = (*state);
664// int ret;
665//
666// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
667// assert_non_null(ly_ctx_load_module(st->ctx, "statements", NULL));
668//
669// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/union2.xml", LYD_XML, LYD_OPT_CONFIG);
670// assert_ptr_not_equal(st->dt1, NULL);
671//
672// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
673// assert_int_equal(ret, 0);
674//
675// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
676// assert_ptr_not_equal(st->dt2, NULL);
677//
678// check_data_tree(st->dt1, st->dt2);
679// }
680//
681// static void
682// test_collisions(void **state)
683// {
684// struct state *st = (*state);
685// int ret;
686//
687// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
688// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
689//
690// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/collisions.xml", LYD_XML, LYD_OPT_CONFIG);
691// assert_ptr_not_equal(st->dt1, NULL);
692//
693// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
694// assert_int_equal(ret, 0);
695//
696// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
697// assert_ptr_not_equal(st->dt2, NULL);
698//
699// check_data_tree(st->dt1, st->dt2);
700// }
701//
702// static void
703// test_anydata(void **state)
704// {
705// struct state *st = (*state);
706// const struct lys_module *mod;
707// int ret;
708// const char *test_anydata =
709// "module test-anydata {"
710// " namespace \"urn:test-anydata\";"
711// " prefix ya;"
712// ""
713// " container cont {"
714// " anydata ntf;"
715// " }"
716// "}";
717//
718// assert_non_null(ly_ctx_load_module(st->ctx, "ietf-netconf-notifications", NULL));
719//
720// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL);
721// assert_ptr_not_equal(st->dt1, NULL);
722//
723// /* get notification in LYB format to set as anydata content */
724// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
725// assert_int_equal(ret, 0);
726//
727// lyd_free_withsiblings(st->dt1);
728// st->dt1 = NULL;
729//
730// /* now comes the real test, test anydata */
731// mod = lys_parse_mem(st->ctx, test_anydata, LYS_YANG);
732// assert_non_null(mod);
733//
734// st->dt1 = lyd_new(NULL, mod, "cont");
735// assert_non_null(st->dt1);
736//
737// assert_non_null(lyd_new_anydata(st->dt1, NULL, "ntf", st->mem, LYD_ANYDATA_LYBD));
738// st->mem = NULL;
739//
740// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
741// assert_int_equal(ret, 0);
742//
743// ret = lyd_validate(&st->dt1, LYD_OPT_CONFIG, NULL);
744// assert_int_equal(ret, 0);
745//
746// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
747// assert_ptr_not_equal(st->dt2, NULL);
748//
749// check_data_tree(st->dt1, st->dt2);
750//
751// /* and also test the embedded notification itself */
752// free(st->mem);
753// ret = lyd_lyb_data_length(((struct lyd_node_anydata *)st->dt1->child)->value.mem);
754// st->mem = malloc(ret);
755// memcpy(st->mem, ((struct lyd_node_anydata *)st->dt1->child)->value.mem, ret);
756//
757// lyd_free_withsiblings(st->dt2);
758// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_NOTIF | LYD_OPT_STRICT | LYD_OPT_NOEXTDEPS, NULL);
759// assert_ptr_not_equal(st->dt2, NULL);
760//
761// /* parse the JSON again for this comparison */
762// lyd_free_withsiblings(st->dt1);
763// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL);
764// assert_ptr_not_equal(st->dt1, NULL);
765//
766// check_data_tree(st->dt1, st->dt2);
767// }
768//
769// static void
770// test_submodule_feature(void **state)
771// {
772// struct state *st = (*state);
773// const struct lys_module *mod;
774// int ret;
775//
776// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
777// mod = ly_ctx_load_module(st->ctx, "feature-submodule-main", NULL);
778// assert_non_null(mod);
779// assert_int_equal(lys_features_enable(mod, "test-submodule-feature"), 0);
780//
781// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/test-submodule-feature.json", LYD_JSON, LYD_OPT_CONFIG);
782// assert_ptr_not_equal(st->dt1, NULL);
783//
784// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
785// assert_int_equal(ret, 0);
786//
787// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
788// assert_ptr_not_equal(st->dt2, NULL);
789//
790// check_data_tree(st->dt1, st->dt2);
791// }
792//
793// static void
794// test_coliding_augments(void **state)
795// {
796// struct state *st = (*state);
797// int ret;
798//
799// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
800// assert_non_null(ly_ctx_load_module(st->ctx, "augment-target", NULL));
801// assert_non_null(ly_ctx_load_module(st->ctx, "augment0", NULL));
802// assert_non_null(ly_ctx_load_module(st->ctx, "augment1", NULL));
803//
804// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/augment.xml", LYD_XML, LYD_OPT_CONFIG);
805// assert_ptr_not_equal(st->dt1, NULL);
806//
807// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
808// assert_int_equal(ret, 0);
809//
810// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
811// assert_ptr_not_equal(st->dt2, NULL);
812//
813// check_data_tree(st->dt1, st->dt2);
814// }
815//
816// static void
817// test_leafrefs(void **state)
818// {
819// struct state *st = (*state);
820// int ret;
821//
822// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
823// assert_non_null(ly_ctx_load_module(st->ctx, "leafrefs2", NULL));
824//
825// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/leafrefs2.json", LYD_JSON, LYD_OPT_CONFIG | LYD_OPT_STRICT);
826// assert_ptr_not_equal(st->dt1, NULL);
827//
828// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
829// assert_int_equal(ret, 0);
830//
831// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
832// assert_ptr_not_equal(st->dt2, NULL);
833//
834// check_data_tree(st->dt1, st->dt2);
835// }
836
837int
838main(void)
839{
840 const struct CMUnitTest tests[] = {
841 cmocka_unit_test_setup_teardown(test_ietf_interfaces, setup_f, teardown_f),
842 cmocka_unit_test_setup_teardown(test_origin, setup_f, teardown_f),
843 cmocka_unit_test_setup_teardown(test_statements, setup_f, teardown_f),
844 /*cmocka_unit_test_setup_teardown(test_types, setup_f, teardown_f),
845 cmocka_unit_test_setup_teardown(test_annotations, setup_f, teardown_f),
846 cmocka_unit_test_setup_teardown(test_similar_annot_names, setup_f, teardown_f),
847 cmocka_unit_test_setup_teardown(test_many_child_annot, setup_f, teardown_f),
848 cmocka_unit_test_setup_teardown(test_union, setup_f, teardown_f),
849 cmocka_unit_test_setup_teardown(test_union2, setup_f, teardown_f),
850 cmocka_unit_test_setup_teardown(test_collisions, setup_f, teardown_f),
851 cmocka_unit_test_setup_teardown(test_anydata, setup_f, teardown_f),
852 cmocka_unit_test_setup_teardown(test_submodule_feature, setup_f, teardown_f),
853 cmocka_unit_test_setup_teardown(test_coliding_augments, setup_f, teardown_f),
854 cmocka_unit_test_setup_teardown(test_leafrefs, setup_f, teardown_f),*/
855 };
856
857 return cmocka_run_group_tests(tests, NULL, NULL);
858}