blob: 80736c9876b242ee6f675c177748269d1c03eefb [file] [log] [blame]
David Sedlákb1ce3f82019-06-05 14:37:26 +02001/**
2 * @file test_parser_yin.c
3 * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
4 * @brief unit tests for functions from parser_yin.c
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
David Sedlák3b4db242018-10-19 16:11:01 +020015#include <stdarg.h>
16#include <stddef.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20#include <stdio.h>
21#include <string.h>
David Sedlák79e50cb2019-06-05 16:33:09 +020022#include <stdbool.h>
David Sedlák3b4db242018-10-19 16:11:01 +020023
David Sedlákecf5eb82019-06-03 14:12:44 +020024#include "../../src/common.h"
25#include "../../src/tree_schema.h"
26#include "../../src/tree_schema_internal.h"
27#include "../../src/parser_yin.h"
David Sedlák8f5bce02019-06-03 16:41:08 +020028#include "../../src/xml.h"
David Sedlák3b4db242018-10-19 16:11:01 +020029
David Sedlák555c7202019-07-04 12:14:12 +020030/* prototypes of static functions */
31void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +020032void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +020033void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +020034void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +020035void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +020036void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +020037void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +020038void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +020039void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +020040void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +020041void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
David Sedlák031b9e72019-07-23 15:19:37 +020042void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
David Sedláke3ce9ef2019-07-23 16:34:30 +020043void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
David Sedlák05404f62019-07-24 14:11:53 +020044void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
David Sedlák85d0eca2019-07-24 15:15:21 +020045void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
David Sedlák992fb7c2019-07-24 16:51:01 +020046void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +020047void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +020048void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +020049void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod);
50void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +020051
David Sedláke6cd89e2019-08-07 12:46:02 +020052/* wrapping element used for mocking has nothing to do with real module structure */
53#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
54#define ELEMENT_WRAPPER_END "</status>"
55
David Sedlák68a1af12019-03-08 13:46:54 +010056struct state {
David Sedlák3b4db242018-10-19 16:11:01 +020057 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010058 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020059 struct lysp_module *lysp_mod;
David Sedlákda8ffa32019-07-08 14:17:10 +020060 struct yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020061 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010062};
David Sedlák872c7b42018-10-26 13:15:20 +020063
David Sedlák79e50cb2019-06-05 16:33:09 +020064#define BUFSIZE 1024
65char logbuf[BUFSIZE] = {0};
66int store = -1; /* negative for infinite logging, positive for limited logging */
67
68/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedlákaa98bba2019-09-12 11:52:14 +020069#define ENABLE_LOGGER_CHECKING 0
David Sedlák79e50cb2019-06-05 16:33:09 +020070
71#if ENABLE_LOGGER_CHECKING
72static void
73logger(LY_LOG_LEVEL level, const char *msg, const char *path)
74{
75 (void) level; /* unused */
76 if (store) {
77 if (path && path[0]) {
78 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
79 } else {
80 strncpy(logbuf, msg, BUFSIZE - 1);
81 }
82 if (store > 0) {
83 --store;
84 }
85 }
86}
87#endif
88
89#if ENABLE_LOGGER_CHECKING
90# define logbuf_assert(str) assert_string_equal(logbuf, str)
91#else
92# define logbuf_assert(str)
93#endif
94
95#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
96 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
97 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
98 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
99 CLEANUP
100
David Sedlák8e7bda82019-07-16 17:57:50 +0200101int
102setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100103{
104 struct state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +0200105
David Sedlák68a1af12019-03-08 13:46:54 +0100106 /* allocate state variable */
107 (*state) = st = calloc(1, sizeof(*st));
108 if (!st) {
109 fprintf(stderr, "Memmory allocation failed");
110 return EXIT_FAILURE;
111 }
David Sedlák872c7b42018-10-26 13:15:20 +0200112
David Sedlák68a1af12019-03-08 13:46:54 +0100113 /* create new libyang context */
114 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200115
David Sedlák8e7bda82019-07-16 17:57:50 +0200116 return EXIT_SUCCESS;
117}
118
119int
120destroy_ly_ctx(void **state)
121{
122 struct state *st = *state;
123 ly_ctx_destroy(st->ctx, NULL);
124 free(st);
125
126 return EXIT_SUCCESS;
127}
128
129static int
130setup_f(void **state)
131{
132 struct state *st = *state;
133
134#if ENABLE_LOGGER_CHECKING
135 /* setup logger */
136 ly_set_log_clb(logger, 1);
137#endif
138
David Sedlák68a1af12019-03-08 13:46:54 +0100139 /* allocate new module */
140 st->mod = calloc(1, sizeof(*st->mod));
141 st->mod->ctx = st->ctx;
142
David Sedlák619db942019-07-03 14:47:30 +0200143 /* allocate new parsed module */
144 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
145 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
146 st->lysp_mod->mod->ctx = st->ctx;
147
148 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200149 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
150 st->yin_ctx->xml_ctx.ctx = st->ctx;
Radek Krejci99435242019-09-05 16:19:15 +0200151 st->yin_ctx->pos_type = LY_VLOG_LINE;
David Sedlákda8ffa32019-07-08 14:17:10 +0200152 st->yin_ctx->xml_ctx.line = 1;
David Sedlák8f5bce02019-06-03 16:41:08 +0200153
David Sedlák68a1af12019-03-08 13:46:54 +0100154 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200155}
156
157static int
David Sedlák68a1af12019-03-08 13:46:54 +0100158teardown_f(void **state)
159{
160 struct state *st = *(struct state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200161 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100162
David Sedlák79e50cb2019-06-05 16:33:09 +0200163#if ENABLE_LOGGER_CHECKING
164 /* teardown logger */
165 if (!st->finished_correctly && logbuf[0] != '\0') {
166 fprintf(stderr, "%s\n", logbuf);
167 }
168#endif
169
David Sedlák619db942019-07-03 14:47:30 +0200170 temp = st->lysp_mod->mod;
171
David Sedlákda8ffa32019-07-08 14:17:10 +0200172 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100173 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200174 lysp_module_free(st->lysp_mod);
175 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200176 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100177
178 return EXIT_SUCCESS;
179}
180
David Sedlák392af4f2019-06-04 16:02:42 +0200181static struct state*
182reset_state(void **state)
183{
David Sedlák79e50cb2019-06-05 16:33:09 +0200184 ((struct state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200185 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200186 teardown_f(state);
187 setup_f(state);
188
189 return *state;
190}
191
David Sedlák79e50cb2019-06-05 16:33:09 +0200192void
193logbuf_clean(void)
194{
195 logbuf[0] = '\0';
196}
197
David Sedlák8985a142019-07-31 16:43:06 +0200198static int
199setup_logger(void **state)
200{
201 (void)state; /* unused */
202#if ENABLE_LOGGER_CHECKING
203 /* setup logger */
204 ly_set_log_clb(logger, 1);
205#endif
206
207 logbuf[0] = '\0';
208
209 return EXIT_SUCCESS;
210}
211
212static int
213teardown_logger(void **state)
214{
215 struct state *st = *state;
216
217#if ENABLE_LOGGER_CHECKING
218 /* teardown logger */
219 if (!st->finished_correctly && logbuf[0] != '\0') {
220 fprintf(stderr, "%s\n", logbuf);
221 }
222#endif
223
224 return EXIT_SUCCESS;
225}
226
227static int
228setup_element_test(void **state)
229{
230 setup_logger(state);
231 struct state *st = *state;
232
233 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
234
235 /* allocate parser context */
236 st->yin_ctx->xml_ctx.ctx = st->ctx;
Radek Krejci99435242019-09-05 16:19:15 +0200237 st->yin_ctx->pos_type = LY_VLOG_LINE;
David Sedlák8985a142019-07-31 16:43:06 +0200238 st->yin_ctx->xml_ctx.line = 1;
239
240 return EXIT_SUCCESS;
241}
242
243static int
244teardown_element_test(void **state)
245{
246 struct state *st = *(struct state **)state;
247
248 lyxml_context_clear(&st->yin_ctx->xml_ctx);
249 free(st->yin_ctx);
250
251 teardown_logger(state);
252
253 return EXIT_SUCCESS;
254}
255
David Sedlák68a1af12019-03-08 13:46:54 +0100256static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200257test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200258{
David Sedlák8f7a1172019-06-20 14:42:18 +0200259 struct state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200260
David Sedlák8f7a1172019-06-20 14:42:18 +0200261 const char *prefix, *name;
262 struct yin_arg_record *args = NULL;
263 size_t prefix_len, name_len;
264 /* create mock yin namespace in xml context */
265 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200266 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
267 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák8f7a1172019-06-20 14:42:18 +0200268 LY_ARRAY_FREE(args);
269
Radek Krejcid6b76452019-09-03 17:03:03 +0200270 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
318 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
319 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
320 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
321 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
322 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
323 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
324 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
325 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
326 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
327 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
328 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
329 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
330 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
331 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
332 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
333 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
334 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
335 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
336 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
337 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
338 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
339 assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
David Sedlák8f7a1172019-06-20 14:42:18 +0200340
341 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200342}
David Sedlák3b4db242018-10-19 16:11:01 +0200343
David Sedlák872c7b42018-10-26 13:15:20 +0200344static void
David Sedlák060b00e2019-06-19 11:12:06 +0200345test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200346{
David Sedlák68a1af12019-03-08 13:46:54 +0100347 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200348
David Sedlák060b00e2019-06-19 11:12:06 +0200349 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
350 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
351 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
352 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
353 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
354 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
355 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
356 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
357 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
358 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
359 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
360 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200361}
362
David Sedlák68a1af12019-03-08 13:46:54 +0100363static void
David Sedlákb1a78352019-06-28 16:16:29 +0200364test_yin_parse_element_generic(void **state)
365{
366 const char *prefix, *name;
367 struct state *st = *state;
368 struct lysp_ext_instance exts;
369 size_t prefix_len, name_len;
370 LY_ERR ret;
371
372 memset(&exts, 0, sizeof(exts));
373
David Sedlákb0ca07d2019-09-11 11:54:05 +0200374 const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200375 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlák071f7662019-09-12 02:02:51 +0200376 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_EXTENSION_INSTANCE, &data, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200377 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200378 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb0ca07d2019-09-11 11:54:05 +0200379 assert_string_equal(exts.child->stmt, "myext:elem");
David Sedlákb1a78352019-06-28 16:16:29 +0200380 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200381 assert_string_equal(exts.child->child->stmt, "attr");
382 assert_string_equal(exts.child->child->arg, "value");
383 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200384 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200385 st = reset_state(state);
386
David Sedlákb0ca07d2019-09-11 11:54:05 +0200387 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200388 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlák071f7662019-09-12 02:02:51 +0200389 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_EXTENSION_INSTANCE, &data, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200390 assert_int_equal(ret, LY_SUCCESS);
David Sedlákb0ca07d2019-09-11 11:54:05 +0200391 assert_string_equal(exts.child->stmt, "myext:elem");
David Sedlák5392a212019-07-01 09:19:10 +0200392 assert_null(exts.child->child);
393 assert_null(exts.child->arg);
David Sedlákda8ffa32019-07-08 14:17:10 +0200394 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák5392a212019-07-01 09:19:10 +0200395 lysp_ext_instance_free(st->ctx, &exts);
396
David Sedlákb1a78352019-06-28 16:16:29 +0200397 st->finished_correctly = true;
398}
399
400static void
401test_yin_parse_extension_instance(void **state)
402{
403 LY_ERR ret;
404 struct state *st = *state;
405 const char *prefix, *name;
406 size_t prefix_len, name_len;
407 struct yin_arg_record *args = NULL;
408 struct lysp_ext_instance *exts = NULL;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200409 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200410 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
411 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200412 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name2fname(name, prefix_len),
413 len2flen(name_len, prefix_len), LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200414 assert_int_equal(ret, LY_SUCCESS);
David Sedlákb0ca07d2019-09-11 11:54:05 +0200415 assert_string_equal(exts->name, "myext:ext");
David Sedlákb1a78352019-06-28 16:16:29 +0200416 assert_int_equal(exts->insubstmt_index, 0);
417 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
418 assert_true(exts->yin & LYS_YIN);
419 assert_string_equal(exts->child->stmt, "value1");
420 assert_string_equal(exts->child->arg, "test");
421 assert_null(exts->child->child);
422 assert_true(exts->child->flags & LYS_YIN_ATTR);
423 assert_string_equal(exts->child->next->stmt, "value");
424 assert_string_equal(exts->child->next->arg, "test2");
425 assert_null(exts->child->next->child);
426 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
427
David Sedlákb0ca07d2019-09-11 11:54:05 +0200428 assert_string_equal(exts->child->next->next->stmt, "myext:subelem");
David Sedlákb1a78352019-06-28 16:16:29 +0200429 assert_string_equal(exts->child->next->next->arg, "text");
430 assert_null(exts->child->next->next->child);
431 assert_null(exts->child->next->next->next);
432 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákda8ffa32019-07-08 14:17:10 +0200433 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200434 LY_ARRAY_FREE(args);
435 lysp_ext_instance_free(st->ctx, exts);
436 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200437 exts = NULL;
438 args = NULL;
439 st = reset_state(state);
440
David Sedlákb0ca07d2019-09-11 11:54:05 +0200441 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200442 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
443 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200444 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200445 assert_int_equal(ret, LY_SUCCESS);
446 assert_string_equal(exts->name, "extension-elem");
447 assert_null(exts->argument);
448 assert_null(exts->child);
449 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
450 assert_int_equal(exts->insubstmt_index, 0);
451 assert_true(exts->yin & LYS_YIN);
David Sedlákda8ffa32019-07-08 14:17:10 +0200452 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákf250ecf2019-07-01 11:02:05 +0200453 LY_ARRAY_FREE(args);
454 lysp_ext_instance_free(st->ctx, exts);
455 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200456 exts = NULL;
457 args = NULL;
458 st = reset_state(state);
459
David Sedlákb0ca07d2019-09-11 11:54:05 +0200460 data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">"
461 "<myext:ext-sub1/>"
462 "<myext:ext-sub2 sattr1=\"stext2\">"
463 "<myext:ext-sub21>"
464 "<myext:ext-sub211 sattr21=\"text21\"/>"
465 "</myext:ext-sub21>"
466 "</myext:ext-sub2>"
467 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
468 "</myext:ext>";
David Sedlákadd0c2e2019-08-16 10:49:12 +0200469 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
470 yin_load_attributes(st->yin_ctx, &data, &args);
471 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
472 assert_int_equal(ret, LY_SUCCESS);
473
474 assert_string_equal(exts->name, "ext");
475 assert_null(exts->argument);
476 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
477 assert_int_equal(exts->insubstmt_index, 0);
478 assert_true(exts->yin & LYS_YIN);
479 assert_string_equal(exts->child->stmt, "attr1");
480 assert_string_equal(exts->child->arg, "text1");
481 assert_null(exts->child->child);
482 assert_true(exts->child->flags & LYS_YIN_ATTR);
483
484 assert_string_equal(exts->child->next->stmt, "attr2");
485 assert_string_equal(exts->child->next->arg, "text2");
486 assert_null(exts->child->next->child);
487 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
488
David Sedlákb0ca07d2019-09-11 11:54:05 +0200489 assert_string_equal(exts->child->next->next->stmt, "myext:ext-sub1");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200490 assert_null(exts->child->next->next->arg);
491 assert_null(exts->child->next->next->child);
492 assert_int_equal(exts->child->next->next->flags, 0);
493
David Sedlákb0ca07d2019-09-11 11:54:05 +0200494 assert_string_equal(exts->child->next->next->next->stmt, "myext:ext-sub2");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200495 assert_null(exts->child->next->next->next->arg);
496 assert_int_equal(exts->child->next->next->next->flags, 0);
497 assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
498 assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
499 assert_null(exts->child->next->next->next->child->child);
500 assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
501
David Sedlákb0ca07d2019-09-11 11:54:05 +0200502 assert_string_equal(exts->child->next->next->next->child->next->stmt, "myext:ext-sub21");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200503 assert_null(exts->child->next->next->next->child->next->arg);
504 assert_null(exts->child->next->next->next->child->next->next);
505 assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
506
David Sedlákb0ca07d2019-09-11 11:54:05 +0200507 assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "myext:ext-sub211");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200508 assert_null(exts->child->next->next->next->child->next->child->arg);
509 assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
510 assert_null(exts->child->next->next->next->child->next->child->next);
511
512 assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
513 assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
514 assert_null(exts->child->next->next->next->child->next->child->child->next);
515 assert_null(exts->child->next->next->next->child->next->child->child->child);
516 assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
517
David Sedlákb0ca07d2019-09-11 11:54:05 +0200518 assert_string_equal(exts->child->next->next->next->next->stmt, "myext:ext-sub3");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200519 assert_null(exts->child->next->next->next->next->arg);
520 assert_null(exts->child->next->next->next->next->next);
521 assert_int_equal(exts->child->next->next->next->next->flags, 0);
522
523 assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
524 assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
525 assert_null(exts->child->next->next->next->next->child->next);
526 assert_null(exts->child->next->next->next->next->child->child);
527 assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
528
529 LY_ARRAY_FREE(args);
530 lysp_ext_instance_free(st->ctx, exts);
531 LY_ARRAY_FREE(exts);
532 exts = NULL;
533 args = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200534 st = reset_state(state);
535
536 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">"
537 "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>"
538 "<yin:augment target-node=\"target\"/>"
539 "<yin:status value=\"value\"/>"
540 "<yin:include module=\"mod\"/>"
541 "<yin:input />"
542 "<yin:must condition=\"cond\"/>"
543 "<yin:namespace uri=\"uri\"/>"
544 "<yin:revision date=\"data\"/>"
545 "<yin:unique tag=\"tag\"/>"
546 "<yin:contact><text>contact-val</text></yin:contact>"
547 "<yin:error-message><value>err-msg</value></yin:error-message>"
548 "</myext:extension-elem>";
549 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
550 yin_load_attributes(st->yin_ctx, &data, &args);
551 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
552 assert_int_equal(ret, LY_SUCCESS);
553 assert_string_equal(exts->child->arg, "act-name");
554 assert_string_equal(exts->child->next->arg, "target");
555 assert_string_equal(exts->child->next->next->arg, "value");
556 assert_string_equal(exts->child->next->next->next->arg, "mod");
557 assert_null(exts->child->next->next->next->next->arg);
558 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
559 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
560 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
561 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
562 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
563 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
564 LY_ARRAY_FREE(args);
565 lysp_ext_instance_free(st->ctx, exts);
566 LY_ARRAY_FREE(exts);
567 exts = NULL;
568 args = NULL;
569 st = reset_state(state);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200570
David Sedlákb1a78352019-06-28 16:16:29 +0200571 st->finished_correctly = true;
572}
573
David Sedlák555c7202019-07-04 12:14:12 +0200574static void
575test_yin_parse_content(void **state)
576{
577 struct state *st = *state;
578 LY_ERR ret = LY_SUCCESS;
David Sedlákc5b20842019-08-13 10:18:31 +0200579 const char *name, *prefix;
580 size_t name_len, prefix_len;
David Sedlák555c7202019-07-04 12:14:12 +0200581 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200582 "<myext:custom xmlns:myext=\"urn:example:extensions\">"
David Sedlák555c7202019-07-04 12:14:12 +0200583 "totally amazing extension"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200584 "</myext:custom>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200585 "<extension name=\"ext\">"
David Sedlák986cb412019-07-04 13:10:11 +0200586 "<argument name=\"argname\"></argument>"
587 "<description><text>desc</text></description>"
588 "<reference><text>ref</text></reference>"
589 "<status value=\"deprecated\"></status>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200590 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200591 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200592 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200593 "<when condition=\"condition...\">"
594 "<reference><text>when_ref</text></reference>"
595 "<description><text>when_desc</text></description>"
596 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200597 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200598 "<error-message>"
599 "<value>error-msg</value>"
600 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200601 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200602 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200603 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200604 "<position value=\"25\"></position>"
605 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200606 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200607 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200608 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200609 "<pattern value='pattern'>"
610 "<modifier value='invert-match'/>"
611 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200612 "<enum name=\"yay\">"
613 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200614 "</prefix>";
615 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200616 const char **if_features = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200617 struct yin_arg_record *attrs = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200618 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200619 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200620 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200621 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200622 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200623 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200624
David Sedlákc5b20842019-08-13 10:18:31 +0200625 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200626 yin_load_attributes(st->yin_ctx, &data, &attrs);
David Sedlák555c7202019-07-04 12:14:12 +0200627
David Sedlákfd5b9c32019-07-12 15:33:13 +0200628 struct yin_subelement subelems[17] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200629 {LY_STMT_CONFIG, &config, 0},
630 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
631 {LY_STMT_ENUM, &enum_type, 0},
632 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
633 {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
634 {LY_STMT_EXTENSION, &ext_def, 0},
635 {LY_STMT_IF_FEATURE, &if_features, 0},
636 {LY_STMT_LENGTH, &len_type, 0},
637 {LY_STMT_PATTERN, &patter_type, 0},
638 {LY_STMT_POSITION, &pos_enum, 0},
639 {LY_STMT_RANGE, &range_type, 0},
640 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
641 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
642 {LY_STMT_VALUE, &val_enum, 0},
643 {LY_STMT_WHEN, &when_p, 0},
644 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
645 {LY_STMT_ARG_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200646 };
Radek Krejcid6b76452019-09-03 17:03:03 +0200647 ret = yin_parse_content(st->yin_ctx, subelems, 17, &data, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200648 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200649 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák2ce1be62019-07-10 16:15:09 +0200650 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200651 assert_string_equal(def, "default-value");
David Sedlákaa98bba2019-09-12 11:52:14 +0200652 assert_string_equal(exts->name, "myext:custom");
David Sedlák555c7202019-07-04 12:14:12 +0200653 assert_string_equal(exts->argument, "totally amazing extension");
654 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200655 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200656 assert_string_equal(when_p->cond, "condition...");
657 assert_string_equal(when_p->dsc, "when_desc");
658 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200659 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200660 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200661 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200662 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200663 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200664 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200665 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200666 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200667 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200668 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200669 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200670 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200671 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200672 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200673 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200674 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200675 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200676 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200677 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200678 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200679 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200680 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200681 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200682 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200683 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200684 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200685 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200686 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200687 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200688 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200689 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200690 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200691 LY_ARRAY_FREE(ext_def);
David Sedlák555c7202019-07-04 12:14:12 +0200692 LY_ARRAY_FREE(attrs);
David Sedlákd3983112019-07-12 11:20:56 +0200693 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200694 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200695 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200696 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200697 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200698 attrs = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200699 st = reset_state(state);
700
701 /* test unique subelem */
702 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200703 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
704 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
David Sedláke6cd89e2019-08-07 12:46:02 +0200705 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200706 "<prefix value=\"inv_mod\" />"
707 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
708 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200709 ELEMENT_WRAPPER_END;
David Sedlákc5b20842019-08-13 10:18:31 +0200710 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200711 yin_load_attributes(st->yin_ctx, &data, &attrs);
Radek Krejcid6b76452019-09-03 17:03:03 +0200712 ret = yin_parse_content(st->yin_ctx, subelems2, 2, &data, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200713 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200714 logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200715 lydict_remove(st->ctx, prefix_value);
716 lydict_remove(st->ctx, value);
717 st = reset_state(state);
718 LY_ARRAY_FREE(attrs);
719 attrs = NULL;
720
721 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200722 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200723 "<prefix value=\"inv_mod\" />"
724 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
725 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200726 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200727 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
728 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
David Sedlákc5b20842019-08-13 10:18:31 +0200729 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200730 yin_load_attributes(st->yin_ctx, &data, &attrs);
Radek Krejcid6b76452019-09-03 17:03:03 +0200731 ret = yin_parse_content(st->yin_ctx, subelems3, 2, &data, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200732 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200733 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 +0200734 lydict_remove(st->ctx, prefix_value);
735 st = reset_state(state);
736 LY_ARRAY_FREE(attrs);
737 attrs = NULL;
738
739 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200740 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200741 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
David Sedlákc5b20842019-08-13 10:18:31 +0200742 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlákda8ffa32019-07-08 14:17:10 +0200743 yin_load_attributes(st->yin_ctx, &data, &attrs);
Radek Krejcid6b76452019-09-03 17:03:03 +0200744 ret = yin_parse_content(st->yin_ctx, subelems4, 1, &data, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200745 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200746 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200747 LY_ARRAY_FREE(attrs);
748
749 st->finished_correctly = true;
750}
751
David Sedlák92147b02019-07-09 14:01:01 +0200752static void
David Sedlák4a650532019-07-10 11:55:18 +0200753test_validate_value(void **state)
754{
755 struct state *st = *state;
756 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "#invalid", 8), LY_EVALID);
757 logbuf_assert("Invalid identifier character '#'. Line number 1.");
758 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG, "", 0), LY_SUCCESS);
759 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "pre:b", 5), LY_EVALID);
760 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:b", 5), LY_SUCCESS);
761 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:pre:b", 9), LY_EVALID);
762
763 st->finished_correctly = true;
764}
765
David Sedlák32488102019-07-15 17:44:10 +0200766/* helper function to simplify unit test of each element using parse_content function */
767LY_ERR
768test_element_helper(struct state *st, const char **data, void *dest, const char **text,
769 struct lysp_ext_instance **exts, bool valid)
770{
771 struct yin_arg_record *attrs = NULL;
David Sedlákc5b20842019-08-13 10:18:31 +0200772 const char *name, *prefix;
773 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200774 LY_ERR ret = LY_SUCCESS;
775 struct yin_subelement subelems[71] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200776 {LY_STMT_ACTION, dest, 0},
777 {LY_STMT_ANYDATA, dest, 0},
778 {LY_STMT_ANYXML, dest, 0},
779 {LY_STMT_ARGUMENT,dest, 0},
780 {LY_STMT_AUGMENT, dest, 0},
781 {LY_STMT_BASE, dest, 0},
782 {LY_STMT_BELONGS_TO, dest, 0},
783 {LY_STMT_BIT, dest, 0},
784 {LY_STMT_CASE, dest, 0},
785 {LY_STMT_CHOICE, dest, 0},
786 {LY_STMT_CONFIG, dest, 0},
787 {LY_STMT_CONTACT, dest, 0},
788 {LY_STMT_CONTAINER, dest, 0},
789 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
790 {LY_STMT_DESCRIPTION, dest, 0},
791 {LY_STMT_DEVIATE, dest, 0},
792 {LY_STMT_DEVIATION, dest, 0},
793 {LY_STMT_ENUM, dest, 0},
794 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
795 {LY_STMT_ERROR_MESSAGE, dest, 0},
796 {LY_STMT_EXTENSION, dest, 0},
797 {LY_STMT_FEATURE, dest, 0},
798 {LY_STMT_FRACTION_DIGITS, dest, 0},
799 {LY_STMT_GROUPING, dest, 0},
800 {LY_STMT_IDENTITY, dest, 0},
801 {LY_STMT_IF_FEATURE, dest, 0},
802 {LY_STMT_IMPORT, dest, 0},
803 {LY_STMT_INCLUDE, dest, 0},
804 {LY_STMT_INPUT, dest, 0},
805 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
806 {LY_STMT_LEAF, dest, 0},
807 {LY_STMT_LEAF_LIST, dest, 0},
808 {LY_STMT_LENGTH, dest, 0},
809 {LY_STMT_LIST, dest, 0},
810 {LY_STMT_MANDATORY, dest, 0},
811 {LY_STMT_MAX_ELEMENTS, dest, 0},
812 {LY_STMT_MIN_ELEMENTS, dest, 0},
813 {LY_STMT_MODIFIER, dest, 0},
814 {LY_STMT_MODULE, dest, 0},
815 {LY_STMT_MUST, dest, 0},
816 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
817 {LY_STMT_NOTIFICATION, dest, 0},
818 {LY_STMT_ORDERED_BY, dest, 0},
819 {LY_STMT_ORGANIZATION, dest, 0},
820 {LY_STMT_OUTPUT, dest, 0},
821 {LY_STMT_PATH, dest, 0},
822 {LY_STMT_PATTERN, dest, 0},
823 {LY_STMT_POSITION, dest, 0},
824 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
825 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
826 {LY_STMT_RANGE, dest, 0},
827 {LY_STMT_REFERENCE, dest, 0},
828 {LY_STMT_REFINE, dest, 0},
829 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
830 {LY_STMT_REVISION, dest, 0},
831 {LY_STMT_REVISION_DATE, dest, 0},
832 {LY_STMT_RPC, dest, 0},
833 {LY_STMT_STATUS, dest, 0},
834 {LY_STMT_SUBMODULE, dest, 0},
835 {LY_STMT_TYPE, dest, 0},
836 {LY_STMT_TYPEDEF, dest, 0},
837 {LY_STMT_UNIQUE, dest, 0},
838 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
839 {LY_STMT_USES, dest, 0},
840 {LY_STMT_VALUE, dest, 0},
841 {LY_STMT_WHEN, dest, 0},
842 {LY_STMT_YANG_VERSION, dest, 0},
843 {LY_STMT_YIN_ELEMENT, dest, 0},
844 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
845 {LY_STMT_ARG_TEXT, dest, 0},
846 {LY_STMT_ARG_VALUE, dest, 0}
David Sedlák32488102019-07-15 17:44:10 +0200847 };
David Sedlákc5b20842019-08-13 10:18:31 +0200848 LY_CHECK_RET(lyxml_get_element(&st->yin_ctx->xml_ctx, data, &prefix, &prefix_len, &name, &name_len));
David Sedlák4f03b932019-07-26 13:01:47 +0200849 LY_CHECK_RET(yin_load_attributes(st->yin_ctx, data, &attrs));
Radek Krejcid6b76452019-09-03 17:03:03 +0200850 ret = yin_parse_content(st->yin_ctx, subelems, 71, data, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
David Sedlák32488102019-07-15 17:44:10 +0200851 LY_ARRAY_FREE(attrs);
852 if (valid) {
853 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
854 }
855 /* reset status */
856 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
857 return ret;
858}
859
David Sedlákd1144562019-08-06 12:36:14 +0200860#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
861
David Sedlák32488102019-07-15 17:44:10 +0200862static void
David Sedlák43801c92019-08-05 15:58:54 +0200863test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200864{
David Sedlák32488102019-07-15 17:44:10 +0200865 struct state *st = *state;
866 struct lysp_type type = {};
867 const char *data;
868 data = ELEMENT_WRAPPER_START
869 "<enum name=\"enum-name\">"
870 "<if-feature name=\"feature\" />"
871 "<value value=\"55\" />"
872 "<status value=\"deprecated\" />"
873 "<description><text>desc...</text></description>"
874 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200875 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +0200876 "</enum>"
877 ELEMENT_WRAPPER_END;
878 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200879 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200880 assert_string_equal(*type.enums->iffeatures, "feature");
881 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200882 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200883 assert_string_equal(type.enums->dsc, "desc...");
884 assert_string_equal(type.enums->ref, "ref...");
David Sedlákd1144562019-08-06 12:36:14 +0200885 assert_string_equal(type.enums->exts->name, "myext:c-define");
886 assert_int_equal(type.enums->exts->insubstmt_index, 0);
887 assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
888 lysp_type_free(st->ctx, &type);
889 memset(&type, 0, sizeof type);
890
891 data = ELEMENT_WRAPPER_START
892 "<enum name=\"enum-name\"></enum>"
893 ELEMENT_WRAPPER_END;
894 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
895 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200896 lysp_type_free(st->ctx, &type);
897 memset(&type, 0, sizeof type);
898
David Sedlák43801c92019-08-05 15:58:54 +0200899 st->finished_correctly = true;
900}
901
902static void
903test_bit_elem(void **state)
904{
905 struct state *st = *state;
906 struct lysp_type type = {};
907 const char *data;
908 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200909 "<bit name=\"bit-name\">"
David Sedlák43801c92019-08-05 15:58:54 +0200910 "<if-feature name=\"feature\" />"
911 "<position value=\"55\" />"
912 "<status value=\"deprecated\" />"
913 "<description><text>desc...</text></description>"
914 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200915 EXT_SUBELEM
David Sedlák43801c92019-08-05 15:58:54 +0200916 "</bit>"
917 ELEMENT_WRAPPER_END;
918 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200919 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200920 assert_string_equal(*type.bits->iffeatures, "feature");
921 assert_int_equal(type.bits->value, 55);
922 assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
923 assert_string_equal(type.bits->dsc, "desc...");
924 assert_string_equal(type.bits->ref, "ref...");
David Sedlákd1144562019-08-06 12:36:14 +0200925 assert_string_equal(type.bits->exts->name, "myext:c-define");
926 assert_int_equal(type.bits->exts->insubstmt_index, 0);
927 assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
928 lysp_type_free(st->ctx, &type);
929 memset(&type, 0, sizeof type);
930
931 data = ELEMENT_WRAPPER_START
932 "<bit name=\"bit-name\"> </bit>"
933 ELEMENT_WRAPPER_END;
934 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
935 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200936 lysp_type_free(st->ctx, &type);
937 memset(&type, 0, sizeof type);
938
David Sedlák32488102019-07-15 17:44:10 +0200939 st->finished_correctly = true;
940}
941
942static void
943test_meta_elem(void **state)
944{
945 struct state *st = *state;
946 char *value = NULL;
947 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200948 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200949
950 /* organization element */
951 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200952 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
David Sedlák32488102019-07-15 17:44:10 +0200953 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200954 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
955 assert_string_equal(exts[0].name, "myext:c-define");
956 assert_int_equal(exts[0].insubstmt_index, 0);
957 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
958 assert_string_equal(exts[1].name, "myext:c-define");
959 assert_int_equal(exts[1].insubstmt_index, 0);
960 assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedlák32488102019-07-15 17:44:10 +0200961 assert_string_equal(value, "organization...");
962 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200963 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200964 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200965 exts = NULL;
966
David Sedlák32488102019-07-15 17:44:10 +0200967 /* contact element */
968 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200969 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
David Sedlák32488102019-07-15 17:44:10 +0200970 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200971 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
972 assert_string_equal(exts[0].name, "myext:c-define");
973 assert_int_equal(exts[0].insubstmt_index, 0);
974 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200975 assert_string_equal(value, "contact...");
976 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200977 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
978 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200979 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200980
David Sedlák32488102019-07-15 17:44:10 +0200981 /* description element */
982 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200983 "<description><text>description...</text>" EXT_SUBELEM "</description>"
David Sedlák32488102019-07-15 17:44:10 +0200984 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200985 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200986 assert_string_equal(value, "description...");
David Sedlákd1144562019-08-06 12:36:14 +0200987 assert_string_equal(exts[0].name, "myext:c-define");
988 assert_int_equal(exts[0].insubstmt_index, 0);
989 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200990 FREE_STRING(st->ctx, value);
991 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200992 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
993 exts = NULL;
994
David Sedlák32488102019-07-15 17:44:10 +0200995 /* reference element */
996 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200997 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
David Sedlák32488102019-07-15 17:44:10 +0200998 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +0200999 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001000 assert_string_equal(value, "reference...");
David Sedlákd1144562019-08-06 12:36:14 +02001001 assert_string_equal(exts[0].name, "myext:c-define");
1002 assert_int_equal(exts[0].insubstmt_index, 0);
1003 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
David Sedlák32488102019-07-15 17:44:10 +02001004 FREE_STRING(st->ctx, value);
1005 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001006 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1007 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001008
David Sedlákdf2a9732019-08-07 13:23:16 +02001009 /* reference element */
1010 data = ELEMENT_WRAPPER_START
1011 "<reference invalid=\"text\"><text>reference...</text>""</reference>"
1012 ELEMENT_WRAPPER_END;
1013 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001014 logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001015 FREE_STRING(st->ctx, value);
1016 value = NULL;
1017 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1018 exts = NULL;
1019
David Sedlák32488102019-07-15 17:44:10 +02001020 /* missing text subelement */
1021 data = ELEMENT_WRAPPER_START
1022 "<reference>reference...</reference>"
1023 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +02001024 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001025 logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001026
David Sedlákd1144562019-08-06 12:36:14 +02001027 /* reference element */
1028 data = ELEMENT_WRAPPER_START
1029 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
1030 ELEMENT_WRAPPER_END;
1031 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001032 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 +02001033 FREE_STRING(st->ctx, value);
1034 value = NULL;
1035 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1036 exts = NULL;
1037
David Sedlák32488102019-07-15 17:44:10 +02001038 st->finished_correctly = true;
1039}
1040
1041static void
1042test_import_elem(void **state)
1043{
1044 struct state *st = *state;
1045 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02001046 struct lysp_import *imports = NULL;
1047 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +02001048
1049 /* max subelems */
1050 data = ELEMENT_WRAPPER_START
1051 "<import module=\"a\">"
David Sedlákd1144562019-08-06 12:36:14 +02001052 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001053 "<prefix value=\"a_mod\"/>"
1054 "<revision-date date=\"2015-01-01\"></revision-date>"
1055 "<description><text>import description</text></description>"
1056 "<reference><text>import reference</text></reference>"
1057 "</import>"
1058 ELEMENT_WRAPPER_END;
David Sedlák298ff6d2019-07-26 14:29:03 +02001059 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS);
1060 assert_string_equal(imports->name, "a");
1061 assert_string_equal(imports->prefix, "a_mod");
1062 assert_string_equal(imports->rev, "2015-01-01");
1063 assert_string_equal(imports->dsc, "import description");
1064 assert_string_equal(imports->ref, "import reference");
David Sedlákd1144562019-08-06 12:36:14 +02001065 assert_string_equal(imports->exts->name, "myext:c-define");
1066 assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
1067 assert_int_equal(imports->exts->insubstmt_index, 0);
David Sedlák298ff6d2019-07-26 14:29:03 +02001068 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1069 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001070
1071 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +02001072 data = ELEMENT_WRAPPER_START
1073 "<import module=\"a\">"
1074 "<prefix value=\"a_mod\"/>"
1075 "</import>"
1076 ELEMENT_WRAPPER_END;
David Sedlák298ff6d2019-07-26 14:29:03 +02001077 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS);
1078 assert_string_equal(imports->prefix, "a_mod");
1079 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1080 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001081
1082 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +02001083 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
1084 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001085 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
David Sedlák298ff6d2019-07-26 14:29:03 +02001086 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1087 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001088
1089 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +02001090 data = ELEMENT_WRAPPER_START
1091 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001092 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001093 "</import>"
1094 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001095 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001096 "</import>"
1097 ELEMENT_WRAPPER_END;
David Sedlák298ff6d2019-07-26 14:29:03 +02001098 assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID);
1099 logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1.");
1100 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1101 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001102
1103 st->finished_correctly = true;
1104}
1105
1106static void
1107test_status_elem(void **state)
1108{
1109 struct state *st = *state;
1110 const char *data;
1111 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001112 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001113
1114 /* test valid values */
1115 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
1116 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001117 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001118
1119 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
1120 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001121 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001122
David Sedlákd1144562019-08-06 12:36:14 +02001123 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END;
1124 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001125 assert_true(flags & LYS_STATUS_OBSLT);
David Sedlákd1144562019-08-06 12:36:14 +02001126 assert_string_equal(exts[0].name, "myext:c-define");
1127 assert_int_equal(exts[0].insubstmt_index, 0);
1128 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
1129 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1130 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001131
1132 /* test invalid value */
1133 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
1134 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001135 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 +02001136 st->finished_correctly = true;
1137}
1138
1139static void
1140test_ext_elem(void **state)
1141{
1142 struct state *st = *state;
1143 const char *data;
1144 struct lysp_ext *ext = NULL;
1145
1146 /* max subelems */
1147 data = ELEMENT_WRAPPER_START
1148 "<extension name=\"ext_name\">"
1149 "<argument name=\"arg\"></argument>"
1150 "<status value=\"current\"/>"
1151 "<description><text>ext_desc</text></description>"
1152 "<reference><text>ext_ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001153 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001154 "</extension>"
1155 ELEMENT_WRAPPER_END;
1156 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
1157 assert_string_equal(ext->name, "ext_name");
1158 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001159 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001160 assert_string_equal(ext->dsc, "ext_desc");
1161 assert_string_equal(ext->ref, "ext_ref");
David Sedlákd1144562019-08-06 12:36:14 +02001162 assert_string_equal(ext->exts[0].name, "myext:c-define");
1163 assert_int_equal(ext->exts[0].insubstmt_index, 0);
1164 assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák32488102019-07-15 17:44:10 +02001165 lysp_ext_free(st->ctx, ext);
1166 LY_ARRAY_FREE(ext);
1167 ext = NULL;
1168
1169 /* min subelems */
1170 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
1171 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
1172 assert_string_equal(ext->name, "ext_name");
1173 lysp_ext_free(st->ctx, ext);
1174 LY_ARRAY_FREE(ext);
1175 ext = NULL;
1176
1177 st->finished_correctly = true;
1178}
1179
1180static void
1181test_yin_element_elem(void **state)
1182{
1183 struct state *st = *state;
1184 const char *data;
1185 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001186 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001187
1188 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
1189 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001190 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001191
David Sedlákd1144562019-08-06 12:36:14 +02001192 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
1193 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001194 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlákd1144562019-08-06 12:36:14 +02001195 assert_string_equal(exts[0].name, "myext:c-define");
1196 assert_int_equal(exts[0].insubstmt_index, 0);
1197 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
1198 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001199
1200 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
1201 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001202 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák26ea1432019-08-14 13:42:23 +02001203 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 +02001204 st->finished_correctly = true;
1205}
1206
1207static void
1208test_yangversion_elem(void **state)
1209{
1210 struct state *st = *state;
1211 const char *data;
1212 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001213 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001214
1215 /* valid values */
1216 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
1217 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001218 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001219 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1220
David Sedlákd1144562019-08-06 12:36:14 +02001221 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
1222 assert_int_equal(test_element_helper(st, &data, &version, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001223 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001224 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
David Sedlákd1144562019-08-06 12:36:14 +02001225 assert_string_equal(exts[0].name, "myext:c-define");
1226 assert_int_equal(exts[0].insubstmt_index, 0);
1227 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
1228 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001229
1230 /* invalid value */
1231 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
1232 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001233 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 +02001234
1235 st->finished_correctly = true;
1236}
1237
1238static void
1239test_mandatory_elem(void **state)
1240{
1241 struct state *st = *state;
1242 const char *data;
1243 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001244 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001245
1246 /* valid values */
1247 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
1248 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1249 assert_int_equal(man, LYS_MAND_TRUE);
1250 man = 0;
1251
David Sedlákd1144562019-08-06 12:36:14 +02001252 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
1253 assert_int_equal(test_element_helper(st, &data, &man, NULL, &exts, true), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001254 assert_int_equal(man, LYS_MAND_FALSE);
David Sedlákd1144562019-08-06 12:36:14 +02001255 assert_string_equal(exts[0].name, "myext:c-define");
1256 assert_int_equal(exts[0].insubstmt_index, 0);
1257 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
1258 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001259
1260 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
1261 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001262 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 +02001263
1264 st->finished_correctly = true;
1265}
1266
David Sedlák8e7bda82019-07-16 17:57:50 +02001267static void
1268test_argument_elem(void **state)
1269{
1270 struct state *st = *state;
1271 const char *data;
1272 uint16_t flags = 0;
1273 const char *arg;
1274 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001275 struct lysp_ext_instance *exts = NULL;
1276
David Sedlák8e7bda82019-07-16 17:57:50 +02001277 /* max subelems */
1278 data = ELEMENT_WRAPPER_START
1279 "<argument name=\"arg-name\">"
1280 "<yin-element value=\"true\" />"
David Sedlákd1144562019-08-06 12:36:14 +02001281 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001282 "</argument>"
1283 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +02001284 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001285 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001286 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlákd1144562019-08-06 12:36:14 +02001287 assert_string_equal(exts[0].name, "myext:c-define");
1288 assert_int_equal(exts[0].insubstmt_index, 0);
1289 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
1290 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1291 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001292 flags = 0;
1293 FREE_STRING(st->ctx, arg);
1294 arg = NULL;
1295
1296 /* min subelems */
1297 data = ELEMENT_WRAPPER_START
1298 "<argument name=\"arg\">"
1299 "</argument>"
1300 ELEMENT_WRAPPER_END;
1301 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1302 assert_string_equal(arg, "arg");
1303 assert_true(flags == 0);
1304 FREE_STRING(st->ctx, arg);
1305
1306 st->finished_correctly = true;
1307}
1308
1309static void
1310test_base_elem(void **state)
1311{
1312 struct state *st = *state;
1313 const char *data;
1314 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001315 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001316 struct lysp_type type = {};
1317
1318 /* as identity subelement */
1319 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001320 "<base name=\"base-name\">"
1321 EXT_SUBELEM
1322 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001323 "</identity>";
David Sedlákd1144562019-08-06 12:36:14 +02001324 assert_int_equal(test_element_helper(st, &data, &bases, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001325 assert_string_equal(*bases, "base-name");
David Sedlákd1144562019-08-06 12:36:14 +02001326 assert_string_equal(exts[0].name, "myext:c-define");
1327 assert_int_equal(exts[0].insubstmt_index, 0);
1328 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1329 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1330 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001331 FREE_STRING(st->ctx, *bases);
1332 LY_ARRAY_FREE(bases);
1333
1334 /* as type subelement */
1335 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001336 "<base name=\"base-name\">"
1337 EXT_SUBELEM
1338 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001339 "</type>";
David Sedlákd1144562019-08-06 12:36:14 +02001340 assert_int_equal(test_element_helper(st, &data, &type, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001341 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001342 assert_true(type.flags & LYS_SET_BASE);
David Sedlákd1144562019-08-06 12:36:14 +02001343 assert_string_equal(exts[0].name, "myext:c-define");
1344 assert_int_equal(exts[0].insubstmt_index, 0);
1345 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1346 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1347 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001348 FREE_STRING(st->ctx, *type.bases);
1349 LY_ARRAY_FREE(type.bases);
1350
1351 st->finished_correctly = true;
1352}
1353
1354static void
1355test_belongsto_elem(void **state)
1356{
1357 struct state *st = *state;
1358 const char *data;
1359 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001360 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001361
1362 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001363 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001364 ELEMENT_WRAPPER_END;
David Sedlákd1144562019-08-06 12:36:14 +02001365 assert_int_equal(test_element_helper(st, &data, &submod, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001366 assert_string_equal(submod.belongsto, "module-name");
1367 assert_string_equal(submod.prefix, "pref");
David Sedlákd1144562019-08-06 12:36:14 +02001368 assert_string_equal(exts[0].name, "myext:c-define");
1369 assert_int_equal(exts[0].insubstmt_index, 0);
1370 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
1371 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1372 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001373 FREE_STRING(st->ctx, submod.belongsto);
1374 FREE_STRING(st->ctx, submod.prefix);
1375
1376 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
1377 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001378 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001379 FREE_STRING(st->ctx, submod.belongsto);
1380
1381 st->finished_correctly = true;
1382}
1383
1384static void
1385test_config_elem(void **state)
1386{
1387 struct state *st = *state;
1388 const char *data;
1389 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001390 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001391
David Sedlákd1144562019-08-06 12:36:14 +02001392 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
1393 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001394 assert_true(flags & LYS_CONFIG_W);
David Sedlákd1144562019-08-06 12:36:14 +02001395 assert_string_equal(exts[0].name, "myext:c-define");
1396 assert_int_equal(exts[0].insubstmt_index, 0);
1397 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
1398 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1399 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001400 flags = 0;
1401
1402 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
1403 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001404 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001405 flags = 0;
1406
1407 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1408 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001409 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 +02001410
1411 st->finished_correctly = true;
1412}
1413
1414static void
1415test_default_elem(void **state)
1416{
1417 struct state *st = *state;
1418 const char *data;
1419 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001420 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001421
David Sedlákd1144562019-08-06 12:36:14 +02001422 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END;
1423 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001424 assert_string_equal(val, "defaul-value");
David Sedlákd1144562019-08-06 12:36:14 +02001425 assert_string_equal(exts[0].name, "myext:c-define");
1426 assert_int_equal(exts[0].insubstmt_index, 0);
1427 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
1428 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1429 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001430 FREE_STRING(st->ctx, val);
1431 val = NULL;
1432
1433 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
1434 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1435 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1436
1437 st->finished_correctly = true;
1438}
1439
1440static void
1441test_err_app_tag_elem(void **state)
1442{
1443 struct state *st = *state;
1444 const char *data;
1445 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001446 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001447
David Sedlákd1144562019-08-06 12:36:14 +02001448 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END;
1449 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001450 assert_string_equal(val, "val");
David Sedlákd1144562019-08-06 12:36:14 +02001451 assert_string_equal(exts[0].name, "myext:c-define");
1452 assert_int_equal(exts[0].insubstmt_index, 0);
1453 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
1454 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1455 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001456 FREE_STRING(st->ctx, val);
1457 val = NULL;
1458
1459 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
1460 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1461 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1462
1463 st->finished_correctly = true;
1464}
1465
1466static void
1467test_err_msg_elem(void **state)
1468{
1469 struct state *st = *state;
1470 const char *data;
1471 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001472 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001473
David Sedlákd1144562019-08-06 12:36:14 +02001474 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END;
1475 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001476 assert_string_equal(val, "val");
David Sedlákd1144562019-08-06 12:36:14 +02001477 assert_string_equal(exts[0].name, "myext:c-define");
1478 assert_int_equal(exts[0].insubstmt_index, 0);
1479 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
1480 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1481 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001482 FREE_STRING(st->ctx, val);
1483
1484 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
1485 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001486 logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001487
David Sedlákdf2a9732019-08-07 13:23:16 +02001488 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
1489 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001490 logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001491
David Sedlák8e7bda82019-07-16 17:57:50 +02001492 st->finished_correctly = true;
1493}
1494
1495static void
1496test_fracdigits_elem(void **state)
1497{
1498 struct state *st = *state;
1499 const char *data;
1500 struct lysp_type type = {};
1501
1502 /* valid value */
David Sedlákd1144562019-08-06 12:36:14 +02001503 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001504 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001505 assert_string_equal(type.exts[0].name, "myext:c-define");
1506 assert_int_equal(type.exts[0].insubstmt_index, 0);
1507 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001508 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001509 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlákd1144562019-08-06 12:36:14 +02001510 FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001511
1512 /* invalid values */
1513 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
1514 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001515 logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001516
1517 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
1518 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001519 logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001520
1521 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
1522 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001523 logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001524
1525 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
1526 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001527 logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001528
1529 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
1530 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001531 logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001532
1533 st->finished_correctly = true;
1534}
1535
1536static void
1537test_iffeature_elem(void **state)
1538{
1539 struct state *st = *state;
1540 const char *data;
1541 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001542 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001543
David Sedlákd1144562019-08-06 12:36:14 +02001544 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END;
1545 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001546 assert_string_equal(*iffeatures, "local-storage");
David Sedlákd1144562019-08-06 12:36:14 +02001547 assert_string_equal(exts[0].name, "myext:c-define");
1548 assert_int_equal(exts[0].insubstmt_index, 0);
1549 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
1550 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1551 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001552 FREE_STRING(st->ctx, *iffeatures);
1553 LY_ARRAY_FREE(iffeatures);
1554 iffeatures = NULL;
1555
1556 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
1557 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID);
1558 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1559 LY_ARRAY_FREE(iffeatures);
1560 iffeatures = NULL;
1561
1562 st->finished_correctly = true;
1563}
1564
1565static void
1566test_length_elem(void **state)
1567{
1568 struct state *st = *state;
1569 const char *data;
1570 struct lysp_type type = {};
1571
1572 /* max subelems */
1573 data = ELEMENT_WRAPPER_START
1574 "<length value=\"length-str\">"
1575 "<error-message><value>err-msg</value></error-message>"
1576 "<error-app-tag value=\"err-app-tag\"/>"
1577 "<description><text>desc</text></description>"
1578 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001579 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001580 "</length>"
1581 ELEMENT_WRAPPER_END;
1582 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1583 assert_string_equal(type.length->arg, "length-str");
1584 assert_string_equal(type.length->emsg, "err-msg");
1585 assert_string_equal(type.length->eapptag, "err-app-tag");
1586 assert_string_equal(type.length->dsc, "desc");
1587 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001588 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlákd1144562019-08-06 12:36:14 +02001589 assert_string_equal(type.length->exts[0].name, "myext:c-define");
1590 assert_int_equal(type.length->exts[0].insubstmt_index, 0);
1591 assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001592 lysp_type_free(st->ctx, &type);
1593 memset(&type, 0, sizeof(type));
1594
1595 /* min subelems */
1596 data = ELEMENT_WRAPPER_START
1597 "<length value=\"length-str\">"
1598 "</length>"
1599 ELEMENT_WRAPPER_END;
1600 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1601 assert_string_equal(type.length->arg, "length-str");
1602 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001603 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001604 memset(&type, 0, sizeof(type));
1605
1606 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
1607 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1608 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1609 lysp_type_free(st->ctx, &type);
1610 memset(&type, 0, sizeof(type));
1611
1612 st->finished_correctly = true;
1613}
1614
1615static void
1616test_modifier_elem(void **state)
1617{
1618 struct state *st = *state;
1619 const char *data;
1620 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
David Sedlákd1144562019-08-06 12:36:14 +02001621 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001622
David Sedlákd1144562019-08-06 12:36:14 +02001623 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
1624 assert_int_equal(test_element_helper(st, &data, &pat, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001625 assert_string_equal(pat, "\x015pattern");
David Sedlákd1144562019-08-06 12:36:14 +02001626 assert_string_equal(exts[0].name, "myext:c-define");
1627 assert_int_equal(exts[0].insubstmt_index, 0);
1628 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
1629 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1630 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001631 FREE_STRING(st->ctx, pat);
1632
1633 pat = lydict_insert(st->ctx, "\006pattern", 8);
1634 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
1635 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001636 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 +02001637 FREE_STRING(st->ctx, pat);
1638
1639 st->finished_correctly = true;
1640}
1641
1642static void
1643test_namespace_elem(void **state)
1644{
1645 struct state *st = *state;
1646 const char *data;
1647 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001648 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001649
David Sedlákd1144562019-08-06 12:36:14 +02001650 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
1651 assert_int_equal(test_element_helper(st, &data, &ns, NULL, &exts, true), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001652 assert_string_equal(ns, "ns");
David Sedlákd1144562019-08-06 12:36:14 +02001653 assert_string_equal(exts[0].name, "myext:c-define");
1654 assert_int_equal(exts[0].insubstmt_index, 0);
1655 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
1656 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1657 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001658 FREE_STRING(st->ctx, ns);
1659
1660 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
1661 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID);
1662 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1663
1664 st->finished_correctly = true;
1665}
1666
1667static void
1668test_path_elem(void **state)
1669{
1670 struct state *st = *state;
1671 const char *data;
1672 struct lysp_type type = {};
1673
David Sedlák169cc522019-08-15 13:23:45 +02001674 data = ELEMENT_WRAPPER_START "<path value=\"p&amp;th-val\">" EXT_SUBELEM "</path>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001675 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlák169cc522019-08-15 13:23:45 +02001676 assert_string_equal("p&th-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001677 assert_true(type.flags & LYS_SET_PATH);
David Sedlákd1144562019-08-06 12:36:14 +02001678 assert_string_equal(type.exts[0].name, "myext:c-define");
1679 assert_int_equal(type.exts[0].insubstmt_index, 0);
1680 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001681 lysp_type_free(st->ctx, &type);
1682
1683 st->finished_correctly = true;
1684}
1685
1686static void
1687test_pattern_elem(void **state)
1688{
1689 struct state *st = *state;
1690 const char *data;
1691 struct lysp_type type = {};
1692
1693 /* max subelems */
1694 data = ELEMENT_WRAPPER_START
1695 "<pattern value=\"super_pattern\">"
1696 "<modifier value=\"invert-match\"/>"
1697 "<error-message><value>err-msg-value</value></error-message>"
1698 "<error-app-tag value=\"err-app-tag-value\"/>"
David Sedlák169cc522019-08-15 13:23:45 +02001699 "<description><text>&quot;pattern-desc&quot;</text></description>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001700 "<reference><text>pattern-ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001701 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001702 "</pattern>"
1703 ELEMENT_WRAPPER_END;
1704 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001705 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001706 assert_string_equal(type.patterns->arg, "\x015super_pattern");
David Sedlák169cc522019-08-15 13:23:45 +02001707 assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
David Sedlák8e7bda82019-07-16 17:57:50 +02001708 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1709 assert_string_equal(type.patterns->emsg, "err-msg-value");
David Sedlák8e7bda82019-07-16 17:57:50 +02001710 assert_string_equal(type.patterns->ref, "pattern-ref");
David Sedlákd1144562019-08-06 12:36:14 +02001711 assert_string_equal(type.patterns->exts[0].name, "myext:c-define");
1712 assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
1713 assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001714 lysp_type_free(st->ctx, &type);
1715 memset(&type, 0, sizeof(type));
1716
1717 /* min subelems */
1718 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
1719 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1720 assert_string_equal(type.patterns->arg, "\x006pattern");
1721 lysp_type_free(st->ctx, &type);
1722 memset(&type, 0, sizeof(type));
1723
1724 st->finished_correctly = true;
1725}
1726
1727static void
1728test_value_position_elem(void **state)
1729{
1730 struct state *st = *state;
1731 const char *data;
1732 struct lysp_type_enum en = {};
1733
1734 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001735 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001736 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1737 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001738 assert_true(en.flags & LYS_SET_VALUE);
David Sedlákd1144562019-08-06 12:36:14 +02001739 assert_string_equal(en.exts[0].name, "myext:c-define");
1740 assert_int_equal(en.exts[0].insubstmt_index, 0);
1741 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
1742 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001743 memset(&en, 0, sizeof(en));
1744
1745 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
1746 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1747 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001748 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001749 memset(&en, 0, sizeof(en));
1750
1751 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
1752 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1753 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001754 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001755 memset(&en, 0, sizeof(en));
1756
1757 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
1758 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1759 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001760 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001761 memset(&en, 0, sizeof(en));
1762
1763 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001764 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
David Sedlák8e7bda82019-07-16 17:57:50 +02001765 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1766 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001767 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8d552d62019-08-06 15:29:05 +02001768 assert_string_equal(en.exts[0].name, "myext:c-define");
1769 assert_int_equal(en.exts[0].insubstmt_index, 0);
1770 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
1771 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001772 memset(&en, 0, sizeof(en));
1773
1774 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
1775 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1776 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001777 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001778 memset(&en, 0, sizeof(en));
1779
1780 /* invalid values */
1781 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
1782 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001783 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001784
1785 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
1786 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001787 logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001788
David Sedlák69f01612019-07-17 11:41:08 +02001789 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
1790 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001791 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001792
David Sedlák8e7bda82019-07-16 17:57:50 +02001793 /*invalid positions */
1794 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
1795 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001796 logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001797
1798 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
1799 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001800 logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001801
1802 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
1803 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001804 logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001805
David Sedlák69f01612019-07-17 11:41:08 +02001806 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
1807 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001808 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001809
1810 st->finished_correctly = true;
1811}
1812
1813static void
1814test_prefix_elem(void **state)
1815{
1816 struct state *st = *state;
1817 const char *data;
1818 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001819 struct lysp_ext_instance *exts = NULL;
1820
1821 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
1822 assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS);
1823 assert_string_equal(value, "pref");
1824 assert_string_equal(exts[0].name, "myext:c-define");
1825 assert_int_equal(exts[0].insubstmt_index, 0);
1826 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
1827 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1828 exts = NULL;
1829 FREE_STRING(st->ctx, value);
David Sedlák69f01612019-07-17 11:41:08 +02001830
1831 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
1832 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
1833 assert_string_equal(value, "pref");
1834 FREE_STRING(st->ctx, value);
1835
1836 st->finished_correctly = true;
1837}
1838
1839static void
1840test_range_elem(void **state)
1841{
1842 struct state *st = *state;
1843 const char *data;
1844 struct lysp_type type = {};
1845
1846 /* max subelems */
1847 data = ELEMENT_WRAPPER_START
1848 "<range value=\"range-str\">"
1849 "<error-message><value>err-msg</value></error-message>"
1850 "<error-app-tag value=\"err-app-tag\" />"
1851 "<description><text>desc</text></description>"
1852 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001853 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001854 "</range>"
1855 ELEMENT_WRAPPER_END;
1856 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1857 assert_string_equal(type.range->arg, "range-str");
1858 assert_string_equal(type.range->dsc, "desc");
1859 assert_string_equal(type.range->eapptag, "err-app-tag");
1860 assert_string_equal(type.range->emsg, "err-msg");
1861 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001862 assert_true(type.flags & LYS_SET_RANGE);
David Sedlákd1144562019-08-06 12:36:14 +02001863 assert_string_equal(type.range->exts[0].name, "myext:c-define");
1864 assert_int_equal(type.range->exts[0].insubstmt_index, 0);
1865 assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001866 lysp_type_free(st->ctx, &type);
1867 memset(&type, 0, sizeof(type));
1868
1869 /* min subelems */
1870 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
1871 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1872 assert_string_equal(type.range->arg, "range-str");
1873 lysp_type_free(st->ctx, &type);
1874 memset(&type, 0, sizeof(type));
1875
1876 st->finished_correctly = true;
1877}
1878
1879static void
1880test_reqinstance_elem(void **state)
1881{
1882 struct state *st = *state;
1883 const char *data;
1884 struct lysp_type type = {};
1885
David Sedlákd1144562019-08-06 12:36:14 +02001886 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
David Sedlák69f01612019-07-17 11:41:08 +02001887 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1888 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001889 assert_true(type.flags & LYS_SET_REQINST);
David Sedlákd1144562019-08-06 12:36:14 +02001890 assert_string_equal(type.exts[0].name, "myext:c-define");
1891 assert_int_equal(type.exts[0].insubstmt_index, 0);
1892 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
1893 lysp_type_free(st->ctx, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001894 memset(&type, 0, sizeof(type));
1895
1896 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
1897 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1898 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001899 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001900 memset(&type, 0, sizeof(type));
1901
1902 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1903 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1904 memset(&type, 0, sizeof(type));
David Sedlák26ea1432019-08-14 13:42:23 +02001905 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 +02001906
1907 st->finished_correctly = true;
1908}
1909
1910static void
1911test_revision_date_elem(void **state)
1912{
1913 struct state *st = *state;
1914 const char *data;
1915 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001916 struct lysp_ext_instance *exts = NULL;
1917
1918 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END;
1919 assert_int_equal(test_element_helper(st, &data, rev, NULL, &exts, true), LY_SUCCESS);
1920 assert_string_equal(rev, "2000-01-01");
1921 assert_string_equal(exts[0].name, "myext:c-define");
1922 assert_int_equal(exts[0].insubstmt_index, 0);
1923 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
1924 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001925
1926 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
1927 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS);
1928 assert_string_equal(rev, "2000-01-01");
1929
1930 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
1931 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID);
1932 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1933
1934 st->finished_correctly = true;
1935}
1936
1937static void
1938test_unique_elem(void **state)
1939{
1940 struct state *st = *state;
1941 const char *data;
1942 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001943 struct lysp_ext_instance *exts = NULL;
1944
1945 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END;
1946 assert_int_equal(test_element_helper(st, &data, &values, NULL, &exts, true), LY_SUCCESS);
1947 assert_string_equal(*values, "tag");
1948 assert_string_equal(exts[0].name, "myext:c-define");
1949 assert_int_equal(exts[0].insubstmt_index, 0);
1950 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
1951 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1952 FREE_STRING(st->ctx, *values);
1953 LY_ARRAY_FREE(values);
1954 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001955
1956 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
1957 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1958 assert_string_equal(*values, "tag");
1959 FREE_STRING(st->ctx, *values);
1960 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001961 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001962
1963 st->finished_correctly = true;
1964}
1965
1966static void
1967test_units_elem(void **state)
1968{
1969 struct state *st = *state;
1970 const char *data;
1971 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001972 struct lysp_ext_instance *exts = NULL;
1973
1974 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END;
1975 assert_int_equal(test_element_helper(st, &data, &values, NULL, &exts, true), LY_SUCCESS);
1976 assert_string_equal(values, "name");
1977 assert_string_equal(exts[0].name, "myext:c-define");
1978 assert_int_equal(exts[0].insubstmt_index, 0);
1979 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
1980 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1981 FREE_STRING(st->ctx, values);
1982 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001983
1984 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
1985 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1986 assert_string_equal(values, "name");
1987 FREE_STRING(st->ctx, values);
David Sedlákd1144562019-08-06 12:36:14 +02001988 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001989
1990 st->finished_correctly = true;
1991}
1992
1993static void
1994test_when_elem(void **state)
1995{
1996 struct state *st = *state;
1997 const char *data;
1998 struct lysp_when *when = NULL;
1999
2000 data = ELEMENT_WRAPPER_START
2001 "<when condition=\"cond\">"
2002 "<description><text>desc</text></description>"
2003 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002004 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02002005 "</when>"
2006 ELEMENT_WRAPPER_END;
2007 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
2008 assert_string_equal(when->cond, "cond");
2009 assert_string_equal(when->dsc, "desc");
2010 assert_string_equal(when->ref, "ref");
David Sedlákd1144562019-08-06 12:36:14 +02002011 assert_string_equal(when->exts[0].name, "myext:c-define");
2012 assert_int_equal(when->exts[0].insubstmt_index, 0);
2013 assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02002014 lysp_when_free(st->ctx, when);
2015 free(when);
2016 when = NULL;
2017
2018 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
2019 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
2020 assert_string_equal(when->cond, "cond");
2021 lysp_when_free(st->ctx, when);
2022 free(when);
2023 when = NULL;
2024
2025 st->finished_correctly = true;
2026}
2027
2028static void
2029test_yin_text_value_elem(void **state)
2030{
2031 struct state *st = *state;
2032 const char *data;
2033 const char *val;
2034
2035 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
2036 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2037 assert_string_equal(val, "text");
2038 FREE_STRING(st->ctx, val);
2039
2040 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
2041 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2042 assert_string_equal(val, "text");
2043 FREE_STRING(st->ctx, val);
2044
2045 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
2046 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2047 assert_string_equal("", val);
2048 FREE_STRING(st->ctx, val);
2049
David Sedlák8e7bda82019-07-16 17:57:50 +02002050 st->finished_correctly = true;
2051}
David Sedlák32488102019-07-15 17:44:10 +02002052
David Sedlák374d2b32019-07-17 15:06:55 +02002053static void
2054test_type_elem(void **state)
2055{
2056 struct state *st = *state;
2057 const char *data;
2058 struct lysp_type type = {};
2059
2060 /* max subelems */
2061 data = ELEMENT_WRAPPER_START
2062 "<type name=\"type-name\">"
2063 "<base name=\"base-name\"/>"
2064 "<bit name=\"bit\"/>"
2065 "<enum name=\"enum\"/>"
2066 "<fraction-digits value=\"2\"/>"
2067 "<length value=\"length\"/>"
2068 "<path value=\"path\"/>"
2069 "<pattern value=\"pattern\"/>"
2070 "<range value=\"range\" />"
2071 "<require-instance value=\"true\"/>"
2072 "<type name=\"sub-type-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002073 EXT_SUBELEM
David Sedlák374d2b32019-07-17 15:06:55 +02002074 "</type>"
2075 ELEMENT_WRAPPER_END;
2076 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
2077 assert_string_equal(type.name, "type-name");
2078 assert_string_equal(*type.bases, "base-name");
2079 assert_string_equal(type.bits->name, "bit");
2080 assert_string_equal(type.enums->name, "enum");
2081 assert_int_equal(type.fraction_digits, 2);
2082 assert_string_equal(type.length->arg, "length");
2083 assert_string_equal(type.path, "path");
2084 assert_string_equal(type.patterns->arg, "\006pattern");
2085 assert_string_equal(type.range->arg, "range");
2086 assert_int_equal(type.require_instance, 1);
2087 assert_string_equal(type.types->name, "sub-type-name");
David Sedlákd1144562019-08-06 12:36:14 +02002088 assert_string_equal(type.exts[0].name, "myext:c-define");
2089 assert_int_equal(type.exts[0].insubstmt_index, 0);
2090 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002091 assert_true(type.flags & LYS_SET_BASE);
2092 assert_true(type.flags & LYS_SET_BIT);
2093 assert_true(type.flags & LYS_SET_ENUM);
2094 assert_true(type.flags & LYS_SET_FRDIGITS);
2095 assert_true(type.flags & LYS_SET_LENGTH);
2096 assert_true(type.flags & LYS_SET_PATH);
2097 assert_true(type.flags & LYS_SET_PATTERN);
2098 assert_true(type.flags & LYS_SET_RANGE);
2099 assert_true(type.flags & LYS_SET_REQINST);
2100 assert_true(type.flags & LYS_SET_TYPE);
David Sedlákd1144562019-08-06 12:36:14 +02002101 lysp_type_free(st->ctx, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02002102 memset(&type, 0, sizeof(type));
2103
2104 /* min subelems */
2105 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
2106 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
2107 lysp_type_free(st->ctx, &type);
2108 memset(&type, 0, sizeof(type));
2109
2110 st->finished_correctly = true;
2111}
2112
David Sedlák1af868e2019-07-17 17:03:14 +02002113static void
2114test_max_elems_elem(void **state)
2115{
2116 struct state *st = *state;
2117 const char *data;
2118 struct lysp_node_list list = {};
2119 struct lysp_node_leaflist llist = {};
2120 struct lysp_refine refine = {};
2121
David Sedlákd1144562019-08-06 12:36:14 +02002122 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>";
David Sedlák1af868e2019-07-17 17:03:14 +02002123 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
2124 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002125 assert_true(refine.flags & LYS_SET_MAX);
David Sedlákd1144562019-08-06 12:36:14 +02002126 assert_string_equal(refine.exts[0].name, "myext:c-define");
2127 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2128 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2129 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002130
David Sedlákd1144562019-08-06 12:36:14 +02002131 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>";
David Sedlák1af868e2019-07-17 17:03:14 +02002132 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
2133 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002134 assert_true(list.flags & LYS_SET_MAX);
David Sedlákd1144562019-08-06 12:36:14 +02002135 assert_string_equal(list.exts[0].name, "myext:c-define");
2136 assert_int_equal(list.exts[0].insubstmt_index, 0);
2137 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2138 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002139
David Sedlákd1144562019-08-06 12:36:14 +02002140 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>";
David Sedlák1af868e2019-07-17 17:03:14 +02002141 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
2142 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002143 assert_true(llist.flags & LYS_SET_MAX);
David Sedlákd1144562019-08-06 12:36:14 +02002144 assert_string_equal(llist.exts[0].name, "myext:c-define");
2145 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2146 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2147 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002148
2149 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
2150 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
2151 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002152 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02002153
2154 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
2155 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002156 logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002157
2158 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
2159 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002160 logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002161
2162 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
2163 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002164 logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002165
2166 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
2167 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002168 logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002169
2170 st->finished_correctly = true;
2171}
2172
David Sedlák09e18c92019-07-18 11:17:11 +02002173static void
2174test_min_elems_elem(void **state)
2175{
2176 struct state *st = *state;
2177 const char *data;
2178 struct lysp_node_list list = {};
2179 struct lysp_node_leaflist llist = {};
2180 struct lysp_refine refine = {};
2181
David Sedlákd1144562019-08-06 12:36:14 +02002182 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>";
David Sedlák09e18c92019-07-18 11:17:11 +02002183 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
2184 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002185 assert_true(refine.flags & LYS_SET_MIN);
David Sedlákd1144562019-08-06 12:36:14 +02002186 assert_string_equal(refine.exts[0].name, "myext:c-define");
2187 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2188 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2189 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002190
David Sedlákd1144562019-08-06 12:36:14 +02002191 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>";
David Sedlák09e18c92019-07-18 11:17:11 +02002192 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
2193 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002194 assert_true(list.flags & LYS_SET_MIN);
David Sedlákd1144562019-08-06 12:36:14 +02002195 assert_string_equal(list.exts[0].name, "myext:c-define");
2196 assert_int_equal(list.exts[0].insubstmt_index, 0);
2197 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2198 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002199
David Sedlákd1144562019-08-06 12:36:14 +02002200 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>";
David Sedlák09e18c92019-07-18 11:17:11 +02002201 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
2202 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002203 assert_true(llist.flags & LYS_SET_MIN);
David Sedlákd1144562019-08-06 12:36:14 +02002204 assert_string_equal(llist.exts[0].name, "myext:c-define");
2205 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2206 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2207 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002208
2209 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
2210 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002211 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 +02002212
2213 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
2214 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002215 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 +02002216
2217 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
2218 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002219 logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002220
2221 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
2222 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002223 logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002224
2225 st->finished_correctly = true;
2226}
2227
David Sedláka2dad212019-07-18 12:45:19 +02002228static void
2229test_ordby_elem(void **state)
2230{
2231 struct state *st = *state;
2232 const char *data;
2233 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02002234 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02002235
David Sedlákd1144562019-08-06 12:36:14 +02002236 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END;
2237 assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002238 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedlákd1144562019-08-06 12:36:14 +02002239 assert_string_equal(exts[0].name, "myext:c-define");
2240 assert_int_equal(exts[0].insubstmt_index, 0);
2241 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
2242 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02002243
2244 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
2245 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002246 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02002247
2248 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
2249 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02002250 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 +02002251
2252 st->finished_correctly = true;
2253}
2254
David Sedlák8a83bbb2019-07-18 14:46:00 +02002255static void
2256test_any_elem(void **state)
2257{
2258 struct state *st = *state;
2259 const char *data;
2260 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002261 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02002262 struct lysp_node_anydata *parsed = NULL;
2263
2264 /* anyxml max subelems */
2265 data = ELEMENT_WRAPPER_START
2266 "<anyxml name=\"any-name\">"
2267 "<config value=\"true\" />"
2268 "<description><text>desc</text></description>"
2269 "<if-feature name=\"feature\" />"
2270 "<mandatory value=\"true\" />"
2271 "<must condition=\"must-cond\" />"
2272 "<reference><text>ref</text></reference>"
2273 "<status value=\"deprecated\"/>"
2274 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002275 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002276 "</anyxml>"
2277 ELEMENT_WRAPPER_END;
2278 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2279 parsed = (struct lysp_node_anydata *)siblings;
2280 assert_null(parsed->parent);
2281 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002282 assert_true(parsed->flags & LYS_CONFIG_W);
2283 assert_true(parsed->flags & LYS_MAND_TRUE);
2284 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002285 assert_null(parsed->next);
2286 assert_string_equal(parsed->name, "any-name");
2287 assert_string_equal(parsed->dsc, "desc");
2288 assert_string_equal(parsed->ref, "ref");
2289 assert_string_equal(parsed->when->cond, "when-cond");
2290 assert_string_equal(*parsed->iffeatures, "feature");
David Sedlákd1144562019-08-06 12:36:14 +02002291 assert_string_equal(parsed->exts[0].name, "myext:c-define");
2292 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2293 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002294 lysp_node_free(st->ctx, siblings);
2295 siblings = NULL;
2296
2297 /* anydata max subelems */
2298 data = ELEMENT_WRAPPER_START
2299 "<anydata name=\"any-name\">"
2300 "<config value=\"true\" />"
2301 "<description><text>desc</text></description>"
2302 "<if-feature name=\"feature\" />"
2303 "<mandatory value=\"true\" />"
2304 "<must condition=\"must-cond\" />"
2305 "<reference><text>ref</text></reference>"
2306 "<status value=\"deprecated\"/>"
2307 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002308 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002309 "</anydata>"
2310 ELEMENT_WRAPPER_END;
2311 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2312 parsed = (struct lysp_node_anydata *)siblings;
2313 assert_null(parsed->parent);
2314 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002315 assert_true(parsed->flags & LYS_CONFIG_W);
2316 assert_true(parsed->flags & LYS_MAND_TRUE);
2317 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002318 assert_null(parsed->next);
2319 assert_string_equal(parsed->name, "any-name");
2320 assert_string_equal(parsed->dsc, "desc");
2321 assert_string_equal(parsed->ref, "ref");
2322 assert_string_equal(parsed->when->cond, "when-cond");
2323 assert_string_equal(*parsed->iffeatures, "feature");
David Sedlákd1144562019-08-06 12:36:14 +02002324 assert_string_equal(parsed->exts[0].name, "myext:c-define");
2325 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2326 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002327 lysp_node_free(st->ctx, siblings);
2328 siblings = NULL;
2329
2330 /* min subelems */
2331 node_meta.parent = (void *)0x10;
2332 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
2333 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2334 parsed = (struct lysp_node_anydata *)siblings;
2335 assert_ptr_equal(parsed->parent, node_meta.parent);
2336 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
2337 assert_null(parsed->next);
2338 assert_null(parsed->exts);
2339 lysp_node_free(st->ctx, siblings);
2340
2341 st->finished_correctly = true;
2342}
2343
David Sedlák203ca3a2019-07-18 15:26:25 +02002344static void
2345test_leaf_elem(void **state)
2346{
2347 struct state *st = *state;
2348 const char *data;
2349 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002350 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002351 struct lysp_node_leaf *parsed = NULL;
2352
2353 /* max elements */
2354 data = ELEMENT_WRAPPER_START
2355 "<leaf name=\"leaf\">"
2356 "<config value=\"true\" />"
2357 "<default value=\"def-val\"/>"
2358 "<description><text>desc</text></description>"
2359 "<if-feature name=\"feature\" />"
2360 "<mandatory value=\"true\" />"
2361 "<must condition=\"must-cond\" />"
2362 "<reference><text>ref</text></reference>"
2363 "<status value=\"deprecated\"/>"
2364 "<type name=\"type\"/>"
2365 "<units name=\"uni\"/>"
2366 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002367 EXT_SUBELEM
David Sedlák203ca3a2019-07-18 15:26:25 +02002368 "</leaf>"
2369 ELEMENT_WRAPPER_END;
2370 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2371 parsed = (struct lysp_node_leaf *)siblings;
2372 assert_null(parsed->parent);
2373 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002374 assert_true(parsed->flags & LYS_CONFIG_W);
2375 assert_true(parsed->flags & LYS_MAND_TRUE);
2376 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02002377 assert_null(parsed->next);
2378 assert_string_equal(parsed->name, "leaf");
2379 assert_string_equal(parsed->dsc, "desc");
2380 assert_string_equal(parsed->ref, "ref");
2381 assert_string_equal(parsed->when->cond, "when-cond");
2382 assert_string_equal(*parsed->iffeatures, "feature");
David Sedlákd1144562019-08-06 12:36:14 +02002383 assert_string_equal(parsed->exts[0].name, "myext:c-define");
2384 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2385 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák203ca3a2019-07-18 15:26:25 +02002386 assert_string_equal(parsed->musts->arg, "must-cond");
2387 assert_string_equal(parsed->type.name, "type");
2388 assert_string_equal(parsed->units, "uni");
2389 assert_string_equal(parsed->dflt, "def-val");
2390 lysp_node_free(st->ctx, siblings);
2391 siblings = NULL;
2392
2393 /* min elements */
2394 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
2395 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2396 parsed = (struct lysp_node_leaf *)siblings;
2397 assert_string_equal(parsed->name, "leaf");
2398 assert_string_equal(parsed->type.name, "type");
2399 lysp_node_free(st->ctx, siblings);
2400 siblings = NULL;
2401
2402 st->finished_correctly = true;
2403}
2404
David Sedlákc3da3ef2019-07-19 12:56:08 +02002405static void
2406test_leaf_list_elem(void **state)
2407{
2408 struct state *st = *state;
2409 const char *data;
2410 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002411 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002412 struct lysp_node_leaflist *parsed = NULL;
2413
2414 data = ELEMENT_WRAPPER_START
2415 "<leaf-list name=\"llist\">"
2416 "<config value=\"true\" />"
2417 "<default value=\"def-val0\"/>"
2418 "<default value=\"def-val1\"/>"
2419 "<description><text>desc</text></description>"
2420 "<if-feature name=\"feature\"/>"
2421 "<max-elements value=\"5\"/>"
2422 "<must condition=\"must-cond\"/>"
2423 "<ordered-by value=\"user\" />"
2424 "<reference><text>ref</text></reference>"
2425 "<status value=\"current\"/>"
2426 "<type name=\"type\"/>"
2427 "<units name=\"uni\"/>"
2428 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002429 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002430 "</leaf-list>"
2431 ELEMENT_WRAPPER_END;
2432 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2433 parsed = (struct lysp_node_leaflist *)siblings;
2434 assert_string_equal(parsed->dflts[0], "def-val0");
2435 assert_string_equal(parsed->dflts[1], "def-val1");
2436 assert_string_equal(parsed->dsc, "desc");
2437 assert_string_equal(*parsed->iffeatures, "feature");
2438 assert_int_equal(parsed->max, 5);
2439 assert_string_equal(parsed->musts->arg, "must-cond");
2440 assert_string_equal(parsed->name, "llist");
2441 assert_null(parsed->next);
2442 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2443 assert_null(parsed->parent);
2444 assert_string_equal(parsed->ref, "ref");
2445 assert_string_equal(parsed->type.name, "type");
2446 assert_string_equal(parsed->units, "uni");
2447 assert_string_equal(parsed->when->cond, "when-cond");
2448 assert_true(parsed->flags & LYS_CONFIG_W);
2449 assert_true(parsed->flags & LYS_ORDBY_USER);
2450 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedlákd1144562019-08-06 12:36:14 +02002451 assert_string_equal(parsed->exts[0].name, "myext:c-define");
2452 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2453 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002454 lysp_node_free(st->ctx, siblings);
2455 siblings = NULL;
2456
2457 data = ELEMENT_WRAPPER_START
2458 "<leaf-list name=\"llist\">"
2459 "<config value=\"true\" />"
2460 "<description><text>desc</text></description>"
2461 "<if-feature name=\"feature\"/>"
2462 "<min-elements value=\"5\"/>"
2463 "<must condition=\"must-cond\"/>"
2464 "<ordered-by value=\"user\" />"
2465 "<reference><text>ref</text></reference>"
2466 "<status value=\"current\"/>"
2467 "<type name=\"type\"/>"
2468 "<units name=\"uni\"/>"
2469 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002470 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002471 "</leaf-list>"
2472 ELEMENT_WRAPPER_END;
2473 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2474 parsed = (struct lysp_node_leaflist *)siblings;
2475 assert_string_equal(parsed->dsc, "desc");
2476 assert_string_equal(*parsed->iffeatures, "feature");
2477 assert_int_equal(parsed->min, 5);
2478 assert_string_equal(parsed->musts->arg, "must-cond");
2479 assert_string_equal(parsed->name, "llist");
2480 assert_null(parsed->next);
2481 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2482 assert_null(parsed->parent);
2483 assert_string_equal(parsed->ref, "ref");
2484 assert_string_equal(parsed->type.name, "type");
2485 assert_string_equal(parsed->units, "uni");
2486 assert_string_equal(parsed->when->cond, "when-cond");
2487 assert_true(parsed->flags & LYS_CONFIG_W);
2488 assert_true(parsed->flags & LYS_ORDBY_USER);
2489 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedlákd1144562019-08-06 12:36:14 +02002490 assert_string_equal(parsed->exts[0].name, "myext:c-define");
2491 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2492 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002493 lysp_node_free(st->ctx, siblings);
2494 siblings = NULL;
2495
2496 data = ELEMENT_WRAPPER_START
2497 "<leaf-list name=\"llist\">"
2498 "<config value=\"true\" />"
2499 "<description><text>desc</text></description>"
2500 "<if-feature name=\"feature\"/>"
2501 "<max-elements value=\"15\"/>"
2502 "<min-elements value=\"5\"/>"
2503 "<must condition=\"must-cond\"/>"
2504 "<ordered-by value=\"user\" />"
2505 "<reference><text>ref</text></reference>"
2506 "<status value=\"current\"/>"
2507 "<type name=\"type\"/>"
2508 "<units name=\"uni\"/>"
2509 "<when condition=\"when-cond\"/>"
2510 "</leaf-list>"
2511 ELEMENT_WRAPPER_END;
2512 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2513 parsed = (struct lysp_node_leaflist *)siblings;
2514 assert_string_equal(parsed->dsc, "desc");
2515 assert_string_equal(*parsed->iffeatures, "feature");
2516 assert_int_equal(parsed->min, 5);
2517 assert_int_equal(parsed->max, 15);
2518 assert_string_equal(parsed->musts->arg, "must-cond");
2519 assert_string_equal(parsed->name, "llist");
2520 assert_null(parsed->next);
2521 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2522 assert_null(parsed->parent);
2523 assert_string_equal(parsed->ref, "ref");
2524 assert_string_equal(parsed->type.name, "type");
2525 assert_string_equal(parsed->units, "uni");
2526 assert_string_equal(parsed->when->cond, "when-cond");
2527 assert_true(parsed->flags & LYS_CONFIG_W);
2528 assert_true(parsed->flags & LYS_ORDBY_USER);
2529 assert_true(parsed->flags & LYS_STATUS_CURR);
2530 lysp_node_free(st->ctx, siblings);
2531 siblings = NULL;
2532
2533 data = ELEMENT_WRAPPER_START
2534 "<leaf-list name=\"llist\">"
2535 "<type name=\"type\"/>"
2536 "</leaf-list>"
2537 ELEMENT_WRAPPER_END;
2538 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2539 parsed = (struct lysp_node_leaflist *)siblings;
2540 assert_string_equal(parsed->name, "llist");
2541 assert_string_equal(parsed->type.name, "type");
2542 lysp_node_free(st->ctx, siblings);
2543 siblings = NULL;
2544
2545 /* invalid combinations */
2546 data = ELEMENT_WRAPPER_START
2547 "<leaf-list name=\"llist\">"
2548 "<max-elements value=\"5\"/>"
2549 "<min-elements value=\"15\"/>"
2550 "<type name=\"type\"/>"
2551 "</leaf-list>"
2552 ELEMENT_WRAPPER_END;
2553 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2554 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2555 lysp_node_free(st->ctx, siblings);
2556 siblings = NULL;
2557
2558 data = ELEMENT_WRAPPER_START
2559 "<leaf-list name=\"llist\">"
2560 "<default value=\"def-val1\"/>"
2561 "<min-elements value=\"15\"/>"
2562 "<type name=\"type\"/>"
2563 "</leaf-list>"
2564 ELEMENT_WRAPPER_END;
2565 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002566 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 +02002567 lysp_node_free(st->ctx, siblings);
2568 siblings = NULL;
2569
2570 data = ELEMENT_WRAPPER_START
2571 "<leaf-list name=\"llist\">"
2572 "</leaf-list>"
2573 ELEMENT_WRAPPER_END;
2574 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002575 logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002576 lysp_node_free(st->ctx, siblings);
2577 siblings = NULL;
2578
2579 st->finished_correctly = true;
2580}
2581
David Sedlákcb39f642019-07-19 13:19:55 +02002582static void
2583test_presence_elem(void **state)
2584{
2585 struct state *st = *state;
2586 const char *data;
2587 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002588 struct lysp_ext_instance *exts = NULL;
2589
2590 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END;
2591 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
2592 assert_string_equal(val, "presence-val");
2593 assert_string_equal(exts[0].name, "myext:c-define");
2594 assert_int_equal(exts[0].insubstmt_index, 0);
2595 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
2596 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2597 FREE_STRING(st->ctx, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002598
2599 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
2600 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2601 assert_string_equal(val, "presence-val");
2602 FREE_STRING(st->ctx, val);
2603
2604 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
2605 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2606 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2607
2608 st->finished_correctly = true;
2609}
2610
David Sedlák12470a82019-07-19 13:44:36 +02002611static void
2612test_key_elem(void **state)
2613{
2614 struct state *st = *state;
2615 const char *data;
2616 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002617 struct lysp_ext_instance *exts = NULL;
2618
2619 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END;
2620 assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS);
2621 assert_string_equal(val, "key-value");
2622 assert_string_equal(exts[0].name, "myext:c-define");
2623 assert_int_equal(exts[0].insubstmt_index, 0);
2624 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
2625 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2626 FREE_STRING(st->ctx, val);
David Sedlák12470a82019-07-19 13:44:36 +02002627
2628 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
2629 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2630 assert_string_equal(val, "key-value");
2631 FREE_STRING(st->ctx, val);
2632
2633 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
2634 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2635 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2636
2637 st->finished_correctly = true;
2638}
2639
David Sedlák04e17b22019-07-19 15:29:48 +02002640static void
2641test_typedef_elem(void **state)
2642{
2643 struct state *st = *state;
2644 const char *data;
2645 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002646 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002647
2648 data = ELEMENT_WRAPPER_START
2649 "<typedef name=\"tpdf-name\">"
2650 "<default value=\"def-val\"/>"
2651 "<description><text>desc-text</text></description>"
2652 "<reference><text>ref-text</text></reference>"
2653 "<status value=\"current\"/>"
2654 "<type name=\"type\"/>"
2655 "<units name=\"uni\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002656 EXT_SUBELEM
David Sedlák04e17b22019-07-19 15:29:48 +02002657 "</typedef>"
2658 ELEMENT_WRAPPER_END;
2659 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2660 assert_string_equal(tpdfs[0].dflt, "def-val");
2661 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002662 assert_string_equal(tpdfs[0].name, "tpdf-name");
2663 assert_string_equal(tpdfs[0].ref, "ref-text");
2664 assert_string_equal(tpdfs[0].type.name, "type");
2665 assert_string_equal(tpdfs[0].units, "uni");
2666 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
David Sedlákd1144562019-08-06 12:36:14 +02002667 assert_string_equal(tpdfs[0].exts[0].name, "myext:c-define");
2668 assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
2669 assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák04e17b22019-07-19 15:29:48 +02002670 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2671 tpdfs = NULL;
2672
2673 data = ELEMENT_WRAPPER_START
2674 "<typedef name=\"tpdf-name\">"
2675 "<type name=\"type\"/>"
2676 "</typedef>"
2677 ELEMENT_WRAPPER_END;
2678 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2679 assert_string_equal(tpdfs[0].name, "tpdf-name");
2680 assert_string_equal(tpdfs[0].type.name, "type");
2681 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2682 tpdfs = NULL;
2683
2684 st->finished_correctly = true;
2685}
2686
David Sedlákd2d676a2019-07-22 11:28:19 +02002687static void
2688test_refine_elem(void **state)
2689{
2690 struct state *st = *state;
2691 const char *data;
2692 struct lysp_refine *refines = NULL;
2693
2694 /* max subelems */
2695 data = ELEMENT_WRAPPER_START
2696 "<refine target-node=\"target\">"
2697 "<if-feature name=\"feature\" />"
2698 "<must condition=\"cond\" />"
2699 "<presence value=\"presence\" />"
2700 "<default value=\"def\" />"
2701 "<config value=\"true\" />"
2702 "<mandatory value=\"true\" />"
2703 "<min-elements value=\"10\" />"
2704 "<max-elements value=\"20\" />"
2705 "<description><text>desc</text></description>"
2706 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002707 EXT_SUBELEM
David Sedlákd2d676a2019-07-22 11:28:19 +02002708 "</refine>"
2709 ELEMENT_WRAPPER_END;
2710 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2711 assert_string_equal(refines->nodeid, "target");
2712 assert_string_equal(*refines->dflts, "def");
2713 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002714 assert_true(refines->flags & LYS_CONFIG_W);
2715 assert_true(refines->flags & LYS_MAND_TRUE);
2716 assert_string_equal(*refines->iffeatures, "feature");
2717 assert_int_equal(refines->max, 20);
2718 assert_int_equal(refines->min, 10);
2719 assert_string_equal(refines->musts->arg, "cond");
2720 assert_string_equal(refines->presence, "presence");
2721 assert_string_equal(refines->ref, "ref");
David Sedlákd1144562019-08-06 12:36:14 +02002722 assert_string_equal(refines->exts[0].name, "myext:c-define");
2723 assert_int_equal(refines->exts[0].insubstmt_index, 0);
2724 assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákd2d676a2019-07-22 11:28:19 +02002725 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2726 refines = NULL;
2727
2728 /* min subelems */
2729 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
2730 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2731 assert_string_equal(refines->nodeid, "target");
2732 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2733 refines = NULL;
2734
2735 st->finished_correctly = true;
2736}
2737
David Sedlák0d6de5a2019-07-22 13:25:44 +02002738static void
2739test_uses_elem(void **state)
2740{
2741 struct state *st = *state;
2742 const char *data;
2743 struct lysp_node *siblings = NULL;
2744 struct tree_node_meta node_meta = {NULL, &siblings};
2745 struct lysp_node_uses *parsed = NULL;
2746
2747 /* max subelems */
2748 data = ELEMENT_WRAPPER_START
2749 "<uses name=\"uses-name\">"
2750 "<when condition=\"cond\" />"
2751 "<if-feature name=\"feature\" />"
2752 "<status value=\"obsolete\" />"
2753 "<description><text>desc</text></description>"
2754 "<reference><text>ref</text></reference>"
2755 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002756 "<augment target-node=\"target\" />"
David Sedlákd1144562019-08-06 12:36:14 +02002757 EXT_SUBELEM
David Sedlák0d6de5a2019-07-22 13:25:44 +02002758 "</uses>"
2759 ELEMENT_WRAPPER_END;
2760 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2761 parsed = (struct lysp_node_uses *)&siblings[0];
2762 assert_string_equal(parsed->name, "uses-name");
2763 assert_string_equal(parsed->dsc, "desc");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002764 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2765 assert_string_equal(*parsed->iffeatures, "feature");
2766 assert_null(parsed->next);
2767 assert_int_equal(parsed->nodetype, LYS_USES);
2768 assert_null(parsed->parent);
2769 assert_string_equal(parsed->ref, "ref");
2770 assert_string_equal(parsed->refines->nodeid, "target");
2771 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002772 assert_string_equal(parsed->augments->nodeid, "target");
David Sedlákd1144562019-08-06 12:36:14 +02002773 assert_string_equal(parsed->exts[0].name, "myext:c-define");
2774 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2775 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002776 lysp_node_free(st->ctx, siblings);
2777 siblings = NULL;
2778
2779 /* min subelems */
2780 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
2781 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2782 assert_string_equal(siblings[0].name, "uses-name");
2783 lysp_node_free(st->ctx, siblings);
2784 siblings = NULL;
2785
2786 st->finished_correctly = true;
2787}
2788
David Sedlákaa854b02019-07-22 14:17:10 +02002789static void
2790test_revision_elem(void **state)
2791{
2792 struct state *st = *state;
2793 const char *data;
2794 struct lysp_revision *revs = NULL;
2795
2796 /* max subelems */
2797 data = ELEMENT_WRAPPER_START
2798 "<revision date=\"2018-12-25\">"
2799 "<description><text>desc</text></description>"
2800 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002801 EXT_SUBELEM
David Sedlákaa854b02019-07-22 14:17:10 +02002802 "</revision>"
2803 ELEMENT_WRAPPER_END;
2804 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2805 assert_string_equal(revs->date, "2018-12-25");
2806 assert_string_equal(revs->dsc, "desc");
2807 assert_string_equal(revs->ref, "ref");
David Sedlákd1144562019-08-06 12:36:14 +02002808 assert_string_equal(revs->exts[0].name, "myext:c-define");
2809 assert_int_equal(revs->exts[0].insubstmt_index, 0);
2810 assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaa854b02019-07-22 14:17:10 +02002811 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2812 revs = NULL;
2813
2814 /* min subelems */
2815 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
2816 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2817 assert_string_equal(revs->date, "2005-05-05");
2818 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2819 revs = NULL;
2820
2821 /* invalid value */
2822 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
2823 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID);
2824 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2825 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2826 revs = NULL;
2827
2828 st->finished_correctly = true;
2829}
2830
David Sedlák0c2bab92019-07-22 15:33:19 +02002831static void
2832test_include_elem(void **state)
2833{
2834 struct state *st = *state;
2835 const char *data;
2836 struct lysp_include *includes = NULL;
2837 struct include_meta inc_meta = {"module-name", &includes};
2838
2839 /* max subelems */
2840 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2841 data = ELEMENT_WRAPPER_START
2842 "<include module=\"mod\">"
2843 "<description><text>desc</text></description>"
2844 "<reference><text>ref</text></reference>"
2845 "<revision-date date=\"1999-09-09\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002846 EXT_SUBELEM
David Sedlák0c2bab92019-07-22 15:33:19 +02002847 "</include>"
2848 ELEMENT_WRAPPER_END;
2849 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2850 assert_string_equal(includes->name, "mod");
2851 assert_string_equal(includes->dsc, "desc");
2852 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002853 assert_string_equal(includes->rev, "1999-09-09");
David Sedlákd1144562019-08-06 12:36:14 +02002854 assert_string_equal(includes->exts[0].name, "myext:c-define");
2855 assert_int_equal(includes->exts[0].insubstmt_index, 0);
2856 assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0c2bab92019-07-22 15:33:19 +02002857 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2858 includes = NULL;
2859
2860 /* min subelems */
2861 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
2862 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2863 assert_string_equal(includes->name, "mod");
2864 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2865 includes = NULL;
2866
2867 /* invalid combinations */
2868 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2869 data = ELEMENT_WRAPPER_START
2870 "<include module=\"mod\">"
2871 "<description><text>desc</text></description>"
2872 "<revision-date date=\"1999-09-09\"/>"
2873 "</include>"
2874 ELEMENT_WRAPPER_END;
2875 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2876 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.");
2877 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2878 includes = NULL;
2879
2880 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2881 data = ELEMENT_WRAPPER_START
2882 "<include module=\"mod\">"
2883 "<reference><text>ref</text></reference>"
2884 "<revision-date date=\"1999-09-09\"/>"
2885 "</include>"
2886 ELEMENT_WRAPPER_END;
2887 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2888 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.");
2889 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2890 includes = NULL;
2891
2892 st->finished_correctly = true;
2893}
2894
David Sedlák5e13dea2019-07-22 16:06:45 +02002895static void
2896test_feature_elem(void **state)
2897{
2898 struct state *st = *state;
2899 const char *data;
2900 struct lysp_feature *features = NULL;
2901
2902 /* max subelems */
2903 data = ELEMENT_WRAPPER_START
2904 "<feature name=\"feature-name\">"
2905 "<if-feature name=\"iff\"/>"
2906 "<status value=\"deprecated\"/>"
2907 "<description><text>desc</text></description>"
2908 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002909 EXT_SUBELEM
David Sedlák5e13dea2019-07-22 16:06:45 +02002910 "</feature>"
2911 ELEMENT_WRAPPER_END;
2912 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2913 assert_string_equal(features->name, "feature-name");
2914 assert_string_equal(features->dsc, "desc");
David Sedlák5e13dea2019-07-22 16:06:45 +02002915 assert_true(features->flags & LYS_STATUS_DEPRC);
2916 assert_string_equal(*features->iffeatures, "iff");
2917 assert_string_equal(features->ref, "ref");
David Sedlákd1144562019-08-06 12:36:14 +02002918 assert_string_equal(features->exts[0].name, "myext:c-define");
2919 assert_int_equal(features->exts[0].insubstmt_index, 0);
2920 assert_int_equal(features->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5e13dea2019-07-22 16:06:45 +02002921 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2922 features = NULL;
2923
2924 /* min subelems */
2925 data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
2926 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2927 assert_string_equal(features->name, "feature-name");
2928 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2929 features = NULL;
2930
2931 st->finished_correctly = true;
2932}
2933
David Sedlák28794f22019-07-22 16:45:00 +02002934static void
2935test_identity_elem(void **state)
2936{
2937 struct state *st = *state;
2938 const char *data;
2939 struct lysp_ident *identities = NULL;
2940
2941 /* max subelems */
2942 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2943 data = ELEMENT_WRAPPER_START
2944 "<identity name=\"ident-name\">"
2945 "<if-feature name=\"iff\"/>"
2946 "<base name=\"base-name\"/>"
2947 "<status value=\"deprecated\"/>"
2948 "<description><text>desc</text></description>"
2949 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002950 EXT_SUBELEM
David Sedlák28794f22019-07-22 16:45:00 +02002951 "</identity>"
2952 ELEMENT_WRAPPER_END;
2953 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2954 assert_string_equal(identities->name, "ident-name");
2955 assert_string_equal(*identities->bases, "base-name");
2956 assert_string_equal(*identities->iffeatures, "iff");
2957 assert_string_equal(identities->dsc, "desc");
2958 assert_string_equal(identities->ref, "ref");
2959 assert_true(identities->flags & LYS_STATUS_DEPRC);
David Sedlákd1144562019-08-06 12:36:14 +02002960 assert_string_equal(identities->exts[0].name, "myext:c-define");
2961 assert_int_equal(identities->exts[0].insubstmt_index, 0);
2962 assert_int_equal(identities->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák28794f22019-07-22 16:45:00 +02002963 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2964 identities = NULL;
2965
2966 /* min subelems */
2967 data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END;
2968 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2969 assert_string_equal(identities->name, "ident-name");
2970 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2971 identities = NULL;
2972
2973 /* invalid */
2974 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2975 data = ELEMENT_WRAPPER_START
2976 "<identity name=\"ident-name\">"
2977 "<if-feature name=\"iff\"/>"
2978 "</identity>"
2979 ELEMENT_WRAPPER_END;
2980 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID);
2981 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.");
2982 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2983 identities = NULL;
2984
2985 st->finished_correctly = true;
2986}
2987
David Sedlákaf536aa2019-07-23 13:42:23 +02002988static void
2989test_list_elem(void **state)
2990{
2991 struct state *st = *state;
2992 const char *data;
2993 struct lysp_node *siblings = NULL;
2994 struct tree_node_meta node_meta = {NULL, &siblings};
2995 struct lysp_node_list *parsed = NULL;
2996
2997 /* max subelems */
2998 data = ELEMENT_WRAPPER_START
2999 "<list name=\"list-name\">"
3000 "<when condition=\"when\"/>"
3001 "<if-feature name=\"iff\"/>"
3002 "<must condition=\"must-cond\"/>"
3003 "<key value=\"key\"/>"
3004 "<unique tag=\"utag\"/>"
3005 "<config value=\"true\"/>"
3006 "<min-elements value=\"10\"/>"
3007 "<ordered-by value=\"user\"/>"
3008 "<status value=\"deprecated\"/>"
3009 "<description><text>desc</text></description>"
3010 "<reference><text>ref</text></reference>"
3011 "<anydata name=\"anyd\"/>"
3012 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003013 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003014 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003015 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003016 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02003017 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003018 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3019 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02003020 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003021 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02003022 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003023 EXT_SUBELEM
David Sedlákaf536aa2019-07-23 13:42:23 +02003024 "</list>"
3025 ELEMENT_WRAPPER_END;
3026 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3027 parsed = (struct lysp_node_list *)&siblings[0];
3028 assert_string_equal(parsed->dsc, "desc");
3029 assert_string_equal(parsed->child->name, "anyd");
3030 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3031 assert_string_equal(parsed->child->next->name, "anyx");
3032 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02003033 assert_string_equal(parsed->child->next->next->name, "cont");
3034 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003035 assert_string_equal(parsed->child->next->next->next->name, "choice");
3036 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02003037 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
3038 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
3039 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
3040 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3041 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
3042 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
3043 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
3044 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3045 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003046 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02003047 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003048 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02003049 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02003050 assert_true(parsed->flags & LYS_ORDBY_USER);
3051 assert_true(parsed->flags & LYS_STATUS_DEPRC);
3052 assert_true(parsed->flags & LYS_CONFIG_W);
3053 assert_string_equal(*parsed->iffeatures, "iff");
3054 assert_string_equal(parsed->key, "key");
3055 assert_int_equal(parsed->min, 10);
3056 assert_string_equal(parsed->musts->arg, "must-cond");
3057 assert_string_equal(parsed->name, "list-name");
3058 assert_null(parsed->next);
3059 assert_int_equal(parsed->nodetype, LYS_LIST);
3060 assert_null(parsed->parent);
3061 assert_string_equal(parsed->ref, "ref");
3062 assert_string_equal(parsed->typedefs->name, "tpdf");
3063 assert_string_equal(*parsed->uniques, "utag");
3064 assert_string_equal(parsed->when->cond, "when");
David Sedlákd1144562019-08-06 12:36:14 +02003065 assert_string_equal(parsed->exts[0].name, "myext:c-define");
3066 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3067 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaf536aa2019-07-23 13:42:23 +02003068 lysp_node_free(st->ctx, siblings);
3069 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3070 siblings = NULL;
3071
3072 /* min subelems */
3073 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
3074 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3075 parsed = (struct lysp_node_list *)&siblings[0];
3076 assert_string_equal(parsed->name, "list-name");
3077 lysp_node_free(st->ctx, siblings);
3078 siblings = NULL;
3079
3080 st->finished_correctly = true;
3081}
3082
David Sedlák031b9e72019-07-23 15:19:37 +02003083static void
3084test_notification_elem(void **state)
3085{
3086 struct state *st = *state;
3087 const char *data;
3088 struct lysp_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003089 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02003090
3091 /* max subelems */
3092 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3093 data = ELEMENT_WRAPPER_START
3094 "<notification name=\"notif-name\">"
3095 "<anydata name=\"anyd\"/>"
3096 "<anyxml name=\"anyx\"/>"
3097 "<description><text>desc</text></description>"
3098 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003099 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3100 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02003101 "<list name=\"sub-list\"/>"
3102 "<must condition=\"cond\"/>"
3103 "<reference><text>ref</text></reference>"
3104 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003105 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02003106 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003107 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003108 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003109 "<grouping name=\"grp\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003110 EXT_SUBELEM
David Sedlák031b9e72019-07-23 15:19:37 +02003111 "</notification>"
3112 ELEMENT_WRAPPER_END;
3113 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
3114 assert_string_equal(notifs->name, "notif-name");
3115 assert_string_equal(notifs->data->name, "anyd");
3116 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
3117 assert_string_equal(notifs->data->next->name, "anyx");
3118 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
3119 assert_string_equal(notifs->data->next->next->name, "leaf");
3120 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
3121 assert_string_equal(notifs->data->next->next->next->name, "llist");
3122 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
3123 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
3124 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02003125 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003126 assert_string_equal(notifs->groupings->name, "grp");
3127 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02003128 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
3129 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
3130 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
3131 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003132 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3133 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
3134 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02003135 assert_string_equal(*notifs->iffeatures, "iff");
3136 assert_string_equal(notifs->musts->arg, "cond");
3137 assert_int_equal(notifs->nodetype, LYS_NOTIF);
3138 assert_null(notifs->parent);
3139 assert_string_equal(notifs->ref, "ref");
3140 assert_string_equal(notifs->typedefs->name, "tpdf");
David Sedlákd1144562019-08-06 12:36:14 +02003141 assert_string_equal(notifs->exts[0].name, "myext:c-define");
3142 assert_int_equal(notifs->exts[0].insubstmt_index, 0);
3143 assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák031b9e72019-07-23 15:19:37 +02003144 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
3145 notifs = NULL;
3146
3147 /* min subelems */
3148 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
3149 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
3150 assert_string_equal(notifs->name, "notif-name");
3151 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003152 notifs = NULL;
3153
3154 st->finished_correctly = true;
3155}
3156
3157static void
3158test_grouping_elem(void **state)
3159{
3160 struct state *st = *state;
3161 const char *data;
3162 struct lysp_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003163 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02003164
3165 /* max subelems */
3166 data = ELEMENT_WRAPPER_START
3167 "<grouping name=\"grp-name\">"
3168 "<anydata name=\"anyd\"/>"
3169 "<anyxml name=\"anyx\"/>"
3170 "<description><text>desc</text></description>"
3171 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003172 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3173 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003174 "<list name=\"list\"/>"
3175 "<notification name=\"notf\"/>"
3176 "<reference><text>ref</text></reference>"
3177 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003178 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003179 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003180 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003181 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003182 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003183 EXT_SUBELEM
David Sedláke3ce9ef2019-07-23 16:34:30 +02003184 "</grouping>"
3185 ELEMENT_WRAPPER_END;
3186 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
3187 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003188 assert_string_equal(grps->data->name, "anyd");
3189 assert_string_equal(grps->data->next->name, "anyx");
3190 assert_string_equal(grps->data->next->next->name, "leaf");
3191 assert_string_equal(grps->data->next->next->next->name, "llist");
3192 assert_string_equal(grps->data->next->next->next->next->name, "list");
3193 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003194 assert_true(grps->flags & LYS_STATUS_CURR);
3195 assert_string_equal(grps->groupings->name, "sub-grp");
3196 assert_int_equal(grps->nodetype, LYS_GROUPING);
3197 assert_string_equal(grps->notifs->name, "notf");
3198 assert_null(grps->parent);
3199 assert_string_equal(grps->ref, "ref");
3200 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003201 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02003202 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003203 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02003204 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003205 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
3206 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
3207 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedlákd1144562019-08-06 12:36:14 +02003208 assert_string_equal(grps->exts[0].name, "myext:c-define");
3209 assert_int_equal(grps->exts[0].insubstmt_index, 0);
3210 assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003211 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3212 grps = NULL;
3213
3214 /* min subelems */
3215 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
3216 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
3217 assert_string_equal(grps->name, "grp-name");
3218 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3219 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02003220
3221 st->finished_correctly = true;
3222}
3223
David Sedlákf111bcb2019-07-23 17:15:51 +02003224static void
3225test_container_elem(void **state)
3226{
3227 struct state *st = *state;
3228 const char *data;
3229 struct lysp_node *siblings = NULL;
3230 struct tree_node_meta node_meta = {NULL, &siblings};
3231 struct lysp_node_container *parsed = NULL;
3232
3233 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02003234 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3235 data = ELEMENT_WRAPPER_START
3236 "<container name=\"cont-name\">"
3237 "<anydata name=\"anyd\"/>"
3238 "<anyxml name=\"anyx\"/>"
3239 "<config value=\"true\"/>"
3240 "<container name=\"subcont\"/>"
3241 "<description><text>desc</text></description>"
3242 "<grouping name=\"sub-grp\"/>"
3243 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003244 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3245 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003246 "<list name=\"list\"/>"
3247 "<must condition=\"cond\"/>"
3248 "<notification name=\"notf\"/>"
3249 "<presence value=\"presence\"/>"
3250 "<reference><text>ref</text></reference>"
3251 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003252 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003253 "<uses name=\"uses-name\"/>"
3254 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003255 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003256 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003257 EXT_SUBELEM
David Sedláke2dc9e92019-07-24 09:59:21 +02003258 "</container>"
3259 ELEMENT_WRAPPER_END;
3260 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3261 parsed = (struct lysp_node_container *)siblings;
3262 assert_string_equal(parsed->name, "cont-name");
3263 assert_null(parsed->parent);
3264 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
3265 assert_true(parsed->flags & LYS_CONFIG_W);
3266 assert_true(parsed->flags & LYS_STATUS_CURR);
3267 assert_null(parsed->next);
3268 assert_string_equal(parsed->dsc, "desc");
3269 assert_string_equal(parsed->ref, "ref");
3270 assert_string_equal(parsed->when->cond, "when-cond");
3271 assert_string_equal(*parsed->iffeatures, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02003272 assert_string_equal(parsed->musts->arg, "cond");
3273 assert_string_equal(parsed->presence, "presence");
3274 assert_string_equal(parsed->typedefs->name, "tpdf");
3275 assert_string_equal(parsed->groupings->name, "sub-grp");
3276 assert_string_equal(parsed->child->name, "anyd");
3277 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3278 assert_string_equal(parsed->child->next->name, "anyx");
3279 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3280 assert_string_equal(parsed->child->next->next->name, "subcont");
3281 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3282 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3283 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3284 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3285 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3286 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3287 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3288 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3289 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003290 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3291 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3292 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02003293 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003294 assert_string_equal(parsed->actions->name, "act");
David Sedlákd1144562019-08-06 12:36:14 +02003295 assert_string_equal(parsed->exts[0].name, "myext:c-define");
3296 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3297 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke2dc9e92019-07-24 09:59:21 +02003298 lysp_node_free(st->ctx, siblings);
3299 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3300 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02003301
3302 /* min subelems */
3303 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
3304 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3305 parsed = (struct lysp_node_container *)siblings;
3306 assert_string_equal(parsed->name, "cont-name");
3307 lysp_node_free(st->ctx, siblings);
3308 siblings = NULL;
3309
3310 st->finished_correctly = true;
3311}
3312
David Sedlák5379d392019-07-24 10:42:03 +02003313static void
3314test_case_elem(void **state)
3315{
3316 struct state *st = *state;
3317 const char *data;
3318 struct lysp_node *siblings = NULL;
3319 struct tree_node_meta node_meta = {NULL, &siblings};
3320 struct lysp_node_case *parsed = NULL;
3321
3322 /* max subelems */
3323 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3324 data = ELEMENT_WRAPPER_START
3325 "<case name=\"case-name\">"
3326 "<anydata name=\"anyd\"/>"
3327 "<anyxml name=\"anyx\"/>"
3328 "<container name=\"subcont\"/>"
3329 "<description><text>desc</text></description>"
3330 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003331 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3332 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02003333 "<list name=\"list\"/>"
3334 "<reference><text>ref</text></reference>"
3335 "<status value=\"current\"/>"
3336 "<uses name=\"uses-name\"/>"
3337 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003338 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003339 EXT_SUBELEM
David Sedlák5379d392019-07-24 10:42:03 +02003340 "</case>"
3341 ELEMENT_WRAPPER_END;
3342 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3343 parsed = (struct lysp_node_case *)siblings;
3344 assert_string_equal(parsed->name, "case-name");
3345 assert_null(parsed->parent);
3346 assert_int_equal(parsed->nodetype, LYS_CASE);
3347 assert_true(parsed->flags & LYS_STATUS_CURR);
3348 assert_null(parsed->next);
3349 assert_string_equal(parsed->dsc, "desc");
3350 assert_string_equal(parsed->ref, "ref");
3351 assert_string_equal(parsed->when->cond, "when-cond");
3352 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02003353 assert_string_equal(parsed->child->name, "anyd");
3354 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3355 assert_string_equal(parsed->child->next->name, "anyx");
3356 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3357 assert_string_equal(parsed->child->next->next->name, "subcont");
3358 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3359 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3360 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3361 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3362 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3363 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3364 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3365 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3366 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003367 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3368 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3369 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedlákd1144562019-08-06 12:36:14 +02003370 assert_string_equal(parsed->exts[0].name, "myext:c-define");
3371 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3372 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5379d392019-07-24 10:42:03 +02003373 lysp_node_free(st->ctx, siblings);
3374 siblings = NULL;
3375
3376 /* min subelems */
3377 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
3378 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3379 parsed = (struct lysp_node_case *)siblings;
3380 assert_string_equal(parsed->name, "case-name");
3381 lysp_node_free(st->ctx, siblings);
3382 siblings = NULL;
3383
3384 st->finished_correctly = true;
3385}
3386
David Sedlákb7abcfa2019-07-24 12:33:35 +02003387static void
3388test_choice_elem(void **state)
3389{
3390 struct state *st = *state;
3391 const char *data;
3392 struct lysp_node *siblings = NULL;
3393 struct tree_node_meta node_meta = {NULL, &siblings};
3394 struct lysp_node_choice *parsed = NULL;
3395
3396 /* max subelems */
3397 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3398 data = ELEMENT_WRAPPER_START
3399 "<choice name=\"choice-name\">"
3400 "<anydata name=\"anyd\"/>"
3401 "<anyxml name=\"anyx\"/>"
3402 "<case name=\"sub-case\"/>"
3403 "<choice name=\"choice\"/>"
3404 "<config value=\"true\"/>"
3405 "<container name=\"subcont\"/>"
3406 "<default value=\"def\"/>"
3407 "<description><text>desc</text></description>"
3408 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003409 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3410 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003411 "<list name=\"list\"/>"
3412 "<mandatory value=\"true\" />"
3413 "<reference><text>ref</text></reference>"
3414 "<status value=\"current\"/>"
3415 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003416 EXT_SUBELEM
David Sedlákb7abcfa2019-07-24 12:33:35 +02003417 "</choice>"
3418 ELEMENT_WRAPPER_END;
3419 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3420 parsed = (struct lysp_node_choice *)siblings;
3421 assert_string_equal(parsed->name, "choice-name");
3422 assert_null(parsed->parent);
3423 assert_int_equal(parsed->nodetype, LYS_CHOICE);
3424 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
3425 assert_null(parsed->next);
3426 assert_string_equal(parsed->dsc, "desc");
3427 assert_string_equal(parsed->ref, "ref");
3428 assert_string_equal(parsed->when->cond, "when-cond");
3429 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003430 assert_string_equal(parsed->child->name, "anyd");
3431 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3432 assert_string_equal(parsed->child->next->name, "anyx");
3433 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3434 assert_string_equal(parsed->child->next->next->name, "sub-case");
3435 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
3436 assert_string_equal(parsed->child->next->next->next->name, "choice");
3437 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
3438 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
3439 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
3440 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
3441 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
3442 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
3443 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3444 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
3445 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3446 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedlákd1144562019-08-06 12:36:14 +02003447 assert_string_equal(parsed->exts[0].name, "myext:c-define");
3448 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3449 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003450 lysp_node_free(st->ctx, siblings);
3451 siblings = NULL;
3452
3453 /* min subelems */
3454 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
3455 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
3456 parsed = (struct lysp_node_choice *)siblings;
3457 assert_string_equal(parsed->name, "choice-name");
3458 lysp_node_free(st->ctx, siblings);
3459 siblings = NULL;
3460
3461 st->finished_correctly = true;
3462}
3463
David Sedlák05404f62019-07-24 14:11:53 +02003464static void
3465test_inout_elem(void **state)
3466{
3467 struct state *st = *state;
3468 const char *data;
3469 struct lysp_action_inout inout = {};
3470 struct inout_meta inout_meta = {NULL, &inout};
3471
3472 /* max subelements */
3473 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3474 data = ELEMENT_WRAPPER_START
3475 "<input>"
3476 "<anydata name=\"anyd\"/>"
3477 "<anyxml name=\"anyx\"/>"
3478 "<choice name=\"choice\"/>"
3479 "<container name=\"subcont\"/>"
3480 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003481 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3482 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003483 "<list name=\"list\"/>"
3484 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003485 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003486 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003487 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003488 "</input>"
3489 ELEMENT_WRAPPER_END;
3490 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3491 assert_null(inout.parent);
3492 assert_int_equal(inout.nodetype, LYS_INPUT);
3493 assert_string_equal(inout.musts->arg, "cond");
3494 assert_string_equal(inout.typedefs->name, "tpdf");
3495 assert_string_equal(inout.groupings->name, "sub-grp");
3496 assert_string_equal(inout.data->name, "anyd");
3497 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3498 assert_string_equal(inout.data->next->name, "anyx");
3499 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3500 assert_string_equal(inout.data->next->next->name, "choice");
3501 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3502 assert_string_equal(inout.data->next->next->next->name, "subcont");
3503 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3504 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3505 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3506 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3507 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3508 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3509 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3510 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3511 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3512 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedlákd1144562019-08-06 12:36:14 +02003513 assert_string_equal(inout.exts[0].name, "myext:c-define");
3514 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3515 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003516 lysp_action_inout_free(st->ctx, &inout);
3517 memset(&inout, 0, sizeof inout);
3518
3519 /* max subelements */
3520 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3521 data = ELEMENT_WRAPPER_START
3522 "<output>"
3523 "<anydata name=\"anyd\"/>"
3524 "<anyxml name=\"anyx\"/>"
3525 "<choice name=\"choice\"/>"
3526 "<container name=\"subcont\"/>"
3527 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003528 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3529 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003530 "<list name=\"list\"/>"
3531 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003532 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003533 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003534 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003535 "</output>"
3536 ELEMENT_WRAPPER_END;
3537 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3538 assert_null(inout.parent);
3539 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3540 assert_string_equal(inout.musts->arg, "cond");
3541 assert_string_equal(inout.typedefs->name, "tpdf");
3542 assert_string_equal(inout.groupings->name, "sub-grp");
3543 assert_string_equal(inout.data->name, "anyd");
3544 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3545 assert_string_equal(inout.data->next->name, "anyx");
3546 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3547 assert_string_equal(inout.data->next->next->name, "choice");
3548 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3549 assert_string_equal(inout.data->next->next->next->name, "subcont");
3550 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3551 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3552 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3553 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3554 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3555 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3556 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3557 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3558 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3559 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedlákd1144562019-08-06 12:36:14 +02003560 assert_string_equal(inout.exts[0].name, "myext:c-define");
3561 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3562 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003563 lysp_action_inout_free(st->ctx, &inout);
3564 memset(&inout, 0, sizeof inout);
3565
3566 /* min subelems */
3567 data = ELEMENT_WRAPPER_START "<input />" ELEMENT_WRAPPER_END;
3568 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3569 memset(&inout, 0, sizeof inout);
3570
3571 data = ELEMENT_WRAPPER_START "<output />" ELEMENT_WRAPPER_END;
3572 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3573 memset(&inout, 0, sizeof inout);
3574
3575 /* invalid combinations */
3576 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
3577 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, false), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02003578 logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003579 memset(&inout, 0, sizeof inout);
3580
3581 st->finished_correctly = true;
3582}
3583
David Sedlák85d0eca2019-07-24 15:15:21 +02003584static void
3585test_action_elem(void **state)
3586{
3587 struct state *st = *state;
3588 const char *data;
3589 struct lysp_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003590 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
David Sedlák85d0eca2019-07-24 15:15:21 +02003591
3592 /* max subelems */
3593 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3594 data = ELEMENT_WRAPPER_START
3595 "<action name=\"act\">"
3596 "<description><text>desc</text></description>"
3597 "<grouping name=\"grouping\"/>"
3598 "<if-feature name=\"iff\"/>"
3599 "<input><uses name=\"uses-name\"/></input>"
3600 "<output><must condition=\"cond\"/></output>"
3601 "<reference><text>ref</text></reference>"
3602 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003603 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003604 EXT_SUBELEM
David Sedlák85d0eca2019-07-24 15:15:21 +02003605 "</action>"
3606 ELEMENT_WRAPPER_END;
3607 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3608 assert_null(actions->parent);
3609 assert_int_equal(actions->nodetype, LYS_ACTION);
3610 assert_true(actions->flags & LYS_STATUS_DEPRC);
3611 assert_string_equal(actions->name, "act");
3612 assert_string_equal(actions->dsc, "desc");
3613 assert_string_equal(actions->ref, "ref");
3614 assert_string_equal(*actions->iffeatures, "iff");
3615 assert_string_equal(actions->typedefs->name, "tpdf");
3616 assert_string_equal(actions->groupings->name, "grouping");
3617 assert_string_equal(actions->input.data->name, "uses-name");
3618 assert_string_equal(actions->output.musts->arg, "cond");
David Sedlákd1144562019-08-06 12:36:14 +02003619 assert_string_equal(actions->exts[0].name, "myext:c-define");
3620 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3621 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák85d0eca2019-07-24 15:15:21 +02003622 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3623 actions = NULL;
3624
David Sedlákeaa45792019-07-24 15:25:01 +02003625 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3626 data = ELEMENT_WRAPPER_START
3627 "<rpc name=\"act\">"
3628 "<description><text>desc</text></description>"
3629 "<grouping name=\"grouping\"/>"
3630 "<if-feature name=\"iff\"/>"
3631 "<input><uses name=\"uses-name\"/></input>"
3632 "<output><must condition=\"cond\"/></output>"
3633 "<reference><text>ref</text></reference>"
3634 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003635 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003636 EXT_SUBELEM
David Sedlákeaa45792019-07-24 15:25:01 +02003637 "</rpc>"
3638 ELEMENT_WRAPPER_END;
3639 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3640 assert_null(actions->parent);
3641 assert_int_equal(actions->nodetype, LYS_ACTION);
3642 assert_true(actions->flags & LYS_STATUS_DEPRC);
3643 assert_string_equal(actions->name, "act");
3644 assert_string_equal(actions->dsc, "desc");
3645 assert_string_equal(actions->ref, "ref");
3646 assert_string_equal(*actions->iffeatures, "iff");
3647 assert_string_equal(actions->typedefs->name, "tpdf");
3648 assert_string_equal(actions->groupings->name, "grouping");
3649 assert_string_equal(actions->input.data->name, "uses-name");
3650 assert_string_equal(actions->output.musts->arg, "cond");
David Sedlákd1144562019-08-06 12:36:14 +02003651 assert_string_equal(actions->exts[0].name, "myext:c-define");
3652 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3653 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákeaa45792019-07-24 15:25:01 +02003654 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3655 actions = NULL;
3656
David Sedlák85d0eca2019-07-24 15:15:21 +02003657 /* min subelems */
3658 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
3659 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3660 assert_string_equal(actions->name, "act");
3661 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3662 actions = NULL;
3663
3664 st->finished_correctly = true;
3665}
3666
David Sedlák992fb7c2019-07-24 16:51:01 +02003667static void
3668test_augment_elem(void **state)
3669{
3670 struct state *st = *state;
3671 const char *data;
3672 struct lysp_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003673 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003674
3675 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3676 data = ELEMENT_WRAPPER_START
3677 "<augment target-node=\"target\">"
3678 "<action name=\"action\"/>"
3679 "<anydata name=\"anyd\"/>"
3680 "<anyxml name=\"anyx\"/>"
3681 "<case name=\"case\"/>"
3682 "<choice name=\"choice\"/>"
3683 "<container name=\"subcont\"/>"
3684 "<description><text>desc</text></description>"
3685 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003686 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3687 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003688 "<list name=\"list\"/>"
3689 "<notification name=\"notif\"/>"
3690 "<reference><text>ref</text></reference>"
3691 "<status value=\"current\"/>"
3692 "<uses name=\"uses\"/>"
3693 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003694 EXT_SUBELEM
David Sedlák992fb7c2019-07-24 16:51:01 +02003695 "</augment>"
3696 ELEMENT_WRAPPER_END;
3697 assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS);
3698 assert_string_equal(augments->nodeid, "target");
3699 assert_null(augments->parent);
3700 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3701 assert_true(augments->flags & LYS_STATUS_CURR);
3702 assert_string_equal(augments->dsc, "desc");
3703 assert_string_equal(augments->ref, "ref");
3704 assert_string_equal(augments->when->cond, "when-cond");
3705 assert_string_equal(*augments->iffeatures, "iff");
3706 assert_string_equal(augments->child->name, "anyd");
3707 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3708 assert_string_equal(augments->child->next->name, "anyx");
3709 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3710 assert_string_equal(augments->child->next->next->name, "case");
3711 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3712 assert_string_equal(augments->child->next->next->next->name, "choice");
3713 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3714 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3715 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3716 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3717 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3718 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3719 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3720 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3721 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3722 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3723 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3724 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3725 assert_string_equal(augments->actions->name, "action");
3726 assert_string_equal(augments->notifs->name, "notif");
David Sedlákd1144562019-08-06 12:36:14 +02003727 assert_string_equal(augments->exts[0].name, "myext:c-define");
3728 assert_int_equal(augments->exts[0].insubstmt_index, 0);
3729 assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák992fb7c2019-07-24 16:51:01 +02003730 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3731 augments = NULL;
3732
3733 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
3734 assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS);
3735 assert_string_equal(augments->nodeid, "target");
3736 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3737 augments = NULL;
3738
3739 st->finished_correctly = true;
3740}
3741
David Sedlák4ffcec82019-07-25 15:10:21 +02003742static void
3743test_deviate_elem(void **state)
3744{
3745 struct state *st = *state;
3746 const char *data;
3747 struct lysp_deviate *deviates = NULL;
3748 struct lysp_deviate_add *d_add;
3749 struct lysp_deviate_rpl *d_rpl;
3750 struct lysp_deviate_del *d_del;
3751
3752 /* all valid arguments with min subelems */
3753 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
3754 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3755 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3756 lysp_deviate_free(st->ctx, deviates);
3757 free(deviates);
3758 deviates = NULL;
3759
3760 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
3761 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3762 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3763 lysp_deviate_free(st->ctx, deviates);
3764 free(deviates);
3765 deviates = NULL;
3766
3767 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
3768 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3769 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3770 lysp_deviate_free(st->ctx, deviates);
3771 free(deviates);
3772 deviates = NULL;
3773
3774 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
3775 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3776 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3777 lysp_deviate_free(st->ctx, deviates);
3778 free(deviates);
3779 deviates = NULL;
3780
3781 /* max subelems and valid arguments */
3782 data = ELEMENT_WRAPPER_START
3783 "<deviate value=\"not-supported\">"
David Sedlákd1144562019-08-06 12:36:14 +02003784 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003785 "</deviate>"
3786 ELEMENT_WRAPPER_END;
3787 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3788 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
David Sedlákd1144562019-08-06 12:36:14 +02003789 assert_string_equal(deviates->exts[0].name, "myext:c-define");
3790 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3791 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003792 lysp_deviate_free(st->ctx, deviates);
3793 free(deviates);
3794 deviates = NULL;
3795
3796 data = ELEMENT_WRAPPER_START
3797 "<deviate value=\"add\">"
3798 "<units name=\"units\"/>"
3799 "<must condition=\"cond\"/>"
3800 "<unique tag=\"utag\"/>"
3801 "<default value=\"def\"/>"
3802 "<config value=\"true\"/>"
3803 "<mandatory value=\"true\"/>"
3804 "<min-elements value=\"5\"/>"
3805 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003806 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003807 "</deviate>"
3808 ELEMENT_WRAPPER_END;
3809 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3810 d_add = (struct lysp_deviate_add *)deviates;
3811 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3812 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003813 assert_string_equal(d_add->units, "units");
3814 assert_string_equal(d_add->musts->arg, "cond");
3815 assert_string_equal(*d_add->uniques, "utag");
3816 assert_string_equal(*d_add->dflts, "def");
3817 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3818 assert_int_equal(d_add->min, 5);
3819 assert_int_equal(d_add->max, 15);
David Sedlákd1144562019-08-06 12:36:14 +02003820 assert_string_equal(deviates->exts[0].name, "myext:c-define");
3821 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3822 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003823 lysp_deviate_free(st->ctx, deviates);
3824 free(deviates);
3825 deviates = NULL;
3826
3827 data = ELEMENT_WRAPPER_START
3828 "<deviate value=\"replace\">"
3829 "<type name=\"newtype\"/>"
3830 "<units name=\"uni\"/>"
3831 "<default value=\"def\"/>"
3832 "<config value=\"true\"/>"
3833 "<mandatory value=\"true\"/>"
3834 "<min-elements value=\"5\"/>"
3835 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003836 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003837 "</deviate>"
3838 ELEMENT_WRAPPER_END;
3839 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3840 d_rpl = (struct lysp_deviate_rpl *)deviates;
3841 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3842 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003843 assert_string_equal(d_rpl->type->name, "newtype");
3844 assert_string_equal(d_rpl->units, "uni");
3845 assert_string_equal(d_rpl->dflt, "def");
3846 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3847 assert_int_equal(d_rpl->min, 5);
3848 assert_int_equal(d_rpl->max, 15);
David Sedlákd1144562019-08-06 12:36:14 +02003849 assert_string_equal(deviates->exts[0].name, "myext:c-define");
3850 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3851 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003852 lysp_deviate_free(st->ctx, deviates);
3853 free(deviates);
3854 deviates = NULL;
3855
3856 data = ELEMENT_WRAPPER_START
3857 "<deviate value=\"delete\">"
3858 "<units name=\"u\"/>"
3859 "<must condition=\"c\"/>"
3860 "<unique tag=\"tag\"/>"
3861 "<default value=\"default\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003862 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003863 "</deviate>"
3864 ELEMENT_WRAPPER_END;
3865 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3866 d_del = (struct lysp_deviate_del *)deviates;
3867 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3868 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003869 assert_string_equal(d_del->units, "u");
3870 assert_string_equal(d_del->musts->arg, "c");
3871 assert_string_equal(*d_del->uniques, "tag");
3872 assert_string_equal(*d_del->dflts, "default");
David Sedlákd1144562019-08-06 12:36:14 +02003873 assert_string_equal(deviates->exts[0].name, "myext:c-define");
3874 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3875 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003876 lysp_deviate_free(st->ctx, deviates);
3877 free(deviates);
3878 deviates = NULL;
3879
3880 /* invalid arguments */
3881 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
3882 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003883 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 +02003884 deviates = NULL;
3885
3886 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
3887 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003888 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 +02003889 deviates = NULL;
3890
3891 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
3892 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003893 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 +02003894 deviates = NULL;
3895
3896 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
3897 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003898 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 +02003899 deviates = NULL;
3900
3901 data = ELEMENT_WRAPPER_START
3902 "<deviate value=\"not-supported\">"
3903 "<must condition=\"c\"/>"
3904 "</deviate>"
3905 ELEMENT_WRAPPER_END;
3906 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3907 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3908
3909 st->finished_correctly = true;
3910}
3911
David Sedlák8b754462019-07-25 16:22:13 +02003912static void
3913test_deviation_elem(void **state)
3914{
3915 struct state *st = *state;
3916 const char *data;
3917 struct lysp_deviation *deviations = NULL;
3918
3919 /* min subelems */
3920 data = ELEMENT_WRAPPER_START
3921 "<deviation target-node=\"target\">"
3922 "<deviate value=\"not-supported\"/>"
3923 "</deviation>"
3924 ELEMENT_WRAPPER_END;
3925 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS);
3926 assert_string_equal(deviations->nodeid, "target");
3927 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3928 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3929 deviations = NULL;
3930
3931 /* max subelems */
3932 data = ELEMENT_WRAPPER_START
3933 "<deviation target-node=\"target\">"
3934 "<reference><text>ref</text></reference>"
3935 "<description><text>desc</text></description>"
3936 "<deviate value=\"add\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003937 EXT_SUBELEM
David Sedlák8b754462019-07-25 16:22:13 +02003938 "</deviation>"
3939 ELEMENT_WRAPPER_END;
3940 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS);
3941 assert_string_equal(deviations->nodeid, "target");
3942 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3943 assert_string_equal(deviations->ref, "ref");
3944 assert_string_equal(deviations->dsc, "desc");
David Sedlákd1144562019-08-06 12:36:14 +02003945 assert_string_equal(deviations->exts[0].name, "myext:c-define");
3946 assert_int_equal(deviations->exts[0].insubstmt_index, 0);
3947 assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8b754462019-07-25 16:22:13 +02003948 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3949 deviations = NULL;
3950
3951 /* invalid */
3952 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
3953 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, false), LY_EVALID);
3954 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3955 deviations = NULL;
David Sedlák1538a842019-08-08 15:38:51 +02003956 logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
3957 /* TODO */
David Sedlák8b754462019-07-25 16:22:13 +02003958 st->finished_correctly = true;
3959}
3960
David Sedlák4f03b932019-07-26 13:01:47 +02003961static void
3962test_module_elem(void **state)
3963{
3964 struct state *st = *state;
David Sedlákc5b20842019-08-13 10:18:31 +02003965 const char *data, *name, *prefix;
3966 size_t name_len, prefix_len;
David Sedlák4f03b932019-07-26 13:01:47 +02003967 struct yin_arg_record *attrs = NULL;
David Sedlák4f03b932019-07-26 13:01:47 +02003968 struct lys_module *lys_mod = NULL;
3969 struct lysp_module *lysp_mod = NULL;
3970
3971 /* max subelems */
3972 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
3973 lys_mod = calloc(1, sizeof *lys_mod);
3974 lysp_mod = calloc(1, sizeof *lysp_mod);
3975 lys_mod->ctx = st->ctx;
3976 lysp_mod->mod = lys_mod;
3977 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3978 "<yang-version value=\"1.1\"/>\n"
3979 "<namespace uri=\"ns\"/>\n"
3980 "<prefix value=\"pref\"/>\n"
3981 "<include module=\"b-mod\"/>\n"
3982 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3983 "<organization><text>org</text></organization>\n"
3984 "<contact><text>contact</text></contact>\n"
3985 "<description><text>desc</text></description>"
3986 "<reference><text>ref</text></reference>\n"
3987 "<revision date=\"2019-02-02\"/>\n"
3988 "<anydata name=\"anyd\"/>\n"
3989 "<anyxml name=\"anyx\"/>\n"
3990 "<choice name=\"choice\"/>\n"
3991 "<container name=\"cont\"/>\n"
3992 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3993 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3994 "<list name=\"sub-list\"/>\n"
3995 "<uses name=\"uses-name\"/>\n"
3996 "<augment target-node=\"target\"/>\n"
3997 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3998 "<extension name=\"ext\"/>\n"
3999 "<feature name=\"feature\"/>\n"
4000 "<grouping name=\"grp\"/>\n"
4001 "<identity name=\"ident-name\"/>\n"
4002 "<notification name=\"notf\"/>\n"
4003 "<rpc name=\"rpc-name\"/>\n"
4004 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004005 EXT_SUBELEM"\n"
David Sedlák4f03b932019-07-26 13:01:47 +02004006 "</module>\n";
David Sedlákc5b20842019-08-13 10:18:31 +02004007 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02004008 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4009 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS);
4010 assert_string_equal(lysp_mod->mod->name, "mod");
4011 assert_string_equal(lysp_mod->revs, "2019-02-02");
4012 assert_string_equal(lysp_mod->mod->ns, "ns");
4013 assert_string_equal(lysp_mod->mod->prefix, "pref");
4014 assert_null(lysp_mod->mod->filepath);
4015 assert_string_equal(lysp_mod->mod->org, "org");
4016 assert_string_equal(lysp_mod->mod->contact, "contact");
4017 assert_string_equal(lysp_mod->mod->dsc, "desc");
4018 assert_string_equal(lysp_mod->mod->ref, "ref");
4019 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
4020 assert_string_equal(lysp_mod->imports->name, "a-mod");
4021 assert_string_equal(lysp_mod->includes->name, "b-mod");
4022 assert_string_equal(lysp_mod->extensions->name, "ext");
4023 assert_string_equal(lysp_mod->features->name, "feature");
4024 assert_string_equal(lysp_mod->identities->name, "ident-name");
4025 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
4026 assert_string_equal(lysp_mod->groupings->name, "grp");
4027 assert_string_equal(lysp_mod->data->name, "anyd");
4028 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
4029 assert_string_equal(lysp_mod->data->next->name, "anyx");
4030 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
4031 assert_string_equal(lysp_mod->data->next->next->name, "choice");
4032 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
4033 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
4034 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
4035 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
4036 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
4037 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
4038 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4039 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
4040 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4041 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
4042 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4043 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
4044 assert_string_equal(lysp_mod->augments->nodeid, "target");
4045 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
4046 assert_string_equal(lysp_mod->notifs->name, "notf");
4047 assert_string_equal(lysp_mod->deviations->nodeid, "target");
David Sedlákd1144562019-08-06 12:36:14 +02004048 assert_string_equal(lysp_mod->exts[0].name, "myext:c-define");
4049 assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
4050 assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4f03b932019-07-26 13:01:47 +02004051 lysp_module_free(lysp_mod);
4052 lys_module_free(lys_mod, NULL);
4053 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4054 attrs = NULL;
4055
4056 /* min subelems */
4057 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4058 lys_mod = calloc(1, sizeof *lys_mod);
4059 lysp_mod = calloc(1, sizeof *lysp_mod);
4060 lys_mod->ctx = st->ctx;
4061 lysp_mod->mod = lys_mod;
4062 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
4063 "<namespace uri=\"ns\"/>"
4064 "<prefix value=\"pref\"/>"
4065 "<yang-version value=\"1.1\"/>"
4066 "</module>";
David Sedlákc5b20842019-08-13 10:18:31 +02004067 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02004068 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4069 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004070 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák4f03b932019-07-26 13:01:47 +02004071 lysp_module_free(lysp_mod);
4072 lys_module_free(lys_mod, NULL);
4073 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4074 attrs = NULL;
David Sedlák298ff6d2019-07-26 14:29:03 +02004075
David Sedláke6cd89e2019-08-07 12:46:02 +02004076 /* incorrect subelem order */
4077 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4078 lys_mod = calloc(1, sizeof *lys_mod);
4079 lysp_mod = calloc(1, sizeof *lysp_mod);
4080 lys_mod->ctx = st->ctx;
4081 lysp_mod->mod = lys_mod;
4082 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
4083 "<feature name=\"feature\"/>\n"
4084 "<namespace uri=\"ns\"/>"
4085 "<prefix value=\"pref\"/>"
4086 "<yang-version value=\"1.1\"/>"
4087 "</module>";
David Sedlákc5b20842019-08-13 10:18:31 +02004088 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedláke6cd89e2019-08-07 12:46:02 +02004089 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4090 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02004091 logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 30.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004092 lysp_module_free(lysp_mod);
4093 lys_module_free(lys_mod, NULL);
4094 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4095 attrs = NULL;
4096
David Sedlák298ff6d2019-07-26 14:29:03 +02004097 st->finished_correctly = true;
4098}
4099
4100static void
4101test_submodule_elem(void **state)
4102{
4103 struct state *st = *state;
David Sedlákc5b20842019-08-13 10:18:31 +02004104 const char *data, *name, *prefix;
4105 size_t name_len, prefix_len;
David Sedlák298ff6d2019-07-26 14:29:03 +02004106 struct yin_arg_record *attrs = NULL;
David Sedlák298ff6d2019-07-26 14:29:03 +02004107 struct lysp_submodule *lysp_submod = NULL;
4108
4109 /* max subelements */
4110 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4111 lysp_submod = calloc(1, sizeof *lysp_submod);
4112 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
4113 "<yang-version value=\"1.1\"/>\n"
4114 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4115 "<include module=\"b-mod\"/>\n"
4116 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
4117 "<organization><text>org</text></organization>\n"
4118 "<contact><text>contact</text></contact>\n"
4119 "<description><text>desc</text></description>"
4120 "<reference><text>ref</text></reference>\n"
4121 "<revision date=\"2019-02-02\"/>\n"
4122 "<anydata name=\"anyd\"/>\n"
4123 "<anyxml name=\"anyx\"/>\n"
4124 "<choice name=\"choice\"/>\n"
4125 "<container name=\"cont\"/>\n"
4126 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
4127 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
4128 "<list name=\"sub-list\"/>\n"
4129 "<uses name=\"uses-name\"/>\n"
4130 "<augment target-node=\"target\"/>\n"
4131 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
4132 "<extension name=\"ext\"/>\n"
4133 "<feature name=\"feature\"/>\n"
4134 "<grouping name=\"grp\"/>\n"
4135 "<identity name=\"ident-name\"/>\n"
4136 "<notification name=\"notf\"/>\n"
4137 "<rpc name=\"rpc-name\"/>\n"
4138 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004139 EXT_SUBELEM"\n"
David Sedlák298ff6d2019-07-26 14:29:03 +02004140 "</submodule>\n";
David Sedlákc5b20842019-08-13 10:18:31 +02004141 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004142 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4143 assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS);
4144
4145 assert_string_equal(lysp_submod->name, "mod");
4146 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02004147 assert_string_equal(lysp_submod->prefix, "pref");
4148 assert_null(lysp_submod->filepath);
4149 assert_string_equal(lysp_submod->org, "org");
4150 assert_string_equal(lysp_submod->contact, "contact");
4151 assert_string_equal(lysp_submod->dsc, "desc");
4152 assert_string_equal(lysp_submod->ref, "ref");
4153 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
4154 assert_string_equal(lysp_submod->imports->name, "a-mod");
4155 assert_string_equal(lysp_submod->includes->name, "b-mod");
4156 assert_string_equal(lysp_submod->extensions->name, "ext");
4157 assert_string_equal(lysp_submod->features->name, "feature");
4158 assert_string_equal(lysp_submod->identities->name, "ident-name");
4159 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
4160 assert_string_equal(lysp_submod->groupings->name, "grp");
4161 assert_string_equal(lysp_submod->data->name, "anyd");
4162 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
4163 assert_string_equal(lysp_submod->data->next->name, "anyx");
4164 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
4165 assert_string_equal(lysp_submod->data->next->next->name, "choice");
4166 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
4167 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
4168 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
4169 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
4170 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
4171 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
4172 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4173 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
4174 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4175 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
4176 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4177 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
4178 assert_string_equal(lysp_submod->augments->nodeid, "target");
4179 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
4180 assert_string_equal(lysp_submod->notifs->name, "notf");
4181 assert_string_equal(lysp_submod->deviations->nodeid, "target");
David Sedlákd1144562019-08-06 12:36:14 +02004182 assert_string_equal(lysp_submod->exts[0].name, "myext:c-define");
4183 assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
4184 assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák298ff6d2019-07-26 14:29:03 +02004185
4186 lysp_submodule_free(st->ctx, lysp_submod);
4187 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4188 attrs = NULL;
4189
4190 /* min subelemnts */
4191 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4192 lysp_submod = calloc(1, sizeof *lysp_submod);
4193 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4194 "<yang-version value=\"1.0\"/>"
4195 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4196 "</submodule>";
David Sedlákc5b20842019-08-13 10:18:31 +02004197 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004198 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4199 assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS);
4200 assert_string_equal(lysp_submod->prefix, "pref");
4201 assert_string_equal(lysp_submod->belongsto, "mod-name");
4202 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
4203 lysp_submodule_free(st->ctx, lysp_submod);
4204 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4205 attrs = NULL;
4206
David Sedláke6cd89e2019-08-07 12:46:02 +02004207 /* incorrect subelem order */
4208 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
4209 lysp_submod = calloc(1, sizeof *lysp_submod);
4210 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4211 "<yang-version value=\"1.0\"/>"
4212 "<reference><text>ref</text></reference>\n"
4213 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4214 "</submodule>";
David Sedlákc5b20842019-08-13 10:18:31 +02004215 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS);
David Sedláke6cd89e2019-08-07 12:46:02 +02004216 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
4217 assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02004218 logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 28.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004219 lysp_submodule_free(st->ctx, lysp_submod);
4220 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
4221 attrs = NULL;
4222
David Sedlák298ff6d2019-07-26 14:29:03 +02004223 st->finished_correctly = true;
David Sedlák4f03b932019-07-26 13:01:47 +02004224}
4225
David Sedlák8985a142019-07-31 16:43:06 +02004226static void
4227test_yin_parse_module(void **state)
4228{
4229 struct state *st = *state;
4230 const char *data;
4231 struct lys_module *mod;
4232 struct yin_parser_ctx *yin_ctx = NULL;
4233
4234 mod = calloc(1, sizeof *mod);
4235 mod->ctx = st->ctx;
4236 data = "<module name=\"example-foo\""
4237 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4238 "xmlns:foo=\"urn:example:foo\""
4239 "xmlns:myext=\"urn:example:extensions\">\n"
4240
4241 "<yang-version value=\"1.0\"/>\n"
4242
4243 "<namespace uri=\"urn:example:foo\"/>\n"
4244 "<prefix value=\"foo\"/>\n"
4245
4246 "<import module=\"example-extensions\">\n"
David Sedlák6d781b62019-08-02 15:22:52 +02004247 "<prefix value=\"myext\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02004248 "</import>\n"
4249
4250 "<list name=\"interface\">\n"
4251 "<key value=\"name\"/>\n"
4252 "<leaf name=\"name\">\n"
4253 "<type name=\"string\"/>\n"
4254 "</leaf>\n"
4255 "<leaf name=\"mtu\">\n"
4256 "<type name=\"uint32\"/>\n"
4257 "<description>\n"
4258 "<text>The MTU of the interface.</text>\n"
4259 "</description>\n"
4260 "<myext:c-define name=\"MY_MTU\"/>\n"
4261 "</leaf>\n"
4262 "</list>\n"
4263 "</module>\n";
4264 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4265 lys_module_free(mod, NULL);
4266 yin_parser_ctx_free(yin_ctx);
4267 mod = NULL;
4268 yin_ctx = NULL;
4269
4270 mod = calloc(1, sizeof *mod);
4271 mod->ctx = st->ctx;
David Sedlák6d781b62019-08-02 15:22:52 +02004272 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4273 "<yang-version value=\"1.0\"/>\n"
4274 "<namespace uri=\"urn:example:foo\"/>\n"
4275 "<prefix value=\"foo\"/>\n"
4276 "</module>\n";
4277 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4278 lys_module_free(mod, NULL);
4279 yin_parser_ctx_free(yin_ctx);
4280 mod = NULL;
4281 yin_ctx = NULL;
4282
4283
4284 mod = calloc(1, sizeof *mod);
4285 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004286 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4287 "</submodule>\n";
4288 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL);
4289 logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
4290 lys_module_free(mod, NULL);
4291 yin_parser_ctx_free(yin_ctx);
4292
David Sedlák6d781b62019-08-02 15:22:52 +02004293 mod = calloc(1, sizeof *mod);
4294 mod->ctx = st->ctx;
4295 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4296 "<yang-version value=\"1.0\"/>\n"
4297 "<namespace uri=\"urn:example:foo\"/>\n"
4298 "<prefix value=\"foo\"/>\n"
4299 "</module>"
4300 "<module>";
4301 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID);
4302 logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
4303 lys_module_free(mod, NULL);
4304 yin_parser_ctx_free(yin_ctx);
4305 mod = NULL;
4306 yin_ctx = NULL;
4307
David Sedlák8985a142019-07-31 16:43:06 +02004308 st->finished_correctly = true;
4309}
4310
4311static void
4312test_yin_parse_submodule(void **state)
4313{
4314 struct state *st = *state;
4315 const char *data;
4316 struct yin_parser_ctx *yin_ctx = NULL;
4317 struct lysp_submodule *submod = NULL;
David Sedlák1b623122019-08-05 15:27:49 +02004318 struct lys_parser_ctx main_ctx = {};
David Sedlák8985a142019-07-31 16:43:06 +02004319
4320 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4321 "<submodule name=\"asub\""
4322 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4323 "xmlns:a=\"urn:a\">"
4324 "<yang-version value=\"1.0\"/>\n"
4325 "<belongs-to module=\"a\">"
4326 "<prefix value=\"a_pref\"/>"
4327 "</belongs-to>"
4328 "<include module=\"atop\"/>"
4329 "<feature name=\"fox\"/>"
4330 "<notification name=\"bar-notif\">"
4331 "<if-feature name=\"bar\"/>"
4332 "</notification>"
4333 "<notification name=\"fox-notif\">"
4334 "<if-feature name=\"fox\"/>"
4335 "</notification>"
4336 "<augment target-node=\"/a_pref:top\">"
4337 "<if-feature name=\"bar\"/>"
4338 "<container name=\"bar-sub\"/>"
4339 "</augment>"
4340 "<augment target-node=\"/top\">"
4341 "<container name=\"bar-sub2\"/>"
4342 "</augment>"
4343 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004344 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004345 lysp_submodule_free(st->ctx, submod);
4346 yin_parser_ctx_free(yin_ctx);
4347 yin_ctx = NULL;
4348 submod = NULL;
4349
4350 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák6d781b62019-08-02 15:22:52 +02004351 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4352 "<yang-version value=\"1.0\"/>\n"
4353 "<belongs-to module=\"a\">"
4354 "<prefix value=\"a_pref\"/>"
4355 "</belongs-to>"
4356 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004357 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004358 lysp_submodule_free(st->ctx, submod);
4359 yin_parser_ctx_free(yin_ctx);
4360 yin_ctx = NULL;
4361 submod = NULL;
4362
4363 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák8985a142019-07-31 16:43:06 +02004364 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4365 "</module>";
David Sedlák1b623122019-08-05 15:27:49 +02004366 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004367 logbuf_assert("Input data contains module in situation when a submodule is expected.");
4368 lysp_submodule_free(st->ctx, submod);
4369 yin_parser_ctx_free(yin_ctx);
4370 yin_ctx = NULL;
4371 submod = NULL;
4372
David Sedlák6d781b62019-08-02 15:22:52 +02004373 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4374 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4375 "<yang-version value=\"1.0\"/>\n"
4376 "<belongs-to module=\"a\">"
4377 "<prefix value=\"a_pref\"/>"
4378 "</belongs-to>"
4379 "</submodule>"
4380 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4381 "<yang-version value=\"1.0\"/>\n"
4382 "<belongs-to module=\"a\">"
4383 "<prefix value=\"a_pref\"/>"
4384 "</belongs-to>"
4385 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004386 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004387 logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
4388 lysp_submodule_free(st->ctx, submod);
4389 yin_parser_ctx_free(yin_ctx);
4390 yin_ctx = NULL;
4391 submod = NULL;
4392
David Sedlák8985a142019-07-31 16:43:06 +02004393 st->finished_correctly = true;
4394}
4395
David Sedlák3b4db242018-10-19 16:11:01 +02004396int
4397main(void)
4398{
4399
4400 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02004401 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02004402 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
4403 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák071f7662019-09-12 02:02:51 +02004404 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02004405 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02004406
David Sedlák8e7bda82019-07-16 17:57:50 +02004407 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák43801c92019-08-05 15:58:54 +02004408 cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test),
4409 cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test),
David Sedlák32488102019-07-15 17:44:10 +02004410 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
4411 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
4412 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
4413 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
4414 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
4415 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
4416 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004417 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
4418 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
4419 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
4420 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
4421 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
4422 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
4423 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
4424 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
4425 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
4426 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
4427 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
4428 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
4429 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
4430 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
4431 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02004432 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
4433 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
4434 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
4435 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
4436 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
4437 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
4438 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
4439 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02004440 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02004441 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02004442 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02004443 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02004444 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02004445 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02004446 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02004447 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02004448 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02004449 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02004450 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02004451 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02004452 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02004453 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlák5e13dea2019-07-22 16:06:45 +02004454 cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
David Sedlák28794f22019-07-22 16:45:00 +02004455 cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02004456 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02004457 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02004458 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02004459 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02004460 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02004461 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02004462 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02004463 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02004464 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02004465 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02004466 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02004467 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák298ff6d2019-07-26 14:29:03 +02004468 cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test),
David Sedlák8985a142019-07-31 16:43:06 +02004469
4470 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger),
4471 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger),
David Sedlák3b4db242018-10-19 16:11:01 +02004472 };
4473
David Sedlák8e7bda82019-07-16 17:57:50 +02004474 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02004475}