blob: 4e9366b7a1cc5e0399408d5d5e6cd42e32c101c1 [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;
Michal Vaskob36053d2020-03-26 15:49:30 +010060 struct lys_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));
Michal Vaskob36053d2020-03-26 15:49:30 +0100150 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8f5bce02019-06-03 16:41:08 +0200151
David Sedlák68a1af12019-03-08 13:46:54 +0100152 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200153}
154
155static int
David Sedlák68a1af12019-03-08 13:46:54 +0100156teardown_f(void **state)
157{
158 struct state *st = *(struct state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200159 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100160
David Sedlák79e50cb2019-06-05 16:33:09 +0200161#if ENABLE_LOGGER_CHECKING
162 /* teardown logger */
163 if (!st->finished_correctly && logbuf[0] != '\0') {
164 fprintf(stderr, "%s\n", logbuf);
165 }
166#endif
167
David Sedlák619db942019-07-03 14:47:30 +0200168 temp = st->lysp_mod->mod;
169
Michal Vaskob36053d2020-03-26 15:49:30 +0100170 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100171 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200172 lysp_module_free(st->lysp_mod);
173 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200174 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100175
176 return EXIT_SUCCESS;
177}
178
David Sedlák392af4f2019-06-04 16:02:42 +0200179static struct state*
180reset_state(void **state)
181{
David Sedlák79e50cb2019-06-05 16:33:09 +0200182 ((struct state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200183 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200184 teardown_f(state);
185 setup_f(state);
186
187 return *state;
188}
189
David Sedlák79e50cb2019-06-05 16:33:09 +0200190void
191logbuf_clean(void)
192{
193 logbuf[0] = '\0';
194}
195
David Sedlák8985a142019-07-31 16:43:06 +0200196static int
197setup_logger(void **state)
198{
199 (void)state; /* unused */
200#if ENABLE_LOGGER_CHECKING
201 /* setup logger */
202 ly_set_log_clb(logger, 1);
203#endif
204
205 logbuf[0] = '\0';
206
207 return EXIT_SUCCESS;
208}
209
210static int
211teardown_logger(void **state)
212{
213 struct state *st = *state;
214
215#if ENABLE_LOGGER_CHECKING
216 /* teardown logger */
217 if (!st->finished_correctly && logbuf[0] != '\0') {
218 fprintf(stderr, "%s\n", logbuf);
219 }
220#endif
221
222 return EXIT_SUCCESS;
223}
224
225static int
226setup_element_test(void **state)
227{
228 setup_logger(state);
229 struct state *st = *state;
230
231 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100232 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8985a142019-07-31 16:43:06 +0200233
234 return EXIT_SUCCESS;
235}
236
237static int
238teardown_element_test(void **state)
239{
240 struct state *st = *(struct state **)state;
241
Michal Vaskob36053d2020-03-26 15:49:30 +0100242 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák8985a142019-07-31 16:43:06 +0200243 free(st->yin_ctx);
244
245 teardown_logger(state);
246
247 return EXIT_SUCCESS;
248}
249
David Sedlák68a1af12019-03-08 13:46:54 +0100250static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200251test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200252{
David Sedlák8f7a1172019-06-20 14:42:18 +0200253 struct state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200254
Michal Vaskob36053d2020-03-26 15:49:30 +0100255 const char *prefix;
256 size_t prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200257 /* create mock yin namespace in xml context */
258 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
Michal Vaskob36053d2020-03-26 15:49:30 +0100259 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
260 prefix = st->yin_ctx->xmlctx->prefix;
261 prefix_len = st->yin_ctx->xmlctx->prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200262
Radek Krejcid6b76452019-09-03 17:03:03 +0200263 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
264 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
265 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
266 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
267 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
268 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
269 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
270 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
283 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);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
318 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
319 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
320 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
321 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
322 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
323 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
324 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
325 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
326 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
327 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
328 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
329 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
330 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
331 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
332 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 +0200333
334 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200335}
David Sedlák3b4db242018-10-19 16:11:01 +0200336
David Sedlák872c7b42018-10-26 13:15:20 +0200337static void
David Sedlák060b00e2019-06-19 11:12:06 +0200338test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200339{
David Sedlák68a1af12019-03-08 13:46:54 +0100340 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200341
David Sedlák060b00e2019-06-19 11:12:06 +0200342 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
343 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
344 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
345 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
346 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
347 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
348 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
349 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
350 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
351 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
352 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
353 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200354}
355
David Sedlák68a1af12019-03-08 13:46:54 +0100356static void
David Sedlákb1a78352019-06-28 16:16:29 +0200357test_yin_parse_element_generic(void **state)
358{
David Sedlákb1a78352019-06-28 16:16:29 +0200359 struct state *st = *state;
360 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200361 LY_ERR ret;
362
363 memset(&exts, 0, sizeof(exts));
364
David Sedlákb0ca07d2019-09-11 11:54:05 +0200365 const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100366 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
367
368 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200369 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100370 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200371 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlákb1a78352019-06-28 16:16:29 +0200372 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200373 assert_string_equal(exts.child->child->stmt, "attr");
374 assert_string_equal(exts.child->child->arg, "value");
375 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200376 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200377 st = reset_state(state);
378
David Sedlákb0ca07d2019-09-11 11:54:05 +0200379 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100380 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
381
382 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200383 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100384 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200385 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlák5392a212019-07-01 09:19:10 +0200386 assert_null(exts.child->child);
387 assert_null(exts.child->arg);
388 lysp_ext_instance_free(st->ctx, &exts);
389
David Sedlákb1a78352019-06-28 16:16:29 +0200390 st->finished_correctly = true;
391}
392
393static void
394test_yin_parse_extension_instance(void **state)
395{
396 LY_ERR ret;
397 struct state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200398 struct lysp_ext_instance *exts = NULL;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200399 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100400 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
401
402 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200403 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200404 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákb1a78352019-06-28 16:16:29 +0200405 assert_int_equal(exts->insubstmt_index, 0);
406 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
407 assert_true(exts->yin & LYS_YIN);
408 assert_string_equal(exts->child->stmt, "value1");
409 assert_string_equal(exts->child->arg, "test");
410 assert_null(exts->child->child);
411 assert_true(exts->child->flags & LYS_YIN_ATTR);
412 assert_string_equal(exts->child->next->stmt, "value");
413 assert_string_equal(exts->child->next->arg, "test2");
414 assert_null(exts->child->next->child);
415 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
416
David Sedláke0ef1c62019-09-13 10:05:55 +0200417 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
David Sedlákb1a78352019-06-28 16:16:29 +0200418 assert_string_equal(exts->child->next->next->arg, "text");
419 assert_null(exts->child->next->next->child);
420 assert_null(exts->child->next->next->next);
421 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200422 lysp_ext_instance_free(st->ctx, exts);
423 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200424 exts = NULL;
David Sedlákf250ecf2019-07-01 11:02:05 +0200425 st = reset_state(state);
426
David Sedlákb0ca07d2019-09-11 11:54:05 +0200427 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Michal Vaskob36053d2020-03-26 15:49:30 +0100428 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
429
430 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200431 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200432 assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
David Sedlákf250ecf2019-07-01 11:02:05 +0200433 assert_null(exts->argument);
434 assert_null(exts->child);
435 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
436 assert_int_equal(exts->insubstmt_index, 0);
437 assert_true(exts->yin & LYS_YIN);
David Sedlákf250ecf2019-07-01 11:02:05 +0200438 lysp_ext_instance_free(st->ctx, exts);
439 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200440 exts = NULL;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200441 st = reset_state(state);
442
David Sedlákb0ca07d2019-09-11 11:54:05 +0200443 data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">"
444 "<myext:ext-sub1/>"
445 "<myext:ext-sub2 sattr1=\"stext2\">"
446 "<myext:ext-sub21>"
447 "<myext:ext-sub211 sattr21=\"text21\"/>"
448 "</myext:ext-sub21>"
449 "</myext:ext-sub2>"
450 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
451 "</myext:ext>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100452 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
453
454 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200455 assert_int_equal(ret, LY_SUCCESS);
456
David Sedláke0ef1c62019-09-13 10:05:55 +0200457 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200458 assert_null(exts->argument);
459 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
460 assert_int_equal(exts->insubstmt_index, 0);
461 assert_true(exts->yin & LYS_YIN);
462 assert_string_equal(exts->child->stmt, "attr1");
463 assert_string_equal(exts->child->arg, "text1");
464 assert_null(exts->child->child);
465 assert_true(exts->child->flags & LYS_YIN_ATTR);
466
467 assert_string_equal(exts->child->next->stmt, "attr2");
468 assert_string_equal(exts->child->next->arg, "text2");
469 assert_null(exts->child->next->child);
470 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
471
David Sedláke0ef1c62019-09-13 10:05:55 +0200472 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200473 assert_null(exts->child->next->next->arg);
474 assert_null(exts->child->next->next->child);
475 assert_int_equal(exts->child->next->next->flags, 0);
476
David Sedláke0ef1c62019-09-13 10:05:55 +0200477 assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200478 assert_null(exts->child->next->next->next->arg);
479 assert_int_equal(exts->child->next->next->next->flags, 0);
480 assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
481 assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
482 assert_null(exts->child->next->next->next->child->child);
483 assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
484
David Sedláke0ef1c62019-09-13 10:05:55 +0200485 assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200486 assert_null(exts->child->next->next->next->child->next->arg);
487 assert_null(exts->child->next->next->next->child->next->next);
488 assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
489
David Sedláke0ef1c62019-09-13 10:05:55 +0200490 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 +0200491 assert_null(exts->child->next->next->next->child->next->child->arg);
492 assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
493 assert_null(exts->child->next->next->next->child->next->child->next);
494
495 assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
496 assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
497 assert_null(exts->child->next->next->next->child->next->child->child->next);
498 assert_null(exts->child->next->next->next->child->next->child->child->child);
499 assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
500
David Sedláke0ef1c62019-09-13 10:05:55 +0200501 assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200502 assert_null(exts->child->next->next->next->next->arg);
503 assert_null(exts->child->next->next->next->next->next);
504 assert_int_equal(exts->child->next->next->next->next->flags, 0);
505
506 assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
507 assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
508 assert_null(exts->child->next->next->next->next->child->next);
509 assert_null(exts->child->next->next->next->next->child->child);
510 assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
511
David Sedlákadd0c2e2019-08-16 10:49:12 +0200512 lysp_ext_instance_free(st->ctx, exts);
513 LY_ARRAY_FREE(exts);
514 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200515 st = reset_state(state);
516
517 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">"
518 "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>"
519 "<yin:augment target-node=\"target\"/>"
520 "<yin:status value=\"value\"/>"
521 "<yin:include module=\"mod\"/>"
522 "<yin:input />"
523 "<yin:must condition=\"cond\"/>"
524 "<yin:namespace uri=\"uri\"/>"
525 "<yin:revision date=\"data\"/>"
526 "<yin:unique tag=\"tag\"/>"
David Sedlákd2844882019-09-13 16:01:22 +0200527 "<yin:description><yin:text>contact-val</yin:text></yin:description>"
528 "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200529 "</myext:extension-elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100530 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
531
532 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200533 assert_int_equal(ret, LY_SUCCESS);
534 assert_string_equal(exts->child->arg, "act-name");
535 assert_string_equal(exts->child->next->arg, "target");
536 assert_string_equal(exts->child->next->next->arg, "value");
537 assert_string_equal(exts->child->next->next->next->arg, "mod");
538 assert_null(exts->child->next->next->next->next->arg);
539 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
540 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
541 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
542 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
543 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
David Sedlákaa98bba2019-09-12 11:52:14 +0200544 lysp_ext_instance_free(st->ctx, exts);
545 LY_ARRAY_FREE(exts);
546 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200547 st = reset_state(state);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200548
David Sedlákb1a78352019-06-28 16:16:29 +0200549 st->finished_correctly = true;
550}
551
David Sedlák555c7202019-07-04 12:14:12 +0200552static void
553test_yin_parse_content(void **state)
554{
555 struct state *st = *state;
556 LY_ERR ret = LY_SUCCESS;
David Sedlák555c7202019-07-04 12:14:12 +0200557 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200558 "<myext:custom xmlns:myext=\"urn:example:extensions\">"
David Sedlák555c7202019-07-04 12:14:12 +0200559 "totally amazing extension"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200560 "</myext:custom>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200561 "<extension name=\"ext\">"
David Sedlák986cb412019-07-04 13:10:11 +0200562 "<argument name=\"argname\"></argument>"
563 "<description><text>desc</text></description>"
564 "<reference><text>ref</text></reference>"
565 "<status value=\"deprecated\"></status>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200566 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200567 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200568 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200569 "<when condition=\"condition...\">"
570 "<reference><text>when_ref</text></reference>"
571 "<description><text>when_desc</text></description>"
572 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200573 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200574 "<error-message>"
575 "<value>error-msg</value>"
576 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200577 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200578 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200579 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200580 "<position value=\"25\"></position>"
581 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200582 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200583 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200584 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200585 "<pattern value='pattern'>"
586 "<modifier value='invert-match'/>"
587 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200588 "<enum name=\"yay\">"
589 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200590 "</prefix>";
591 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200592 const char **if_features = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200593 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200594 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200595 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200596 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200597 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200598 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200599
Michal Vaskob36053d2020-03-26 15:49:30 +0100600 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
601 lyxml_ctx_next(st->yin_ctx->xmlctx);
602 lyxml_ctx_next(st->yin_ctx->xmlctx);
603 lyxml_ctx_next(st->yin_ctx->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200604
David Sedlákfd5b9c32019-07-12 15:33:13 +0200605 struct yin_subelement subelems[17] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200606 {LY_STMT_CONFIG, &config, 0},
607 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
608 {LY_STMT_ENUM, &enum_type, 0},
609 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
610 {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
611 {LY_STMT_EXTENSION, &ext_def, 0},
612 {LY_STMT_IF_FEATURE, &if_features, 0},
613 {LY_STMT_LENGTH, &len_type, 0},
614 {LY_STMT_PATTERN, &patter_type, 0},
615 {LY_STMT_POSITION, &pos_enum, 0},
616 {LY_STMT_RANGE, &range_type, 0},
617 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
618 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
619 {LY_STMT_VALUE, &val_enum, 0},
620 {LY_STMT_WHEN, &when_p, 0},
621 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
622 {LY_STMT_ARG_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200623 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100624 ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200625 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200626 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200627 assert_string_equal(def, "default-value");
David Sedláke0ef1c62019-09-13 10:05:55 +0200628 assert_string_equal(exts->name, "urn:example:extensions:custom");
David Sedlák555c7202019-07-04 12:14:12 +0200629 assert_string_equal(exts->argument, "totally amazing extension");
630 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200631 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200632 assert_string_equal(when_p->cond, "condition...");
633 assert_string_equal(when_p->dsc, "when_desc");
634 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200635 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200636 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200637 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200638 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200639 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200640 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200641 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200642 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200643 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200644 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200645 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200646 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200647 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200648 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200649 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200650 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200651 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200652 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200653 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200654 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200655 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200656 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200657 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200658 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200659 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200660 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200661 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200662 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200663 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200664 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200665 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200666 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200667 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200668 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200669 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200670 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200671 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200672 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200673 st = reset_state(state);
674
675 /* test unique subelem */
676 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200677 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
678 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
David Sedláke6cd89e2019-08-07 12:46:02 +0200679 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200680 "<prefix value=\"inv_mod\" />"
681 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
682 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200683 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100684 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
685 lyxml_ctx_next(st->yin_ctx->xmlctx);
686
687 ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200688 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200689 logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200690 lydict_remove(st->ctx, prefix_value);
691 lydict_remove(st->ctx, value);
692 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200693
694 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200695 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200696 "<prefix value=\"inv_mod\" />"
697 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
698 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200699 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200700 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
701 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
Michal Vaskob36053d2020-03-26 15:49:30 +0100702 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
703 lyxml_ctx_next(st->yin_ctx->xmlctx);
704
705 ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200706 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200707 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 +0200708 lydict_remove(st->ctx, prefix_value);
709 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200710
711 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200712 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200713 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Michal Vaskob36053d2020-03-26 15:49:30 +0100714 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
715 lyxml_ctx_next(st->yin_ctx->xmlctx);
716
717 ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200718 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200719 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200720
721 st->finished_correctly = true;
722}
723
David Sedlák92147b02019-07-09 14:01:01 +0200724static void
David Sedlák4a650532019-07-10 11:55:18 +0200725test_validate_value(void **state)
726{
727 struct state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +0100728 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
729
730 /* create some XML context */
731 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
732 st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
733 st->yin_ctx->xmlctx->dynamic = 0;
734
735 st->yin_ctx->xmlctx->value = "#invalid";
736 st->yin_ctx->xmlctx->value_len = 8;
737 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200738 logbuf_assert("Invalid identifier character '#'. Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100739
740 st->yin_ctx->xmlctx->value = "";
741 st->yin_ctx->xmlctx->value_len = 0;
742 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS);
743
744 st->yin_ctx->xmlctx->value = "pre:b";
745 st->yin_ctx->xmlctx->value_len = 5;
746 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
747 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
748
749 st->yin_ctx->xmlctx->value = "pre:pre:b";
750 st->yin_ctx->xmlctx->value_len = 9;
751 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200752
753 st->finished_correctly = true;
754}
755
David Sedlák32488102019-07-15 17:44:10 +0200756/* helper function to simplify unit test of each element using parse_content function */
757LY_ERR
Michal Vaskob36053d2020-03-26 15:49:30 +0100758test_element_helper(struct state *st, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
David Sedlák32488102019-07-15 17:44:10 +0200759{
David Sedlákc5b20842019-08-13 10:18:31 +0200760 const char *name, *prefix;
761 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200762 LY_ERR ret = LY_SUCCESS;
763 struct yin_subelement subelems[71] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200764 {LY_STMT_ACTION, dest, 0},
765 {LY_STMT_ANYDATA, dest, 0},
766 {LY_STMT_ANYXML, dest, 0},
767 {LY_STMT_ARGUMENT,dest, 0},
768 {LY_STMT_AUGMENT, dest, 0},
769 {LY_STMT_BASE, dest, 0},
770 {LY_STMT_BELONGS_TO, dest, 0},
771 {LY_STMT_BIT, dest, 0},
772 {LY_STMT_CASE, dest, 0},
773 {LY_STMT_CHOICE, dest, 0},
774 {LY_STMT_CONFIG, dest, 0},
775 {LY_STMT_CONTACT, dest, 0},
776 {LY_STMT_CONTAINER, dest, 0},
777 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
778 {LY_STMT_DESCRIPTION, dest, 0},
779 {LY_STMT_DEVIATE, dest, 0},
780 {LY_STMT_DEVIATION, dest, 0},
781 {LY_STMT_ENUM, dest, 0},
782 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
783 {LY_STMT_ERROR_MESSAGE, dest, 0},
784 {LY_STMT_EXTENSION, dest, 0},
785 {LY_STMT_FEATURE, dest, 0},
786 {LY_STMT_FRACTION_DIGITS, dest, 0},
787 {LY_STMT_GROUPING, dest, 0},
788 {LY_STMT_IDENTITY, dest, 0},
789 {LY_STMT_IF_FEATURE, dest, 0},
790 {LY_STMT_IMPORT, dest, 0},
791 {LY_STMT_INCLUDE, dest, 0},
792 {LY_STMT_INPUT, dest, 0},
793 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
794 {LY_STMT_LEAF, dest, 0},
795 {LY_STMT_LEAF_LIST, dest, 0},
796 {LY_STMT_LENGTH, dest, 0},
797 {LY_STMT_LIST, dest, 0},
798 {LY_STMT_MANDATORY, dest, 0},
799 {LY_STMT_MAX_ELEMENTS, dest, 0},
800 {LY_STMT_MIN_ELEMENTS, dest, 0},
801 {LY_STMT_MODIFIER, dest, 0},
802 {LY_STMT_MODULE, dest, 0},
803 {LY_STMT_MUST, dest, 0},
804 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
805 {LY_STMT_NOTIFICATION, dest, 0},
806 {LY_STMT_ORDERED_BY, dest, 0},
807 {LY_STMT_ORGANIZATION, dest, 0},
808 {LY_STMT_OUTPUT, dest, 0},
809 {LY_STMT_PATH, dest, 0},
810 {LY_STMT_PATTERN, dest, 0},
811 {LY_STMT_POSITION, dest, 0},
812 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
813 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
814 {LY_STMT_RANGE, dest, 0},
815 {LY_STMT_REFERENCE, dest, 0},
816 {LY_STMT_REFINE, dest, 0},
817 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
818 {LY_STMT_REVISION, dest, 0},
819 {LY_STMT_REVISION_DATE, dest, 0},
820 {LY_STMT_RPC, dest, 0},
821 {LY_STMT_STATUS, dest, 0},
822 {LY_STMT_SUBMODULE, dest, 0},
823 {LY_STMT_TYPE, dest, 0},
824 {LY_STMT_TYPEDEF, dest, 0},
825 {LY_STMT_UNIQUE, dest, 0},
826 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
827 {LY_STMT_USES, dest, 0},
828 {LY_STMT_VALUE, dest, 0},
829 {LY_STMT_WHEN, dest, 0},
830 {LY_STMT_YANG_VERSION, dest, 0},
831 {LY_STMT_YIN_ELEMENT, dest, 0},
832 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
833 {LY_STMT_ARG_TEXT, dest, 0},
834 {LY_STMT_ARG_VALUE, dest, 0}
David Sedlák32488102019-07-15 17:44:10 +0200835 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100836 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
837 prefix = st->yin_ctx->xmlctx->prefix;
838 prefix_len = st->yin_ctx->xmlctx->prefix_len;
839 name = st->yin_ctx->xmlctx->name;
840 name_len = st->yin_ctx->xmlctx->name_len;
841 lyxml_ctx_next(st->yin_ctx->xmlctx);
842
843 ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
844
845 /* free parser */
846 lyxml_ctx_free(st->yin_ctx->xmlctx);
847 st->yin_ctx->xmlctx = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200848 return ret;
849}
850
David Sedlákd1144562019-08-06 12:36:14 +0200851#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
852
David Sedlák32488102019-07-15 17:44:10 +0200853static void
David Sedlák43801c92019-08-05 15:58:54 +0200854test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200855{
David Sedlák32488102019-07-15 17:44:10 +0200856 struct state *st = *state;
857 struct lysp_type type = {};
858 const char *data;
859 data = ELEMENT_WRAPPER_START
860 "<enum name=\"enum-name\">"
861 "<if-feature name=\"feature\" />"
862 "<value value=\"55\" />"
863 "<status value=\"deprecated\" />"
864 "<description><text>desc...</text></description>"
865 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200866 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +0200867 "</enum>"
868 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100869 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200870 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200871 assert_string_equal(*type.enums->iffeatures, "feature");
872 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200873 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200874 assert_string_equal(type.enums->dsc, "desc...");
875 assert_string_equal(type.enums->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200876 assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200877 assert_int_equal(type.enums->exts->insubstmt_index, 0);
878 assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
879 lysp_type_free(st->ctx, &type);
880 memset(&type, 0, sizeof type);
881
882 data = ELEMENT_WRAPPER_START
883 "<enum name=\"enum-name\"></enum>"
884 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100885 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200886 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200887 lysp_type_free(st->ctx, &type);
888 memset(&type, 0, sizeof type);
889
David Sedlák43801c92019-08-05 15:58:54 +0200890 st->finished_correctly = true;
891}
892
893static void
894test_bit_elem(void **state)
895{
896 struct state *st = *state;
897 struct lysp_type type = {};
898 const char *data;
899 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200900 "<bit name=\"bit-name\">"
David Sedlák43801c92019-08-05 15:58:54 +0200901 "<if-feature name=\"feature\" />"
902 "<position value=\"55\" />"
903 "<status value=\"deprecated\" />"
904 "<description><text>desc...</text></description>"
905 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200906 EXT_SUBELEM
David Sedlák43801c92019-08-05 15:58:54 +0200907 "</bit>"
908 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100909 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200910 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200911 assert_string_equal(*type.bits->iffeatures, "feature");
912 assert_int_equal(type.bits->value, 55);
913 assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
914 assert_string_equal(type.bits->dsc, "desc...");
915 assert_string_equal(type.bits->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200916 assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200917 assert_int_equal(type.bits->exts->insubstmt_index, 0);
918 assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
919 lysp_type_free(st->ctx, &type);
920 memset(&type, 0, sizeof type);
921
922 data = ELEMENT_WRAPPER_START
923 "<bit name=\"bit-name\"> </bit>"
924 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100925 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200926 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200927 lysp_type_free(st->ctx, &type);
928 memset(&type, 0, sizeof type);
929
David Sedlák32488102019-07-15 17:44:10 +0200930 st->finished_correctly = true;
931}
932
933static void
934test_meta_elem(void **state)
935{
936 struct state *st = *state;
937 char *value = NULL;
938 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200939 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200940
941 /* organization element */
942 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200943 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
David Sedlák32488102019-07-15 17:44:10 +0200944 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100945 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200946 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200947 assert_int_equal(exts[0].insubstmt_index, 0);
948 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedláke0ef1c62019-09-13 10:05:55 +0200949 assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200950 assert_int_equal(exts[1].insubstmt_index, 0);
951 assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedlák32488102019-07-15 17:44:10 +0200952 assert_string_equal(value, "organization...");
953 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200954 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200955 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200956 exts = NULL;
957
David Sedlák32488102019-07-15 17:44:10 +0200958 /* contact element */
959 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200960 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
David Sedlák32488102019-07-15 17:44:10 +0200961 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100962 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200963 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200964 assert_int_equal(exts[0].insubstmt_index, 0);
965 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200966 assert_string_equal(value, "contact...");
967 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200968 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
969 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200970 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200971
David Sedlák32488102019-07-15 17:44:10 +0200972 /* description element */
973 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200974 "<description><text>description...</text>" EXT_SUBELEM "</description>"
David Sedlák32488102019-07-15 17:44:10 +0200975 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100976 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200977 assert_string_equal(value, "description...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200978 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200979 assert_int_equal(exts[0].insubstmt_index, 0);
980 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200981 FREE_STRING(st->ctx, value);
982 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200983 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
984 exts = NULL;
985
David Sedlák32488102019-07-15 17:44:10 +0200986 /* reference element */
987 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200988 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
David Sedlák32488102019-07-15 17:44:10 +0200989 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100990 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200991 assert_string_equal(value, "reference...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200992 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200993 assert_int_equal(exts[0].insubstmt_index, 0);
994 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
David Sedlák32488102019-07-15 17:44:10 +0200995 FREE_STRING(st->ctx, value);
996 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200997 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
998 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200999
David Sedlákdf2a9732019-08-07 13:23:16 +02001000 /* reference element */
1001 data = ELEMENT_WRAPPER_START
1002 "<reference invalid=\"text\"><text>reference...</text>""</reference>"
1003 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001004 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001005 logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001006 FREE_STRING(st->ctx, value);
1007 value = NULL;
1008 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1009 exts = NULL;
1010
David Sedlák32488102019-07-15 17:44:10 +02001011 /* missing text subelement */
1012 data = ELEMENT_WRAPPER_START
1013 "<reference>reference...</reference>"
1014 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001015 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001016 logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001017
David Sedlákd1144562019-08-06 12:36:14 +02001018 /* reference element */
1019 data = ELEMENT_WRAPPER_START
1020 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
1021 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001022 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001023 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 +02001024 FREE_STRING(st->ctx, value);
1025 value = NULL;
1026 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1027 exts = NULL;
1028
David Sedlák32488102019-07-15 17:44:10 +02001029 st->finished_correctly = true;
1030}
1031
1032static void
1033test_import_elem(void **state)
1034{
1035 struct state *st = *state;
1036 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02001037 struct lysp_import *imports = NULL;
1038 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +02001039
1040 /* max subelems */
1041 data = ELEMENT_WRAPPER_START
1042 "<import module=\"a\">"
David Sedlákd1144562019-08-06 12:36:14 +02001043 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001044 "<prefix value=\"a_mod\"/>"
1045 "<revision-date date=\"2015-01-01\"></revision-date>"
1046 "<description><text>import description</text></description>"
1047 "<reference><text>import reference</text></reference>"
1048 "</import>"
1049 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001050 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001051 assert_string_equal(imports->name, "a");
1052 assert_string_equal(imports->prefix, "a_mod");
1053 assert_string_equal(imports->rev, "2015-01-01");
1054 assert_string_equal(imports->dsc, "import description");
1055 assert_string_equal(imports->ref, "import reference");
David Sedláke0ef1c62019-09-13 10:05:55 +02001056 assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001057 assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
1058 assert_int_equal(imports->exts->insubstmt_index, 0);
David Sedlák298ff6d2019-07-26 14:29:03 +02001059 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1060 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001061
1062 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +02001063 data = ELEMENT_WRAPPER_START
1064 "<import module=\"a\">"
1065 "<prefix value=\"a_mod\"/>"
1066 "</import>"
1067 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001068 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001069 assert_string_equal(imports->prefix, "a_mod");
1070 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1071 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001072
1073 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +02001074 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001075 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001076 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
David Sedlák298ff6d2019-07-26 14:29:03 +02001077 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1078 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001079
1080 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +02001081 data = ELEMENT_WRAPPER_START
1082 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001083 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001084 "</import>"
1085 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001086 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001087 "</import>"
1088 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001089 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák298ff6d2019-07-26 14:29:03 +02001090 logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1.");
1091 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1092 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001093
1094 st->finished_correctly = true;
1095}
1096
1097static void
1098test_status_elem(void **state)
1099{
1100 struct state *st = *state;
1101 const char *data;
1102 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001103 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001104
1105 /* test valid values */
1106 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001107 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001108 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001109
1110 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001111 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001112 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001113
David Sedlákd1144562019-08-06 12:36:14 +02001114 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001115 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001116 assert_true(flags & LYS_STATUS_OBSLT);
David Sedláke0ef1c62019-09-13 10:05:55 +02001117 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001118 assert_int_equal(exts[0].insubstmt_index, 0);
1119 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
1120 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1121 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001122
1123 /* test invalid value */
1124 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001125 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001126 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 +02001127 st->finished_correctly = true;
1128}
1129
1130static void
1131test_ext_elem(void **state)
1132{
1133 struct state *st = *state;
1134 const char *data;
1135 struct lysp_ext *ext = NULL;
1136
1137 /* max subelems */
1138 data = ELEMENT_WRAPPER_START
1139 "<extension name=\"ext_name\">"
1140 "<argument name=\"arg\"></argument>"
1141 "<status value=\"current\"/>"
1142 "<description><text>ext_desc</text></description>"
1143 "<reference><text>ext_ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001144 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001145 "</extension>"
1146 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001147 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001148 assert_string_equal(ext->name, "ext_name");
1149 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001150 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001151 assert_string_equal(ext->dsc, "ext_desc");
1152 assert_string_equal(ext->ref, "ext_ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001153 assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001154 assert_int_equal(ext->exts[0].insubstmt_index, 0);
1155 assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák32488102019-07-15 17:44:10 +02001156 lysp_ext_free(st->ctx, ext);
1157 LY_ARRAY_FREE(ext);
1158 ext = NULL;
1159
1160 /* min subelems */
1161 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001162 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001163 assert_string_equal(ext->name, "ext_name");
1164 lysp_ext_free(st->ctx, ext);
1165 LY_ARRAY_FREE(ext);
1166 ext = NULL;
1167
1168 st->finished_correctly = true;
1169}
1170
1171static void
1172test_yin_element_elem(void **state)
1173{
1174 struct state *st = *state;
1175 const char *data;
1176 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001177 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001178
1179 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001180 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001181 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001182
David Sedlákd1144562019-08-06 12:36:14 +02001183 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001184 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001185 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001186 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001187 assert_int_equal(exts[0].insubstmt_index, 0);
1188 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
1189 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001190
1191 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001192 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001193 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák26ea1432019-08-14 13:42:23 +02001194 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 +02001195 st->finished_correctly = true;
1196}
1197
1198static void
1199test_yangversion_elem(void **state)
1200{
1201 struct state *st = *state;
1202 const char *data;
1203 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001204 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001205
1206 /* valid values */
1207 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001208 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001209 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001210 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1211
David Sedlákd1144562019-08-06 12:36:14 +02001212 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001213 assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001214 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001215 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
David Sedláke0ef1c62019-09-13 10:05:55 +02001216 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001217 assert_int_equal(exts[0].insubstmt_index, 0);
1218 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
1219 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001220
1221 /* invalid value */
1222 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001223 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001224 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 +02001225
1226 st->finished_correctly = true;
1227}
1228
1229static void
1230test_mandatory_elem(void **state)
1231{
1232 struct state *st = *state;
1233 const char *data;
1234 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001235 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001236
1237 /* valid values */
1238 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001239 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001240 assert_int_equal(man, LYS_MAND_TRUE);
1241 man = 0;
1242
David Sedlákd1144562019-08-06 12:36:14 +02001243 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001244 assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001245 assert_int_equal(man, LYS_MAND_FALSE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001246 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001247 assert_int_equal(exts[0].insubstmt_index, 0);
1248 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
1249 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001250
1251 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001252 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001253 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 +02001254
1255 st->finished_correctly = true;
1256}
1257
David Sedlák8e7bda82019-07-16 17:57:50 +02001258static void
1259test_argument_elem(void **state)
1260{
1261 struct state *st = *state;
1262 const char *data;
1263 uint16_t flags = 0;
1264 const char *arg;
1265 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001266 struct lysp_ext_instance *exts = NULL;
1267
David Sedlák8e7bda82019-07-16 17:57:50 +02001268 /* max subelems */
1269 data = ELEMENT_WRAPPER_START
1270 "<argument name=\"arg-name\">"
1271 "<yin-element value=\"true\" />"
David Sedlákd1144562019-08-06 12:36:14 +02001272 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001273 "</argument>"
1274 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001275 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001276 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001277 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001278 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001279 assert_int_equal(exts[0].insubstmt_index, 0);
1280 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
1281 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1282 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001283 flags = 0;
1284 FREE_STRING(st->ctx, arg);
1285 arg = NULL;
1286
1287 /* min subelems */
1288 data = ELEMENT_WRAPPER_START
1289 "<argument name=\"arg\">"
1290 "</argument>"
1291 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001292 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001293 assert_string_equal(arg, "arg");
1294 assert_true(flags == 0);
1295 FREE_STRING(st->ctx, arg);
1296
1297 st->finished_correctly = true;
1298}
1299
1300static void
1301test_base_elem(void **state)
1302{
1303 struct state *st = *state;
1304 const char *data;
1305 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001306 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001307 struct lysp_type type = {};
1308
1309 /* as identity subelement */
1310 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001311 "<base name=\"base-name\">"
1312 EXT_SUBELEM
1313 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001314 "</identity>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001315 assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001316 assert_string_equal(*bases, "base-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001317 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001318 assert_int_equal(exts[0].insubstmt_index, 0);
1319 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1320 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1321 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001322 FREE_STRING(st->ctx, *bases);
1323 LY_ARRAY_FREE(bases);
1324
1325 /* as type subelement */
1326 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001327 "<base name=\"base-name\">"
1328 EXT_SUBELEM
1329 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001330 "</type>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001331 assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001332 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001333 assert_true(type.flags & LYS_SET_BASE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001334 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001335 assert_int_equal(exts[0].insubstmt_index, 0);
1336 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1337 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1338 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001339 FREE_STRING(st->ctx, *type.bases);
1340 LY_ARRAY_FREE(type.bases);
1341
1342 st->finished_correctly = true;
1343}
1344
1345static void
1346test_belongsto_elem(void **state)
1347{
1348 struct state *st = *state;
1349 const char *data;
1350 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001351 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001352
1353 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001354 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001355 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001356 assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001357 assert_string_equal(submod.belongsto, "module-name");
1358 assert_string_equal(submod.prefix, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001359 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001360 assert_int_equal(exts[0].insubstmt_index, 0);
1361 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
1362 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1363 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001364 FREE_STRING(st->ctx, submod.belongsto);
1365 FREE_STRING(st->ctx, submod.prefix);
1366
1367 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001368 assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001369 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001370 FREE_STRING(st->ctx, submod.belongsto);
1371
1372 st->finished_correctly = true;
1373}
1374
1375static void
1376test_config_elem(void **state)
1377{
1378 struct state *st = *state;
1379 const char *data;
1380 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001381 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001382
David Sedlákd1144562019-08-06 12:36:14 +02001383 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001384 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001385 assert_true(flags & LYS_CONFIG_W);
David Sedláke0ef1c62019-09-13 10:05:55 +02001386 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001387 assert_int_equal(exts[0].insubstmt_index, 0);
1388 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
1389 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1390 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001391 flags = 0;
1392
1393 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001394 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001395 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001396 flags = 0;
1397
1398 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001399 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001400 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 +02001401
1402 st->finished_correctly = true;
1403}
1404
1405static void
1406test_default_elem(void **state)
1407{
1408 struct state *st = *state;
1409 const char *data;
1410 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001411 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001412
David Sedlákd1144562019-08-06 12:36:14 +02001413 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001414 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001415 assert_string_equal(val, "defaul-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02001416 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001417 assert_int_equal(exts[0].insubstmt_index, 0);
1418 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
1419 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1420 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001421 FREE_STRING(st->ctx, val);
1422 val = NULL;
1423
1424 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001425 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001426 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1427
1428 st->finished_correctly = true;
1429}
1430
1431static void
1432test_err_app_tag_elem(void **state)
1433{
1434 struct state *st = *state;
1435 const char *data;
1436 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001437 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001438
David Sedlákd1144562019-08-06 12:36:14 +02001439 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001440 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001441 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001442 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001443 assert_int_equal(exts[0].insubstmt_index, 0);
1444 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
1445 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1446 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001447 FREE_STRING(st->ctx, val);
1448 val = NULL;
1449
1450 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001451 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001452 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1453
1454 st->finished_correctly = true;
1455}
1456
1457static void
1458test_err_msg_elem(void **state)
1459{
1460 struct state *st = *state;
1461 const char *data;
1462 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001463 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001464
David Sedlákd1144562019-08-06 12:36:14 +02001465 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001466 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001467 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001468 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001469 assert_int_equal(exts[0].insubstmt_index, 0);
1470 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
1471 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1472 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001473 FREE_STRING(st->ctx, val);
1474
1475 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001476 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001477 logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001478
David Sedlákdf2a9732019-08-07 13:23:16 +02001479 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001480 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001481 logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001482
David Sedlák8e7bda82019-07-16 17:57:50 +02001483 st->finished_correctly = true;
1484}
1485
1486static void
1487test_fracdigits_elem(void **state)
1488{
1489 struct state *st = *state;
1490 const char *data;
1491 struct lysp_type type = {};
1492
1493 /* valid value */
David Sedlákd1144562019-08-06 12:36:14 +02001494 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001495 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +02001496 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001497 assert_int_equal(type.exts[0].insubstmt_index, 0);
1498 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001499 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001500 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlákd1144562019-08-06 12:36:14 +02001501 FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001502
1503 /* invalid values */
1504 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001505 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001506 logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001507
1508 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001509 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001510 logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001511
1512 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001513 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001514 logbuf_assert("Invalid value \"1p\" 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=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001517 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001518 logbuf_assert("Invalid value \"19\" 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=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001521 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001522 logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001523
1524 st->finished_correctly = true;
1525}
1526
1527static void
1528test_iffeature_elem(void **state)
1529{
1530 struct state *st = *state;
1531 const char *data;
1532 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001533 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001534
David Sedlákd1144562019-08-06 12:36:14 +02001535 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001536 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001537 assert_string_equal(*iffeatures, "local-storage");
David Sedláke0ef1c62019-09-13 10:05:55 +02001538 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001539 assert_int_equal(exts[0].insubstmt_index, 0);
1540 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
1541 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1542 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001543 FREE_STRING(st->ctx, *iffeatures);
1544 LY_ARRAY_FREE(iffeatures);
1545 iffeatures = NULL;
1546
1547 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001548 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001549 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1550 LY_ARRAY_FREE(iffeatures);
1551 iffeatures = NULL;
1552
1553 st->finished_correctly = true;
1554}
1555
1556static void
1557test_length_elem(void **state)
1558{
1559 struct state *st = *state;
1560 const char *data;
1561 struct lysp_type type = {};
1562
1563 /* max subelems */
1564 data = ELEMENT_WRAPPER_START
1565 "<length value=\"length-str\">"
1566 "<error-message><value>err-msg</value></error-message>"
1567 "<error-app-tag value=\"err-app-tag\"/>"
1568 "<description><text>desc</text></description>"
1569 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001570 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001571 "</length>"
1572 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001573 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001574 assert_string_equal(type.length->arg, "length-str");
1575 assert_string_equal(type.length->emsg, "err-msg");
1576 assert_string_equal(type.length->eapptag, "err-app-tag");
1577 assert_string_equal(type.length->dsc, "desc");
1578 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001579 assert_true(type.flags & LYS_SET_LENGTH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001580 assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001581 assert_int_equal(type.length->exts[0].insubstmt_index, 0);
1582 assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001583 lysp_type_free(st->ctx, &type);
1584 memset(&type, 0, sizeof(type));
1585
1586 /* min subelems */
1587 data = ELEMENT_WRAPPER_START
1588 "<length value=\"length-str\">"
1589 "</length>"
1590 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001591 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001592 assert_string_equal(type.length->arg, "length-str");
1593 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001594 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001595 memset(&type, 0, sizeof(type));
1596
1597 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001598 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001599 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1600 lysp_type_free(st->ctx, &type);
1601 memset(&type, 0, sizeof(type));
1602
1603 st->finished_correctly = true;
1604}
1605
1606static void
1607test_modifier_elem(void **state)
1608{
1609 struct state *st = *state;
1610 const char *data;
1611 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
David Sedlákd1144562019-08-06 12:36:14 +02001612 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001613
David Sedlákd1144562019-08-06 12:36:14 +02001614 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001615 assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001616 assert_string_equal(pat, "\x015pattern");
David Sedláke0ef1c62019-09-13 10:05:55 +02001617 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001618 assert_int_equal(exts[0].insubstmt_index, 0);
1619 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
1620 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1621 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001622 FREE_STRING(st->ctx, pat);
1623
1624 pat = lydict_insert(st->ctx, "\006pattern", 8);
1625 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001626 assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001627 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 +02001628 FREE_STRING(st->ctx, pat);
1629
1630 st->finished_correctly = true;
1631}
1632
1633static void
1634test_namespace_elem(void **state)
1635{
1636 struct state *st = *state;
1637 const char *data;
1638 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001639 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001640
David Sedlákd1144562019-08-06 12:36:14 +02001641 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001642 assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001643 assert_string_equal(ns, "ns");
David Sedláke0ef1c62019-09-13 10:05:55 +02001644 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001645 assert_int_equal(exts[0].insubstmt_index, 0);
1646 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
1647 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1648 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001649 FREE_STRING(st->ctx, ns);
1650
1651 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001652 assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001653 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1654
1655 st->finished_correctly = true;
1656}
1657
1658static void
1659test_path_elem(void **state)
1660{
1661 struct state *st = *state;
1662 const char *data;
1663 struct lysp_type type = {};
1664
David Sedlák169cc522019-08-15 13:23:45 +02001665 data = ELEMENT_WRAPPER_START "<path value=\"p&amp;th-val\">" EXT_SUBELEM "</path>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001666 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák169cc522019-08-15 13:23:45 +02001667 assert_string_equal("p&th-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001668 assert_true(type.flags & LYS_SET_PATH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001669 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001670 assert_int_equal(type.exts[0].insubstmt_index, 0);
1671 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001672 lysp_type_free(st->ctx, &type);
1673
1674 st->finished_correctly = true;
1675}
1676
1677static void
1678test_pattern_elem(void **state)
1679{
1680 struct state *st = *state;
1681 const char *data;
1682 struct lysp_type type = {};
1683
1684 /* max subelems */
1685 data = ELEMENT_WRAPPER_START
1686 "<pattern value=\"super_pattern\">"
1687 "<modifier value=\"invert-match\"/>"
1688 "<error-message><value>err-msg-value</value></error-message>"
1689 "<error-app-tag value=\"err-app-tag-value\"/>"
David Sedlák169cc522019-08-15 13:23:45 +02001690 "<description><text>&quot;pattern-desc&quot;</text></description>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001691 "<reference><text>pattern-ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001692 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001693 "</pattern>"
1694 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001695 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001696 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001697 assert_string_equal(type.patterns->arg, "\x015super_pattern");
David Sedlák169cc522019-08-15 13:23:45 +02001698 assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
David Sedlák8e7bda82019-07-16 17:57:50 +02001699 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1700 assert_string_equal(type.patterns->emsg, "err-msg-value");
David Sedlák8e7bda82019-07-16 17:57:50 +02001701 assert_string_equal(type.patterns->ref, "pattern-ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001702 assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001703 assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
1704 assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001705 lysp_type_free(st->ctx, &type);
1706 memset(&type, 0, sizeof(type));
1707
1708 /* min subelems */
1709 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001710 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001711 assert_string_equal(type.patterns->arg, "\x006pattern");
1712 lysp_type_free(st->ctx, &type);
1713 memset(&type, 0, sizeof(type));
1714
1715 st->finished_correctly = true;
1716}
1717
1718static void
1719test_value_position_elem(void **state)
1720{
1721 struct state *st = *state;
1722 const char *data;
1723 struct lysp_type_enum en = {};
1724
1725 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001726 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001727 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001728 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001729 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001730 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001731 assert_int_equal(en.exts[0].insubstmt_index, 0);
1732 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
1733 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001734 memset(&en, 0, sizeof(en));
1735
1736 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001737 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001738 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001739 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001740 memset(&en, 0, sizeof(en));
1741
1742 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001743 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001744 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001745 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001746 memset(&en, 0, sizeof(en));
1747
1748 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001749 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001750 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001751 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001752 memset(&en, 0, sizeof(en));
1753
1754 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001755 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001756 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001757 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001758 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001759 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlák8d552d62019-08-06 15:29:05 +02001760 assert_int_equal(en.exts[0].insubstmt_index, 0);
1761 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
1762 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001763 memset(&en, 0, sizeof(en));
1764
1765 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001766 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001767 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001768 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001769 memset(&en, 0, sizeof(en));
1770
1771 /* invalid values */
1772 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001773 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001774 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001775
1776 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001777 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001778 logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001779
David Sedlák69f01612019-07-17 11:41:08 +02001780 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001781 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001782 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001783
David Sedlák8e7bda82019-07-16 17:57:50 +02001784 /*invalid positions */
1785 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001786 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001787 logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001788
1789 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001790 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001791 logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001792
1793 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001794 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001795 logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001796
David Sedlák69f01612019-07-17 11:41:08 +02001797 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001798 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001799 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001800
1801 st->finished_correctly = true;
1802}
1803
1804static void
1805test_prefix_elem(void **state)
1806{
1807 struct state *st = *state;
1808 const char *data;
1809 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001810 struct lysp_ext_instance *exts = NULL;
1811
1812 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001813 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001814 assert_string_equal(value, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001815 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001816 assert_int_equal(exts[0].insubstmt_index, 0);
1817 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
1818 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1819 exts = NULL;
1820 FREE_STRING(st->ctx, value);
David Sedlák69f01612019-07-17 11:41:08 +02001821
1822 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001823 assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001824 assert_string_equal(value, "pref");
1825 FREE_STRING(st->ctx, value);
1826
1827 st->finished_correctly = true;
1828}
1829
1830static void
1831test_range_elem(void **state)
1832{
1833 struct state *st = *state;
1834 const char *data;
1835 struct lysp_type type = {};
1836
1837 /* max subelems */
1838 data = ELEMENT_WRAPPER_START
1839 "<range value=\"range-str\">"
1840 "<error-message><value>err-msg</value></error-message>"
1841 "<error-app-tag value=\"err-app-tag\" />"
1842 "<description><text>desc</text></description>"
1843 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001844 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001845 "</range>"
1846 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001847 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001848 assert_string_equal(type.range->arg, "range-str");
1849 assert_string_equal(type.range->dsc, "desc");
1850 assert_string_equal(type.range->eapptag, "err-app-tag");
1851 assert_string_equal(type.range->emsg, "err-msg");
1852 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001853 assert_true(type.flags & LYS_SET_RANGE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001854 assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001855 assert_int_equal(type.range->exts[0].insubstmt_index, 0);
1856 assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001857 lysp_type_free(st->ctx, &type);
1858 memset(&type, 0, sizeof(type));
1859
1860 /* min subelems */
1861 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001862 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001863 assert_string_equal(type.range->arg, "range-str");
1864 lysp_type_free(st->ctx, &type);
1865 memset(&type, 0, sizeof(type));
1866
1867 st->finished_correctly = true;
1868}
1869
1870static void
1871test_reqinstance_elem(void **state)
1872{
1873 struct state *st = *state;
1874 const char *data;
1875 struct lysp_type type = {};
1876
David Sedlákd1144562019-08-06 12:36:14 +02001877 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001878 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001879 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001880 assert_true(type.flags & LYS_SET_REQINST);
David Sedláke0ef1c62019-09-13 10:05:55 +02001881 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001882 assert_int_equal(type.exts[0].insubstmt_index, 0);
1883 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
1884 lysp_type_free(st->ctx, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001885 memset(&type, 0, sizeof(type));
1886
1887 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001888 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001889 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001890 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001891 memset(&type, 0, sizeof(type));
1892
1893 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001894 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001895 memset(&type, 0, sizeof(type));
David Sedlák26ea1432019-08-14 13:42:23 +02001896 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 +02001897
1898 st->finished_correctly = true;
1899}
1900
1901static void
1902test_revision_date_elem(void **state)
1903{
1904 struct state *st = *state;
1905 const char *data;
1906 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001907 struct lysp_ext_instance *exts = NULL;
1908
1909 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001910 assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001911 assert_string_equal(rev, "2000-01-01");
David Sedláke0ef1c62019-09-13 10:05:55 +02001912 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001913 assert_int_equal(exts[0].insubstmt_index, 0);
1914 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
1915 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001916
1917 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001918 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001919 assert_string_equal(rev, "2000-01-01");
1920
1921 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001922 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001923 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1924
1925 st->finished_correctly = true;
1926}
1927
1928static void
1929test_unique_elem(void **state)
1930{
1931 struct state *st = *state;
1932 const char *data;
1933 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001934 struct lysp_ext_instance *exts = NULL;
1935
1936 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001937 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001938 assert_string_equal(*values, "tag");
David Sedláke0ef1c62019-09-13 10:05:55 +02001939 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001940 assert_int_equal(exts[0].insubstmt_index, 0);
1941 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
1942 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1943 FREE_STRING(st->ctx, *values);
1944 LY_ARRAY_FREE(values);
1945 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001946
1947 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001948 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001949 assert_string_equal(*values, "tag");
1950 FREE_STRING(st->ctx, *values);
1951 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001952 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001953
1954 st->finished_correctly = true;
1955}
1956
1957static void
1958test_units_elem(void **state)
1959{
1960 struct state *st = *state;
1961 const char *data;
1962 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001963 struct lysp_ext_instance *exts = NULL;
1964
1965 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001966 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001967 assert_string_equal(values, "name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001968 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001969 assert_int_equal(exts[0].insubstmt_index, 0);
1970 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
1971 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1972 FREE_STRING(st->ctx, values);
1973 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001974
1975 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001976 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001977 assert_string_equal(values, "name");
1978 FREE_STRING(st->ctx, values);
David Sedlákd1144562019-08-06 12:36:14 +02001979 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001980
1981 st->finished_correctly = true;
1982}
1983
1984static void
1985test_when_elem(void **state)
1986{
1987 struct state *st = *state;
1988 const char *data;
1989 struct lysp_when *when = NULL;
1990
1991 data = ELEMENT_WRAPPER_START
1992 "<when condition=\"cond\">"
1993 "<description><text>desc</text></description>"
1994 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001995 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001996 "</when>"
1997 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001998 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001999 assert_string_equal(when->cond, "cond");
2000 assert_string_equal(when->dsc, "desc");
2001 assert_string_equal(when->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002002 assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002003 assert_int_equal(when->exts[0].insubstmt_index, 0);
2004 assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02002005 lysp_when_free(st->ctx, when);
2006 free(when);
2007 when = NULL;
2008
2009 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002010 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002011 assert_string_equal(when->cond, "cond");
2012 lysp_when_free(st->ctx, when);
2013 free(when);
2014 when = NULL;
2015
2016 st->finished_correctly = true;
2017}
2018
2019static void
2020test_yin_text_value_elem(void **state)
2021{
2022 struct state *st = *state;
2023 const char *data;
2024 const char *val;
2025
2026 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002027 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002028 assert_string_equal(val, "text");
2029 FREE_STRING(st->ctx, val);
2030
2031 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002032 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002033 assert_string_equal(val, "text");
2034 FREE_STRING(st->ctx, val);
2035
2036 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002037 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002038 assert_string_equal("", val);
2039 FREE_STRING(st->ctx, val);
2040
David Sedlák8e7bda82019-07-16 17:57:50 +02002041 st->finished_correctly = true;
2042}
David Sedlák32488102019-07-15 17:44:10 +02002043
David Sedlák374d2b32019-07-17 15:06:55 +02002044static void
2045test_type_elem(void **state)
2046{
2047 struct state *st = *state;
2048 const char *data;
2049 struct lysp_type type = {};
2050
2051 /* max subelems */
2052 data = ELEMENT_WRAPPER_START
2053 "<type name=\"type-name\">"
2054 "<base name=\"base-name\"/>"
2055 "<bit name=\"bit\"/>"
2056 "<enum name=\"enum\"/>"
2057 "<fraction-digits value=\"2\"/>"
2058 "<length value=\"length\"/>"
2059 "<path value=\"path\"/>"
2060 "<pattern value=\"pattern\"/>"
2061 "<range value=\"range\" />"
2062 "<require-instance value=\"true\"/>"
2063 "<type name=\"sub-type-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002064 EXT_SUBELEM
David Sedlák374d2b32019-07-17 15:06:55 +02002065 "</type>"
2066 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002067 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002068 assert_string_equal(type.name, "type-name");
2069 assert_string_equal(*type.bases, "base-name");
2070 assert_string_equal(type.bits->name, "bit");
2071 assert_string_equal(type.enums->name, "enum");
2072 assert_int_equal(type.fraction_digits, 2);
2073 assert_string_equal(type.length->arg, "length");
2074 assert_string_equal(type.path, "path");
2075 assert_string_equal(type.patterns->arg, "\006pattern");
2076 assert_string_equal(type.range->arg, "range");
2077 assert_int_equal(type.require_instance, 1);
2078 assert_string_equal(type.types->name, "sub-type-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02002079 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002080 assert_int_equal(type.exts[0].insubstmt_index, 0);
2081 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002082 assert_true(type.flags & LYS_SET_BASE);
2083 assert_true(type.flags & LYS_SET_BIT);
2084 assert_true(type.flags & LYS_SET_ENUM);
2085 assert_true(type.flags & LYS_SET_FRDIGITS);
2086 assert_true(type.flags & LYS_SET_LENGTH);
2087 assert_true(type.flags & LYS_SET_PATH);
2088 assert_true(type.flags & LYS_SET_PATTERN);
2089 assert_true(type.flags & LYS_SET_RANGE);
2090 assert_true(type.flags & LYS_SET_REQINST);
2091 assert_true(type.flags & LYS_SET_TYPE);
David Sedlákd1144562019-08-06 12:36:14 +02002092 lysp_type_free(st->ctx, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02002093 memset(&type, 0, sizeof(type));
2094
2095 /* min subelems */
2096 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002097 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002098 lysp_type_free(st->ctx, &type);
2099 memset(&type, 0, sizeof(type));
2100
2101 st->finished_correctly = true;
2102}
2103
David Sedlák1af868e2019-07-17 17:03:14 +02002104static void
2105test_max_elems_elem(void **state)
2106{
2107 struct state *st = *state;
2108 const char *data;
2109 struct lysp_node_list list = {};
2110 struct lysp_node_leaflist llist = {};
2111 struct lysp_refine refine = {};
2112
David Sedlákd1144562019-08-06 12:36:14 +02002113 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002114 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002115 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002116 assert_true(refine.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002117 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002118 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2119 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2120 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002121
David Sedlákd1144562019-08-06 12:36:14 +02002122 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002123 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002124 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002125 assert_true(list.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002126 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002127 assert_int_equal(list.exts[0].insubstmt_index, 0);
2128 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2129 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002130
David Sedlákd1144562019-08-06 12:36:14 +02002131 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002132 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002133 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002134 assert_true(llist.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002135 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002136 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2137 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2138 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002139
2140 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002141 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002142 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002143 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02002144
2145 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002146 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002147 logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002148
2149 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002150 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002151 logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002152
2153 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002154 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002155 logbuf_assert("Invalid value \"k\" 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=\"u12\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002158 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002159 logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002160
2161 st->finished_correctly = true;
2162}
2163
David Sedlák09e18c92019-07-18 11:17:11 +02002164static void
2165test_min_elems_elem(void **state)
2166{
2167 struct state *st = *state;
2168 const char *data;
2169 struct lysp_node_list list = {};
2170 struct lysp_node_leaflist llist = {};
2171 struct lysp_refine refine = {};
2172
David Sedlákd1144562019-08-06 12:36:14 +02002173 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002174 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002175 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002176 assert_true(refine.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002177 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002178 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2179 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2180 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002181
David Sedlákd1144562019-08-06 12:36:14 +02002182 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002183 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002184 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002185 assert_true(list.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002186 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002187 assert_int_equal(list.exts[0].insubstmt_index, 0);
2188 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2189 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002190
David Sedlákd1144562019-08-06 12:36:14 +02002191 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002192 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002193 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002194 assert_true(llist.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002195 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002196 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2197 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2198 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002199
2200 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002201 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002202 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 +02002203
2204 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002205 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002206 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 +02002207
2208 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002209 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002210 logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. 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=\"05\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002213 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002214 logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002215
2216 st->finished_correctly = true;
2217}
2218
David Sedláka2dad212019-07-18 12:45:19 +02002219static void
2220test_ordby_elem(void **state)
2221{
2222 struct state *st = *state;
2223 const char *data;
2224 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02002225 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02002226
David Sedlákd1144562019-08-06 12:36:14 +02002227 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002228 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002229 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláke0ef1c62019-09-13 10:05:55 +02002230 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002231 assert_int_equal(exts[0].insubstmt_index, 0);
2232 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
2233 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02002234
2235 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002236 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002237 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02002238
2239 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002240 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02002241 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 +02002242
2243 st->finished_correctly = true;
2244}
2245
David Sedlák8a83bbb2019-07-18 14:46:00 +02002246static void
2247test_any_elem(void **state)
2248{
2249 struct state *st = *state;
2250 const char *data;
2251 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002252 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02002253 struct lysp_node_anydata *parsed = NULL;
2254
2255 /* anyxml max subelems */
2256 data = ELEMENT_WRAPPER_START
2257 "<anyxml name=\"any-name\">"
2258 "<config value=\"true\" />"
2259 "<description><text>desc</text></description>"
2260 "<if-feature name=\"feature\" />"
2261 "<mandatory value=\"true\" />"
2262 "<must condition=\"must-cond\" />"
2263 "<reference><text>ref</text></reference>"
2264 "<status value=\"deprecated\"/>"
2265 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002266 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002267 "</anyxml>"
2268 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002269 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002270 parsed = (struct lysp_node_anydata *)siblings;
2271 assert_null(parsed->parent);
2272 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002273 assert_true(parsed->flags & LYS_CONFIG_W);
2274 assert_true(parsed->flags & LYS_MAND_TRUE);
2275 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002276 assert_null(parsed->next);
2277 assert_string_equal(parsed->name, "any-name");
2278 assert_string_equal(parsed->dsc, "desc");
2279 assert_string_equal(parsed->ref, "ref");
2280 assert_string_equal(parsed->when->cond, "when-cond");
2281 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002282 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002283 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2284 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002285 lysp_node_free(st->ctx, siblings);
2286 siblings = NULL;
2287
2288 /* anydata max subelems */
2289 data = ELEMENT_WRAPPER_START
2290 "<anydata name=\"any-name\">"
2291 "<config value=\"true\" />"
2292 "<description><text>desc</text></description>"
2293 "<if-feature name=\"feature\" />"
2294 "<mandatory value=\"true\" />"
2295 "<must condition=\"must-cond\" />"
2296 "<reference><text>ref</text></reference>"
2297 "<status value=\"deprecated\"/>"
2298 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002299 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002300 "</anydata>"
2301 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002302 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002303 parsed = (struct lysp_node_anydata *)siblings;
2304 assert_null(parsed->parent);
2305 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002306 assert_true(parsed->flags & LYS_CONFIG_W);
2307 assert_true(parsed->flags & LYS_MAND_TRUE);
2308 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002309 assert_null(parsed->next);
2310 assert_string_equal(parsed->name, "any-name");
2311 assert_string_equal(parsed->dsc, "desc");
2312 assert_string_equal(parsed->ref, "ref");
2313 assert_string_equal(parsed->when->cond, "when-cond");
2314 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002315 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002316 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2317 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002318 lysp_node_free(st->ctx, siblings);
2319 siblings = NULL;
2320
2321 /* min subelems */
2322 node_meta.parent = (void *)0x10;
2323 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002324 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002325 parsed = (struct lysp_node_anydata *)siblings;
2326 assert_ptr_equal(parsed->parent, node_meta.parent);
2327 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
2328 assert_null(parsed->next);
2329 assert_null(parsed->exts);
2330 lysp_node_free(st->ctx, siblings);
2331
2332 st->finished_correctly = true;
2333}
2334
David Sedlák203ca3a2019-07-18 15:26:25 +02002335static void
2336test_leaf_elem(void **state)
2337{
2338 struct state *st = *state;
2339 const char *data;
2340 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002341 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002342 struct lysp_node_leaf *parsed = NULL;
2343
2344 /* max elements */
2345 data = ELEMENT_WRAPPER_START
2346 "<leaf name=\"leaf\">"
2347 "<config value=\"true\" />"
2348 "<default value=\"def-val\"/>"
2349 "<description><text>desc</text></description>"
2350 "<if-feature name=\"feature\" />"
2351 "<mandatory value=\"true\" />"
2352 "<must condition=\"must-cond\" />"
2353 "<reference><text>ref</text></reference>"
2354 "<status value=\"deprecated\"/>"
2355 "<type name=\"type\"/>"
2356 "<units name=\"uni\"/>"
2357 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002358 EXT_SUBELEM
David Sedlák203ca3a2019-07-18 15:26:25 +02002359 "</leaf>"
2360 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002361 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002362 parsed = (struct lysp_node_leaf *)siblings;
2363 assert_null(parsed->parent);
2364 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002365 assert_true(parsed->flags & LYS_CONFIG_W);
2366 assert_true(parsed->flags & LYS_MAND_TRUE);
2367 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02002368 assert_null(parsed->next);
2369 assert_string_equal(parsed->name, "leaf");
2370 assert_string_equal(parsed->dsc, "desc");
2371 assert_string_equal(parsed->ref, "ref");
2372 assert_string_equal(parsed->when->cond, "when-cond");
2373 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002374 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002375 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2376 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák203ca3a2019-07-18 15:26:25 +02002377 assert_string_equal(parsed->musts->arg, "must-cond");
2378 assert_string_equal(parsed->type.name, "type");
2379 assert_string_equal(parsed->units, "uni");
2380 assert_string_equal(parsed->dflt, "def-val");
2381 lysp_node_free(st->ctx, siblings);
2382 siblings = NULL;
2383
2384 /* min elements */
2385 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002386 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002387 parsed = (struct lysp_node_leaf *)siblings;
2388 assert_string_equal(parsed->name, "leaf");
2389 assert_string_equal(parsed->type.name, "type");
2390 lysp_node_free(st->ctx, siblings);
2391 siblings = NULL;
2392
2393 st->finished_correctly = true;
2394}
2395
David Sedlákc3da3ef2019-07-19 12:56:08 +02002396static void
2397test_leaf_list_elem(void **state)
2398{
2399 struct state *st = *state;
2400 const char *data;
2401 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002402 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002403 struct lysp_node_leaflist *parsed = NULL;
2404
2405 data = ELEMENT_WRAPPER_START
2406 "<leaf-list name=\"llist\">"
2407 "<config value=\"true\" />"
2408 "<default value=\"def-val0\"/>"
2409 "<default value=\"def-val1\"/>"
2410 "<description><text>desc</text></description>"
2411 "<if-feature name=\"feature\"/>"
2412 "<max-elements value=\"5\"/>"
2413 "<must condition=\"must-cond\"/>"
2414 "<ordered-by value=\"user\" />"
2415 "<reference><text>ref</text></reference>"
2416 "<status value=\"current\"/>"
2417 "<type name=\"type\"/>"
2418 "<units name=\"uni\"/>"
2419 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002420 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002421 "</leaf-list>"
2422 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002423 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002424 parsed = (struct lysp_node_leaflist *)siblings;
2425 assert_string_equal(parsed->dflts[0], "def-val0");
2426 assert_string_equal(parsed->dflts[1], "def-val1");
2427 assert_string_equal(parsed->dsc, "desc");
2428 assert_string_equal(*parsed->iffeatures, "feature");
2429 assert_int_equal(parsed->max, 5);
2430 assert_string_equal(parsed->musts->arg, "must-cond");
2431 assert_string_equal(parsed->name, "llist");
2432 assert_null(parsed->next);
2433 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2434 assert_null(parsed->parent);
2435 assert_string_equal(parsed->ref, "ref");
2436 assert_string_equal(parsed->type.name, "type");
2437 assert_string_equal(parsed->units, "uni");
2438 assert_string_equal(parsed->when->cond, "when-cond");
2439 assert_true(parsed->flags & LYS_CONFIG_W);
2440 assert_true(parsed->flags & LYS_ORDBY_USER);
2441 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002442 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002443 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2444 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002445 lysp_node_free(st->ctx, siblings);
2446 siblings = NULL;
2447
2448 data = ELEMENT_WRAPPER_START
2449 "<leaf-list name=\"llist\">"
2450 "<config value=\"true\" />"
2451 "<description><text>desc</text></description>"
2452 "<if-feature name=\"feature\"/>"
2453 "<min-elements value=\"5\"/>"
2454 "<must condition=\"must-cond\"/>"
2455 "<ordered-by value=\"user\" />"
2456 "<reference><text>ref</text></reference>"
2457 "<status value=\"current\"/>"
2458 "<type name=\"type\"/>"
2459 "<units name=\"uni\"/>"
2460 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002461 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002462 "</leaf-list>"
2463 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002464 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002465 parsed = (struct lysp_node_leaflist *)siblings;
2466 assert_string_equal(parsed->dsc, "desc");
2467 assert_string_equal(*parsed->iffeatures, "feature");
2468 assert_int_equal(parsed->min, 5);
2469 assert_string_equal(parsed->musts->arg, "must-cond");
2470 assert_string_equal(parsed->name, "llist");
2471 assert_null(parsed->next);
2472 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2473 assert_null(parsed->parent);
2474 assert_string_equal(parsed->ref, "ref");
2475 assert_string_equal(parsed->type.name, "type");
2476 assert_string_equal(parsed->units, "uni");
2477 assert_string_equal(parsed->when->cond, "when-cond");
2478 assert_true(parsed->flags & LYS_CONFIG_W);
2479 assert_true(parsed->flags & LYS_ORDBY_USER);
2480 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002481 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002482 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2483 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002484 lysp_node_free(st->ctx, siblings);
2485 siblings = NULL;
2486
2487 data = ELEMENT_WRAPPER_START
2488 "<leaf-list name=\"llist\">"
2489 "<config value=\"true\" />"
2490 "<description><text>desc</text></description>"
2491 "<if-feature name=\"feature\"/>"
2492 "<max-elements value=\"15\"/>"
2493 "<min-elements value=\"5\"/>"
2494 "<must condition=\"must-cond\"/>"
2495 "<ordered-by value=\"user\" />"
2496 "<reference><text>ref</text></reference>"
2497 "<status value=\"current\"/>"
2498 "<type name=\"type\"/>"
2499 "<units name=\"uni\"/>"
2500 "<when condition=\"when-cond\"/>"
2501 "</leaf-list>"
2502 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002503 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002504 parsed = (struct lysp_node_leaflist *)siblings;
2505 assert_string_equal(parsed->dsc, "desc");
2506 assert_string_equal(*parsed->iffeatures, "feature");
2507 assert_int_equal(parsed->min, 5);
2508 assert_int_equal(parsed->max, 15);
2509 assert_string_equal(parsed->musts->arg, "must-cond");
2510 assert_string_equal(parsed->name, "llist");
2511 assert_null(parsed->next);
2512 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2513 assert_null(parsed->parent);
2514 assert_string_equal(parsed->ref, "ref");
2515 assert_string_equal(parsed->type.name, "type");
2516 assert_string_equal(parsed->units, "uni");
2517 assert_string_equal(parsed->when->cond, "when-cond");
2518 assert_true(parsed->flags & LYS_CONFIG_W);
2519 assert_true(parsed->flags & LYS_ORDBY_USER);
2520 assert_true(parsed->flags & LYS_STATUS_CURR);
2521 lysp_node_free(st->ctx, siblings);
2522 siblings = NULL;
2523
2524 data = ELEMENT_WRAPPER_START
2525 "<leaf-list name=\"llist\">"
2526 "<type name=\"type\"/>"
2527 "</leaf-list>"
2528 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002529 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002530 parsed = (struct lysp_node_leaflist *)siblings;
2531 assert_string_equal(parsed->name, "llist");
2532 assert_string_equal(parsed->type.name, "type");
2533 lysp_node_free(st->ctx, siblings);
2534 siblings = NULL;
2535
2536 /* invalid combinations */
2537 data = ELEMENT_WRAPPER_START
2538 "<leaf-list name=\"llist\">"
2539 "<max-elements value=\"5\"/>"
2540 "<min-elements value=\"15\"/>"
2541 "<type name=\"type\"/>"
2542 "</leaf-list>"
2543 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002544 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002545 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2546 lysp_node_free(st->ctx, siblings);
2547 siblings = NULL;
2548
2549 data = ELEMENT_WRAPPER_START
2550 "<leaf-list name=\"llist\">"
2551 "<default value=\"def-val1\"/>"
2552 "<min-elements value=\"15\"/>"
2553 "<type name=\"type\"/>"
2554 "</leaf-list>"
2555 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002556 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002557 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 +02002558 lysp_node_free(st->ctx, siblings);
2559 siblings = NULL;
2560
2561 data = ELEMENT_WRAPPER_START
2562 "<leaf-list name=\"llist\">"
2563 "</leaf-list>"
2564 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002565 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002566 logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002567 lysp_node_free(st->ctx, siblings);
2568 siblings = NULL;
2569
2570 st->finished_correctly = true;
2571}
2572
David Sedlákcb39f642019-07-19 13:19:55 +02002573static void
2574test_presence_elem(void **state)
2575{
2576 struct state *st = *state;
2577 const char *data;
2578 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002579 struct lysp_ext_instance *exts = NULL;
2580
2581 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002582 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002583 assert_string_equal(val, "presence-val");
David Sedláke0ef1c62019-09-13 10:05:55 +02002584 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002585 assert_int_equal(exts[0].insubstmt_index, 0);
2586 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
2587 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2588 FREE_STRING(st->ctx, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002589
2590 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002591 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002592 assert_string_equal(val, "presence-val");
2593 FREE_STRING(st->ctx, val);
2594
2595 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002596 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlákcb39f642019-07-19 13:19:55 +02002597 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2598
2599 st->finished_correctly = true;
2600}
2601
David Sedlák12470a82019-07-19 13:44:36 +02002602static void
2603test_key_elem(void **state)
2604{
2605 struct state *st = *state;
2606 const char *data;
2607 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002608 struct lysp_ext_instance *exts = NULL;
2609
2610 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002611 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002612 assert_string_equal(val, "key-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02002613 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002614 assert_int_equal(exts[0].insubstmt_index, 0);
2615 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
2616 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2617 FREE_STRING(st->ctx, val);
David Sedlák12470a82019-07-19 13:44:36 +02002618
2619 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002620 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002621 assert_string_equal(val, "key-value");
2622 FREE_STRING(st->ctx, val);
2623
2624 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002625 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák12470a82019-07-19 13:44:36 +02002626 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2627
2628 st->finished_correctly = true;
2629}
2630
David Sedlák04e17b22019-07-19 15:29:48 +02002631static void
2632test_typedef_elem(void **state)
2633{
2634 struct state *st = *state;
2635 const char *data;
2636 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002637 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002638
2639 data = ELEMENT_WRAPPER_START
2640 "<typedef name=\"tpdf-name\">"
2641 "<default value=\"def-val\"/>"
2642 "<description><text>desc-text</text></description>"
2643 "<reference><text>ref-text</text></reference>"
2644 "<status value=\"current\"/>"
2645 "<type name=\"type\"/>"
2646 "<units name=\"uni\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002647 EXT_SUBELEM
David Sedlák04e17b22019-07-19 15:29:48 +02002648 "</typedef>"
2649 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002650 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002651 assert_string_equal(tpdfs[0].dflt, "def-val");
2652 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002653 assert_string_equal(tpdfs[0].name, "tpdf-name");
2654 assert_string_equal(tpdfs[0].ref, "ref-text");
2655 assert_string_equal(tpdfs[0].type.name, "type");
2656 assert_string_equal(tpdfs[0].units, "uni");
2657 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002658 assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002659 assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
2660 assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák04e17b22019-07-19 15:29:48 +02002661 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2662 tpdfs = NULL;
2663
2664 data = ELEMENT_WRAPPER_START
2665 "<typedef name=\"tpdf-name\">"
2666 "<type name=\"type\"/>"
2667 "</typedef>"
2668 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002669 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002670 assert_string_equal(tpdfs[0].name, "tpdf-name");
2671 assert_string_equal(tpdfs[0].type.name, "type");
2672 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2673 tpdfs = NULL;
2674
2675 st->finished_correctly = true;
2676}
2677
David Sedlákd2d676a2019-07-22 11:28:19 +02002678static void
2679test_refine_elem(void **state)
2680{
2681 struct state *st = *state;
2682 const char *data;
2683 struct lysp_refine *refines = NULL;
2684
2685 /* max subelems */
2686 data = ELEMENT_WRAPPER_START
2687 "<refine target-node=\"target\">"
2688 "<if-feature name=\"feature\" />"
2689 "<must condition=\"cond\" />"
2690 "<presence value=\"presence\" />"
2691 "<default value=\"def\" />"
2692 "<config value=\"true\" />"
2693 "<mandatory value=\"true\" />"
2694 "<min-elements value=\"10\" />"
2695 "<max-elements value=\"20\" />"
2696 "<description><text>desc</text></description>"
2697 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002698 EXT_SUBELEM
David Sedlákd2d676a2019-07-22 11:28:19 +02002699 "</refine>"
2700 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002701 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002702 assert_string_equal(refines->nodeid, "target");
2703 assert_string_equal(*refines->dflts, "def");
2704 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002705 assert_true(refines->flags & LYS_CONFIG_W);
2706 assert_true(refines->flags & LYS_MAND_TRUE);
2707 assert_string_equal(*refines->iffeatures, "feature");
2708 assert_int_equal(refines->max, 20);
2709 assert_int_equal(refines->min, 10);
2710 assert_string_equal(refines->musts->arg, "cond");
2711 assert_string_equal(refines->presence, "presence");
2712 assert_string_equal(refines->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002713 assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002714 assert_int_equal(refines->exts[0].insubstmt_index, 0);
2715 assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákd2d676a2019-07-22 11:28:19 +02002716 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2717 refines = NULL;
2718
2719 /* min subelems */
2720 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002721 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002722 assert_string_equal(refines->nodeid, "target");
2723 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2724 refines = NULL;
2725
2726 st->finished_correctly = true;
2727}
2728
David Sedlák0d6de5a2019-07-22 13:25:44 +02002729static void
2730test_uses_elem(void **state)
2731{
2732 struct state *st = *state;
2733 const char *data;
2734 struct lysp_node *siblings = NULL;
2735 struct tree_node_meta node_meta = {NULL, &siblings};
2736 struct lysp_node_uses *parsed = NULL;
2737
2738 /* max subelems */
2739 data = ELEMENT_WRAPPER_START
2740 "<uses name=\"uses-name\">"
2741 "<when condition=\"cond\" />"
2742 "<if-feature name=\"feature\" />"
2743 "<status value=\"obsolete\" />"
2744 "<description><text>desc</text></description>"
2745 "<reference><text>ref</text></reference>"
2746 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002747 "<augment target-node=\"target\" />"
David Sedlákd1144562019-08-06 12:36:14 +02002748 EXT_SUBELEM
David Sedlák0d6de5a2019-07-22 13:25:44 +02002749 "</uses>"
2750 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002751 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002752 parsed = (struct lysp_node_uses *)&siblings[0];
2753 assert_string_equal(parsed->name, "uses-name");
2754 assert_string_equal(parsed->dsc, "desc");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002755 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2756 assert_string_equal(*parsed->iffeatures, "feature");
2757 assert_null(parsed->next);
2758 assert_int_equal(parsed->nodetype, LYS_USES);
2759 assert_null(parsed->parent);
2760 assert_string_equal(parsed->ref, "ref");
2761 assert_string_equal(parsed->refines->nodeid, "target");
2762 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002763 assert_string_equal(parsed->augments->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02002764 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002765 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2766 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002767 lysp_node_free(st->ctx, siblings);
2768 siblings = NULL;
2769
2770 /* min subelems */
2771 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002772 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002773 assert_string_equal(siblings[0].name, "uses-name");
2774 lysp_node_free(st->ctx, siblings);
2775 siblings = NULL;
2776
2777 st->finished_correctly = true;
2778}
2779
David Sedlákaa854b02019-07-22 14:17:10 +02002780static void
2781test_revision_elem(void **state)
2782{
2783 struct state *st = *state;
2784 const char *data;
2785 struct lysp_revision *revs = NULL;
2786
2787 /* max subelems */
2788 data = ELEMENT_WRAPPER_START
2789 "<revision date=\"2018-12-25\">"
2790 "<description><text>desc</text></description>"
2791 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002792 EXT_SUBELEM
David Sedlákaa854b02019-07-22 14:17:10 +02002793 "</revision>"
2794 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002795 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002796 assert_string_equal(revs->date, "2018-12-25");
2797 assert_string_equal(revs->dsc, "desc");
2798 assert_string_equal(revs->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002799 assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002800 assert_int_equal(revs->exts[0].insubstmt_index, 0);
2801 assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaa854b02019-07-22 14:17:10 +02002802 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2803 revs = NULL;
2804
2805 /* min subelems */
2806 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002807 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002808 assert_string_equal(revs->date, "2005-05-05");
2809 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2810 revs = NULL;
2811
2812 /* invalid value */
2813 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002814 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID);
David Sedlákaa854b02019-07-22 14:17:10 +02002815 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2816 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2817 revs = NULL;
2818
2819 st->finished_correctly = true;
2820}
2821
David Sedlák0c2bab92019-07-22 15:33:19 +02002822static void
2823test_include_elem(void **state)
2824{
2825 struct state *st = *state;
2826 const char *data;
2827 struct lysp_include *includes = NULL;
2828 struct include_meta inc_meta = {"module-name", &includes};
2829
2830 /* max subelems */
2831 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2832 data = ELEMENT_WRAPPER_START
2833 "<include module=\"mod\">"
2834 "<description><text>desc</text></description>"
2835 "<reference><text>ref</text></reference>"
2836 "<revision-date date=\"1999-09-09\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002837 EXT_SUBELEM
David Sedlák0c2bab92019-07-22 15:33:19 +02002838 "</include>"
2839 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002840 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002841 assert_string_equal(includes->name, "mod");
2842 assert_string_equal(includes->dsc, "desc");
2843 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002844 assert_string_equal(includes->rev, "1999-09-09");
David Sedláke0ef1c62019-09-13 10:05:55 +02002845 assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002846 assert_int_equal(includes->exts[0].insubstmt_index, 0);
2847 assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0c2bab92019-07-22 15:33:19 +02002848 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2849 includes = NULL;
2850
2851 /* min subelems */
2852 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002853 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002854 assert_string_equal(includes->name, "mod");
2855 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2856 includes = NULL;
2857
2858 /* invalid combinations */
2859 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2860 data = ELEMENT_WRAPPER_START
2861 "<include module=\"mod\">"
2862 "<description><text>desc</text></description>"
2863 "<revision-date date=\"1999-09-09\"/>"
2864 "</include>"
2865 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002866 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002867 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.");
2868 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2869 includes = NULL;
2870
2871 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2872 data = ELEMENT_WRAPPER_START
2873 "<include module=\"mod\">"
2874 "<reference><text>ref</text></reference>"
2875 "<revision-date date=\"1999-09-09\"/>"
2876 "</include>"
2877 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002878 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002879 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.");
2880 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2881 includes = NULL;
2882
2883 st->finished_correctly = true;
2884}
2885
David Sedlák5e13dea2019-07-22 16:06:45 +02002886static void
2887test_feature_elem(void **state)
2888{
2889 struct state *st = *state;
2890 const char *data;
2891 struct lysp_feature *features = NULL;
2892
2893 /* max subelems */
2894 data = ELEMENT_WRAPPER_START
2895 "<feature name=\"feature-name\">"
2896 "<if-feature name=\"iff\"/>"
2897 "<status value=\"deprecated\"/>"
2898 "<description><text>desc</text></description>"
2899 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002900 EXT_SUBELEM
David Sedlák5e13dea2019-07-22 16:06:45 +02002901 "</feature>"
2902 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002903 assert_int_equal(test_element_helper(st, data, &features, NULL, NULL), LY_SUCCESS);
David Sedlák5e13dea2019-07-22 16:06:45 +02002904 assert_string_equal(features->name, "feature-name");
2905 assert_string_equal(features->dsc, "desc");
David Sedlák5e13dea2019-07-22 16:06:45 +02002906 assert_true(features->flags & LYS_STATUS_DEPRC);
2907 assert_string_equal(*features->iffeatures, "iff");
2908 assert_string_equal(features->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002909 assert_string_equal(features->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002910 assert_int_equal(features->exts[0].insubstmt_index, 0);
2911 assert_int_equal(features->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5e13dea2019-07-22 16:06:45 +02002912 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2913 features = NULL;
2914
2915 /* min subelems */
2916 data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002917 assert_int_equal(test_element_helper(st, data, &features, NULL, NULL), LY_SUCCESS);
David Sedlák5e13dea2019-07-22 16:06:45 +02002918 assert_string_equal(features->name, "feature-name");
2919 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2920 features = NULL;
2921
2922 st->finished_correctly = true;
2923}
2924
David Sedlák28794f22019-07-22 16:45:00 +02002925static void
2926test_identity_elem(void **state)
2927{
2928 struct state *st = *state;
2929 const char *data;
2930 struct lysp_ident *identities = NULL;
2931
2932 /* max subelems */
2933 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2934 data = ELEMENT_WRAPPER_START
2935 "<identity name=\"ident-name\">"
2936 "<if-feature name=\"iff\"/>"
2937 "<base name=\"base-name\"/>"
2938 "<status value=\"deprecated\"/>"
2939 "<description><text>desc</text></description>"
2940 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002941 EXT_SUBELEM
David Sedlák28794f22019-07-22 16:45:00 +02002942 "</identity>"
2943 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002944 assert_int_equal(test_element_helper(st, data, &identities, NULL, NULL), LY_SUCCESS);
David Sedlák28794f22019-07-22 16:45:00 +02002945 assert_string_equal(identities->name, "ident-name");
2946 assert_string_equal(*identities->bases, "base-name");
2947 assert_string_equal(*identities->iffeatures, "iff");
2948 assert_string_equal(identities->dsc, "desc");
2949 assert_string_equal(identities->ref, "ref");
2950 assert_true(identities->flags & LYS_STATUS_DEPRC);
David Sedláke0ef1c62019-09-13 10:05:55 +02002951 assert_string_equal(identities->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002952 assert_int_equal(identities->exts[0].insubstmt_index, 0);
2953 assert_int_equal(identities->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák28794f22019-07-22 16:45:00 +02002954 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2955 identities = NULL;
2956
2957 /* min subelems */
2958 data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002959 assert_int_equal(test_element_helper(st, data, &identities, NULL, NULL), LY_SUCCESS);
David Sedlák28794f22019-07-22 16:45:00 +02002960 assert_string_equal(identities->name, "ident-name");
2961 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2962 identities = NULL;
2963
2964 /* invalid */
2965 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2966 data = ELEMENT_WRAPPER_START
2967 "<identity name=\"ident-name\">"
2968 "<if-feature name=\"iff\"/>"
2969 "</identity>"
2970 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002971 assert_int_equal(test_element_helper(st, data, &identities, NULL, NULL), LY_EVALID);
David Sedlák28794f22019-07-22 16:45:00 +02002972 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.");
2973 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2974 identities = NULL;
2975
2976 st->finished_correctly = true;
2977}
2978
David Sedlákaf536aa2019-07-23 13:42:23 +02002979static void
2980test_list_elem(void **state)
2981{
2982 struct state *st = *state;
2983 const char *data;
2984 struct lysp_node *siblings = NULL;
2985 struct tree_node_meta node_meta = {NULL, &siblings};
2986 struct lysp_node_list *parsed = NULL;
2987
2988 /* max subelems */
2989 data = ELEMENT_WRAPPER_START
2990 "<list name=\"list-name\">"
2991 "<when condition=\"when\"/>"
2992 "<if-feature name=\"iff\"/>"
2993 "<must condition=\"must-cond\"/>"
2994 "<key value=\"key\"/>"
2995 "<unique tag=\"utag\"/>"
2996 "<config value=\"true\"/>"
2997 "<min-elements value=\"10\"/>"
2998 "<ordered-by value=\"user\"/>"
2999 "<status value=\"deprecated\"/>"
3000 "<description><text>desc</text></description>"
3001 "<reference><text>ref</text></reference>"
3002 "<anydata name=\"anyd\"/>"
3003 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003004 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003005 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003006 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003007 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02003008 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003009 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3010 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02003011 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003012 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02003013 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003014 EXT_SUBELEM
David Sedlákaf536aa2019-07-23 13:42:23 +02003015 "</list>"
3016 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003017 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02003018 parsed = (struct lysp_node_list *)&siblings[0];
3019 assert_string_equal(parsed->dsc, "desc");
3020 assert_string_equal(parsed->child->name, "anyd");
3021 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3022 assert_string_equal(parsed->child->next->name, "anyx");
3023 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02003024 assert_string_equal(parsed->child->next->next->name, "cont");
3025 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003026 assert_string_equal(parsed->child->next->next->next->name, "choice");
3027 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02003028 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
3029 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
3030 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
3031 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3032 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
3033 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
3034 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
3035 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3036 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003037 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02003038 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003039 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02003040 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02003041 assert_true(parsed->flags & LYS_ORDBY_USER);
3042 assert_true(parsed->flags & LYS_STATUS_DEPRC);
3043 assert_true(parsed->flags & LYS_CONFIG_W);
3044 assert_string_equal(*parsed->iffeatures, "iff");
3045 assert_string_equal(parsed->key, "key");
3046 assert_int_equal(parsed->min, 10);
3047 assert_string_equal(parsed->musts->arg, "must-cond");
3048 assert_string_equal(parsed->name, "list-name");
3049 assert_null(parsed->next);
3050 assert_int_equal(parsed->nodetype, LYS_LIST);
3051 assert_null(parsed->parent);
3052 assert_string_equal(parsed->ref, "ref");
3053 assert_string_equal(parsed->typedefs->name, "tpdf");
3054 assert_string_equal(*parsed->uniques, "utag");
3055 assert_string_equal(parsed->when->cond, "when");
David Sedláke0ef1c62019-09-13 10:05:55 +02003056 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003057 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3058 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaf536aa2019-07-23 13:42:23 +02003059 lysp_node_free(st->ctx, siblings);
3060 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3061 siblings = NULL;
3062
3063 /* min subelems */
3064 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003065 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02003066 parsed = (struct lysp_node_list *)&siblings[0];
3067 assert_string_equal(parsed->name, "list-name");
3068 lysp_node_free(st->ctx, siblings);
3069 siblings = NULL;
3070
3071 st->finished_correctly = true;
3072}
3073
David Sedlák031b9e72019-07-23 15:19:37 +02003074static void
3075test_notification_elem(void **state)
3076{
3077 struct state *st = *state;
3078 const char *data;
3079 struct lysp_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003080 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02003081
3082 /* max subelems */
3083 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3084 data = ELEMENT_WRAPPER_START
3085 "<notification name=\"notif-name\">"
3086 "<anydata name=\"anyd\"/>"
3087 "<anyxml name=\"anyx\"/>"
3088 "<description><text>desc</text></description>"
3089 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003090 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3091 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02003092 "<list name=\"sub-list\"/>"
3093 "<must condition=\"cond\"/>"
3094 "<reference><text>ref</text></reference>"
3095 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003096 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02003097 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003098 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003099 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003100 "<grouping name=\"grp\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003101 EXT_SUBELEM
David Sedlák031b9e72019-07-23 15:19:37 +02003102 "</notification>"
3103 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003104 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003105 assert_string_equal(notifs->name, "notif-name");
3106 assert_string_equal(notifs->data->name, "anyd");
3107 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
3108 assert_string_equal(notifs->data->next->name, "anyx");
3109 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
3110 assert_string_equal(notifs->data->next->next->name, "leaf");
3111 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
3112 assert_string_equal(notifs->data->next->next->next->name, "llist");
3113 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
3114 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
3115 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02003116 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003117 assert_string_equal(notifs->groupings->name, "grp");
3118 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02003119 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
3120 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
3121 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
3122 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003123 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3124 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
3125 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02003126 assert_string_equal(*notifs->iffeatures, "iff");
3127 assert_string_equal(notifs->musts->arg, "cond");
3128 assert_int_equal(notifs->nodetype, LYS_NOTIF);
3129 assert_null(notifs->parent);
3130 assert_string_equal(notifs->ref, "ref");
3131 assert_string_equal(notifs->typedefs->name, "tpdf");
David Sedláke0ef1c62019-09-13 10:05:55 +02003132 assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003133 assert_int_equal(notifs->exts[0].insubstmt_index, 0);
3134 assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák031b9e72019-07-23 15:19:37 +02003135 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
3136 notifs = NULL;
3137
3138 /* min subelems */
3139 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003140 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003141 assert_string_equal(notifs->name, "notif-name");
3142 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003143 notifs = NULL;
3144
3145 st->finished_correctly = true;
3146}
3147
3148static void
3149test_grouping_elem(void **state)
3150{
3151 struct state *st = *state;
3152 const char *data;
3153 struct lysp_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003154 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02003155
3156 /* max subelems */
3157 data = ELEMENT_WRAPPER_START
3158 "<grouping name=\"grp-name\">"
3159 "<anydata name=\"anyd\"/>"
3160 "<anyxml name=\"anyx\"/>"
3161 "<description><text>desc</text></description>"
3162 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003163 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3164 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003165 "<list name=\"list\"/>"
3166 "<notification name=\"notf\"/>"
3167 "<reference><text>ref</text></reference>"
3168 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003169 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003170 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003171 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003172 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003173 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003174 EXT_SUBELEM
David Sedláke3ce9ef2019-07-23 16:34:30 +02003175 "</grouping>"
3176 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003177 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003178 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003179 assert_string_equal(grps->data->name, "anyd");
3180 assert_string_equal(grps->data->next->name, "anyx");
3181 assert_string_equal(grps->data->next->next->name, "leaf");
3182 assert_string_equal(grps->data->next->next->next->name, "llist");
3183 assert_string_equal(grps->data->next->next->next->next->name, "list");
3184 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003185 assert_true(grps->flags & LYS_STATUS_CURR);
3186 assert_string_equal(grps->groupings->name, "sub-grp");
3187 assert_int_equal(grps->nodetype, LYS_GROUPING);
3188 assert_string_equal(grps->notifs->name, "notf");
3189 assert_null(grps->parent);
3190 assert_string_equal(grps->ref, "ref");
3191 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003192 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02003193 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003194 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02003195 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003196 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
3197 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
3198 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke0ef1c62019-09-13 10:05:55 +02003199 assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003200 assert_int_equal(grps->exts[0].insubstmt_index, 0);
3201 assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003202 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3203 grps = NULL;
3204
3205 /* min subelems */
3206 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003207 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003208 assert_string_equal(grps->name, "grp-name");
3209 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3210 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02003211
3212 st->finished_correctly = true;
3213}
3214
David Sedlákf111bcb2019-07-23 17:15:51 +02003215static void
3216test_container_elem(void **state)
3217{
3218 struct state *st = *state;
3219 const char *data;
3220 struct lysp_node *siblings = NULL;
3221 struct tree_node_meta node_meta = {NULL, &siblings};
3222 struct lysp_node_container *parsed = NULL;
3223
3224 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02003225 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3226 data = ELEMENT_WRAPPER_START
3227 "<container name=\"cont-name\">"
3228 "<anydata name=\"anyd\"/>"
3229 "<anyxml name=\"anyx\"/>"
3230 "<config value=\"true\"/>"
3231 "<container name=\"subcont\"/>"
3232 "<description><text>desc</text></description>"
3233 "<grouping name=\"sub-grp\"/>"
3234 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003235 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3236 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003237 "<list name=\"list\"/>"
3238 "<must condition=\"cond\"/>"
3239 "<notification name=\"notf\"/>"
3240 "<presence value=\"presence\"/>"
3241 "<reference><text>ref</text></reference>"
3242 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003243 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003244 "<uses name=\"uses-name\"/>"
3245 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003246 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003247 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003248 EXT_SUBELEM
David Sedláke2dc9e92019-07-24 09:59:21 +02003249 "</container>"
3250 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003251 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02003252 parsed = (struct lysp_node_container *)siblings;
3253 assert_string_equal(parsed->name, "cont-name");
3254 assert_null(parsed->parent);
3255 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
3256 assert_true(parsed->flags & LYS_CONFIG_W);
3257 assert_true(parsed->flags & LYS_STATUS_CURR);
3258 assert_null(parsed->next);
3259 assert_string_equal(parsed->dsc, "desc");
3260 assert_string_equal(parsed->ref, "ref");
3261 assert_string_equal(parsed->when->cond, "when-cond");
3262 assert_string_equal(*parsed->iffeatures, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02003263 assert_string_equal(parsed->musts->arg, "cond");
3264 assert_string_equal(parsed->presence, "presence");
3265 assert_string_equal(parsed->typedefs->name, "tpdf");
3266 assert_string_equal(parsed->groupings->name, "sub-grp");
3267 assert_string_equal(parsed->child->name, "anyd");
3268 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3269 assert_string_equal(parsed->child->next->name, "anyx");
3270 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3271 assert_string_equal(parsed->child->next->next->name, "subcont");
3272 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3273 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3274 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3275 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3276 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3277 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3278 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3279 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3280 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003281 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3282 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3283 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02003284 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003285 assert_string_equal(parsed->actions->name, "act");
David Sedláke0ef1c62019-09-13 10:05:55 +02003286 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003287 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3288 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke2dc9e92019-07-24 09:59:21 +02003289 lysp_node_free(st->ctx, siblings);
3290 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3291 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02003292
3293 /* min subelems */
3294 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003295 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02003296 parsed = (struct lysp_node_container *)siblings;
3297 assert_string_equal(parsed->name, "cont-name");
3298 lysp_node_free(st->ctx, siblings);
3299 siblings = NULL;
3300
3301 st->finished_correctly = true;
3302}
3303
David Sedlák5379d392019-07-24 10:42:03 +02003304static void
3305test_case_elem(void **state)
3306{
3307 struct state *st = *state;
3308 const char *data;
3309 struct lysp_node *siblings = NULL;
3310 struct tree_node_meta node_meta = {NULL, &siblings};
3311 struct lysp_node_case *parsed = NULL;
3312
3313 /* max subelems */
3314 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3315 data = ELEMENT_WRAPPER_START
3316 "<case name=\"case-name\">"
3317 "<anydata name=\"anyd\"/>"
3318 "<anyxml name=\"anyx\"/>"
3319 "<container name=\"subcont\"/>"
3320 "<description><text>desc</text></description>"
3321 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003322 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3323 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02003324 "<list name=\"list\"/>"
3325 "<reference><text>ref</text></reference>"
3326 "<status value=\"current\"/>"
3327 "<uses name=\"uses-name\"/>"
3328 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003329 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003330 EXT_SUBELEM
David Sedlák5379d392019-07-24 10:42:03 +02003331 "</case>"
3332 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003333 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003334 parsed = (struct lysp_node_case *)siblings;
3335 assert_string_equal(parsed->name, "case-name");
3336 assert_null(parsed->parent);
3337 assert_int_equal(parsed->nodetype, LYS_CASE);
3338 assert_true(parsed->flags & LYS_STATUS_CURR);
3339 assert_null(parsed->next);
3340 assert_string_equal(parsed->dsc, "desc");
3341 assert_string_equal(parsed->ref, "ref");
3342 assert_string_equal(parsed->when->cond, "when-cond");
3343 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02003344 assert_string_equal(parsed->child->name, "anyd");
3345 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3346 assert_string_equal(parsed->child->next->name, "anyx");
3347 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3348 assert_string_equal(parsed->child->next->next->name, "subcont");
3349 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3350 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3351 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3352 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3353 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3354 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3355 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3356 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3357 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003358 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3359 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3360 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003361 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003362 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3363 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5379d392019-07-24 10:42:03 +02003364 lysp_node_free(st->ctx, siblings);
3365 siblings = NULL;
3366
3367 /* min subelems */
3368 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003369 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003370 parsed = (struct lysp_node_case *)siblings;
3371 assert_string_equal(parsed->name, "case-name");
3372 lysp_node_free(st->ctx, siblings);
3373 siblings = NULL;
3374
3375 st->finished_correctly = true;
3376}
3377
David Sedlákb7abcfa2019-07-24 12:33:35 +02003378static void
3379test_choice_elem(void **state)
3380{
3381 struct state *st = *state;
3382 const char *data;
3383 struct lysp_node *siblings = NULL;
3384 struct tree_node_meta node_meta = {NULL, &siblings};
3385 struct lysp_node_choice *parsed = NULL;
3386
3387 /* max subelems */
3388 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3389 data = ELEMENT_WRAPPER_START
3390 "<choice name=\"choice-name\">"
3391 "<anydata name=\"anyd\"/>"
3392 "<anyxml name=\"anyx\"/>"
3393 "<case name=\"sub-case\"/>"
3394 "<choice name=\"choice\"/>"
3395 "<config value=\"true\"/>"
3396 "<container name=\"subcont\"/>"
3397 "<default value=\"def\"/>"
3398 "<description><text>desc</text></description>"
3399 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003400 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3401 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003402 "<list name=\"list\"/>"
3403 "<mandatory value=\"true\" />"
3404 "<reference><text>ref</text></reference>"
3405 "<status value=\"current\"/>"
3406 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003407 EXT_SUBELEM
David Sedlákb7abcfa2019-07-24 12:33:35 +02003408 "</choice>"
3409 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003410 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003411 parsed = (struct lysp_node_choice *)siblings;
3412 assert_string_equal(parsed->name, "choice-name");
3413 assert_null(parsed->parent);
3414 assert_int_equal(parsed->nodetype, LYS_CHOICE);
3415 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
3416 assert_null(parsed->next);
3417 assert_string_equal(parsed->dsc, "desc");
3418 assert_string_equal(parsed->ref, "ref");
3419 assert_string_equal(parsed->when->cond, "when-cond");
3420 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003421 assert_string_equal(parsed->child->name, "anyd");
3422 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3423 assert_string_equal(parsed->child->next->name, "anyx");
3424 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3425 assert_string_equal(parsed->child->next->next->name, "sub-case");
3426 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
3427 assert_string_equal(parsed->child->next->next->next->name, "choice");
3428 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
3429 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
3430 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
3431 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
3432 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
3433 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
3434 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3435 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
3436 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3437 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003438 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003439 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3440 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003441 lysp_node_free(st->ctx, siblings);
3442 siblings = NULL;
3443
3444 /* min subelems */
3445 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003446 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003447 parsed = (struct lysp_node_choice *)siblings;
3448 assert_string_equal(parsed->name, "choice-name");
3449 lysp_node_free(st->ctx, siblings);
3450 siblings = NULL;
3451
3452 st->finished_correctly = true;
3453}
3454
David Sedlák05404f62019-07-24 14:11:53 +02003455static void
3456test_inout_elem(void **state)
3457{
3458 struct state *st = *state;
3459 const char *data;
3460 struct lysp_action_inout inout = {};
3461 struct inout_meta inout_meta = {NULL, &inout};
3462
3463 /* max subelements */
3464 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3465 data = ELEMENT_WRAPPER_START
3466 "<input>"
3467 "<anydata name=\"anyd\"/>"
3468 "<anyxml name=\"anyx\"/>"
3469 "<choice name=\"choice\"/>"
3470 "<container name=\"subcont\"/>"
3471 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003472 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3473 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003474 "<list name=\"list\"/>"
3475 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003476 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003477 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003478 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003479 "</input>"
3480 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003481 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003482 assert_null(inout.parent);
3483 assert_int_equal(inout.nodetype, LYS_INPUT);
3484 assert_string_equal(inout.musts->arg, "cond");
3485 assert_string_equal(inout.typedefs->name, "tpdf");
3486 assert_string_equal(inout.groupings->name, "sub-grp");
3487 assert_string_equal(inout.data->name, "anyd");
3488 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3489 assert_string_equal(inout.data->next->name, "anyx");
3490 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3491 assert_string_equal(inout.data->next->next->name, "choice");
3492 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3493 assert_string_equal(inout.data->next->next->next->name, "subcont");
3494 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3495 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3496 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3497 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3498 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3499 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3500 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3501 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3502 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3503 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003504 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003505 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3506 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003507 lysp_action_inout_free(st->ctx, &inout);
3508 memset(&inout, 0, sizeof inout);
3509
3510 /* max subelements */
3511 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3512 data = ELEMENT_WRAPPER_START
3513 "<output>"
3514 "<anydata name=\"anyd\"/>"
3515 "<anyxml name=\"anyx\"/>"
3516 "<choice name=\"choice\"/>"
3517 "<container name=\"subcont\"/>"
3518 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003519 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3520 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003521 "<list name=\"list\"/>"
3522 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003523 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003524 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003525 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003526 "</output>"
3527 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003528 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003529 assert_null(inout.parent);
3530 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3531 assert_string_equal(inout.musts->arg, "cond");
3532 assert_string_equal(inout.typedefs->name, "tpdf");
3533 assert_string_equal(inout.groupings->name, "sub-grp");
3534 assert_string_equal(inout.data->name, "anyd");
3535 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3536 assert_string_equal(inout.data->next->name, "anyx");
3537 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3538 assert_string_equal(inout.data->next->next->name, "choice");
3539 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3540 assert_string_equal(inout.data->next->next->next->name, "subcont");
3541 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3542 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3543 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3544 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3545 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3546 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3547 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3548 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3549 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3550 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003551 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003552 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3553 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003554 lysp_action_inout_free(st->ctx, &inout);
3555 memset(&inout, 0, sizeof inout);
3556
3557 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003558 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003559 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003560 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003561 memset(&inout, 0, sizeof inout);
3562
Michal Vaskob83af8a2020-01-06 09:49:22 +01003563 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003564 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003565 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003566 memset(&inout, 0, sizeof inout);
3567
3568 /* invalid combinations */
3569 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003570 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02003571 logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003572 memset(&inout, 0, sizeof inout);
3573
3574 st->finished_correctly = true;
3575}
3576
David Sedlák85d0eca2019-07-24 15:15:21 +02003577static void
3578test_action_elem(void **state)
3579{
3580 struct state *st = *state;
3581 const char *data;
3582 struct lysp_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003583 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
David Sedlák85d0eca2019-07-24 15:15:21 +02003584
3585 /* max subelems */
3586 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3587 data = ELEMENT_WRAPPER_START
3588 "<action name=\"act\">"
3589 "<description><text>desc</text></description>"
3590 "<grouping name=\"grouping\"/>"
3591 "<if-feature name=\"iff\"/>"
3592 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003593 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003594 "<reference><text>ref</text></reference>"
3595 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003596 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003597 EXT_SUBELEM
David Sedlák85d0eca2019-07-24 15:15:21 +02003598 "</action>"
3599 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003600 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003601 assert_null(actions->parent);
3602 assert_int_equal(actions->nodetype, LYS_ACTION);
3603 assert_true(actions->flags & LYS_STATUS_DEPRC);
3604 assert_string_equal(actions->name, "act");
3605 assert_string_equal(actions->dsc, "desc");
3606 assert_string_equal(actions->ref, "ref");
3607 assert_string_equal(*actions->iffeatures, "iff");
3608 assert_string_equal(actions->typedefs->name, "tpdf");
3609 assert_string_equal(actions->groupings->name, "grouping");
3610 assert_string_equal(actions->input.data->name, "uses-name");
3611 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003612 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003613 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3614 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák85d0eca2019-07-24 15:15:21 +02003615 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3616 actions = NULL;
3617
David Sedlákeaa45792019-07-24 15:25:01 +02003618 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3619 data = ELEMENT_WRAPPER_START
3620 "<rpc name=\"act\">"
3621 "<description><text>desc</text></description>"
3622 "<grouping name=\"grouping\"/>"
3623 "<if-feature name=\"iff\"/>"
3624 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003625 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlákeaa45792019-07-24 15:25:01 +02003626 "<reference><text>ref</text></reference>"
3627 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003628 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003629 EXT_SUBELEM
David Sedlákeaa45792019-07-24 15:25:01 +02003630 "</rpc>"
3631 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003632 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlákeaa45792019-07-24 15:25:01 +02003633 assert_null(actions->parent);
3634 assert_int_equal(actions->nodetype, LYS_ACTION);
3635 assert_true(actions->flags & LYS_STATUS_DEPRC);
3636 assert_string_equal(actions->name, "act");
3637 assert_string_equal(actions->dsc, "desc");
3638 assert_string_equal(actions->ref, "ref");
3639 assert_string_equal(*actions->iffeatures, "iff");
3640 assert_string_equal(actions->typedefs->name, "tpdf");
3641 assert_string_equal(actions->groupings->name, "grouping");
3642 assert_string_equal(actions->input.data->name, "uses-name");
3643 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003644 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003645 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3646 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákeaa45792019-07-24 15:25:01 +02003647 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3648 actions = NULL;
3649
David Sedlák85d0eca2019-07-24 15:15:21 +02003650 /* min subelems */
3651 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003652 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003653 assert_string_equal(actions->name, "act");
3654 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3655 actions = NULL;
3656
3657 st->finished_correctly = true;
3658}
3659
David Sedlák992fb7c2019-07-24 16:51:01 +02003660static void
3661test_augment_elem(void **state)
3662{
3663 struct state *st = *state;
3664 const char *data;
3665 struct lysp_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003666 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003667
3668 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3669 data = ELEMENT_WRAPPER_START
3670 "<augment target-node=\"target\">"
3671 "<action name=\"action\"/>"
3672 "<anydata name=\"anyd\"/>"
3673 "<anyxml name=\"anyx\"/>"
3674 "<case name=\"case\"/>"
3675 "<choice name=\"choice\"/>"
3676 "<container name=\"subcont\"/>"
3677 "<description><text>desc</text></description>"
3678 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003679 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3680 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003681 "<list name=\"list\"/>"
3682 "<notification name=\"notif\"/>"
3683 "<reference><text>ref</text></reference>"
3684 "<status value=\"current\"/>"
3685 "<uses name=\"uses\"/>"
3686 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003687 EXT_SUBELEM
David Sedlák992fb7c2019-07-24 16:51:01 +02003688 "</augment>"
3689 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003690 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003691 assert_string_equal(augments->nodeid, "target");
3692 assert_null(augments->parent);
3693 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3694 assert_true(augments->flags & LYS_STATUS_CURR);
3695 assert_string_equal(augments->dsc, "desc");
3696 assert_string_equal(augments->ref, "ref");
3697 assert_string_equal(augments->when->cond, "when-cond");
3698 assert_string_equal(*augments->iffeatures, "iff");
3699 assert_string_equal(augments->child->name, "anyd");
3700 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3701 assert_string_equal(augments->child->next->name, "anyx");
3702 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3703 assert_string_equal(augments->child->next->next->name, "case");
3704 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3705 assert_string_equal(augments->child->next->next->next->name, "choice");
3706 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3707 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3708 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3709 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3710 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3711 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3712 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3713 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3714 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3715 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3716 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3717 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3718 assert_string_equal(augments->actions->name, "action");
3719 assert_string_equal(augments->notifs->name, "notif");
David Sedláke0ef1c62019-09-13 10:05:55 +02003720 assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003721 assert_int_equal(augments->exts[0].insubstmt_index, 0);
3722 assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák992fb7c2019-07-24 16:51:01 +02003723 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3724 augments = NULL;
3725
3726 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003727 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003728 assert_string_equal(augments->nodeid, "target");
3729 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3730 augments = NULL;
3731
3732 st->finished_correctly = true;
3733}
3734
David Sedlák4ffcec82019-07-25 15:10:21 +02003735static void
3736test_deviate_elem(void **state)
3737{
3738 struct state *st = *state;
3739 const char *data;
3740 struct lysp_deviate *deviates = NULL;
3741 struct lysp_deviate_add *d_add;
3742 struct lysp_deviate_rpl *d_rpl;
3743 struct lysp_deviate_del *d_del;
3744
3745 /* all valid arguments with min subelems */
3746 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003747 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003748 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3749 lysp_deviate_free(st->ctx, deviates);
3750 free(deviates);
3751 deviates = NULL;
3752
3753 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003754 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003755 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3756 lysp_deviate_free(st->ctx, deviates);
3757 free(deviates);
3758 deviates = NULL;
3759
3760 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003761 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003762 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3763 lysp_deviate_free(st->ctx, deviates);
3764 free(deviates);
3765 deviates = NULL;
3766
3767 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003768 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003769 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3770 lysp_deviate_free(st->ctx, deviates);
3771 free(deviates);
3772 deviates = NULL;
3773
3774 /* max subelems and valid arguments */
3775 data = ELEMENT_WRAPPER_START
3776 "<deviate value=\"not-supported\">"
David Sedlákd1144562019-08-06 12:36:14 +02003777 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003778 "</deviate>"
3779 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003780 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003781 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
David Sedláke0ef1c62019-09-13 10:05:55 +02003782 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003783 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3784 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003785 lysp_deviate_free(st->ctx, deviates);
3786 free(deviates);
3787 deviates = NULL;
3788
3789 data = ELEMENT_WRAPPER_START
3790 "<deviate value=\"add\">"
3791 "<units name=\"units\"/>"
3792 "<must condition=\"cond\"/>"
3793 "<unique tag=\"utag\"/>"
3794 "<default value=\"def\"/>"
3795 "<config value=\"true\"/>"
3796 "<mandatory value=\"true\"/>"
3797 "<min-elements value=\"5\"/>"
3798 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003799 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003800 "</deviate>"
3801 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003802 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003803 d_add = (struct lysp_deviate_add *)deviates;
3804 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3805 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003806 assert_string_equal(d_add->units, "units");
3807 assert_string_equal(d_add->musts->arg, "cond");
3808 assert_string_equal(*d_add->uniques, "utag");
3809 assert_string_equal(*d_add->dflts, "def");
3810 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3811 assert_int_equal(d_add->min, 5);
3812 assert_int_equal(d_add->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003813 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003814 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3815 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003816 lysp_deviate_free(st->ctx, deviates);
3817 free(deviates);
3818 deviates = NULL;
3819
3820 data = ELEMENT_WRAPPER_START
3821 "<deviate value=\"replace\">"
3822 "<type name=\"newtype\"/>"
3823 "<units name=\"uni\"/>"
3824 "<default value=\"def\"/>"
3825 "<config value=\"true\"/>"
3826 "<mandatory value=\"true\"/>"
3827 "<min-elements value=\"5\"/>"
3828 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003829 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003830 "</deviate>"
3831 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003832 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003833 d_rpl = (struct lysp_deviate_rpl *)deviates;
3834 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3835 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003836 assert_string_equal(d_rpl->type->name, "newtype");
3837 assert_string_equal(d_rpl->units, "uni");
3838 assert_string_equal(d_rpl->dflt, "def");
3839 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3840 assert_int_equal(d_rpl->min, 5);
3841 assert_int_equal(d_rpl->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003842 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003843 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3844 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003845 lysp_deviate_free(st->ctx, deviates);
3846 free(deviates);
3847 deviates = NULL;
3848
3849 data = ELEMENT_WRAPPER_START
3850 "<deviate value=\"delete\">"
3851 "<units name=\"u\"/>"
3852 "<must condition=\"c\"/>"
3853 "<unique tag=\"tag\"/>"
3854 "<default value=\"default\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003855 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003856 "</deviate>"
3857 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003858 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003859 d_del = (struct lysp_deviate_del *)deviates;
3860 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3861 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003862 assert_string_equal(d_del->units, "u");
3863 assert_string_equal(d_del->musts->arg, "c");
3864 assert_string_equal(*d_del->uniques, "tag");
3865 assert_string_equal(*d_del->dflts, "default");
David Sedláke0ef1c62019-09-13 10:05:55 +02003866 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003867 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3868 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003869 lysp_deviate_free(st->ctx, deviates);
3870 free(deviates);
3871 deviates = NULL;
3872
3873 /* invalid arguments */
3874 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003875 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003876 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 +02003877 deviates = NULL;
3878
3879 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003880 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003881 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 +02003882 deviates = NULL;
3883
3884 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003885 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003886 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 +02003887 deviates = NULL;
3888
3889 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003890 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003891 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 +02003892 deviates = NULL;
3893
3894 data = ELEMENT_WRAPPER_START
3895 "<deviate value=\"not-supported\">"
3896 "<must condition=\"c\"/>"
3897 "</deviate>"
3898 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003899 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák4ffcec82019-07-25 15:10:21 +02003900 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3901
3902 st->finished_correctly = true;
3903}
3904
David Sedlák8b754462019-07-25 16:22:13 +02003905static void
3906test_deviation_elem(void **state)
3907{
3908 struct state *st = *state;
3909 const char *data;
3910 struct lysp_deviation *deviations = NULL;
3911
3912 /* min subelems */
3913 data = ELEMENT_WRAPPER_START
3914 "<deviation target-node=\"target\">"
3915 "<deviate value=\"not-supported\"/>"
3916 "</deviation>"
3917 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003918 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003919 assert_string_equal(deviations->nodeid, "target");
3920 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3921 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3922 deviations = NULL;
3923
3924 /* max subelems */
3925 data = ELEMENT_WRAPPER_START
3926 "<deviation target-node=\"target\">"
3927 "<reference><text>ref</text></reference>"
3928 "<description><text>desc</text></description>"
3929 "<deviate value=\"add\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003930 EXT_SUBELEM
David Sedlák8b754462019-07-25 16:22:13 +02003931 "</deviation>"
3932 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003933 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003934 assert_string_equal(deviations->nodeid, "target");
3935 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3936 assert_string_equal(deviations->ref, "ref");
3937 assert_string_equal(deviations->dsc, "desc");
David Sedláke0ef1c62019-09-13 10:05:55 +02003938 assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003939 assert_int_equal(deviations->exts[0].insubstmt_index, 0);
3940 assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8b754462019-07-25 16:22:13 +02003941 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3942 deviations = NULL;
3943
3944 /* invalid */
3945 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003946 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID);
David Sedlák8b754462019-07-25 16:22:13 +02003947 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3948 deviations = NULL;
David Sedlák1538a842019-08-08 15:38:51 +02003949 logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
3950 /* TODO */
David Sedlák8b754462019-07-25 16:22:13 +02003951 st->finished_correctly = true;
3952}
3953
David Sedlák4f03b932019-07-26 13:01:47 +02003954static void
3955test_module_elem(void **state)
3956{
3957 struct state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01003958 const char *data;
David Sedlák4f03b932019-07-26 13:01:47 +02003959 struct lys_module *lys_mod = NULL;
3960 struct lysp_module *lysp_mod = NULL;
3961
3962 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003963 lys_mod = calloc(1, sizeof *lys_mod);
3964 lysp_mod = calloc(1, sizeof *lysp_mod);
3965 lys_mod->ctx = st->ctx;
3966 lysp_mod->mod = lys_mod;
3967 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3968 "<yang-version value=\"1.1\"/>\n"
3969 "<namespace uri=\"ns\"/>\n"
3970 "<prefix value=\"pref\"/>\n"
3971 "<include module=\"b-mod\"/>\n"
3972 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3973 "<organization><text>org</text></organization>\n"
3974 "<contact><text>contact</text></contact>\n"
3975 "<description><text>desc</text></description>"
3976 "<reference><text>ref</text></reference>\n"
3977 "<revision date=\"2019-02-02\"/>\n"
3978 "<anydata name=\"anyd\"/>\n"
3979 "<anyxml name=\"anyx\"/>\n"
3980 "<choice name=\"choice\"/>\n"
3981 "<container name=\"cont\"/>\n"
3982 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3983 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3984 "<list name=\"sub-list\"/>\n"
3985 "<uses name=\"uses-name\"/>\n"
3986 "<augment target-node=\"target\"/>\n"
3987 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3988 "<extension name=\"ext\"/>\n"
3989 "<feature name=\"feature\"/>\n"
3990 "<grouping name=\"grp\"/>\n"
3991 "<identity name=\"ident-name\"/>\n"
3992 "<notification name=\"notf\"/>\n"
3993 "<rpc name=\"rpc-name\"/>\n"
3994 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02003995 EXT_SUBELEM"\n"
David Sedlák4f03b932019-07-26 13:01:47 +02003996 "</module>\n";
Michal Vaskob36053d2020-03-26 15:49:30 +01003997 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3998
3999 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02004000 assert_string_equal(lysp_mod->mod->name, "mod");
4001 assert_string_equal(lysp_mod->revs, "2019-02-02");
4002 assert_string_equal(lysp_mod->mod->ns, "ns");
4003 assert_string_equal(lysp_mod->mod->prefix, "pref");
4004 assert_null(lysp_mod->mod->filepath);
4005 assert_string_equal(lysp_mod->mod->org, "org");
4006 assert_string_equal(lysp_mod->mod->contact, "contact");
4007 assert_string_equal(lysp_mod->mod->dsc, "desc");
4008 assert_string_equal(lysp_mod->mod->ref, "ref");
4009 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
4010 assert_string_equal(lysp_mod->imports->name, "a-mod");
4011 assert_string_equal(lysp_mod->includes->name, "b-mod");
4012 assert_string_equal(lysp_mod->extensions->name, "ext");
4013 assert_string_equal(lysp_mod->features->name, "feature");
4014 assert_string_equal(lysp_mod->identities->name, "ident-name");
4015 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
4016 assert_string_equal(lysp_mod->groupings->name, "grp");
4017 assert_string_equal(lysp_mod->data->name, "anyd");
4018 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
4019 assert_string_equal(lysp_mod->data->next->name, "anyx");
4020 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
4021 assert_string_equal(lysp_mod->data->next->next->name, "choice");
4022 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
4023 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
4024 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
4025 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
4026 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
4027 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
4028 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4029 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
4030 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4031 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
4032 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4033 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
4034 assert_string_equal(lysp_mod->augments->nodeid, "target");
4035 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
4036 assert_string_equal(lysp_mod->notifs->name, "notf");
4037 assert_string_equal(lysp_mod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004038 assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004039 assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
4040 assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4f03b932019-07-26 13:01:47 +02004041 lysp_module_free(lysp_mod);
4042 lys_module_free(lys_mod, NULL);
David Sedlák4f03b932019-07-26 13:01:47 +02004043
4044 /* min subelems */
Michal Vaskob36053d2020-03-26 15:49:30 +01004045 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák4f03b932019-07-26 13:01:47 +02004046 lys_mod = calloc(1, sizeof *lys_mod);
4047 lysp_mod = calloc(1, sizeof *lysp_mod);
4048 lys_mod->ctx = st->ctx;
4049 lysp_mod->mod = lys_mod;
4050 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
4051 "<namespace uri=\"ns\"/>"
4052 "<prefix value=\"pref\"/>"
4053 "<yang-version value=\"1.1\"/>"
4054 "</module>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004055 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4056 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004057 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák4f03b932019-07-26 13:01:47 +02004058 lysp_module_free(lysp_mod);
4059 lys_module_free(lys_mod, NULL);
David Sedlák298ff6d2019-07-26 14:29:03 +02004060
David Sedláke6cd89e2019-08-07 12:46:02 +02004061 /* incorrect subelem order */
Michal Vaskob36053d2020-03-26 15:49:30 +01004062 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02004063 lys_mod = calloc(1, sizeof *lys_mod);
4064 lysp_mod = calloc(1, sizeof *lysp_mod);
4065 lys_mod->ctx = st->ctx;
4066 lysp_mod->mod = lys_mod;
4067 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
4068 "<feature name=\"feature\"/>\n"
4069 "<namespace uri=\"ns\"/>"
4070 "<prefix value=\"pref\"/>"
4071 "<yang-version value=\"1.1\"/>"
4072 "</module>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004073 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4074 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
4075 logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 2.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004076 lysp_module_free(lysp_mod);
4077 lys_module_free(lys_mod, NULL);
David Sedláke6cd89e2019-08-07 12:46:02 +02004078
David Sedlák298ff6d2019-07-26 14:29:03 +02004079 st->finished_correctly = true;
4080}
4081
4082static void
4083test_submodule_elem(void **state)
4084{
4085 struct state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01004086 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02004087 struct lysp_submodule *lysp_submod = NULL;
4088
4089 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02004090 lysp_submod = calloc(1, sizeof *lysp_submod);
4091 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
4092 "<yang-version value=\"1.1\"/>\n"
4093 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4094 "<include module=\"b-mod\"/>\n"
4095 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
4096 "<organization><text>org</text></organization>\n"
4097 "<contact><text>contact</text></contact>\n"
4098 "<description><text>desc</text></description>"
4099 "<reference><text>ref</text></reference>\n"
4100 "<revision date=\"2019-02-02\"/>\n"
4101 "<anydata name=\"anyd\"/>\n"
4102 "<anyxml name=\"anyx\"/>\n"
4103 "<choice name=\"choice\"/>\n"
4104 "<container name=\"cont\"/>\n"
4105 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
4106 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
4107 "<list name=\"sub-list\"/>\n"
4108 "<uses name=\"uses-name\"/>\n"
4109 "<augment target-node=\"target\"/>\n"
4110 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
4111 "<extension name=\"ext\"/>\n"
4112 "<feature name=\"feature\"/>\n"
4113 "<grouping name=\"grp\"/>\n"
4114 "<identity name=\"ident-name\"/>\n"
4115 "<notification name=\"notf\"/>\n"
4116 "<rpc name=\"rpc-name\"/>\n"
4117 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004118 EXT_SUBELEM"\n"
David Sedlák298ff6d2019-07-26 14:29:03 +02004119 "</submodule>\n";
Michal Vaskob36053d2020-03-26 15:49:30 +01004120 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4121 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004122
4123 assert_string_equal(lysp_submod->name, "mod");
4124 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02004125 assert_string_equal(lysp_submod->prefix, "pref");
4126 assert_null(lysp_submod->filepath);
4127 assert_string_equal(lysp_submod->org, "org");
4128 assert_string_equal(lysp_submod->contact, "contact");
4129 assert_string_equal(lysp_submod->dsc, "desc");
4130 assert_string_equal(lysp_submod->ref, "ref");
4131 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
4132 assert_string_equal(lysp_submod->imports->name, "a-mod");
4133 assert_string_equal(lysp_submod->includes->name, "b-mod");
4134 assert_string_equal(lysp_submod->extensions->name, "ext");
4135 assert_string_equal(lysp_submod->features->name, "feature");
4136 assert_string_equal(lysp_submod->identities->name, "ident-name");
4137 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
4138 assert_string_equal(lysp_submod->groupings->name, "grp");
4139 assert_string_equal(lysp_submod->data->name, "anyd");
4140 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
4141 assert_string_equal(lysp_submod->data->next->name, "anyx");
4142 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
4143 assert_string_equal(lysp_submod->data->next->next->name, "choice");
4144 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
4145 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
4146 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
4147 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
4148 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
4149 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
4150 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4151 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
4152 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4153 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
4154 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4155 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
4156 assert_string_equal(lysp_submod->augments->nodeid, "target");
4157 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
4158 assert_string_equal(lysp_submod->notifs->name, "notf");
4159 assert_string_equal(lysp_submod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004160 assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004161 assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
4162 assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák298ff6d2019-07-26 14:29:03 +02004163
4164 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004165
4166 /* min subelemnts */
Michal Vaskob36053d2020-03-26 15:49:30 +01004167 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák298ff6d2019-07-26 14:29:03 +02004168 lysp_submod = calloc(1, sizeof *lysp_submod);
4169 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4170 "<yang-version value=\"1.0\"/>"
4171 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4172 "</submodule>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004173 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4174 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004175 assert_string_equal(lysp_submod->prefix, "pref");
4176 assert_string_equal(lysp_submod->belongsto, "mod-name");
4177 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
4178 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004179
David Sedláke6cd89e2019-08-07 12:46:02 +02004180 /* incorrect subelem order */
Michal Vaskob36053d2020-03-26 15:49:30 +01004181 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02004182 lysp_submod = calloc(1, sizeof *lysp_submod);
4183 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4184 "<yang-version value=\"1.0\"/>"
4185 "<reference><text>ref</text></reference>\n"
4186 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4187 "</submodule>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004188 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4189 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
4190 logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 2.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004191 lysp_submodule_free(st->ctx, lysp_submod);
David Sedláke6cd89e2019-08-07 12:46:02 +02004192
David Sedlák298ff6d2019-07-26 14:29:03 +02004193 st->finished_correctly = true;
David Sedlák4f03b932019-07-26 13:01:47 +02004194}
4195
David Sedlák8985a142019-07-31 16:43:06 +02004196static void
4197test_yin_parse_module(void **state)
4198{
4199 struct state *st = *state;
4200 const char *data;
4201 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01004202 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004203
4204 mod = calloc(1, sizeof *mod);
4205 mod->ctx = st->ctx;
David Sedlákd2844882019-09-13 16:01:22 +02004206 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"
4207 "<yang-version value=\"1.1\"/>\n"
4208 "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
4209 "<prefix value=\"a\"/>\n"
4210 "<import module=\"ietf-yang-metadata\">\n"
4211 "<prefix value=\"md\"/>\n"
4212 "</import>\n"
4213 "<feature name=\"f\"/>\n"
4214 "<md:annotation name=\"x\">\n"
4215 "<description>\n"
4216 "<text>test</text>\n"
4217 "</description>\n"
4218 "<reference>\n"
4219 "<text>test</text>\n"
4220 "</reference>\n"
4221 "<if-feature name=\"f\"/>\n"
4222 "<status value=\"current\"/>\n"
4223 "<type name=\"uint8\"/>\n"
4224 "<units name=\"meters\"/>\n"
4225 "</md:annotation>\n"
4226 "</module>\n";
4227 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4228 assert_null(mod->parsed->exts->child->next->child);
4229 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
4230 lys_module_free(mod, NULL);
4231 yin_parser_ctx_free(yin_ctx);
4232 mod = NULL;
4233 yin_ctx = NULL;
4234
4235 mod = calloc(1, sizeof *mod);
4236 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004237 data = "<module name=\"example-foo\""
4238 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4239 "xmlns:foo=\"urn:example:foo\""
4240 "xmlns:myext=\"urn:example:extensions\">\n"
4241
4242 "<yang-version value=\"1.0\"/>\n"
4243
4244 "<namespace uri=\"urn:example:foo\"/>\n"
4245 "<prefix value=\"foo\"/>\n"
4246
4247 "<import module=\"example-extensions\">\n"
David Sedlák6d781b62019-08-02 15:22:52 +02004248 "<prefix value=\"myext\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02004249 "</import>\n"
4250
4251 "<list name=\"interface\">\n"
4252 "<key value=\"name\"/>\n"
4253 "<leaf name=\"name\">\n"
4254 "<type name=\"string\"/>\n"
4255 "</leaf>\n"
4256 "<leaf name=\"mtu\">\n"
4257 "<type name=\"uint32\"/>\n"
4258 "<description>\n"
4259 "<text>The MTU of the interface.</text>\n"
4260 "</description>\n"
4261 "<myext:c-define name=\"MY_MTU\"/>\n"
4262 "</leaf>\n"
4263 "</list>\n"
4264 "</module>\n";
4265 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4266 lys_module_free(mod, NULL);
4267 yin_parser_ctx_free(yin_ctx);
4268 mod = NULL;
4269 yin_ctx = NULL;
4270
4271 mod = calloc(1, sizeof *mod);
4272 mod->ctx = st->ctx;
David Sedlák6d781b62019-08-02 15:22:52 +02004273 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4274 "<yang-version value=\"1.0\"/>\n"
4275 "<namespace uri=\"urn:example:foo\"/>\n"
4276 "<prefix value=\"foo\"/>\n"
4277 "</module>\n";
4278 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4279 lys_module_free(mod, NULL);
4280 yin_parser_ctx_free(yin_ctx);
4281 mod = NULL;
4282 yin_ctx = NULL;
4283
4284
4285 mod = calloc(1, sizeof *mod);
4286 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004287 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4288 "</submodule>\n";
4289 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL);
4290 logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
4291 lys_module_free(mod, NULL);
4292 yin_parser_ctx_free(yin_ctx);
4293
David Sedlák6d781b62019-08-02 15:22:52 +02004294 mod = calloc(1, sizeof *mod);
4295 mod->ctx = st->ctx;
4296 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4297 "<yang-version value=\"1.0\"/>\n"
4298 "<namespace uri=\"urn:example:foo\"/>\n"
4299 "<prefix value=\"foo\"/>\n"
4300 "</module>"
4301 "<module>";
4302 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID);
4303 logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
4304 lys_module_free(mod, NULL);
4305 yin_parser_ctx_free(yin_ctx);
4306 mod = NULL;
4307 yin_ctx = NULL;
4308
David Sedlák8985a142019-07-31 16:43:06 +02004309 st->finished_correctly = true;
4310}
4311
4312static void
4313test_yin_parse_submodule(void **state)
4314{
4315 struct state *st = *state;
4316 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01004317 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004318 struct lysp_submodule *submod = NULL;
David Sedlák1b623122019-08-05 15:27:49 +02004319 struct lys_parser_ctx main_ctx = {};
David Sedlák8985a142019-07-31 16:43:06 +02004320
4321 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4322 "<submodule name=\"asub\""
4323 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4324 "xmlns:a=\"urn:a\">"
4325 "<yang-version value=\"1.0\"/>\n"
4326 "<belongs-to module=\"a\">"
4327 "<prefix value=\"a_pref\"/>"
4328 "</belongs-to>"
4329 "<include module=\"atop\"/>"
4330 "<feature name=\"fox\"/>"
4331 "<notification name=\"bar-notif\">"
4332 "<if-feature name=\"bar\"/>"
4333 "</notification>"
4334 "<notification name=\"fox-notif\">"
4335 "<if-feature name=\"fox\"/>"
4336 "</notification>"
4337 "<augment target-node=\"/a_pref:top\">"
4338 "<if-feature name=\"bar\"/>"
4339 "<container name=\"bar-sub\"/>"
4340 "</augment>"
4341 "<augment target-node=\"/top\">"
4342 "<container name=\"bar-sub2\"/>"
4343 "</augment>"
4344 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004345 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004346 lysp_submodule_free(st->ctx, submod);
4347 yin_parser_ctx_free(yin_ctx);
4348 yin_ctx = NULL;
4349 submod = NULL;
4350
4351 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák6d781b62019-08-02 15:22:52 +02004352 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4353 "<yang-version value=\"1.0\"/>\n"
4354 "<belongs-to module=\"a\">"
4355 "<prefix value=\"a_pref\"/>"
4356 "</belongs-to>"
4357 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004358 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004359 lysp_submodule_free(st->ctx, submod);
4360 yin_parser_ctx_free(yin_ctx);
4361 yin_ctx = NULL;
4362 submod = NULL;
4363
4364 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák8985a142019-07-31 16:43:06 +02004365 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4366 "</module>";
David Sedlák1b623122019-08-05 15:27:49 +02004367 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004368 logbuf_assert("Input data contains module in situation when a submodule is expected.");
4369 lysp_submodule_free(st->ctx, submod);
4370 yin_parser_ctx_free(yin_ctx);
4371 yin_ctx = NULL;
4372 submod = NULL;
4373
David Sedlák6d781b62019-08-02 15:22:52 +02004374 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4375 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4376 "<yang-version value=\"1.0\"/>\n"
4377 "<belongs-to module=\"a\">"
4378 "<prefix value=\"a_pref\"/>"
4379 "</belongs-to>"
4380 "</submodule>"
4381 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4382 "<yang-version value=\"1.0\"/>\n"
4383 "<belongs-to module=\"a\">"
4384 "<prefix value=\"a_pref\"/>"
4385 "</belongs-to>"
4386 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004387 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004388 logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
4389 lysp_submodule_free(st->ctx, submod);
4390 yin_parser_ctx_free(yin_ctx);
4391 yin_ctx = NULL;
4392 submod = NULL;
4393
David Sedlák8985a142019-07-31 16:43:06 +02004394 st->finished_correctly = true;
4395}
4396
David Sedlák3b4db242018-10-19 16:11:01 +02004397int
4398main(void)
4399{
4400
4401 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02004402 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02004403 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
4404 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák071f7662019-09-12 02:02:51 +02004405 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02004406 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02004407
David Sedlák8e7bda82019-07-16 17:57:50 +02004408 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák43801c92019-08-05 15:58:54 +02004409 cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test),
4410 cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test),
David Sedlák32488102019-07-15 17:44:10 +02004411 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
4412 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
4413 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
4414 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
4415 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
4416 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
4417 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004418 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
4419 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
4420 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
4421 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
4422 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
4423 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
4424 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
4425 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
4426 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
4427 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
4428 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
4429 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
4430 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
4431 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
4432 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02004433 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
4434 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
4435 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
4436 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
4437 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
4438 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
4439 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
4440 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02004441 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02004442 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02004443 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02004444 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02004445 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02004446 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02004447 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02004448 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02004449 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02004450 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02004451 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02004452 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02004453 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02004454 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlák5e13dea2019-07-22 16:06:45 +02004455 cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
David Sedlák28794f22019-07-22 16:45:00 +02004456 cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02004457 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02004458 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02004459 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02004460 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02004461 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02004462 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02004463 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02004464 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02004465 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02004466 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02004467 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02004468 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák298ff6d2019-07-26 14:29:03 +02004469 cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test),
David Sedlák8985a142019-07-31 16:43:06 +02004470
4471 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger),
4472 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger),
David Sedlák3b4db242018-10-19 16:11:01 +02004473 };
4474
David Sedlák8e7bda82019-07-16 17:57:50 +02004475 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02004476}