blob: 201de0d5563c4111157065ced215a043d75c281c [file] [log] [blame]
David Sedlákb1ce3f82019-06-05 14:37:26 +02001/**
2 * @file test_parser_yin.c
3 * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
4 * @brief unit tests for functions from parser_yin.c
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
David Sedlák3b4db242018-10-19 16:11:01 +020015#include <stdarg.h>
16#include <stddef.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20#include <stdio.h>
21#include <string.h>
David Sedlák79e50cb2019-06-05 16:33:09 +020022#include <stdbool.h>
David Sedlák3b4db242018-10-19 16:11:01 +020023
Radek Krejci70593c12020-06-13 20:48:09 +020024#include "common.h"
25#include "parser_internal.h"
26#include "parser_yin.h"
27#include "tree_schema.h"
28#include "tree_schema_internal.h"
29#include "xml.h"
30#include "xpath.h"
David Sedlák3b4db242018-10-19 16:11:01 +020031
David Sedlák555c7202019-07-04 12:14:12 +020032/* prototypes of static functions */
33void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +020034void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +020035void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +020036void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +020037void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +020038void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +020039void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +020040void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +020041void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +020042void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +020043void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
David Sedlák031b9e72019-07-23 15:19:37 +020044void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
David Sedláke3ce9ef2019-07-23 16:34:30 +020045void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
David Sedlák05404f62019-07-24 14:11:53 +020046void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
David Sedlák85d0eca2019-07-24 15:15:21 +020047void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
David Sedlák992fb7c2019-07-24 16:51:01 +020048void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +020049void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +020050void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +020051void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod);
52void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +020053
David Sedláke6cd89e2019-08-07 12:46:02 +020054/* wrapping element used for mocking has nothing to do with real module structure */
55#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
56#define ELEMENT_WRAPPER_END "</status>"
57
Radek Krejci3a4889a2020-05-19 17:01:58 +020058struct test_parser_yin_state {
David Sedlák3b4db242018-10-19 16:11:01 +020059 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010060 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020061 struct lysp_module *lysp_mod;
Michal Vaskob36053d2020-03-26 15:49:30 +010062 struct lys_yin_parser_ctx *yin_ctx;
Michal Vasko63f3d842020-07-08 10:10:14 +020063 struct ly_in *in;
David Sedlák79e50cb2019-06-05 16:33:09 +020064 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010065};
David Sedlák872c7b42018-10-26 13:15:20 +020066
David Sedlák79e50cb2019-06-05 16:33:09 +020067#define BUFSIZE 1024
68char logbuf[BUFSIZE] = {0};
69int store = -1; /* negative for infinite logging, positive for limited logging */
70
71/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedláke0ef1c62019-09-13 10:05:55 +020072#define ENABLE_LOGGER_CHECKING 1
David Sedlák79e50cb2019-06-05 16:33:09 +020073
74#if ENABLE_LOGGER_CHECKING
75static void
76logger(LY_LOG_LEVEL level, const char *msg, const char *path)
77{
78 (void) level; /* unused */
79 if (store) {
80 if (path && path[0]) {
81 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
82 } else {
83 strncpy(logbuf, msg, BUFSIZE - 1);
84 }
85 if (store > 0) {
86 --store;
87 }
88 }
89}
90#endif
91
92#if ENABLE_LOGGER_CHECKING
93# define logbuf_assert(str) assert_string_equal(logbuf, str)
94#else
95# define logbuf_assert(str)
96#endif
97
98#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
99 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
100 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
101 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
102 CLEANUP
103
David Sedlák8e7bda82019-07-16 17:57:50 +0200104int
105setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100106{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200107 struct test_parser_yin_state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +0200108
David Sedlák68a1af12019-03-08 13:46:54 +0100109 /* allocate state variable */
110 (*state) = st = calloc(1, sizeof(*st));
111 if (!st) {
112 fprintf(stderr, "Memmory allocation failed");
113 return EXIT_FAILURE;
114 }
David Sedlák872c7b42018-10-26 13:15:20 +0200115
David Sedlák68a1af12019-03-08 13:46:54 +0100116 /* create new libyang context */
117 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200118
David Sedlák8e7bda82019-07-16 17:57:50 +0200119 return EXIT_SUCCESS;
120}
121
122int
123destroy_ly_ctx(void **state)
124{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200125 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +0200126 ly_ctx_destroy(st->ctx, NULL);
127 free(st);
128
129 return EXIT_SUCCESS;
130}
131
132static int
133setup_f(void **state)
134{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200135 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +0200136
137#if ENABLE_LOGGER_CHECKING
138 /* setup logger */
139 ly_set_log_clb(logger, 1);
140#endif
141
David Sedlák68a1af12019-03-08 13:46:54 +0100142 /* allocate new module */
143 st->mod = calloc(1, sizeof(*st->mod));
144 st->mod->ctx = st->ctx;
145
David Sedlák619db942019-07-03 14:47:30 +0200146 /* allocate new parsed module */
147 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
148 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
149 st->lysp_mod->mod->ctx = st->ctx;
150
151 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200152 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100153 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8f5bce02019-06-03 16:41:08 +0200154
Michal Vasko63f3d842020-07-08 10:10:14 +0200155 st->in = NULL;
156
David Sedlák68a1af12019-03-08 13:46:54 +0100157 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200158}
159
160static int
David Sedlák68a1af12019-03-08 13:46:54 +0100161teardown_f(void **state)
162{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200163 struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200164 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100165
David Sedlák79e50cb2019-06-05 16:33:09 +0200166#if ENABLE_LOGGER_CHECKING
167 /* teardown logger */
168 if (!st->finished_correctly && logbuf[0] != '\0') {
169 fprintf(stderr, "%s\n", logbuf);
170 }
171#endif
172
David Sedlák619db942019-07-03 14:47:30 +0200173 temp = st->lysp_mod->mod;
174
Michal Vaskob36053d2020-03-26 15:49:30 +0100175 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100176 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200177 lysp_module_free(st->lysp_mod);
178 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200179 free(st->yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +0200180 ly_in_free(st->in, 0);
David Sedlák68a1af12019-03-08 13:46:54 +0100181
182 return EXIT_SUCCESS;
183}
184
Radek Krejci3a4889a2020-05-19 17:01:58 +0200185static struct test_parser_yin_state*
David Sedlák392af4f2019-06-04 16:02:42 +0200186reset_state(void **state)
187{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200188 ((struct test_parser_yin_state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200189 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200190 teardown_f(state);
191 setup_f(state);
192
193 return *state;
194}
195
David Sedlák79e50cb2019-06-05 16:33:09 +0200196void
197logbuf_clean(void)
198{
199 logbuf[0] = '\0';
200}
201
David Sedlák8985a142019-07-31 16:43:06 +0200202static int
203setup_logger(void **state)
204{
205 (void)state; /* unused */
206#if ENABLE_LOGGER_CHECKING
207 /* setup logger */
208 ly_set_log_clb(logger, 1);
209#endif
210
211 logbuf[0] = '\0';
212
213 return EXIT_SUCCESS;
214}
215
216static int
217teardown_logger(void **state)
218{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200219 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +0200220
221#if ENABLE_LOGGER_CHECKING
222 /* teardown logger */
223 if (!st->finished_correctly && logbuf[0] != '\0') {
224 fprintf(stderr, "%s\n", logbuf);
225 }
226#endif
227
228 return EXIT_SUCCESS;
229}
230
231static int
232setup_element_test(void **state)
233{
234 setup_logger(state);
Radek Krejci3a4889a2020-05-19 17:01:58 +0200235 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +0200236
237 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
Michal Vaskob36053d2020-03-26 15:49:30 +0100238 st->yin_ctx->format = LYS_IN_YIN;
David Sedlák8985a142019-07-31 16:43:06 +0200239
240 return EXIT_SUCCESS;
241}
242
243static int
244teardown_element_test(void **state)
245{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200246 struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
David Sedlák8985a142019-07-31 16:43:06 +0200247
Michal Vaskob36053d2020-03-26 15:49:30 +0100248 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák8985a142019-07-31 16:43:06 +0200249 free(st->yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +0200250 ly_in_free(st->in, 0);
David Sedlák8985a142019-07-31 16:43:06 +0200251
252 teardown_logger(state);
253
254 return EXIT_SUCCESS;
255}
256
David Sedlák68a1af12019-03-08 13:46:54 +0100257static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200258test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200259{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200260 struct test_parser_yin_state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200261
Michal Vaskob36053d2020-03-26 15:49:30 +0100262 const char *prefix;
263 size_t prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200264 /* create mock yin namespace in xml context */
265 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
Michal Vasko63f3d842020-07-08 10:10:14 +0200266 ly_in_new_memory(data, &st->in);
267 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100268 prefix = st->yin_ctx->xmlctx->prefix;
269 prefix_len = st->yin_ctx->xmlctx->prefix_len;
David Sedlák8f7a1172019-06-20 14:42:18 +0200270
Radek Krejcid6b76452019-09-03 17:03:03 +0200271 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
275 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
276 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
277 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
278 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
279 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
280 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
281 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
282 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
283 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
284 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
285 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
286 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
287 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
288 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
289 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
290 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
291 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);
292 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
293 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
294 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
295 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
296 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
297 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
298 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
299 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
300 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
301 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
302 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
303 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
304 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
305 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
306 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
307 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
308 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
309 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
310 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
311 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
312 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
313 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
314 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
315 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
316 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
317 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
318 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
319 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
320 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
321 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
322 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
323 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
324 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
325 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
326 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
327 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
328 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
329 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
330 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
331 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
332 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
333 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
334 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
335 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
336 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
337 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
338 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
339 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
340 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 +0200341
342 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200343}
David Sedlák3b4db242018-10-19 16:11:01 +0200344
David Sedlák872c7b42018-10-26 13:15:20 +0200345static void
David Sedlák060b00e2019-06-19 11:12:06 +0200346test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200347{
David Sedlák68a1af12019-03-08 13:46:54 +0100348 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200349
David Sedlák060b00e2019-06-19 11:12:06 +0200350 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
351 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
352 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
353 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
354 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
355 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
356 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
357 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
358 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
359 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
360 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
361 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200362}
363
David Sedlák68a1af12019-03-08 13:46:54 +0100364static void
David Sedlákb1a78352019-06-28 16:16:29 +0200365test_yin_parse_element_generic(void **state)
366{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200367 struct test_parser_yin_state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200368 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200369 LY_ERR ret;
370
371 memset(&exts, 0, sizeof(exts));
372
David Sedlákb0ca07d2019-09-11 11:54:05 +0200373 const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
Michal Vasko63f3d842020-07-08 10:10:14 +0200374 ly_in_new_memory(data, &st->in);
375 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100376
377 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200378 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100379 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200380 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlákb1a78352019-06-28 16:16:29 +0200381 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200382 assert_string_equal(exts.child->child->stmt, "attr");
383 assert_string_equal(exts.child->child->arg, "value");
384 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200385 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200386 st = reset_state(state);
387
David Sedlákb0ca07d2019-09-11 11:54:05 +0200388 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Michal Vasko63f3d842020-07-08 10:10:14 +0200389 ly_in_new_memory(data, &st->in);
390 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100391
392 ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200393 assert_int_equal(ret, LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100394 assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
David Sedláke0ef1c62019-09-13 10:05:55 +0200395 assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
David Sedlák5392a212019-07-01 09:19:10 +0200396 assert_null(exts.child->child);
397 assert_null(exts.child->arg);
398 lysp_ext_instance_free(st->ctx, &exts);
399
David Sedlákb1a78352019-06-28 16:16:29 +0200400 st->finished_correctly = true;
401}
402
403static void
404test_yin_parse_extension_instance(void **state)
405{
406 LY_ERR ret;
Radek Krejci3a4889a2020-05-19 17:01:58 +0200407 struct test_parser_yin_state *st = *state;
David Sedlákb1a78352019-06-28 16:16:29 +0200408 struct lysp_ext_instance *exts = NULL;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200409 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
Michal Vasko63f3d842020-07-08 10:10:14 +0200410 ly_in_new_memory(data, &st->in);
411 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100412
413 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200414 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200415 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákb1a78352019-06-28 16:16:29 +0200416 assert_int_equal(exts->insubstmt_index, 0);
417 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
418 assert_true(exts->yin & LYS_YIN);
419 assert_string_equal(exts->child->stmt, "value1");
420 assert_string_equal(exts->child->arg, "test");
421 assert_null(exts->child->child);
422 assert_true(exts->child->flags & LYS_YIN_ATTR);
423 assert_string_equal(exts->child->next->stmt, "value");
424 assert_string_equal(exts->child->next->arg, "test2");
425 assert_null(exts->child->next->child);
426 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
427
David Sedláke0ef1c62019-09-13 10:05:55 +0200428 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
David Sedlákb1a78352019-06-28 16:16:29 +0200429 assert_string_equal(exts->child->next->next->arg, "text");
430 assert_null(exts->child->next->next->child);
431 assert_null(exts->child->next->next->next);
432 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200433 lysp_ext_instance_free(st->ctx, exts);
434 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200435 exts = NULL;
David Sedlákf250ecf2019-07-01 11:02:05 +0200436 st = reset_state(state);
437
David Sedlákb0ca07d2019-09-11 11:54:05 +0200438 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Michal Vasko63f3d842020-07-08 10:10:14 +0200439 ly_in_new_memory(data, &st->in);
440 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100441
442 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200443 assert_int_equal(ret, LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200444 assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
David Sedlákf250ecf2019-07-01 11:02:05 +0200445 assert_null(exts->argument);
446 assert_null(exts->child);
447 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
448 assert_int_equal(exts->insubstmt_index, 0);
449 assert_true(exts->yin & LYS_YIN);
David Sedlákf250ecf2019-07-01 11:02:05 +0200450 lysp_ext_instance_free(st->ctx, exts);
451 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200452 exts = NULL;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200453 st = reset_state(state);
454
David Sedlákb0ca07d2019-09-11 11:54:05 +0200455 data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">"
456 "<myext:ext-sub1/>"
457 "<myext:ext-sub2 sattr1=\"stext2\">"
458 "<myext:ext-sub21>"
459 "<myext:ext-sub211 sattr21=\"text21\"/>"
460 "</myext:ext-sub21>"
461 "</myext:ext-sub2>"
462 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
463 "</myext:ext>";
Michal Vasko63f3d842020-07-08 10:10:14 +0200464 ly_in_new_memory(data, &st->in);
465 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100466
467 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200468 assert_int_equal(ret, LY_SUCCESS);
469
David Sedláke0ef1c62019-09-13 10:05:55 +0200470 assert_string_equal(exts->name, "urn:example:extensions:ext");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200471 assert_null(exts->argument);
472 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
473 assert_int_equal(exts->insubstmt_index, 0);
474 assert_true(exts->yin & LYS_YIN);
475 assert_string_equal(exts->child->stmt, "attr1");
476 assert_string_equal(exts->child->arg, "text1");
477 assert_null(exts->child->child);
478 assert_true(exts->child->flags & LYS_YIN_ATTR);
479
480 assert_string_equal(exts->child->next->stmt, "attr2");
481 assert_string_equal(exts->child->next->arg, "text2");
482 assert_null(exts->child->next->child);
483 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
484
David Sedláke0ef1c62019-09-13 10:05:55 +0200485 assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200486 assert_null(exts->child->next->next->arg);
487 assert_null(exts->child->next->next->child);
488 assert_int_equal(exts->child->next->next->flags, 0);
489
David Sedláke0ef1c62019-09-13 10:05:55 +0200490 assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200491 assert_null(exts->child->next->next->next->arg);
492 assert_int_equal(exts->child->next->next->next->flags, 0);
493 assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
494 assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
495 assert_null(exts->child->next->next->next->child->child);
496 assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
497
David Sedláke0ef1c62019-09-13 10:05:55 +0200498 assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200499 assert_null(exts->child->next->next->next->child->next->arg);
500 assert_null(exts->child->next->next->next->child->next->next);
501 assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
502
David Sedláke0ef1c62019-09-13 10:05:55 +0200503 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 +0200504 assert_null(exts->child->next->next->next->child->next->child->arg);
505 assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
506 assert_null(exts->child->next->next->next->child->next->child->next);
507
508 assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
509 assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
510 assert_null(exts->child->next->next->next->child->next->child->child->next);
511 assert_null(exts->child->next->next->next->child->next->child->child->child);
512 assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
513
David Sedláke0ef1c62019-09-13 10:05:55 +0200514 assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
David Sedlákadd0c2e2019-08-16 10:49:12 +0200515 assert_null(exts->child->next->next->next->next->arg);
516 assert_null(exts->child->next->next->next->next->next);
517 assert_int_equal(exts->child->next->next->next->next->flags, 0);
518
519 assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
520 assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
521 assert_null(exts->child->next->next->next->next->child->next);
522 assert_null(exts->child->next->next->next->next->child->child);
523 assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
524
David Sedlákadd0c2e2019-08-16 10:49:12 +0200525 lysp_ext_instance_free(st->ctx, exts);
526 LY_ARRAY_FREE(exts);
527 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200528 st = reset_state(state);
529
530 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">"
531 "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>"
532 "<yin:augment target-node=\"target\"/>"
533 "<yin:status value=\"value\"/>"
534 "<yin:include module=\"mod\"/>"
535 "<yin:input />"
536 "<yin:must condition=\"cond\"/>"
537 "<yin:namespace uri=\"uri\"/>"
538 "<yin:revision date=\"data\"/>"
539 "<yin:unique tag=\"tag\"/>"
David Sedlákd2844882019-09-13 16:01:22 +0200540 "<yin:description><yin:text>contact-val</yin:text></yin:description>"
541 "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200542 "</myext:extension-elem>";
Michal Vasko63f3d842020-07-08 10:10:14 +0200543 ly_in_new_memory(data, &st->in);
544 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100545
546 ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200547 assert_int_equal(ret, LY_SUCCESS);
548 assert_string_equal(exts->child->arg, "act-name");
549 assert_string_equal(exts->child->next->arg, "target");
550 assert_string_equal(exts->child->next->next->arg, "value");
551 assert_string_equal(exts->child->next->next->next->arg, "mod");
552 assert_null(exts->child->next->next->next->next->arg);
553 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
554 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
555 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
556 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
557 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 +0200558 lysp_ext_instance_free(st->ctx, exts);
559 LY_ARRAY_FREE(exts);
560 exts = NULL;
David Sedlákaa98bba2019-09-12 11:52:14 +0200561 st = reset_state(state);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200562
David Sedlákb1a78352019-06-28 16:16:29 +0200563 st->finished_correctly = true;
564}
565
David Sedlák555c7202019-07-04 12:14:12 +0200566static void
567test_yin_parse_content(void **state)
568{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200569 struct test_parser_yin_state *st = *state;
David Sedlák555c7202019-07-04 12:14:12 +0200570 LY_ERR ret = LY_SUCCESS;
David Sedlák555c7202019-07-04 12:14:12 +0200571 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200572 "<myext:custom xmlns:myext=\"urn:example:extensions\">"
David Sedlák555c7202019-07-04 12:14:12 +0200573 "totally amazing extension"
David Sedlákb0ca07d2019-09-11 11:54:05 +0200574 "</myext:custom>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200575 "<extension name=\"ext\">"
David Sedlák986cb412019-07-04 13:10:11 +0200576 "<argument name=\"argname\"></argument>"
577 "<description><text>desc</text></description>"
578 "<reference><text>ref</text></reference>"
579 "<status value=\"deprecated\"></status>"
David Sedlákaa98bba2019-09-12 11:52:14 +0200580 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200581 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200582 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200583 "<when condition=\"condition...\">"
584 "<reference><text>when_ref</text></reference>"
585 "<description><text>when_desc</text></description>"
586 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200587 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200588 "<error-message>"
589 "<value>error-msg</value>"
590 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200591 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200592 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200593 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200594 "<position value=\"25\"></position>"
595 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200596 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200597 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200598 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200599 "<pattern value='pattern'>"
600 "<modifier value='invert-match'/>"
601 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200602 "<enum name=\"yay\">"
603 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200604 "</prefix>";
605 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200606 const char **if_features = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200607 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200608 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200609 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200610 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200611 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200612 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200613
Michal Vasko63f3d842020-07-08 10:10:14 +0200614 ly_in_new_memory(data, &st->in);
615 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100616 lyxml_ctx_next(st->yin_ctx->xmlctx);
617 lyxml_ctx_next(st->yin_ctx->xmlctx);
618 lyxml_ctx_next(st->yin_ctx->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200619
David Sedlákfd5b9c32019-07-12 15:33:13 +0200620 struct yin_subelement subelems[17] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200621 {LY_STMT_CONFIG, &config, 0},
622 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
623 {LY_STMT_ENUM, &enum_type, 0},
624 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
625 {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
626 {LY_STMT_EXTENSION, &ext_def, 0},
627 {LY_STMT_IF_FEATURE, &if_features, 0},
628 {LY_STMT_LENGTH, &len_type, 0},
629 {LY_STMT_PATTERN, &patter_type, 0},
630 {LY_STMT_POSITION, &pos_enum, 0},
631 {LY_STMT_RANGE, &range_type, 0},
632 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
633 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
634 {LY_STMT_VALUE, &val_enum, 0},
635 {LY_STMT_WHEN, &when_p, 0},
636 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
637 {LY_STMT_ARG_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200638 };
Michal Vaskob36053d2020-03-26 15:49:30 +0100639 ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200640 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200641 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200642 assert_string_equal(def, "default-value");
David Sedláke0ef1c62019-09-13 10:05:55 +0200643 assert_string_equal(exts->name, "urn:example:extensions:custom");
David Sedlák555c7202019-07-04 12:14:12 +0200644 assert_string_equal(exts->argument, "totally amazing extension");
645 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200646 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200647 assert_string_equal(when_p->cond, "condition...");
648 assert_string_equal(when_p->dsc, "when_desc");
649 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200650 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200651 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200652 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200653 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200654 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200655 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200656 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200657 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200658 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200659 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200660 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200661 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200662 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200663 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200664 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200665 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200666 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200667 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200668 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200669 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200670 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200671 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200672 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200673 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200674 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200675 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200676 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200677 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200678 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200679 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200680 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200681 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200682 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200683 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200684 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200685 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200686 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200687 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200688 st = reset_state(state);
689
690 /* test unique subelem */
691 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200692 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
693 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
David Sedláke6cd89e2019-08-07 12:46:02 +0200694 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200695 "<prefix value=\"inv_mod\" />"
696 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
697 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200698 ELEMENT_WRAPPER_END;
Michal Vasko63f3d842020-07-08 10:10:14 +0200699 ly_in_new_memory(data, &st->in);
700 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100701 lyxml_ctx_next(st->yin_ctx->xmlctx);
702
703 ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200704 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200705 logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200706 lydict_remove(st->ctx, prefix_value);
707 lydict_remove(st->ctx, value);
708 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200709
710 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200711 data = ELEMENT_WRAPPER_START
David Sedlák555c7202019-07-04 12:14:12 +0200712 "<prefix value=\"inv_mod\" />"
713 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
714 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedláke6cd89e2019-08-07 12:46:02 +0200715 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200716 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
717 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
Michal Vasko63f3d842020-07-08 10:10:14 +0200718 ly_in_new_memory(data, &st->in);
719 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100720 lyxml_ctx_next(st->yin_ctx->xmlctx);
721
722 ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200723 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200724 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 +0200725 lydict_remove(st->ctx, prefix_value);
726 st = reset_state(state);
David Sedlák555c7202019-07-04 12:14:12 +0200727
728 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200729 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200730 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Michal Vasko63f3d842020-07-08 10:10:14 +0200731 ly_in_new_memory(data, &st->in);
732 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100733 lyxml_ctx_next(st->yin_ctx->xmlctx);
734
735 ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200736 assert_int_equal(ret, LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +0200737 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200738
739 st->finished_correctly = true;
740}
741
David Sedlák92147b02019-07-09 14:01:01 +0200742static void
David Sedlák4a650532019-07-10 11:55:18 +0200743test_validate_value(void **state)
744{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200745 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +0100746 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
747
748 /* create some XML context */
Michal Vasko63f3d842020-07-08 10:10:14 +0200749 ly_in_new_memory(data, &st->in);
750 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100751 st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
752 st->yin_ctx->xmlctx->dynamic = 0;
753
754 st->yin_ctx->xmlctx->value = "#invalid";
755 st->yin_ctx->xmlctx->value_len = 8;
756 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200757 logbuf_assert("Invalid identifier character '#'. Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100758
759 st->yin_ctx->xmlctx->value = "";
760 st->yin_ctx->xmlctx->value_len = 0;
761 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS);
762
763 st->yin_ctx->xmlctx->value = "pre:b";
764 st->yin_ctx->xmlctx->value_len = 5;
765 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
766 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
767
768 st->yin_ctx->xmlctx->value = "pre:pre:b";
769 st->yin_ctx->xmlctx->value_len = 9;
770 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200771
772 st->finished_correctly = true;
773}
774
David Sedlák32488102019-07-15 17:44:10 +0200775/* helper function to simplify unit test of each element using parse_content function */
776LY_ERR
Radek Krejci3a4889a2020-05-19 17:01:58 +0200777test_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 +0200778{
David Sedlákc5b20842019-08-13 10:18:31 +0200779 const char *name, *prefix;
780 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200781 LY_ERR ret = LY_SUCCESS;
782 struct yin_subelement subelems[71] = {
Radek Krejcid6b76452019-09-03 17:03:03 +0200783 {LY_STMT_ACTION, dest, 0},
784 {LY_STMT_ANYDATA, dest, 0},
785 {LY_STMT_ANYXML, dest, 0},
786 {LY_STMT_ARGUMENT,dest, 0},
787 {LY_STMT_AUGMENT, dest, 0},
788 {LY_STMT_BASE, dest, 0},
789 {LY_STMT_BELONGS_TO, dest, 0},
790 {LY_STMT_BIT, dest, 0},
791 {LY_STMT_CASE, dest, 0},
792 {LY_STMT_CHOICE, dest, 0},
793 {LY_STMT_CONFIG, dest, 0},
794 {LY_STMT_CONTACT, dest, 0},
795 {LY_STMT_CONTAINER, dest, 0},
796 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
797 {LY_STMT_DESCRIPTION, dest, 0},
798 {LY_STMT_DEVIATE, dest, 0},
799 {LY_STMT_DEVIATION, dest, 0},
800 {LY_STMT_ENUM, dest, 0},
801 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
802 {LY_STMT_ERROR_MESSAGE, dest, 0},
803 {LY_STMT_EXTENSION, dest, 0},
804 {LY_STMT_FEATURE, dest, 0},
805 {LY_STMT_FRACTION_DIGITS, dest, 0},
806 {LY_STMT_GROUPING, dest, 0},
807 {LY_STMT_IDENTITY, dest, 0},
808 {LY_STMT_IF_FEATURE, dest, 0},
809 {LY_STMT_IMPORT, dest, 0},
810 {LY_STMT_INCLUDE, dest, 0},
811 {LY_STMT_INPUT, dest, 0},
812 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
813 {LY_STMT_LEAF, dest, 0},
814 {LY_STMT_LEAF_LIST, dest, 0},
815 {LY_STMT_LENGTH, dest, 0},
816 {LY_STMT_LIST, dest, 0},
817 {LY_STMT_MANDATORY, dest, 0},
818 {LY_STMT_MAX_ELEMENTS, dest, 0},
819 {LY_STMT_MIN_ELEMENTS, dest, 0},
820 {LY_STMT_MODIFIER, dest, 0},
821 {LY_STMT_MODULE, dest, 0},
822 {LY_STMT_MUST, dest, 0},
823 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
824 {LY_STMT_NOTIFICATION, dest, 0},
825 {LY_STMT_ORDERED_BY, dest, 0},
826 {LY_STMT_ORGANIZATION, dest, 0},
827 {LY_STMT_OUTPUT, dest, 0},
828 {LY_STMT_PATH, dest, 0},
829 {LY_STMT_PATTERN, dest, 0},
830 {LY_STMT_POSITION, dest, 0},
831 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
832 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
833 {LY_STMT_RANGE, dest, 0},
834 {LY_STMT_REFERENCE, dest, 0},
835 {LY_STMT_REFINE, dest, 0},
836 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
837 {LY_STMT_REVISION, dest, 0},
838 {LY_STMT_REVISION_DATE, dest, 0},
839 {LY_STMT_RPC, dest, 0},
840 {LY_STMT_STATUS, dest, 0},
841 {LY_STMT_SUBMODULE, dest, 0},
842 {LY_STMT_TYPE, dest, 0},
843 {LY_STMT_TYPEDEF, dest, 0},
844 {LY_STMT_UNIQUE, dest, 0},
845 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
846 {LY_STMT_USES, dest, 0},
847 {LY_STMT_VALUE, dest, 0},
848 {LY_STMT_WHEN, dest, 0},
849 {LY_STMT_YANG_VERSION, dest, 0},
850 {LY_STMT_YIN_ELEMENT, dest, 0},
851 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
852 {LY_STMT_ARG_TEXT, dest, 0},
853 {LY_STMT_ARG_VALUE, dest, 0}
David Sedlák32488102019-07-15 17:44:10 +0200854 };
Michal Vasko63f3d842020-07-08 10:10:14 +0200855 ly_in_new_memory(data, &st->in);
856 lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100857 prefix = st->yin_ctx->xmlctx->prefix;
858 prefix_len = st->yin_ctx->xmlctx->prefix_len;
859 name = st->yin_ctx->xmlctx->name;
860 name_len = st->yin_ctx->xmlctx->name_len;
861 lyxml_ctx_next(st->yin_ctx->xmlctx);
862
863 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);
864
Michal Vasko63f3d842020-07-08 10:10:14 +0200865 /* free parser and input */
Michal Vaskob36053d2020-03-26 15:49:30 +0100866 lyxml_ctx_free(st->yin_ctx->xmlctx);
867 st->yin_ctx->xmlctx = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +0200868 ly_in_free(st->in, 0);
869 st->in = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200870 return ret;
871}
872
David Sedlákd1144562019-08-06 12:36:14 +0200873#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
874
David Sedlák32488102019-07-15 17:44:10 +0200875static void
David Sedlák43801c92019-08-05 15:58:54 +0200876test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200877{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200878 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200879 struct lysp_type type = {};
880 const char *data;
881 data = ELEMENT_WRAPPER_START
882 "<enum name=\"enum-name\">"
883 "<if-feature name=\"feature\" />"
884 "<value value=\"55\" />"
885 "<status value=\"deprecated\" />"
886 "<description><text>desc...</text></description>"
887 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200888 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +0200889 "</enum>"
890 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100891 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200892 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200893 assert_string_equal(*type.enums->iffeatures, "feature");
894 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200895 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200896 assert_string_equal(type.enums->dsc, "desc...");
897 assert_string_equal(type.enums->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200898 assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200899 assert_int_equal(type.enums->exts->insubstmt_index, 0);
900 assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
901 lysp_type_free(st->ctx, &type);
902 memset(&type, 0, sizeof type);
903
904 data = ELEMENT_WRAPPER_START
905 "<enum name=\"enum-name\"></enum>"
906 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100907 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200908 assert_string_equal(type.enums->name, "enum-name");
David Sedlák32488102019-07-15 17:44:10 +0200909 lysp_type_free(st->ctx, &type);
910 memset(&type, 0, sizeof type);
911
David Sedlák43801c92019-08-05 15:58:54 +0200912 st->finished_correctly = true;
913}
914
915static void
916test_bit_elem(void **state)
917{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200918 struct test_parser_yin_state *st = *state;
David Sedlák43801c92019-08-05 15:58:54 +0200919 struct lysp_type type = {};
920 const char *data;
921 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200922 "<bit name=\"bit-name\">"
David Sedlák43801c92019-08-05 15:58:54 +0200923 "<if-feature name=\"feature\" />"
924 "<position value=\"55\" />"
925 "<status value=\"deprecated\" />"
926 "<description><text>desc...</text></description>"
927 "<reference><text>ref...</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +0200928 EXT_SUBELEM
David Sedlák43801c92019-08-05 15:58:54 +0200929 "</bit>"
930 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100931 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200932 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200933 assert_string_equal(*type.bits->iffeatures, "feature");
934 assert_int_equal(type.bits->value, 55);
935 assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
936 assert_string_equal(type.bits->dsc, "desc...");
937 assert_string_equal(type.bits->ref, "ref...");
David Sedláke0ef1c62019-09-13 10:05:55 +0200938 assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200939 assert_int_equal(type.bits->exts->insubstmt_index, 0);
940 assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
941 lysp_type_free(st->ctx, &type);
942 memset(&type, 0, sizeof type);
943
944 data = ELEMENT_WRAPPER_START
945 "<bit name=\"bit-name\"> </bit>"
946 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100947 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200948 assert_string_equal(type.bits->name, "bit-name");
David Sedlák43801c92019-08-05 15:58:54 +0200949 lysp_type_free(st->ctx, &type);
950 memset(&type, 0, sizeof type);
951
David Sedlák32488102019-07-15 17:44:10 +0200952 st->finished_correctly = true;
953}
954
955static void
956test_meta_elem(void **state)
957{
Radek Krejci3a4889a2020-05-19 17:01:58 +0200958 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200959 char *value = NULL;
960 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200961 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200962
963 /* organization element */
964 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200965 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
David Sedlák32488102019-07-15 17:44:10 +0200966 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100967 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200968 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200969 assert_int_equal(exts[0].insubstmt_index, 0);
970 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedláke0ef1c62019-09-13 10:05:55 +0200971 assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200972 assert_int_equal(exts[1].insubstmt_index, 0);
973 assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
David Sedlák32488102019-07-15 17:44:10 +0200974 assert_string_equal(value, "organization...");
975 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200976 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200977 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200978 exts = NULL;
979
David Sedlák32488102019-07-15 17:44:10 +0200980 /* contact element */
981 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200982 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
David Sedlák32488102019-07-15 17:44:10 +0200983 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100984 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +0200985 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +0200986 assert_int_equal(exts[0].insubstmt_index, 0);
987 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200988 assert_string_equal(value, "contact...");
989 FREE_STRING(st->ctx, value);
David Sedlákd1144562019-08-06 12:36:14 +0200990 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
991 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200992 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200993
David Sedlák32488102019-07-15 17:44:10 +0200994 /* description element */
995 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +0200996 "<description><text>description...</text>" EXT_SUBELEM "</description>"
David Sedlák32488102019-07-15 17:44:10 +0200997 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +0100998 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200999 assert_string_equal(value, "description...");
David Sedláke0ef1c62019-09-13 10:05:55 +02001000 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001001 assert_int_equal(exts[0].insubstmt_index, 0);
1002 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +02001003 FREE_STRING(st->ctx, value);
1004 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001005 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1006 exts = NULL;
1007
David Sedlák32488102019-07-15 17:44:10 +02001008 /* reference element */
1009 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001010 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
David Sedlák32488102019-07-15 17:44:10 +02001011 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001012 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001013 assert_string_equal(value, "reference...");
David Sedláke0ef1c62019-09-13 10:05:55 +02001014 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001015 assert_int_equal(exts[0].insubstmt_index, 0);
1016 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
David Sedlák32488102019-07-15 17:44:10 +02001017 FREE_STRING(st->ctx, value);
1018 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001019 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1020 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001021
David Sedlákdf2a9732019-08-07 13:23:16 +02001022 /* reference element */
1023 data = ELEMENT_WRAPPER_START
1024 "<reference invalid=\"text\"><text>reference...</text>""</reference>"
1025 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001026 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001027 logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001028 FREE_STRING(st->ctx, value);
1029 value = NULL;
1030 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1031 exts = NULL;
1032
David Sedlák32488102019-07-15 17:44:10 +02001033 /* missing text subelement */
1034 data = ELEMENT_WRAPPER_START
1035 "<reference>reference...</reference>"
1036 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001037 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001038 logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001039
David Sedlákd1144562019-08-06 12:36:14 +02001040 /* reference element */
1041 data = ELEMENT_WRAPPER_START
1042 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
1043 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001044 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001045 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 +02001046 FREE_STRING(st->ctx, value);
1047 value = NULL;
1048 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1049 exts = NULL;
1050
David Sedlák32488102019-07-15 17:44:10 +02001051 st->finished_correctly = true;
1052}
1053
1054static void
1055test_import_elem(void **state)
1056{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001057 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001058 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02001059 struct lysp_import *imports = NULL;
1060 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +02001061
1062 /* max subelems */
1063 data = ELEMENT_WRAPPER_START
1064 "<import module=\"a\">"
David Sedlákd1144562019-08-06 12:36:14 +02001065 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001066 "<prefix value=\"a_mod\"/>"
1067 "<revision-date date=\"2015-01-01\"></revision-date>"
1068 "<description><text>import description</text></description>"
1069 "<reference><text>import reference</text></reference>"
1070 "</import>"
1071 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001072 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001073 assert_string_equal(imports->name, "a");
1074 assert_string_equal(imports->prefix, "a_mod");
1075 assert_string_equal(imports->rev, "2015-01-01");
1076 assert_string_equal(imports->dsc, "import description");
1077 assert_string_equal(imports->ref, "import reference");
David Sedláke0ef1c62019-09-13 10:05:55 +02001078 assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001079 assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
1080 assert_int_equal(imports->exts->insubstmt_index, 0);
David Sedlák298ff6d2019-07-26 14:29:03 +02001081 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1082 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001083
1084 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +02001085 data = ELEMENT_WRAPPER_START
1086 "<import module=\"a\">"
1087 "<prefix value=\"a_mod\"/>"
1088 "</import>"
1089 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001090 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02001091 assert_string_equal(imports->prefix, "a_mod");
1092 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1093 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001094
1095 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +02001096 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001097 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001098 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
David Sedlák298ff6d2019-07-26 14:29:03 +02001099 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1100 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001101
1102 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +02001103 data = ELEMENT_WRAPPER_START
1104 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001105 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001106 "</import>"
1107 "<import module=\"a\">"
David Sedlák298ff6d2019-07-26 14:29:03 +02001108 "<prefix value=\"prefix\"/>"
David Sedlák32488102019-07-15 17:44:10 +02001109 "</import>"
1110 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001111 assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
David Sedlák298ff6d2019-07-26 14:29:03 +02001112 logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1.");
1113 FREE_ARRAY(st->ctx, imports, lysp_import_free);
1114 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001115
1116 st->finished_correctly = true;
1117}
1118
1119static void
1120test_status_elem(void **state)
1121{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001122 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001123 const char *data;
1124 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001125 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001126
1127 /* test valid values */
1128 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001129 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001130 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001131
1132 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001133 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001134 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001135
David Sedlákd1144562019-08-06 12:36:14 +02001136 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001137 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001138 assert_true(flags & LYS_STATUS_OBSLT);
David Sedláke0ef1c62019-09-13 10:05:55 +02001139 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001140 assert_int_equal(exts[0].insubstmt_index, 0);
1141 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
1142 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1143 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001144
1145 /* test invalid value */
1146 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001147 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001148 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 +02001149 st->finished_correctly = true;
1150}
1151
1152static void
1153test_ext_elem(void **state)
1154{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001155 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001156 const char *data;
1157 struct lysp_ext *ext = NULL;
1158
1159 /* max subelems */
1160 data = ELEMENT_WRAPPER_START
1161 "<extension name=\"ext_name\">"
1162 "<argument name=\"arg\"></argument>"
1163 "<status value=\"current\"/>"
1164 "<description><text>ext_desc</text></description>"
1165 "<reference><text>ext_ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001166 EXT_SUBELEM
David Sedlák32488102019-07-15 17:44:10 +02001167 "</extension>"
1168 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001169 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001170 assert_string_equal(ext->name, "ext_name");
1171 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001172 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001173 assert_string_equal(ext->dsc, "ext_desc");
1174 assert_string_equal(ext->ref, "ext_ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001175 assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001176 assert_int_equal(ext->exts[0].insubstmt_index, 0);
1177 assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák32488102019-07-15 17:44:10 +02001178 lysp_ext_free(st->ctx, ext);
1179 LY_ARRAY_FREE(ext);
1180 ext = NULL;
1181
1182 /* min subelems */
1183 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001184 assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001185 assert_string_equal(ext->name, "ext_name");
1186 lysp_ext_free(st->ctx, ext);
1187 LY_ARRAY_FREE(ext);
1188 ext = NULL;
1189
1190 st->finished_correctly = true;
1191}
1192
1193static void
1194test_yin_element_elem(void **state)
1195{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001196 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001197 const char *data;
1198 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001199 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001200
1201 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001202 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001203 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001204
David Sedlákd1144562019-08-06 12:36:14 +02001205 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001206 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001207 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001208 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001209 assert_int_equal(exts[0].insubstmt_index, 0);
1210 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
1211 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001212
1213 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001214 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001215 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák26ea1432019-08-14 13:42:23 +02001216 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 +02001217 st->finished_correctly = true;
1218}
1219
1220static void
1221test_yangversion_elem(void **state)
1222{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001223 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001224 const char *data;
1225 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001226 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001227
1228 /* valid values */
1229 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001230 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001231 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001232 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
1233
David Sedlákd1144562019-08-06 12:36:14 +02001234 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001235 assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001236 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +02001237 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
David Sedláke0ef1c62019-09-13 10:05:55 +02001238 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001239 assert_int_equal(exts[0].insubstmt_index, 0);
1240 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
1241 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001242
1243 /* invalid value */
1244 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001245 assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001246 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 +02001247
1248 st->finished_correctly = true;
1249}
1250
1251static void
1252test_mandatory_elem(void **state)
1253{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001254 struct test_parser_yin_state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +02001255 const char *data;
1256 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001257 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001258
1259 /* valid values */
1260 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001261 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001262 assert_int_equal(man, LYS_MAND_TRUE);
1263 man = 0;
1264
David Sedlákd1144562019-08-06 12:36:14 +02001265 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001266 assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001267 assert_int_equal(man, LYS_MAND_FALSE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001268 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001269 assert_int_equal(exts[0].insubstmt_index, 0);
1270 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
1271 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001272
1273 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001274 assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001275 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 +02001276
1277 st->finished_correctly = true;
1278}
1279
David Sedlák8e7bda82019-07-16 17:57:50 +02001280static void
1281test_argument_elem(void **state)
1282{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001283 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001284 const char *data;
1285 uint16_t flags = 0;
1286 const char *arg;
1287 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001288 struct lysp_ext_instance *exts = NULL;
1289
David Sedlák8e7bda82019-07-16 17:57:50 +02001290 /* max subelems */
1291 data = ELEMENT_WRAPPER_START
1292 "<argument name=\"arg-name\">"
1293 "<yin-element value=\"true\" />"
David Sedlákd1144562019-08-06 12:36:14 +02001294 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001295 "</argument>"
1296 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001297 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001298 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001299 assert_true(flags & LYS_YINELEM_TRUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001300 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001301 assert_int_equal(exts[0].insubstmt_index, 0);
1302 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
1303 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1304 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001305 flags = 0;
1306 FREE_STRING(st->ctx, arg);
1307 arg = NULL;
1308
1309 /* min subelems */
1310 data = ELEMENT_WRAPPER_START
1311 "<argument name=\"arg\">"
1312 "</argument>"
1313 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001314 assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001315 assert_string_equal(arg, "arg");
1316 assert_true(flags == 0);
1317 FREE_STRING(st->ctx, arg);
1318
1319 st->finished_correctly = true;
1320}
1321
1322static void
1323test_base_elem(void **state)
1324{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001325 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001326 const char *data;
1327 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001328 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001329 struct lysp_type type = {};
1330
1331 /* as identity subelement */
1332 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001333 "<base name=\"base-name\">"
1334 EXT_SUBELEM
1335 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001336 "</identity>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001337 assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001338 assert_string_equal(*bases, "base-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001339 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001340 assert_int_equal(exts[0].insubstmt_index, 0);
1341 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1342 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1343 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001344 FREE_STRING(st->ctx, *bases);
1345 LY_ARRAY_FREE(bases);
1346
1347 /* as type subelement */
1348 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlákd1144562019-08-06 12:36:14 +02001349 "<base name=\"base-name\">"
1350 EXT_SUBELEM
1351 "</base>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001352 "</type>";
Michal Vaskob36053d2020-03-26 15:49:30 +01001353 assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001354 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001355 assert_true(type.flags & LYS_SET_BASE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001356 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001357 assert_int_equal(exts[0].insubstmt_index, 0);
1358 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
1359 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1360 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001361 FREE_STRING(st->ctx, *type.bases);
1362 LY_ARRAY_FREE(type.bases);
1363
1364 st->finished_correctly = true;
1365}
1366
1367static void
1368test_belongsto_elem(void **state)
1369{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001370 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001371 const char *data;
1372 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001373 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001374
1375 data = ELEMENT_WRAPPER_START
David Sedlákd1144562019-08-06 12:36:14 +02001376 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001377 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001378 assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001379 assert_string_equal(submod.belongsto, "module-name");
1380 assert_string_equal(submod.prefix, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001381 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001382 assert_int_equal(exts[0].insubstmt_index, 0);
1383 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
1384 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1385 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001386 FREE_STRING(st->ctx, submod.belongsto);
1387 FREE_STRING(st->ctx, submod.prefix);
1388
1389 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001390 assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001391 logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001392 FREE_STRING(st->ctx, submod.belongsto);
1393
1394 st->finished_correctly = true;
1395}
1396
1397static void
1398test_config_elem(void **state)
1399{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001400 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001401 const char *data;
1402 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001403 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001404
David Sedlákd1144562019-08-06 12:36:14 +02001405 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001406 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001407 assert_true(flags & LYS_CONFIG_W);
David Sedláke0ef1c62019-09-13 10:05:55 +02001408 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001409 assert_int_equal(exts[0].insubstmt_index, 0);
1410 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
1411 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1412 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001413 flags = 0;
1414
1415 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001416 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001417 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001418 flags = 0;
1419
1420 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001421 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001422 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 +02001423
1424 st->finished_correctly = true;
1425}
1426
1427static void
1428test_default_elem(void **state)
1429{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001430 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001431 const char *data;
1432 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001433 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001434
David Sedlákd1144562019-08-06 12:36:14 +02001435 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001436 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001437 assert_string_equal(val, "defaul-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02001438 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001439 assert_int_equal(exts[0].insubstmt_index, 0);
1440 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
1441 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1442 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001443 FREE_STRING(st->ctx, val);
1444 val = NULL;
1445
1446 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001447 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001448 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1449
1450 st->finished_correctly = true;
1451}
1452
1453static void
1454test_err_app_tag_elem(void **state)
1455{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001456 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001457 const char *data;
1458 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001459 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001460
David Sedlákd1144562019-08-06 12:36:14 +02001461 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001462 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001463 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001464 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001465 assert_int_equal(exts[0].insubstmt_index, 0);
1466 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
1467 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1468 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001469 FREE_STRING(st->ctx, val);
1470 val = NULL;
1471
1472 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001473 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001474 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1475
1476 st->finished_correctly = true;
1477}
1478
1479static void
1480test_err_msg_elem(void **state)
1481{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001482 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001483 const char *data;
1484 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001485 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001486
David Sedlákd1144562019-08-06 12:36:14 +02001487 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001488 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001489 assert_string_equal(val, "val");
David Sedláke0ef1c62019-09-13 10:05:55 +02001490 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001491 assert_int_equal(exts[0].insubstmt_index, 0);
1492 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
1493 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1494 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001495 FREE_STRING(st->ctx, val);
1496
1497 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001498 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001499 logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001500
David Sedlákdf2a9732019-08-07 13:23:16 +02001501 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001502 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001503 logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
David Sedlákdf2a9732019-08-07 13:23:16 +02001504
David Sedlák8e7bda82019-07-16 17:57:50 +02001505 st->finished_correctly = true;
1506}
1507
1508static void
1509test_fracdigits_elem(void **state)
1510{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001511 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001512 const char *data;
1513 struct lysp_type type = {};
1514
1515 /* valid value */
David Sedlákd1144562019-08-06 12:36:14 +02001516 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</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_SUCCESS);
David Sedláke0ef1c62019-09-13 10:05:55 +02001518 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001519 assert_int_equal(type.exts[0].insubstmt_index, 0);
1520 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001521 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001522 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlákd1144562019-08-06 12:36:14 +02001523 FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001524
1525 /* invalid values */
1526 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001527 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001528 logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001529
1530 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001531 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001532 logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001533
1534 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001535 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001536 logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001537
1538 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001539 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001540 logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001541
1542 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001543 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001544 logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001545
1546 st->finished_correctly = true;
1547}
1548
1549static void
1550test_iffeature_elem(void **state)
1551{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001552 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001553 const char *data;
1554 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001555 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001556
David Sedlákd1144562019-08-06 12:36:14 +02001557 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001558 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001559 assert_string_equal(*iffeatures, "local-storage");
David Sedláke0ef1c62019-09-13 10:05:55 +02001560 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001561 assert_int_equal(exts[0].insubstmt_index, 0);
1562 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
1563 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1564 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001565 FREE_STRING(st->ctx, *iffeatures);
1566 LY_ARRAY_FREE(iffeatures);
1567 iffeatures = NULL;
1568
1569 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001570 assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001571 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1572 LY_ARRAY_FREE(iffeatures);
1573 iffeatures = NULL;
1574
1575 st->finished_correctly = true;
1576}
1577
1578static void
1579test_length_elem(void **state)
1580{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001581 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001582 const char *data;
1583 struct lysp_type type = {};
1584
1585 /* max subelems */
1586 data = ELEMENT_WRAPPER_START
1587 "<length value=\"length-str\">"
1588 "<error-message><value>err-msg</value></error-message>"
1589 "<error-app-tag value=\"err-app-tag\"/>"
1590 "<description><text>desc</text></description>"
1591 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001592 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001593 "</length>"
1594 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001595 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001596 assert_string_equal(type.length->arg, "length-str");
1597 assert_string_equal(type.length->emsg, "err-msg");
1598 assert_string_equal(type.length->eapptag, "err-app-tag");
1599 assert_string_equal(type.length->dsc, "desc");
1600 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001601 assert_true(type.flags & LYS_SET_LENGTH);
David Sedláke0ef1c62019-09-13 10:05:55 +02001602 assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001603 assert_int_equal(type.length->exts[0].insubstmt_index, 0);
1604 assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001605 lysp_type_free(st->ctx, &type);
1606 memset(&type, 0, sizeof(type));
1607
1608 /* min subelems */
1609 data = ELEMENT_WRAPPER_START
1610 "<length value=\"length-str\">"
1611 "</length>"
1612 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001613 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001614 assert_string_equal(type.length->arg, "length-str");
1615 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001616 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001617 memset(&type, 0, sizeof(type));
1618
1619 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001620 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001621 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1622 lysp_type_free(st->ctx, &type);
1623 memset(&type, 0, sizeof(type));
1624
1625 st->finished_correctly = true;
1626}
1627
1628static void
1629test_modifier_elem(void **state)
1630{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001631 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001632 const char *data;
1633 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
David Sedlákd1144562019-08-06 12:36:14 +02001634 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001635
David Sedlákd1144562019-08-06 12:36:14 +02001636 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001637 assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001638 assert_string_equal(pat, "\x015pattern");
David Sedláke0ef1c62019-09-13 10:05:55 +02001639 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001640 assert_int_equal(exts[0].insubstmt_index, 0);
1641 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
1642 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1643 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001644 FREE_STRING(st->ctx, pat);
1645
1646 pat = lydict_insert(st->ctx, "\006pattern", 8);
1647 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001648 assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02001649 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 +02001650 FREE_STRING(st->ctx, pat);
1651
1652 st->finished_correctly = true;
1653}
1654
1655static void
1656test_namespace_elem(void **state)
1657{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001658 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001659 const char *data;
1660 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001661 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001662
David Sedlákd1144562019-08-06 12:36:14 +02001663 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001664 assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001665 assert_string_equal(ns, "ns");
David Sedláke0ef1c62019-09-13 10:05:55 +02001666 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001667 assert_int_equal(exts[0].insubstmt_index, 0);
1668 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
1669 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1670 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001671 FREE_STRING(st->ctx, ns);
1672
1673 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001674 assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID);
David Sedlák8e7bda82019-07-16 17:57:50 +02001675 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1676
1677 st->finished_correctly = true;
1678}
1679
1680static void
David Sedlák8e7bda82019-07-16 17:57:50 +02001681test_pattern_elem(void **state)
1682{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001683 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001684 const char *data;
1685 struct lysp_type type = {};
1686
1687 /* max subelems */
1688 data = ELEMENT_WRAPPER_START
1689 "<pattern value=\"super_pattern\">"
1690 "<modifier value=\"invert-match\"/>"
1691 "<error-message><value>err-msg-value</value></error-message>"
1692 "<error-app-tag value=\"err-app-tag-value\"/>"
David Sedlák169cc522019-08-15 13:23:45 +02001693 "<description><text>&quot;pattern-desc&quot;</text></description>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001694 "<reference><text>pattern-ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001695 EXT_SUBELEM
David Sedlák8e7bda82019-07-16 17:57:50 +02001696 "</pattern>"
1697 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001698 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001699 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001700 assert_string_equal(type.patterns->arg, "\x015super_pattern");
David Sedlák169cc522019-08-15 13:23:45 +02001701 assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
David Sedlák8e7bda82019-07-16 17:57:50 +02001702 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1703 assert_string_equal(type.patterns->emsg, "err-msg-value");
David Sedlák8e7bda82019-07-16 17:57:50 +02001704 assert_string_equal(type.patterns->ref, "pattern-ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001705 assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001706 assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
1707 assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8e7bda82019-07-16 17:57:50 +02001708 lysp_type_free(st->ctx, &type);
1709 memset(&type, 0, sizeof(type));
1710
1711 /* min subelems */
1712 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001713 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001714 assert_string_equal(type.patterns->arg, "\x006pattern");
1715 lysp_type_free(st->ctx, &type);
1716 memset(&type, 0, sizeof(type));
1717
1718 st->finished_correctly = true;
1719}
1720
1721static void
1722test_value_position_elem(void **state)
1723{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001724 struct test_parser_yin_state *st = *state;
David Sedlák8e7bda82019-07-16 17:57:50 +02001725 const char *data;
1726 struct lysp_type_enum en = {};
1727
1728 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001729 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001730 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001731 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001732 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001733 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001734 assert_int_equal(en.exts[0].insubstmt_index, 0);
1735 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
1736 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001737 memset(&en, 0, sizeof(en));
1738
1739 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001740 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001741 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001742 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001743 memset(&en, 0, sizeof(en));
1744
1745 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001746 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001747 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001748 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001749 memset(&en, 0, sizeof(en));
1750
1751 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001752 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001753 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001754 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001755 memset(&en, 0, sizeof(en));
1756
1757 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001758 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001759 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001760 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001761 assert_true(en.flags & LYS_SET_VALUE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001762 assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
David Sedlák8d552d62019-08-06 15:29:05 +02001763 assert_int_equal(en.exts[0].insubstmt_index, 0);
1764 assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
1765 FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001766 memset(&en, 0, sizeof(en));
1767
1768 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001769 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001770 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001771 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001772 memset(&en, 0, sizeof(en));
1773
1774 /* invalid values */
1775 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001776 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001777 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001778
1779 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001780 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001781 logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001782
David Sedlák69f01612019-07-17 11:41:08 +02001783 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001784 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001785 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001786
David Sedlák8e7bda82019-07-16 17:57:50 +02001787 /*invalid positions */
1788 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001789 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001790 logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001791
1792 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001793 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001794 logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001795
1796 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001797 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001798 logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001799
David Sedlák69f01612019-07-17 11:41:08 +02001800 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001801 assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02001802 logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001803
1804 st->finished_correctly = true;
1805}
1806
1807static void
1808test_prefix_elem(void **state)
1809{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001810 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001811 const char *data;
1812 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001813 struct lysp_ext_instance *exts = NULL;
1814
1815 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001816 assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001817 assert_string_equal(value, "pref");
David Sedláke0ef1c62019-09-13 10:05:55 +02001818 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001819 assert_int_equal(exts[0].insubstmt_index, 0);
1820 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
1821 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1822 exts = NULL;
1823 FREE_STRING(st->ctx, value);
David Sedlák69f01612019-07-17 11:41:08 +02001824
1825 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001826 assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001827 assert_string_equal(value, "pref");
1828 FREE_STRING(st->ctx, value);
1829
1830 st->finished_correctly = true;
1831}
1832
1833static void
1834test_range_elem(void **state)
1835{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001836 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001837 const char *data;
1838 struct lysp_type type = {};
1839
1840 /* max subelems */
1841 data = ELEMENT_WRAPPER_START
1842 "<range value=\"range-str\">"
1843 "<error-message><value>err-msg</value></error-message>"
1844 "<error-app-tag value=\"err-app-tag\" />"
1845 "<description><text>desc</text></description>"
1846 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001847 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001848 "</range>"
1849 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001850 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001851 assert_string_equal(type.range->arg, "range-str");
1852 assert_string_equal(type.range->dsc, "desc");
1853 assert_string_equal(type.range->eapptag, "err-app-tag");
1854 assert_string_equal(type.range->emsg, "err-msg");
1855 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001856 assert_true(type.flags & LYS_SET_RANGE);
David Sedláke0ef1c62019-09-13 10:05:55 +02001857 assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001858 assert_int_equal(type.range->exts[0].insubstmt_index, 0);
1859 assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02001860 lysp_type_free(st->ctx, &type);
1861 memset(&type, 0, sizeof(type));
1862
1863 /* min subelems */
1864 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001865 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001866 assert_string_equal(type.range->arg, "range-str");
1867 lysp_type_free(st->ctx, &type);
1868 memset(&type, 0, sizeof(type));
1869
1870 st->finished_correctly = true;
1871}
1872
1873static void
1874test_reqinstance_elem(void **state)
1875{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001876 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001877 const char *data;
1878 struct lysp_type type = {};
1879
David Sedlákd1144562019-08-06 12:36:14 +02001880 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001881 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001882 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001883 assert_true(type.flags & LYS_SET_REQINST);
David Sedláke0ef1c62019-09-13 10:05:55 +02001884 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001885 assert_int_equal(type.exts[0].insubstmt_index, 0);
1886 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
1887 lysp_type_free(st->ctx, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001888 memset(&type, 0, sizeof(type));
1889
1890 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001891 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001892 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001893 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001894 memset(&type, 0, sizeof(type));
1895
1896 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001897 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001898 memset(&type, 0, sizeof(type));
David Sedlák26ea1432019-08-14 13:42:23 +02001899 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 +02001900
1901 st->finished_correctly = true;
1902}
1903
1904static void
1905test_revision_date_elem(void **state)
1906{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001907 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001908 const char *data;
1909 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001910 struct lysp_ext_instance *exts = NULL;
1911
1912 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001913 assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001914 assert_string_equal(rev, "2000-01-01");
David Sedláke0ef1c62019-09-13 10:05:55 +02001915 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001916 assert_int_equal(exts[0].insubstmt_index, 0);
1917 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
1918 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001919
1920 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001921 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001922 assert_string_equal(rev, "2000-01-01");
1923
1924 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001925 assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001926 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1927
1928 st->finished_correctly = true;
1929}
1930
1931static void
1932test_unique_elem(void **state)
1933{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001934 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001935 const char *data;
1936 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001937 struct lysp_ext_instance *exts = NULL;
1938
1939 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001940 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001941 assert_string_equal(*values, "tag");
David Sedláke0ef1c62019-09-13 10:05:55 +02001942 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001943 assert_int_equal(exts[0].insubstmt_index, 0);
1944 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
1945 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1946 FREE_STRING(st->ctx, *values);
1947 LY_ARRAY_FREE(values);
1948 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001949
1950 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001951 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001952 assert_string_equal(*values, "tag");
1953 FREE_STRING(st->ctx, *values);
1954 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001955 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001956
1957 st->finished_correctly = true;
1958}
1959
1960static void
1961test_units_elem(void **state)
1962{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001963 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001964 const char *data;
1965 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001966 struct lysp_ext_instance *exts = NULL;
1967
1968 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001969 assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001970 assert_string_equal(values, "name");
David Sedláke0ef1c62019-09-13 10:05:55 +02001971 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02001972 assert_int_equal(exts[0].insubstmt_index, 0);
1973 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
1974 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
1975 FREE_STRING(st->ctx, values);
1976 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001977
1978 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01001979 assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001980 assert_string_equal(values, "name");
1981 FREE_STRING(st->ctx, values);
David Sedlákd1144562019-08-06 12:36:14 +02001982 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001983
1984 st->finished_correctly = true;
1985}
1986
1987static void
1988test_when_elem(void **state)
1989{
Radek Krejci3a4889a2020-05-19 17:01:58 +02001990 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02001991 const char *data;
1992 struct lysp_when *when = NULL;
1993
1994 data = ELEMENT_WRAPPER_START
1995 "<when condition=\"cond\">"
1996 "<description><text>desc</text></description>"
1997 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02001998 EXT_SUBELEM
David Sedlák69f01612019-07-17 11:41:08 +02001999 "</when>"
2000 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002001 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002002 assert_string_equal(when->cond, "cond");
2003 assert_string_equal(when->dsc, "desc");
2004 assert_string_equal(when->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002005 assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002006 assert_int_equal(when->exts[0].insubstmt_index, 0);
2007 assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák69f01612019-07-17 11:41:08 +02002008 lysp_when_free(st->ctx, when);
2009 free(when);
2010 when = NULL;
2011
2012 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002013 assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002014 assert_string_equal(when->cond, "cond");
2015 lysp_when_free(st->ctx, when);
2016 free(when);
2017 when = NULL;
2018
2019 st->finished_correctly = true;
2020}
2021
2022static void
2023test_yin_text_value_elem(void **state)
2024{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002025 struct test_parser_yin_state *st = *state;
David Sedlák69f01612019-07-17 11:41:08 +02002026 const char *data;
2027 const char *val;
2028
2029 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002030 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002031 assert_string_equal(val, "text");
2032 FREE_STRING(st->ctx, val);
2033
2034 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002035 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002036 assert_string_equal(val, "text");
2037 FREE_STRING(st->ctx, val);
2038
2039 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002040 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02002041 assert_string_equal("", val);
2042 FREE_STRING(st->ctx, val);
2043
David Sedlák8e7bda82019-07-16 17:57:50 +02002044 st->finished_correctly = true;
2045}
David Sedlák32488102019-07-15 17:44:10 +02002046
David Sedlák374d2b32019-07-17 15:06:55 +02002047static void
2048test_type_elem(void **state)
2049{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002050 struct test_parser_yin_state *st = *state;
David Sedlák374d2b32019-07-17 15:06:55 +02002051 const char *data;
2052 struct lysp_type type = {};
2053
2054 /* max subelems */
2055 data = ELEMENT_WRAPPER_START
2056 "<type name=\"type-name\">"
2057 "<base name=\"base-name\"/>"
2058 "<bit name=\"bit\"/>"
2059 "<enum name=\"enum\"/>"
2060 "<fraction-digits value=\"2\"/>"
2061 "<length value=\"length\"/>"
2062 "<path value=\"path\"/>"
2063 "<pattern value=\"pattern\"/>"
2064 "<range value=\"range\" />"
2065 "<require-instance value=\"true\"/>"
2066 "<type name=\"sub-type-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002067 EXT_SUBELEM
David Sedlák374d2b32019-07-17 15:06:55 +02002068 "</type>"
2069 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002070 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002071 assert_string_equal(type.name, "type-name");
2072 assert_string_equal(*type.bases, "base-name");
2073 assert_string_equal(type.bits->name, "bit");
2074 assert_string_equal(type.enums->name, "enum");
2075 assert_int_equal(type.fraction_digits, 2);
2076 assert_string_equal(type.length->arg, "length");
Michal Vasko004d3152020-06-11 19:59:22 +02002077 assert_string_equal(type.path->expr, "path");
David Sedlák374d2b32019-07-17 15:06:55 +02002078 assert_string_equal(type.patterns->arg, "\006pattern");
2079 assert_string_equal(type.range->arg, "range");
2080 assert_int_equal(type.require_instance, 1);
2081 assert_string_equal(type.types->name, "sub-type-name");
David Sedláke0ef1c62019-09-13 10:05:55 +02002082 assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002083 assert_int_equal(type.exts[0].insubstmt_index, 0);
2084 assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002085 assert_true(type.flags & LYS_SET_BASE);
2086 assert_true(type.flags & LYS_SET_BIT);
2087 assert_true(type.flags & LYS_SET_ENUM);
2088 assert_true(type.flags & LYS_SET_FRDIGITS);
2089 assert_true(type.flags & LYS_SET_LENGTH);
2090 assert_true(type.flags & LYS_SET_PATH);
2091 assert_true(type.flags & LYS_SET_PATTERN);
2092 assert_true(type.flags & LYS_SET_RANGE);
2093 assert_true(type.flags & LYS_SET_REQINST);
2094 assert_true(type.flags & LYS_SET_TYPE);
David Sedlákd1144562019-08-06 12:36:14 +02002095 lysp_type_free(st->ctx, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02002096 memset(&type, 0, sizeof(type));
2097
2098 /* min subelems */
2099 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002100 assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02002101 lysp_type_free(st->ctx, &type);
2102 memset(&type, 0, sizeof(type));
2103
2104 st->finished_correctly = true;
2105}
2106
David Sedlák1af868e2019-07-17 17:03:14 +02002107static void
2108test_max_elems_elem(void **state)
2109{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002110 struct test_parser_yin_state *st = *state;
David Sedlák1af868e2019-07-17 17:03:14 +02002111 const char *data;
2112 struct lysp_node_list list = {};
2113 struct lysp_node_leaflist llist = {};
2114 struct lysp_refine refine = {};
2115
David Sedlákd1144562019-08-06 12:36:14 +02002116 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 +01002117 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002118 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002119 assert_true(refine.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002120 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002121 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2122 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2123 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002124
David Sedlákd1144562019-08-06 12:36:14 +02002125 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 +01002126 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002127 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002128 assert_true(list.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002129 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002130 assert_int_equal(list.exts[0].insubstmt_index, 0);
2131 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2132 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002133
David Sedlákd1144562019-08-06 12:36:14 +02002134 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 +01002135 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002136 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002137 assert_true(llist.flags & LYS_SET_MAX);
David Sedláke0ef1c62019-09-13 10:05:55 +02002138 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002139 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2140 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
2141 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02002142
2143 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002144 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02002145 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002146 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02002147
2148 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002149 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002150 logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002151
2152 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002153 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002154 logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002155
2156 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002157 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002158 logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002159
2160 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Michal Vaskob36053d2020-03-26 15:49:30 +01002161 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002162 logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02002163
2164 st->finished_correctly = true;
2165}
2166
David Sedlák09e18c92019-07-18 11:17:11 +02002167static void
2168test_min_elems_elem(void **state)
2169{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002170 struct test_parser_yin_state *st = *state;
David Sedlák09e18c92019-07-18 11:17:11 +02002171 const char *data;
2172 struct lysp_node_list list = {};
2173 struct lysp_node_leaflist llist = {};
2174 struct lysp_refine refine = {};
2175
David Sedlákd1144562019-08-06 12:36:14 +02002176 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 +01002177 assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002178 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002179 assert_true(refine.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002180 assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002181 assert_int_equal(refine.exts[0].insubstmt_index, 0);
2182 assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2183 FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002184
David Sedlákd1144562019-08-06 12:36:14 +02002185 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 +01002186 assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002187 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002188 assert_true(list.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002189 assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002190 assert_int_equal(list.exts[0].insubstmt_index, 0);
2191 assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2192 FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002193
David Sedlákd1144562019-08-06 12:36:14 +02002194 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 +01002195 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02002196 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002197 assert_true(llist.flags & LYS_SET_MIN);
David Sedláke0ef1c62019-09-13 10:05:55 +02002198 assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002199 assert_int_equal(llist.exts[0].insubstmt_index, 0);
2200 assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
2201 FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02002202
2203 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 +01002204 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002205 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 +02002206
2207 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 +01002208 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002209 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 +02002210
2211 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 +01002212 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002213 logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002214
2215 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 +01002216 assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002217 logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02002218
2219 st->finished_correctly = true;
2220}
2221
David Sedláka2dad212019-07-18 12:45:19 +02002222static void
2223test_ordby_elem(void **state)
2224{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002225 struct test_parser_yin_state *st = *state;
David Sedláka2dad212019-07-18 12:45:19 +02002226 const char *data;
2227 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02002228 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02002229
David Sedlákd1144562019-08-06 12:36:14 +02002230 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002231 assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002232 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláke0ef1c62019-09-13 10:05:55 +02002233 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002234 assert_int_equal(exts[0].insubstmt_index, 0);
2235 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
2236 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02002237
2238 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002239 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002240 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02002241
2242 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002243 assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02002244 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 +02002245
2246 st->finished_correctly = true;
2247}
2248
David Sedlák8a83bbb2019-07-18 14:46:00 +02002249static void
2250test_any_elem(void **state)
2251{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002252 struct test_parser_yin_state *st = *state;
David Sedlák8a83bbb2019-07-18 14:46:00 +02002253 const char *data;
2254 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002255 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02002256 struct lysp_node_anydata *parsed = NULL;
2257
2258 /* anyxml max subelems */
2259 data = ELEMENT_WRAPPER_START
2260 "<anyxml name=\"any-name\">"
2261 "<config value=\"true\" />"
2262 "<description><text>desc</text></description>"
2263 "<if-feature name=\"feature\" />"
2264 "<mandatory value=\"true\" />"
2265 "<must condition=\"must-cond\" />"
2266 "<reference><text>ref</text></reference>"
2267 "<status value=\"deprecated\"/>"
2268 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002269 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002270 "</anyxml>"
2271 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002272 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002273 parsed = (struct lysp_node_anydata *)siblings;
2274 assert_null(parsed->parent);
2275 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002276 assert_true(parsed->flags & LYS_CONFIG_W);
2277 assert_true(parsed->flags & LYS_MAND_TRUE);
2278 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002279 assert_null(parsed->next);
2280 assert_string_equal(parsed->name, "any-name");
2281 assert_string_equal(parsed->dsc, "desc");
2282 assert_string_equal(parsed->ref, "ref");
2283 assert_string_equal(parsed->when->cond, "when-cond");
2284 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002285 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002286 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2287 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002288 lysp_node_free(st->ctx, siblings);
2289 siblings = NULL;
2290
2291 /* anydata max subelems */
2292 data = ELEMENT_WRAPPER_START
2293 "<anydata name=\"any-name\">"
2294 "<config value=\"true\" />"
2295 "<description><text>desc</text></description>"
2296 "<if-feature name=\"feature\" />"
2297 "<mandatory value=\"true\" />"
2298 "<must condition=\"must-cond\" />"
2299 "<reference><text>ref</text></reference>"
2300 "<status value=\"deprecated\"/>"
2301 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002302 EXT_SUBELEM
David Sedlák8a83bbb2019-07-18 14:46:00 +02002303 "</anydata>"
2304 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002305 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002306 parsed = (struct lysp_node_anydata *)siblings;
2307 assert_null(parsed->parent);
2308 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002309 assert_true(parsed->flags & LYS_CONFIG_W);
2310 assert_true(parsed->flags & LYS_MAND_TRUE);
2311 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002312 assert_null(parsed->next);
2313 assert_string_equal(parsed->name, "any-name");
2314 assert_string_equal(parsed->dsc, "desc");
2315 assert_string_equal(parsed->ref, "ref");
2316 assert_string_equal(parsed->when->cond, "when-cond");
2317 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002318 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002319 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2320 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002321 lysp_node_free(st->ctx, siblings);
2322 siblings = NULL;
2323
2324 /* min subelems */
2325 node_meta.parent = (void *)0x10;
2326 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002327 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002328 parsed = (struct lysp_node_anydata *)siblings;
2329 assert_ptr_equal(parsed->parent, node_meta.parent);
2330 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
2331 assert_null(parsed->next);
2332 assert_null(parsed->exts);
2333 lysp_node_free(st->ctx, siblings);
2334
2335 st->finished_correctly = true;
2336}
2337
David Sedlák203ca3a2019-07-18 15:26:25 +02002338static void
2339test_leaf_elem(void **state)
2340{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002341 struct test_parser_yin_state *st = *state;
David Sedlák203ca3a2019-07-18 15:26:25 +02002342 const char *data;
2343 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002344 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002345 struct lysp_node_leaf *parsed = NULL;
2346
2347 /* max elements */
2348 data = ELEMENT_WRAPPER_START
2349 "<leaf name=\"leaf\">"
2350 "<config value=\"true\" />"
2351 "<default value=\"def-val\"/>"
2352 "<description><text>desc</text></description>"
2353 "<if-feature name=\"feature\" />"
2354 "<mandatory value=\"true\" />"
2355 "<must condition=\"must-cond\" />"
2356 "<reference><text>ref</text></reference>"
2357 "<status value=\"deprecated\"/>"
2358 "<type name=\"type\"/>"
2359 "<units name=\"uni\"/>"
2360 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002361 EXT_SUBELEM
David Sedlák203ca3a2019-07-18 15:26:25 +02002362 "</leaf>"
2363 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002364 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002365 parsed = (struct lysp_node_leaf *)siblings;
2366 assert_null(parsed->parent);
2367 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002368 assert_true(parsed->flags & LYS_CONFIG_W);
2369 assert_true(parsed->flags & LYS_MAND_TRUE);
2370 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02002371 assert_null(parsed->next);
2372 assert_string_equal(parsed->name, "leaf");
2373 assert_string_equal(parsed->dsc, "desc");
2374 assert_string_equal(parsed->ref, "ref");
2375 assert_string_equal(parsed->when->cond, "when-cond");
2376 assert_string_equal(*parsed->iffeatures, "feature");
David Sedláke0ef1c62019-09-13 10:05:55 +02002377 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002378 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2379 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák203ca3a2019-07-18 15:26:25 +02002380 assert_string_equal(parsed->musts->arg, "must-cond");
2381 assert_string_equal(parsed->type.name, "type");
2382 assert_string_equal(parsed->units, "uni");
2383 assert_string_equal(parsed->dflt, "def-val");
2384 lysp_node_free(st->ctx, siblings);
2385 siblings = NULL;
2386
2387 /* min elements */
2388 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002389 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002390 parsed = (struct lysp_node_leaf *)siblings;
2391 assert_string_equal(parsed->name, "leaf");
2392 assert_string_equal(parsed->type.name, "type");
2393 lysp_node_free(st->ctx, siblings);
2394 siblings = NULL;
2395
2396 st->finished_correctly = true;
2397}
2398
David Sedlákc3da3ef2019-07-19 12:56:08 +02002399static void
2400test_leaf_list_elem(void **state)
2401{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002402 struct test_parser_yin_state *st = *state;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002403 const char *data;
2404 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002405 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002406 struct lysp_node_leaflist *parsed = NULL;
2407
2408 data = ELEMENT_WRAPPER_START
2409 "<leaf-list name=\"llist\">"
2410 "<config value=\"true\" />"
2411 "<default value=\"def-val0\"/>"
2412 "<default value=\"def-val1\"/>"
2413 "<description><text>desc</text></description>"
2414 "<if-feature name=\"feature\"/>"
2415 "<max-elements value=\"5\"/>"
2416 "<must condition=\"must-cond\"/>"
2417 "<ordered-by value=\"user\" />"
2418 "<reference><text>ref</text></reference>"
2419 "<status value=\"current\"/>"
2420 "<type name=\"type\"/>"
2421 "<units name=\"uni\"/>"
2422 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002423 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002424 "</leaf-list>"
2425 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002426 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002427 parsed = (struct lysp_node_leaflist *)siblings;
2428 assert_string_equal(parsed->dflts[0], "def-val0");
2429 assert_string_equal(parsed->dflts[1], "def-val1");
2430 assert_string_equal(parsed->dsc, "desc");
2431 assert_string_equal(*parsed->iffeatures, "feature");
2432 assert_int_equal(parsed->max, 5);
2433 assert_string_equal(parsed->musts->arg, "must-cond");
2434 assert_string_equal(parsed->name, "llist");
2435 assert_null(parsed->next);
2436 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2437 assert_null(parsed->parent);
2438 assert_string_equal(parsed->ref, "ref");
2439 assert_string_equal(parsed->type.name, "type");
2440 assert_string_equal(parsed->units, "uni");
2441 assert_string_equal(parsed->when->cond, "when-cond");
2442 assert_true(parsed->flags & LYS_CONFIG_W);
2443 assert_true(parsed->flags & LYS_ORDBY_USER);
2444 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002445 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002446 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2447 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002448 lysp_node_free(st->ctx, siblings);
2449 siblings = NULL;
2450
2451 data = ELEMENT_WRAPPER_START
2452 "<leaf-list name=\"llist\">"
2453 "<config value=\"true\" />"
2454 "<description><text>desc</text></description>"
2455 "<if-feature name=\"feature\"/>"
2456 "<min-elements value=\"5\"/>"
2457 "<must condition=\"must-cond\"/>"
2458 "<ordered-by value=\"user\" />"
2459 "<reference><text>ref</text></reference>"
2460 "<status value=\"current\"/>"
2461 "<type name=\"type\"/>"
2462 "<units name=\"uni\"/>"
2463 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002464 EXT_SUBELEM
David Sedlákc3da3ef2019-07-19 12:56:08 +02002465 "</leaf-list>"
2466 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002467 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002468 parsed = (struct lysp_node_leaflist *)siblings;
2469 assert_string_equal(parsed->dsc, "desc");
2470 assert_string_equal(*parsed->iffeatures, "feature");
2471 assert_int_equal(parsed->min, 5);
2472 assert_string_equal(parsed->musts->arg, "must-cond");
2473 assert_string_equal(parsed->name, "llist");
2474 assert_null(parsed->next);
2475 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2476 assert_null(parsed->parent);
2477 assert_string_equal(parsed->ref, "ref");
2478 assert_string_equal(parsed->type.name, "type");
2479 assert_string_equal(parsed->units, "uni");
2480 assert_string_equal(parsed->when->cond, "when-cond");
2481 assert_true(parsed->flags & LYS_CONFIG_W);
2482 assert_true(parsed->flags & LYS_ORDBY_USER);
2483 assert_true(parsed->flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002484 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002485 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2486 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002487 lysp_node_free(st->ctx, siblings);
2488 siblings = NULL;
2489
2490 data = ELEMENT_WRAPPER_START
2491 "<leaf-list name=\"llist\">"
2492 "<config value=\"true\" />"
2493 "<description><text>desc</text></description>"
2494 "<if-feature name=\"feature\"/>"
2495 "<max-elements value=\"15\"/>"
2496 "<min-elements value=\"5\"/>"
2497 "<must condition=\"must-cond\"/>"
2498 "<ordered-by value=\"user\" />"
2499 "<reference><text>ref</text></reference>"
2500 "<status value=\"current\"/>"
2501 "<type name=\"type\"/>"
2502 "<units name=\"uni\"/>"
2503 "<when condition=\"when-cond\"/>"
2504 "</leaf-list>"
2505 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002506 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002507 parsed = (struct lysp_node_leaflist *)siblings;
2508 assert_string_equal(parsed->dsc, "desc");
2509 assert_string_equal(*parsed->iffeatures, "feature");
2510 assert_int_equal(parsed->min, 5);
2511 assert_int_equal(parsed->max, 15);
2512 assert_string_equal(parsed->musts->arg, "must-cond");
2513 assert_string_equal(parsed->name, "llist");
2514 assert_null(parsed->next);
2515 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2516 assert_null(parsed->parent);
2517 assert_string_equal(parsed->ref, "ref");
2518 assert_string_equal(parsed->type.name, "type");
2519 assert_string_equal(parsed->units, "uni");
2520 assert_string_equal(parsed->when->cond, "when-cond");
2521 assert_true(parsed->flags & LYS_CONFIG_W);
2522 assert_true(parsed->flags & LYS_ORDBY_USER);
2523 assert_true(parsed->flags & LYS_STATUS_CURR);
2524 lysp_node_free(st->ctx, siblings);
2525 siblings = NULL;
2526
2527 data = ELEMENT_WRAPPER_START
2528 "<leaf-list name=\"llist\">"
2529 "<type name=\"type\"/>"
2530 "</leaf-list>"
2531 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002532 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002533 parsed = (struct lysp_node_leaflist *)siblings;
2534 assert_string_equal(parsed->name, "llist");
2535 assert_string_equal(parsed->type.name, "type");
2536 lysp_node_free(st->ctx, siblings);
2537 siblings = NULL;
2538
2539 /* invalid combinations */
2540 data = ELEMENT_WRAPPER_START
2541 "<leaf-list name=\"llist\">"
2542 "<max-elements value=\"5\"/>"
2543 "<min-elements value=\"15\"/>"
2544 "<type name=\"type\"/>"
2545 "</leaf-list>"
2546 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002547 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002548 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2549 lysp_node_free(st->ctx, siblings);
2550 siblings = NULL;
2551
2552 data = ELEMENT_WRAPPER_START
2553 "<leaf-list name=\"llist\">"
2554 "<default value=\"def-val1\"/>"
2555 "<min-elements value=\"15\"/>"
2556 "<type name=\"type\"/>"
2557 "</leaf-list>"
2558 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002559 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002560 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 +02002561 lysp_node_free(st->ctx, siblings);
2562 siblings = NULL;
2563
2564 data = ELEMENT_WRAPPER_START
2565 "<leaf-list name=\"llist\">"
2566 "</leaf-list>"
2567 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002568 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02002569 logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002570 lysp_node_free(st->ctx, siblings);
2571 siblings = NULL;
2572
2573 st->finished_correctly = true;
2574}
2575
David Sedlákcb39f642019-07-19 13:19:55 +02002576static void
2577test_presence_elem(void **state)
2578{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002579 struct test_parser_yin_state *st = *state;
David Sedlákcb39f642019-07-19 13:19:55 +02002580 const char *data;
2581 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002582 struct lysp_ext_instance *exts = NULL;
2583
2584 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002585 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002586 assert_string_equal(val, "presence-val");
David Sedláke0ef1c62019-09-13 10:05:55 +02002587 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002588 assert_int_equal(exts[0].insubstmt_index, 0);
2589 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
2590 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2591 FREE_STRING(st->ctx, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002592
2593 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002594 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002595 assert_string_equal(val, "presence-val");
2596 FREE_STRING(st->ctx, val);
2597
2598 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002599 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlákcb39f642019-07-19 13:19:55 +02002600 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2601
2602 st->finished_correctly = true;
2603}
2604
David Sedlák12470a82019-07-19 13:44:36 +02002605static void
2606test_key_elem(void **state)
2607{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002608 struct test_parser_yin_state *st = *state;
David Sedlák12470a82019-07-19 13:44:36 +02002609 const char *data;
2610 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002611 struct lysp_ext_instance *exts = NULL;
2612
2613 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002614 assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002615 assert_string_equal(val, "key-value");
David Sedláke0ef1c62019-09-13 10:05:55 +02002616 assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002617 assert_int_equal(exts[0].insubstmt_index, 0);
2618 assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
2619 FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
2620 FREE_STRING(st->ctx, val);
David Sedlák12470a82019-07-19 13:44:36 +02002621
2622 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002623 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002624 assert_string_equal(val, "key-value");
2625 FREE_STRING(st->ctx, val);
2626
2627 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002628 assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
David Sedlák12470a82019-07-19 13:44:36 +02002629 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2630
2631 st->finished_correctly = true;
2632}
2633
David Sedlák04e17b22019-07-19 15:29:48 +02002634static void
2635test_typedef_elem(void **state)
2636{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002637 struct test_parser_yin_state *st = *state;
David Sedlák04e17b22019-07-19 15:29:48 +02002638 const char *data;
2639 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002640 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002641
2642 data = ELEMENT_WRAPPER_START
2643 "<typedef name=\"tpdf-name\">"
2644 "<default value=\"def-val\"/>"
2645 "<description><text>desc-text</text></description>"
2646 "<reference><text>ref-text</text></reference>"
2647 "<status value=\"current\"/>"
2648 "<type name=\"type\"/>"
2649 "<units name=\"uni\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002650 EXT_SUBELEM
David Sedlák04e17b22019-07-19 15:29:48 +02002651 "</typedef>"
2652 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002653 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002654 assert_string_equal(tpdfs[0].dflt, "def-val");
2655 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002656 assert_string_equal(tpdfs[0].name, "tpdf-name");
2657 assert_string_equal(tpdfs[0].ref, "ref-text");
2658 assert_string_equal(tpdfs[0].type.name, "type");
2659 assert_string_equal(tpdfs[0].units, "uni");
2660 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
David Sedláke0ef1c62019-09-13 10:05:55 +02002661 assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002662 assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
2663 assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák04e17b22019-07-19 15:29:48 +02002664 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2665 tpdfs = NULL;
2666
2667 data = ELEMENT_WRAPPER_START
2668 "<typedef name=\"tpdf-name\">"
2669 "<type name=\"type\"/>"
2670 "</typedef>"
2671 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002672 assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002673 assert_string_equal(tpdfs[0].name, "tpdf-name");
2674 assert_string_equal(tpdfs[0].type.name, "type");
2675 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2676 tpdfs = NULL;
2677
2678 st->finished_correctly = true;
2679}
2680
David Sedlákd2d676a2019-07-22 11:28:19 +02002681static void
2682test_refine_elem(void **state)
2683{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002684 struct test_parser_yin_state *st = *state;
David Sedlákd2d676a2019-07-22 11:28:19 +02002685 const char *data;
2686 struct lysp_refine *refines = NULL;
2687
2688 /* max subelems */
2689 data = ELEMENT_WRAPPER_START
2690 "<refine target-node=\"target\">"
2691 "<if-feature name=\"feature\" />"
2692 "<must condition=\"cond\" />"
2693 "<presence value=\"presence\" />"
2694 "<default value=\"def\" />"
2695 "<config value=\"true\" />"
2696 "<mandatory value=\"true\" />"
2697 "<min-elements value=\"10\" />"
2698 "<max-elements value=\"20\" />"
2699 "<description><text>desc</text></description>"
2700 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002701 EXT_SUBELEM
David Sedlákd2d676a2019-07-22 11:28:19 +02002702 "</refine>"
2703 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002704 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002705 assert_string_equal(refines->nodeid, "target");
2706 assert_string_equal(*refines->dflts, "def");
2707 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002708 assert_true(refines->flags & LYS_CONFIG_W);
2709 assert_true(refines->flags & LYS_MAND_TRUE);
2710 assert_string_equal(*refines->iffeatures, "feature");
2711 assert_int_equal(refines->max, 20);
2712 assert_int_equal(refines->min, 10);
2713 assert_string_equal(refines->musts->arg, "cond");
2714 assert_string_equal(refines->presence, "presence");
2715 assert_string_equal(refines->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002716 assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002717 assert_int_equal(refines->exts[0].insubstmt_index, 0);
2718 assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákd2d676a2019-07-22 11:28:19 +02002719 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2720 refines = NULL;
2721
2722 /* min subelems */
2723 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002724 assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002725 assert_string_equal(refines->nodeid, "target");
2726 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2727 refines = NULL;
2728
2729 st->finished_correctly = true;
2730}
2731
David Sedlák0d6de5a2019-07-22 13:25:44 +02002732static void
2733test_uses_elem(void **state)
2734{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002735 struct test_parser_yin_state *st = *state;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002736 const char *data;
2737 struct lysp_node *siblings = NULL;
2738 struct tree_node_meta node_meta = {NULL, &siblings};
2739 struct lysp_node_uses *parsed = NULL;
2740
2741 /* max subelems */
2742 data = ELEMENT_WRAPPER_START
2743 "<uses name=\"uses-name\">"
2744 "<when condition=\"cond\" />"
2745 "<if-feature name=\"feature\" />"
2746 "<status value=\"obsolete\" />"
2747 "<description><text>desc</text></description>"
2748 "<reference><text>ref</text></reference>"
2749 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002750 "<augment target-node=\"target\" />"
David Sedlákd1144562019-08-06 12:36:14 +02002751 EXT_SUBELEM
David Sedlák0d6de5a2019-07-22 13:25:44 +02002752 "</uses>"
2753 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002754 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002755 parsed = (struct lysp_node_uses *)&siblings[0];
2756 assert_string_equal(parsed->name, "uses-name");
2757 assert_string_equal(parsed->dsc, "desc");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002758 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2759 assert_string_equal(*parsed->iffeatures, "feature");
2760 assert_null(parsed->next);
2761 assert_int_equal(parsed->nodetype, LYS_USES);
2762 assert_null(parsed->parent);
2763 assert_string_equal(parsed->ref, "ref");
2764 assert_string_equal(parsed->refines->nodeid, "target");
2765 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002766 assert_string_equal(parsed->augments->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02002767 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002768 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2769 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002770 lysp_node_free(st->ctx, siblings);
2771 siblings = NULL;
2772
2773 /* min subelems */
2774 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002775 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002776 assert_string_equal(siblings[0].name, "uses-name");
2777 lysp_node_free(st->ctx, siblings);
2778 siblings = NULL;
2779
2780 st->finished_correctly = true;
2781}
2782
David Sedlákaa854b02019-07-22 14:17:10 +02002783static void
2784test_revision_elem(void **state)
2785{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002786 struct test_parser_yin_state *st = *state;
David Sedlákaa854b02019-07-22 14:17:10 +02002787 const char *data;
2788 struct lysp_revision *revs = NULL;
2789
2790 /* max subelems */
2791 data = ELEMENT_WRAPPER_START
2792 "<revision date=\"2018-12-25\">"
2793 "<description><text>desc</text></description>"
2794 "<reference><text>ref</text></reference>"
David Sedlákd1144562019-08-06 12:36:14 +02002795 EXT_SUBELEM
David Sedlákaa854b02019-07-22 14:17:10 +02002796 "</revision>"
2797 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002798 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002799 assert_string_equal(revs->date, "2018-12-25");
2800 assert_string_equal(revs->dsc, "desc");
2801 assert_string_equal(revs->ref, "ref");
David Sedláke0ef1c62019-09-13 10:05:55 +02002802 assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002803 assert_int_equal(revs->exts[0].insubstmt_index, 0);
2804 assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaa854b02019-07-22 14:17:10 +02002805 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2806 revs = NULL;
2807
2808 /* min subelems */
2809 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002810 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002811 assert_string_equal(revs->date, "2005-05-05");
2812 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2813 revs = NULL;
2814
2815 /* invalid value */
2816 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002817 assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID);
David Sedlákaa854b02019-07-22 14:17:10 +02002818 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2819 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2820 revs = NULL;
2821
2822 st->finished_correctly = true;
2823}
2824
David Sedlák0c2bab92019-07-22 15:33:19 +02002825static void
2826test_include_elem(void **state)
2827{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002828 struct test_parser_yin_state *st = *state;
David Sedlák0c2bab92019-07-22 15:33:19 +02002829 const char *data;
2830 struct lysp_include *includes = NULL;
2831 struct include_meta inc_meta = {"module-name", &includes};
2832
2833 /* max subelems */
2834 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2835 data = ELEMENT_WRAPPER_START
2836 "<include module=\"mod\">"
2837 "<description><text>desc</text></description>"
2838 "<reference><text>ref</text></reference>"
2839 "<revision-date date=\"1999-09-09\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002840 EXT_SUBELEM
David Sedlák0c2bab92019-07-22 15:33:19 +02002841 "</include>"
2842 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002843 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002844 assert_string_equal(includes->name, "mod");
2845 assert_string_equal(includes->dsc, "desc");
2846 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002847 assert_string_equal(includes->rev, "1999-09-09");
David Sedláke0ef1c62019-09-13 10:05:55 +02002848 assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002849 assert_int_equal(includes->exts[0].insubstmt_index, 0);
2850 assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák0c2bab92019-07-22 15:33:19 +02002851 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2852 includes = NULL;
2853
2854 /* min subelems */
2855 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002856 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002857 assert_string_equal(includes->name, "mod");
2858 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2859 includes = NULL;
2860
2861 /* invalid combinations */
2862 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2863 data = ELEMENT_WRAPPER_START
2864 "<include module=\"mod\">"
2865 "<description><text>desc</text></description>"
2866 "<revision-date date=\"1999-09-09\"/>"
2867 "</include>"
2868 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002869 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002870 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.");
2871 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2872 includes = NULL;
2873
2874 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2875 data = ELEMENT_WRAPPER_START
2876 "<include module=\"mod\">"
2877 "<reference><text>ref</text></reference>"
2878 "<revision-date date=\"1999-09-09\"/>"
2879 "</include>"
2880 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002881 assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
David Sedlák0c2bab92019-07-22 15:33:19 +02002882 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.");
2883 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2884 includes = NULL;
2885
2886 st->finished_correctly = true;
2887}
2888
David Sedlák5e13dea2019-07-22 16:06:45 +02002889static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002890test_list_elem(void **state)
2891{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002892 struct test_parser_yin_state *st = *state;
David Sedlákaf536aa2019-07-23 13:42:23 +02002893 const char *data;
2894 struct lysp_node *siblings = NULL;
2895 struct tree_node_meta node_meta = {NULL, &siblings};
2896 struct lysp_node_list *parsed = NULL;
2897
2898 /* max subelems */
2899 data = ELEMENT_WRAPPER_START
2900 "<list name=\"list-name\">"
2901 "<when condition=\"when\"/>"
2902 "<if-feature name=\"iff\"/>"
2903 "<must condition=\"must-cond\"/>"
2904 "<key value=\"key\"/>"
2905 "<unique tag=\"utag\"/>"
2906 "<config value=\"true\"/>"
2907 "<min-elements value=\"10\"/>"
2908 "<ordered-by value=\"user\"/>"
2909 "<status value=\"deprecated\"/>"
2910 "<description><text>desc</text></description>"
2911 "<reference><text>ref</text></reference>"
2912 "<anydata name=\"anyd\"/>"
2913 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002914 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002915 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002916 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002917 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002918 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002919 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2920 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002921 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002922 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002923 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02002924 EXT_SUBELEM
David Sedlákaf536aa2019-07-23 13:42:23 +02002925 "</list>"
2926 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002927 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002928 parsed = (struct lysp_node_list *)&siblings[0];
2929 assert_string_equal(parsed->dsc, "desc");
2930 assert_string_equal(parsed->child->name, "anyd");
2931 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2932 assert_string_equal(parsed->child->next->name, "anyx");
2933 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002934 assert_string_equal(parsed->child->next->next->name, "cont");
2935 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002936 assert_string_equal(parsed->child->next->next->next->name, "choice");
2937 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002938 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2939 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2940 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2941 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2942 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2943 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2944 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2945 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2946 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002947 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002948 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002949 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002950 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02002951 assert_true(parsed->flags & LYS_ORDBY_USER);
2952 assert_true(parsed->flags & LYS_STATUS_DEPRC);
2953 assert_true(parsed->flags & LYS_CONFIG_W);
2954 assert_string_equal(*parsed->iffeatures, "iff");
2955 assert_string_equal(parsed->key, "key");
2956 assert_int_equal(parsed->min, 10);
2957 assert_string_equal(parsed->musts->arg, "must-cond");
2958 assert_string_equal(parsed->name, "list-name");
2959 assert_null(parsed->next);
2960 assert_int_equal(parsed->nodetype, LYS_LIST);
2961 assert_null(parsed->parent);
2962 assert_string_equal(parsed->ref, "ref");
2963 assert_string_equal(parsed->typedefs->name, "tpdf");
2964 assert_string_equal(*parsed->uniques, "utag");
2965 assert_string_equal(parsed->when->cond, "when");
David Sedláke0ef1c62019-09-13 10:05:55 +02002966 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02002967 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
2968 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákaf536aa2019-07-23 13:42:23 +02002969 lysp_node_free(st->ctx, siblings);
2970 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2971 siblings = NULL;
2972
2973 /* min subelems */
2974 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01002975 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002976 parsed = (struct lysp_node_list *)&siblings[0];
2977 assert_string_equal(parsed->name, "list-name");
2978 lysp_node_free(st->ctx, siblings);
2979 siblings = NULL;
2980
2981 st->finished_correctly = true;
2982}
2983
David Sedlák031b9e72019-07-23 15:19:37 +02002984static void
2985test_notification_elem(void **state)
2986{
Radek Krejci3a4889a2020-05-19 17:01:58 +02002987 struct test_parser_yin_state *st = *state;
David Sedlák031b9e72019-07-23 15:19:37 +02002988 const char *data;
2989 struct lysp_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002990 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002991
2992 /* max subelems */
2993 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2994 data = ELEMENT_WRAPPER_START
2995 "<notification name=\"notif-name\">"
2996 "<anydata name=\"anyd\"/>"
2997 "<anyxml name=\"anyx\"/>"
2998 "<description><text>desc</text></description>"
2999 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003000 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3001 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02003002 "<list name=\"sub-list\"/>"
3003 "<must condition=\"cond\"/>"
3004 "<reference><text>ref</text></reference>"
3005 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003006 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02003007 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003008 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003009 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003010 "<grouping name=\"grp\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003011 EXT_SUBELEM
David Sedlák031b9e72019-07-23 15:19:37 +02003012 "</notification>"
3013 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003014 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003015 assert_string_equal(notifs->name, "notif-name");
3016 assert_string_equal(notifs->data->name, "anyd");
3017 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
3018 assert_string_equal(notifs->data->next->name, "anyx");
3019 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
3020 assert_string_equal(notifs->data->next->next->name, "leaf");
3021 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
3022 assert_string_equal(notifs->data->next->next->next->name, "llist");
3023 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
3024 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
3025 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02003026 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003027 assert_string_equal(notifs->groupings->name, "grp");
3028 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02003029 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
3030 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
3031 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
3032 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003033 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3034 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
3035 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02003036 assert_string_equal(*notifs->iffeatures, "iff");
3037 assert_string_equal(notifs->musts->arg, "cond");
3038 assert_int_equal(notifs->nodetype, LYS_NOTIF);
3039 assert_null(notifs->parent);
3040 assert_string_equal(notifs->ref, "ref");
3041 assert_string_equal(notifs->typedefs->name, "tpdf");
David Sedláke0ef1c62019-09-13 10:05:55 +02003042 assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003043 assert_int_equal(notifs->exts[0].insubstmt_index, 0);
3044 assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák031b9e72019-07-23 15:19:37 +02003045 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
3046 notifs = NULL;
3047
3048 /* min subelems */
3049 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003050 assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02003051 assert_string_equal(notifs->name, "notif-name");
3052 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003053 notifs = NULL;
3054
3055 st->finished_correctly = true;
3056}
3057
3058static void
3059test_grouping_elem(void **state)
3060{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003061 struct test_parser_yin_state *st = *state;
David Sedláke3ce9ef2019-07-23 16:34:30 +02003062 const char *data;
3063 struct lysp_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003064 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02003065
3066 /* max subelems */
3067 data = ELEMENT_WRAPPER_START
3068 "<grouping name=\"grp-name\">"
3069 "<anydata name=\"anyd\"/>"
3070 "<anyxml name=\"anyx\"/>"
3071 "<description><text>desc</text></description>"
3072 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003073 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3074 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003075 "<list name=\"list\"/>"
3076 "<notification name=\"notf\"/>"
3077 "<reference><text>ref</text></reference>"
3078 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003079 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02003080 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003081 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02003082 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003083 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003084 EXT_SUBELEM
David Sedláke3ce9ef2019-07-23 16:34:30 +02003085 "</grouping>"
3086 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003087 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003088 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003089 assert_string_equal(grps->data->name, "anyd");
3090 assert_string_equal(grps->data->next->name, "anyx");
3091 assert_string_equal(grps->data->next->next->name, "leaf");
3092 assert_string_equal(grps->data->next->next->next->name, "llist");
3093 assert_string_equal(grps->data->next->next->next->next->name, "list");
3094 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02003095 assert_true(grps->flags & LYS_STATUS_CURR);
3096 assert_string_equal(grps->groupings->name, "sub-grp");
3097 assert_int_equal(grps->nodetype, LYS_GROUPING);
3098 assert_string_equal(grps->notifs->name, "notf");
3099 assert_null(grps->parent);
3100 assert_string_equal(grps->ref, "ref");
3101 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003102 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02003103 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003104 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02003105 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003106 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
3107 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
3108 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke0ef1c62019-09-13 10:05:55 +02003109 assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003110 assert_int_equal(grps->exts[0].insubstmt_index, 0);
3111 assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003112 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3113 grps = NULL;
3114
3115 /* min subelems */
3116 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003117 assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02003118 assert_string_equal(grps->name, "grp-name");
3119 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
3120 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02003121
3122 st->finished_correctly = true;
3123}
3124
David Sedlákf111bcb2019-07-23 17:15:51 +02003125static void
3126test_container_elem(void **state)
3127{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003128 struct test_parser_yin_state *st = *state;
David Sedlákf111bcb2019-07-23 17:15:51 +02003129 const char *data;
3130 struct lysp_node *siblings = NULL;
3131 struct tree_node_meta node_meta = {NULL, &siblings};
3132 struct lysp_node_container *parsed = NULL;
3133
3134 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02003135 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3136 data = ELEMENT_WRAPPER_START
3137 "<container name=\"cont-name\">"
3138 "<anydata name=\"anyd\"/>"
3139 "<anyxml name=\"anyx\"/>"
3140 "<config value=\"true\"/>"
3141 "<container name=\"subcont\"/>"
3142 "<description><text>desc</text></description>"
3143 "<grouping name=\"sub-grp\"/>"
3144 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003145 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3146 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003147 "<list name=\"list\"/>"
3148 "<must condition=\"cond\"/>"
3149 "<notification name=\"notf\"/>"
3150 "<presence value=\"presence\"/>"
3151 "<reference><text>ref</text></reference>"
3152 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003153 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02003154 "<uses name=\"uses-name\"/>"
3155 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003156 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003157 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003158 EXT_SUBELEM
David Sedláke2dc9e92019-07-24 09:59:21 +02003159 "</container>"
3160 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003161 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02003162 parsed = (struct lysp_node_container *)siblings;
3163 assert_string_equal(parsed->name, "cont-name");
3164 assert_null(parsed->parent);
3165 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
3166 assert_true(parsed->flags & LYS_CONFIG_W);
3167 assert_true(parsed->flags & LYS_STATUS_CURR);
3168 assert_null(parsed->next);
3169 assert_string_equal(parsed->dsc, "desc");
3170 assert_string_equal(parsed->ref, "ref");
3171 assert_string_equal(parsed->when->cond, "when-cond");
3172 assert_string_equal(*parsed->iffeatures, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02003173 assert_string_equal(parsed->musts->arg, "cond");
3174 assert_string_equal(parsed->presence, "presence");
3175 assert_string_equal(parsed->typedefs->name, "tpdf");
3176 assert_string_equal(parsed->groupings->name, "sub-grp");
3177 assert_string_equal(parsed->child->name, "anyd");
3178 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3179 assert_string_equal(parsed->child->next->name, "anyx");
3180 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3181 assert_string_equal(parsed->child->next->next->name, "subcont");
3182 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3183 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3184 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3185 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3186 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3187 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3188 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3189 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3190 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003191 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3192 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3193 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02003194 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02003195 assert_string_equal(parsed->actions->name, "act");
David Sedláke0ef1c62019-09-13 10:05:55 +02003196 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003197 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3198 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedláke2dc9e92019-07-24 09:59:21 +02003199 lysp_node_free(st->ctx, siblings);
3200 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
3201 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02003202
3203 /* min subelems */
3204 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003205 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02003206 parsed = (struct lysp_node_container *)siblings;
3207 assert_string_equal(parsed->name, "cont-name");
3208 lysp_node_free(st->ctx, siblings);
3209 siblings = NULL;
3210
3211 st->finished_correctly = true;
3212}
3213
David Sedlák5379d392019-07-24 10:42:03 +02003214static void
3215test_case_elem(void **state)
3216{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003217 struct test_parser_yin_state *st = *state;
David Sedlák5379d392019-07-24 10:42:03 +02003218 const char *data;
3219 struct lysp_node *siblings = NULL;
3220 struct tree_node_meta node_meta = {NULL, &siblings};
3221 struct lysp_node_case *parsed = NULL;
3222
3223 /* max subelems */
3224 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3225 data = ELEMENT_WRAPPER_START
3226 "<case name=\"case-name\">"
3227 "<anydata name=\"anyd\"/>"
3228 "<anyxml name=\"anyx\"/>"
3229 "<container name=\"subcont\"/>"
3230 "<description><text>desc</text></description>"
3231 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003232 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3233 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02003234 "<list name=\"list\"/>"
3235 "<reference><text>ref</text></reference>"
3236 "<status value=\"current\"/>"
3237 "<uses name=\"uses-name\"/>"
3238 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003239 "<choice name=\"choice\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003240 EXT_SUBELEM
David Sedlák5379d392019-07-24 10:42:03 +02003241 "</case>"
3242 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003243 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003244 parsed = (struct lysp_node_case *)siblings;
3245 assert_string_equal(parsed->name, "case-name");
3246 assert_null(parsed->parent);
3247 assert_int_equal(parsed->nodetype, LYS_CASE);
3248 assert_true(parsed->flags & LYS_STATUS_CURR);
3249 assert_null(parsed->next);
3250 assert_string_equal(parsed->dsc, "desc");
3251 assert_string_equal(parsed->ref, "ref");
3252 assert_string_equal(parsed->when->cond, "when-cond");
3253 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02003254 assert_string_equal(parsed->child->name, "anyd");
3255 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3256 assert_string_equal(parsed->child->next->name, "anyx");
3257 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3258 assert_string_equal(parsed->child->next->next->name, "subcont");
3259 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
3260 assert_string_equal(parsed->child->next->next->next->name, "leaf");
3261 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
3262 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
3263 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
3264 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
3265 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
3266 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
3267 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003268 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
3269 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
3270 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003271 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003272 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3273 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák5379d392019-07-24 10:42:03 +02003274 lysp_node_free(st->ctx, siblings);
3275 siblings = NULL;
3276
3277 /* min subelems */
3278 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003279 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02003280 parsed = (struct lysp_node_case *)siblings;
3281 assert_string_equal(parsed->name, "case-name");
3282 lysp_node_free(st->ctx, siblings);
3283 siblings = NULL;
3284
3285 st->finished_correctly = true;
3286}
3287
David Sedlákb7abcfa2019-07-24 12:33:35 +02003288static void
3289test_choice_elem(void **state)
3290{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003291 struct test_parser_yin_state *st = *state;
David Sedlákb7abcfa2019-07-24 12:33:35 +02003292 const char *data;
3293 struct lysp_node *siblings = NULL;
3294 struct tree_node_meta node_meta = {NULL, &siblings};
3295 struct lysp_node_choice *parsed = NULL;
3296
3297 /* max subelems */
3298 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3299 data = ELEMENT_WRAPPER_START
3300 "<choice name=\"choice-name\">"
3301 "<anydata name=\"anyd\"/>"
3302 "<anyxml name=\"anyx\"/>"
3303 "<case name=\"sub-case\"/>"
3304 "<choice name=\"choice\"/>"
3305 "<config value=\"true\"/>"
3306 "<container name=\"subcont\"/>"
3307 "<default value=\"def\"/>"
3308 "<description><text>desc</text></description>"
3309 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003310 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3311 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02003312 "<list name=\"list\"/>"
3313 "<mandatory value=\"true\" />"
3314 "<reference><text>ref</text></reference>"
3315 "<status value=\"current\"/>"
3316 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003317 EXT_SUBELEM
David Sedlákb7abcfa2019-07-24 12:33:35 +02003318 "</choice>"
3319 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003320 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003321 parsed = (struct lysp_node_choice *)siblings;
3322 assert_string_equal(parsed->name, "choice-name");
3323 assert_null(parsed->parent);
3324 assert_int_equal(parsed->nodetype, LYS_CHOICE);
3325 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
3326 assert_null(parsed->next);
3327 assert_string_equal(parsed->dsc, "desc");
3328 assert_string_equal(parsed->ref, "ref");
3329 assert_string_equal(parsed->when->cond, "when-cond");
3330 assert_string_equal(*parsed->iffeatures, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02003331 assert_string_equal(parsed->child->name, "anyd");
3332 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
3333 assert_string_equal(parsed->child->next->name, "anyx");
3334 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
3335 assert_string_equal(parsed->child->next->next->name, "sub-case");
3336 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
3337 assert_string_equal(parsed->child->next->next->next->name, "choice");
3338 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
3339 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
3340 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
3341 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
3342 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
3343 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
3344 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3345 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
3346 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3347 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003348 assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003349 assert_int_equal(parsed->exts[0].insubstmt_index, 0);
3350 assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003351 lysp_node_free(st->ctx, siblings);
3352 siblings = NULL;
3353
3354 /* min subelems */
3355 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003356 assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02003357 parsed = (struct lysp_node_choice *)siblings;
3358 assert_string_equal(parsed->name, "choice-name");
3359 lysp_node_free(st->ctx, siblings);
3360 siblings = NULL;
3361
3362 st->finished_correctly = true;
3363}
3364
David Sedlák05404f62019-07-24 14:11:53 +02003365static void
3366test_inout_elem(void **state)
3367{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003368 struct test_parser_yin_state *st = *state;
David Sedlák05404f62019-07-24 14:11:53 +02003369 const char *data;
3370 struct lysp_action_inout inout = {};
3371 struct inout_meta inout_meta = {NULL, &inout};
3372
3373 /* max subelements */
3374 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3375 data = ELEMENT_WRAPPER_START
3376 "<input>"
3377 "<anydata name=\"anyd\"/>"
3378 "<anyxml name=\"anyx\"/>"
3379 "<choice name=\"choice\"/>"
3380 "<container name=\"subcont\"/>"
3381 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003382 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3383 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003384 "<list name=\"list\"/>"
3385 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003386 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003387 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003388 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003389 "</input>"
3390 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003391 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003392 assert_null(inout.parent);
3393 assert_int_equal(inout.nodetype, LYS_INPUT);
3394 assert_string_equal(inout.musts->arg, "cond");
3395 assert_string_equal(inout.typedefs->name, "tpdf");
3396 assert_string_equal(inout.groupings->name, "sub-grp");
3397 assert_string_equal(inout.data->name, "anyd");
3398 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3399 assert_string_equal(inout.data->next->name, "anyx");
3400 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3401 assert_string_equal(inout.data->next->next->name, "choice");
3402 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3403 assert_string_equal(inout.data->next->next->next->name, "subcont");
3404 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3405 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3406 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3407 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3408 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3409 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3410 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3411 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3412 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3413 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003414 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003415 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3416 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003417 lysp_action_inout_free(st->ctx, &inout);
3418 memset(&inout, 0, sizeof inout);
3419
3420 /* max subelements */
3421 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3422 data = ELEMENT_WRAPPER_START
3423 "<output>"
3424 "<anydata name=\"anyd\"/>"
3425 "<anyxml name=\"anyx\"/>"
3426 "<choice name=\"choice\"/>"
3427 "<container name=\"subcont\"/>"
3428 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003429 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3430 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003431 "<list name=\"list\"/>"
3432 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003433 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003434 "<uses name=\"uses-name\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003435 EXT_SUBELEM
David Sedlák05404f62019-07-24 14:11:53 +02003436 "</output>"
3437 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003438 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
David Sedlák05404f62019-07-24 14:11:53 +02003439 assert_null(inout.parent);
3440 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3441 assert_string_equal(inout.musts->arg, "cond");
3442 assert_string_equal(inout.typedefs->name, "tpdf");
3443 assert_string_equal(inout.groupings->name, "sub-grp");
3444 assert_string_equal(inout.data->name, "anyd");
3445 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3446 assert_string_equal(inout.data->next->name, "anyx");
3447 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3448 assert_string_equal(inout.data->next->next->name, "choice");
3449 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3450 assert_string_equal(inout.data->next->next->next->name, "subcont");
3451 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3452 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3453 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3454 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3455 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3456 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3457 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3458 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3459 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3460 assert_null(inout.data->next->next->next->next->next->next->next->next);
David Sedláke0ef1c62019-09-13 10:05:55 +02003461 assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003462 assert_int_equal(inout.exts[0].insubstmt_index, 0);
3463 assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák05404f62019-07-24 14:11:53 +02003464 lysp_action_inout_free(st->ctx, &inout);
3465 memset(&inout, 0, sizeof inout);
3466
3467 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003468 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003469 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003470 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003471 memset(&inout, 0, sizeof inout);
3472
Michal Vaskob83af8a2020-01-06 09:49:22 +01003473 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003474 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Michal Vaskob83af8a2020-01-06 09:49:22 +01003475 lysp_action_inout_free(st->ctx, &inout);
David Sedlák05404f62019-07-24 14:11:53 +02003476 memset(&inout, 0, sizeof inout);
3477
3478 /* invalid combinations */
3479 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003480 assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID);
David Sedlák1538a842019-08-08 15:38:51 +02003481 logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003482 memset(&inout, 0, sizeof inout);
3483
3484 st->finished_correctly = true;
3485}
3486
David Sedlák85d0eca2019-07-24 15:15:21 +02003487static void
3488test_action_elem(void **state)
3489{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003490 struct test_parser_yin_state *st = *state;
David Sedlák85d0eca2019-07-24 15:15:21 +02003491 const char *data;
3492 struct lysp_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003493 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
David Sedlák85d0eca2019-07-24 15:15:21 +02003494
3495 /* max subelems */
3496 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3497 data = ELEMENT_WRAPPER_START
3498 "<action name=\"act\">"
3499 "<description><text>desc</text></description>"
3500 "<grouping name=\"grouping\"/>"
3501 "<if-feature name=\"iff\"/>"
3502 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003503 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003504 "<reference><text>ref</text></reference>"
3505 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003506 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003507 EXT_SUBELEM
David Sedlák85d0eca2019-07-24 15:15:21 +02003508 "</action>"
3509 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003510 /* there must be parent for action */
3511 act_meta.parent = NULL + 1;
Michal Vaskob36053d2020-03-26 15:49:30 +01003512 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003513 act_meta.parent = NULL;
3514 assert_non_null(actions->parent);
David Sedlák85d0eca2019-07-24 15:15:21 +02003515 assert_int_equal(actions->nodetype, LYS_ACTION);
3516 assert_true(actions->flags & LYS_STATUS_DEPRC);
3517 assert_string_equal(actions->name, "act");
3518 assert_string_equal(actions->dsc, "desc");
3519 assert_string_equal(actions->ref, "ref");
3520 assert_string_equal(*actions->iffeatures, "iff");
3521 assert_string_equal(actions->typedefs->name, "tpdf");
3522 assert_string_equal(actions->groupings->name, "grouping");
3523 assert_string_equal(actions->input.data->name, "uses-name");
3524 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003525 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003526 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3527 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák85d0eca2019-07-24 15:15:21 +02003528 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3529 actions = NULL;
3530
David Sedlákeaa45792019-07-24 15:25:01 +02003531 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3532 data = ELEMENT_WRAPPER_START
3533 "<rpc name=\"act\">"
3534 "<description><text>desc</text></description>"
3535 "<grouping name=\"grouping\"/>"
3536 "<if-feature name=\"iff\"/>"
3537 "<input><uses name=\"uses-name\"/></input>"
Michal Vaskob83af8a2020-01-06 09:49:22 +01003538 "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>"
David Sedlákeaa45792019-07-24 15:25:01 +02003539 "<reference><text>ref</text></reference>"
3540 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003541 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákd1144562019-08-06 12:36:14 +02003542 EXT_SUBELEM
David Sedlákeaa45792019-07-24 15:25:01 +02003543 "</rpc>"
3544 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003545 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlákeaa45792019-07-24 15:25:01 +02003546 assert_null(actions->parent);
Michal Vasko1bf09392020-03-27 12:38:10 +01003547 assert_int_equal(actions->nodetype, LYS_RPC);
David Sedlákeaa45792019-07-24 15:25:01 +02003548 assert_true(actions->flags & LYS_STATUS_DEPRC);
3549 assert_string_equal(actions->name, "act");
3550 assert_string_equal(actions->dsc, "desc");
3551 assert_string_equal(actions->ref, "ref");
3552 assert_string_equal(*actions->iffeatures, "iff");
3553 assert_string_equal(actions->typedefs->name, "tpdf");
3554 assert_string_equal(actions->groupings->name, "grouping");
3555 assert_string_equal(actions->input.data->name, "uses-name");
3556 assert_string_equal(actions->output.musts->arg, "cond");
David Sedláke0ef1c62019-09-13 10:05:55 +02003557 assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003558 assert_int_equal(actions->exts[0].insubstmt_index, 0);
3559 assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlákeaa45792019-07-24 15:25:01 +02003560 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3561 actions = NULL;
3562
David Sedlák85d0eca2019-07-24 15:15:21 +02003563 /* min subelems */
3564 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003565 assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003566 assert_string_equal(actions->name, "act");
3567 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3568 actions = NULL;
3569
3570 st->finished_correctly = true;
3571}
3572
David Sedlák992fb7c2019-07-24 16:51:01 +02003573static void
3574test_augment_elem(void **state)
3575{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003576 struct test_parser_yin_state *st = *state;
David Sedlák992fb7c2019-07-24 16:51:01 +02003577 const char *data;
3578 struct lysp_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003579 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003580
3581 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3582 data = ELEMENT_WRAPPER_START
3583 "<augment target-node=\"target\">"
3584 "<action name=\"action\"/>"
3585 "<anydata name=\"anyd\"/>"
3586 "<anyxml name=\"anyx\"/>"
3587 "<case name=\"case\"/>"
3588 "<choice name=\"choice\"/>"
3589 "<container name=\"subcont\"/>"
3590 "<description><text>desc</text></description>"
3591 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003592 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3593 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003594 "<list name=\"list\"/>"
3595 "<notification name=\"notif\"/>"
3596 "<reference><text>ref</text></reference>"
3597 "<status value=\"current\"/>"
3598 "<uses name=\"uses\"/>"
3599 "<when condition=\"when-cond\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003600 EXT_SUBELEM
David Sedlák992fb7c2019-07-24 16:51:01 +02003601 "</augment>"
3602 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003603 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003604 assert_string_equal(augments->nodeid, "target");
3605 assert_null(augments->parent);
3606 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3607 assert_true(augments->flags & LYS_STATUS_CURR);
3608 assert_string_equal(augments->dsc, "desc");
3609 assert_string_equal(augments->ref, "ref");
3610 assert_string_equal(augments->when->cond, "when-cond");
3611 assert_string_equal(*augments->iffeatures, "iff");
3612 assert_string_equal(augments->child->name, "anyd");
3613 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3614 assert_string_equal(augments->child->next->name, "anyx");
3615 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3616 assert_string_equal(augments->child->next->next->name, "case");
3617 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3618 assert_string_equal(augments->child->next->next->next->name, "choice");
3619 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3620 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3621 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3622 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3623 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3624 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3625 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3626 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3627 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3628 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3629 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3630 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3631 assert_string_equal(augments->actions->name, "action");
3632 assert_string_equal(augments->notifs->name, "notif");
David Sedláke0ef1c62019-09-13 10:05:55 +02003633 assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003634 assert_int_equal(augments->exts[0].insubstmt_index, 0);
3635 assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák992fb7c2019-07-24 16:51:01 +02003636 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3637 augments = NULL;
3638
3639 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003640 assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003641 assert_string_equal(augments->nodeid, "target");
3642 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3643 augments = NULL;
3644
3645 st->finished_correctly = true;
3646}
3647
David Sedlák4ffcec82019-07-25 15:10:21 +02003648static void
3649test_deviate_elem(void **state)
3650{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003651 struct test_parser_yin_state *st = *state;
David Sedlák4ffcec82019-07-25 15:10:21 +02003652 const char *data;
3653 struct lysp_deviate *deviates = NULL;
3654 struct lysp_deviate_add *d_add;
3655 struct lysp_deviate_rpl *d_rpl;
3656 struct lysp_deviate_del *d_del;
3657
3658 /* all valid arguments with min subelems */
3659 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003660 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003661 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3662 lysp_deviate_free(st->ctx, deviates);
3663 free(deviates);
3664 deviates = NULL;
3665
3666 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003667 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003668 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3669 lysp_deviate_free(st->ctx, deviates);
3670 free(deviates);
3671 deviates = NULL;
3672
3673 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003674 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003675 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3676 lysp_deviate_free(st->ctx, deviates);
3677 free(deviates);
3678 deviates = NULL;
3679
3680 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003681 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003682 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3683 lysp_deviate_free(st->ctx, deviates);
3684 free(deviates);
3685 deviates = NULL;
3686
3687 /* max subelems and valid arguments */
3688 data = ELEMENT_WRAPPER_START
3689 "<deviate value=\"not-supported\">"
David Sedlákd1144562019-08-06 12:36:14 +02003690 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003691 "</deviate>"
3692 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003693 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003694 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
David Sedláke0ef1c62019-09-13 10:05:55 +02003695 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003696 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3697 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003698 lysp_deviate_free(st->ctx, deviates);
3699 free(deviates);
3700 deviates = NULL;
3701
3702 data = ELEMENT_WRAPPER_START
3703 "<deviate value=\"add\">"
3704 "<units name=\"units\"/>"
3705 "<must condition=\"cond\"/>"
3706 "<unique tag=\"utag\"/>"
3707 "<default value=\"def\"/>"
3708 "<config value=\"true\"/>"
3709 "<mandatory value=\"true\"/>"
3710 "<min-elements value=\"5\"/>"
3711 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003712 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003713 "</deviate>"
3714 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003715 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003716 d_add = (struct lysp_deviate_add *)deviates;
3717 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3718 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003719 assert_string_equal(d_add->units, "units");
3720 assert_string_equal(d_add->musts->arg, "cond");
3721 assert_string_equal(*d_add->uniques, "utag");
3722 assert_string_equal(*d_add->dflts, "def");
3723 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3724 assert_int_equal(d_add->min, 5);
3725 assert_int_equal(d_add->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003726 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003727 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3728 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003729 lysp_deviate_free(st->ctx, deviates);
3730 free(deviates);
3731 deviates = NULL;
3732
3733 data = ELEMENT_WRAPPER_START
3734 "<deviate value=\"replace\">"
3735 "<type name=\"newtype\"/>"
3736 "<units name=\"uni\"/>"
3737 "<default value=\"def\"/>"
3738 "<config value=\"true\"/>"
3739 "<mandatory value=\"true\"/>"
3740 "<min-elements value=\"5\"/>"
3741 "<max-elements value=\"15\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003742 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003743 "</deviate>"
3744 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003745 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003746 d_rpl = (struct lysp_deviate_rpl *)deviates;
3747 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3748 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003749 assert_string_equal(d_rpl->type->name, "newtype");
3750 assert_string_equal(d_rpl->units, "uni");
3751 assert_string_equal(d_rpl->dflt, "def");
3752 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3753 assert_int_equal(d_rpl->min, 5);
3754 assert_int_equal(d_rpl->max, 15);
David Sedláke0ef1c62019-09-13 10:05:55 +02003755 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003756 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3757 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003758 lysp_deviate_free(st->ctx, deviates);
3759 free(deviates);
3760 deviates = NULL;
3761
3762 data = ELEMENT_WRAPPER_START
3763 "<deviate value=\"delete\">"
3764 "<units name=\"u\"/>"
3765 "<must condition=\"c\"/>"
3766 "<unique tag=\"tag\"/>"
3767 "<default value=\"default\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003768 EXT_SUBELEM
David Sedlák4ffcec82019-07-25 15:10:21 +02003769 "</deviate>"
3770 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003771 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003772 d_del = (struct lysp_deviate_del *)deviates;
3773 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3774 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003775 assert_string_equal(d_del->units, "u");
3776 assert_string_equal(d_del->musts->arg, "c");
3777 assert_string_equal(*d_del->uniques, "tag");
3778 assert_string_equal(*d_del->dflts, "default");
David Sedláke0ef1c62019-09-13 10:05:55 +02003779 assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003780 assert_int_equal(deviates->exts[0].insubstmt_index, 0);
3781 assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4ffcec82019-07-25 15:10:21 +02003782 lysp_deviate_free(st->ctx, deviates);
3783 free(deviates);
3784 deviates = NULL;
3785
3786 /* invalid arguments */
3787 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003788 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003789 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 +02003790 deviates = NULL;
3791
3792 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003793 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003794 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 +02003795 deviates = NULL;
3796
3797 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003798 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003799 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 +02003800 deviates = NULL;
3801
3802 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003803 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák26ea1432019-08-14 13:42:23 +02003804 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 +02003805 deviates = NULL;
3806
3807 data = ELEMENT_WRAPPER_START
3808 "<deviate value=\"not-supported\">"
3809 "<must condition=\"c\"/>"
3810 "</deviate>"
3811 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003812 assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
David Sedlák4ffcec82019-07-25 15:10:21 +02003813 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3814
3815 st->finished_correctly = true;
3816}
3817
David Sedlák8b754462019-07-25 16:22:13 +02003818static void
3819test_deviation_elem(void **state)
3820{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003821 struct test_parser_yin_state *st = *state;
David Sedlák8b754462019-07-25 16:22:13 +02003822 const char *data;
3823 struct lysp_deviation *deviations = NULL;
3824
3825 /* min subelems */
3826 data = ELEMENT_WRAPPER_START
3827 "<deviation target-node=\"target\">"
3828 "<deviate value=\"not-supported\"/>"
3829 "</deviation>"
3830 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003831 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003832 assert_string_equal(deviations->nodeid, "target");
3833 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3834 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3835 deviations = NULL;
3836
3837 /* max subelems */
3838 data = ELEMENT_WRAPPER_START
3839 "<deviation target-node=\"target\">"
3840 "<reference><text>ref</text></reference>"
3841 "<description><text>desc</text></description>"
3842 "<deviate value=\"add\"/>"
David Sedlákd1144562019-08-06 12:36:14 +02003843 EXT_SUBELEM
David Sedlák8b754462019-07-25 16:22:13 +02003844 "</deviation>"
3845 ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003846 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003847 assert_string_equal(deviations->nodeid, "target");
3848 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3849 assert_string_equal(deviations->ref, "ref");
3850 assert_string_equal(deviations->dsc, "desc");
David Sedláke0ef1c62019-09-13 10:05:55 +02003851 assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003852 assert_int_equal(deviations->exts[0].insubstmt_index, 0);
3853 assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák8b754462019-07-25 16:22:13 +02003854 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3855 deviations = NULL;
3856
3857 /* invalid */
3858 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Michal Vaskob36053d2020-03-26 15:49:30 +01003859 assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID);
David Sedlák8b754462019-07-25 16:22:13 +02003860 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3861 deviations = NULL;
David Sedlák1538a842019-08-08 15:38:51 +02003862 logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
3863 /* TODO */
David Sedlák8b754462019-07-25 16:22:13 +02003864 st->finished_correctly = true;
3865}
3866
David Sedlák4f03b932019-07-26 13:01:47 +02003867static void
3868test_module_elem(void **state)
3869{
Radek Krejci3a4889a2020-05-19 17:01:58 +02003870 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01003871 const char *data;
David Sedlák4f03b932019-07-26 13:01:47 +02003872 struct lys_module *lys_mod = NULL;
3873 struct lysp_module *lysp_mod = NULL;
3874
3875 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003876 lys_mod = calloc(1, sizeof *lys_mod);
3877 lysp_mod = calloc(1, sizeof *lysp_mod);
3878 lys_mod->ctx = st->ctx;
3879 lysp_mod->mod = lys_mod;
3880 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3881 "<yang-version value=\"1.1\"/>\n"
3882 "<namespace uri=\"ns\"/>\n"
3883 "<prefix value=\"pref\"/>\n"
3884 "<include module=\"b-mod\"/>\n"
3885 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3886 "<organization><text>org</text></organization>\n"
3887 "<contact><text>contact</text></contact>\n"
3888 "<description><text>desc</text></description>"
3889 "<reference><text>ref</text></reference>\n"
3890 "<revision date=\"2019-02-02\"/>\n"
3891 "<anydata name=\"anyd\"/>\n"
3892 "<anyxml name=\"anyx\"/>\n"
3893 "<choice name=\"choice\"/>\n"
3894 "<container name=\"cont\"/>\n"
3895 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3896 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3897 "<list name=\"sub-list\"/>\n"
3898 "<uses name=\"uses-name\"/>\n"
3899 "<augment target-node=\"target\"/>\n"
3900 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3901 "<extension name=\"ext\"/>\n"
3902 "<feature name=\"feature\"/>\n"
3903 "<grouping name=\"grp\"/>\n"
3904 "<identity name=\"ident-name\"/>\n"
3905 "<notification name=\"notf\"/>\n"
3906 "<rpc name=\"rpc-name\"/>\n"
3907 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02003908 EXT_SUBELEM"\n"
David Sedlák4f03b932019-07-26 13:01:47 +02003909 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003910 assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
3911 assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003912
3913 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003914 assert_string_equal(lysp_mod->mod->name, "mod");
3915 assert_string_equal(lysp_mod->revs, "2019-02-02");
3916 assert_string_equal(lysp_mod->mod->ns, "ns");
3917 assert_string_equal(lysp_mod->mod->prefix, "pref");
3918 assert_null(lysp_mod->mod->filepath);
3919 assert_string_equal(lysp_mod->mod->org, "org");
3920 assert_string_equal(lysp_mod->mod->contact, "contact");
3921 assert_string_equal(lysp_mod->mod->dsc, "desc");
3922 assert_string_equal(lysp_mod->mod->ref, "ref");
3923 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
3924 assert_string_equal(lysp_mod->imports->name, "a-mod");
3925 assert_string_equal(lysp_mod->includes->name, "b-mod");
3926 assert_string_equal(lysp_mod->extensions->name, "ext");
3927 assert_string_equal(lysp_mod->features->name, "feature");
3928 assert_string_equal(lysp_mod->identities->name, "ident-name");
3929 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3930 assert_string_equal(lysp_mod->groupings->name, "grp");
3931 assert_string_equal(lysp_mod->data->name, "anyd");
3932 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3933 assert_string_equal(lysp_mod->data->next->name, "anyx");
3934 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3935 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3936 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3937 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3938 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3939 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3940 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3941 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3942 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3943 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3944 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3945 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3946 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3947 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3948 assert_string_equal(lysp_mod->augments->nodeid, "target");
3949 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3950 assert_string_equal(lysp_mod->notifs->name, "notf");
3951 assert_string_equal(lysp_mod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02003952 assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02003953 assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
3954 assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák4f03b932019-07-26 13:01:47 +02003955 lysp_module_free(lysp_mod);
3956 lys_module_free(lys_mod, NULL);
David Sedlák4f03b932019-07-26 13:01:47 +02003957
3958 /* min subelems */
Michal Vasko63f3d842020-07-08 10:10:14 +02003959 ly_in_free(st->in, 0);
Michal Vaskob36053d2020-03-26 15:49:30 +01003960 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák4f03b932019-07-26 13:01:47 +02003961 lys_mod = calloc(1, sizeof *lys_mod);
3962 lysp_mod = calloc(1, sizeof *lysp_mod);
3963 lys_mod->ctx = st->ctx;
3964 lysp_mod->mod = lys_mod;
3965 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
3966 "<namespace uri=\"ns\"/>"
3967 "<prefix value=\"pref\"/>"
3968 "<yang-version value=\"1.1\"/>"
3969 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003970 assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
3971 assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003972 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003973 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák4f03b932019-07-26 13:01:47 +02003974 lysp_module_free(lysp_mod);
3975 lys_module_free(lys_mod, NULL);
David Sedlák298ff6d2019-07-26 14:29:03 +02003976
David Sedláke6cd89e2019-08-07 12:46:02 +02003977 /* incorrect subelem order */
Michal Vasko63f3d842020-07-08 10:10:14 +02003978 ly_in_free(st->in, 0);
Michal Vaskob36053d2020-03-26 15:49:30 +01003979 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02003980 lys_mod = calloc(1, sizeof *lys_mod);
3981 lysp_mod = calloc(1, sizeof *lysp_mod);
3982 lys_mod->ctx = st->ctx;
3983 lysp_mod->mod = lys_mod;
3984 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
3985 "<feature name=\"feature\"/>\n"
3986 "<namespace uri=\"ns\"/>"
3987 "<prefix value=\"pref\"/>"
3988 "<yang-version value=\"1.1\"/>"
3989 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003990 assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
3991 assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003992 assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
3993 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 +02003994 lysp_module_free(lysp_mod);
3995 lys_module_free(lys_mod, NULL);
David Sedláke6cd89e2019-08-07 12:46:02 +02003996
David Sedlák298ff6d2019-07-26 14:29:03 +02003997 st->finished_correctly = true;
3998}
3999
4000static void
4001test_submodule_elem(void **state)
4002{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004003 struct test_parser_yin_state *st = *state;
Michal Vaskob36053d2020-03-26 15:49:30 +01004004 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +02004005 struct lysp_submodule *lysp_submod = NULL;
4006
4007 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02004008 lysp_submod = calloc(1, sizeof *lysp_submod);
4009 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
4010 "<yang-version value=\"1.1\"/>\n"
4011 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4012 "<include module=\"b-mod\"/>\n"
4013 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
4014 "<organization><text>org</text></organization>\n"
4015 "<contact><text>contact</text></contact>\n"
4016 "<description><text>desc</text></description>"
4017 "<reference><text>ref</text></reference>\n"
4018 "<revision date=\"2019-02-02\"/>\n"
4019 "<anydata name=\"anyd\"/>\n"
4020 "<anyxml name=\"anyx\"/>\n"
4021 "<choice name=\"choice\"/>\n"
4022 "<container name=\"cont\"/>\n"
4023 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
4024 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
4025 "<list name=\"sub-list\"/>\n"
4026 "<uses name=\"uses-name\"/>\n"
4027 "<augment target-node=\"target\"/>\n"
4028 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
4029 "<extension name=\"ext\"/>\n"
4030 "<feature name=\"feature\"/>\n"
4031 "<grouping name=\"grp\"/>\n"
4032 "<identity name=\"ident-name\"/>\n"
4033 "<notification name=\"notf\"/>\n"
4034 "<rpc name=\"rpc-name\"/>\n"
4035 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
David Sedlákd1144562019-08-06 12:36:14 +02004036 EXT_SUBELEM"\n"
David Sedlák298ff6d2019-07-26 14:29:03 +02004037 "</submodule>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02004038 assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
4039 assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01004040 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004041
4042 assert_string_equal(lysp_submod->name, "mod");
4043 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02004044 assert_string_equal(lysp_submod->prefix, "pref");
4045 assert_null(lysp_submod->filepath);
4046 assert_string_equal(lysp_submod->org, "org");
4047 assert_string_equal(lysp_submod->contact, "contact");
4048 assert_string_equal(lysp_submod->dsc, "desc");
4049 assert_string_equal(lysp_submod->ref, "ref");
4050 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
4051 assert_string_equal(lysp_submod->imports->name, "a-mod");
4052 assert_string_equal(lysp_submod->includes->name, "b-mod");
4053 assert_string_equal(lysp_submod->extensions->name, "ext");
4054 assert_string_equal(lysp_submod->features->name, "feature");
4055 assert_string_equal(lysp_submod->identities->name, "ident-name");
4056 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
4057 assert_string_equal(lysp_submod->groupings->name, "grp");
4058 assert_string_equal(lysp_submod->data->name, "anyd");
4059 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
4060 assert_string_equal(lysp_submod->data->next->name, "anyx");
4061 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
4062 assert_string_equal(lysp_submod->data->next->next->name, "choice");
4063 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
4064 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
4065 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
4066 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
4067 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
4068 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
4069 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
4070 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
4071 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
4072 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
4073 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
4074 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
4075 assert_string_equal(lysp_submod->augments->nodeid, "target");
4076 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
4077 assert_string_equal(lysp_submod->notifs->name, "notf");
4078 assert_string_equal(lysp_submod->deviations->nodeid, "target");
David Sedláke0ef1c62019-09-13 10:05:55 +02004079 assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
David Sedlákd1144562019-08-06 12:36:14 +02004080 assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
4081 assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
David Sedlák298ff6d2019-07-26 14:29:03 +02004082
4083 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004084
4085 /* min subelemnts */
Michal Vasko63f3d842020-07-08 10:10:14 +02004086 ly_in_free(st->in, 0);
Michal Vaskob36053d2020-03-26 15:49:30 +01004087 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedlák298ff6d2019-07-26 14:29:03 +02004088 lysp_submod = calloc(1, sizeof *lysp_submod);
4089 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4090 "<yang-version value=\"1.0\"/>"
4091 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4092 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004093 assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
4094 assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01004095 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02004096 assert_string_equal(lysp_submod->prefix, "pref");
4097 assert_string_equal(lysp_submod->belongsto, "mod-name");
4098 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
4099 lysp_submodule_free(st->ctx, lysp_submod);
David Sedlák298ff6d2019-07-26 14:29:03 +02004100
David Sedláke6cd89e2019-08-07 12:46:02 +02004101 /* incorrect subelem order */
Michal Vasko63f3d842020-07-08 10:10:14 +02004102 ly_in_free(st->in, 0);
Michal Vaskob36053d2020-03-26 15:49:30 +01004103 lyxml_ctx_free(st->yin_ctx->xmlctx);
David Sedláke6cd89e2019-08-07 12:46:02 +02004104 lysp_submod = calloc(1, sizeof *lysp_submod);
4105 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
4106 "<yang-version value=\"1.0\"/>"
4107 "<reference><text>ref</text></reference>\n"
4108 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
4109 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004110 assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
4111 assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01004112 assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
4113 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 +02004114 lysp_submodule_free(st->ctx, lysp_submod);
David Sedláke6cd89e2019-08-07 12:46:02 +02004115
David Sedlák298ff6d2019-07-26 14:29:03 +02004116 st->finished_correctly = true;
David Sedlák4f03b932019-07-26 13:01:47 +02004117}
4118
David Sedlák8985a142019-07-31 16:43:06 +02004119static void
4120test_yin_parse_module(void **state)
4121{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004122 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +02004123 const char *data;
4124 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01004125 struct lys_yin_parser_ctx *yin_ctx = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02004126 struct ly_in *in = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004127
4128 mod = calloc(1, sizeof *mod);
4129 mod->ctx = st->ctx;
David Sedlákd2844882019-09-13 16:01:22 +02004130 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"
4131 "<yang-version value=\"1.1\"/>\n"
4132 "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
4133 "<prefix value=\"a\"/>\n"
4134 "<import module=\"ietf-yang-metadata\">\n"
4135 "<prefix value=\"md\"/>\n"
4136 "</import>\n"
4137 "<feature name=\"f\"/>\n"
4138 "<md:annotation name=\"x\">\n"
4139 "<description>\n"
4140 "<text>test</text>\n"
4141 "</description>\n"
4142 "<reference>\n"
4143 "<text>test</text>\n"
4144 "</reference>\n"
4145 "<if-feature name=\"f\"/>\n"
4146 "<status value=\"current\"/>\n"
4147 "<type name=\"uint8\"/>\n"
4148 "<units name=\"meters\"/>\n"
4149 "</md:annotation>\n"
4150 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02004151 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4152 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
David Sedlákd2844882019-09-13 16:01:22 +02004153 assert_null(mod->parsed->exts->child->next->child);
4154 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
4155 lys_module_free(mod, NULL);
4156 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004157 ly_in_free(in, 0);
David Sedlákd2844882019-09-13 16:01:22 +02004158 mod = NULL;
4159 yin_ctx = NULL;
4160
4161 mod = calloc(1, sizeof *mod);
4162 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004163 data = "<module name=\"example-foo\""
4164 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4165 "xmlns:foo=\"urn:example:foo\""
4166 "xmlns:myext=\"urn:example:extensions\">\n"
4167
4168 "<yang-version value=\"1.0\"/>\n"
4169
4170 "<namespace uri=\"urn:example:foo\"/>\n"
4171 "<prefix value=\"foo\"/>\n"
4172
4173 "<import module=\"example-extensions\">\n"
David Sedlák6d781b62019-08-02 15:22:52 +02004174 "<prefix value=\"myext\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02004175 "</import>\n"
4176
4177 "<list name=\"interface\">\n"
4178 "<key value=\"name\"/>\n"
4179 "<leaf name=\"name\">\n"
4180 "<type name=\"string\"/>\n"
4181 "</leaf>\n"
4182 "<leaf name=\"mtu\">\n"
4183 "<type name=\"uint32\"/>\n"
4184 "<description>\n"
4185 "<text>The MTU of the interface.</text>\n"
4186 "</description>\n"
4187 "<myext:c-define name=\"MY_MTU\"/>\n"
4188 "</leaf>\n"
4189 "</list>\n"
4190 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02004191 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4192 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004193 lys_module_free(mod, NULL);
4194 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004195 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02004196 mod = NULL;
4197 yin_ctx = NULL;
4198
4199 mod = calloc(1, sizeof *mod);
4200 mod->ctx = st->ctx;
David Sedlák6d781b62019-08-02 15:22:52 +02004201 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4202 "<yang-version value=\"1.0\"/>\n"
4203 "<namespace uri=\"urn:example:foo\"/>\n"
4204 "<prefix value=\"foo\"/>\n"
4205 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02004206 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4207 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004208 lys_module_free(mod, NULL);
4209 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004210 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02004211 mod = NULL;
4212 yin_ctx = NULL;
4213
4214
4215 mod = calloc(1, sizeof *mod);
4216 mod->ctx = st->ctx;
David Sedlák8985a142019-07-31 16:43:06 +02004217 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4218 "</submodule>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02004219 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4220 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004221 logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
4222 lys_module_free(mod, NULL);
4223 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004224 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02004225
David Sedlák6d781b62019-08-02 15:22:52 +02004226 mod = calloc(1, sizeof *mod);
4227 mod->ctx = st->ctx;
4228 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
4229 "<yang-version value=\"1.0\"/>\n"
4230 "<namespace uri=\"urn:example:foo\"/>\n"
4231 "<prefix value=\"foo\"/>\n"
4232 "</module>"
4233 "<module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004234 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4235 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004236 logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
4237 lys_module_free(mod, NULL);
4238 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004239 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02004240 mod = NULL;
4241 yin_ctx = NULL;
4242
David Sedlák8985a142019-07-31 16:43:06 +02004243 st->finished_correctly = true;
4244}
4245
4246static void
4247test_yin_parse_submodule(void **state)
4248{
Radek Krejci3a4889a2020-05-19 17:01:58 +02004249 struct test_parser_yin_state *st = *state;
David Sedlák8985a142019-07-31 16:43:06 +02004250 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01004251 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02004252 struct lysp_submodule *submod = NULL;
David Sedlák1b623122019-08-05 15:27:49 +02004253 struct lys_parser_ctx main_ctx = {};
Michal Vasko63f3d842020-07-08 10:10:14 +02004254 struct ly_in *in;
David Sedlák8985a142019-07-31 16:43:06 +02004255
4256 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4257 "<submodule name=\"asub\""
4258 "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
4259 "xmlns:a=\"urn:a\">"
4260 "<yang-version value=\"1.0\"/>\n"
4261 "<belongs-to module=\"a\">"
4262 "<prefix value=\"a_pref\"/>"
4263 "</belongs-to>"
4264 "<include module=\"atop\"/>"
4265 "<feature name=\"fox\"/>"
4266 "<notification name=\"bar-notif\">"
4267 "<if-feature name=\"bar\"/>"
4268 "</notification>"
4269 "<notification name=\"fox-notif\">"
4270 "<if-feature name=\"fox\"/>"
4271 "</notification>"
4272 "<augment target-node=\"/a_pref:top\">"
4273 "<if-feature name=\"bar\"/>"
4274 "<container name=\"bar-sub\"/>"
4275 "</augment>"
4276 "<augment target-node=\"/top\">"
4277 "<container name=\"bar-sub2\"/>"
4278 "</augment>"
4279 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004280 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4281 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_SUCCESS);
David Sedlák8985a142019-07-31 16:43:06 +02004282 lysp_submodule_free(st->ctx, submod);
4283 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004284 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02004285 yin_ctx = NULL;
4286 submod = NULL;
4287
4288 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák6d781b62019-08-02 15:22:52 +02004289 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4290 "<yang-version value=\"1.0\"/>\n"
4291 "<belongs-to module=\"a\">"
4292 "<prefix value=\"a_pref\"/>"
4293 "</belongs-to>"
4294 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004295 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4296 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_SUCCESS);
David Sedlák6d781b62019-08-02 15:22:52 +02004297 lysp_submodule_free(st->ctx, submod);
4298 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004299 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02004300 yin_ctx = NULL;
4301 submod = NULL;
4302
4303 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
David Sedlák8985a142019-07-31 16:43:06 +02004304 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4305 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004306 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4307 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_EINVAL);
David Sedlák8985a142019-07-31 16:43:06 +02004308 logbuf_assert("Input data contains module in situation when a submodule is expected.");
4309 lysp_submodule_free(st->ctx, submod);
4310 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004311 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02004312 yin_ctx = NULL;
4313 submod = NULL;
4314
David Sedlák6d781b62019-08-02 15:22:52 +02004315 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
4316 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4317 "<yang-version value=\"1.0\"/>\n"
4318 "<belongs-to module=\"a\">"
4319 "<prefix value=\"a_pref\"/>"
4320 "</belongs-to>"
4321 "</submodule>"
4322 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
4323 "<yang-version value=\"1.0\"/>\n"
4324 "<belongs-to module=\"a\">"
4325 "<prefix value=\"a_pref\"/>"
4326 "</belongs-to>"
4327 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02004328 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
4329 assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_EVALID);
David Sedlák6d781b62019-08-02 15:22:52 +02004330 logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
4331 lysp_submodule_free(st->ctx, submod);
4332 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02004333 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02004334 yin_ctx = NULL;
4335 submod = NULL;
4336
David Sedlák8985a142019-07-31 16:43:06 +02004337 st->finished_correctly = true;
4338}
4339
David Sedlák3b4db242018-10-19 16:11:01 +02004340int
4341main(void)
4342{
4343
4344 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02004345 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02004346 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
4347 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák071f7662019-09-12 02:02:51 +02004348 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02004349 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02004350
David Sedlák8e7bda82019-07-16 17:57:50 +02004351 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák43801c92019-08-05 15:58:54 +02004352 cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test),
4353 cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test),
David Sedlák32488102019-07-15 17:44:10 +02004354 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
4355 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
4356 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
4357 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
4358 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
4359 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
4360 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004361 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
4362 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
4363 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
4364 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
4365 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
4366 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
4367 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
4368 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
4369 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
4370 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
4371 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
4372 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02004373 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
4374 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02004375 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
4376 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
4377 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
4378 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
4379 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
4380 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
4381 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
4382 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02004383 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02004384 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02004385 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02004386 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02004387 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02004388 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02004389 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02004390 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02004391 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02004392 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02004393 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02004394 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02004395 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02004396 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02004397 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02004398 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02004399 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02004400 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02004401 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02004402 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02004403 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02004404 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02004405 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02004406 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02004407 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02004408 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák298ff6d2019-07-26 14:29:03 +02004409 cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test),
David Sedlák8985a142019-07-31 16:43:06 +02004410
4411 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger),
4412 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger),
David Sedlák3b4db242018-10-19 16:11:01 +02004413 };
4414
David Sedlák8e7bda82019-07-16 17:57:50 +02004415 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02004416}