blob: a5da6de57e8e27e6f20fd42e81fb59ef97f8f4ce [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ák05404f62019-07-24 14:11:53 +020044void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
David Sedlák85d0eca2019-07-24 15:15:21 +020045void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
David Sedlák555c7202019-07-04 12:14:12 +020046
David Sedlák68a1af12019-03-08 13:46:54 +010047struct state {
David Sedlák3b4db242018-10-19 16:11:01 +020048 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010049 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020050 struct lysp_module *lysp_mod;
David Sedlákda8ffa32019-07-08 14:17:10 +020051 struct yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020052 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010053};
David Sedlák872c7b42018-10-26 13:15:20 +020054
David Sedlák79e50cb2019-06-05 16:33:09 +020055#define BUFSIZE 1024
56char logbuf[BUFSIZE] = {0};
57int store = -1; /* negative for infinite logging, positive for limited logging */
58
59/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedlákb7abcfa2019-07-24 12:33:35 +020060#define ENABLE_LOGGER_CHECKING 1
David Sedlák79e50cb2019-06-05 16:33:09 +020061
62#if ENABLE_LOGGER_CHECKING
63static void
64logger(LY_LOG_LEVEL level, const char *msg, const char *path)
65{
66 (void) level; /* unused */
67 if (store) {
68 if (path && path[0]) {
69 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
70 } else {
71 strncpy(logbuf, msg, BUFSIZE - 1);
72 }
73 if (store > 0) {
74 --store;
75 }
76 }
77}
78#endif
79
80#if ENABLE_LOGGER_CHECKING
81# define logbuf_assert(str) assert_string_equal(logbuf, str)
82#else
83# define logbuf_assert(str)
84#endif
85
86#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
87 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
88 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
89 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
90 CLEANUP
91
David Sedlák8e7bda82019-07-16 17:57:50 +020092int
93setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +010094{
95 struct state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +020096
David Sedlák68a1af12019-03-08 13:46:54 +010097 /* allocate state variable */
98 (*state) = st = calloc(1, sizeof(*st));
99 if (!st) {
100 fprintf(stderr, "Memmory allocation failed");
101 return EXIT_FAILURE;
102 }
David Sedlák872c7b42018-10-26 13:15:20 +0200103
David Sedlák68a1af12019-03-08 13:46:54 +0100104 /* create new libyang context */
105 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200106
David Sedlák8e7bda82019-07-16 17:57:50 +0200107 return EXIT_SUCCESS;
108}
109
110int
111destroy_ly_ctx(void **state)
112{
113 struct state *st = *state;
114 ly_ctx_destroy(st->ctx, NULL);
115 free(st);
116
117 return EXIT_SUCCESS;
118}
119
120static int
121setup_f(void **state)
122{
123 struct state *st = *state;
124
125#if ENABLE_LOGGER_CHECKING
126 /* setup logger */
127 ly_set_log_clb(logger, 1);
128#endif
129
David Sedlák68a1af12019-03-08 13:46:54 +0100130 /* allocate new module */
131 st->mod = calloc(1, sizeof(*st->mod));
132 st->mod->ctx = st->ctx;
133
David Sedlák619db942019-07-03 14:47:30 +0200134 /* allocate new parsed module */
135 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
136 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
137 st->lysp_mod->mod->ctx = st->ctx;
138
139 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200140 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
141 st->yin_ctx->xml_ctx.ctx = st->ctx;
142 st->yin_ctx->xml_ctx.line = 1;
David Sedlák8f5bce02019-06-03 16:41:08 +0200143
David Sedlák68a1af12019-03-08 13:46:54 +0100144 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200145}
146
147static int
David Sedlák68a1af12019-03-08 13:46:54 +0100148teardown_f(void **state)
149{
150 struct state *st = *(struct state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200151 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100152
David Sedlák79e50cb2019-06-05 16:33:09 +0200153#if ENABLE_LOGGER_CHECKING
154 /* teardown logger */
155 if (!st->finished_correctly && logbuf[0] != '\0') {
156 fprintf(stderr, "%s\n", logbuf);
157 }
158#endif
159
David Sedlák619db942019-07-03 14:47:30 +0200160 temp = st->lysp_mod->mod;
161
David Sedlákda8ffa32019-07-08 14:17:10 +0200162 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100163 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200164 lysp_module_free(st->lysp_mod);
165 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200166 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100167
168 return EXIT_SUCCESS;
169}
170
David Sedlák392af4f2019-06-04 16:02:42 +0200171static struct state*
172reset_state(void **state)
173{
David Sedlák79e50cb2019-06-05 16:33:09 +0200174 ((struct state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200175 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200176 teardown_f(state);
177 setup_f(state);
178
179 return *state;
180}
181
David Sedlák79e50cb2019-06-05 16:33:09 +0200182void
183logbuf_clean(void)
184{
185 logbuf[0] = '\0';
186}
187
David Sedlák68a1af12019-03-08 13:46:54 +0100188static void
David Sedlák392af4f2019-06-04 16:02:42 +0200189test_yin_parse_module(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100190{
191 LY_ERR ret = LY_SUCCESS;
192 struct state *st = *state;
193
194 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200195 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
196 name=\"example-foo\"\
David Sedlák18730132019-03-15 15:51:34 +0100197 xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\
198 xmlns:foo=\"urn:example:foo\"\
199 xmlns:myext=\"urn:example:extensions\">\
David Sedlákcd0c9512019-03-29 13:23:06 +0100200 <namespace uri=\"urn:example:foo\" xmlns:myext=\"urn:example:extensions\"/>\
David Sedláka7406952019-04-05 10:33:07 +0200201 <prefix xmlns:myxt=\"urn:emple:extensions\" value=\"foo\" xmlns:myext=\"urn:example:extensions\"/>\
David Sedlákd9d3a312019-06-04 09:47:10 +0200202 </module>",
David Sedlák68a1af12019-03-08 13:46:54 +0100203 st->mod);
204
205 assert_int_equal(ret, LY_SUCCESS);
206 assert_string_equal(st->mod->parsed->mod->name, "example-foo");
207 assert_string_equal(st->mod->parsed->mod->prefix, "foo");
David Sedlákcd0c9512019-03-29 13:23:06 +0100208 assert_string_equal(st->mod->parsed->mod->ns, "urn:example:foo");
David Sedlák392af4f2019-06-04 16:02:42 +0200209
210 st = reset_state(state);
211 ret = yin_parse_module(st->ctx,
David Sedlák2b214ac2019-06-06 16:11:03 +0200212 "<module name=\"example-foo\">\
213 <invalid-tag uri=\"urn:example:foo\"\"/>\
214 </module>",
215 st->mod);
David Sedlák392af4f2019-06-04 16:02:42 +0200216 assert_int_equal(ret, LY_EVALID);
217
218 st = reset_state(state);
219 ret = yin_parse_module(st->ctx,
David Sedlák8f7a1172019-06-20 14:42:18 +0200220 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\
David Sedlák57715b12019-06-17 13:05:22 +0200221 </module>",
David Sedlák2b214ac2019-06-06 16:11:03 +0200222 st->mod);
David Sedlák392af4f2019-06-04 16:02:42 +0200223 assert_int_equal(ret, LY_EVALID);
David Sedlák882a8072019-07-08 17:51:20 +0200224 logbuf_assert("Missing mandatory attribute name of module element. Line number 1.");
David Sedlák392af4f2019-06-04 16:02:42 +0200225
226 st = reset_state(state);
227 ret = yin_parse_module(st->ctx,
228 "",
229 st->mod);
230 assert_int_equal(ret, LY_EVALID);
David Sedlák79e50cb2019-06-05 16:33:09 +0200231 logbuf_assert("Invalid keyword \"(null)\", expected \"module\" or \"submodule\". Line number 1.");
232 st->finished_correctly = true;
David Sedlák3b4db242018-10-19 16:11:01 +0200233}
234
235static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200236test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200237{
David Sedlák8f7a1172019-06-20 14:42:18 +0200238 struct state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200239
David Sedlák8f7a1172019-06-20 14:42:18 +0200240 const char *prefix, *name;
241 struct yin_arg_record *args = NULL;
242 size_t prefix_len, name_len;
243 /* create mock yin namespace in xml context */
244 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200245 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
246 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák8f7a1172019-06-20 14:42:18 +0200247 LY_ARRAY_FREE(args);
248
David Sedlákc1771b12019-07-10 15:55:46 +0200249 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, YANG_NONE), YANG_NONE);
250 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, YANG_NONE), YANG_NONE);
251 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, YANG_NONE), YANG_NONE);
252 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, YANG_NONE), YANG_ANYDATA);
253 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, YANG_NONE), YANG_ANYXML);
254 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, YANG_NONE), YANG_ARGUMENT);
255 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, YANG_NONE), YANG_AUGMENT);
256 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, YANG_NONE), YANG_BASE);
257 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, YANG_NONE), YANG_BELONGS_TO);
258 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, YANG_NONE), YANG_BIT);
259 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, YANG_NONE), YANG_CASE);
260 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, YANG_NONE), YANG_CHOICE);
261 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, YANG_NONE), YANG_CONFIG);
262 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, YANG_NONE), YANG_CONTACT);
263 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, YANG_NONE), YANG_CONTAINER);
264 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, YANG_NONE), YANG_DEFAULT);
265 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, YANG_NONE), YANG_DESCRIPTION);
266 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, YANG_NONE), YANG_DEVIATE);
267 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, YANG_NONE), YANG_DEVIATION);
268 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, YANG_NONE), YANG_ENUM);
269 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);
270 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, YANG_NONE), YANG_ERROR_MESSAGE);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, YANG_NONE), YANG_EXTENSION);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, YANG_NONE), YANG_FEATURE);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, YANG_NONE), YANG_FRACTION_DIGITS);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, YANG_NONE), YANG_GROUPING);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, YANG_NONE), YANG_IDENTITY);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, YANG_NONE), YANG_IF_FEATURE);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, YANG_NONE), YANG_IMPORT);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, YANG_NONE), YANG_INCLUDE);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, YANG_NONE), YANG_INPUT);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, YANG_NONE), YANG_KEY);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, YANG_NONE), YANG_LEAF);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, YANG_NONE), YANG_LEAF_LIST);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, YANG_NONE), YANG_LENGTH);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, YANG_NONE), YANG_LIST);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, YANG_NONE), YANG_MANDATORY);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, YANG_NONE), YANG_MAX_ELEMENTS);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, YANG_NONE), YANG_MIN_ELEMENTS);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, YANG_NONE), YANG_MODIFIER);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, YANG_NONE), YANG_MODULE);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, YANG_NONE), YANG_MUST);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, YANG_NONE), YANG_NAMESPACE);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, YANG_NONE), YANG_NOTIFICATION);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, YANG_NONE), YANG_ORDERED_BY);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, YANG_NONE), YANG_ORGANIZATION);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, YANG_NONE), YANG_OUTPUT);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, YANG_NONE), YANG_PATH);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, YANG_NONE), YANG_PATTERN);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, YANG_NONE), YANG_POSITION);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, YANG_NONE), YANG_PREFIX);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, YANG_NONE), YANG_PRESENCE);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, YANG_NONE), YANG_RANGE);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, YANG_NONE), YANG_REFERENCE);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, YANG_NONE), YANG_REFINE);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, YANG_NONE), YANG_REQUIRE_INSTANCE);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, YANG_NONE), YANG_REVISION);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, YANG_NONE), YANG_REVISION_DATE);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, YANG_NONE), YANG_RPC);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, YANG_NONE), YANG_STATUS);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, YANG_NONE), YANG_SUBMODULE);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, YANG_NONE), YANG_TYPE);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, YANG_NONE), YANG_TYPEDEF);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, YANG_NONE), YANG_UNIQUE);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, YANG_NONE), YANG_UNITS);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, YANG_NONE), YANG_USES);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, YANG_NONE), YANG_VALUE);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, YANG_NONE), YANG_WHEN);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, YANG_NONE), YANG_YANG_VERSION);
318 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 +0200319
320 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200321}
David Sedlák3b4db242018-10-19 16:11:01 +0200322
David Sedlák872c7b42018-10-26 13:15:20 +0200323static void
David Sedlák060b00e2019-06-19 11:12:06 +0200324test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200325{
David Sedlák68a1af12019-03-08 13:46:54 +0100326 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200327
David Sedlák060b00e2019-06-19 11:12:06 +0200328 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
329 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
330 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
331 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
332 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
333 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
334 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
335 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
336 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
337 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
338 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
339 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200340}
341
David Sedlák68a1af12019-03-08 13:46:54 +0100342static void
David Sedlákb1a78352019-06-28 16:16:29 +0200343test_yin_parse_element_generic(void **state)
344{
345 const char *prefix, *name;
346 struct state *st = *state;
347 struct lysp_ext_instance exts;
348 size_t prefix_len, name_len;
349 LY_ERR ret;
350
351 memset(&exts, 0, sizeof(exts));
352
353 const char *data = "<elem attr=\"value\">text_value</elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200354 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
355 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 +0200356 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200357 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200358 assert_string_equal(exts.child->stmt, "elem");
359 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200360 assert_string_equal(exts.child->child->stmt, "attr");
361 assert_string_equal(exts.child->child->arg, "value");
362 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200363 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200364 st = reset_state(state);
365
366 data = "<elem></elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200367 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
368 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 +0200369 assert_int_equal(ret, LY_SUCCESS);
370 assert_string_equal(exts.child->stmt, "elem");
371 assert_null(exts.child->child);
372 assert_null(exts.child->arg);
David Sedlákda8ffa32019-07-08 14:17:10 +0200373 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák5392a212019-07-01 09:19:10 +0200374 lysp_ext_instance_free(st->ctx, &exts);
375
David Sedlákb1a78352019-06-28 16:16:29 +0200376 st->finished_correctly = true;
377}
378
379static void
380test_yin_parse_extension_instance(void **state)
381{
382 LY_ERR ret;
383 struct state *st = *state;
384 const char *prefix, *name;
385 size_t prefix_len, name_len;
386 struct yin_arg_record *args = NULL;
387 struct lysp_ext_instance *exts = NULL;
David Sedlákb1a78352019-06-28 16:16:29 +0200388 const char *data = "<ext value1=\"test\" value=\"test2\"><subelem>text</subelem></ext>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200389 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
390 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200391 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name2fullname(name, prefix_len),
David Sedlák619db942019-07-03 14:47:30 +0200392 namelen2fulllen(name_len, prefix_len), LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200393 assert_int_equal(ret, LY_SUCCESS);
394 assert_string_equal(exts->name, "ext");
395 assert_int_equal(exts->insubstmt_index, 0);
396 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
397 assert_true(exts->yin & LYS_YIN);
398 assert_string_equal(exts->child->stmt, "value1");
399 assert_string_equal(exts->child->arg, "test");
400 assert_null(exts->child->child);
401 assert_true(exts->child->flags & LYS_YIN_ATTR);
402 assert_string_equal(exts->child->next->stmt, "value");
403 assert_string_equal(exts->child->next->arg, "test2");
404 assert_null(exts->child->next->child);
405 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
406
407 assert_string_equal(exts->child->next->next->stmt, "subelem");
408 assert_string_equal(exts->child->next->next->arg, "text");
409 assert_null(exts->child->next->next->child);
410 assert_null(exts->child->next->next->next);
411 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákda8ffa32019-07-08 14:17:10 +0200412 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200413 LY_ARRAY_FREE(args);
414 lysp_ext_instance_free(st->ctx, exts);
415 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200416 exts = NULL;
417 args = NULL;
418 st = reset_state(state);
419
420 data = "<extension-elem />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200421 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
422 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200423 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 +0200424 assert_int_equal(ret, LY_SUCCESS);
425 assert_string_equal(exts->name, "extension-elem");
426 assert_null(exts->argument);
427 assert_null(exts->child);
428 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
429 assert_int_equal(exts->insubstmt_index, 0);
430 assert_true(exts->yin & LYS_YIN);
David Sedlákda8ffa32019-07-08 14:17:10 +0200431 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákf250ecf2019-07-01 11:02:05 +0200432 LY_ARRAY_FREE(args);
433 lysp_ext_instance_free(st->ctx, exts);
434 LY_ARRAY_FREE(exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200435 st->finished_correctly = true;
436}
437
David Sedlák555c7202019-07-04 12:14:12 +0200438static void
439test_yin_parse_content(void **state)
440{
441 struct state *st = *state;
442 LY_ERR ret = LY_SUCCESS;
443 struct sized_string name, prefix;
444 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
445 "<custom xmlns=\"my-ext\">"
446 "totally amazing extension"
447 "</custom>"
David Sedlák986cb412019-07-04 13:10:11 +0200448 "<extension name=\"ext\">"
449 "<argument name=\"argname\"></argument>"
450 "<description><text>desc</text></description>"
451 "<reference><text>ref</text></reference>"
452 "<status value=\"deprecated\"></status>"
453 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200454 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200455 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200456 "<when condition=\"condition...\">"
457 "<reference><text>when_ref</text></reference>"
458 "<description><text>when_desc</text></description>"
459 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200460 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200461 "<error-message>"
462 "<value>error-msg</value>"
463 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200464 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200465 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200466 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200467 "<position value=\"25\"></position>"
468 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200469 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200470 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200471 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200472 "<pattern value='pattern'>"
473 "<modifier value='invert-match'/>"
474 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200475 "<enum name=\"yay\">"
476 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200477 "</prefix>";
478 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200479 const char **if_features = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200480 struct yin_arg_record *attrs = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200481 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200482 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200483 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200484 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200485 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200486 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200487
David Sedlákda8ffa32019-07-08 14:17:10 +0200488 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
489 yin_load_attributes(st->yin_ctx, &data, &attrs);
David Sedlák555c7202019-07-04 12:14:12 +0200490
David Sedlákfd5b9c32019-07-12 15:33:13 +0200491 struct yin_subelement subelems[17] = {
David Sedlák438ae432019-07-11 15:36:54 +0200492 {YANG_CONFIG, &config, 0},
David Sedlákc3da3ef2019-07-19 12:56:08 +0200493 {YANG_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
David Sedlákfd5b9c32019-07-12 15:33:13 +0200494 {YANG_ENUM, &enum_type, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200495 {YANG_ERROR_APP_TAG, &app_tag, 0},
496 {YANG_ERROR_MESSAGE, &err_msg, 0},
497 {YANG_EXTENSION, &ext_def, 0},
498 {YANG_IF_FEATURE, &if_features, 0},
499 {YANG_LENGTH, &len_type, 0},
David Sedlákd3983112019-07-12 11:20:56 +0200500 {YANG_PATTERN, &patter_type, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200501 {YANG_RANGE, &range_type, 0},
502 {YANG_REQUIRE_INSTANCE, &req_type, 0},
503 {YANG_UNITS, &units, 0},
David Sedlák374d2b32019-07-17 15:06:55 +0200504 {YANG_POSITION, &pos_enum, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200505 {YANG_VALUE, &val_enum, 0},
506 {YANG_WHEN, &when_p, 0},
507 {YANG_CUSTOM, NULL, 0},
508 {YIN_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200509 };
David Sedlákfd5b9c32019-07-12 15:33:13 +0200510 ret = yin_parse_content(st->yin_ctx, subelems, 17, &data, YANG_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200511 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200512 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák2ce1be62019-07-10 16:15:09 +0200513 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200514 assert_string_equal(def, "default-value");
David Sedlák555c7202019-07-04 12:14:12 +0200515 assert_string_equal(exts->name, "custom");
516 assert_string_equal(exts->argument, "totally amazing extension");
517 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200518 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200519 assert_string_equal(when_p->cond, "condition...");
520 assert_string_equal(when_p->dsc, "when_desc");
521 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200522 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200523 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200524 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200525 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200526 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200527 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200528 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200529 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200530 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200531 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200532 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200533 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200534 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200535 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200536 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200537 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200538 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200539 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200540 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200541 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200542 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200543 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200544 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200545 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200546 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200547 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200548 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200549 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200550 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200551 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200552 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200553 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200554 LY_ARRAY_FREE(ext_def);
David Sedlák555c7202019-07-04 12:14:12 +0200555 LY_ARRAY_FREE(attrs);
David Sedlákd3983112019-07-12 11:20:56 +0200556 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200557 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200558 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200559 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200560 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200561 attrs = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200562 st = reset_state(state);
563
564 /* test unique subelem */
565 const char *prefix_value;
566 struct yin_subelement subelems2[2] = {{YANG_PREFIX, &prefix_value, 0},
567 {YIN_TEXT, &value, YIN_SUBELEM_UNIQUE}};
568 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
569 "<prefix value=\"inv_mod\" />"
570 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
571 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
572 "</module>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200573 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
574 yin_load_attributes(st->yin_ctx, &data, &attrs);
575 ret = yin_parse_content(st->yin_ctx, subelems2, 2, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200576 assert_int_equal(ret, LY_EVALID);
577 logbuf_assert("Redefinition of text element in module element. Line number 1.");
578 lydict_remove(st->ctx, prefix_value);
579 lydict_remove(st->ctx, value);
580 st = reset_state(state);
581 LY_ARRAY_FREE(attrs);
582 attrs = NULL;
583
584 /* test first subelem */
585 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
586 "<prefix value=\"inv_mod\" />"
587 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
588 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
589 "</module>";
590 struct yin_subelement subelems3[2] = {{YANG_PREFIX, &prefix_value, 0},
591 {YIN_TEXT, &value, YIN_SUBELEM_FIRST}};
David Sedlákda8ffa32019-07-08 14:17:10 +0200592 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
593 yin_load_attributes(st->yin_ctx, &data, &attrs);
594 ret = yin_parse_content(st->yin_ctx, subelems3, 2, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200595 assert_int_equal(ret, LY_EVALID);
596 logbuf_assert("Subelement text of module element must be defined as first subelement. Line number 1.");
597 lydict_remove(st->ctx, prefix_value);
598 st = reset_state(state);
599 LY_ARRAY_FREE(attrs);
600 attrs = NULL;
601
602 /* test mandatory subelem */
603 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
604 "</module>";
605 struct yin_subelement subelems4[1] = {{YANG_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY}};
David Sedlákda8ffa32019-07-08 14:17:10 +0200606 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
607 yin_load_attributes(st->yin_ctx, &data, &attrs);
608 ret = yin_parse_content(st->yin_ctx, subelems4, 1, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200609 assert_int_equal(ret, LY_EVALID);
610 logbuf_assert("Missing mandatory subelement prefix of module element. Line number 1.");
611 LY_ARRAY_FREE(attrs);
612
613 st->finished_correctly = true;
614}
615
David Sedlák92147b02019-07-09 14:01:01 +0200616static void
David Sedlák4a650532019-07-10 11:55:18 +0200617test_validate_value(void **state)
618{
619 struct state *st = *state;
620 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "#invalid", 8), LY_EVALID);
621 logbuf_assert("Invalid identifier character '#'. Line number 1.");
622 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG, "", 0), LY_SUCCESS);
623 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "pre:b", 5), LY_EVALID);
624 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:b", 5), LY_SUCCESS);
625 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:pre:b", 9), LY_EVALID);
626
627 st->finished_correctly = true;
628}
629
David Sedlák32488102019-07-15 17:44:10 +0200630static int
631setup_element_test(void **state)
632{
David Sedlák8e7bda82019-07-16 17:57:50 +0200633 struct state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200634
635#if ENABLE_LOGGER_CHECKING
636 /* setup logger */
637 ly_set_log_clb(logger, 1);
638#endif
639
640 /* reset logbuf */
641 logbuf[0] = '\0';
David Sedlák32488102019-07-15 17:44:10 +0200642
643 /* allocate parser context */
644 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
645 st->yin_ctx->xml_ctx.ctx = st->ctx;
646 st->yin_ctx->xml_ctx.line = 1;
647
648 return EXIT_SUCCESS;
649}
650
651static int
652teardown_element_test(void **state)
653{
654 struct state *st = *(struct state **)state;
655
656#if ENABLE_LOGGER_CHECKING
657 /* teardown logger */
658 if (!st->finished_correctly && logbuf[0] != '\0') {
659 fprintf(stderr, "%s\n", logbuf);
660 }
661#endif
662
663 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák32488102019-07-15 17:44:10 +0200664 free(st->yin_ctx);
David Sedlák32488102019-07-15 17:44:10 +0200665
666 return EXIT_SUCCESS;
667}
668
669#define ELEMENT_WRAPPER_START "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
670#define ELEMENT_WRAPPER_END "</module>"
671
672/* helper function to simplify unit test of each element using parse_content function */
673LY_ERR
674test_element_helper(struct state *st, const char **data, void *dest, const char **text,
675 struct lysp_ext_instance **exts, bool valid)
676{
677 struct yin_arg_record *attrs = NULL;
678 struct sized_string name, prefix;
679 LY_ERR ret = LY_SUCCESS;
680 struct yin_subelement subelems[71] = {
681 {YANG_ACTION, dest, 0},
682 {YANG_ANYDATA, dest, 0},
683 {YANG_ANYXML, dest, 0},
684 {YANG_ARGUMENT,dest, 0},
685 {YANG_AUGMENT, dest, 0},
686 {YANG_BASE, dest, 0},
687 {YANG_BELONGS_TO, dest, 0},
688 {YANG_BIT, dest, 0},
689 {YANG_CASE, dest, 0},
690 {YANG_CHOICE, dest, 0},
691 {YANG_CONFIG, dest, 0},
692 {YANG_CONTACT, dest, 0},
693 {YANG_CONTAINER, dest, 0},
David Sedlákc3da3ef2019-07-19 12:56:08 +0200694 {YANG_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
David Sedlák32488102019-07-15 17:44:10 +0200695 {YANG_DESCRIPTION, dest, 0},
696 {YANG_DEVIATE, dest, 0},
697 {YANG_DEVIATION, dest, 0},
698 {YANG_ENUM, dest, 0},
699 {YANG_ERROR_APP_TAG, dest, 0},
700 {YANG_ERROR_MESSAGE, dest, 0},
701 {YANG_EXTENSION, dest, 0},
702 {YANG_FEATURE, dest, 0},
703 {YANG_FRACTION_DIGITS, dest, 0},
704 {YANG_GROUPING, dest, 0},
705 {YANG_IDENTITY, dest, 0},
706 {YANG_IF_FEATURE, dest, 0},
707 {YANG_IMPORT, dest, 0},
708 {YANG_INCLUDE, dest, 0},
709 {YANG_INPUT, dest, 0},
710 {YANG_KEY, dest, 0},
711 {YANG_LEAF, dest, 0},
712 {YANG_LEAF_LIST, dest, 0},
713 {YANG_LENGTH, dest, 0},
714 {YANG_LIST, dest, 0},
715 {YANG_MANDATORY, dest, 0},
716 {YANG_MAX_ELEMENTS, dest, 0},
717 {YANG_MIN_ELEMENTS, dest, 0},
718 {YANG_MODIFIER, dest, 0},
719 {YANG_MODULE, dest, 0},
720 {YANG_MUST, dest, 0},
721 {YANG_NAMESPACE, dest, 0},
722 {YANG_NOTIFICATION, dest, 0},
723 {YANG_ORDERED_BY, dest, 0},
724 {YANG_ORGANIZATION, dest, 0},
725 {YANG_OUTPUT, dest, 0},
726 {YANG_PATH, dest, 0},
727 {YANG_PATTERN, dest, 0},
David Sedlák32488102019-07-15 17:44:10 +0200728 {YANG_PREFIX, dest, 0},
729 {YANG_PRESENCE, dest, 0},
730 {YANG_RANGE, dest, 0},
731 {YANG_REFERENCE, dest, 0},
732 {YANG_REFINE, dest, 0},
733 {YANG_REQUIRE_INSTANCE, dest, 0},
734 {YANG_REVISION, dest, 0},
735 {YANG_REVISION_DATE, dest, 0},
736 {YANG_RPC, dest, 0},
737 {YANG_STATUS, dest, 0},
738 {YANG_SUBMODULE, dest, 0},
739 {YANG_TYPE, dest, 0},
740 {YANG_TYPEDEF, dest, 0},
741 {YANG_UNIQUE, dest, 0},
742 {YANG_UNITS, dest, 0},
743 {YANG_USES, dest, 0},
David Sedlák374d2b32019-07-17 15:06:55 +0200744 {YANG_POSITION, dest, 0},
David Sedlák32488102019-07-15 17:44:10 +0200745 {YANG_VALUE, dest, 0},
746 {YANG_WHEN, dest, 0},
747 {YANG_YANG_VERSION, dest, 0},
748 {YANG_YIN_ELEMENT, dest, 0},
749 {YANG_CUSTOM, dest, 0},
750 {YIN_TEXT, dest, 0},
751 {YIN_VALUE, dest, 0}
752 };
753 LY_CHECK_RET(lyxml_get_element(&st->yin_ctx->xml_ctx, data, &prefix.value, &prefix.len, &name.value, &name.len));\
754 LY_CHECK_RET(yin_load_attributes(st->yin_ctx, data, &attrs));\
David Sedlák8e7bda82019-07-16 17:57:50 +0200755 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 +0200756 LY_ARRAY_FREE(attrs);
757 if (valid) {
758 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
759 }
760 /* reset status */
761 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
762 return ret;
763}
764
765static void
766test_enum_bit_elem(void **state)
767{
768 /* yin_parse_enum_bit is function that is being mainly tested by this test */
769 struct state *st = *state;
770 struct lysp_type type = {};
771 const char *data;
772 data = ELEMENT_WRAPPER_START
773 "<enum name=\"enum-name\">"
774 "<if-feature name=\"feature\" />"
775 "<value value=\"55\" />"
776 "<status value=\"deprecated\" />"
777 "<description><text>desc...</text></description>"
778 "<reference><text>ref...</text></reference>"
779 "</enum>"
780 ELEMENT_WRAPPER_END;
781 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
782 assert_string_equal(*type.enums->iffeatures, "feature");
783 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200784 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200785 assert_string_equal(type.enums->dsc, "desc...");
786 assert_string_equal(type.enums->ref, "ref...");
787 lysp_type_free(st->ctx, &type);
788 memset(&type, 0, sizeof type);
789
790 /* todo bit element test */
791 st->finished_correctly = true;
792}
793
794static void
795test_meta_elem(void **state)
796{
797 struct state *st = *state;
798 char *value = NULL;
799 const char *data;
800
801 /* organization element */
802 data = ELEMENT_WRAPPER_START
803 "<organization><text>organization...</text></organization>"
804 ELEMENT_WRAPPER_END;
805 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
806 assert_string_equal(value, "organization...");
807 FREE_STRING(st->ctx, value);
808 value = NULL;
809 /* contact element */
810 data = ELEMENT_WRAPPER_START
811 "<contact><text>contact...</text></contact>"
812 ELEMENT_WRAPPER_END;
813 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
814 assert_string_equal(value, "contact...");
815 FREE_STRING(st->ctx, value);
816 value = NULL;
817 /* description element */
818 data = ELEMENT_WRAPPER_START
819 "<description><text>description...</text></description>"
820 ELEMENT_WRAPPER_END;
821 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
822 assert_string_equal(value, "description...");
823 FREE_STRING(st->ctx, value);
824 value = NULL;
825 /* reference element */
826 data = ELEMENT_WRAPPER_START
827 "<reference><text>reference...</text></reference>"
828 ELEMENT_WRAPPER_END;
829 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
830 assert_string_equal(value, "reference...");
831 FREE_STRING(st->ctx, value);
832 value = NULL;
833
834 /* missing text subelement */
835 data = ELEMENT_WRAPPER_START
836 "<reference>reference...</reference>"
837 ELEMENT_WRAPPER_END;
838 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, false), LY_EVALID);
839 logbuf_assert("Missing mandatory subelement text of reference element. Line number 1.");
840
841 st->finished_correctly = true;
842}
843
844static void
845test_import_elem(void **state)
846{
847 struct state *st = *state;
848 const char *data;
849 struct lys_module *lys_mod = calloc(1, sizeof *lys_mod);
850 struct lysp_module *lysp_mod = calloc(1, sizeof *lysp_mod);
851 lys_mod->ctx = st->ctx;
852 lysp_mod->mod = lys_mod;
853
854 /* max subelems */
855 data = ELEMENT_WRAPPER_START
856 "<import module=\"a\">"
857 "<prefix value=\"a_mod\"/>"
858 "<revision-date date=\"2015-01-01\"></revision-date>"
859 "<description><text>import description</text></description>"
860 "<reference><text>import reference</text></reference>"
861 "</import>"
862 ELEMENT_WRAPPER_END;
863 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, true), LY_SUCCESS);
864 assert_string_equal(lysp_mod->imports->name, "a");
865 assert_string_equal(lysp_mod->imports->prefix, "a_mod");
866 assert_string_equal(lysp_mod->imports->rev, "2015-01-01");
867 assert_string_equal(lysp_mod->imports->dsc, "import description");
868 assert_string_equal(lysp_mod->imports->ref, "import reference");
869 lysp_module_free(lysp_mod);
870 lys_module_free(lys_mod, NULL);
871
872 /* min subelems */
873 lys_mod = calloc(1, sizeof *lys_mod);
874 lysp_mod = calloc(1, sizeof *lysp_mod);
875 lys_mod->ctx = st->ctx;
876 lysp_mod->mod = lys_mod;
877 data = ELEMENT_WRAPPER_START
878 "<import module=\"a\">"
879 "<prefix value=\"a_mod\"/>"
880 "</import>"
881 ELEMENT_WRAPPER_END;
882 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, true), LY_SUCCESS);
883 assert_string_equal(lysp_mod->imports->prefix, "a_mod");
884 lysp_module_free(lysp_mod);
885 lys_module_free(lys_mod, NULL);
886
887 /* invalid (missing prefix) */
888 lys_mod = calloc(1, sizeof *lys_mod);
889 lysp_mod = calloc(1, sizeof *lysp_mod);
890 lys_mod->ctx = st->ctx;
891 lysp_mod->mod = lys_mod;
892 data = ELEMENT_WRAPPER_START "<import module=\"a\">""</import>" ELEMENT_WRAPPER_END;
893 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, false), LY_EVALID);
894 logbuf_assert("Missing mandatory subelement prefix of import element. Line number 1.");
895 lysp_module_free(lysp_mod);
896 lys_module_free(lys_mod, NULL);
897
898 /* invalid reused prefix */
899 lys_mod = calloc(1, sizeof *lys_mod);
900 lysp_mod = calloc(1, sizeof *lysp_mod);
901 lys_mod->ctx = st->ctx;
902 lysp_mod->mod = lys_mod;
903 data = ELEMENT_WRAPPER_START
904 "<import module=\"a\">"
905 "<prefix value=\"a_mod\"/>"
906 "</import>"
907 "<import module=\"a\">"
908 "<prefix value=\"a_mod\"/>"
909 "</import>"
910 ELEMENT_WRAPPER_END;
911 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, false), LY_EVALID);
912 logbuf_assert("Prefix \"a_mod\" already used to import \"a\" module. Line number 1.");
913 lysp_module_free(lysp_mod);
914 lys_module_free(lys_mod, NULL);
915
916 st->finished_correctly = true;
917}
918
919static void
920test_status_elem(void **state)
921{
922 struct state *st = *state;
923 const char *data;
924 uint16_t flags = 0;
925
926 /* test valid values */
927 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
928 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200929 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +0200930
931 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
932 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200933 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +0200934
935 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\"></status>" ELEMENT_WRAPPER_END;
936 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200937 assert_true(flags & LYS_STATUS_OBSLT);
David Sedlák32488102019-07-15 17:44:10 +0200938
939 /* test invalid value */
940 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
941 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
942 logbuf_assert("Invalid value \"invalid\" of \"status\". Line number 1.");
943 st->finished_correctly = true;
944}
945
946static void
947test_ext_elem(void **state)
948{
949 struct state *st = *state;
950 const char *data;
951 struct lysp_ext *ext = NULL;
952
953 /* max subelems */
954 data = ELEMENT_WRAPPER_START
955 "<extension name=\"ext_name\">"
956 "<argument name=\"arg\"></argument>"
957 "<status value=\"current\"/>"
958 "<description><text>ext_desc</text></description>"
959 "<reference><text>ext_ref</text></reference>"
960 "</extension>"
961 ELEMENT_WRAPPER_END;
962 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
963 assert_string_equal(ext->name, "ext_name");
964 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200965 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +0200966 assert_string_equal(ext->dsc, "ext_desc");
967 assert_string_equal(ext->ref, "ext_ref");
968 lysp_ext_free(st->ctx, ext);
969 LY_ARRAY_FREE(ext);
970 ext = NULL;
971
972 /* min subelems */
973 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
974 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
975 assert_string_equal(ext->name, "ext_name");
976 lysp_ext_free(st->ctx, ext);
977 LY_ARRAY_FREE(ext);
978 ext = NULL;
979
980 st->finished_correctly = true;
981}
982
983static void
984test_yin_element_elem(void **state)
985{
986 struct state *st = *state;
987 const char *data;
988 uint16_t flags = 0;
989
990 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
991 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200992 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200993
994 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\" />" ELEMENT_WRAPPER_END;
995 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200996 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200997
998 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
999 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001000 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001001 logbuf_assert("Invalid value \"invalid\" of \"yin-element\". Line number 1.");
1002 st->finished_correctly = true;
1003}
1004
1005static void
1006test_yangversion_elem(void **state)
1007{
1008 struct state *st = *state;
1009 const char *data;
1010 uint8_t version = 0;
1011
1012 /* valid values */
1013 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
1014 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001015 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001016 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1017
1018 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\" />" ELEMENT_WRAPPER_END;
1019 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001020 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001021 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
1022
1023 /* invalid value */
1024 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
1025 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID);
1026 logbuf_assert("Invalid value \"version\" of \"yang-version\". Line number 1.");
1027
1028 st->finished_correctly = true;
1029}
1030
1031static void
1032test_mandatory_elem(void **state)
1033{
1034 struct state *st = *state;
1035 const char *data;
1036 uint16_t man = 0;
1037
1038 /* valid values */
1039 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
1040 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1041 assert_int_equal(man, LYS_MAND_TRUE);
1042 man = 0;
1043
1044 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\" />" ELEMENT_WRAPPER_END;
1045 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1046 assert_int_equal(man, LYS_MAND_FALSE);
1047
1048 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
1049 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID);
1050 logbuf_assert("Invalid value \"invalid\" of \"mandatory\". Line number 1.");
1051
1052 st->finished_correctly = true;
1053}
1054
David Sedlák8e7bda82019-07-16 17:57:50 +02001055static void
1056test_argument_elem(void **state)
1057{
1058 struct state *st = *state;
1059 const char *data;
1060 uint16_t flags = 0;
1061 const char *arg;
1062 struct yin_argument_meta arg_meta = {&flags, &arg};
1063 /* max subelems */
1064 data = ELEMENT_WRAPPER_START
1065 "<argument name=\"arg-name\">"
1066 "<yin-element value=\"true\" />"
1067 "</argument>"
1068 ELEMENT_WRAPPER_END;
1069 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1070 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001071 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001072 flags = 0;
1073 FREE_STRING(st->ctx, arg);
1074 arg = NULL;
1075
1076 /* min subelems */
1077 data = ELEMENT_WRAPPER_START
1078 "<argument name=\"arg\">"
1079 "</argument>"
1080 ELEMENT_WRAPPER_END;
1081 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1082 assert_string_equal(arg, "arg");
1083 assert_true(flags == 0);
1084 FREE_STRING(st->ctx, arg);
1085
1086 st->finished_correctly = true;
1087}
1088
1089static void
1090test_base_elem(void **state)
1091{
1092 struct state *st = *state;
1093 const char *data;
1094 const char **bases = NULL;
1095 struct lysp_type type = {};
1096
1097 /* as identity subelement */
1098 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
1099 "<base name=\"base-name\"/>"
1100 "</identity>";
1101 assert_int_equal(test_element_helper(st, &data, &bases, NULL, NULL, true), LY_SUCCESS);
1102 assert_string_equal(*bases, "base-name");
1103 FREE_STRING(st->ctx, *bases);
1104 LY_ARRAY_FREE(bases);
1105
1106 /* as type subelement */
1107 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
1108 "<base name=\"base-name\"/>"
1109 "</type>";
1110 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1111 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001112 assert_true(type.flags & LYS_SET_BASE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001113 FREE_STRING(st->ctx, *type.bases);
1114 LY_ARRAY_FREE(type.bases);
1115
1116 st->finished_correctly = true;
1117}
1118
1119static void
1120test_belongsto_elem(void **state)
1121{
1122 struct state *st = *state;
1123 const char *data;
1124 struct lysp_submodule submod;
1125
1126 data = ELEMENT_WRAPPER_START
1127 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>"
1128 ELEMENT_WRAPPER_END;
1129 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, true), LY_SUCCESS);
1130 assert_string_equal(submod.belongsto, "module-name");
1131 assert_string_equal(submod.prefix, "pref");
1132 FREE_STRING(st->ctx, submod.belongsto);
1133 FREE_STRING(st->ctx, submod.prefix);
1134
1135 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
1136 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID);
1137 logbuf_assert("Missing mandatory subelement prefix of belongs-to element. Line number 1.");
1138 FREE_STRING(st->ctx, submod.belongsto);
1139
1140 st->finished_correctly = true;
1141}
1142
1143static void
1144test_config_elem(void **state)
1145{
1146 struct state *st = *state;
1147 const char *data;
1148 uint16_t flags = 0;
1149
1150 data = ELEMENT_WRAPPER_START "<config value=\"true\"/>" ELEMENT_WRAPPER_END;
1151 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001152 assert_true(flags & LYS_CONFIG_W);
David Sedlák8e7bda82019-07-16 17:57:50 +02001153 flags = 0;
1154
1155 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
1156 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001157 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001158 flags = 0;
1159
1160 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1161 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
1162 logbuf_assert("Invalid value \"invalid\" of \"config\". Line number 1.");
1163
1164 st->finished_correctly = true;
1165}
1166
1167static void
1168test_default_elem(void **state)
1169{
1170 struct state *st = *state;
1171 const char *data;
1172 const char *val = NULL;
1173
1174 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\"/>" ELEMENT_WRAPPER_END;
1175 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1176 assert_string_equal(val, "defaul-value");
1177 FREE_STRING(st->ctx, val);
1178 val = NULL;
1179
1180 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
1181 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1182 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1183
1184 st->finished_correctly = true;
1185}
1186
1187static void
1188test_err_app_tag_elem(void **state)
1189{
1190 struct state *st = *state;
1191 const char *data;
1192 const char *val = NULL;
1193
1194 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\"/>" ELEMENT_WRAPPER_END;
1195 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1196 assert_string_equal(val, "val");
1197 FREE_STRING(st->ctx, val);
1198 val = NULL;
1199
1200 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
1201 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1202 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1203
1204 st->finished_correctly = true;
1205}
1206
1207static void
1208test_err_msg_elem(void **state)
1209{
1210 struct state *st = *state;
1211 const char *data;
1212 const char *val = NULL;
1213
1214 data = ELEMENT_WRAPPER_START "<error-message><value>val</value></error-message>" ELEMENT_WRAPPER_END;
1215 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1216 assert_string_equal(val, "val");
1217 FREE_STRING(st->ctx, val);
1218
1219 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
1220 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1221 logbuf_assert("Missing mandatory subelement value of error-message element. Line number 1.");
1222
1223 st->finished_correctly = true;
1224}
1225
1226static void
1227test_fracdigits_elem(void **state)
1228{
1229 struct state *st = *state;
1230 const char *data;
1231 struct lysp_type type = {};
1232
1233 /* valid value */
1234 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\"></fraction-digits>" ELEMENT_WRAPPER_END;
1235 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1236 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001237 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001238
1239 /* invalid values */
1240 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
1241 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1242 logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1.");
1243
1244 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
1245 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1246 logbuf_assert("Invalid value \"02\" of \"fraction-digits\". Line number 1.");
1247
1248 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
1249 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1250 logbuf_assert("Invalid value \"1p\" of \"fraction-digits\". Line number 1.");
1251
1252 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
1253 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1254 logbuf_assert("Invalid value \"19\" of \"fraction-digits\". Line number 1.");
1255
1256 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
1257 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1258 logbuf_assert("Invalid value \"999999999999999999\" of \"fraction-digits\". Line number 1.");
1259
1260 st->finished_correctly = true;
1261}
1262
1263static void
1264test_iffeature_elem(void **state)
1265{
1266 struct state *st = *state;
1267 const char *data;
1268 const char **iffeatures = NULL;
1269
1270 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\"></if-feature>" ELEMENT_WRAPPER_END;
1271 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, true), LY_SUCCESS);
1272 assert_string_equal(*iffeatures, "local-storage");
1273 FREE_STRING(st->ctx, *iffeatures);
1274 LY_ARRAY_FREE(iffeatures);
1275 iffeatures = NULL;
1276
1277 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
1278 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID);
1279 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1280 LY_ARRAY_FREE(iffeatures);
1281 iffeatures = NULL;
1282
1283 st->finished_correctly = true;
1284}
1285
1286static void
1287test_length_elem(void **state)
1288{
1289 struct state *st = *state;
1290 const char *data;
1291 struct lysp_type type = {};
1292
1293 /* max subelems */
1294 data = ELEMENT_WRAPPER_START
1295 "<length value=\"length-str\">"
1296 "<error-message><value>err-msg</value></error-message>"
1297 "<error-app-tag value=\"err-app-tag\"/>"
1298 "<description><text>desc</text></description>"
1299 "<reference><text>ref</text></reference>"
1300 "</length>"
1301 ELEMENT_WRAPPER_END;
1302 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1303 assert_string_equal(type.length->arg, "length-str");
1304 assert_string_equal(type.length->emsg, "err-msg");
1305 assert_string_equal(type.length->eapptag, "err-app-tag");
1306 assert_string_equal(type.length->dsc, "desc");
1307 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001308 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001309 lysp_type_free(st->ctx, &type);
1310 memset(&type, 0, sizeof(type));
1311
1312 /* min subelems */
1313 data = ELEMENT_WRAPPER_START
1314 "<length value=\"length-str\">"
1315 "</length>"
1316 ELEMENT_WRAPPER_END;
1317 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1318 assert_string_equal(type.length->arg, "length-str");
1319 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001320 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001321 memset(&type, 0, sizeof(type));
1322
1323 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
1324 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1325 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1326 lysp_type_free(st->ctx, &type);
1327 memset(&type, 0, sizeof(type));
1328
1329 st->finished_correctly = true;
1330}
1331
1332static void
1333test_modifier_elem(void **state)
1334{
1335 struct state *st = *state;
1336 const char *data;
1337 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
1338
1339 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\" />" ELEMENT_WRAPPER_END;
1340 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, true), LY_SUCCESS);
1341 assert_string_equal(pat, "\x015pattern");
1342 FREE_STRING(st->ctx, pat);
1343
1344 pat = lydict_insert(st->ctx, "\006pattern", 8);
1345 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
1346 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID);
1347 logbuf_assert("Invalid value \"invert\" of \"modifier\". Line number 1.");
1348 FREE_STRING(st->ctx, pat);
1349
1350 st->finished_correctly = true;
1351}
1352
1353static void
1354test_namespace_elem(void **state)
1355{
1356 struct state *st = *state;
1357 const char *data;
1358 const char *ns;
1359
1360 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\"/>" ELEMENT_WRAPPER_END;
1361 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, true), LY_SUCCESS);
1362 assert_string_equal(ns, "ns");
1363 FREE_STRING(st->ctx, ns);
1364
1365 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
1366 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID);
1367 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1368
1369 st->finished_correctly = true;
1370}
1371
1372static void
1373test_path_elem(void **state)
1374{
1375 struct state *st = *state;
1376 const char *data;
1377 struct lysp_type type = {};
1378
1379 data = ELEMENT_WRAPPER_START "<path value=\"path-val\"/>" ELEMENT_WRAPPER_END;
1380 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1381 assert_string_equal("path-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001382 assert_true(type.flags & LYS_SET_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001383 lysp_type_free(st->ctx, &type);
1384
1385 st->finished_correctly = true;
1386}
1387
1388static void
1389test_pattern_elem(void **state)
1390{
1391 struct state *st = *state;
1392 const char *data;
1393 struct lysp_type type = {};
1394
1395 /* max subelems */
1396 data = ELEMENT_WRAPPER_START
1397 "<pattern value=\"super_pattern\">"
1398 "<modifier value=\"invert-match\"/>"
1399 "<error-message><value>err-msg-value</value></error-message>"
1400 "<error-app-tag value=\"err-app-tag-value\"/>"
1401 "<description><text>pattern-desc</text></description>"
1402 "<reference><text>pattern-ref</text></reference>"
1403 "</pattern>"
1404 ELEMENT_WRAPPER_END;
1405 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001406 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001407 assert_string_equal(type.patterns->arg, "\x015super_pattern");
1408 assert_string_equal(type.patterns->dsc, "pattern-desc");
1409 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1410 assert_string_equal(type.patterns->emsg, "err-msg-value");
1411 assert_string_equal(type.patterns->dsc, "pattern-desc");
1412 assert_string_equal(type.patterns->ref, "pattern-ref");
1413 lysp_type_free(st->ctx, &type);
1414 memset(&type, 0, sizeof(type));
1415
1416 /* min subelems */
1417 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
1418 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1419 assert_string_equal(type.patterns->arg, "\x006pattern");
1420 lysp_type_free(st->ctx, &type);
1421 memset(&type, 0, sizeof(type));
1422
1423 st->finished_correctly = true;
1424}
1425
1426static void
1427test_value_position_elem(void **state)
1428{
1429 struct state *st = *state;
1430 const char *data;
1431 struct lysp_type_enum en = {};
1432
1433 /* valid values */
1434 data = ELEMENT_WRAPPER_START "<value value=\"55\" />" ELEMENT_WRAPPER_END;
1435 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1436 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001437 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001438 memset(&en, 0, sizeof(en));
1439
1440 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
1441 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1442 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001443 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001444 memset(&en, 0, sizeof(en));
1445
1446 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
1447 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1448 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001449 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001450 memset(&en, 0, sizeof(en));
1451
1452 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
1453 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1454 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001455 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001456 memset(&en, 0, sizeof(en));
1457
1458 /* valid positions */
1459 data = ELEMENT_WRAPPER_START "<position value=\"55\" />" ELEMENT_WRAPPER_END;
1460 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1461 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001462 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001463 memset(&en, 0, sizeof(en));
1464
1465 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
1466 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1467 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001468 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001469 memset(&en, 0, sizeof(en));
1470
1471 /* invalid values */
1472 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
1473 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1474 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\". Line number 1.");
1475
1476 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
1477 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1478 logbuf_assert("Invalid value \"1k\" of \"value\". Line number 1.");
1479
David Sedlák69f01612019-07-17 11:41:08 +02001480 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
1481 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1482 logbuf_assert("Invalid value \"\" of \"value\". Line number 1.");
1483
David Sedlák8e7bda82019-07-16 17:57:50 +02001484 /*invalid positions */
1485 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
1486 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1487 logbuf_assert("Invalid value \"-5\" of \"position\". Line number 1.");
1488
1489 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
1490 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1491 logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1.");
1492
1493 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
1494 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1495 logbuf_assert("Invalid value \"99999999999999999999\" of \"position\". Line number 1.");
1496
David Sedlák69f01612019-07-17 11:41:08 +02001497 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
1498 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1499 logbuf_assert("Invalid value \"\" of \"position\". Line number 1.");
1500
1501 st->finished_correctly = true;
1502}
1503
1504static void
1505test_prefix_elem(void **state)
1506{
1507 struct state *st = *state;
1508 const char *data;
1509 const char *value = NULL;
1510
1511 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
1512 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
1513 assert_string_equal(value, "pref");
1514 FREE_STRING(st->ctx, value);
1515
1516 st->finished_correctly = true;
1517}
1518
1519static void
1520test_range_elem(void **state)
1521{
1522 struct state *st = *state;
1523 const char *data;
1524 struct lysp_type type = {};
1525
1526 /* max subelems */
1527 data = ELEMENT_WRAPPER_START
1528 "<range value=\"range-str\">"
1529 "<error-message><value>err-msg</value></error-message>"
1530 "<error-app-tag value=\"err-app-tag\" />"
1531 "<description><text>desc</text></description>"
1532 "<reference><text>ref</text></reference>"
1533 "</range>"
1534 ELEMENT_WRAPPER_END;
1535 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1536 assert_string_equal(type.range->arg, "range-str");
1537 assert_string_equal(type.range->dsc, "desc");
1538 assert_string_equal(type.range->eapptag, "err-app-tag");
1539 assert_string_equal(type.range->emsg, "err-msg");
1540 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001541 assert_true(type.flags & LYS_SET_RANGE);
David Sedlák69f01612019-07-17 11:41:08 +02001542 lysp_type_free(st->ctx, &type);
1543 memset(&type, 0, sizeof(type));
1544
1545 /* min subelems */
1546 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
1547 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1548 assert_string_equal(type.range->arg, "range-str");
1549 lysp_type_free(st->ctx, &type);
1550 memset(&type, 0, sizeof(type));
1551
1552 st->finished_correctly = true;
1553}
1554
1555static void
1556test_reqinstance_elem(void **state)
1557{
1558 struct state *st = *state;
1559 const char *data;
1560 struct lysp_type type = {};
1561
1562 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\"/>" ELEMENT_WRAPPER_END;
1563 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1564 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001565 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001566 memset(&type, 0, sizeof(type));
1567
1568 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
1569 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1570 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001571 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001572 memset(&type, 0, sizeof(type));
1573
1574 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1575 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1576 memset(&type, 0, sizeof(type));
1577 logbuf_assert("Invalid value \"invalid\" of \"require-instance\". Line number 1.");
1578
1579 st->finished_correctly = true;
1580}
1581
1582static void
1583test_revision_date_elem(void **state)
1584{
1585 struct state *st = *state;
1586 const char *data;
1587 char rev[LY_REV_SIZE];
1588
1589 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
1590 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS);
1591 assert_string_equal(rev, "2000-01-01");
1592
1593 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
1594 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID);
1595 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1596
1597 st->finished_correctly = true;
1598}
1599
1600static void
1601test_unique_elem(void **state)
1602{
1603 struct state *st = *state;
1604 const char *data;
1605 const char **values = NULL;
1606
1607 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
1608 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1609 assert_string_equal(*values, "tag");
1610 FREE_STRING(st->ctx, *values);
1611 LY_ARRAY_FREE(values);
1612
1613 st->finished_correctly = true;
1614}
1615
1616static void
1617test_units_elem(void **state)
1618{
1619 struct state *st = *state;
1620 const char *data;
1621 const char *values = NULL;
1622
1623 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
1624 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1625 assert_string_equal(values, "name");
1626 FREE_STRING(st->ctx, values);
1627
1628 st->finished_correctly = true;
1629}
1630
1631static void
1632test_when_elem(void **state)
1633{
1634 struct state *st = *state;
1635 const char *data;
1636 struct lysp_when *when = NULL;
1637
1638 data = ELEMENT_WRAPPER_START
1639 "<when condition=\"cond\">"
1640 "<description><text>desc</text></description>"
1641 "<reference><text>ref</text></reference>"
1642 "</when>"
1643 ELEMENT_WRAPPER_END;
1644 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
1645 assert_string_equal(when->cond, "cond");
1646 assert_string_equal(when->dsc, "desc");
1647 assert_string_equal(when->ref, "ref");
1648 lysp_when_free(st->ctx, when);
1649 free(when);
1650 when = NULL;
1651
1652 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
1653 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
1654 assert_string_equal(when->cond, "cond");
1655 lysp_when_free(st->ctx, when);
1656 free(when);
1657 when = NULL;
1658
1659 st->finished_correctly = true;
1660}
1661
1662static void
1663test_yin_text_value_elem(void **state)
1664{
1665 struct state *st = *state;
1666 const char *data;
1667 const char *val;
1668
1669 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
1670 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1671 assert_string_equal(val, "text");
1672 FREE_STRING(st->ctx, val);
1673
1674 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
1675 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1676 assert_string_equal(val, "text");
1677 FREE_STRING(st->ctx, val);
1678
1679 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
1680 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1681 assert_string_equal("", val);
1682 FREE_STRING(st->ctx, val);
1683
David Sedlák8e7bda82019-07-16 17:57:50 +02001684 st->finished_correctly = true;
1685}
David Sedlák32488102019-07-15 17:44:10 +02001686
David Sedlák374d2b32019-07-17 15:06:55 +02001687static void
1688test_type_elem(void **state)
1689{
1690 struct state *st = *state;
1691 const char *data;
1692 struct lysp_type type = {};
1693
1694 /* max subelems */
1695 data = ELEMENT_WRAPPER_START
1696 "<type name=\"type-name\">"
1697 "<base name=\"base-name\"/>"
1698 "<bit name=\"bit\"/>"
1699 "<enum name=\"enum\"/>"
1700 "<fraction-digits value=\"2\"/>"
1701 "<length value=\"length\"/>"
1702 "<path value=\"path\"/>"
1703 "<pattern value=\"pattern\"/>"
1704 "<range value=\"range\" />"
1705 "<require-instance value=\"true\"/>"
1706 "<type name=\"sub-type-name\"/>"
1707 "</type>"
1708 ELEMENT_WRAPPER_END;
1709 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1710 assert_string_equal(type.name, "type-name");
1711 assert_string_equal(*type.bases, "base-name");
1712 assert_string_equal(type.bits->name, "bit");
1713 assert_string_equal(type.enums->name, "enum");
1714 assert_int_equal(type.fraction_digits, 2);
1715 assert_string_equal(type.length->arg, "length");
1716 assert_string_equal(type.path, "path");
1717 assert_string_equal(type.patterns->arg, "\006pattern");
1718 assert_string_equal(type.range->arg, "range");
1719 assert_int_equal(type.require_instance, 1);
1720 assert_string_equal(type.types->name, "sub-type-name");
1721 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001722 assert_true(type.flags & LYS_SET_BASE);
1723 assert_true(type.flags & LYS_SET_BIT);
1724 assert_true(type.flags & LYS_SET_ENUM);
1725 assert_true(type.flags & LYS_SET_FRDIGITS);
1726 assert_true(type.flags & LYS_SET_LENGTH);
1727 assert_true(type.flags & LYS_SET_PATH);
1728 assert_true(type.flags & LYS_SET_PATTERN);
1729 assert_true(type.flags & LYS_SET_RANGE);
1730 assert_true(type.flags & LYS_SET_REQINST);
1731 assert_true(type.flags & LYS_SET_TYPE);
David Sedlák374d2b32019-07-17 15:06:55 +02001732 memset(&type, 0, sizeof(type));
1733
1734 /* min subelems */
1735 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
1736 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1737 lysp_type_free(st->ctx, &type);
1738 memset(&type, 0, sizeof(type));
1739
1740 st->finished_correctly = true;
1741}
1742
David Sedlák1af868e2019-07-17 17:03:14 +02001743static void
1744test_max_elems_elem(void **state)
1745{
1746 struct state *st = *state;
1747 const char *data;
1748 struct lysp_node_list list = {};
1749 struct lysp_node_leaflist llist = {};
1750 struct lysp_refine refine = {};
1751
1752 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\"/> </refine>";
1753 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1754 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001755 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001756
1757 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\"/> </list>";
1758 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
1759 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001760 assert_true(list.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001761
1762 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\"/> </leaf-list>";
1763 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
1764 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001765 assert_true(llist.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001766
1767 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
1768 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1769 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001770 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001771
1772 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
1773 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1774 logbuf_assert("Invalid value \"0\" of \"max-elements\". Line number 1.");
1775
1776 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
1777 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1778 logbuf_assert("Invalid value \"-10\" of \"max-elements\". Line number 1.");
1779
1780 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
1781 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1782 logbuf_assert("Invalid value \"k\" of \"max-elements\". Line number 1.");
1783
1784 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
1785 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1786 logbuf_assert("Invalid value \"u12\" of \"max-elements\". Line number 1.");
1787
1788 st->finished_correctly = true;
1789}
1790
David Sedlák09e18c92019-07-18 11:17:11 +02001791static void
1792test_min_elems_elem(void **state)
1793{
1794 struct state *st = *state;
1795 const char *data;
1796 struct lysp_node_list list = {};
1797 struct lysp_node_leaflist llist = {};
1798 struct lysp_refine refine = {};
1799
1800 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\"/> </refine>";
1801 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1802 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001803 assert_true(refine.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001804
1805 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\"/> </list>";
1806 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
1807 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001808 assert_true(list.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001809
1810 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\"/> </leaf-list>";
1811 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
1812 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001813 assert_true(llist.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001814
1815 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
1816 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1817 logbuf_assert("Value \"-5\" is out of \"min-elements\" bounds. Line number 1.");
1818
1819 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
1820 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1821 logbuf_assert("Value \"99999999999999999\" is out of \"min-elements\" bounds. Line number 1.");
1822
1823 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
1824 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1825 logbuf_assert("Invalid value \"5k\" of \"min-elements\". Line number 1.");
1826
1827 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
1828 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1829 logbuf_assert("Invalid value \"05\" of \"min-elements\". Line number 1.");
1830
1831 st->finished_correctly = true;
1832}
1833
David Sedláka2dad212019-07-18 12:45:19 +02001834static void
1835test_ordby_elem(void **state)
1836{
1837 struct state *st = *state;
1838 const char *data;
1839 uint16_t flags = 0;
1840
1841 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\"/>" ELEMENT_WRAPPER_END;
1842 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001843 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláka2dad212019-07-18 12:45:19 +02001844
1845 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
1846 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001847 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001848
1849 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
1850 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
1851 logbuf_assert("Invalid value \"inv\" of \"ordered-by\". Line number 1.");
1852
1853 st->finished_correctly = true;
1854}
1855
David Sedlák8a83bbb2019-07-18 14:46:00 +02001856static void
1857test_any_elem(void **state)
1858{
1859 struct state *st = *state;
1860 const char *data;
1861 struct lysp_node *siblings = NULL;
1862 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1863 struct lysp_node_anydata *parsed = NULL;
1864
1865 /* anyxml max subelems */
1866 data = ELEMENT_WRAPPER_START
1867 "<anyxml name=\"any-name\">"
1868 "<config value=\"true\" />"
1869 "<description><text>desc</text></description>"
1870 "<if-feature name=\"feature\" />"
1871 "<mandatory value=\"true\" />"
1872 "<must condition=\"must-cond\" />"
1873 "<reference><text>ref</text></reference>"
1874 "<status value=\"deprecated\"/>"
1875 "<when condition=\"when-cond\"/>"
1876 "</anyxml>"
1877 ELEMENT_WRAPPER_END;
1878 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1879 parsed = (struct lysp_node_anydata *)siblings;
1880 assert_null(parsed->parent);
1881 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001882 assert_true(parsed->flags & LYS_CONFIG_W);
1883 assert_true(parsed->flags & LYS_MAND_TRUE);
1884 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001885 assert_null(parsed->next);
1886 assert_string_equal(parsed->name, "any-name");
1887 assert_string_equal(parsed->dsc, "desc");
1888 assert_string_equal(parsed->ref, "ref");
1889 assert_string_equal(parsed->when->cond, "when-cond");
1890 assert_string_equal(*parsed->iffeatures, "feature");
1891 assert_null(parsed->exts);
1892 lysp_node_free(st->ctx, siblings);
1893 siblings = NULL;
1894
1895 /* anydata max subelems */
1896 data = ELEMENT_WRAPPER_START
1897 "<anydata name=\"any-name\">"
1898 "<config value=\"true\" />"
1899 "<description><text>desc</text></description>"
1900 "<if-feature name=\"feature\" />"
1901 "<mandatory value=\"true\" />"
1902 "<must condition=\"must-cond\" />"
1903 "<reference><text>ref</text></reference>"
1904 "<status value=\"deprecated\"/>"
1905 "<when condition=\"when-cond\"/>"
1906 "</anydata>"
1907 ELEMENT_WRAPPER_END;
1908 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1909 parsed = (struct lysp_node_anydata *)siblings;
1910 assert_null(parsed->parent);
1911 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001912 assert_true(parsed->flags & LYS_CONFIG_W);
1913 assert_true(parsed->flags & LYS_MAND_TRUE);
1914 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001915 assert_null(parsed->next);
1916 assert_string_equal(parsed->name, "any-name");
1917 assert_string_equal(parsed->dsc, "desc");
1918 assert_string_equal(parsed->ref, "ref");
1919 assert_string_equal(parsed->when->cond, "when-cond");
1920 assert_string_equal(*parsed->iffeatures, "feature");
1921 assert_null(parsed->exts);
1922 lysp_node_free(st->ctx, siblings);
1923 siblings = NULL;
1924
1925 /* min subelems */
1926 node_meta.parent = (void *)0x10;
1927 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
1928 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1929 parsed = (struct lysp_node_anydata *)siblings;
1930 assert_ptr_equal(parsed->parent, node_meta.parent);
1931 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
1932 assert_null(parsed->next);
1933 assert_null(parsed->exts);
1934 lysp_node_free(st->ctx, siblings);
1935
1936 st->finished_correctly = true;
1937}
1938
David Sedlák203ca3a2019-07-18 15:26:25 +02001939static void
1940test_leaf_elem(void **state)
1941{
1942 struct state *st = *state;
1943 const char *data;
1944 struct lysp_node *siblings = NULL;
1945 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1946 struct lysp_node_leaf *parsed = NULL;
1947
1948 /* max elements */
1949 data = ELEMENT_WRAPPER_START
1950 "<leaf name=\"leaf\">"
1951 "<config value=\"true\" />"
1952 "<default value=\"def-val\"/>"
1953 "<description><text>desc</text></description>"
1954 "<if-feature name=\"feature\" />"
1955 "<mandatory value=\"true\" />"
1956 "<must condition=\"must-cond\" />"
1957 "<reference><text>ref</text></reference>"
1958 "<status value=\"deprecated\"/>"
1959 "<type name=\"type\"/>"
1960 "<units name=\"uni\"/>"
1961 "<when condition=\"when-cond\"/>"
1962 "</leaf>"
1963 ELEMENT_WRAPPER_END;
1964 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1965 parsed = (struct lysp_node_leaf *)siblings;
1966 assert_null(parsed->parent);
1967 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001968 assert_true(parsed->flags & LYS_CONFIG_W);
1969 assert_true(parsed->flags & LYS_MAND_TRUE);
1970 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02001971 assert_null(parsed->next);
1972 assert_string_equal(parsed->name, "leaf");
1973 assert_string_equal(parsed->dsc, "desc");
1974 assert_string_equal(parsed->ref, "ref");
1975 assert_string_equal(parsed->when->cond, "when-cond");
1976 assert_string_equal(*parsed->iffeatures, "feature");
1977 assert_null(parsed->exts);
1978 assert_string_equal(parsed->musts->arg, "must-cond");
1979 assert_string_equal(parsed->type.name, "type");
1980 assert_string_equal(parsed->units, "uni");
1981 assert_string_equal(parsed->dflt, "def-val");
1982 lysp_node_free(st->ctx, siblings);
1983 siblings = NULL;
1984
1985 /* min elements */
1986 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
1987 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1988 parsed = (struct lysp_node_leaf *)siblings;
1989 assert_string_equal(parsed->name, "leaf");
1990 assert_string_equal(parsed->type.name, "type");
1991 lysp_node_free(st->ctx, siblings);
1992 siblings = NULL;
1993
1994 st->finished_correctly = true;
1995}
1996
David Sedlákc3da3ef2019-07-19 12:56:08 +02001997static void
1998test_leaf_list_elem(void **state)
1999{
2000 struct state *st = *state;
2001 const char *data;
2002 struct lysp_node *siblings = NULL;
2003 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
2004 struct lysp_node_leaflist *parsed = NULL;
2005
2006 data = ELEMENT_WRAPPER_START
2007 "<leaf-list name=\"llist\">"
2008 "<config value=\"true\" />"
2009 "<default value=\"def-val0\"/>"
2010 "<default value=\"def-val1\"/>"
2011 "<description><text>desc</text></description>"
2012 "<if-feature name=\"feature\"/>"
2013 "<max-elements value=\"5\"/>"
2014 "<must condition=\"must-cond\"/>"
2015 "<ordered-by value=\"user\" />"
2016 "<reference><text>ref</text></reference>"
2017 "<status value=\"current\"/>"
2018 "<type name=\"type\"/>"
2019 "<units name=\"uni\"/>"
2020 "<when condition=\"when-cond\"/>"
2021 "</leaf-list>"
2022 ELEMENT_WRAPPER_END;
2023 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2024 parsed = (struct lysp_node_leaflist *)siblings;
2025 assert_string_equal(parsed->dflts[0], "def-val0");
2026 assert_string_equal(parsed->dflts[1], "def-val1");
2027 assert_string_equal(parsed->dsc, "desc");
2028 assert_string_equal(*parsed->iffeatures, "feature");
2029 assert_int_equal(parsed->max, 5);
2030 assert_string_equal(parsed->musts->arg, "must-cond");
2031 assert_string_equal(parsed->name, "llist");
2032 assert_null(parsed->next);
2033 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2034 assert_null(parsed->parent);
2035 assert_string_equal(parsed->ref, "ref");
2036 assert_string_equal(parsed->type.name, "type");
2037 assert_string_equal(parsed->units, "uni");
2038 assert_string_equal(parsed->when->cond, "when-cond");
2039 assert_true(parsed->flags & LYS_CONFIG_W);
2040 assert_true(parsed->flags & LYS_ORDBY_USER);
2041 assert_true(parsed->flags & LYS_STATUS_CURR);
2042 lysp_node_free(st->ctx, siblings);
2043 siblings = NULL;
2044
2045 data = ELEMENT_WRAPPER_START
2046 "<leaf-list name=\"llist\">"
2047 "<config value=\"true\" />"
2048 "<description><text>desc</text></description>"
2049 "<if-feature name=\"feature\"/>"
2050 "<min-elements value=\"5\"/>"
2051 "<must condition=\"must-cond\"/>"
2052 "<ordered-by value=\"user\" />"
2053 "<reference><text>ref</text></reference>"
2054 "<status value=\"current\"/>"
2055 "<type name=\"type\"/>"
2056 "<units name=\"uni\"/>"
2057 "<when condition=\"when-cond\"/>"
2058 "</leaf-list>"
2059 ELEMENT_WRAPPER_END;
2060 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2061 parsed = (struct lysp_node_leaflist *)siblings;
2062 assert_string_equal(parsed->dsc, "desc");
2063 assert_string_equal(*parsed->iffeatures, "feature");
2064 assert_int_equal(parsed->min, 5);
2065 assert_string_equal(parsed->musts->arg, "must-cond");
2066 assert_string_equal(parsed->name, "llist");
2067 assert_null(parsed->next);
2068 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2069 assert_null(parsed->parent);
2070 assert_string_equal(parsed->ref, "ref");
2071 assert_string_equal(parsed->type.name, "type");
2072 assert_string_equal(parsed->units, "uni");
2073 assert_string_equal(parsed->when->cond, "when-cond");
2074 assert_true(parsed->flags & LYS_CONFIG_W);
2075 assert_true(parsed->flags & LYS_ORDBY_USER);
2076 assert_true(parsed->flags & LYS_STATUS_CURR);
2077 lysp_node_free(st->ctx, siblings);
2078 siblings = NULL;
2079
2080 data = ELEMENT_WRAPPER_START
2081 "<leaf-list name=\"llist\">"
2082 "<config value=\"true\" />"
2083 "<description><text>desc</text></description>"
2084 "<if-feature name=\"feature\"/>"
2085 "<max-elements value=\"15\"/>"
2086 "<min-elements value=\"5\"/>"
2087 "<must condition=\"must-cond\"/>"
2088 "<ordered-by value=\"user\" />"
2089 "<reference><text>ref</text></reference>"
2090 "<status value=\"current\"/>"
2091 "<type name=\"type\"/>"
2092 "<units name=\"uni\"/>"
2093 "<when condition=\"when-cond\"/>"
2094 "</leaf-list>"
2095 ELEMENT_WRAPPER_END;
2096 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2097 parsed = (struct lysp_node_leaflist *)siblings;
2098 assert_string_equal(parsed->dsc, "desc");
2099 assert_string_equal(*parsed->iffeatures, "feature");
2100 assert_int_equal(parsed->min, 5);
2101 assert_int_equal(parsed->max, 15);
2102 assert_string_equal(parsed->musts->arg, "must-cond");
2103 assert_string_equal(parsed->name, "llist");
2104 assert_null(parsed->next);
2105 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2106 assert_null(parsed->parent);
2107 assert_string_equal(parsed->ref, "ref");
2108 assert_string_equal(parsed->type.name, "type");
2109 assert_string_equal(parsed->units, "uni");
2110 assert_string_equal(parsed->when->cond, "when-cond");
2111 assert_true(parsed->flags & LYS_CONFIG_W);
2112 assert_true(parsed->flags & LYS_ORDBY_USER);
2113 assert_true(parsed->flags & LYS_STATUS_CURR);
2114 lysp_node_free(st->ctx, siblings);
2115 siblings = NULL;
2116
2117 data = ELEMENT_WRAPPER_START
2118 "<leaf-list name=\"llist\">"
2119 "<type name=\"type\"/>"
2120 "</leaf-list>"
2121 ELEMENT_WRAPPER_END;
2122 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2123 parsed = (struct lysp_node_leaflist *)siblings;
2124 assert_string_equal(parsed->name, "llist");
2125 assert_string_equal(parsed->type.name, "type");
2126 lysp_node_free(st->ctx, siblings);
2127 siblings = NULL;
2128
2129 /* invalid combinations */
2130 data = ELEMENT_WRAPPER_START
2131 "<leaf-list name=\"llist\">"
2132 "<max-elements value=\"5\"/>"
2133 "<min-elements value=\"15\"/>"
2134 "<type name=\"type\"/>"
2135 "</leaf-list>"
2136 ELEMENT_WRAPPER_END;
2137 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2138 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2139 lysp_node_free(st->ctx, siblings);
2140 siblings = NULL;
2141
2142 data = ELEMENT_WRAPPER_START
2143 "<leaf-list name=\"llist\">"
2144 "<default value=\"def-val1\"/>"
2145 "<min-elements value=\"15\"/>"
2146 "<type name=\"type\"/>"
2147 "</leaf-list>"
2148 ELEMENT_WRAPPER_END;
2149 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2150 logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1.");
2151 lysp_node_free(st->ctx, siblings);
2152 siblings = NULL;
2153
2154 data = ELEMENT_WRAPPER_START
2155 "<leaf-list name=\"llist\">"
2156 "</leaf-list>"
2157 ELEMENT_WRAPPER_END;
2158 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2159 logbuf_assert("Missing mandatory subelement type of leaf-list element. Line number 1.");
2160 lysp_node_free(st->ctx, siblings);
2161 siblings = NULL;
2162
2163 st->finished_correctly = true;
2164}
2165
David Sedlákcb39f642019-07-19 13:19:55 +02002166static void
2167test_presence_elem(void **state)
2168{
2169 struct state *st = *state;
2170 const char *data;
2171 const char *val;
2172
2173 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
2174 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2175 assert_string_equal(val, "presence-val");
2176 FREE_STRING(st->ctx, val);
2177
2178 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
2179 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2180 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2181
2182 st->finished_correctly = true;
2183}
2184
David Sedlák12470a82019-07-19 13:44:36 +02002185static void
2186test_key_elem(void **state)
2187{
2188 struct state *st = *state;
2189 const char *data;
2190 const char *val;
2191
2192 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
2193 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2194 assert_string_equal(val, "key-value");
2195 FREE_STRING(st->ctx, val);
2196
2197 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
2198 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2199 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2200
2201 st->finished_correctly = true;
2202}
2203
David Sedlák04e17b22019-07-19 15:29:48 +02002204static void
2205test_typedef_elem(void **state)
2206{
2207 struct state *st = *state;
2208 const char *data;
2209 struct lysp_tpdf *tpdfs = NULL;
2210 struct typedef_meta typdef_meta = {NULL, &tpdfs};
2211
2212 data = ELEMENT_WRAPPER_START
2213 "<typedef name=\"tpdf-name\">"
2214 "<default value=\"def-val\"/>"
2215 "<description><text>desc-text</text></description>"
2216 "<reference><text>ref-text</text></reference>"
2217 "<status value=\"current\"/>"
2218 "<type name=\"type\"/>"
2219 "<units name=\"uni\"/>"
2220 "</typedef>"
2221 ELEMENT_WRAPPER_END;
2222 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2223 assert_string_equal(tpdfs[0].dflt, "def-val");
2224 assert_string_equal(tpdfs[0].dsc, "desc-text");
2225 assert_null(tpdfs[0].exts);
2226 assert_string_equal(tpdfs[0].name, "tpdf-name");
2227 assert_string_equal(tpdfs[0].ref, "ref-text");
2228 assert_string_equal(tpdfs[0].type.name, "type");
2229 assert_string_equal(tpdfs[0].units, "uni");
2230 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
2231 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2232 tpdfs = NULL;
2233
2234 data = ELEMENT_WRAPPER_START
2235 "<typedef name=\"tpdf-name\">"
2236 "<type name=\"type\"/>"
2237 "</typedef>"
2238 ELEMENT_WRAPPER_END;
2239 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2240 assert_string_equal(tpdfs[0].name, "tpdf-name");
2241 assert_string_equal(tpdfs[0].type.name, "type");
2242 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2243 tpdfs = NULL;
2244
2245 st->finished_correctly = true;
2246}
2247
David Sedlákd2d676a2019-07-22 11:28:19 +02002248static void
2249test_refine_elem(void **state)
2250{
2251 struct state *st = *state;
2252 const char *data;
2253 struct lysp_refine *refines = NULL;
2254
2255 /* max subelems */
2256 data = ELEMENT_WRAPPER_START
2257 "<refine target-node=\"target\">"
2258 "<if-feature name=\"feature\" />"
2259 "<must condition=\"cond\" />"
2260 "<presence value=\"presence\" />"
2261 "<default value=\"def\" />"
2262 "<config value=\"true\" />"
2263 "<mandatory value=\"true\" />"
2264 "<min-elements value=\"10\" />"
2265 "<max-elements value=\"20\" />"
2266 "<description><text>desc</text></description>"
2267 "<reference><text>ref</text></reference>"
2268 "</refine>"
2269 ELEMENT_WRAPPER_END;
2270 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2271 assert_string_equal(refines->nodeid, "target");
2272 assert_string_equal(*refines->dflts, "def");
2273 assert_string_equal(refines->dsc, "desc");
2274 assert_null(refines->exts);
2275 assert_true(refines->flags & LYS_CONFIG_W);
2276 assert_true(refines->flags & LYS_MAND_TRUE);
2277 assert_string_equal(*refines->iffeatures, "feature");
2278 assert_int_equal(refines->max, 20);
2279 assert_int_equal(refines->min, 10);
2280 assert_string_equal(refines->musts->arg, "cond");
2281 assert_string_equal(refines->presence, "presence");
2282 assert_string_equal(refines->ref, "ref");
2283 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2284 refines = NULL;
2285
2286 /* min subelems */
2287 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
2288 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2289 assert_string_equal(refines->nodeid, "target");
2290 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2291 refines = NULL;
2292
2293 st->finished_correctly = true;
2294}
2295
David Sedlák0d6de5a2019-07-22 13:25:44 +02002296static void
2297test_uses_elem(void **state)
2298{
2299 struct state *st = *state;
2300 const char *data;
2301 struct lysp_node *siblings = NULL;
2302 struct tree_node_meta node_meta = {NULL, &siblings};
2303 struct lysp_node_uses *parsed = NULL;
2304
2305 /* max subelems */
2306 data = ELEMENT_WRAPPER_START
2307 "<uses name=\"uses-name\">"
2308 "<when condition=\"cond\" />"
2309 "<if-feature name=\"feature\" />"
2310 "<status value=\"obsolete\" />"
2311 "<description><text>desc</text></description>"
2312 "<reference><text>ref</text></reference>"
2313 "<refine target-node=\"target\"/>"
2314 /* TODO add uses-augment-stmt instance */
2315 "</uses>"
2316 ELEMENT_WRAPPER_END;
2317 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2318 parsed = (struct lysp_node_uses *)&siblings[0];
2319 assert_string_equal(parsed->name, "uses-name");
2320 assert_string_equal(parsed->dsc, "desc");
2321 assert_null(parsed->exts);
2322 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2323 assert_string_equal(*parsed->iffeatures, "feature");
2324 assert_null(parsed->next);
2325 assert_int_equal(parsed->nodetype, LYS_USES);
2326 assert_null(parsed->parent);
2327 assert_string_equal(parsed->ref, "ref");
2328 assert_string_equal(parsed->refines->nodeid, "target");
2329 assert_string_equal(parsed->when->cond, "cond");
2330 lysp_node_free(st->ctx, siblings);
2331 siblings = NULL;
2332
2333 /* min subelems */
2334 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
2335 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2336 assert_string_equal(siblings[0].name, "uses-name");
2337 lysp_node_free(st->ctx, siblings);
2338 siblings = NULL;
2339
2340 st->finished_correctly = true;
2341}
2342
David Sedlákaa854b02019-07-22 14:17:10 +02002343static void
2344test_revision_elem(void **state)
2345{
2346 struct state *st = *state;
2347 const char *data;
2348 struct lysp_revision *revs = NULL;
2349
2350 /* max subelems */
2351 data = ELEMENT_WRAPPER_START
2352 "<revision date=\"2018-12-25\">"
2353 "<description><text>desc</text></description>"
2354 "<reference><text>ref</text></reference>"
2355 "</revision>"
2356 ELEMENT_WRAPPER_END;
2357 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2358 assert_string_equal(revs->date, "2018-12-25");
2359 assert_string_equal(revs->dsc, "desc");
2360 assert_string_equal(revs->ref, "ref");
2361 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2362 revs = NULL;
2363
2364 /* min subelems */
2365 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
2366 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2367 assert_string_equal(revs->date, "2005-05-05");
2368 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2369 revs = NULL;
2370
2371 /* invalid value */
2372 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
2373 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID);
2374 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2375 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2376 revs = NULL;
2377
2378 st->finished_correctly = true;
2379}
2380
David Sedlák0c2bab92019-07-22 15:33:19 +02002381static void
2382test_include_elem(void **state)
2383{
2384 struct state *st = *state;
2385 const char *data;
2386 struct lysp_include *includes = NULL;
2387 struct include_meta inc_meta = {"module-name", &includes};
2388
2389 /* max subelems */
2390 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2391 data = ELEMENT_WRAPPER_START
2392 "<include module=\"mod\">"
2393 "<description><text>desc</text></description>"
2394 "<reference><text>ref</text></reference>"
2395 "<revision-date date=\"1999-09-09\"/>"
2396 "</include>"
2397 ELEMENT_WRAPPER_END;
2398 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2399 assert_string_equal(includes->name, "mod");
2400 assert_string_equal(includes->dsc, "desc");
2401 assert_string_equal(includes->ref, "ref");
2402 assert_null(includes->exts);
2403 assert_string_equal(includes->rev, "1999-09-09");
2404 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2405 includes = NULL;
2406
2407 /* min subelems */
2408 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
2409 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2410 assert_string_equal(includes->name, "mod");
2411 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2412 includes = NULL;
2413
2414 /* invalid combinations */
2415 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2416 data = ELEMENT_WRAPPER_START
2417 "<include module=\"mod\">"
2418 "<description><text>desc</text></description>"
2419 "<revision-date date=\"1999-09-09\"/>"
2420 "</include>"
2421 ELEMENT_WRAPPER_END;
2422 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2423 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.");
2424 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2425 includes = NULL;
2426
2427 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2428 data = ELEMENT_WRAPPER_START
2429 "<include module=\"mod\">"
2430 "<reference><text>ref</text></reference>"
2431 "<revision-date date=\"1999-09-09\"/>"
2432 "</include>"
2433 ELEMENT_WRAPPER_END;
2434 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2435 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.");
2436 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2437 includes = NULL;
2438
2439 st->finished_correctly = true;
2440}
2441
David Sedlák5e13dea2019-07-22 16:06:45 +02002442static void
2443test_feature_elem(void **state)
2444{
2445 struct state *st = *state;
2446 const char *data;
2447 struct lysp_feature *features = NULL;
2448
2449 /* max subelems */
2450 data = ELEMENT_WRAPPER_START
2451 "<feature name=\"feature-name\">"
2452 "<if-feature name=\"iff\"/>"
2453 "<status value=\"deprecated\"/>"
2454 "<description><text>desc</text></description>"
2455 "<reference><text>ref</text></reference>"
2456 "</feature>"
2457 ELEMENT_WRAPPER_END;
2458 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2459 assert_string_equal(features->name, "feature-name");
2460 assert_string_equal(features->dsc, "desc");
2461 assert_null(features->exts);
2462 assert_true(features->flags & LYS_STATUS_DEPRC);
2463 assert_string_equal(*features->iffeatures, "iff");
2464 assert_string_equal(features->ref, "ref");
2465 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2466 features = NULL;
2467
2468 /* min subelems */
2469 data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
2470 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2471 assert_string_equal(features->name, "feature-name");
2472 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2473 features = NULL;
2474
2475 st->finished_correctly = true;
2476}
2477
David Sedlák28794f22019-07-22 16:45:00 +02002478static void
2479test_identity_elem(void **state)
2480{
2481 struct state *st = *state;
2482 const char *data;
2483 struct lysp_ident *identities = NULL;
2484
2485 /* max subelems */
2486 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2487 data = ELEMENT_WRAPPER_START
2488 "<identity name=\"ident-name\">"
2489 "<if-feature name=\"iff\"/>"
2490 "<base name=\"base-name\"/>"
2491 "<status value=\"deprecated\"/>"
2492 "<description><text>desc</text></description>"
2493 "<reference><text>ref</text></reference>"
2494 "</identity>"
2495 ELEMENT_WRAPPER_END;
2496 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2497 assert_string_equal(identities->name, "ident-name");
2498 assert_string_equal(*identities->bases, "base-name");
2499 assert_string_equal(*identities->iffeatures, "iff");
2500 assert_string_equal(identities->dsc, "desc");
2501 assert_string_equal(identities->ref, "ref");
2502 assert_true(identities->flags & LYS_STATUS_DEPRC);
2503 assert_null(identities->exts);
2504 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2505 identities = NULL;
2506
2507 /* min subelems */
2508 data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END;
2509 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2510 assert_string_equal(identities->name, "ident-name");
2511 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2512 identities = NULL;
2513
2514 /* invalid */
2515 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2516 data = ELEMENT_WRAPPER_START
2517 "<identity name=\"ident-name\">"
2518 "<if-feature name=\"iff\"/>"
2519 "</identity>"
2520 ELEMENT_WRAPPER_END;
2521 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID);
2522 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.");
2523 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2524 identities = NULL;
2525
2526 st->finished_correctly = true;
2527}
2528
David Sedlákaf536aa2019-07-23 13:42:23 +02002529static void
2530test_list_elem(void **state)
2531{
2532 struct state *st = *state;
2533 const char *data;
2534 struct lysp_node *siblings = NULL;
2535 struct tree_node_meta node_meta = {NULL, &siblings};
2536 struct lysp_node_list *parsed = NULL;
2537
2538 /* max subelems */
2539 data = ELEMENT_WRAPPER_START
2540 "<list name=\"list-name\">"
2541 "<when condition=\"when\"/>"
2542 "<if-feature name=\"iff\"/>"
2543 "<must condition=\"must-cond\"/>"
2544 "<key value=\"key\"/>"
2545 "<unique tag=\"utag\"/>"
2546 "<config value=\"true\"/>"
2547 "<min-elements value=\"10\"/>"
2548 "<ordered-by value=\"user\"/>"
2549 "<status value=\"deprecated\"/>"
2550 "<description><text>desc</text></description>"
2551 "<reference><text>ref</text></reference>"
2552 "<anydata name=\"anyd\"/>"
2553 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002554 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002555 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002556 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002557 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002558 "<notification name=\"notf\"/>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002559 "<leaf name=\"leaf\"/>"
2560 "<leaf-list name=\"llist\"/>"
2561 "<list name=\"sub-list\"/>"
2562 "<typedef name=\"tpdf\"/>"
2563 "<uses name=\"uses-name\"/>"
2564 "</list>"
2565 ELEMENT_WRAPPER_END;
2566 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2567 parsed = (struct lysp_node_list *)&siblings[0];
2568 assert_string_equal(parsed->dsc, "desc");
2569 assert_string_equal(parsed->child->name, "anyd");
2570 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2571 assert_string_equal(parsed->child->next->name, "anyx");
2572 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002573 assert_string_equal(parsed->child->next->next->name, "cont");
2574 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002575 assert_string_equal(parsed->child->next->next->next->name, "choice");
2576 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002577 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2578 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2579 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2580 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2581 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2582 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2583 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2584 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2585 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002586 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002587 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002588 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002589 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02002590 assert_null(parsed->exts);
2591 assert_true(parsed->flags & LYS_ORDBY_USER);
2592 assert_true(parsed->flags & LYS_STATUS_DEPRC);
2593 assert_true(parsed->flags & LYS_CONFIG_W);
2594 assert_string_equal(*parsed->iffeatures, "iff");
2595 assert_string_equal(parsed->key, "key");
2596 assert_int_equal(parsed->min, 10);
2597 assert_string_equal(parsed->musts->arg, "must-cond");
2598 assert_string_equal(parsed->name, "list-name");
2599 assert_null(parsed->next);
2600 assert_int_equal(parsed->nodetype, LYS_LIST);
2601 assert_null(parsed->parent);
2602 assert_string_equal(parsed->ref, "ref");
2603 assert_string_equal(parsed->typedefs->name, "tpdf");
2604 assert_string_equal(*parsed->uniques, "utag");
2605 assert_string_equal(parsed->when->cond, "when");
2606 lysp_node_free(st->ctx, siblings);
2607 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2608 siblings = NULL;
2609
2610 /* min subelems */
2611 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
2612 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2613 parsed = (struct lysp_node_list *)&siblings[0];
2614 assert_string_equal(parsed->name, "list-name");
2615 lysp_node_free(st->ctx, siblings);
2616 siblings = NULL;
2617
2618 st->finished_correctly = true;
2619}
2620
David Sedlák031b9e72019-07-23 15:19:37 +02002621static void
2622test_notification_elem(void **state)
2623{
2624 struct state *st = *state;
2625 const char *data;
2626 struct lysp_notif *notifs = NULL;
2627 struct notif_meta notif_meta = {NULL, &notifs};
2628
2629 /* max subelems */
2630 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2631 data = ELEMENT_WRAPPER_START
2632 "<notification name=\"notif-name\">"
2633 "<anydata name=\"anyd\"/>"
2634 "<anyxml name=\"anyx\"/>"
2635 "<description><text>desc</text></description>"
2636 "<if-feature name=\"iff\"/>"
2637 "<leaf name=\"leaf\"/>"
2638 "<leaf-list name=\"llist\"/>"
2639 "<list name=\"sub-list\"/>"
2640 "<must condition=\"cond\"/>"
2641 "<reference><text>ref</text></reference>"
2642 "<status value=\"deprecated\"/>"
2643 "<typedef name=\"tpdf\"/>"
2644 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002645 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002646 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002647 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002648 "</notification>"
2649 ELEMENT_WRAPPER_END;
2650 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
2651 assert_string_equal(notifs->name, "notif-name");
2652 assert_string_equal(notifs->data->name, "anyd");
2653 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
2654 assert_string_equal(notifs->data->next->name, "anyx");
2655 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
2656 assert_string_equal(notifs->data->next->next->name, "leaf");
2657 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
2658 assert_string_equal(notifs->data->next->next->next->name, "llist");
2659 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
2660 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
2661 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
2662 assert_null(notifs->exts);
2663 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002664 assert_string_equal(notifs->groupings->name, "grp");
2665 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02002666 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
2667 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
2668 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
2669 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002670 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2671 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
2672 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02002673 assert_string_equal(*notifs->iffeatures, "iff");
2674 assert_string_equal(notifs->musts->arg, "cond");
2675 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2676 assert_null(notifs->parent);
2677 assert_string_equal(notifs->ref, "ref");
2678 assert_string_equal(notifs->typedefs->name, "tpdf");
2679 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
2680 notifs = NULL;
2681
2682 /* min subelems */
2683 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
2684 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
2685 assert_string_equal(notifs->name, "notif-name");
2686 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002687 notifs = NULL;
2688
2689 st->finished_correctly = true;
2690}
2691
2692static void
2693test_grouping_elem(void **state)
2694{
2695 struct state *st = *state;
2696 const char *data;
2697 struct lysp_grp *grps = NULL;
2698 struct grouping_meta grp_meta = {NULL, &grps};
2699
2700 /* max subelems */
2701 data = ELEMENT_WRAPPER_START
2702 "<grouping name=\"grp-name\">"
2703 "<anydata name=\"anyd\"/>"
2704 "<anyxml name=\"anyx\"/>"
2705 "<description><text>desc</text></description>"
2706 "<grouping name=\"sub-grp\"/>"
2707 "<leaf name=\"leaf\"/>"
2708 "<leaf-list name=\"llist\"/>"
2709 "<list name=\"list\"/>"
2710 "<notification name=\"notf\"/>"
2711 "<reference><text>ref</text></reference>"
2712 "<status value=\"current\"/>"
2713 "<typedef name=\"tpdf\"/>"
2714 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002715 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002716 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002717 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002718 "</grouping>"
2719 ELEMENT_WRAPPER_END;
2720 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
2721 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002722 assert_string_equal(grps->data->name, "anyd");
2723 assert_string_equal(grps->data->next->name, "anyx");
2724 assert_string_equal(grps->data->next->next->name, "leaf");
2725 assert_string_equal(grps->data->next->next->next->name, "llist");
2726 assert_string_equal(grps->data->next->next->next->next->name, "list");
2727 assert_string_equal(grps->dsc, "desc");
2728 assert_null(grps->exts);
2729 assert_true(grps->flags & LYS_STATUS_CURR);
2730 assert_string_equal(grps->groupings->name, "sub-grp");
2731 assert_int_equal(grps->nodetype, LYS_GROUPING);
2732 assert_string_equal(grps->notifs->name, "notf");
2733 assert_null(grps->parent);
2734 assert_string_equal(grps->ref, "ref");
2735 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002736 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02002737 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002738 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02002739 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002740 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2741 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
2742 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002743 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
2744 grps = NULL;
2745
2746 /* min subelems */
2747 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
2748 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
2749 assert_string_equal(grps->name, "grp-name");
2750 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
2751 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002752
2753 st->finished_correctly = true;
2754}
2755
David Sedlákf111bcb2019-07-23 17:15:51 +02002756static void
2757test_container_elem(void **state)
2758{
2759 struct state *st = *state;
2760 const char *data;
2761 struct lysp_node *siblings = NULL;
2762 struct tree_node_meta node_meta = {NULL, &siblings};
2763 struct lysp_node_container *parsed = NULL;
2764
2765 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02002766 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2767 data = ELEMENT_WRAPPER_START
2768 "<container name=\"cont-name\">"
2769 "<anydata name=\"anyd\"/>"
2770 "<anyxml name=\"anyx\"/>"
2771 "<config value=\"true\"/>"
2772 "<container name=\"subcont\"/>"
2773 "<description><text>desc</text></description>"
2774 "<grouping name=\"sub-grp\"/>"
2775 "<if-feature name=\"iff\"/>"
2776 "<leaf name=\"leaf\"/>"
2777 "<leaf-list name=\"llist\"/>"
2778 "<list name=\"list\"/>"
2779 "<must condition=\"cond\"/>"
2780 "<notification name=\"notf\"/>"
2781 "<presence value=\"presence\"/>"
2782 "<reference><text>ref</text></reference>"
2783 "<status value=\"current\"/>"
2784 "<typedef name=\"tpdf\"/>"
2785 "<uses name=\"uses-name\"/>"
2786 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002787 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002788 "<choice name=\"choice\"/>"
David Sedláke2dc9e92019-07-24 09:59:21 +02002789 "</container>"
2790 ELEMENT_WRAPPER_END;
2791 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2792 parsed = (struct lysp_node_container *)siblings;
2793 assert_string_equal(parsed->name, "cont-name");
2794 assert_null(parsed->parent);
2795 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
2796 assert_true(parsed->flags & LYS_CONFIG_W);
2797 assert_true(parsed->flags & LYS_STATUS_CURR);
2798 assert_null(parsed->next);
2799 assert_string_equal(parsed->dsc, "desc");
2800 assert_string_equal(parsed->ref, "ref");
2801 assert_string_equal(parsed->when->cond, "when-cond");
2802 assert_string_equal(*parsed->iffeatures, "iff");
2803 assert_null(parsed->exts);
2804 assert_string_equal(parsed->musts->arg, "cond");
2805 assert_string_equal(parsed->presence, "presence");
2806 assert_string_equal(parsed->typedefs->name, "tpdf");
2807 assert_string_equal(parsed->groupings->name, "sub-grp");
2808 assert_string_equal(parsed->child->name, "anyd");
2809 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2810 assert_string_equal(parsed->child->next->name, "anyx");
2811 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2812 assert_string_equal(parsed->child->next->next->name, "subcont");
2813 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2814 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2815 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2816 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2817 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2818 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2819 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2820 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2821 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002822 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2823 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2824 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02002825 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002826 assert_string_equal(parsed->actions->name, "act");
David Sedláke2dc9e92019-07-24 09:59:21 +02002827 lysp_node_free(st->ctx, siblings);
2828 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2829 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002830
2831 /* min subelems */
2832 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
2833 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2834 parsed = (struct lysp_node_container *)siblings;
2835 assert_string_equal(parsed->name, "cont-name");
2836 lysp_node_free(st->ctx, siblings);
2837 siblings = NULL;
2838
2839 st->finished_correctly = true;
2840}
2841
David Sedlák5379d392019-07-24 10:42:03 +02002842static void
2843test_case_elem(void **state)
2844{
2845 struct state *st = *state;
2846 const char *data;
2847 struct lysp_node *siblings = NULL;
2848 struct tree_node_meta node_meta = {NULL, &siblings};
2849 struct lysp_node_case *parsed = NULL;
2850
2851 /* max subelems */
2852 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2853 data = ELEMENT_WRAPPER_START
2854 "<case name=\"case-name\">"
2855 "<anydata name=\"anyd\"/>"
2856 "<anyxml name=\"anyx\"/>"
2857 "<container name=\"subcont\"/>"
2858 "<description><text>desc</text></description>"
2859 "<if-feature name=\"iff\"/>"
2860 "<leaf name=\"leaf\"/>"
2861 "<leaf-list name=\"llist\"/>"
2862 "<list name=\"list\"/>"
2863 "<reference><text>ref</text></reference>"
2864 "<status value=\"current\"/>"
2865 "<uses name=\"uses-name\"/>"
2866 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002867 "<choice name=\"choice\"/>"
David Sedlák5379d392019-07-24 10:42:03 +02002868 "</case>"
2869 ELEMENT_WRAPPER_END;
2870 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2871 parsed = (struct lysp_node_case *)siblings;
2872 assert_string_equal(parsed->name, "case-name");
2873 assert_null(parsed->parent);
2874 assert_int_equal(parsed->nodetype, LYS_CASE);
2875 assert_true(parsed->flags & LYS_STATUS_CURR);
2876 assert_null(parsed->next);
2877 assert_string_equal(parsed->dsc, "desc");
2878 assert_string_equal(parsed->ref, "ref");
2879 assert_string_equal(parsed->when->cond, "when-cond");
2880 assert_string_equal(*parsed->iffeatures, "iff");
2881 assert_null(parsed->exts);
2882 assert_string_equal(parsed->child->name, "anyd");
2883 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2884 assert_string_equal(parsed->child->next->name, "anyx");
2885 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2886 assert_string_equal(parsed->child->next->next->name, "subcont");
2887 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2888 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2889 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2890 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2891 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2892 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2893 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2894 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2895 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002896 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2897 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2898 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedlák5379d392019-07-24 10:42:03 +02002899 lysp_node_free(st->ctx, siblings);
2900 siblings = NULL;
2901
2902 /* min subelems */
2903 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
2904 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2905 parsed = (struct lysp_node_case *)siblings;
2906 assert_string_equal(parsed->name, "case-name");
2907 lysp_node_free(st->ctx, siblings);
2908 siblings = NULL;
2909
2910 st->finished_correctly = true;
2911}
2912
David Sedlákb7abcfa2019-07-24 12:33:35 +02002913static void
2914test_choice_elem(void **state)
2915{
2916 struct state *st = *state;
2917 const char *data;
2918 struct lysp_node *siblings = NULL;
2919 struct tree_node_meta node_meta = {NULL, &siblings};
2920 struct lysp_node_choice *parsed = NULL;
2921
2922 /* max subelems */
2923 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2924 data = ELEMENT_WRAPPER_START
2925 "<choice name=\"choice-name\">"
2926 "<anydata name=\"anyd\"/>"
2927 "<anyxml name=\"anyx\"/>"
2928 "<case name=\"sub-case\"/>"
2929 "<choice name=\"choice\"/>"
2930 "<config value=\"true\"/>"
2931 "<container name=\"subcont\"/>"
2932 "<default value=\"def\"/>"
2933 "<description><text>desc</text></description>"
2934 "<if-feature name=\"iff\"/>"
2935 "<leaf name=\"leaf\"/>"
2936 "<leaf-list name=\"llist\"/>"
2937 "<list name=\"list\"/>"
2938 "<mandatory value=\"true\" />"
2939 "<reference><text>ref</text></reference>"
2940 "<status value=\"current\"/>"
2941 "<when condition=\"when-cond\"/>"
2942 "</choice>"
2943 ELEMENT_WRAPPER_END;
2944 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2945 parsed = (struct lysp_node_choice *)siblings;
2946 assert_string_equal(parsed->name, "choice-name");
2947 assert_null(parsed->parent);
2948 assert_int_equal(parsed->nodetype, LYS_CHOICE);
2949 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
2950 assert_null(parsed->next);
2951 assert_string_equal(parsed->dsc, "desc");
2952 assert_string_equal(parsed->ref, "ref");
2953 assert_string_equal(parsed->when->cond, "when-cond");
2954 assert_string_equal(*parsed->iffeatures, "iff");
2955 assert_null(parsed->exts);
2956 assert_string_equal(parsed->child->name, "anyd");
2957 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2958 assert_string_equal(parsed->child->next->name, "anyx");
2959 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2960 assert_string_equal(parsed->child->next->next->name, "sub-case");
2961 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
2962 assert_string_equal(parsed->child->next->next->next->name, "choice");
2963 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2964 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
2965 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
2966 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
2967 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
2968 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
2969 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2970 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
2971 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
2972 assert_null(parsed->child->next->next->next->next->next->next->next->next);
2973 lysp_node_free(st->ctx, siblings);
2974 siblings = NULL;
2975
2976 /* min subelems */
2977 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
2978 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2979 parsed = (struct lysp_node_choice *)siblings;
2980 assert_string_equal(parsed->name, "choice-name");
2981 lysp_node_free(st->ctx, siblings);
2982 siblings = NULL;
2983
2984 st->finished_correctly = true;
2985}
2986
David Sedlák05404f62019-07-24 14:11:53 +02002987static void
2988test_inout_elem(void **state)
2989{
2990 struct state *st = *state;
2991 const char *data;
2992 struct lysp_action_inout inout = {};
2993 struct inout_meta inout_meta = {NULL, &inout};
2994
2995 /* max subelements */
2996 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2997 data = ELEMENT_WRAPPER_START
2998 "<input>"
2999 "<anydata name=\"anyd\"/>"
3000 "<anyxml name=\"anyx\"/>"
3001 "<choice name=\"choice\"/>"
3002 "<container name=\"subcont\"/>"
3003 "<grouping name=\"sub-grp\"/>"
3004 "<leaf name=\"leaf\"/>"
3005 "<leaf-list name=\"llist\"/>"
3006 "<list name=\"list\"/>"
3007 "<must condition=\"cond\"/>"
3008 "<typedef name=\"tpdf\"/>"
3009 "<uses name=\"uses-name\"/>"
3010 "</input>"
3011 ELEMENT_WRAPPER_END;
3012 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3013 assert_null(inout.parent);
3014 assert_int_equal(inout.nodetype, LYS_INPUT);
3015 assert_string_equal(inout.musts->arg, "cond");
3016 assert_string_equal(inout.typedefs->name, "tpdf");
3017 assert_string_equal(inout.groupings->name, "sub-grp");
3018 assert_string_equal(inout.data->name, "anyd");
3019 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3020 assert_string_equal(inout.data->next->name, "anyx");
3021 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3022 assert_string_equal(inout.data->next->next->name, "choice");
3023 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3024 assert_string_equal(inout.data->next->next->next->name, "subcont");
3025 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3026 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3027 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3028 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3029 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3030 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3031 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3032 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3033 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3034 assert_null(inout.data->next->next->next->next->next->next->next->next);
3035 lysp_action_inout_free(st->ctx, &inout);
3036 memset(&inout, 0, sizeof inout);
3037
3038 /* max subelements */
3039 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3040 data = ELEMENT_WRAPPER_START
3041 "<output>"
3042 "<anydata name=\"anyd\"/>"
3043 "<anyxml name=\"anyx\"/>"
3044 "<choice name=\"choice\"/>"
3045 "<container name=\"subcont\"/>"
3046 "<grouping name=\"sub-grp\"/>"
3047 "<leaf name=\"leaf\"/>"
3048 "<leaf-list name=\"llist\"/>"
3049 "<list name=\"list\"/>"
3050 "<must condition=\"cond\"/>"
3051 "<typedef name=\"tpdf\"/>"
3052 "<uses name=\"uses-name\"/>"
3053 "</output>"
3054 ELEMENT_WRAPPER_END;
3055 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3056 assert_null(inout.parent);
3057 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3058 assert_string_equal(inout.musts->arg, "cond");
3059 assert_string_equal(inout.typedefs->name, "tpdf");
3060 assert_string_equal(inout.groupings->name, "sub-grp");
3061 assert_string_equal(inout.data->name, "anyd");
3062 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3063 assert_string_equal(inout.data->next->name, "anyx");
3064 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3065 assert_string_equal(inout.data->next->next->name, "choice");
3066 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3067 assert_string_equal(inout.data->next->next->next->name, "subcont");
3068 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3069 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3070 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3071 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3072 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3073 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3074 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3075 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3076 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3077 assert_null(inout.data->next->next->next->next->next->next->next->next);
3078 lysp_action_inout_free(st->ctx, &inout);
3079 memset(&inout, 0, sizeof inout);
3080
3081 /* min subelems */
3082 data = ELEMENT_WRAPPER_START "<input />" ELEMENT_WRAPPER_END;
3083 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3084 memset(&inout, 0, sizeof inout);
3085
3086 data = ELEMENT_WRAPPER_START "<output />" ELEMENT_WRAPPER_END;
3087 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3088 memset(&inout, 0, sizeof inout);
3089
3090 /* invalid combinations */
3091 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
3092 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, false), LY_EVALID);
3093 logbuf_assert("Unexpected attribute \"name\" of input element. Line number 1.");
3094 memset(&inout, 0, sizeof inout);
3095
3096 st->finished_correctly = true;
3097}
3098
David Sedlák85d0eca2019-07-24 15:15:21 +02003099static void
3100test_action_elem(void **state)
3101{
3102 struct state *st = *state;
3103 const char *data;
3104 struct lysp_action *actions = NULL;
3105 struct action_meta act_meta = {NULL, &actions};
3106
3107 /* max subelems */
3108 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3109 data = ELEMENT_WRAPPER_START
3110 "<action name=\"act\">"
3111 "<description><text>desc</text></description>"
3112 "<grouping name=\"grouping\"/>"
3113 "<if-feature name=\"iff\"/>"
3114 "<input><uses name=\"uses-name\"/></input>"
3115 "<output><must condition=\"cond\"/></output>"
3116 "<reference><text>ref</text></reference>"
3117 "<status value=\"deprecated\"/>"
3118 "<typedef name=\"tpdf\"/>"
3119 "</action>"
3120 ELEMENT_WRAPPER_END;
3121 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3122 assert_null(actions->parent);
3123 assert_int_equal(actions->nodetype, LYS_ACTION);
3124 assert_true(actions->flags & LYS_STATUS_DEPRC);
3125 assert_string_equal(actions->name, "act");
3126 assert_string_equal(actions->dsc, "desc");
3127 assert_string_equal(actions->ref, "ref");
3128 assert_string_equal(*actions->iffeatures, "iff");
3129 assert_string_equal(actions->typedefs->name, "tpdf");
3130 assert_string_equal(actions->groupings->name, "grouping");
3131 assert_string_equal(actions->input.data->name, "uses-name");
3132 assert_string_equal(actions->output.musts->arg, "cond");
3133 assert_null(actions->exts);
3134 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3135 actions = NULL;
3136
3137 /* min subelems */
3138 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
3139 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3140 assert_string_equal(actions->name, "act");
3141 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3142 actions = NULL;
3143
3144 st->finished_correctly = true;
3145}
3146
David Sedlák3b4db242018-10-19 16:11:01 +02003147int
3148main(void)
3149{
3150
3151 const struct CMUnitTest tests[] = {
David Sedlák392af4f2019-06-04 16:02:42 +02003152 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f),
David Sedlák8f7a1172019-06-20 14:42:18 +02003153 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02003154 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
3155 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák555c7202019-07-04 12:14:12 +02003156 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02003157 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02003158
David Sedlák8e7bda82019-07-16 17:57:50 +02003159 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák32488102019-07-15 17:44:10 +02003160 cmocka_unit_test_setup_teardown(test_enum_bit_elem, setup_element_test, teardown_element_test),
3161 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
3162 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
3163 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
3164 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
3165 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
3166 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
3167 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02003168 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
3169 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
3170 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
3171 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
3172 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
3173 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
3174 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
3175 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
3176 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
3177 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
3178 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
3179 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
3180 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
3181 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
3182 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02003183 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
3184 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
3185 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
3186 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
3187 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
3188 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
3189 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
3190 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02003191 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02003192 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02003193 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02003194 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02003195 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02003196 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02003197 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02003198 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02003199 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02003200 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02003201 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02003202 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02003203 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02003204 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlák5e13dea2019-07-22 16:06:45 +02003205 cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
David Sedlák28794f22019-07-22 16:45:00 +02003206 cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02003207 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02003208 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02003209 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02003210 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02003211 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02003212 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02003213 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02003214 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák3b4db242018-10-19 16:11:01 +02003215 };
3216
David Sedlák8e7bda82019-07-16 17:57:50 +02003217 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02003218}