blob: e24ba1bdf08e03f79e9628825796388da50d74aa [file] [log] [blame]
Radek Krejci1a4a1c82016-09-14 16:07:25 +02001/**
Radek Krejci9e68d872016-09-15 14:50:48 +02002 * \file test_conformance.c
Radek Krejci1a4a1c82016-09-14 16:07:25 +02003 * \author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejci9e68d872016-09-15 14:50:48 +02004 * \brief libyang tests - setting up modules as imported or implemented
Radek Krejci1a4a1c82016-09-14 16:07:25 +02005 *
6 * Copyright (c) 2015 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 <errno.h>
16#include <fcntl.h>
17#include <pthread.h>
18#include <setjmp.h>
19#include <stdarg.h>
20#include <stddef.h>
21#include <stdlib.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25
26#include <cmocka.h>
27
Jan Kundrátfd7a5c72017-10-26 17:45:06 +020028#include "libyang.h"
29#include "tests/config.h"
Radek Krejci1a4a1c82016-09-14 16:07:25 +020030
31#define SCHEMA_FOLDER_YIN TESTS_DIR"/schema/yin/conformance"
32#define SCHEMA_FOLDER_YANG TESTS_DIR"/schema/yang/conformance"
33
34static int
35setup_ctx(void **state)
36{
Radek Krejcidd3263a2017-07-15 11:50:09 +020037 *state = ly_ctx_new(NULL, 0);
Radek Krejci1a4a1c82016-09-14 16:07:25 +020038 if (!*state) {
39 return -1;
40 }
41 return 0;
42}
43
44static int
45teardown_ctx(void **state)
46{
47 ly_ctx_destroy(*state, NULL);
48 return 0;
49}
50
51static void
52test_implemented1_yin(void **state)
53{
54 struct ly_ctx *ctx = *state;
55 const struct lys_module *a, *b, *b2, *c, *c2;
56
57 ly_ctx_set_searchdir(ctx, SCHEMA_FOLDER_YIN);
58
59 /* loads a.yin (impl), b@2015-01-01.yin (impl by augment) and c@2015-03-03.yin (imp) */
60 a = lys_parse_path(ctx, SCHEMA_FOLDER_YIN"/a.yin", LYS_IN_YIN);
61 assert_ptr_not_equal(a, NULL);
62 assert_int_equal(a->implemented, 1);
63
Radek Krejcidfb00d62017-09-06 09:39:35 +020064 b = ly_ctx_get_module(ctx, "b", NULL, 1);
Radek Krejci1a4a1c82016-09-14 16:07:25 +020065 assert_ptr_not_equal(b, NULL);
66 assert_int_equal(b->implemented, 1);
67
Radek Krejcidfb00d62017-09-06 09:39:35 +020068 c = ly_ctx_get_module(ctx, "c", NULL, 0);
Radek Krejci1a4a1c82016-09-14 16:07:25 +020069 assert_ptr_not_equal(c, NULL);
70 assert_int_equal(c->implemented, 0);
71
72 /* another b cannot be loaded, since it is already implemented */
73 b2 = lys_parse_path(ctx, SCHEMA_FOLDER_YIN"/b@2015-04-04.yin", LYS_IN_YIN);
74 assert_ptr_equal(b2, NULL);
75 assert_int_equal(ly_errno, LY_EINVAL);
76 assert_string_equal(ly_errmsg(), "Module \"b\" parsing failed.");
77
78 /* older c can be loaded and it will be marked as implemented */
79 c2 = lys_parse_path(ctx, SCHEMA_FOLDER_YIN"/c@2015-01-01.yin", LYS_IN_YIN);
80 assert_ptr_not_equal(c2, NULL);
81 assert_int_equal(c2->implemented, 1);
82 assert_ptr_not_equal(c, c2);
83}
84
85static void
Pavol Vican5c186c22016-09-27 10:46:14 +020086test_implemented1_yang(void **state)
87{
88 struct ly_ctx *ctx = *state;
89 const struct lys_module *a, *b, *b2, *c, *c2;
90
91 ly_ctx_set_searchdir(ctx, SCHEMA_FOLDER_YANG);
92
93 /* loads a.yang (impl), b@2015-01-01.yang (impl by augment) and c@2015-03-03.yang (imp) */
94 a = lys_parse_path(ctx, SCHEMA_FOLDER_YANG"/a.yang", LYS_IN_YANG);
95 assert_ptr_not_equal(a, NULL);
96 assert_int_equal(a->implemented, 1);
97
Radek Krejcidfb00d62017-09-06 09:39:35 +020098 b = ly_ctx_get_module(ctx, "b", NULL, 1);
Pavol Vican5c186c22016-09-27 10:46:14 +020099 assert_ptr_not_equal(b, NULL);
100 assert_int_equal(b->implemented, 1);
101
Radek Krejcidfb00d62017-09-06 09:39:35 +0200102 c = ly_ctx_get_module(ctx, "c", NULL, 0);
Pavol Vican5c186c22016-09-27 10:46:14 +0200103 assert_ptr_not_equal(c, NULL);
104 assert_int_equal(c->implemented, 0);
105
106 /* another b cannot be loaded, since it is already implemented */
107 b2 = lys_parse_path(ctx, SCHEMA_FOLDER_YANG"/b@2015-04-04.yang", LYS_IN_YANG);
108 assert_ptr_equal(b2, NULL);
109 assert_int_equal(ly_errno, LY_EINVAL);
110 assert_string_equal(ly_errmsg(), "Module \"b\" parsing failed.");
111
112 /* older c can be loaded and it will be marked as implemented */
113 c2 = lys_parse_path(ctx, SCHEMA_FOLDER_YANG"/c@2015-01-01.yang", LYS_IN_YANG);
114 assert_ptr_not_equal(c2, NULL);
115 assert_int_equal(c2->implemented, 1);
116 assert_ptr_not_equal(c, c2);
117}
118
119static void
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200120test_implemented2_yin(void **state)
121{
122 struct ly_ctx *ctx = *state;
Michal Vaskoa51f3ad2017-05-23 10:54:37 +0200123 const struct lys_module *a, *b2;
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200124
125 ly_ctx_set_searchdir(ctx, SCHEMA_FOLDER_YIN);
126
127 /* load the newest b first, it is implemented */
128 b2 = ly_ctx_load_module(ctx, "b", "2015-04-04");
129 assert_ptr_not_equal(b2, NULL);
130 assert_int_equal(b2->implemented, 1);
131
Michal Vaskoa51f3ad2017-05-23 10:54:37 +0200132 /* loads a.yin (impl), b@2015-04-04 is augmented by a, but cannot be implemented */
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200133 a = lys_parse_path(ctx, SCHEMA_FOLDER_YIN"/a.yin", LYS_IN_YIN);
Michal Vaskoa51f3ad2017-05-23 10:54:37 +0200134 assert_ptr_equal(a, NULL);
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200135}
136
137static void
Pavol Vican5c186c22016-09-27 10:46:14 +0200138test_implemented2_yang(void **state)
139{
140 struct ly_ctx *ctx = *state;
Michal Vaskoa51f3ad2017-05-23 10:54:37 +0200141 const struct lys_module *a, *b2;
Pavol Vican5c186c22016-09-27 10:46:14 +0200142
143 ly_ctx_set_searchdir(ctx, SCHEMA_FOLDER_YANG);
144
145 /* load the newest b first, it is implemented */
146 b2 = ly_ctx_load_module(ctx, "b", "2015-04-04");
147 assert_ptr_not_equal(b2, NULL);
148 assert_int_equal(b2->implemented, 1);
149
Michal Vaskoa51f3ad2017-05-23 10:54:37 +0200150 /* loads a.yin (impl), b@2015-04-04 is augmented by a, but cannot be implemented */
Pavol Vican5c186c22016-09-27 10:46:14 +0200151 a = lys_parse_path(ctx, SCHEMA_FOLDER_YANG"/a.yang", LYS_IN_YANG);
Michal Vaskoa51f3ad2017-05-23 10:54:37 +0200152 assert_ptr_equal(a, NULL);
Pavol Vican5c186c22016-09-27 10:46:14 +0200153}
154
155static void
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200156test_implemented_info_yin(void **state)
157{
158 struct ly_ctx *ctx = *state;
159 struct lyd_node *info;
160 const struct lys_module *a;
161 char *data;
Radek Krejcidfb00d62017-09-06 09:39:35 +0200162 const char *template = "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">\n"
163" <modules>\n"
164" <module>\n"
165" <id>0</id>\n"
166" <name>ietf-yang-metadata</name>\n"
167" <revision>2016-08-05</revision>\n"
168" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-metadata</namespace>\n"
169" <conformance-type>import</conformance-type>\n"
170" </module>\n"
171" <module>\n"
172" <id>1</id>\n"
173" <name>yang</name>\n"
174" <revision>2017-02-20</revision>\n"
175" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"
176" <conformance-type>implement</conformance-type>\n"
177" </module>\n"
178" <module>\n"
179" <id>2</id>\n"
180" <name>ietf-inet-types</name>\n"
181" <revision>2013-07-15</revision>\n"
182" <namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</namespace>\n"
183" <conformance-type>import</conformance-type>\n"
184" </module>\n"
185" <module>\n"
186" <id>3</id>\n"
187" <name>ietf-yang-types</name>\n"
188" <revision>2013-07-15</revision>\n"
189" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>\n"
190" <conformance-type>import</conformance-type>\n"
191" </module>\n"
192" <module>\n"
193" <id>4</id>\n"
194" <name>ietf-datastores</name>\n"
195" <revision>2017-08-17</revision>\n"
196" <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>\n"
Radek Krejcib39dfce2017-09-12 14:28:00 +0200197" <conformance-type>import</conformance-type>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200198" </module>\n"
199" <module>\n"
200" <id>5</id>\n"
201" <name>ietf-yang-library</name>\n"
202" <revision>2017-08-17</revision>\n"
203" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>\n"
204" <conformance-type>implement</conformance-type>\n"
205" </module>\n"
206" <module>\n"
207" <id>6</id>\n"
208" <name>b</name>\n"
209" <revision>2015-01-01</revision>\n"
210" <schema>file://"SCHEMA_FOLDER_YIN"/b@2015-01-01.yin</schema>\n"
211" <namespace>urn:example:b</namespace>\n"
212" <conformance-type>implement</conformance-type>\n"
213" </module>\n"
214" <module>\n"
215" <id>7</id>\n"
216" <name>c</name>\n"
217" <revision>2015-03-03</revision>\n"
218" <schema>file://"SCHEMA_FOLDER_YIN"/c@2015-03-03.yin</schema>\n"
219" <namespace>urn:example:c</namespace>\n"
220" <conformance-type>import</conformance-type>\n"
221" </module>\n"
222" <module>\n"
223" <id>8</id>\n"
224" <name>a</name>\n"
225" <revision>2015-01-01</revision>\n"
226" <schema>file://"SCHEMA_FOLDER_YIN"/a.yin</schema>\n"
227" <namespace>urn:example:a</namespace>\n"
228" <feature>foo</feature>\n"
229" <conformance-type>implement</conformance-type>\n"
230" </module>\n"
231" </modules>\n"
232" <module-sets>\n"
233" <module-set>\n"
234" <id>complete</id>\n"
235" <module>0</module>\n"
236" <module>1</module>\n"
237" <module>2</module>\n"
238" <module>3</module>\n"
239" <module>4</module>\n"
240" <module>5</module>\n"
241" <module>6</module>\n"
242" <module>7</module>\n"
243" <module>8</module>\n"
244" </module-set>\n"
245" </module-sets>\n"
246" <checksum>10</checksum>\n"
247"</yang-library>\n"
248"<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">\n"
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200249" <module>\n"
Radek Krejci532e5e92017-02-22 12:59:24 +0100250" <name>ietf-yang-metadata</name>\n"
251" <revision>2016-08-05</revision>\n"
252" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-metadata</namespace>\n"
253" <conformance-type>import</conformance-type>\n"
254" </module>\n"
255" <module>\n"
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200256" <name>yang</name>\n"
Radek Krejci532e5e92017-02-22 12:59:24 +0100257" <revision>2017-02-20</revision>\n"
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200258" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"
259" <conformance-type>implement</conformance-type>\n"
260" </module>\n"
261" <module>\n"
262" <name>ietf-inet-types</name>\n"
263" <revision>2013-07-15</revision>\n"
264" <namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</namespace>\n"
265" <conformance-type>import</conformance-type>\n"
266" </module>\n"
267" <module>\n"
268" <name>ietf-yang-types</name>\n"
269" <revision>2013-07-15</revision>\n"
270" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>\n"
271" <conformance-type>import</conformance-type>\n"
272" </module>\n"
273" <module>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200274" <name>ietf-datastores</name>\n"
275" <revision>2017-08-17</revision>\n"
276" <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>\n"
Radek Krejcib39dfce2017-09-12 14:28:00 +0200277" <conformance-type>import</conformance-type>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200278" </module>\n"
279" <module>\n"
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200280" <name>ietf-yang-library</name>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200281" <revision>2017-08-17</revision>\n"
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200282" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>\n"
283" <conformance-type>implement</conformance-type>\n"
284" </module>\n"
285" <module>\n"
286" <name>b</name>\n"
287" <revision>2015-01-01</revision>\n"
288" <schema>file://"SCHEMA_FOLDER_YIN"/b@2015-01-01.yin</schema>\n"
289" <namespace>urn:example:b</namespace>\n"
290" <conformance-type>implement</conformance-type>\n"
291" </module>\n"
292" <module>\n"
293" <name>c</name>\n"
294" <revision>2015-03-03</revision>\n"
295" <schema>file://"SCHEMA_FOLDER_YIN"/c@2015-03-03.yin</schema>\n"
296" <namespace>urn:example:c</namespace>\n"
297" <conformance-type>import</conformance-type>\n"
298" </module>\n"
299" <module>\n"
300" <name>a</name>\n"
301" <revision>2015-01-01</revision>\n"
302" <schema>file://"SCHEMA_FOLDER_YIN"/a.yin</schema>\n"
303" <namespace>urn:example:a</namespace>\n"
304" <feature>foo</feature>\n"
305" <conformance-type>implement</conformance-type>\n"
306" </module>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200307" <module-set-id>10</module-set-id>\n"
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200308"</modules-state>\n";
309
310 ly_ctx_set_searchdir(ctx, SCHEMA_FOLDER_YIN);
311
312 /* loads a.yin (impl), b@2015-01-01.yin (impl by augment) and c@2015-03-03.yin (imp) */
313 assert_ptr_not_equal((a = lys_parse_path(ctx, SCHEMA_FOLDER_YIN"/a.yin", LYS_IN_YIN)), NULL);
314 assert_int_equal(lys_features_enable(a, "foo"), 0);
315
316 /* get yang-library data */
317 info = ly_ctx_info(ctx);
318 assert_ptr_not_equal(info, NULL);
319
Radek Krejcidfb00d62017-09-06 09:39:35 +0200320 lyd_print_mem(&data, info, LYD_XML, LYP_FORMAT | LYP_WITHSIBLINGS);
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200321 lyd_free_withsiblings(info);
322 assert_string_equal(data, template);
323 free(data);
324}
325
Pavol Vican5c186c22016-09-27 10:46:14 +0200326static void
327test_implemented_info_yang(void **state)
328{
329 struct ly_ctx *ctx = *state;
330 struct lyd_node *info;
331 const struct lys_module *a;
332 char *data;
Radek Krejcidfb00d62017-09-06 09:39:35 +0200333 const char *template = "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">\n"
334" <modules>\n"
335" <module>\n"
336" <id>0</id>\n"
337" <name>ietf-yang-metadata</name>\n"
338" <revision>2016-08-05</revision>\n"
339" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-metadata</namespace>\n"
340" <conformance-type>import</conformance-type>\n"
341" </module>\n"
342" <module>\n"
343" <id>1</id>\n"
344" <name>yang</name>\n"
345" <revision>2017-02-20</revision>\n"
346" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"
347" <conformance-type>implement</conformance-type>\n"
348" </module>\n"
349" <module>\n"
350" <id>2</id>\n"
351" <name>ietf-inet-types</name>\n"
352" <revision>2013-07-15</revision>\n"
353" <namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</namespace>\n"
354" <conformance-type>import</conformance-type>\n"
355" </module>\n"
356" <module>\n"
357" <id>3</id>\n"
358" <name>ietf-yang-types</name>\n"
359" <revision>2013-07-15</revision>\n"
360" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>\n"
361" <conformance-type>import</conformance-type>\n"
362" </module>\n"
363" <module>\n"
364" <id>4</id>\n"
365" <name>ietf-datastores</name>\n"
366" <revision>2017-08-17</revision>\n"
367" <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>\n"
Radek Krejcib39dfce2017-09-12 14:28:00 +0200368" <conformance-type>import</conformance-type>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200369" </module>\n"
370" <module>\n"
371" <id>5</id>\n"
372" <name>ietf-yang-library</name>\n"
373" <revision>2017-08-17</revision>\n"
374" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>\n"
375" <conformance-type>implement</conformance-type>\n"
376" </module>\n"
377" <module>\n"
378" <id>6</id>\n"
379" <name>b</name>\n"
380" <revision>2015-01-01</revision>\n"
381" <schema>file://"SCHEMA_FOLDER_YANG"/b@2015-01-01.yang</schema>\n"
382" <namespace>urn:example:b</namespace>\n"
383" <conformance-type>implement</conformance-type>\n"
384" </module>\n"
385" <module>\n"
386" <id>7</id>\n"
387" <name>c</name>\n"
388" <revision>2015-03-03</revision>\n"
389" <schema>file://"SCHEMA_FOLDER_YANG"/c@2015-03-03.yang</schema>\n"
390" <namespace>urn:example:c</namespace>\n"
391" <conformance-type>import</conformance-type>\n"
392" </module>\n"
393" <module>\n"
394" <id>8</id>\n"
395" <name>a</name>\n"
396" <revision>2015-01-01</revision>\n"
397" <schema>file://"SCHEMA_FOLDER_YANG"/a.yang</schema>\n"
398" <namespace>urn:example:a</namespace>\n"
399" <feature>foo</feature>\n"
400" <conformance-type>implement</conformance-type>\n"
401" </module>\n"
402" </modules>\n"
403" <module-sets>\n"
404" <module-set>\n"
405" <id>complete</id>\n"
406" <module>0</module>\n"
407" <module>1</module>\n"
408" <module>2</module>\n"
409" <module>3</module>\n"
410" <module>4</module>\n"
411" <module>5</module>\n"
412" <module>6</module>\n"
413" <module>7</module>\n"
414" <module>8</module>\n"
415" </module-set>\n"
416" </module-sets>\n"
417" <checksum>10</checksum>\n"
418"</yang-library>\n"
419"<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">\n"
Pavol Vican5c186c22016-09-27 10:46:14 +0200420" <module>\n"
Radek Krejci532e5e92017-02-22 12:59:24 +0100421" <name>ietf-yang-metadata</name>\n"
422" <revision>2016-08-05</revision>\n"
423" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-metadata</namespace>\n"
424" <conformance-type>import</conformance-type>\n"
425" </module>\n"
426" <module>\n"
Pavol Vican5c186c22016-09-27 10:46:14 +0200427" <name>yang</name>\n"
Radek Krejci532e5e92017-02-22 12:59:24 +0100428" <revision>2017-02-20</revision>\n"
Pavol Vican5c186c22016-09-27 10:46:14 +0200429" <namespace>urn:ietf:params:xml:ns:yang:1</namespace>\n"
430" <conformance-type>implement</conformance-type>\n"
431" </module>\n"
432" <module>\n"
433" <name>ietf-inet-types</name>\n"
434" <revision>2013-07-15</revision>\n"
435" <namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</namespace>\n"
436" <conformance-type>import</conformance-type>\n"
437" </module>\n"
438" <module>\n"
439" <name>ietf-yang-types</name>\n"
440" <revision>2013-07-15</revision>\n"
441" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>\n"
442" <conformance-type>import</conformance-type>\n"
443" </module>\n"
444" <module>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200445" <name>ietf-datastores</name>\n"
446" <revision>2017-08-17</revision>\n"
447" <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>\n"
Radek Krejcib39dfce2017-09-12 14:28:00 +0200448" <conformance-type>import</conformance-type>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200449" </module>\n"
450" <module>\n"
Pavol Vican5c186c22016-09-27 10:46:14 +0200451" <name>ietf-yang-library</name>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200452" <revision>2017-08-17</revision>\n"
Pavol Vican5c186c22016-09-27 10:46:14 +0200453" <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>\n"
454" <conformance-type>implement</conformance-type>\n"
455" </module>\n"
456" <module>\n"
457" <name>b</name>\n"
458" <revision>2015-01-01</revision>\n"
459" <schema>file://"SCHEMA_FOLDER_YANG"/b@2015-01-01.yang</schema>\n"
460" <namespace>urn:example:b</namespace>\n"
461" <conformance-type>implement</conformance-type>\n"
462" </module>\n"
463" <module>\n"
464" <name>c</name>\n"
465" <revision>2015-03-03</revision>\n"
466" <schema>file://"SCHEMA_FOLDER_YANG"/c@2015-03-03.yang</schema>\n"
467" <namespace>urn:example:c</namespace>\n"
468" <conformance-type>import</conformance-type>\n"
469" </module>\n"
470" <module>\n"
471" <name>a</name>\n"
472" <revision>2015-01-01</revision>\n"
473" <schema>file://"SCHEMA_FOLDER_YANG"/a.yang</schema>\n"
474" <namespace>urn:example:a</namespace>\n"
475" <feature>foo</feature>\n"
476" <conformance-type>implement</conformance-type>\n"
477" </module>\n"
Radek Krejcidfb00d62017-09-06 09:39:35 +0200478" <module-set-id>10</module-set-id>\n"
Pavol Vican5c186c22016-09-27 10:46:14 +0200479"</modules-state>\n";
480
481 ly_ctx_set_searchdir(ctx, SCHEMA_FOLDER_YANG);
482
483 /* loads a.yang (impl), b@2015-01-01.yang (impl by augment) and c@2015-03-03.yang (imp) */
484 assert_ptr_not_equal((a = lys_parse_path(ctx, SCHEMA_FOLDER_YANG"/a.yang", LYS_IN_YANG)), NULL);
485 assert_int_equal(lys_features_enable(a, "foo"), 0);
486
487 /* get yang-library data */
488 info = ly_ctx_info(ctx);
489 assert_ptr_not_equal(info, NULL);
490
Radek Krejcidfb00d62017-09-06 09:39:35 +0200491 lyd_print_mem(&data, info, LYD_XML, LYP_FORMAT | LYP_WITHSIBLINGS);
Pavol Vican5c186c22016-09-27 10:46:14 +0200492 lyd_free_withsiblings(info);
493 assert_string_equal(data, template);
494 free(data);
495}
496
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200497int
498main(void)
499{
500 const struct CMUnitTest cmut[] = {
501 cmocka_unit_test_setup_teardown(test_implemented1_yin, setup_ctx, teardown_ctx),
Pavol Vican5c186c22016-09-27 10:46:14 +0200502 cmocka_unit_test_setup_teardown(test_implemented1_yang, setup_ctx, teardown_ctx),
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200503 cmocka_unit_test_setup_teardown(test_implemented2_yin, setup_ctx, teardown_ctx),
Pavol Vican5c186c22016-09-27 10:46:14 +0200504 cmocka_unit_test_setup_teardown(test_implemented2_yang, setup_ctx, teardown_ctx),
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200505 cmocka_unit_test_setup_teardown(test_implemented_info_yin, setup_ctx, teardown_ctx),
Pavol Vican5c186c22016-09-27 10:46:14 +0200506 cmocka_unit_test_setup_teardown(test_implemented_info_yang, setup_ctx, teardown_ctx),
Radek Krejci1a4a1c82016-09-14 16:07:25 +0200507 };
508
509 return cmocka_run_group_tests(cmut, NULL, NULL);
510}