blob: 779f746b9d567d8da1da551bd2a16e67afb648c1 [file] [log] [blame]
David Sedlákb1ce3f82019-06-05 14:37:26 +02001/**
2 * @file test_parser_yin.c
3 * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
4 * @brief unit tests for functions from parser_yin.c
5 *
6 * Copyright (c) 2015 - 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
David Sedlák3b4db242018-10-19 16:11:01 +020015#include <stdarg.h>
16#include <stddef.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20#include <stdio.h>
21#include <string.h>
David Sedlák79e50cb2019-06-05 16:33:09 +020022#include <stdbool.h>
David Sedlák3b4db242018-10-19 16:11:01 +020023
David Sedlákecf5eb82019-06-03 14:12:44 +020024#include "../../src/common.h"
25#include "../../src/tree_schema.h"
26#include "../../src/tree_schema_internal.h"
27#include "../../src/parser_yin.h"
David Sedlák8f5bce02019-06-03 16:41:08 +020028#include "../../src/xml.h"
David Sedlák3b4db242018-10-19 16:11:01 +020029
David Sedlák68a1af12019-03-08 13:46:54 +010030struct state {
David Sedlák3b4db242018-10-19 16:11:01 +020031 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010032 struct lys_module *mod;
David Sedlák8f5bce02019-06-03 16:41:08 +020033 struct lyxml_context *xml_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020034 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010035};
David Sedlák872c7b42018-10-26 13:15:20 +020036
David Sedlák79e50cb2019-06-05 16:33:09 +020037#define BUFSIZE 1024
38char logbuf[BUFSIZE] = {0};
39int store = -1; /* negative for infinite logging, positive for limited logging */
40
41/* set to 0 to printing error messages to stderr instead of checking them in code */
42#define ENABLE_LOGGER_CHECKING 1
43
44#if ENABLE_LOGGER_CHECKING
45static void
46logger(LY_LOG_LEVEL level, const char *msg, const char *path)
47{
48 (void) level; /* unused */
49 if (store) {
50 if (path && path[0]) {
51 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
52 } else {
53 strncpy(logbuf, msg, BUFSIZE - 1);
54 }
55 if (store > 0) {
56 --store;
57 }
58 }
59}
60#endif
61
62#if ENABLE_LOGGER_CHECKING
63# define logbuf_assert(str) assert_string_equal(logbuf, str)
64#else
65# define logbuf_assert(str)
66#endif
67
68#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
69 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
70 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
71 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
72 CLEANUP
73
74
David Sedlák68a1af12019-03-08 13:46:54 +010075static int
76setup_f(void **state)
77{
78 struct state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +020079
David Sedlák79e50cb2019-06-05 16:33:09 +020080#if ENABLE_LOGGER_CHECKING
81 /* setup logger */
82 ly_set_log_clb(logger, 1);
83#endif
84
David Sedlák68a1af12019-03-08 13:46:54 +010085 /* allocate state variable */
86 (*state) = st = calloc(1, sizeof(*st));
87 if (!st) {
88 fprintf(stderr, "Memmory allocation failed");
89 return EXIT_FAILURE;
90 }
David Sedlák872c7b42018-10-26 13:15:20 +020091
David Sedlák68a1af12019-03-08 13:46:54 +010092 /* create new libyang context */
93 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +020094
David Sedlák68a1af12019-03-08 13:46:54 +010095 /* allocate new module */
96 st->mod = calloc(1, sizeof(*st->mod));
97 st->mod->ctx = st->ctx;
98
David Sedlák8f5bce02019-06-03 16:41:08 +020099 st->xml_ctx = calloc(1, sizeof(struct lys_parser_ctx));
100 st->xml_ctx->ctx = st->ctx;
101 st->xml_ctx->line = 1;
102
David Sedlák68a1af12019-03-08 13:46:54 +0100103 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200104}
105
106static int
David Sedlák68a1af12019-03-08 13:46:54 +0100107teardown_f(void **state)
108{
109 struct state *st = *(struct state **)state;
110
David Sedlák79e50cb2019-06-05 16:33:09 +0200111#if ENABLE_LOGGER_CHECKING
112 /* teardown logger */
113 if (!st->finished_correctly && logbuf[0] != '\0') {
114 fprintf(stderr, "%s\n", logbuf);
115 }
116#endif
117
David Sedlák8f5bce02019-06-03 16:41:08 +0200118 lyxml_context_clear(st->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100119 lys_module_free(st->mod, NULL);
120 ly_ctx_destroy(st->ctx, NULL);
David Sedlák8f5bce02019-06-03 16:41:08 +0200121 free(st->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100122 free(st);
123
124 return EXIT_SUCCESS;
125}
126
David Sedlák392af4f2019-06-04 16:02:42 +0200127static struct state*
128reset_state(void **state)
129{
David Sedlák79e50cb2019-06-05 16:33:09 +0200130 ((struct state *)*state)->finished_correctly = true;
David Sedlák392af4f2019-06-04 16:02:42 +0200131 teardown_f(state);
132 setup_f(state);
133
134 return *state;
135}
136
David Sedlák79e50cb2019-06-05 16:33:09 +0200137void
138logbuf_clean(void)
139{
140 logbuf[0] = '\0';
141}
142
David Sedlák68a1af12019-03-08 13:46:54 +0100143static void
David Sedlák392af4f2019-06-04 16:02:42 +0200144test_yin_parse_module(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100145{
146 LY_ERR ret = LY_SUCCESS;
147 struct state *st = *state;
148
149 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200150 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
151 name=\"example-foo\"\
David Sedlák18730132019-03-15 15:51:34 +0100152 xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
153 xmlns:foo=\"urn:example:foo\"\
154 xmlns:myext=\"urn:example:extensions\">\
David Sedlákcd0c9512019-03-29 13:23:06 +0100155 <namespace uri=\"urn:example:foo\" xmlns:myext=\"urn:example:extensions\"/>\
David Sedláka7406952019-04-05 10:33:07 +0200156 <prefix xmlns:myxt=\"urn:emple:extensions\" value=\"foo\" xmlns:myext=\"urn:example:extensions\"/>\
David Sedlákd9d3a312019-06-04 09:47:10 +0200157 </module>",
David Sedlák68a1af12019-03-08 13:46:54 +0100158 st->mod);
159
160 assert_int_equal(ret, LY_SUCCESS);
161 assert_string_equal(st->mod->parsed->mod->name, "example-foo");
162 assert_string_equal(st->mod->parsed->mod->prefix, "foo");
David Sedlákcd0c9512019-03-29 13:23:06 +0100163 assert_string_equal(st->mod->parsed->mod->ns, "urn:example:foo");
David Sedlák392af4f2019-06-04 16:02:42 +0200164
165 st = reset_state(state);
166 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200167 "<module name=\"example-foo\">\
168 <invalid-tag uri=\"urn:example:foo\"\"/>\
169 </module>",
170 st->mod);
David Sedlák392af4f2019-06-04 16:02:42 +0200171 assert_int_equal(ret, LY_EVALID);
172
173 st = reset_state(state);
174 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200175 "<module>\
David Sedlák57715b12019-06-17 13:05:22 +0200176 </module>",
David Sedlák2b214ac2019-06-06 16:11:03 +0200177 st->mod);
David Sedlák392af4f2019-06-04 16:02:42 +0200178 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200179 logbuf_assert("Missing argument name of a module Line number 1.");
David Sedlák392af4f2019-06-04 16:02:42 +0200180
181 st = reset_state(state);
182 ret = yin_parse_module(st->ctx,
183 "",
184 st->mod);
185 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200186 logbuf_assert("Invalid keyword \"(null)\", expected \"module\" or \"submodule\". Line number 1.");
187 st->finished_correctly = true;
David Sedlák3b4db242018-10-19 16:11:01 +0200188}
189
190static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200191test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200192{
193 (void)state; /* unused */
194
David Sedlák1bccdfa2019-06-17 15:55:27 +0200195 assert_int_equal(yin_match_keyword("anydatax", strlen("anydatax"), 0), YANG_NONE);
196 assert_int_equal(yin_match_keyword("asdasd", strlen("asdasd"), 0), YANG_NONE);
197 assert_int_equal(yin_match_keyword("", 0, 0), YANG_NONE);
198 assert_int_equal(yin_match_keyword("anydata", strlen("anydata"), 0), YANG_ANYDATA);
199 assert_int_equal(yin_match_keyword("anyxml", strlen("anyxml"), 0), YANG_ANYXML);
200 assert_int_equal(yin_match_keyword("argument", strlen("argument"), 0), YANG_ARGUMENT);
201 assert_int_equal(yin_match_keyword("augment", strlen("augment"), 0), YANG_AUGMENT);
202 assert_int_equal(yin_match_keyword("base", strlen("base"), 0), YANG_BASE);
203 assert_int_equal(yin_match_keyword("belongs-to", strlen("belongs-to"), 0), YANG_BELONGS_TO);
204 assert_int_equal(yin_match_keyword("bit", strlen("bit"), 0), YANG_BIT);
205 assert_int_equal(yin_match_keyword("case", strlen("case"), 0), YANG_CASE);
206 assert_int_equal(yin_match_keyword("choice", strlen("choice"), 0), YANG_CHOICE);
207 assert_int_equal(yin_match_keyword("config", strlen("config"), 0), YANG_CONFIG);
208 assert_int_equal(yin_match_keyword("contact", strlen("contact"), 0), YANG_CONTACT);
209 assert_int_equal(yin_match_keyword("container", strlen("container"), 0), YANG_CONTAINER);
210 assert_int_equal(yin_match_keyword("default", strlen("default"), 0), YANG_DEFAULT);
211 assert_int_equal(yin_match_keyword("description", strlen("description"), 0), YANG_DESCRIPTION);
212 assert_int_equal(yin_match_keyword("deviate", strlen("deviate"), 0), YANG_DEVIATE);
213 assert_int_equal(yin_match_keyword("deviation", strlen("deviation"), 0), YANG_DEVIATION);
214 assert_int_equal(yin_match_keyword("enum", strlen("enum"), 0), YANG_ENUM);
215 assert_int_equal(yin_match_keyword("error-app-tag", strlen("error-app-tag"), 0), YANG_ERROR_APP_TAG);
216 assert_int_equal(yin_match_keyword("error-message", strlen("error-message"), 0), YANG_ERROR_MESSAGE);
217 assert_int_equal(yin_match_keyword("extension", strlen("extension"), 0), YANG_EXTENSION);
218 assert_int_equal(yin_match_keyword("feature", strlen("feature"), 0), YANG_FEATURE);
219 assert_int_equal(yin_match_keyword("fraction-digits", strlen("fraction-digits"), 0), YANG_FRACTION_DIGITS);
220 assert_int_equal(yin_match_keyword("grouping", strlen("grouping"), 0), YANG_GROUPING);
221 assert_int_equal(yin_match_keyword("identity", strlen("identity"), 0), YANG_IDENTITY);
222 assert_int_equal(yin_match_keyword("if-feature", strlen("if-feature"), 0), YANG_IF_FEATURE);
223 assert_int_equal(yin_match_keyword("import", strlen("import"), 0), YANG_IMPORT);
224 assert_int_equal(yin_match_keyword("include", strlen("include"), 0), YANG_INCLUDE);
225 assert_int_equal(yin_match_keyword("input", strlen("input"), 0), YANG_INPUT);
226 assert_int_equal(yin_match_keyword("key", strlen("key"), 0), YANG_KEY);
227 assert_int_equal(yin_match_keyword("leaf", strlen("leaf"), 0), YANG_LEAF);
228 assert_int_equal(yin_match_keyword("leaf-list", strlen("leaf-list"), 0), YANG_LEAF_LIST);
229 assert_int_equal(yin_match_keyword("length", strlen("length"), 0), YANG_LENGTH);
230 assert_int_equal(yin_match_keyword("list", strlen("list"), 0), YANG_LIST);
231 assert_int_equal(yin_match_keyword("mandatory", strlen("mandatory"), 0), YANG_MANDATORY);
232 assert_int_equal(yin_match_keyword("max-elements", strlen("max-elements"), 0), YANG_MAX_ELEMENTS);
233 assert_int_equal(yin_match_keyword("min-elements", strlen("min-elements"), 0), YANG_MIN_ELEMENTS);
234 assert_int_equal(yin_match_keyword("modifier", strlen("modifier"), 0), YANG_MODIFIER);
235 assert_int_equal(yin_match_keyword("module", strlen("module"), 0), YANG_MODULE);
236 assert_int_equal(yin_match_keyword("must", strlen("must"), 0), YANG_MUST);
237 assert_int_equal(yin_match_keyword("namespace", strlen("namespace"), 0), YANG_NAMESPACE);
238 assert_int_equal(yin_match_keyword("notification", strlen("notification"), 0), YANG_NOTIFICATION);
239 assert_int_equal(yin_match_keyword("ordered-by", strlen("ordered-by"), 0), YANG_ORDERED_BY);
240 assert_int_equal(yin_match_keyword("organization", strlen("organization"), 0), YANG_ORGANIZATION);
241 assert_int_equal(yin_match_keyword("output", strlen("output"), 0), YANG_OUTPUT);
242 assert_int_equal(yin_match_keyword("path", strlen("path"), 0), YANG_PATH);
243 assert_int_equal(yin_match_keyword("pattern", strlen("pattern"), 0), YANG_PATTERN);
244 assert_int_equal(yin_match_keyword("position", strlen("position"), 0), YANG_POSITION);
245 assert_int_equal(yin_match_keyword("prefix", strlen("prefix"), 0), YANG_PREFIX);
246 assert_int_equal(yin_match_keyword("presence", strlen("presence"), 0), YANG_PRESENCE);
247 assert_int_equal(yin_match_keyword("range", strlen("range"), 0), YANG_RANGE);
248 assert_int_equal(yin_match_keyword("reference", strlen("reference"), 0), YANG_REFERENCE);
249 assert_int_equal(yin_match_keyword("refine", strlen("refine"), 0), YANG_REFINE);
250 assert_int_equal(yin_match_keyword("require-instance", strlen("require-instance"), 0), YANG_REQUIRE_INSTANCE);
251 assert_int_equal(yin_match_keyword("revision", strlen("revision"), 0), YANG_REVISION);
252 assert_int_equal(yin_match_keyword("revision-date", strlen("revision-date"), 0), YANG_REVISION_DATE);
253 assert_int_equal(yin_match_keyword("rpc", strlen("rpc"), 0), YANG_RPC);
254 assert_int_equal(yin_match_keyword("status", strlen("status"), 0), YANG_STATUS);
255 assert_int_equal(yin_match_keyword("submodule", strlen("submodule"), 0), YANG_SUBMODULE);
256 assert_int_equal(yin_match_keyword("type", strlen("type"), 0), YANG_TYPE);
257 assert_int_equal(yin_match_keyword("typedef", strlen("typedef"), 0), YANG_TYPEDEF);
258 assert_int_equal(yin_match_keyword("unique", strlen("unique"), 0), YANG_UNIQUE);
259 assert_int_equal(yin_match_keyword("units", strlen("units"), 0), YANG_UNITS);
260 assert_int_equal(yin_match_keyword("uses", strlen("uses"), 0), YANG_USES);
261 assert_int_equal(yin_match_keyword("value", strlen("value"), 0), YANG_VALUE);
262 assert_int_equal(yin_match_keyword("when", strlen("when"), 0), YANG_WHEN);
263 assert_int_equal(yin_match_keyword("yang-version", strlen("yang-version"), 0), YANG_YANG_VERSION);
264 assert_int_equal(yin_match_keyword("yin-element", strlen("yin-element"), 0), YANG_YIN_ELEMENT);
David Sedlák872c7b42018-10-26 13:15:20 +0200265}
David Sedlák3b4db242018-10-19 16:11:01 +0200266
David Sedlák872c7b42018-10-26 13:15:20 +0200267static void
268test_match_argument(void **state)
269{
David Sedlák68a1af12019-03-08 13:46:54 +0100270 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200271
David Sedláka7406952019-04-05 10:33:07 +0200272 assert_int_equal(match_argument_name("", 5), YIN_ARG_UNKNOWN);
273 assert_int_equal(match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
274 assert_int_equal(match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
David Sedlák872c7b42018-10-26 13:15:20 +0200275 assert_int_equal(match_argument_name("condition", 9), YIN_ARG_CONDITION);
276 assert_int_equal(match_argument_name("date", 4), YIN_ARG_DATE);
277 assert_int_equal(match_argument_name("module", 6), YIN_ARG_MODULE);
278 assert_int_equal(match_argument_name("name", 4), YIN_ARG_NAME);
279 assert_int_equal(match_argument_name("tag", 3), YIN_ARG_TAG);
280 assert_int_equal(match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
281 assert_int_equal(match_argument_name("text", 4), YIN_ARG_TEXT);
282 assert_int_equal(match_argument_name("uri", 3), YIN_ARG_URI);
283 assert_int_equal(match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200284}
285
David Sedlák68a1af12019-03-08 13:46:54 +0100286static void
287test_meta(void **state)
288{
289 LY_ERR ret = LY_SUCCESS;
290 struct state *st = *state;
291
David Sedlák2b214ac2019-06-06 16:11:03 +0200292 ret = yin_parse_module(st->ctx,"<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
293 name=\"example-foo\">\
David Sedlák15a92662019-06-18 11:55:15 +0200294 <organization xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"><text>organization...</text></organization>\
295 <contact><text>contact...</text></contact>\
296 <description><text>description...</text></description>\
297 <reference><text>reference...</text></reference>\
David Sedlák68a1af12019-03-08 13:46:54 +0100298 </module>", st->mod);
299
300 assert_int_equal(ret, LY_SUCCESS);
David Sedláka7406952019-04-05 10:33:07 +0200301 assert_string_equal(st->mod->parsed->mod->org, "organization...");
David Sedlák68a1af12019-03-08 13:46:54 +0100302 assert_string_equal(st->mod->parsed->mod->contact, "contact...");
303 assert_string_equal(st->mod->parsed->mod->dsc, "description...");
304 assert_string_equal(st->mod->parsed->mod->ref, "reference...");
David Sedlák68826732019-06-05 10:50:58 +0200305
306 st = reset_state(state);
307 ret = yin_parse_module(st->ctx,"<module name=\"example-foo\">\
308 <organization test=\"invalid-argument\">organization...</organization>\
309 </module>", st->mod);
310 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200311
312 st->finished_correctly = true;
David Sedlák68a1af12019-03-08 13:46:54 +0100313}
314
David Sedlák8f5bce02019-06-03 16:41:08 +0200315static void
316test_parse_text_element(void **state)
317{
318 struct state *st = *state;
319 const char *res = NULL, *prefix = NULL, *name = NULL;
320 size_t prefix_len = 0, name_len = 0;
321 LY_ERR ret = LY_SUCCESS;
322
323 const char *data = "<elem>content</elem>";
324 lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
325 parse_text_element(st->xml_ctx, &data, &res);
326 assert_string_equal(res, "content");
327 lydict_remove(st->ctx, "content");
David Sedlák15a92662019-06-18 11:55:15 +0200328 st = reset_state(state);
David Sedlák8f5bce02019-06-03 16:41:08 +0200329
David Sedlák8f5bce02019-06-03 16:41:08 +0200330 data = "<elem xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">another-content</elem>";
331 lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
332 parse_text_element(st->xml_ctx, &data, &res);
333 assert_string_equal(res, "another-content");
334 lydict_remove(st->ctx, "another-content");
David Sedlák15a92662019-06-18 11:55:15 +0200335 st = reset_state(state);
David Sedlák8f5bce02019-06-03 16:41:08 +0200336
David Sedlák7ff55a92019-06-17 11:11:41 +0200337 data = "<elem invalid=\"invalid\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">text</elem>";
David Sedlák8f5bce02019-06-03 16:41:08 +0200338 lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
339 ret = parse_text_element(st->xml_ctx, &data, &res);
340 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200341
342 st->finished_correctly = true;
David Sedlák8f5bce02019-06-03 16:41:08 +0200343}
344
David Sedlákd9d3a312019-06-04 09:47:10 +0200345static void
David Sedlákda63c082019-06-04 13:52:23 +0200346test_yin_parse_import(void **state)
347{
348 struct state *st = *state;
349 const char *prefix = NULL, *name = NULL;
350 size_t prefix_len = 0, name_len = 0;
351 LY_ERR ret = LY_SUCCESS;
352 struct lysp_import *imports = NULL;
353
David Sedlák2b214ac2019-06-06 16:11:03 +0200354 const char *data = "<import xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" module=\"a\">\
David Sedlákda63c082019-06-04 13:52:23 +0200355 <prefix value=\"a_mod\"/>\
356 <revision-date date=\"2015-01-01\"/>\
David Sedlákc67dcaa2019-06-04 14:49:05 +0200357 </import>\
358 \
David Sedlák2b214ac2019-06-06 16:11:03 +0200359 <import xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" module=\"a\">\
David Sedlákc67dcaa2019-06-04 14:49:05 +0200360 <prefix value=\"a_mod\"/>\
361 <revision-date date=\"2015-01-01\"/>\
David Sedlákda63c082019-06-04 13:52:23 +0200362 </import>";
363
364 lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
365 ret = yin_parse_import(st->xml_ctx, "b-mod", &data, &imports);
366 assert_int_equal(ret, LY_SUCCESS);
367 assert_string_equal(imports->name, "a");
368 assert_string_equal(imports->prefix, "a_mod");
369 assert_string_equal(imports->rev, "2015-01-01");
370 lydict_remove(st->ctx, imports->name);
371 lydict_remove(st->ctx, imports->prefix);
372 LY_ARRAY_FREE(imports);
David Sedlákda63c082019-06-04 13:52:23 +0200373 imports = NULL;
David Sedlákc67dcaa2019-06-04 14:49:05 +0200374
David Sedlákda63c082019-06-04 13:52:23 +0200375 lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
376 ret = yin_parse_import(st->xml_ctx, "a_mod", &data, &imports);
377 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200378 logbuf_assert("Prefix \"a_mod\" already used as module prefix. Line number 1.");
David Sedlákda63c082019-06-04 13:52:23 +0200379 lydict_remove(st->ctx, imports->name);
380 lydict_remove(st->ctx, imports->prefix);
381 LY_ARRAY_FREE(imports);
David Sedlák79e50cb2019-06-05 16:33:09 +0200382
383 st->finished_correctly = true;
David Sedlákda63c082019-06-04 13:52:23 +0200384}
385
David Sedlák3b4db242018-10-19 16:11:01 +0200386int
387main(void)
388{
389
390 const struct CMUnitTest tests[] = {
David Sedlák392af4f2019-06-04 16:02:42 +0200391 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f),
David Sedlák68a1af12019-03-08 13:46:54 +0100392 cmocka_unit_test_setup_teardown(test_meta, setup_f, teardown_f),
David Sedlák8f5bce02019-06-03 16:41:08 +0200393 cmocka_unit_test_setup_teardown(test_parse_text_element, setup_f, teardown_f),
David Sedlákda63c082019-06-04 13:52:23 +0200394 cmocka_unit_test_setup_teardown(test_yin_parse_import, setup_f, teardown_f),
David Sedlák1bccdfa2019-06-17 15:55:27 +0200395 cmocka_unit_test(test_yin_match_keyword),
David Sedlák872c7b42018-10-26 13:15:20 +0200396 cmocka_unit_test(test_match_argument),
David Sedlák3b4db242018-10-19 16:11:01 +0200397 };
398
399 return cmocka_run_group_tests(tests, NULL, NULL);
400}