blob: ea223330c4062705326fd3df350b4b52b22f10c3 [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 Krejci3a4889a2020-05-19 17:01:58 +020024#include "../../../src/common.h"
25#include "../../../src/tree_schema.h"
26#include "../../../src/tree_schema_internal.h"
27#include "../../../src/parser_yin.h"
28#include "../../../src/xml.h"
David Sedlák3b4db242018-10-19 16:11:01 +020029
David Sedlák555c7202019-07-04 12:14:12 +020030/* prototypes of static functions */
31void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +020032void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +020033void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +020034void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +020035void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +020036void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +020037void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +020038void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +020039void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +020040void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +020041void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
David Sedlák031b9e72019-07-23 15:19:37 +020042void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
David Sedláke3ce9ef2019-07-23 16:34:30 +020043void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
David Sedlák05404f62019-07-24 14:11:53 +020044void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
David Sedlák85d0eca2019-07-24 15:15:21 +020045void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
David Sedlák992fb7c2019-07-24 16:51:01 +020046void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +020047void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +020048void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +020049void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod);
50void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +020051
David Sedláke6cd89e2019-08-07 12:46:02 +020052/* wrapping element used for mocking has nothing to do with real module structure */
53#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
54#define ELEMENT_WRAPPER_END "</status>"
55
Radek Krejci3a4889a2020-05-19 17:01:58 +020056struct test_parser_yin_state {
David Sedlák3b4db242018-10-19 16:11:01 +020057 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010058 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020059 struct lysp_module *lysp_mod;
Michal Vaskob36053d2020-03-26 15:49:30 +010060 struct lys_yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020061 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010062};
David Sedlák872c7b42018-10-26 13:15:20 +020063
David Sedlák79e50cb2019-06-05 16:33:09 +020064#define BUFSIZE 1024
65char logbuf[BUFSIZE] = {0};
66int store = -1; /* negative for infinite logging, positive for limited logging */
67
68/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedláke0ef1c62019-09-13 10:05:55 +020069#define ENABLE_LOGGER_CHECKING 1
David Sedlák79e50cb2019-06-05 16:33:09 +020070
71#if ENABLE_LOGGER_CHECKING
72static void
73logger(LY_LOG_LEVEL level, const char *msg, const char *path)
74{
75 (void) level; /* unused */
76 if (store) {
77 if (path && path[0]) {
78 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
79 } else {
80 strncpy(logbuf, msg, BUFSIZE - 1);
81 }
82 if (store > 0) {
83 --store;
84 }
85 }
86}
87#endif
88
89#if ENABLE_LOGGER_CHECKING
90# define logbuf_assert(str) assert_string_equal(logbuf, str)
91#else
92# define logbuf_assert(str)
93#endif
94
95#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
96 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
97 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
98 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
99 CLEANUP
100
David Sedlák8e7bda82019-07-16 17:57:50 +0200101int
102setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100103{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200104 struct test_parser_yin_state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +0200105
David Sedlák68a1af12019-03-08 13:46:54 +0100106 /* allocate state variable */
107 (*state) = st = calloc(1, sizeof(*st));
108 if (!st) {
109 fprintf(stderr, "Memmory allocation failed");
110 return EXIT_FAILURE;
111 }
David Sedlák872c7b42018-10-26 13:15:20 +0200112
David Sedlák68a1af12019-03-08 13:46:54 +0100113 /* create new libyang context */
114 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200115
David Sedlák8e7bda82019-07-16 17:57:50 +0200116 return EXIT_SUCCESS;
117}
118
119int
120destroy_ly_ctx(void **state)
121{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200122 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +0200123 ly_ctx_destroy(st->ctx, NULL);
124 free(st);
125
126 return EXIT_SUCCESS;
127}
128
129static int
130setup_f(void **state)
131{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200132 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +0200133
134#if ENABLE_LOGGER_CHECKING
135 /* setup logger */
136 ly_set_log_clb(logger, 1);
137#endif
138
David Sedlák68a1af12019-03-08 13:46:54 +0100139 /* allocate new module */
140 st->mod = calloc(1, sizeof(*st->mod));
141 st->mod->ctx = st->ctx;
142
David Sedlák619db942019-07-03 14:47:30 +0200143 /* allocate new parsed module */
144 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
145 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
146 st->lysp_mod->mod->ctx = st->ctx;
147
148 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200149 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100150 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8f5bce02019-06-03 16:41:08 +0200151
David Sedlák68a1af12019-03-08 13:46:54 +0100152 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200153}
154
155static int
David Sedlák68a1af12019-03-08 13:46:54 +0100156teardown_f(void **state)
157{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200158 struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200159 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100160
David Sedlák79e50cb2019-06-05 16:33:09 +0200161#if ENABLE_LOGGER_CHECKING
162 /* teardown logger */
163 if (!st->finished_correctly && logbuf[0] != '\0') {
164 fprintf(stderr, "%s\n", logbuf);
165 }
166#endif
167
David Sedlák619db942019-07-03 14:47:30 +0200168 temp = st->lysp_mod->mod;
169
Michal Vaskob36053d2020-03-26 15:49:30 +0100170 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100171 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200172 lysp_module_free(st->lysp_mod);
173 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200174 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100175
176 return EXIT_SUCCESS;
177}
178
Radek Krejci3a4889a2020-05-19 17:01:58 +0200179static struct test_parser_yin_state*
David Sedlák392af4f2019-06-04 16:02:42 +0200180reset_state(void **state)
181{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200182 ((struct test_parser_yin_state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200183 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200184 teardown_f(state);
185 setup_f(state);
186
187 return *state;
188}
189
David Sedlák79e50cb2019-06-05 16:33:09 +0200190void
191logbuf_clean(void)
192{
193 logbuf[0] = '\0';
194}
195
David Sedlák8985a142019-07-31 16:43:06 +0200196static int
197setup_logger(void **state)
198{
199 (void)state; /* unused */
200#if ENABLE_LOGGER_CHECKING
201 /* setup logger */
202 ly_set_log_clb(logger, 1);
203#endif
204
205 logbuf[0] = '\0';
206
207 return EXIT_SUCCESS;
208}
209
210static int
211teardown_logger(void **state)
212{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200213 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +0200214
215#if ENABLE_LOGGER_CHECKING
216 /* teardown logger */
217 if (!st->finished_correctly && logbuf[0] != '\0') {
218 fprintf(stderr, "%s\n", logbuf);
219 }
220#endif
221
222 return EXIT_SUCCESS;
223}
224
225static int
226setup_element_test(void **state)
227{
228 setup_logger(state);
Radek Krejci3a4889a2020-05-19 17:01:58 +0200229 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +0200230
231 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100232 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8985a142019-07-31 16:43:06 +0200233
234 return EXIT_SUCCESS;
235}
236
237static int
238teardown_element_test(void **state)
239{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200240 struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
David Sedlák8985a142019-07-31 16:43:06 +0200241
Michal Vaskob36053d2020-03-26 15:49:30 +0100242 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák8985a142019-07-31 16:43:06 +0200243 free(st->yin_ctx);
244
245 teardown_logger(state);
246
247 return EXIT_SUCCESS;
248}
249
David Sedlák68a1af12019-03-08 13:46:54 +0100250static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200251test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200252{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200253 struct test_parser_yin_state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200254
Michal Vaskob36053d2020-03-26 15:49:30 +0100255 const char *prefix;
256 size_t prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200257 /* create mock yin namespace in xml context */
258 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
Michal Vaskob36053d2020-03-26 15:49:30 +0100259 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
260 prefix = st->yin_ctx->xmlctx->prefix;
261 prefix_len = st->yin_ctx->xmlctx->prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200262
Radek Krejcid6b76452019-09-03 17:03:03 +0200263 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
264 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
265 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
266 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
267 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
268 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
269 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
270 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
291 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
318 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
319 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
320 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
321 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
322 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
323 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
324 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
325 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
326 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
327 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
328 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
329 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
330 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
331 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
332 assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
David Sedlák8f7a1172019-06-20 14:42:18 +0200333
334 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200335}
David Sedlák3b4db242018-10-19 16:11:01 +0200336
David Sedlák872c7b42018-10-26 13:15:20 +0200337static void
David Sedlák060b00e2019-06-19 11:12:06 +0200338test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200339{
David Sedlák68a1af12019-03-08 13:46:54 +0100340 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200341
David Sedlák060b00e2019-06-19 11:12:06 +0200342 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
343 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
344 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
345 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
346 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
347 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
348 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
349 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
350 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
351 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
352 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
353 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200354}
355
David Sedlák68a1af12019-03-08 13:46:54 +0100356static void
David Sedlákb1a78352019-06-28 16:16:29 +0200357test_yin_parse_element_generic(void **state)
358{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200359 struct test_parser_yin_state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200360 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200361 LY_ERR ret;
362
363 memset(&exts, 0, sizeof(exts));
364
David Sedlákb0ca07d2019-09-11 11:54:05 +0200365 const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100366 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
367
368 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200369 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100370 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200371 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlákb1a78352019-06-28 16:16:29 +0200372 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200373 assert_string_equal(exts.child->child->stmt, "attr");
374 assert_string_equal(exts.child->child->arg, "value");
375 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200376 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200377 st = reset_state(state);
378
David Sedlákb0ca07d2019-09-11 11:54:05 +0200379 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100380 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
381
382 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200383 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100384 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200385 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlák5392a212019-07-01 09:19:10 +0200386 assert_null(exts.child->child);
387 assert_null(exts.child->arg);
388 lysp_ext_instance_free(st->ctx, &exts);
389
David Sedlákb1a78352019-06-28 16:16:29 +0200390 st->finished_correctly = true;
391}
392
393static void
394test_yin_parse_extension_instance(void **state)
395{
396 LY_ERR ret;
Radek Krejci3a4889a2020-05-19 17:01:58 +0200397 struct test_parser_yin_state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200398 struct lysp_ext_instance *exts = NULL;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200399 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100400 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
401
402 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200403 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200404 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákb1a78352019-06-28 16:16:29 +0200405 assert_int_equal(exts->insubstmt_index, 0);
406 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
407 assert_true(exts->yin & LYS_YIN);
408 assert_string_equal(exts->child->stmt, "value1");
409 assert_string_equal(exts->child->arg, "test");
410 assert_null(exts->child->child);
411 assert_true(exts->child->flags & LYS_YIN_ATTR);
412 assert_string_equal(exts->child->next->stmt, "value");
413 assert_string_equal(exts->child->next->arg, "test2");
414 assert_null(exts->child->next->child);
415 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
416
David Sedláke0ef1c62019-09-13 10:05:55 +0200417 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
David Sedlákb1a78352019-06-28 16:16:29 +0200418 assert_string_equal(exts->child->next->next->arg, "text");
419 assert_null(exts->child->next->next->child);
420 assert_null(exts->child->next->next->next);
421 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200422 lysp_ext_instance_free(st->ctx, exts);
423 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200424 exts = NULL;
David Sedlákf250ecf2019-07-01 11:02:05 +0200425 st = reset_state(state);
426
David Sedlákb0ca07d2019-09-11 11:54:05 +0200427 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Michal Vaskob36053d2020-03-26 15:49:30 +0100428 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
429
430 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200431 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200432 assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
David Sedlákf250ecf2019-07-01 11:02:05 +0200433 assert_null(exts->argument);
434 assert_null(exts->child);
435 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
436 assert_int_equal(exts->insubstmt_index, 0);
437 assert_true(exts->yin & LYS_YIN);
David Sedlákf250ecf2019-07-01 11:02:05 +0200438 lysp_ext_instance_free(st->ctx, exts);
439 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200440 exts = NULL;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200441 st = reset_state(state);
442
David Sedlákb0ca07d2019-09-11 11:54:05 +0200443 data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">"
444 "<myext:ext-sub1/>"
445 "<myext:ext-sub2 sattr1=\"stext2\">"
446 "<myext:ext-sub21>"
447 "<myext:ext-sub211 sattr21=\"text21\"/>"
448 "</myext:ext-sub21>"
449 "</myext:ext-sub2>"
450 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
451 "</myext:ext>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100452 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
453
454 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200455 assert_int_equal(ret, LY_SUCCESS);
456
David Sedláke0ef1c62019-09-13 10:05:55 +0200457 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200458 assert_null(exts->argument);
459 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
460 assert_int_equal(exts->insubstmt_index, 0);
461 assert_true(exts->yin & LYS_YIN);
462 assert_string_equal(exts->child->stmt, "attr1");
463 assert_string_equal(exts->child->arg, "text1");
464 assert_null(exts->child->child);
465 assert_true(exts->child->flags & LYS_YIN_ATTR);
466
467 assert_string_equal(exts->child->next->stmt, "attr2");
468 assert_string_equal(exts->child->next->arg, "text2");
469 assert_null(exts->child->next->child);
470 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
471
David Sedláke0ef1c62019-09-13 10:05:55 +0200472 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200473 assert_null(exts->child->next->next->arg);
474 assert_null(exts->child->next->next->child);
475 assert_int_equal(exts->child->next->next->flags, 0);
476
David Sedláke0ef1c62019-09-13 10:05:55 +0200477 assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200478 assert_null(exts->child->next->next->next->arg);
479 assert_int_equal(exts->child->next->next->next->flags, 0);
480 assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
481 assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
482 assert_null(exts->child->next->next->next->child->child);
483 assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
484
David Sedláke0ef1c62019-09-13 10:05:55 +0200485 assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200486 assert_null(exts->child->next->next->next->child->next->arg);
487 assert_null(exts->child->next->next->next->child->next->next);
488 assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
489
David Sedláke0ef1c62019-09-13 10:05:55 +0200490 assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200491 assert_null(exts->child->next->next->next->child->next->child->arg);
492 assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
493 assert_null(exts->child->next->next->next->child->next->child->next);
494
495 assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
496 assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
497 assert_null(exts->child->next->next->next->child->next->child->child->next);
498 assert_null(exts->child->next->next->next->child->next->child->child->child);
499 assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
500
David Sedláke0ef1c62019-09-13 10:05:55 +0200501 assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200502 assert_null(exts->child->next->next->next->next->arg);
503 assert_null(exts->child->next->next->next->next->next);
504 assert_int_equal(exts->child->next->next->next->next->flags, 0);
505
506 assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
507 assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
508 assert_null(exts->child->next->next->next->next->child->next);
509 assert_null(exts->child->next->next->next->next->child->child);
510 assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
511
David Sedlákadd0c2e2019-08-16 10:49:12 +0200512 lysp_ext_instance_free(st->ctx, exts);
513 LY_ARRAY_FREE(exts);
514 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200515 st = reset_state(state);
516
517 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">"
518 "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>"
519 "<yin:augment target-node=\"target\"/>"
520 "<yin:status value=\"value\"/>"
521 "<yin:include module=\"mod\"/>"
522 "<yin:input />"
523 "<yin:must condition=\"cond\"/>"
524 "<yin:namespace uri=\"uri\"/>"
525 "<yin:revision date=\"data\"/>"
526 "<yin:unique tag=\"tag\"/>"
David Sedlákd2844882019-09-13 16:01:22 +0200527 "<yin:description><yin:text>contact-val</yin:text></yin:description>"
528 "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200529 "</myext:extension-elem>";
Michal Vaskob36053d2020-03-26 15:49:30 +0100530 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
531
532 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200533 assert_int_equal(ret, LY_SUCCESS);
534 assert_string_equal(exts->child->arg, "act-name");
535 assert_string_equal(exts->child->next->arg, "target");
536 assert_string_equal(exts->child->next->next->arg, "value");
537 assert_string_equal(exts->child->next->next->next->arg, "mod");
538 assert_null(exts->child->next->next->next->next->arg);
539 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
540 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
541 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
542 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
543 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
David Sedlákaa98bba2019-09-12 11:52:14 +0200544 lysp_ext_instance_free(st->ctx, exts);
545 LY_ARRAY_FREE(exts);
546 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200547 st = reset_state(state);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200548
David Sedlákb1a78352019-06-28 16:16:29 +0200549 st->finished_correctly = true;
550}
551
David Sedlák555c7202019-07-04 12:14:12 +0200552static void
553test_yin_parse_content(void **state)
554{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200555 struct test_parser_yin_state *st = *state;
David Sedlák555c7202019-07-04 12:14:12 +0200556 LY_ERR ret = LY_SUCCESS;
David Sedlák555c7202019-07-04 12:14:12 +0200557 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200558 "<myext:custom xmlns:myext=\"urn:example:extensions\">"
David Sedlák555c7202019-07-04 12:14:12 +0200559 "totally amazing extension"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200560 "</myext:custom>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200561 "<extension name=\"ext\">"
David Sedlák986cb412019-07-04 13:10:11 +0200562 "<argument name=\"argname\"></argument>"
563 "<description><text>desc</text></description>"
564 "<reference><text>ref</text></reference>"
565 "<status value=\"deprecated\"></status>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200566 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200567 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200568 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200569 "<when condition=\"condition...\">"
570 "<reference><text>when_ref</text></reference>"
571 "<description><text>when_desc</text></description>"
572 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200573 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200574 "<error-message>"
575 "<value>error-msg</value>"
576 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200577 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200578 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200579 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200580 "<position value=\"25\"></position>"
581 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200582 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200583 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200584 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200585 "<pattern value='pattern'>"
586 "<modifier value='invert-match'/>"
587 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200588 "<enum name=\"yay\">"
589 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200590 "</prefix>";
591 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200592 const char **if_features = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200593 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200594 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200595 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200596 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200597 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200598 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200599
Michal Vaskob36053d2020-03-26 15:49:30 +0100600 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
601 lyxml_ctx_next(st->yin_ctx->xmlctx);
602 lyxml_ctx_next(st->yin_ctx->xmlctx);
603 lyxml_ctx_next(st->yin_ctx->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200604
David Sedlákfd5b9c32019-07-12 15:33:13 +0200605 struct yin_subelement subelems[17] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200606 {LY_STMT_CONFIG, &config, 0},
607 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
608 {LY_STMT_ENUM, &enum_type, 0},
609 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
610 {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
611 {LY_STMT_EXTENSION, &ext_def, 0},
612 {LY_STMT_IF_FEATURE, &if_features, 0},
613 {LY_STMT_LENGTH, &len_type, 0},
614 {LY_STMT_PATTERN, &patter_type, 0},
615 {LY_STMT_POSITION, &pos_enum, 0},
616 {LY_STMT_RANGE, &range_type, 0},
617 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
618 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
619 {LY_STMT_VALUE, &val_enum, 0},
620 {LY_STMT_WHEN, &when_p, 0},
621 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
622 {LY_STMT_ARG_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200623 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100624 ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200625 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200626 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200627 assert_string_equal(def, "default-value");
David Sedláke0ef1c62019-09-13 10:05:55 +0200628 assert_string_equal(exts->name, "urn:example:extensions:custom");
David Sedlák555c7202019-07-04 12:14:12 +0200629 assert_string_equal(exts->argument, "totally amazing extension");
630 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200631 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200632 assert_string_equal(when_p->cond, "condition...");
633 assert_string_equal(when_p->dsc, "when_desc");
634 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200635 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200636 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200637 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200638 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200639 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200640 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200641 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200642 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200643 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200644 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200645 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200646 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200647 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200648 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200649 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200650 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200651 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200652 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200653 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200654 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200655 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200656 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200657 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200658 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200659 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200660 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200661 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200662 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200663 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200664 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200665 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200666 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200667 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200668 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200669 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200670 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200671 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200672 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200673 st = reset_state(state);
674
675 /* test unique subelem */
676 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200677 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
678 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
David Sedláke6cd89e2019-08-07 12:46:02 +0200679 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200680 "<prefix value=\"inv_mod\" />"
681 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
682 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200683 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100684 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
685 lyxml_ctx_next(st->yin_ctx->xmlctx);
686
687 ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200688 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200689 logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200690 lydict_remove(st->ctx, prefix_value);
691 lydict_remove(st->ctx, value);
692 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200693
694 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200695 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200696 "<prefix value=\"inv_mod\" />"
697 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
698 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200699 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200700 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
701 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
Michal Vaskob36053d2020-03-26 15:49:30 +0100702 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
703 lyxml_ctx_next(st->yin_ctx->xmlctx);
704
705 ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200706 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200707 logbuf_assert("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200708 lydict_remove(st->ctx, prefix_value);
709 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200710
711 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200712 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200713 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Michal Vaskob36053d2020-03-26 15:49:30 +0100714 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
715 lyxml_ctx_next(st->yin_ctx->xmlctx);
716
717 ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200718 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200719 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200720
721 st->finished_correctly = true;
722}
723
David Sedlák92147b02019-07-09 14:01:01 +0200724static void
David Sedlák4a650532019-07-10 11:55:18 +0200725test_validate_value(void **state)
726{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200727 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +0100728 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
729
730 /* create some XML context */
731 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
732 st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
733 st->yin_ctx->xmlctx->dynamic = 0;
734
735 st->yin_ctx->xmlctx->value = "#invalid";
736 st->yin_ctx->xmlctx->value_len = 8;
737 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200738 logbuf_assert("Invalid identifier character '#'. Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100739
740 st->yin_ctx->xmlctx->value = "";
741 st->yin_ctx->xmlctx->value_len = 0;
742 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS);
743
744 st->yin_ctx->xmlctx->value = "pre:b";
745 st->yin_ctx->xmlctx->value_len = 5;
746 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
747 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
748
749 st->yin_ctx->xmlctx->value = "pre:pre:b";
750 st->yin_ctx->xmlctx->value_len = 9;
751 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200752
753 st->finished_correctly = true;
754}
755
David Sedlák32488102019-07-15 17:44:10 +0200756/* helper function to simplify unit test of each element using parse_content function */
757LY_ERR
Radek Krejci3a4889a2020-05-19 17:01:58 +0200758test_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 +0200759{
David Sedlákc5b20842019-08-13 10:18:31 +0200760 const char *name, *prefix;
761 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200762 LY_ERR ret = LY_SUCCESS;
763 struct yin_subelement subelems[71] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200764 {LY_STMT_ACTION, dest, 0},
765 {LY_STMT_ANYDATA, dest, 0},
766 {LY_STMT_ANYXML, dest, 0},
767 {LY_STMT_ARGUMENT,dest, 0},
768 {LY_STMT_AUGMENT, dest, 0},
769 {LY_STMT_BASE, dest, 0},
770 {LY_STMT_BELONGS_TO, dest, 0},
771 {LY_STMT_BIT, dest, 0},
772 {LY_STMT_CASE, dest, 0},
773 {LY_STMT_CHOICE, dest, 0},
774 {LY_STMT_CONFIG, dest, 0},
775 {LY_STMT_CONTACT, dest, 0},
776 {LY_STMT_CONTAINER, dest, 0},
777 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
778 {LY_STMT_DESCRIPTION, dest, 0},
779 {LY_STMT_DEVIATE, dest, 0},
780 {LY_STMT_DEVIATION, dest, 0},
781 {LY_STMT_ENUM, dest, 0},
782 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
783 {LY_STMT_ERROR_MESSAGE, dest, 0},
784 {LY_STMT_EXTENSION, dest, 0},
785 {LY_STMT_FEATURE, dest, 0},
786 {LY_STMT_FRACTION_DIGITS, dest, 0},
787 {LY_STMT_GROUPING, dest, 0},
788 {LY_STMT_IDENTITY, dest, 0},
789 {LY_STMT_IF_FEATURE, dest, 0},
790 {LY_STMT_IMPORT, dest, 0},
791 {LY_STMT_INCLUDE, dest, 0},
792 {LY_STMT_INPUT, dest, 0},
793 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
794 {LY_STMT_LEAF, dest, 0},
795 {LY_STMT_LEAF_LIST, dest, 0},
796 {LY_STMT_LENGTH, dest, 0},
797 {LY_STMT_LIST, dest, 0},
798 {LY_STMT_MANDATORY, dest, 0},
799 {LY_STMT_MAX_ELEMENTS, dest, 0},
800 {LY_STMT_MIN_ELEMENTS, dest, 0},
801 {LY_STMT_MODIFIER, dest, 0},
802 {LY_STMT_MODULE, dest, 0},
803 {LY_STMT_MUST, dest, 0},
804 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
805 {LY_STMT_NOTIFICATION, dest, 0},
806 {LY_STMT_ORDERED_BY, dest, 0},
807 {LY_STMT_ORGANIZATION, dest, 0},
808 {LY_STMT_OUTPUT, dest, 0},
809 {LY_STMT_PATH, dest, 0},
810 {LY_STMT_PATTERN, dest, 0},
811 {LY_STMT_POSITION, dest, 0},
812 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
813 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
814 {LY_STMT_RANGE, dest, 0},
815 {LY_STMT_REFERENCE, dest, 0},
816 {LY_STMT_REFINE, dest, 0},
817 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
818 {LY_STMT_REVISION, dest, 0},
819 {LY_STMT_REVISION_DATE, dest, 0},
820 {LY_STMT_RPC, dest, 0},
821 {LY_STMT_STATUS, dest, 0},
822 {LY_STMT_SUBMODULE, dest, 0},
823 {LY_STMT_TYPE, dest, 0},
824 {LY_STMT_TYPEDEF, dest, 0},
825 {LY_STMT_UNIQUE, dest, 0},
826 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
827 {LY_STMT_USES, dest, 0},
828 {LY_STMT_VALUE, dest, 0},
829 {LY_STMT_WHEN, dest, 0},
830 {LY_STMT_YANG_VERSION, dest, 0},
831 {LY_STMT_YIN_ELEMENT, dest, 0},
832 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
833 {LY_STMT_ARG_TEXT, dest, 0},
834 {LY_STMT_ARG_VALUE, dest, 0}
David Sedlák32488102019-07-15 17:44:10 +0200835 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100836 lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
837 prefix = st->yin_ctx->xmlctx->prefix;
838 prefix_len = st->yin_ctx->xmlctx->prefix_len;
839 name = st->yin_ctx->xmlctx->name;
840 name_len = st->yin_ctx->xmlctx->name_len;
841 lyxml_ctx_next(st->yin_ctx->xmlctx);
842
843 ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
844
845 /* free parser */
846 lyxml_ctx_free(st->yin_ctx->xmlctx);
847 st->yin_ctx->xmlctx = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200848 return ret;
849}
850
David Sedlákd1144562019-08-06 12:36:14 +0200851#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
852
David Sedlák32488102019-07-15 17:44:10 +0200853static void
David Sedlák43801c92019-08-05 15:58:54 +0200854test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200855{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200856 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200857 struct lysp_type type = {};
858 const char *data;
859 data = ELEMENT_WRAPPER_START
860 "<enum name=\"enum-name\">"
861 "<if-feature name=\"feature\" />"
862 "<value value=\"55\" />"
863 "<status value=\"deprecated\" />"
864 "<description><text>desc...</text></description>"
865 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200866 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +0200867 "</enum>"
868 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100869 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200870 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200871 assert_string_equal(*type.enums->iffeatures, "feature");
872 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200873 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200874 assert_string_equal(type.enums->dsc, "desc...");
875 assert_string_equal(type.enums->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200876 assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200877 assert_int_equal(type.enums->exts->insubstmt_index, 0);
878 assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
879 lysp_type_free(st->ctx, &type);
880 memset(&type, 0, sizeof type);
881
882 data = ELEMENT_WRAPPER_START
883 "<enum name=\"enum-name\"></enum>"
884 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100885 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200886 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200887 lysp_type_free(st->ctx, &type);
888 memset(&type, 0, sizeof type);
889
David Sedlák43801c92019-08-05 15:58:54 +0200890 st->finished_correctly = true;
891}
892
893static void
894test_bit_elem(void **state)
895{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200896 struct test_parser_yin_state *st = *state;
David Sedlák43801c92019-08-05 15:58:54 +0200897 struct lysp_type type = {};
898 const char *data;
899 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200900 "<bit name=\"bit-name\">"
David Sedlák43801c92019-08-05 15:58:54 +0200901 "<if-feature name=\"feature\" />"
902 "<position value=\"55\" />"
903 "<status value=\"deprecated\" />"
904 "<description><text>desc...</text></description>"
905 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200906 EXT_SUBELEM
David Sedlák43801c92019-08-05 15:58:54 +0200907 "</bit>"
908 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100909 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200910 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200911 assert_string_equal(*type.bits->iffeatures, "feature");
912 assert_int_equal(type.bits->value, 55);
913 assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
914 assert_string_equal(type.bits->dsc, "desc...");
915 assert_string_equal(type.bits->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200916 assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200917 assert_int_equal(type.bits->exts->insubstmt_index, 0);
918 assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
919 lysp_type_free(st->ctx, &type);
920 memset(&type, 0, sizeof type);
921
922 data = ELEMENT_WRAPPER_START
923 "<bit name=\"bit-name\"> </bit>"
924 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100925 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200926 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200927 lysp_type_free(st->ctx, &type);
928 memset(&type, 0, sizeof type);
929
David Sedlák32488102019-07-15 17:44:10 +0200930 st->finished_correctly = true;
931}
932
933static void
934test_meta_elem(void **state)
935{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200936 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200937 char *value = NULL;
938 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200939 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200940
941 /* organization element */
942 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200943 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
David Sedlák32488102019-07-15 17:44:10 +0200944 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100945 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200946 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200947 assert_int_equal(exts[0].insubstmt_index, 0);
948 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedláke0ef1c62019-09-13 10:05:55 +0200949 assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200950 assert_int_equal(exts[1].insubstmt_index, 0);
951 assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedlák32488102019-07-15 17:44:10 +0200952 assert_string_equal(value, "organization...");
953 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200954 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200955 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200956 exts = NULL;
957
David Sedlák32488102019-07-15 17:44:10 +0200958 /* contact element */
959 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200960 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
David Sedlák32488102019-07-15 17:44:10 +0200961 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100962 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200963 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200964 assert_int_equal(exts[0].insubstmt_index, 0);
965 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200966 assert_string_equal(value, "contact...");
967 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200968 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
969 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200970 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200971
David Sedlák32488102019-07-15 17:44:10 +0200972 /* description element */
973 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200974 "<description><text>description...</text>" EXT_SUBELEM "</description>"
David Sedlák32488102019-07-15 17:44:10 +0200975 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100976 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200977 assert_string_equal(value, "description...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200978 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200979 assert_int_equal(exts[0].insubstmt_index, 0);
980 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200981 FREE_STRING(st->ctx, value);
982 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200983 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
984 exts = NULL;
985
David Sedlák32488102019-07-15 17:44:10 +0200986 /* reference element */
987 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200988 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
David Sedlák32488102019-07-15 17:44:10 +0200989 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100990 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200991 assert_string_equal(value, "reference...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200992 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200993 assert_int_equal(exts[0].insubstmt_index, 0);
994 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
David Sedlák32488102019-07-15 17:44:10 +0200995 FREE_STRING(st->ctx, value);
996 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200997 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
998 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200999
David Sedlákdf2a9732019-08-07 13:23:16 +02001000 /* reference element */
1001 data = ELEMENT_WRAPPER_START
1002 "<reference invalid=\"text\"><text>reference...</text>""</reference>"
1003 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001004 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001005 logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001006 FREE_STRING(st->ctx, value);
1007 value = NULL;
1008 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1009 exts = NULL;
1010
David Sedlák32488102019-07-15 17:44:10 +02001011 /* missing text subelement */
1012 data = ELEMENT_WRAPPER_START
1013 "<reference>reference...</reference>"
1014 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001015 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001016 logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001017
David Sedlákd1144562019-08-06 12:36:14 +02001018 /* reference element */
1019 data = ELEMENT_WRAPPER_START
1020 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
1021 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001022 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001023 logbuf_assert("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element. Line number 1.");
David Sedlákd1144562019-08-06 12:36:14 +02001024 FREE_STRING(st->ctx, value);
1025 value = NULL;
1026 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1027 exts = NULL;
1028
David Sedlák32488102019-07-15 17:44:10 +02001029 st->finished_correctly = true;
1030}
1031
1032static void
1033test_import_elem(void **state)
1034{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001035 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001036 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02001037 struct lysp_import *imports = NULL;
1038 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +02001039
1040 /* max subelems */
1041 data = ELEMENT_WRAPPER_START
1042 "<import module=\"a\">"
David Sedlákd1144562019-08-06 12:36:14 +02001043 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001044 "<prefix value=\"a_mod\"/>"
1045 "<revision-date date=\"2015-01-01\"></revision-date>"
1046 "<description><text>import description</text></description>"
1047 "<reference><text>import reference</text></reference>"
1048 "</import>"
1049 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001050 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001051 assert_string_equal(imports->name, "a");
1052 assert_string_equal(imports->prefix, "a_mod");
1053 assert_string_equal(imports->rev, "2015-01-01");
1054 assert_string_equal(imports->dsc, "import description");
1055 assert_string_equal(imports->ref, "import reference");
David Sedláke0ef1c62019-09-13 10:05:55 +02001056 assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001057 assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
1058 assert_int_equal(imports->exts->insubstmt_index, 0);
David Sedlák298ff6d2019-07-26 14:29:03 +02001059 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1060 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001061
1062 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +02001063 data = ELEMENT_WRAPPER_START
1064 "<import module=\"a\">"
1065 "<prefix value=\"a_mod\"/>"
1066 "</import>"
1067 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001068 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001069 assert_string_equal(imports->prefix, "a_mod");
1070 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1071 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001072
1073 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +02001074 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001075 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001076 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
David Sedlák298ff6d2019-07-26 14:29:03 +02001077 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1078 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001079
1080 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +02001081 data = ELEMENT_WRAPPER_START
1082 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001083 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001084 "</import>"
1085 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001086 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001087 "</import>"
1088 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001089 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák298ff6d2019-07-26 14:29:03 +02001090 logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1.");
1091 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1092 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001093
1094 st->finished_correctly = true;
1095}
1096
1097static void
1098test_status_elem(void **state)
1099{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001100 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001101 const char *data;
1102 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001103 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001104
1105 /* test valid values */
1106 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001107 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001108 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001109
1110 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001111 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001112 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001113
David Sedlákd1144562019-08-06 12:36:14 +02001114 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001115 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001116 assert_true(flags & LYS_STATUS_OBSLT);
David Sedláke0ef1c62019-09-13 10:05:55 +02001117 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001118 assert_int_equal(exts[0].insubstmt_index, 0);
1119 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
1120 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1121 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001122
1123 /* test invalid value */
1124 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001125 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001126 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Valid values are \"current\", \"deprecated\" and \"obsolete\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001127 st->finished_correctly = true;
1128}
1129
1130static void
1131test_ext_elem(void **state)
1132{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001133 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001134 const char *data;
1135 struct lysp_ext *ext = NULL;
1136
1137 /* max subelems */
1138 data = ELEMENT_WRAPPER_START
1139 "<extension name=\"ext_name\">"
1140 "<argument name=\"arg\"></argument>"
1141 "<status value=\"current\"/>"
1142 "<description><text>ext_desc</text></description>"
1143 "<reference><text>ext_ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001144 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001145 "</extension>"
1146 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001147 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001148 assert_string_equal(ext->name, "ext_name");
1149 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001150 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001151 assert_string_equal(ext->dsc, "ext_desc");
1152 assert_string_equal(ext->ref, "ext_ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001153 assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001154 assert_int_equal(ext->exts[0].insubstmt_index, 0);
1155 assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák32488102019-07-15 17:44:10 +02001156 lysp_ext_free(st->ctx, ext);
1157 LY_ARRAY_FREE(ext);
1158 ext = NULL;
1159
1160 /* min subelems */
1161 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001162 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001163 assert_string_equal(ext->name, "ext_name");
1164 lysp_ext_free(st->ctx, ext);
1165 LY_ARRAY_FREE(ext);
1166 ext = NULL;
1167
1168 st->finished_correctly = true;
1169}
1170
1171static void
1172test_yin_element_elem(void **state)
1173{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001174 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001175 const char *data;
1176 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001177 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001178
1179 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001180 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001181 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001182
David Sedlákd1144562019-08-06 12:36:14 +02001183 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001184 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001185 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001186 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001187 assert_int_equal(exts[0].insubstmt_index, 0);
1188 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
1189 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001190
1191 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001192 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001193 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák26ea1432019-08-14 13:42:23 +02001194 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001195 st->finished_correctly = true;
1196}
1197
1198static void
1199test_yangversion_elem(void **state)
1200{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001201 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001202 const char *data;
1203 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001204 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001205
1206 /* valid values */
1207 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001208 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001209 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001210 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1211
David Sedlákd1144562019-08-06 12:36:14 +02001212 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001213 assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001214 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001215 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
David Sedláke0ef1c62019-09-13 10:05:55 +02001216 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001217 assert_int_equal(exts[0].insubstmt_index, 0);
1218 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
1219 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001220
1221 /* invalid value */
1222 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001223 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001224 logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Valid values are \"1.0\" and \"1.1\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001225
1226 st->finished_correctly = true;
1227}
1228
1229static void
1230test_mandatory_elem(void **state)
1231{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001232 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001233 const char *data;
1234 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001235 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001236
1237 /* valid values */
1238 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001239 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001240 assert_int_equal(man, LYS_MAND_TRUE);
1241 man = 0;
1242
David Sedlákd1144562019-08-06 12:36:14 +02001243 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001244 assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001245 assert_int_equal(man, LYS_MAND_FALSE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001246 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001247 assert_int_equal(exts[0].insubstmt_index, 0);
1248 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
1249 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001250
1251 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001252 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001253 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001254
1255 st->finished_correctly = true;
1256}
1257
David Sedlák8e7bda82019-07-16 17:57:50 +02001258static void
1259test_argument_elem(void **state)
1260{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001261 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001262 const char *data;
1263 uint16_t flags = 0;
1264 const char *arg;
1265 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001266 struct lysp_ext_instance *exts = NULL;
1267
David Sedlák8e7bda82019-07-16 17:57:50 +02001268 /* max subelems */
1269 data = ELEMENT_WRAPPER_START
1270 "<argument name=\"arg-name\">"
1271 "<yin-element value=\"true\" />"
David Sedlákd1144562019-08-06 12:36:14 +02001272 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001273 "</argument>"
1274 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001275 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001276 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001277 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001278 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001279 assert_int_equal(exts[0].insubstmt_index, 0);
1280 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
1281 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1282 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001283 flags = 0;
1284 FREE_STRING(st->ctx, arg);
1285 arg = NULL;
1286
1287 /* min subelems */
1288 data = ELEMENT_WRAPPER_START
1289 "<argument name=\"arg\">"
1290 "</argument>"
1291 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001292 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001293 assert_string_equal(arg, "arg");
1294 assert_true(flags == 0);
1295 FREE_STRING(st->ctx, arg);
1296
1297 st->finished_correctly = true;
1298}
1299
1300static void
1301test_base_elem(void **state)
1302{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001303 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001304 const char *data;
1305 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001306 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001307 struct lysp_type type = {};
1308
1309 /* as identity subelement */
1310 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001311 "<base name=\"base-name\">"
1312 EXT_SUBELEM
1313 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001314 "</identity>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001315 assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001316 assert_string_equal(*bases, "base-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001317 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001318 assert_int_equal(exts[0].insubstmt_index, 0);
1319 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1320 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1321 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001322 FREE_STRING(st->ctx, *bases);
1323 LY_ARRAY_FREE(bases);
1324
1325 /* as type subelement */
1326 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001327 "<base name=\"base-name\">"
1328 EXT_SUBELEM
1329 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001330 "</type>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001331 assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001332 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001333 assert_true(type.flags & LYS_SET_BASE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001334 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001335 assert_int_equal(exts[0].insubstmt_index, 0);
1336 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1337 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1338 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001339 FREE_STRING(st->ctx, *type.bases);
1340 LY_ARRAY_FREE(type.bases);
1341
1342 st->finished_correctly = true;
1343}
1344
1345static void
1346test_belongsto_elem(void **state)
1347{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001348 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001349 const char *data;
1350 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001351 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001352
1353 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001354 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001355 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001356 assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001357 assert_string_equal(submod.belongsto, "module-name");
1358 assert_string_equal(submod.prefix, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001359 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001360 assert_int_equal(exts[0].insubstmt_index, 0);
1361 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
1362 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1363 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001364 FREE_STRING(st->ctx, submod.belongsto);
1365 FREE_STRING(st->ctx, submod.prefix);
1366
1367 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001368 assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001369 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001370 FREE_STRING(st->ctx, submod.belongsto);
1371
1372 st->finished_correctly = true;
1373}
1374
1375static void
1376test_config_elem(void **state)
1377{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001378 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001379 const char *data;
1380 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001381 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001382
David Sedlákd1144562019-08-06 12:36:14 +02001383 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001384 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001385 assert_true(flags & LYS_CONFIG_W);
David Sedláke0ef1c62019-09-13 10:05:55 +02001386 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001387 assert_int_equal(exts[0].insubstmt_index, 0);
1388 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
1389 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1390 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001391 flags = 0;
1392
1393 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001394 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001395 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001396 flags = 0;
1397
1398 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001399 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001400 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001401
1402 st->finished_correctly = true;
1403}
1404
1405static void
1406test_default_elem(void **state)
1407{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001408 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001409 const char *data;
1410 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001411 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001412
David Sedlákd1144562019-08-06 12:36:14 +02001413 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001414 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001415 assert_string_equal(val, "defaul-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02001416 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001417 assert_int_equal(exts[0].insubstmt_index, 0);
1418 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
1419 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1420 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001421 FREE_STRING(st->ctx, val);
1422 val = NULL;
1423
1424 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001425 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001426 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1427
1428 st->finished_correctly = true;
1429}
1430
1431static void
1432test_err_app_tag_elem(void **state)
1433{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001434 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001435 const char *data;
1436 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001437 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001438
David Sedlákd1144562019-08-06 12:36:14 +02001439 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001440 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001441 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001442 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001443 assert_int_equal(exts[0].insubstmt_index, 0);
1444 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
1445 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1446 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001447 FREE_STRING(st->ctx, val);
1448 val = NULL;
1449
1450 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001451 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001452 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1453
1454 st->finished_correctly = true;
1455}
1456
1457static void
1458test_err_msg_elem(void **state)
1459{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001460 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001461 const char *data;
1462 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001463 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001464
David Sedlákd1144562019-08-06 12:36:14 +02001465 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001466 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001467 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001468 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001469 assert_int_equal(exts[0].insubstmt_index, 0);
1470 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
1471 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1472 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001473 FREE_STRING(st->ctx, val);
1474
1475 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001476 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001477 logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001478
David Sedlákdf2a9732019-08-07 13:23:16 +02001479 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001480 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001481 logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001482
David Sedlák8e7bda82019-07-16 17:57:50 +02001483 st->finished_correctly = true;
1484}
1485
1486static void
1487test_fracdigits_elem(void **state)
1488{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001489 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001490 const char *data;
1491 struct lysp_type type = {};
1492
1493 /* valid value */
David Sedlákd1144562019-08-06 12:36:14 +02001494 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001495 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +02001496 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001497 assert_int_equal(type.exts[0].insubstmt_index, 0);
1498 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001499 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001500 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlákd1144562019-08-06 12:36:14 +02001501 FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001502
1503 /* invalid values */
1504 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001505 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001506 logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001507
1508 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001509 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001510 logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001511
1512 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001513 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001514 logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001515
1516 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001517 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001518 logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001519
1520 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001521 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001522 logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001523
1524 st->finished_correctly = true;
1525}
1526
1527static void
1528test_iffeature_elem(void **state)
1529{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001530 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001531 const char *data;
1532 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001533 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001534
David Sedlákd1144562019-08-06 12:36:14 +02001535 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001536 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001537 assert_string_equal(*iffeatures, "local-storage");
David Sedláke0ef1c62019-09-13 10:05:55 +02001538 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001539 assert_int_equal(exts[0].insubstmt_index, 0);
1540 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
1541 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1542 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001543 FREE_STRING(st->ctx, *iffeatures);
1544 LY_ARRAY_FREE(iffeatures);
1545 iffeatures = NULL;
1546
1547 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001548 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001549 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1550 LY_ARRAY_FREE(iffeatures);
1551 iffeatures = NULL;
1552
1553 st->finished_correctly = true;
1554}
1555
1556static void
1557test_length_elem(void **state)
1558{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001559 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001560 const char *data;
1561 struct lysp_type type = {};
1562
1563 /* max subelems */
1564 data = ELEMENT_WRAPPER_START
1565 "<length value=\"length-str\">"
1566 "<error-message><value>err-msg</value></error-message>"
1567 "<error-app-tag value=\"err-app-tag\"/>"
1568 "<description><text>desc</text></description>"
1569 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001570 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001571 "</length>"
1572 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001573 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001574 assert_string_equal(type.length->arg, "length-str");
1575 assert_string_equal(type.length->emsg, "err-msg");
1576 assert_string_equal(type.length->eapptag, "err-app-tag");
1577 assert_string_equal(type.length->dsc, "desc");
1578 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001579 assert_true(type.flags & LYS_SET_LENGTH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001580 assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001581 assert_int_equal(type.length->exts[0].insubstmt_index, 0);
1582 assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001583 lysp_type_free(st->ctx, &type);
1584 memset(&type, 0, sizeof(type));
1585
1586 /* min subelems */
1587 data = ELEMENT_WRAPPER_START
1588 "<length value=\"length-str\">"
1589 "</length>"
1590 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001591 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001592 assert_string_equal(type.length->arg, "length-str");
1593 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001594 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001595 memset(&type, 0, sizeof(type));
1596
1597 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001598 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001599 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1600 lysp_type_free(st->ctx, &type);
1601 memset(&type, 0, sizeof(type));
1602
1603 st->finished_correctly = true;
1604}
1605
1606static void
1607test_modifier_elem(void **state)
1608{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001609 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001610 const char *data;
1611 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
David Sedlákd1144562019-08-06 12:36:14 +02001612 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001613
David Sedlákd1144562019-08-06 12:36:14 +02001614 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001615 assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001616 assert_string_equal(pat, "\x015pattern");
David Sedláke0ef1c62019-09-13 10:05:55 +02001617 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001618 assert_int_equal(exts[0].insubstmt_index, 0);
1619 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
1620 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1621 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001622 FREE_STRING(st->ctx, pat);
1623
1624 pat = lydict_insert(st->ctx, "\006pattern", 8);
1625 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001626 assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001627 logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Only valid value is \"invert-match\". Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001628 FREE_STRING(st->ctx, pat);
1629
1630 st->finished_correctly = true;
1631}
1632
1633static void
1634test_namespace_elem(void **state)
1635{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001636 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001637 const char *data;
1638 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001639 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001640
David Sedlákd1144562019-08-06 12:36:14 +02001641 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001642 assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001643 assert_string_equal(ns, "ns");
David Sedláke0ef1c62019-09-13 10:05:55 +02001644 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001645 assert_int_equal(exts[0].insubstmt_index, 0);
1646 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
1647 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1648 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001649 FREE_STRING(st->ctx, ns);
1650
1651 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001652 assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001653 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1654
1655 st->finished_correctly = true;
1656}
1657
1658static void
1659test_path_elem(void **state)
1660{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001661 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001662 const char *data;
1663 struct lysp_type type = {};
1664
David Sedlák169cc522019-08-15 13:23:45 +02001665 data = ELEMENT_WRAPPER_START "<path value=\"p&amp;th-val\">" EXT_SUBELEM "</path>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001666 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák169cc522019-08-15 13:23:45 +02001667 assert_string_equal("p&th-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001668 assert_true(type.flags & LYS_SET_PATH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001669 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001670 assert_int_equal(type.exts[0].insubstmt_index, 0);
1671 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001672 lysp_type_free(st->ctx, &type);
1673
1674 st->finished_correctly = true;
1675}
1676
1677static void
1678test_pattern_elem(void **state)
1679{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001680 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001681 const char *data;
1682 struct lysp_type type = {};
1683
1684 /* max subelems */
1685 data = ELEMENT_WRAPPER_START
1686 "<pattern value=\"super_pattern\">"
1687 "<modifier value=\"invert-match\"/>"
1688 "<error-message><value>err-msg-value</value></error-message>"
1689 "<error-app-tag value=\"err-app-tag-value\"/>"
David Sedlák169cc522019-08-15 13:23:45 +02001690 "<description><text>&quot;pattern-desc&quot;</text></description>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001691 "<reference><text>pattern-ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001692 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001693 "</pattern>"
1694 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001695 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001696 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001697 assert_string_equal(type.patterns->arg, "\x015super_pattern");
David Sedlák169cc522019-08-15 13:23:45 +02001698 assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
David Sedlák8e7bda82019-07-16 17:57:50 +02001699 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1700 assert_string_equal(type.patterns->emsg, "err-msg-value");
David Sedlák8e7bda82019-07-16 17:57:50 +02001701 assert_string_equal(type.patterns->ref, "pattern-ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001702 assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001703 assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
1704 assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001705 lysp_type_free(st->ctx, &type);
1706 memset(&type, 0, sizeof(type));
1707
1708 /* min subelems */
1709 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001710 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001711 assert_string_equal(type.patterns->arg, "\x006pattern");
1712 lysp_type_free(st->ctx, &type);
1713 memset(&type, 0, sizeof(type));
1714
1715 st->finished_correctly = true;
1716}
1717
1718static void
1719test_value_position_elem(void **state)
1720{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001721 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001722 const char *data;
1723 struct lysp_type_enum en = {};
1724
1725 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001726 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001727 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001728 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001729 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001730 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001731 assert_int_equal(en.exts[0].insubstmt_index, 0);
1732 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
1733 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001734 memset(&en, 0, sizeof(en));
1735
1736 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001737 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001738 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001739 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001740 memset(&en, 0, sizeof(en));
1741
1742 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001743 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001744 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001745 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001746 memset(&en, 0, sizeof(en));
1747
1748 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001749 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001750 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001751 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001752 memset(&en, 0, sizeof(en));
1753
1754 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001755 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001756 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001757 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001758 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001759 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlák8d552d62019-08-06 15:29:05 +02001760 assert_int_equal(en.exts[0].insubstmt_index, 0);
1761 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
1762 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001763 memset(&en, 0, sizeof(en));
1764
1765 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001766 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001767 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001768 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001769 memset(&en, 0, sizeof(en));
1770
1771 /* invalid values */
1772 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001773 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001774 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001775
1776 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001777 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001778 logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001779
David Sedlák69f01612019-07-17 11:41:08 +02001780 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001781 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001782 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001783
David Sedlák8e7bda82019-07-16 17:57:50 +02001784 /*invalid positions */
1785 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001786 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001787 logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001788
1789 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001790 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001791 logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001792
1793 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001794 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001795 logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001796
David Sedlák69f01612019-07-17 11:41:08 +02001797 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001798 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001799 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001800
1801 st->finished_correctly = true;
1802}
1803
1804static void
1805test_prefix_elem(void **state)
1806{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001807 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001808 const char *data;
1809 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001810 struct lysp_ext_instance *exts = NULL;
1811
1812 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001813 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001814 assert_string_equal(value, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001815 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001816 assert_int_equal(exts[0].insubstmt_index, 0);
1817 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
1818 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1819 exts = NULL;
1820 FREE_STRING(st->ctx, value);
David Sedlák69f01612019-07-17 11:41:08 +02001821
1822 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001823 assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001824 assert_string_equal(value, "pref");
1825 FREE_STRING(st->ctx, value);
1826
1827 st->finished_correctly = true;
1828}
1829
1830static void
1831test_range_elem(void **state)
1832{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001833 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001834 const char *data;
1835 struct lysp_type type = {};
1836
1837 /* max subelems */
1838 data = ELEMENT_WRAPPER_START
1839 "<range value=\"range-str\">"
1840 "<error-message><value>err-msg</value></error-message>"
1841 "<error-app-tag value=\"err-app-tag\" />"
1842 "<description><text>desc</text></description>"
1843 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001844 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001845 "</range>"
1846 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001847 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001848 assert_string_equal(type.range->arg, "range-str");
1849 assert_string_equal(type.range->dsc, "desc");
1850 assert_string_equal(type.range->eapptag, "err-app-tag");
1851 assert_string_equal(type.range->emsg, "err-msg");
1852 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001853 assert_true(type.flags & LYS_SET_RANGE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001854 assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001855 assert_int_equal(type.range->exts[0].insubstmt_index, 0);
1856 assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001857 lysp_type_free(st->ctx, &type);
1858 memset(&type, 0, sizeof(type));
1859
1860 /* min subelems */
1861 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001862 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001863 assert_string_equal(type.range->arg, "range-str");
1864 lysp_type_free(st->ctx, &type);
1865 memset(&type, 0, sizeof(type));
1866
1867 st->finished_correctly = true;
1868}
1869
1870static void
1871test_reqinstance_elem(void **state)
1872{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001873 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001874 const char *data;
1875 struct lysp_type type = {};
1876
David Sedlákd1144562019-08-06 12:36:14 +02001877 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001878 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001879 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001880 assert_true(type.flags & LYS_SET_REQINST);
David Sedláke0ef1c62019-09-13 10:05:55 +02001881 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001882 assert_int_equal(type.exts[0].insubstmt_index, 0);
1883 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
1884 lysp_type_free(st->ctx, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001885 memset(&type, 0, sizeof(type));
1886
1887 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001888 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001889 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001890 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001891 memset(&type, 0, sizeof(type));
1892
1893 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001894 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001895 memset(&type, 0, sizeof(type));
David Sedlák26ea1432019-08-14 13:42:23 +02001896 logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Valid values are \"true\" and \"false\". Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001897
1898 st->finished_correctly = true;
1899}
1900
1901static void
1902test_revision_date_elem(void **state)
1903{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001904 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001905 const char *data;
1906 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001907 struct lysp_ext_instance *exts = NULL;
1908
1909 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001910 assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001911 assert_string_equal(rev, "2000-01-01");
David Sedláke0ef1c62019-09-13 10:05:55 +02001912 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001913 assert_int_equal(exts[0].insubstmt_index, 0);
1914 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
1915 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001916
1917 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001918 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001919 assert_string_equal(rev, "2000-01-01");
1920
1921 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001922 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001923 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1924
1925 st->finished_correctly = true;
1926}
1927
1928static void
1929test_unique_elem(void **state)
1930{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001931 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001932 const char *data;
1933 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001934 struct lysp_ext_instance *exts = NULL;
1935
1936 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001937 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001938 assert_string_equal(*values, "tag");
David Sedláke0ef1c62019-09-13 10:05:55 +02001939 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001940 assert_int_equal(exts[0].insubstmt_index, 0);
1941 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
1942 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1943 FREE_STRING(st->ctx, *values);
1944 LY_ARRAY_FREE(values);
1945 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001946
1947 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001948 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001949 assert_string_equal(*values, "tag");
1950 FREE_STRING(st->ctx, *values);
1951 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001952 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001953
1954 st->finished_correctly = true;
1955}
1956
1957static void
1958test_units_elem(void **state)
1959{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001960 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001961 const char *data;
1962 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001963 struct lysp_ext_instance *exts = NULL;
1964
1965 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001966 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001967 assert_string_equal(values, "name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001968 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001969 assert_int_equal(exts[0].insubstmt_index, 0);
1970 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
1971 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1972 FREE_STRING(st->ctx, values);
1973 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001974
1975 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001976 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001977 assert_string_equal(values, "name");
1978 FREE_STRING(st->ctx, values);
David Sedlákd1144562019-08-06 12:36:14 +02001979 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001980
1981 st->finished_correctly = true;
1982}
1983
1984static void
1985test_when_elem(void **state)
1986{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001987 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001988 const char *data;
1989 struct lysp_when *when = NULL;
1990
1991 data = ELEMENT_WRAPPER_START
1992 "<when condition=\"cond\">"
1993 "<description><text>desc</text></description>"
1994 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001995 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001996 "</when>"
1997 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001998 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001999 assert_string_equal(when->cond, "cond");
2000 assert_string_equal(when->dsc, "desc");
2001 assert_string_equal(when->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002002 assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002003 assert_int_equal(when->exts[0].insubstmt_index, 0);
2004 assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02002005 lysp_when_free(st->ctx, when);
2006 free(when);
2007 when = NULL;
2008
2009 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002010 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002011 assert_string_equal(when->cond, "cond");
2012 lysp_when_free(st->ctx, when);
2013 free(when);
2014 when = NULL;
2015
2016 st->finished_correctly = true;
2017}
2018
2019static void
2020test_yin_text_value_elem(void **state)
2021{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002022 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02002023 const char *data;
2024 const char *val;
2025
2026 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002027 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002028 assert_string_equal(val, "text");
2029 FREE_STRING(st->ctx, val);
2030
2031 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002032 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002033 assert_string_equal(val, "text");
2034 FREE_STRING(st->ctx, val);
2035
2036 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002037 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002038 assert_string_equal("", val);
2039 FREE_STRING(st->ctx, val);
2040
David Sedlák8e7bda82019-07-16 17:57:50 +02002041 st->finished_correctly = true;
2042}
David Sedlák32488102019-07-15 17:44:10 +02002043
David Sedlák374d2b32019-07-17 15:06:55 +02002044static void
2045test_type_elem(void **state)
2046{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002047 struct test_parser_yin_state *st = *state;
David Sedlák374d2b32019-07-17 15:06:55 +02002048 const char *data;
2049 struct lysp_type type = {};
2050
2051 /* max subelems */
2052 data = ELEMENT_WRAPPER_START
2053 "<type name=\"type-name\">"
2054 "<base name=\"base-name\"/>"
2055 "<bit name=\"bit\"/>"
2056 "<enum name=\"enum\"/>"
2057 "<fraction-digits value=\"2\"/>"
2058 "<length value=\"length\"/>"
2059 "<path value=\"path\"/>"
2060 "<pattern value=\"pattern\"/>"
2061 "<range value=\"range\" />"
2062 "<require-instance value=\"true\"/>"
2063 "<type name=\"sub-type-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002064 EXT_SUBELEM
David Sedlák374d2b32019-07-17 15:06:55 +02002065 "</type>"
2066 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002067 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002068 assert_string_equal(type.name, "type-name");
2069 assert_string_equal(*type.bases, "base-name");
2070 assert_string_equal(type.bits->name, "bit");
2071 assert_string_equal(type.enums->name, "enum");
2072 assert_int_equal(type.fraction_digits, 2);
2073 assert_string_equal(type.length->arg, "length");
2074 assert_string_equal(type.path, "path");
2075 assert_string_equal(type.patterns->arg, "\006pattern");
2076 assert_string_equal(type.range->arg, "range");
2077 assert_int_equal(type.require_instance, 1);
2078 assert_string_equal(type.types->name, "sub-type-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02002079 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002080 assert_int_equal(type.exts[0].insubstmt_index, 0);
2081 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002082 assert_true(type.flags & LYS_SET_BASE);
2083 assert_true(type.flags & LYS_SET_BIT);
2084 assert_true(type.flags & LYS_SET_ENUM);
2085 assert_true(type.flags & LYS_SET_FRDIGITS);
2086 assert_true(type.flags & LYS_SET_LENGTH);
2087 assert_true(type.flags & LYS_SET_PATH);
2088 assert_true(type.flags & LYS_SET_PATTERN);
2089 assert_true(type.flags & LYS_SET_RANGE);
2090 assert_true(type.flags & LYS_SET_REQINST);
2091 assert_true(type.flags & LYS_SET_TYPE);
David Sedlákd1144562019-08-06 12:36:14 +02002092 lysp_type_free(st->ctx, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02002093 memset(&type, 0, sizeof(type));
2094
2095 /* min subelems */
2096 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002097 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002098 lysp_type_free(st->ctx, &type);
2099 memset(&type, 0, sizeof(type));
2100
2101 st->finished_correctly = true;
2102}
2103
David Sedlák1af868e2019-07-17 17:03:14 +02002104static void
2105test_max_elems_elem(void **state)
2106{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002107 struct test_parser_yin_state *st = *state;
David Sedlák1af868e2019-07-17 17:03:14 +02002108 const char *data;
2109 struct lysp_node_list list = {};
2110 struct lysp_node_leaflist llist = {};
2111 struct lysp_refine refine = {};
2112
David Sedlákd1144562019-08-06 12:36:14 +02002113 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002114 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002115 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002116 assert_true(refine.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002117 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002118 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2119 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2120 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002121
David Sedlákd1144562019-08-06 12:36:14 +02002122 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002123 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002124 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002125 assert_true(list.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002126 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002127 assert_int_equal(list.exts[0].insubstmt_index, 0);
2128 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2129 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002130
David Sedlákd1144562019-08-06 12:36:14 +02002131 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002132 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002133 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002134 assert_true(llist.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002135 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002136 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2137 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2138 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002139
2140 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002141 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002142 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002143 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02002144
2145 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002146 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002147 logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002148
2149 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002150 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002151 logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002152
2153 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002154 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002155 logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002156
2157 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002158 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002159 logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002160
2161 st->finished_correctly = true;
2162}
2163
David Sedlák09e18c92019-07-18 11:17:11 +02002164static void
2165test_min_elems_elem(void **state)
2166{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002167 struct test_parser_yin_state *st = *state;
David Sedlák09e18c92019-07-18 11:17:11 +02002168 const char *data;
2169 struct lysp_node_list list = {};
2170 struct lysp_node_leaflist llist = {};
2171 struct lysp_refine refine = {};
2172
David Sedlákd1144562019-08-06 12:36:14 +02002173 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002174 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002175 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002176 assert_true(refine.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002177 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002178 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2179 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2180 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002181
David Sedlákd1144562019-08-06 12:36:14 +02002182 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002183 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002184 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002185 assert_true(list.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002186 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002187 assert_int_equal(list.exts[0].insubstmt_index, 0);
2188 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2189 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002190
David Sedlákd1144562019-08-06 12:36:14 +02002191 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002192 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002193 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002194 assert_true(llist.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002195 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002196 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2197 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2198 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002199
2200 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002201 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002202 logbuf_assert("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002203
2204 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002205 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002206 logbuf_assert("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002207
2208 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002209 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002210 logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002211
2212 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002213 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002214 logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002215
2216 st->finished_correctly = true;
2217}
2218
David Sedláka2dad212019-07-18 12:45:19 +02002219static void
2220test_ordby_elem(void **state)
2221{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002222 struct test_parser_yin_state *st = *state;
David Sedláka2dad212019-07-18 12:45:19 +02002223 const char *data;
2224 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02002225 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02002226
David Sedlákd1144562019-08-06 12:36:14 +02002227 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002228 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002229 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláke0ef1c62019-09-13 10:05:55 +02002230 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002231 assert_int_equal(exts[0].insubstmt_index, 0);
2232 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
2233 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02002234
2235 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002236 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002237 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02002238
2239 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002240 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02002241 logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Valid values are \"system\" and \"user\". Line number 1.");
David Sedláka2dad212019-07-18 12:45:19 +02002242
2243 st->finished_correctly = true;
2244}
2245
David Sedlák8a83bbb2019-07-18 14:46:00 +02002246static void
2247test_any_elem(void **state)
2248{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002249 struct test_parser_yin_state *st = *state;
David Sedlák8a83bbb2019-07-18 14:46:00 +02002250 const char *data;
2251 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002252 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02002253 struct lysp_node_anydata *parsed = NULL;
2254
2255 /* anyxml max subelems */
2256 data = ELEMENT_WRAPPER_START
2257 "<anyxml name=\"any-name\">"
2258 "<config value=\"true\" />"
2259 "<description><text>desc</text></description>"
2260 "<if-feature name=\"feature\" />"
2261 "<mandatory value=\"true\" />"
2262 "<must condition=\"must-cond\" />"
2263 "<reference><text>ref</text></reference>"
2264 "<status value=\"deprecated\"/>"
2265 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002266 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002267 "</anyxml>"
2268 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002269 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002270 parsed = (struct lysp_node_anydata *)siblings;
2271 assert_null(parsed->parent);
2272 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002273 assert_true(parsed->flags & LYS_CONFIG_W);
2274 assert_true(parsed->flags & LYS_MAND_TRUE);
2275 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002276 assert_null(parsed->next);
2277 assert_string_equal(parsed->name, "any-name");
2278 assert_string_equal(parsed->dsc, "desc");
2279 assert_string_equal(parsed->ref, "ref");
2280 assert_string_equal(parsed->when->cond, "when-cond");
2281 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002282 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002283 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2284 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002285 lysp_node_free(st->ctx, siblings);
2286 siblings = NULL;
2287
2288 /* anydata max subelems */
2289 data = ELEMENT_WRAPPER_START
2290 "<anydata name=\"any-name\">"
2291 "<config value=\"true\" />"
2292 "<description><text>desc</text></description>"
2293 "<if-feature name=\"feature\" />"
2294 "<mandatory value=\"true\" />"
2295 "<must condition=\"must-cond\" />"
2296 "<reference><text>ref</text></reference>"
2297 "<status value=\"deprecated\"/>"
2298 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002299 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002300 "</anydata>"
2301 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002302 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002303 parsed = (struct lysp_node_anydata *)siblings;
2304 assert_null(parsed->parent);
2305 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002306 assert_true(parsed->flags & LYS_CONFIG_W);
2307 assert_true(parsed->flags & LYS_MAND_TRUE);
2308 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002309 assert_null(parsed->next);
2310 assert_string_equal(parsed->name, "any-name");
2311 assert_string_equal(parsed->dsc, "desc");
2312 assert_string_equal(parsed->ref, "ref");
2313 assert_string_equal(parsed->when->cond, "when-cond");
2314 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002315 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002316 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2317 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002318 lysp_node_free(st->ctx, siblings);
2319 siblings = NULL;
2320
2321 /* min subelems */
2322 node_meta.parent = (void *)0x10;
2323 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002324 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002325 parsed = (struct lysp_node_anydata *)siblings;
2326 assert_ptr_equal(parsed->parent, node_meta.parent);
2327 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
2328 assert_null(parsed->next);
2329 assert_null(parsed->exts);
2330 lysp_node_free(st->ctx, siblings);
2331
2332 st->finished_correctly = true;
2333}
2334
David Sedlák203ca3a2019-07-18 15:26:25 +02002335static void
2336test_leaf_elem(void **state)
2337{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002338 struct test_parser_yin_state *st = *state;
David Sedlák203ca3a2019-07-18 15:26:25 +02002339 const char *data;
2340 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002341 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002342 struct lysp_node_leaf *parsed = NULL;
2343
2344 /* max elements */
2345 data = ELEMENT_WRAPPER_START
2346 "<leaf name=\"leaf\">"
2347 "<config value=\"true\" />"
2348 "<default value=\"def-val\"/>"
2349 "<description><text>desc</text></description>"
2350 "<if-feature name=\"feature\" />"
2351 "<mandatory value=\"true\" />"
2352 "<must condition=\"must-cond\" />"
2353 "<reference><text>ref</text></reference>"
2354 "<status value=\"deprecated\"/>"
2355 "<type name=\"type\"/>"
2356 "<units name=\"uni\"/>"
2357 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002358 EXT_SUBELEM
David Sedlák203ca3a2019-07-18 15:26:25 +02002359 "</leaf>"
2360 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002361 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002362 parsed = (struct lysp_node_leaf *)siblings;
2363 assert_null(parsed->parent);
2364 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002365 assert_true(parsed->flags & LYS_CONFIG_W);
2366 assert_true(parsed->flags & LYS_MAND_TRUE);
2367 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02002368 assert_null(parsed->next);
2369 assert_string_equal(parsed->name, "leaf");
2370 assert_string_equal(parsed->dsc, "desc");
2371 assert_string_equal(parsed->ref, "ref");
2372 assert_string_equal(parsed->when->cond, "when-cond");
2373 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002374 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002375 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2376 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák203ca3a2019-07-18 15:26:25 +02002377 assert_string_equal(parsed->musts->arg, "must-cond");
2378 assert_string_equal(parsed->type.name, "type");
2379 assert_string_equal(parsed->units, "uni");
2380 assert_string_equal(parsed->dflt, "def-val");
2381 lysp_node_free(st->ctx, siblings);
2382 siblings = NULL;
2383
2384 /* min elements */
2385 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002386 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002387 parsed = (struct lysp_node_leaf *)siblings;
2388 assert_string_equal(parsed->name, "leaf");
2389 assert_string_equal(parsed->type.name, "type");
2390 lysp_node_free(st->ctx, siblings);
2391 siblings = NULL;
2392
2393 st->finished_correctly = true;
2394}
2395
David Sedlákc3da3ef2019-07-19 12:56:08 +02002396static void
2397test_leaf_list_elem(void **state)
2398{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002399 struct test_parser_yin_state *st = *state;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002400 const char *data;
2401 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002402 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002403 struct lysp_node_leaflist *parsed = NULL;
2404
2405 data = ELEMENT_WRAPPER_START
2406 "<leaf-list name=\"llist\">"
2407 "<config value=\"true\" />"
2408 "<default value=\"def-val0\"/>"
2409 "<default value=\"def-val1\"/>"
2410 "<description><text>desc</text></description>"
2411 "<if-feature name=\"feature\"/>"
2412 "<max-elements value=\"5\"/>"
2413 "<must condition=\"must-cond\"/>"
2414 "<ordered-by value=\"user\" />"
2415 "<reference><text>ref</text></reference>"
2416 "<status value=\"current\"/>"
2417 "<type name=\"type\"/>"
2418 "<units name=\"uni\"/>"
2419 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002420 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002421 "</leaf-list>"
2422 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002423 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002424 parsed = (struct lysp_node_leaflist *)siblings;
2425 assert_string_equal(parsed->dflts[0], "def-val0");
2426 assert_string_equal(parsed->dflts[1], "def-val1");
2427 assert_string_equal(parsed->dsc, "desc");
2428 assert_string_equal(*parsed->iffeatures, "feature");
2429 assert_int_equal(parsed->max, 5);
2430 assert_string_equal(parsed->musts->arg, "must-cond");
2431 assert_string_equal(parsed->name, "llist");
2432 assert_null(parsed->next);
2433 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2434 assert_null(parsed->parent);
2435 assert_string_equal(parsed->ref, "ref");
2436 assert_string_equal(parsed->type.name, "type");
2437 assert_string_equal(parsed->units, "uni");
2438 assert_string_equal(parsed->when->cond, "when-cond");
2439 assert_true(parsed->flags & LYS_CONFIG_W);
2440 assert_true(parsed->flags & LYS_ORDBY_USER);
2441 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002442 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002443 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2444 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002445 lysp_node_free(st->ctx, siblings);
2446 siblings = NULL;
2447
2448 data = ELEMENT_WRAPPER_START
2449 "<leaf-list name=\"llist\">"
2450 "<config value=\"true\" />"
2451 "<description><text>desc</text></description>"
2452 "<if-feature name=\"feature\"/>"
2453 "<min-elements value=\"5\"/>"
2454 "<must condition=\"must-cond\"/>"
2455 "<ordered-by value=\"user\" />"
2456 "<reference><text>ref</text></reference>"
2457 "<status value=\"current\"/>"
2458 "<type name=\"type\"/>"
2459 "<units name=\"uni\"/>"
2460 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002461 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002462 "</leaf-list>"
2463 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002464 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002465 parsed = (struct lysp_node_leaflist *)siblings;
2466 assert_string_equal(parsed->dsc, "desc");
2467 assert_string_equal(*parsed->iffeatures, "feature");
2468 assert_int_equal(parsed->min, 5);
2469 assert_string_equal(parsed->musts->arg, "must-cond");
2470 assert_string_equal(parsed->name, "llist");
2471 assert_null(parsed->next);
2472 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2473 assert_null(parsed->parent);
2474 assert_string_equal(parsed->ref, "ref");
2475 assert_string_equal(parsed->type.name, "type");
2476 assert_string_equal(parsed->units, "uni");
2477 assert_string_equal(parsed->when->cond, "when-cond");
2478 assert_true(parsed->flags & LYS_CONFIG_W);
2479 assert_true(parsed->flags & LYS_ORDBY_USER);
2480 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002481 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002482 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2483 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002484 lysp_node_free(st->ctx, siblings);
2485 siblings = NULL;
2486
2487 data = ELEMENT_WRAPPER_START
2488 "<leaf-list name=\"llist\">"
2489 "<config value=\"true\" />"
2490 "<description><text>desc</text></description>"
2491 "<if-feature name=\"feature\"/>"
2492 "<max-elements value=\"15\"/>"
2493 "<min-elements value=\"5\"/>"
2494 "<must condition=\"must-cond\"/>"
2495 "<ordered-by value=\"user\" />"
2496 "<reference><text>ref</text></reference>"
2497 "<status value=\"current\"/>"
2498 "<type name=\"type\"/>"
2499 "<units name=\"uni\"/>"
2500 "<when condition=\"when-cond\"/>"
2501 "</leaf-list>"
2502 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002503 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002504 parsed = (struct lysp_node_leaflist *)siblings;
2505 assert_string_equal(parsed->dsc, "desc");
2506 assert_string_equal(*parsed->iffeatures, "feature");
2507 assert_int_equal(parsed->min, 5);
2508 assert_int_equal(parsed->max, 15);
2509 assert_string_equal(parsed->musts->arg, "must-cond");
2510 assert_string_equal(parsed->name, "llist");
2511 assert_null(parsed->next);
2512 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2513 assert_null(parsed->parent);
2514 assert_string_equal(parsed->ref, "ref");
2515 assert_string_equal(parsed->type.name, "type");
2516 assert_string_equal(parsed->units, "uni");
2517 assert_string_equal(parsed->when->cond, "when-cond");
2518 assert_true(parsed->flags & LYS_CONFIG_W);
2519 assert_true(parsed->flags & LYS_ORDBY_USER);
2520 assert_true(parsed->flags & LYS_STATUS_CURR);
2521 lysp_node_free(st->ctx, siblings);
2522 siblings = NULL;
2523
2524 data = ELEMENT_WRAPPER_START
2525 "<leaf-list name=\"llist\">"
2526 "<type name=\"type\"/>"
2527 "</leaf-list>"
2528 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002529 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002530 parsed = (struct lysp_node_leaflist *)siblings;
2531 assert_string_equal(parsed->name, "llist");
2532 assert_string_equal(parsed->type.name, "type");
2533 lysp_node_free(st->ctx, siblings);
2534 siblings = NULL;
2535
2536 /* invalid combinations */
2537 data = ELEMENT_WRAPPER_START
2538 "<leaf-list name=\"llist\">"
2539 "<max-elements value=\"5\"/>"
2540 "<min-elements value=\"15\"/>"
2541 "<type name=\"type\"/>"
2542 "</leaf-list>"
2543 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002544 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002545 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2546 lysp_node_free(st->ctx, siblings);
2547 siblings = NULL;
2548
2549 data = ELEMENT_WRAPPER_START
2550 "<leaf-list name=\"llist\">"
2551 "<default value=\"def-val1\"/>"
2552 "<min-elements value=\"15\"/>"
2553 "<type name=\"type\"/>"
2554 "</leaf-list>"
2555 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002556 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002557 logbuf_assert("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002558 lysp_node_free(st->ctx, siblings);
2559 siblings = NULL;
2560
2561 data = ELEMENT_WRAPPER_START
2562 "<leaf-list name=\"llist\">"
2563 "</leaf-list>"
2564 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002565 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002566 logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002567 lysp_node_free(st->ctx, siblings);
2568 siblings = NULL;
2569
2570 st->finished_correctly = true;
2571}
2572
David Sedlákcb39f642019-07-19 13:19:55 +02002573static void
2574test_presence_elem(void **state)
2575{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002576 struct test_parser_yin_state *st = *state;
David Sedlákcb39f642019-07-19 13:19:55 +02002577 const char *data;
2578 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002579 struct lysp_ext_instance *exts = NULL;
2580
2581 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002582 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002583 assert_string_equal(val, "presence-val");
David Sedláke0ef1c62019-09-13 10:05:55 +02002584 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002585 assert_int_equal(exts[0].insubstmt_index, 0);
2586 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
2587 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2588 FREE_STRING(st->ctx, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002589
2590 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002591 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002592 assert_string_equal(val, "presence-val");
2593 FREE_STRING(st->ctx, val);
2594
2595 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002596 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlákcb39f642019-07-19 13:19:55 +02002597 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2598
2599 st->finished_correctly = true;
2600}
2601
David Sedlák12470a82019-07-19 13:44:36 +02002602static void
2603test_key_elem(void **state)
2604{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002605 struct test_parser_yin_state *st = *state;
David Sedlák12470a82019-07-19 13:44:36 +02002606 const char *data;
2607 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002608 struct lysp_ext_instance *exts = NULL;
2609
2610 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002611 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002612 assert_string_equal(val, "key-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02002613 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002614 assert_int_equal(exts[0].insubstmt_index, 0);
2615 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
2616 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2617 FREE_STRING(st->ctx, val);
David Sedlák12470a82019-07-19 13:44:36 +02002618
2619 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002620 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002621 assert_string_equal(val, "key-value");
2622 FREE_STRING(st->ctx, val);
2623
2624 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002625 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák12470a82019-07-19 13:44:36 +02002626 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2627
2628 st->finished_correctly = true;
2629}
2630
David Sedlák04e17b22019-07-19 15:29:48 +02002631static void
2632test_typedef_elem(void **state)
2633{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002634 struct test_parser_yin_state *st = *state;
David Sedlák04e17b22019-07-19 15:29:48 +02002635 const char *data;
2636 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002637 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002638
2639 data = ELEMENT_WRAPPER_START
2640 "<typedef name=\"tpdf-name\">"
2641 "<default value=\"def-val\"/>"
2642 "<description><text>desc-text</text></description>"
2643 "<reference><text>ref-text</text></reference>"
2644 "<status value=\"current\"/>"
2645 "<type name=\"type\"/>"
2646 "<units name=\"uni\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002647 EXT_SUBELEM
David Sedlák04e17b22019-07-19 15:29:48 +02002648 "</typedef>"
2649 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002650 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002651 assert_string_equal(tpdfs[0].dflt, "def-val");
2652 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002653 assert_string_equal(tpdfs[0].name, "tpdf-name");
2654 assert_string_equal(tpdfs[0].ref, "ref-text");
2655 assert_string_equal(tpdfs[0].type.name, "type");
2656 assert_string_equal(tpdfs[0].units, "uni");
2657 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002658 assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002659 assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
2660 assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák04e17b22019-07-19 15:29:48 +02002661 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2662 tpdfs = NULL;
2663
2664 data = ELEMENT_WRAPPER_START
2665 "<typedef name=\"tpdf-name\">"
2666 "<type name=\"type\"/>"
2667 "</typedef>"
2668 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002669 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002670 assert_string_equal(tpdfs[0].name, "tpdf-name");
2671 assert_string_equal(tpdfs[0].type.name, "type");
2672 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2673 tpdfs = NULL;
2674
2675 st->finished_correctly = true;
2676}
2677
David Sedlákd2d676a2019-07-22 11:28:19 +02002678static void
2679test_refine_elem(void **state)
2680{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002681 struct test_parser_yin_state *st = *state;
David Sedlákd2d676a2019-07-22 11:28:19 +02002682 const char *data;
2683 struct lysp_refine *refines = NULL;
2684
2685 /* max subelems */
2686 data = ELEMENT_WRAPPER_START
2687 "<refine target-node=\"target\">"
2688 "<if-feature name=\"feature\" />"
2689 "<must condition=\"cond\" />"
2690 "<presence value=\"presence\" />"
2691 "<default value=\"def\" />"
2692 "<config value=\"true\" />"
2693 "<mandatory value=\"true\" />"
2694 "<min-elements value=\"10\" />"
2695 "<max-elements value=\"20\" />"
2696 "<description><text>desc</text></description>"
2697 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002698 EXT_SUBELEM
David Sedlákd2d676a2019-07-22 11:28:19 +02002699 "</refine>"
2700 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002701 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002702 assert_string_equal(refines->nodeid, "target");
2703 assert_string_equal(*refines->dflts, "def");
2704 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002705 assert_true(refines->flags & LYS_CONFIG_W);
2706 assert_true(refines->flags & LYS_MAND_TRUE);
2707 assert_string_equal(*refines->iffeatures, "feature");
2708 assert_int_equal(refines->max, 20);
2709 assert_int_equal(refines->min, 10);
2710 assert_string_equal(refines->musts->arg, "cond");
2711 assert_string_equal(refines->presence, "presence");
2712 assert_string_equal(refines->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002713 assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002714 assert_int_equal(refines->exts[0].insubstmt_index, 0);
2715 assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákd2d676a2019-07-22 11:28:19 +02002716 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2717 refines = NULL;
2718
2719 /* min subelems */
2720 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002721 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002722 assert_string_equal(refines->nodeid, "target");
2723 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2724 refines = NULL;
2725
2726 st->finished_correctly = true;
2727}
2728
David Sedlák0d6de5a2019-07-22 13:25:44 +02002729static void
2730test_uses_elem(void **state)
2731{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002732 struct test_parser_yin_state *st = *state;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002733 const char *data;
2734 struct lysp_node *siblings = NULL;
2735 struct tree_node_meta node_meta = {NULL, &siblings};
2736 struct lysp_node_uses *parsed = NULL;
2737
2738 /* max subelems */
2739 data = ELEMENT_WRAPPER_START
2740 "<uses name=\"uses-name\">"
2741 "<when condition=\"cond\" />"
2742 "<if-feature name=\"feature\" />"
2743 "<status value=\"obsolete\" />"
2744 "<description><text>desc</text></description>"
2745 "<reference><text>ref</text></reference>"
2746 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002747 "<augment target-node=\"target\" />"
David Sedlákd1144562019-08-06 12:36:14 +02002748 EXT_SUBELEM
David Sedlák0d6de5a2019-07-22 13:25:44 +02002749 "</uses>"
2750 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002751 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002752 parsed = (struct lysp_node_uses *)&siblings[0];
2753 assert_string_equal(parsed->name, "uses-name");
2754 assert_string_equal(parsed->dsc, "desc");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002755 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2756 assert_string_equal(*parsed->iffeatures, "feature");
2757 assert_null(parsed->next);
2758 assert_int_equal(parsed->nodetype, LYS_USES);
2759 assert_null(parsed->parent);
2760 assert_string_equal(parsed->ref, "ref");
2761 assert_string_equal(parsed->refines->nodeid, "target");
2762 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002763 assert_string_equal(parsed->augments->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02002764 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002765 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2766 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002767 lysp_node_free(st->ctx, siblings);
2768 siblings = NULL;
2769
2770 /* min subelems */
2771 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002772 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002773 assert_string_equal(siblings[0].name, "uses-name");
2774 lysp_node_free(st->ctx, siblings);
2775 siblings = NULL;
2776
2777 st->finished_correctly = true;
2778}
2779
David Sedlákaa854b02019-07-22 14:17:10 +02002780static void
2781test_revision_elem(void **state)
2782{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002783 struct test_parser_yin_state *st = *state;
David Sedlákaa854b02019-07-22 14:17:10 +02002784 const char *data;
2785 struct lysp_revision *revs = NULL;
2786
2787 /* max subelems */
2788 data = ELEMENT_WRAPPER_START
2789 "<revision date=\"2018-12-25\">"
2790 "<description><text>desc</text></description>"
2791 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002792 EXT_SUBELEM
David Sedlákaa854b02019-07-22 14:17:10 +02002793 "</revision>"
2794 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002795 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002796 assert_string_equal(revs->date, "2018-12-25");
2797 assert_string_equal(revs->dsc, "desc");
2798 assert_string_equal(revs->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002799 assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002800 assert_int_equal(revs->exts[0].insubstmt_index, 0);
2801 assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaa854b02019-07-22 14:17:10 +02002802 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2803 revs = NULL;
2804
2805 /* min subelems */
2806 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002807 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002808 assert_string_equal(revs->date, "2005-05-05");
2809 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2810 revs = NULL;
2811
2812 /* invalid value */
2813 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002814 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID);
David Sedlákaa854b02019-07-22 14:17:10 +02002815 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2816 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2817 revs = NULL;
2818
2819 st->finished_correctly = true;
2820}
2821
David Sedlák0c2bab92019-07-22 15:33:19 +02002822static void
2823test_include_elem(void **state)
2824{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002825 struct test_parser_yin_state *st = *state;
David Sedlák0c2bab92019-07-22 15:33:19 +02002826 const char *data;
2827 struct lysp_include *includes = NULL;
2828 struct include_meta inc_meta = {"module-name", &includes};
2829
2830 /* max subelems */
2831 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2832 data = ELEMENT_WRAPPER_START
2833 "<include module=\"mod\">"
2834 "<description><text>desc</text></description>"
2835 "<reference><text>ref</text></reference>"
2836 "<revision-date date=\"1999-09-09\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002837 EXT_SUBELEM
David Sedlák0c2bab92019-07-22 15:33:19 +02002838 "</include>"
2839 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002840 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002841 assert_string_equal(includes->name, "mod");
2842 assert_string_equal(includes->dsc, "desc");
2843 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002844 assert_string_equal(includes->rev, "1999-09-09");
David Sedláke0ef1c62019-09-13 10:05:55 +02002845 assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002846 assert_int_equal(includes->exts[0].insubstmt_index, 0);
2847 assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0c2bab92019-07-22 15:33:19 +02002848 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2849 includes = NULL;
2850
2851 /* min subelems */
2852 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002853 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002854 assert_string_equal(includes->name, "mod");
2855 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2856 includes = NULL;
2857
2858 /* invalid combinations */
2859 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2860 data = ELEMENT_WRAPPER_START
2861 "<include module=\"mod\">"
2862 "<description><text>desc</text></description>"
2863 "<revision-date date=\"1999-09-09\"/>"
2864 "</include>"
2865 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002866 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002867 logbuf_assert("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
2868 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2869 includes = NULL;
2870
2871 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2872 data = ELEMENT_WRAPPER_START
2873 "<include module=\"mod\">"
2874 "<reference><text>ref</text></reference>"
2875 "<revision-date date=\"1999-09-09\"/>"
2876 "</include>"
2877 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002878 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002879 logbuf_assert("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
2880 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2881 includes = NULL;
2882
2883 st->finished_correctly = true;
2884}
2885
David Sedlák5e13dea2019-07-22 16:06:45 +02002886static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002887test_list_elem(void **state)
2888{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002889 struct test_parser_yin_state *st = *state;
David Sedlákaf536aa2019-07-23 13:42:23 +02002890 const char *data;
2891 struct lysp_node *siblings = NULL;
2892 struct tree_node_meta node_meta = {NULL, &siblings};
2893 struct lysp_node_list *parsed = NULL;
2894
2895 /* max subelems */
2896 data = ELEMENT_WRAPPER_START
2897 "<list name=\"list-name\">"
2898 "<when condition=\"when\"/>"
2899 "<if-feature name=\"iff\"/>"
2900 "<must condition=\"must-cond\"/>"
2901 "<key value=\"key\"/>"
2902 "<unique tag=\"utag\"/>"
2903 "<config value=\"true\"/>"
2904 "<min-elements value=\"10\"/>"
2905 "<ordered-by value=\"user\"/>"
2906 "<status value=\"deprecated\"/>"
2907 "<description><text>desc</text></description>"
2908 "<reference><text>ref</text></reference>"
2909 "<anydata name=\"anyd\"/>"
2910 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002911 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002912 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002913 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002914 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002915 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002916 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2917 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002918 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002919 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002920 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002921 EXT_SUBELEM
David Sedlákaf536aa2019-07-23 13:42:23 +02002922 "</list>"
2923 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002924 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002925 parsed = (struct lysp_node_list *)&siblings[0];
2926 assert_string_equal(parsed->dsc, "desc");
2927 assert_string_equal(parsed->child->name, "anyd");
2928 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2929 assert_string_equal(parsed->child->next->name, "anyx");
2930 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002931 assert_string_equal(parsed->child->next->next->name, "cont");
2932 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002933 assert_string_equal(parsed->child->next->next->next->name, "choice");
2934 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002935 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2936 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2937 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2938 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2939 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2940 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2941 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2942 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2943 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002944 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002945 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002946 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002947 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02002948 assert_true(parsed->flags & LYS_ORDBY_USER);
2949 assert_true(parsed->flags & LYS_STATUS_DEPRC);
2950 assert_true(parsed->flags & LYS_CONFIG_W);
2951 assert_string_equal(*parsed->iffeatures, "iff");
2952 assert_string_equal(parsed->key, "key");
2953 assert_int_equal(parsed->min, 10);
2954 assert_string_equal(parsed->musts->arg, "must-cond");
2955 assert_string_equal(parsed->name, "list-name");
2956 assert_null(parsed->next);
2957 assert_int_equal(parsed->nodetype, LYS_LIST);
2958 assert_null(parsed->parent);
2959 assert_string_equal(parsed->ref, "ref");
2960 assert_string_equal(parsed->typedefs->name, "tpdf");
2961 assert_string_equal(*parsed->uniques, "utag");
2962 assert_string_equal(parsed->when->cond, "when");
David Sedláke0ef1c62019-09-13 10:05:55 +02002963 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002964 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2965 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaf536aa2019-07-23 13:42:23 +02002966 lysp_node_free(st->ctx, siblings);
2967 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2968 siblings = NULL;
2969
2970 /* min subelems */
2971 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002972 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002973 parsed = (struct lysp_node_list *)&siblings[0];
2974 assert_string_equal(parsed->name, "list-name");
2975 lysp_node_free(st->ctx, siblings);
2976 siblings = NULL;
2977
2978 st->finished_correctly = true;
2979}
2980
David Sedlák031b9e72019-07-23 15:19:37 +02002981static void
2982test_notification_elem(void **state)
2983{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002984 struct test_parser_yin_state *st = *state;
David Sedlák031b9e72019-07-23 15:19:37 +02002985 const char *data;
2986 struct lysp_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002987 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002988
2989 /* max subelems */
2990 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2991 data = ELEMENT_WRAPPER_START
2992 "<notification name=\"notif-name\">"
2993 "<anydata name=\"anyd\"/>"
2994 "<anyxml name=\"anyx\"/>"
2995 "<description><text>desc</text></description>"
2996 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002997 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2998 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02002999 "<list name=\"sub-list\"/>"
3000 "<must condition=\"cond\"/>"
3001 "<reference><text>ref</text></reference>"
3002 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003003 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02003004 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003005 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003006 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003007 "<grouping name=\"grp\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003008 EXT_SUBELEM
David Sedlák031b9e72019-07-23 15:19:37 +02003009 "</notification>"
3010 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003011 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003012 assert_string_equal(notifs->name, "notif-name");
3013 assert_string_equal(notifs->data->name, "anyd");
3014 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
3015 assert_string_equal(notifs->data->next->name, "anyx");
3016 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
3017 assert_string_equal(notifs->data->next->next->name, "leaf");
3018 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
3019 assert_string_equal(notifs->data->next->next->next->name, "llist");
3020 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
3021 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
3022 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02003023 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003024 assert_string_equal(notifs->groupings->name, "grp");
3025 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02003026 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
3027 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
3028 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
3029 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003030 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3031 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
3032 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02003033 assert_string_equal(*notifs->iffeatures, "iff");
3034 assert_string_equal(notifs->musts->arg, "cond");
3035 assert_int_equal(notifs->nodetype, LYS_NOTIF);
3036 assert_null(notifs->parent);
3037 assert_string_equal(notifs->ref, "ref");
3038 assert_string_equal(notifs->typedefs->name, "tpdf");
David Sedláke0ef1c62019-09-13 10:05:55 +02003039 assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003040 assert_int_equal(notifs->exts[0].insubstmt_index, 0);
3041 assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák031b9e72019-07-23 15:19:37 +02003042 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
3043 notifs = NULL;
3044
3045 /* min subelems */
3046 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003047 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003048 assert_string_equal(notifs->name, "notif-name");
3049 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003050 notifs = NULL;
3051
3052 st->finished_correctly = true;
3053}
3054
3055static void
3056test_grouping_elem(void **state)
3057{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003058 struct test_parser_yin_state *st = *state;
David Sedláke3ce9ef2019-07-23 16:34:30 +02003059 const char *data;
3060 struct lysp_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003061 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02003062
3063 /* max subelems */
3064 data = ELEMENT_WRAPPER_START
3065 "<grouping name=\"grp-name\">"
3066 "<anydata name=\"anyd\"/>"
3067 "<anyxml name=\"anyx\"/>"
3068 "<description><text>desc</text></description>"
3069 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003070 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3071 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003072 "<list name=\"list\"/>"
3073 "<notification name=\"notf\"/>"
3074 "<reference><text>ref</text></reference>"
3075 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003076 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003077 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003078 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003079 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003080 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003081 EXT_SUBELEM
David Sedláke3ce9ef2019-07-23 16:34:30 +02003082 "</grouping>"
3083 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003084 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003085 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003086 assert_string_equal(grps->data->name, "anyd");
3087 assert_string_equal(grps->data->next->name, "anyx");
3088 assert_string_equal(grps->data->next->next->name, "leaf");
3089 assert_string_equal(grps->data->next->next->next->name, "llist");
3090 assert_string_equal(grps->data->next->next->next->next->name, "list");
3091 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003092 assert_true(grps->flags & LYS_STATUS_CURR);
3093 assert_string_equal(grps->groupings->name, "sub-grp");
3094 assert_int_equal(grps->nodetype, LYS_GROUPING);
3095 assert_string_equal(grps->notifs->name, "notf");
3096 assert_null(grps->parent);
3097 assert_string_equal(grps->ref, "ref");
3098 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003099 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02003100 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003101 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02003102 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003103 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
3104 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
3105 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke0ef1c62019-09-13 10:05:55 +02003106 assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003107 assert_int_equal(grps->exts[0].insubstmt_index, 0);
3108 assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003109 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3110 grps = NULL;
3111
3112 /* min subelems */
3113 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003114 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003115 assert_string_equal(grps->name, "grp-name");
3116 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3117 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02003118
3119 st->finished_correctly = true;
3120}
3121
David Sedlákf111bcb2019-07-23 17:15:51 +02003122static void
3123test_container_elem(void **state)
3124{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003125 struct test_parser_yin_state *st = *state;
David Sedlákf111bcb2019-07-23 17:15:51 +02003126 const char *data;
3127 struct lysp_node *siblings = NULL;
3128 struct tree_node_meta node_meta = {NULL, &siblings};
3129 struct lysp_node_container *parsed = NULL;
3130
3131 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02003132 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3133 data = ELEMENT_WRAPPER_START
3134 "<container name=\"cont-name\">"
3135 "<anydata name=\"anyd\"/>"
3136 "<anyxml name=\"anyx\"/>"
3137 "<config value=\"true\"/>"
3138 "<container name=\"subcont\"/>"
3139 "<description><text>desc</text></description>"
3140 "<grouping name=\"sub-grp\"/>"
3141 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003142 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3143 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003144 "<list name=\"list\"/>"
3145 "<must condition=\"cond\"/>"
3146 "<notification name=\"notf\"/>"
3147 "<presence value=\"presence\"/>"
3148 "<reference><text>ref</text></reference>"
3149 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003150 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003151 "<uses name=\"uses-name\"/>"
3152 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003153 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003154 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003155 EXT_SUBELEM
David Sedláke2dc9e92019-07-24 09:59:21 +02003156 "</container>"
3157 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003158 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02003159 parsed = (struct lysp_node_container *)siblings;
3160 assert_string_equal(parsed->name, "cont-name");
3161 assert_null(parsed->parent);
3162 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
3163 assert_true(parsed->flags & LYS_CONFIG_W);
3164 assert_true(parsed->flags & LYS_STATUS_CURR);
3165 assert_null(parsed->next);
3166 assert_string_equal(parsed->dsc, "desc");
3167 assert_string_equal(parsed->ref, "ref");
3168 assert_string_equal(parsed->when->cond, "when-cond");
3169 assert_string_equal(*parsed->iffeatures, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02003170 assert_string_equal(parsed->musts->arg, "cond");
3171 assert_string_equal(parsed->presence, "presence");
3172 assert_string_equal(parsed->typedefs->name, "tpdf");
3173 assert_string_equal(parsed->groupings->name, "sub-grp");
3174 assert_string_equal(parsed->child->name, "anyd");
3175 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3176 assert_string_equal(parsed->child->next->name, "anyx");
3177 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3178 assert_string_equal(parsed->child->next->next->name, "subcont");
3179 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3180 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3181 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3182 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3183 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3184 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3185 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3186 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3187 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003188 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3189 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3190 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02003191 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003192 assert_string_equal(parsed->actions->name, "act");
David Sedláke0ef1c62019-09-13 10:05:55 +02003193 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003194 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3195 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke2dc9e92019-07-24 09:59:21 +02003196 lysp_node_free(st->ctx, siblings);
3197 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3198 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02003199
3200 /* min subelems */
3201 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003202 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02003203 parsed = (struct lysp_node_container *)siblings;
3204 assert_string_equal(parsed->name, "cont-name");
3205 lysp_node_free(st->ctx, siblings);
3206 siblings = NULL;
3207
3208 st->finished_correctly = true;
3209}
3210
David Sedlák5379d392019-07-24 10:42:03 +02003211static void
3212test_case_elem(void **state)
3213{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003214 struct test_parser_yin_state *st = *state;
David Sedlák5379d392019-07-24 10:42:03 +02003215 const char *data;
3216 struct lysp_node *siblings = NULL;
3217 struct tree_node_meta node_meta = {NULL, &siblings};
3218 struct lysp_node_case *parsed = NULL;
3219
3220 /* max subelems */
3221 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3222 data = ELEMENT_WRAPPER_START
3223 "<case name=\"case-name\">"
3224 "<anydata name=\"anyd\"/>"
3225 "<anyxml name=\"anyx\"/>"
3226 "<container name=\"subcont\"/>"
3227 "<description><text>desc</text></description>"
3228 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003229 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3230 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02003231 "<list name=\"list\"/>"
3232 "<reference><text>ref</text></reference>"
3233 "<status value=\"current\"/>"
3234 "<uses name=\"uses-name\"/>"
3235 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003236 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003237 EXT_SUBELEM
David Sedlák5379d392019-07-24 10:42:03 +02003238 "</case>"
3239 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003240 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003241 parsed = (struct lysp_node_case *)siblings;
3242 assert_string_equal(parsed->name, "case-name");
3243 assert_null(parsed->parent);
3244 assert_int_equal(parsed->nodetype, LYS_CASE);
3245 assert_true(parsed->flags & LYS_STATUS_CURR);
3246 assert_null(parsed->next);
3247 assert_string_equal(parsed->dsc, "desc");
3248 assert_string_equal(parsed->ref, "ref");
3249 assert_string_equal(parsed->when->cond, "when-cond");
3250 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02003251 assert_string_equal(parsed->child->name, "anyd");
3252 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3253 assert_string_equal(parsed->child->next->name, "anyx");
3254 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3255 assert_string_equal(parsed->child->next->next->name, "subcont");
3256 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3257 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3258 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3259 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3260 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3261 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3262 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3263 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3264 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003265 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3266 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3267 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003268 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003269 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3270 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5379d392019-07-24 10:42:03 +02003271 lysp_node_free(st->ctx, siblings);
3272 siblings = NULL;
3273
3274 /* min subelems */
3275 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003276 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003277 parsed = (struct lysp_node_case *)siblings;
3278 assert_string_equal(parsed->name, "case-name");
3279 lysp_node_free(st->ctx, siblings);
3280 siblings = NULL;
3281
3282 st->finished_correctly = true;
3283}
3284
David Sedlákb7abcfa2019-07-24 12:33:35 +02003285static void
3286test_choice_elem(void **state)
3287{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003288 struct test_parser_yin_state *st = *state;
David Sedlákb7abcfa2019-07-24 12:33:35 +02003289 const char *data;
3290 struct lysp_node *siblings = NULL;
3291 struct tree_node_meta node_meta = {NULL, &siblings};
3292 struct lysp_node_choice *parsed = NULL;
3293
3294 /* max subelems */
3295 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3296 data = ELEMENT_WRAPPER_START
3297 "<choice name=\"choice-name\">"
3298 "<anydata name=\"anyd\"/>"
3299 "<anyxml name=\"anyx\"/>"
3300 "<case name=\"sub-case\"/>"
3301 "<choice name=\"choice\"/>"
3302 "<config value=\"true\"/>"
3303 "<container name=\"subcont\"/>"
3304 "<default value=\"def\"/>"
3305 "<description><text>desc</text></description>"
3306 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003307 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3308 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003309 "<list name=\"list\"/>"
3310 "<mandatory value=\"true\" />"
3311 "<reference><text>ref</text></reference>"
3312 "<status value=\"current\"/>"
3313 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003314 EXT_SUBELEM
David Sedlákb7abcfa2019-07-24 12:33:35 +02003315 "</choice>"
3316 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003317 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003318 parsed = (struct lysp_node_choice *)siblings;
3319 assert_string_equal(parsed->name, "choice-name");
3320 assert_null(parsed->parent);
3321 assert_int_equal(parsed->nodetype, LYS_CHOICE);
3322 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
3323 assert_null(parsed->next);
3324 assert_string_equal(parsed->dsc, "desc");
3325 assert_string_equal(parsed->ref, "ref");
3326 assert_string_equal(parsed->when->cond, "when-cond");
3327 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003328 assert_string_equal(parsed->child->name, "anyd");
3329 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3330 assert_string_equal(parsed->child->next->name, "anyx");
3331 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3332 assert_string_equal(parsed->child->next->next->name, "sub-case");
3333 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
3334 assert_string_equal(parsed->child->next->next->next->name, "choice");
3335 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
3336 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
3337 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
3338 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
3339 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
3340 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
3341 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3342 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
3343 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3344 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003345 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003346 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3347 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003348 lysp_node_free(st->ctx, siblings);
3349 siblings = NULL;
3350
3351 /* min subelems */
3352 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003353 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003354 parsed = (struct lysp_node_choice *)siblings;
3355 assert_string_equal(parsed->name, "choice-name");
3356 lysp_node_free(st->ctx, siblings);
3357 siblings = NULL;
3358
3359 st->finished_correctly = true;
3360}
3361
David Sedlák05404f62019-07-24 14:11:53 +02003362static void
3363test_inout_elem(void **state)
3364{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003365 struct test_parser_yin_state *st = *state;
David Sedlák05404f62019-07-24 14:11:53 +02003366 const char *data;
3367 struct lysp_action_inout inout = {};
3368 struct inout_meta inout_meta = {NULL, &inout};
3369
3370 /* max subelements */
3371 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3372 data = ELEMENT_WRAPPER_START
3373 "<input>"
3374 "<anydata name=\"anyd\"/>"
3375 "<anyxml name=\"anyx\"/>"
3376 "<choice name=\"choice\"/>"
3377 "<container name=\"subcont\"/>"
3378 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003379 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3380 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003381 "<list name=\"list\"/>"
3382 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003383 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003384 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003385 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003386 "</input>"
3387 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003388 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003389 assert_null(inout.parent);
3390 assert_int_equal(inout.nodetype, LYS_INPUT);
3391 assert_string_equal(inout.musts->arg, "cond");
3392 assert_string_equal(inout.typedefs->name, "tpdf");
3393 assert_string_equal(inout.groupings->name, "sub-grp");
3394 assert_string_equal(inout.data->name, "anyd");
3395 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3396 assert_string_equal(inout.data->next->name, "anyx");
3397 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3398 assert_string_equal(inout.data->next->next->name, "choice");
3399 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3400 assert_string_equal(inout.data->next->next->next->name, "subcont");
3401 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3402 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3403 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3404 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3405 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3406 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3407 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3408 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3409 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3410 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003411 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003412 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3413 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003414 lysp_action_inout_free(st->ctx, &inout);
3415 memset(&inout, 0, sizeof inout);
3416
3417 /* max subelements */
3418 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3419 data = ELEMENT_WRAPPER_START
3420 "<output>"
3421 "<anydata name=\"anyd\"/>"
3422 "<anyxml name=\"anyx\"/>"
3423 "<choice name=\"choice\"/>"
3424 "<container name=\"subcont\"/>"
3425 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003426 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3427 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003428 "<list name=\"list\"/>"
3429 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003430 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003431 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003432 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003433 "</output>"
3434 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003435 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003436 assert_null(inout.parent);
3437 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3438 assert_string_equal(inout.musts->arg, "cond");
3439 assert_string_equal(inout.typedefs->name, "tpdf");
3440 assert_string_equal(inout.groupings->name, "sub-grp");
3441 assert_string_equal(inout.data->name, "anyd");
3442 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3443 assert_string_equal(inout.data->next->name, "anyx");
3444 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3445 assert_string_equal(inout.data->next->next->name, "choice");
3446 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3447 assert_string_equal(inout.data->next->next->next->name, "subcont");
3448 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3449 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3450 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3451 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3452 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3453 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3454 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3455 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3456 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3457 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003458 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003459 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3460 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003461 lysp_action_inout_free(st->ctx, &inout);
3462 memset(&inout, 0, sizeof inout);
3463
3464 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003465 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003466 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003467 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003468 memset(&inout, 0, sizeof inout);
3469
Michal Vaskob83af8a2020-01-06 09:49:22 +01003470 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003471 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003472 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003473 memset(&inout, 0, sizeof inout);
3474
3475 /* invalid combinations */
3476 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003477 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02003478 logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003479 memset(&inout, 0, sizeof inout);
3480
3481 st->finished_correctly = true;
3482}
3483
David Sedlák85d0eca2019-07-24 15:15:21 +02003484static void
3485test_action_elem(void **state)
3486{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003487 struct test_parser_yin_state *st = *state;
David Sedlák85d0eca2019-07-24 15:15:21 +02003488 const char *data;
3489 struct lysp_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003490 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
David Sedlák85d0eca2019-07-24 15:15:21 +02003491
3492 /* max subelems */
3493 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3494 data = ELEMENT_WRAPPER_START
3495 "<action name=\"act\">"
3496 "<description><text>desc</text></description>"
3497 "<grouping name=\"grouping\"/>"
3498 "<if-feature name=\"iff\"/>"
3499 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003500 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003501 "<reference><text>ref</text></reference>"
3502 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003503 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003504 EXT_SUBELEM
David Sedlák85d0eca2019-07-24 15:15:21 +02003505 "</action>"
3506 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003507 /* there must be parent for action */
3508 act_meta.parent = NULL + 1;
Michal Vaskob36053d2020-03-26 15:49:30 +01003509 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003510 act_meta.parent = NULL;
3511 assert_non_null(actions->parent);
David Sedlák85d0eca2019-07-24 15:15:21 +02003512 assert_int_equal(actions->nodetype, LYS_ACTION);
3513 assert_true(actions->flags & LYS_STATUS_DEPRC);
3514 assert_string_equal(actions->name, "act");
3515 assert_string_equal(actions->dsc, "desc");
3516 assert_string_equal(actions->ref, "ref");
3517 assert_string_equal(*actions->iffeatures, "iff");
3518 assert_string_equal(actions->typedefs->name, "tpdf");
3519 assert_string_equal(actions->groupings->name, "grouping");
3520 assert_string_equal(actions->input.data->name, "uses-name");
3521 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003522 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003523 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3524 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák85d0eca2019-07-24 15:15:21 +02003525 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3526 actions = NULL;
3527
David Sedlákeaa45792019-07-24 15:25:01 +02003528 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3529 data = ELEMENT_WRAPPER_START
3530 "<rpc name=\"act\">"
3531 "<description><text>desc</text></description>"
3532 "<grouping name=\"grouping\"/>"
3533 "<if-feature name=\"iff\"/>"
3534 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003535 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlákeaa45792019-07-24 15:25:01 +02003536 "<reference><text>ref</text></reference>"
3537 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003538 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003539 EXT_SUBELEM
David Sedlákeaa45792019-07-24 15:25:01 +02003540 "</rpc>"
3541 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003542 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlákeaa45792019-07-24 15:25:01 +02003543 assert_null(actions->parent);
Michal Vasko1bf09392020-03-27 12:38:10 +01003544 assert_int_equal(actions->nodetype, LYS_RPC);
David Sedlákeaa45792019-07-24 15:25:01 +02003545 assert_true(actions->flags & LYS_STATUS_DEPRC);
3546 assert_string_equal(actions->name, "act");
3547 assert_string_equal(actions->dsc, "desc");
3548 assert_string_equal(actions->ref, "ref");
3549 assert_string_equal(*actions->iffeatures, "iff");
3550 assert_string_equal(actions->typedefs->name, "tpdf");
3551 assert_string_equal(actions->groupings->name, "grouping");
3552 assert_string_equal(actions->input.data->name, "uses-name");
3553 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003554 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003555 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3556 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákeaa45792019-07-24 15:25:01 +02003557 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3558 actions = NULL;
3559
David Sedlák85d0eca2019-07-24 15:15:21 +02003560 /* min subelems */
3561 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003562 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003563 assert_string_equal(actions->name, "act");
3564 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3565 actions = NULL;
3566
3567 st->finished_correctly = true;
3568}
3569
David Sedlák992fb7c2019-07-24 16:51:01 +02003570static void
3571test_augment_elem(void **state)
3572{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003573 struct test_parser_yin_state *st = *state;
David Sedlák992fb7c2019-07-24 16:51:01 +02003574 const char *data;
3575 struct lysp_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003576 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003577
3578 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3579 data = ELEMENT_WRAPPER_START
3580 "<augment target-node=\"target\">"
3581 "<action name=\"action\"/>"
3582 "<anydata name=\"anyd\"/>"
3583 "<anyxml name=\"anyx\"/>"
3584 "<case name=\"case\"/>"
3585 "<choice name=\"choice\"/>"
3586 "<container name=\"subcont\"/>"
3587 "<description><text>desc</text></description>"
3588 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003589 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3590 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003591 "<list name=\"list\"/>"
3592 "<notification name=\"notif\"/>"
3593 "<reference><text>ref</text></reference>"
3594 "<status value=\"current\"/>"
3595 "<uses name=\"uses\"/>"
3596 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003597 EXT_SUBELEM
David Sedlák992fb7c2019-07-24 16:51:01 +02003598 "</augment>"
3599 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003600 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003601 assert_string_equal(augments->nodeid, "target");
3602 assert_null(augments->parent);
3603 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3604 assert_true(augments->flags & LYS_STATUS_CURR);
3605 assert_string_equal(augments->dsc, "desc");
3606 assert_string_equal(augments->ref, "ref");
3607 assert_string_equal(augments->when->cond, "when-cond");
3608 assert_string_equal(*augments->iffeatures, "iff");
3609 assert_string_equal(augments->child->name, "anyd");
3610 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3611 assert_string_equal(augments->child->next->name, "anyx");
3612 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3613 assert_string_equal(augments->child->next->next->name, "case");
3614 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3615 assert_string_equal(augments->child->next->next->next->name, "choice");
3616 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3617 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3618 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3619 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3620 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3621 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3622 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3623 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3624 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3625 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3626 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3627 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3628 assert_string_equal(augments->actions->name, "action");
3629 assert_string_equal(augments->notifs->name, "notif");
David Sedláke0ef1c62019-09-13 10:05:55 +02003630 assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003631 assert_int_equal(augments->exts[0].insubstmt_index, 0);
3632 assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák992fb7c2019-07-24 16:51:01 +02003633 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3634 augments = NULL;
3635
3636 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003637 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003638 assert_string_equal(augments->nodeid, "target");
3639 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3640 augments = NULL;
3641
3642 st->finished_correctly = true;
3643}
3644
David Sedlák4ffcec82019-07-25 15:10:21 +02003645static void
3646test_deviate_elem(void **state)
3647{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003648 struct test_parser_yin_state *st = *state;
David Sedlák4ffcec82019-07-25 15:10:21 +02003649 const char *data;
3650 struct lysp_deviate *deviates = NULL;
3651 struct lysp_deviate_add *d_add;
3652 struct lysp_deviate_rpl *d_rpl;
3653 struct lysp_deviate_del *d_del;
3654
3655 /* all valid arguments with min subelems */
3656 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003657 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003658 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3659 lysp_deviate_free(st->ctx, deviates);
3660 free(deviates);
3661 deviates = NULL;
3662
3663 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003664 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003665 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3666 lysp_deviate_free(st->ctx, deviates);
3667 free(deviates);
3668 deviates = NULL;
3669
3670 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003671 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003672 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3673 lysp_deviate_free(st->ctx, deviates);
3674 free(deviates);
3675 deviates = NULL;
3676
3677 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003678 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003679 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3680 lysp_deviate_free(st->ctx, deviates);
3681 free(deviates);
3682 deviates = NULL;
3683
3684 /* max subelems and valid arguments */
3685 data = ELEMENT_WRAPPER_START
3686 "<deviate value=\"not-supported\">"
David Sedlákd1144562019-08-06 12:36:14 +02003687 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003688 "</deviate>"
3689 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003690 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003691 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
David Sedláke0ef1c62019-09-13 10:05:55 +02003692 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003693 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3694 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003695 lysp_deviate_free(st->ctx, deviates);
3696 free(deviates);
3697 deviates = NULL;
3698
3699 data = ELEMENT_WRAPPER_START
3700 "<deviate value=\"add\">"
3701 "<units name=\"units\"/>"
3702 "<must condition=\"cond\"/>"
3703 "<unique tag=\"utag\"/>"
3704 "<default value=\"def\"/>"
3705 "<config value=\"true\"/>"
3706 "<mandatory value=\"true\"/>"
3707 "<min-elements value=\"5\"/>"
3708 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003709 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003710 "</deviate>"
3711 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003712 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003713 d_add = (struct lysp_deviate_add *)deviates;
3714 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3715 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003716 assert_string_equal(d_add->units, "units");
3717 assert_string_equal(d_add->musts->arg, "cond");
3718 assert_string_equal(*d_add->uniques, "utag");
3719 assert_string_equal(*d_add->dflts, "def");
3720 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3721 assert_int_equal(d_add->min, 5);
3722 assert_int_equal(d_add->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003723 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003724 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3725 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003726 lysp_deviate_free(st->ctx, deviates);
3727 free(deviates);
3728 deviates = NULL;
3729
3730 data = ELEMENT_WRAPPER_START
3731 "<deviate value=\"replace\">"
3732 "<type name=\"newtype\"/>"
3733 "<units name=\"uni\"/>"
3734 "<default value=\"def\"/>"
3735 "<config value=\"true\"/>"
3736 "<mandatory value=\"true\"/>"
3737 "<min-elements value=\"5\"/>"
3738 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003739 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003740 "</deviate>"
3741 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003742 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003743 d_rpl = (struct lysp_deviate_rpl *)deviates;
3744 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3745 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003746 assert_string_equal(d_rpl->type->name, "newtype");
3747 assert_string_equal(d_rpl->units, "uni");
3748 assert_string_equal(d_rpl->dflt, "def");
3749 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3750 assert_int_equal(d_rpl->min, 5);
3751 assert_int_equal(d_rpl->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003752 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003753 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3754 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003755 lysp_deviate_free(st->ctx, deviates);
3756 free(deviates);
3757 deviates = NULL;
3758
3759 data = ELEMENT_WRAPPER_START
3760 "<deviate value=\"delete\">"
3761 "<units name=\"u\"/>"
3762 "<must condition=\"c\"/>"
3763 "<unique tag=\"tag\"/>"
3764 "<default value=\"default\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003765 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003766 "</deviate>"
3767 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003768 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003769 d_del = (struct lysp_deviate_del *)deviates;
3770 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3771 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003772 assert_string_equal(d_del->units, "u");
3773 assert_string_equal(d_del->musts->arg, "c");
3774 assert_string_equal(*d_del->uniques, "tag");
3775 assert_string_equal(*d_del->dflts, "default");
David Sedláke0ef1c62019-09-13 10:05:55 +02003776 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003777 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3778 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003779 lysp_deviate_free(st->ctx, deviates);
3780 free(deviates);
3781 deviates = NULL;
3782
3783 /* invalid arguments */
3784 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003785 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003786 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 +02003787 deviates = NULL;
3788
3789 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003790 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003791 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 +02003792 deviates = NULL;
3793
3794 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003795 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003796 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 +02003797 deviates = NULL;
3798
3799 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003800 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003801 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 +02003802 deviates = NULL;
3803
3804 data = ELEMENT_WRAPPER_START
3805 "<deviate value=\"not-supported\">"
3806 "<must condition=\"c\"/>"
3807 "</deviate>"
3808 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003809 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák4ffcec82019-07-25 15:10:21 +02003810 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3811
3812 st->finished_correctly = true;
3813}
3814
David Sedlák8b754462019-07-25 16:22:13 +02003815static void
3816test_deviation_elem(void **state)
3817{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003818 struct test_parser_yin_state *st = *state;
David Sedlák8b754462019-07-25 16:22:13 +02003819 const char *data;
3820 struct lysp_deviation *deviations = NULL;
3821
3822 /* min subelems */
3823 data = ELEMENT_WRAPPER_START
3824 "<deviation target-node=\"target\">"
3825 "<deviate value=\"not-supported\"/>"
3826 "</deviation>"
3827 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003828 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003829 assert_string_equal(deviations->nodeid, "target");
3830 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3831 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3832 deviations = NULL;
3833
3834 /* max subelems */
3835 data = ELEMENT_WRAPPER_START
3836 "<deviation target-node=\"target\">"
3837 "<reference><text>ref</text></reference>"
3838 "<description><text>desc</text></description>"
3839 "<deviate value=\"add\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003840 EXT_SUBELEM
David Sedlák8b754462019-07-25 16:22:13 +02003841 "</deviation>"
3842 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003843 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003844 assert_string_equal(deviations->nodeid, "target");
3845 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3846 assert_string_equal(deviations->ref, "ref");
3847 assert_string_equal(deviations->dsc, "desc");
David Sedláke0ef1c62019-09-13 10:05:55 +02003848 assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003849 assert_int_equal(deviations->exts[0].insubstmt_index, 0);
3850 assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8b754462019-07-25 16:22:13 +02003851 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3852 deviations = NULL;
3853
3854 /* invalid */
3855 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003856 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID);
David Sedlák8b754462019-07-25 16:22:13 +02003857 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3858 deviations = NULL;
David Sedlák1538a842019-08-08 15:38:51 +02003859 logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
3860 /* TODO */
David Sedlák8b754462019-07-25 16:22:13 +02003861 st->finished_correctly = true;
3862}
3863
David Sedlák4f03b932019-07-26 13:01:47 +02003864static void
3865test_module_elem(void **state)
3866{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003867 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01003868 const char *data;
David Sedlák4f03b932019-07-26 13:01:47 +02003869 struct lys_module *lys_mod = NULL;
3870 struct lysp_module *lysp_mod = NULL;
3871
3872 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003873 lys_mod = calloc(1, sizeof *lys_mod);
3874 lysp_mod = calloc(1, sizeof *lysp_mod);
3875 lys_mod->ctx = st->ctx;
3876 lysp_mod->mod = lys_mod;
3877 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3878 "<yang-version value=\"1.1\"/>\n"
3879 "<namespace uri=\"ns\"/>\n"
3880 "<prefix value=\"pref\"/>\n"
3881 "<include module=\"b-mod\"/>\n"
3882 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3883 "<organization><text>org</text></organization>\n"
3884 "<contact><text>contact</text></contact>\n"
3885 "<description><text>desc</text></description>"
3886 "<reference><text>ref</text></reference>\n"
3887 "<revision date=\"2019-02-02\"/>\n"
3888 "<anydata name=\"anyd\"/>\n"
3889 "<anyxml name=\"anyx\"/>\n"
3890 "<choice name=\"choice\"/>\n"
3891 "<container name=\"cont\"/>\n"
3892 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3893 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3894 "<list name=\"sub-list\"/>\n"
3895 "<uses name=\"uses-name\"/>\n"
3896 "<augment target-node=\"target\"/>\n"
3897 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3898 "<extension name=\"ext\"/>\n"
3899 "<feature name=\"feature\"/>\n"
3900 "<grouping name=\"grp\"/>\n"
3901 "<identity name=\"ident-name\"/>\n"
3902 "<notification name=\"notf\"/>\n"
3903 "<rpc name=\"rpc-name\"/>\n"
3904 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02003905 EXT_SUBELEM"\n"
David Sedlák4f03b932019-07-26 13:01:47 +02003906 "</module>\n";
Michal Vaskob36053d2020-03-26 15:49:30 +01003907 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3908
3909 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003910 assert_string_equal(lysp_mod->mod->name, "mod");
3911 assert_string_equal(lysp_mod->revs, "2019-02-02");
3912 assert_string_equal(lysp_mod->mod->ns, "ns");
3913 assert_string_equal(lysp_mod->mod->prefix, "pref");
3914 assert_null(lysp_mod->mod->filepath);
3915 assert_string_equal(lysp_mod->mod->org, "org");
3916 assert_string_equal(lysp_mod->mod->contact, "contact");
3917 assert_string_equal(lysp_mod->mod->dsc, "desc");
3918 assert_string_equal(lysp_mod->mod->ref, "ref");
3919 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
3920 assert_string_equal(lysp_mod->imports->name, "a-mod");
3921 assert_string_equal(lysp_mod->includes->name, "b-mod");
3922 assert_string_equal(lysp_mod->extensions->name, "ext");
3923 assert_string_equal(lysp_mod->features->name, "feature");
3924 assert_string_equal(lysp_mod->identities->name, "ident-name");
3925 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3926 assert_string_equal(lysp_mod->groupings->name, "grp");
3927 assert_string_equal(lysp_mod->data->name, "anyd");
3928 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3929 assert_string_equal(lysp_mod->data->next->name, "anyx");
3930 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3931 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3932 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3933 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3934 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3935 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3936 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3937 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3938 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3939 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3940 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3941 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3942 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3943 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3944 assert_string_equal(lysp_mod->augments->nodeid, "target");
3945 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3946 assert_string_equal(lysp_mod->notifs->name, "notf");
3947 assert_string_equal(lysp_mod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02003948 assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003949 assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
3950 assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4f03b932019-07-26 13:01:47 +02003951 lysp_module_free(lysp_mod);
3952 lys_module_free(lys_mod, NULL);
David Sedlák4f03b932019-07-26 13:01:47 +02003953
3954 /* min subelems */
Michal Vaskob36053d2020-03-26 15:49:30 +01003955 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák4f03b932019-07-26 13:01:47 +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 "<namespace uri=\"ns\"/>"
3962 "<prefix value=\"pref\"/>"
3963 "<yang-version value=\"1.1\"/>"
3964 "</module>";
Michal Vaskob36053d2020-03-26 15:49:30 +01003965 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3966 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003967 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák4f03b932019-07-26 13:01:47 +02003968 lysp_module_free(lysp_mod);
3969 lys_module_free(lys_mod, NULL);
David Sedlák298ff6d2019-07-26 14:29:03 +02003970
David Sedláke6cd89e2019-08-07 12:46:02 +02003971 /* incorrect subelem order */
Michal Vaskob36053d2020-03-26 15:49:30 +01003972 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02003973 lys_mod = calloc(1, sizeof *lys_mod);
3974 lysp_mod = calloc(1, sizeof *lysp_mod);
3975 lys_mod->ctx = st->ctx;
3976 lysp_mod->mod = lys_mod;
3977 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
3978 "<feature name=\"feature\"/>\n"
3979 "<namespace uri=\"ns\"/>"
3980 "<prefix value=\"pref\"/>"
3981 "<yang-version value=\"1.1\"/>"
3982 "</module>";
Michal Vaskob36053d2020-03-26 15:49:30 +01003983 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
3984 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
3985 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 +02003986 lysp_module_free(lysp_mod);
3987 lys_module_free(lys_mod, NULL);
David Sedláke6cd89e2019-08-07 12:46:02 +02003988
David Sedlák298ff6d2019-07-26 14:29:03 +02003989 st->finished_correctly = true;
3990}
3991
3992static void
3993test_submodule_elem(void **state)
3994{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003995 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01003996 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02003997 struct lysp_submodule *lysp_submod = NULL;
3998
3999 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02004000 lysp_submod = calloc(1, sizeof *lysp_submod);
4001 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
4002 "<yang-version value=\"1.1\"/>\n"
4003 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4004 "<include module=\"b-mod\"/>\n"
4005 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
4006 "<organization><text>org</text></organization>\n"
4007 "<contact><text>contact</text></contact>\n"
4008 "<description><text>desc</text></description>"
4009 "<reference><text>ref</text></reference>\n"
4010 "<revision date=\"2019-02-02\"/>\n"
4011 "<anydata name=\"anyd\"/>\n"
4012 "<anyxml name=\"anyx\"/>\n"
4013 "<choice name=\"choice\"/>\n"
4014 "<container name=\"cont\"/>\n"
4015 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
4016 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
4017 "<list name=\"sub-list\"/>\n"
4018 "<uses name=\"uses-name\"/>\n"
4019 "<augment target-node=\"target\"/>\n"
4020 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
4021 "<extension name=\"ext\"/>\n"
4022 "<feature name=\"feature\"/>\n"
4023 "<grouping name=\"grp\"/>\n"
4024 "<identity name=\"ident-name\"/>\n"
4025 "<notification name=\"notf\"/>\n"
4026 "<rpc name=\"rpc-name\"/>\n"
4027 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004028 EXT_SUBELEM"\n"
David Sedlák298ff6d2019-07-26 14:29:03 +02004029 "</submodule>\n";
Michal Vaskob36053d2020-03-26 15:49:30 +01004030 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4031 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004032
4033 assert_string_equal(lysp_submod->name, "mod");
4034 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02004035 assert_string_equal(lysp_submod->prefix, "pref");
4036 assert_null(lysp_submod->filepath);
4037 assert_string_equal(lysp_submod->org, "org");
4038 assert_string_equal(lysp_submod->contact, "contact");
4039 assert_string_equal(lysp_submod->dsc, "desc");
4040 assert_string_equal(lysp_submod->ref, "ref");
4041 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
4042 assert_string_equal(lysp_submod->imports->name, "a-mod");
4043 assert_string_equal(lysp_submod->includes->name, "b-mod");
4044 assert_string_equal(lysp_submod->extensions->name, "ext");
4045 assert_string_equal(lysp_submod->features->name, "feature");
4046 assert_string_equal(lysp_submod->identities->name, "ident-name");
4047 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
4048 assert_string_equal(lysp_submod->groupings->name, "grp");
4049 assert_string_equal(lysp_submod->data->name, "anyd");
4050 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
4051 assert_string_equal(lysp_submod->data->next->name, "anyx");
4052 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
4053 assert_string_equal(lysp_submod->data->next->next->name, "choice");
4054 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
4055 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
4056 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
4057 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
4058 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
4059 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
4060 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4061 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
4062 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4063 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
4064 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4065 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
4066 assert_string_equal(lysp_submod->augments->nodeid, "target");
4067 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
4068 assert_string_equal(lysp_submod->notifs->name, "notf");
4069 assert_string_equal(lysp_submod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004070 assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004071 assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
4072 assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák298ff6d2019-07-26 14:29:03 +02004073
4074 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004075
4076 /* min subelemnts */
Michal Vaskob36053d2020-03-26 15:49:30 +01004077 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák298ff6d2019-07-26 14:29:03 +02004078 lysp_submod = calloc(1, sizeof *lysp_submod);
4079 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4080 "<yang-version value=\"1.0\"/>"
4081 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4082 "</submodule>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004083 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4084 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004085 assert_string_equal(lysp_submod->prefix, "pref");
4086 assert_string_equal(lysp_submod->belongsto, "mod-name");
4087 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
4088 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004089
David Sedláke6cd89e2019-08-07 12:46:02 +02004090 /* incorrect subelem order */
Michal Vaskob36053d2020-03-26 15:49:30 +01004091 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02004092 lysp_submod = calloc(1, sizeof *lysp_submod);
4093 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4094 "<yang-version value=\"1.0\"/>"
4095 "<reference><text>ref</text></reference>\n"
4096 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4097 "</submodule>";
Michal Vaskob36053d2020-03-26 15:49:30 +01004098 assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
4099 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
4100 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 +02004101 lysp_submodule_free(st->ctx, lysp_submod);
David Sedláke6cd89e2019-08-07 12:46:02 +02004102
David Sedlák298ff6d2019-07-26 14:29:03 +02004103 st->finished_correctly = true;
David Sedlák4f03b932019-07-26 13:01:47 +02004104}
4105
David Sedlák8985a142019-07-31 16:43:06 +02004106static void
4107test_yin_parse_module(void **state)
4108{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004109 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +02004110 const char *data;
4111 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01004112 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004113
4114 mod = calloc(1, sizeof *mod);
4115 mod->ctx = st->ctx;
David Sedlákd2844882019-09-13 16:01:22 +02004116 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"
4117 "<yang-version value=\"1.1\"/>\n"
4118 "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
4119 "<prefix value=\"a\"/>\n"
4120 "<import module=\"ietf-yang-metadata\">\n"
4121 "<prefix value=\"md\"/>\n"
4122 "</import>\n"
4123 "<feature name=\"f\"/>\n"
4124 "<md:annotation name=\"x\">\n"
4125 "<description>\n"
4126 "<text>test</text>\n"
4127 "</description>\n"
4128 "<reference>\n"
4129 "<text>test</text>\n"
4130 "</reference>\n"
4131 "<if-feature name=\"f\"/>\n"
4132 "<status value=\"current\"/>\n"
4133 "<type name=\"uint8\"/>\n"
4134 "<units name=\"meters\"/>\n"
4135 "</md:annotation>\n"
4136 "</module>\n";
4137 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4138 assert_null(mod->parsed->exts->child->next->child);
4139 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
4140 lys_module_free(mod, NULL);
4141 yin_parser_ctx_free(yin_ctx);
4142 mod = NULL;
4143 yin_ctx = NULL;
4144
4145 mod = calloc(1, sizeof *mod);
4146 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004147 data = "<module name=\"example-foo\""
4148 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4149 "xmlns:foo=\"urn:example:foo\""
4150 "xmlns:myext=\"urn:example:extensions\">\n"
4151
4152 "<yang-version value=\"1.0\"/>\n"
4153
4154 "<namespace uri=\"urn:example:foo\"/>\n"
4155 "<prefix value=\"foo\"/>\n"
4156
4157 "<import module=\"example-extensions\">\n"
David Sedlák6d781b62019-08-02 15:22:52 +02004158 "<prefix value=\"myext\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02004159 "</import>\n"
4160
4161 "<list name=\"interface\">\n"
4162 "<key value=\"name\"/>\n"
4163 "<leaf name=\"name\">\n"
4164 "<type name=\"string\"/>\n"
4165 "</leaf>\n"
4166 "<leaf name=\"mtu\">\n"
4167 "<type name=\"uint32\"/>\n"
4168 "<description>\n"
4169 "<text>The MTU of the interface.</text>\n"
4170 "</description>\n"
4171 "<myext:c-define name=\"MY_MTU\"/>\n"
4172 "</leaf>\n"
4173 "</list>\n"
4174 "</module>\n";
4175 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4176 lys_module_free(mod, NULL);
4177 yin_parser_ctx_free(yin_ctx);
4178 mod = NULL;
4179 yin_ctx = NULL;
4180
4181 mod = calloc(1, sizeof *mod);
4182 mod->ctx = st->ctx;
David Sedlák6d781b62019-08-02 15:22:52 +02004183 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4184 "<yang-version value=\"1.0\"/>\n"
4185 "<namespace uri=\"urn:example:foo\"/>\n"
4186 "<prefix value=\"foo\"/>\n"
4187 "</module>\n";
4188 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
4189 lys_module_free(mod, NULL);
4190 yin_parser_ctx_free(yin_ctx);
4191 mod = NULL;
4192 yin_ctx = NULL;
4193
4194
4195 mod = calloc(1, sizeof *mod);
4196 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004197 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4198 "</submodule>\n";
4199 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL);
4200 logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
4201 lys_module_free(mod, NULL);
4202 yin_parser_ctx_free(yin_ctx);
4203
David Sedlák6d781b62019-08-02 15:22:52 +02004204 mod = calloc(1, sizeof *mod);
4205 mod->ctx = st->ctx;
4206 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4207 "<yang-version value=\"1.0\"/>\n"
4208 "<namespace uri=\"urn:example:foo\"/>\n"
4209 "<prefix value=\"foo\"/>\n"
4210 "</module>"
4211 "<module>";
4212 assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID);
4213 logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
4214 lys_module_free(mod, NULL);
4215 yin_parser_ctx_free(yin_ctx);
4216 mod = NULL;
4217 yin_ctx = NULL;
4218
David Sedlák8985a142019-07-31 16:43:06 +02004219 st->finished_correctly = true;
4220}
4221
4222static void
4223test_yin_parse_submodule(void **state)
4224{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004225 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +02004226 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01004227 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004228 struct lysp_submodule *submod = NULL;
David Sedlák1b623122019-08-05 15:27:49 +02004229 struct lys_parser_ctx main_ctx = {};
David Sedlák8985a142019-07-31 16:43:06 +02004230
4231 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4232 "<submodule name=\"asub\""
4233 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4234 "xmlns:a=\"urn:a\">"
4235 "<yang-version value=\"1.0\"/>\n"
4236 "<belongs-to module=\"a\">"
4237 "<prefix value=\"a_pref\"/>"
4238 "</belongs-to>"
4239 "<include module=\"atop\"/>"
4240 "<feature name=\"fox\"/>"
4241 "<notification name=\"bar-notif\">"
4242 "<if-feature name=\"bar\"/>"
4243 "</notification>"
4244 "<notification name=\"fox-notif\">"
4245 "<if-feature name=\"fox\"/>"
4246 "</notification>"
4247 "<augment target-node=\"/a_pref:top\">"
4248 "<if-feature name=\"bar\"/>"
4249 "<container name=\"bar-sub\"/>"
4250 "</augment>"
4251 "<augment target-node=\"/top\">"
4252 "<container name=\"bar-sub2\"/>"
4253 "</augment>"
4254 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004255 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004256 lysp_submodule_free(st->ctx, submod);
4257 yin_parser_ctx_free(yin_ctx);
4258 yin_ctx = NULL;
4259 submod = NULL;
4260
4261 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák6d781b62019-08-02 15:22:52 +02004262 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4263 "<yang-version value=\"1.0\"/>\n"
4264 "<belongs-to module=\"a\">"
4265 "<prefix value=\"a_pref\"/>"
4266 "</belongs-to>"
4267 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004268 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004269 lysp_submodule_free(st->ctx, submod);
4270 yin_parser_ctx_free(yin_ctx);
4271 yin_ctx = NULL;
4272 submod = NULL;
4273
4274 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák8985a142019-07-31 16:43:06 +02004275 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4276 "</module>";
David Sedlák1b623122019-08-05 15:27:49 +02004277 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004278 logbuf_assert("Input data contains module in situation when a submodule is expected.");
4279 lysp_submodule_free(st->ctx, submod);
4280 yin_parser_ctx_free(yin_ctx);
4281 yin_ctx = NULL;
4282 submod = NULL;
4283
David Sedlák6d781b62019-08-02 15:22:52 +02004284 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4285 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4286 "<yang-version value=\"1.0\"/>\n"
4287 "<belongs-to module=\"a\">"
4288 "<prefix value=\"a_pref\"/>"
4289 "</belongs-to>"
4290 "</submodule>"
4291 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4292 "<yang-version value=\"1.0\"/>\n"
4293 "<belongs-to module=\"a\">"
4294 "<prefix value=\"a_pref\"/>"
4295 "</belongs-to>"
4296 "</submodule>";
David Sedlák1b623122019-08-05 15:27:49 +02004297 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004298 logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
4299 lysp_submodule_free(st->ctx, submod);
4300 yin_parser_ctx_free(yin_ctx);
4301 yin_ctx = NULL;
4302 submod = NULL;
4303
David Sedlák8985a142019-07-31 16:43:06 +02004304 st->finished_correctly = true;
4305}
4306
David Sedlák3b4db242018-10-19 16:11:01 +02004307int
4308main(void)
4309{
4310
4311 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02004312 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02004313 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
4314 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák071f7662019-09-12 02:02:51 +02004315 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02004316 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02004317
David Sedlák8e7bda82019-07-16 17:57:50 +02004318 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák43801c92019-08-05 15:58:54 +02004319 cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test),
4320 cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test),
David Sedlák32488102019-07-15 17:44:10 +02004321 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
4322 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
4323 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
4324 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
4325 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
4326 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
4327 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004328 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
4329 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
4330 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
4331 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
4332 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
4333 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
4334 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
4335 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
4336 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
4337 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
4338 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
4339 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
4340 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
4341 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
4342 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02004343 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
4344 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
4345 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
4346 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
4347 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
4348 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
4349 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
4350 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02004351 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02004352 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02004353 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02004354 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02004355 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02004356 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02004357 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02004358 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02004359 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02004360 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02004361 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02004362 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02004363 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02004364 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02004365 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02004366 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02004367 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02004368 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02004369 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02004370 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02004371 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02004372 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02004373 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02004374 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02004375 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02004376 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák298ff6d2019-07-26 14:29:03 +02004377 cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test),
David Sedlák8985a142019-07-31 16:43:06 +02004378
4379 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger),
4380 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger),
David Sedlák3b4db242018-10-19 16:11:01 +02004381 };
4382
David Sedlák8e7bda82019-07-16 17:57:50 +02004383 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02004384}