blob: 737d2d5115facc3efd24360a4b718f604b4ccb6e [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
Radek Krejci70593c12020-06-13 20:48:09 +020024#include "common.h"
25#include "parser_internal.h"
26#include "parser_yin.h"
27#include "tree_schema.h"
28#include "tree_schema_internal.h"
29#include "xml.h"
30#include "xpath.h"
David Sedlák3b4db242018-10-19 16:11:01 +020031
David Sedlák555c7202019-07-04 12:14:12 +020032/* prototypes of static functions */
33void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +020034void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +020035void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +020036void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +020037void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +020038void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +020039void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +020040void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +020041void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +020042void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +020043void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
David Sedlák031b9e72019-07-23 15:19:37 +020044void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
David Sedláke3ce9ef2019-07-23 16:34:30 +020045void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
David Sedlák05404f62019-07-24 14:11:53 +020046void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
David Sedlák85d0eca2019-07-24 15:15:21 +020047void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
David Sedlák992fb7c2019-07-24 16:51:01 +020048void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +020049void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +020050void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +020051void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod);
52void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +020053
David Sedláke6cd89e2019-08-07 12:46:02 +020054/* wrapping element used for mocking has nothing to do with real module structure */
55#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
56#define ELEMENT_WRAPPER_END "</status>"
57
Radek Krejci3a4889a2020-05-19 17:01:58 +020058struct test_parser_yin_state {
David Sedlák3b4db242018-10-19 16:11:01 +020059 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010060 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020061 struct lysp_module *lysp_mod;
Michal Vaskob36053d2020-03-26 15:49:30 +010062 struct lys_yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020063 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010064};
David Sedlák872c7b42018-10-26 13:15:20 +020065
David Sedlák79e50cb2019-06-05 16:33:09 +020066#define BUFSIZE 1024
67char logbuf[BUFSIZE] = {0};
68int store = -1; /* negative for infinite logging, positive for limited logging */
69
70/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedláke0ef1c62019-09-13 10:05:55 +020071#define ENABLE_LOGGER_CHECKING 1
David Sedlák79e50cb2019-06-05 16:33:09 +020072
73#if ENABLE_LOGGER_CHECKING
74static void
75logger(LY_LOG_LEVEL level, const char *msg, const char *path)
76{
77 (void) level; /* unused */
78 if (store) {
79 if (path && path[0]) {
80 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
81 } else {
82 strncpy(logbuf, msg, BUFSIZE - 1);
83 }
84 if (store > 0) {
85 --store;
86 }
87 }
88}
89#endif
90
91#if ENABLE_LOGGER_CHECKING
92# define logbuf_assert(str) assert_string_equal(logbuf, str)
93#else
94# define logbuf_assert(str)
95#endif
96
97#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
98 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
99 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
100 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
101 CLEANUP
102
David Sedlák8e7bda82019-07-16 17:57:50 +0200103int
104setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100105{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200106 struct test_parser_yin_state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +0200107
David Sedlák68a1af12019-03-08 13:46:54 +0100108 /* allocate state variable */
109 (*state) = st = calloc(1, sizeof(*st));
110 if (!st) {
111 fprintf(stderr, "Memmory allocation failed");
112 return EXIT_FAILURE;
113 }
David Sedlák872c7b42018-10-26 13:15:20 +0200114
David Sedlák68a1af12019-03-08 13:46:54 +0100115 /* create new libyang context */
116 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200117
David Sedlák8e7bda82019-07-16 17:57:50 +0200118 return EXIT_SUCCESS;
119}
120
121int
122destroy_ly_ctx(void **state)
123{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200124 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +0200125 ly_ctx_destroy(st->ctx, NULL);
126 free(st);
127
128 return EXIT_SUCCESS;
129}
130
131static int
132setup_f(void **state)
133{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200134 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +0200135
136#if ENABLE_LOGGER_CHECKING
137 /* setup logger */
138 ly_set_log_clb(logger, 1);
139#endif
140
David Sedlák68a1af12019-03-08 13:46:54 +0100141 /* allocate new module */
142 st->mod = calloc(1, sizeof(*st->mod));
143 st->mod->ctx = st->ctx;
144
David Sedlák619db942019-07-03 14:47:30 +0200145 /* allocate new parsed module */
146 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
147 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
148 st->lysp_mod->mod->ctx = st->ctx;
149
150 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200151 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100152 st->yin_ctx->format = LYS_IN_YIN;
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{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200160 struct test_parser_yin_state *st = *(struct test_parser_yin_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
Michal Vaskob36053d2020-03-26 15:49:30 +0100172 lyxml_ctx_free(st->yin_ctx->xmlctx);
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
Radek Krejci3a4889a2020-05-19 17:01:58 +0200181static struct test_parser_yin_state*
David Sedlák392af4f2019-06-04 16:02:42 +0200182reset_state(void **state)
183{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200184 ((struct test_parser_yin_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{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200215 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +0200216
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);
Radek Krejci3a4889a2020-05-19 17:01:58 +0200231 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +0200232
233 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100234 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8985a142019-07-31 16:43:06 +0200235
236 return EXIT_SUCCESS;
237}
238
239static int
240teardown_element_test(void **state)
241{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200242 struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
David Sedlák8985a142019-07-31 16:43:06 +0200243
Michal Vaskob36053d2020-03-26 15:49:30 +0100244 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák8985a142019-07-31 16:43:06 +0200245 free(st->yin_ctx);
246
247 teardown_logger(state);
248
249 return EXIT_SUCCESS;
250}
251
David Sedlák68a1af12019-03-08 13:46:54 +0100252static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200253test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200254{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200255 struct test_parser_yin_state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200256
Michal Vaskob36053d2020-03-26 15:49:30 +0100257 const char *prefix;
258 size_t prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200259 /* create mock yin namespace in xml context */
260 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
Michal Vaskob36053d2020-03-26 15:49:30 +0100261 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
262 prefix = st->yin_ctx->xmlctx->prefix;
263 prefix_len = st->yin_ctx->xmlctx->prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200264
Radek Krejcid6b76452019-09-03 17:03:03 +0200265 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
266 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
267 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
268 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
269 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
270 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
285 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);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
318 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
319 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
320 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
321 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
322 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
323 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
324 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
325 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
326 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
327 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
328 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
329 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
330 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
331 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
332 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
333 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
334 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 +0200335
336 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200337}
David Sedlák3b4db242018-10-19 16:11:01 +0200338
David Sedlák872c7b42018-10-26 13:15:20 +0200339static void
David Sedlák060b00e2019-06-19 11:12:06 +0200340test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200341{
David Sedlák68a1af12019-03-08 13:46:54 +0100342 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200343
David Sedlák060b00e2019-06-19 11:12:06 +0200344 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
345 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
346 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
347 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
348 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
349 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
350 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
351 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
352 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
353 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
354 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
355 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200356}
357
David Sedlák68a1af12019-03-08 13:46:54 +0100358static void
David Sedlákb1a78352019-06-28 16:16:29 +0200359test_yin_parse_element_generic(void **state)
360{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200361 struct test_parser_yin_state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200362 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200363 LY_ERR ret;
364
365 memset(&exts, 0, sizeof(exts));
366
David Sedlákb0ca07d2019-09-11 11:54:05 +0200367 const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100368 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
369
370 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200371 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100372 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200373 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlákb1a78352019-06-28 16:16:29 +0200374 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200375 assert_string_equal(exts.child->child->stmt, "attr");
376 assert_string_equal(exts.child->child->arg, "value");
377 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200378 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200379 st = reset_state(state);
380
David Sedlákb0ca07d2019-09-11 11:54:05 +0200381 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100382 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
383
384 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200385 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100386 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200387 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlák5392a212019-07-01 09:19:10 +0200388 assert_null(exts.child->child);
389 assert_null(exts.child->arg);
390 lysp_ext_instance_free(st->ctx, &exts);
391
David Sedlákb1a78352019-06-28 16:16:29 +0200392 st->finished_correctly = true;
393}
394
395static void
396test_yin_parse_extension_instance(void **state)
397{
398 LY_ERR ret;
Radek Krejci3a4889a2020-05-19 17:01:58 +0200399 struct test_parser_yin_state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200400 struct lysp_ext_instance *exts = NULL;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200401 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100402 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
403
404 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200405 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200406 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákb1a78352019-06-28 16:16:29 +0200407 assert_int_equal(exts->insubstmt_index, 0);
408 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
409 assert_true(exts->yin & LYS_YIN);
410 assert_string_equal(exts->child->stmt, "value1");
411 assert_string_equal(exts->child->arg, "test");
412 assert_null(exts->child->child);
413 assert_true(exts->child->flags & LYS_YIN_ATTR);
414 assert_string_equal(exts->child->next->stmt, "value");
415 assert_string_equal(exts->child->next->arg, "test2");
416 assert_null(exts->child->next->child);
417 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
418
David Sedláke0ef1c62019-09-13 10:05:55 +0200419 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
David Sedlákb1a78352019-06-28 16:16:29 +0200420 assert_string_equal(exts->child->next->next->arg, "text");
421 assert_null(exts->child->next->next->child);
422 assert_null(exts->child->next->next->next);
423 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200424 lysp_ext_instance_free(st->ctx, exts);
425 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200426 exts = NULL;
David Sedlákf250ecf2019-07-01 11:02:05 +0200427 st = reset_state(state);
428
David Sedlákb0ca07d2019-09-11 11:54:05 +0200429 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Michal Vaskob36053d2020-03-26 15:49:30 +0100430 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
431
432 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200433 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200434 assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
David Sedlákf250ecf2019-07-01 11:02:05 +0200435 assert_null(exts->argument);
436 assert_null(exts->child);
437 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
438 assert_int_equal(exts->insubstmt_index, 0);
439 assert_true(exts->yin & LYS_YIN);
David Sedlákf250ecf2019-07-01 11:02:05 +0200440 lysp_ext_instance_free(st->ctx, exts);
441 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200442 exts = NULL;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200443 st = reset_state(state);
444
David Sedlákb0ca07d2019-09-11 11:54:05 +0200445 data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">"
446 "<myext:ext-sub1/>"
447 "<myext:ext-sub2 sattr1=\"stext2\">"
448 "<myext:ext-sub21>"
449 "<myext:ext-sub211 sattr21=\"text21\"/>"
450 "</myext:ext-sub21>"
451 "</myext:ext-sub2>"
452 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
453 "</myext:ext>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100454 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
455
456 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200457 assert_int_equal(ret, LY_SUCCESS);
458
David Sedláke0ef1c62019-09-13 10:05:55 +0200459 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200460 assert_null(exts->argument);
461 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
462 assert_int_equal(exts->insubstmt_index, 0);
463 assert_true(exts->yin & LYS_YIN);
464 assert_string_equal(exts->child->stmt, "attr1");
465 assert_string_equal(exts->child->arg, "text1");
466 assert_null(exts->child->child);
467 assert_true(exts->child->flags & LYS_YIN_ATTR);
468
469 assert_string_equal(exts->child->next->stmt, "attr2");
470 assert_string_equal(exts->child->next->arg, "text2");
471 assert_null(exts->child->next->child);
472 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
473
David Sedláke0ef1c62019-09-13 10:05:55 +0200474 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200475 assert_null(exts->child->next->next->arg);
476 assert_null(exts->child->next->next->child);
477 assert_int_equal(exts->child->next->next->flags, 0);
478
David Sedláke0ef1c62019-09-13 10:05:55 +0200479 assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200480 assert_null(exts->child->next->next->next->arg);
481 assert_int_equal(exts->child->next->next->next->flags, 0);
482 assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
483 assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
484 assert_null(exts->child->next->next->next->child->child);
485 assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
486
David Sedláke0ef1c62019-09-13 10:05:55 +0200487 assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200488 assert_null(exts->child->next->next->next->child->next->arg);
489 assert_null(exts->child->next->next->next->child->next->next);
490 assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
491
David Sedláke0ef1c62019-09-13 10:05:55 +0200492 assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200493 assert_null(exts->child->next->next->next->child->next->child->arg);
494 assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
495 assert_null(exts->child->next->next->next->child->next->child->next);
496
497 assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
498 assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
499 assert_null(exts->child->next->next->next->child->next->child->child->next);
500 assert_null(exts->child->next->next->next->child->next->child->child->child);
501 assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
502
David Sedláke0ef1c62019-09-13 10:05:55 +0200503 assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200504 assert_null(exts->child->next->next->next->next->arg);
505 assert_null(exts->child->next->next->next->next->next);
506 assert_int_equal(exts->child->next->next->next->next->flags, 0);
507
508 assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
509 assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
510 assert_null(exts->child->next->next->next->next->child->next);
511 assert_null(exts->child->next->next->next->next->child->child);
512 assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
513
David Sedlákadd0c2e2019-08-16 10:49:12 +0200514 lysp_ext_instance_free(st->ctx, exts);
515 LY_ARRAY_FREE(exts);
516 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200517 st = reset_state(state);
518
519 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">"
520 "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>"
521 "<yin:augment target-node=\"target\"/>"
522 "<yin:status value=\"value\"/>"
523 "<yin:include module=\"mod\"/>"
524 "<yin:input />"
525 "<yin:must condition=\"cond\"/>"
526 "<yin:namespace uri=\"uri\"/>"
527 "<yin:revision date=\"data\"/>"
528 "<yin:unique tag=\"tag\"/>"
David Sedlákd2844882019-09-13 16:01:22 +0200529 "<yin:description><yin:text>contact-val</yin:text></yin:description>"
530 "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200531 "</myext:extension-elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100532 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
533
534 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200535 assert_int_equal(ret, LY_SUCCESS);
536 assert_string_equal(exts->child->arg, "act-name");
537 assert_string_equal(exts->child->next->arg, "target");
538 assert_string_equal(exts->child->next->next->arg, "value");
539 assert_string_equal(exts->child->next->next->next->arg, "mod");
540 assert_null(exts->child->next->next->next->next->arg);
541 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
542 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
543 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
544 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
545 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
David Sedlákaa98bba2019-09-12 11:52:14 +0200546 lysp_ext_instance_free(st->ctx, exts);
547 LY_ARRAY_FREE(exts);
548 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200549 st = reset_state(state);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200550
David Sedlákb1a78352019-06-28 16:16:29 +0200551 st->finished_correctly = true;
552}
553
David Sedlák555c7202019-07-04 12:14:12 +0200554static void
555test_yin_parse_content(void **state)
556{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200557 struct test_parser_yin_state *st = *state;
David Sedlák555c7202019-07-04 12:14:12 +0200558 LY_ERR ret = LY_SUCCESS;
David Sedlák555c7202019-07-04 12:14:12 +0200559 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200560 "<myext:custom xmlns:myext=\"urn:example:extensions\">"
David Sedlák555c7202019-07-04 12:14:12 +0200561 "totally amazing extension"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200562 "</myext:custom>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200563 "<extension name=\"ext\">"
David Sedlák986cb412019-07-04 13:10:11 +0200564 "<argument name=\"argname\"></argument>"
565 "<description><text>desc</text></description>"
566 "<reference><text>ref</text></reference>"
567 "<status value=\"deprecated\"></status>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200568 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200569 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200570 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200571 "<when condition=\"condition...\">"
572 "<reference><text>when_ref</text></reference>"
573 "<description><text>when_desc</text></description>"
574 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200575 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200576 "<error-message>"
577 "<value>error-msg</value>"
578 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200579 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200580 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200581 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200582 "<position value=\"25\"></position>"
583 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200584 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200585 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200586 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200587 "<pattern value='pattern'>"
588 "<modifier value='invert-match'/>"
589 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200590 "<enum name=\"yay\">"
591 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200592 "</prefix>";
593 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200594 const char **if_features = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200595 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200596 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200597 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200598 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200599 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200600 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200601
Michal Vaskob36053d2020-03-26 15:49:30 +0100602 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
603 lyxml_ctx_next(st->yin_ctx->xmlctx);
604 lyxml_ctx_next(st->yin_ctx->xmlctx);
605 lyxml_ctx_next(st->yin_ctx->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200606
David Sedlákfd5b9c32019-07-12 15:33:13 +0200607 struct yin_subelement subelems[17] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200608 {LY_STMT_CONFIG, &config, 0},
609 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
610 {LY_STMT_ENUM, &enum_type, 0},
611 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
612 {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
613 {LY_STMT_EXTENSION, &ext_def, 0},
614 {LY_STMT_IF_FEATURE, &if_features, 0},
615 {LY_STMT_LENGTH, &len_type, 0},
616 {LY_STMT_PATTERN, &patter_type, 0},
617 {LY_STMT_POSITION, &pos_enum, 0},
618 {LY_STMT_RANGE, &range_type, 0},
619 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
620 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
621 {LY_STMT_VALUE, &val_enum, 0},
622 {LY_STMT_WHEN, &when_p, 0},
623 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
624 {LY_STMT_ARG_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200625 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100626 ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200627 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200628 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200629 assert_string_equal(def, "default-value");
David Sedláke0ef1c62019-09-13 10:05:55 +0200630 assert_string_equal(exts->name, "urn:example:extensions:custom");
David Sedlák555c7202019-07-04 12:14:12 +0200631 assert_string_equal(exts->argument, "totally amazing extension");
632 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200633 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200634 assert_string_equal(when_p->cond, "condition...");
635 assert_string_equal(when_p->dsc, "when_desc");
636 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200637 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200638 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200639 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200640 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200641 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200642 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200643 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200644 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200645 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200646 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200647 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200648 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200649 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200650 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200651 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200652 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200653 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200654 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200655 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200656 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200657 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200658 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200659 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200660 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200661 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200662 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200663 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200664 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200665 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200666 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200667 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200668 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200669 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200670 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200671 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200672 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200673 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200674 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200675 st = reset_state(state);
676
677 /* test unique subelem */
678 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200679 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
680 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
David Sedláke6cd89e2019-08-07 12:46:02 +0200681 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200682 "<prefix value=\"inv_mod\" />"
683 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
684 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200685 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100686 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
687 lyxml_ctx_next(st->yin_ctx->xmlctx);
688
689 ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200690 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200691 logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200692 lydict_remove(st->ctx, prefix_value);
693 lydict_remove(st->ctx, value);
694 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200695
696 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200697 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200698 "<prefix value=\"inv_mod\" />"
699 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
700 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200701 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200702 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
703 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
Michal Vaskob36053d2020-03-26 15:49:30 +0100704 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
705 lyxml_ctx_next(st->yin_ctx->xmlctx);
706
707 ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200708 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200709 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 +0200710 lydict_remove(st->ctx, prefix_value);
711 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200712
713 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200714 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200715 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Michal Vaskob36053d2020-03-26 15:49:30 +0100716 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
717 lyxml_ctx_next(st->yin_ctx->xmlctx);
718
719 ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200720 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200721 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200722
723 st->finished_correctly = true;
724}
725
David Sedlák92147b02019-07-09 14:01:01 +0200726static void
David Sedlák4a650532019-07-10 11:55:18 +0200727test_validate_value(void **state)
728{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200729 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +0100730 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
731
732 /* create some XML context */
733 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
734 st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
735 st->yin_ctx->xmlctx->dynamic = 0;
736
737 st->yin_ctx->xmlctx->value = "#invalid";
738 st->yin_ctx->xmlctx->value_len = 8;
739 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200740 logbuf_assert("Invalid identifier character '#'. Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100741
742 st->yin_ctx->xmlctx->value = "";
743 st->yin_ctx->xmlctx->value_len = 0;
744 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS);
745
746 st->yin_ctx->xmlctx->value = "pre:b";
747 st->yin_ctx->xmlctx->value_len = 5;
748 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
749 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
750
751 st->yin_ctx->xmlctx->value = "pre:pre:b";
752 st->yin_ctx->xmlctx->value_len = 9;
753 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200754
755 st->finished_correctly = true;
756}
757
David Sedlák32488102019-07-15 17:44:10 +0200758/* helper function to simplify unit test of each element using parse_content function */
759LY_ERR
Radek Krejci3a4889a2020-05-19 17:01:58 +0200760test_element_helper(struct test_parser_yin_state *st, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
David Sedlák32488102019-07-15 17:44:10 +0200761{
David Sedlákc5b20842019-08-13 10:18:31 +0200762 const char *name, *prefix;
763 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200764 LY_ERR ret = LY_SUCCESS;
765 struct yin_subelement subelems[71] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200766 {LY_STMT_ACTION, dest, 0},
767 {LY_STMT_ANYDATA, dest, 0},
768 {LY_STMT_ANYXML, dest, 0},
769 {LY_STMT_ARGUMENT,dest, 0},
770 {LY_STMT_AUGMENT, dest, 0},
771 {LY_STMT_BASE, dest, 0},
772 {LY_STMT_BELONGS_TO, dest, 0},
773 {LY_STMT_BIT, dest, 0},
774 {LY_STMT_CASE, dest, 0},
775 {LY_STMT_CHOICE, dest, 0},
776 {LY_STMT_CONFIG, dest, 0},
777 {LY_STMT_CONTACT, dest, 0},
778 {LY_STMT_CONTAINER, dest, 0},
779 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
780 {LY_STMT_DESCRIPTION, dest, 0},
781 {LY_STMT_DEVIATE, dest, 0},
782 {LY_STMT_DEVIATION, dest, 0},
783 {LY_STMT_ENUM, dest, 0},
784 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
785 {LY_STMT_ERROR_MESSAGE, dest, 0},
786 {LY_STMT_EXTENSION, dest, 0},
787 {LY_STMT_FEATURE, dest, 0},
788 {LY_STMT_FRACTION_DIGITS, dest, 0},
789 {LY_STMT_GROUPING, dest, 0},
790 {LY_STMT_IDENTITY, dest, 0},
791 {LY_STMT_IF_FEATURE, dest, 0},
792 {LY_STMT_IMPORT, dest, 0},
793 {LY_STMT_INCLUDE, dest, 0},
794 {LY_STMT_INPUT, dest, 0},
795 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
796 {LY_STMT_LEAF, dest, 0},
797 {LY_STMT_LEAF_LIST, dest, 0},
798 {LY_STMT_LENGTH, dest, 0},
799 {LY_STMT_LIST, dest, 0},
800 {LY_STMT_MANDATORY, dest, 0},
801 {LY_STMT_MAX_ELEMENTS, dest, 0},
802 {LY_STMT_MIN_ELEMENTS, dest, 0},
803 {LY_STMT_MODIFIER, dest, 0},
804 {LY_STMT_MODULE, dest, 0},
805 {LY_STMT_MUST, dest, 0},
806 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
807 {LY_STMT_NOTIFICATION, dest, 0},
808 {LY_STMT_ORDERED_BY, dest, 0},
809 {LY_STMT_ORGANIZATION, dest, 0},
810 {LY_STMT_OUTPUT, dest, 0},
811 {LY_STMT_PATH, dest, 0},
812 {LY_STMT_PATTERN, dest, 0},
813 {LY_STMT_POSITION, dest, 0},
814 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
815 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
816 {LY_STMT_RANGE, dest, 0},
817 {LY_STMT_REFERENCE, dest, 0},
818 {LY_STMT_REFINE, dest, 0},
819 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
820 {LY_STMT_REVISION, dest, 0},
821 {LY_STMT_REVISION_DATE, dest, 0},
822 {LY_STMT_RPC, dest, 0},
823 {LY_STMT_STATUS, dest, 0},
824 {LY_STMT_SUBMODULE, dest, 0},
825 {LY_STMT_TYPE, dest, 0},
826 {LY_STMT_TYPEDEF, dest, 0},
827 {LY_STMT_UNIQUE, dest, 0},
828 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
829 {LY_STMT_USES, dest, 0},
830 {LY_STMT_VALUE, dest, 0},
831 {LY_STMT_WHEN, dest, 0},
832 {LY_STMT_YANG_VERSION, dest, 0},
833 {LY_STMT_YIN_ELEMENT, dest, 0},
834 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
835 {LY_STMT_ARG_TEXT, dest, 0},
836 {LY_STMT_ARG_VALUE, dest, 0}
David Sedlák32488102019-07-15 17:44:10 +0200837 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100838 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
839 prefix = st->yin_ctx->xmlctx->prefix;
840 prefix_len = st->yin_ctx->xmlctx->prefix_len;
841 name = st->yin_ctx->xmlctx->name;
842 name_len = st->yin_ctx->xmlctx->name_len;
843 lyxml_ctx_next(st->yin_ctx->xmlctx);
844
845 ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
846
847 /* free parser */
848 lyxml_ctx_free(st->yin_ctx->xmlctx);
849 st->yin_ctx->xmlctx = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200850 return ret;
851}
852
David Sedlákd1144562019-08-06 12:36:14 +0200853#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
854
David Sedlák32488102019-07-15 17:44:10 +0200855static void
David Sedlák43801c92019-08-05 15:58:54 +0200856test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200857{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200858 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200859 struct lysp_type type = {};
860 const char *data;
861 data = ELEMENT_WRAPPER_START
862 "<enum name=\"enum-name\">"
863 "<if-feature name=\"feature\" />"
864 "<value value=\"55\" />"
865 "<status value=\"deprecated\" />"
866 "<description><text>desc...</text></description>"
867 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200868 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +0200869 "</enum>"
870 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100871 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200872 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200873 assert_string_equal(*type.enums->iffeatures, "feature");
874 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200875 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200876 assert_string_equal(type.enums->dsc, "desc...");
877 assert_string_equal(type.enums->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200878 assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200879 assert_int_equal(type.enums->exts->insubstmt_index, 0);
880 assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
881 lysp_type_free(st->ctx, &type);
882 memset(&type, 0, sizeof type);
883
884 data = ELEMENT_WRAPPER_START
885 "<enum name=\"enum-name\"></enum>"
886 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100887 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200888 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200889 lysp_type_free(st->ctx, &type);
890 memset(&type, 0, sizeof type);
891
David Sedlák43801c92019-08-05 15:58:54 +0200892 st->finished_correctly = true;
893}
894
895static void
896test_bit_elem(void **state)
897{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200898 struct test_parser_yin_state *st = *state;
David Sedlák43801c92019-08-05 15:58:54 +0200899 struct lysp_type type = {};
900 const char *data;
901 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200902 "<bit name=\"bit-name\">"
David Sedlák43801c92019-08-05 15:58:54 +0200903 "<if-feature name=\"feature\" />"
904 "<position value=\"55\" />"
905 "<status value=\"deprecated\" />"
906 "<description><text>desc...</text></description>"
907 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200908 EXT_SUBELEM
David Sedlák43801c92019-08-05 15:58:54 +0200909 "</bit>"
910 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100911 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200912 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200913 assert_string_equal(*type.bits->iffeatures, "feature");
914 assert_int_equal(type.bits->value, 55);
915 assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
916 assert_string_equal(type.bits->dsc, "desc...");
917 assert_string_equal(type.bits->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200918 assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200919 assert_int_equal(type.bits->exts->insubstmt_index, 0);
920 assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
921 lysp_type_free(st->ctx, &type);
922 memset(&type, 0, sizeof type);
923
924 data = ELEMENT_WRAPPER_START
925 "<bit name=\"bit-name\"> </bit>"
926 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100927 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200928 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200929 lysp_type_free(st->ctx, &type);
930 memset(&type, 0, sizeof type);
931
David Sedlák32488102019-07-15 17:44:10 +0200932 st->finished_correctly = true;
933}
934
935static void
936test_meta_elem(void **state)
937{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200938 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200939 char *value = NULL;
940 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200941 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200942
943 /* organization element */
944 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200945 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
David Sedlák32488102019-07-15 17:44:10 +0200946 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100947 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200948 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200949 assert_int_equal(exts[0].insubstmt_index, 0);
950 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedláke0ef1c62019-09-13 10:05:55 +0200951 assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200952 assert_int_equal(exts[1].insubstmt_index, 0);
953 assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedlák32488102019-07-15 17:44:10 +0200954 assert_string_equal(value, "organization...");
955 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200956 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200957 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200958 exts = NULL;
959
David Sedlák32488102019-07-15 17:44:10 +0200960 /* contact element */
961 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200962 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
David Sedlák32488102019-07-15 17:44:10 +0200963 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100964 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200965 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200966 assert_int_equal(exts[0].insubstmt_index, 0);
967 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200968 assert_string_equal(value, "contact...");
969 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200970 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
971 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200972 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200973
David Sedlák32488102019-07-15 17:44:10 +0200974 /* description element */
975 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200976 "<description><text>description...</text>" EXT_SUBELEM "</description>"
David Sedlák32488102019-07-15 17:44:10 +0200977 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100978 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200979 assert_string_equal(value, "description...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200980 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200981 assert_int_equal(exts[0].insubstmt_index, 0);
982 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200983 FREE_STRING(st->ctx, value);
984 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200985 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
986 exts = NULL;
987
David Sedlák32488102019-07-15 17:44:10 +0200988 /* reference element */
989 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200990 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
David Sedlák32488102019-07-15 17:44:10 +0200991 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100992 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200993 assert_string_equal(value, "reference...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200994 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200995 assert_int_equal(exts[0].insubstmt_index, 0);
996 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
David Sedlák32488102019-07-15 17:44:10 +0200997 FREE_STRING(st->ctx, value);
998 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200999 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1000 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001001
David Sedlákdf2a9732019-08-07 13:23:16 +02001002 /* reference element */
1003 data = ELEMENT_WRAPPER_START
1004 "<reference invalid=\"text\"><text>reference...</text>""</reference>"
1005 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001006 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001007 logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001008 FREE_STRING(st->ctx, value);
1009 value = NULL;
1010 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1011 exts = NULL;
1012
David Sedlák32488102019-07-15 17:44:10 +02001013 /* missing text subelement */
1014 data = ELEMENT_WRAPPER_START
1015 "<reference>reference...</reference>"
1016 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001017 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001018 logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001019
David Sedlákd1144562019-08-06 12:36:14 +02001020 /* reference element */
1021 data = ELEMENT_WRAPPER_START
1022 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
1023 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001024 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001025 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 +02001026 FREE_STRING(st->ctx, value);
1027 value = NULL;
1028 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1029 exts = NULL;
1030
David Sedlák32488102019-07-15 17:44:10 +02001031 st->finished_correctly = true;
1032}
1033
1034static void
1035test_import_elem(void **state)
1036{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001037 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001038 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02001039 struct lysp_import *imports = NULL;
1040 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +02001041
1042 /* max subelems */
1043 data = ELEMENT_WRAPPER_START
1044 "<import module=\"a\">"
David Sedlákd1144562019-08-06 12:36:14 +02001045 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001046 "<prefix value=\"a_mod\"/>"
1047 "<revision-date date=\"2015-01-01\"></revision-date>"
1048 "<description><text>import description</text></description>"
1049 "<reference><text>import reference</text></reference>"
1050 "</import>"
1051 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001052 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001053 assert_string_equal(imports->name, "a");
1054 assert_string_equal(imports->prefix, "a_mod");
1055 assert_string_equal(imports->rev, "2015-01-01");
1056 assert_string_equal(imports->dsc, "import description");
1057 assert_string_equal(imports->ref, "import reference");
David Sedláke0ef1c62019-09-13 10:05:55 +02001058 assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001059 assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
1060 assert_int_equal(imports->exts->insubstmt_index, 0);
David Sedlák298ff6d2019-07-26 14:29:03 +02001061 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1062 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001063
1064 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +02001065 data = ELEMENT_WRAPPER_START
1066 "<import module=\"a\">"
1067 "<prefix value=\"a_mod\"/>"
1068 "</import>"
1069 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001070 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001071 assert_string_equal(imports->prefix, "a_mod");
1072 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1073 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001074
1075 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +02001076 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001077 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001078 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
David Sedlák298ff6d2019-07-26 14:29:03 +02001079 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1080 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001081
1082 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +02001083 data = ELEMENT_WRAPPER_START
1084 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001085 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001086 "</import>"
1087 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001088 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001089 "</import>"
1090 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001091 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák298ff6d2019-07-26 14:29:03 +02001092 logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1.");
1093 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1094 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001095
1096 st->finished_correctly = true;
1097}
1098
1099static void
1100test_status_elem(void **state)
1101{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001102 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001103 const char *data;
1104 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001105 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001106
1107 /* test valid values */
1108 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001109 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001110 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001111
1112 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001113 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001114 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001115
David Sedlákd1144562019-08-06 12:36:14 +02001116 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001117 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001118 assert_true(flags & LYS_STATUS_OBSLT);
David Sedláke0ef1c62019-09-13 10:05:55 +02001119 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001120 assert_int_equal(exts[0].insubstmt_index, 0);
1121 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
1122 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1123 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001124
1125 /* test invalid value */
1126 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001127 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001128 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 +02001129 st->finished_correctly = true;
1130}
1131
1132static void
1133test_ext_elem(void **state)
1134{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001135 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001136 const char *data;
1137 struct lysp_ext *ext = NULL;
1138
1139 /* max subelems */
1140 data = ELEMENT_WRAPPER_START
1141 "<extension name=\"ext_name\">"
1142 "<argument name=\"arg\"></argument>"
1143 "<status value=\"current\"/>"
1144 "<description><text>ext_desc</text></description>"
1145 "<reference><text>ext_ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001146 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001147 "</extension>"
1148 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001149 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001150 assert_string_equal(ext->name, "ext_name");
1151 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001152 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001153 assert_string_equal(ext->dsc, "ext_desc");
1154 assert_string_equal(ext->ref, "ext_ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001155 assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001156 assert_int_equal(ext->exts[0].insubstmt_index, 0);
1157 assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák32488102019-07-15 17:44:10 +02001158 lysp_ext_free(st->ctx, ext);
1159 LY_ARRAY_FREE(ext);
1160 ext = NULL;
1161
1162 /* min subelems */
1163 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001164 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001165 assert_string_equal(ext->name, "ext_name");
1166 lysp_ext_free(st->ctx, ext);
1167 LY_ARRAY_FREE(ext);
1168 ext = NULL;
1169
1170 st->finished_correctly = true;
1171}
1172
1173static void
1174test_yin_element_elem(void **state)
1175{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001176 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001177 const char *data;
1178 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001179 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001180
1181 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001182 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001183 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001184
David Sedlákd1144562019-08-06 12:36:14 +02001185 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001186 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001187 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001188 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001189 assert_int_equal(exts[0].insubstmt_index, 0);
1190 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
1191 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001192
1193 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001194 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001195 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák26ea1432019-08-14 13:42:23 +02001196 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 +02001197 st->finished_correctly = true;
1198}
1199
1200static void
1201test_yangversion_elem(void **state)
1202{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001203 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001204 const char *data;
1205 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001206 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001207
1208 /* valid values */
1209 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001210 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001211 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001212 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1213
David Sedlákd1144562019-08-06 12:36:14 +02001214 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001215 assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001216 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001217 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
David Sedláke0ef1c62019-09-13 10:05:55 +02001218 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001219 assert_int_equal(exts[0].insubstmt_index, 0);
1220 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
1221 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001222
1223 /* invalid value */
1224 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001225 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001226 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 +02001227
1228 st->finished_correctly = true;
1229}
1230
1231static void
1232test_mandatory_elem(void **state)
1233{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001234 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001235 const char *data;
1236 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001237 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001238
1239 /* valid values */
1240 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001241 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001242 assert_int_equal(man, LYS_MAND_TRUE);
1243 man = 0;
1244
David Sedlákd1144562019-08-06 12:36:14 +02001245 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001246 assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001247 assert_int_equal(man, LYS_MAND_FALSE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001248 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001249 assert_int_equal(exts[0].insubstmt_index, 0);
1250 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
1251 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001252
1253 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001254 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001255 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 +02001256
1257 st->finished_correctly = true;
1258}
1259
David Sedlák8e7bda82019-07-16 17:57:50 +02001260static void
1261test_argument_elem(void **state)
1262{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001263 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001264 const char *data;
1265 uint16_t flags = 0;
1266 const char *arg;
1267 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001268 struct lysp_ext_instance *exts = NULL;
1269
David Sedlák8e7bda82019-07-16 17:57:50 +02001270 /* max subelems */
1271 data = ELEMENT_WRAPPER_START
1272 "<argument name=\"arg-name\">"
1273 "<yin-element value=\"true\" />"
David Sedlákd1144562019-08-06 12:36:14 +02001274 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001275 "</argument>"
1276 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001277 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001278 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001279 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001280 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001281 assert_int_equal(exts[0].insubstmt_index, 0);
1282 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
1283 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1284 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001285 flags = 0;
1286 FREE_STRING(st->ctx, arg);
1287 arg = NULL;
1288
1289 /* min subelems */
1290 data = ELEMENT_WRAPPER_START
1291 "<argument name=\"arg\">"
1292 "</argument>"
1293 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001294 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001295 assert_string_equal(arg, "arg");
1296 assert_true(flags == 0);
1297 FREE_STRING(st->ctx, arg);
1298
1299 st->finished_correctly = true;
1300}
1301
1302static void
1303test_base_elem(void **state)
1304{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001305 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001306 const char *data;
1307 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001308 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001309 struct lysp_type type = {};
1310
1311 /* as identity subelement */
1312 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001313 "<base name=\"base-name\">"
1314 EXT_SUBELEM
1315 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001316 "</identity>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001317 assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001318 assert_string_equal(*bases, "base-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001319 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001320 assert_int_equal(exts[0].insubstmt_index, 0);
1321 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1322 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1323 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001324 FREE_STRING(st->ctx, *bases);
1325 LY_ARRAY_FREE(bases);
1326
1327 /* as type subelement */
1328 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001329 "<base name=\"base-name\">"
1330 EXT_SUBELEM
1331 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001332 "</type>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001333 assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001334 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001335 assert_true(type.flags & LYS_SET_BASE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001336 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001337 assert_int_equal(exts[0].insubstmt_index, 0);
1338 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1339 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1340 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001341 FREE_STRING(st->ctx, *type.bases);
1342 LY_ARRAY_FREE(type.bases);
1343
1344 st->finished_correctly = true;
1345}
1346
1347static void
1348test_belongsto_elem(void **state)
1349{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001350 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001351 const char *data;
1352 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001353 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001354
1355 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001356 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001357 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001358 assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001359 assert_string_equal(submod.belongsto, "module-name");
1360 assert_string_equal(submod.prefix, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001361 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001362 assert_int_equal(exts[0].insubstmt_index, 0);
1363 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
1364 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1365 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001366 FREE_STRING(st->ctx, submod.belongsto);
1367 FREE_STRING(st->ctx, submod.prefix);
1368
1369 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001370 assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001371 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001372 FREE_STRING(st->ctx, submod.belongsto);
1373
1374 st->finished_correctly = true;
1375}
1376
1377static void
1378test_config_elem(void **state)
1379{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001380 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001381 const char *data;
1382 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001383 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001384
David Sedlákd1144562019-08-06 12:36:14 +02001385 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001386 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001387 assert_true(flags & LYS_CONFIG_W);
David Sedláke0ef1c62019-09-13 10:05:55 +02001388 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001389 assert_int_equal(exts[0].insubstmt_index, 0);
1390 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
1391 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1392 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001393 flags = 0;
1394
1395 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001396 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001397 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001398 flags = 0;
1399
1400 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001401 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001402 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 +02001403
1404 st->finished_correctly = true;
1405}
1406
1407static void
1408test_default_elem(void **state)
1409{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001410 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001411 const char *data;
1412 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001413 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001414
David Sedlákd1144562019-08-06 12:36:14 +02001415 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001416 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001417 assert_string_equal(val, "defaul-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02001418 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001419 assert_int_equal(exts[0].insubstmt_index, 0);
1420 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
1421 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1422 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001423 FREE_STRING(st->ctx, val);
1424 val = NULL;
1425
1426 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001427 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001428 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1429
1430 st->finished_correctly = true;
1431}
1432
1433static void
1434test_err_app_tag_elem(void **state)
1435{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001436 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001437 const char *data;
1438 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001439 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001440
David Sedlákd1144562019-08-06 12:36:14 +02001441 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001442 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001443 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001444 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001445 assert_int_equal(exts[0].insubstmt_index, 0);
1446 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
1447 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1448 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001449 FREE_STRING(st->ctx, val);
1450 val = NULL;
1451
1452 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001453 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001454 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1455
1456 st->finished_correctly = true;
1457}
1458
1459static void
1460test_err_msg_elem(void **state)
1461{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001462 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001463 const char *data;
1464 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001465 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001466
David Sedlákd1144562019-08-06 12:36:14 +02001467 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001468 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001469 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001470 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001471 assert_int_equal(exts[0].insubstmt_index, 0);
1472 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
1473 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1474 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001475 FREE_STRING(st->ctx, val);
1476
1477 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001478 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001479 logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001480
David Sedlákdf2a9732019-08-07 13:23:16 +02001481 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001482 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001483 logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001484
David Sedlák8e7bda82019-07-16 17:57:50 +02001485 st->finished_correctly = true;
1486}
1487
1488static void
1489test_fracdigits_elem(void **state)
1490{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001491 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001492 const char *data;
1493 struct lysp_type type = {};
1494
1495 /* valid value */
David Sedlákd1144562019-08-06 12:36:14 +02001496 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001497 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +02001498 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001499 assert_int_equal(type.exts[0].insubstmt_index, 0);
1500 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001501 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001502 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlákd1144562019-08-06 12:36:14 +02001503 FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001504
1505 /* invalid values */
1506 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001507 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001508 logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001509
1510 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001511 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001512 logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001513
1514 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001515 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001516 logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001517
1518 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001519 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001520 logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001521
1522 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001523 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001524 logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001525
1526 st->finished_correctly = true;
1527}
1528
1529static void
1530test_iffeature_elem(void **state)
1531{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001532 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001533 const char *data;
1534 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001535 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001536
David Sedlákd1144562019-08-06 12:36:14 +02001537 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001538 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001539 assert_string_equal(*iffeatures, "local-storage");
David Sedláke0ef1c62019-09-13 10:05:55 +02001540 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001541 assert_int_equal(exts[0].insubstmt_index, 0);
1542 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
1543 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1544 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001545 FREE_STRING(st->ctx, *iffeatures);
1546 LY_ARRAY_FREE(iffeatures);
1547 iffeatures = NULL;
1548
1549 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001550 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001551 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1552 LY_ARRAY_FREE(iffeatures);
1553 iffeatures = NULL;
1554
1555 st->finished_correctly = true;
1556}
1557
1558static void
1559test_length_elem(void **state)
1560{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001561 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001562 const char *data;
1563 struct lysp_type type = {};
1564
1565 /* max subelems */
1566 data = ELEMENT_WRAPPER_START
1567 "<length value=\"length-str\">"
1568 "<error-message><value>err-msg</value></error-message>"
1569 "<error-app-tag value=\"err-app-tag\"/>"
1570 "<description><text>desc</text></description>"
1571 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001572 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001573 "</length>"
1574 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001575 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001576 assert_string_equal(type.length->arg, "length-str");
1577 assert_string_equal(type.length->emsg, "err-msg");
1578 assert_string_equal(type.length->eapptag, "err-app-tag");
1579 assert_string_equal(type.length->dsc, "desc");
1580 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001581 assert_true(type.flags & LYS_SET_LENGTH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001582 assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001583 assert_int_equal(type.length->exts[0].insubstmt_index, 0);
1584 assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001585 lysp_type_free(st->ctx, &type);
1586 memset(&type, 0, sizeof(type));
1587
1588 /* min subelems */
1589 data = ELEMENT_WRAPPER_START
1590 "<length value=\"length-str\">"
1591 "</length>"
1592 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001593 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001594 assert_string_equal(type.length->arg, "length-str");
1595 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001596 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001597 memset(&type, 0, sizeof(type));
1598
1599 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001600 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001601 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1602 lysp_type_free(st->ctx, &type);
1603 memset(&type, 0, sizeof(type));
1604
1605 st->finished_correctly = true;
1606}
1607
1608static void
1609test_modifier_elem(void **state)
1610{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001611 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001612 const char *data;
1613 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
David Sedlákd1144562019-08-06 12:36:14 +02001614 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001615
David Sedlákd1144562019-08-06 12:36:14 +02001616 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001617 assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001618 assert_string_equal(pat, "\x015pattern");
David Sedláke0ef1c62019-09-13 10:05:55 +02001619 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001620 assert_int_equal(exts[0].insubstmt_index, 0);
1621 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
1622 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1623 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001624 FREE_STRING(st->ctx, pat);
1625
1626 pat = lydict_insert(st->ctx, "\006pattern", 8);
1627 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001628 assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001629 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 +02001630 FREE_STRING(st->ctx, pat);
1631
1632 st->finished_correctly = true;
1633}
1634
1635static void
1636test_namespace_elem(void **state)
1637{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001638 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001639 const char *data;
1640 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001641 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001642
David Sedlákd1144562019-08-06 12:36:14 +02001643 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001644 assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001645 assert_string_equal(ns, "ns");
David Sedláke0ef1c62019-09-13 10:05:55 +02001646 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001647 assert_int_equal(exts[0].insubstmt_index, 0);
1648 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
1649 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1650 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001651 FREE_STRING(st->ctx, ns);
1652
1653 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001654 assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001655 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1656
1657 st->finished_correctly = true;
1658}
1659
1660static void
David Sedlák8e7bda82019-07-16 17:57:50 +02001661test_pattern_elem(void **state)
1662{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001663 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001664 const char *data;
1665 struct lysp_type type = {};
1666
1667 /* max subelems */
1668 data = ELEMENT_WRAPPER_START
1669 "<pattern value=\"super_pattern\">"
1670 "<modifier value=\"invert-match\"/>"
1671 "<error-message><value>err-msg-value</value></error-message>"
1672 "<error-app-tag value=\"err-app-tag-value\"/>"
David Sedlák169cc522019-08-15 13:23:45 +02001673 "<description><text>&quot;pattern-desc&quot;</text></description>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001674 "<reference><text>pattern-ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001675 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001676 "</pattern>"
1677 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001678 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001679 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001680 assert_string_equal(type.patterns->arg, "\x015super_pattern");
David Sedlák169cc522019-08-15 13:23:45 +02001681 assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
David Sedlák8e7bda82019-07-16 17:57:50 +02001682 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1683 assert_string_equal(type.patterns->emsg, "err-msg-value");
David Sedlák8e7bda82019-07-16 17:57:50 +02001684 assert_string_equal(type.patterns->ref, "pattern-ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001685 assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001686 assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
1687 assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001688 lysp_type_free(st->ctx, &type);
1689 memset(&type, 0, sizeof(type));
1690
1691 /* min subelems */
1692 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001693 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001694 assert_string_equal(type.patterns->arg, "\x006pattern");
1695 lysp_type_free(st->ctx, &type);
1696 memset(&type, 0, sizeof(type));
1697
1698 st->finished_correctly = true;
1699}
1700
1701static void
1702test_value_position_elem(void **state)
1703{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001704 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001705 const char *data;
1706 struct lysp_type_enum en = {};
1707
1708 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001709 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001710 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001711 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001712 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001713 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001714 assert_int_equal(en.exts[0].insubstmt_index, 0);
1715 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
1716 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001717 memset(&en, 0, sizeof(en));
1718
1719 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001720 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001721 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001722 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001723 memset(&en, 0, sizeof(en));
1724
1725 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001726 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001727 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001728 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001729 memset(&en, 0, sizeof(en));
1730
1731 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001732 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001733 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001734 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001735 memset(&en, 0, sizeof(en));
1736
1737 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001738 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001739 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001740 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001741 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001742 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlák8d552d62019-08-06 15:29:05 +02001743 assert_int_equal(en.exts[0].insubstmt_index, 0);
1744 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
1745 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001746 memset(&en, 0, sizeof(en));
1747
1748 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001749 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001750 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001751 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001752 memset(&en, 0, sizeof(en));
1753
1754 /* invalid values */
1755 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001756 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001757 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001758
1759 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001760 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001761 logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001762
David Sedlák69f01612019-07-17 11:41:08 +02001763 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001764 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001765 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001766
David Sedlák8e7bda82019-07-16 17:57:50 +02001767 /*invalid positions */
1768 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001769 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001770 logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001771
1772 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001773 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001774 logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001775
1776 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001777 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001778 logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001779
David Sedlák69f01612019-07-17 11:41:08 +02001780 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001781 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001782 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001783
1784 st->finished_correctly = true;
1785}
1786
1787static void
1788test_prefix_elem(void **state)
1789{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001790 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001791 const char *data;
1792 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001793 struct lysp_ext_instance *exts = NULL;
1794
1795 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001796 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001797 assert_string_equal(value, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001798 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001799 assert_int_equal(exts[0].insubstmt_index, 0);
1800 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
1801 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1802 exts = NULL;
1803 FREE_STRING(st->ctx, value);
David Sedlák69f01612019-07-17 11:41:08 +02001804
1805 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001806 assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001807 assert_string_equal(value, "pref");
1808 FREE_STRING(st->ctx, value);
1809
1810 st->finished_correctly = true;
1811}
1812
1813static void
1814test_range_elem(void **state)
1815{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001816 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001817 const char *data;
1818 struct lysp_type type = {};
1819
1820 /* max subelems */
1821 data = ELEMENT_WRAPPER_START
1822 "<range value=\"range-str\">"
1823 "<error-message><value>err-msg</value></error-message>"
1824 "<error-app-tag value=\"err-app-tag\" />"
1825 "<description><text>desc</text></description>"
1826 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001827 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001828 "</range>"
1829 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001830 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001831 assert_string_equal(type.range->arg, "range-str");
1832 assert_string_equal(type.range->dsc, "desc");
1833 assert_string_equal(type.range->eapptag, "err-app-tag");
1834 assert_string_equal(type.range->emsg, "err-msg");
1835 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001836 assert_true(type.flags & LYS_SET_RANGE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001837 assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001838 assert_int_equal(type.range->exts[0].insubstmt_index, 0);
1839 assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001840 lysp_type_free(st->ctx, &type);
1841 memset(&type, 0, sizeof(type));
1842
1843 /* min subelems */
1844 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001845 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001846 assert_string_equal(type.range->arg, "range-str");
1847 lysp_type_free(st->ctx, &type);
1848 memset(&type, 0, sizeof(type));
1849
1850 st->finished_correctly = true;
1851}
1852
1853static void
1854test_reqinstance_elem(void **state)
1855{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001856 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001857 const char *data;
1858 struct lysp_type type = {};
1859
David Sedlákd1144562019-08-06 12:36:14 +02001860 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001861 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001862 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001863 assert_true(type.flags & LYS_SET_REQINST);
David Sedláke0ef1c62019-09-13 10:05:55 +02001864 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001865 assert_int_equal(type.exts[0].insubstmt_index, 0);
1866 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
1867 lysp_type_free(st->ctx, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001868 memset(&type, 0, sizeof(type));
1869
1870 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001871 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001872 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001873 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001874 memset(&type, 0, sizeof(type));
1875
1876 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001877 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001878 memset(&type, 0, sizeof(type));
David Sedlák26ea1432019-08-14 13:42:23 +02001879 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 +02001880
1881 st->finished_correctly = true;
1882}
1883
1884static void
1885test_revision_date_elem(void **state)
1886{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001887 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001888 const char *data;
1889 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001890 struct lysp_ext_instance *exts = NULL;
1891
1892 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001893 assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001894 assert_string_equal(rev, "2000-01-01");
David Sedláke0ef1c62019-09-13 10:05:55 +02001895 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001896 assert_int_equal(exts[0].insubstmt_index, 0);
1897 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
1898 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001899
1900 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001901 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001902 assert_string_equal(rev, "2000-01-01");
1903
1904 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001905 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001906 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1907
1908 st->finished_correctly = true;
1909}
1910
1911static void
1912test_unique_elem(void **state)
1913{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001914 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001915 const char *data;
1916 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001917 struct lysp_ext_instance *exts = NULL;
1918
1919 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001920 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001921 assert_string_equal(*values, "tag");
David Sedláke0ef1c62019-09-13 10:05:55 +02001922 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001923 assert_int_equal(exts[0].insubstmt_index, 0);
1924 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
1925 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1926 FREE_STRING(st->ctx, *values);
1927 LY_ARRAY_FREE(values);
1928 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001929
1930 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001931 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001932 assert_string_equal(*values, "tag");
1933 FREE_STRING(st->ctx, *values);
1934 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001935 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001936
1937 st->finished_correctly = true;
1938}
1939
1940static void
1941test_units_elem(void **state)
1942{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001943 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001944 const char *data;
1945 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001946 struct lysp_ext_instance *exts = NULL;
1947
1948 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001949 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001950 assert_string_equal(values, "name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001951 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001952 assert_int_equal(exts[0].insubstmt_index, 0);
1953 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
1954 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1955 FREE_STRING(st->ctx, values);
1956 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001957
1958 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001959 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001960 assert_string_equal(values, "name");
1961 FREE_STRING(st->ctx, values);
David Sedlákd1144562019-08-06 12:36:14 +02001962 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001963
1964 st->finished_correctly = true;
1965}
1966
1967static void
1968test_when_elem(void **state)
1969{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001970 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001971 const char *data;
1972 struct lysp_when *when = NULL;
1973
1974 data = ELEMENT_WRAPPER_START
1975 "<when condition=\"cond\">"
1976 "<description><text>desc</text></description>"
1977 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001978 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001979 "</when>"
1980 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001981 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001982 assert_string_equal(when->cond, "cond");
1983 assert_string_equal(when->dsc, "desc");
1984 assert_string_equal(when->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001985 assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001986 assert_int_equal(when->exts[0].insubstmt_index, 0);
1987 assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001988 lysp_when_free(st->ctx, when);
1989 free(when);
1990 when = NULL;
1991
1992 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001993 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001994 assert_string_equal(when->cond, "cond");
1995 lysp_when_free(st->ctx, when);
1996 free(when);
1997 when = NULL;
1998
1999 st->finished_correctly = true;
2000}
2001
2002static void
2003test_yin_text_value_elem(void **state)
2004{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002005 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02002006 const char *data;
2007 const char *val;
2008
2009 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002010 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002011 assert_string_equal(val, "text");
2012 FREE_STRING(st->ctx, val);
2013
2014 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002015 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002016 assert_string_equal(val, "text");
2017 FREE_STRING(st->ctx, val);
2018
2019 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002020 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002021 assert_string_equal("", val);
2022 FREE_STRING(st->ctx, val);
2023
David Sedlák8e7bda82019-07-16 17:57:50 +02002024 st->finished_correctly = true;
2025}
David Sedlák32488102019-07-15 17:44:10 +02002026
David Sedlák374d2b32019-07-17 15:06:55 +02002027static void
2028test_type_elem(void **state)
2029{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002030 struct test_parser_yin_state *st = *state;
David Sedlák374d2b32019-07-17 15:06:55 +02002031 const char *data;
2032 struct lysp_type type = {};
2033
2034 /* max subelems */
2035 data = ELEMENT_WRAPPER_START
2036 "<type name=\"type-name\">"
2037 "<base name=\"base-name\"/>"
2038 "<bit name=\"bit\"/>"
2039 "<enum name=\"enum\"/>"
2040 "<fraction-digits value=\"2\"/>"
2041 "<length value=\"length\"/>"
2042 "<path value=\"path\"/>"
2043 "<pattern value=\"pattern\"/>"
2044 "<range value=\"range\" />"
2045 "<require-instance value=\"true\"/>"
2046 "<type name=\"sub-type-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002047 EXT_SUBELEM
David Sedlák374d2b32019-07-17 15:06:55 +02002048 "</type>"
2049 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002050 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002051 assert_string_equal(type.name, "type-name");
2052 assert_string_equal(*type.bases, "base-name");
2053 assert_string_equal(type.bits->name, "bit");
2054 assert_string_equal(type.enums->name, "enum");
2055 assert_int_equal(type.fraction_digits, 2);
2056 assert_string_equal(type.length->arg, "length");
Michal Vasko004d3152020-06-11 19:59:22 +02002057 assert_string_equal(type.path->expr, "path");
David Sedlák374d2b32019-07-17 15:06:55 +02002058 assert_string_equal(type.patterns->arg, "\006pattern");
2059 assert_string_equal(type.range->arg, "range");
2060 assert_int_equal(type.require_instance, 1);
2061 assert_string_equal(type.types->name, "sub-type-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02002062 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002063 assert_int_equal(type.exts[0].insubstmt_index, 0);
2064 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002065 assert_true(type.flags & LYS_SET_BASE);
2066 assert_true(type.flags & LYS_SET_BIT);
2067 assert_true(type.flags & LYS_SET_ENUM);
2068 assert_true(type.flags & LYS_SET_FRDIGITS);
2069 assert_true(type.flags & LYS_SET_LENGTH);
2070 assert_true(type.flags & LYS_SET_PATH);
2071 assert_true(type.flags & LYS_SET_PATTERN);
2072 assert_true(type.flags & LYS_SET_RANGE);
2073 assert_true(type.flags & LYS_SET_REQINST);
2074 assert_true(type.flags & LYS_SET_TYPE);
David Sedlákd1144562019-08-06 12:36:14 +02002075 lysp_type_free(st->ctx, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02002076 memset(&type, 0, sizeof(type));
2077
2078 /* min subelems */
2079 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002080 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002081 lysp_type_free(st->ctx, &type);
2082 memset(&type, 0, sizeof(type));
2083
2084 st->finished_correctly = true;
2085}
2086
David Sedlák1af868e2019-07-17 17:03:14 +02002087static void
2088test_max_elems_elem(void **state)
2089{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002090 struct test_parser_yin_state *st = *state;
David Sedlák1af868e2019-07-17 17:03:14 +02002091 const char *data;
2092 struct lysp_node_list list = {};
2093 struct lysp_node_leaflist llist = {};
2094 struct lysp_refine refine = {};
2095
David Sedlákd1144562019-08-06 12:36:14 +02002096 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002097 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002098 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002099 assert_true(refine.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002100 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002101 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2102 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2103 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002104
David Sedlákd1144562019-08-06 12:36:14 +02002105 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002106 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002107 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002108 assert_true(list.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002109 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002110 assert_int_equal(list.exts[0].insubstmt_index, 0);
2111 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2112 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002113
David Sedlákd1144562019-08-06 12:36:14 +02002114 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002115 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002116 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002117 assert_true(llist.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002118 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002119 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2120 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2121 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002122
2123 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002124 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002125 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002126 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02002127
2128 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002129 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002130 logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002131
2132 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002133 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002134 logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002135
2136 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002137 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002138 logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002139
2140 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002141 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002142 logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002143
2144 st->finished_correctly = true;
2145}
2146
David Sedlák09e18c92019-07-18 11:17:11 +02002147static void
2148test_min_elems_elem(void **state)
2149{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002150 struct test_parser_yin_state *st = *state;
David Sedlák09e18c92019-07-18 11:17:11 +02002151 const char *data;
2152 struct lysp_node_list list = {};
2153 struct lysp_node_leaflist llist = {};
2154 struct lysp_refine refine = {};
2155
David Sedlákd1144562019-08-06 12:36:14 +02002156 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002157 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002158 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002159 assert_true(refine.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002160 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002161 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2162 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2163 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002164
David Sedlákd1144562019-08-06 12:36:14 +02002165 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002166 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002167 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002168 assert_true(list.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002169 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002170 assert_int_equal(list.exts[0].insubstmt_index, 0);
2171 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2172 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002173
David Sedlákd1144562019-08-06 12:36:14 +02002174 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002175 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002176 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002177 assert_true(llist.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002178 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002179 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2180 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2181 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002182
2183 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002184 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002185 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 +02002186
2187 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002188 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002189 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 +02002190
2191 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002192 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002193 logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002194
2195 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002196 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002197 logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002198
2199 st->finished_correctly = true;
2200}
2201
David Sedláka2dad212019-07-18 12:45:19 +02002202static void
2203test_ordby_elem(void **state)
2204{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002205 struct test_parser_yin_state *st = *state;
David Sedláka2dad212019-07-18 12:45:19 +02002206 const char *data;
2207 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02002208 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02002209
David Sedlákd1144562019-08-06 12:36:14 +02002210 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002211 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002212 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláke0ef1c62019-09-13 10:05:55 +02002213 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002214 assert_int_equal(exts[0].insubstmt_index, 0);
2215 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
2216 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02002217
2218 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002219 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002220 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02002221
2222 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002223 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02002224 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 +02002225
2226 st->finished_correctly = true;
2227}
2228
David Sedlák8a83bbb2019-07-18 14:46:00 +02002229static void
2230test_any_elem(void **state)
2231{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002232 struct test_parser_yin_state *st = *state;
David Sedlák8a83bbb2019-07-18 14:46:00 +02002233 const char *data;
2234 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002235 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02002236 struct lysp_node_anydata *parsed = NULL;
2237
2238 /* anyxml max subelems */
2239 data = ELEMENT_WRAPPER_START
2240 "<anyxml name=\"any-name\">"
2241 "<config value=\"true\" />"
2242 "<description><text>desc</text></description>"
2243 "<if-feature name=\"feature\" />"
2244 "<mandatory value=\"true\" />"
2245 "<must condition=\"must-cond\" />"
2246 "<reference><text>ref</text></reference>"
2247 "<status value=\"deprecated\"/>"
2248 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002249 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002250 "</anyxml>"
2251 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002252 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002253 parsed = (struct lysp_node_anydata *)siblings;
2254 assert_null(parsed->parent);
2255 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002256 assert_true(parsed->flags & LYS_CONFIG_W);
2257 assert_true(parsed->flags & LYS_MAND_TRUE);
2258 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002259 assert_null(parsed->next);
2260 assert_string_equal(parsed->name, "any-name");
2261 assert_string_equal(parsed->dsc, "desc");
2262 assert_string_equal(parsed->ref, "ref");
2263 assert_string_equal(parsed->when->cond, "when-cond");
2264 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002265 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002266 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2267 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002268 lysp_node_free(st->ctx, siblings);
2269 siblings = NULL;
2270
2271 /* anydata max subelems */
2272 data = ELEMENT_WRAPPER_START
2273 "<anydata name=\"any-name\">"
2274 "<config value=\"true\" />"
2275 "<description><text>desc</text></description>"
2276 "<if-feature name=\"feature\" />"
2277 "<mandatory value=\"true\" />"
2278 "<must condition=\"must-cond\" />"
2279 "<reference><text>ref</text></reference>"
2280 "<status value=\"deprecated\"/>"
2281 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002282 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002283 "</anydata>"
2284 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002285 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002286 parsed = (struct lysp_node_anydata *)siblings;
2287 assert_null(parsed->parent);
2288 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002289 assert_true(parsed->flags & LYS_CONFIG_W);
2290 assert_true(parsed->flags & LYS_MAND_TRUE);
2291 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002292 assert_null(parsed->next);
2293 assert_string_equal(parsed->name, "any-name");
2294 assert_string_equal(parsed->dsc, "desc");
2295 assert_string_equal(parsed->ref, "ref");
2296 assert_string_equal(parsed->when->cond, "when-cond");
2297 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002298 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002299 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2300 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002301 lysp_node_free(st->ctx, siblings);
2302 siblings = NULL;
2303
2304 /* min subelems */
2305 node_meta.parent = (void *)0x10;
2306 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002307 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002308 parsed = (struct lysp_node_anydata *)siblings;
2309 assert_ptr_equal(parsed->parent, node_meta.parent);
2310 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
2311 assert_null(parsed->next);
2312 assert_null(parsed->exts);
2313 lysp_node_free(st->ctx, siblings);
2314
2315 st->finished_correctly = true;
2316}
2317
David Sedlák203ca3a2019-07-18 15:26:25 +02002318static void
2319test_leaf_elem(void **state)
2320{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002321 struct test_parser_yin_state *st = *state;
David Sedlák203ca3a2019-07-18 15:26:25 +02002322 const char *data;
2323 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002324 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002325 struct lysp_node_leaf *parsed = NULL;
2326
2327 /* max elements */
2328 data = ELEMENT_WRAPPER_START
2329 "<leaf name=\"leaf\">"
2330 "<config value=\"true\" />"
2331 "<default value=\"def-val\"/>"
2332 "<description><text>desc</text></description>"
2333 "<if-feature name=\"feature\" />"
2334 "<mandatory value=\"true\" />"
2335 "<must condition=\"must-cond\" />"
2336 "<reference><text>ref</text></reference>"
2337 "<status value=\"deprecated\"/>"
2338 "<type name=\"type\"/>"
2339 "<units name=\"uni\"/>"
2340 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002341 EXT_SUBELEM
David Sedlák203ca3a2019-07-18 15:26:25 +02002342 "</leaf>"
2343 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002344 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002345 parsed = (struct lysp_node_leaf *)siblings;
2346 assert_null(parsed->parent);
2347 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002348 assert_true(parsed->flags & LYS_CONFIG_W);
2349 assert_true(parsed->flags & LYS_MAND_TRUE);
2350 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02002351 assert_null(parsed->next);
2352 assert_string_equal(parsed->name, "leaf");
2353 assert_string_equal(parsed->dsc, "desc");
2354 assert_string_equal(parsed->ref, "ref");
2355 assert_string_equal(parsed->when->cond, "when-cond");
2356 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002357 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002358 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2359 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák203ca3a2019-07-18 15:26:25 +02002360 assert_string_equal(parsed->musts->arg, "must-cond");
2361 assert_string_equal(parsed->type.name, "type");
2362 assert_string_equal(parsed->units, "uni");
2363 assert_string_equal(parsed->dflt, "def-val");
2364 lysp_node_free(st->ctx, siblings);
2365 siblings = NULL;
2366
2367 /* min elements */
2368 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002369 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002370 parsed = (struct lysp_node_leaf *)siblings;
2371 assert_string_equal(parsed->name, "leaf");
2372 assert_string_equal(parsed->type.name, "type");
2373 lysp_node_free(st->ctx, siblings);
2374 siblings = NULL;
2375
2376 st->finished_correctly = true;
2377}
2378
David Sedlákc3da3ef2019-07-19 12:56:08 +02002379static void
2380test_leaf_list_elem(void **state)
2381{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002382 struct test_parser_yin_state *st = *state;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002383 const char *data;
2384 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002385 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002386 struct lysp_node_leaflist *parsed = NULL;
2387
2388 data = ELEMENT_WRAPPER_START
2389 "<leaf-list name=\"llist\">"
2390 "<config value=\"true\" />"
2391 "<default value=\"def-val0\"/>"
2392 "<default value=\"def-val1\"/>"
2393 "<description><text>desc</text></description>"
2394 "<if-feature name=\"feature\"/>"
2395 "<max-elements value=\"5\"/>"
2396 "<must condition=\"must-cond\"/>"
2397 "<ordered-by value=\"user\" />"
2398 "<reference><text>ref</text></reference>"
2399 "<status value=\"current\"/>"
2400 "<type name=\"type\"/>"
2401 "<units name=\"uni\"/>"
2402 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002403 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002404 "</leaf-list>"
2405 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002406 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002407 parsed = (struct lysp_node_leaflist *)siblings;
2408 assert_string_equal(parsed->dflts[0], "def-val0");
2409 assert_string_equal(parsed->dflts[1], "def-val1");
2410 assert_string_equal(parsed->dsc, "desc");
2411 assert_string_equal(*parsed->iffeatures, "feature");
2412 assert_int_equal(parsed->max, 5);
2413 assert_string_equal(parsed->musts->arg, "must-cond");
2414 assert_string_equal(parsed->name, "llist");
2415 assert_null(parsed->next);
2416 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2417 assert_null(parsed->parent);
2418 assert_string_equal(parsed->ref, "ref");
2419 assert_string_equal(parsed->type.name, "type");
2420 assert_string_equal(parsed->units, "uni");
2421 assert_string_equal(parsed->when->cond, "when-cond");
2422 assert_true(parsed->flags & LYS_CONFIG_W);
2423 assert_true(parsed->flags & LYS_ORDBY_USER);
2424 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002425 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002426 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2427 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002428 lysp_node_free(st->ctx, siblings);
2429 siblings = NULL;
2430
2431 data = ELEMENT_WRAPPER_START
2432 "<leaf-list name=\"llist\">"
2433 "<config value=\"true\" />"
2434 "<description><text>desc</text></description>"
2435 "<if-feature name=\"feature\"/>"
2436 "<min-elements value=\"5\"/>"
2437 "<must condition=\"must-cond\"/>"
2438 "<ordered-by value=\"user\" />"
2439 "<reference><text>ref</text></reference>"
2440 "<status value=\"current\"/>"
2441 "<type name=\"type\"/>"
2442 "<units name=\"uni\"/>"
2443 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002444 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002445 "</leaf-list>"
2446 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002447 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002448 parsed = (struct lysp_node_leaflist *)siblings;
2449 assert_string_equal(parsed->dsc, "desc");
2450 assert_string_equal(*parsed->iffeatures, "feature");
2451 assert_int_equal(parsed->min, 5);
2452 assert_string_equal(parsed->musts->arg, "must-cond");
2453 assert_string_equal(parsed->name, "llist");
2454 assert_null(parsed->next);
2455 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2456 assert_null(parsed->parent);
2457 assert_string_equal(parsed->ref, "ref");
2458 assert_string_equal(parsed->type.name, "type");
2459 assert_string_equal(parsed->units, "uni");
2460 assert_string_equal(parsed->when->cond, "when-cond");
2461 assert_true(parsed->flags & LYS_CONFIG_W);
2462 assert_true(parsed->flags & LYS_ORDBY_USER);
2463 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002464 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002465 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2466 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002467 lysp_node_free(st->ctx, siblings);
2468 siblings = NULL;
2469
2470 data = ELEMENT_WRAPPER_START
2471 "<leaf-list name=\"llist\">"
2472 "<config value=\"true\" />"
2473 "<description><text>desc</text></description>"
2474 "<if-feature name=\"feature\"/>"
2475 "<max-elements value=\"15\"/>"
2476 "<min-elements value=\"5\"/>"
2477 "<must condition=\"must-cond\"/>"
2478 "<ordered-by value=\"user\" />"
2479 "<reference><text>ref</text></reference>"
2480 "<status value=\"current\"/>"
2481 "<type name=\"type\"/>"
2482 "<units name=\"uni\"/>"
2483 "<when condition=\"when-cond\"/>"
2484 "</leaf-list>"
2485 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002486 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002487 parsed = (struct lysp_node_leaflist *)siblings;
2488 assert_string_equal(parsed->dsc, "desc");
2489 assert_string_equal(*parsed->iffeatures, "feature");
2490 assert_int_equal(parsed->min, 5);
2491 assert_int_equal(parsed->max, 15);
2492 assert_string_equal(parsed->musts->arg, "must-cond");
2493 assert_string_equal(parsed->name, "llist");
2494 assert_null(parsed->next);
2495 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2496 assert_null(parsed->parent);
2497 assert_string_equal(parsed->ref, "ref");
2498 assert_string_equal(parsed->type.name, "type");
2499 assert_string_equal(parsed->units, "uni");
2500 assert_string_equal(parsed->when->cond, "when-cond");
2501 assert_true(parsed->flags & LYS_CONFIG_W);
2502 assert_true(parsed->flags & LYS_ORDBY_USER);
2503 assert_true(parsed->flags & LYS_STATUS_CURR);
2504 lysp_node_free(st->ctx, siblings);
2505 siblings = NULL;
2506
2507 data = ELEMENT_WRAPPER_START
2508 "<leaf-list name=\"llist\">"
2509 "<type name=\"type\"/>"
2510 "</leaf-list>"
2511 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002512 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002513 parsed = (struct lysp_node_leaflist *)siblings;
2514 assert_string_equal(parsed->name, "llist");
2515 assert_string_equal(parsed->type.name, "type");
2516 lysp_node_free(st->ctx, siblings);
2517 siblings = NULL;
2518
2519 /* invalid combinations */
2520 data = ELEMENT_WRAPPER_START
2521 "<leaf-list name=\"llist\">"
2522 "<max-elements value=\"5\"/>"
2523 "<min-elements value=\"15\"/>"
2524 "<type name=\"type\"/>"
2525 "</leaf-list>"
2526 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002527 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002528 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2529 lysp_node_free(st->ctx, siblings);
2530 siblings = NULL;
2531
2532 data = ELEMENT_WRAPPER_START
2533 "<leaf-list name=\"llist\">"
2534 "<default value=\"def-val1\"/>"
2535 "<min-elements value=\"15\"/>"
2536 "<type name=\"type\"/>"
2537 "</leaf-list>"
2538 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002539 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002540 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 +02002541 lysp_node_free(st->ctx, siblings);
2542 siblings = NULL;
2543
2544 data = ELEMENT_WRAPPER_START
2545 "<leaf-list name=\"llist\">"
2546 "</leaf-list>"
2547 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002548 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002549 logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002550 lysp_node_free(st->ctx, siblings);
2551 siblings = NULL;
2552
2553 st->finished_correctly = true;
2554}
2555
David Sedlákcb39f642019-07-19 13:19:55 +02002556static void
2557test_presence_elem(void **state)
2558{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002559 struct test_parser_yin_state *st = *state;
David Sedlákcb39f642019-07-19 13:19:55 +02002560 const char *data;
2561 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002562 struct lysp_ext_instance *exts = NULL;
2563
2564 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002565 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002566 assert_string_equal(val, "presence-val");
David Sedláke0ef1c62019-09-13 10:05:55 +02002567 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002568 assert_int_equal(exts[0].insubstmt_index, 0);
2569 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
2570 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2571 FREE_STRING(st->ctx, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002572
2573 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002574 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002575 assert_string_equal(val, "presence-val");
2576 FREE_STRING(st->ctx, val);
2577
2578 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002579 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlákcb39f642019-07-19 13:19:55 +02002580 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2581
2582 st->finished_correctly = true;
2583}
2584
David Sedlák12470a82019-07-19 13:44:36 +02002585static void
2586test_key_elem(void **state)
2587{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002588 struct test_parser_yin_state *st = *state;
David Sedlák12470a82019-07-19 13:44:36 +02002589 const char *data;
2590 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002591 struct lysp_ext_instance *exts = NULL;
2592
2593 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002594 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002595 assert_string_equal(val, "key-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02002596 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002597 assert_int_equal(exts[0].insubstmt_index, 0);
2598 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
2599 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2600 FREE_STRING(st->ctx, val);
David Sedlák12470a82019-07-19 13:44:36 +02002601
2602 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002603 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002604 assert_string_equal(val, "key-value");
2605 FREE_STRING(st->ctx, val);
2606
2607 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002608 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák12470a82019-07-19 13:44:36 +02002609 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2610
2611 st->finished_correctly = true;
2612}
2613
David Sedlák04e17b22019-07-19 15:29:48 +02002614static void
2615test_typedef_elem(void **state)
2616{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002617 struct test_parser_yin_state *st = *state;
David Sedlák04e17b22019-07-19 15:29:48 +02002618 const char *data;
2619 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002620 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002621
2622 data = ELEMENT_WRAPPER_START
2623 "<typedef name=\"tpdf-name\">"
2624 "<default value=\"def-val\"/>"
2625 "<description><text>desc-text</text></description>"
2626 "<reference><text>ref-text</text></reference>"
2627 "<status value=\"current\"/>"
2628 "<type name=\"type\"/>"
2629 "<units name=\"uni\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002630 EXT_SUBELEM
David Sedlák04e17b22019-07-19 15:29:48 +02002631 "</typedef>"
2632 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002633 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002634 assert_string_equal(tpdfs[0].dflt, "def-val");
2635 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002636 assert_string_equal(tpdfs[0].name, "tpdf-name");
2637 assert_string_equal(tpdfs[0].ref, "ref-text");
2638 assert_string_equal(tpdfs[0].type.name, "type");
2639 assert_string_equal(tpdfs[0].units, "uni");
2640 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002641 assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002642 assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
2643 assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák04e17b22019-07-19 15:29:48 +02002644 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2645 tpdfs = NULL;
2646
2647 data = ELEMENT_WRAPPER_START
2648 "<typedef name=\"tpdf-name\">"
2649 "<type name=\"type\"/>"
2650 "</typedef>"
2651 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002652 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002653 assert_string_equal(tpdfs[0].name, "tpdf-name");
2654 assert_string_equal(tpdfs[0].type.name, "type");
2655 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2656 tpdfs = NULL;
2657
2658 st->finished_correctly = true;
2659}
2660
David Sedlákd2d676a2019-07-22 11:28:19 +02002661static void
2662test_refine_elem(void **state)
2663{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002664 struct test_parser_yin_state *st = *state;
David Sedlákd2d676a2019-07-22 11:28:19 +02002665 const char *data;
2666 struct lysp_refine *refines = NULL;
2667
2668 /* max subelems */
2669 data = ELEMENT_WRAPPER_START
2670 "<refine target-node=\"target\">"
2671 "<if-feature name=\"feature\" />"
2672 "<must condition=\"cond\" />"
2673 "<presence value=\"presence\" />"
2674 "<default value=\"def\" />"
2675 "<config value=\"true\" />"
2676 "<mandatory value=\"true\" />"
2677 "<min-elements value=\"10\" />"
2678 "<max-elements value=\"20\" />"
2679 "<description><text>desc</text></description>"
2680 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002681 EXT_SUBELEM
David Sedlákd2d676a2019-07-22 11:28:19 +02002682 "</refine>"
2683 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002684 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002685 assert_string_equal(refines->nodeid, "target");
2686 assert_string_equal(*refines->dflts, "def");
2687 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002688 assert_true(refines->flags & LYS_CONFIG_W);
2689 assert_true(refines->flags & LYS_MAND_TRUE);
2690 assert_string_equal(*refines->iffeatures, "feature");
2691 assert_int_equal(refines->max, 20);
2692 assert_int_equal(refines->min, 10);
2693 assert_string_equal(refines->musts->arg, "cond");
2694 assert_string_equal(refines->presence, "presence");
2695 assert_string_equal(refines->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002696 assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002697 assert_int_equal(refines->exts[0].insubstmt_index, 0);
2698 assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákd2d676a2019-07-22 11:28:19 +02002699 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2700 refines = NULL;
2701
2702 /* min subelems */
2703 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002704 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002705 assert_string_equal(refines->nodeid, "target");
2706 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2707 refines = NULL;
2708
2709 st->finished_correctly = true;
2710}
2711
David Sedlák0d6de5a2019-07-22 13:25:44 +02002712static void
2713test_uses_elem(void **state)
2714{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002715 struct test_parser_yin_state *st = *state;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002716 const char *data;
2717 struct lysp_node *siblings = NULL;
2718 struct tree_node_meta node_meta = {NULL, &siblings};
2719 struct lysp_node_uses *parsed = NULL;
2720
2721 /* max subelems */
2722 data = ELEMENT_WRAPPER_START
2723 "<uses name=\"uses-name\">"
2724 "<when condition=\"cond\" />"
2725 "<if-feature name=\"feature\" />"
2726 "<status value=\"obsolete\" />"
2727 "<description><text>desc</text></description>"
2728 "<reference><text>ref</text></reference>"
2729 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002730 "<augment target-node=\"target\" />"
David Sedlákd1144562019-08-06 12:36:14 +02002731 EXT_SUBELEM
David Sedlák0d6de5a2019-07-22 13:25:44 +02002732 "</uses>"
2733 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002734 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002735 parsed = (struct lysp_node_uses *)&siblings[0];
2736 assert_string_equal(parsed->name, "uses-name");
2737 assert_string_equal(parsed->dsc, "desc");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002738 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2739 assert_string_equal(*parsed->iffeatures, "feature");
2740 assert_null(parsed->next);
2741 assert_int_equal(parsed->nodetype, LYS_USES);
2742 assert_null(parsed->parent);
2743 assert_string_equal(parsed->ref, "ref");
2744 assert_string_equal(parsed->refines->nodeid, "target");
2745 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002746 assert_string_equal(parsed->augments->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02002747 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002748 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2749 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002750 lysp_node_free(st->ctx, siblings);
2751 siblings = NULL;
2752
2753 /* min subelems */
2754 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002755 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002756 assert_string_equal(siblings[0].name, "uses-name");
2757 lysp_node_free(st->ctx, siblings);
2758 siblings = NULL;
2759
2760 st->finished_correctly = true;
2761}
2762
David Sedlákaa854b02019-07-22 14:17:10 +02002763static void
2764test_revision_elem(void **state)
2765{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002766 struct test_parser_yin_state *st = *state;
David Sedlákaa854b02019-07-22 14:17:10 +02002767 const char *data;
2768 struct lysp_revision *revs = NULL;
2769
2770 /* max subelems */
2771 data = ELEMENT_WRAPPER_START
2772 "<revision date=\"2018-12-25\">"
2773 "<description><text>desc</text></description>"
2774 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002775 EXT_SUBELEM
David Sedlákaa854b02019-07-22 14:17:10 +02002776 "</revision>"
2777 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002778 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002779 assert_string_equal(revs->date, "2018-12-25");
2780 assert_string_equal(revs->dsc, "desc");
2781 assert_string_equal(revs->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002782 assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002783 assert_int_equal(revs->exts[0].insubstmt_index, 0);
2784 assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaa854b02019-07-22 14:17:10 +02002785 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2786 revs = NULL;
2787
2788 /* min subelems */
2789 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002790 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002791 assert_string_equal(revs->date, "2005-05-05");
2792 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2793 revs = NULL;
2794
2795 /* invalid value */
2796 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002797 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID);
David Sedlákaa854b02019-07-22 14:17:10 +02002798 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2799 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2800 revs = NULL;
2801
2802 st->finished_correctly = true;
2803}
2804
David Sedlák0c2bab92019-07-22 15:33:19 +02002805static void
2806test_include_elem(void **state)
2807{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002808 struct test_parser_yin_state *st = *state;
David Sedlák0c2bab92019-07-22 15:33:19 +02002809 const char *data;
2810 struct lysp_include *includes = NULL;
2811 struct include_meta inc_meta = {"module-name", &includes};
2812
2813 /* max subelems */
2814 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2815 data = ELEMENT_WRAPPER_START
2816 "<include module=\"mod\">"
2817 "<description><text>desc</text></description>"
2818 "<reference><text>ref</text></reference>"
2819 "<revision-date date=\"1999-09-09\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002820 EXT_SUBELEM
David Sedlák0c2bab92019-07-22 15:33:19 +02002821 "</include>"
2822 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002823 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002824 assert_string_equal(includes->name, "mod");
2825 assert_string_equal(includes->dsc, "desc");
2826 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002827 assert_string_equal(includes->rev, "1999-09-09");
David Sedláke0ef1c62019-09-13 10:05:55 +02002828 assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002829 assert_int_equal(includes->exts[0].insubstmt_index, 0);
2830 assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0c2bab92019-07-22 15:33:19 +02002831 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2832 includes = NULL;
2833
2834 /* min subelems */
2835 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002836 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002837 assert_string_equal(includes->name, "mod");
2838 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2839 includes = NULL;
2840
2841 /* invalid combinations */
2842 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2843 data = ELEMENT_WRAPPER_START
2844 "<include module=\"mod\">"
2845 "<description><text>desc</text></description>"
2846 "<revision-date date=\"1999-09-09\"/>"
2847 "</include>"
2848 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002849 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002850 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.");
2851 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2852 includes = NULL;
2853
2854 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2855 data = ELEMENT_WRAPPER_START
2856 "<include module=\"mod\">"
2857 "<reference><text>ref</text></reference>"
2858 "<revision-date date=\"1999-09-09\"/>"
2859 "</include>"
2860 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002861 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002862 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.");
2863 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2864 includes = NULL;
2865
2866 st->finished_correctly = true;
2867}
2868
David Sedlák5e13dea2019-07-22 16:06:45 +02002869static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002870test_list_elem(void **state)
2871{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002872 struct test_parser_yin_state *st = *state;
David Sedlákaf536aa2019-07-23 13:42:23 +02002873 const char *data;
2874 struct lysp_node *siblings = NULL;
2875 struct tree_node_meta node_meta = {NULL, &siblings};
2876 struct lysp_node_list *parsed = NULL;
2877
2878 /* max subelems */
2879 data = ELEMENT_WRAPPER_START
2880 "<list name=\"list-name\">"
2881 "<when condition=\"when\"/>"
2882 "<if-feature name=\"iff\"/>"
2883 "<must condition=\"must-cond\"/>"
2884 "<key value=\"key\"/>"
2885 "<unique tag=\"utag\"/>"
2886 "<config value=\"true\"/>"
2887 "<min-elements value=\"10\"/>"
2888 "<ordered-by value=\"user\"/>"
2889 "<status value=\"deprecated\"/>"
2890 "<description><text>desc</text></description>"
2891 "<reference><text>ref</text></reference>"
2892 "<anydata name=\"anyd\"/>"
2893 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002894 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002895 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002896 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002897 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002898 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002899 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2900 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002901 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002902 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002903 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002904 EXT_SUBELEM
David Sedlákaf536aa2019-07-23 13:42:23 +02002905 "</list>"
2906 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002907 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002908 parsed = (struct lysp_node_list *)&siblings[0];
2909 assert_string_equal(parsed->dsc, "desc");
2910 assert_string_equal(parsed->child->name, "anyd");
2911 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2912 assert_string_equal(parsed->child->next->name, "anyx");
2913 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002914 assert_string_equal(parsed->child->next->next->name, "cont");
2915 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002916 assert_string_equal(parsed->child->next->next->next->name, "choice");
2917 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002918 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2919 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2920 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2921 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2922 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2923 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2924 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2925 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2926 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002927 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002928 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002929 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002930 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02002931 assert_true(parsed->flags & LYS_ORDBY_USER);
2932 assert_true(parsed->flags & LYS_STATUS_DEPRC);
2933 assert_true(parsed->flags & LYS_CONFIG_W);
2934 assert_string_equal(*parsed->iffeatures, "iff");
2935 assert_string_equal(parsed->key, "key");
2936 assert_int_equal(parsed->min, 10);
2937 assert_string_equal(parsed->musts->arg, "must-cond");
2938 assert_string_equal(parsed->name, "list-name");
2939 assert_null(parsed->next);
2940 assert_int_equal(parsed->nodetype, LYS_LIST);
2941 assert_null(parsed->parent);
2942 assert_string_equal(parsed->ref, "ref");
2943 assert_string_equal(parsed->typedefs->name, "tpdf");
2944 assert_string_equal(*parsed->uniques, "utag");
2945 assert_string_equal(parsed->when->cond, "when");
David Sedláke0ef1c62019-09-13 10:05:55 +02002946 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002947 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2948 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaf536aa2019-07-23 13:42:23 +02002949 lysp_node_free(st->ctx, siblings);
2950 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2951 siblings = NULL;
2952
2953 /* min subelems */
2954 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002955 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002956 parsed = (struct lysp_node_list *)&siblings[0];
2957 assert_string_equal(parsed->name, "list-name");
2958 lysp_node_free(st->ctx, siblings);
2959 siblings = NULL;
2960
2961 st->finished_correctly = true;
2962}
2963
David Sedlák031b9e72019-07-23 15:19:37 +02002964static void
2965test_notification_elem(void **state)
2966{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002967 struct test_parser_yin_state *st = *state;
David Sedlák031b9e72019-07-23 15:19:37 +02002968 const char *data;
2969 struct lysp_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002970 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002971
2972 /* max subelems */
2973 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2974 data = ELEMENT_WRAPPER_START
2975 "<notification name=\"notif-name\">"
2976 "<anydata name=\"anyd\"/>"
2977 "<anyxml name=\"anyx\"/>"
2978 "<description><text>desc</text></description>"
2979 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002980 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2981 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02002982 "<list name=\"sub-list\"/>"
2983 "<must condition=\"cond\"/>"
2984 "<reference><text>ref</text></reference>"
2985 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002986 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02002987 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002988 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002989 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002990 "<grouping name=\"grp\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002991 EXT_SUBELEM
David Sedlák031b9e72019-07-23 15:19:37 +02002992 "</notification>"
2993 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002994 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002995 assert_string_equal(notifs->name, "notif-name");
2996 assert_string_equal(notifs->data->name, "anyd");
2997 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
2998 assert_string_equal(notifs->data->next->name, "anyx");
2999 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
3000 assert_string_equal(notifs->data->next->next->name, "leaf");
3001 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
3002 assert_string_equal(notifs->data->next->next->next->name, "llist");
3003 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
3004 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
3005 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02003006 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003007 assert_string_equal(notifs->groupings->name, "grp");
3008 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02003009 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
3010 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
3011 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
3012 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003013 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3014 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
3015 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02003016 assert_string_equal(*notifs->iffeatures, "iff");
3017 assert_string_equal(notifs->musts->arg, "cond");
3018 assert_int_equal(notifs->nodetype, LYS_NOTIF);
3019 assert_null(notifs->parent);
3020 assert_string_equal(notifs->ref, "ref");
3021 assert_string_equal(notifs->typedefs->name, "tpdf");
David Sedláke0ef1c62019-09-13 10:05:55 +02003022 assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003023 assert_int_equal(notifs->exts[0].insubstmt_index, 0);
3024 assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák031b9e72019-07-23 15:19:37 +02003025 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
3026 notifs = NULL;
3027
3028 /* min subelems */
3029 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003030 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003031 assert_string_equal(notifs->name, "notif-name");
3032 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003033 notifs = NULL;
3034
3035 st->finished_correctly = true;
3036}
3037
3038static void
3039test_grouping_elem(void **state)
3040{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003041 struct test_parser_yin_state *st = *state;
David Sedláke3ce9ef2019-07-23 16:34:30 +02003042 const char *data;
3043 struct lysp_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003044 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02003045
3046 /* max subelems */
3047 data = ELEMENT_WRAPPER_START
3048 "<grouping name=\"grp-name\">"
3049 "<anydata name=\"anyd\"/>"
3050 "<anyxml name=\"anyx\"/>"
3051 "<description><text>desc</text></description>"
3052 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003053 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3054 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003055 "<list name=\"list\"/>"
3056 "<notification name=\"notf\"/>"
3057 "<reference><text>ref</text></reference>"
3058 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003059 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003060 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003061 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003062 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003063 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003064 EXT_SUBELEM
David Sedláke3ce9ef2019-07-23 16:34:30 +02003065 "</grouping>"
3066 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003067 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003068 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003069 assert_string_equal(grps->data->name, "anyd");
3070 assert_string_equal(grps->data->next->name, "anyx");
3071 assert_string_equal(grps->data->next->next->name, "leaf");
3072 assert_string_equal(grps->data->next->next->next->name, "llist");
3073 assert_string_equal(grps->data->next->next->next->next->name, "list");
3074 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003075 assert_true(grps->flags & LYS_STATUS_CURR);
3076 assert_string_equal(grps->groupings->name, "sub-grp");
3077 assert_int_equal(grps->nodetype, LYS_GROUPING);
3078 assert_string_equal(grps->notifs->name, "notf");
3079 assert_null(grps->parent);
3080 assert_string_equal(grps->ref, "ref");
3081 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003082 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02003083 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003084 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02003085 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003086 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
3087 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
3088 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke0ef1c62019-09-13 10:05:55 +02003089 assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003090 assert_int_equal(grps->exts[0].insubstmt_index, 0);
3091 assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003092 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3093 grps = NULL;
3094
3095 /* min subelems */
3096 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003097 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003098 assert_string_equal(grps->name, "grp-name");
3099 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3100 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02003101
3102 st->finished_correctly = true;
3103}
3104
David Sedlákf111bcb2019-07-23 17:15:51 +02003105static void
3106test_container_elem(void **state)
3107{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003108 struct test_parser_yin_state *st = *state;
David Sedlákf111bcb2019-07-23 17:15:51 +02003109 const char *data;
3110 struct lysp_node *siblings = NULL;
3111 struct tree_node_meta node_meta = {NULL, &siblings};
3112 struct lysp_node_container *parsed = NULL;
3113
3114 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02003115 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3116 data = ELEMENT_WRAPPER_START
3117 "<container name=\"cont-name\">"
3118 "<anydata name=\"anyd\"/>"
3119 "<anyxml name=\"anyx\"/>"
3120 "<config value=\"true\"/>"
3121 "<container name=\"subcont\"/>"
3122 "<description><text>desc</text></description>"
3123 "<grouping name=\"sub-grp\"/>"
3124 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003125 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3126 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003127 "<list name=\"list\"/>"
3128 "<must condition=\"cond\"/>"
3129 "<notification name=\"notf\"/>"
3130 "<presence value=\"presence\"/>"
3131 "<reference><text>ref</text></reference>"
3132 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003133 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003134 "<uses name=\"uses-name\"/>"
3135 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003136 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003137 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003138 EXT_SUBELEM
David Sedláke2dc9e92019-07-24 09:59:21 +02003139 "</container>"
3140 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003141 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02003142 parsed = (struct lysp_node_container *)siblings;
3143 assert_string_equal(parsed->name, "cont-name");
3144 assert_null(parsed->parent);
3145 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
3146 assert_true(parsed->flags & LYS_CONFIG_W);
3147 assert_true(parsed->flags & LYS_STATUS_CURR);
3148 assert_null(parsed->next);
3149 assert_string_equal(parsed->dsc, "desc");
3150 assert_string_equal(parsed->ref, "ref");
3151 assert_string_equal(parsed->when->cond, "when-cond");
3152 assert_string_equal(*parsed->iffeatures, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02003153 assert_string_equal(parsed->musts->arg, "cond");
3154 assert_string_equal(parsed->presence, "presence");
3155 assert_string_equal(parsed->typedefs->name, "tpdf");
3156 assert_string_equal(parsed->groupings->name, "sub-grp");
3157 assert_string_equal(parsed->child->name, "anyd");
3158 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3159 assert_string_equal(parsed->child->next->name, "anyx");
3160 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3161 assert_string_equal(parsed->child->next->next->name, "subcont");
3162 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3163 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3164 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3165 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3166 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3167 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3168 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3169 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3170 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003171 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3172 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3173 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02003174 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003175 assert_string_equal(parsed->actions->name, "act");
David Sedláke0ef1c62019-09-13 10:05:55 +02003176 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003177 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3178 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke2dc9e92019-07-24 09:59:21 +02003179 lysp_node_free(st->ctx, siblings);
3180 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3181 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02003182
3183 /* min subelems */
3184 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003185 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02003186 parsed = (struct lysp_node_container *)siblings;
3187 assert_string_equal(parsed->name, "cont-name");
3188 lysp_node_free(st->ctx, siblings);
3189 siblings = NULL;
3190
3191 st->finished_correctly = true;
3192}
3193
David Sedlák5379d392019-07-24 10:42:03 +02003194static void
3195test_case_elem(void **state)
3196{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003197 struct test_parser_yin_state *st = *state;
David Sedlák5379d392019-07-24 10:42:03 +02003198 const char *data;
3199 struct lysp_node *siblings = NULL;
3200 struct tree_node_meta node_meta = {NULL, &siblings};
3201 struct lysp_node_case *parsed = NULL;
3202
3203 /* max subelems */
3204 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3205 data = ELEMENT_WRAPPER_START
3206 "<case name=\"case-name\">"
3207 "<anydata name=\"anyd\"/>"
3208 "<anyxml name=\"anyx\"/>"
3209 "<container name=\"subcont\"/>"
3210 "<description><text>desc</text></description>"
3211 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003212 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3213 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02003214 "<list name=\"list\"/>"
3215 "<reference><text>ref</text></reference>"
3216 "<status value=\"current\"/>"
3217 "<uses name=\"uses-name\"/>"
3218 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003219 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003220 EXT_SUBELEM
David Sedlák5379d392019-07-24 10:42:03 +02003221 "</case>"
3222 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003223 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003224 parsed = (struct lysp_node_case *)siblings;
3225 assert_string_equal(parsed->name, "case-name");
3226 assert_null(parsed->parent);
3227 assert_int_equal(parsed->nodetype, LYS_CASE);
3228 assert_true(parsed->flags & LYS_STATUS_CURR);
3229 assert_null(parsed->next);
3230 assert_string_equal(parsed->dsc, "desc");
3231 assert_string_equal(parsed->ref, "ref");
3232 assert_string_equal(parsed->when->cond, "when-cond");
3233 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02003234 assert_string_equal(parsed->child->name, "anyd");
3235 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3236 assert_string_equal(parsed->child->next->name, "anyx");
3237 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3238 assert_string_equal(parsed->child->next->next->name, "subcont");
3239 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3240 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3241 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3242 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3243 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3244 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3245 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3246 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3247 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003248 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3249 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3250 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003251 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003252 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3253 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5379d392019-07-24 10:42:03 +02003254 lysp_node_free(st->ctx, siblings);
3255 siblings = NULL;
3256
3257 /* min subelems */
3258 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003259 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003260 parsed = (struct lysp_node_case *)siblings;
3261 assert_string_equal(parsed->name, "case-name");
3262 lysp_node_free(st->ctx, siblings);
3263 siblings = NULL;
3264
3265 st->finished_correctly = true;
3266}
3267
David Sedlákb7abcfa2019-07-24 12:33:35 +02003268static void
3269test_choice_elem(void **state)
3270{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003271 struct test_parser_yin_state *st = *state;
David Sedlákb7abcfa2019-07-24 12:33:35 +02003272 const char *data;
3273 struct lysp_node *siblings = NULL;
3274 struct tree_node_meta node_meta = {NULL, &siblings};
3275 struct lysp_node_choice *parsed = NULL;
3276
3277 /* max subelems */
3278 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3279 data = ELEMENT_WRAPPER_START
3280 "<choice name=\"choice-name\">"
3281 "<anydata name=\"anyd\"/>"
3282 "<anyxml name=\"anyx\"/>"
3283 "<case name=\"sub-case\"/>"
3284 "<choice name=\"choice\"/>"
3285 "<config value=\"true\"/>"
3286 "<container name=\"subcont\"/>"
3287 "<default value=\"def\"/>"
3288 "<description><text>desc</text></description>"
3289 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003290 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3291 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003292 "<list name=\"list\"/>"
3293 "<mandatory value=\"true\" />"
3294 "<reference><text>ref</text></reference>"
3295 "<status value=\"current\"/>"
3296 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003297 EXT_SUBELEM
David Sedlákb7abcfa2019-07-24 12:33:35 +02003298 "</choice>"
3299 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003300 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003301 parsed = (struct lysp_node_choice *)siblings;
3302 assert_string_equal(parsed->name, "choice-name");
3303 assert_null(parsed->parent);
3304 assert_int_equal(parsed->nodetype, LYS_CHOICE);
3305 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
3306 assert_null(parsed->next);
3307 assert_string_equal(parsed->dsc, "desc");
3308 assert_string_equal(parsed->ref, "ref");
3309 assert_string_equal(parsed->when->cond, "when-cond");
3310 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003311 assert_string_equal(parsed->child->name, "anyd");
3312 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3313 assert_string_equal(parsed->child->next->name, "anyx");
3314 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3315 assert_string_equal(parsed->child->next->next->name, "sub-case");
3316 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
3317 assert_string_equal(parsed->child->next->next->next->name, "choice");
3318 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
3319 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
3320 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
3321 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
3322 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
3323 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
3324 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3325 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
3326 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3327 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003328 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003329 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3330 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003331 lysp_node_free(st->ctx, siblings);
3332 siblings = NULL;
3333
3334 /* min subelems */
3335 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003336 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003337 parsed = (struct lysp_node_choice *)siblings;
3338 assert_string_equal(parsed->name, "choice-name");
3339 lysp_node_free(st->ctx, siblings);
3340 siblings = NULL;
3341
3342 st->finished_correctly = true;
3343}
3344
David Sedlák05404f62019-07-24 14:11:53 +02003345static void
3346test_inout_elem(void **state)
3347{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003348 struct test_parser_yin_state *st = *state;
David Sedlák05404f62019-07-24 14:11:53 +02003349 const char *data;
3350 struct lysp_action_inout inout = {};
3351 struct inout_meta inout_meta = {NULL, &inout};
3352
3353 /* max subelements */
3354 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3355 data = ELEMENT_WRAPPER_START
3356 "<input>"
3357 "<anydata name=\"anyd\"/>"
3358 "<anyxml name=\"anyx\"/>"
3359 "<choice name=\"choice\"/>"
3360 "<container name=\"subcont\"/>"
3361 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003362 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3363 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003364 "<list name=\"list\"/>"
3365 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003366 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003367 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003368 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003369 "</input>"
3370 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003371 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003372 assert_null(inout.parent);
3373 assert_int_equal(inout.nodetype, LYS_INPUT);
3374 assert_string_equal(inout.musts->arg, "cond");
3375 assert_string_equal(inout.typedefs->name, "tpdf");
3376 assert_string_equal(inout.groupings->name, "sub-grp");
3377 assert_string_equal(inout.data->name, "anyd");
3378 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3379 assert_string_equal(inout.data->next->name, "anyx");
3380 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3381 assert_string_equal(inout.data->next->next->name, "choice");
3382 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3383 assert_string_equal(inout.data->next->next->next->name, "subcont");
3384 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3385 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3386 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3387 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3388 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3389 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3390 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3391 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3392 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3393 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003394 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003395 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3396 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003397 lysp_action_inout_free(st->ctx, &inout);
3398 memset(&inout, 0, sizeof inout);
3399
3400 /* max subelements */
3401 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3402 data = ELEMENT_WRAPPER_START
3403 "<output>"
3404 "<anydata name=\"anyd\"/>"
3405 "<anyxml name=\"anyx\"/>"
3406 "<choice name=\"choice\"/>"
3407 "<container name=\"subcont\"/>"
3408 "<grouping name=\"sub-grp\"/>"
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ák05404f62019-07-24 14:11:53 +02003411 "<list name=\"list\"/>"
3412 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003413 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003414 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003415 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003416 "</output>"
3417 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003418 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003419 assert_null(inout.parent);
3420 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3421 assert_string_equal(inout.musts->arg, "cond");
3422 assert_string_equal(inout.typedefs->name, "tpdf");
3423 assert_string_equal(inout.groupings->name, "sub-grp");
3424 assert_string_equal(inout.data->name, "anyd");
3425 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3426 assert_string_equal(inout.data->next->name, "anyx");
3427 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3428 assert_string_equal(inout.data->next->next->name, "choice");
3429 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3430 assert_string_equal(inout.data->next->next->next->name, "subcont");
3431 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3432 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3433 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3434 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3435 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3436 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3437 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3438 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3439 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3440 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003441 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003442 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3443 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003444 lysp_action_inout_free(st->ctx, &inout);
3445 memset(&inout, 0, sizeof inout);
3446
3447 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003448 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003449 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003450 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003451 memset(&inout, 0, sizeof inout);
3452
Michal Vaskob83af8a2020-01-06 09:49:22 +01003453 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003454 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003455 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003456 memset(&inout, 0, sizeof inout);
3457
3458 /* invalid combinations */
3459 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003460 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02003461 logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003462 memset(&inout, 0, sizeof inout);
3463
3464 st->finished_correctly = true;
3465}
3466
David Sedlák85d0eca2019-07-24 15:15:21 +02003467static void
3468test_action_elem(void **state)
3469{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003470 struct test_parser_yin_state *st = *state;
David Sedlák85d0eca2019-07-24 15:15:21 +02003471 const char *data;
3472 struct lysp_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003473 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
David Sedlák85d0eca2019-07-24 15:15:21 +02003474
3475 /* max subelems */
3476 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3477 data = ELEMENT_WRAPPER_START
3478 "<action name=\"act\">"
3479 "<description><text>desc</text></description>"
3480 "<grouping name=\"grouping\"/>"
3481 "<if-feature name=\"iff\"/>"
3482 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003483 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003484 "<reference><text>ref</text></reference>"
3485 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003486 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003487 EXT_SUBELEM
David Sedlák85d0eca2019-07-24 15:15:21 +02003488 "</action>"
3489 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003490 /* there must be parent for action */
3491 act_meta.parent = NULL + 1;
Michal Vaskob36053d2020-03-26 15:49:30 +01003492 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003493 act_meta.parent = NULL;
3494 assert_non_null(actions->parent);
David Sedlák85d0eca2019-07-24 15:15:21 +02003495 assert_int_equal(actions->nodetype, LYS_ACTION);
3496 assert_true(actions->flags & LYS_STATUS_DEPRC);
3497 assert_string_equal(actions->name, "act");
3498 assert_string_equal(actions->dsc, "desc");
3499 assert_string_equal(actions->ref, "ref");
3500 assert_string_equal(*actions->iffeatures, "iff");
3501 assert_string_equal(actions->typedefs->name, "tpdf");
3502 assert_string_equal(actions->groupings->name, "grouping");
3503 assert_string_equal(actions->input.data->name, "uses-name");
3504 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003505 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003506 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3507 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák85d0eca2019-07-24 15:15:21 +02003508 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3509 actions = NULL;
3510
David Sedlákeaa45792019-07-24 15:25:01 +02003511 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3512 data = ELEMENT_WRAPPER_START
3513 "<rpc name=\"act\">"
3514 "<description><text>desc</text></description>"
3515 "<grouping name=\"grouping\"/>"
3516 "<if-feature name=\"iff\"/>"
3517 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003518 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlákeaa45792019-07-24 15:25:01 +02003519 "<reference><text>ref</text></reference>"
3520 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003521 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003522 EXT_SUBELEM
David Sedlákeaa45792019-07-24 15:25:01 +02003523 "</rpc>"
3524 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003525 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlákeaa45792019-07-24 15:25:01 +02003526 assert_null(actions->parent);
Michal Vasko1bf09392020-03-27 12:38:10 +01003527 assert_int_equal(actions->nodetype, LYS_RPC);
David Sedlákeaa45792019-07-24 15:25:01 +02003528 assert_true(actions->flags & LYS_STATUS_DEPRC);
3529 assert_string_equal(actions->name, "act");
3530 assert_string_equal(actions->dsc, "desc");
3531 assert_string_equal(actions->ref, "ref");
3532 assert_string_equal(*actions->iffeatures, "iff");
3533 assert_string_equal(actions->typedefs->name, "tpdf");
3534 assert_string_equal(actions->groupings->name, "grouping");
3535 assert_string_equal(actions->input.data->name, "uses-name");
3536 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003537 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003538 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3539 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákeaa45792019-07-24 15:25:01 +02003540 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3541 actions = NULL;
3542
David Sedlák85d0eca2019-07-24 15:15:21 +02003543 /* min subelems */
3544 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003545 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003546 assert_string_equal(actions->name, "act");
3547 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3548 actions = NULL;
3549
3550 st->finished_correctly = true;
3551}
3552
David Sedlák992fb7c2019-07-24 16:51:01 +02003553static void
3554test_augment_elem(void **state)
3555{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003556 struct test_parser_yin_state *st = *state;
David Sedlák992fb7c2019-07-24 16:51:01 +02003557 const char *data;
3558 struct lysp_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003559 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003560
3561 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3562 data = ELEMENT_WRAPPER_START
3563 "<augment target-node=\"target\">"
3564 "<action name=\"action\"/>"
3565 "<anydata name=\"anyd\"/>"
3566 "<anyxml name=\"anyx\"/>"
3567 "<case name=\"case\"/>"
3568 "<choice name=\"choice\"/>"
3569 "<container name=\"subcont\"/>"
3570 "<description><text>desc</text></description>"
3571 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003572 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3573 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003574 "<list name=\"list\"/>"
3575 "<notification name=\"notif\"/>"
3576 "<reference><text>ref</text></reference>"
3577 "<status value=\"current\"/>"
3578 "<uses name=\"uses\"/>"
3579 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003580 EXT_SUBELEM
David Sedlák992fb7c2019-07-24 16:51:01 +02003581 "</augment>"
3582 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003583 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003584 assert_string_equal(augments->nodeid, "target");
3585 assert_null(augments->parent);
3586 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3587 assert_true(augments->flags & LYS_STATUS_CURR);
3588 assert_string_equal(augments->dsc, "desc");
3589 assert_string_equal(augments->ref, "ref");
3590 assert_string_equal(augments->when->cond, "when-cond");
3591 assert_string_equal(*augments->iffeatures, "iff");
3592 assert_string_equal(augments->child->name, "anyd");
3593 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3594 assert_string_equal(augments->child->next->name, "anyx");
3595 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3596 assert_string_equal(augments->child->next->next->name, "case");
3597 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3598 assert_string_equal(augments->child->next->next->next->name, "choice");
3599 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3600 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3601 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3602 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3603 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3604 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3605 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3606 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3607 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3608 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3609 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3610 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3611 assert_string_equal(augments->actions->name, "action");
3612 assert_string_equal(augments->notifs->name, "notif");
David Sedláke0ef1c62019-09-13 10:05:55 +02003613 assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003614 assert_int_equal(augments->exts[0].insubstmt_index, 0);
3615 assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák992fb7c2019-07-24 16:51:01 +02003616 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3617 augments = NULL;
3618
3619 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003620 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003621 assert_string_equal(augments->nodeid, "target");
3622 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3623 augments = NULL;
3624
3625 st->finished_correctly = true;
3626}
3627
David Sedlák4ffcec82019-07-25 15:10:21 +02003628static void
3629test_deviate_elem(void **state)
3630{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003631 struct test_parser_yin_state *st = *state;
David Sedlák4ffcec82019-07-25 15:10:21 +02003632 const char *data;
3633 struct lysp_deviate *deviates = NULL;
3634 struct lysp_deviate_add *d_add;
3635 struct lysp_deviate_rpl *d_rpl;
3636 struct lysp_deviate_del *d_del;
3637
3638 /* all valid arguments with min subelems */
3639 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003640 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003641 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3642 lysp_deviate_free(st->ctx, deviates);
3643 free(deviates);
3644 deviates = NULL;
3645
3646 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003647 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003648 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3649 lysp_deviate_free(st->ctx, deviates);
3650 free(deviates);
3651 deviates = NULL;
3652
3653 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003654 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003655 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3656 lysp_deviate_free(st->ctx, deviates);
3657 free(deviates);
3658 deviates = NULL;
3659
3660 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003661 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003662 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3663 lysp_deviate_free(st->ctx, deviates);
3664 free(deviates);
3665 deviates = NULL;
3666
3667 /* max subelems and valid arguments */
3668 data = ELEMENT_WRAPPER_START
3669 "<deviate value=\"not-supported\">"
David Sedlákd1144562019-08-06 12:36:14 +02003670 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003671 "</deviate>"
3672 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003673 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003674 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
David Sedláke0ef1c62019-09-13 10:05:55 +02003675 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003676 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3677 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003678 lysp_deviate_free(st->ctx, deviates);
3679 free(deviates);
3680 deviates = NULL;
3681
3682 data = ELEMENT_WRAPPER_START
3683 "<deviate value=\"add\">"
3684 "<units name=\"units\"/>"
3685 "<must condition=\"cond\"/>"
3686 "<unique tag=\"utag\"/>"
3687 "<default value=\"def\"/>"
3688 "<config value=\"true\"/>"
3689 "<mandatory value=\"true\"/>"
3690 "<min-elements value=\"5\"/>"
3691 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003692 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003693 "</deviate>"
3694 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003695 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003696 d_add = (struct lysp_deviate_add *)deviates;
3697 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3698 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003699 assert_string_equal(d_add->units, "units");
3700 assert_string_equal(d_add->musts->arg, "cond");
3701 assert_string_equal(*d_add->uniques, "utag");
3702 assert_string_equal(*d_add->dflts, "def");
3703 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3704 assert_int_equal(d_add->min, 5);
3705 assert_int_equal(d_add->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003706 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003707 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3708 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003709 lysp_deviate_free(st->ctx, deviates);
3710 free(deviates);
3711 deviates = NULL;
3712
3713 data = ELEMENT_WRAPPER_START
3714 "<deviate value=\"replace\">"
3715 "<type name=\"newtype\"/>"
3716 "<units name=\"uni\"/>"
3717 "<default value=\"def\"/>"
3718 "<config value=\"true\"/>"
3719 "<mandatory value=\"true\"/>"
3720 "<min-elements value=\"5\"/>"
3721 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003722 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003723 "</deviate>"
3724 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003725 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003726 d_rpl = (struct lysp_deviate_rpl *)deviates;
3727 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3728 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003729 assert_string_equal(d_rpl->type->name, "newtype");
3730 assert_string_equal(d_rpl->units, "uni");
3731 assert_string_equal(d_rpl->dflt, "def");
3732 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3733 assert_int_equal(d_rpl->min, 5);
3734 assert_int_equal(d_rpl->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003735 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003736 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3737 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003738 lysp_deviate_free(st->ctx, deviates);
3739 free(deviates);
3740 deviates = NULL;
3741
3742 data = ELEMENT_WRAPPER_START
3743 "<deviate value=\"delete\">"
3744 "<units name=\"u\"/>"
3745 "<must condition=\"c\"/>"
3746 "<unique tag=\"tag\"/>"
3747 "<default value=\"default\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003748 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003749 "</deviate>"
3750 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003751 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003752 d_del = (struct lysp_deviate_del *)deviates;
3753 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3754 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003755 assert_string_equal(d_del->units, "u");
3756 assert_string_equal(d_del->musts->arg, "c");
3757 assert_string_equal(*d_del->uniques, "tag");
3758 assert_string_equal(*d_del->dflts, "default");
David Sedláke0ef1c62019-09-13 10:05:55 +02003759 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003760 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3761 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003762 lysp_deviate_free(st->ctx, deviates);
3763 free(deviates);
3764 deviates = NULL;
3765
3766 /* invalid arguments */
3767 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003768 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003769 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 +02003770 deviates = NULL;
3771
3772 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003773 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003774 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 +02003775 deviates = NULL;
3776
3777 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003778 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003779 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 +02003780 deviates = NULL;
3781
3782 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003783 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003784 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 +02003785 deviates = NULL;
3786
3787 data = ELEMENT_WRAPPER_START
3788 "<deviate value=\"not-supported\">"
3789 "<must condition=\"c\"/>"
3790 "</deviate>"
3791 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003792 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák4ffcec82019-07-25 15:10:21 +02003793 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3794
3795 st->finished_correctly = true;
3796}
3797
David Sedlák8b754462019-07-25 16:22:13 +02003798static void
3799test_deviation_elem(void **state)
3800{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003801 struct test_parser_yin_state *st = *state;
David Sedlák8b754462019-07-25 16:22:13 +02003802 const char *data;
3803 struct lysp_deviation *deviations = NULL;
3804
3805 /* min subelems */
3806 data = ELEMENT_WRAPPER_START
3807 "<deviation target-node=\"target\">"
3808 "<deviate value=\"not-supported\"/>"
3809 "</deviation>"
3810 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003811 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003812 assert_string_equal(deviations->nodeid, "target");
3813 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3814 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3815 deviations = NULL;
3816
3817 /* max subelems */
3818 data = ELEMENT_WRAPPER_START
3819 "<deviation target-node=\"target\">"
3820 "<reference><text>ref</text></reference>"
3821 "<description><text>desc</text></description>"
3822 "<deviate value=\"add\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003823 EXT_SUBELEM
David Sedlák8b754462019-07-25 16:22:13 +02003824 "</deviation>"
3825 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003826 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003827 assert_string_equal(deviations->nodeid, "target");
3828 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3829 assert_string_equal(deviations->ref, "ref");
3830 assert_string_equal(deviations->dsc, "desc");
David Sedláke0ef1c62019-09-13 10:05:55 +02003831 assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003832 assert_int_equal(deviations->exts[0].insubstmt_index, 0);
3833 assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8b754462019-07-25 16:22:13 +02003834 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3835 deviations = NULL;
3836
3837 /* invalid */
3838 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003839 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID);
David Sedlák8b754462019-07-25 16:22:13 +02003840 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3841 deviations = NULL;
David Sedlák1538a842019-08-08 15:38:51 +02003842 logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
3843 /* TODO */
David Sedlák8b754462019-07-25 16:22:13 +02003844 st->finished_correctly = true;
3845}
3846
David Sedlák4f03b932019-07-26 13:01:47 +02003847static void
3848test_module_elem(void **state)
3849{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003850 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01003851 const char *data;
David Sedlák4f03b932019-07-26 13:01:47 +02003852 struct lys_module *lys_mod = NULL;
3853 struct lysp_module *lysp_mod = NULL;
3854
3855 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003856 lys_mod = calloc(1, sizeof *lys_mod);
3857 lysp_mod = calloc(1, sizeof *lysp_mod);
3858 lys_mod->ctx = st->ctx;
3859 lysp_mod->mod = lys_mod;
3860 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3861 "<yang-version value=\"1.1\"/>\n"
3862 "<namespace uri=\"ns\"/>\n"
3863 "<prefix value=\"pref\"/>\n"
3864 "<include module=\"b-mod\"/>\n"
3865 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3866 "<organization><text>org</text></organization>\n"
3867 "<contact><text>contact</text></contact>\n"
3868 "<description><text>desc</text></description>"
3869 "<reference><text>ref</text></reference>\n"
3870 "<revision date=\"2019-02-02\"/>\n"
3871 "<anydata name=\"anyd\"/>\n"
3872 "<anyxml name=\"anyx\"/>\n"
3873 "<choice name=\"choice\"/>\n"
3874 "<container name=\"cont\"/>\n"
3875 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3876 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3877 "<list name=\"sub-list\"/>\n"
3878 "<uses name=\"uses-name\"/>\n"
3879 "<augment target-node=\"target\"/>\n"
3880 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3881 "<extension name=\"ext\"/>\n"
3882 "<feature name=\"feature\"/>\n"
3883 "<grouping name=\"grp\"/>\n"
3884 "<identity name=\"ident-name\"/>\n"
3885 "<notification name=\"notf\"/>\n"
3886 "<rpc name=\"rpc-name\"/>\n"
3887 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02003888 EXT_SUBELEM"\n"
David Sedlák4f03b932019-07-26 13:01:47 +02003889 "</module>\n";
Michal Vaskob36053d2020-03-26 15:49:30 +01003890 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3891
3892 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003893 assert_string_equal(lysp_mod->mod->name, "mod");
3894 assert_string_equal(lysp_mod->revs, "2019-02-02");
3895 assert_string_equal(lysp_mod->mod->ns, "ns");
3896 assert_string_equal(lysp_mod->mod->prefix, "pref");
3897 assert_null(lysp_mod->mod->filepath);
3898 assert_string_equal(lysp_mod->mod->org, "org");
3899 assert_string_equal(lysp_mod->mod->contact, "contact");
3900 assert_string_equal(lysp_mod->mod->dsc, "desc");
3901 assert_string_equal(lysp_mod->mod->ref, "ref");
3902 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
3903 assert_string_equal(lysp_mod->imports->name, "a-mod");
3904 assert_string_equal(lysp_mod->includes->name, "b-mod");
3905 assert_string_equal(lysp_mod->extensions->name, "ext");
3906 assert_string_equal(lysp_mod->features->name, "feature");
3907 assert_string_equal(lysp_mod->identities->name, "ident-name");
3908 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3909 assert_string_equal(lysp_mod->groupings->name, "grp");
3910 assert_string_equal(lysp_mod->data->name, "anyd");
3911 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3912 assert_string_equal(lysp_mod->data->next->name, "anyx");
3913 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3914 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3915 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3916 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3917 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3918 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3919 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3920 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3921 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3922 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3923 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3924 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3925 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3926 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3927 assert_string_equal(lysp_mod->augments->nodeid, "target");
3928 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3929 assert_string_equal(lysp_mod->notifs->name, "notf");
3930 assert_string_equal(lysp_mod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02003931 assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003932 assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
3933 assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4f03b932019-07-26 13:01:47 +02003934 lysp_module_free(lysp_mod);
3935 lys_module_free(lys_mod, NULL);
David Sedlák4f03b932019-07-26 13:01:47 +02003936
3937 /* min subelems */
Michal Vaskob36053d2020-03-26 15:49:30 +01003938 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák4f03b932019-07-26 13:01:47 +02003939 lys_mod = calloc(1, sizeof *lys_mod);
3940 lysp_mod = calloc(1, sizeof *lysp_mod);
3941 lys_mod->ctx = st->ctx;
3942 lysp_mod->mod = lys_mod;
3943 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
3944 "<namespace uri=\"ns\"/>"
3945 "<prefix value=\"pref\"/>"
3946 "<yang-version value=\"1.1\"/>"
3947 "</module>";
Michal Vaskob36053d2020-03-26 15:49:30 +01003948 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3949 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003950 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák4f03b932019-07-26 13:01:47 +02003951 lysp_module_free(lysp_mod);
3952 lys_module_free(lys_mod, NULL);
David Sedlák298ff6d2019-07-26 14:29:03 +02003953
David Sedláke6cd89e2019-08-07 12:46:02 +02003954 /* incorrect subelem order */
Michal Vaskob36053d2020-03-26 15:49:30 +01003955 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02003956 lys_mod = calloc(1, sizeof *lys_mod);
3957 lysp_mod = calloc(1, sizeof *lysp_mod);
3958 lys_mod->ctx = st->ctx;
3959 lysp_mod->mod = lys_mod;
3960 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
3961 "<feature name=\"feature\"/>\n"
3962 "<namespace uri=\"ns\"/>"
3963 "<prefix value=\"pref\"/>"
3964 "<yang-version value=\"1.1\"/>"
3965 "</module>";
Michal Vaskob36053d2020-03-26 15:49:30 +01003966 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3967 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
3968 logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 2.");
David Sedláke6cd89e2019-08-07 12:46:02 +02003969 lysp_module_free(lysp_mod);
3970 lys_module_free(lys_mod, NULL);
David Sedláke6cd89e2019-08-07 12:46:02 +02003971
David Sedlák298ff6d2019-07-26 14:29:03 +02003972 st->finished_correctly = true;
3973}
3974
3975static void
3976test_submodule_elem(void **state)
3977{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003978 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01003979 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02003980 struct lysp_submodule *lysp_submod = NULL;
3981
3982 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02003983 lysp_submod = calloc(1, sizeof *lysp_submod);
3984 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3985 "<yang-version value=\"1.1\"/>\n"
3986 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
3987 "<include module=\"b-mod\"/>\n"
3988 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3989 "<organization><text>org</text></organization>\n"
3990 "<contact><text>contact</text></contact>\n"
3991 "<description><text>desc</text></description>"
3992 "<reference><text>ref</text></reference>\n"
3993 "<revision date=\"2019-02-02\"/>\n"
3994 "<anydata name=\"anyd\"/>\n"
3995 "<anyxml name=\"anyx\"/>\n"
3996 "<choice name=\"choice\"/>\n"
3997 "<container name=\"cont\"/>\n"
3998 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3999 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
4000 "<list name=\"sub-list\"/>\n"
4001 "<uses name=\"uses-name\"/>\n"
4002 "<augment target-node=\"target\"/>\n"
4003 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
4004 "<extension name=\"ext\"/>\n"
4005 "<feature name=\"feature\"/>\n"
4006 "<grouping name=\"grp\"/>\n"
4007 "<identity name=\"ident-name\"/>\n"
4008 "<notification name=\"notf\"/>\n"
4009 "<rpc name=\"rpc-name\"/>\n"
4010 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004011 EXT_SUBELEM"\n"
David Sedlák298ff6d2019-07-26 14:29:03 +02004012 "</submodule>\n";
Michal Vaskob36053d2020-03-26 15:49:30 +01004013 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4014 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004015
4016 assert_string_equal(lysp_submod->name, "mod");
4017 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02004018 assert_string_equal(lysp_submod->prefix, "pref");
4019 assert_null(lysp_submod->filepath);
4020 assert_string_equal(lysp_submod->org, "org");
4021 assert_string_equal(lysp_submod->contact, "contact");
4022 assert_string_equal(lysp_submod->dsc, "desc");
4023 assert_string_equal(lysp_submod->ref, "ref");
4024 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
4025 assert_string_equal(lysp_submod->imports->name, "a-mod");
4026 assert_string_equal(lysp_submod->includes->name, "b-mod");
4027 assert_string_equal(lysp_submod->extensions->name, "ext");
4028 assert_string_equal(lysp_submod->features->name, "feature");
4029 assert_string_equal(lysp_submod->identities->name, "ident-name");
4030 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
4031 assert_string_equal(lysp_submod->groupings->name, "grp");
4032 assert_string_equal(lysp_submod->data->name, "anyd");
4033 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
4034 assert_string_equal(lysp_submod->data->next->name, "anyx");
4035 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
4036 assert_string_equal(lysp_submod->data->next->next->name, "choice");
4037 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
4038 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
4039 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
4040 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
4041 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
4042 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
4043 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4044 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
4045 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4046 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
4047 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4048 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
4049 assert_string_equal(lysp_submod->augments->nodeid, "target");
4050 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
4051 assert_string_equal(lysp_submod->notifs->name, "notf");
4052 assert_string_equal(lysp_submod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004053 assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004054 assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
4055 assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák298ff6d2019-07-26 14:29:03 +02004056
4057 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004058
4059 /* min subelemnts */
Michal Vaskob36053d2020-03-26 15:49:30 +01004060 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák298ff6d2019-07-26 14:29:03 +02004061 lysp_submod = calloc(1, sizeof *lysp_submod);
4062 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4063 "<yang-version value=\"1.0\"/>"
4064 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4065 "</submodule>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004066 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4067 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004068 assert_string_equal(lysp_submod->prefix, "pref");
4069 assert_string_equal(lysp_submod->belongsto, "mod-name");
4070 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
4071 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004072
David Sedláke6cd89e2019-08-07 12:46:02 +02004073 /* incorrect subelem order */
Michal Vaskob36053d2020-03-26 15:49:30 +01004074 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02004075 lysp_submod = calloc(1, sizeof *lysp_submod);
4076 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4077 "<yang-version value=\"1.0\"/>"
4078 "<reference><text>ref</text></reference>\n"
4079 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4080 "</submodule>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004081 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4082 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
4083 logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 2.");
David Sedláke6cd89e2019-08-07 12:46:02 +02004084 lysp_submodule_free(st->ctx, lysp_submod);
David Sedláke6cd89e2019-08-07 12:46:02 +02004085
David Sedlák298ff6d2019-07-26 14:29:03 +02004086 st->finished_correctly = true;
David Sedlák4f03b932019-07-26 13:01:47 +02004087}
4088
David Sedlák8985a142019-07-31 16:43:06 +02004089static void
4090test_yin_parse_module(void **state)
4091{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004092 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +02004093 const char *data;
4094 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01004095 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004096
4097 mod = calloc(1, sizeof *mod);
4098 mod->ctx = st->ctx;
David Sedlákd2844882019-09-13 16:01:22 +02004099 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n"
4100 "<yang-version value=\"1.1\"/>\n"
4101 "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
4102 "<prefix value=\"a\"/>\n"
4103 "<import module=\"ietf-yang-metadata\">\n"
4104 "<prefix value=\"md\"/>\n"
4105 "</import>\n"
4106 "<feature name=\"f\"/>\n"
4107 "<md:annotation name=\"x\">\n"
4108 "<description>\n"
4109 "<text>test</text>\n"
4110 "</description>\n"
4111 "<reference>\n"
4112 "<text>test</text>\n"
4113 "</reference>\n"
4114 "<if-feature name=\"f\"/>\n"
4115 "<status value=\"current\"/>\n"
4116 "<type name=\"uint8\"/>\n"
4117 "<units name=\"meters\"/>\n"
4118 "</md:annotation>\n"
4119 "</module>\n";
4120 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4121 assert_null(mod->parsed->exts->child->next->child);
4122 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
4123 lys_module_free(mod, NULL);
4124 yin_parser_ctx_free(yin_ctx);
4125 mod = NULL;
4126 yin_ctx = NULL;
4127
4128 mod = calloc(1, sizeof *mod);
4129 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004130 data = "<module name=\"example-foo\""
4131 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4132 "xmlns:foo=\"urn:example:foo\""
4133 "xmlns:myext=\"urn:example:extensions\">\n"
4134
4135 "<yang-version value=\"1.0\"/>\n"
4136
4137 "<namespace uri=\"urn:example:foo\"/>\n"
4138 "<prefix value=\"foo\"/>\n"
4139
4140 "<import module=\"example-extensions\">\n"
David Sedlák6d781b62019-08-02 15:22:52 +02004141 "<prefix value=\"myext\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02004142 "</import>\n"
4143
4144 "<list name=\"interface\">\n"
4145 "<key value=\"name\"/>\n"
4146 "<leaf name=\"name\">\n"
4147 "<type name=\"string\"/>\n"
4148 "</leaf>\n"
4149 "<leaf name=\"mtu\">\n"
4150 "<type name=\"uint32\"/>\n"
4151 "<description>\n"
4152 "<text>The MTU of the interface.</text>\n"
4153 "</description>\n"
4154 "<myext:c-define name=\"MY_MTU\"/>\n"
4155 "</leaf>\n"
4156 "</list>\n"
4157 "</module>\n";
4158 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4159 lys_module_free(mod, NULL);
4160 yin_parser_ctx_free(yin_ctx);
4161 mod = NULL;
4162 yin_ctx = NULL;
4163
4164 mod = calloc(1, sizeof *mod);
4165 mod->ctx = st->ctx;
David Sedlák6d781b62019-08-02 15:22:52 +02004166 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4167 "<yang-version value=\"1.0\"/>\n"
4168 "<namespace uri=\"urn:example:foo\"/>\n"
4169 "<prefix value=\"foo\"/>\n"
4170 "</module>\n";
4171 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4172 lys_module_free(mod, NULL);
4173 yin_parser_ctx_free(yin_ctx);
4174 mod = NULL;
4175 yin_ctx = NULL;
4176
4177
4178 mod = calloc(1, sizeof *mod);
4179 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004180 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4181 "</submodule>\n";
4182 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL);
4183 logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
4184 lys_module_free(mod, NULL);
4185 yin_parser_ctx_free(yin_ctx);
4186
David Sedlák6d781b62019-08-02 15:22:52 +02004187 mod = calloc(1, sizeof *mod);
4188 mod->ctx = st->ctx;
4189 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4190 "<yang-version value=\"1.0\"/>\n"
4191 "<namespace uri=\"urn:example:foo\"/>\n"
4192 "<prefix value=\"foo\"/>\n"
4193 "</module>"
4194 "<module>";
4195 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID);
4196 logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
4197 lys_module_free(mod, NULL);
4198 yin_parser_ctx_free(yin_ctx);
4199 mod = NULL;
4200 yin_ctx = NULL;
4201
David Sedlák8985a142019-07-31 16:43:06 +02004202 st->finished_correctly = true;
4203}
4204
4205static void
4206test_yin_parse_submodule(void **state)
4207{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004208 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +02004209 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01004210 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004211 struct lysp_submodule *submod = NULL;
David Sedlák1b623122019-08-05 15:27:49 +02004212 struct lys_parser_ctx main_ctx = {};
David Sedlák8985a142019-07-31 16:43:06 +02004213
4214 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4215 "<submodule name=\"asub\""
4216 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4217 "xmlns:a=\"urn:a\">"
4218 "<yang-version value=\"1.0\"/>\n"
4219 "<belongs-to module=\"a\">"
4220 "<prefix value=\"a_pref\"/>"
4221 "</belongs-to>"
4222 "<include module=\"atop\"/>"
4223 "<feature name=\"fox\"/>"
4224 "<notification name=\"bar-notif\">"
4225 "<if-feature name=\"bar\"/>"
4226 "</notification>"
4227 "<notification name=\"fox-notif\">"
4228 "<if-feature name=\"fox\"/>"
4229 "</notification>"
4230 "<augment target-node=\"/a_pref:top\">"
4231 "<if-feature name=\"bar\"/>"
4232 "<container name=\"bar-sub\"/>"
4233 "</augment>"
4234 "<augment target-node=\"/top\">"
4235 "<container name=\"bar-sub2\"/>"
4236 "</augment>"
4237 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004238 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004239 lysp_submodule_free(st->ctx, submod);
4240 yin_parser_ctx_free(yin_ctx);
4241 yin_ctx = NULL;
4242 submod = NULL;
4243
4244 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák6d781b62019-08-02 15:22:52 +02004245 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4246 "<yang-version value=\"1.0\"/>\n"
4247 "<belongs-to module=\"a\">"
4248 "<prefix value=\"a_pref\"/>"
4249 "</belongs-to>"
4250 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004251 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004252 lysp_submodule_free(st->ctx, submod);
4253 yin_parser_ctx_free(yin_ctx);
4254 yin_ctx = NULL;
4255 submod = NULL;
4256
4257 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák8985a142019-07-31 16:43:06 +02004258 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4259 "</module>";
David Sedlák1b623122019-08-05 15:27:49 +02004260 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004261 logbuf_assert("Input data contains module in situation when a submodule is expected.");
4262 lysp_submodule_free(st->ctx, submod);
4263 yin_parser_ctx_free(yin_ctx);
4264 yin_ctx = NULL;
4265 submod = NULL;
4266
David Sedlák6d781b62019-08-02 15:22:52 +02004267 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4268 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4269 "<yang-version value=\"1.0\"/>\n"
4270 "<belongs-to module=\"a\">"
4271 "<prefix value=\"a_pref\"/>"
4272 "</belongs-to>"
4273 "</submodule>"
4274 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4275 "<yang-version value=\"1.0\"/>\n"
4276 "<belongs-to module=\"a\">"
4277 "<prefix value=\"a_pref\"/>"
4278 "</belongs-to>"
4279 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004280 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004281 logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
4282 lysp_submodule_free(st->ctx, submod);
4283 yin_parser_ctx_free(yin_ctx);
4284 yin_ctx = NULL;
4285 submod = NULL;
4286
David Sedlák8985a142019-07-31 16:43:06 +02004287 st->finished_correctly = true;
4288}
4289
David Sedlák3b4db242018-10-19 16:11:01 +02004290int
4291main(void)
4292{
4293
4294 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02004295 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02004296 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
4297 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák071f7662019-09-12 02:02:51 +02004298 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02004299 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02004300
David Sedlák8e7bda82019-07-16 17:57:50 +02004301 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák43801c92019-08-05 15:58:54 +02004302 cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test),
4303 cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test),
David Sedlák32488102019-07-15 17:44:10 +02004304 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
4305 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
4306 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
4307 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
4308 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
4309 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
4310 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004311 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
4312 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
4313 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
4314 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
4315 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
4316 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
4317 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
4318 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
4319 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
4320 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
4321 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
4322 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004323 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
4324 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02004325 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
4326 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
4327 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
4328 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
4329 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
4330 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
4331 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
4332 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02004333 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02004334 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02004335 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02004336 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02004337 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02004338 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02004339 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02004340 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02004341 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02004342 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02004343 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02004344 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02004345 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02004346 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02004347 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02004348 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02004349 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02004350 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02004351 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02004352 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02004353 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02004354 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02004355 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02004356 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02004357 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02004358 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák298ff6d2019-07-26 14:29:03 +02004359 cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test),
David Sedlák8985a142019-07-31 16:43:06 +02004360
4361 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger),
4362 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger),
David Sedlák3b4db242018-10-19 16:11:01 +02004363 };
4364
David Sedlák8e7bda82019-07-16 17:57:50 +02004365 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02004366}