blob: 6ceaf8e3a9ba4ce63dc2b02dee56b9f0470393c6 [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ák555c7202019-07-04 12:14:12 +020030/* prototypes of static functions */
31void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +020032void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +020033void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +020034void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +020035void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +020036void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +020037void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +020038void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +020039void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +020040void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +020041void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
David Sedlák031b9e72019-07-23 15:19:37 +020042void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
David Sedláke3ce9ef2019-07-23 16:34:30 +020043void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
David Sedlák555c7202019-07-04 12:14:12 +020044
David Sedlák68a1af12019-03-08 13:46:54 +010045struct state {
David Sedlák3b4db242018-10-19 16:11:01 +020046 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010047 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020048 struct lysp_module *lysp_mod;
David Sedlákda8ffa32019-07-08 14:17:10 +020049 struct yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020050 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010051};
David Sedlák872c7b42018-10-26 13:15:20 +020052
David Sedlák79e50cb2019-06-05 16:33:09 +020053#define BUFSIZE 1024
54char logbuf[BUFSIZE] = {0};
55int store = -1; /* negative for infinite logging, positive for limited logging */
56
57/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedlákaf536aa2019-07-23 13:42:23 +020058#define ENABLE_LOGGER_CHECKING 0
David Sedlák79e50cb2019-06-05 16:33:09 +020059
60#if ENABLE_LOGGER_CHECKING
61static void
62logger(LY_LOG_LEVEL level, const char *msg, const char *path)
63{
64 (void) level; /* unused */
65 if (store) {
66 if (path && path[0]) {
67 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
68 } else {
69 strncpy(logbuf, msg, BUFSIZE - 1);
70 }
71 if (store > 0) {
72 --store;
73 }
74 }
75}
76#endif
77
78#if ENABLE_LOGGER_CHECKING
79# define logbuf_assert(str) assert_string_equal(logbuf, str)
80#else
81# define logbuf_assert(str)
82#endif
83
84#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
85 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
86 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
87 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
88 CLEANUP
89
David Sedlák8e7bda82019-07-16 17:57:50 +020090int
91setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +010092{
93 struct state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +020094
David Sedlák68a1af12019-03-08 13:46:54 +010095 /* allocate state variable */
96 (*state) = st = calloc(1, sizeof(*st));
97 if (!st) {
98 fprintf(stderr, "Memmory allocation failed");
99 return EXIT_FAILURE;
100 }
David Sedlák872c7b42018-10-26 13:15:20 +0200101
David Sedlák68a1af12019-03-08 13:46:54 +0100102 /* create new libyang context */
103 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200104
David Sedlák8e7bda82019-07-16 17:57:50 +0200105 return EXIT_SUCCESS;
106}
107
108int
109destroy_ly_ctx(void **state)
110{
111 struct state *st = *state;
112 ly_ctx_destroy(st->ctx, NULL);
113 free(st);
114
115 return EXIT_SUCCESS;
116}
117
118static int
119setup_f(void **state)
120{
121 struct state *st = *state;
122
123#if ENABLE_LOGGER_CHECKING
124 /* setup logger */
125 ly_set_log_clb(logger, 1);
126#endif
127
David Sedlák68a1af12019-03-08 13:46:54 +0100128 /* allocate new module */
129 st->mod = calloc(1, sizeof(*st->mod));
130 st->mod->ctx = st->ctx;
131
David Sedlák619db942019-07-03 14:47:30 +0200132 /* allocate new parsed module */
133 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
134 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
135 st->lysp_mod->mod->ctx = st->ctx;
136
137 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200138 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
139 st->yin_ctx->xml_ctx.ctx = st->ctx;
140 st->yin_ctx->xml_ctx.line = 1;
David Sedlák8f5bce02019-06-03 16:41:08 +0200141
David Sedlák68a1af12019-03-08 13:46:54 +0100142 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200143}
144
145static int
David Sedlák68a1af12019-03-08 13:46:54 +0100146teardown_f(void **state)
147{
148 struct state *st = *(struct state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200149 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100150
David Sedlák79e50cb2019-06-05 16:33:09 +0200151#if ENABLE_LOGGER_CHECKING
152 /* teardown logger */
153 if (!st->finished_correctly && logbuf[0] != '\0') {
154 fprintf(stderr, "%s\n", logbuf);
155 }
156#endif
157
David Sedlák619db942019-07-03 14:47:30 +0200158 temp = st->lysp_mod->mod;
159
David Sedlákda8ffa32019-07-08 14:17:10 +0200160 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100161 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200162 lysp_module_free(st->lysp_mod);
163 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200164 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100165
166 return EXIT_SUCCESS;
167}
168
David Sedlák392af4f2019-06-04 16:02:42 +0200169static struct state*
170reset_state(void **state)
171{
David Sedlák79e50cb2019-06-05 16:33:09 +0200172 ((struct state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200173 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200174 teardown_f(state);
175 setup_f(state);
176
177 return *state;
178}
179
David Sedlák79e50cb2019-06-05 16:33:09 +0200180void
181logbuf_clean(void)
182{
183 logbuf[0] = '\0';
184}
185
David Sedlák68a1af12019-03-08 13:46:54 +0100186static void
David Sedlák392af4f2019-06-04 16:02:42 +0200187test_yin_parse_module(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100188{
189 LY_ERR ret = LY_SUCCESS;
190 struct state *st = *state;
191
192 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200193 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
194 name=\"example-foo\"\
David Sedlák18730132019-03-15 15:51:34 +0100195 xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
196 xmlns:foo=\"urn:example:foo\"\
197 xmlns:myext=\"urn:example:extensions\">\
David Sedlákcd0c9512019-03-29 13:23:06 +0100198 <namespace uri=\"urn:example:foo\" xmlns:myext=\"urn:example:extensions\"/>\
David Sedláka7406952019-04-05 10:33:07 +0200199 <prefix xmlns:myxt=\"urn:emple:extensions\" value=\"foo\" xmlns:myext=\"urn:example:extensions\"/>\
David Sedlákd9d3a312019-06-04 09:47:10 +0200200 </module>",
David Sedlák68a1af12019-03-08 13:46:54 +0100201 st->mod);
202
203 assert_int_equal(ret, LY_SUCCESS);
204 assert_string_equal(st->mod->parsed->mod->name, "example-foo");
205 assert_string_equal(st->mod->parsed->mod->prefix, "foo");
David Sedlákcd0c9512019-03-29 13:23:06 +0100206 assert_string_equal(st->mod->parsed->mod->ns, "urn:example:foo");
David Sedlák392af4f2019-06-04 16:02:42 +0200207
208 st = reset_state(state);
209 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200210 "<module name=\"example-foo\">\
211 <invalid-tag uri=\"urn:example:foo\"\"/>\
212 </module>",
213 st->mod);
David Sedlák392af4f2019-06-04 16:02:42 +0200214 assert_int_equal(ret, LY_EVALID);
215
216 st = reset_state(state);
217 ret = yin_parse_module(st->ctx,
David Sedlák8f7a1172019-06-20 14:42:18 +0200218 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\
David Sedlák57715b12019-06-17 13:05:22 +0200219 </module>",
David Sedlák2b214ac2019-06-06 16:11:03 +0200220 st->mod);
David Sedlák392af4f2019-06-04 16:02:42 +0200221 assert_int_equal(ret, LY_EVALID);
David Sedlák882a8072019-07-08 17:51:20 +0200222 logbuf_assert("Missing mandatory attribute name of module element. Line number 1.");
David Sedlák392af4f2019-06-04 16:02:42 +0200223
224 st = reset_state(state);
225 ret = yin_parse_module(st->ctx,
226 "",
227 st->mod);
228 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200229 logbuf_assert("Invalid keyword \"(null)\", expected \"module\" or \"submodule\". Line number 1.");
230 st->finished_correctly = true;
David Sedlák3b4db242018-10-19 16:11:01 +0200231}
232
233static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200234test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200235{
David Sedlák8f7a1172019-06-20 14:42:18 +0200236 struct state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200237
David Sedlák8f7a1172019-06-20 14:42:18 +0200238 const char *prefix, *name;
239 struct yin_arg_record *args = NULL;
240 size_t prefix_len, name_len;
241 /* create mock yin namespace in xml context */
242 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200243 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
244 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák8f7a1172019-06-20 14:42:18 +0200245 LY_ARRAY_FREE(args);
246
David Sedlákc1771b12019-07-10 15:55:46 +0200247 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, YANG_NONE), YANG_NONE);
248 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, YANG_NONE), YANG_NONE);
249 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, YANG_NONE), YANG_NONE);
250 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, YANG_NONE), YANG_ANYDATA);
251 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, YANG_NONE), YANG_ANYXML);
252 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, YANG_NONE), YANG_ARGUMENT);
253 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, YANG_NONE), YANG_AUGMENT);
254 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, YANG_NONE), YANG_BASE);
255 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, YANG_NONE), YANG_BELONGS_TO);
256 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, YANG_NONE), YANG_BIT);
257 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, YANG_NONE), YANG_CASE);
258 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, YANG_NONE), YANG_CHOICE);
259 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, YANG_NONE), YANG_CONFIG);
260 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, YANG_NONE), YANG_CONTACT);
261 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, YANG_NONE), YANG_CONTAINER);
262 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, YANG_NONE), YANG_DEFAULT);
263 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, YANG_NONE), YANG_DESCRIPTION);
264 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, YANG_NONE), YANG_DEVIATE);
265 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, YANG_NONE), YANG_DEVIATION);
266 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, YANG_NONE), YANG_ENUM);
267 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, YANG_NONE), YANG_ERROR_APP_TAG);
268 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, YANG_NONE), YANG_ERROR_MESSAGE);
269 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, YANG_NONE), YANG_EXTENSION);
270 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, YANG_NONE), YANG_FEATURE);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, YANG_NONE), YANG_FRACTION_DIGITS);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, YANG_NONE), YANG_GROUPING);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, YANG_NONE), YANG_IDENTITY);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, YANG_NONE), YANG_IF_FEATURE);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, YANG_NONE), YANG_IMPORT);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, YANG_NONE), YANG_INCLUDE);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, YANG_NONE), YANG_INPUT);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, YANG_NONE), YANG_KEY);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, YANG_NONE), YANG_LEAF);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, YANG_NONE), YANG_LEAF_LIST);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, YANG_NONE), YANG_LENGTH);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, YANG_NONE), YANG_LIST);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, YANG_NONE), YANG_MANDATORY);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, YANG_NONE), YANG_MAX_ELEMENTS);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, YANG_NONE), YANG_MIN_ELEMENTS);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, YANG_NONE), YANG_MODIFIER);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, YANG_NONE), YANG_MODULE);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, YANG_NONE), YANG_MUST);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, YANG_NONE), YANG_NAMESPACE);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, YANG_NONE), YANG_NOTIFICATION);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, YANG_NONE), YANG_ORDERED_BY);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, YANG_NONE), YANG_ORGANIZATION);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, YANG_NONE), YANG_OUTPUT);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, YANG_NONE), YANG_PATH);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, YANG_NONE), YANG_PATTERN);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, YANG_NONE), YANG_POSITION);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, YANG_NONE), YANG_PREFIX);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, YANG_NONE), YANG_PRESENCE);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, YANG_NONE), YANG_RANGE);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, YANG_NONE), YANG_REFERENCE);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, YANG_NONE), YANG_REFINE);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, YANG_NONE), YANG_REQUIRE_INSTANCE);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, YANG_NONE), YANG_REVISION);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, YANG_NONE), YANG_REVISION_DATE);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, YANG_NONE), YANG_RPC);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, YANG_NONE), YANG_STATUS);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, YANG_NONE), YANG_SUBMODULE);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, YANG_NONE), YANG_TYPE);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, YANG_NONE), YANG_TYPEDEF);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, YANG_NONE), YANG_UNIQUE);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, YANG_NONE), YANG_UNITS);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, YANG_NONE), YANG_USES);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, YANG_NONE), YANG_VALUE);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, YANG_NONE), YANG_WHEN);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, YANG_NONE), YANG_YANG_VERSION);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, YANG_NONE), YANG_YIN_ELEMENT);
David Sedlák8f7a1172019-06-20 14:42:18 +0200317
318 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200319}
David Sedlák3b4db242018-10-19 16:11:01 +0200320
David Sedlák872c7b42018-10-26 13:15:20 +0200321static void
David Sedlák060b00e2019-06-19 11:12:06 +0200322test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200323{
David Sedlák68a1af12019-03-08 13:46:54 +0100324 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200325
David Sedlák060b00e2019-06-19 11:12:06 +0200326 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
327 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
328 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
329 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
330 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
331 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
332 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
333 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
334 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
335 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
336 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
337 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200338}
339
David Sedlák68a1af12019-03-08 13:46:54 +0100340static void
David Sedlákb1a78352019-06-28 16:16:29 +0200341test_yin_parse_element_generic(void **state)
342{
343 const char *prefix, *name;
344 struct state *st = *state;
345 struct lysp_ext_instance exts;
346 size_t prefix_len, name_len;
347 LY_ERR ret;
348
349 memset(&exts, 0, sizeof(exts));
350
351 const char *data = "<elem attr=\"value\">text_value</elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200352 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
353 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, prefix, prefix_len, &data, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200354 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200355 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200356 assert_string_equal(exts.child->stmt, "elem");
357 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200358 assert_string_equal(exts.child->child->stmt, "attr");
359 assert_string_equal(exts.child->child->arg, "value");
360 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200361 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200362 st = reset_state(state);
363
364 data = "<elem></elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200365 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
366 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, prefix, prefix_len, &data, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200367 assert_int_equal(ret, LY_SUCCESS);
368 assert_string_equal(exts.child->stmt, "elem");
369 assert_null(exts.child->child);
370 assert_null(exts.child->arg);
David Sedlákda8ffa32019-07-08 14:17:10 +0200371 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák5392a212019-07-01 09:19:10 +0200372 lysp_ext_instance_free(st->ctx, &exts);
373
David Sedlákb1a78352019-06-28 16:16:29 +0200374 st->finished_correctly = true;
375}
376
377static void
378test_yin_parse_extension_instance(void **state)
379{
380 LY_ERR ret;
381 struct state *st = *state;
382 const char *prefix, *name;
383 size_t prefix_len, name_len;
384 struct yin_arg_record *args = NULL;
385 struct lysp_ext_instance *exts = NULL;
David Sedlákb1a78352019-06-28 16:16:29 +0200386 const char *data = "<ext value1=\"test\" value=\"test2\"><subelem>text</subelem></ext>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200387 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
388 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200389 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name2fullname(name, prefix_len),
David Sedlák619db942019-07-03 14:47:30 +0200390 namelen2fulllen(name_len, prefix_len), LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200391 assert_int_equal(ret, LY_SUCCESS);
392 assert_string_equal(exts->name, "ext");
393 assert_int_equal(exts->insubstmt_index, 0);
394 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
395 assert_true(exts->yin & LYS_YIN);
396 assert_string_equal(exts->child->stmt, "value1");
397 assert_string_equal(exts->child->arg, "test");
398 assert_null(exts->child->child);
399 assert_true(exts->child->flags & LYS_YIN_ATTR);
400 assert_string_equal(exts->child->next->stmt, "value");
401 assert_string_equal(exts->child->next->arg, "test2");
402 assert_null(exts->child->next->child);
403 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
404
405 assert_string_equal(exts->child->next->next->stmt, "subelem");
406 assert_string_equal(exts->child->next->next->arg, "text");
407 assert_null(exts->child->next->next->child);
408 assert_null(exts->child->next->next->next);
409 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákda8ffa32019-07-08 14:17:10 +0200410 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200411 LY_ARRAY_FREE(args);
412 lysp_ext_instance_free(st->ctx, exts);
413 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200414 exts = NULL;
415 args = NULL;
416 st = reset_state(state);
417
418 data = "<extension-elem />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200419 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
420 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200421 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200422 assert_int_equal(ret, LY_SUCCESS);
423 assert_string_equal(exts->name, "extension-elem");
424 assert_null(exts->argument);
425 assert_null(exts->child);
426 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
427 assert_int_equal(exts->insubstmt_index, 0);
428 assert_true(exts->yin & LYS_YIN);
David Sedlákda8ffa32019-07-08 14:17:10 +0200429 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákf250ecf2019-07-01 11:02:05 +0200430 LY_ARRAY_FREE(args);
431 lysp_ext_instance_free(st->ctx, exts);
432 LY_ARRAY_FREE(exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200433 st->finished_correctly = true;
434}
435
David Sedlák555c7202019-07-04 12:14:12 +0200436static void
437test_yin_parse_content(void **state)
438{
439 struct state *st = *state;
440 LY_ERR ret = LY_SUCCESS;
441 struct sized_string name, prefix;
442 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
443 "<custom xmlns=\"my-ext\">"
444 "totally amazing extension"
445 "</custom>"
David Sedlák986cb412019-07-04 13:10:11 +0200446 "<extension name=\"ext\">"
447 "<argument name=\"argname\"></argument>"
448 "<description><text>desc</text></description>"
449 "<reference><text>ref</text></reference>"
450 "<status value=\"deprecated\"></status>"
451 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200452 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200453 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200454 "<when condition=\"condition...\">"
455 "<reference><text>when_ref</text></reference>"
456 "<description><text>when_desc</text></description>"
457 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200458 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200459 "<error-message>"
460 "<value>error-msg</value>"
461 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200462 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200463 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200464 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200465 "<position value=\"25\"></position>"
466 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200467 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200468 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200469 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200470 "<pattern value='pattern'>"
471 "<modifier value='invert-match'/>"
472 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200473 "<enum name=\"yay\">"
474 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200475 "</prefix>";
476 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200477 const char **if_features = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200478 struct yin_arg_record *attrs = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200479 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200480 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200481 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200482 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200483 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200484 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200485
David Sedlákda8ffa32019-07-08 14:17:10 +0200486 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
487 yin_load_attributes(st->yin_ctx, &data, &attrs);
David Sedlák555c7202019-07-04 12:14:12 +0200488
David Sedlákfd5b9c32019-07-12 15:33:13 +0200489 struct yin_subelement subelems[17] = {
David Sedlák438ae432019-07-11 15:36:54 +0200490 {YANG_CONFIG, &config, 0},
David Sedlákc3da3ef2019-07-19 12:56:08 +0200491 {YANG_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
David Sedlákfd5b9c32019-07-12 15:33:13 +0200492 {YANG_ENUM, &enum_type, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200493 {YANG_ERROR_APP_TAG, &app_tag, 0},
494 {YANG_ERROR_MESSAGE, &err_msg, 0},
495 {YANG_EXTENSION, &ext_def, 0},
496 {YANG_IF_FEATURE, &if_features, 0},
497 {YANG_LENGTH, &len_type, 0},
David Sedlákd3983112019-07-12 11:20:56 +0200498 {YANG_PATTERN, &patter_type, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200499 {YANG_RANGE, &range_type, 0},
500 {YANG_REQUIRE_INSTANCE, &req_type, 0},
501 {YANG_UNITS, &units, 0},
David Sedlák374d2b32019-07-17 15:06:55 +0200502 {YANG_POSITION, &pos_enum, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200503 {YANG_VALUE, &val_enum, 0},
504 {YANG_WHEN, &when_p, 0},
505 {YANG_CUSTOM, NULL, 0},
506 {YIN_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200507 };
David Sedlákfd5b9c32019-07-12 15:33:13 +0200508 ret = yin_parse_content(st->yin_ctx, subelems, 17, &data, YANG_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200509 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200510 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák2ce1be62019-07-10 16:15:09 +0200511 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200512 assert_string_equal(def, "default-value");
David Sedlák555c7202019-07-04 12:14:12 +0200513 assert_string_equal(exts->name, "custom");
514 assert_string_equal(exts->argument, "totally amazing extension");
515 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200516 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200517 assert_string_equal(when_p->cond, "condition...");
518 assert_string_equal(when_p->dsc, "when_desc");
519 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200520 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200521 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200522 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200523 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200524 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200525 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200526 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200527 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200528 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200529 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200530 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200531 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200532 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200533 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200534 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200535 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200536 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200537 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200538 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200539 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200540 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200541 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200542 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200543 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200544 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200545 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200546 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200547 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200548 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200549 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200550 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200551 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200552 LY_ARRAY_FREE(ext_def);
David Sedlák555c7202019-07-04 12:14:12 +0200553 LY_ARRAY_FREE(attrs);
David Sedlákd3983112019-07-12 11:20:56 +0200554 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200555 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200556 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200557 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200558 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200559 attrs = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200560 st = reset_state(state);
561
562 /* test unique subelem */
563 const char *prefix_value;
564 struct yin_subelement subelems2[2] = {{YANG_PREFIX, &prefix_value, 0},
565 {YIN_TEXT, &value, YIN_SUBELEM_UNIQUE}};
566 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
567 "<prefix value=\"inv_mod\" />"
568 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
569 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
570 "</module>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200571 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
572 yin_load_attributes(st->yin_ctx, &data, &attrs);
573 ret = yin_parse_content(st->yin_ctx, subelems2, 2, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200574 assert_int_equal(ret, LY_EVALID);
575 logbuf_assert("Redefinition of text element in module element. Line number 1.");
576 lydict_remove(st->ctx, prefix_value);
577 lydict_remove(st->ctx, value);
578 st = reset_state(state);
579 LY_ARRAY_FREE(attrs);
580 attrs = NULL;
581
582 /* test first subelem */
583 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
584 "<prefix value=\"inv_mod\" />"
585 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
586 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
587 "</module>";
588 struct yin_subelement subelems3[2] = {{YANG_PREFIX, &prefix_value, 0},
589 {YIN_TEXT, &value, YIN_SUBELEM_FIRST}};
David Sedlákda8ffa32019-07-08 14:17:10 +0200590 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
591 yin_load_attributes(st->yin_ctx, &data, &attrs);
592 ret = yin_parse_content(st->yin_ctx, subelems3, 2, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200593 assert_int_equal(ret, LY_EVALID);
594 logbuf_assert("Subelement text of module element must be defined as first subelement. Line number 1.");
595 lydict_remove(st->ctx, prefix_value);
596 st = reset_state(state);
597 LY_ARRAY_FREE(attrs);
598 attrs = NULL;
599
600 /* test mandatory subelem */
601 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
602 "</module>";
603 struct yin_subelement subelems4[1] = {{YANG_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY}};
David Sedlákda8ffa32019-07-08 14:17:10 +0200604 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
605 yin_load_attributes(st->yin_ctx, &data, &attrs);
606 ret = yin_parse_content(st->yin_ctx, subelems4, 1, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200607 assert_int_equal(ret, LY_EVALID);
608 logbuf_assert("Missing mandatory subelement prefix of module element. Line number 1.");
609 LY_ARRAY_FREE(attrs);
610
611 st->finished_correctly = true;
612}
613
David Sedlák92147b02019-07-09 14:01:01 +0200614static void
David Sedlák4a650532019-07-10 11:55:18 +0200615test_validate_value(void **state)
616{
617 struct state *st = *state;
618 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "#invalid", 8), LY_EVALID);
619 logbuf_assert("Invalid identifier character '#'. Line number 1.");
620 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG, "", 0), LY_SUCCESS);
621 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "pre:b", 5), LY_EVALID);
622 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:b", 5), LY_SUCCESS);
623 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:pre:b", 9), LY_EVALID);
624
625 st->finished_correctly = true;
626}
627
David Sedlák32488102019-07-15 17:44:10 +0200628static int
629setup_element_test(void **state)
630{
David Sedlák8e7bda82019-07-16 17:57:50 +0200631 struct state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200632
633#if ENABLE_LOGGER_CHECKING
634 /* setup logger */
635 ly_set_log_clb(logger, 1);
636#endif
637
638 /* reset logbuf */
639 logbuf[0] = '\0';
David Sedlák32488102019-07-15 17:44:10 +0200640
641 /* allocate parser context */
642 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
643 st->yin_ctx->xml_ctx.ctx = st->ctx;
644 st->yin_ctx->xml_ctx.line = 1;
645
646 return EXIT_SUCCESS;
647}
648
649static int
650teardown_element_test(void **state)
651{
652 struct state *st = *(struct state **)state;
653
654#if ENABLE_LOGGER_CHECKING
655 /* teardown logger */
656 if (!st->finished_correctly && logbuf[0] != '\0') {
657 fprintf(stderr, "%s\n", logbuf);
658 }
659#endif
660
661 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák32488102019-07-15 17:44:10 +0200662 free(st->yin_ctx);
David Sedlák32488102019-07-15 17:44:10 +0200663
664 return EXIT_SUCCESS;
665}
666
667#define ELEMENT_WRAPPER_START "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
668#define ELEMENT_WRAPPER_END "</module>"
669
670/* helper function to simplify unit test of each element using parse_content function */
671LY_ERR
672test_element_helper(struct state *st, const char **data, void *dest, const char **text,
673 struct lysp_ext_instance **exts, bool valid)
674{
675 struct yin_arg_record *attrs = NULL;
676 struct sized_string name, prefix;
677 LY_ERR ret = LY_SUCCESS;
678 struct yin_subelement subelems[71] = {
679 {YANG_ACTION, dest, 0},
680 {YANG_ANYDATA, dest, 0},
681 {YANG_ANYXML, dest, 0},
682 {YANG_ARGUMENT,dest, 0},
683 {YANG_AUGMENT, dest, 0},
684 {YANG_BASE, dest, 0},
685 {YANG_BELONGS_TO, dest, 0},
686 {YANG_BIT, dest, 0},
687 {YANG_CASE, dest, 0},
688 {YANG_CHOICE, dest, 0},
689 {YANG_CONFIG, dest, 0},
690 {YANG_CONTACT, dest, 0},
691 {YANG_CONTAINER, dest, 0},
David Sedlákc3da3ef2019-07-19 12:56:08 +0200692 {YANG_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
David Sedlák32488102019-07-15 17:44:10 +0200693 {YANG_DESCRIPTION, dest, 0},
694 {YANG_DEVIATE, dest, 0},
695 {YANG_DEVIATION, dest, 0},
696 {YANG_ENUM, dest, 0},
697 {YANG_ERROR_APP_TAG, dest, 0},
698 {YANG_ERROR_MESSAGE, dest, 0},
699 {YANG_EXTENSION, dest, 0},
700 {YANG_FEATURE, dest, 0},
701 {YANG_FRACTION_DIGITS, dest, 0},
702 {YANG_GROUPING, dest, 0},
703 {YANG_IDENTITY, dest, 0},
704 {YANG_IF_FEATURE, dest, 0},
705 {YANG_IMPORT, dest, 0},
706 {YANG_INCLUDE, dest, 0},
707 {YANG_INPUT, dest, 0},
708 {YANG_KEY, dest, 0},
709 {YANG_LEAF, dest, 0},
710 {YANG_LEAF_LIST, dest, 0},
711 {YANG_LENGTH, dest, 0},
712 {YANG_LIST, dest, 0},
713 {YANG_MANDATORY, dest, 0},
714 {YANG_MAX_ELEMENTS, dest, 0},
715 {YANG_MIN_ELEMENTS, dest, 0},
716 {YANG_MODIFIER, dest, 0},
717 {YANG_MODULE, dest, 0},
718 {YANG_MUST, dest, 0},
719 {YANG_NAMESPACE, dest, 0},
720 {YANG_NOTIFICATION, dest, 0},
721 {YANG_ORDERED_BY, dest, 0},
722 {YANG_ORGANIZATION, dest, 0},
723 {YANG_OUTPUT, dest, 0},
724 {YANG_PATH, dest, 0},
725 {YANG_PATTERN, dest, 0},
David Sedlák32488102019-07-15 17:44:10 +0200726 {YANG_PREFIX, dest, 0},
727 {YANG_PRESENCE, dest, 0},
728 {YANG_RANGE, dest, 0},
729 {YANG_REFERENCE, dest, 0},
730 {YANG_REFINE, dest, 0},
731 {YANG_REQUIRE_INSTANCE, dest, 0},
732 {YANG_REVISION, dest, 0},
733 {YANG_REVISION_DATE, dest, 0},
734 {YANG_RPC, dest, 0},
735 {YANG_STATUS, dest, 0},
736 {YANG_SUBMODULE, dest, 0},
737 {YANG_TYPE, dest, 0},
738 {YANG_TYPEDEF, dest, 0},
739 {YANG_UNIQUE, dest, 0},
740 {YANG_UNITS, dest, 0},
741 {YANG_USES, dest, 0},
David Sedlák374d2b32019-07-17 15:06:55 +0200742 {YANG_POSITION, dest, 0},
David Sedlák32488102019-07-15 17:44:10 +0200743 {YANG_VALUE, dest, 0},
744 {YANG_WHEN, dest, 0},
745 {YANG_YANG_VERSION, dest, 0},
746 {YANG_YIN_ELEMENT, dest, 0},
747 {YANG_CUSTOM, dest, 0},
748 {YIN_TEXT, dest, 0},
749 {YIN_VALUE, dest, 0}
750 };
751 LY_CHECK_RET(lyxml_get_element(&st->yin_ctx->xml_ctx, data, &prefix.value, &prefix.len, &name.value, &name.len));\
752 LY_CHECK_RET(yin_load_attributes(st->yin_ctx, data, &attrs));\
David Sedlák8e7bda82019-07-16 17:57:50 +0200753 ret = yin_parse_content(st->yin_ctx, subelems, 71, data, yin_match_keyword(st->yin_ctx, name.value, name.len, prefix.value, prefix.len, YANG_NONE), text, exts);
David Sedlák32488102019-07-15 17:44:10 +0200754 LY_ARRAY_FREE(attrs);
755 if (valid) {
756 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
757 }
758 /* reset status */
759 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
760 return ret;
761}
762
763static void
764test_enum_bit_elem(void **state)
765{
766 /* yin_parse_enum_bit is function that is being mainly tested by this test */
767 struct state *st = *state;
768 struct lysp_type type = {};
769 const char *data;
770 data = ELEMENT_WRAPPER_START
771 "<enum name=\"enum-name\">"
772 "<if-feature name=\"feature\" />"
773 "<value value=\"55\" />"
774 "<status value=\"deprecated\" />"
775 "<description><text>desc...</text></description>"
776 "<reference><text>ref...</text></reference>"
777 "</enum>"
778 ELEMENT_WRAPPER_END;
779 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
780 assert_string_equal(*type.enums->iffeatures, "feature");
781 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200782 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200783 assert_string_equal(type.enums->dsc, "desc...");
784 assert_string_equal(type.enums->ref, "ref...");
785 lysp_type_free(st->ctx, &type);
786 memset(&type, 0, sizeof type);
787
788 /* todo bit element test */
789 st->finished_correctly = true;
790}
791
792static void
793test_meta_elem(void **state)
794{
795 struct state *st = *state;
796 char *value = NULL;
797 const char *data;
798
799 /* organization element */
800 data = ELEMENT_WRAPPER_START
801 "<organization><text>organization...</text></organization>"
802 ELEMENT_WRAPPER_END;
803 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
804 assert_string_equal(value, "organization...");
805 FREE_STRING(st->ctx, value);
806 value = NULL;
807 /* contact element */
808 data = ELEMENT_WRAPPER_START
809 "<contact><text>contact...</text></contact>"
810 ELEMENT_WRAPPER_END;
811 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
812 assert_string_equal(value, "contact...");
813 FREE_STRING(st->ctx, value);
814 value = NULL;
815 /* description element */
816 data = ELEMENT_WRAPPER_START
817 "<description><text>description...</text></description>"
818 ELEMENT_WRAPPER_END;
819 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
820 assert_string_equal(value, "description...");
821 FREE_STRING(st->ctx, value);
822 value = NULL;
823 /* reference element */
824 data = ELEMENT_WRAPPER_START
825 "<reference><text>reference...</text></reference>"
826 ELEMENT_WRAPPER_END;
827 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
828 assert_string_equal(value, "reference...");
829 FREE_STRING(st->ctx, value);
830 value = NULL;
831
832 /* missing text subelement */
833 data = ELEMENT_WRAPPER_START
834 "<reference>reference...</reference>"
835 ELEMENT_WRAPPER_END;
836 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, false), LY_EVALID);
837 logbuf_assert("Missing mandatory subelement text of reference element. Line number 1.");
838
839 st->finished_correctly = true;
840}
841
842static void
843test_import_elem(void **state)
844{
845 struct state *st = *state;
846 const char *data;
847 struct lys_module *lys_mod = calloc(1, sizeof *lys_mod);
848 struct lysp_module *lysp_mod = calloc(1, sizeof *lysp_mod);
849 lys_mod->ctx = st->ctx;
850 lysp_mod->mod = lys_mod;
851
852 /* max subelems */
853 data = ELEMENT_WRAPPER_START
854 "<import module=\"a\">"
855 "<prefix value=\"a_mod\"/>"
856 "<revision-date date=\"2015-01-01\"></revision-date>"
857 "<description><text>import description</text></description>"
858 "<reference><text>import reference</text></reference>"
859 "</import>"
860 ELEMENT_WRAPPER_END;
861 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, true), LY_SUCCESS);
862 assert_string_equal(lysp_mod->imports->name, "a");
863 assert_string_equal(lysp_mod->imports->prefix, "a_mod");
864 assert_string_equal(lysp_mod->imports->rev, "2015-01-01");
865 assert_string_equal(lysp_mod->imports->dsc, "import description");
866 assert_string_equal(lysp_mod->imports->ref, "import reference");
867 lysp_module_free(lysp_mod);
868 lys_module_free(lys_mod, NULL);
869
870 /* min subelems */
871 lys_mod = calloc(1, sizeof *lys_mod);
872 lysp_mod = calloc(1, sizeof *lysp_mod);
873 lys_mod->ctx = st->ctx;
874 lysp_mod->mod = lys_mod;
875 data = ELEMENT_WRAPPER_START
876 "<import module=\"a\">"
877 "<prefix value=\"a_mod\"/>"
878 "</import>"
879 ELEMENT_WRAPPER_END;
880 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, true), LY_SUCCESS);
881 assert_string_equal(lysp_mod->imports->prefix, "a_mod");
882 lysp_module_free(lysp_mod);
883 lys_module_free(lys_mod, NULL);
884
885 /* invalid (missing prefix) */
886 lys_mod = calloc(1, sizeof *lys_mod);
887 lysp_mod = calloc(1, sizeof *lysp_mod);
888 lys_mod->ctx = st->ctx;
889 lysp_mod->mod = lys_mod;
890 data = ELEMENT_WRAPPER_START "<import module=\"a\">""</import>" ELEMENT_WRAPPER_END;
891 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, false), LY_EVALID);
892 logbuf_assert("Missing mandatory subelement prefix of import element. Line number 1.");
893 lysp_module_free(lysp_mod);
894 lys_module_free(lys_mod, NULL);
895
896 /* invalid reused prefix */
897 lys_mod = calloc(1, sizeof *lys_mod);
898 lysp_mod = calloc(1, sizeof *lysp_mod);
899 lys_mod->ctx = st->ctx;
900 lysp_mod->mod = lys_mod;
901 data = ELEMENT_WRAPPER_START
902 "<import module=\"a\">"
903 "<prefix value=\"a_mod\"/>"
904 "</import>"
905 "<import module=\"a\">"
906 "<prefix value=\"a_mod\"/>"
907 "</import>"
908 ELEMENT_WRAPPER_END;
909 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, false), LY_EVALID);
910 logbuf_assert("Prefix \"a_mod\" already used to import \"a\" module. Line number 1.");
911 lysp_module_free(lysp_mod);
912 lys_module_free(lys_mod, NULL);
913
914 st->finished_correctly = true;
915}
916
917static void
918test_status_elem(void **state)
919{
920 struct state *st = *state;
921 const char *data;
922 uint16_t flags = 0;
923
924 /* test valid values */
925 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
926 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200927 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +0200928
929 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
930 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200931 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +0200932
933 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\"></status>" ELEMENT_WRAPPER_END;
934 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200935 assert_true(flags & LYS_STATUS_OBSLT);
David Sedlák32488102019-07-15 17:44:10 +0200936
937 /* test invalid value */
938 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
939 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
940 logbuf_assert("Invalid value \"invalid\" of \"status\". Line number 1.");
941 st->finished_correctly = true;
942}
943
944static void
945test_ext_elem(void **state)
946{
947 struct state *st = *state;
948 const char *data;
949 struct lysp_ext *ext = NULL;
950
951 /* max subelems */
952 data = ELEMENT_WRAPPER_START
953 "<extension name=\"ext_name\">"
954 "<argument name=\"arg\"></argument>"
955 "<status value=\"current\"/>"
956 "<description><text>ext_desc</text></description>"
957 "<reference><text>ext_ref</text></reference>"
958 "</extension>"
959 ELEMENT_WRAPPER_END;
960 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
961 assert_string_equal(ext->name, "ext_name");
962 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200963 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +0200964 assert_string_equal(ext->dsc, "ext_desc");
965 assert_string_equal(ext->ref, "ext_ref");
966 lysp_ext_free(st->ctx, ext);
967 LY_ARRAY_FREE(ext);
968 ext = NULL;
969
970 /* min subelems */
971 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
972 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
973 assert_string_equal(ext->name, "ext_name");
974 lysp_ext_free(st->ctx, ext);
975 LY_ARRAY_FREE(ext);
976 ext = NULL;
977
978 st->finished_correctly = true;
979}
980
981static void
982test_yin_element_elem(void **state)
983{
984 struct state *st = *state;
985 const char *data;
986 uint16_t flags = 0;
987
988 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
989 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200990 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200991
992 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\" />" ELEMENT_WRAPPER_END;
993 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200994 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200995
996 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
997 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200998 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200999 logbuf_assert("Invalid value \"invalid\" of \"yin-element\". Line number 1.");
1000 st->finished_correctly = true;
1001}
1002
1003static void
1004test_yangversion_elem(void **state)
1005{
1006 struct state *st = *state;
1007 const char *data;
1008 uint8_t version = 0;
1009
1010 /* valid values */
1011 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
1012 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001013 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001014 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1015
1016 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\" />" ELEMENT_WRAPPER_END;
1017 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001018 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001019 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
1020
1021 /* invalid value */
1022 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
1023 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID);
1024 logbuf_assert("Invalid value \"version\" of \"yang-version\". Line number 1.");
1025
1026 st->finished_correctly = true;
1027}
1028
1029static void
1030test_mandatory_elem(void **state)
1031{
1032 struct state *st = *state;
1033 const char *data;
1034 uint16_t man = 0;
1035
1036 /* valid values */
1037 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
1038 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1039 assert_int_equal(man, LYS_MAND_TRUE);
1040 man = 0;
1041
1042 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\" />" ELEMENT_WRAPPER_END;
1043 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1044 assert_int_equal(man, LYS_MAND_FALSE);
1045
1046 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
1047 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID);
1048 logbuf_assert("Invalid value \"invalid\" of \"mandatory\". Line number 1.");
1049
1050 st->finished_correctly = true;
1051}
1052
David Sedlák8e7bda82019-07-16 17:57:50 +02001053static void
1054test_argument_elem(void **state)
1055{
1056 struct state *st = *state;
1057 const char *data;
1058 uint16_t flags = 0;
1059 const char *arg;
1060 struct yin_argument_meta arg_meta = {&flags, &arg};
1061 /* max subelems */
1062 data = ELEMENT_WRAPPER_START
1063 "<argument name=\"arg-name\">"
1064 "<yin-element value=\"true\" />"
1065 "</argument>"
1066 ELEMENT_WRAPPER_END;
1067 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1068 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001069 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001070 flags = 0;
1071 FREE_STRING(st->ctx, arg);
1072 arg = NULL;
1073
1074 /* min subelems */
1075 data = ELEMENT_WRAPPER_START
1076 "<argument name=\"arg\">"
1077 "</argument>"
1078 ELEMENT_WRAPPER_END;
1079 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1080 assert_string_equal(arg, "arg");
1081 assert_true(flags == 0);
1082 FREE_STRING(st->ctx, arg);
1083
1084 st->finished_correctly = true;
1085}
1086
1087static void
1088test_base_elem(void **state)
1089{
1090 struct state *st = *state;
1091 const char *data;
1092 const char **bases = NULL;
1093 struct lysp_type type = {};
1094
1095 /* as identity subelement */
1096 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
1097 "<base name=\"base-name\"/>"
1098 "</identity>";
1099 assert_int_equal(test_element_helper(st, &data, &bases, NULL, NULL, true), LY_SUCCESS);
1100 assert_string_equal(*bases, "base-name");
1101 FREE_STRING(st->ctx, *bases);
1102 LY_ARRAY_FREE(bases);
1103
1104 /* as type subelement */
1105 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
1106 "<base name=\"base-name\"/>"
1107 "</type>";
1108 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1109 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001110 assert_true(type.flags & LYS_SET_BASE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001111 FREE_STRING(st->ctx, *type.bases);
1112 LY_ARRAY_FREE(type.bases);
1113
1114 st->finished_correctly = true;
1115}
1116
1117static void
1118test_belongsto_elem(void **state)
1119{
1120 struct state *st = *state;
1121 const char *data;
1122 struct lysp_submodule submod;
1123
1124 data = ELEMENT_WRAPPER_START
1125 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>"
1126 ELEMENT_WRAPPER_END;
1127 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, true), LY_SUCCESS);
1128 assert_string_equal(submod.belongsto, "module-name");
1129 assert_string_equal(submod.prefix, "pref");
1130 FREE_STRING(st->ctx, submod.belongsto);
1131 FREE_STRING(st->ctx, submod.prefix);
1132
1133 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
1134 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID);
1135 logbuf_assert("Missing mandatory subelement prefix of belongs-to element. Line number 1.");
1136 FREE_STRING(st->ctx, submod.belongsto);
1137
1138 st->finished_correctly = true;
1139}
1140
1141static void
1142test_config_elem(void **state)
1143{
1144 struct state *st = *state;
1145 const char *data;
1146 uint16_t flags = 0;
1147
1148 data = ELEMENT_WRAPPER_START "<config value=\"true\"/>" ELEMENT_WRAPPER_END;
1149 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001150 assert_true(flags & LYS_CONFIG_W);
David Sedlák8e7bda82019-07-16 17:57:50 +02001151 flags = 0;
1152
1153 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
1154 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001155 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001156 flags = 0;
1157
1158 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1159 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
1160 logbuf_assert("Invalid value \"invalid\" of \"config\". Line number 1.");
1161
1162 st->finished_correctly = true;
1163}
1164
1165static void
1166test_default_elem(void **state)
1167{
1168 struct state *st = *state;
1169 const char *data;
1170 const char *val = NULL;
1171
1172 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\"/>" ELEMENT_WRAPPER_END;
1173 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1174 assert_string_equal(val, "defaul-value");
1175 FREE_STRING(st->ctx, val);
1176 val = NULL;
1177
1178 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
1179 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1180 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1181
1182 st->finished_correctly = true;
1183}
1184
1185static void
1186test_err_app_tag_elem(void **state)
1187{
1188 struct state *st = *state;
1189 const char *data;
1190 const char *val = NULL;
1191
1192 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\"/>" ELEMENT_WRAPPER_END;
1193 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1194 assert_string_equal(val, "val");
1195 FREE_STRING(st->ctx, val);
1196 val = NULL;
1197
1198 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
1199 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1200 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1201
1202 st->finished_correctly = true;
1203}
1204
1205static void
1206test_err_msg_elem(void **state)
1207{
1208 struct state *st = *state;
1209 const char *data;
1210 const char *val = NULL;
1211
1212 data = ELEMENT_WRAPPER_START "<error-message><value>val</value></error-message>" ELEMENT_WRAPPER_END;
1213 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1214 assert_string_equal(val, "val");
1215 FREE_STRING(st->ctx, val);
1216
1217 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
1218 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1219 logbuf_assert("Missing mandatory subelement value of error-message element. Line number 1.");
1220
1221 st->finished_correctly = true;
1222}
1223
1224static void
1225test_fracdigits_elem(void **state)
1226{
1227 struct state *st = *state;
1228 const char *data;
1229 struct lysp_type type = {};
1230
1231 /* valid value */
1232 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\"></fraction-digits>" ELEMENT_WRAPPER_END;
1233 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1234 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001235 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001236
1237 /* invalid values */
1238 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
1239 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1240 logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1.");
1241
1242 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
1243 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1244 logbuf_assert("Invalid value \"02\" of \"fraction-digits\". Line number 1.");
1245
1246 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
1247 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1248 logbuf_assert("Invalid value \"1p\" of \"fraction-digits\". Line number 1.");
1249
1250 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
1251 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1252 logbuf_assert("Invalid value \"19\" of \"fraction-digits\". Line number 1.");
1253
1254 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
1255 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1256 logbuf_assert("Invalid value \"999999999999999999\" of \"fraction-digits\". Line number 1.");
1257
1258 st->finished_correctly = true;
1259}
1260
1261static void
1262test_iffeature_elem(void **state)
1263{
1264 struct state *st = *state;
1265 const char *data;
1266 const char **iffeatures = NULL;
1267
1268 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\"></if-feature>" ELEMENT_WRAPPER_END;
1269 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, true), LY_SUCCESS);
1270 assert_string_equal(*iffeatures, "local-storage");
1271 FREE_STRING(st->ctx, *iffeatures);
1272 LY_ARRAY_FREE(iffeatures);
1273 iffeatures = NULL;
1274
1275 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
1276 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID);
1277 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1278 LY_ARRAY_FREE(iffeatures);
1279 iffeatures = NULL;
1280
1281 st->finished_correctly = true;
1282}
1283
1284static void
1285test_length_elem(void **state)
1286{
1287 struct state *st = *state;
1288 const char *data;
1289 struct lysp_type type = {};
1290
1291 /* max subelems */
1292 data = ELEMENT_WRAPPER_START
1293 "<length value=\"length-str\">"
1294 "<error-message><value>err-msg</value></error-message>"
1295 "<error-app-tag value=\"err-app-tag\"/>"
1296 "<description><text>desc</text></description>"
1297 "<reference><text>ref</text></reference>"
1298 "</length>"
1299 ELEMENT_WRAPPER_END;
1300 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1301 assert_string_equal(type.length->arg, "length-str");
1302 assert_string_equal(type.length->emsg, "err-msg");
1303 assert_string_equal(type.length->eapptag, "err-app-tag");
1304 assert_string_equal(type.length->dsc, "desc");
1305 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001306 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001307 lysp_type_free(st->ctx, &type);
1308 memset(&type, 0, sizeof(type));
1309
1310 /* min subelems */
1311 data = ELEMENT_WRAPPER_START
1312 "<length value=\"length-str\">"
1313 "</length>"
1314 ELEMENT_WRAPPER_END;
1315 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1316 assert_string_equal(type.length->arg, "length-str");
1317 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001318 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001319 memset(&type, 0, sizeof(type));
1320
1321 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
1322 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1323 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1324 lysp_type_free(st->ctx, &type);
1325 memset(&type, 0, sizeof(type));
1326
1327 st->finished_correctly = true;
1328}
1329
1330static void
1331test_modifier_elem(void **state)
1332{
1333 struct state *st = *state;
1334 const char *data;
1335 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
1336
1337 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\" />" ELEMENT_WRAPPER_END;
1338 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, true), LY_SUCCESS);
1339 assert_string_equal(pat, "\x015pattern");
1340 FREE_STRING(st->ctx, pat);
1341
1342 pat = lydict_insert(st->ctx, "\006pattern", 8);
1343 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
1344 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID);
1345 logbuf_assert("Invalid value \"invert\" of \"modifier\". Line number 1.");
1346 FREE_STRING(st->ctx, pat);
1347
1348 st->finished_correctly = true;
1349}
1350
1351static void
1352test_namespace_elem(void **state)
1353{
1354 struct state *st = *state;
1355 const char *data;
1356 const char *ns;
1357
1358 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\"/>" ELEMENT_WRAPPER_END;
1359 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, true), LY_SUCCESS);
1360 assert_string_equal(ns, "ns");
1361 FREE_STRING(st->ctx, ns);
1362
1363 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
1364 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID);
1365 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1366
1367 st->finished_correctly = true;
1368}
1369
1370static void
1371test_path_elem(void **state)
1372{
1373 struct state *st = *state;
1374 const char *data;
1375 struct lysp_type type = {};
1376
1377 data = ELEMENT_WRAPPER_START "<path value=\"path-val\"/>" ELEMENT_WRAPPER_END;
1378 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1379 assert_string_equal("path-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001380 assert_true(type.flags & LYS_SET_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001381 lysp_type_free(st->ctx, &type);
1382
1383 st->finished_correctly = true;
1384}
1385
1386static void
1387test_pattern_elem(void **state)
1388{
1389 struct state *st = *state;
1390 const char *data;
1391 struct lysp_type type = {};
1392
1393 /* max subelems */
1394 data = ELEMENT_WRAPPER_START
1395 "<pattern value=\"super_pattern\">"
1396 "<modifier value=\"invert-match\"/>"
1397 "<error-message><value>err-msg-value</value></error-message>"
1398 "<error-app-tag value=\"err-app-tag-value\"/>"
1399 "<description><text>pattern-desc</text></description>"
1400 "<reference><text>pattern-ref</text></reference>"
1401 "</pattern>"
1402 ELEMENT_WRAPPER_END;
1403 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001404 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001405 assert_string_equal(type.patterns->arg, "\x015super_pattern");
1406 assert_string_equal(type.patterns->dsc, "pattern-desc");
1407 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1408 assert_string_equal(type.patterns->emsg, "err-msg-value");
1409 assert_string_equal(type.patterns->dsc, "pattern-desc");
1410 assert_string_equal(type.patterns->ref, "pattern-ref");
1411 lysp_type_free(st->ctx, &type);
1412 memset(&type, 0, sizeof(type));
1413
1414 /* min subelems */
1415 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
1416 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1417 assert_string_equal(type.patterns->arg, "\x006pattern");
1418 lysp_type_free(st->ctx, &type);
1419 memset(&type, 0, sizeof(type));
1420
1421 st->finished_correctly = true;
1422}
1423
1424static void
1425test_value_position_elem(void **state)
1426{
1427 struct state *st = *state;
1428 const char *data;
1429 struct lysp_type_enum en = {};
1430
1431 /* valid values */
1432 data = ELEMENT_WRAPPER_START "<value value=\"55\" />" ELEMENT_WRAPPER_END;
1433 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1434 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001435 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001436 memset(&en, 0, sizeof(en));
1437
1438 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
1439 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1440 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001441 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001442 memset(&en, 0, sizeof(en));
1443
1444 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
1445 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1446 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001447 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001448 memset(&en, 0, sizeof(en));
1449
1450 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
1451 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1452 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001453 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001454 memset(&en, 0, sizeof(en));
1455
1456 /* valid positions */
1457 data = ELEMENT_WRAPPER_START "<position value=\"55\" />" ELEMENT_WRAPPER_END;
1458 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1459 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001460 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001461 memset(&en, 0, sizeof(en));
1462
1463 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
1464 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1465 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001466 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001467 memset(&en, 0, sizeof(en));
1468
1469 /* invalid values */
1470 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
1471 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1472 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\". Line number 1.");
1473
1474 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
1475 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1476 logbuf_assert("Invalid value \"1k\" of \"value\". Line number 1.");
1477
David Sedlák69f01612019-07-17 11:41:08 +02001478 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
1479 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1480 logbuf_assert("Invalid value \"\" of \"value\". Line number 1.");
1481
David Sedlák8e7bda82019-07-16 17:57:50 +02001482 /*invalid positions */
1483 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
1484 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1485 logbuf_assert("Invalid value \"-5\" of \"position\". Line number 1.");
1486
1487 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
1488 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1489 logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1.");
1490
1491 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
1492 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1493 logbuf_assert("Invalid value \"99999999999999999999\" of \"position\". Line number 1.");
1494
David Sedlák69f01612019-07-17 11:41:08 +02001495 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
1496 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1497 logbuf_assert("Invalid value \"\" of \"position\". Line number 1.");
1498
1499 st->finished_correctly = true;
1500}
1501
1502static void
1503test_prefix_elem(void **state)
1504{
1505 struct state *st = *state;
1506 const char *data;
1507 const char *value = NULL;
1508
1509 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
1510 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
1511 assert_string_equal(value, "pref");
1512 FREE_STRING(st->ctx, value);
1513
1514 st->finished_correctly = true;
1515}
1516
1517static void
1518test_range_elem(void **state)
1519{
1520 struct state *st = *state;
1521 const char *data;
1522 struct lysp_type type = {};
1523
1524 /* max subelems */
1525 data = ELEMENT_WRAPPER_START
1526 "<range value=\"range-str\">"
1527 "<error-message><value>err-msg</value></error-message>"
1528 "<error-app-tag value=\"err-app-tag\" />"
1529 "<description><text>desc</text></description>"
1530 "<reference><text>ref</text></reference>"
1531 "</range>"
1532 ELEMENT_WRAPPER_END;
1533 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1534 assert_string_equal(type.range->arg, "range-str");
1535 assert_string_equal(type.range->dsc, "desc");
1536 assert_string_equal(type.range->eapptag, "err-app-tag");
1537 assert_string_equal(type.range->emsg, "err-msg");
1538 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001539 assert_true(type.flags & LYS_SET_RANGE);
David Sedlák69f01612019-07-17 11:41:08 +02001540 lysp_type_free(st->ctx, &type);
1541 memset(&type, 0, sizeof(type));
1542
1543 /* min subelems */
1544 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
1545 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1546 assert_string_equal(type.range->arg, "range-str");
1547 lysp_type_free(st->ctx, &type);
1548 memset(&type, 0, sizeof(type));
1549
1550 st->finished_correctly = true;
1551}
1552
1553static void
1554test_reqinstance_elem(void **state)
1555{
1556 struct state *st = *state;
1557 const char *data;
1558 struct lysp_type type = {};
1559
1560 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\"/>" ELEMENT_WRAPPER_END;
1561 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1562 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001563 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001564 memset(&type, 0, sizeof(type));
1565
1566 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
1567 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1568 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001569 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001570 memset(&type, 0, sizeof(type));
1571
1572 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1573 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1574 memset(&type, 0, sizeof(type));
1575 logbuf_assert("Invalid value \"invalid\" of \"require-instance\". Line number 1.");
1576
1577 st->finished_correctly = true;
1578}
1579
1580static void
1581test_revision_date_elem(void **state)
1582{
1583 struct state *st = *state;
1584 const char *data;
1585 char rev[LY_REV_SIZE];
1586
1587 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
1588 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS);
1589 assert_string_equal(rev, "2000-01-01");
1590
1591 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
1592 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID);
1593 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1594
1595 st->finished_correctly = true;
1596}
1597
1598static void
1599test_unique_elem(void **state)
1600{
1601 struct state *st = *state;
1602 const char *data;
1603 const char **values = NULL;
1604
1605 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
1606 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1607 assert_string_equal(*values, "tag");
1608 FREE_STRING(st->ctx, *values);
1609 LY_ARRAY_FREE(values);
1610
1611 st->finished_correctly = true;
1612}
1613
1614static void
1615test_units_elem(void **state)
1616{
1617 struct state *st = *state;
1618 const char *data;
1619 const char *values = NULL;
1620
1621 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
1622 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1623 assert_string_equal(values, "name");
1624 FREE_STRING(st->ctx, values);
1625
1626 st->finished_correctly = true;
1627}
1628
1629static void
1630test_when_elem(void **state)
1631{
1632 struct state *st = *state;
1633 const char *data;
1634 struct lysp_when *when = NULL;
1635
1636 data = ELEMENT_WRAPPER_START
1637 "<when condition=\"cond\">"
1638 "<description><text>desc</text></description>"
1639 "<reference><text>ref</text></reference>"
1640 "</when>"
1641 ELEMENT_WRAPPER_END;
1642 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
1643 assert_string_equal(when->cond, "cond");
1644 assert_string_equal(when->dsc, "desc");
1645 assert_string_equal(when->ref, "ref");
1646 lysp_when_free(st->ctx, when);
1647 free(when);
1648 when = NULL;
1649
1650 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
1651 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
1652 assert_string_equal(when->cond, "cond");
1653 lysp_when_free(st->ctx, when);
1654 free(when);
1655 when = NULL;
1656
1657 st->finished_correctly = true;
1658}
1659
1660static void
1661test_yin_text_value_elem(void **state)
1662{
1663 struct state *st = *state;
1664 const char *data;
1665 const char *val;
1666
1667 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
1668 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1669 assert_string_equal(val, "text");
1670 FREE_STRING(st->ctx, val);
1671
1672 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
1673 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1674 assert_string_equal(val, "text");
1675 FREE_STRING(st->ctx, val);
1676
1677 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
1678 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1679 assert_string_equal("", val);
1680 FREE_STRING(st->ctx, val);
1681
David Sedlák8e7bda82019-07-16 17:57:50 +02001682 st->finished_correctly = true;
1683}
David Sedlák32488102019-07-15 17:44:10 +02001684
David Sedlák374d2b32019-07-17 15:06:55 +02001685static void
1686test_type_elem(void **state)
1687{
1688 struct state *st = *state;
1689 const char *data;
1690 struct lysp_type type = {};
1691
1692 /* max subelems */
1693 data = ELEMENT_WRAPPER_START
1694 "<type name=\"type-name\">"
1695 "<base name=\"base-name\"/>"
1696 "<bit name=\"bit\"/>"
1697 "<enum name=\"enum\"/>"
1698 "<fraction-digits value=\"2\"/>"
1699 "<length value=\"length\"/>"
1700 "<path value=\"path\"/>"
1701 "<pattern value=\"pattern\"/>"
1702 "<range value=\"range\" />"
1703 "<require-instance value=\"true\"/>"
1704 "<type name=\"sub-type-name\"/>"
1705 "</type>"
1706 ELEMENT_WRAPPER_END;
1707 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1708 assert_string_equal(type.name, "type-name");
1709 assert_string_equal(*type.bases, "base-name");
1710 assert_string_equal(type.bits->name, "bit");
1711 assert_string_equal(type.enums->name, "enum");
1712 assert_int_equal(type.fraction_digits, 2);
1713 assert_string_equal(type.length->arg, "length");
1714 assert_string_equal(type.path, "path");
1715 assert_string_equal(type.patterns->arg, "\006pattern");
1716 assert_string_equal(type.range->arg, "range");
1717 assert_int_equal(type.require_instance, 1);
1718 assert_string_equal(type.types->name, "sub-type-name");
1719 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001720 assert_true(type.flags & LYS_SET_BASE);
1721 assert_true(type.flags & LYS_SET_BIT);
1722 assert_true(type.flags & LYS_SET_ENUM);
1723 assert_true(type.flags & LYS_SET_FRDIGITS);
1724 assert_true(type.flags & LYS_SET_LENGTH);
1725 assert_true(type.flags & LYS_SET_PATH);
1726 assert_true(type.flags & LYS_SET_PATTERN);
1727 assert_true(type.flags & LYS_SET_RANGE);
1728 assert_true(type.flags & LYS_SET_REQINST);
1729 assert_true(type.flags & LYS_SET_TYPE);
David Sedlák374d2b32019-07-17 15:06:55 +02001730 memset(&type, 0, sizeof(type));
1731
1732 /* min subelems */
1733 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
1734 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1735 lysp_type_free(st->ctx, &type);
1736 memset(&type, 0, sizeof(type));
1737
1738 st->finished_correctly = true;
1739}
1740
David Sedlák1af868e2019-07-17 17:03:14 +02001741static void
1742test_max_elems_elem(void **state)
1743{
1744 struct state *st = *state;
1745 const char *data;
1746 struct lysp_node_list list = {};
1747 struct lysp_node_leaflist llist = {};
1748 struct lysp_refine refine = {};
1749
1750 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\"/> </refine>";
1751 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1752 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001753 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001754
1755 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\"/> </list>";
1756 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
1757 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001758 assert_true(list.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001759
1760 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\"/> </leaf-list>";
1761 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
1762 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001763 assert_true(llist.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001764
1765 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
1766 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1767 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001768 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001769
1770 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
1771 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1772 logbuf_assert("Invalid value \"0\" of \"max-elements\". Line number 1.");
1773
1774 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
1775 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1776 logbuf_assert("Invalid value \"-10\" of \"max-elements\". Line number 1.");
1777
1778 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
1779 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1780 logbuf_assert("Invalid value \"k\" of \"max-elements\". Line number 1.");
1781
1782 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
1783 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1784 logbuf_assert("Invalid value \"u12\" of \"max-elements\". Line number 1.");
1785
1786 st->finished_correctly = true;
1787}
1788
David Sedlák09e18c92019-07-18 11:17:11 +02001789static void
1790test_min_elems_elem(void **state)
1791{
1792 struct state *st = *state;
1793 const char *data;
1794 struct lysp_node_list list = {};
1795 struct lysp_node_leaflist llist = {};
1796 struct lysp_refine refine = {};
1797
1798 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\"/> </refine>";
1799 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1800 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001801 assert_true(refine.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001802
1803 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\"/> </list>";
1804 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
1805 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001806 assert_true(list.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001807
1808 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\"/> </leaf-list>";
1809 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
1810 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001811 assert_true(llist.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001812
1813 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
1814 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1815 logbuf_assert("Value \"-5\" is out of \"min-elements\" bounds. Line number 1.");
1816
1817 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
1818 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1819 logbuf_assert("Value \"99999999999999999\" is out of \"min-elements\" bounds. Line number 1.");
1820
1821 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
1822 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1823 logbuf_assert("Invalid value \"5k\" of \"min-elements\". Line number 1.");
1824
1825 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
1826 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1827 logbuf_assert("Invalid value \"05\" of \"min-elements\". Line number 1.");
1828
1829 st->finished_correctly = true;
1830}
1831
David Sedláka2dad212019-07-18 12:45:19 +02001832static void
1833test_ordby_elem(void **state)
1834{
1835 struct state *st = *state;
1836 const char *data;
1837 uint16_t flags = 0;
1838
1839 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\"/>" ELEMENT_WRAPPER_END;
1840 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001841 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláka2dad212019-07-18 12:45:19 +02001842
1843 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
1844 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001845 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001846
1847 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
1848 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
1849 logbuf_assert("Invalid value \"inv\" of \"ordered-by\". Line number 1.");
1850
1851 st->finished_correctly = true;
1852}
1853
David Sedlák8a83bbb2019-07-18 14:46:00 +02001854static void
1855test_any_elem(void **state)
1856{
1857 struct state *st = *state;
1858 const char *data;
1859 struct lysp_node *siblings = NULL;
1860 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1861 struct lysp_node_anydata *parsed = NULL;
1862
1863 /* anyxml max subelems */
1864 data = ELEMENT_WRAPPER_START
1865 "<anyxml name=\"any-name\">"
1866 "<config value=\"true\" />"
1867 "<description><text>desc</text></description>"
1868 "<if-feature name=\"feature\" />"
1869 "<mandatory value=\"true\" />"
1870 "<must condition=\"must-cond\" />"
1871 "<reference><text>ref</text></reference>"
1872 "<status value=\"deprecated\"/>"
1873 "<when condition=\"when-cond\"/>"
1874 "</anyxml>"
1875 ELEMENT_WRAPPER_END;
1876 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1877 parsed = (struct lysp_node_anydata *)siblings;
1878 assert_null(parsed->parent);
1879 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001880 assert_true(parsed->flags & LYS_CONFIG_W);
1881 assert_true(parsed->flags & LYS_MAND_TRUE);
1882 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001883 assert_null(parsed->next);
1884 assert_string_equal(parsed->name, "any-name");
1885 assert_string_equal(parsed->dsc, "desc");
1886 assert_string_equal(parsed->ref, "ref");
1887 assert_string_equal(parsed->when->cond, "when-cond");
1888 assert_string_equal(*parsed->iffeatures, "feature");
1889 assert_null(parsed->exts);
1890 lysp_node_free(st->ctx, siblings);
1891 siblings = NULL;
1892
1893 /* anydata max subelems */
1894 data = ELEMENT_WRAPPER_START
1895 "<anydata name=\"any-name\">"
1896 "<config value=\"true\" />"
1897 "<description><text>desc</text></description>"
1898 "<if-feature name=\"feature\" />"
1899 "<mandatory value=\"true\" />"
1900 "<must condition=\"must-cond\" />"
1901 "<reference><text>ref</text></reference>"
1902 "<status value=\"deprecated\"/>"
1903 "<when condition=\"when-cond\"/>"
1904 "</anydata>"
1905 ELEMENT_WRAPPER_END;
1906 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1907 parsed = (struct lysp_node_anydata *)siblings;
1908 assert_null(parsed->parent);
1909 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001910 assert_true(parsed->flags & LYS_CONFIG_W);
1911 assert_true(parsed->flags & LYS_MAND_TRUE);
1912 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001913 assert_null(parsed->next);
1914 assert_string_equal(parsed->name, "any-name");
1915 assert_string_equal(parsed->dsc, "desc");
1916 assert_string_equal(parsed->ref, "ref");
1917 assert_string_equal(parsed->when->cond, "when-cond");
1918 assert_string_equal(*parsed->iffeatures, "feature");
1919 assert_null(parsed->exts);
1920 lysp_node_free(st->ctx, siblings);
1921 siblings = NULL;
1922
1923 /* min subelems */
1924 node_meta.parent = (void *)0x10;
1925 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
1926 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1927 parsed = (struct lysp_node_anydata *)siblings;
1928 assert_ptr_equal(parsed->parent, node_meta.parent);
1929 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
1930 assert_null(parsed->next);
1931 assert_null(parsed->exts);
1932 lysp_node_free(st->ctx, siblings);
1933
1934 st->finished_correctly = true;
1935}
1936
David Sedlák203ca3a2019-07-18 15:26:25 +02001937static void
1938test_leaf_elem(void **state)
1939{
1940 struct state *st = *state;
1941 const char *data;
1942 struct lysp_node *siblings = NULL;
1943 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1944 struct lysp_node_leaf *parsed = NULL;
1945
1946 /* max elements */
1947 data = ELEMENT_WRAPPER_START
1948 "<leaf name=\"leaf\">"
1949 "<config value=\"true\" />"
1950 "<default value=\"def-val\"/>"
1951 "<description><text>desc</text></description>"
1952 "<if-feature name=\"feature\" />"
1953 "<mandatory value=\"true\" />"
1954 "<must condition=\"must-cond\" />"
1955 "<reference><text>ref</text></reference>"
1956 "<status value=\"deprecated\"/>"
1957 "<type name=\"type\"/>"
1958 "<units name=\"uni\"/>"
1959 "<when condition=\"when-cond\"/>"
1960 "</leaf>"
1961 ELEMENT_WRAPPER_END;
1962 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1963 parsed = (struct lysp_node_leaf *)siblings;
1964 assert_null(parsed->parent);
1965 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001966 assert_true(parsed->flags & LYS_CONFIG_W);
1967 assert_true(parsed->flags & LYS_MAND_TRUE);
1968 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02001969 assert_null(parsed->next);
1970 assert_string_equal(parsed->name, "leaf");
1971 assert_string_equal(parsed->dsc, "desc");
1972 assert_string_equal(parsed->ref, "ref");
1973 assert_string_equal(parsed->when->cond, "when-cond");
1974 assert_string_equal(*parsed->iffeatures, "feature");
1975 assert_null(parsed->exts);
1976 assert_string_equal(parsed->musts->arg, "must-cond");
1977 assert_string_equal(parsed->type.name, "type");
1978 assert_string_equal(parsed->units, "uni");
1979 assert_string_equal(parsed->dflt, "def-val");
1980 lysp_node_free(st->ctx, siblings);
1981 siblings = NULL;
1982
1983 /* min elements */
1984 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
1985 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1986 parsed = (struct lysp_node_leaf *)siblings;
1987 assert_string_equal(parsed->name, "leaf");
1988 assert_string_equal(parsed->type.name, "type");
1989 lysp_node_free(st->ctx, siblings);
1990 siblings = NULL;
1991
1992 st->finished_correctly = true;
1993}
1994
David Sedlákc3da3ef2019-07-19 12:56:08 +02001995static void
1996test_leaf_list_elem(void **state)
1997{
1998 struct state *st = *state;
1999 const char *data;
2000 struct lysp_node *siblings = NULL;
2001 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
2002 struct lysp_node_leaflist *parsed = NULL;
2003
2004 data = ELEMENT_WRAPPER_START
2005 "<leaf-list name=\"llist\">"
2006 "<config value=\"true\" />"
2007 "<default value=\"def-val0\"/>"
2008 "<default value=\"def-val1\"/>"
2009 "<description><text>desc</text></description>"
2010 "<if-feature name=\"feature\"/>"
2011 "<max-elements value=\"5\"/>"
2012 "<must condition=\"must-cond\"/>"
2013 "<ordered-by value=\"user\" />"
2014 "<reference><text>ref</text></reference>"
2015 "<status value=\"current\"/>"
2016 "<type name=\"type\"/>"
2017 "<units name=\"uni\"/>"
2018 "<when condition=\"when-cond\"/>"
2019 "</leaf-list>"
2020 ELEMENT_WRAPPER_END;
2021 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2022 parsed = (struct lysp_node_leaflist *)siblings;
2023 assert_string_equal(parsed->dflts[0], "def-val0");
2024 assert_string_equal(parsed->dflts[1], "def-val1");
2025 assert_string_equal(parsed->dsc, "desc");
2026 assert_string_equal(*parsed->iffeatures, "feature");
2027 assert_int_equal(parsed->max, 5);
2028 assert_string_equal(parsed->musts->arg, "must-cond");
2029 assert_string_equal(parsed->name, "llist");
2030 assert_null(parsed->next);
2031 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2032 assert_null(parsed->parent);
2033 assert_string_equal(parsed->ref, "ref");
2034 assert_string_equal(parsed->type.name, "type");
2035 assert_string_equal(parsed->units, "uni");
2036 assert_string_equal(parsed->when->cond, "when-cond");
2037 assert_true(parsed->flags & LYS_CONFIG_W);
2038 assert_true(parsed->flags & LYS_ORDBY_USER);
2039 assert_true(parsed->flags & LYS_STATUS_CURR);
2040 lysp_node_free(st->ctx, siblings);
2041 siblings = NULL;
2042
2043 data = ELEMENT_WRAPPER_START
2044 "<leaf-list name=\"llist\">"
2045 "<config value=\"true\" />"
2046 "<description><text>desc</text></description>"
2047 "<if-feature name=\"feature\"/>"
2048 "<min-elements value=\"5\"/>"
2049 "<must condition=\"must-cond\"/>"
2050 "<ordered-by value=\"user\" />"
2051 "<reference><text>ref</text></reference>"
2052 "<status value=\"current\"/>"
2053 "<type name=\"type\"/>"
2054 "<units name=\"uni\"/>"
2055 "<when condition=\"when-cond\"/>"
2056 "</leaf-list>"
2057 ELEMENT_WRAPPER_END;
2058 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2059 parsed = (struct lysp_node_leaflist *)siblings;
2060 assert_string_equal(parsed->dsc, "desc");
2061 assert_string_equal(*parsed->iffeatures, "feature");
2062 assert_int_equal(parsed->min, 5);
2063 assert_string_equal(parsed->musts->arg, "must-cond");
2064 assert_string_equal(parsed->name, "llist");
2065 assert_null(parsed->next);
2066 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2067 assert_null(parsed->parent);
2068 assert_string_equal(parsed->ref, "ref");
2069 assert_string_equal(parsed->type.name, "type");
2070 assert_string_equal(parsed->units, "uni");
2071 assert_string_equal(parsed->when->cond, "when-cond");
2072 assert_true(parsed->flags & LYS_CONFIG_W);
2073 assert_true(parsed->flags & LYS_ORDBY_USER);
2074 assert_true(parsed->flags & LYS_STATUS_CURR);
2075 lysp_node_free(st->ctx, siblings);
2076 siblings = NULL;
2077
2078 data = ELEMENT_WRAPPER_START
2079 "<leaf-list name=\"llist\">"
2080 "<config value=\"true\" />"
2081 "<description><text>desc</text></description>"
2082 "<if-feature name=\"feature\"/>"
2083 "<max-elements value=\"15\"/>"
2084 "<min-elements value=\"5\"/>"
2085 "<must condition=\"must-cond\"/>"
2086 "<ordered-by value=\"user\" />"
2087 "<reference><text>ref</text></reference>"
2088 "<status value=\"current\"/>"
2089 "<type name=\"type\"/>"
2090 "<units name=\"uni\"/>"
2091 "<when condition=\"when-cond\"/>"
2092 "</leaf-list>"
2093 ELEMENT_WRAPPER_END;
2094 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2095 parsed = (struct lysp_node_leaflist *)siblings;
2096 assert_string_equal(parsed->dsc, "desc");
2097 assert_string_equal(*parsed->iffeatures, "feature");
2098 assert_int_equal(parsed->min, 5);
2099 assert_int_equal(parsed->max, 15);
2100 assert_string_equal(parsed->musts->arg, "must-cond");
2101 assert_string_equal(parsed->name, "llist");
2102 assert_null(parsed->next);
2103 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2104 assert_null(parsed->parent);
2105 assert_string_equal(parsed->ref, "ref");
2106 assert_string_equal(parsed->type.name, "type");
2107 assert_string_equal(parsed->units, "uni");
2108 assert_string_equal(parsed->when->cond, "when-cond");
2109 assert_true(parsed->flags & LYS_CONFIG_W);
2110 assert_true(parsed->flags & LYS_ORDBY_USER);
2111 assert_true(parsed->flags & LYS_STATUS_CURR);
2112 lysp_node_free(st->ctx, siblings);
2113 siblings = NULL;
2114
2115 data = ELEMENT_WRAPPER_START
2116 "<leaf-list name=\"llist\">"
2117 "<type name=\"type\"/>"
2118 "</leaf-list>"
2119 ELEMENT_WRAPPER_END;
2120 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2121 parsed = (struct lysp_node_leaflist *)siblings;
2122 assert_string_equal(parsed->name, "llist");
2123 assert_string_equal(parsed->type.name, "type");
2124 lysp_node_free(st->ctx, siblings);
2125 siblings = NULL;
2126
2127 /* invalid combinations */
2128 data = ELEMENT_WRAPPER_START
2129 "<leaf-list name=\"llist\">"
2130 "<max-elements value=\"5\"/>"
2131 "<min-elements value=\"15\"/>"
2132 "<type name=\"type\"/>"
2133 "</leaf-list>"
2134 ELEMENT_WRAPPER_END;
2135 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2136 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2137 lysp_node_free(st->ctx, siblings);
2138 siblings = NULL;
2139
2140 data = ELEMENT_WRAPPER_START
2141 "<leaf-list name=\"llist\">"
2142 "<default value=\"def-val1\"/>"
2143 "<min-elements value=\"15\"/>"
2144 "<type name=\"type\"/>"
2145 "</leaf-list>"
2146 ELEMENT_WRAPPER_END;
2147 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2148 logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1.");
2149 lysp_node_free(st->ctx, siblings);
2150 siblings = NULL;
2151
2152 data = ELEMENT_WRAPPER_START
2153 "<leaf-list name=\"llist\">"
2154 "</leaf-list>"
2155 ELEMENT_WRAPPER_END;
2156 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2157 logbuf_assert("Missing mandatory subelement type of leaf-list element. Line number 1.");
2158 lysp_node_free(st->ctx, siblings);
2159 siblings = NULL;
2160
2161 st->finished_correctly = true;
2162}
2163
David Sedlákcb39f642019-07-19 13:19:55 +02002164static void
2165test_presence_elem(void **state)
2166{
2167 struct state *st = *state;
2168 const char *data;
2169 const char *val;
2170
2171 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
2172 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2173 assert_string_equal(val, "presence-val");
2174 FREE_STRING(st->ctx, val);
2175
2176 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
2177 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2178 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2179
2180 st->finished_correctly = true;
2181}
2182
David Sedlák12470a82019-07-19 13:44:36 +02002183static void
2184test_key_elem(void **state)
2185{
2186 struct state *st = *state;
2187 const char *data;
2188 const char *val;
2189
2190 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
2191 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2192 assert_string_equal(val, "key-value");
2193 FREE_STRING(st->ctx, val);
2194
2195 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
2196 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2197 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2198
2199 st->finished_correctly = true;
2200}
2201
David Sedlák04e17b22019-07-19 15:29:48 +02002202static void
2203test_typedef_elem(void **state)
2204{
2205 struct state *st = *state;
2206 const char *data;
2207 struct lysp_tpdf *tpdfs = NULL;
2208 struct typedef_meta typdef_meta = {NULL, &tpdfs};
2209
2210 data = ELEMENT_WRAPPER_START
2211 "<typedef name=\"tpdf-name\">"
2212 "<default value=\"def-val\"/>"
2213 "<description><text>desc-text</text></description>"
2214 "<reference><text>ref-text</text></reference>"
2215 "<status value=\"current\"/>"
2216 "<type name=\"type\"/>"
2217 "<units name=\"uni\"/>"
2218 "</typedef>"
2219 ELEMENT_WRAPPER_END;
2220 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2221 assert_string_equal(tpdfs[0].dflt, "def-val");
2222 assert_string_equal(tpdfs[0].dsc, "desc-text");
2223 assert_null(tpdfs[0].exts);
2224 assert_string_equal(tpdfs[0].name, "tpdf-name");
2225 assert_string_equal(tpdfs[0].ref, "ref-text");
2226 assert_string_equal(tpdfs[0].type.name, "type");
2227 assert_string_equal(tpdfs[0].units, "uni");
2228 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
2229 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2230 tpdfs = NULL;
2231
2232 data = ELEMENT_WRAPPER_START
2233 "<typedef name=\"tpdf-name\">"
2234 "<type name=\"type\"/>"
2235 "</typedef>"
2236 ELEMENT_WRAPPER_END;
2237 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2238 assert_string_equal(tpdfs[0].name, "tpdf-name");
2239 assert_string_equal(tpdfs[0].type.name, "type");
2240 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2241 tpdfs = NULL;
2242
2243 st->finished_correctly = true;
2244}
2245
David Sedlákd2d676a2019-07-22 11:28:19 +02002246static void
2247test_refine_elem(void **state)
2248{
2249 struct state *st = *state;
2250 const char *data;
2251 struct lysp_refine *refines = NULL;
2252
2253 /* max subelems */
2254 data = ELEMENT_WRAPPER_START
2255 "<refine target-node=\"target\">"
2256 "<if-feature name=\"feature\" />"
2257 "<must condition=\"cond\" />"
2258 "<presence value=\"presence\" />"
2259 "<default value=\"def\" />"
2260 "<config value=\"true\" />"
2261 "<mandatory value=\"true\" />"
2262 "<min-elements value=\"10\" />"
2263 "<max-elements value=\"20\" />"
2264 "<description><text>desc</text></description>"
2265 "<reference><text>ref</text></reference>"
2266 "</refine>"
2267 ELEMENT_WRAPPER_END;
2268 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2269 assert_string_equal(refines->nodeid, "target");
2270 assert_string_equal(*refines->dflts, "def");
2271 assert_string_equal(refines->dsc, "desc");
2272 assert_null(refines->exts);
2273 assert_true(refines->flags & LYS_CONFIG_W);
2274 assert_true(refines->flags & LYS_MAND_TRUE);
2275 assert_string_equal(*refines->iffeatures, "feature");
2276 assert_int_equal(refines->max, 20);
2277 assert_int_equal(refines->min, 10);
2278 assert_string_equal(refines->musts->arg, "cond");
2279 assert_string_equal(refines->presence, "presence");
2280 assert_string_equal(refines->ref, "ref");
2281 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2282 refines = NULL;
2283
2284 /* min subelems */
2285 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
2286 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2287 assert_string_equal(refines->nodeid, "target");
2288 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2289 refines = NULL;
2290
2291 st->finished_correctly = true;
2292}
2293
David Sedlák0d6de5a2019-07-22 13:25:44 +02002294static void
2295test_uses_elem(void **state)
2296{
2297 struct state *st = *state;
2298 const char *data;
2299 struct lysp_node *siblings = NULL;
2300 struct tree_node_meta node_meta = {NULL, &siblings};
2301 struct lysp_node_uses *parsed = NULL;
2302
2303 /* max subelems */
2304 data = ELEMENT_WRAPPER_START
2305 "<uses name=\"uses-name\">"
2306 "<when condition=\"cond\" />"
2307 "<if-feature name=\"feature\" />"
2308 "<status value=\"obsolete\" />"
2309 "<description><text>desc</text></description>"
2310 "<reference><text>ref</text></reference>"
2311 "<refine target-node=\"target\"/>"
2312 /* TODO add uses-augment-stmt instance */
2313 "</uses>"
2314 ELEMENT_WRAPPER_END;
2315 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2316 parsed = (struct lysp_node_uses *)&siblings[0];
2317 assert_string_equal(parsed->name, "uses-name");
2318 assert_string_equal(parsed->dsc, "desc");
2319 assert_null(parsed->exts);
2320 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2321 assert_string_equal(*parsed->iffeatures, "feature");
2322 assert_null(parsed->next);
2323 assert_int_equal(parsed->nodetype, LYS_USES);
2324 assert_null(parsed->parent);
2325 assert_string_equal(parsed->ref, "ref");
2326 assert_string_equal(parsed->refines->nodeid, "target");
2327 assert_string_equal(parsed->when->cond, "cond");
2328 lysp_node_free(st->ctx, siblings);
2329 siblings = NULL;
2330
2331 /* min subelems */
2332 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
2333 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2334 assert_string_equal(siblings[0].name, "uses-name");
2335 lysp_node_free(st->ctx, siblings);
2336 siblings = NULL;
2337
2338 st->finished_correctly = true;
2339}
2340
David Sedlákaa854b02019-07-22 14:17:10 +02002341static void
2342test_revision_elem(void **state)
2343{
2344 struct state *st = *state;
2345 const char *data;
2346 struct lysp_revision *revs = NULL;
2347
2348 /* max subelems */
2349 data = ELEMENT_WRAPPER_START
2350 "<revision date=\"2018-12-25\">"
2351 "<description><text>desc</text></description>"
2352 "<reference><text>ref</text></reference>"
2353 "</revision>"
2354 ELEMENT_WRAPPER_END;
2355 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2356 assert_string_equal(revs->date, "2018-12-25");
2357 assert_string_equal(revs->dsc, "desc");
2358 assert_string_equal(revs->ref, "ref");
2359 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2360 revs = NULL;
2361
2362 /* min subelems */
2363 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
2364 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2365 assert_string_equal(revs->date, "2005-05-05");
2366 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2367 revs = NULL;
2368
2369 /* invalid value */
2370 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
2371 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID);
2372 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2373 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2374 revs = NULL;
2375
2376 st->finished_correctly = true;
2377}
2378
David Sedlák0c2bab92019-07-22 15:33:19 +02002379static void
2380test_include_elem(void **state)
2381{
2382 struct state *st = *state;
2383 const char *data;
2384 struct lysp_include *includes = NULL;
2385 struct include_meta inc_meta = {"module-name", &includes};
2386
2387 /* max subelems */
2388 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2389 data = ELEMENT_WRAPPER_START
2390 "<include module=\"mod\">"
2391 "<description><text>desc</text></description>"
2392 "<reference><text>ref</text></reference>"
2393 "<revision-date date=\"1999-09-09\"/>"
2394 "</include>"
2395 ELEMENT_WRAPPER_END;
2396 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2397 assert_string_equal(includes->name, "mod");
2398 assert_string_equal(includes->dsc, "desc");
2399 assert_string_equal(includes->ref, "ref");
2400 assert_null(includes->exts);
2401 assert_string_equal(includes->rev, "1999-09-09");
2402 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2403 includes = NULL;
2404
2405 /* min subelems */
2406 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
2407 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2408 assert_string_equal(includes->name, "mod");
2409 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2410 includes = NULL;
2411
2412 /* invalid combinations */
2413 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2414 data = ELEMENT_WRAPPER_START
2415 "<include module=\"mod\">"
2416 "<description><text>desc</text></description>"
2417 "<revision-date date=\"1999-09-09\"/>"
2418 "</include>"
2419 ELEMENT_WRAPPER_END;
2420 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2421 logbuf_assert("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
2422 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2423 includes = NULL;
2424
2425 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2426 data = ELEMENT_WRAPPER_START
2427 "<include module=\"mod\">"
2428 "<reference><text>ref</text></reference>"
2429 "<revision-date date=\"1999-09-09\"/>"
2430 "</include>"
2431 ELEMENT_WRAPPER_END;
2432 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2433 logbuf_assert("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
2434 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2435 includes = NULL;
2436
2437 st->finished_correctly = true;
2438}
2439
David Sedlák5e13dea2019-07-22 16:06:45 +02002440static void
2441test_feature_elem(void **state)
2442{
2443 struct state *st = *state;
2444 const char *data;
2445 struct lysp_feature *features = NULL;
2446
2447 /* max subelems */
2448 data = ELEMENT_WRAPPER_START
2449 "<feature name=\"feature-name\">"
2450 "<if-feature name=\"iff\"/>"
2451 "<status value=\"deprecated\"/>"
2452 "<description><text>desc</text></description>"
2453 "<reference><text>ref</text></reference>"
2454 "</feature>"
2455 ELEMENT_WRAPPER_END;
2456 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2457 assert_string_equal(features->name, "feature-name");
2458 assert_string_equal(features->dsc, "desc");
2459 assert_null(features->exts);
2460 assert_true(features->flags & LYS_STATUS_DEPRC);
2461 assert_string_equal(*features->iffeatures, "iff");
2462 assert_string_equal(features->ref, "ref");
2463 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2464 features = NULL;
2465
2466 /* min subelems */
2467 data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
2468 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2469 assert_string_equal(features->name, "feature-name");
2470 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2471 features = NULL;
2472
2473 st->finished_correctly = true;
2474}
2475
David Sedlák28794f22019-07-22 16:45:00 +02002476static void
2477test_identity_elem(void **state)
2478{
2479 struct state *st = *state;
2480 const char *data;
2481 struct lysp_ident *identities = NULL;
2482
2483 /* max subelems */
2484 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2485 data = ELEMENT_WRAPPER_START
2486 "<identity name=\"ident-name\">"
2487 "<if-feature name=\"iff\"/>"
2488 "<base name=\"base-name\"/>"
2489 "<status value=\"deprecated\"/>"
2490 "<description><text>desc</text></description>"
2491 "<reference><text>ref</text></reference>"
2492 "</identity>"
2493 ELEMENT_WRAPPER_END;
2494 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2495 assert_string_equal(identities->name, "ident-name");
2496 assert_string_equal(*identities->bases, "base-name");
2497 assert_string_equal(*identities->iffeatures, "iff");
2498 assert_string_equal(identities->dsc, "desc");
2499 assert_string_equal(identities->ref, "ref");
2500 assert_true(identities->flags & LYS_STATUS_DEPRC);
2501 assert_null(identities->exts);
2502 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2503 identities = NULL;
2504
2505 /* min subelems */
2506 data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END;
2507 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2508 assert_string_equal(identities->name, "ident-name");
2509 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2510 identities = NULL;
2511
2512 /* invalid */
2513 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2514 data = ELEMENT_WRAPPER_START
2515 "<identity name=\"ident-name\">"
2516 "<if-feature name=\"iff\"/>"
2517 "</identity>"
2518 ELEMENT_WRAPPER_END;
2519 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID);
2520 logbuf_assert("Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
2521 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2522 identities = NULL;
2523
2524 st->finished_correctly = true;
2525}
2526
David Sedlákaf536aa2019-07-23 13:42:23 +02002527static void
2528test_list_elem(void **state)
2529{
2530 struct state *st = *state;
2531 const char *data;
2532 struct lysp_node *siblings = NULL;
2533 struct tree_node_meta node_meta = {NULL, &siblings};
2534 struct lysp_node_list *parsed = NULL;
2535
2536 /* max subelems */
2537 data = ELEMENT_WRAPPER_START
2538 "<list name=\"list-name\">"
2539 "<when condition=\"when\"/>"
2540 "<if-feature name=\"iff\"/>"
2541 "<must condition=\"must-cond\"/>"
2542 "<key value=\"key\"/>"
2543 "<unique tag=\"utag\"/>"
2544 "<config value=\"true\"/>"
2545 "<min-elements value=\"10\"/>"
2546 "<ordered-by value=\"user\"/>"
2547 "<status value=\"deprecated\"/>"
2548 "<description><text>desc</text></description>"
2549 "<reference><text>ref</text></reference>"
2550 "<anydata name=\"anyd\"/>"
2551 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002552 "<container name=\"cont\"/>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002553 // "<choice name=\"choice\"/>"
2554 // "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002555 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002556 "<notification name=\"notf\"/>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002557 "<leaf name=\"leaf\"/>"
2558 "<leaf-list name=\"llist\"/>"
2559 "<list name=\"sub-list\"/>"
2560 "<typedef name=\"tpdf\"/>"
2561 "<uses name=\"uses-name\"/>"
2562 "</list>"
2563 ELEMENT_WRAPPER_END;
2564 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2565 parsed = (struct lysp_node_list *)&siblings[0];
2566 assert_string_equal(parsed->dsc, "desc");
2567 assert_string_equal(parsed->child->name, "anyd");
2568 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2569 assert_string_equal(parsed->child->next->name, "anyx");
2570 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002571 assert_string_equal(parsed->child->next->next->name, "cont");
2572 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2573 // assert_string_equal(parsed->child->next->next->next->name, "choice");
2574 // assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2575 // assert_string_equal(parsed->child->next->next->next->next->name, "action");
2576 // assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_ACTION);
2577 // assert_null(parsed->child->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002578 assert_string_equal(parsed->groupings->name, "grp");
2579 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002580 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02002581 assert_null(parsed->exts);
2582 assert_true(parsed->flags & LYS_ORDBY_USER);
2583 assert_true(parsed->flags & LYS_STATUS_DEPRC);
2584 assert_true(parsed->flags & LYS_CONFIG_W);
2585 assert_string_equal(*parsed->iffeatures, "iff");
2586 assert_string_equal(parsed->key, "key");
2587 assert_int_equal(parsed->min, 10);
2588 assert_string_equal(parsed->musts->arg, "must-cond");
2589 assert_string_equal(parsed->name, "list-name");
2590 assert_null(parsed->next);
2591 assert_int_equal(parsed->nodetype, LYS_LIST);
2592 assert_null(parsed->parent);
2593 assert_string_equal(parsed->ref, "ref");
2594 assert_string_equal(parsed->typedefs->name, "tpdf");
2595 assert_string_equal(*parsed->uniques, "utag");
2596 assert_string_equal(parsed->when->cond, "when");
2597 lysp_node_free(st->ctx, siblings);
2598 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2599 siblings = NULL;
2600
2601 /* min subelems */
2602 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
2603 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2604 parsed = (struct lysp_node_list *)&siblings[0];
2605 assert_string_equal(parsed->name, "list-name");
2606 lysp_node_free(st->ctx, siblings);
2607 siblings = NULL;
2608
2609 st->finished_correctly = true;
2610}
2611
David Sedlák031b9e72019-07-23 15:19:37 +02002612static void
2613test_notification_elem(void **state)
2614{
2615 struct state *st = *state;
2616 const char *data;
2617 struct lysp_notif *notifs = NULL;
2618 struct notif_meta notif_meta = {NULL, &notifs};
2619
2620 /* max subelems */
2621 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2622 data = ELEMENT_WRAPPER_START
2623 "<notification name=\"notif-name\">"
2624 "<anydata name=\"anyd\"/>"
2625 "<anyxml name=\"anyx\"/>"
2626 "<description><text>desc</text></description>"
2627 "<if-feature name=\"iff\"/>"
2628 "<leaf name=\"leaf\"/>"
2629 "<leaf-list name=\"llist\"/>"
2630 "<list name=\"sub-list\"/>"
2631 "<must condition=\"cond\"/>"
2632 "<reference><text>ref</text></reference>"
2633 "<status value=\"deprecated\"/>"
2634 "<typedef name=\"tpdf\"/>"
2635 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002636 "<container name=\"cont\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002637 // "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002638 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002639 "</notification>"
2640 ELEMENT_WRAPPER_END;
2641 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
2642 assert_string_equal(notifs->name, "notif-name");
2643 assert_string_equal(notifs->data->name, "anyd");
2644 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
2645 assert_string_equal(notifs->data->next->name, "anyx");
2646 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
2647 assert_string_equal(notifs->data->next->next->name, "leaf");
2648 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
2649 assert_string_equal(notifs->data->next->next->next->name, "llist");
2650 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
2651 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
2652 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
2653 assert_null(notifs->exts);
2654 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002655 assert_string_equal(notifs->groupings->name, "grp");
2656 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02002657 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
2658 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
2659 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
2660 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2661 // assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2662 // assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
2663 // assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02002664 assert_string_equal(*notifs->iffeatures, "iff");
2665 assert_string_equal(notifs->musts->arg, "cond");
2666 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2667 assert_null(notifs->parent);
2668 assert_string_equal(notifs->ref, "ref");
2669 assert_string_equal(notifs->typedefs->name, "tpdf");
2670 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
2671 notifs = NULL;
2672
2673 /* min subelems */
2674 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
2675 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
2676 assert_string_equal(notifs->name, "notif-name");
2677 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002678 notifs = NULL;
2679
2680 st->finished_correctly = true;
2681}
2682
2683static void
2684test_grouping_elem(void **state)
2685{
2686 struct state *st = *state;
2687 const char *data;
2688 struct lysp_grp *grps = NULL;
2689 struct grouping_meta grp_meta = {NULL, &grps};
2690
2691 /* max subelems */
2692 data = ELEMENT_WRAPPER_START
2693 "<grouping name=\"grp-name\">"
2694 "<anydata name=\"anyd\"/>"
2695 "<anyxml name=\"anyx\"/>"
2696 "<description><text>desc</text></description>"
2697 "<grouping name=\"sub-grp\"/>"
2698 "<leaf name=\"leaf\"/>"
2699 "<leaf-list name=\"llist\"/>"
2700 "<list name=\"list\"/>"
2701 "<notification name=\"notf\"/>"
2702 "<reference><text>ref</text></reference>"
2703 "<status value=\"current\"/>"
2704 "<typedef name=\"tpdf\"/>"
2705 "<uses name=\"uses-name\"/>"
2706 // "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002707 "<container name=\"cont\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002708 // "<choice name=\"choice\"/>"
2709 "</grouping>"
2710 ELEMENT_WRAPPER_END;
2711 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
2712 assert_string_equal(grps->name, "grp-name");
2713 // assert_string_equal(grps->actions->name, "act");
2714 assert_string_equal(grps->data->name, "anyd");
2715 assert_string_equal(grps->data->next->name, "anyx");
2716 assert_string_equal(grps->data->next->next->name, "leaf");
2717 assert_string_equal(grps->data->next->next->next->name, "llist");
2718 assert_string_equal(grps->data->next->next->next->next->name, "list");
2719 assert_string_equal(grps->dsc, "desc");
2720 assert_null(grps->exts);
2721 assert_true(grps->flags & LYS_STATUS_CURR);
2722 assert_string_equal(grps->groupings->name, "sub-grp");
2723 assert_int_equal(grps->nodetype, LYS_GROUPING);
2724 assert_string_equal(grps->notifs->name, "notf");
2725 assert_null(grps->parent);
2726 assert_string_equal(grps->ref, "ref");
2727 assert_string_equal(grps->typedefs->name, "tpdf");
2728 // assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02002729 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
2730 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002731 // assert_string_equal(grps->data->next->next->next->next->next->next->name, "choice");
2732 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
2733 grps = NULL;
2734
2735 /* min subelems */
2736 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
2737 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
2738 assert_string_equal(grps->name, "grp-name");
2739 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
2740 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002741
2742 st->finished_correctly = true;
2743}
2744
David Sedlákf111bcb2019-07-23 17:15:51 +02002745static void
2746test_container_elem(void **state)
2747{
2748 struct state *st = *state;
2749 const char *data;
2750 struct lysp_node *siblings = NULL;
2751 struct tree_node_meta node_meta = {NULL, &siblings};
2752 struct lysp_node_container *parsed = NULL;
2753
2754 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02002755 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2756 data = ELEMENT_WRAPPER_START
2757 "<container name=\"cont-name\">"
2758 "<anydata name=\"anyd\"/>"
2759 "<anyxml name=\"anyx\"/>"
2760 "<config value=\"true\"/>"
2761 "<container name=\"subcont\"/>"
2762 "<description><text>desc</text></description>"
2763 "<grouping name=\"sub-grp\"/>"
2764 "<if-feature name=\"iff\"/>"
2765 "<leaf name=\"leaf\"/>"
2766 "<leaf-list name=\"llist\"/>"
2767 "<list name=\"list\"/>"
2768 "<must condition=\"cond\"/>"
2769 "<notification name=\"notf\"/>"
2770 "<presence value=\"presence\"/>"
2771 "<reference><text>ref</text></reference>"
2772 "<status value=\"current\"/>"
2773 "<typedef name=\"tpdf\"/>"
2774 "<uses name=\"uses-name\"/>"
2775 "<when condition=\"when-cond\"/>"
2776 // "<action name=\"act\"/>"
2777 // "<choice name=\"choice\"/>"
2778 "</container>"
2779 ELEMENT_WRAPPER_END;
2780 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2781 parsed = (struct lysp_node_container *)siblings;
2782 assert_string_equal(parsed->name, "cont-name");
2783 assert_null(parsed->parent);
2784 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
2785 assert_true(parsed->flags & LYS_CONFIG_W);
2786 assert_true(parsed->flags & LYS_STATUS_CURR);
2787 assert_null(parsed->next);
2788 assert_string_equal(parsed->dsc, "desc");
2789 assert_string_equal(parsed->ref, "ref");
2790 assert_string_equal(parsed->when->cond, "when-cond");
2791 assert_string_equal(*parsed->iffeatures, "iff");
2792 assert_null(parsed->exts);
2793 assert_string_equal(parsed->musts->arg, "cond");
2794 assert_string_equal(parsed->presence, "presence");
2795 assert_string_equal(parsed->typedefs->name, "tpdf");
2796 assert_string_equal(parsed->groupings->name, "sub-grp");
2797 assert_string_equal(parsed->child->name, "anyd");
2798 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2799 assert_string_equal(parsed->child->next->name, "anyx");
2800 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2801 assert_string_equal(parsed->child->next->next->name, "subcont");
2802 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2803 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2804 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2805 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2806 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2807 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2808 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2809 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2810 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
2811 // assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2812 // assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2813 // assert_null(parsed->child->next->next->next->next->next->next->next->next);
2814 assert_string_equal(parsed->notifs->name, "notf");
2815 //assert_string_equal(parsed->actions->name, "act");
2816 lysp_node_free(st->ctx, siblings);
2817 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2818 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002819
2820 /* min subelems */
2821 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
2822 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2823 parsed = (struct lysp_node_container *)siblings;
2824 assert_string_equal(parsed->name, "cont-name");
2825 lysp_node_free(st->ctx, siblings);
2826 siblings = NULL;
2827
2828 st->finished_correctly = true;
2829}
2830
David Sedlák3b4db242018-10-19 16:11:01 +02002831int
2832main(void)
2833{
2834
2835 const struct CMUnitTest tests[] = {
David Sedlák392af4f2019-06-04 16:02:42 +02002836 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f),
David Sedlák8f7a1172019-06-20 14:42:18 +02002837 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02002838 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
2839 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák555c7202019-07-04 12:14:12 +02002840 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02002841 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02002842
David Sedlák8e7bda82019-07-16 17:57:50 +02002843 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák32488102019-07-15 17:44:10 +02002844 cmocka_unit_test_setup_teardown(test_enum_bit_elem, setup_element_test, teardown_element_test),
2845 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
2846 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
2847 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
2848 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
2849 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
2850 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
2851 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02002852 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
2853 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
2854 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
2855 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
2856 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
2857 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
2858 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
2859 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
2860 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
2861 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
2862 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
2863 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
2864 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
2865 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
2866 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02002867 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
2868 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
2869 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
2870 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
2871 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
2872 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
2873 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
2874 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02002875 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02002876 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02002877 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02002878 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02002879 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02002880 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02002881 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02002882 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02002883 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02002884 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02002885 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02002886 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02002887 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02002888 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlák5e13dea2019-07-22 16:06:45 +02002889 cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
David Sedlák28794f22019-07-22 16:45:00 +02002890 cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02002891 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02002892 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02002893 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02002894 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02002895
David Sedlák3b4db242018-10-19 16:11:01 +02002896 };
2897
David Sedlák8e7bda82019-07-16 17:57:50 +02002898 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02002899}