blob: c4d6d23b52860ded970bce161ac77172932392c4 [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ák992fb7c2019-07-24 16:51:01 +020046void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +020047void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +020048void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +020049void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod);
50void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +020051
David Sedláke6cd89e2019-08-07 12:46:02 +020052/* wrapping element used for mocking has nothing to do with real module structure */
53#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
54#define ELEMENT_WRAPPER_END "</status>"
55
David Sedlák68a1af12019-03-08 13:46:54 +010056struct state {
David Sedlák3b4db242018-10-19 16:11:01 +020057 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010058 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020059 struct lysp_module *lysp_mod;
David Sedlákda8ffa32019-07-08 14:17:10 +020060 struct yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020061 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010062};
David Sedlák872c7b42018-10-26 13:15:20 +020063
David Sedlák79e50cb2019-06-05 16:33:09 +020064#define BUFSIZE 1024
65char logbuf[BUFSIZE] = {0};
66int store = -1; /* negative for infinite logging, positive for limited logging */
67
68/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedláke0ef1c62019-09-13 10:05:55 +020069#define ENABLE_LOGGER_CHECKING 1
David Sedlák79e50cb2019-06-05 16:33:09 +020070
71#if ENABLE_LOGGER_CHECKING
72static void
73logger(LY_LOG_LEVEL level, const char *msg, const char *path)
74{
75 (void) level; /* unused */
76 if (store) {
77 if (path && path[0]) {
78 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
79 } else {
80 strncpy(logbuf, msg, BUFSIZE - 1);
81 }
82 if (store > 0) {
83 --store;
84 }
85 }
86}
87#endif
88
89#if ENABLE_LOGGER_CHECKING
90# define logbuf_assert(str) assert_string_equal(logbuf, str)
91#else
92# define logbuf_assert(str)
93#endif
94
95#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
96 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
97 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
98 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
99 CLEANUP
100
David Sedlák8e7bda82019-07-16 17:57:50 +0200101int
102setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100103{
104 struct state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +0200105
David Sedlák68a1af12019-03-08 13:46:54 +0100106 /* allocate state variable */
107 (*state) = st = calloc(1, sizeof(*st));
108 if (!st) {
109 fprintf(stderr, "Memmory allocation failed");
110 return EXIT_FAILURE;
111 }
David Sedlák872c7b42018-10-26 13:15:20 +0200112
David Sedlák68a1af12019-03-08 13:46:54 +0100113 /* create new libyang context */
114 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200115
David Sedlák8e7bda82019-07-16 17:57:50 +0200116 return EXIT_SUCCESS;
117}
118
119int
120destroy_ly_ctx(void **state)
121{
122 struct state *st = *state;
123 ly_ctx_destroy(st->ctx, NULL);
124 free(st);
125
126 return EXIT_SUCCESS;
127}
128
129static int
130setup_f(void **state)
131{
132 struct state *st = *state;
133
134#if ENABLE_LOGGER_CHECKING
135 /* setup logger */
136 ly_set_log_clb(logger, 1);
137#endif
138
David Sedlák68a1af12019-03-08 13:46:54 +0100139 /* allocate new module */
140 st->mod = calloc(1, sizeof(*st->mod));
141 st->mod->ctx = st->ctx;
142
David Sedlák619db942019-07-03 14:47:30 +0200143 /* allocate new parsed module */
144 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
145 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
146 st->lysp_mod->mod->ctx = st->ctx;
147
148 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200149 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
150 st->yin_ctx->xml_ctx.ctx = st->ctx;
Radek Krejci99435242019-09-05 16:19:15 +0200151 st->yin_ctx->pos_type = LY_VLOG_LINE;
David Sedlákda8ffa32019-07-08 14:17:10 +0200152 st->yin_ctx->xml_ctx.line = 1;
David Sedlák8f5bce02019-06-03 16:41:08 +0200153
David Sedlák68a1af12019-03-08 13:46:54 +0100154 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200155}
156
157static int
David Sedlák68a1af12019-03-08 13:46:54 +0100158teardown_f(void **state)
159{
160 struct state *st = *(struct state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200161 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100162
David Sedlák79e50cb2019-06-05 16:33:09 +0200163#if ENABLE_LOGGER_CHECKING
164 /* teardown logger */
165 if (!st->finished_correctly && logbuf[0] != '\0') {
166 fprintf(stderr, "%s\n", logbuf);
167 }
168#endif
169
David Sedlák619db942019-07-03 14:47:30 +0200170 temp = st->lysp_mod->mod;
171
David Sedlákda8ffa32019-07-08 14:17:10 +0200172 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100173 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200174 lysp_module_free(st->lysp_mod);
175 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200176 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100177
178 return EXIT_SUCCESS;
179}
180
David Sedlák392af4f2019-06-04 16:02:42 +0200181static struct state*
182reset_state(void **state)
183{
David Sedlák79e50cb2019-06-05 16:33:09 +0200184 ((struct state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200185 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200186 teardown_f(state);
187 setup_f(state);
188
189 return *state;
190}
191
David Sedlák79e50cb2019-06-05 16:33:09 +0200192void
193logbuf_clean(void)
194{
195 logbuf[0] = '\0';
196}
197
David Sedlák8985a142019-07-31 16:43:06 +0200198static int
199setup_logger(void **state)
200{
201 (void)state; /* unused */
202#if ENABLE_LOGGER_CHECKING
203 /* setup logger */
204 ly_set_log_clb(logger, 1);
205#endif
206
207 logbuf[0] = '\0';
208
209 return EXIT_SUCCESS;
210}
211
212static int
213teardown_logger(void **state)
214{
215 struct state *st = *state;
216
217#if ENABLE_LOGGER_CHECKING
218 /* teardown logger */
219 if (!st->finished_correctly && logbuf[0] != '\0') {
220 fprintf(stderr, "%s\n", logbuf);
221 }
222#endif
223
224 return EXIT_SUCCESS;
225}
226
227static int
228setup_element_test(void **state)
229{
230 setup_logger(state);
231 struct state *st = *state;
232
233 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
234
235 /* allocate parser context */
236 st->yin_ctx->xml_ctx.ctx = st->ctx;
Radek Krejci99435242019-09-05 16:19:15 +0200237 st->yin_ctx->pos_type = LY_VLOG_LINE;
David Sedlák8985a142019-07-31 16:43:06 +0200238 st->yin_ctx->xml_ctx.line = 1;
239
240 return EXIT_SUCCESS;
241}
242
243static int
244teardown_element_test(void **state)
245{
246 struct state *st = *(struct state **)state;
247
248 lyxml_context_clear(&st->yin_ctx->xml_ctx);
249 free(st->yin_ctx);
250
251 teardown_logger(state);
252
253 return EXIT_SUCCESS;
254}
255
David Sedlák68a1af12019-03-08 13:46:54 +0100256static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200257test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200258{
David Sedlák8f7a1172019-06-20 14:42:18 +0200259 struct state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200260
David Sedlák8f7a1172019-06-20 14:42:18 +0200261 const char *prefix, *name;
262 struct yin_arg_record *args = NULL;
263 size_t prefix_len, name_len;
264 /* create mock yin namespace in xml context */
265 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200266 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
267 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák8f7a1172019-06-20 14:42:18 +0200268 LY_ARRAY_FREE(args);
269
Radek Krejcid6b76452019-09-03 17:03:03 +0200270 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
318 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
319 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
320 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
321 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
322 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
323 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
324 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
325 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
326 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
327 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
328 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
329 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
330 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
331 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
332 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
333 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
334 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
335 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
336 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
337 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
338 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
339 assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
David Sedlák8f7a1172019-06-20 14:42:18 +0200340
341 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200342}
David Sedlák3b4db242018-10-19 16:11:01 +0200343
David Sedlák872c7b42018-10-26 13:15:20 +0200344static void
David Sedlák060b00e2019-06-19 11:12:06 +0200345test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200346{
David Sedlák68a1af12019-03-08 13:46:54 +0100347 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200348
David Sedlák060b00e2019-06-19 11:12:06 +0200349 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
350 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
351 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
352 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
353 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
354 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
355 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
356 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
357 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
358 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
359 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
360 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200361}
362
David Sedlák68a1af12019-03-08 13:46:54 +0100363static void
David Sedlákb1a78352019-06-28 16:16:29 +0200364test_yin_parse_element_generic(void **state)
365{
366 const char *prefix, *name;
367 struct state *st = *state;
368 struct lysp_ext_instance exts;
369 size_t prefix_len, name_len;
370 LY_ERR ret;
371
372 memset(&exts, 0, sizeof(exts));
373
David Sedlákb0ca07d2019-09-11 11:54:05 +0200374 const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200375 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlák071f7662019-09-12 02:02:51 +0200376 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_EXTENSION_INSTANCE, &data, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200377 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200378 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedláke0ef1c62019-09-13 10:05:55 +0200379 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlákb1a78352019-06-28 16:16:29 +0200380 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200381 assert_string_equal(exts.child->child->stmt, "attr");
382 assert_string_equal(exts.child->child->arg, "value");
383 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200384 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200385 st = reset_state(state);
386
David Sedlákb0ca07d2019-09-11 11:54:05 +0200387 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200388 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlák071f7662019-09-12 02:02:51 +0200389 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_EXTENSION_INSTANCE, &data, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200390 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200391 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlák5392a212019-07-01 09:19:10 +0200392 assert_null(exts.child->child);
393 assert_null(exts.child->arg);
David Sedlákda8ffa32019-07-08 14:17:10 +0200394 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák5392a212019-07-01 09:19:10 +0200395 lysp_ext_instance_free(st->ctx, &exts);
396
David Sedlákb1a78352019-06-28 16:16:29 +0200397 st->finished_correctly = true;
398}
399
400static void
401test_yin_parse_extension_instance(void **state)
402{
403 LY_ERR ret;
404 struct state *st = *state;
405 const char *prefix, *name;
406 size_t prefix_len, name_len;
407 struct yin_arg_record *args = NULL;
408 struct lysp_ext_instance *exts = NULL;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200409 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200410 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
411 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedláke0ef1c62019-09-13 10:05:55 +0200412 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, prefix, prefix_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200413 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200414 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákb1a78352019-06-28 16:16:29 +0200415 assert_int_equal(exts->insubstmt_index, 0);
416 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
417 assert_true(exts->yin & LYS_YIN);
418 assert_string_equal(exts->child->stmt, "value1");
419 assert_string_equal(exts->child->arg, "test");
420 assert_null(exts->child->child);
421 assert_true(exts->child->flags & LYS_YIN_ATTR);
422 assert_string_equal(exts->child->next->stmt, "value");
423 assert_string_equal(exts->child->next->arg, "test2");
424 assert_null(exts->child->next->child);
425 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
426
David Sedláke0ef1c62019-09-13 10:05:55 +0200427 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
David Sedlákb1a78352019-06-28 16:16:29 +0200428 assert_string_equal(exts->child->next->next->arg, "text");
429 assert_null(exts->child->next->next->child);
430 assert_null(exts->child->next->next->next);
431 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákda8ffa32019-07-08 14:17:10 +0200432 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200433 LY_ARRAY_FREE(args);
434 lysp_ext_instance_free(st->ctx, exts);
435 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200436 exts = NULL;
437 args = NULL;
438 st = reset_state(state);
439
David Sedlákb0ca07d2019-09-11 11:54:05 +0200440 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200441 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
442 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedláke0ef1c62019-09-13 10:05:55 +0200443 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, prefix, prefix_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200444 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200445 assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
David Sedlákf250ecf2019-07-01 11:02:05 +0200446 assert_null(exts->argument);
447 assert_null(exts->child);
448 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
449 assert_int_equal(exts->insubstmt_index, 0);
450 assert_true(exts->yin & LYS_YIN);
David Sedlákda8ffa32019-07-08 14:17:10 +0200451 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákf250ecf2019-07-01 11:02:05 +0200452 LY_ARRAY_FREE(args);
453 lysp_ext_instance_free(st->ctx, exts);
454 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200455 exts = NULL;
456 args = NULL;
457 st = reset_state(state);
458
David Sedlákb0ca07d2019-09-11 11:54:05 +0200459 data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">"
460 "<myext:ext-sub1/>"
461 "<myext:ext-sub2 sattr1=\"stext2\">"
462 "<myext:ext-sub21>"
463 "<myext:ext-sub211 sattr21=\"text21\"/>"
464 "</myext:ext-sub21>"
465 "</myext:ext-sub2>"
466 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
467 "</myext:ext>";
David Sedlákadd0c2e2019-08-16 10:49:12 +0200468 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
469 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedláke0ef1c62019-09-13 10:05:55 +0200470 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, prefix, prefix_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200471 assert_int_equal(ret, LY_SUCCESS);
472
David Sedláke0ef1c62019-09-13 10:05:55 +0200473 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200474 assert_null(exts->argument);
475 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
476 assert_int_equal(exts->insubstmt_index, 0);
477 assert_true(exts->yin & LYS_YIN);
478 assert_string_equal(exts->child->stmt, "attr1");
479 assert_string_equal(exts->child->arg, "text1");
480 assert_null(exts->child->child);
481 assert_true(exts->child->flags & LYS_YIN_ATTR);
482
483 assert_string_equal(exts->child->next->stmt, "attr2");
484 assert_string_equal(exts->child->next->arg, "text2");
485 assert_null(exts->child->next->child);
486 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
487
David Sedláke0ef1c62019-09-13 10:05:55 +0200488 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200489 assert_null(exts->child->next->next->arg);
490 assert_null(exts->child->next->next->child);
491 assert_int_equal(exts->child->next->next->flags, 0);
492
David Sedláke0ef1c62019-09-13 10:05:55 +0200493 assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200494 assert_null(exts->child->next->next->next->arg);
495 assert_int_equal(exts->child->next->next->next->flags, 0);
496 assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
497 assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
498 assert_null(exts->child->next->next->next->child->child);
499 assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
500
David Sedláke0ef1c62019-09-13 10:05:55 +0200501 assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200502 assert_null(exts->child->next->next->next->child->next->arg);
503 assert_null(exts->child->next->next->next->child->next->next);
504 assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
505
David Sedláke0ef1c62019-09-13 10:05:55 +0200506 assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200507 assert_null(exts->child->next->next->next->child->next->child->arg);
508 assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
509 assert_null(exts->child->next->next->next->child->next->child->next);
510
511 assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
512 assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
513 assert_null(exts->child->next->next->next->child->next->child->child->next);
514 assert_null(exts->child->next->next->next->child->next->child->child->child);
515 assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
516
David Sedláke0ef1c62019-09-13 10:05:55 +0200517 assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200518 assert_null(exts->child->next->next->next->next->arg);
519 assert_null(exts->child->next->next->next->next->next);
520 assert_int_equal(exts->child->next->next->next->next->flags, 0);
521
522 assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
523 assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
524 assert_null(exts->child->next->next->next->next->child->next);
525 assert_null(exts->child->next->next->next->next->child->child);
526 assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
527
528 LY_ARRAY_FREE(args);
529 lysp_ext_instance_free(st->ctx, exts);
530 LY_ARRAY_FREE(exts);
531 exts = NULL;
532 args = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200533 st = reset_state(state);
534
535 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">"
536 "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>"
537 "<yin:augment target-node=\"target\"/>"
538 "<yin:status value=\"value\"/>"
539 "<yin:include module=\"mod\"/>"
540 "<yin:input />"
541 "<yin:must condition=\"cond\"/>"
542 "<yin:namespace uri=\"uri\"/>"
543 "<yin:revision date=\"data\"/>"
544 "<yin:unique tag=\"tag\"/>"
David Sedlákd2844882019-09-13 16:01:22 +0200545 "<yin:description><yin:text>contact-val</yin:text></yin:description>"
546 "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200547 "</myext:extension-elem>";
548 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
549 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedláke0ef1c62019-09-13 10:05:55 +0200550 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, prefix, prefix_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200551 assert_int_equal(ret, LY_SUCCESS);
552 assert_string_equal(exts->child->arg, "act-name");
553 assert_string_equal(exts->child->next->arg, "target");
554 assert_string_equal(exts->child->next->next->arg, "value");
555 assert_string_equal(exts->child->next->next->next->arg, "mod");
556 assert_null(exts->child->next->next->next->next->arg);
557 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
558 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
559 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
560 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
561 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
562 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
563 LY_ARRAY_FREE(args);
564 lysp_ext_instance_free(st->ctx, exts);
565 LY_ARRAY_FREE(exts);
566 exts = NULL;
567 args = NULL;
568 st = reset_state(state);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200569
David Sedlákb1a78352019-06-28 16:16:29 +0200570 st->finished_correctly = true;
571}
572
David Sedlák555c7202019-07-04 12:14:12 +0200573static void
574test_yin_parse_content(void **state)
575{
576 struct state *st = *state;
577 LY_ERR ret = LY_SUCCESS;
David Sedlákc5b20842019-08-13 10:18:31 +0200578 const char *name, *prefix;
579 size_t name_len, prefix_len;
David Sedlák555c7202019-07-04 12:14:12 +0200580 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200581 "<myext:custom xmlns:myext=\"urn:example:extensions\">"
David Sedlák555c7202019-07-04 12:14:12 +0200582 "totally amazing extension"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200583 "</myext:custom>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200584 "<extension name=\"ext\">"
David Sedlák986cb412019-07-04 13:10:11 +0200585 "<argument name=\"argname\"></argument>"
586 "<description><text>desc</text></description>"
587 "<reference><text>ref</text></reference>"
588 "<status value=\"deprecated\"></status>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200589 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200590 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200591 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200592 "<when condition=\"condition...\">"
593 "<reference><text>when_ref</text></reference>"
594 "<description><text>when_desc</text></description>"
595 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200596 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200597 "<error-message>"
598 "<value>error-msg</value>"
599 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200600 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200601 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200602 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200603 "<position value=\"25\"></position>"
604 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200605 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200606 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200607 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200608 "<pattern value='pattern'>"
609 "<modifier value='invert-match'/>"
610 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200611 "<enum name=\"yay\">"
612 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200613 "</prefix>";
614 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200615 const char **if_features = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200616 struct yin_arg_record *attrs = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200617 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200618 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200619 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200620 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200621 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200622 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200623
David Sedlákc5b20842019-08-13 10:18:31 +0200624 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200625 yin_load_attributes(st->yin_ctx, &data, &attrs);
David Sedlák555c7202019-07-04 12:14:12 +0200626
David Sedlákfd5b9c32019-07-12 15:33:13 +0200627 struct yin_subelement subelems[17] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200628 {LY_STMT_CONFIG, &config, 0},
629 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
630 {LY_STMT_ENUM, &enum_type, 0},
631 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
632 {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
633 {LY_STMT_EXTENSION, &ext_def, 0},
634 {LY_STMT_IF_FEATURE, &if_features, 0},
635 {LY_STMT_LENGTH, &len_type, 0},
636 {LY_STMT_PATTERN, &patter_type, 0},
637 {LY_STMT_POSITION, &pos_enum, 0},
638 {LY_STMT_RANGE, &range_type, 0},
639 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
640 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
641 {LY_STMT_VALUE, &val_enum, 0},
642 {LY_STMT_WHEN, &when_p, 0},
643 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
644 {LY_STMT_ARG_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200645 };
Radek Krejcid6b76452019-09-03 17:03:03 +0200646 ret = yin_parse_content(st->yin_ctx, subelems, 17, &data, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200647 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200648 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák2ce1be62019-07-10 16:15:09 +0200649 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200650 assert_string_equal(def, "default-value");
David Sedláke0ef1c62019-09-13 10:05:55 +0200651 assert_string_equal(exts->name, "urn:example:extensions:custom");
David Sedlák555c7202019-07-04 12:14:12 +0200652 assert_string_equal(exts->argument, "totally amazing extension");
653 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200654 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200655 assert_string_equal(when_p->cond, "condition...");
656 assert_string_equal(when_p->dsc, "when_desc");
657 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200658 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200659 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200660 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200661 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200662 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200663 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200664 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200665 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200666 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200667 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200668 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200669 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200670 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200671 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200672 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200673 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200674 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200675 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200676 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200677 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200678 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200679 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200680 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200681 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200682 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200683 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200684 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200685 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200686 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200687 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200688 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200689 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200690 LY_ARRAY_FREE(ext_def);
David Sedlák555c7202019-07-04 12:14:12 +0200691 LY_ARRAY_FREE(attrs);
David Sedlákd3983112019-07-12 11:20:56 +0200692 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200693 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200694 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200695 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200696 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200697 attrs = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200698 st = reset_state(state);
699
700 /* test unique subelem */
701 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200702 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
703 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
David Sedláke6cd89e2019-08-07 12:46:02 +0200704 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200705 "<prefix value=\"inv_mod\" />"
706 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
707 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200708 ELEMENT_WRAPPER_END;
David Sedlákc5b20842019-08-13 10:18:31 +0200709 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200710 yin_load_attributes(st->yin_ctx, &data, &attrs);
Radek Krejcid6b76452019-09-03 17:03:03 +0200711 ret = yin_parse_content(st->yin_ctx, subelems2, 2, &data, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200712 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200713 logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200714 lydict_remove(st->ctx, prefix_value);
715 lydict_remove(st->ctx, value);
716 st = reset_state(state);
717 LY_ARRAY_FREE(attrs);
718 attrs = NULL;
719
720 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200721 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200722 "<prefix value=\"inv_mod\" />"
723 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
724 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200725 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200726 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
727 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
David Sedlákc5b20842019-08-13 10:18:31 +0200728 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200729 yin_load_attributes(st->yin_ctx, &data, &attrs);
Radek Krejcid6b76452019-09-03 17:03:03 +0200730 ret = yin_parse_content(st->yin_ctx, subelems3, 2, &data, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200731 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200732 logbuf_assert("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200733 lydict_remove(st->ctx, prefix_value);
734 st = reset_state(state);
735 LY_ARRAY_FREE(attrs);
736 attrs = NULL;
737
738 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200739 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200740 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
David Sedlákc5b20842019-08-13 10:18:31 +0200741 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200742 yin_load_attributes(st->yin_ctx, &data, &attrs);
Radek Krejcid6b76452019-09-03 17:03:03 +0200743 ret = yin_parse_content(st->yin_ctx, subelems4, 1, &data, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200744 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200745 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200746 LY_ARRAY_FREE(attrs);
747
748 st->finished_correctly = true;
749}
750
David Sedlák92147b02019-07-09 14:01:01 +0200751static void
David Sedlák4a650532019-07-10 11:55:18 +0200752test_validate_value(void **state)
753{
754 struct state *st = *state;
755 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "#invalid", 8), LY_EVALID);
756 logbuf_assert("Invalid identifier character '#'. Line number 1.");
757 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG, "", 0), LY_SUCCESS);
758 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "pre:b", 5), LY_EVALID);
759 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:b", 5), LY_SUCCESS);
760 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:pre:b", 9), LY_EVALID);
761
762 st->finished_correctly = true;
763}
764
David Sedlák32488102019-07-15 17:44:10 +0200765/* helper function to simplify unit test of each element using parse_content function */
766LY_ERR
767test_element_helper(struct state *st, const char **data, void *dest, const char **text,
768 struct lysp_ext_instance **exts, bool valid)
769{
770 struct yin_arg_record *attrs = NULL;
David Sedlákc5b20842019-08-13 10:18:31 +0200771 const char *name, *prefix;
772 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200773 LY_ERR ret = LY_SUCCESS;
774 struct yin_subelement subelems[71] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200775 {LY_STMT_ACTION, dest, 0},
776 {LY_STMT_ANYDATA, dest, 0},
777 {LY_STMT_ANYXML, dest, 0},
778 {LY_STMT_ARGUMENT,dest, 0},
779 {LY_STMT_AUGMENT, dest, 0},
780 {LY_STMT_BASE, dest, 0},
781 {LY_STMT_BELONGS_TO, dest, 0},
782 {LY_STMT_BIT, dest, 0},
783 {LY_STMT_CASE, dest, 0},
784 {LY_STMT_CHOICE, dest, 0},
785 {LY_STMT_CONFIG, dest, 0},
786 {LY_STMT_CONTACT, dest, 0},
787 {LY_STMT_CONTAINER, dest, 0},
788 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
789 {LY_STMT_DESCRIPTION, dest, 0},
790 {LY_STMT_DEVIATE, dest, 0},
791 {LY_STMT_DEVIATION, dest, 0},
792 {LY_STMT_ENUM, dest, 0},
793 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
794 {LY_STMT_ERROR_MESSAGE, dest, 0},
795 {LY_STMT_EXTENSION, dest, 0},
796 {LY_STMT_FEATURE, dest, 0},
797 {LY_STMT_FRACTION_DIGITS, dest, 0},
798 {LY_STMT_GROUPING, dest, 0},
799 {LY_STMT_IDENTITY, dest, 0},
800 {LY_STMT_IF_FEATURE, dest, 0},
801 {LY_STMT_IMPORT, dest, 0},
802 {LY_STMT_INCLUDE, dest, 0},
803 {LY_STMT_INPUT, dest, 0},
804 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
805 {LY_STMT_LEAF, dest, 0},
806 {LY_STMT_LEAF_LIST, dest, 0},
807 {LY_STMT_LENGTH, dest, 0},
808 {LY_STMT_LIST, dest, 0},
809 {LY_STMT_MANDATORY, dest, 0},
810 {LY_STMT_MAX_ELEMENTS, dest, 0},
811 {LY_STMT_MIN_ELEMENTS, dest, 0},
812 {LY_STMT_MODIFIER, dest, 0},
813 {LY_STMT_MODULE, dest, 0},
814 {LY_STMT_MUST, dest, 0},
815 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
816 {LY_STMT_NOTIFICATION, dest, 0},
817 {LY_STMT_ORDERED_BY, dest, 0},
818 {LY_STMT_ORGANIZATION, dest, 0},
819 {LY_STMT_OUTPUT, dest, 0},
820 {LY_STMT_PATH, dest, 0},
821 {LY_STMT_PATTERN, dest, 0},
822 {LY_STMT_POSITION, dest, 0},
823 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
824 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
825 {LY_STMT_RANGE, dest, 0},
826 {LY_STMT_REFERENCE, dest, 0},
827 {LY_STMT_REFINE, dest, 0},
828 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
829 {LY_STMT_REVISION, dest, 0},
830 {LY_STMT_REVISION_DATE, dest, 0},
831 {LY_STMT_RPC, dest, 0},
832 {LY_STMT_STATUS, dest, 0},
833 {LY_STMT_SUBMODULE, dest, 0},
834 {LY_STMT_TYPE, dest, 0},
835 {LY_STMT_TYPEDEF, dest, 0},
836 {LY_STMT_UNIQUE, dest, 0},
837 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
838 {LY_STMT_USES, dest, 0},
839 {LY_STMT_VALUE, dest, 0},
840 {LY_STMT_WHEN, dest, 0},
841 {LY_STMT_YANG_VERSION, dest, 0},
842 {LY_STMT_YIN_ELEMENT, dest, 0},
843 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
844 {LY_STMT_ARG_TEXT, dest, 0},
845 {LY_STMT_ARG_VALUE, dest, 0}
David Sedlák32488102019-07-15 17:44:10 +0200846 };
David Sedlákc5b20842019-08-13 10:18:31 +0200847 LY_CHECK_RET(lyxml_get_element(&st->yin_ctx->xml_ctx, data, &prefix, &prefix_len, &name, &name_len));
David Sedlák4f03b932019-07-26 13:01:47 +0200848 LY_CHECK_RET(yin_load_attributes(st->yin_ctx, data, &attrs));
Radek Krejcid6b76452019-09-03 17:03:03 +0200849 ret = yin_parse_content(st->yin_ctx, subelems, 71, data, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
David Sedlák32488102019-07-15 17:44:10 +0200850 LY_ARRAY_FREE(attrs);
851 if (valid) {
852 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
853 }
854 /* reset status */
855 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
856 return ret;
857}
858
David Sedlákd1144562019-08-06 12:36:14 +0200859#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
860
David Sedlák32488102019-07-15 17:44:10 +0200861static void
David Sedlák43801c92019-08-05 15:58:54 +0200862test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200863{
David Sedlák32488102019-07-15 17:44:10 +0200864 struct state *st = *state;
865 struct lysp_type type = {};
866 const char *data;
867 data = ELEMENT_WRAPPER_START
868 "<enum name=\"enum-name\">"
869 "<if-feature name=\"feature\" />"
870 "<value value=\"55\" />"
871 "<status value=\"deprecated\" />"
872 "<description><text>desc...</text></description>"
873 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200874 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +0200875 "</enum>"
876 ELEMENT_WRAPPER_END;
877 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200878 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200879 assert_string_equal(*type.enums->iffeatures, "feature");
880 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200881 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200882 assert_string_equal(type.enums->dsc, "desc...");
883 assert_string_equal(type.enums->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200884 assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200885 assert_int_equal(type.enums->exts->insubstmt_index, 0);
886 assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
887 lysp_type_free(st->ctx, &type);
888 memset(&type, 0, sizeof type);
889
890 data = ELEMENT_WRAPPER_START
891 "<enum name=\"enum-name\"></enum>"
892 ELEMENT_WRAPPER_END;
893 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
894 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200895 lysp_type_free(st->ctx, &type);
896 memset(&type, 0, sizeof type);
897
David Sedlák43801c92019-08-05 15:58:54 +0200898 st->finished_correctly = true;
899}
900
901static void
902test_bit_elem(void **state)
903{
904 struct state *st = *state;
905 struct lysp_type type = {};
906 const char *data;
907 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200908 "<bit name=\"bit-name\">"
David Sedlák43801c92019-08-05 15:58:54 +0200909 "<if-feature name=\"feature\" />"
910 "<position value=\"55\" />"
911 "<status value=\"deprecated\" />"
912 "<description><text>desc...</text></description>"
913 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200914 EXT_SUBELEM
David Sedlák43801c92019-08-05 15:58:54 +0200915 "</bit>"
916 ELEMENT_WRAPPER_END;
917 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200918 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200919 assert_string_equal(*type.bits->iffeatures, "feature");
920 assert_int_equal(type.bits->value, 55);
921 assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
922 assert_string_equal(type.bits->dsc, "desc...");
923 assert_string_equal(type.bits->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200924 assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200925 assert_int_equal(type.bits->exts->insubstmt_index, 0);
926 assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
927 lysp_type_free(st->ctx, &type);
928 memset(&type, 0, sizeof type);
929
930 data = ELEMENT_WRAPPER_START
931 "<bit name=\"bit-name\"> </bit>"
932 ELEMENT_WRAPPER_END;
933 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
934 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200935 lysp_type_free(st->ctx, &type);
936 memset(&type, 0, sizeof type);
937
David Sedlák32488102019-07-15 17:44:10 +0200938 st->finished_correctly = true;
939}
940
941static void
942test_meta_elem(void **state)
943{
944 struct state *st = *state;
945 char *value = NULL;
946 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200947 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200948
949 /* organization element */
950 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200951 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
David Sedlák32488102019-07-15 17:44:10 +0200952 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200953 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200954 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200955 assert_int_equal(exts[0].insubstmt_index, 0);
956 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedláke0ef1c62019-09-13 10:05:55 +0200957 assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200958 assert_int_equal(exts[1].insubstmt_index, 0);
959 assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedlák32488102019-07-15 17:44:10 +0200960 assert_string_equal(value, "organization...");
961 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200962 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200963 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200964 exts = NULL;
965
David Sedlák32488102019-07-15 17:44:10 +0200966 /* contact element */
967 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200968 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
David Sedlák32488102019-07-15 17:44:10 +0200969 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200970 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200971 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200972 assert_int_equal(exts[0].insubstmt_index, 0);
973 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200974 assert_string_equal(value, "contact...");
975 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200976 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
977 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200978 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200979
David Sedlák32488102019-07-15 17:44:10 +0200980 /* description element */
981 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200982 "<description><text>description...</text>" EXT_SUBELEM "</description>"
David Sedlák32488102019-07-15 17:44:10 +0200983 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200984 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200985 assert_string_equal(value, "description...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200986 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200987 assert_int_equal(exts[0].insubstmt_index, 0);
988 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200989 FREE_STRING(st->ctx, value);
990 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200991 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
992 exts = NULL;
993
David Sedlák32488102019-07-15 17:44:10 +0200994 /* reference element */
995 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200996 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
David Sedlák32488102019-07-15 17:44:10 +0200997 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200998 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200999 assert_string_equal(value, "reference...");
David Sedláke0ef1c62019-09-13 10:05:55 +02001000 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001001 assert_int_equal(exts[0].insubstmt_index, 0);
1002 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
David Sedlák32488102019-07-15 17:44:10 +02001003 FREE_STRING(st->ctx, value);
1004 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001005 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1006 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001007
David Sedlákdf2a9732019-08-07 13:23:16 +02001008 /* reference element */
1009 data = ELEMENT_WRAPPER_START
1010 "<reference invalid=\"text\"><text>reference...</text>""</reference>"
1011 ELEMENT_WRAPPER_END;
1012 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001013 logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001014 FREE_STRING(st->ctx, value);
1015 value = NULL;
1016 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1017 exts = NULL;
1018
David Sedlák32488102019-07-15 17:44:10 +02001019 /* missing text subelement */
1020 data = ELEMENT_WRAPPER_START
1021 "<reference>reference...</reference>"
1022 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +02001023 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001024 logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001025
David Sedlákd1144562019-08-06 12:36:14 +02001026 /* reference element */
1027 data = ELEMENT_WRAPPER_START
1028 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
1029 ELEMENT_WRAPPER_END;
1030 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001031 logbuf_assert("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element. Line number 1.");
David Sedlákd1144562019-08-06 12:36:14 +02001032 FREE_STRING(st->ctx, value);
1033 value = NULL;
1034 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1035 exts = NULL;
1036
David Sedlák32488102019-07-15 17:44:10 +02001037 st->finished_correctly = true;
1038}
1039
1040static void
1041test_import_elem(void **state)
1042{
1043 struct state *st = *state;
1044 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02001045 struct lysp_import *imports = NULL;
1046 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +02001047
1048 /* max subelems */
1049 data = ELEMENT_WRAPPER_START
1050 "<import module=\"a\">"
David Sedlákd1144562019-08-06 12:36:14 +02001051 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001052 "<prefix value=\"a_mod\"/>"
1053 "<revision-date date=\"2015-01-01\"></revision-date>"
1054 "<description><text>import description</text></description>"
1055 "<reference><text>import reference</text></reference>"
1056 "</import>"
1057 ELEMENT_WRAPPER_END;
David Sedlák298ff6d2019-07-26 14:29:03 +02001058 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS);
1059 assert_string_equal(imports->name, "a");
1060 assert_string_equal(imports->prefix, "a_mod");
1061 assert_string_equal(imports->rev, "2015-01-01");
1062 assert_string_equal(imports->dsc, "import description");
1063 assert_string_equal(imports->ref, "import reference");
David Sedláke0ef1c62019-09-13 10:05:55 +02001064 assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001065 assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
1066 assert_int_equal(imports->exts->insubstmt_index, 0);
David Sedlák298ff6d2019-07-26 14:29:03 +02001067 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1068 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001069
1070 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +02001071 data = ELEMENT_WRAPPER_START
1072 "<import module=\"a\">"
1073 "<prefix value=\"a_mod\"/>"
1074 "</import>"
1075 ELEMENT_WRAPPER_END;
David Sedlák298ff6d2019-07-26 14:29:03 +02001076 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS);
1077 assert_string_equal(imports->prefix, "a_mod");
1078 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1079 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001080
1081 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +02001082 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
1083 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001084 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
David Sedlák298ff6d2019-07-26 14:29:03 +02001085 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1086 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001087
1088 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +02001089 data = ELEMENT_WRAPPER_START
1090 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001091 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001092 "</import>"
1093 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001094 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001095 "</import>"
1096 ELEMENT_WRAPPER_END;
David Sedlák298ff6d2019-07-26 14:29:03 +02001097 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID);
1098 logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1.");
1099 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1100 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001101
1102 st->finished_correctly = true;
1103}
1104
1105static void
1106test_status_elem(void **state)
1107{
1108 struct state *st = *state;
1109 const char *data;
1110 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001111 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001112
1113 /* test valid values */
1114 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
1115 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001116 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001117
1118 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
1119 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001120 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001121
David Sedlákd1144562019-08-06 12:36:14 +02001122 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END;
1123 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001124 assert_true(flags & LYS_STATUS_OBSLT);
David Sedláke0ef1c62019-09-13 10:05:55 +02001125 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001126 assert_int_equal(exts[0].insubstmt_index, 0);
1127 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
1128 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1129 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001130
1131 /* test invalid value */
1132 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
1133 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001134 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Valid values are \"current\", \"deprecated\" and \"obsolete\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001135 st->finished_correctly = true;
1136}
1137
1138static void
1139test_ext_elem(void **state)
1140{
1141 struct state *st = *state;
1142 const char *data;
1143 struct lysp_ext *ext = NULL;
1144
1145 /* max subelems */
1146 data = ELEMENT_WRAPPER_START
1147 "<extension name=\"ext_name\">"
1148 "<argument name=\"arg\"></argument>"
1149 "<status value=\"current\"/>"
1150 "<description><text>ext_desc</text></description>"
1151 "<reference><text>ext_ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001152 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001153 "</extension>"
1154 ELEMENT_WRAPPER_END;
1155 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
1156 assert_string_equal(ext->name, "ext_name");
1157 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001158 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001159 assert_string_equal(ext->dsc, "ext_desc");
1160 assert_string_equal(ext->ref, "ext_ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001161 assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001162 assert_int_equal(ext->exts[0].insubstmt_index, 0);
1163 assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák32488102019-07-15 17:44:10 +02001164 lysp_ext_free(st->ctx, ext);
1165 LY_ARRAY_FREE(ext);
1166 ext = NULL;
1167
1168 /* min subelems */
1169 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
1170 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
1171 assert_string_equal(ext->name, "ext_name");
1172 lysp_ext_free(st->ctx, ext);
1173 LY_ARRAY_FREE(ext);
1174 ext = NULL;
1175
1176 st->finished_correctly = true;
1177}
1178
1179static void
1180test_yin_element_elem(void **state)
1181{
1182 struct state *st = *state;
1183 const char *data;
1184 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001185 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001186
1187 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
1188 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001189 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001190
David Sedlákd1144562019-08-06 12:36:14 +02001191 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
1192 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001193 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001194 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001195 assert_int_equal(exts[0].insubstmt_index, 0);
1196 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
1197 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001198
1199 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
1200 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001201 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák26ea1432019-08-14 13:42:23 +02001202 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001203 st->finished_correctly = true;
1204}
1205
1206static void
1207test_yangversion_elem(void **state)
1208{
1209 struct state *st = *state;
1210 const char *data;
1211 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001212 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001213
1214 /* valid values */
1215 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
1216 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001217 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001218 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1219
David Sedlákd1144562019-08-06 12:36:14 +02001220 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
1221 assert_int_equal(test_element_helper(st, &data, &version, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001222 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001223 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
David Sedláke0ef1c62019-09-13 10:05:55 +02001224 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001225 assert_int_equal(exts[0].insubstmt_index, 0);
1226 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
1227 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001228
1229 /* invalid value */
1230 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
1231 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001232 logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Valid values are \"1.0\" and \"1.1\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001233
1234 st->finished_correctly = true;
1235}
1236
1237static void
1238test_mandatory_elem(void **state)
1239{
1240 struct state *st = *state;
1241 const char *data;
1242 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001243 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001244
1245 /* valid values */
1246 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
1247 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1248 assert_int_equal(man, LYS_MAND_TRUE);
1249 man = 0;
1250
David Sedlákd1144562019-08-06 12:36:14 +02001251 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
1252 assert_int_equal(test_element_helper(st, &data, &man, NULL, &exts, true), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001253 assert_int_equal(man, LYS_MAND_FALSE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001254 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001255 assert_int_equal(exts[0].insubstmt_index, 0);
1256 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
1257 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001258
1259 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
1260 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001261 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001262
1263 st->finished_correctly = true;
1264}
1265
David Sedlák8e7bda82019-07-16 17:57:50 +02001266static void
1267test_argument_elem(void **state)
1268{
1269 struct state *st = *state;
1270 const char *data;
1271 uint16_t flags = 0;
1272 const char *arg;
1273 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001274 struct lysp_ext_instance *exts = NULL;
1275
David Sedlák8e7bda82019-07-16 17:57:50 +02001276 /* max subelems */
1277 data = ELEMENT_WRAPPER_START
1278 "<argument name=\"arg-name\">"
1279 "<yin-element value=\"true\" />"
David Sedlákd1144562019-08-06 12:36:14 +02001280 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001281 "</argument>"
1282 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +02001283 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001284 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001285 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001286 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001287 assert_int_equal(exts[0].insubstmt_index, 0);
1288 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
1289 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1290 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001291 flags = 0;
1292 FREE_STRING(st->ctx, arg);
1293 arg = NULL;
1294
1295 /* min subelems */
1296 data = ELEMENT_WRAPPER_START
1297 "<argument name=\"arg\">"
1298 "</argument>"
1299 ELEMENT_WRAPPER_END;
1300 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1301 assert_string_equal(arg, "arg");
1302 assert_true(flags == 0);
1303 FREE_STRING(st->ctx, arg);
1304
1305 st->finished_correctly = true;
1306}
1307
1308static void
1309test_base_elem(void **state)
1310{
1311 struct state *st = *state;
1312 const char *data;
1313 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001314 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001315 struct lysp_type type = {};
1316
1317 /* as identity subelement */
1318 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001319 "<base name=\"base-name\">"
1320 EXT_SUBELEM
1321 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001322 "</identity>";
David Sedlákd1144562019-08-06 12:36:14 +02001323 assert_int_equal(test_element_helper(st, &data, &bases, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001324 assert_string_equal(*bases, "base-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001325 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001326 assert_int_equal(exts[0].insubstmt_index, 0);
1327 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1328 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1329 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001330 FREE_STRING(st->ctx, *bases);
1331 LY_ARRAY_FREE(bases);
1332
1333 /* as type subelement */
1334 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001335 "<base name=\"base-name\">"
1336 EXT_SUBELEM
1337 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001338 "</type>";
David Sedlákd1144562019-08-06 12:36:14 +02001339 assert_int_equal(test_element_helper(st, &data, &type, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001340 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001341 assert_true(type.flags & LYS_SET_BASE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001342 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001343 assert_int_equal(exts[0].insubstmt_index, 0);
1344 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1345 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1346 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001347 FREE_STRING(st->ctx, *type.bases);
1348 LY_ARRAY_FREE(type.bases);
1349
1350 st->finished_correctly = true;
1351}
1352
1353static void
1354test_belongsto_elem(void **state)
1355{
1356 struct state *st = *state;
1357 const char *data;
1358 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001359 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001360
1361 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001362 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001363 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +02001364 assert_int_equal(test_element_helper(st, &data, &submod, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001365 assert_string_equal(submod.belongsto, "module-name");
1366 assert_string_equal(submod.prefix, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001367 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001368 assert_int_equal(exts[0].insubstmt_index, 0);
1369 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
1370 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1371 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001372 FREE_STRING(st->ctx, submod.belongsto);
1373 FREE_STRING(st->ctx, submod.prefix);
1374
1375 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
1376 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001377 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001378 FREE_STRING(st->ctx, submod.belongsto);
1379
1380 st->finished_correctly = true;
1381}
1382
1383static void
1384test_config_elem(void **state)
1385{
1386 struct state *st = *state;
1387 const char *data;
1388 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001389 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001390
David Sedlákd1144562019-08-06 12:36:14 +02001391 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
1392 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001393 assert_true(flags & LYS_CONFIG_W);
David Sedláke0ef1c62019-09-13 10:05:55 +02001394 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001395 assert_int_equal(exts[0].insubstmt_index, 0);
1396 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
1397 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1398 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001399 flags = 0;
1400
1401 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
1402 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001403 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001404 flags = 0;
1405
1406 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1407 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001408 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001409
1410 st->finished_correctly = true;
1411}
1412
1413static void
1414test_default_elem(void **state)
1415{
1416 struct state *st = *state;
1417 const char *data;
1418 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001419 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001420
David Sedlákd1144562019-08-06 12:36:14 +02001421 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END;
1422 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001423 assert_string_equal(val, "defaul-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02001424 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001425 assert_int_equal(exts[0].insubstmt_index, 0);
1426 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
1427 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1428 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001429 FREE_STRING(st->ctx, val);
1430 val = NULL;
1431
1432 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
1433 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1434 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1435
1436 st->finished_correctly = true;
1437}
1438
1439static void
1440test_err_app_tag_elem(void **state)
1441{
1442 struct state *st = *state;
1443 const char *data;
1444 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001445 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001446
David Sedlákd1144562019-08-06 12:36:14 +02001447 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END;
1448 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001449 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001450 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001451 assert_int_equal(exts[0].insubstmt_index, 0);
1452 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
1453 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1454 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001455 FREE_STRING(st->ctx, val);
1456 val = NULL;
1457
1458 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
1459 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1460 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1461
1462 st->finished_correctly = true;
1463}
1464
1465static void
1466test_err_msg_elem(void **state)
1467{
1468 struct state *st = *state;
1469 const char *data;
1470 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001471 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001472
David Sedlákd1144562019-08-06 12:36:14 +02001473 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END;
1474 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001475 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001476 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001477 assert_int_equal(exts[0].insubstmt_index, 0);
1478 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
1479 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1480 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001481 FREE_STRING(st->ctx, val);
1482
1483 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
1484 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001485 logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001486
David Sedlákdf2a9732019-08-07 13:23:16 +02001487 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
1488 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001489 logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001490
David Sedlák8e7bda82019-07-16 17:57:50 +02001491 st->finished_correctly = true;
1492}
1493
1494static void
1495test_fracdigits_elem(void **state)
1496{
1497 struct state *st = *state;
1498 const char *data;
1499 struct lysp_type type = {};
1500
1501 /* valid value */
David Sedlákd1144562019-08-06 12:36:14 +02001502 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001503 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +02001504 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001505 assert_int_equal(type.exts[0].insubstmt_index, 0);
1506 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001507 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001508 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlákd1144562019-08-06 12:36:14 +02001509 FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001510
1511 /* invalid values */
1512 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
1513 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001514 logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001515
1516 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
1517 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001518 logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001519
1520 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
1521 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001522 logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001523
1524 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
1525 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001526 logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001527
1528 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
1529 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001530 logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001531
1532 st->finished_correctly = true;
1533}
1534
1535static void
1536test_iffeature_elem(void **state)
1537{
1538 struct state *st = *state;
1539 const char *data;
1540 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001541 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001542
David Sedlákd1144562019-08-06 12:36:14 +02001543 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END;
1544 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001545 assert_string_equal(*iffeatures, "local-storage");
David Sedláke0ef1c62019-09-13 10:05:55 +02001546 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001547 assert_int_equal(exts[0].insubstmt_index, 0);
1548 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
1549 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1550 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001551 FREE_STRING(st->ctx, *iffeatures);
1552 LY_ARRAY_FREE(iffeatures);
1553 iffeatures = NULL;
1554
1555 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
1556 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID);
1557 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1558 LY_ARRAY_FREE(iffeatures);
1559 iffeatures = NULL;
1560
1561 st->finished_correctly = true;
1562}
1563
1564static void
1565test_length_elem(void **state)
1566{
1567 struct state *st = *state;
1568 const char *data;
1569 struct lysp_type type = {};
1570
1571 /* max subelems */
1572 data = ELEMENT_WRAPPER_START
1573 "<length value=\"length-str\">"
1574 "<error-message><value>err-msg</value></error-message>"
1575 "<error-app-tag value=\"err-app-tag\"/>"
1576 "<description><text>desc</text></description>"
1577 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001578 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001579 "</length>"
1580 ELEMENT_WRAPPER_END;
1581 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1582 assert_string_equal(type.length->arg, "length-str");
1583 assert_string_equal(type.length->emsg, "err-msg");
1584 assert_string_equal(type.length->eapptag, "err-app-tag");
1585 assert_string_equal(type.length->dsc, "desc");
1586 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001587 assert_true(type.flags & LYS_SET_LENGTH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001588 assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001589 assert_int_equal(type.length->exts[0].insubstmt_index, 0);
1590 assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001591 lysp_type_free(st->ctx, &type);
1592 memset(&type, 0, sizeof(type));
1593
1594 /* min subelems */
1595 data = ELEMENT_WRAPPER_START
1596 "<length value=\"length-str\">"
1597 "</length>"
1598 ELEMENT_WRAPPER_END;
1599 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1600 assert_string_equal(type.length->arg, "length-str");
1601 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001602 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001603 memset(&type, 0, sizeof(type));
1604
1605 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
1606 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1607 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1608 lysp_type_free(st->ctx, &type);
1609 memset(&type, 0, sizeof(type));
1610
1611 st->finished_correctly = true;
1612}
1613
1614static void
1615test_modifier_elem(void **state)
1616{
1617 struct state *st = *state;
1618 const char *data;
1619 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
David Sedlákd1144562019-08-06 12:36:14 +02001620 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001621
David Sedlákd1144562019-08-06 12:36:14 +02001622 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
1623 assert_int_equal(test_element_helper(st, &data, &pat, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001624 assert_string_equal(pat, "\x015pattern");
David Sedláke0ef1c62019-09-13 10:05:55 +02001625 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001626 assert_int_equal(exts[0].insubstmt_index, 0);
1627 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
1628 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1629 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001630 FREE_STRING(st->ctx, pat);
1631
1632 pat = lydict_insert(st->ctx, "\006pattern", 8);
1633 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
1634 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001635 logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Only valid value is \"invert-match\". Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001636 FREE_STRING(st->ctx, pat);
1637
1638 st->finished_correctly = true;
1639}
1640
1641static void
1642test_namespace_elem(void **state)
1643{
1644 struct state *st = *state;
1645 const char *data;
1646 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001647 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001648
David Sedlákd1144562019-08-06 12:36:14 +02001649 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
1650 assert_int_equal(test_element_helper(st, &data, &ns, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001651 assert_string_equal(ns, "ns");
David Sedláke0ef1c62019-09-13 10:05:55 +02001652 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001653 assert_int_equal(exts[0].insubstmt_index, 0);
1654 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
1655 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1656 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001657 FREE_STRING(st->ctx, ns);
1658
1659 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
1660 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID);
1661 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1662
1663 st->finished_correctly = true;
1664}
1665
1666static void
1667test_path_elem(void **state)
1668{
1669 struct state *st = *state;
1670 const char *data;
1671 struct lysp_type type = {};
1672
David Sedlák169cc522019-08-15 13:23:45 +02001673 data = ELEMENT_WRAPPER_START "<path value=\"p&amp;th-val\">" EXT_SUBELEM "</path>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001674 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlák169cc522019-08-15 13:23:45 +02001675 assert_string_equal("p&th-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001676 assert_true(type.flags & LYS_SET_PATH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001677 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001678 assert_int_equal(type.exts[0].insubstmt_index, 0);
1679 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001680 lysp_type_free(st->ctx, &type);
1681
1682 st->finished_correctly = true;
1683}
1684
1685static void
1686test_pattern_elem(void **state)
1687{
1688 struct state *st = *state;
1689 const char *data;
1690 struct lysp_type type = {};
1691
1692 /* max subelems */
1693 data = ELEMENT_WRAPPER_START
1694 "<pattern value=\"super_pattern\">"
1695 "<modifier value=\"invert-match\"/>"
1696 "<error-message><value>err-msg-value</value></error-message>"
1697 "<error-app-tag value=\"err-app-tag-value\"/>"
David Sedlák169cc522019-08-15 13:23:45 +02001698 "<description><text>&quot;pattern-desc&quot;</text></description>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001699 "<reference><text>pattern-ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001700 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001701 "</pattern>"
1702 ELEMENT_WRAPPER_END;
1703 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001704 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001705 assert_string_equal(type.patterns->arg, "\x015super_pattern");
David Sedlák169cc522019-08-15 13:23:45 +02001706 assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
David Sedlák8e7bda82019-07-16 17:57:50 +02001707 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1708 assert_string_equal(type.patterns->emsg, "err-msg-value");
David Sedlák8e7bda82019-07-16 17:57:50 +02001709 assert_string_equal(type.patterns->ref, "pattern-ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001710 assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001711 assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
1712 assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001713 lysp_type_free(st->ctx, &type);
1714 memset(&type, 0, sizeof(type));
1715
1716 /* min subelems */
1717 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
1718 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1719 assert_string_equal(type.patterns->arg, "\x006pattern");
1720 lysp_type_free(st->ctx, &type);
1721 memset(&type, 0, sizeof(type));
1722
1723 st->finished_correctly = true;
1724}
1725
1726static void
1727test_value_position_elem(void **state)
1728{
1729 struct state *st = *state;
1730 const char *data;
1731 struct lysp_type_enum en = {};
1732
1733 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001734 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001735 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1736 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001737 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001738 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001739 assert_int_equal(en.exts[0].insubstmt_index, 0);
1740 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
1741 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001742 memset(&en, 0, sizeof(en));
1743
1744 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
1745 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1746 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001747 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001748 memset(&en, 0, sizeof(en));
1749
1750 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
1751 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1752 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001753 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001754 memset(&en, 0, sizeof(en));
1755
1756 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
1757 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1758 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001759 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001760 memset(&en, 0, sizeof(en));
1761
1762 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001763 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001764 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1765 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001766 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001767 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlák8d552d62019-08-06 15:29:05 +02001768 assert_int_equal(en.exts[0].insubstmt_index, 0);
1769 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
1770 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001771 memset(&en, 0, sizeof(en));
1772
1773 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
1774 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1775 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001776 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001777 memset(&en, 0, sizeof(en));
1778
1779 /* invalid values */
1780 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
1781 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001782 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001783
1784 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
1785 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001786 logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001787
David Sedlák69f01612019-07-17 11:41:08 +02001788 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
1789 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001790 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001791
David Sedlák8e7bda82019-07-16 17:57:50 +02001792 /*invalid positions */
1793 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
1794 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001795 logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001796
1797 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
1798 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001799 logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001800
1801 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
1802 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001803 logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001804
David Sedlák69f01612019-07-17 11:41:08 +02001805 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
1806 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001807 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001808
1809 st->finished_correctly = true;
1810}
1811
1812static void
1813test_prefix_elem(void **state)
1814{
1815 struct state *st = *state;
1816 const char *data;
1817 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001818 struct lysp_ext_instance *exts = NULL;
1819
1820 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
1821 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
1822 assert_string_equal(value, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001823 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001824 assert_int_equal(exts[0].insubstmt_index, 0);
1825 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
1826 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1827 exts = NULL;
1828 FREE_STRING(st->ctx, value);
David Sedlák69f01612019-07-17 11:41:08 +02001829
1830 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
1831 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
1832 assert_string_equal(value, "pref");
1833 FREE_STRING(st->ctx, value);
1834
1835 st->finished_correctly = true;
1836}
1837
1838static void
1839test_range_elem(void **state)
1840{
1841 struct state *st = *state;
1842 const char *data;
1843 struct lysp_type type = {};
1844
1845 /* max subelems */
1846 data = ELEMENT_WRAPPER_START
1847 "<range value=\"range-str\">"
1848 "<error-message><value>err-msg</value></error-message>"
1849 "<error-app-tag value=\"err-app-tag\" />"
1850 "<description><text>desc</text></description>"
1851 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001852 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001853 "</range>"
1854 ELEMENT_WRAPPER_END;
1855 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1856 assert_string_equal(type.range->arg, "range-str");
1857 assert_string_equal(type.range->dsc, "desc");
1858 assert_string_equal(type.range->eapptag, "err-app-tag");
1859 assert_string_equal(type.range->emsg, "err-msg");
1860 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001861 assert_true(type.flags & LYS_SET_RANGE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001862 assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001863 assert_int_equal(type.range->exts[0].insubstmt_index, 0);
1864 assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001865 lysp_type_free(st->ctx, &type);
1866 memset(&type, 0, sizeof(type));
1867
1868 /* min subelems */
1869 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
1870 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1871 assert_string_equal(type.range->arg, "range-str");
1872 lysp_type_free(st->ctx, &type);
1873 memset(&type, 0, sizeof(type));
1874
1875 st->finished_correctly = true;
1876}
1877
1878static void
1879test_reqinstance_elem(void **state)
1880{
1881 struct state *st = *state;
1882 const char *data;
1883 struct lysp_type type = {};
1884
David Sedlákd1144562019-08-06 12:36:14 +02001885 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
David Sedlák69f01612019-07-17 11:41:08 +02001886 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1887 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001888 assert_true(type.flags & LYS_SET_REQINST);
David Sedláke0ef1c62019-09-13 10:05:55 +02001889 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001890 assert_int_equal(type.exts[0].insubstmt_index, 0);
1891 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
1892 lysp_type_free(st->ctx, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001893 memset(&type, 0, sizeof(type));
1894
1895 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
1896 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1897 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001898 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001899 memset(&type, 0, sizeof(type));
1900
1901 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1902 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1903 memset(&type, 0, sizeof(type));
David Sedlák26ea1432019-08-14 13:42:23 +02001904 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001905
1906 st->finished_correctly = true;
1907}
1908
1909static void
1910test_revision_date_elem(void **state)
1911{
1912 struct state *st = *state;
1913 const char *data;
1914 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001915 struct lysp_ext_instance *exts = NULL;
1916
1917 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END;
1918 assert_int_equal(test_element_helper(st, &data, rev, NULL, &exts, true), LY_SUCCESS);
1919 assert_string_equal(rev, "2000-01-01");
David Sedláke0ef1c62019-09-13 10:05:55 +02001920 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001921 assert_int_equal(exts[0].insubstmt_index, 0);
1922 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
1923 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001924
1925 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
1926 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS);
1927 assert_string_equal(rev, "2000-01-01");
1928
1929 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
1930 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID);
1931 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1932
1933 st->finished_correctly = true;
1934}
1935
1936static void
1937test_unique_elem(void **state)
1938{
1939 struct state *st = *state;
1940 const char *data;
1941 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001942 struct lysp_ext_instance *exts = NULL;
1943
1944 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END;
1945 assert_int_equal(test_element_helper(st, &data, &values, NULL, &exts, true), LY_SUCCESS);
1946 assert_string_equal(*values, "tag");
David Sedláke0ef1c62019-09-13 10:05:55 +02001947 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001948 assert_int_equal(exts[0].insubstmt_index, 0);
1949 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
1950 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1951 FREE_STRING(st->ctx, *values);
1952 LY_ARRAY_FREE(values);
1953 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001954
1955 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
1956 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1957 assert_string_equal(*values, "tag");
1958 FREE_STRING(st->ctx, *values);
1959 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001960 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001961
1962 st->finished_correctly = true;
1963}
1964
1965static void
1966test_units_elem(void **state)
1967{
1968 struct state *st = *state;
1969 const char *data;
1970 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001971 struct lysp_ext_instance *exts = NULL;
1972
1973 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END;
1974 assert_int_equal(test_element_helper(st, &data, &values, NULL, &exts, true), LY_SUCCESS);
1975 assert_string_equal(values, "name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001976 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001977 assert_int_equal(exts[0].insubstmt_index, 0);
1978 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
1979 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1980 FREE_STRING(st->ctx, values);
1981 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001982
1983 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
1984 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1985 assert_string_equal(values, "name");
1986 FREE_STRING(st->ctx, values);
David Sedlákd1144562019-08-06 12:36:14 +02001987 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001988
1989 st->finished_correctly = true;
1990}
1991
1992static void
1993test_when_elem(void **state)
1994{
1995 struct state *st = *state;
1996 const char *data;
1997 struct lysp_when *when = NULL;
1998
1999 data = ELEMENT_WRAPPER_START
2000 "<when condition=\"cond\">"
2001 "<description><text>desc</text></description>"
2002 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002003 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02002004 "</when>"
2005 ELEMENT_WRAPPER_END;
2006 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
2007 assert_string_equal(when->cond, "cond");
2008 assert_string_equal(when->dsc, "desc");
2009 assert_string_equal(when->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002010 assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002011 assert_int_equal(when->exts[0].insubstmt_index, 0);
2012 assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02002013 lysp_when_free(st->ctx, when);
2014 free(when);
2015 when = NULL;
2016
2017 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
2018 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
2019 assert_string_equal(when->cond, "cond");
2020 lysp_when_free(st->ctx, when);
2021 free(when);
2022 when = NULL;
2023
2024 st->finished_correctly = true;
2025}
2026
2027static void
2028test_yin_text_value_elem(void **state)
2029{
2030 struct state *st = *state;
2031 const char *data;
2032 const char *val;
2033
2034 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
2035 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2036 assert_string_equal(val, "text");
2037 FREE_STRING(st->ctx, val);
2038
2039 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
2040 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2041 assert_string_equal(val, "text");
2042 FREE_STRING(st->ctx, val);
2043
2044 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
2045 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2046 assert_string_equal("", val);
2047 FREE_STRING(st->ctx, val);
2048
David Sedlák8e7bda82019-07-16 17:57:50 +02002049 st->finished_correctly = true;
2050}
David Sedlák32488102019-07-15 17:44:10 +02002051
David Sedlák374d2b32019-07-17 15:06:55 +02002052static void
2053test_type_elem(void **state)
2054{
2055 struct state *st = *state;
2056 const char *data;
2057 struct lysp_type type = {};
2058
2059 /* max subelems */
2060 data = ELEMENT_WRAPPER_START
2061 "<type name=\"type-name\">"
2062 "<base name=\"base-name\"/>"
2063 "<bit name=\"bit\"/>"
2064 "<enum name=\"enum\"/>"
2065 "<fraction-digits value=\"2\"/>"
2066 "<length value=\"length\"/>"
2067 "<path value=\"path\"/>"
2068 "<pattern value=\"pattern\"/>"
2069 "<range value=\"range\" />"
2070 "<require-instance value=\"true\"/>"
2071 "<type name=\"sub-type-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002072 EXT_SUBELEM
David Sedlák374d2b32019-07-17 15:06:55 +02002073 "</type>"
2074 ELEMENT_WRAPPER_END;
2075 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
2076 assert_string_equal(type.name, "type-name");
2077 assert_string_equal(*type.bases, "base-name");
2078 assert_string_equal(type.bits->name, "bit");
2079 assert_string_equal(type.enums->name, "enum");
2080 assert_int_equal(type.fraction_digits, 2);
2081 assert_string_equal(type.length->arg, "length");
2082 assert_string_equal(type.path, "path");
2083 assert_string_equal(type.patterns->arg, "\006pattern");
2084 assert_string_equal(type.range->arg, "range");
2085 assert_int_equal(type.require_instance, 1);
2086 assert_string_equal(type.types->name, "sub-type-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02002087 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002088 assert_int_equal(type.exts[0].insubstmt_index, 0);
2089 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002090 assert_true(type.flags & LYS_SET_BASE);
2091 assert_true(type.flags & LYS_SET_BIT);
2092 assert_true(type.flags & LYS_SET_ENUM);
2093 assert_true(type.flags & LYS_SET_FRDIGITS);
2094 assert_true(type.flags & LYS_SET_LENGTH);
2095 assert_true(type.flags & LYS_SET_PATH);
2096 assert_true(type.flags & LYS_SET_PATTERN);
2097 assert_true(type.flags & LYS_SET_RANGE);
2098 assert_true(type.flags & LYS_SET_REQINST);
2099 assert_true(type.flags & LYS_SET_TYPE);
David Sedlákd1144562019-08-06 12:36:14 +02002100 lysp_type_free(st->ctx, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02002101 memset(&type, 0, sizeof(type));
2102
2103 /* min subelems */
2104 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
2105 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
2106 lysp_type_free(st->ctx, &type);
2107 memset(&type, 0, sizeof(type));
2108
2109 st->finished_correctly = true;
2110}
2111
David Sedlák1af868e2019-07-17 17:03:14 +02002112static void
2113test_max_elems_elem(void **state)
2114{
2115 struct state *st = *state;
2116 const char *data;
2117 struct lysp_node_list list = {};
2118 struct lysp_node_leaflist llist = {};
2119 struct lysp_refine refine = {};
2120
David Sedlákd1144562019-08-06 12:36:14 +02002121 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>";
David Sedlák1af868e2019-07-17 17:03:14 +02002122 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
2123 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002124 assert_true(refine.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002125 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002126 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2127 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2128 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002129
David Sedlákd1144562019-08-06 12:36:14 +02002130 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>";
David Sedlák1af868e2019-07-17 17:03:14 +02002131 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
2132 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002133 assert_true(list.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002134 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002135 assert_int_equal(list.exts[0].insubstmt_index, 0);
2136 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2137 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002138
David Sedlákd1144562019-08-06 12:36:14 +02002139 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>";
David Sedlák1af868e2019-07-17 17:03:14 +02002140 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
2141 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002142 assert_true(llist.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002143 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002144 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2145 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2146 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002147
2148 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
2149 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
2150 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002151 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02002152
2153 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
2154 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002155 logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002156
2157 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
2158 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002159 logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002160
2161 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
2162 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002163 logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002164
2165 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
2166 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002167 logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002168
2169 st->finished_correctly = true;
2170}
2171
David Sedlák09e18c92019-07-18 11:17:11 +02002172static void
2173test_min_elems_elem(void **state)
2174{
2175 struct state *st = *state;
2176 const char *data;
2177 struct lysp_node_list list = {};
2178 struct lysp_node_leaflist llist = {};
2179 struct lysp_refine refine = {};
2180
David Sedlákd1144562019-08-06 12:36:14 +02002181 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>";
David Sedlák09e18c92019-07-18 11:17:11 +02002182 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
2183 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002184 assert_true(refine.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002185 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002186 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2187 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2188 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002189
David Sedlákd1144562019-08-06 12:36:14 +02002190 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>";
David Sedlák09e18c92019-07-18 11:17:11 +02002191 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
2192 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002193 assert_true(list.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002194 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002195 assert_int_equal(list.exts[0].insubstmt_index, 0);
2196 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2197 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002198
David Sedlákd1144562019-08-06 12:36:14 +02002199 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>";
David Sedlák09e18c92019-07-18 11:17:11 +02002200 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
2201 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002202 assert_true(llist.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002203 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002204 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2205 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2206 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002207
2208 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
2209 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002210 logbuf_assert("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002211
2212 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
2213 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002214 logbuf_assert("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002215
2216 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
2217 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002218 logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002219
2220 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
2221 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002222 logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002223
2224 st->finished_correctly = true;
2225}
2226
David Sedláka2dad212019-07-18 12:45:19 +02002227static void
2228test_ordby_elem(void **state)
2229{
2230 struct state *st = *state;
2231 const char *data;
2232 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02002233 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02002234
David Sedlákd1144562019-08-06 12:36:14 +02002235 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END;
2236 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002237 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláke0ef1c62019-09-13 10:05:55 +02002238 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002239 assert_int_equal(exts[0].insubstmt_index, 0);
2240 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
2241 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02002242
2243 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
2244 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002245 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02002246
2247 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
2248 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02002249 logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Valid values are \"system\" and \"user\". Line number 1.");
David Sedláka2dad212019-07-18 12:45:19 +02002250
2251 st->finished_correctly = true;
2252}
2253
David Sedlák8a83bbb2019-07-18 14:46:00 +02002254static void
2255test_any_elem(void **state)
2256{
2257 struct state *st = *state;
2258 const char *data;
2259 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002260 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02002261 struct lysp_node_anydata *parsed = NULL;
2262
2263 /* anyxml max subelems */
2264 data = ELEMENT_WRAPPER_START
2265 "<anyxml name=\"any-name\">"
2266 "<config value=\"true\" />"
2267 "<description><text>desc</text></description>"
2268 "<if-feature name=\"feature\" />"
2269 "<mandatory value=\"true\" />"
2270 "<must condition=\"must-cond\" />"
2271 "<reference><text>ref</text></reference>"
2272 "<status value=\"deprecated\"/>"
2273 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002274 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002275 "</anyxml>"
2276 ELEMENT_WRAPPER_END;
2277 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2278 parsed = (struct lysp_node_anydata *)siblings;
2279 assert_null(parsed->parent);
2280 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002281 assert_true(parsed->flags & LYS_CONFIG_W);
2282 assert_true(parsed->flags & LYS_MAND_TRUE);
2283 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002284 assert_null(parsed->next);
2285 assert_string_equal(parsed->name, "any-name");
2286 assert_string_equal(parsed->dsc, "desc");
2287 assert_string_equal(parsed->ref, "ref");
2288 assert_string_equal(parsed->when->cond, "when-cond");
2289 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002290 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002291 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2292 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002293 lysp_node_free(st->ctx, siblings);
2294 siblings = NULL;
2295
2296 /* anydata max subelems */
2297 data = ELEMENT_WRAPPER_START
2298 "<anydata name=\"any-name\">"
2299 "<config value=\"true\" />"
2300 "<description><text>desc</text></description>"
2301 "<if-feature name=\"feature\" />"
2302 "<mandatory value=\"true\" />"
2303 "<must condition=\"must-cond\" />"
2304 "<reference><text>ref</text></reference>"
2305 "<status value=\"deprecated\"/>"
2306 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002307 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002308 "</anydata>"
2309 ELEMENT_WRAPPER_END;
2310 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2311 parsed = (struct lysp_node_anydata *)siblings;
2312 assert_null(parsed->parent);
2313 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002314 assert_true(parsed->flags & LYS_CONFIG_W);
2315 assert_true(parsed->flags & LYS_MAND_TRUE);
2316 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002317 assert_null(parsed->next);
2318 assert_string_equal(parsed->name, "any-name");
2319 assert_string_equal(parsed->dsc, "desc");
2320 assert_string_equal(parsed->ref, "ref");
2321 assert_string_equal(parsed->when->cond, "when-cond");
2322 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002323 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002324 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2325 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002326 lysp_node_free(st->ctx, siblings);
2327 siblings = NULL;
2328
2329 /* min subelems */
2330 node_meta.parent = (void *)0x10;
2331 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
2332 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2333 parsed = (struct lysp_node_anydata *)siblings;
2334 assert_ptr_equal(parsed->parent, node_meta.parent);
2335 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
2336 assert_null(parsed->next);
2337 assert_null(parsed->exts);
2338 lysp_node_free(st->ctx, siblings);
2339
2340 st->finished_correctly = true;
2341}
2342
David Sedlák203ca3a2019-07-18 15:26:25 +02002343static void
2344test_leaf_elem(void **state)
2345{
2346 struct state *st = *state;
2347 const char *data;
2348 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002349 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002350 struct lysp_node_leaf *parsed = NULL;
2351
2352 /* max elements */
2353 data = ELEMENT_WRAPPER_START
2354 "<leaf name=\"leaf\">"
2355 "<config value=\"true\" />"
2356 "<default value=\"def-val\"/>"
2357 "<description><text>desc</text></description>"
2358 "<if-feature name=\"feature\" />"
2359 "<mandatory value=\"true\" />"
2360 "<must condition=\"must-cond\" />"
2361 "<reference><text>ref</text></reference>"
2362 "<status value=\"deprecated\"/>"
2363 "<type name=\"type\"/>"
2364 "<units name=\"uni\"/>"
2365 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002366 EXT_SUBELEM
David Sedlák203ca3a2019-07-18 15:26:25 +02002367 "</leaf>"
2368 ELEMENT_WRAPPER_END;
2369 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2370 parsed = (struct lysp_node_leaf *)siblings;
2371 assert_null(parsed->parent);
2372 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002373 assert_true(parsed->flags & LYS_CONFIG_W);
2374 assert_true(parsed->flags & LYS_MAND_TRUE);
2375 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02002376 assert_null(parsed->next);
2377 assert_string_equal(parsed->name, "leaf");
2378 assert_string_equal(parsed->dsc, "desc");
2379 assert_string_equal(parsed->ref, "ref");
2380 assert_string_equal(parsed->when->cond, "when-cond");
2381 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002382 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002383 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2384 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák203ca3a2019-07-18 15:26:25 +02002385 assert_string_equal(parsed->musts->arg, "must-cond");
2386 assert_string_equal(parsed->type.name, "type");
2387 assert_string_equal(parsed->units, "uni");
2388 assert_string_equal(parsed->dflt, "def-val");
2389 lysp_node_free(st->ctx, siblings);
2390 siblings = NULL;
2391
2392 /* min elements */
2393 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
2394 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2395 parsed = (struct lysp_node_leaf *)siblings;
2396 assert_string_equal(parsed->name, "leaf");
2397 assert_string_equal(parsed->type.name, "type");
2398 lysp_node_free(st->ctx, siblings);
2399 siblings = NULL;
2400
2401 st->finished_correctly = true;
2402}
2403
David Sedlákc3da3ef2019-07-19 12:56:08 +02002404static void
2405test_leaf_list_elem(void **state)
2406{
2407 struct state *st = *state;
2408 const char *data;
2409 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002410 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002411 struct lysp_node_leaflist *parsed = NULL;
2412
2413 data = ELEMENT_WRAPPER_START
2414 "<leaf-list name=\"llist\">"
2415 "<config value=\"true\" />"
2416 "<default value=\"def-val0\"/>"
2417 "<default value=\"def-val1\"/>"
2418 "<description><text>desc</text></description>"
2419 "<if-feature name=\"feature\"/>"
2420 "<max-elements value=\"5\"/>"
2421 "<must condition=\"must-cond\"/>"
2422 "<ordered-by value=\"user\" />"
2423 "<reference><text>ref</text></reference>"
2424 "<status value=\"current\"/>"
2425 "<type name=\"type\"/>"
2426 "<units name=\"uni\"/>"
2427 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002428 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002429 "</leaf-list>"
2430 ELEMENT_WRAPPER_END;
2431 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2432 parsed = (struct lysp_node_leaflist *)siblings;
2433 assert_string_equal(parsed->dflts[0], "def-val0");
2434 assert_string_equal(parsed->dflts[1], "def-val1");
2435 assert_string_equal(parsed->dsc, "desc");
2436 assert_string_equal(*parsed->iffeatures, "feature");
2437 assert_int_equal(parsed->max, 5);
2438 assert_string_equal(parsed->musts->arg, "must-cond");
2439 assert_string_equal(parsed->name, "llist");
2440 assert_null(parsed->next);
2441 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2442 assert_null(parsed->parent);
2443 assert_string_equal(parsed->ref, "ref");
2444 assert_string_equal(parsed->type.name, "type");
2445 assert_string_equal(parsed->units, "uni");
2446 assert_string_equal(parsed->when->cond, "when-cond");
2447 assert_true(parsed->flags & LYS_CONFIG_W);
2448 assert_true(parsed->flags & LYS_ORDBY_USER);
2449 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002450 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002451 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2452 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002453 lysp_node_free(st->ctx, siblings);
2454 siblings = NULL;
2455
2456 data = ELEMENT_WRAPPER_START
2457 "<leaf-list name=\"llist\">"
2458 "<config value=\"true\" />"
2459 "<description><text>desc</text></description>"
2460 "<if-feature name=\"feature\"/>"
2461 "<min-elements value=\"5\"/>"
2462 "<must condition=\"must-cond\"/>"
2463 "<ordered-by value=\"user\" />"
2464 "<reference><text>ref</text></reference>"
2465 "<status value=\"current\"/>"
2466 "<type name=\"type\"/>"
2467 "<units name=\"uni\"/>"
2468 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002469 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002470 "</leaf-list>"
2471 ELEMENT_WRAPPER_END;
2472 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2473 parsed = (struct lysp_node_leaflist *)siblings;
2474 assert_string_equal(parsed->dsc, "desc");
2475 assert_string_equal(*parsed->iffeatures, "feature");
2476 assert_int_equal(parsed->min, 5);
2477 assert_string_equal(parsed->musts->arg, "must-cond");
2478 assert_string_equal(parsed->name, "llist");
2479 assert_null(parsed->next);
2480 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2481 assert_null(parsed->parent);
2482 assert_string_equal(parsed->ref, "ref");
2483 assert_string_equal(parsed->type.name, "type");
2484 assert_string_equal(parsed->units, "uni");
2485 assert_string_equal(parsed->when->cond, "when-cond");
2486 assert_true(parsed->flags & LYS_CONFIG_W);
2487 assert_true(parsed->flags & LYS_ORDBY_USER);
2488 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002489 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002490 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2491 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002492 lysp_node_free(st->ctx, siblings);
2493 siblings = NULL;
2494
2495 data = ELEMENT_WRAPPER_START
2496 "<leaf-list name=\"llist\">"
2497 "<config value=\"true\" />"
2498 "<description><text>desc</text></description>"
2499 "<if-feature name=\"feature\"/>"
2500 "<max-elements value=\"15\"/>"
2501 "<min-elements value=\"5\"/>"
2502 "<must condition=\"must-cond\"/>"
2503 "<ordered-by value=\"user\" />"
2504 "<reference><text>ref</text></reference>"
2505 "<status value=\"current\"/>"
2506 "<type name=\"type\"/>"
2507 "<units name=\"uni\"/>"
2508 "<when condition=\"when-cond\"/>"
2509 "</leaf-list>"
2510 ELEMENT_WRAPPER_END;
2511 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2512 parsed = (struct lysp_node_leaflist *)siblings;
2513 assert_string_equal(parsed->dsc, "desc");
2514 assert_string_equal(*parsed->iffeatures, "feature");
2515 assert_int_equal(parsed->min, 5);
2516 assert_int_equal(parsed->max, 15);
2517 assert_string_equal(parsed->musts->arg, "must-cond");
2518 assert_string_equal(parsed->name, "llist");
2519 assert_null(parsed->next);
2520 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2521 assert_null(parsed->parent);
2522 assert_string_equal(parsed->ref, "ref");
2523 assert_string_equal(parsed->type.name, "type");
2524 assert_string_equal(parsed->units, "uni");
2525 assert_string_equal(parsed->when->cond, "when-cond");
2526 assert_true(parsed->flags & LYS_CONFIG_W);
2527 assert_true(parsed->flags & LYS_ORDBY_USER);
2528 assert_true(parsed->flags & LYS_STATUS_CURR);
2529 lysp_node_free(st->ctx, siblings);
2530 siblings = NULL;
2531
2532 data = ELEMENT_WRAPPER_START
2533 "<leaf-list name=\"llist\">"
2534 "<type name=\"type\"/>"
2535 "</leaf-list>"
2536 ELEMENT_WRAPPER_END;
2537 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2538 parsed = (struct lysp_node_leaflist *)siblings;
2539 assert_string_equal(parsed->name, "llist");
2540 assert_string_equal(parsed->type.name, "type");
2541 lysp_node_free(st->ctx, siblings);
2542 siblings = NULL;
2543
2544 /* invalid combinations */
2545 data = ELEMENT_WRAPPER_START
2546 "<leaf-list name=\"llist\">"
2547 "<max-elements value=\"5\"/>"
2548 "<min-elements value=\"15\"/>"
2549 "<type name=\"type\"/>"
2550 "</leaf-list>"
2551 ELEMENT_WRAPPER_END;
2552 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2553 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2554 lysp_node_free(st->ctx, siblings);
2555 siblings = NULL;
2556
2557 data = ELEMENT_WRAPPER_START
2558 "<leaf-list name=\"llist\">"
2559 "<default value=\"def-val1\"/>"
2560 "<min-elements value=\"15\"/>"
2561 "<type name=\"type\"/>"
2562 "</leaf-list>"
2563 ELEMENT_WRAPPER_END;
2564 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002565 logbuf_assert("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002566 lysp_node_free(st->ctx, siblings);
2567 siblings = NULL;
2568
2569 data = ELEMENT_WRAPPER_START
2570 "<leaf-list name=\"llist\">"
2571 "</leaf-list>"
2572 ELEMENT_WRAPPER_END;
2573 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002574 logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002575 lysp_node_free(st->ctx, siblings);
2576 siblings = NULL;
2577
2578 st->finished_correctly = true;
2579}
2580
David Sedlákcb39f642019-07-19 13:19:55 +02002581static void
2582test_presence_elem(void **state)
2583{
2584 struct state *st = *state;
2585 const char *data;
2586 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002587 struct lysp_ext_instance *exts = NULL;
2588
2589 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END;
2590 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
2591 assert_string_equal(val, "presence-val");
David Sedláke0ef1c62019-09-13 10:05:55 +02002592 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002593 assert_int_equal(exts[0].insubstmt_index, 0);
2594 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
2595 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2596 FREE_STRING(st->ctx, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002597
2598 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
2599 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2600 assert_string_equal(val, "presence-val");
2601 FREE_STRING(st->ctx, val);
2602
2603 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
2604 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2605 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2606
2607 st->finished_correctly = true;
2608}
2609
David Sedlák12470a82019-07-19 13:44:36 +02002610static void
2611test_key_elem(void **state)
2612{
2613 struct state *st = *state;
2614 const char *data;
2615 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002616 struct lysp_ext_instance *exts = NULL;
2617
2618 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END;
2619 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
2620 assert_string_equal(val, "key-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02002621 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002622 assert_int_equal(exts[0].insubstmt_index, 0);
2623 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
2624 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2625 FREE_STRING(st->ctx, val);
David Sedlák12470a82019-07-19 13:44:36 +02002626
2627 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
2628 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2629 assert_string_equal(val, "key-value");
2630 FREE_STRING(st->ctx, val);
2631
2632 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
2633 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2634 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2635
2636 st->finished_correctly = true;
2637}
2638
David Sedlák04e17b22019-07-19 15:29:48 +02002639static void
2640test_typedef_elem(void **state)
2641{
2642 struct state *st = *state;
2643 const char *data;
2644 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002645 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002646
2647 data = ELEMENT_WRAPPER_START
2648 "<typedef name=\"tpdf-name\">"
2649 "<default value=\"def-val\"/>"
2650 "<description><text>desc-text</text></description>"
2651 "<reference><text>ref-text</text></reference>"
2652 "<status value=\"current\"/>"
2653 "<type name=\"type\"/>"
2654 "<units name=\"uni\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002655 EXT_SUBELEM
David Sedlák04e17b22019-07-19 15:29:48 +02002656 "</typedef>"
2657 ELEMENT_WRAPPER_END;
2658 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2659 assert_string_equal(tpdfs[0].dflt, "def-val");
2660 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002661 assert_string_equal(tpdfs[0].name, "tpdf-name");
2662 assert_string_equal(tpdfs[0].ref, "ref-text");
2663 assert_string_equal(tpdfs[0].type.name, "type");
2664 assert_string_equal(tpdfs[0].units, "uni");
2665 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002666 assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002667 assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
2668 assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák04e17b22019-07-19 15:29:48 +02002669 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2670 tpdfs = NULL;
2671
2672 data = ELEMENT_WRAPPER_START
2673 "<typedef name=\"tpdf-name\">"
2674 "<type name=\"type\"/>"
2675 "</typedef>"
2676 ELEMENT_WRAPPER_END;
2677 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2678 assert_string_equal(tpdfs[0].name, "tpdf-name");
2679 assert_string_equal(tpdfs[0].type.name, "type");
2680 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2681 tpdfs = NULL;
2682
2683 st->finished_correctly = true;
2684}
2685
David Sedlákd2d676a2019-07-22 11:28:19 +02002686static void
2687test_refine_elem(void **state)
2688{
2689 struct state *st = *state;
2690 const char *data;
2691 struct lysp_refine *refines = NULL;
2692
2693 /* max subelems */
2694 data = ELEMENT_WRAPPER_START
2695 "<refine target-node=\"target\">"
2696 "<if-feature name=\"feature\" />"
2697 "<must condition=\"cond\" />"
2698 "<presence value=\"presence\" />"
2699 "<default value=\"def\" />"
2700 "<config value=\"true\" />"
2701 "<mandatory value=\"true\" />"
2702 "<min-elements value=\"10\" />"
2703 "<max-elements value=\"20\" />"
2704 "<description><text>desc</text></description>"
2705 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002706 EXT_SUBELEM
David Sedlákd2d676a2019-07-22 11:28:19 +02002707 "</refine>"
2708 ELEMENT_WRAPPER_END;
2709 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2710 assert_string_equal(refines->nodeid, "target");
2711 assert_string_equal(*refines->dflts, "def");
2712 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002713 assert_true(refines->flags & LYS_CONFIG_W);
2714 assert_true(refines->flags & LYS_MAND_TRUE);
2715 assert_string_equal(*refines->iffeatures, "feature");
2716 assert_int_equal(refines->max, 20);
2717 assert_int_equal(refines->min, 10);
2718 assert_string_equal(refines->musts->arg, "cond");
2719 assert_string_equal(refines->presence, "presence");
2720 assert_string_equal(refines->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002721 assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002722 assert_int_equal(refines->exts[0].insubstmt_index, 0);
2723 assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákd2d676a2019-07-22 11:28:19 +02002724 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2725 refines = NULL;
2726
2727 /* min subelems */
2728 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
2729 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2730 assert_string_equal(refines->nodeid, "target");
2731 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2732 refines = NULL;
2733
2734 st->finished_correctly = true;
2735}
2736
David Sedlák0d6de5a2019-07-22 13:25:44 +02002737static void
2738test_uses_elem(void **state)
2739{
2740 struct state *st = *state;
2741 const char *data;
2742 struct lysp_node *siblings = NULL;
2743 struct tree_node_meta node_meta = {NULL, &siblings};
2744 struct lysp_node_uses *parsed = NULL;
2745
2746 /* max subelems */
2747 data = ELEMENT_WRAPPER_START
2748 "<uses name=\"uses-name\">"
2749 "<when condition=\"cond\" />"
2750 "<if-feature name=\"feature\" />"
2751 "<status value=\"obsolete\" />"
2752 "<description><text>desc</text></description>"
2753 "<reference><text>ref</text></reference>"
2754 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002755 "<augment target-node=\"target\" />"
David Sedlákd1144562019-08-06 12:36:14 +02002756 EXT_SUBELEM
David Sedlák0d6de5a2019-07-22 13:25:44 +02002757 "</uses>"
2758 ELEMENT_WRAPPER_END;
2759 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2760 parsed = (struct lysp_node_uses *)&siblings[0];
2761 assert_string_equal(parsed->name, "uses-name");
2762 assert_string_equal(parsed->dsc, "desc");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002763 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2764 assert_string_equal(*parsed->iffeatures, "feature");
2765 assert_null(parsed->next);
2766 assert_int_equal(parsed->nodetype, LYS_USES);
2767 assert_null(parsed->parent);
2768 assert_string_equal(parsed->ref, "ref");
2769 assert_string_equal(parsed->refines->nodeid, "target");
2770 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002771 assert_string_equal(parsed->augments->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02002772 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002773 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2774 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002775 lysp_node_free(st->ctx, siblings);
2776 siblings = NULL;
2777
2778 /* min subelems */
2779 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
2780 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2781 assert_string_equal(siblings[0].name, "uses-name");
2782 lysp_node_free(st->ctx, siblings);
2783 siblings = NULL;
2784
2785 st->finished_correctly = true;
2786}
2787
David Sedlákaa854b02019-07-22 14:17:10 +02002788static void
2789test_revision_elem(void **state)
2790{
2791 struct state *st = *state;
2792 const char *data;
2793 struct lysp_revision *revs = NULL;
2794
2795 /* max subelems */
2796 data = ELEMENT_WRAPPER_START
2797 "<revision date=\"2018-12-25\">"
2798 "<description><text>desc</text></description>"
2799 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002800 EXT_SUBELEM
David Sedlákaa854b02019-07-22 14:17:10 +02002801 "</revision>"
2802 ELEMENT_WRAPPER_END;
2803 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2804 assert_string_equal(revs->date, "2018-12-25");
2805 assert_string_equal(revs->dsc, "desc");
2806 assert_string_equal(revs->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002807 assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002808 assert_int_equal(revs->exts[0].insubstmt_index, 0);
2809 assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaa854b02019-07-22 14:17:10 +02002810 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2811 revs = NULL;
2812
2813 /* min subelems */
2814 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
2815 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2816 assert_string_equal(revs->date, "2005-05-05");
2817 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2818 revs = NULL;
2819
2820 /* invalid value */
2821 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
2822 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID);
2823 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2824 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2825 revs = NULL;
2826
2827 st->finished_correctly = true;
2828}
2829
David Sedlák0c2bab92019-07-22 15:33:19 +02002830static void
2831test_include_elem(void **state)
2832{
2833 struct state *st = *state;
2834 const char *data;
2835 struct lysp_include *includes = NULL;
2836 struct include_meta inc_meta = {"module-name", &includes};
2837
2838 /* max subelems */
2839 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2840 data = ELEMENT_WRAPPER_START
2841 "<include module=\"mod\">"
2842 "<description><text>desc</text></description>"
2843 "<reference><text>ref</text></reference>"
2844 "<revision-date date=\"1999-09-09\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002845 EXT_SUBELEM
David Sedlák0c2bab92019-07-22 15:33:19 +02002846 "</include>"
2847 ELEMENT_WRAPPER_END;
2848 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2849 assert_string_equal(includes->name, "mod");
2850 assert_string_equal(includes->dsc, "desc");
2851 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002852 assert_string_equal(includes->rev, "1999-09-09");
David Sedláke0ef1c62019-09-13 10:05:55 +02002853 assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002854 assert_int_equal(includes->exts[0].insubstmt_index, 0);
2855 assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0c2bab92019-07-22 15:33:19 +02002856 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2857 includes = NULL;
2858
2859 /* min subelems */
2860 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
2861 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2862 assert_string_equal(includes->name, "mod");
2863 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2864 includes = NULL;
2865
2866 /* invalid combinations */
2867 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2868 data = ELEMENT_WRAPPER_START
2869 "<include module=\"mod\">"
2870 "<description><text>desc</text></description>"
2871 "<revision-date date=\"1999-09-09\"/>"
2872 "</include>"
2873 ELEMENT_WRAPPER_END;
2874 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2875 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.");
2876 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2877 includes = NULL;
2878
2879 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2880 data = ELEMENT_WRAPPER_START
2881 "<include module=\"mod\">"
2882 "<reference><text>ref</text></reference>"
2883 "<revision-date date=\"1999-09-09\"/>"
2884 "</include>"
2885 ELEMENT_WRAPPER_END;
2886 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2887 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.");
2888 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2889 includes = NULL;
2890
2891 st->finished_correctly = true;
2892}
2893
David Sedlák5e13dea2019-07-22 16:06:45 +02002894static void
2895test_feature_elem(void **state)
2896{
2897 struct state *st = *state;
2898 const char *data;
2899 struct lysp_feature *features = NULL;
2900
2901 /* max subelems */
2902 data = ELEMENT_WRAPPER_START
2903 "<feature name=\"feature-name\">"
2904 "<if-feature name=\"iff\"/>"
2905 "<status value=\"deprecated\"/>"
2906 "<description><text>desc</text></description>"
2907 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002908 EXT_SUBELEM
David Sedlák5e13dea2019-07-22 16:06:45 +02002909 "</feature>"
2910 ELEMENT_WRAPPER_END;
2911 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2912 assert_string_equal(features->name, "feature-name");
2913 assert_string_equal(features->dsc, "desc");
David Sedlák5e13dea2019-07-22 16:06:45 +02002914 assert_true(features->flags & LYS_STATUS_DEPRC);
2915 assert_string_equal(*features->iffeatures, "iff");
2916 assert_string_equal(features->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002917 assert_string_equal(features->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002918 assert_int_equal(features->exts[0].insubstmt_index, 0);
2919 assert_int_equal(features->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5e13dea2019-07-22 16:06:45 +02002920 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2921 features = NULL;
2922
2923 /* min subelems */
2924 data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
2925 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2926 assert_string_equal(features->name, "feature-name");
2927 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2928 features = NULL;
2929
2930 st->finished_correctly = true;
2931}
2932
David Sedlák28794f22019-07-22 16:45:00 +02002933static void
2934test_identity_elem(void **state)
2935{
2936 struct state *st = *state;
2937 const char *data;
2938 struct lysp_ident *identities = NULL;
2939
2940 /* max subelems */
2941 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2942 data = ELEMENT_WRAPPER_START
2943 "<identity name=\"ident-name\">"
2944 "<if-feature name=\"iff\"/>"
2945 "<base name=\"base-name\"/>"
2946 "<status value=\"deprecated\"/>"
2947 "<description><text>desc</text></description>"
2948 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002949 EXT_SUBELEM
David Sedlák28794f22019-07-22 16:45:00 +02002950 "</identity>"
2951 ELEMENT_WRAPPER_END;
2952 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2953 assert_string_equal(identities->name, "ident-name");
2954 assert_string_equal(*identities->bases, "base-name");
2955 assert_string_equal(*identities->iffeatures, "iff");
2956 assert_string_equal(identities->dsc, "desc");
2957 assert_string_equal(identities->ref, "ref");
2958 assert_true(identities->flags & LYS_STATUS_DEPRC);
David Sedláke0ef1c62019-09-13 10:05:55 +02002959 assert_string_equal(identities->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002960 assert_int_equal(identities->exts[0].insubstmt_index, 0);
2961 assert_int_equal(identities->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák28794f22019-07-22 16:45:00 +02002962 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2963 identities = NULL;
2964
2965 /* min subelems */
2966 data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END;
2967 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2968 assert_string_equal(identities->name, "ident-name");
2969 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2970 identities = NULL;
2971
2972 /* invalid */
2973 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2974 data = ELEMENT_WRAPPER_START
2975 "<identity name=\"ident-name\">"
2976 "<if-feature name=\"iff\"/>"
2977 "</identity>"
2978 ELEMENT_WRAPPER_END;
2979 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID);
2980 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.");
2981 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2982 identities = NULL;
2983
2984 st->finished_correctly = true;
2985}
2986
David Sedlákaf536aa2019-07-23 13:42:23 +02002987static void
2988test_list_elem(void **state)
2989{
2990 struct state *st = *state;
2991 const char *data;
2992 struct lysp_node *siblings = NULL;
2993 struct tree_node_meta node_meta = {NULL, &siblings};
2994 struct lysp_node_list *parsed = NULL;
2995
2996 /* max subelems */
2997 data = ELEMENT_WRAPPER_START
2998 "<list name=\"list-name\">"
2999 "<when condition=\"when\"/>"
3000 "<if-feature name=\"iff\"/>"
3001 "<must condition=\"must-cond\"/>"
3002 "<key value=\"key\"/>"
3003 "<unique tag=\"utag\"/>"
3004 "<config value=\"true\"/>"
3005 "<min-elements value=\"10\"/>"
3006 "<ordered-by value=\"user\"/>"
3007 "<status value=\"deprecated\"/>"
3008 "<description><text>desc</text></description>"
3009 "<reference><text>ref</text></reference>"
3010 "<anydata name=\"anyd\"/>"
3011 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003012 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003013 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003014 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003015 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02003016 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003017 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3018 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02003019 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003020 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02003021 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003022 EXT_SUBELEM
David Sedlákaf536aa2019-07-23 13:42:23 +02003023 "</list>"
3024 ELEMENT_WRAPPER_END;
3025 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3026 parsed = (struct lysp_node_list *)&siblings[0];
3027 assert_string_equal(parsed->dsc, "desc");
3028 assert_string_equal(parsed->child->name, "anyd");
3029 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3030 assert_string_equal(parsed->child->next->name, "anyx");
3031 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02003032 assert_string_equal(parsed->child->next->next->name, "cont");
3033 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003034 assert_string_equal(parsed->child->next->next->next->name, "choice");
3035 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02003036 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
3037 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
3038 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
3039 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3040 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
3041 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
3042 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
3043 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3044 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003045 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02003046 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003047 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02003048 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02003049 assert_true(parsed->flags & LYS_ORDBY_USER);
3050 assert_true(parsed->flags & LYS_STATUS_DEPRC);
3051 assert_true(parsed->flags & LYS_CONFIG_W);
3052 assert_string_equal(*parsed->iffeatures, "iff");
3053 assert_string_equal(parsed->key, "key");
3054 assert_int_equal(parsed->min, 10);
3055 assert_string_equal(parsed->musts->arg, "must-cond");
3056 assert_string_equal(parsed->name, "list-name");
3057 assert_null(parsed->next);
3058 assert_int_equal(parsed->nodetype, LYS_LIST);
3059 assert_null(parsed->parent);
3060 assert_string_equal(parsed->ref, "ref");
3061 assert_string_equal(parsed->typedefs->name, "tpdf");
3062 assert_string_equal(*parsed->uniques, "utag");
3063 assert_string_equal(parsed->when->cond, "when");
David Sedláke0ef1c62019-09-13 10:05:55 +02003064 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003065 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3066 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaf536aa2019-07-23 13:42:23 +02003067 lysp_node_free(st->ctx, siblings);
3068 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3069 siblings = NULL;
3070
3071 /* min subelems */
3072 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
3073 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3074 parsed = (struct lysp_node_list *)&siblings[0];
3075 assert_string_equal(parsed->name, "list-name");
3076 lysp_node_free(st->ctx, siblings);
3077 siblings = NULL;
3078
3079 st->finished_correctly = true;
3080}
3081
David Sedlák031b9e72019-07-23 15:19:37 +02003082static void
3083test_notification_elem(void **state)
3084{
3085 struct state *st = *state;
3086 const char *data;
3087 struct lysp_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003088 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02003089
3090 /* max subelems */
3091 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3092 data = ELEMENT_WRAPPER_START
3093 "<notification name=\"notif-name\">"
3094 "<anydata name=\"anyd\"/>"
3095 "<anyxml name=\"anyx\"/>"
3096 "<description><text>desc</text></description>"
3097 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003098 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3099 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02003100 "<list name=\"sub-list\"/>"
3101 "<must condition=\"cond\"/>"
3102 "<reference><text>ref</text></reference>"
3103 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003104 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02003105 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003106 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003107 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003108 "<grouping name=\"grp\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003109 EXT_SUBELEM
David Sedlák031b9e72019-07-23 15:19:37 +02003110 "</notification>"
3111 ELEMENT_WRAPPER_END;
3112 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
3113 assert_string_equal(notifs->name, "notif-name");
3114 assert_string_equal(notifs->data->name, "anyd");
3115 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
3116 assert_string_equal(notifs->data->next->name, "anyx");
3117 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
3118 assert_string_equal(notifs->data->next->next->name, "leaf");
3119 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
3120 assert_string_equal(notifs->data->next->next->next->name, "llist");
3121 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
3122 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
3123 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02003124 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003125 assert_string_equal(notifs->groupings->name, "grp");
3126 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02003127 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
3128 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
3129 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
3130 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003131 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3132 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
3133 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02003134 assert_string_equal(*notifs->iffeatures, "iff");
3135 assert_string_equal(notifs->musts->arg, "cond");
3136 assert_int_equal(notifs->nodetype, LYS_NOTIF);
3137 assert_null(notifs->parent);
3138 assert_string_equal(notifs->ref, "ref");
3139 assert_string_equal(notifs->typedefs->name, "tpdf");
David Sedláke0ef1c62019-09-13 10:05:55 +02003140 assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003141 assert_int_equal(notifs->exts[0].insubstmt_index, 0);
3142 assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák031b9e72019-07-23 15:19:37 +02003143 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
3144 notifs = NULL;
3145
3146 /* min subelems */
3147 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
3148 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
3149 assert_string_equal(notifs->name, "notif-name");
3150 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003151 notifs = NULL;
3152
3153 st->finished_correctly = true;
3154}
3155
3156static void
3157test_grouping_elem(void **state)
3158{
3159 struct state *st = *state;
3160 const char *data;
3161 struct lysp_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003162 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02003163
3164 /* max subelems */
3165 data = ELEMENT_WRAPPER_START
3166 "<grouping name=\"grp-name\">"
3167 "<anydata name=\"anyd\"/>"
3168 "<anyxml name=\"anyx\"/>"
3169 "<description><text>desc</text></description>"
3170 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003171 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3172 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003173 "<list name=\"list\"/>"
3174 "<notification name=\"notf\"/>"
3175 "<reference><text>ref</text></reference>"
3176 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003177 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003178 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003179 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003180 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003181 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003182 EXT_SUBELEM
David Sedláke3ce9ef2019-07-23 16:34:30 +02003183 "</grouping>"
3184 ELEMENT_WRAPPER_END;
3185 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
3186 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003187 assert_string_equal(grps->data->name, "anyd");
3188 assert_string_equal(grps->data->next->name, "anyx");
3189 assert_string_equal(grps->data->next->next->name, "leaf");
3190 assert_string_equal(grps->data->next->next->next->name, "llist");
3191 assert_string_equal(grps->data->next->next->next->next->name, "list");
3192 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003193 assert_true(grps->flags & LYS_STATUS_CURR);
3194 assert_string_equal(grps->groupings->name, "sub-grp");
3195 assert_int_equal(grps->nodetype, LYS_GROUPING);
3196 assert_string_equal(grps->notifs->name, "notf");
3197 assert_null(grps->parent);
3198 assert_string_equal(grps->ref, "ref");
3199 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003200 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02003201 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003202 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02003203 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003204 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
3205 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
3206 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke0ef1c62019-09-13 10:05:55 +02003207 assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003208 assert_int_equal(grps->exts[0].insubstmt_index, 0);
3209 assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003210 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3211 grps = NULL;
3212
3213 /* min subelems */
3214 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
3215 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
3216 assert_string_equal(grps->name, "grp-name");
3217 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3218 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02003219
3220 st->finished_correctly = true;
3221}
3222
David Sedlákf111bcb2019-07-23 17:15:51 +02003223static void
3224test_container_elem(void **state)
3225{
3226 struct state *st = *state;
3227 const char *data;
3228 struct lysp_node *siblings = NULL;
3229 struct tree_node_meta node_meta = {NULL, &siblings};
3230 struct lysp_node_container *parsed = NULL;
3231
3232 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02003233 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3234 data = ELEMENT_WRAPPER_START
3235 "<container name=\"cont-name\">"
3236 "<anydata name=\"anyd\"/>"
3237 "<anyxml name=\"anyx\"/>"
3238 "<config value=\"true\"/>"
3239 "<container name=\"subcont\"/>"
3240 "<description><text>desc</text></description>"
3241 "<grouping name=\"sub-grp\"/>"
3242 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003243 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3244 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003245 "<list name=\"list\"/>"
3246 "<must condition=\"cond\"/>"
3247 "<notification name=\"notf\"/>"
3248 "<presence value=\"presence\"/>"
3249 "<reference><text>ref</text></reference>"
3250 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003251 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003252 "<uses name=\"uses-name\"/>"
3253 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003254 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003255 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003256 EXT_SUBELEM
David Sedláke2dc9e92019-07-24 09:59:21 +02003257 "</container>"
3258 ELEMENT_WRAPPER_END;
3259 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3260 parsed = (struct lysp_node_container *)siblings;
3261 assert_string_equal(parsed->name, "cont-name");
3262 assert_null(parsed->parent);
3263 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
3264 assert_true(parsed->flags & LYS_CONFIG_W);
3265 assert_true(parsed->flags & LYS_STATUS_CURR);
3266 assert_null(parsed->next);
3267 assert_string_equal(parsed->dsc, "desc");
3268 assert_string_equal(parsed->ref, "ref");
3269 assert_string_equal(parsed->when->cond, "when-cond");
3270 assert_string_equal(*parsed->iffeatures, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02003271 assert_string_equal(parsed->musts->arg, "cond");
3272 assert_string_equal(parsed->presence, "presence");
3273 assert_string_equal(parsed->typedefs->name, "tpdf");
3274 assert_string_equal(parsed->groupings->name, "sub-grp");
3275 assert_string_equal(parsed->child->name, "anyd");
3276 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3277 assert_string_equal(parsed->child->next->name, "anyx");
3278 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3279 assert_string_equal(parsed->child->next->next->name, "subcont");
3280 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3281 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3282 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3283 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3284 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3285 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3286 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3287 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3288 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003289 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3290 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3291 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02003292 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003293 assert_string_equal(parsed->actions->name, "act");
David Sedláke0ef1c62019-09-13 10:05:55 +02003294 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003295 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3296 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke2dc9e92019-07-24 09:59:21 +02003297 lysp_node_free(st->ctx, siblings);
3298 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3299 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02003300
3301 /* min subelems */
3302 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
3303 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3304 parsed = (struct lysp_node_container *)siblings;
3305 assert_string_equal(parsed->name, "cont-name");
3306 lysp_node_free(st->ctx, siblings);
3307 siblings = NULL;
3308
3309 st->finished_correctly = true;
3310}
3311
David Sedlák5379d392019-07-24 10:42:03 +02003312static void
3313test_case_elem(void **state)
3314{
3315 struct state *st = *state;
3316 const char *data;
3317 struct lysp_node *siblings = NULL;
3318 struct tree_node_meta node_meta = {NULL, &siblings};
3319 struct lysp_node_case *parsed = NULL;
3320
3321 /* max subelems */
3322 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3323 data = ELEMENT_WRAPPER_START
3324 "<case name=\"case-name\">"
3325 "<anydata name=\"anyd\"/>"
3326 "<anyxml name=\"anyx\"/>"
3327 "<container name=\"subcont\"/>"
3328 "<description><text>desc</text></description>"
3329 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003330 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3331 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02003332 "<list name=\"list\"/>"
3333 "<reference><text>ref</text></reference>"
3334 "<status value=\"current\"/>"
3335 "<uses name=\"uses-name\"/>"
3336 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003337 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003338 EXT_SUBELEM
David Sedlák5379d392019-07-24 10:42:03 +02003339 "</case>"
3340 ELEMENT_WRAPPER_END;
3341 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3342 parsed = (struct lysp_node_case *)siblings;
3343 assert_string_equal(parsed->name, "case-name");
3344 assert_null(parsed->parent);
3345 assert_int_equal(parsed->nodetype, LYS_CASE);
3346 assert_true(parsed->flags & LYS_STATUS_CURR);
3347 assert_null(parsed->next);
3348 assert_string_equal(parsed->dsc, "desc");
3349 assert_string_equal(parsed->ref, "ref");
3350 assert_string_equal(parsed->when->cond, "when-cond");
3351 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02003352 assert_string_equal(parsed->child->name, "anyd");
3353 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3354 assert_string_equal(parsed->child->next->name, "anyx");
3355 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3356 assert_string_equal(parsed->child->next->next->name, "subcont");
3357 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3358 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3359 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3360 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3361 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3362 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3363 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3364 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3365 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003366 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3367 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3368 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003369 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003370 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3371 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5379d392019-07-24 10:42:03 +02003372 lysp_node_free(st->ctx, siblings);
3373 siblings = NULL;
3374
3375 /* min subelems */
3376 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
3377 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3378 parsed = (struct lysp_node_case *)siblings;
3379 assert_string_equal(parsed->name, "case-name");
3380 lysp_node_free(st->ctx, siblings);
3381 siblings = NULL;
3382
3383 st->finished_correctly = true;
3384}
3385
David Sedlákb7abcfa2019-07-24 12:33:35 +02003386static void
3387test_choice_elem(void **state)
3388{
3389 struct state *st = *state;
3390 const char *data;
3391 struct lysp_node *siblings = NULL;
3392 struct tree_node_meta node_meta = {NULL, &siblings};
3393 struct lysp_node_choice *parsed = NULL;
3394
3395 /* max subelems */
3396 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3397 data = ELEMENT_WRAPPER_START
3398 "<choice name=\"choice-name\">"
3399 "<anydata name=\"anyd\"/>"
3400 "<anyxml name=\"anyx\"/>"
3401 "<case name=\"sub-case\"/>"
3402 "<choice name=\"choice\"/>"
3403 "<config value=\"true\"/>"
3404 "<container name=\"subcont\"/>"
3405 "<default value=\"def\"/>"
3406 "<description><text>desc</text></description>"
3407 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003408 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3409 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003410 "<list name=\"list\"/>"
3411 "<mandatory value=\"true\" />"
3412 "<reference><text>ref</text></reference>"
3413 "<status value=\"current\"/>"
3414 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003415 EXT_SUBELEM
David Sedlákb7abcfa2019-07-24 12:33:35 +02003416 "</choice>"
3417 ELEMENT_WRAPPER_END;
3418 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3419 parsed = (struct lysp_node_choice *)siblings;
3420 assert_string_equal(parsed->name, "choice-name");
3421 assert_null(parsed->parent);
3422 assert_int_equal(parsed->nodetype, LYS_CHOICE);
3423 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
3424 assert_null(parsed->next);
3425 assert_string_equal(parsed->dsc, "desc");
3426 assert_string_equal(parsed->ref, "ref");
3427 assert_string_equal(parsed->when->cond, "when-cond");
3428 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003429 assert_string_equal(parsed->child->name, "anyd");
3430 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3431 assert_string_equal(parsed->child->next->name, "anyx");
3432 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3433 assert_string_equal(parsed->child->next->next->name, "sub-case");
3434 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
3435 assert_string_equal(parsed->child->next->next->next->name, "choice");
3436 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
3437 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
3438 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
3439 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
3440 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
3441 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
3442 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3443 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
3444 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3445 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003446 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003447 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3448 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003449 lysp_node_free(st->ctx, siblings);
3450 siblings = NULL;
3451
3452 /* min subelems */
3453 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
3454 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3455 parsed = (struct lysp_node_choice *)siblings;
3456 assert_string_equal(parsed->name, "choice-name");
3457 lysp_node_free(st->ctx, siblings);
3458 siblings = NULL;
3459
3460 st->finished_correctly = true;
3461}
3462
David Sedlák05404f62019-07-24 14:11:53 +02003463static void
3464test_inout_elem(void **state)
3465{
3466 struct state *st = *state;
3467 const char *data;
3468 struct lysp_action_inout inout = {};
3469 struct inout_meta inout_meta = {NULL, &inout};
3470
3471 /* max subelements */
3472 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3473 data = ELEMENT_WRAPPER_START
3474 "<input>"
3475 "<anydata name=\"anyd\"/>"
3476 "<anyxml name=\"anyx\"/>"
3477 "<choice name=\"choice\"/>"
3478 "<container name=\"subcont\"/>"
3479 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003480 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3481 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003482 "<list name=\"list\"/>"
3483 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003484 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003485 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003486 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003487 "</input>"
3488 ELEMENT_WRAPPER_END;
3489 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3490 assert_null(inout.parent);
3491 assert_int_equal(inout.nodetype, LYS_INPUT);
3492 assert_string_equal(inout.musts->arg, "cond");
3493 assert_string_equal(inout.typedefs->name, "tpdf");
3494 assert_string_equal(inout.groupings->name, "sub-grp");
3495 assert_string_equal(inout.data->name, "anyd");
3496 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3497 assert_string_equal(inout.data->next->name, "anyx");
3498 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3499 assert_string_equal(inout.data->next->next->name, "choice");
3500 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3501 assert_string_equal(inout.data->next->next->next->name, "subcont");
3502 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3503 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3504 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3505 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3506 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3507 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3508 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3509 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3510 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3511 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003512 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003513 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3514 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003515 lysp_action_inout_free(st->ctx, &inout);
3516 memset(&inout, 0, sizeof inout);
3517
3518 /* max subelements */
3519 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3520 data = ELEMENT_WRAPPER_START
3521 "<output>"
3522 "<anydata name=\"anyd\"/>"
3523 "<anyxml name=\"anyx\"/>"
3524 "<choice name=\"choice\"/>"
3525 "<container name=\"subcont\"/>"
3526 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003527 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3528 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003529 "<list name=\"list\"/>"
3530 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003531 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003532 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003533 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003534 "</output>"
3535 ELEMENT_WRAPPER_END;
3536 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3537 assert_null(inout.parent);
3538 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3539 assert_string_equal(inout.musts->arg, "cond");
3540 assert_string_equal(inout.typedefs->name, "tpdf");
3541 assert_string_equal(inout.groupings->name, "sub-grp");
3542 assert_string_equal(inout.data->name, "anyd");
3543 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3544 assert_string_equal(inout.data->next->name, "anyx");
3545 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3546 assert_string_equal(inout.data->next->next->name, "choice");
3547 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3548 assert_string_equal(inout.data->next->next->next->name, "subcont");
3549 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3550 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3551 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3552 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3553 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3554 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3555 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3556 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3557 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3558 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003559 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003560 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3561 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003562 lysp_action_inout_free(st->ctx, &inout);
3563 memset(&inout, 0, sizeof inout);
3564
3565 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003566 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
David Sedlák05404f62019-07-24 14:11:53 +02003567 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003568 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003569 memset(&inout, 0, sizeof inout);
3570
Michal Vaskob83af8a2020-01-06 09:49:22 +01003571 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
David Sedlák05404f62019-07-24 14:11:53 +02003572 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003573 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003574 memset(&inout, 0, sizeof inout);
3575
3576 /* invalid combinations */
3577 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
3578 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02003579 logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003580 memset(&inout, 0, sizeof inout);
3581
3582 st->finished_correctly = true;
3583}
3584
David Sedlák85d0eca2019-07-24 15:15:21 +02003585static void
3586test_action_elem(void **state)
3587{
3588 struct state *st = *state;
3589 const char *data;
3590 struct lysp_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003591 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
David Sedlák85d0eca2019-07-24 15:15:21 +02003592
3593 /* max subelems */
3594 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3595 data = ELEMENT_WRAPPER_START
3596 "<action name=\"act\">"
3597 "<description><text>desc</text></description>"
3598 "<grouping name=\"grouping\"/>"
3599 "<if-feature name=\"iff\"/>"
3600 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003601 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003602 "<reference><text>ref</text></reference>"
3603 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003604 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003605 EXT_SUBELEM
David Sedlák85d0eca2019-07-24 15:15:21 +02003606 "</action>"
3607 ELEMENT_WRAPPER_END;
3608 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3609 assert_null(actions->parent);
3610 assert_int_equal(actions->nodetype, LYS_ACTION);
3611 assert_true(actions->flags & LYS_STATUS_DEPRC);
3612 assert_string_equal(actions->name, "act");
3613 assert_string_equal(actions->dsc, "desc");
3614 assert_string_equal(actions->ref, "ref");
3615 assert_string_equal(*actions->iffeatures, "iff");
3616 assert_string_equal(actions->typedefs->name, "tpdf");
3617 assert_string_equal(actions->groupings->name, "grouping");
3618 assert_string_equal(actions->input.data->name, "uses-name");
3619 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003620 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003621 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3622 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák85d0eca2019-07-24 15:15:21 +02003623 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3624 actions = NULL;
3625
David Sedlákeaa45792019-07-24 15:25:01 +02003626 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3627 data = ELEMENT_WRAPPER_START
3628 "<rpc name=\"act\">"
3629 "<description><text>desc</text></description>"
3630 "<grouping name=\"grouping\"/>"
3631 "<if-feature name=\"iff\"/>"
3632 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003633 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlákeaa45792019-07-24 15:25:01 +02003634 "<reference><text>ref</text></reference>"
3635 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003636 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003637 EXT_SUBELEM
David Sedlákeaa45792019-07-24 15:25:01 +02003638 "</rpc>"
3639 ELEMENT_WRAPPER_END;
3640 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3641 assert_null(actions->parent);
3642 assert_int_equal(actions->nodetype, LYS_ACTION);
3643 assert_true(actions->flags & LYS_STATUS_DEPRC);
3644 assert_string_equal(actions->name, "act");
3645 assert_string_equal(actions->dsc, "desc");
3646 assert_string_equal(actions->ref, "ref");
3647 assert_string_equal(*actions->iffeatures, "iff");
3648 assert_string_equal(actions->typedefs->name, "tpdf");
3649 assert_string_equal(actions->groupings->name, "grouping");
3650 assert_string_equal(actions->input.data->name, "uses-name");
3651 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003652 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003653 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3654 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákeaa45792019-07-24 15:25:01 +02003655 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3656 actions = NULL;
3657
David Sedlák85d0eca2019-07-24 15:15:21 +02003658 /* min subelems */
3659 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
3660 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3661 assert_string_equal(actions->name, "act");
3662 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3663 actions = NULL;
3664
3665 st->finished_correctly = true;
3666}
3667
David Sedlák992fb7c2019-07-24 16:51:01 +02003668static void
3669test_augment_elem(void **state)
3670{
3671 struct state *st = *state;
3672 const char *data;
3673 struct lysp_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003674 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003675
3676 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3677 data = ELEMENT_WRAPPER_START
3678 "<augment target-node=\"target\">"
3679 "<action name=\"action\"/>"
3680 "<anydata name=\"anyd\"/>"
3681 "<anyxml name=\"anyx\"/>"
3682 "<case name=\"case\"/>"
3683 "<choice name=\"choice\"/>"
3684 "<container name=\"subcont\"/>"
3685 "<description><text>desc</text></description>"
3686 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003687 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3688 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003689 "<list name=\"list\"/>"
3690 "<notification name=\"notif\"/>"
3691 "<reference><text>ref</text></reference>"
3692 "<status value=\"current\"/>"
3693 "<uses name=\"uses\"/>"
3694 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003695 EXT_SUBELEM
David Sedlák992fb7c2019-07-24 16:51:01 +02003696 "</augment>"
3697 ELEMENT_WRAPPER_END;
3698 assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS);
3699 assert_string_equal(augments->nodeid, "target");
3700 assert_null(augments->parent);
3701 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3702 assert_true(augments->flags & LYS_STATUS_CURR);
3703 assert_string_equal(augments->dsc, "desc");
3704 assert_string_equal(augments->ref, "ref");
3705 assert_string_equal(augments->when->cond, "when-cond");
3706 assert_string_equal(*augments->iffeatures, "iff");
3707 assert_string_equal(augments->child->name, "anyd");
3708 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3709 assert_string_equal(augments->child->next->name, "anyx");
3710 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3711 assert_string_equal(augments->child->next->next->name, "case");
3712 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3713 assert_string_equal(augments->child->next->next->next->name, "choice");
3714 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3715 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3716 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3717 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3718 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3719 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3720 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3721 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3722 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3723 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3724 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3725 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3726 assert_string_equal(augments->actions->name, "action");
3727 assert_string_equal(augments->notifs->name, "notif");
David Sedláke0ef1c62019-09-13 10:05:55 +02003728 assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003729 assert_int_equal(augments->exts[0].insubstmt_index, 0);
3730 assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák992fb7c2019-07-24 16:51:01 +02003731 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3732 augments = NULL;
3733
3734 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
3735 assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS);
3736 assert_string_equal(augments->nodeid, "target");
3737 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3738 augments = NULL;
3739
3740 st->finished_correctly = true;
3741}
3742
David Sedlák4ffcec82019-07-25 15:10:21 +02003743static void
3744test_deviate_elem(void **state)
3745{
3746 struct state *st = *state;
3747 const char *data;
3748 struct lysp_deviate *deviates = NULL;
3749 struct lysp_deviate_add *d_add;
3750 struct lysp_deviate_rpl *d_rpl;
3751 struct lysp_deviate_del *d_del;
3752
3753 /* all valid arguments with min subelems */
3754 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
3755 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3756 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3757 lysp_deviate_free(st->ctx, deviates);
3758 free(deviates);
3759 deviates = NULL;
3760
3761 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
3762 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3763 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3764 lysp_deviate_free(st->ctx, deviates);
3765 free(deviates);
3766 deviates = NULL;
3767
3768 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
3769 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3770 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3771 lysp_deviate_free(st->ctx, deviates);
3772 free(deviates);
3773 deviates = NULL;
3774
3775 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
3776 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3777 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3778 lysp_deviate_free(st->ctx, deviates);
3779 free(deviates);
3780 deviates = NULL;
3781
3782 /* max subelems and valid arguments */
3783 data = ELEMENT_WRAPPER_START
3784 "<deviate value=\"not-supported\">"
David Sedlákd1144562019-08-06 12:36:14 +02003785 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003786 "</deviate>"
3787 ELEMENT_WRAPPER_END;
3788 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3789 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
David Sedláke0ef1c62019-09-13 10:05:55 +02003790 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003791 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3792 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003793 lysp_deviate_free(st->ctx, deviates);
3794 free(deviates);
3795 deviates = NULL;
3796
3797 data = ELEMENT_WRAPPER_START
3798 "<deviate value=\"add\">"
3799 "<units name=\"units\"/>"
3800 "<must condition=\"cond\"/>"
3801 "<unique tag=\"utag\"/>"
3802 "<default value=\"def\"/>"
3803 "<config value=\"true\"/>"
3804 "<mandatory value=\"true\"/>"
3805 "<min-elements value=\"5\"/>"
3806 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003807 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003808 "</deviate>"
3809 ELEMENT_WRAPPER_END;
3810 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3811 d_add = (struct lysp_deviate_add *)deviates;
3812 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3813 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003814 assert_string_equal(d_add->units, "units");
3815 assert_string_equal(d_add->musts->arg, "cond");
3816 assert_string_equal(*d_add->uniques, "utag");
3817 assert_string_equal(*d_add->dflts, "def");
3818 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3819 assert_int_equal(d_add->min, 5);
3820 assert_int_equal(d_add->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003821 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003822 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3823 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003824 lysp_deviate_free(st->ctx, deviates);
3825 free(deviates);
3826 deviates = NULL;
3827
3828 data = ELEMENT_WRAPPER_START
3829 "<deviate value=\"replace\">"
3830 "<type name=\"newtype\"/>"
3831 "<units name=\"uni\"/>"
3832 "<default value=\"def\"/>"
3833 "<config value=\"true\"/>"
3834 "<mandatory value=\"true\"/>"
3835 "<min-elements value=\"5\"/>"
3836 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003837 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003838 "</deviate>"
3839 ELEMENT_WRAPPER_END;
3840 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3841 d_rpl = (struct lysp_deviate_rpl *)deviates;
3842 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3843 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003844 assert_string_equal(d_rpl->type->name, "newtype");
3845 assert_string_equal(d_rpl->units, "uni");
3846 assert_string_equal(d_rpl->dflt, "def");
3847 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3848 assert_int_equal(d_rpl->min, 5);
3849 assert_int_equal(d_rpl->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003850 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003851 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3852 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003853 lysp_deviate_free(st->ctx, deviates);
3854 free(deviates);
3855 deviates = NULL;
3856
3857 data = ELEMENT_WRAPPER_START
3858 "<deviate value=\"delete\">"
3859 "<units name=\"u\"/>"
3860 "<must condition=\"c\"/>"
3861 "<unique tag=\"tag\"/>"
3862 "<default value=\"default\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003863 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003864 "</deviate>"
3865 ELEMENT_WRAPPER_END;
3866 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3867 d_del = (struct lysp_deviate_del *)deviates;
3868 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3869 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003870 assert_string_equal(d_del->units, "u");
3871 assert_string_equal(d_del->musts->arg, "c");
3872 assert_string_equal(*d_del->uniques, "tag");
3873 assert_string_equal(*d_del->dflts, "default");
David Sedláke0ef1c62019-09-13 10:05:55 +02003874 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003875 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3876 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003877 lysp_deviate_free(st->ctx, deviates);
3878 free(deviates);
3879 deviates = NULL;
3880
3881 /* invalid arguments */
3882 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
3883 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003884 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003885 deviates = NULL;
3886
3887 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
3888 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003889 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003890 deviates = NULL;
3891
3892 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
3893 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003894 logbuf_assert("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003895 deviates = NULL;
3896
3897 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
3898 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003899 logbuf_assert("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003900 deviates = NULL;
3901
3902 data = ELEMENT_WRAPPER_START
3903 "<deviate value=\"not-supported\">"
3904 "<must condition=\"c\"/>"
3905 "</deviate>"
3906 ELEMENT_WRAPPER_END;
3907 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3908 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3909
3910 st->finished_correctly = true;
3911}
3912
David Sedlák8b754462019-07-25 16:22:13 +02003913static void
3914test_deviation_elem(void **state)
3915{
3916 struct state *st = *state;
3917 const char *data;
3918 struct lysp_deviation *deviations = NULL;
3919
3920 /* min subelems */
3921 data = ELEMENT_WRAPPER_START
3922 "<deviation target-node=\"target\">"
3923 "<deviate value=\"not-supported\"/>"
3924 "</deviation>"
3925 ELEMENT_WRAPPER_END;
3926 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS);
3927 assert_string_equal(deviations->nodeid, "target");
3928 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3929 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3930 deviations = NULL;
3931
3932 /* max subelems */
3933 data = ELEMENT_WRAPPER_START
3934 "<deviation target-node=\"target\">"
3935 "<reference><text>ref</text></reference>"
3936 "<description><text>desc</text></description>"
3937 "<deviate value=\"add\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003938 EXT_SUBELEM
David Sedlák8b754462019-07-25 16:22:13 +02003939 "</deviation>"
3940 ELEMENT_WRAPPER_END;
3941 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS);
3942 assert_string_equal(deviations->nodeid, "target");
3943 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3944 assert_string_equal(deviations->ref, "ref");
3945 assert_string_equal(deviations->dsc, "desc");
David Sedláke0ef1c62019-09-13 10:05:55 +02003946 assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003947 assert_int_equal(deviations->exts[0].insubstmt_index, 0);
3948 assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8b754462019-07-25 16:22:13 +02003949 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3950 deviations = NULL;
3951
3952 /* invalid */
3953 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
3954 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, false), LY_EVALID);
3955 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3956 deviations = NULL;
David Sedlák1538a842019-08-08 15:38:51 +02003957 logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
3958 /* TODO */
David Sedlák8b754462019-07-25 16:22:13 +02003959 st->finished_correctly = true;
3960}
3961
David Sedlák4f03b932019-07-26 13:01:47 +02003962static void
3963test_module_elem(void **state)
3964{
3965 struct state *st = *state;
David Sedlákc5b20842019-08-13 10:18:31 +02003966 const char *data, *name, *prefix;
3967 size_t name_len, prefix_len;
David Sedlák4f03b932019-07-26 13:01:47 +02003968 struct yin_arg_record *attrs = NULL;
David Sedlák4f03b932019-07-26 13:01:47 +02003969 struct lys_module *lys_mod = NULL;
3970 struct lysp_module *lysp_mod = NULL;
3971
3972 /* max subelems */
3973 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
3974 lys_mod = calloc(1, sizeof *lys_mod);
3975 lysp_mod = calloc(1, sizeof *lysp_mod);
3976 lys_mod->ctx = st->ctx;
3977 lysp_mod->mod = lys_mod;
3978 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3979 "<yang-version value=\"1.1\"/>\n"
3980 "<namespace uri=\"ns\"/>\n"
3981 "<prefix value=\"pref\"/>\n"
3982 "<include module=\"b-mod\"/>\n"
3983 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3984 "<organization><text>org</text></organization>\n"
3985 "<contact><text>contact</text></contact>\n"
3986 "<description><text>desc</text></description>"
3987 "<reference><text>ref</text></reference>\n"
3988 "<revision date=\"2019-02-02\"/>\n"
3989 "<anydata name=\"anyd\"/>\n"
3990 "<anyxml name=\"anyx\"/>\n"
3991 "<choice name=\"choice\"/>\n"
3992 "<container name=\"cont\"/>\n"
3993 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3994 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3995 "<list name=\"sub-list\"/>\n"
3996 "<uses name=\"uses-name\"/>\n"
3997 "<augment target-node=\"target\"/>\n"
3998 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3999 "<extension name=\"ext\"/>\n"
4000 "<feature name=\"feature\"/>\n"
4001 "<grouping name=\"grp\"/>\n"
4002 "<identity name=\"ident-name\"/>\n"
4003 "<notification name=\"notf\"/>\n"
4004 "<rpc name=\"rpc-name\"/>\n"
4005 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004006 EXT_SUBELEM"\n"
David Sedlák4f03b932019-07-26 13:01:47 +02004007 "</module>\n";
David Sedlákc5b20842019-08-13 10:18:31 +02004008 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02004009 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4010 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS);
4011 assert_string_equal(lysp_mod->mod->name, "mod");
4012 assert_string_equal(lysp_mod->revs, "2019-02-02");
4013 assert_string_equal(lysp_mod->mod->ns, "ns");
4014 assert_string_equal(lysp_mod->mod->prefix, "pref");
4015 assert_null(lysp_mod->mod->filepath);
4016 assert_string_equal(lysp_mod->mod->org, "org");
4017 assert_string_equal(lysp_mod->mod->contact, "contact");
4018 assert_string_equal(lysp_mod->mod->dsc, "desc");
4019 assert_string_equal(lysp_mod->mod->ref, "ref");
4020 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
4021 assert_string_equal(lysp_mod->imports->name, "a-mod");
4022 assert_string_equal(lysp_mod->includes->name, "b-mod");
4023 assert_string_equal(lysp_mod->extensions->name, "ext");
4024 assert_string_equal(lysp_mod->features->name, "feature");
4025 assert_string_equal(lysp_mod->identities->name, "ident-name");
4026 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
4027 assert_string_equal(lysp_mod->groupings->name, "grp");
4028 assert_string_equal(lysp_mod->data->name, "anyd");
4029 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
4030 assert_string_equal(lysp_mod->data->next->name, "anyx");
4031 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
4032 assert_string_equal(lysp_mod->data->next->next->name, "choice");
4033 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
4034 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
4035 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
4036 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
4037 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
4038 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
4039 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4040 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
4041 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4042 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
4043 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4044 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
4045 assert_string_equal(lysp_mod->augments->nodeid, "target");
4046 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
4047 assert_string_equal(lysp_mod->notifs->name, "notf");
4048 assert_string_equal(lysp_mod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004049 assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004050 assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
4051 assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4f03b932019-07-26 13:01:47 +02004052 lysp_module_free(lysp_mod);
4053 lys_module_free(lys_mod, NULL);
4054 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4055 attrs = NULL;
4056
4057 /* min subelems */
4058 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4059 lys_mod = calloc(1, sizeof *lys_mod);
4060 lysp_mod = calloc(1, sizeof *lysp_mod);
4061 lys_mod->ctx = st->ctx;
4062 lysp_mod->mod = lys_mod;
4063 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
4064 "<namespace uri=\"ns\"/>"
4065 "<prefix value=\"pref\"/>"
4066 "<yang-version value=\"1.1\"/>"
4067 "</module>";
David Sedlákc5b20842019-08-13 10:18:31 +02004068 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02004069 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4070 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004071 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák4f03b932019-07-26 13:01:47 +02004072 lysp_module_free(lysp_mod);
4073 lys_module_free(lys_mod, NULL);
4074 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4075 attrs = NULL;
David Sedlák298ff6d2019-07-26 14:29:03 +02004076
David Sedláke6cd89e2019-08-07 12:46:02 +02004077 /* incorrect subelem order */
4078 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4079 lys_mod = calloc(1, sizeof *lys_mod);
4080 lysp_mod = calloc(1, sizeof *lysp_mod);
4081 lys_mod->ctx = st->ctx;
4082 lysp_mod->mod = lys_mod;
4083 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
4084 "<feature name=\"feature\"/>\n"
4085 "<namespace uri=\"ns\"/>"
4086 "<prefix value=\"pref\"/>"
4087 "<yang-version value=\"1.1\"/>"
4088 "</module>";
David Sedlákc5b20842019-08-13 10:18:31 +02004089 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedláke6cd89e2019-08-07 12:46:02 +02004090 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4091 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02004092 logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 30.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004093 lysp_module_free(lysp_mod);
4094 lys_module_free(lys_mod, NULL);
4095 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4096 attrs = NULL;
4097
David Sedlák298ff6d2019-07-26 14:29:03 +02004098 st->finished_correctly = true;
4099}
4100
4101static void
4102test_submodule_elem(void **state)
4103{
4104 struct state *st = *state;
David Sedlákc5b20842019-08-13 10:18:31 +02004105 const char *data, *name, *prefix;
4106 size_t name_len, prefix_len;
David Sedlák298ff6d2019-07-26 14:29:03 +02004107 struct yin_arg_record *attrs = NULL;
David Sedlák298ff6d2019-07-26 14:29:03 +02004108 struct lysp_submodule *lysp_submod = NULL;
4109
4110 /* max subelements */
4111 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4112 lysp_submod = calloc(1, sizeof *lysp_submod);
4113 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
4114 "<yang-version value=\"1.1\"/>\n"
4115 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4116 "<include module=\"b-mod\"/>\n"
4117 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
4118 "<organization><text>org</text></organization>\n"
4119 "<contact><text>contact</text></contact>\n"
4120 "<description><text>desc</text></description>"
4121 "<reference><text>ref</text></reference>\n"
4122 "<revision date=\"2019-02-02\"/>\n"
4123 "<anydata name=\"anyd\"/>\n"
4124 "<anyxml name=\"anyx\"/>\n"
4125 "<choice name=\"choice\"/>\n"
4126 "<container name=\"cont\"/>\n"
4127 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
4128 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
4129 "<list name=\"sub-list\"/>\n"
4130 "<uses name=\"uses-name\"/>\n"
4131 "<augment target-node=\"target\"/>\n"
4132 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
4133 "<extension name=\"ext\"/>\n"
4134 "<feature name=\"feature\"/>\n"
4135 "<grouping name=\"grp\"/>\n"
4136 "<identity name=\"ident-name\"/>\n"
4137 "<notification name=\"notf\"/>\n"
4138 "<rpc name=\"rpc-name\"/>\n"
4139 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004140 EXT_SUBELEM"\n"
David Sedlák298ff6d2019-07-26 14:29:03 +02004141 "</submodule>\n";
David Sedlákc5b20842019-08-13 10:18:31 +02004142 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004143 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4144 assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS);
4145
4146 assert_string_equal(lysp_submod->name, "mod");
4147 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02004148 assert_string_equal(lysp_submod->prefix, "pref");
4149 assert_null(lysp_submod->filepath);
4150 assert_string_equal(lysp_submod->org, "org");
4151 assert_string_equal(lysp_submod->contact, "contact");
4152 assert_string_equal(lysp_submod->dsc, "desc");
4153 assert_string_equal(lysp_submod->ref, "ref");
4154 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
4155 assert_string_equal(lysp_submod->imports->name, "a-mod");
4156 assert_string_equal(lysp_submod->includes->name, "b-mod");
4157 assert_string_equal(lysp_submod->extensions->name, "ext");
4158 assert_string_equal(lysp_submod->features->name, "feature");
4159 assert_string_equal(lysp_submod->identities->name, "ident-name");
4160 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
4161 assert_string_equal(lysp_submod->groupings->name, "grp");
4162 assert_string_equal(lysp_submod->data->name, "anyd");
4163 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
4164 assert_string_equal(lysp_submod->data->next->name, "anyx");
4165 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
4166 assert_string_equal(lysp_submod->data->next->next->name, "choice");
4167 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
4168 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
4169 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
4170 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
4171 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
4172 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
4173 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4174 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
4175 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4176 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
4177 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4178 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
4179 assert_string_equal(lysp_submod->augments->nodeid, "target");
4180 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
4181 assert_string_equal(lysp_submod->notifs->name, "notf");
4182 assert_string_equal(lysp_submod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004183 assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004184 assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
4185 assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák298ff6d2019-07-26 14:29:03 +02004186
4187 lysp_submodule_free(st->ctx, lysp_submod);
4188 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4189 attrs = NULL;
4190
4191 /* min subelemnts */
4192 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4193 lysp_submod = calloc(1, sizeof *lysp_submod);
4194 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4195 "<yang-version value=\"1.0\"/>"
4196 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4197 "</submodule>";
David Sedlákc5b20842019-08-13 10:18:31 +02004198 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004199 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4200 assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS);
4201 assert_string_equal(lysp_submod->prefix, "pref");
4202 assert_string_equal(lysp_submod->belongsto, "mod-name");
4203 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
4204 lysp_submodule_free(st->ctx, lysp_submod);
4205 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4206 attrs = NULL;
4207
David Sedláke6cd89e2019-08-07 12:46:02 +02004208 /* incorrect subelem order */
4209 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4210 lysp_submod = calloc(1, sizeof *lysp_submod);
4211 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4212 "<yang-version value=\"1.0\"/>"
4213 "<reference><text>ref</text></reference>\n"
4214 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4215 "</submodule>";
David Sedlákc5b20842019-08-13 10:18:31 +02004216 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedláke6cd89e2019-08-07 12:46:02 +02004217 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4218 assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02004219 logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 28.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004220 lysp_submodule_free(st->ctx, lysp_submod);
4221 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4222 attrs = NULL;
4223
David Sedlák298ff6d2019-07-26 14:29:03 +02004224 st->finished_correctly = true;
David Sedlák4f03b932019-07-26 13:01:47 +02004225}
4226
David Sedlák8985a142019-07-31 16:43:06 +02004227static void
4228test_yin_parse_module(void **state)
4229{
4230 struct state *st = *state;
4231 const char *data;
4232 struct lys_module *mod;
4233 struct yin_parser_ctx *yin_ctx = NULL;
4234
4235 mod = calloc(1, sizeof *mod);
4236 mod->ctx = st->ctx;
David Sedlákd2844882019-09-13 16:01:22 +02004237 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n"
4238 "<yang-version value=\"1.1\"/>\n"
4239 "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
4240 "<prefix value=\"a\"/>\n"
4241 "<import module=\"ietf-yang-metadata\">\n"
4242 "<prefix value=\"md\"/>\n"
4243 "</import>\n"
4244 "<feature name=\"f\"/>\n"
4245 "<md:annotation name=\"x\">\n"
4246 "<description>\n"
4247 "<text>test</text>\n"
4248 "</description>\n"
4249 "<reference>\n"
4250 "<text>test</text>\n"
4251 "</reference>\n"
4252 "<if-feature name=\"f\"/>\n"
4253 "<status value=\"current\"/>\n"
4254 "<type name=\"uint8\"/>\n"
4255 "<units name=\"meters\"/>\n"
4256 "</md:annotation>\n"
4257 "</module>\n";
4258 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4259 assert_null(mod->parsed->exts->child->next->child);
4260 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
4261 lys_module_free(mod, NULL);
4262 yin_parser_ctx_free(yin_ctx);
4263 mod = NULL;
4264 yin_ctx = NULL;
4265
4266 mod = calloc(1, sizeof *mod);
4267 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004268 data = "<module name=\"example-foo\""
4269 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4270 "xmlns:foo=\"urn:example:foo\""
4271 "xmlns:myext=\"urn:example:extensions\">\n"
4272
4273 "<yang-version value=\"1.0\"/>\n"
4274
4275 "<namespace uri=\"urn:example:foo\"/>\n"
4276 "<prefix value=\"foo\"/>\n"
4277
4278 "<import module=\"example-extensions\">\n"
David Sedlák6d781b62019-08-02 15:22:52 +02004279 "<prefix value=\"myext\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02004280 "</import>\n"
4281
4282 "<list name=\"interface\">\n"
4283 "<key value=\"name\"/>\n"
4284 "<leaf name=\"name\">\n"
4285 "<type name=\"string\"/>\n"
4286 "</leaf>\n"
4287 "<leaf name=\"mtu\">\n"
4288 "<type name=\"uint32\"/>\n"
4289 "<description>\n"
4290 "<text>The MTU of the interface.</text>\n"
4291 "</description>\n"
4292 "<myext:c-define name=\"MY_MTU\"/>\n"
4293 "</leaf>\n"
4294 "</list>\n"
4295 "</module>\n";
4296 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4297 lys_module_free(mod, NULL);
4298 yin_parser_ctx_free(yin_ctx);
4299 mod = NULL;
4300 yin_ctx = NULL;
4301
4302 mod = calloc(1, sizeof *mod);
4303 mod->ctx = st->ctx;
David Sedlák6d781b62019-08-02 15:22:52 +02004304 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4305 "<yang-version value=\"1.0\"/>\n"
4306 "<namespace uri=\"urn:example:foo\"/>\n"
4307 "<prefix value=\"foo\"/>\n"
4308 "</module>\n";
4309 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4310 lys_module_free(mod, NULL);
4311 yin_parser_ctx_free(yin_ctx);
4312 mod = NULL;
4313 yin_ctx = NULL;
4314
4315
4316 mod = calloc(1, sizeof *mod);
4317 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004318 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4319 "</submodule>\n";
4320 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL);
4321 logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
4322 lys_module_free(mod, NULL);
4323 yin_parser_ctx_free(yin_ctx);
4324
David Sedlák6d781b62019-08-02 15:22:52 +02004325 mod = calloc(1, sizeof *mod);
4326 mod->ctx = st->ctx;
4327 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4328 "<yang-version value=\"1.0\"/>\n"
4329 "<namespace uri=\"urn:example:foo\"/>\n"
4330 "<prefix value=\"foo\"/>\n"
4331 "</module>"
4332 "<module>";
4333 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID);
4334 logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
4335 lys_module_free(mod, NULL);
4336 yin_parser_ctx_free(yin_ctx);
4337 mod = NULL;
4338 yin_ctx = NULL;
4339
David Sedlák8985a142019-07-31 16:43:06 +02004340 st->finished_correctly = true;
4341}
4342
4343static void
4344test_yin_parse_submodule(void **state)
4345{
4346 struct state *st = *state;
4347 const char *data;
4348 struct yin_parser_ctx *yin_ctx = NULL;
4349 struct lysp_submodule *submod = NULL;
David Sedlák1b623122019-08-05 15:27:49 +02004350 struct lys_parser_ctx main_ctx = {};
David Sedlák8985a142019-07-31 16:43:06 +02004351
4352 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4353 "<submodule name=\"asub\""
4354 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4355 "xmlns:a=\"urn:a\">"
4356 "<yang-version value=\"1.0\"/>\n"
4357 "<belongs-to module=\"a\">"
4358 "<prefix value=\"a_pref\"/>"
4359 "</belongs-to>"
4360 "<include module=\"atop\"/>"
4361 "<feature name=\"fox\"/>"
4362 "<notification name=\"bar-notif\">"
4363 "<if-feature name=\"bar\"/>"
4364 "</notification>"
4365 "<notification name=\"fox-notif\">"
4366 "<if-feature name=\"fox\"/>"
4367 "</notification>"
4368 "<augment target-node=\"/a_pref:top\">"
4369 "<if-feature name=\"bar\"/>"
4370 "<container name=\"bar-sub\"/>"
4371 "</augment>"
4372 "<augment target-node=\"/top\">"
4373 "<container name=\"bar-sub2\"/>"
4374 "</augment>"
4375 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004376 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004377 lysp_submodule_free(st->ctx, submod);
4378 yin_parser_ctx_free(yin_ctx);
4379 yin_ctx = NULL;
4380 submod = NULL;
4381
4382 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák6d781b62019-08-02 15:22:52 +02004383 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4384 "<yang-version value=\"1.0\"/>\n"
4385 "<belongs-to module=\"a\">"
4386 "<prefix value=\"a_pref\"/>"
4387 "</belongs-to>"
4388 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004389 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004390 lysp_submodule_free(st->ctx, submod);
4391 yin_parser_ctx_free(yin_ctx);
4392 yin_ctx = NULL;
4393 submod = NULL;
4394
4395 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák8985a142019-07-31 16:43:06 +02004396 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4397 "</module>";
David Sedlák1b623122019-08-05 15:27:49 +02004398 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004399 logbuf_assert("Input data contains module in situation when a submodule is expected.");
4400 lysp_submodule_free(st->ctx, submod);
4401 yin_parser_ctx_free(yin_ctx);
4402 yin_ctx = NULL;
4403 submod = NULL;
4404
David Sedlák6d781b62019-08-02 15:22:52 +02004405 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4406 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4407 "<yang-version value=\"1.0\"/>\n"
4408 "<belongs-to module=\"a\">"
4409 "<prefix value=\"a_pref\"/>"
4410 "</belongs-to>"
4411 "</submodule>"
4412 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4413 "<yang-version value=\"1.0\"/>\n"
4414 "<belongs-to module=\"a\">"
4415 "<prefix value=\"a_pref\"/>"
4416 "</belongs-to>"
4417 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004418 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004419 logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
4420 lysp_submodule_free(st->ctx, submod);
4421 yin_parser_ctx_free(yin_ctx);
4422 yin_ctx = NULL;
4423 submod = NULL;
4424
David Sedlák8985a142019-07-31 16:43:06 +02004425 st->finished_correctly = true;
4426}
4427
David Sedlák3b4db242018-10-19 16:11:01 +02004428int
4429main(void)
4430{
4431
4432 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02004433 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02004434 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
4435 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák071f7662019-09-12 02:02:51 +02004436 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02004437 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02004438
David Sedlák8e7bda82019-07-16 17:57:50 +02004439 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák43801c92019-08-05 15:58:54 +02004440 cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test),
4441 cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test),
David Sedlák32488102019-07-15 17:44:10 +02004442 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
4443 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
4444 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
4445 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
4446 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
4447 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
4448 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004449 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
4450 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
4451 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
4452 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
4453 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
4454 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
4455 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
4456 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
4457 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
4458 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
4459 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
4460 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
4461 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
4462 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
4463 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02004464 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
4465 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
4466 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
4467 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
4468 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
4469 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
4470 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
4471 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02004472 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02004473 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02004474 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02004475 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02004476 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02004477 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02004478 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02004479 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02004480 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02004481 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02004482 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02004483 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02004484 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02004485 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlák5e13dea2019-07-22 16:06:45 +02004486 cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
David Sedlák28794f22019-07-22 16:45:00 +02004487 cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02004488 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02004489 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02004490 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02004491 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02004492 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02004493 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02004494 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02004495 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02004496 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02004497 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02004498 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02004499 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák298ff6d2019-07-26 14:29:03 +02004500 cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test),
David Sedlák8985a142019-07-31 16:43:06 +02004501
4502 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger),
4503 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger),
David Sedlák3b4db242018-10-19 16:11:01 +02004504 };
4505
David Sedlák8e7bda82019-07-16 17:57:50 +02004506 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02004507}