blob: a23d322819f779debec2f8a346232a95ade32818 [file] [log] [blame]
David Sedlákb1ce3f82019-06-05 14:37:26 +02001/**
2 * @file test_parser_yin.c
3 * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
4 * @brief unit tests for functions from parser_yin.c
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
David Sedlák3b4db242018-10-19 16:11:01 +020015#include <stdarg.h>
16#include <stddef.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20#include <stdio.h>
21#include <string.h>
David Sedlák79e50cb2019-06-05 16:33:09 +020022#include <stdbool.h>
David Sedlák3b4db242018-10-19 16:11:01 +020023
David Sedlákecf5eb82019-06-03 14:12:44 +020024#include "../../src/common.h"
25#include "../../src/tree_schema.h"
26#include "../../src/tree_schema_internal.h"
27#include "../../src/parser_yin.h"
David Sedlák8f5bce02019-06-03 16:41:08 +020028#include "../../src/xml.h"
David Sedlák3b4db242018-10-19 16:11:01 +020029
David Sedlák555c7202019-07-04 12:14:12 +020030/* prototypes of static functions */
31void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +020032void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +020033void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +020034void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +020035void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +020036void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +020037void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +020038void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +020039void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +020040void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +020041void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
David Sedlák031b9e72019-07-23 15:19:37 +020042void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
David Sedláke3ce9ef2019-07-23 16:34:30 +020043void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
David Sedlák05404f62019-07-24 14:11:53 +020044void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
David Sedlák85d0eca2019-07-24 15:15:21 +020045void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
David Sedlák992fb7c2019-07-24 16:51:01 +020046void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +020047void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +020048void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák555c7202019-07-04 12:14:12 +020049
David Sedlák68a1af12019-03-08 13:46:54 +010050struct state {
David Sedlák3b4db242018-10-19 16:11:01 +020051 struct ly_ctx *ctx;
David Sedlák3017da42019-02-15 09:48:04 +010052 struct lys_module *mod;
David Sedlák619db942019-07-03 14:47:30 +020053 struct lysp_module *lysp_mod;
David Sedlákda8ffa32019-07-08 14:17:10 +020054 struct yin_parser_ctx *yin_ctx;
David Sedlák79e50cb2019-06-05 16:33:09 +020055 bool finished_correctly;
David Sedlák68a1af12019-03-08 13:46:54 +010056};
David Sedlák872c7b42018-10-26 13:15:20 +020057
David Sedlák79e50cb2019-06-05 16:33:09 +020058#define BUFSIZE 1024
59char logbuf[BUFSIZE] = {0};
60int store = -1; /* negative for infinite logging, positive for limited logging */
61
62/* set to 0 to printing error messages to stderr instead of checking them in code */
David Sedlák4f03b932019-07-26 13:01:47 +020063#define ENABLE_LOGGER_CHECKING 0
David Sedlák79e50cb2019-06-05 16:33:09 +020064
65#if ENABLE_LOGGER_CHECKING
66static void
67logger(LY_LOG_LEVEL level, const char *msg, const char *path)
68{
69 (void) level; /* unused */
70 if (store) {
71 if (path && path[0]) {
72 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
73 } else {
74 strncpy(logbuf, msg, BUFSIZE - 1);
75 }
76 if (store > 0) {
77 --store;
78 }
79 }
80}
81#endif
82
83#if ENABLE_LOGGER_CHECKING
84# define logbuf_assert(str) assert_string_equal(logbuf, str)
85#else
86# define logbuf_assert(str)
87#endif
88
89#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
90 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
91 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
92 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
93 CLEANUP
94
David Sedlák8e7bda82019-07-16 17:57:50 +020095int
96setup_ly_ctx(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +010097{
98 struct state *st = NULL;
David Sedlák3b4db242018-10-19 16:11:01 +020099
David Sedlák68a1af12019-03-08 13:46:54 +0100100 /* allocate state variable */
101 (*state) = st = calloc(1, sizeof(*st));
102 if (!st) {
103 fprintf(stderr, "Memmory allocation failed");
104 return EXIT_FAILURE;
105 }
David Sedlák872c7b42018-10-26 13:15:20 +0200106
David Sedlák68a1af12019-03-08 13:46:54 +0100107 /* create new libyang context */
108 ly_ctx_new(NULL, 0, &st->ctx);
David Sedlák872c7b42018-10-26 13:15:20 +0200109
David Sedlák8e7bda82019-07-16 17:57:50 +0200110 return EXIT_SUCCESS;
111}
112
113int
114destroy_ly_ctx(void **state)
115{
116 struct state *st = *state;
117 ly_ctx_destroy(st->ctx, NULL);
118 free(st);
119
120 return EXIT_SUCCESS;
121}
122
123static int
124setup_f(void **state)
125{
126 struct state *st = *state;
127
128#if ENABLE_LOGGER_CHECKING
129 /* setup logger */
130 ly_set_log_clb(logger, 1);
131#endif
132
David Sedlák68a1af12019-03-08 13:46:54 +0100133 /* allocate new module */
134 st->mod = calloc(1, sizeof(*st->mod));
135 st->mod->ctx = st->ctx;
136
David Sedlák619db942019-07-03 14:47:30 +0200137 /* allocate new parsed module */
138 st->lysp_mod = calloc(1, sizeof(*st->lysp_mod));
139 st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod));
140 st->lysp_mod->mod->ctx = st->ctx;
141
142 /* allocate parser context */
David Sedlákda8ffa32019-07-08 14:17:10 +0200143 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
144 st->yin_ctx->xml_ctx.ctx = st->ctx;
145 st->yin_ctx->xml_ctx.line = 1;
David Sedlák8f5bce02019-06-03 16:41:08 +0200146
David Sedlák68a1af12019-03-08 13:46:54 +0100147 return EXIT_SUCCESS;
David Sedlák3b4db242018-10-19 16:11:01 +0200148}
149
150static int
David Sedlák68a1af12019-03-08 13:46:54 +0100151teardown_f(void **state)
152{
153 struct state *st = *(struct state **)state;
David Sedlák619db942019-07-03 14:47:30 +0200154 struct lys_module *temp;
David Sedlák68a1af12019-03-08 13:46:54 +0100155
David Sedlák79e50cb2019-06-05 16:33:09 +0200156#if ENABLE_LOGGER_CHECKING
157 /* teardown logger */
158 if (!st->finished_correctly && logbuf[0] != '\0') {
159 fprintf(stderr, "%s\n", logbuf);
160 }
161#endif
162
David Sedlák619db942019-07-03 14:47:30 +0200163 temp = st->lysp_mod->mod;
164
David Sedlákda8ffa32019-07-08 14:17:10 +0200165 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100166 lys_module_free(st->mod, NULL);
David Sedlák619db942019-07-03 14:47:30 +0200167 lysp_module_free(st->lysp_mod);
168 lys_module_free(temp, NULL);
David Sedlákda8ffa32019-07-08 14:17:10 +0200169 free(st->yin_ctx);
David Sedlák68a1af12019-03-08 13:46:54 +0100170
171 return EXIT_SUCCESS;
172}
173
David Sedlák392af4f2019-06-04 16:02:42 +0200174static struct state*
175reset_state(void **state)
176{
David Sedlák79e50cb2019-06-05 16:33:09 +0200177 ((struct state *)*state)->finished_correctly = true;
David Sedlák555c7202019-07-04 12:14:12 +0200178 logbuf[0] = '\0';
David Sedlák392af4f2019-06-04 16:02:42 +0200179 teardown_f(state);
180 setup_f(state);
181
182 return *state;
183}
184
David Sedlák79e50cb2019-06-05 16:33:09 +0200185void
186logbuf_clean(void)
187{
188 logbuf[0] = '\0';
189}
190
David Sedlák68a1af12019-03-08 13:46:54 +0100191static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200192test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200193{
David Sedlák8f7a1172019-06-20 14:42:18 +0200194 struct state *st = *state;
David Sedlák3b4db242018-10-19 16:11:01 +0200195
David Sedlák8f7a1172019-06-20 14:42:18 +0200196 const char *prefix, *name;
197 struct yin_arg_record *args = NULL;
198 size_t prefix_len, name_len;
199 /* create mock yin namespace in xml context */
200 const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200201 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
202 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák8f7a1172019-06-20 14:42:18 +0200203 LY_ARRAY_FREE(args);
204
David Sedlákc1771b12019-07-10 15:55:46 +0200205 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, YANG_NONE), YANG_NONE);
206 assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, YANG_NONE), YANG_NONE);
207 assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, YANG_NONE), YANG_NONE);
208 assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, YANG_NONE), YANG_ANYDATA);
209 assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, YANG_NONE), YANG_ANYXML);
210 assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, YANG_NONE), YANG_ARGUMENT);
211 assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, YANG_NONE), YANG_AUGMENT);
212 assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, YANG_NONE), YANG_BASE);
213 assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, YANG_NONE), YANG_BELONGS_TO);
214 assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, YANG_NONE), YANG_BIT);
215 assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, YANG_NONE), YANG_CASE);
216 assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, YANG_NONE), YANG_CHOICE);
217 assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, YANG_NONE), YANG_CONFIG);
218 assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, YANG_NONE), YANG_CONTACT);
219 assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, YANG_NONE), YANG_CONTAINER);
220 assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, YANG_NONE), YANG_DEFAULT);
221 assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, YANG_NONE), YANG_DESCRIPTION);
222 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, YANG_NONE), YANG_DEVIATE);
223 assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, YANG_NONE), YANG_DEVIATION);
224 assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, YANG_NONE), YANG_ENUM);
225 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, YANG_NONE), YANG_ERROR_APP_TAG);
226 assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, YANG_NONE), YANG_ERROR_MESSAGE);
227 assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, YANG_NONE), YANG_EXTENSION);
228 assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, YANG_NONE), YANG_FEATURE);
229 assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, YANG_NONE), YANG_FRACTION_DIGITS);
230 assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, YANG_NONE), YANG_GROUPING);
231 assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, YANG_NONE), YANG_IDENTITY);
232 assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, YANG_NONE), YANG_IF_FEATURE);
233 assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, YANG_NONE), YANG_IMPORT);
234 assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, YANG_NONE), YANG_INCLUDE);
235 assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, YANG_NONE), YANG_INPUT);
236 assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, YANG_NONE), YANG_KEY);
237 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, YANG_NONE), YANG_LEAF);
238 assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, YANG_NONE), YANG_LEAF_LIST);
239 assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, YANG_NONE), YANG_LENGTH);
240 assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, YANG_NONE), YANG_LIST);
241 assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, YANG_NONE), YANG_MANDATORY);
242 assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, YANG_NONE), YANG_MAX_ELEMENTS);
243 assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, YANG_NONE), YANG_MIN_ELEMENTS);
244 assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, YANG_NONE), YANG_MODIFIER);
245 assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, YANG_NONE), YANG_MODULE);
246 assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, YANG_NONE), YANG_MUST);
247 assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, YANG_NONE), YANG_NAMESPACE);
248 assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, YANG_NONE), YANG_NOTIFICATION);
249 assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, YANG_NONE), YANG_ORDERED_BY);
250 assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, YANG_NONE), YANG_ORGANIZATION);
251 assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, YANG_NONE), YANG_OUTPUT);
252 assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, YANG_NONE), YANG_PATH);
253 assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, YANG_NONE), YANG_PATTERN);
254 assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, YANG_NONE), YANG_POSITION);
255 assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, YANG_NONE), YANG_PREFIX);
256 assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, YANG_NONE), YANG_PRESENCE);
257 assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, YANG_NONE), YANG_RANGE);
258 assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, YANG_NONE), YANG_REFERENCE);
259 assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, YANG_NONE), YANG_REFINE);
260 assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, YANG_NONE), YANG_REQUIRE_INSTANCE);
261 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, YANG_NONE), YANG_REVISION);
262 assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, YANG_NONE), YANG_REVISION_DATE);
263 assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, YANG_NONE), YANG_RPC);
264 assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, YANG_NONE), YANG_STATUS);
265 assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, YANG_NONE), YANG_SUBMODULE);
266 assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, YANG_NONE), YANG_TYPE);
267 assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, YANG_NONE), YANG_TYPEDEF);
268 assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, YANG_NONE), YANG_UNIQUE);
269 assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, YANG_NONE), YANG_UNITS);
270 assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, YANG_NONE), YANG_USES);
271 assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, YANG_NONE), YANG_VALUE);
272 assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, YANG_NONE), YANG_WHEN);
273 assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, YANG_NONE), YANG_YANG_VERSION);
274 assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, YANG_NONE), YANG_YIN_ELEMENT);
David Sedlák8f7a1172019-06-20 14:42:18 +0200275
276 st->finished_correctly = true;
David Sedlák872c7b42018-10-26 13:15:20 +0200277}
David Sedlák3b4db242018-10-19 16:11:01 +0200278
David Sedlák872c7b42018-10-26 13:15:20 +0200279static void
David Sedlák060b00e2019-06-19 11:12:06 +0200280test_yin_match_argument_name(void **state)
David Sedlák872c7b42018-10-26 13:15:20 +0200281{
David Sedlák68a1af12019-03-08 13:46:54 +0100282 (void)state; /* unused */
David Sedlák872c7b42018-10-26 13:15:20 +0200283
David Sedlák060b00e2019-06-19 11:12:06 +0200284 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
285 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
286 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
287 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
288 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
289 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
290 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
291 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
292 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
293 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
294 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
295 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200296}
297
David Sedlák68a1af12019-03-08 13:46:54 +0100298static void
David Sedlákb1a78352019-06-28 16:16:29 +0200299test_yin_parse_element_generic(void **state)
300{
301 const char *prefix, *name;
302 struct state *st = *state;
303 struct lysp_ext_instance exts;
304 size_t prefix_len, name_len;
305 LY_ERR ret;
306
307 memset(&exts, 0, sizeof(exts));
308
309 const char *data = "<elem attr=\"value\">text_value</elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200310 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlák4ffcec82019-07-25 15:10:21 +0200311 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, &data, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200312 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200313 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200314 assert_string_equal(exts.child->stmt, "elem");
315 assert_string_equal(exts.child->arg, "text_value");
David Sedlákb1a78352019-06-28 16:16:29 +0200316 assert_string_equal(exts.child->child->stmt, "attr");
317 assert_string_equal(exts.child->child->arg, "value");
318 assert_true(exts.child->child->flags & LYS_YIN_ATTR);
David Sedlákb1a78352019-06-28 16:16:29 +0200319 lysp_ext_instance_free(st->ctx, &exts);
David Sedlák5392a212019-07-01 09:19:10 +0200320 st = reset_state(state);
321
322 data = "<elem></elem>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200323 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
David Sedlák4ffcec82019-07-25 15:10:21 +0200324 ret = yin_parse_element_generic(st->yin_ctx, name, name_len, &data, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200325 assert_int_equal(ret, LY_SUCCESS);
326 assert_string_equal(exts.child->stmt, "elem");
327 assert_null(exts.child->child);
328 assert_null(exts.child->arg);
David Sedlákda8ffa32019-07-08 14:17:10 +0200329 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák5392a212019-07-01 09:19:10 +0200330 lysp_ext_instance_free(st->ctx, &exts);
331
David Sedlákb1a78352019-06-28 16:16:29 +0200332 st->finished_correctly = true;
333}
334
335static void
336test_yin_parse_extension_instance(void **state)
337{
338 LY_ERR ret;
339 struct state *st = *state;
340 const char *prefix, *name;
341 size_t prefix_len, name_len;
342 struct yin_arg_record *args = NULL;
343 struct lysp_ext_instance *exts = NULL;
David Sedlákb1a78352019-06-28 16:16:29 +0200344 const char *data = "<ext value1=\"test\" value=\"test2\"><subelem>text</subelem></ext>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200345 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
346 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200347 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name2fullname(name, prefix_len),
David Sedlák619db942019-07-03 14:47:30 +0200348 namelen2fulllen(name_len, prefix_len), LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200349 assert_int_equal(ret, LY_SUCCESS);
350 assert_string_equal(exts->name, "ext");
351 assert_int_equal(exts->insubstmt_index, 0);
352 assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
353 assert_true(exts->yin & LYS_YIN);
354 assert_string_equal(exts->child->stmt, "value1");
355 assert_string_equal(exts->child->arg, "test");
356 assert_null(exts->child->child);
357 assert_true(exts->child->flags & LYS_YIN_ATTR);
358 assert_string_equal(exts->child->next->stmt, "value");
359 assert_string_equal(exts->child->next->arg, "test2");
360 assert_null(exts->child->next->child);
361 assert_true(exts->child->next->flags & LYS_YIN_ATTR);
362
363 assert_string_equal(exts->child->next->next->stmt, "subelem");
364 assert_string_equal(exts->child->next->next->arg, "text");
365 assert_null(exts->child->next->next->child);
366 assert_null(exts->child->next->next->next);
367 assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
David Sedlákda8ffa32019-07-08 14:17:10 +0200368 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákb1a78352019-06-28 16:16:29 +0200369 LY_ARRAY_FREE(args);
370 lysp_ext_instance_free(st->ctx, exts);
371 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200372 exts = NULL;
373 args = NULL;
374 st = reset_state(state);
375
376 data = "<extension-elem />";
David Sedlákda8ffa32019-07-08 14:17:10 +0200377 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
378 yin_load_attributes(st->yin_ctx, &data, &args);
David Sedlák1f90d252019-07-10 17:09:32 +0200379 ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, LYEXT_SUBSTMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200380 assert_int_equal(ret, LY_SUCCESS);
381 assert_string_equal(exts->name, "extension-elem");
382 assert_null(exts->argument);
383 assert_null(exts->child);
384 assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
385 assert_int_equal(exts->insubstmt_index, 0);
386 assert_true(exts->yin & LYS_YIN);
David Sedlákda8ffa32019-07-08 14:17:10 +0200387 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlákf250ecf2019-07-01 11:02:05 +0200388 LY_ARRAY_FREE(args);
389 lysp_ext_instance_free(st->ctx, exts);
390 LY_ARRAY_FREE(exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200391 st->finished_correctly = true;
392}
393
David Sedlák555c7202019-07-04 12:14:12 +0200394static void
395test_yin_parse_content(void **state)
396{
397 struct state *st = *state;
398 LY_ERR ret = LY_SUCCESS;
399 struct sized_string name, prefix;
400 const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
401 "<custom xmlns=\"my-ext\">"
402 "totally amazing extension"
403 "</custom>"
David Sedlák986cb412019-07-04 13:10:11 +0200404 "<extension name=\"ext\">"
405 "<argument name=\"argname\"></argument>"
406 "<description><text>desc</text></description>"
407 "<reference><text>ref</text></reference>"
408 "<status value=\"deprecated\"></status>"
409 "</extension>"
David Sedlák555c7202019-07-04 12:14:12 +0200410 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
David Sedlák32488102019-07-15 17:44:10 +0200411 "<if-feature name=\"foo\"></if-feature>"
David Sedlák32eee7b2019-07-09 12:38:44 +0200412 "<when condition=\"condition...\">"
413 "<reference><text>when_ref</text></reference>"
414 "<description><text>when_desc</text></description>"
415 "</when>"
David Sedláke1a30302019-07-10 13:49:38 +0200416 "<config value=\"true\"/>"
David Sedlákc1771b12019-07-10 15:55:46 +0200417 "<error-message>"
418 "<value>error-msg</value>"
419 "</error-message>"
David Sedlák2ce1be62019-07-10 16:15:09 +0200420 "<error-app-tag value=\"err-app-tag\"/>"
David Sedláka5b1d382019-07-10 16:31:09 +0200421 "<units name=\"radians\"></units>"
David Sedláke7084ce2019-07-10 16:44:15 +0200422 "<default value=\"default-value\"/>"
David Sedlák5545f5d2019-07-11 11:55:16 +0200423 "<position value=\"25\"></position>"
424 "<value value=\"-5\"/>"
David Sedlákcf5569a2019-07-11 13:31:34 +0200425 "<require-instance value=\"true\"></require-instance>"
David Sedlákb7296dd2019-07-11 14:58:38 +0200426 "<range value=\"5..10\" />"
David Sedlák438ae432019-07-11 15:36:54 +0200427 "<length value=\"baf\"/>"
David Sedlákd3983112019-07-12 11:20:56 +0200428 "<pattern value='pattern'>"
429 "<modifier value='invert-match'/>"
430 "</pattern>"
David Sedlákfd5b9c32019-07-12 15:33:13 +0200431 "<enum name=\"yay\">"
432 "</enum>"
David Sedlák555c7202019-07-04 12:14:12 +0200433 "</prefix>";
434 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200435 const char **if_features = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200436 struct yin_arg_record *attrs = NULL;
David Sedláke7084ce2019-07-10 16:44:15 +0200437 const char *value, *err_msg, *app_tag, *units, *def;
David Sedlák986cb412019-07-04 13:10:11 +0200438 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200439 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200440 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200441 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
David Sedláke1a30302019-07-10 13:49:38 +0200442 uint8_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200443
David Sedlákda8ffa32019-07-08 14:17:10 +0200444 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
445 yin_load_attributes(st->yin_ctx, &data, &attrs);
David Sedlák555c7202019-07-04 12:14:12 +0200446
David Sedlákfd5b9c32019-07-12 15:33:13 +0200447 struct yin_subelement subelems[17] = {
David Sedlák438ae432019-07-11 15:36:54 +0200448 {YANG_CONFIG, &config, 0},
David Sedlákc3da3ef2019-07-19 12:56:08 +0200449 {YANG_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
David Sedlákfd5b9c32019-07-12 15:33:13 +0200450 {YANG_ENUM, &enum_type, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200451 {YANG_ERROR_APP_TAG, &app_tag, 0},
452 {YANG_ERROR_MESSAGE, &err_msg, 0},
453 {YANG_EXTENSION, &ext_def, 0},
454 {YANG_IF_FEATURE, &if_features, 0},
455 {YANG_LENGTH, &len_type, 0},
David Sedlákd3983112019-07-12 11:20:56 +0200456 {YANG_PATTERN, &patter_type, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200457 {YANG_RANGE, &range_type, 0},
458 {YANG_REQUIRE_INSTANCE, &req_type, 0},
459 {YANG_UNITS, &units, 0},
David Sedlák374d2b32019-07-17 15:06:55 +0200460 {YANG_POSITION, &pos_enum, 0},
David Sedlák438ae432019-07-11 15:36:54 +0200461 {YANG_VALUE, &val_enum, 0},
462 {YANG_WHEN, &when_p, 0},
463 {YANG_CUSTOM, NULL, 0},
464 {YIN_TEXT, &value, 0}
David Sedlákd3983112019-07-12 11:20:56 +0200465 };
David Sedlákfd5b9c32019-07-12 15:33:13 +0200466 ret = yin_parse_content(st->yin_ctx, subelems, 17, &data, YANG_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200467 assert_int_equal(ret, LY_SUCCESS);
David Sedlák1fdb2522019-07-09 16:22:57 +0200468 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
David Sedlák2ce1be62019-07-10 16:15:09 +0200469 /* check parsed values */
David Sedláke7084ce2019-07-10 16:44:15 +0200470 assert_string_equal(def, "default-value");
David Sedlák555c7202019-07-04 12:14:12 +0200471 assert_string_equal(exts->name, "custom");
472 assert_string_equal(exts->argument, "totally amazing extension");
473 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200474 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200475 assert_string_equal(when_p->cond, "condition...");
476 assert_string_equal(when_p->dsc, "when_desc");
477 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200478 assert_int_equal(config, LYS_CONFIG_W);
David Sedlák5545f5d2019-07-11 11:55:16 +0200479 assert_int_equal(pos_enum.value, 25);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200480 assert_true(pos_enum.flags & LYS_SET_VALUE);
David Sedlák5545f5d2019-07-11 11:55:16 +0200481 assert_int_equal(val_enum.value, -5);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200482 assert_true(val_enum.flags & LYS_SET_VALUE);
David Sedlákcf5569a2019-07-11 13:31:34 +0200483 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200484 assert_true(req_type.flags &= LYS_SET_REQINST);
David Sedlákb7296dd2019-07-11 14:58:38 +0200485 assert_string_equal(range_type.range->arg, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200486 assert_true(range_type.flags & LYS_SET_RANGE);
David Sedlákc1771b12019-07-10 15:55:46 +0200487 assert_string_equal(err_msg, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200488 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200489 assert_string_equal(enum_type.enums->name, "yay");
David Sedlák438ae432019-07-11 15:36:54 +0200490 assert_string_equal(len_type.length->arg, "baf");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200491 assert_true(len_type.flags & LYS_SET_LENGTH);
David Sedlákd3983112019-07-12 11:20:56 +0200492 assert_string_equal(patter_type.patterns->arg, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200493 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200494 /* cleanup */
David Sedlák555c7202019-07-04 12:14:12 +0200495 lysp_ext_instance_free(st->ctx, exts);
David Sedlák32eee7b2019-07-09 12:38:44 +0200496 lysp_when_free(st->ctx, when_p);
David Sedlák986cb412019-07-04 13:10:11 +0200497 lysp_ext_free(st->ctx, ext_def);
David Sedlák5f8191e2019-07-08 16:35:52 +0200498 FREE_STRING(st->ctx, *if_features);
David Sedlákc1771b12019-07-10 15:55:46 +0200499 FREE_STRING(st->ctx, err_msg);
David Sedlák2ce1be62019-07-10 16:15:09 +0200500 FREE_STRING(st->ctx, app_tag);
David Sedláka5b1d382019-07-10 16:31:09 +0200501 FREE_STRING(st->ctx, units);
David Sedlákd3983112019-07-12 11:20:56 +0200502 FREE_STRING(st->ctx, patter_type.patterns->arg);
David Sedláke7084ce2019-07-10 16:44:15 +0200503 FREE_STRING(st->ctx, def);
David Sedlákb7296dd2019-07-11 14:58:38 +0200504 FREE_STRING(st->ctx, range_type.range->arg);
David Sedlák438ae432019-07-11 15:36:54 +0200505 FREE_STRING(st->ctx, len_type.length->arg);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200506 FREE_STRING(st->ctx, enum_type.enums->name);
David Sedlákb7296dd2019-07-11 14:58:38 +0200507 FREE_STRING(st->ctx, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200508 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200509 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200510 LY_ARRAY_FREE(ext_def);
David Sedlák555c7202019-07-04 12:14:12 +0200511 LY_ARRAY_FREE(attrs);
David Sedlákd3983112019-07-12 11:20:56 +0200512 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200513 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200514 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200515 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200516 free(len_type.length);
David Sedlák555c7202019-07-04 12:14:12 +0200517 attrs = NULL;
David Sedlák555c7202019-07-04 12:14:12 +0200518 st = reset_state(state);
519
520 /* test unique subelem */
521 const char *prefix_value;
522 struct yin_subelement subelems2[2] = {{YANG_PREFIX, &prefix_value, 0},
523 {YIN_TEXT, &value, YIN_SUBELEM_UNIQUE}};
524 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
525 "<prefix value=\"inv_mod\" />"
526 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
527 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
528 "</module>";
David Sedlákda8ffa32019-07-08 14:17:10 +0200529 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
530 yin_load_attributes(st->yin_ctx, &data, &attrs);
531 ret = yin_parse_content(st->yin_ctx, subelems2, 2, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200532 assert_int_equal(ret, LY_EVALID);
533 logbuf_assert("Redefinition of text element in module element. Line number 1.");
534 lydict_remove(st->ctx, prefix_value);
535 lydict_remove(st->ctx, value);
536 st = reset_state(state);
537 LY_ARRAY_FREE(attrs);
538 attrs = NULL;
539
540 /* test first subelem */
541 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
542 "<prefix value=\"inv_mod\" />"
543 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
544 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
545 "</module>";
546 struct yin_subelement subelems3[2] = {{YANG_PREFIX, &prefix_value, 0},
547 {YIN_TEXT, &value, YIN_SUBELEM_FIRST}};
David Sedlákda8ffa32019-07-08 14:17:10 +0200548 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
549 yin_load_attributes(st->yin_ctx, &data, &attrs);
550 ret = yin_parse_content(st->yin_ctx, subelems3, 2, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200551 assert_int_equal(ret, LY_EVALID);
552 logbuf_assert("Subelement text of module element must be defined as first subelement. Line number 1.");
553 lydict_remove(st->ctx, prefix_value);
554 st = reset_state(state);
555 LY_ARRAY_FREE(attrs);
556 attrs = NULL;
557
558 /* test mandatory subelem */
559 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
560 "</module>";
561 struct yin_subelement subelems4[1] = {{YANG_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY}};
David Sedlákda8ffa32019-07-08 14:17:10 +0200562 lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
563 yin_load_attributes(st->yin_ctx, &data, &attrs);
564 ret = yin_parse_content(st->yin_ctx, subelems4, 1, &data, YANG_MODULE, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200565 assert_int_equal(ret, LY_EVALID);
566 logbuf_assert("Missing mandatory subelement prefix of module element. Line number 1.");
567 LY_ARRAY_FREE(attrs);
568
569 st->finished_correctly = true;
570}
571
David Sedlák92147b02019-07-09 14:01:01 +0200572static void
David Sedlák4a650532019-07-10 11:55:18 +0200573test_validate_value(void **state)
574{
575 struct state *st = *state;
576 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "#invalid", 8), LY_EVALID);
577 logbuf_assert("Invalid identifier character '#'. Line number 1.");
578 assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG, "", 0), LY_SUCCESS);
579 assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "pre:b", 5), LY_EVALID);
580 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:b", 5), LY_SUCCESS);
581 assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:pre:b", 9), LY_EVALID);
582
583 st->finished_correctly = true;
584}
585
David Sedlák32488102019-07-15 17:44:10 +0200586static int
587setup_element_test(void **state)
588{
David Sedlák8e7bda82019-07-16 17:57:50 +0200589 struct state *st = *state;
David Sedlák32488102019-07-15 17:44:10 +0200590
591#if ENABLE_LOGGER_CHECKING
592 /* setup logger */
593 ly_set_log_clb(logger, 1);
594#endif
595
596 /* reset logbuf */
597 logbuf[0] = '\0';
David Sedlák32488102019-07-15 17:44:10 +0200598
599 /* allocate parser context */
600 st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
601 st->yin_ctx->xml_ctx.ctx = st->ctx;
602 st->yin_ctx->xml_ctx.line = 1;
603
604 return EXIT_SUCCESS;
605}
606
607static int
608teardown_element_test(void **state)
609{
610 struct state *st = *(struct state **)state;
611
612#if ENABLE_LOGGER_CHECKING
613 /* teardown logger */
614 if (!st->finished_correctly && logbuf[0] != '\0') {
615 fprintf(stderr, "%s\n", logbuf);
616 }
617#endif
618
619 lyxml_context_clear(&st->yin_ctx->xml_ctx);
David Sedlák32488102019-07-15 17:44:10 +0200620 free(st->yin_ctx);
David Sedlák32488102019-07-15 17:44:10 +0200621
622 return EXIT_SUCCESS;
623}
624
625#define ELEMENT_WRAPPER_START "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
626#define ELEMENT_WRAPPER_END "</module>"
627
628/* helper function to simplify unit test of each element using parse_content function */
629LY_ERR
630test_element_helper(struct state *st, const char **data, void *dest, const char **text,
631 struct lysp_ext_instance **exts, bool valid)
632{
633 struct yin_arg_record *attrs = NULL;
634 struct sized_string name, prefix;
635 LY_ERR ret = LY_SUCCESS;
636 struct yin_subelement subelems[71] = {
637 {YANG_ACTION, dest, 0},
638 {YANG_ANYDATA, dest, 0},
639 {YANG_ANYXML, dest, 0},
640 {YANG_ARGUMENT,dest, 0},
641 {YANG_AUGMENT, dest, 0},
642 {YANG_BASE, dest, 0},
643 {YANG_BELONGS_TO, dest, 0},
644 {YANG_BIT, dest, 0},
645 {YANG_CASE, dest, 0},
646 {YANG_CHOICE, dest, 0},
647 {YANG_CONFIG, dest, 0},
648 {YANG_CONTACT, dest, 0},
649 {YANG_CONTAINER, dest, 0},
David Sedlákc3da3ef2019-07-19 12:56:08 +0200650 {YANG_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
David Sedlák32488102019-07-15 17:44:10 +0200651 {YANG_DESCRIPTION, dest, 0},
652 {YANG_DEVIATE, dest, 0},
653 {YANG_DEVIATION, dest, 0},
654 {YANG_ENUM, dest, 0},
655 {YANG_ERROR_APP_TAG, dest, 0},
656 {YANG_ERROR_MESSAGE, dest, 0},
657 {YANG_EXTENSION, dest, 0},
658 {YANG_FEATURE, dest, 0},
659 {YANG_FRACTION_DIGITS, dest, 0},
660 {YANG_GROUPING, dest, 0},
661 {YANG_IDENTITY, dest, 0},
662 {YANG_IF_FEATURE, dest, 0},
663 {YANG_IMPORT, dest, 0},
664 {YANG_INCLUDE, dest, 0},
665 {YANG_INPUT, dest, 0},
666 {YANG_KEY, dest, 0},
667 {YANG_LEAF, dest, 0},
668 {YANG_LEAF_LIST, dest, 0},
669 {YANG_LENGTH, dest, 0},
670 {YANG_LIST, dest, 0},
671 {YANG_MANDATORY, dest, 0},
672 {YANG_MAX_ELEMENTS, dest, 0},
673 {YANG_MIN_ELEMENTS, dest, 0},
674 {YANG_MODIFIER, dest, 0},
675 {YANG_MODULE, dest, 0},
676 {YANG_MUST, dest, 0},
677 {YANG_NAMESPACE, dest, 0},
678 {YANG_NOTIFICATION, dest, 0},
679 {YANG_ORDERED_BY, dest, 0},
680 {YANG_ORGANIZATION, dest, 0},
681 {YANG_OUTPUT, dest, 0},
682 {YANG_PATH, dest, 0},
683 {YANG_PATTERN, dest, 0},
David Sedlák32488102019-07-15 17:44:10 +0200684 {YANG_PREFIX, dest, 0},
685 {YANG_PRESENCE, dest, 0},
686 {YANG_RANGE, dest, 0},
687 {YANG_REFERENCE, dest, 0},
688 {YANG_REFINE, dest, 0},
689 {YANG_REQUIRE_INSTANCE, dest, 0},
690 {YANG_REVISION, dest, 0},
691 {YANG_REVISION_DATE, dest, 0},
692 {YANG_RPC, dest, 0},
693 {YANG_STATUS, dest, 0},
694 {YANG_SUBMODULE, dest, 0},
695 {YANG_TYPE, dest, 0},
696 {YANG_TYPEDEF, dest, 0},
697 {YANG_UNIQUE, dest, 0},
698 {YANG_UNITS, dest, 0},
699 {YANG_USES, dest, 0},
David Sedlák374d2b32019-07-17 15:06:55 +0200700 {YANG_POSITION, dest, 0},
David Sedlák32488102019-07-15 17:44:10 +0200701 {YANG_VALUE, dest, 0},
702 {YANG_WHEN, dest, 0},
703 {YANG_YANG_VERSION, dest, 0},
704 {YANG_YIN_ELEMENT, dest, 0},
705 {YANG_CUSTOM, dest, 0},
706 {YIN_TEXT, dest, 0},
707 {YIN_VALUE, dest, 0}
708 };
David Sedlák4f03b932019-07-26 13:01:47 +0200709 LY_CHECK_RET(lyxml_get_element(&st->yin_ctx->xml_ctx, data, &prefix.value, &prefix.len, &name.value, &name.len));
710 LY_CHECK_RET(yin_load_attributes(st->yin_ctx, data, &attrs));
David Sedlák8e7bda82019-07-16 17:57:50 +0200711 ret = yin_parse_content(st->yin_ctx, subelems, 71, data, yin_match_keyword(st->yin_ctx, name.value, name.len, prefix.value, prefix.len, YANG_NONE), text, exts);
David Sedlák32488102019-07-15 17:44:10 +0200712 LY_ARRAY_FREE(attrs);
713 if (valid) {
714 assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END);
715 }
716 /* reset status */
717 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
718 return ret;
719}
720
721static void
722test_enum_bit_elem(void **state)
723{
724 /* yin_parse_enum_bit is function that is being mainly tested by this test */
725 struct state *st = *state;
726 struct lysp_type type = {};
727 const char *data;
728 data = ELEMENT_WRAPPER_START
729 "<enum name=\"enum-name\">"
730 "<if-feature name=\"feature\" />"
731 "<value value=\"55\" />"
732 "<status value=\"deprecated\" />"
733 "<description><text>desc...</text></description>"
734 "<reference><text>ref...</text></reference>"
735 "</enum>"
736 ELEMENT_WRAPPER_END;
737 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
738 assert_string_equal(*type.enums->iffeatures, "feature");
739 assert_int_equal(type.enums->value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200740 assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
David Sedlák32488102019-07-15 17:44:10 +0200741 assert_string_equal(type.enums->dsc, "desc...");
742 assert_string_equal(type.enums->ref, "ref...");
743 lysp_type_free(st->ctx, &type);
744 memset(&type, 0, sizeof type);
745
746 /* todo bit element test */
747 st->finished_correctly = true;
748}
749
750static void
751test_meta_elem(void **state)
752{
753 struct state *st = *state;
754 char *value = NULL;
755 const char *data;
756
757 /* organization element */
758 data = ELEMENT_WRAPPER_START
759 "<organization><text>organization...</text></organization>"
760 ELEMENT_WRAPPER_END;
761 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
762 assert_string_equal(value, "organization...");
763 FREE_STRING(st->ctx, value);
764 value = NULL;
765 /* contact element */
766 data = ELEMENT_WRAPPER_START
767 "<contact><text>contact...</text></contact>"
768 ELEMENT_WRAPPER_END;
769 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
770 assert_string_equal(value, "contact...");
771 FREE_STRING(st->ctx, value);
772 value = NULL;
773 /* description element */
774 data = ELEMENT_WRAPPER_START
775 "<description><text>description...</text></description>"
776 ELEMENT_WRAPPER_END;
777 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
778 assert_string_equal(value, "description...");
779 FREE_STRING(st->ctx, value);
780 value = NULL;
781 /* reference element */
782 data = ELEMENT_WRAPPER_START
783 "<reference><text>reference...</text></reference>"
784 ELEMENT_WRAPPER_END;
785 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
786 assert_string_equal(value, "reference...");
787 FREE_STRING(st->ctx, value);
788 value = NULL;
789
790 /* missing text subelement */
791 data = ELEMENT_WRAPPER_START
792 "<reference>reference...</reference>"
793 ELEMENT_WRAPPER_END;
794 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, false), LY_EVALID);
795 logbuf_assert("Missing mandatory subelement text of reference element. Line number 1.");
796
797 st->finished_correctly = true;
798}
799
800static void
801test_import_elem(void **state)
802{
803 struct state *st = *state;
804 const char *data;
805 struct lys_module *lys_mod = calloc(1, sizeof *lys_mod);
806 struct lysp_module *lysp_mod = calloc(1, sizeof *lysp_mod);
807 lys_mod->ctx = st->ctx;
808 lysp_mod->mod = lys_mod;
809
810 /* max subelems */
811 data = ELEMENT_WRAPPER_START
812 "<import module=\"a\">"
813 "<prefix value=\"a_mod\"/>"
814 "<revision-date date=\"2015-01-01\"></revision-date>"
815 "<description><text>import description</text></description>"
816 "<reference><text>import reference</text></reference>"
817 "</import>"
818 ELEMENT_WRAPPER_END;
819 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, true), LY_SUCCESS);
820 assert_string_equal(lysp_mod->imports->name, "a");
821 assert_string_equal(lysp_mod->imports->prefix, "a_mod");
822 assert_string_equal(lysp_mod->imports->rev, "2015-01-01");
823 assert_string_equal(lysp_mod->imports->dsc, "import description");
824 assert_string_equal(lysp_mod->imports->ref, "import reference");
825 lysp_module_free(lysp_mod);
826 lys_module_free(lys_mod, NULL);
827
828 /* min subelems */
829 lys_mod = calloc(1, sizeof *lys_mod);
830 lysp_mod = calloc(1, sizeof *lysp_mod);
831 lys_mod->ctx = st->ctx;
832 lysp_mod->mod = lys_mod;
833 data = ELEMENT_WRAPPER_START
834 "<import module=\"a\">"
835 "<prefix value=\"a_mod\"/>"
836 "</import>"
837 ELEMENT_WRAPPER_END;
838 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, true), LY_SUCCESS);
839 assert_string_equal(lysp_mod->imports->prefix, "a_mod");
840 lysp_module_free(lysp_mod);
841 lys_module_free(lys_mod, NULL);
842
843 /* invalid (missing prefix) */
844 lys_mod = calloc(1, sizeof *lys_mod);
845 lysp_mod = calloc(1, sizeof *lysp_mod);
846 lys_mod->ctx = st->ctx;
847 lysp_mod->mod = lys_mod;
848 data = ELEMENT_WRAPPER_START "<import module=\"a\">""</import>" ELEMENT_WRAPPER_END;
849 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, false), LY_EVALID);
850 logbuf_assert("Missing mandatory subelement prefix of import element. Line number 1.");
851 lysp_module_free(lysp_mod);
852 lys_module_free(lys_mod, NULL);
853
854 /* invalid reused prefix */
855 lys_mod = calloc(1, sizeof *lys_mod);
856 lysp_mod = calloc(1, sizeof *lysp_mod);
857 lys_mod->ctx = st->ctx;
858 lysp_mod->mod = lys_mod;
859 data = ELEMENT_WRAPPER_START
860 "<import module=\"a\">"
861 "<prefix value=\"a_mod\"/>"
862 "</import>"
863 "<import module=\"a\">"
864 "<prefix value=\"a_mod\"/>"
865 "</import>"
866 ELEMENT_WRAPPER_END;
867 assert_int_equal(test_element_helper(st, &data, lysp_mod, NULL, NULL, false), LY_EVALID);
868 logbuf_assert("Prefix \"a_mod\" already used to import \"a\" module. Line number 1.");
869 lysp_module_free(lysp_mod);
870 lys_module_free(lys_mod, NULL);
871
872 st->finished_correctly = true;
873}
874
875static void
876test_status_elem(void **state)
877{
878 struct state *st = *state;
879 const char *data;
880 uint16_t flags = 0;
881
882 /* test valid values */
883 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
884 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200885 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +0200886
887 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
888 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200889 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +0200890
891 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\"></status>" ELEMENT_WRAPPER_END;
892 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200893 assert_true(flags & LYS_STATUS_OBSLT);
David Sedlák32488102019-07-15 17:44:10 +0200894
895 /* test invalid value */
896 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
897 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
898 logbuf_assert("Invalid value \"invalid\" of \"status\". Line number 1.");
899 st->finished_correctly = true;
900}
901
902static void
903test_ext_elem(void **state)
904{
905 struct state *st = *state;
906 const char *data;
907 struct lysp_ext *ext = NULL;
908
909 /* max subelems */
910 data = ELEMENT_WRAPPER_START
911 "<extension name=\"ext_name\">"
912 "<argument name=\"arg\"></argument>"
913 "<status value=\"current\"/>"
914 "<description><text>ext_desc</text></description>"
915 "<reference><text>ext_ref</text></reference>"
916 "</extension>"
917 ELEMENT_WRAPPER_END;
918 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
919 assert_string_equal(ext->name, "ext_name");
920 assert_string_equal(ext->argument, "arg");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200921 assert_true(ext->flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +0200922 assert_string_equal(ext->dsc, "ext_desc");
923 assert_string_equal(ext->ref, "ext_ref");
924 lysp_ext_free(st->ctx, ext);
925 LY_ARRAY_FREE(ext);
926 ext = NULL;
927
928 /* min subelems */
929 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
930 assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS);
931 assert_string_equal(ext->name, "ext_name");
932 lysp_ext_free(st->ctx, ext);
933 LY_ARRAY_FREE(ext);
934 ext = NULL;
935
936 st->finished_correctly = true;
937}
938
939static void
940test_yin_element_elem(void **state)
941{
942 struct state *st = *state;
943 const char *data;
944 uint16_t flags = 0;
945
946 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
947 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200948 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200949
950 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\" />" ELEMENT_WRAPPER_END;
951 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200952 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200953
954 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
955 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200956 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +0200957 logbuf_assert("Invalid value \"invalid\" of \"yin-element\". Line number 1.");
958 st->finished_correctly = true;
959}
960
961static void
962test_yangversion_elem(void **state)
963{
964 struct state *st = *state;
965 const char *data;
966 uint8_t version = 0;
967
968 /* valid values */
969 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END;
970 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200971 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +0200972 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0);
973
974 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\" />" ELEMENT_WRAPPER_END;
975 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200976 assert_true(version & LYS_VERSION_1_1);
David Sedlák32488102019-07-15 17:44:10 +0200977 assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1);
978
979 /* invalid value */
980 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
981 assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID);
982 logbuf_assert("Invalid value \"version\" of \"yang-version\". Line number 1.");
983
984 st->finished_correctly = true;
985}
986
987static void
988test_mandatory_elem(void **state)
989{
990 struct state *st = *state;
991 const char *data;
992 uint16_t man = 0;
993
994 /* valid values */
995 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
996 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
997 assert_int_equal(man, LYS_MAND_TRUE);
998 man = 0;
999
1000 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\" />" ELEMENT_WRAPPER_END;
1001 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS);
1002 assert_int_equal(man, LYS_MAND_FALSE);
1003
1004 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
1005 assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID);
1006 logbuf_assert("Invalid value \"invalid\" of \"mandatory\". Line number 1.");
1007
1008 st->finished_correctly = true;
1009}
1010
David Sedlák8e7bda82019-07-16 17:57:50 +02001011static void
1012test_argument_elem(void **state)
1013{
1014 struct state *st = *state;
1015 const char *data;
1016 uint16_t flags = 0;
1017 const char *arg;
1018 struct yin_argument_meta arg_meta = {&flags, &arg};
1019 /* max subelems */
1020 data = ELEMENT_WRAPPER_START
1021 "<argument name=\"arg-name\">"
1022 "<yin-element value=\"true\" />"
1023 "</argument>"
1024 ELEMENT_WRAPPER_END;
1025 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1026 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001027 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001028 flags = 0;
1029 FREE_STRING(st->ctx, arg);
1030 arg = NULL;
1031
1032 /* min subelems */
1033 data = ELEMENT_WRAPPER_START
1034 "<argument name=\"arg\">"
1035 "</argument>"
1036 ELEMENT_WRAPPER_END;
1037 assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS);
1038 assert_string_equal(arg, "arg");
1039 assert_true(flags == 0);
1040 FREE_STRING(st->ctx, arg);
1041
1042 st->finished_correctly = true;
1043}
1044
1045static void
1046test_base_elem(void **state)
1047{
1048 struct state *st = *state;
1049 const char *data;
1050 const char **bases = NULL;
1051 struct lysp_type type = {};
1052
1053 /* as identity subelement */
1054 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
1055 "<base name=\"base-name\"/>"
1056 "</identity>";
1057 assert_int_equal(test_element_helper(st, &data, &bases, NULL, NULL, true), LY_SUCCESS);
1058 assert_string_equal(*bases, "base-name");
1059 FREE_STRING(st->ctx, *bases);
1060 LY_ARRAY_FREE(bases);
1061
1062 /* as type subelement */
1063 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
1064 "<base name=\"base-name\"/>"
1065 "</type>";
1066 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1067 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001068 assert_true(type.flags & LYS_SET_BASE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001069 FREE_STRING(st->ctx, *type.bases);
1070 LY_ARRAY_FREE(type.bases);
1071
1072 st->finished_correctly = true;
1073}
1074
1075static void
1076test_belongsto_elem(void **state)
1077{
1078 struct state *st = *state;
1079 const char *data;
1080 struct lysp_submodule submod;
1081
1082 data = ELEMENT_WRAPPER_START
1083 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>"
1084 ELEMENT_WRAPPER_END;
1085 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, true), LY_SUCCESS);
1086 assert_string_equal(submod.belongsto, "module-name");
1087 assert_string_equal(submod.prefix, "pref");
1088 FREE_STRING(st->ctx, submod.belongsto);
1089 FREE_STRING(st->ctx, submod.prefix);
1090
1091 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
1092 assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID);
1093 logbuf_assert("Missing mandatory subelement prefix of belongs-to element. Line number 1.");
1094 FREE_STRING(st->ctx, submod.belongsto);
1095
1096 st->finished_correctly = true;
1097}
1098
1099static void
1100test_config_elem(void **state)
1101{
1102 struct state *st = *state;
1103 const char *data;
1104 uint16_t flags = 0;
1105
1106 data = ELEMENT_WRAPPER_START "<config value=\"true\"/>" ELEMENT_WRAPPER_END;
1107 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001108 assert_true(flags & LYS_CONFIG_W);
David Sedlák8e7bda82019-07-16 17:57:50 +02001109 flags = 0;
1110
1111 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
1112 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001113 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001114 flags = 0;
1115
1116 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1117 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
1118 logbuf_assert("Invalid value \"invalid\" of \"config\". Line number 1.");
1119
1120 st->finished_correctly = true;
1121}
1122
1123static void
1124test_default_elem(void **state)
1125{
1126 struct state *st = *state;
1127 const char *data;
1128 const char *val = NULL;
1129
1130 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\"/>" ELEMENT_WRAPPER_END;
1131 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1132 assert_string_equal(val, "defaul-value");
1133 FREE_STRING(st->ctx, val);
1134 val = NULL;
1135
1136 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
1137 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1138 logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
1139
1140 st->finished_correctly = true;
1141}
1142
1143static void
1144test_err_app_tag_elem(void **state)
1145{
1146 struct state *st = *state;
1147 const char *data;
1148 const char *val = NULL;
1149
1150 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\"/>" ELEMENT_WRAPPER_END;
1151 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1152 assert_string_equal(val, "val");
1153 FREE_STRING(st->ctx, val);
1154 val = NULL;
1155
1156 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
1157 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1158 logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
1159
1160 st->finished_correctly = true;
1161}
1162
1163static void
1164test_err_msg_elem(void **state)
1165{
1166 struct state *st = *state;
1167 const char *data;
1168 const char *val = NULL;
1169
1170 data = ELEMENT_WRAPPER_START "<error-message><value>val</value></error-message>" ELEMENT_WRAPPER_END;
1171 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1172 assert_string_equal(val, "val");
1173 FREE_STRING(st->ctx, val);
1174
1175 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
1176 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
1177 logbuf_assert("Missing mandatory subelement value of error-message element. Line number 1.");
1178
1179 st->finished_correctly = true;
1180}
1181
1182static void
1183test_fracdigits_elem(void **state)
1184{
1185 struct state *st = *state;
1186 const char *data;
1187 struct lysp_type type = {};
1188
1189 /* valid value */
1190 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\"></fraction-digits>" ELEMENT_WRAPPER_END;
1191 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1192 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001193 assert_true(type.flags & LYS_SET_FRDIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001194
1195 /* invalid values */
1196 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
1197 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1198 logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1.");
1199
1200 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
1201 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1202 logbuf_assert("Invalid value \"02\" of \"fraction-digits\". Line number 1.");
1203
1204 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
1205 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1206 logbuf_assert("Invalid value \"1p\" of \"fraction-digits\". Line number 1.");
1207
1208 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
1209 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1210 logbuf_assert("Invalid value \"19\" of \"fraction-digits\". Line number 1.");
1211
1212 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
1213 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1214 logbuf_assert("Invalid value \"999999999999999999\" of \"fraction-digits\". Line number 1.");
1215
1216 st->finished_correctly = true;
1217}
1218
1219static void
1220test_iffeature_elem(void **state)
1221{
1222 struct state *st = *state;
1223 const char *data;
1224 const char **iffeatures = NULL;
1225
1226 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\"></if-feature>" ELEMENT_WRAPPER_END;
1227 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, true), LY_SUCCESS);
1228 assert_string_equal(*iffeatures, "local-storage");
1229 FREE_STRING(st->ctx, *iffeatures);
1230 LY_ARRAY_FREE(iffeatures);
1231 iffeatures = NULL;
1232
1233 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
1234 assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID);
1235 logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
1236 LY_ARRAY_FREE(iffeatures);
1237 iffeatures = NULL;
1238
1239 st->finished_correctly = true;
1240}
1241
1242static void
1243test_length_elem(void **state)
1244{
1245 struct state *st = *state;
1246 const char *data;
1247 struct lysp_type type = {};
1248
1249 /* max subelems */
1250 data = ELEMENT_WRAPPER_START
1251 "<length value=\"length-str\">"
1252 "<error-message><value>err-msg</value></error-message>"
1253 "<error-app-tag value=\"err-app-tag\"/>"
1254 "<description><text>desc</text></description>"
1255 "<reference><text>ref</text></reference>"
1256 "</length>"
1257 ELEMENT_WRAPPER_END;
1258 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1259 assert_string_equal(type.length->arg, "length-str");
1260 assert_string_equal(type.length->emsg, "err-msg");
1261 assert_string_equal(type.length->eapptag, "err-app-tag");
1262 assert_string_equal(type.length->dsc, "desc");
1263 assert_string_equal(type.length->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001264 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001265 lysp_type_free(st->ctx, &type);
1266 memset(&type, 0, sizeof(type));
1267
1268 /* min subelems */
1269 data = ELEMENT_WRAPPER_START
1270 "<length value=\"length-str\">"
1271 "</length>"
1272 ELEMENT_WRAPPER_END;
1273 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1274 assert_string_equal(type.length->arg, "length-str");
1275 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001276 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001277 memset(&type, 0, sizeof(type));
1278
1279 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
1280 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1281 logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
1282 lysp_type_free(st->ctx, &type);
1283 memset(&type, 0, sizeof(type));
1284
1285 st->finished_correctly = true;
1286}
1287
1288static void
1289test_modifier_elem(void **state)
1290{
1291 struct state *st = *state;
1292 const char *data;
1293 const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
1294
1295 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\" />" ELEMENT_WRAPPER_END;
1296 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, true), LY_SUCCESS);
1297 assert_string_equal(pat, "\x015pattern");
1298 FREE_STRING(st->ctx, pat);
1299
1300 pat = lydict_insert(st->ctx, "\006pattern", 8);
1301 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
1302 assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID);
1303 logbuf_assert("Invalid value \"invert\" of \"modifier\". Line number 1.");
1304 FREE_STRING(st->ctx, pat);
1305
1306 st->finished_correctly = true;
1307}
1308
1309static void
1310test_namespace_elem(void **state)
1311{
1312 struct state *st = *state;
1313 const char *data;
1314 const char *ns;
1315
1316 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\"/>" ELEMENT_WRAPPER_END;
1317 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, true), LY_SUCCESS);
1318 assert_string_equal(ns, "ns");
1319 FREE_STRING(st->ctx, ns);
1320
1321 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
1322 assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID);
1323 logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
1324
1325 st->finished_correctly = true;
1326}
1327
1328static void
1329test_path_elem(void **state)
1330{
1331 struct state *st = *state;
1332 const char *data;
1333 struct lysp_type type = {};
1334
1335 data = ELEMENT_WRAPPER_START "<path value=\"path-val\"/>" ELEMENT_WRAPPER_END;
1336 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1337 assert_string_equal("path-val", type.path);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001338 assert_true(type.flags & LYS_SET_PATH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001339 lysp_type_free(st->ctx, &type);
1340
1341 st->finished_correctly = true;
1342}
1343
1344static void
1345test_pattern_elem(void **state)
1346{
1347 struct state *st = *state;
1348 const char *data;
1349 struct lysp_type type = {};
1350
1351 /* max subelems */
1352 data = ELEMENT_WRAPPER_START
1353 "<pattern value=\"super_pattern\">"
1354 "<modifier value=\"invert-match\"/>"
1355 "<error-message><value>err-msg-value</value></error-message>"
1356 "<error-app-tag value=\"err-app-tag-value\"/>"
1357 "<description><text>pattern-desc</text></description>"
1358 "<reference><text>pattern-ref</text></reference>"
1359 "</pattern>"
1360 ELEMENT_WRAPPER_END;
1361 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001362 assert_true(type.flags & LYS_SET_PATTERN);
David Sedlák8e7bda82019-07-16 17:57:50 +02001363 assert_string_equal(type.patterns->arg, "\x015super_pattern");
1364 assert_string_equal(type.patterns->dsc, "pattern-desc");
1365 assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
1366 assert_string_equal(type.patterns->emsg, "err-msg-value");
1367 assert_string_equal(type.patterns->dsc, "pattern-desc");
1368 assert_string_equal(type.patterns->ref, "pattern-ref");
1369 lysp_type_free(st->ctx, &type);
1370 memset(&type, 0, sizeof(type));
1371
1372 /* min subelems */
1373 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
1374 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1375 assert_string_equal(type.patterns->arg, "\x006pattern");
1376 lysp_type_free(st->ctx, &type);
1377 memset(&type, 0, sizeof(type));
1378
1379 st->finished_correctly = true;
1380}
1381
1382static void
1383test_value_position_elem(void **state)
1384{
1385 struct state *st = *state;
1386 const char *data;
1387 struct lysp_type_enum en = {};
1388
1389 /* valid values */
1390 data = ELEMENT_WRAPPER_START "<value value=\"55\" />" ELEMENT_WRAPPER_END;
1391 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1392 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001393 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001394 memset(&en, 0, sizeof(en));
1395
1396 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
1397 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1398 assert_int_equal(en.value, -55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001399 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001400 memset(&en, 0, sizeof(en));
1401
1402 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
1403 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1404 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001405 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001406 memset(&en, 0, sizeof(en));
1407
1408 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
1409 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1410 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001411 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001412 memset(&en, 0, sizeof(en));
1413
1414 /* valid positions */
1415 data = ELEMENT_WRAPPER_START "<position value=\"55\" />" ELEMENT_WRAPPER_END;
1416 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1417 assert_int_equal(en.value, 55);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001418 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001419 memset(&en, 0, sizeof(en));
1420
1421 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
1422 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS);
1423 assert_int_equal(en.value, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001424 assert_true(en.flags & LYS_SET_VALUE);
David Sedlák8e7bda82019-07-16 17:57:50 +02001425 memset(&en, 0, sizeof(en));
1426
1427 /* invalid values */
1428 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
1429 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1430 logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\". Line number 1.");
1431
1432 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
1433 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1434 logbuf_assert("Invalid value \"1k\" of \"value\". Line number 1.");
1435
David Sedlák69f01612019-07-17 11:41:08 +02001436 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
1437 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1438 logbuf_assert("Invalid value \"\" of \"value\". Line number 1.");
1439
David Sedlák8e7bda82019-07-16 17:57:50 +02001440 /*invalid positions */
1441 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
1442 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1443 logbuf_assert("Invalid value \"-5\" of \"position\". Line number 1.");
1444
1445 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
1446 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1447 logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1.");
1448
1449 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
1450 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1451 logbuf_assert("Invalid value \"99999999999999999999\" of \"position\". Line number 1.");
1452
David Sedlák69f01612019-07-17 11:41:08 +02001453 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
1454 assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID);
1455 logbuf_assert("Invalid value \"\" of \"position\". Line number 1.");
1456
1457 st->finished_correctly = true;
1458}
1459
1460static void
1461test_prefix_elem(void **state)
1462{
1463 struct state *st = *state;
1464 const char *data;
1465 const char *value = NULL;
1466
1467 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
1468 assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS);
1469 assert_string_equal(value, "pref");
1470 FREE_STRING(st->ctx, value);
1471
1472 st->finished_correctly = true;
1473}
1474
1475static void
1476test_range_elem(void **state)
1477{
1478 struct state *st = *state;
1479 const char *data;
1480 struct lysp_type type = {};
1481
1482 /* max subelems */
1483 data = ELEMENT_WRAPPER_START
1484 "<range value=\"range-str\">"
1485 "<error-message><value>err-msg</value></error-message>"
1486 "<error-app-tag value=\"err-app-tag\" />"
1487 "<description><text>desc</text></description>"
1488 "<reference><text>ref</text></reference>"
1489 "</range>"
1490 ELEMENT_WRAPPER_END;
1491 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1492 assert_string_equal(type.range->arg, "range-str");
1493 assert_string_equal(type.range->dsc, "desc");
1494 assert_string_equal(type.range->eapptag, "err-app-tag");
1495 assert_string_equal(type.range->emsg, "err-msg");
1496 assert_string_equal(type.range->ref, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001497 assert_true(type.flags & LYS_SET_RANGE);
David Sedlák69f01612019-07-17 11:41:08 +02001498 lysp_type_free(st->ctx, &type);
1499 memset(&type, 0, sizeof(type));
1500
1501 /* min subelems */
1502 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
1503 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1504 assert_string_equal(type.range->arg, "range-str");
1505 lysp_type_free(st->ctx, &type);
1506 memset(&type, 0, sizeof(type));
1507
1508 st->finished_correctly = true;
1509}
1510
1511static void
1512test_reqinstance_elem(void **state)
1513{
1514 struct state *st = *state;
1515 const char *data;
1516 struct lysp_type type = {};
1517
1518 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\"/>" ELEMENT_WRAPPER_END;
1519 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1520 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001521 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001522 memset(&type, 0, sizeof(type));
1523
1524 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
1525 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1526 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001527 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001528 memset(&type, 0, sizeof(type));
1529
1530 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
1531 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID);
1532 memset(&type, 0, sizeof(type));
1533 logbuf_assert("Invalid value \"invalid\" of \"require-instance\". Line number 1.");
1534
1535 st->finished_correctly = true;
1536}
1537
1538static void
1539test_revision_date_elem(void **state)
1540{
1541 struct state *st = *state;
1542 const char *data;
1543 char rev[LY_REV_SIZE];
1544
1545 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
1546 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS);
1547 assert_string_equal(rev, "2000-01-01");
1548
1549 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
1550 assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID);
1551 logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
1552
1553 st->finished_correctly = true;
1554}
1555
1556static void
1557test_unique_elem(void **state)
1558{
1559 struct state *st = *state;
1560 const char *data;
1561 const char **values = NULL;
1562
1563 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
1564 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1565 assert_string_equal(*values, "tag");
1566 FREE_STRING(st->ctx, *values);
1567 LY_ARRAY_FREE(values);
1568
1569 st->finished_correctly = true;
1570}
1571
1572static void
1573test_units_elem(void **state)
1574{
1575 struct state *st = *state;
1576 const char *data;
1577 const char *values = NULL;
1578
1579 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
1580 assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS);
1581 assert_string_equal(values, "name");
1582 FREE_STRING(st->ctx, values);
1583
1584 st->finished_correctly = true;
1585}
1586
1587static void
1588test_when_elem(void **state)
1589{
1590 struct state *st = *state;
1591 const char *data;
1592 struct lysp_when *when = NULL;
1593
1594 data = ELEMENT_WRAPPER_START
1595 "<when condition=\"cond\">"
1596 "<description><text>desc</text></description>"
1597 "<reference><text>ref</text></reference>"
1598 "</when>"
1599 ELEMENT_WRAPPER_END;
1600 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
1601 assert_string_equal(when->cond, "cond");
1602 assert_string_equal(when->dsc, "desc");
1603 assert_string_equal(when->ref, "ref");
1604 lysp_when_free(st->ctx, when);
1605 free(when);
1606 when = NULL;
1607
1608 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
1609 assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS);
1610 assert_string_equal(when->cond, "cond");
1611 lysp_when_free(st->ctx, when);
1612 free(when);
1613 when = NULL;
1614
1615 st->finished_correctly = true;
1616}
1617
1618static void
1619test_yin_text_value_elem(void **state)
1620{
1621 struct state *st = *state;
1622 const char *data;
1623 const char *val;
1624
1625 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
1626 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1627 assert_string_equal(val, "text");
1628 FREE_STRING(st->ctx, val);
1629
1630 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
1631 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1632 assert_string_equal(val, "text");
1633 FREE_STRING(st->ctx, val);
1634
1635 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
1636 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
1637 assert_string_equal("", val);
1638 FREE_STRING(st->ctx, val);
1639
David Sedlák8e7bda82019-07-16 17:57:50 +02001640 st->finished_correctly = true;
1641}
David Sedlák32488102019-07-15 17:44:10 +02001642
David Sedlák374d2b32019-07-17 15:06:55 +02001643static void
1644test_type_elem(void **state)
1645{
1646 struct state *st = *state;
1647 const char *data;
1648 struct lysp_type type = {};
1649
1650 /* max subelems */
1651 data = ELEMENT_WRAPPER_START
1652 "<type name=\"type-name\">"
1653 "<base name=\"base-name\"/>"
1654 "<bit name=\"bit\"/>"
1655 "<enum name=\"enum\"/>"
1656 "<fraction-digits value=\"2\"/>"
1657 "<length value=\"length\"/>"
1658 "<path value=\"path\"/>"
1659 "<pattern value=\"pattern\"/>"
1660 "<range value=\"range\" />"
1661 "<require-instance value=\"true\"/>"
1662 "<type name=\"sub-type-name\"/>"
1663 "</type>"
1664 ELEMENT_WRAPPER_END;
1665 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1666 assert_string_equal(type.name, "type-name");
1667 assert_string_equal(*type.bases, "base-name");
1668 assert_string_equal(type.bits->name, "bit");
1669 assert_string_equal(type.enums->name, "enum");
1670 assert_int_equal(type.fraction_digits, 2);
1671 assert_string_equal(type.length->arg, "length");
1672 assert_string_equal(type.path, "path");
1673 assert_string_equal(type.patterns->arg, "\006pattern");
1674 assert_string_equal(type.range->arg, "range");
1675 assert_int_equal(type.require_instance, 1);
1676 assert_string_equal(type.types->name, "sub-type-name");
1677 lysp_type_free(st->ctx, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001678 assert_true(type.flags & LYS_SET_BASE);
1679 assert_true(type.flags & LYS_SET_BIT);
1680 assert_true(type.flags & LYS_SET_ENUM);
1681 assert_true(type.flags & LYS_SET_FRDIGITS);
1682 assert_true(type.flags & LYS_SET_LENGTH);
1683 assert_true(type.flags & LYS_SET_PATH);
1684 assert_true(type.flags & LYS_SET_PATTERN);
1685 assert_true(type.flags & LYS_SET_RANGE);
1686 assert_true(type.flags & LYS_SET_REQINST);
1687 assert_true(type.flags & LYS_SET_TYPE);
David Sedlák374d2b32019-07-17 15:06:55 +02001688 memset(&type, 0, sizeof(type));
1689
1690 /* min subelems */
1691 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
1692 assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS);
1693 lysp_type_free(st->ctx, &type);
1694 memset(&type, 0, sizeof(type));
1695
1696 st->finished_correctly = true;
1697}
1698
David Sedlák1af868e2019-07-17 17:03:14 +02001699static void
1700test_max_elems_elem(void **state)
1701{
1702 struct state *st = *state;
1703 const char *data;
1704 struct lysp_node_list list = {};
1705 struct lysp_node_leaflist llist = {};
1706 struct lysp_refine refine = {};
1707
1708 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\"/> </refine>";
1709 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1710 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001711 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001712
1713 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\"/> </list>";
1714 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
1715 assert_int_equal(list.max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001716 assert_true(list.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001717
1718 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\"/> </leaf-list>";
1719 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
1720 assert_int_equal(llist.max, 85);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001721 assert_true(llist.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001722
1723 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
1724 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1725 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001726 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001727
1728 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
1729 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1730 logbuf_assert("Invalid value \"0\" of \"max-elements\". Line number 1.");
1731
1732 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
1733 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1734 logbuf_assert("Invalid value \"-10\" of \"max-elements\". Line number 1.");
1735
1736 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
1737 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1738 logbuf_assert("Invalid value \"k\" of \"max-elements\". Line number 1.");
1739
1740 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
1741 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID);
1742 logbuf_assert("Invalid value \"u12\" of \"max-elements\". Line number 1.");
1743
1744 st->finished_correctly = true;
1745}
1746
David Sedlák09e18c92019-07-18 11:17:11 +02001747static void
1748test_min_elems_elem(void **state)
1749{
1750 struct state *st = *state;
1751 const char *data;
1752 struct lysp_node_list list = {};
1753 struct lysp_node_leaflist llist = {};
1754 struct lysp_refine refine = {};
1755
1756 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\"/> </refine>";
1757 assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS);
1758 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001759 assert_true(refine.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001760
1761 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\"/> </list>";
1762 assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS);
1763 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001764 assert_true(list.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001765
1766 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\"/> </leaf-list>";
1767 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS);
1768 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001769 assert_true(llist.flags & LYS_SET_MIN);
David Sedlák09e18c92019-07-18 11:17:11 +02001770
1771 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
1772 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1773 logbuf_assert("Value \"-5\" is out of \"min-elements\" bounds. Line number 1.");
1774
1775 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
1776 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1777 logbuf_assert("Value \"99999999999999999\" is out of \"min-elements\" bounds. Line number 1.");
1778
1779 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
1780 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1781 logbuf_assert("Invalid value \"5k\" of \"min-elements\". Line number 1.");
1782
1783 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
1784 assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID);
1785 logbuf_assert("Invalid value \"05\" of \"min-elements\". Line number 1.");
1786
1787 st->finished_correctly = true;
1788}
1789
David Sedláka2dad212019-07-18 12:45:19 +02001790static void
1791test_ordby_elem(void **state)
1792{
1793 struct state *st = *state;
1794 const char *data;
1795 uint16_t flags = 0;
1796
1797 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\"/>" ELEMENT_WRAPPER_END;
1798 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001799 assert_true(flags & LYS_ORDBY_SYSTEM);
David Sedláka2dad212019-07-18 12:45:19 +02001800
1801 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
1802 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001803 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001804
1805 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
1806 assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID);
1807 logbuf_assert("Invalid value \"inv\" of \"ordered-by\". Line number 1.");
1808
1809 st->finished_correctly = true;
1810}
1811
David Sedlák8a83bbb2019-07-18 14:46:00 +02001812static void
1813test_any_elem(void **state)
1814{
1815 struct state *st = *state;
1816 const char *data;
1817 struct lysp_node *siblings = NULL;
1818 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1819 struct lysp_node_anydata *parsed = NULL;
1820
1821 /* anyxml max subelems */
1822 data = ELEMENT_WRAPPER_START
1823 "<anyxml name=\"any-name\">"
1824 "<config value=\"true\" />"
1825 "<description><text>desc</text></description>"
1826 "<if-feature name=\"feature\" />"
1827 "<mandatory value=\"true\" />"
1828 "<must condition=\"must-cond\" />"
1829 "<reference><text>ref</text></reference>"
1830 "<status value=\"deprecated\"/>"
1831 "<when condition=\"when-cond\"/>"
1832 "</anyxml>"
1833 ELEMENT_WRAPPER_END;
1834 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1835 parsed = (struct lysp_node_anydata *)siblings;
1836 assert_null(parsed->parent);
1837 assert_int_equal(parsed->nodetype, LYS_ANYXML);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001838 assert_true(parsed->flags & LYS_CONFIG_W);
1839 assert_true(parsed->flags & LYS_MAND_TRUE);
1840 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001841 assert_null(parsed->next);
1842 assert_string_equal(parsed->name, "any-name");
1843 assert_string_equal(parsed->dsc, "desc");
1844 assert_string_equal(parsed->ref, "ref");
1845 assert_string_equal(parsed->when->cond, "when-cond");
1846 assert_string_equal(*parsed->iffeatures, "feature");
1847 assert_null(parsed->exts);
1848 lysp_node_free(st->ctx, siblings);
1849 siblings = NULL;
1850
1851 /* anydata max subelems */
1852 data = ELEMENT_WRAPPER_START
1853 "<anydata name=\"any-name\">"
1854 "<config value=\"true\" />"
1855 "<description><text>desc</text></description>"
1856 "<if-feature name=\"feature\" />"
1857 "<mandatory value=\"true\" />"
1858 "<must condition=\"must-cond\" />"
1859 "<reference><text>ref</text></reference>"
1860 "<status value=\"deprecated\"/>"
1861 "<when condition=\"when-cond\"/>"
1862 "</anydata>"
1863 ELEMENT_WRAPPER_END;
1864 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1865 parsed = (struct lysp_node_anydata *)siblings;
1866 assert_null(parsed->parent);
1867 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001868 assert_true(parsed->flags & LYS_CONFIG_W);
1869 assert_true(parsed->flags & LYS_MAND_TRUE);
1870 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001871 assert_null(parsed->next);
1872 assert_string_equal(parsed->name, "any-name");
1873 assert_string_equal(parsed->dsc, "desc");
1874 assert_string_equal(parsed->ref, "ref");
1875 assert_string_equal(parsed->when->cond, "when-cond");
1876 assert_string_equal(*parsed->iffeatures, "feature");
1877 assert_null(parsed->exts);
1878 lysp_node_free(st->ctx, siblings);
1879 siblings = NULL;
1880
1881 /* min subelems */
1882 node_meta.parent = (void *)0x10;
1883 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
1884 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1885 parsed = (struct lysp_node_anydata *)siblings;
1886 assert_ptr_equal(parsed->parent, node_meta.parent);
1887 assert_int_equal(parsed->nodetype, LYS_ANYDATA);
1888 assert_null(parsed->next);
1889 assert_null(parsed->exts);
1890 lysp_node_free(st->ctx, siblings);
1891
1892 st->finished_correctly = true;
1893}
1894
David Sedlák203ca3a2019-07-18 15:26:25 +02001895static void
1896test_leaf_elem(void **state)
1897{
1898 struct state *st = *state;
1899 const char *data;
1900 struct lysp_node *siblings = NULL;
1901 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1902 struct lysp_node_leaf *parsed = NULL;
1903
1904 /* max elements */
1905 data = ELEMENT_WRAPPER_START
1906 "<leaf name=\"leaf\">"
1907 "<config value=\"true\" />"
1908 "<default value=\"def-val\"/>"
1909 "<description><text>desc</text></description>"
1910 "<if-feature name=\"feature\" />"
1911 "<mandatory value=\"true\" />"
1912 "<must condition=\"must-cond\" />"
1913 "<reference><text>ref</text></reference>"
1914 "<status value=\"deprecated\"/>"
1915 "<type name=\"type\"/>"
1916 "<units name=\"uni\"/>"
1917 "<when condition=\"when-cond\"/>"
1918 "</leaf>"
1919 ELEMENT_WRAPPER_END;
1920 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1921 parsed = (struct lysp_node_leaf *)siblings;
1922 assert_null(parsed->parent);
1923 assert_int_equal(parsed->nodetype, LYS_LEAF);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001924 assert_true(parsed->flags & LYS_CONFIG_W);
1925 assert_true(parsed->flags & LYS_MAND_TRUE);
1926 assert_true(parsed->flags & LYS_STATUS_DEPRC);
David Sedlák203ca3a2019-07-18 15:26:25 +02001927 assert_null(parsed->next);
1928 assert_string_equal(parsed->name, "leaf");
1929 assert_string_equal(parsed->dsc, "desc");
1930 assert_string_equal(parsed->ref, "ref");
1931 assert_string_equal(parsed->when->cond, "when-cond");
1932 assert_string_equal(*parsed->iffeatures, "feature");
1933 assert_null(parsed->exts);
1934 assert_string_equal(parsed->musts->arg, "must-cond");
1935 assert_string_equal(parsed->type.name, "type");
1936 assert_string_equal(parsed->units, "uni");
1937 assert_string_equal(parsed->dflt, "def-val");
1938 lysp_node_free(st->ctx, siblings);
1939 siblings = NULL;
1940
1941 /* min elements */
1942 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
1943 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1944 parsed = (struct lysp_node_leaf *)siblings;
1945 assert_string_equal(parsed->name, "leaf");
1946 assert_string_equal(parsed->type.name, "type");
1947 lysp_node_free(st->ctx, siblings);
1948 siblings = NULL;
1949
1950 st->finished_correctly = true;
1951}
1952
David Sedlákc3da3ef2019-07-19 12:56:08 +02001953static void
1954test_leaf_list_elem(void **state)
1955{
1956 struct state *st = *state;
1957 const char *data;
1958 struct lysp_node *siblings = NULL;
1959 struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings};
1960 struct lysp_node_leaflist *parsed = NULL;
1961
1962 data = ELEMENT_WRAPPER_START
1963 "<leaf-list name=\"llist\">"
1964 "<config value=\"true\" />"
1965 "<default value=\"def-val0\"/>"
1966 "<default value=\"def-val1\"/>"
1967 "<description><text>desc</text></description>"
1968 "<if-feature name=\"feature\"/>"
1969 "<max-elements value=\"5\"/>"
1970 "<must condition=\"must-cond\"/>"
1971 "<ordered-by value=\"user\" />"
1972 "<reference><text>ref</text></reference>"
1973 "<status value=\"current\"/>"
1974 "<type name=\"type\"/>"
1975 "<units name=\"uni\"/>"
1976 "<when condition=\"when-cond\"/>"
1977 "</leaf-list>"
1978 ELEMENT_WRAPPER_END;
1979 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
1980 parsed = (struct lysp_node_leaflist *)siblings;
1981 assert_string_equal(parsed->dflts[0], "def-val0");
1982 assert_string_equal(parsed->dflts[1], "def-val1");
1983 assert_string_equal(parsed->dsc, "desc");
1984 assert_string_equal(*parsed->iffeatures, "feature");
1985 assert_int_equal(parsed->max, 5);
1986 assert_string_equal(parsed->musts->arg, "must-cond");
1987 assert_string_equal(parsed->name, "llist");
1988 assert_null(parsed->next);
1989 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
1990 assert_null(parsed->parent);
1991 assert_string_equal(parsed->ref, "ref");
1992 assert_string_equal(parsed->type.name, "type");
1993 assert_string_equal(parsed->units, "uni");
1994 assert_string_equal(parsed->when->cond, "when-cond");
1995 assert_true(parsed->flags & LYS_CONFIG_W);
1996 assert_true(parsed->flags & LYS_ORDBY_USER);
1997 assert_true(parsed->flags & LYS_STATUS_CURR);
1998 lysp_node_free(st->ctx, siblings);
1999 siblings = NULL;
2000
2001 data = ELEMENT_WRAPPER_START
2002 "<leaf-list name=\"llist\">"
2003 "<config value=\"true\" />"
2004 "<description><text>desc</text></description>"
2005 "<if-feature name=\"feature\"/>"
2006 "<min-elements value=\"5\"/>"
2007 "<must condition=\"must-cond\"/>"
2008 "<ordered-by value=\"user\" />"
2009 "<reference><text>ref</text></reference>"
2010 "<status value=\"current\"/>"
2011 "<type name=\"type\"/>"
2012 "<units name=\"uni\"/>"
2013 "<when condition=\"when-cond\"/>"
2014 "</leaf-list>"
2015 ELEMENT_WRAPPER_END;
2016 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2017 parsed = (struct lysp_node_leaflist *)siblings;
2018 assert_string_equal(parsed->dsc, "desc");
2019 assert_string_equal(*parsed->iffeatures, "feature");
2020 assert_int_equal(parsed->min, 5);
2021 assert_string_equal(parsed->musts->arg, "must-cond");
2022 assert_string_equal(parsed->name, "llist");
2023 assert_null(parsed->next);
2024 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2025 assert_null(parsed->parent);
2026 assert_string_equal(parsed->ref, "ref");
2027 assert_string_equal(parsed->type.name, "type");
2028 assert_string_equal(parsed->units, "uni");
2029 assert_string_equal(parsed->when->cond, "when-cond");
2030 assert_true(parsed->flags & LYS_CONFIG_W);
2031 assert_true(parsed->flags & LYS_ORDBY_USER);
2032 assert_true(parsed->flags & LYS_STATUS_CURR);
2033 lysp_node_free(st->ctx, siblings);
2034 siblings = NULL;
2035
2036 data = ELEMENT_WRAPPER_START
2037 "<leaf-list name=\"llist\">"
2038 "<config value=\"true\" />"
2039 "<description><text>desc</text></description>"
2040 "<if-feature name=\"feature\"/>"
2041 "<max-elements value=\"15\"/>"
2042 "<min-elements value=\"5\"/>"
2043 "<must condition=\"must-cond\"/>"
2044 "<ordered-by value=\"user\" />"
2045 "<reference><text>ref</text></reference>"
2046 "<status value=\"current\"/>"
2047 "<type name=\"type\"/>"
2048 "<units name=\"uni\"/>"
2049 "<when condition=\"when-cond\"/>"
2050 "</leaf-list>"
2051 ELEMENT_WRAPPER_END;
2052 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2053 parsed = (struct lysp_node_leaflist *)siblings;
2054 assert_string_equal(parsed->dsc, "desc");
2055 assert_string_equal(*parsed->iffeatures, "feature");
2056 assert_int_equal(parsed->min, 5);
2057 assert_int_equal(parsed->max, 15);
2058 assert_string_equal(parsed->musts->arg, "must-cond");
2059 assert_string_equal(parsed->name, "llist");
2060 assert_null(parsed->next);
2061 assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
2062 assert_null(parsed->parent);
2063 assert_string_equal(parsed->ref, "ref");
2064 assert_string_equal(parsed->type.name, "type");
2065 assert_string_equal(parsed->units, "uni");
2066 assert_string_equal(parsed->when->cond, "when-cond");
2067 assert_true(parsed->flags & LYS_CONFIG_W);
2068 assert_true(parsed->flags & LYS_ORDBY_USER);
2069 assert_true(parsed->flags & LYS_STATUS_CURR);
2070 lysp_node_free(st->ctx, siblings);
2071 siblings = NULL;
2072
2073 data = ELEMENT_WRAPPER_START
2074 "<leaf-list name=\"llist\">"
2075 "<type name=\"type\"/>"
2076 "</leaf-list>"
2077 ELEMENT_WRAPPER_END;
2078 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2079 parsed = (struct lysp_node_leaflist *)siblings;
2080 assert_string_equal(parsed->name, "llist");
2081 assert_string_equal(parsed->type.name, "type");
2082 lysp_node_free(st->ctx, siblings);
2083 siblings = NULL;
2084
2085 /* invalid combinations */
2086 data = ELEMENT_WRAPPER_START
2087 "<leaf-list name=\"llist\">"
2088 "<max-elements value=\"5\"/>"
2089 "<min-elements value=\"15\"/>"
2090 "<type name=\"type\"/>"
2091 "</leaf-list>"
2092 ELEMENT_WRAPPER_END;
2093 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2094 logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1.");
2095 lysp_node_free(st->ctx, siblings);
2096 siblings = NULL;
2097
2098 data = ELEMENT_WRAPPER_START
2099 "<leaf-list name=\"llist\">"
2100 "<default value=\"def-val1\"/>"
2101 "<min-elements value=\"15\"/>"
2102 "<type name=\"type\"/>"
2103 "</leaf-list>"
2104 ELEMENT_WRAPPER_END;
2105 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2106 logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1.");
2107 lysp_node_free(st->ctx, siblings);
2108 siblings = NULL;
2109
2110 data = ELEMENT_WRAPPER_START
2111 "<leaf-list name=\"llist\">"
2112 "</leaf-list>"
2113 ELEMENT_WRAPPER_END;
2114 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID);
2115 logbuf_assert("Missing mandatory subelement type of leaf-list element. Line number 1.");
2116 lysp_node_free(st->ctx, siblings);
2117 siblings = NULL;
2118
2119 st->finished_correctly = true;
2120}
2121
David Sedlákcb39f642019-07-19 13:19:55 +02002122static void
2123test_presence_elem(void **state)
2124{
2125 struct state *st = *state;
2126 const char *data;
2127 const char *val;
2128
2129 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
2130 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2131 assert_string_equal(val, "presence-val");
2132 FREE_STRING(st->ctx, val);
2133
2134 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
2135 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2136 logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
2137
2138 st->finished_correctly = true;
2139}
2140
David Sedlák12470a82019-07-19 13:44:36 +02002141static void
2142test_key_elem(void **state)
2143{
2144 struct state *st = *state;
2145 const char *data;
2146 const char *val;
2147
2148 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
2149 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS);
2150 assert_string_equal(val, "key-value");
2151 FREE_STRING(st->ctx, val);
2152
2153 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
2154 assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID);
2155 logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
2156
2157 st->finished_correctly = true;
2158}
2159
David Sedlák04e17b22019-07-19 15:29:48 +02002160static void
2161test_typedef_elem(void **state)
2162{
2163 struct state *st = *state;
2164 const char *data;
2165 struct lysp_tpdf *tpdfs = NULL;
2166 struct typedef_meta typdef_meta = {NULL, &tpdfs};
2167
2168 data = ELEMENT_WRAPPER_START
2169 "<typedef name=\"tpdf-name\">"
2170 "<default value=\"def-val\"/>"
2171 "<description><text>desc-text</text></description>"
2172 "<reference><text>ref-text</text></reference>"
2173 "<status value=\"current\"/>"
2174 "<type name=\"type\"/>"
2175 "<units name=\"uni\"/>"
2176 "</typedef>"
2177 ELEMENT_WRAPPER_END;
2178 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2179 assert_string_equal(tpdfs[0].dflt, "def-val");
2180 assert_string_equal(tpdfs[0].dsc, "desc-text");
2181 assert_null(tpdfs[0].exts);
2182 assert_string_equal(tpdfs[0].name, "tpdf-name");
2183 assert_string_equal(tpdfs[0].ref, "ref-text");
2184 assert_string_equal(tpdfs[0].type.name, "type");
2185 assert_string_equal(tpdfs[0].units, "uni");
2186 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
2187 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2188 tpdfs = NULL;
2189
2190 data = ELEMENT_WRAPPER_START
2191 "<typedef name=\"tpdf-name\">"
2192 "<type name=\"type\"/>"
2193 "</typedef>"
2194 ELEMENT_WRAPPER_END;
2195 assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS);
2196 assert_string_equal(tpdfs[0].name, "tpdf-name");
2197 assert_string_equal(tpdfs[0].type.name, "type");
2198 FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
2199 tpdfs = NULL;
2200
2201 st->finished_correctly = true;
2202}
2203
David Sedlákd2d676a2019-07-22 11:28:19 +02002204static void
2205test_refine_elem(void **state)
2206{
2207 struct state *st = *state;
2208 const char *data;
2209 struct lysp_refine *refines = NULL;
2210
2211 /* max subelems */
2212 data = ELEMENT_WRAPPER_START
2213 "<refine target-node=\"target\">"
2214 "<if-feature name=\"feature\" />"
2215 "<must condition=\"cond\" />"
2216 "<presence value=\"presence\" />"
2217 "<default value=\"def\" />"
2218 "<config value=\"true\" />"
2219 "<mandatory value=\"true\" />"
2220 "<min-elements value=\"10\" />"
2221 "<max-elements value=\"20\" />"
2222 "<description><text>desc</text></description>"
2223 "<reference><text>ref</text></reference>"
2224 "</refine>"
2225 ELEMENT_WRAPPER_END;
2226 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2227 assert_string_equal(refines->nodeid, "target");
2228 assert_string_equal(*refines->dflts, "def");
2229 assert_string_equal(refines->dsc, "desc");
2230 assert_null(refines->exts);
2231 assert_true(refines->flags & LYS_CONFIG_W);
2232 assert_true(refines->flags & LYS_MAND_TRUE);
2233 assert_string_equal(*refines->iffeatures, "feature");
2234 assert_int_equal(refines->max, 20);
2235 assert_int_equal(refines->min, 10);
2236 assert_string_equal(refines->musts->arg, "cond");
2237 assert_string_equal(refines->presence, "presence");
2238 assert_string_equal(refines->ref, "ref");
2239 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2240 refines = NULL;
2241
2242 /* min subelems */
2243 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
2244 assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS);
2245 assert_string_equal(refines->nodeid, "target");
2246 FREE_ARRAY(st->ctx, refines, lysp_refine_free);
2247 refines = NULL;
2248
2249 st->finished_correctly = true;
2250}
2251
David Sedlák0d6de5a2019-07-22 13:25:44 +02002252static void
2253test_uses_elem(void **state)
2254{
2255 struct state *st = *state;
2256 const char *data;
2257 struct lysp_node *siblings = NULL;
2258 struct tree_node_meta node_meta = {NULL, &siblings};
2259 struct lysp_node_uses *parsed = NULL;
2260
2261 /* max subelems */
2262 data = ELEMENT_WRAPPER_START
2263 "<uses name=\"uses-name\">"
2264 "<when condition=\"cond\" />"
2265 "<if-feature name=\"feature\" />"
2266 "<status value=\"obsolete\" />"
2267 "<description><text>desc</text></description>"
2268 "<reference><text>ref</text></reference>"
2269 "<refine target-node=\"target\"/>"
David Sedlák992fb7c2019-07-24 16:51:01 +02002270 "<augment target-node=\"target\" />"
David Sedlák0d6de5a2019-07-22 13:25:44 +02002271 "</uses>"
2272 ELEMENT_WRAPPER_END;
2273 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2274 parsed = (struct lysp_node_uses *)&siblings[0];
2275 assert_string_equal(parsed->name, "uses-name");
2276 assert_string_equal(parsed->dsc, "desc");
2277 assert_null(parsed->exts);
2278 assert_true(parsed->flags & LYS_STATUS_OBSLT);
2279 assert_string_equal(*parsed->iffeatures, "feature");
2280 assert_null(parsed->next);
2281 assert_int_equal(parsed->nodetype, LYS_USES);
2282 assert_null(parsed->parent);
2283 assert_string_equal(parsed->ref, "ref");
2284 assert_string_equal(parsed->refines->nodeid, "target");
2285 assert_string_equal(parsed->when->cond, "cond");
David Sedlák992fb7c2019-07-24 16:51:01 +02002286 assert_string_equal(parsed->augments->nodeid, "target");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002287 lysp_node_free(st->ctx, siblings);
2288 siblings = NULL;
2289
2290 /* min subelems */
2291 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
2292 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2293 assert_string_equal(siblings[0].name, "uses-name");
2294 lysp_node_free(st->ctx, siblings);
2295 siblings = NULL;
2296
2297 st->finished_correctly = true;
2298}
2299
David Sedlákaa854b02019-07-22 14:17:10 +02002300static void
2301test_revision_elem(void **state)
2302{
2303 struct state *st = *state;
2304 const char *data;
2305 struct lysp_revision *revs = NULL;
2306
2307 /* max subelems */
2308 data = ELEMENT_WRAPPER_START
2309 "<revision date=\"2018-12-25\">"
2310 "<description><text>desc</text></description>"
2311 "<reference><text>ref</text></reference>"
2312 "</revision>"
2313 ELEMENT_WRAPPER_END;
2314 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2315 assert_string_equal(revs->date, "2018-12-25");
2316 assert_string_equal(revs->dsc, "desc");
2317 assert_string_equal(revs->ref, "ref");
2318 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2319 revs = NULL;
2320
2321 /* min subelems */
2322 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
2323 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS);
2324 assert_string_equal(revs->date, "2005-05-05");
2325 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2326 revs = NULL;
2327
2328 /* invalid value */
2329 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
2330 assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID);
2331 logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
2332 FREE_ARRAY(st->ctx, revs, lysp_revision_free);
2333 revs = NULL;
2334
2335 st->finished_correctly = true;
2336}
2337
David Sedlák0c2bab92019-07-22 15:33:19 +02002338static void
2339test_include_elem(void **state)
2340{
2341 struct state *st = *state;
2342 const char *data;
2343 struct lysp_include *includes = NULL;
2344 struct include_meta inc_meta = {"module-name", &includes};
2345
2346 /* max subelems */
2347 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2348 data = ELEMENT_WRAPPER_START
2349 "<include module=\"mod\">"
2350 "<description><text>desc</text></description>"
2351 "<reference><text>ref</text></reference>"
2352 "<revision-date date=\"1999-09-09\"/>"
2353 "</include>"
2354 ELEMENT_WRAPPER_END;
2355 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2356 assert_string_equal(includes->name, "mod");
2357 assert_string_equal(includes->dsc, "desc");
2358 assert_string_equal(includes->ref, "ref");
2359 assert_null(includes->exts);
2360 assert_string_equal(includes->rev, "1999-09-09");
2361 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2362 includes = NULL;
2363
2364 /* min subelems */
2365 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
2366 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS);
2367 assert_string_equal(includes->name, "mod");
2368 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2369 includes = NULL;
2370
2371 /* invalid combinations */
2372 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2373 data = ELEMENT_WRAPPER_START
2374 "<include module=\"mod\">"
2375 "<description><text>desc</text></description>"
2376 "<revision-date date=\"1999-09-09\"/>"
2377 "</include>"
2378 ELEMENT_WRAPPER_END;
2379 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2380 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.");
2381 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2382 includes = NULL;
2383
2384 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2385 data = ELEMENT_WRAPPER_START
2386 "<include module=\"mod\">"
2387 "<reference><text>ref</text></reference>"
2388 "<revision-date date=\"1999-09-09\"/>"
2389 "</include>"
2390 ELEMENT_WRAPPER_END;
2391 assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID);
2392 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.");
2393 FREE_ARRAY(st->ctx, includes, lysp_include_free);
2394 includes = NULL;
2395
2396 st->finished_correctly = true;
2397}
2398
David Sedlák5e13dea2019-07-22 16:06:45 +02002399static void
2400test_feature_elem(void **state)
2401{
2402 struct state *st = *state;
2403 const char *data;
2404 struct lysp_feature *features = NULL;
2405
2406 /* max subelems */
2407 data = ELEMENT_WRAPPER_START
2408 "<feature name=\"feature-name\">"
2409 "<if-feature name=\"iff\"/>"
2410 "<status value=\"deprecated\"/>"
2411 "<description><text>desc</text></description>"
2412 "<reference><text>ref</text></reference>"
2413 "</feature>"
2414 ELEMENT_WRAPPER_END;
2415 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2416 assert_string_equal(features->name, "feature-name");
2417 assert_string_equal(features->dsc, "desc");
2418 assert_null(features->exts);
2419 assert_true(features->flags & LYS_STATUS_DEPRC);
2420 assert_string_equal(*features->iffeatures, "iff");
2421 assert_string_equal(features->ref, "ref");
2422 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2423 features = NULL;
2424
2425 /* min subelems */
2426 data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
2427 assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
2428 assert_string_equal(features->name, "feature-name");
2429 FREE_ARRAY(st->ctx, features, lysp_feature_free);
2430 features = NULL;
2431
2432 st->finished_correctly = true;
2433}
2434
David Sedlák28794f22019-07-22 16:45:00 +02002435static void
2436test_identity_elem(void **state)
2437{
2438 struct state *st = *state;
2439 const char *data;
2440 struct lysp_ident *identities = NULL;
2441
2442 /* max subelems */
2443 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2444 data = ELEMENT_WRAPPER_START
2445 "<identity name=\"ident-name\">"
2446 "<if-feature name=\"iff\"/>"
2447 "<base name=\"base-name\"/>"
2448 "<status value=\"deprecated\"/>"
2449 "<description><text>desc</text></description>"
2450 "<reference><text>ref</text></reference>"
2451 "</identity>"
2452 ELEMENT_WRAPPER_END;
2453 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2454 assert_string_equal(identities->name, "ident-name");
2455 assert_string_equal(*identities->bases, "base-name");
2456 assert_string_equal(*identities->iffeatures, "iff");
2457 assert_string_equal(identities->dsc, "desc");
2458 assert_string_equal(identities->ref, "ref");
2459 assert_true(identities->flags & LYS_STATUS_DEPRC);
2460 assert_null(identities->exts);
2461 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2462 identities = NULL;
2463
2464 /* min subelems */
2465 data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END;
2466 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS);
2467 assert_string_equal(identities->name, "ident-name");
2468 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2469 identities = NULL;
2470
2471 /* invalid */
2472 st->yin_ctx->mod_version = LYS_VERSION_1_0;
2473 data = ELEMENT_WRAPPER_START
2474 "<identity name=\"ident-name\">"
2475 "<if-feature name=\"iff\"/>"
2476 "</identity>"
2477 ELEMENT_WRAPPER_END;
2478 assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID);
2479 logbuf_assert("Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
2480 FREE_ARRAY(st->ctx, identities, lysp_ident_free);
2481 identities = NULL;
2482
2483 st->finished_correctly = true;
2484}
2485
David Sedlákaf536aa2019-07-23 13:42:23 +02002486static void
2487test_list_elem(void **state)
2488{
2489 struct state *st = *state;
2490 const char *data;
2491 struct lysp_node *siblings = NULL;
2492 struct tree_node_meta node_meta = {NULL, &siblings};
2493 struct lysp_node_list *parsed = NULL;
2494
2495 /* max subelems */
2496 data = ELEMENT_WRAPPER_START
2497 "<list name=\"list-name\">"
2498 "<when condition=\"when\"/>"
2499 "<if-feature name=\"iff\"/>"
2500 "<must condition=\"must-cond\"/>"
2501 "<key value=\"key\"/>"
2502 "<unique tag=\"utag\"/>"
2503 "<config value=\"true\"/>"
2504 "<min-elements value=\"10\"/>"
2505 "<ordered-by value=\"user\"/>"
2506 "<status value=\"deprecated\"/>"
2507 "<description><text>desc</text></description>"
2508 "<reference><text>ref</text></reference>"
2509 "<anydata name=\"anyd\"/>"
2510 "<anyxml name=\"anyx\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002511 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002512 "<choice name=\"choice\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002513 "<action name=\"action\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002514 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002515 "<notification name=\"notf\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002516 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2517 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002518 "<list name=\"sub-list\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002519 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákaf536aa2019-07-23 13:42:23 +02002520 "<uses name=\"uses-name\"/>"
2521 "</list>"
2522 ELEMENT_WRAPPER_END;
2523 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2524 parsed = (struct lysp_node_list *)&siblings[0];
2525 assert_string_equal(parsed->dsc, "desc");
2526 assert_string_equal(parsed->child->name, "anyd");
2527 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2528 assert_string_equal(parsed->child->next->name, "anyx");
2529 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002530 assert_string_equal(parsed->child->next->next->name, "cont");
2531 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002532 assert_string_equal(parsed->child->next->next->next->name, "choice");
2533 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002534 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2535 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2536 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2537 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2538 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2539 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2540 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2541 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2542 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002543 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002544 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002545 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002546 assert_string_equal(parsed->notifs->name, "notf");
David Sedlákaf536aa2019-07-23 13:42:23 +02002547 assert_null(parsed->exts);
2548 assert_true(parsed->flags & LYS_ORDBY_USER);
2549 assert_true(parsed->flags & LYS_STATUS_DEPRC);
2550 assert_true(parsed->flags & LYS_CONFIG_W);
2551 assert_string_equal(*parsed->iffeatures, "iff");
2552 assert_string_equal(parsed->key, "key");
2553 assert_int_equal(parsed->min, 10);
2554 assert_string_equal(parsed->musts->arg, "must-cond");
2555 assert_string_equal(parsed->name, "list-name");
2556 assert_null(parsed->next);
2557 assert_int_equal(parsed->nodetype, LYS_LIST);
2558 assert_null(parsed->parent);
2559 assert_string_equal(parsed->ref, "ref");
2560 assert_string_equal(parsed->typedefs->name, "tpdf");
2561 assert_string_equal(*parsed->uniques, "utag");
2562 assert_string_equal(parsed->when->cond, "when");
2563 lysp_node_free(st->ctx, siblings);
2564 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2565 siblings = NULL;
2566
2567 /* min subelems */
2568 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
2569 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2570 parsed = (struct lysp_node_list *)&siblings[0];
2571 assert_string_equal(parsed->name, "list-name");
2572 lysp_node_free(st->ctx, siblings);
2573 siblings = NULL;
2574
2575 st->finished_correctly = true;
2576}
2577
David Sedlák031b9e72019-07-23 15:19:37 +02002578static void
2579test_notification_elem(void **state)
2580{
2581 struct state *st = *state;
2582 const char *data;
2583 struct lysp_notif *notifs = NULL;
2584 struct notif_meta notif_meta = {NULL, &notifs};
2585
2586 /* max subelems */
2587 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2588 data = ELEMENT_WRAPPER_START
2589 "<notification name=\"notif-name\">"
2590 "<anydata name=\"anyd\"/>"
2591 "<anyxml name=\"anyx\"/>"
2592 "<description><text>desc</text></description>"
2593 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002594 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2595 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák031b9e72019-07-23 15:19:37 +02002596 "<list name=\"sub-list\"/>"
2597 "<must condition=\"cond\"/>"
2598 "<reference><text>ref</text></reference>"
2599 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002600 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák031b9e72019-07-23 15:19:37 +02002601 "<uses name=\"uses-name\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002602 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002603 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002604 "<grouping name=\"grp\"/>"
David Sedlák031b9e72019-07-23 15:19:37 +02002605 "</notification>"
2606 ELEMENT_WRAPPER_END;
2607 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
2608 assert_string_equal(notifs->name, "notif-name");
2609 assert_string_equal(notifs->data->name, "anyd");
2610 assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
2611 assert_string_equal(notifs->data->next->name, "anyx");
2612 assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML);
2613 assert_string_equal(notifs->data->next->next->name, "leaf");
2614 assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF);
2615 assert_string_equal(notifs->data->next->next->next->name, "llist");
2616 assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST);
2617 assert_string_equal(notifs->data->next->next->next->next->name, "sub-list");
2618 assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST);
2619 assert_null(notifs->exts);
2620 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002621 assert_string_equal(notifs->groupings->name, "grp");
2622 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
David Sedlákf111bcb2019-07-23 17:15:51 +02002623 assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name");
2624 assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES);
2625 assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont");
2626 assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002627 assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2628 assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice");
2629 assert_null(notifs->data->next->next->next->next->next->next->next->next);
David Sedlák031b9e72019-07-23 15:19:37 +02002630 assert_string_equal(*notifs->iffeatures, "iff");
2631 assert_string_equal(notifs->musts->arg, "cond");
2632 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2633 assert_null(notifs->parent);
2634 assert_string_equal(notifs->ref, "ref");
2635 assert_string_equal(notifs->typedefs->name, "tpdf");
2636 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
2637 notifs = NULL;
2638
2639 /* min subelems */
2640 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
2641 assert_int_equal(test_element_helper(st, &data, &notif_meta, NULL, NULL, true), LY_SUCCESS);
2642 assert_string_equal(notifs->name, "notif-name");
2643 FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002644 notifs = NULL;
2645
2646 st->finished_correctly = true;
2647}
2648
2649static void
2650test_grouping_elem(void **state)
2651{
2652 struct state *st = *state;
2653 const char *data;
2654 struct lysp_grp *grps = NULL;
2655 struct grouping_meta grp_meta = {NULL, &grps};
2656
2657 /* max subelems */
2658 data = ELEMENT_WRAPPER_START
2659 "<grouping name=\"grp-name\">"
2660 "<anydata name=\"anyd\"/>"
2661 "<anyxml name=\"anyx\"/>"
2662 "<description><text>desc</text></description>"
2663 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002664 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2665 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002666 "<list name=\"list\"/>"
2667 "<notification name=\"notf\"/>"
2668 "<reference><text>ref</text></reference>"
2669 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002670 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002671 "<uses name=\"uses-name\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002672 "<action name=\"act\"/>"
David Sedlákf111bcb2019-07-23 17:15:51 +02002673 "<container name=\"cont\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002674 "<choice name=\"choice\"/>"
David Sedláke3ce9ef2019-07-23 16:34:30 +02002675 "</grouping>"
2676 ELEMENT_WRAPPER_END;
2677 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
2678 assert_string_equal(grps->name, "grp-name");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002679 assert_string_equal(grps->data->name, "anyd");
2680 assert_string_equal(grps->data->next->name, "anyx");
2681 assert_string_equal(grps->data->next->next->name, "leaf");
2682 assert_string_equal(grps->data->next->next->next->name, "llist");
2683 assert_string_equal(grps->data->next->next->next->next->name, "list");
2684 assert_string_equal(grps->dsc, "desc");
2685 assert_null(grps->exts);
2686 assert_true(grps->flags & LYS_STATUS_CURR);
2687 assert_string_equal(grps->groupings->name, "sub-grp");
2688 assert_int_equal(grps->nodetype, LYS_GROUPING);
2689 assert_string_equal(grps->notifs->name, "notf");
2690 assert_null(grps->parent);
2691 assert_string_equal(grps->ref, "ref");
2692 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002693 assert_string_equal(grps->actions->name, "act");
David Sedlákf111bcb2019-07-23 17:15:51 +02002694 assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002695 assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákf111bcb2019-07-23 17:15:51 +02002696 assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002697 assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2698 assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
2699 assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002700 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
2701 grps = NULL;
2702
2703 /* min subelems */
2704 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
2705 assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS);
2706 assert_string_equal(grps->name, "grp-name");
2707 FREE_ARRAY(st->ctx, grps, lysp_grp_free);
2708 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002709
2710 st->finished_correctly = true;
2711}
2712
David Sedlákf111bcb2019-07-23 17:15:51 +02002713static void
2714test_container_elem(void **state)
2715{
2716 struct state *st = *state;
2717 const char *data;
2718 struct lysp_node *siblings = NULL;
2719 struct tree_node_meta node_meta = {NULL, &siblings};
2720 struct lysp_node_container *parsed = NULL;
2721
2722 /* max subelems */
David Sedláke2dc9e92019-07-24 09:59:21 +02002723 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2724 data = ELEMENT_WRAPPER_START
2725 "<container name=\"cont-name\">"
2726 "<anydata name=\"anyd\"/>"
2727 "<anyxml name=\"anyx\"/>"
2728 "<config value=\"true\"/>"
2729 "<container name=\"subcont\"/>"
2730 "<description><text>desc</text></description>"
2731 "<grouping name=\"sub-grp\"/>"
2732 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002733 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2734 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedláke2dc9e92019-07-24 09:59:21 +02002735 "<list name=\"list\"/>"
2736 "<must condition=\"cond\"/>"
2737 "<notification name=\"notf\"/>"
2738 "<presence value=\"presence\"/>"
2739 "<reference><text>ref</text></reference>"
2740 "<status value=\"current\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002741 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedláke2dc9e92019-07-24 09:59:21 +02002742 "<uses name=\"uses-name\"/>"
2743 "<when condition=\"when-cond\"/>"
David Sedlák85d0eca2019-07-24 15:15:21 +02002744 "<action name=\"act\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002745 "<choice name=\"choice\"/>"
David Sedláke2dc9e92019-07-24 09:59:21 +02002746 "</container>"
2747 ELEMENT_WRAPPER_END;
2748 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2749 parsed = (struct lysp_node_container *)siblings;
2750 assert_string_equal(parsed->name, "cont-name");
2751 assert_null(parsed->parent);
2752 assert_int_equal(parsed->nodetype, LYS_CONTAINER);
2753 assert_true(parsed->flags & LYS_CONFIG_W);
2754 assert_true(parsed->flags & LYS_STATUS_CURR);
2755 assert_null(parsed->next);
2756 assert_string_equal(parsed->dsc, "desc");
2757 assert_string_equal(parsed->ref, "ref");
2758 assert_string_equal(parsed->when->cond, "when-cond");
2759 assert_string_equal(*parsed->iffeatures, "iff");
2760 assert_null(parsed->exts);
2761 assert_string_equal(parsed->musts->arg, "cond");
2762 assert_string_equal(parsed->presence, "presence");
2763 assert_string_equal(parsed->typedefs->name, "tpdf");
2764 assert_string_equal(parsed->groupings->name, "sub-grp");
2765 assert_string_equal(parsed->child->name, "anyd");
2766 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2767 assert_string_equal(parsed->child->next->name, "anyx");
2768 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2769 assert_string_equal(parsed->child->next->next->name, "subcont");
2770 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2771 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2772 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2773 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2774 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2775 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2776 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2777 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2778 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002779 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2780 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2781 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02002782 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002783 assert_string_equal(parsed->actions->name, "act");
David Sedláke2dc9e92019-07-24 09:59:21 +02002784 lysp_node_free(st->ctx, siblings);
2785 ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
2786 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002787
2788 /* min subelems */
2789 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
2790 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2791 parsed = (struct lysp_node_container *)siblings;
2792 assert_string_equal(parsed->name, "cont-name");
2793 lysp_node_free(st->ctx, siblings);
2794 siblings = NULL;
2795
2796 st->finished_correctly = true;
2797}
2798
David Sedlák5379d392019-07-24 10:42:03 +02002799static void
2800test_case_elem(void **state)
2801{
2802 struct state *st = *state;
2803 const char *data;
2804 struct lysp_node *siblings = NULL;
2805 struct tree_node_meta node_meta = {NULL, &siblings};
2806 struct lysp_node_case *parsed = NULL;
2807
2808 /* max subelems */
2809 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2810 data = ELEMENT_WRAPPER_START
2811 "<case name=\"case-name\">"
2812 "<anydata name=\"anyd\"/>"
2813 "<anyxml name=\"anyx\"/>"
2814 "<container name=\"subcont\"/>"
2815 "<description><text>desc</text></description>"
2816 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002817 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2818 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák5379d392019-07-24 10:42:03 +02002819 "<list name=\"list\"/>"
2820 "<reference><text>ref</text></reference>"
2821 "<status value=\"current\"/>"
2822 "<uses name=\"uses-name\"/>"
2823 "<when condition=\"when-cond\"/>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002824 "<choice name=\"choice\"/>"
David Sedlák5379d392019-07-24 10:42:03 +02002825 "</case>"
2826 ELEMENT_WRAPPER_END;
2827 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2828 parsed = (struct lysp_node_case *)siblings;
2829 assert_string_equal(parsed->name, "case-name");
2830 assert_null(parsed->parent);
2831 assert_int_equal(parsed->nodetype, LYS_CASE);
2832 assert_true(parsed->flags & LYS_STATUS_CURR);
2833 assert_null(parsed->next);
2834 assert_string_equal(parsed->dsc, "desc");
2835 assert_string_equal(parsed->ref, "ref");
2836 assert_string_equal(parsed->when->cond, "when-cond");
2837 assert_string_equal(*parsed->iffeatures, "iff");
2838 assert_null(parsed->exts);
2839 assert_string_equal(parsed->child->name, "anyd");
2840 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2841 assert_string_equal(parsed->child->next->name, "anyx");
2842 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2843 assert_string_equal(parsed->child->next->next->name, "subcont");
2844 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2845 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2846 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2847 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2848 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2849 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2850 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2851 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2852 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002853 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2854 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2855 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedlák5379d392019-07-24 10:42:03 +02002856 lysp_node_free(st->ctx, siblings);
2857 siblings = NULL;
2858
2859 /* min subelems */
2860 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
2861 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2862 parsed = (struct lysp_node_case *)siblings;
2863 assert_string_equal(parsed->name, "case-name");
2864 lysp_node_free(st->ctx, siblings);
2865 siblings = NULL;
2866
2867 st->finished_correctly = true;
2868}
2869
David Sedlákb7abcfa2019-07-24 12:33:35 +02002870static void
2871test_choice_elem(void **state)
2872{
2873 struct state *st = *state;
2874 const char *data;
2875 struct lysp_node *siblings = NULL;
2876 struct tree_node_meta node_meta = {NULL, &siblings};
2877 struct lysp_node_choice *parsed = NULL;
2878
2879 /* max subelems */
2880 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2881 data = ELEMENT_WRAPPER_START
2882 "<choice name=\"choice-name\">"
2883 "<anydata name=\"anyd\"/>"
2884 "<anyxml name=\"anyx\"/>"
2885 "<case name=\"sub-case\"/>"
2886 "<choice name=\"choice\"/>"
2887 "<config value=\"true\"/>"
2888 "<container name=\"subcont\"/>"
2889 "<default value=\"def\"/>"
2890 "<description><text>desc</text></description>"
2891 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002892 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2893 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlákb7abcfa2019-07-24 12:33:35 +02002894 "<list name=\"list\"/>"
2895 "<mandatory value=\"true\" />"
2896 "<reference><text>ref</text></reference>"
2897 "<status value=\"current\"/>"
2898 "<when condition=\"when-cond\"/>"
2899 "</choice>"
2900 ELEMENT_WRAPPER_END;
2901 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2902 parsed = (struct lysp_node_choice *)siblings;
2903 assert_string_equal(parsed->name, "choice-name");
2904 assert_null(parsed->parent);
2905 assert_int_equal(parsed->nodetype, LYS_CHOICE);
2906 assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
2907 assert_null(parsed->next);
2908 assert_string_equal(parsed->dsc, "desc");
2909 assert_string_equal(parsed->ref, "ref");
2910 assert_string_equal(parsed->when->cond, "when-cond");
2911 assert_string_equal(*parsed->iffeatures, "iff");
2912 assert_null(parsed->exts);
2913 assert_string_equal(parsed->child->name, "anyd");
2914 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2915 assert_string_equal(parsed->child->next->name, "anyx");
2916 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2917 assert_string_equal(parsed->child->next->next->name, "sub-case");
2918 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
2919 assert_string_equal(parsed->child->next->next->next->name, "choice");
2920 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2921 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
2922 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
2923 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
2924 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
2925 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
2926 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2927 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
2928 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
2929 assert_null(parsed->child->next->next->next->next->next->next->next->next);
2930 lysp_node_free(st->ctx, siblings);
2931 siblings = NULL;
2932
2933 /* min subelems */
2934 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
2935 assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS);
2936 parsed = (struct lysp_node_choice *)siblings;
2937 assert_string_equal(parsed->name, "choice-name");
2938 lysp_node_free(st->ctx, siblings);
2939 siblings = NULL;
2940
2941 st->finished_correctly = true;
2942}
2943
David Sedlák05404f62019-07-24 14:11:53 +02002944static void
2945test_inout_elem(void **state)
2946{
2947 struct state *st = *state;
2948 const char *data;
2949 struct lysp_action_inout inout = {};
2950 struct inout_meta inout_meta = {NULL, &inout};
2951
2952 /* max subelements */
2953 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2954 data = ELEMENT_WRAPPER_START
2955 "<input>"
2956 "<anydata name=\"anyd\"/>"
2957 "<anyxml name=\"anyx\"/>"
2958 "<choice name=\"choice\"/>"
2959 "<container name=\"subcont\"/>"
2960 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002961 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
2962 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02002963 "<list name=\"list\"/>"
2964 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02002965 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02002966 "<uses name=\"uses-name\"/>"
2967 "</input>"
2968 ELEMENT_WRAPPER_END;
2969 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
2970 assert_null(inout.parent);
2971 assert_int_equal(inout.nodetype, LYS_INPUT);
2972 assert_string_equal(inout.musts->arg, "cond");
2973 assert_string_equal(inout.typedefs->name, "tpdf");
2974 assert_string_equal(inout.groupings->name, "sub-grp");
2975 assert_string_equal(inout.data->name, "anyd");
2976 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
2977 assert_string_equal(inout.data->next->name, "anyx");
2978 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
2979 assert_string_equal(inout.data->next->next->name, "choice");
2980 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
2981 assert_string_equal(inout.data->next->next->next->name, "subcont");
2982 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
2983 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
2984 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
2985 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
2986 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2987 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
2988 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
2989 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
2990 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
2991 assert_null(inout.data->next->next->next->next->next->next->next->next);
2992 lysp_action_inout_free(st->ctx, &inout);
2993 memset(&inout, 0, sizeof inout);
2994
2995 /* max subelements */
2996 st->yin_ctx->mod_version = LYS_VERSION_1_1;
2997 data = ELEMENT_WRAPPER_START
2998 "<output>"
2999 "<anydata name=\"anyd\"/>"
3000 "<anyxml name=\"anyx\"/>"
3001 "<choice name=\"choice\"/>"
3002 "<container name=\"subcont\"/>"
3003 "<grouping name=\"sub-grp\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003004 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3005 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák05404f62019-07-24 14:11:53 +02003006 "<list name=\"list\"/>"
3007 "<must condition=\"cond\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003008 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák05404f62019-07-24 14:11:53 +02003009 "<uses name=\"uses-name\"/>"
3010 "</output>"
3011 ELEMENT_WRAPPER_END;
3012 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3013 assert_null(inout.parent);
3014 assert_int_equal(inout.nodetype, LYS_OUTPUT);
3015 assert_string_equal(inout.musts->arg, "cond");
3016 assert_string_equal(inout.typedefs->name, "tpdf");
3017 assert_string_equal(inout.groupings->name, "sub-grp");
3018 assert_string_equal(inout.data->name, "anyd");
3019 assert_int_equal(inout.data->nodetype, LYS_ANYDATA);
3020 assert_string_equal(inout.data->next->name, "anyx");
3021 assert_int_equal(inout.data->next->nodetype, LYS_ANYXML);
3022 assert_string_equal(inout.data->next->next->name, "choice");
3023 assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE);
3024 assert_string_equal(inout.data->next->next->next->name, "subcont");
3025 assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER);
3026 assert_string_equal(inout.data->next->next->next->next->name, "leaf");
3027 assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF);
3028 assert_string_equal(inout.data->next->next->next->next->next->name, "llist");
3029 assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3030 assert_string_equal(inout.data->next->next->next->next->next->next->name, "list");
3031 assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST);
3032 assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
3033 assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3034 assert_null(inout.data->next->next->next->next->next->next->next->next);
3035 lysp_action_inout_free(st->ctx, &inout);
3036 memset(&inout, 0, sizeof inout);
3037
3038 /* min subelems */
3039 data = ELEMENT_WRAPPER_START "<input />" ELEMENT_WRAPPER_END;
3040 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3041 memset(&inout, 0, sizeof inout);
3042
3043 data = ELEMENT_WRAPPER_START "<output />" ELEMENT_WRAPPER_END;
3044 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS);
3045 memset(&inout, 0, sizeof inout);
3046
3047 /* invalid combinations */
3048 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
3049 assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, false), LY_EVALID);
3050 logbuf_assert("Unexpected attribute \"name\" of input element. Line number 1.");
3051 memset(&inout, 0, sizeof inout);
3052
3053 st->finished_correctly = true;
3054}
3055
David Sedlák85d0eca2019-07-24 15:15:21 +02003056static void
3057test_action_elem(void **state)
3058{
3059 struct state *st = *state;
3060 const char *data;
3061 struct lysp_action *actions = NULL;
3062 struct action_meta act_meta = {NULL, &actions};
3063
3064 /* max subelems */
3065 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3066 data = ELEMENT_WRAPPER_START
3067 "<action name=\"act\">"
3068 "<description><text>desc</text></description>"
3069 "<grouping name=\"grouping\"/>"
3070 "<if-feature name=\"iff\"/>"
3071 "<input><uses name=\"uses-name\"/></input>"
3072 "<output><must condition=\"cond\"/></output>"
3073 "<reference><text>ref</text></reference>"
3074 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003075 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlák85d0eca2019-07-24 15:15:21 +02003076 "</action>"
3077 ELEMENT_WRAPPER_END;
3078 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3079 assert_null(actions->parent);
3080 assert_int_equal(actions->nodetype, LYS_ACTION);
3081 assert_true(actions->flags & LYS_STATUS_DEPRC);
3082 assert_string_equal(actions->name, "act");
3083 assert_string_equal(actions->dsc, "desc");
3084 assert_string_equal(actions->ref, "ref");
3085 assert_string_equal(*actions->iffeatures, "iff");
3086 assert_string_equal(actions->typedefs->name, "tpdf");
3087 assert_string_equal(actions->groupings->name, "grouping");
3088 assert_string_equal(actions->input.data->name, "uses-name");
3089 assert_string_equal(actions->output.musts->arg, "cond");
3090 assert_null(actions->exts);
3091 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3092 actions = NULL;
3093
David Sedlákeaa45792019-07-24 15:25:01 +02003094 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3095 data = ELEMENT_WRAPPER_START
3096 "<rpc name=\"act\">"
3097 "<description><text>desc</text></description>"
3098 "<grouping name=\"grouping\"/>"
3099 "<if-feature name=\"iff\"/>"
3100 "<input><uses name=\"uses-name\"/></input>"
3101 "<output><must condition=\"cond\"/></output>"
3102 "<reference><text>ref</text></reference>"
3103 "<status value=\"deprecated\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003104 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>"
David Sedlákeaa45792019-07-24 15:25:01 +02003105 "</rpc>"
3106 ELEMENT_WRAPPER_END;
3107 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3108 assert_null(actions->parent);
3109 assert_int_equal(actions->nodetype, LYS_ACTION);
3110 assert_true(actions->flags & LYS_STATUS_DEPRC);
3111 assert_string_equal(actions->name, "act");
3112 assert_string_equal(actions->dsc, "desc");
3113 assert_string_equal(actions->ref, "ref");
3114 assert_string_equal(*actions->iffeatures, "iff");
3115 assert_string_equal(actions->typedefs->name, "tpdf");
3116 assert_string_equal(actions->groupings->name, "grouping");
3117 assert_string_equal(actions->input.data->name, "uses-name");
3118 assert_string_equal(actions->output.musts->arg, "cond");
3119 assert_null(actions->exts);
3120 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3121 actions = NULL;
3122
David Sedlák85d0eca2019-07-24 15:15:21 +02003123 /* min subelems */
3124 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
3125 assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
3126 assert_string_equal(actions->name, "act");
3127 FREE_ARRAY(st->ctx, actions, lysp_action_free)
3128 actions = NULL;
3129
3130 st->finished_correctly = true;
3131}
3132
David Sedlák992fb7c2019-07-24 16:51:01 +02003133static void
3134test_augment_elem(void **state)
3135{
3136 struct state *st = *state;
3137 const char *data;
3138 struct lysp_augment *augments = NULL;
3139 struct augment_meta aug_meta = {NULL, &augments};
3140
3141 st->yin_ctx->mod_version = LYS_VERSION_1_1;
3142 data = ELEMENT_WRAPPER_START
3143 "<augment target-node=\"target\">"
3144 "<action name=\"action\"/>"
3145 "<anydata name=\"anyd\"/>"
3146 "<anyxml name=\"anyx\"/>"
3147 "<case name=\"case\"/>"
3148 "<choice name=\"choice\"/>"
3149 "<container name=\"subcont\"/>"
3150 "<description><text>desc</text></description>"
3151 "<if-feature name=\"iff\"/>"
David Sedlák8b754462019-07-25 16:22:13 +02003152 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>"
3153 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>"
David Sedlák992fb7c2019-07-24 16:51:01 +02003154 "<list name=\"list\"/>"
3155 "<notification name=\"notif\"/>"
3156 "<reference><text>ref</text></reference>"
3157 "<status value=\"current\"/>"
3158 "<uses name=\"uses\"/>"
3159 "<when condition=\"when-cond\"/>"
3160 "</augment>"
3161 ELEMENT_WRAPPER_END;
3162 assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS);
3163 assert_string_equal(augments->nodeid, "target");
3164 assert_null(augments->parent);
3165 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3166 assert_true(augments->flags & LYS_STATUS_CURR);
3167 assert_string_equal(augments->dsc, "desc");
3168 assert_string_equal(augments->ref, "ref");
3169 assert_string_equal(augments->when->cond, "when-cond");
3170 assert_string_equal(*augments->iffeatures, "iff");
3171 assert_string_equal(augments->child->name, "anyd");
3172 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3173 assert_string_equal(augments->child->next->name, "anyx");
3174 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3175 assert_string_equal(augments->child->next->next->name, "case");
3176 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3177 assert_string_equal(augments->child->next->next->next->name, "choice");
3178 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3179 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3180 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3181 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3182 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3183 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3184 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3185 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3186 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3187 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3188 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3189 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3190 assert_string_equal(augments->actions->name, "action");
3191 assert_string_equal(augments->notifs->name, "notif");
3192 assert_null(augments->exts);
3193 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3194 augments = NULL;
3195
3196 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
3197 assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS);
3198 assert_string_equal(augments->nodeid, "target");
3199 FREE_ARRAY(st->ctx, augments, lysp_augment_free)
3200 augments = NULL;
3201
3202 st->finished_correctly = true;
3203}
3204
David Sedlák4ffcec82019-07-25 15:10:21 +02003205static void
3206test_deviate_elem(void **state)
3207{
3208 struct state *st = *state;
3209 const char *data;
3210 struct lysp_deviate *deviates = NULL;
3211 struct lysp_deviate_add *d_add;
3212 struct lysp_deviate_rpl *d_rpl;
3213 struct lysp_deviate_del *d_del;
3214
3215 /* all valid arguments with min subelems */
3216 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
3217 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3218 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3219 lysp_deviate_free(st->ctx, deviates);
3220 free(deviates);
3221 deviates = NULL;
3222
3223 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
3224 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3225 assert_int_equal(deviates->mod, LYS_DEV_ADD);
3226 lysp_deviate_free(st->ctx, deviates);
3227 free(deviates);
3228 deviates = NULL;
3229
3230 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
3231 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3232 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
3233 lysp_deviate_free(st->ctx, deviates);
3234 free(deviates);
3235 deviates = NULL;
3236
3237 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
3238 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3239 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
3240 lysp_deviate_free(st->ctx, deviates);
3241 free(deviates);
3242 deviates = NULL;
3243
3244 /* max subelems and valid arguments */
3245 data = ELEMENT_WRAPPER_START
3246 "<deviate value=\"not-supported\">"
3247 "</deviate>"
3248 ELEMENT_WRAPPER_END;
3249 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3250 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
3251 lysp_deviate_free(st->ctx, deviates);
3252 free(deviates);
3253 deviates = NULL;
3254
3255 data = ELEMENT_WRAPPER_START
3256 "<deviate value=\"add\">"
3257 "<units name=\"units\"/>"
3258 "<must condition=\"cond\"/>"
3259 "<unique tag=\"utag\"/>"
3260 "<default value=\"def\"/>"
3261 "<config value=\"true\"/>"
3262 "<mandatory value=\"true\"/>"
3263 "<min-elements value=\"5\"/>"
3264 "<max-elements value=\"15\"/>"
3265 "</deviate>"
3266 ELEMENT_WRAPPER_END;
3267 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3268 d_add = (struct lysp_deviate_add *)deviates;
3269 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3270 assert_null(d_add->next);
3271 assert_null(d_add->exts);
3272 assert_string_equal(d_add->units, "units");
3273 assert_string_equal(d_add->musts->arg, "cond");
3274 assert_string_equal(*d_add->uniques, "utag");
3275 assert_string_equal(*d_add->dflts, "def");
3276 assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
3277 assert_int_equal(d_add->min, 5);
3278 assert_int_equal(d_add->max, 15);
3279 lysp_deviate_free(st->ctx, deviates);
3280 free(deviates);
3281 deviates = NULL;
3282
3283 data = ELEMENT_WRAPPER_START
3284 "<deviate value=\"replace\">"
3285 "<type name=\"newtype\"/>"
3286 "<units name=\"uni\"/>"
3287 "<default value=\"def\"/>"
3288 "<config value=\"true\"/>"
3289 "<mandatory value=\"true\"/>"
3290 "<min-elements value=\"5\"/>"
3291 "<max-elements value=\"15\"/>"
3292 "</deviate>"
3293 ELEMENT_WRAPPER_END;
3294 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3295 d_rpl = (struct lysp_deviate_rpl *)deviates;
3296 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3297 assert_null(d_rpl->next);
3298 assert_null(d_rpl->exts);
3299 assert_string_equal(d_rpl->type->name, "newtype");
3300 assert_string_equal(d_rpl->units, "uni");
3301 assert_string_equal(d_rpl->dflt, "def");
3302 assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
3303 assert_int_equal(d_rpl->min, 5);
3304 assert_int_equal(d_rpl->max, 15);
3305 lysp_deviate_free(st->ctx, deviates);
3306 free(deviates);
3307 deviates = NULL;
3308
3309 data = ELEMENT_WRAPPER_START
3310 "<deviate value=\"delete\">"
3311 "<units name=\"u\"/>"
3312 "<must condition=\"c\"/>"
3313 "<unique tag=\"tag\"/>"
3314 "<default value=\"default\"/>"
3315 "</deviate>"
3316 ELEMENT_WRAPPER_END;
3317 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS);
3318 d_del = (struct lysp_deviate_del *)deviates;
3319 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3320 assert_null(d_del->next);
3321 assert_null(d_del->exts);
3322 assert_string_equal(d_del->units, "u");
3323 assert_string_equal(d_del->musts->arg, "c");
3324 assert_string_equal(*d_del->uniques, "tag");
3325 assert_string_equal(*d_del->dflts, "default");
3326 lysp_deviate_free(st->ctx, deviates);
3327 free(deviates);
3328 deviates = NULL;
3329
3330 /* invalid arguments */
3331 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
3332 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3333 logbuf_assert("Invalid value \"\" of \"deviate\". Line number 1.");
3334 deviates = NULL;
3335
3336 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
3337 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3338 logbuf_assert("Invalid value \"invalid\" of \"deviate\". Line number 1.");
3339 deviates = NULL;
3340
3341 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
3342 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3343 logbuf_assert("Invalid value \"ad\" of \"deviate\". Line number 1.");
3344 deviates = NULL;
3345
3346 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
3347 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3348 logbuf_assert("Invalid value \"adds\" of \"deviate\". Line number 1.");
3349 deviates = NULL;
3350
3351 data = ELEMENT_WRAPPER_START
3352 "<deviate value=\"not-supported\">"
3353 "<must condition=\"c\"/>"
3354 "</deviate>"
3355 ELEMENT_WRAPPER_END;
3356 assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID);
3357 logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1.");
3358
3359 st->finished_correctly = true;
3360}
3361
David Sedlák8b754462019-07-25 16:22:13 +02003362static void
3363test_deviation_elem(void **state)
3364{
3365 struct state *st = *state;
3366 const char *data;
3367 struct lysp_deviation *deviations = NULL;
3368
3369 /* min subelems */
3370 data = ELEMENT_WRAPPER_START
3371 "<deviation target-node=\"target\">"
3372 "<deviate value=\"not-supported\"/>"
3373 "</deviation>"
3374 ELEMENT_WRAPPER_END;
3375 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS);
3376 assert_string_equal(deviations->nodeid, "target");
3377 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
3378 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3379 deviations = NULL;
3380
3381 /* max subelems */
3382 data = ELEMENT_WRAPPER_START
3383 "<deviation target-node=\"target\">"
3384 "<reference><text>ref</text></reference>"
3385 "<description><text>desc</text></description>"
3386 "<deviate value=\"add\"/>"
3387 "</deviation>"
3388 ELEMENT_WRAPPER_END;
3389 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS);
3390 assert_string_equal(deviations->nodeid, "target");
3391 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3392 assert_string_equal(deviations->ref, "ref");
3393 assert_string_equal(deviations->dsc, "desc");
3394 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3395 deviations = NULL;
3396
3397 /* invalid */
3398 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
3399 assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, false), LY_EVALID);
3400 FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
3401 deviations = NULL;
3402 logbuf_assert("Missing mandatory subelement deviate of deviate element. Line number 1.");
3403
3404 st->finished_correctly = true;
3405}
3406
David Sedlák4f03b932019-07-26 13:01:47 +02003407static void
3408test_module_elem(void **state)
3409{
3410 struct state *st = *state;
3411 const char *data;
3412 struct yin_arg_record *attrs = NULL;
3413 struct sized_string name, prefix;
3414 struct lys_module *lys_mod = NULL;
3415 struct lysp_module *lysp_mod = NULL;
3416
3417 /* max subelems */
3418 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
3419 lys_mod = calloc(1, sizeof *lys_mod);
3420 lysp_mod = calloc(1, sizeof *lysp_mod);
3421 lys_mod->ctx = st->ctx;
3422 lysp_mod->mod = lys_mod;
3423 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3424 "<yang-version value=\"1.1\"/>\n"
3425 "<namespace uri=\"ns\"/>\n"
3426 "<prefix value=\"pref\"/>\n"
3427 "<include module=\"b-mod\"/>\n"
3428 "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3429 "<organization><text>org</text></organization>\n"
3430 "<contact><text>contact</text></contact>\n"
3431 "<description><text>desc</text></description>"
3432 "<reference><text>ref</text></reference>\n"
3433 "<revision date=\"2019-02-02\"/>\n"
3434 "<anydata name=\"anyd\"/>\n"
3435 "<anyxml name=\"anyx\"/>\n"
3436 "<choice name=\"choice\"/>\n"
3437 "<container name=\"cont\"/>\n"
3438 "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3439 "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3440 "<list name=\"sub-list\"/>\n"
3441 "<uses name=\"uses-name\"/>\n"
3442 "<augment target-node=\"target\"/>\n"
3443 "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n"
3444 "<extension name=\"ext\"/>\n"
3445 "<feature name=\"feature\"/>\n"
3446 "<grouping name=\"grp\"/>\n"
3447 "<identity name=\"ident-name\"/>\n"
3448 "<notification name=\"notf\"/>\n"
3449 "<rpc name=\"rpc-name\"/>\n"
3450 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3451 "</module>\n";
3452 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len), LY_SUCCESS);
3453 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
3454 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS);
3455 assert_string_equal(lysp_mod->mod->name, "mod");
3456 assert_string_equal(lysp_mod->revs, "2019-02-02");
3457 assert_string_equal(lysp_mod->mod->ns, "ns");
3458 assert_string_equal(lysp_mod->mod->prefix, "pref");
3459 assert_null(lysp_mod->mod->filepath);
3460 assert_string_equal(lysp_mod->mod->org, "org");
3461 assert_string_equal(lysp_mod->mod->contact, "contact");
3462 assert_string_equal(lysp_mod->mod->dsc, "desc");
3463 assert_string_equal(lysp_mod->mod->ref, "ref");
3464 assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1);
3465 assert_string_equal(lysp_mod->imports->name, "a-mod");
3466 assert_string_equal(lysp_mod->includes->name, "b-mod");
3467 assert_string_equal(lysp_mod->extensions->name, "ext");
3468 assert_string_equal(lysp_mod->features->name, "feature");
3469 assert_string_equal(lysp_mod->identities->name, "ident-name");
3470 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3471 assert_string_equal(lysp_mod->groupings->name, "grp");
3472 assert_string_equal(lysp_mod->data->name, "anyd");
3473 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3474 assert_string_equal(lysp_mod->data->next->name, "anyx");
3475 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3476 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3477 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3478 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3479 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3480 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3481 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3482 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3483 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3484 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3485 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3486 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3487 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3488 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3489 assert_string_equal(lysp_mod->augments->nodeid, "target");
3490 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3491 assert_string_equal(lysp_mod->notifs->name, "notf");
3492 assert_string_equal(lysp_mod->deviations->nodeid, "target");
3493 assert_null(lysp_mod->exts);
3494 lysp_module_free(lysp_mod);
3495 lys_module_free(lys_mod, NULL);
3496 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
3497 attrs = NULL;
3498
3499 /* min subelems */
3500 st->yin_ctx->xml_ctx.status = LYXML_ELEMENT;
3501 lys_mod = calloc(1, sizeof *lys_mod);
3502 lysp_mod = calloc(1, sizeof *lysp_mod);
3503 lys_mod->ctx = st->ctx;
3504 lysp_mod->mod = lys_mod;
3505 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">"
3506 "<namespace uri=\"ns\"/>"
3507 "<prefix value=\"pref\"/>"
3508 "<yang-version value=\"1.1\"/>"
3509 "</module>";
3510 assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len), LY_SUCCESS);
3511 assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS);
3512 assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS);
3513 lysp_module_free(lysp_mod);
3514 lys_module_free(lys_mod, NULL);
3515 FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec);
3516 attrs = NULL;
3517}
3518
David Sedlák3b4db242018-10-19 16:11:01 +02003519int
3520main(void)
3521{
3522
3523 const struct CMUnitTest tests[] = {
David Sedlák8f7a1172019-06-20 14:42:18 +02003524 cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
David Sedlákb1a78352019-06-28 16:16:29 +02003525 cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
3526 cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
David Sedlák555c7202019-07-04 12:14:12 +02003527 cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
David Sedlák4a650532019-07-10 11:55:18 +02003528 cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
David Sedlák32488102019-07-15 17:44:10 +02003529
David Sedlák8e7bda82019-07-16 17:57:50 +02003530 cmocka_unit_test(test_yin_match_argument_name),
David Sedlák32488102019-07-15 17:44:10 +02003531 cmocka_unit_test_setup_teardown(test_enum_bit_elem, setup_element_test, teardown_element_test),
3532 cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test),
3533 cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test),
3534 cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test),
3535 cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test),
3536 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test),
3537 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test),
3538 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test),
David Sedlák8e7bda82019-07-16 17:57:50 +02003539 cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test),
3540 cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test),
3541 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test),
3542 cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test),
3543 cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test),
3544 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test),
3545 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test),
3546 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test),
3547 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test),
3548 cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test),
3549 cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test),
3550 cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test),
3551 cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test),
3552 cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test),
3553 cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test),
David Sedlák69f01612019-07-17 11:41:08 +02003554 cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test),
3555 cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test),
3556 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test),
3557 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test),
3558 cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test),
3559 cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test),
3560 cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test),
3561 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test),
David Sedlák374d2b32019-07-17 15:06:55 +02003562 cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test),
David Sedlák1af868e2019-07-17 17:03:14 +02003563 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test),
David Sedlák09e18c92019-07-18 11:17:11 +02003564 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test),
David Sedláka2dad212019-07-18 12:45:19 +02003565 cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test),
David Sedlák8a83bbb2019-07-18 14:46:00 +02003566 cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test),
David Sedlák203ca3a2019-07-18 15:26:25 +02003567 cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test),
David Sedlákc3da3ef2019-07-19 12:56:08 +02003568 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test),
David Sedlákcb39f642019-07-19 13:19:55 +02003569 cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test),
David Sedlák12470a82019-07-19 13:44:36 +02003570 cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test),
David Sedlák04e17b22019-07-19 15:29:48 +02003571 cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test),
David Sedlákd2d676a2019-07-22 11:28:19 +02003572 cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test),
David Sedlák0d6de5a2019-07-22 13:25:44 +02003573 cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
David Sedlákaa854b02019-07-22 14:17:10 +02003574 cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
David Sedlák0c2bab92019-07-22 15:33:19 +02003575 cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
David Sedlák5e13dea2019-07-22 16:06:45 +02003576 cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
David Sedlák28794f22019-07-22 16:45:00 +02003577 cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test),
David Sedlákaf536aa2019-07-23 13:42:23 +02003578 cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test),
David Sedlák031b9e72019-07-23 15:19:37 +02003579 cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test),
David Sedláke3ce9ef2019-07-23 16:34:30 +02003580 cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test),
David Sedlákf111bcb2019-07-23 17:15:51 +02003581 cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test),
David Sedlák5379d392019-07-24 10:42:03 +02003582 cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
David Sedlákb7abcfa2019-07-24 12:33:35 +02003583 cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
David Sedlák05404f62019-07-24 14:11:53 +02003584 cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
David Sedlák85d0eca2019-07-24 15:15:21 +02003585 cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
David Sedlák992fb7c2019-07-24 16:51:01 +02003586 cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test),
David Sedlák4ffcec82019-07-25 15:10:21 +02003587 cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test),
David Sedlák8b754462019-07-25 16:22:13 +02003588 cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test),
David Sedlák4f03b932019-07-26 13:01:47 +02003589 cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test),
David Sedlák3b4db242018-10-19 16:11:01 +02003590 };
3591
David Sedlák8e7bda82019-07-16 17:57:50 +02003592 return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
David Sedlák3b4db242018-10-19 16:11:01 +02003593}