blob: 3799065151be51b6a0b5fc9ba4d3584d33f23820 [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 *
Radek Iša56ca9e42020-09-08 18:42:00 +02006 * Copyright (c) 2015 - 2020 CESNET, z.s.p.o.
David Sedlákb1ce3f82019-06-05 14:37:26 +02007 *
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 */
Radek Iša56ca9e42020-09-08 18:42:00 +020014#define _UTEST_MAIN_
15#include "utests.h"
David Sedlákb1ce3f82019-06-05 14:37:26 +020016
Radek Krejcib4ac5a92020-11-23 17:54:33 +010017#include <stdbool.h>
David Sedlák3b4db242018-10-19 16:11:01 +020018#include <stdio.h>
19#include <string.h>
20
Radek Krejci70593c12020-06-13 20:48:09 +020021#include "common.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020022#include "in.h"
Radek Krejci70593c12020-06-13 20:48:09 +020023#include "parser_internal.h"
Michal Vasko405cc9e2020-12-01 12:01:27 +010024#include "schema_compile.h"
Radek Krejci8df109d2021-04-23 12:19:08 +020025#include "tree.h"
Radek Krejci859a15a2021-03-05 20:56:59 +010026#include "tree_edit.h"
Radek Krejci70593c12020-06-13 20:48:09 +020027#include "tree_schema.h"
28#include "tree_schema_internal.h"
29#include "xml.h"
30#include "xpath.h"
David Sedlák3b4db242018-10-19 16:11:01 +020031
Michal Vaskoafac7822020-10-20 14:22:26 +020032/* copied from parser_yin.c */
33enum yin_argument {
34 YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */
35 YIN_ARG_NAME, /**< argument name */
36 YIN_ARG_TARGET_NODE, /**< argument target-node */
37 YIN_ARG_MODULE, /**< argument module */
38 YIN_ARG_VALUE, /**< argument value */
39 YIN_ARG_TEXT, /**< argument text */
40 YIN_ARG_CONDITION, /**< argument condition */
41 YIN_ARG_URI, /**< argument uri */
42 YIN_ARG_DATE, /**< argument data */
43 YIN_ARG_TAG, /**< argument tag */
44 YIN_ARG_NONE /**< empty (special value) */
45};
46
47struct yin_subelement {
48 enum ly_stmt type; /**< type of keyword */
49 void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */
50 uint16_t flags; /**< describes constraints of subelement can be set to YIN_SUBELEM_MANDATORY, YIN_SUBELEM_UNIQUE, YIN_SUBELEM_FIRST, YIN_SUBELEM_VER2, and YIN_SUBELEM_DEFAULT_TEXT */
51};
52
53struct import_meta {
54 const char *prefix; /**< module prefix. */
55 struct lysp_import **imports; /**< imports to add to. */
56};
57
58struct yin_argument_meta {
59 uint16_t *flags; /**< Argument flags */
60 const char **argument; /**< Argument value */
61};
62
63struct tree_node_meta {
64 struct lysp_node *parent; /**< parent node */
65 struct lysp_node **nodes; /**< linked list of siblings */
66};
67
68struct include_meta {
69 const char *name; /**< Module/submodule name. */
70 struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */
71};
72
73struct inout_meta {
74 struct lysp_node *parent; /**< Parent node. */
Radek Krejci2a9fc652021-01-22 17:44:34 +010075 struct lysp_node_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */
Michal Vaskoafac7822020-10-20 14:22:26 +020076};
77
78struct minmax_dev_meta {
79 uint32_t *lim; /**< min/max value to write to. */
80 uint16_t *flags; /**< min/max flags to write to. */
81 struct lysp_ext_instance **exts; /**< extension instances to add to. */
82};
83
84#define YIN_SUBELEM_MANDATORY 0x01
85#define YIN_SUBELEM_UNIQUE 0x02
86#define YIN_SUBELEM_FIRST 0x04
87#define YIN_SUBELEM_VER2 0x08
88
89#define YIN_SUBELEM_PARSED 0x80
90
David Sedlák555c7202019-07-04 12:14:12 +020091/* prototypes of static functions */
Michal Vaskoafac7822020-10-20 14:22:26 +020092enum yin_argument yin_match_argument_name(const char *name, size_t len);
93LY_ERR yin_parse_content(struct lys_yin_parser_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size,
94 enum ly_stmt current_element, const char **text_content, struct lysp_ext_instance **exts);
95LY_ERR yin_validate_value(struct lys_yin_parser_ctx *ctx, enum yang_arg val_type);
96enum ly_stmt yin_match_keyword(struct lys_yin_parser_ctx *ctx, const char *name, size_t name_len,
97 const char *prefix, size_t prefix_len, enum ly_stmt parrent);
Radek Krejcifc596f92021-02-26 22:40:26 +010098LY_ERR yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, enum ly_stmt subelem, LY_ARRAY_COUNT_TYPE subelem_index,
Michal Vaskoafac7822020-10-20 14:22:26 +020099 struct lysp_ext_instance **exts);
100LY_ERR yin_parse_element_generic(struct lys_yin_parser_ctx *ctx, enum ly_stmt parent, struct lysp_stmt **element);
101LY_ERR yin_parse_mod(struct lys_yin_parser_ctx *ctx, struct lysp_module *mod);
102LY_ERR yin_parse_submod(struct lys_yin_parser_ctx *ctx, struct lysp_submodule *submod);
103
David Sedlák555c7202019-07-04 12:14:12 +0200104void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +0200105void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +0200106void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +0200107void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +0200108void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +0200109void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +0200110void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +0200111void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +0200112void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +0200113void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +0200114void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100115void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp);
116void lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +0200117void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +0200118void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +0200119void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +0200120
David Sedláke6cd89e2019-08-07 12:46:02 +0200121/* wrapping element used for mocking has nothing to do with real module structure */
122#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
123#define ELEMENT_WRAPPER_END "</status>"
124
Radek Iša56ca9e42020-09-08 18:42:00 +0200125#define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\
Radek Krejci8df109d2021-04-23 12:19:08 +0200126 CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, INSUBSTMT, 0, "myext:c-define", LY_VALUE_XML)
David Sedlák872c7b42018-10-26 13:15:20 +0200127
Radek Iša56ca9e42020-09-08 18:42:00 +0200128struct lys_yin_parser_ctx *YCTX;
David Sedlák8e7bda82019-07-16 17:57:50 +0200129
130static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200131setup_ctx(void **state)
David Sedlák8e7bda82019-07-16 17:57:50 +0200132{
David Sedlák619db942019-07-03 14:47:30 +0200133 /* allocate parser context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200134 YCTX = calloc(1, sizeof(*YCTX));
135 YCTX->format = LYS_IN_YIN;
David Sedlák8f5bce02019-06-03 16:41:08 +0200136
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200137 /* allocate new parsed module */
Radek Iša56ca9e42020-09-08 18:42:00 +0200138 YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200139
140 /* allocate new module */
Radek Iša56ca9e42020-09-08 18:42:00 +0200141 YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
142 YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
143 YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200144
Radek Iša56ca9e42020-09-08 18:42:00 +0200145 return 0;
David Sedlák3b4db242018-10-19 16:11:01 +0200146}
147
148static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200149setup(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100150{
Radek Iša56ca9e42020-09-08 18:42:00 +0200151 UTEST_SETUP;
David Sedlák68a1af12019-03-08 13:46:54 +0100152
Radek Iša56ca9e42020-09-08 18:42:00 +0200153 setup_ctx(state);
David Sedlák79e50cb2019-06-05 16:33:09 +0200154
Radek Iša56ca9e42020-09-08 18:42:00 +0200155 return 0;
David Sedlák79e50cb2019-06-05 16:33:09 +0200156}
157
David Sedlák8985a142019-07-31 16:43:06 +0200158static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200159teardown_ctx(void **UNUSED(state))
David Sedlák8985a142019-07-31 16:43:06 +0200160{
Radek Krejci90ed21e2021-04-12 14:47:46 +0200161 lys_module_free(YCTX->parsed_mod->mod);
aPiecek8d4e75d2021-06-24 14:47:06 +0200162 yin_parser_ctx_free(YCTX);
Radek Iša56ca9e42020-09-08 18:42:00 +0200163 YCTX = NULL;
David Sedlák8985a142019-07-31 16:43:06 +0200164
Radek Iša56ca9e42020-09-08 18:42:00 +0200165 return 0;
David Sedlák8985a142019-07-31 16:43:06 +0200166}
167
Radek Iša56ca9e42020-09-08 18:42:00 +0200168static int
169teardown(void **state)
170{
171 teardown_ctx(state);
172
173 UTEST_TEARDOWN;
174
175 return 0;
176}
177
178#define RESET_STATE \
179 ly_in_free(UTEST_IN, 0); \
180 UTEST_IN = NULL; \
181 teardown_ctx(state); \
182 setup_ctx(state)
183
David Sedlák68a1af12019-03-08 13:46:54 +0100184static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200185test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200186{
Michal Vaskob36053d2020-03-26 15:49:30 +0100187 const char *prefix;
188 size_t prefix_len;
Radek Iša56ca9e42020-09-08 18:42:00 +0200189
David Sedlák8f7a1172019-06-20 14:42:18 +0200190 /* create mock yin namespace in xml context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200191 ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN);
192 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
193 prefix = YCTX->xmlctx->prefix;
194 prefix_len = YCTX->xmlctx->prefix_len;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100195
Radek Iša56ca9e42020-09-08 18:42:00 +0200196 assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
197 assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
198 assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
199 assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
200 assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
201 assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
202 assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
203 assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
204 assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
205 assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
206 assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
207 assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
208 assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
209 assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
210 assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
211 assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
212 assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
213 assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
214 assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
215 assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
216 assert_int_equal(yin_match_keyword(YCTX, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
217 assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
218 assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
219 assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
220 assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
221 assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
222 assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
223 assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
224 assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
225 assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
226 assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
227 assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
228 assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
229 assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
230 assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
231 assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
232 assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
233 assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
234 assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
235 assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
236 assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
237 assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
238 assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
239 assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
240 assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
241 assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
242 assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
243 assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
244 assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
245 assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
246 assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
247 assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
248 assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
249 assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
250 assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
251 assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
252 assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
253 assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
254 assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
255 assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
256 assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
257 assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
258 assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
259 assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
260 assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
261 assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
262 assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
263 assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
264 assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
265 assert_int_equal(yin_match_keyword(YCTX, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
David Sedlák872c7b42018-10-26 13:15:20 +0200266}
David Sedlák3b4db242018-10-19 16:11:01 +0200267
David Sedlák872c7b42018-10-26 13:15:20 +0200268static void
Radek Iša56ca9e42020-09-08 18:42:00 +0200269test_yin_match_argument_name(void **UNUSED(state))
David Sedlák872c7b42018-10-26 13:15:20 +0200270{
David Sedlák060b00e2019-06-19 11:12:06 +0200271 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
272 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
273 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
274 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
275 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
276 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
277 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
278 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
279 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
280 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
281 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
282 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200283}
284
David Sedlák68a1af12019-03-08 13:46:54 +0100285static void
David Sedlákb1a78352019-06-28 16:16:29 +0200286test_yin_parse_element_generic(void **state)
287{
David Sedlákb1a78352019-06-28 16:16:29 +0200288 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200289 LY_ERR ret;
Radek Iša56ca9e42020-09-08 18:42:00 +0200290 const char *arg;
291 const char *stmt;
292 const char *data;
David Sedlákb1a78352019-06-28 16:16:29 +0200293
294 memset(&exts, 0, sizeof(exts));
295
Radek Iša56ca9e42020-09-08 18:42:00 +0200296 data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
297 ly_in_new_memory(data, &UTEST_IN);
298 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100299
Radek Iša56ca9e42020-09-08 18:42:00 +0200300 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200301 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200302 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100303 stmt = "myext:elem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200304 arg = "text_value";
Radek Krejci996f0772021-02-05 19:39:41 +0100305 CHECK_LYSP_STMT(exts.child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200306 stmt = "attr";
307 arg = "value";
308 CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt);
309 lysp_ext_instance_free(UTEST_LYCTX, &exts);
310 RESET_STATE;
David Sedlák5392a212019-07-01 09:19:10 +0200311
David Sedlákb0ca07d2019-09-11 11:54:05 +0200312 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200313 ly_in_new_memory(data, &UTEST_IN);
314 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100315
Radek Iša56ca9e42020-09-08 18:42:00 +0200316 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200317 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200318 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100319 stmt = "myext:elem";
Radek Krejci996f0772021-02-05 19:39:41 +0100320 CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200321 lysp_ext_instance_free(UTEST_LYCTX, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200322}
323
324static void
325test_yin_parse_extension_instance(void **state)
326{
327 LY_ERR ret;
David Sedlákb1a78352019-06-28 16:16:29 +0200328 struct lysp_ext_instance *exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200329 struct lysp_stmt *act_child;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200330 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200331 const char *stmt = "value1";
332 const char *arg = "test";
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100333
Radek Iša56ca9e42020-09-08 18:42:00 +0200334 ly_in_new_memory(data, &UTEST_IN);
335 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100336
Radek Krejcifc596f92021-02-26 22:40:26 +0100337 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200338 assert_int_equal(ret, LY_SUCCESS);
Radek Krejci8df109d2021-04-23 12:19:08 +0200339 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, LY_STMT_CONTACT, 0, "myext:ext", LY_VALUE_XML);
David Sedlákb1a78352019-06-28 16:16:29 +0200340
Radek Iša56ca9e42020-09-08 18:42:00 +0200341 CHECK_LYSP_STMT(exts->child, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
342 stmt = "value";
343 arg = "test2";
344 CHECK_LYSP_STMT(exts->child->next, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100345 stmt = "myext:subelem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200346 arg = "text";
Radek Krejci996f0772021-02-05 19:39:41 +0100347 CHECK_LYSP_STMT(exts->child->next->next, arg, 0, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200348 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200349 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200350 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200351 RESET_STATE;
David Sedlákf250ecf2019-07-01 11:02:05 +0200352
David Sedlákb0ca07d2019-09-11 11:54:05 +0200353 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Radek Iša56ca9e42020-09-08 18:42:00 +0200354 ly_in_new_memory(data, &UTEST_IN);
355 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100356
Radek Krejcifc596f92021-02-26 22:40:26 +0100357 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200358 assert_int_equal(ret, LY_SUCCESS);
Radek Krejci8df109d2021-04-23 12:19:08 +0200359 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 0, LY_STMT_CONTACT, 0, "myext:extension-elem", LY_VALUE_XML);
Radek Iša56ca9e42020-09-08 18:42:00 +0200360 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200361 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200362 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200363 RESET_STATE;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200364
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100365 data =
366 "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n"
367 " <myext:ext-sub1/>\n"
368 " <myext:ext-sub2 sattr1=\"stext2\">\n"
369 " <myext:ext-sub21>\n"
370 " <myext:ext-sub211 sattr21=\"text21\"/>\n"
371 " </myext:ext-sub21>\n"
372 " </myext:ext-sub2>\n"
373 " <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n"
374 "</myext:ext>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200375 ly_in_new_memory(data, &UTEST_IN);
376 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100377
Radek Krejcifc596f92021-02-26 22:40:26 +0100378 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200379 assert_int_equal(ret, LY_SUCCESS);
380
Radek Krejci8df109d2021-04-23 12:19:08 +0200381 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, LY_STMT_CONTACT, 0, "myext:ext", LY_VALUE_XML);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200382
Radek Iša56ca9e42020-09-08 18:42:00 +0200383 stmt = "attr1";
384 arg = "text1";
385 act_child = exts->child;
386 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
387 stmt = "attr2";
388 arg = "text2";
389 act_child = act_child->next;
390 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100391 stmt = "myext:ext-sub1";
Radek Iša56ca9e42020-09-08 18:42:00 +0200392 arg = NULL;
393 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100394 CHECK_LYSP_STMT(act_child, arg, NULL, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100395 stmt = "myext:ext-sub2";
Radek Iša56ca9e42020-09-08 18:42:00 +0200396 arg = NULL;
397 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100398 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200399
Radek Iša56ca9e42020-09-08 18:42:00 +0200400 stmt = "sattr1";
401 arg = "stext2";
402 act_child = act_child->child;
403 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100404 stmt = "myext:ext-sub21";
Radek Iša56ca9e42020-09-08 18:42:00 +0200405 arg = NULL;
406 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100407 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200408
Michal Vaskofc2cd072021-02-24 13:17:17 +0100409 stmt = "myext:ext-sub211";
Radek Iša56ca9e42020-09-08 18:42:00 +0200410 arg = NULL;
411 act_child = act_child->child;
Radek Krejci996f0772021-02-05 19:39:41 +0100412 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200413
Radek Iša56ca9e42020-09-08 18:42:00 +0200414 stmt = "sattr21";
415 arg = "text21";
416 act_child = act_child->child;
417 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200418
Michal Vaskofc2cd072021-02-24 13:17:17 +0100419 stmt = "myext:ext-sub3";
Radek Iša56ca9e42020-09-08 18:42:00 +0200420 arg = NULL;
421 act_child = exts->child->next->next->next->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100422 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200423 stmt = "attr3";
424 arg = "text3";
425 act_child = act_child->child;
426 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200427
Radek Iša56ca9e42020-09-08 18:42:00 +0200428 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200429 LY_ARRAY_FREE(exts);
430 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200431 RESET_STATE;
David Sedlákaa98bba2019-09-12 11:52:14 +0200432
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100433 data =
434 "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
435 " <yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>\n"
436 " <yin:augment target-node=\"target\"/>\n"
437 " <yin:status value=\"value\"/>\n"
438 " <yin:include module=\"mod\"/>\n"
439 " <yin:input />\n"
440 " <yin:must condition=\"cond\"/>\n"
441 " <yin:namespace uri=\"uri\"/>\n"
442 " <yin:revision date=\"data\"/>\n"
443 " <yin:unique tag=\"tag\"/>\n"
444 " <yin:description><yin:text>contact-val</yin:text></yin:description>\n"
445 " <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n"
446 "</myext:extension-elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200447 ly_in_new_memory(data, &UTEST_IN);
448 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100449
Radek Krejcifc596f92021-02-26 22:40:26 +0100450 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200451 assert_int_equal(ret, LY_SUCCESS);
452 assert_string_equal(exts->child->arg, "act-name");
453 assert_string_equal(exts->child->next->arg, "target");
454 assert_string_equal(exts->child->next->next->arg, "value");
455 assert_string_equal(exts->child->next->next->next->arg, "mod");
456 assert_null(exts->child->next->next->next->next->arg);
457 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
458 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
459 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
460 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
461 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
Radek Iša56ca9e42020-09-08 18:42:00 +0200462 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200463 LY_ARRAY_FREE(exts);
464 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200465 RESET_STATE;
David Sedlákb1a78352019-06-28 16:16:29 +0200466}
467
David Sedlák555c7202019-07-04 12:14:12 +0200468static void
469test_yin_parse_content(void **state)
470{
David Sedlák555c7202019-07-04 12:14:12 +0200471 LY_ERR ret = LY_SUCCESS;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100472 const char *data =
473 "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
474 " <myext:custom xmlns:myext=\"urn:example:extensions\">totally amazing extension</myext:custom>\n"
475 " <extension name=\"ext\">\n"
476 " <argument name=\"argname\"></argument>\n"
477 " <description><text>desc</text></description>\n"
478 " <reference><text>ref</text></reference>\n"
479 " <status value=\"deprecated\"></status>\n"
480 " </extension>\n"
481 " <text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>\n"
482 " <if-feature name=\"foo\"></if-feature>\n"
483 " <when condition=\"condition...\">\n"
484 " <reference><text>when_ref</text></reference>\n"
485 " <description><text>when_desc</text></description>\n"
486 " </when>\n"
487 " <config value=\"true\"/>\n"
488 " <error-message>\n"
489 " <value>error-msg</value>\n"
490 " </error-message>\n"
491 " <error-app-tag value=\"err-app-tag\"/>\n"
492 " <units name=\"radians\"></units>\n"
493 " <default value=\"default-value\"/>\n"
494 " <position value=\"25\"></position>\n"
495 " <value value=\"-5\"/>\n"
496 " <require-instance value=\"true\"></require-instance>\n"
497 " <range value=\"5..10\" />\n"
498 " <length value=\"baf\"/>\n"
499 " <pattern value='pattern'>\n"
500 " <modifier value='invert-match'/>\n"
501 " </pattern>\n"
502 " <enum name=\"yay\">\n"
503 " </enum>\n"
504 "</prefix>";
David Sedlák555c7202019-07-04 12:14:12 +0200505 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200506 const char **if_features = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200507 const char *value, *error_message, *app_tag, *units;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200508 struct lysp_qname def = {0};
David Sedlák986cb412019-07-04 13:10:11 +0200509 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200510 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200511 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200512 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
Juraj Vijtiukf6a07372020-10-29 21:13:33 +0100513 uint16_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200514
Radek Iša56ca9e42020-09-08 18:42:00 +0200515 ly_in_new_memory(data, &UTEST_IN);
516 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
517 lyxml_ctx_next(YCTX->xmlctx);
518 lyxml_ctx_next(YCTX->xmlctx);
519 lyxml_ctx_next(YCTX->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200520
David Sedlákfd5b9c32019-07-12 15:33:13 +0200521 struct yin_subelement subelems[17] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100522 {LY_STMT_CONFIG, &config, 0},
523 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
524 {LY_STMT_ENUM, &enum_type, 0},
525 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
Radek Iša56ca9e42020-09-08 18:42:00 +0200526 {LY_STMT_ERROR_MESSAGE, &error_message, 0},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100527 {LY_STMT_EXTENSION, &ext_def, 0},
528 {LY_STMT_IF_FEATURE, &if_features, 0},
529 {LY_STMT_LENGTH, &len_type, 0},
530 {LY_STMT_PATTERN, &patter_type, 0},
531 {LY_STMT_POSITION, &pos_enum, 0},
532 {LY_STMT_RANGE, &range_type, 0},
533 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
534 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
535 {LY_STMT_VALUE, &val_enum, 0},
536 {LY_STMT_WHEN, &when_p, 0},
537 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
538 {LY_STMT_ARG_TEXT, &value, 0}
539 };
540
Radek Iša56ca9e42020-09-08 18:42:00 +0200541 ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200542 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200543 /* check parsed values */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200544 assert_string_equal(def.str, "default-value");
Michal Vaskofc2cd072021-02-24 13:17:17 +0100545 const char *exts_name = "myext:custom";
Radek Iša56ca9e42020-09-08 18:42:00 +0200546 const char *exts_arg = "totally amazing extension";
547
Radek Krejci8df109d2021-04-23 12:19:08 +0200548 CHECK_LYSP_EXT_INSTANCE(exts, exts_arg, 0, LY_STMT_PREFIX, 0, exts_name, LY_VALUE_XML);
David Sedlák555c7202019-07-04 12:14:12 +0200549 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200550 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200551 assert_string_equal(when_p->cond, "condition...");
552 assert_string_equal(when_p->dsc, "when_desc");
553 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200554 assert_int_equal(config, LYS_CONFIG_W);
Radek Iša56ca9e42020-09-08 18:42:00 +0200555 CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25);
556 CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5);
David Sedlákcf5569a2019-07-11 13:31:34 +0200557 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200558 assert_true(req_type.flags &= LYS_SET_REQINST);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200559 assert_string_equal(range_type.range->arg.str, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200560 assert_true(range_type.flags & LYS_SET_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +0200561 assert_string_equal(error_message, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200562 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200563 assert_string_equal(enum_type.enums->name, "yay");
Radek Iša56ca9e42020-09-08 18:42:00 +0200564 CHECK_LYSP_RESTR(len_type.length, "baf", NULL,
565 NULL, NULL, 0, NULL);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200566 assert_true(len_type.flags & LYS_SET_LENGTH);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200567 assert_string_equal(patter_type.patterns->arg.str, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200568 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200569 /* cleanup */
Radek Iša56ca9e42020-09-08 18:42:00 +0200570 lysp_ext_instance_free(UTEST_LYCTX, exts);
571 lysp_when_free(UTEST_LYCTX, when_p);
572 lysp_ext_free(UTEST_LYCTX, ext_def);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100573 lydict_remove(UTEST_LYCTX, *if_features);
574 lydict_remove(UTEST_LYCTX, error_message);
575 lydict_remove(UTEST_LYCTX, app_tag);
576 lydict_remove(UTEST_LYCTX, units);
577 lydict_remove(UTEST_LYCTX, patter_type.patterns->arg.str);
578 lydict_remove(UTEST_LYCTX, def.str);
579 lydict_remove(UTEST_LYCTX, range_type.range->arg.str);
580 lydict_remove(UTEST_LYCTX, len_type.length->arg.str);
581 lydict_remove(UTEST_LYCTX, enum_type.enums->name);
582 lydict_remove(UTEST_LYCTX, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200583 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200584 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200585 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200586 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200587 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200588 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200589 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200590 free(len_type.length);
Radek Iša56ca9e42020-09-08 18:42:00 +0200591 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200592
593 /* test unique subelem */
594 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200595 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100596 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
597
David Sedláke6cd89e2019-08-07 12:46:02 +0200598 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100599 "<prefix value=\"inv_mod\" />"
600 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
601 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
602 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200603 ly_in_new_memory(data, &UTEST_IN);
604 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
605 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100606
Radek Iša56ca9e42020-09-08 18:42:00 +0200607 ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200608 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200609 CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1.");
610 lydict_remove(UTEST_LYCTX, prefix_value);
611 lydict_remove(UTEST_LYCTX, value);
612 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200613
614 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200615 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100616 "<prefix value=\"inv_mod\" />"
617 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
618 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
619 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200620 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100621 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
622
Radek Iša56ca9e42020-09-08 18:42:00 +0200623 ly_in_new_memory(data, &UTEST_IN);
624 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
625 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100626
Radek Iša56ca9e42020-09-08 18:42:00 +0200627 ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200628 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200629 CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1.");
630 lydict_remove(UTEST_LYCTX, prefix_value);
631 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200632
633 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200634 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200635 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100636
Radek Iša56ca9e42020-09-08 18:42:00 +0200637 ly_in_new_memory(data, &UTEST_IN);
638 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
639 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100640
Radek Iša56ca9e42020-09-08 18:42:00 +0200641 ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200642 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200643 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200644}
645
David Sedlák92147b02019-07-09 14:01:01 +0200646static void
David Sedlák4a650532019-07-10 11:55:18 +0200647test_validate_value(void **state)
648{
Michal Vaskob36053d2020-03-26 15:49:30 +0100649 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
650
651 /* create some XML context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200652 ly_in_new_memory(data, &UTEST_IN);
653 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
654 YCTX->xmlctx->status = LYXML_ELEM_CONTENT;
655 YCTX->xmlctx->dynamic = 0;
Michal Vaskob36053d2020-03-26 15:49:30 +0100656
Radek Iša56ca9e42020-09-08 18:42:00 +0200657 YCTX->xmlctx->value = "#invalid";
658 YCTX->xmlctx->value_len = 8;
659 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
Radek Iša2eac74c2021-03-15 15:53:08 +0100660 CHECK_LOG_CTX("Invalid identifier first character '#' (0x0023).", "Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100661
Radek Iša56ca9e42020-09-08 18:42:00 +0200662 YCTX->xmlctx->value = "";
663 YCTX->xmlctx->value_len = 0;
664 assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100665
Radek Iša56ca9e42020-09-08 18:42:00 +0200666 YCTX->xmlctx->value = "pre:b";
667 YCTX->xmlctx->value_len = 5;
668 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
669 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100670
Radek Iša56ca9e42020-09-08 18:42:00 +0200671 YCTX->xmlctx->value = "pre:pre:b";
672 YCTX->xmlctx->value_len = 9;
673 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200674}
675
David Sedlák32488102019-07-15 17:44:10 +0200676/* helper function to simplify unit test of each element using parse_content function */
677LY_ERR
Radek Iša56ca9e42020-09-08 18:42:00 +0200678test_element_helper(void **state, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
David Sedlák32488102019-07-15 17:44:10 +0200679{
David Sedlákc5b20842019-08-13 10:18:31 +0200680 const char *name, *prefix;
681 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200682 LY_ERR ret = LY_SUCCESS;
683 struct yin_subelement subelems[71] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100684 {LY_STMT_ACTION, dest, 0},
685 {LY_STMT_ANYDATA, dest, 0},
686 {LY_STMT_ANYXML, dest, 0},
687 {LY_STMT_ARGUMENT, dest, 0},
688 {LY_STMT_AUGMENT, dest, 0},
689 {LY_STMT_BASE, dest, 0},
690 {LY_STMT_BELONGS_TO, dest, 0},
691 {LY_STMT_BIT, dest, 0},
692 {LY_STMT_CASE, dest, 0},
693 {LY_STMT_CHOICE, dest, 0},
694 {LY_STMT_CONFIG, dest, 0},
695 {LY_STMT_CONTACT, dest, 0},
696 {LY_STMT_CONTAINER, dest, 0},
697 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
698 {LY_STMT_DESCRIPTION, dest, 0},
699 {LY_STMT_DEVIATE, dest, 0},
700 {LY_STMT_DEVIATION, dest, 0},
701 {LY_STMT_ENUM, dest, 0},
702 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
703 {LY_STMT_ERROR_MESSAGE, dest, 0},
704 {LY_STMT_EXTENSION, dest, 0},
705 {LY_STMT_FEATURE, dest, 0},
706 {LY_STMT_FRACTION_DIGITS, dest, 0},
707 {LY_STMT_GROUPING, dest, 0},
708 {LY_STMT_IDENTITY, dest, 0},
709 {LY_STMT_IF_FEATURE, dest, 0},
710 {LY_STMT_IMPORT, dest, 0},
711 {LY_STMT_INCLUDE, dest, 0},
712 {LY_STMT_INPUT, dest, 0},
713 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
714 {LY_STMT_LEAF, dest, 0},
715 {LY_STMT_LEAF_LIST, dest, 0},
716 {LY_STMT_LENGTH, dest, 0},
717 {LY_STMT_LIST, dest, 0},
718 {LY_STMT_MANDATORY, dest, 0},
719 {LY_STMT_MAX_ELEMENTS, dest, 0},
720 {LY_STMT_MIN_ELEMENTS, dest, 0},
721 {LY_STMT_MODIFIER, dest, 0},
722 {LY_STMT_MODULE, dest, 0},
723 {LY_STMT_MUST, dest, 0},
724 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
725 {LY_STMT_NOTIFICATION, dest, 0},
726 {LY_STMT_ORDERED_BY, dest, 0},
727 {LY_STMT_ORGANIZATION, dest, 0},
728 {LY_STMT_OUTPUT, dest, 0},
729 {LY_STMT_PATH, dest, 0},
730 {LY_STMT_PATTERN, dest, 0},
731 {LY_STMT_POSITION, dest, 0},
732 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
733 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
734 {LY_STMT_RANGE, dest, 0},
735 {LY_STMT_REFERENCE, dest, 0},
736 {LY_STMT_REFINE, dest, 0},
737 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
738 {LY_STMT_REVISION, dest, 0},
739 {LY_STMT_REVISION_DATE, dest, 0},
740 {LY_STMT_RPC, dest, 0},
741 {LY_STMT_STATUS, dest, 0},
742 {LY_STMT_SUBMODULE, dest, 0},
743 {LY_STMT_TYPE, dest, 0},
744 {LY_STMT_TYPEDEF, dest, 0},
745 {LY_STMT_UNIQUE, dest, 0},
746 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
747 {LY_STMT_USES, dest, 0},
748 {LY_STMT_VALUE, dest, 0},
749 {LY_STMT_WHEN, dest, 0},
750 {LY_STMT_YANG_VERSION, dest, 0},
751 {LY_STMT_YIN_ELEMENT, dest, 0},
752 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
753 {LY_STMT_ARG_TEXT, dest, 0},
754 {LY_STMT_ARG_VALUE, dest, 0}
755 };
756
aPiecek8d4e75d2021-06-24 14:47:06 +0200757 YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
Radek Iša56ca9e42020-09-08 18:42:00 +0200758 ly_in_new_memory(data, &UTEST_IN);
759 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
760 prefix = YCTX->xmlctx->prefix;
761 prefix_len = YCTX->xmlctx->prefix_len;
762 name = YCTX->xmlctx->name;
763 name_len = YCTX->xmlctx->name_len;
764 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100765
Radek Iša56ca9e42020-09-08 18:42:00 +0200766 ret = yin_parse_content(YCTX, subelems, 71, yin_match_keyword(YCTX, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
Michal Vaskob36053d2020-03-26 15:49:30 +0100767
Michal Vasko63f3d842020-07-08 10:10:14 +0200768 /* free parser and input */
Radek Iša56ca9e42020-09-08 18:42:00 +0200769 lyxml_ctx_free(YCTX->xmlctx);
770 YCTX->xmlctx = NULL;
771 ly_in_free(UTEST_IN, 0);
772 UTEST_IN = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200773 return ret;
774}
775
David Sedlákd1144562019-08-06 12:36:14 +0200776#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
777
David Sedlák32488102019-07-15 17:44:10 +0200778static void
David Sedlák43801c92019-08-05 15:58:54 +0200779test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200780{
David Sedlák32488102019-07-15 17:44:10 +0200781 struct lysp_type type = {};
782 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100783
David Sedlák32488102019-07-15 17:44:10 +0200784 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100785 "<enum name=\"enum-name\">\n"
786 " <if-feature name=\"feature\" />\n"
787 " <value value=\"55\" />\n"
788 " <status value=\"deprecated\" />\n"
789 " <description><text>desc...</text></description>\n"
790 " <reference><text>ref...</text></reference>\n"
791 " " EXT_SUBELEM "\n"
792 "</enum>"
793 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200794 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
795 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
796
797 CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200798 assert_string_equal(type.enums->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100799 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LY_STMT_ENUM);
Radek Iša56ca9e42020-09-08 18:42:00 +0200800 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200801 memset(&type, 0, sizeof type);
802
803 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100804 "<enum name=\"enum-name\"></enum>"
805 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200806 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200807 assert_string_equal(type.enums->name, "enum-name");
Radek Iša56ca9e42020-09-08 18:42:00 +0200808 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák32488102019-07-15 17:44:10 +0200809 memset(&type, 0, sizeof type);
David Sedlák43801c92019-08-05 15:58:54 +0200810}
811
812static void
813test_bit_elem(void **state)
814{
David Sedlák43801c92019-08-05 15:58:54 +0200815 struct lysp_type type = {};
816 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100817
David Sedlák43801c92019-08-05 15:58:54 +0200818 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100819 "<bit name=\"bit-name\">\n"
820 " <if-feature name=\"feature\" />\n"
821 " <position value=\"55\" />\n"
822 " <status value=\"deprecated\" />\n"
823 " <description><text>desc...</text></description>\n"
824 " <reference><text>ref...</text></reference>\n"
825 EXT_SUBELEM
826 "</bit>"
827 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200828 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
829 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
830
831 CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200832 assert_string_equal(type.bits->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100833 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LY_STMT_BIT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200834 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200835 memset(&type, 0, sizeof type);
836
837 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100838 "<bit name=\"bit-name\"> </bit>"
839 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200840 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
841 CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
842 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák43801c92019-08-05 15:58:54 +0200843 memset(&type, 0, sizeof type);
David Sedlák32488102019-07-15 17:44:10 +0200844}
845
846static void
847test_meta_elem(void **state)
848{
David Sedlák32488102019-07-15 17:44:10 +0200849 char *value = NULL;
850 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200851 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200852
853 /* organization element */
854 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100855 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
856 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200857 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100858 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORGANIZATION);
859 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LY_STMT_ORGANIZATION);
Radek Iša56ca9e42020-09-08 18:42:00 +0200860
David Sedlák32488102019-07-15 17:44:10 +0200861 assert_string_equal(value, "organization...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100862 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200863 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200864 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200865 exts = NULL;
866
David Sedlák32488102019-07-15 17:44:10 +0200867 /* contact element */
868 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100869 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
870 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200871 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100872 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200873 assert_string_equal(value, "contact...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100874 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200875 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200876 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200877 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200878
David Sedlák32488102019-07-15 17:44:10 +0200879 /* description element */
880 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100881 "<description><text>description...</text>" EXT_SUBELEM "</description>"
882 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200883 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100884 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200885 assert_string_equal(value, "description...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100886 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200887 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200888 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200889 exts = NULL;
890
David Sedlák32488102019-07-15 17:44:10 +0200891 /* reference element */
892 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100893 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
894 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200895 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200896 assert_string_equal(value, "reference...");
Radek Krejcifc596f92021-02-26 22:40:26 +0100897 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REFERENCE);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100898 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200899 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200900 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200901 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200902
David Sedlákdf2a9732019-08-07 13:23:16 +0200903 /* reference element */
904 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100905 "<reference invalid=\"text\"><text>reference...</text>" "</reference>"
906 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200907 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
908 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100909 lydict_remove(UTEST_LYCTX, value);
David Sedlákdf2a9732019-08-07 13:23:16 +0200910 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200911 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákdf2a9732019-08-07 13:23:16 +0200912 exts = NULL;
913
David Sedlák32488102019-07-15 17:44:10 +0200914 /* missing text subelement */
915 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100916 "<reference>reference...</reference>"
917 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200918 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
919 CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +0200920
David Sedlákd1144562019-08-06 12:36:14 +0200921 /* reference element */
922 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100923 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
924 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200925 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
926 CHECK_LOG_CTX("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element.", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100927 lydict_remove(UTEST_LYCTX, value);
David Sedlákd1144562019-08-06 12:36:14 +0200928 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200929 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200930 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200931}
932
933static void
934test_import_elem(void **state)
935{
David Sedlák32488102019-07-15 17:44:10 +0200936 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +0200937 struct lysp_import *imports = NULL;
938 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +0200939
940 /* max subelems */
941 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100942 "<import module=\"a\">\n"
943 EXT_SUBELEM
944 " <prefix value=\"a_mod\"/>\n"
945 " <revision-date date=\"2015-01-01\"></revision-date>\n"
946 " <description><text>import description</text></description>\n"
947 " <reference><text>import reference</text></reference>\n"
948 "</import>"
949 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200950 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
951 CHECK_LYSP_IMPORT(imports, "import description", 1, "a",
952 "a_mod", "import reference", "2015-01-01");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100953 TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LY_STMT_IMPORT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200954 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200955 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200956
957 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +0200958 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100959 "<import module=\"a\">\n"
960 " <prefix value=\"a_mod\"/>\n"
961 "</import>"
962 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200963 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
964 CHECK_LYSP_IMPORT(imports, NULL, 0, "a",
965 "a_mod", NULL, "");
966 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200967 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200968
969 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +0200970 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200971 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
972 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1.");
973 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200974 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200975
976 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +0200977 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100978 "<import module=\"a\">\n"
979 " <prefix value=\"prefix\"/>\n"
980 "</import>"
981 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200982 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
983 CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3.");
984 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200985 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200986
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100987 data = ELEMENT_WRAPPER_START
988 "<import module=\"a\">\n"
989 " <prefix value=\"a\"/>\n"
990 "</import>\n"
991 "<import module=\"a\">\n"
992 " <prefix value=\"a\"/>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200993 "</import>\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100994 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200995 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
996 CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6.");
997 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100998 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200999}
1000
1001static void
1002test_status_elem(void **state)
1003{
David Sedlák32488102019-07-15 17:44:10 +02001004 const char *data;
1005 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001006 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001007
1008 /* test valid values */
1009 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001010 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001011 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001012
1013 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001014 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001015 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001016
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001017 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001018 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001019 assert_true(flags & LYS_STATUS_OBSLT);
Radek Krejcifc596f92021-02-26 22:40:26 +01001020 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_STATUS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001021 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001022 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001023
1024 /* test invalid value */
1025 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001026 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1027 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. "
1028 "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001029}
1030
1031static void
1032test_ext_elem(void **state)
1033{
David Sedlák32488102019-07-15 17:44:10 +02001034 const char *data;
1035 struct lysp_ext *ext = NULL;
1036
1037 /* max subelems */
1038 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001039 "<extension name=\"ext_name\">\n"
1040 " <argument name=\"arg\"></argument>\n"
1041 " <status value=\"current\"/>\n"
1042 " <description><text>ext_desc</text></description>\n"
1043 " <reference><text>ext_ref</text></reference>\n"
1044 EXT_SUBELEM
1045 "</extension>"
1046 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001047 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1048 CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001049 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LY_STMT_EXTENSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001050 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001051 LY_ARRAY_FREE(ext);
1052 ext = NULL;
1053
1054 /* min subelems */
1055 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001056 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1057 CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL);
1058 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001059 LY_ARRAY_FREE(ext);
1060 ext = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001061}
1062
1063static void
1064test_yin_element_elem(void **state)
1065{
David Sedlák32488102019-07-15 17:44:10 +02001066 const char *data;
1067 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001068 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001069
1070 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001071 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001072 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001073
David Sedlákd1144562019-08-06 12:36:14 +02001074 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001075 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001076 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001077 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YIN_ELEMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001078 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001079
1080 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001081 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001082 assert_true(flags & LYS_YINELEM_TRUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001083 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. "
1084 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001085}
1086
1087static void
1088test_yangversion_elem(void **state)
1089{
David Sedlák32488102019-07-15 17:44:10 +02001090 const char *data;
1091 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001092 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001093
1094 /* valid values */
Radek Krejci96e48da2020-09-04 13:18:06 +02001095 data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001096 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001097 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001098
David Sedlákd1144562019-08-06 12:36:14 +02001099 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001100 assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001101 assert_true(version & LYS_VERSION_1_1);
Radek Krejcifc596f92021-02-26 22:40:26 +01001102 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YANG_VERSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001103 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001104
1105 /* invalid value */
1106 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001107 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID);
1108 CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. "
1109 "Valid values are \"1\" and \"1.1\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001110}
1111
1112static void
1113test_mandatory_elem(void **state)
1114{
David Sedlák32488102019-07-15 17:44:10 +02001115 const char *data;
1116 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001117 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001118
1119 /* valid values */
1120 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001121 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001122 assert_int_equal(man, LYS_MAND_TRUE);
1123 man = 0;
1124
David Sedlákd1144562019-08-06 12:36:14 +02001125 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001126 assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001127 assert_int_equal(man, LYS_MAND_FALSE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001128 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MANDATORY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001129 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001130
1131 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001132 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID);
1133 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. "
1134 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001135}
1136
David Sedlák8e7bda82019-07-16 17:57:50 +02001137static void
1138test_argument_elem(void **state)
1139{
David Sedlák8e7bda82019-07-16 17:57:50 +02001140 const char *data;
1141 uint16_t flags = 0;
1142 const char *arg;
1143 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001144 struct lysp_ext_instance *exts = NULL;
1145
David Sedlák8e7bda82019-07-16 17:57:50 +02001146 /* max subelems */
1147 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001148 "<argument name=\"arg-name\">\n"
1149 " <yin-element value=\"true\" />\n"
1150 EXT_SUBELEM
1151 "</argument>"
1152 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001153 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001154 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001155 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001156 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ARGUMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001157 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001158 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001159 flags = 0;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001160 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001161 arg = NULL;
1162
1163 /* min subelems */
1164 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001165 "<argument name=\"arg\">"
1166 "</argument>"
1167 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001168 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001169 assert_string_equal(arg, "arg");
1170 assert_true(flags == 0);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001171 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001172}
1173
1174static void
1175test_base_elem(void **state)
1176{
David Sedlák8e7bda82019-07-16 17:57:50 +02001177 const char *data;
1178 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001179 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001180 struct lysp_type type = {};
1181
1182 /* as identity subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001183 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1184 " <base name=\"base-name\">\n"
1185 EXT_SUBELEM
1186 " </base>\n"
1187 "</identity>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001188 assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001189 assert_string_equal(*bases, "base-name");
Radek Krejcifc596f92021-02-26 22:40:26 +01001190 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001191 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001192 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001193 lydict_remove(UTEST_LYCTX, *bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001194 LY_ARRAY_FREE(bases);
1195
1196 /* as type subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001197 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1198 " <base name=\"base-name\">\n"
1199 EXT_SUBELEM
1200 " </base>\n"
1201 "</type>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001202 assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001203 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001204 assert_true(type.flags & LYS_SET_BASE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001205 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001206 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001207 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001208 lydict_remove(UTEST_LYCTX, *type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001209 LY_ARRAY_FREE(type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001210}
1211
1212static void
1213test_belongsto_elem(void **state)
1214{
David Sedlák8e7bda82019-07-16 17:57:50 +02001215 const char *data;
1216 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001217 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001218
Radek Iša56ca9e42020-09-08 18:42:00 +02001219 lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name);
1220
David Sedlák8e7bda82019-07-16 17:57:50 +02001221 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001222 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
1223 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001224 assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001225 assert_string_equal(submod.prefix, "pref");
Radek Krejcifc596f92021-02-26 22:40:26 +01001226 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BELONGS_TO);
Radek Iša56ca9e42020-09-08 18:42:00 +02001227 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001228 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001229 lydict_remove(UTEST_LYCTX, submod.prefix);
David Sedlák8e7bda82019-07-16 17:57:50 +02001230
1231 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001232 assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID);
1233 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001234}
1235
1236static void
1237test_config_elem(void **state)
1238{
David Sedlák8e7bda82019-07-16 17:57:50 +02001239 const char *data;
1240 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001241 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001242
David Sedlákd1144562019-08-06 12:36:14 +02001243 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001244 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001245 assert_true(flags & LYS_CONFIG_W);
Radek Krejcifc596f92021-02-26 22:40:26 +01001246 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONFIG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001247 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001248 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001249 flags = 0;
1250
1251 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001252 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001253 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001254 flags = 0;
1255
1256 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001257 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1258 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. "
1259 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001260}
1261
1262static void
1263test_default_elem(void **state)
1264{
David Sedlák8e7bda82019-07-16 17:57:50 +02001265 const char *data;
Michal Vasko7f45cf22020-10-01 12:49:44 +02001266 struct lysp_qname val = {0};
David Sedlákd1144562019-08-06 12:36:14 +02001267 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001268
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001269 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001270 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001271 assert_string_equal(val.str, "defaul-value");
Radek Krejcifc596f92021-02-26 22:40:26 +01001272 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DEFAULT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001273 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001274 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001275 lydict_remove(UTEST_LYCTX, val.str);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001276 val.str = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001277
1278 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001279 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1280 CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001281}
1282
1283static void
1284test_err_app_tag_elem(void **state)
1285{
David Sedlák8e7bda82019-07-16 17:57:50 +02001286 const char *data;
1287 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001288 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001289
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001290 data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM "</error-app-tag>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001291 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001292 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001293 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_APP_TAG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001294 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001295 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001296 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001297 val = NULL;
1298
1299 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001300 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1301 CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001302}
1303
1304static void
1305test_err_msg_elem(void **state)
1306{
David Sedlák8e7bda82019-07-16 17:57:50 +02001307 const char *data;
1308 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001309 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001310
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001311 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001312 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001313 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001314 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_MESSAGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001315 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001316 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001317 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001318
1319 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001320 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1321 CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001322
David Sedlákdf2a9732019-08-07 13:23:16 +02001323 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001324 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1325 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001326}
1327
1328static void
1329test_fracdigits_elem(void **state)
1330{
David Sedlák8e7bda82019-07-16 17:57:50 +02001331 const char *data;
1332 struct lysp_type type = {};
1333
1334 /* valid value */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001335 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001336 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
Radek Krejci5984d222021-02-26 23:01:45 +01001337 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_FRACTION_DIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001338 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001339 assert_true(type.flags & LYS_SET_FRDIGITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001340 FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001341
1342 /* invalid values */
1343 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001344 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1345 CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001346
1347 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001348 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1349 CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001350
1351 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001352 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1353 CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001354
1355 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001356 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1357 CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001358
1359 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001360 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1361 CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001362}
1363
1364static void
1365test_iffeature_elem(void **state)
1366{
David Sedlák8e7bda82019-07-16 17:57:50 +02001367 const char *data;
1368 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001369 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001370
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001371 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001372 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001373 assert_string_equal(*iffeatures, "local-storage");
Radek Krejci5984d222021-02-26 23:01:45 +01001374 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_IF_FEATURE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001375 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001376 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001377 lydict_remove(UTEST_LYCTX, *iffeatures);
David Sedlák8e7bda82019-07-16 17:57:50 +02001378 LY_ARRAY_FREE(iffeatures);
1379 iffeatures = NULL;
1380
1381 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001382 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID);
1383 CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001384 LY_ARRAY_FREE(iffeatures);
1385 iffeatures = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001386}
1387
1388static void
1389test_length_elem(void **state)
1390{
David Sedlák8e7bda82019-07-16 17:57:50 +02001391 const char *data;
1392 struct lysp_type type = {};
1393
1394 /* max subelems */
1395 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001396 "<length value=\"length-str\">\n"
1397 " <error-message><value>err-msg</value></error-message>\n"
1398 " <error-app-tag value=\"err-app-tag\"/>\n"
1399 " <description><text>desc</text></description>\n"
1400 " <reference><text>ref</text></reference>\n"
1401 EXT_SUBELEM
1402 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001403 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001404 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1405 CHECK_LYSP_RESTR(type.length, "length-str", "desc",
1406 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001407 assert_true(type.flags & LYS_SET_LENGTH);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001408 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LY_STMT_LENGTH);
Radek Iša56ca9e42020-09-08 18:42:00 +02001409 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001410 memset(&type, 0, sizeof(type));
1411
1412 /* min subelems */
1413 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001414 "<length value=\"length-str\">"
1415 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001416 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001417 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1418 CHECK_LYSP_RESTR(type.length, "length-str", NULL,
1419 NULL, NULL, 0, NULL);
1420 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001421 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001422 memset(&type, 0, sizeof(type));
1423
1424 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001425 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1426 CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
1427 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001428 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001429}
1430
1431static void
1432test_modifier_elem(void **state)
1433{
David Sedlák8e7bda82019-07-16 17:57:50 +02001434 const char *data;
Radek Krejci011e4aa2020-09-04 15:22:31 +02001435 const char *pat;
David Sedlákd1144562019-08-06 12:36:14 +02001436 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001437
Radek Iša56ca9e42020-09-08 18:42:00 +02001438 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlákd1144562019-08-06 12:36:14 +02001439 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001440 assert_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001441 assert_string_equal(pat, "\x015pattern");
Radek Krejci5984d222021-02-26 23:01:45 +01001442 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MODIFIER);
Radek Iša56ca9e42020-09-08 18:42:00 +02001443 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001444 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001445 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001446
Radek Iša56ca9e42020-09-08 18:42:00 +02001447 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlák8e7bda82019-07-16 17:57:50 +02001448 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001449 assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID);
1450 CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. "
1451 "Only valid value is \"invert-match\".", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001452 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001453}
1454
1455static void
1456test_namespace_elem(void **state)
1457{
David Sedlák8e7bda82019-07-16 17:57:50 +02001458 const char *data;
1459 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001460 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001461
David Sedlákd1144562019-08-06 12:36:14 +02001462 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001463 assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001464 assert_string_equal(ns, "ns");
Radek Krejci5984d222021-02-26 23:01:45 +01001465 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_NAMESPACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001466 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001467 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001468 lydict_remove(UTEST_LYCTX, ns);
David Sedlák8e7bda82019-07-16 17:57:50 +02001469
1470 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001471 assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID);
1472 CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001473}
1474
1475static void
David Sedlák8e7bda82019-07-16 17:57:50 +02001476test_pattern_elem(void **state)
1477{
David Sedlák8e7bda82019-07-16 17:57:50 +02001478 const char *data;
1479 struct lysp_type type = {};
1480
1481 /* max subelems */
1482 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001483 "<pattern value=\"super_pattern\">\n"
1484 " <modifier value=\"invert-match\"/>\n"
1485 " <error-message><value>err-msg-value</value></error-message>\n"
1486 " <error-app-tag value=\"err-app-tag-value\"/>\n"
1487 " <description><text>&quot;pattern-desc&quot;</text></description>\n"
1488 " <reference><text>pattern-ref</text></reference>\n"
1489 EXT_SUBELEM
1490 "</pattern>"
1491 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001492 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001493 assert_true(type.flags & LYS_SET_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001494 CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
1495 "err-app-tag-value", "err-msg-value", 1, "pattern-ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001496 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LY_STMT_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001497 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001498 memset(&type, 0, sizeof(type));
1499
1500 /* min subelems */
1501 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001502 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1503 CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
1504 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001505 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001506}
1507
1508static void
1509test_value_position_elem(void **state)
1510{
David Sedlák8e7bda82019-07-16 17:57:50 +02001511 const char *data;
1512 struct lysp_type_enum en = {};
1513
1514 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001515 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001516 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1517 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001518 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_VALUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001519 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001520 memset(&en, 0, sizeof(en));
1521
1522 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001523 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1524 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55);
David Sedlák8e7bda82019-07-16 17:57:50 +02001525 memset(&en, 0, sizeof(en));
1526
1527 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001528 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1529 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001530 memset(&en, 0, sizeof(en));
1531
1532 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001533 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1534 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001535 memset(&en, 0, sizeof(en));
1536
1537 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001538 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001539 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1540 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001541 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_POSITION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001542 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001543 memset(&en, 0, sizeof(en));
1544
1545 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001546 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1547 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001548 memset(&en, 0, sizeof(en));
1549
1550 /* invalid values */
1551 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001552 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1553 CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001554
1555 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001556 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1557 CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001558
David Sedlák69f01612019-07-17 11:41:08 +02001559 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001560 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1561 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001562
David Sedlák8e7bda82019-07-16 17:57:50 +02001563 /*invalid positions */
1564 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001565 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1566 CHECK_LOG_CTX("Invalid value \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001567
1568 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001569 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1570 CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001571
1572 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001573 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1574 CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001575
David Sedlák69f01612019-07-17 11:41:08 +02001576 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001577 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1578 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001579}
1580
1581static void
1582test_prefix_elem(void **state)
1583{
David Sedlák69f01612019-07-17 11:41:08 +02001584 const char *data;
1585 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001586 struct lysp_ext_instance *exts = NULL;
1587
1588 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001589 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001590 assert_string_equal(value, "pref");
Radek Krejci5984d222021-02-26 23:01:45 +01001591 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PREFIX);
Radek Iša56ca9e42020-09-08 18:42:00 +02001592 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001593 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001594 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001595
1596 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001597 assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001598 assert_string_equal(value, "pref");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001599 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001600}
1601
1602static void
1603test_range_elem(void **state)
1604{
David Sedlák69f01612019-07-17 11:41:08 +02001605 const char *data;
1606 struct lysp_type type = {};
1607
1608 /* max subelems */
1609 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001610 "<range value=\"range-str\">\n"
1611 " <error-message><value>err-msg</value></error-message>\n"
1612 " <error-app-tag value=\"err-app-tag\" />\n"
1613 " <description><text>desc</text></description>\n"
1614 " <reference><text>ref</text></reference>\n"
1615 EXT_SUBELEM
1616 "</range>"
1617 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001618 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1619 CHECK_LYSP_RESTR(type.range, "range-str", "desc",
1620 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001621 assert_true(type.flags & LYS_SET_RANGE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001622 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LY_STMT_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001623 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001624 memset(&type, 0, sizeof(type));
1625
1626 /* min subelems */
1627 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001628 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1629 CHECK_LYSP_RESTR(type.range, "range-str", NULL,
1630 NULL, NULL, 0, NULL);
1631 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001632 memset(&type, 0, sizeof(type));
David Sedlák69f01612019-07-17 11:41:08 +02001633}
1634
1635static void
1636test_reqinstance_elem(void **state)
1637{
David Sedlák69f01612019-07-17 11:41:08 +02001638 const char *data;
1639 struct lysp_type type = {};
1640
David Sedlákd1144562019-08-06 12:36:14 +02001641 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001642 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001643 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001644 assert_true(type.flags & LYS_SET_REQINST);
Radek Krejci5984d222021-02-26 23:01:45 +01001645 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_REQUIRE_INSTANCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001646 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001647 memset(&type, 0, sizeof(type));
1648
1649 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001650 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001651 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001652 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001653 memset(&type, 0, sizeof(type));
1654
1655 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001656 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001657 memset(&type, 0, sizeof(type));
Radek Iša56ca9e42020-09-08 18:42:00 +02001658 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. "
1659 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001660}
1661
1662static void
1663test_revision_date_elem(void **state)
1664{
David Sedlák69f01612019-07-17 11:41:08 +02001665 const char *data;
1666 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001667 struct lysp_ext_instance *exts = NULL;
1668
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001669 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM "</revision-date>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001670 assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001671 assert_string_equal(rev, "2000-01-01");
Radek Krejci5984d222021-02-26 23:01:45 +01001672 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REVISION_DATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001673 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001674
1675 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001676 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001677 assert_string_equal(rev, "2000-01-01");
1678
1679 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001680 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID);
1681 CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001682}
1683
1684static void
1685test_unique_elem(void **state)
1686{
David Sedlák69f01612019-07-17 11:41:08 +02001687 const char *data;
1688 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001689 struct lysp_ext_instance *exts = NULL;
1690
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001691 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001692 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001693 assert_string_equal(*values, "tag");
Radek Krejci5984d222021-02-26 23:01:45 +01001694 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNIQUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001695 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001696 lydict_remove(UTEST_LYCTX, *values);
David Sedlákd1144562019-08-06 12:36:14 +02001697 LY_ARRAY_FREE(values);
1698 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001699
1700 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001701 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001702 assert_string_equal(*values, "tag");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001703 lydict_remove(UTEST_LYCTX, *values);
David Sedlák69f01612019-07-17 11:41:08 +02001704 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001705 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001706}
1707
1708static void
1709test_units_elem(void **state)
1710{
David Sedlák69f01612019-07-17 11:41:08 +02001711 const char *data;
1712 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001713 struct lysp_ext_instance *exts = NULL;
1714
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001715 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001716 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001717 assert_string_equal(values, "name");
Radek Krejci5984d222021-02-26 23:01:45 +01001718 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001719 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001720 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001721 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001722
1723 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001724 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001725 assert_string_equal(values, "name");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001726 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001727 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001728}
1729
1730static void
1731test_when_elem(void **state)
1732{
David Sedlák69f01612019-07-17 11:41:08 +02001733 const char *data;
1734 struct lysp_when *when = NULL;
1735
1736 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001737 "<when condition=\"cond\">\n"
1738 " <description><text>desc</text></description>\n"
1739 " <reference><text>ref</text></reference>\n"
1740 EXT_SUBELEM
1741 "</when>"
1742 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001743 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1744 CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001745 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]), LY_STMT_WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001746 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001747 free(when);
1748 when = NULL;
1749
1750 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001751 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1752 CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL);
1753 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001754 free(when);
1755 when = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001756}
1757
1758static void
1759test_yin_text_value_elem(void **state)
1760{
David Sedlák69f01612019-07-17 11:41:08 +02001761 const char *data;
1762 const char *val;
1763
1764 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001765 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001766 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001767 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001768
1769 data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001770 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001771 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001772 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001773
1774 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001775 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001776 assert_string_equal("", val);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001777 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001778}
David Sedlák32488102019-07-15 17:44:10 +02001779
David Sedlák374d2b32019-07-17 15:06:55 +02001780static void
1781test_type_elem(void **state)
1782{
David Sedlák374d2b32019-07-17 15:06:55 +02001783 const char *data;
1784 struct lysp_type type = {};
1785
1786 /* max subelems */
1787 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001788 "<type name=\"type-name\">\n"
1789 " <base name=\"base-name\"/>\n"
1790 " <bit name=\"bit\"/>\n"
1791 " <enum name=\"enum\"/>\n"
1792 " <fraction-digits value=\"2\"/>\n"
1793 " <length value=\"length\"/>\n"
1794 " <path value=\"/path\"/>\n"
1795 " <pattern value=\"pattern\"/>\n"
1796 " <range value=\"range\" />\n"
1797 " <require-instance value=\"true\"/>\n"
1798 " <type name=\"sub-type-name\"/>\n"
1799 EXT_SUBELEM
1800 "</type>"
1801 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001802 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02001803 assert_string_equal(type.name, "type-name");
1804 assert_string_equal(*type.bases, "base-name");
1805 assert_string_equal(type.bits->name, "bit");
1806 assert_string_equal(type.enums->name, "enum");
1807 assert_int_equal(type.fraction_digits, 2);
Radek Iša56ca9e42020-09-08 18:42:00 +02001808 CHECK_LYSP_RESTR(type.length, "length", NULL,
1809 NULL, NULL, 0, NULL);
Michal Vaskocb8c6d42020-10-16 11:58:30 +02001810 assert_string_equal(type.path->expr, "/path");
Radek Iša56ca9e42020-09-08 18:42:00 +02001811 CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL,
1812 NULL, NULL, 0, NULL);
1813 CHECK_LYSP_RESTR(type.range, "range", NULL,
1814 NULL, NULL, 0, NULL);
David Sedlák374d2b32019-07-17 15:06:55 +02001815 assert_int_equal(type.require_instance, 1);
1816 assert_string_equal(type.types->name, "sub-type-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001817 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_TYPE);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001818 assert_true(type.flags & LYS_SET_BASE);
1819 assert_true(type.flags & LYS_SET_BIT);
1820 assert_true(type.flags & LYS_SET_ENUM);
1821 assert_true(type.flags & LYS_SET_FRDIGITS);
1822 assert_true(type.flags & LYS_SET_LENGTH);
1823 assert_true(type.flags & LYS_SET_PATH);
1824 assert_true(type.flags & LYS_SET_PATTERN);
1825 assert_true(type.flags & LYS_SET_RANGE);
1826 assert_true(type.flags & LYS_SET_REQINST);
1827 assert_true(type.flags & LYS_SET_TYPE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001828 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001829 memset(&type, 0, sizeof(type));
1830
1831 /* min subelems */
1832 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001833 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1834 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001835 memset(&type, 0, sizeof(type));
David Sedlák374d2b32019-07-17 15:06:55 +02001836}
1837
David Sedlák1af868e2019-07-17 17:03:14 +02001838static void
1839test_max_elems_elem(void **state)
1840{
David Sedlák1af868e2019-07-17 17:03:14 +02001841 const char *data;
1842 struct lysp_node_list list = {};
1843 struct lysp_node_leaflist llist = {};
1844 struct lysp_refine refine = {};
1845
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001846 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM "</max-elements> </refine>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001847 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001848 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001849 assert_true(refine.flags & LYS_SET_MAX);
Radek Krejci5984d222021-02-26 23:01:45 +01001850 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001851 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001852
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001853 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM "</max-elements> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001854 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001855 assert_int_equal(list.max, 5);
Radek Iša56ca9e42020-09-08 18:42:00 +02001856 CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001857 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001858 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001859
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001860 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM "</max-elements> </leaf-list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001861 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001862 assert_int_equal(llist.max, 85);
Radek Iša56ca9e42020-09-08 18:42:00 +02001863 CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001864 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001865 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001866
1867 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001868 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001869 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001870 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001871
1872 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001873 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1874 CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001875
1876 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001877 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1878 CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001879
1880 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001881 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1882 CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001883
1884 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001885 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1886 CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001887}
1888
David Sedlák09e18c92019-07-18 11:17:11 +02001889static void
1890test_min_elems_elem(void **state)
1891{
David Sedlák09e18c92019-07-18 11:17:11 +02001892 const char *data;
1893 struct lysp_node_list list = {};
1894 struct lysp_node_leaflist llist = {};
1895 struct lysp_refine refine = {};
1896
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001897 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM "</min-elements> </refine>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001898 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001899 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001900 assert_true(refine.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001901 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001902 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001903
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001904 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM "</min-elements> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001905 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001906 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001907 assert_true(list.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001908 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001909 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001910
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001911 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM "</min-elements> </leaf-list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001912 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001913 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001914 assert_true(llist.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001915 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001916 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001917
1918 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001919 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1920 CHECK_LOG_CTX("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001921
1922 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001923 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1924 CHECK_LOG_CTX("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001925
1926 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001927 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1928 CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001929
1930 data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001931 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1932 CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001933}
1934
David Sedláka2dad212019-07-18 12:45:19 +02001935static void
1936test_ordby_elem(void **state)
1937{
David Sedláka2dad212019-07-18 12:45:19 +02001938 const char *data;
1939 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001940 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02001941
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001942 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001943 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001944 assert_true(flags & LYS_ORDBY_SYSTEM);
Radek Krejci5984d222021-02-26 23:01:45 +01001945 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORDERED_BY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001946 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02001947
1948 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001949 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001950 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001951
1952 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001953 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1954 CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. "
1955 "Valid values are \"system\" and \"user\".", "Line number 1.");
David Sedláka2dad212019-07-18 12:45:19 +02001956}
1957
David Sedlák8a83bbb2019-07-18 14:46:00 +02001958static void
1959test_any_elem(void **state)
1960{
David Sedlák8a83bbb2019-07-18 14:46:00 +02001961 const char *data;
1962 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02001963 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02001964 struct lysp_node_anydata *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02001965 uint16_t flags;
David Sedlák8a83bbb2019-07-18 14:46:00 +02001966
1967 /* anyxml max subelems */
1968 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001969 "<anyxml name=\"any-name\">\n"
1970 " <config value=\"true\" />\n"
1971 " <description><text>desc</text></description>\n"
1972 " <if-feature name=\"feature\" />\n"
1973 " <mandatory value=\"true\" />\n"
1974 " <must condition=\"must-cond\" />\n"
1975 " <reference><text>ref</text></reference>\n"
1976 " <status value=\"deprecated\"/>\n"
1977 " <when condition=\"when-cond\"/>\n"
1978 EXT_SUBELEM
1979 "</anyxml>"
1980 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001981 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001982 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02001983 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
1984 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
1985 "any-name", 0, LYS_ANYXML, 0, "ref", 1);
1986 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001987 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001988 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYXML);
Radek Iša56ca9e42020-09-08 18:42:00 +02001989 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001990 siblings = NULL;
1991
1992 /* anydata max subelems */
1993 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001994 "<anydata name=\"any-name\">\n"
1995 " <config value=\"true\" />\n"
1996 " <description><text>desc</text></description>\n"
1997 " <if-feature name=\"feature\" />\n"
1998 " <mandatory value=\"true\" />\n"
1999 " <must condition=\"must-cond\" />\n"
2000 " <reference><text>ref</text></reference>\n"
2001 " <status value=\"deprecated\"/>\n"
2002 " <when condition=\"when-cond\"/>\n"
2003 EXT_SUBELEM
2004 "</anydata>"
2005 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002006 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002007 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002008 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2009 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2010 "any-name", 0, LYS_ANYDATA, 0, "ref", 1);
2011 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002012 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002013 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYDATA);
Radek Iša56ca9e42020-09-08 18:42:00 +02002014 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002015 siblings = NULL;
2016
2017 /* min subelems */
2018 node_meta.parent = (void *)0x10;
2019 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002020 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002021 parsed = (struct lysp_node_anydata *)siblings;
2022 assert_ptr_equal(parsed->parent, node_meta.parent);
Radek Iša56ca9e42020-09-08 18:42:00 +02002023 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2024 "any-name", 0, LYS_ANYDATA, 1, NULL, 0);
2025 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002026}
2027
David Sedlák203ca3a2019-07-18 15:26:25 +02002028static void
2029test_leaf_elem(void **state)
2030{
David Sedlák203ca3a2019-07-18 15:26:25 +02002031 const char *data;
2032 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002033 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002034 struct lysp_node_leaf *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002035 uint16_t flags;
David Sedlák203ca3a2019-07-18 15:26:25 +02002036
2037 /* max elements */
2038 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002039 "<leaf name=\"leaf\">\n"
2040 " <config value=\"true\" />\n"
2041 " <default value=\"def-val\"/>\n"
2042 " <description><text>desc</text></description>\n"
2043 " <if-feature name=\"feature\" />\n"
2044 " <mandatory value=\"true\" />\n"
2045 " <must condition=\"must-cond\" />\n"
2046 " <reference><text>ref</text></reference>\n"
2047 " <status value=\"deprecated\"/>\n"
2048 " <type name=\"type\"/>\n"
2049 " <units name=\"uni\"/>\n"
2050 " <when condition=\"when-cond\"/>\n"
2051 EXT_SUBELEM
2052 "</leaf>"
David Sedlák203ca3a2019-07-18 15:26:25 +02002053 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002054 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002055 parsed = (struct lysp_node_leaf *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002056 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2057 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2058 "leaf", 0, LYS_LEAF, 0, "ref", 1);
2059 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002060 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002061 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002062 assert_string_equal(parsed->musts->arg.str, "must-cond");
David Sedlák203ca3a2019-07-18 15:26:25 +02002063 assert_string_equal(parsed->type.name, "type");
2064 assert_string_equal(parsed->units, "uni");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002065 assert_string_equal(parsed->dflt.str, "def-val");
Radek Iša56ca9e42020-09-08 18:42:00 +02002066 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002067 siblings = NULL;
2068
2069 /* min elements */
2070 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002071 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002072 parsed = (struct lysp_node_leaf *)siblings;
2073 assert_string_equal(parsed->name, "leaf");
2074 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002075 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002076 siblings = NULL;
David Sedlák203ca3a2019-07-18 15:26:25 +02002077}
2078
David Sedlákc3da3ef2019-07-19 12:56:08 +02002079static void
2080test_leaf_list_elem(void **state)
2081{
David Sedlákc3da3ef2019-07-19 12:56:08 +02002082 const char *data;
2083 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002084 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002085 struct lysp_node_leaflist *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002086 uint16_t flags;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002087
2088 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002089 "<leaf-list name=\"llist\">\n"
2090 " <config value=\"true\" />\n"
2091 " <default value=\"def-val0\"/>\n"
2092 " <default value=\"def-val1\"/>\n"
2093 " <description><text>desc</text></description>\n"
2094 " <if-feature name=\"feature\"/>\n"
2095 " <max-elements value=\"5\"/>\n"
2096 " <must condition=\"must-cond\"/>\n"
2097 " <ordered-by value=\"user\" />\n"
2098 " <reference><text>ref</text></reference>\n"
2099 " <status value=\"current\"/>\n"
2100 " <type name=\"type\"/>\n"
2101 " <units name=\"uni\"/>\n"
2102 " <when condition=\"when-cond\"/>\n"
2103 EXT_SUBELEM
2104 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002105 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002106 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002107 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002108 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX;
2109 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2110 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2111 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002112 assert_string_equal(parsed->dflts[0].str, "def-val0");
2113 assert_string_equal(parsed->dflts[1].str, "def-val1");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002114 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002115 assert_int_equal(parsed->max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002116 assert_string_equal(parsed->type.name, "type");
2117 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002118 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002119 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002120 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002121 siblings = NULL;
2122
2123 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002124 "<leaf-list name=\"llist\">\n"
2125 " <config value=\"true\" />\n"
2126 " <description><text>desc</text></description>\n"
2127 " <if-feature name=\"feature\"/>\n"
2128 " <min-elements value=\"5\"/>\n"
2129 " <must condition=\"must-cond\"/>\n"
2130 " <ordered-by value=\"user\" />\n"
2131 " <reference><text>ref</text></reference>\n"
2132 " <status value=\"current\"/>\n"
2133 " <type name=\"type\"/>\n"
2134 " <units name=\"uni\"/>\n"
2135 " <when condition=\"when-cond\"/>\n"
2136 EXT_SUBELEM
2137 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002138 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002139 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002140 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002141 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN;
2142 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2143 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2144 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2145 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002146 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002147 assert_int_equal(parsed->min, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002148 assert_string_equal(parsed->type.name, "type");
2149 assert_string_equal(parsed->units, "uni");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002150 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002151 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002152 siblings = NULL;
2153
2154 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002155 "<leaf-list name=\"llist\">\n"
2156 " <config value=\"true\" />\n"
2157 " <description><text>desc</text></description>\n"
2158 " <if-feature name=\"feature\"/>\n"
2159 " <max-elements value=\"15\"/>\n"
2160 " <min-elements value=\"5\"/>\n"
2161 " <must condition=\"must-cond\"/>\n"
2162 " <ordered-by value=\"user\" />\n"
2163 " <reference><text>ref</text></reference>\n"
2164 " <status value=\"current\"/>\n"
2165 " <type name=\"type\"/>\n"
2166 " <units name=\"uni\"/>\n"
2167 " <when condition=\"when-cond\"/>\n"
2168 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002169 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002170 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002171 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002172 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX;
2173 CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1,
2174 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2175 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2176 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002177 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002178 assert_int_equal(parsed->min, 5);
2179 assert_int_equal(parsed->max, 15);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002180 assert_string_equal(parsed->type.name, "type");
2181 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002182 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002183 siblings = NULL;
2184
2185 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002186 "<leaf-list name=\"llist\">\n"
2187 " <type name=\"type\"/>\n"
2188 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002189 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002190 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002191 parsed = (struct lysp_node_leaflist *)siblings;
2192 assert_string_equal(parsed->name, "llist");
2193 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002194 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002195 siblings = NULL;
2196
2197 /* invalid combinations */
2198 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002199 "<leaf-list name=\"llist\">\n"
2200 " <max-elements value=\"5\"/>\n"
2201 " <min-elements value=\"15\"/>\n"
2202 " <type name=\"type\"/>"
2203 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002204 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002205 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2206 CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
2207 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002208 siblings = NULL;
2209
2210 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002211 "<leaf-list name=\"llist\">\n"
2212 " <default value=\"def-val1\"/>\n"
2213 " <min-elements value=\"15\"/>\n"
2214 " <type name=\"type\"/>\n"
2215 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002216 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002217 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2218 CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
2219 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002220 siblings = NULL;
2221
2222 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002223 "<leaf-list name=\"llist\">"
2224 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002225 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002226 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2227 CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
2228 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002229 siblings = NULL;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002230}
2231
David Sedlákcb39f642019-07-19 13:19:55 +02002232static void
2233test_presence_elem(void **state)
2234{
David Sedlákcb39f642019-07-19 13:19:55 +02002235 const char *data;
2236 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002237 struct lysp_ext_instance *exts = NULL;
2238
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002239 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002240 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002241 assert_string_equal(val, "presence-val");
Radek Krejci5984d222021-02-26 23:01:45 +01002242 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PRESENCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002243 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002244 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002245
2246 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002247 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002248 assert_string_equal(val, "presence-val");
Michal Vaskoe180ed02021-02-05 16:31:20 +01002249 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002250
2251 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002252 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2253 CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1.");
David Sedlákcb39f642019-07-19 13:19:55 +02002254}
2255
David Sedlák12470a82019-07-19 13:44:36 +02002256static void
2257test_key_elem(void **state)
2258{
David Sedlák12470a82019-07-19 13:44:36 +02002259 const char *data;
2260 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002261 struct lysp_ext_instance *exts = NULL;
2262
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002263 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002264 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002265 assert_string_equal(val, "key-value");
Radek Krejci5984d222021-02-26 23:01:45 +01002266 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_KEY);
Radek Iša56ca9e42020-09-08 18:42:00 +02002267 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002268 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002269
2270 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002271 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002272 assert_string_equal(val, "key-value");
Michal Vaskoe180ed02021-02-05 16:31:20 +01002273 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002274
2275 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002276 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2277 CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1.");
David Sedlák12470a82019-07-19 13:44:36 +02002278}
2279
David Sedlák04e17b22019-07-19 15:29:48 +02002280static void
2281test_typedef_elem(void **state)
2282{
David Sedlák04e17b22019-07-19 15:29:48 +02002283 const char *data;
2284 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002285 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002286
2287 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002288 "<typedef name=\"tpdf-name\">\n"
2289 " <default value=\"def-val\"/>\n"
2290 " <description><text>desc-text</text></description>\n"
2291 " <reference><text>ref-text</text></reference>\n"
2292 " <status value=\"current\"/>\n"
2293 " <type name=\"type\"/>\n"
2294 " <units name=\"uni\"/>\n"
2295 EXT_SUBELEM
2296 "</typedef>"
2297 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002298 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002299 assert_string_equal(tpdfs[0].dflt.str, "def-val");
David Sedlák04e17b22019-07-19 15:29:48 +02002300 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002301 assert_string_equal(tpdfs[0].name, "tpdf-name");
2302 assert_string_equal(tpdfs[0].ref, "ref-text");
2303 assert_string_equal(tpdfs[0].type.name, "type");
2304 assert_string_equal(tpdfs[0].units, "uni");
2305 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002306 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]), LY_STMT_TYPEDEF);
Radek Iša56ca9e42020-09-08 18:42:00 +02002307 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002308 tpdfs = NULL;
2309
2310 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002311 "<typedef name=\"tpdf-name\">\n"
2312 " <type name=\"type\"/>\n"
2313 "</typedef>"
2314 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002315 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002316 assert_string_equal(tpdfs[0].name, "tpdf-name");
2317 assert_string_equal(tpdfs[0].type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002318 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002319 tpdfs = NULL;
David Sedlák04e17b22019-07-19 15:29:48 +02002320}
2321
David Sedlákd2d676a2019-07-22 11:28:19 +02002322static void
2323test_refine_elem(void **state)
2324{
David Sedlákd2d676a2019-07-22 11:28:19 +02002325 const char *data;
2326 struct lysp_refine *refines = NULL;
2327
2328 /* max subelems */
2329 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002330 "<refine target-node=\"target\">\n"
2331 " <if-feature name=\"feature\" />\n"
2332 " <must condition=\"cond\" />\n"
2333 " <presence value=\"presence\" />\n"
2334 " <default value=\"def\" />\n"
2335 " <config value=\"true\" />\n"
2336 " <mandatory value=\"true\" />\n"
2337 " <min-elements value=\"10\" />\n"
2338 " <max-elements value=\"20\" />\n"
2339 " <description><text>desc</text></description>\n"
2340 " <reference><text>ref</text></reference>\n"
2341 EXT_SUBELEM
2342 "</refine>"
2343 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002344 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002345 assert_string_equal(refines->nodeid, "target");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002346 assert_string_equal(refines->dflts[0].str, "def");
David Sedlákd2d676a2019-07-22 11:28:19 +02002347 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002348 assert_true(refines->flags & LYS_CONFIG_W);
2349 assert_true(refines->flags & LYS_MAND_TRUE);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002350 assert_string_equal(refines->iffeatures[0].str, "feature");
David Sedlákd2d676a2019-07-22 11:28:19 +02002351 assert_int_equal(refines->max, 20);
2352 assert_int_equal(refines->min, 10);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002353 assert_string_equal(refines->musts->arg.str, "cond");
David Sedlákd2d676a2019-07-22 11:28:19 +02002354 assert_string_equal(refines->presence, "presence");
2355 assert_string_equal(refines->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002356 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]), LY_STMT_REFINE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002357 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002358 refines = NULL;
2359
2360 /* min subelems */
2361 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002362 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002363 assert_string_equal(refines->nodeid, "target");
Radek Iša56ca9e42020-09-08 18:42:00 +02002364 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002365 refines = NULL;
David Sedlákd2d676a2019-07-22 11:28:19 +02002366}
2367
David Sedlák0d6de5a2019-07-22 13:25:44 +02002368static void
2369test_uses_elem(void **state)
2370{
David Sedlák0d6de5a2019-07-22 13:25:44 +02002371 const char *data;
2372 struct lysp_node *siblings = NULL;
2373 struct tree_node_meta node_meta = {NULL, &siblings};
2374 struct lysp_node_uses *parsed = NULL;
2375
2376 /* max subelems */
2377 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002378 "<uses name=\"uses-name\">\n"
2379 " <when condition=\"cond\" />\n"
2380 " <if-feature name=\"feature\" />\n"
2381 " <status value=\"obsolete\" />\n"
2382 " <description><text>desc</text></description>\n"
2383 " <reference><text>ref</text></reference>\n"
2384 " <refine target-node=\"target\"/>\n"
2385 " <augment target-node=\"target\" />\n"
2386 EXT_SUBELEM
2387 "</uses>"
2388 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002389 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002390 parsed = (struct lysp_node_uses *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002391 CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1,
2392 "uses-name", 0, LYS_USES, 0, "ref", 1);
2393 CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002394 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002395 assert_string_equal(parsed->refines->nodeid, "target");
David Sedlák992fb7c2019-07-24 16:51:01 +02002396 assert_string_equal(parsed->augments->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002397 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_USES);
Radek Iša56ca9e42020-09-08 18:42:00 +02002398 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002399 siblings = NULL;
2400
2401 /* min subelems */
2402 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002403 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002404 assert_string_equal(siblings[0].name, "uses-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002405 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002406 siblings = NULL;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002407}
2408
David Sedlákaa854b02019-07-22 14:17:10 +02002409static void
2410test_revision_elem(void **state)
2411{
David Sedlákaa854b02019-07-22 14:17:10 +02002412 const char *data;
2413 struct lysp_revision *revs = NULL;
2414
2415 /* max subelems */
2416 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002417 "<revision date=\"2018-12-25\">\n"
2418 " <description><text>desc</text></description>\n"
2419 " <reference><text>ref</text></reference>\n"
2420 EXT_SUBELEM
2421 "</revision>"
2422 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002423 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002424 assert_string_equal(revs->date, "2018-12-25");
2425 assert_string_equal(revs->dsc, "desc");
2426 assert_string_equal(revs->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002427 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]), LY_STMT_REVISION);
Radek Iša56ca9e42020-09-08 18:42:00 +02002428 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002429 revs = NULL;
2430
2431 /* min subelems */
2432 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002433 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002434 assert_string_equal(revs->date, "2005-05-05");
Radek Iša56ca9e42020-09-08 18:42:00 +02002435 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002436 revs = NULL;
2437
2438 /* invalid value */
2439 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002440 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID);
2441 CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1.");
2442 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002443 revs = NULL;
David Sedlákaa854b02019-07-22 14:17:10 +02002444}
2445
David Sedlák0c2bab92019-07-22 15:33:19 +02002446static void
2447test_include_elem(void **state)
2448{
David Sedlák0c2bab92019-07-22 15:33:19 +02002449 const char *data;
2450 struct lysp_include *includes = NULL;
2451 struct include_meta inc_meta = {"module-name", &includes};
2452
2453 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002454 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák0c2bab92019-07-22 15:33:19 +02002455 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002456 "<include module=\"mod\">\n"
2457 " <description><text>desc</text></description>\n"
2458 " <reference><text>ref</text></reference>\n"
2459 " <revision-date date=\"1999-09-09\"/>\n"
2460 EXT_SUBELEM
2461 "</include>"
2462 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002463 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002464 assert_string_equal(includes->name, "mod");
2465 assert_string_equal(includes->dsc, "desc");
2466 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002467 assert_string_equal(includes->rev, "1999-09-09");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002468 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]), LY_STMT_INCLUDE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002469 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002470 includes = NULL;
2471
2472 /* min subelems */
2473 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002474 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002475 assert_string_equal(includes->name, "mod");
Radek Iša56ca9e42020-09-08 18:42:00 +02002476 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002477 includes = NULL;
2478
2479 /* invalid combinations */
Radek Iša56ca9e42020-09-08 18:42:00 +02002480 YCTX->parsed_mod->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002481 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002482 "<include module=\"mod\">\n"
2483 " <description><text>desc</text></description>\n"
2484 " <revision-date date=\"1999-09-09\"/>\n"
2485 "</include>"
2486 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002487 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2488 CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2489 "Line number 2.");
2490 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002491 includes = NULL;
2492
Radek Iša56ca9e42020-09-08 18:42:00 +02002493 YCTX->parsed_mod->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002494 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002495 "<include module=\"mod\">\n"
2496 " <reference><text>ref</text></reference>\n"
2497 " <revision-date date=\"1999-09-09\"/>\n"
2498 "</include>"
2499 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002500 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2501 CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2502 "Line number 2.");
2503 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002504 includes = NULL;
David Sedlák0c2bab92019-07-22 15:33:19 +02002505}
2506
David Sedlák5e13dea2019-07-22 16:06:45 +02002507static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002508test_list_elem(void **state)
2509{
David Sedlákaf536aa2019-07-23 13:42:23 +02002510 const char *data;
2511 struct lysp_node *siblings = NULL;
2512 struct tree_node_meta node_meta = {NULL, &siblings};
2513 struct lysp_node_list *parsed = NULL;
2514
2515 /* max subelems */
2516 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002517 "<list name=\"list-name\">\n"
2518 " <when condition=\"when\"/>\n"
2519 " <if-feature name=\"iff\"/>\n"
2520 " <must condition=\"must-cond\"/>\n"
2521 " <key value=\"key\"/>\n"
2522 " <unique tag=\"utag\"/>\n"
2523 " <config value=\"true\"/>\n"
2524 " <min-elements value=\"10\"/>\n"
2525 " <ordered-by value=\"user\"/>\n"
2526 " <status value=\"deprecated\"/>\n"
2527 " <description><text>desc</text></description>\n"
2528 " <reference><text>ref</text></reference>\n"
2529 " <anydata name=\"anyd\"/>\n"
2530 " <anyxml name=\"anyx\"/>\n"
2531 " <container name=\"cont\"/>\n"
2532 " <choice name=\"choice\"/>\n"
2533 " <action name=\"action\"/>\n"
2534 " <grouping name=\"grp\"/>\n"
2535 " <notification name=\"notf\"/>\n"
2536 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2537 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2538 " <list name=\"sub-list\"/>\n"
2539 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2540 " <uses name=\"uses-name\"/>\n"
2541 EXT_SUBELEM
2542 "</list>"
2543 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002544 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002545 parsed = (struct lysp_node_list *)&siblings[0];
David Sedlákaf536aa2019-07-23 13:42:23 +02002546 assert_string_equal(parsed->child->name, "anyd");
2547 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2548 assert_string_equal(parsed->child->next->name, "anyx");
2549 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002550 assert_string_equal(parsed->child->next->next->name, "cont");
2551 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002552 assert_string_equal(parsed->child->next->next->next->name, "choice");
2553 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002554 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2555 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2556 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2557 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2558 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2559 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2560 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2561 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2562 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Iša56ca9e42020-09-08 18:42:00 +02002563 uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN;
2564
2565 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2566 "list-name", 0, LYS_LIST, 0, "ref", 1);
2567 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2568 CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002569 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002570 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002571 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002572 assert_string_equal(parsed->notifs->name, "notf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002573 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákaf536aa2019-07-23 13:42:23 +02002574 assert_string_equal(parsed->key, "key");
2575 assert_int_equal(parsed->min, 10);
David Sedlákaf536aa2019-07-23 13:42:23 +02002576 assert_string_equal(parsed->typedefs->name, "tpdf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002577 assert_string_equal(parsed->uniques->str, "utag");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002578 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002579 lysp_node_free(UTEST_LYCTX, siblings);
2580 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedlákaf536aa2019-07-23 13:42:23 +02002581 siblings = NULL;
2582
2583 /* min subelems */
2584 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002585 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002586 parsed = (struct lysp_node_list *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002587 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2588 "list-name", 0, LYS_LIST, 0, NULL, 0);
2589 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákaf536aa2019-07-23 13:42:23 +02002590 siblings = NULL;
David Sedlákaf536aa2019-07-23 13:42:23 +02002591}
2592
David Sedlák031b9e72019-07-23 15:19:37 +02002593static void
2594test_notification_elem(void **state)
2595{
David Sedlák031b9e72019-07-23 15:19:37 +02002596 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002597 struct lysp_node_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002598 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002599
2600 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002601 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák031b9e72019-07-23 15:19:37 +02002602 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002603 "<notification name=\"notif-name\">\n"
2604 " <anydata name=\"anyd\"/>\n"
2605 " <anyxml name=\"anyx\"/>\n"
2606 " <description><text>desc</text></description>\n"
2607 " <if-feature name=\"iff\"/>\n"
2608 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2609 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2610 " <list name=\"sub-list\"/>\n"
2611 " <must condition=\"cond\"/>\n"
2612 " <reference><text>ref</text></reference>\n"
2613 " <status value=\"deprecated\"/>\n"
2614 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2615 " <uses name=\"uses-name\"/>\n"
2616 " <container name=\"cont\"/>\n"
2617 " <choice name=\"choice\"/>\n"
2618 " <grouping name=\"grp\"/>\n"
2619 EXT_SUBELEM
2620 "</notification>"
2621 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002622 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002623 assert_string_equal(notifs->name, "notif-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002624 assert_string_equal(notifs->child->name, "anyd");
2625 assert_int_equal(notifs->child->nodetype, LYS_ANYDATA);
2626 assert_string_equal(notifs->child->next->name, "anyx");
2627 assert_int_equal(notifs->child->next->nodetype, LYS_ANYXML);
2628 assert_string_equal(notifs->child->next->next->name, "leaf");
2629 assert_int_equal(notifs->child->next->next->nodetype, LYS_LEAF);
2630 assert_string_equal(notifs->child->next->next->next->name, "llist");
2631 assert_int_equal(notifs->child->next->next->next->nodetype, LYS_LEAFLIST);
2632 assert_string_equal(notifs->child->next->next->next->next->name, "sub-list");
2633 assert_int_equal(notifs->child->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02002634 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002635 assert_string_equal(notifs->groupings->name, "grp");
2636 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
Radek Krejci01180ac2021-01-27 08:48:22 +01002637 assert_string_equal(notifs->child->next->next->next->next->next->name, "uses-name");
2638 assert_int_equal(notifs->child->next->next->next->next->next->nodetype, LYS_USES);
2639 assert_string_equal(notifs->child->next->next->next->next->next->next->name, "cont");
2640 assert_int_equal(notifs->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2641 assert_int_equal(notifs->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2642 assert_string_equal(notifs->child->next->next->next->next->next->next->next->name, "choice");
2643 assert_null(notifs->child->next->next->next->next->next->next->next->next);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002644 assert_string_equal(notifs->iffeatures[0].str, "iff");
2645 assert_string_equal(notifs->musts->arg.str, "cond");
David Sedlák031b9e72019-07-23 15:19:37 +02002646 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2647 assert_null(notifs->parent);
2648 assert_string_equal(notifs->ref, "ref");
2649 assert_string_equal(notifs->typedefs->name, "tpdf");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002650 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LY_STMT_NOTIFICATION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002651 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedlák031b9e72019-07-23 15:19:37 +02002652 notifs = NULL;
2653
2654 /* min subelems */
2655 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002656 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002657 assert_string_equal(notifs->name, "notif-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002658 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002659 notifs = NULL;
David Sedláke3ce9ef2019-07-23 16:34:30 +02002660}
2661
2662static void
2663test_grouping_elem(void **state)
2664{
David Sedláke3ce9ef2019-07-23 16:34:30 +02002665 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002666 struct lysp_node_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002667 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02002668
2669 /* max subelems */
2670 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002671 "<grouping name=\"grp-name\">\n"
2672 " <anydata name=\"anyd\"/>\n"
2673 " <anyxml name=\"anyx\"/>\n"
2674 " <description><text>desc</text></description>\n"
2675 " <grouping name=\"sub-grp\"/>\n"
2676 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2677 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2678 " <list name=\"list\"/>\n"
2679 " <notification name=\"notf\"/>\n"
2680 " <reference><text>ref</text></reference>\n"
2681 " <status value=\"current\"/>\n"
2682 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2683 " <uses name=\"uses-name\"/>\n"
2684 " <action name=\"act\"/>\n"
2685 " <container name=\"cont\"/>\n"
2686 " <choice name=\"choice\"/>\n"
2687 EXT_SUBELEM
2688 "</grouping>"
2689 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002690 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002691 assert_string_equal(grps->name, "grp-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002692 assert_string_equal(grps->child->name, "anyd");
2693 assert_string_equal(grps->child->next->name, "anyx");
2694 assert_string_equal(grps->child->next->next->name, "leaf");
2695 assert_string_equal(grps->child->next->next->next->name, "llist");
2696 assert_string_equal(grps->child->next->next->next->next->name, "list");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002697 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002698 assert_true(grps->flags & LYS_STATUS_CURR);
2699 assert_string_equal(grps->groupings->name, "sub-grp");
2700 assert_int_equal(grps->nodetype, LYS_GROUPING);
2701 assert_string_equal(grps->notifs->name, "notf");
2702 assert_null(grps->parent);
2703 assert_string_equal(grps->ref, "ref");
2704 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002705 assert_string_equal(grps->actions->name, "act");
Radek Krejci01180ac2021-01-27 08:48:22 +01002706 assert_string_equal(grps->child->next->next->next->next->next->name, "uses-name");
2707 assert_int_equal(grps->child->next->next->next->next->next->nodetype, LYS_USES);
2708 assert_string_equal(grps->child->next->next->next->next->next->next->name, "cont");
2709 assert_int_equal(grps->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2710 assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice");
2711 assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002712 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LY_STMT_GROUPING);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002713 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002714 grps = NULL;
2715
2716 /* min subelems */
2717 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002718 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002719 assert_string_equal(grps->name, "grp-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002720 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002721 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002722}
2723
David Sedlákf111bcb2019-07-23 17:15:51 +02002724static void
2725test_container_elem(void **state)
2726{
David Sedlákf111bcb2019-07-23 17:15:51 +02002727 const char *data;
2728 struct lysp_node *siblings = NULL;
2729 struct tree_node_meta node_meta = {NULL, &siblings};
2730 struct lysp_node_container *parsed = NULL;
2731
2732 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002733 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedláke2dc9e92019-07-24 09:59:21 +02002734 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002735 "<container name=\"cont-name\">\n"
2736 " <anydata name=\"anyd\"/>\n"
2737 " <anyxml name=\"anyx\"/>\n"
2738 " <config value=\"true\"/>\n"
2739 " <container name=\"subcont\"/>\n"
2740 " <description><text>desc</text></description>\n"
2741 " <grouping name=\"sub-grp\"/>\n"
2742 " <if-feature name=\"iff\"/>\n"
2743 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2744 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2745 " <list name=\"list\"/>\n"
2746 " <must condition=\"cond\"/>\n"
2747 " <notification name=\"notf\"/>\n"
2748 " <presence value=\"presence\"/>\n"
2749 " <reference><text>ref</text></reference>\n"
2750 " <status value=\"current\"/>\n"
2751 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2752 " <uses name=\"uses-name\"/>\n"
2753 " <when condition=\"when-cond\"/>\n"
2754 " <action name=\"act\"/>\n"
2755 " <choice name=\"choice\"/>\n"
2756 EXT_SUBELEM
2757 "</container>"
2758 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002759 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02002760 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002761 uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR;
2762
2763 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2764 "cont-name", 0, LYS_CONTAINER, 0, "ref", 1);
2765 CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL);
2766 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
2767
Michal Vasko7f45cf22020-10-01 12:49:44 +02002768 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02002769 assert_string_equal(parsed->presence, "presence");
2770 assert_string_equal(parsed->typedefs->name, "tpdf");
2771 assert_string_equal(parsed->groupings->name, "sub-grp");
2772 assert_string_equal(parsed->child->name, "anyd");
2773 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2774 assert_string_equal(parsed->child->next->name, "anyx");
2775 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2776 assert_string_equal(parsed->child->next->next->name, "subcont");
2777 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2778 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2779 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2780 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2781 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2782 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2783 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2784 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2785 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002786 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2787 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2788 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02002789 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002790 assert_string_equal(parsed->actions->name, "act");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002791 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CONTAINER);
Radek Iša56ca9e42020-09-08 18:42:00 +02002792 lysp_node_free(UTEST_LYCTX, siblings);
2793 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedláke2dc9e92019-07-24 09:59:21 +02002794 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002795
2796 /* min subelems */
2797 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002798 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02002799 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002800 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2801 "cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
2802 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákf111bcb2019-07-23 17:15:51 +02002803 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002804}
2805
David Sedlák5379d392019-07-24 10:42:03 +02002806static void
2807test_case_elem(void **state)
2808{
David Sedlák5379d392019-07-24 10:42:03 +02002809 const char *data;
2810 struct lysp_node *siblings = NULL;
2811 struct tree_node_meta node_meta = {NULL, &siblings};
2812 struct lysp_node_case *parsed = NULL;
2813
2814 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002815 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák5379d392019-07-24 10:42:03 +02002816 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002817 "<case name=\"case-name\">\n"
2818 " <anydata name=\"anyd\"/>\n"
2819 " <anyxml name=\"anyx\"/>\n"
2820 " <container name=\"subcont\"/>\n"
2821 " <description><text>desc</text></description>\n"
2822 " <if-feature name=\"iff\"/>\n"
2823 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2824 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2825 " <list name=\"list\"/>\n"
2826 " <reference><text>ref</text></reference>\n"
2827 " <status value=\"current\"/>\n"
2828 " <uses name=\"uses-name\"/>\n"
2829 " <when condition=\"when-cond\"/>\n"
2830 " <choice name=\"choice\"/>\n"
2831 EXT_SUBELEM
2832 "</case>"
2833 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002834 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002835 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002836 uint16_t flags = LYS_STATUS_CURR;
2837
2838 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2839 "case-name", 0, LYS_CASE, 0, "ref", 1);
2840 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002841 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02002842 assert_string_equal(parsed->child->name, "anyd");
2843 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2844 assert_string_equal(parsed->child->next->name, "anyx");
2845 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2846 assert_string_equal(parsed->child->next->next->name, "subcont");
2847 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2848 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2849 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2850 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2851 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2852 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2853 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2854 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2855 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002856 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2857 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2858 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002859 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002860 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002861 siblings = NULL;
2862
2863 /* min subelems */
2864 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002865 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002866 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002867 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2868 "case-name", 0, LYS_CASE, 0, NULL, 0);
2869 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002870 siblings = NULL;
David Sedlák5379d392019-07-24 10:42:03 +02002871}
2872
David Sedlákb7abcfa2019-07-24 12:33:35 +02002873static void
2874test_choice_elem(void **state)
2875{
David Sedlákb7abcfa2019-07-24 12:33:35 +02002876 const char *data;
2877 struct lysp_node *siblings = NULL;
2878 struct tree_node_meta node_meta = {NULL, &siblings};
2879 struct lysp_node_choice *parsed = NULL;
2880
2881 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002882 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002883 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002884 "<choice name=\"choice-name\">\n"
2885 " <anydata name=\"anyd\"/>\n"
2886 " <anyxml name=\"anyx\"/>\n"
2887 " <case name=\"sub-case\"/>\n"
2888 " <choice name=\"choice\"/>\n"
2889 " <config value=\"true\"/>\n"
2890 " <container name=\"subcont\"/>\n"
2891 " <default value=\"def\"/>\n"
2892 " <description><text>desc</text></description>\n"
2893 " <if-feature name=\"iff\"/>\n"
2894 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2895 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2896 " <list name=\"list\"/>\n"
2897 " <mandatory value=\"true\" />\n"
2898 " <reference><text>ref</text></reference>\n"
2899 " <status value=\"current\"/>\n"
2900 " <when condition=\"when-cond\"/>\n"
2901 EXT_SUBELEM
2902 "</choice>"
2903 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002904 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002905 parsed = (struct lysp_node_choice *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002906 uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR;
2907
2908 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2909 "choice-name", 0, LYS_CHOICE, 0, "ref", 1);
2910 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002911 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002912 assert_string_equal(parsed->child->name, "anyd");
2913 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2914 assert_string_equal(parsed->child->next->name, "anyx");
2915 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2916 assert_string_equal(parsed->child->next->next->name, "sub-case");
2917 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
2918 assert_string_equal(parsed->child->next->next->next->name, "choice");
2919 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2920 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
2921 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
2922 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
2923 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
2924 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
2925 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2926 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
2927 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
2928 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002929 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CHOICE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002930 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002931 siblings = NULL;
2932
2933 /* min subelems */
2934 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002935 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002936 parsed = (struct lysp_node_choice *)siblings;
2937 assert_string_equal(parsed->name, "choice-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002938 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2939 "choice-name", 0, LYS_CHOICE, 0, NULL, 0);
2940 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002941 siblings = NULL;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002942}
2943
David Sedlák05404f62019-07-24 14:11:53 +02002944static void
2945test_inout_elem(void **state)
2946{
David Sedlák05404f62019-07-24 14:11:53 +02002947 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002948 struct lysp_node_action_inout inout = {};
David Sedlák05404f62019-07-24 14:11:53 +02002949 struct inout_meta inout_meta = {NULL, &inout};
2950
2951 /* max subelements */
Radek Iša56ca9e42020-09-08 18:42:00 +02002952 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002953 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002954 "<input>\n"
2955 " <anydata name=\"anyd\"/>\n"
2956 " <anyxml name=\"anyx\"/>\n"
2957 " <choice name=\"choice\"/>\n"
2958 " <container name=\"subcont\"/>\n"
2959 " <grouping name=\"sub-grp\"/>\n"
2960 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2961 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2962 " <list name=\"list\"/>\n"
2963 " <must condition=\"cond\"/>\n"
2964 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2965 " <uses name=\"uses-name\"/>\n"
2966 EXT_SUBELEM
2967 "</input>"
2968 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002969 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
2970 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1);
2971 CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL);
David Sedlák05404f62019-07-24 14:11:53 +02002972 assert_string_equal(inout.typedefs->name, "tpdf");
2973 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01002974 assert_string_equal(inout.child->name, "anyd");
2975 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
2976 assert_string_equal(inout.child->next->name, "anyx");
2977 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
2978 assert_string_equal(inout.child->next->next->name, "choice");
2979 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
2980 assert_string_equal(inout.child->next->next->next->name, "subcont");
2981 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
2982 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
2983 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
2984 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
2985 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2986 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
2987 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
2988 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
2989 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2990 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002991 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_INPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002992 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02002993 memset(&inout, 0, sizeof inout);
2994
2995 /* max subelements */
Radek Iša56ca9e42020-09-08 18:42:00 +02002996 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002997 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002998 "<output>\n"
2999 " <anydata name=\"anyd\"/>\n"
3000 " <anyxml name=\"anyx\"/>\n"
3001 " <choice name=\"choice\"/>\n"
3002 " <container name=\"subcont\"/>\n"
3003 " <grouping name=\"sub-grp\"/>\n"
3004 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3005 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3006 " <list name=\"list\"/>\n"
3007 " <must condition=\"cond\"/>\n"
3008 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3009 " <uses name=\"uses-name\"/>\n"
3010 EXT_SUBELEM
3011 "</output>"
3012 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003013 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
3014 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1);
Michal Vasko7f45cf22020-10-01 12:49:44 +02003015 assert_string_equal(inout.musts->arg.str, "cond");
David Sedlák05404f62019-07-24 14:11:53 +02003016 assert_string_equal(inout.typedefs->name, "tpdf");
3017 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01003018 assert_string_equal(inout.child->name, "anyd");
3019 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
3020 assert_string_equal(inout.child->next->name, "anyx");
3021 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
3022 assert_string_equal(inout.child->next->next->name, "choice");
3023 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
3024 assert_string_equal(inout.child->next->next->next->name, "subcont");
3025 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
3026 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
3027 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
3028 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
3029 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3030 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
3031 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
3032 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
3033 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3034 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003035 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_OUTPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003036 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003037 memset(&inout, 0, sizeof inout);
3038
3039 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003040 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003041 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003042 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003043 memset(&inout, 0, sizeof inout);
3044
Michal Vaskob83af8a2020-01-06 09:49:22 +01003045 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003046 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003047 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003048 memset(&inout, 0, sizeof inout);
3049
3050 /* invalid combinations */
3051 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003052 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
Radek Krejci9a3823e2021-01-27 20:26:46 +01003053 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
Radek Iša56ca9e42020-09-08 18:42:00 +02003054 CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003055 memset(&inout, 0, sizeof inout);
David Sedlák05404f62019-07-24 14:11:53 +02003056}
3057
David Sedlák85d0eca2019-07-24 15:15:21 +02003058static void
3059test_action_elem(void **state)
3060{
David Sedlák85d0eca2019-07-24 15:15:21 +02003061 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003062 struct lysp_node_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003063 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
Radek Iša56ca9e42020-09-08 18:42:00 +02003064 uint16_t flags;
David Sedlák85d0eca2019-07-24 15:15:21 +02003065
3066 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003067 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák85d0eca2019-07-24 15:15:21 +02003068 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003069 "<action name=\"act\">\n"
3070 " <description><text>desc</text></description>\n"
3071 " <grouping name=\"grouping\"/>\n"
3072 " <if-feature name=\"iff\"/>\n"
3073 " <input><uses name=\"uses-name\"/></input>\n"
3074 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3075 " <reference><text>ref</text></reference>\n"
3076 " <status value=\"deprecated\"/>\n"
3077 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3078 EXT_SUBELEM
3079 "</action>"
3080 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003081 /* there must be parent for action */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003082 act_meta.parent = (void *)1;
Radek Iša56ca9e42020-09-08 18:42:00 +02003083 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003084 act_meta.parent = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003085 flags = LYS_STATUS_DEPRC;
3086 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3087 1, 0, 0, 0,\
3088 1, 0,\
3089 "act", LYS_ACTION, \
3090 1, 0, 0, 1,\
3091 1, 0,\
3092 1, "ref", 1);
3093
Michal Vasko7f45cf22020-10-01 12:49:44 +02003094 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlák85d0eca2019-07-24 15:15:21 +02003095 assert_string_equal(actions->typedefs->name, "tpdf");
3096 assert_string_equal(actions->groupings->name, "grouping");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003097 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci01180ac2021-01-27 08:48:22 +01003098 assert_string_equal(actions->input.child->name, "uses-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003099 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_ACTION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003100 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003101 actions = NULL;
3102
Radek Iša56ca9e42020-09-08 18:42:00 +02003103 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlákeaa45792019-07-24 15:25:01 +02003104 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003105 "<rpc name=\"act\">\n"
3106 " <description><text>desc</text></description>\n"
3107 " <grouping name=\"grouping\"/>\n"
3108 " <if-feature name=\"iff\"/>\n"
3109 " <input><uses name=\"uses-name\"/></input>\n"
3110 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3111 " <reference><text>ref</text></reference>\n"
3112 " <status value=\"deprecated\"/>\n"
3113 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3114 EXT_SUBELEM
3115 "</rpc>"
3116 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003117 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
3118 flags = LYS_STATUS_DEPRC;
3119 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3120 1, 0, 0, 0,\
3121 1, 0,\
3122 "act", LYS_RPC, \
3123 1, 0, 0, 1,\
3124 1, 0,\
3125 0, "ref", 1);
3126
Michal Vasko7f45cf22020-10-01 12:49:44 +02003127 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlákeaa45792019-07-24 15:25:01 +02003128 assert_string_equal(actions->typedefs->name, "tpdf");
3129 assert_string_equal(actions->groupings->name, "grouping");
Radek Krejci01180ac2021-01-27 08:48:22 +01003130 assert_string_equal(actions->input.child->name, "uses-name");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003131 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003132 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_RPC);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003133 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlákeaa45792019-07-24 15:25:01 +02003134 actions = NULL;
3135
David Sedlák85d0eca2019-07-24 15:15:21 +02003136 /* min subelems */
3137 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003138 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003139 assert_string_equal(actions->name, "act");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003140 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003141 actions = NULL;
David Sedlák85d0eca2019-07-24 15:15:21 +02003142}
3143
David Sedlák992fb7c2019-07-24 16:51:01 +02003144static void
3145test_augment_elem(void **state)
3146{
David Sedlák992fb7c2019-07-24 16:51:01 +02003147 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003148 struct lysp_node_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003149 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003150
Radek Iša56ca9e42020-09-08 18:42:00 +02003151 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák992fb7c2019-07-24 16:51:01 +02003152 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003153 "<augment target-node=\"target\">\n"
3154 " <action name=\"action\"/>\n"
3155 " <anydata name=\"anyd\"/>\n"
3156 " <anyxml name=\"anyx\"/>\n"
3157 " <case name=\"case\"/>\n"
3158 " <choice name=\"choice\"/>\n"
3159 " <container name=\"subcont\"/>\n"
3160 " <description><text>desc</text></description>\n"
3161 " <if-feature name=\"iff\"/>\n"
3162 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3163 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3164 " <list name=\"list\"/>\n"
3165 " <notification name=\"notif\"/>\n"
3166 " <reference><text>ref</text></reference>\n"
3167 " <status value=\"current\"/>\n"
3168 " <uses name=\"uses\"/>\n"
3169 " <when condition=\"when-cond\"/>\n"
3170 EXT_SUBELEM
3171 "</augment>"
3172 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003173 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003174 assert_string_equal(augments->nodeid, "target");
3175 assert_null(augments->parent);
3176 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3177 assert_true(augments->flags & LYS_STATUS_CURR);
3178 assert_string_equal(augments->dsc, "desc");
3179 assert_string_equal(augments->ref, "ref");
3180 assert_string_equal(augments->when->cond, "when-cond");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003181 assert_string_equal(augments->iffeatures[0].str, "iff");
David Sedlák992fb7c2019-07-24 16:51:01 +02003182 assert_string_equal(augments->child->name, "anyd");
3183 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3184 assert_string_equal(augments->child->next->name, "anyx");
3185 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3186 assert_string_equal(augments->child->next->next->name, "case");
3187 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3188 assert_string_equal(augments->child->next->next->next->name, "choice");
3189 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3190 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3191 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3192 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3193 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3194 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3195 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3196 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3197 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3198 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3199 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3200 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3201 assert_string_equal(augments->actions->name, "action");
3202 assert_string_equal(augments->notifs->name, "notif");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003203 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003204 lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003205 augments = NULL;
3206
3207 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003208 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003209 assert_string_equal(augments->nodeid, "target");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003210 lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003211 augments = NULL;
David Sedlák992fb7c2019-07-24 16:51:01 +02003212}
3213
David Sedlák4ffcec82019-07-25 15:10:21 +02003214static void
3215test_deviate_elem(void **state)
3216{
David Sedlák4ffcec82019-07-25 15:10:21 +02003217 const char *data;
3218 struct lysp_deviate *deviates = NULL;
3219 struct lysp_deviate_add *d_add;
3220 struct lysp_deviate_rpl *d_rpl;
3221 struct lysp_deviate_del *d_del;
3222
3223 /* all valid arguments with min subelems */
3224 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003225 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003226 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003227 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003228 free(deviates);
3229 deviates = NULL;
3230
3231 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003232 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003233 assert_int_equal(deviates->mod, LYS_DEV_ADD);
Radek Iša56ca9e42020-09-08 18:42:00 +02003234 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003235 free(deviates);
3236 deviates = NULL;
3237
3238 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003239 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003240 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003241 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003242 free(deviates);
3243 deviates = NULL;
3244
3245 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003246 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003247 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003248 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003249 free(deviates);
3250 deviates = NULL;
3251
3252 /* max subelems and valid arguments */
3253 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003254 "<deviate value=\"not-supported\">"
3255 EXT_SUBELEM
3256 "</deviate>"
3257 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003258 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003259 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003260 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003261 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003262 free(deviates);
3263 deviates = NULL;
3264
3265 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003266 "<deviate value=\"add\">\n"
3267 " <units name=\"units\"/>\n"
3268 " <must condition=\"cond\"/>\n"
3269 " <unique tag=\"utag\"/>\n"
3270 " <default value=\"def\"/>\n"
3271 " <config value=\"true\"/>\n"
3272 " <mandatory value=\"true\"/>\n"
3273 " <min-elements value=\"5\"/>\n"
3274 " <max-elements value=\"15\"/>\n"
3275 EXT_SUBELEM
3276 "</deviate>"
3277 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003278 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003279 d_add = (struct lysp_deviate_add *)deviates;
3280 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3281 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003282 assert_string_equal(d_add->units, "units");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003283 assert_string_equal(d_add->musts->arg.str, "cond");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003284 assert_string_equal(d_add->uniques[0].str, "utag");
3285 assert_string_equal(d_add->dflts[0].str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003286 assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003287 assert_int_equal(d_add->min, 5);
3288 assert_int_equal(d_add->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003289 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003290 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003291 free(deviates);
3292 deviates = NULL;
3293
3294 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003295 "<deviate value=\"replace\">\n"
3296 " <type name=\"newtype\"/>\n"
3297 " <units name=\"uni\"/>\n"
3298 " <default value=\"def\"/>\n"
3299 " <config value=\"true\"/>\n"
3300 " <mandatory value=\"true\"/>\n"
3301 " <min-elements value=\"5\"/>\n"
3302 " <max-elements value=\"15\"/>\n"
3303 EXT_SUBELEM
3304 "</deviate>"
3305 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003306 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003307 d_rpl = (struct lysp_deviate_rpl *)deviates;
3308 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3309 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003310 assert_string_equal(d_rpl->type->name, "newtype");
3311 assert_string_equal(d_rpl->units, "uni");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003312 assert_string_equal(d_rpl->dflt.str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003313 assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003314 assert_int_equal(d_rpl->min, 5);
3315 assert_int_equal(d_rpl->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003316 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003317 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003318 free(deviates);
3319 deviates = NULL;
3320
3321 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003322 "<deviate value=\"delete\">\n"
3323 " <units name=\"u\"/>\n"
3324 " <must condition=\"c\"/>\n"
3325 " <unique tag=\"tag\"/>\n"
3326 " <default value=\"default\"/>\n"
3327 EXT_SUBELEM
3328 "</deviate>"
3329 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003330 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003331 d_del = (struct lysp_deviate_del *)deviates;
3332 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3333 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003334 assert_string_equal(d_del->units, "u");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003335 assert_string_equal(d_del->musts->arg.str, "c");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003336 assert_string_equal(d_del->uniques[0].str, "tag");
3337 assert_string_equal(d_del->dflts[0].str, "default");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003338 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003339 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003340 free(deviates);
3341 deviates = NULL;
3342
3343 /* invalid arguments */
3344 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003345 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3346 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. "
3347 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003348 deviates = NULL;
3349
3350 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003351 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3352 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. "
3353 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003354 deviates = NULL;
3355
3356 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003357 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3358 CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. "
3359 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003360 deviates = NULL;
3361
3362 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003363 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3364 CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. "
3365 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003366 deviates = NULL;
3367
3368 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003369 "<deviate value=\"not-supported\">\n"
3370 " <must condition=\"c\"/>\n"
3371 "</deviate>"
3372 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003373 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3374 CHECK_LOG_CTX("Deviate of this type doesn't allow \"must\" as it's sub-element.", "Line number 2.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003375}
3376
David Sedlák8b754462019-07-25 16:22:13 +02003377static void
3378test_deviation_elem(void **state)
3379{
David Sedlák8b754462019-07-25 16:22:13 +02003380 const char *data;
3381 struct lysp_deviation *deviations = NULL;
3382
3383 /* min subelems */
3384 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003385 "<deviation target-node=\"target\">\n"
3386 " <deviate value=\"not-supported\"/>\n"
3387 "</deviation>"
3388 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003389 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003390 assert_string_equal(deviations->nodeid, "target");
3391 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003392 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003393 deviations = NULL;
3394
3395 /* max subelems */
3396 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003397 "<deviation target-node=\"target\">\n"
3398 " <reference><text>ref</text></reference>\n"
3399 " <description><text>desc</text></description>\n"
3400 " <deviate value=\"add\"/>\n"
3401 EXT_SUBELEM
3402 "</deviation>"
3403 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003404 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003405 assert_string_equal(deviations->nodeid, "target");
3406 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3407 assert_string_equal(deviations->ref, "ref");
3408 assert_string_equal(deviations->dsc, "desc");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003409 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]), LY_STMT_DEVIATION);
Radek Iša56ca9e42020-09-08 18:42:00 +02003410 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003411 deviations = NULL;
3412
3413 /* invalid */
3414 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003415 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID);
3416 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003417 deviations = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003418 CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1.");
3419 /* TODO */}
David Sedlák8b754462019-07-25 16:22:13 +02003420
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003421static struct lysp_module *
3422mod_renew(struct lys_yin_parser_ctx *ctx)
3423{
3424 struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
3425
Radek Krejci90ed21e2021-04-12 14:47:46 +02003426 lys_module_free(ctx->parsed_mod->mod);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003427 ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod);
3428 ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
3429 ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
3430 ctx->parsed_mod->mod->ctx = ly_ctx;
3431
3432 return ctx->parsed_mod;
3433}
3434
David Sedlák4f03b932019-07-26 13:01:47 +02003435static void
3436test_module_elem(void **state)
3437{
Michal Vaskob36053d2020-03-26 15:49:30 +01003438 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003439 struct lysp_module *lysp_mod = mod_renew(YCTX);
David Sedlák4f03b932019-07-26 13:01:47 +02003440
3441 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003442 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003443 " <yang-version value=\"1.1\"/>\n"
3444 " <namespace uri=\"ns\"/>\n"
3445 " <prefix value=\"pref\"/>\n"
3446 " <include module=\"b-mod\"/>\n"
3447 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3448 " <organization><text>org</text></organization>\n"
3449 " <contact><text>contact</text></contact>\n"
3450 " <description><text>desc</text></description>\n"
3451 " <reference><text>ref</text></reference>\n"
3452 " <revision date=\"2019-02-02\"/>\n"
3453 " <anydata name=\"anyd\"/>\n"
3454 " <anyxml name=\"anyx\"/>\n"
3455 " <choice name=\"choice\"/>\n"
3456 " <container name=\"cont\"/>\n"
3457 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3458 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3459 " <list name=\"sub-list\"/>\n"
3460 " <uses name=\"uses-name\"/>\n"
3461 " <augment target-node=\"target\"/>\n"
3462 " <deviation target-node=\"target\">\n"
3463 " <deviate value=\"not-supported\"/>\n"
3464 " </deviation>\n"
3465 " <extension name=\"ext\"/>\n"
3466 " <feature name=\"feature\"/>\n"
3467 " <grouping name=\"grp\"/>\n"
3468 " <identity name=\"ident-name\"/>\n"
3469 " <notification name=\"notf\"/>\n"
3470 " <rpc name=\"rpc-name\"/>\n"
3471 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3472 EXT_SUBELEM "\n"
3473 "</module>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003474 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3475 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003476
Radek Iša56ca9e42020-09-08 18:42:00 +02003477 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003478 assert_string_equal(lysp_mod->mod->name, "mod");
3479 assert_string_equal(lysp_mod->revs, "2019-02-02");
3480 assert_string_equal(lysp_mod->mod->ns, "ns");
3481 assert_string_equal(lysp_mod->mod->prefix, "pref");
3482 assert_null(lysp_mod->mod->filepath);
3483 assert_string_equal(lysp_mod->mod->org, "org");
3484 assert_string_equal(lysp_mod->mod->contact, "contact");
3485 assert_string_equal(lysp_mod->mod->dsc, "desc");
3486 assert_string_equal(lysp_mod->mod->ref, "ref");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003487 assert_int_equal(lysp_mod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003488 CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod",
3489 "imp-pref", NULL, "");
David Sedlák4f03b932019-07-26 13:01:47 +02003490 assert_string_equal(lysp_mod->includes->name, "b-mod");
3491 assert_string_equal(lysp_mod->extensions->name, "ext");
3492 assert_string_equal(lysp_mod->features->name, "feature");
3493 assert_string_equal(lysp_mod->identities->name, "ident-name");
3494 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3495 assert_string_equal(lysp_mod->groupings->name, "grp");
3496 assert_string_equal(lysp_mod->data->name, "anyd");
3497 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3498 assert_string_equal(lysp_mod->data->next->name, "anyx");
3499 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3500 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3501 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3502 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3503 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3504 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3505 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3506 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3507 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3508 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3509 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3510 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3511 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3512 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3513 assert_string_equal(lysp_mod->augments->nodeid, "target");
3514 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3515 assert_string_equal(lysp_mod->notifs->name, "notf");
3516 assert_string_equal(lysp_mod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003517 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LY_STMT_MODULE);
David Sedlák4f03b932019-07-26 13:01:47 +02003518
3519 /* min subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003520 ly_in_free(UTEST_IN, 0);
3521 lyxml_ctx_free(YCTX->xmlctx);
3522 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003523 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3524 " <namespace uri=\"ns\"/>\n"
3525 " <prefix value=\"pref\"/>\n"
3526 " <yang-version value=\"1.1\"/>\n"
3527 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003528 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3529 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3530 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003531 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák298ff6d2019-07-26 14:29:03 +02003532
David Sedláke6cd89e2019-08-07 12:46:02 +02003533 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003534 ly_in_free(UTEST_IN, 0);
3535 lyxml_ctx_free(YCTX->xmlctx);
3536 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003537 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3538 " <feature name=\"feature\"/>\n"
3539 " <namespace uri=\"ns\"/>\n"
3540 " <prefix value=\"pref\"/>\n"
3541 " <yang-version value=\"1.1\"/>\n"
3542 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003543 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3544 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3545 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID);
3546 CHECK_LOG_CTX("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\".", "Line number 3.");
David Sedlák298ff6d2019-07-26 14:29:03 +02003547}
3548
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003549static struct lysp_submodule *
3550submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to)
3551{
3552 struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
3553
Radek Krejci90ed21e2021-04-12 14:47:46 +02003554 lys_module_free(ctx->parsed_mod->mod);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003555 ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule));
3556 ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
3557 lydict_insert(ly_ctx, belongs_to, 0, &ctx->parsed_mod->mod->name);
3558 ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
3559 ctx->parsed_mod->mod->ctx = ly_ctx;
3560
3561 return (struct lysp_submodule *)ctx->parsed_mod;
3562}
3563
David Sedlák298ff6d2019-07-26 14:29:03 +02003564static void
3565test_submodule_elem(void **state)
3566{
Michal Vaskob36053d2020-03-26 15:49:30 +01003567 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003568 struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name");
David Sedlák298ff6d2019-07-26 14:29:03 +02003569
3570 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02003571 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003572 " <yang-version value=\"1.1\"/>\n"
3573 " <belongs-to module=\"module-name\">\n"
3574 " <prefix value=\"pref\"/>\n"
3575 " </belongs-to>\n"
3576 " <include module=\"b-mod\"/>\n"
3577 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3578 " <organization><text>org</text></organization>\n"
3579 " <contact><text>contact</text></contact>\n"
3580 " <description><text>desc</text></description>\n"
3581 " <reference><text>ref</text></reference>\n"
3582 " <revision date=\"2019-02-02\"/>\n"
3583 " <anydata name=\"anyd\"/>\n"
3584 " <anyxml name=\"anyx\"/>\n"
3585 " <choice name=\"choice\"/>\n"
3586 " <container name=\"cont\"/>\n"
3587 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3588 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3589 " <list name=\"sub-list\"/>\n"
3590 " <uses name=\"uses-name\"/>\n"
3591 " <augment target-node=\"target\"/>\n"
3592 " <deviation target-node=\"target\">\n"
3593 " <deviate value=\"not-supported\"/>\n"
3594 " </deviation>\n"
3595 " <extension name=\"ext\"/>\n"
3596 " <feature name=\"feature\"/>\n"
3597 " <grouping name=\"grp\"/>\n"
3598 " <identity name=\"ident-name\"/>\n"
3599 " <notification name=\"notf\"/>\n"
3600 " <rpc name=\"rpc-name\"/>\n"
3601 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3602 EXT_SUBELEM "\n"
3603 "</submodule>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003604 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3605 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003606
Radek Iša56ca9e42020-09-08 18:42:00 +02003607 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003608 assert_string_equal(lysp_submod->name, "mod");
3609 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02003610 assert_string_equal(lysp_submod->prefix, "pref");
3611 assert_null(lysp_submod->filepath);
3612 assert_string_equal(lysp_submod->org, "org");
3613 assert_string_equal(lysp_submod->contact, "contact");
3614 assert_string_equal(lysp_submod->dsc, "desc");
3615 assert_string_equal(lysp_submod->ref, "ref");
3616 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003617 CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod",
3618 "imp-pref", NULL, "");
David Sedlák298ff6d2019-07-26 14:29:03 +02003619 assert_string_equal(lysp_submod->includes->name, "b-mod");
3620 assert_string_equal(lysp_submod->extensions->name, "ext");
3621 assert_string_equal(lysp_submod->features->name, "feature");
3622 assert_string_equal(lysp_submod->identities->name, "ident-name");
3623 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
3624 assert_string_equal(lysp_submod->groupings->name, "grp");
3625 assert_string_equal(lysp_submod->data->name, "anyd");
3626 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
3627 assert_string_equal(lysp_submod->data->next->name, "anyx");
3628 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
3629 assert_string_equal(lysp_submod->data->next->next->name, "choice");
3630 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
3631 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
3632 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
3633 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
3634 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
3635 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
3636 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3637 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
3638 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3639 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
3640 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3641 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
3642 assert_string_equal(lysp_submod->augments->nodeid, "target");
3643 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
3644 assert_string_equal(lysp_submod->notifs->name, "notf");
3645 assert_string_equal(lysp_submod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003646 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LY_STMT_SUBMODULE);
David Sedlák298ff6d2019-07-26 14:29:03 +02003647
David Sedlák298ff6d2019-07-26 14:29:03 +02003648 /* min subelemnts */
Radek Iša56ca9e42020-09-08 18:42:00 +02003649 ly_in_free(UTEST_IN, 0);
3650 lyxml_ctx_free(YCTX->xmlctx);
3651 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003652 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3653 " <yang-version value=\"1\"/>\n"
3654 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3655 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003656 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3657 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3658 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003659 assert_string_equal(lysp_submod->prefix, "pref");
David Sedlák298ff6d2019-07-26 14:29:03 +02003660 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
David Sedlák298ff6d2019-07-26 14:29:03 +02003661
David Sedláke6cd89e2019-08-07 12:46:02 +02003662 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003663 ly_in_free(UTEST_IN, 0);
3664 lyxml_ctx_free(YCTX->xmlctx);
3665 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003666 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3667 " <yang-version value=\"1\"/>\n"
3668 " <reference><text>ref</text></reference>\n"
3669 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3670 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003671 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3672 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3673 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID);
3674 CHECK_LOG_CTX("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\".", "Line number 4.");
David Sedlák4f03b932019-07-26 13:01:47 +02003675}
3676
David Sedlák8985a142019-07-31 16:43:06 +02003677static void
3678test_yin_parse_module(void **state)
3679{
David Sedlák8985a142019-07-31 16:43:06 +02003680 const char *data;
3681 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01003682 struct lys_yin_parser_ctx *yin_ctx = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003683 struct ly_in *in = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003684
3685 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003686 mod->ctx = UTEST_LYCTX;
David Sedlákd2844882019-09-13 16:01:22 +02003687 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003688 " <yang-version value=\"1.1\"/>\n"
3689 " <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
3690 " <prefix value=\"a\"/>\n"
3691 " <import module=\"ietf-yang-metadata\">\n"
3692 " <prefix value=\"md\"/>\n"
3693 " </import>\n"
3694 " <feature name=\"f\"/>\n"
3695 " <md:annotation name=\"x\">\n"
3696 " <description>\n"
3697 " <text>test</text>\n"
3698 " </description>\n"
3699 " <reference>\n"
3700 " <text>test</text>\n"
3701 " </reference>\n"
3702 " <if-feature name=\"f\"/>\n"
3703 " <status value=\"current\"/>\n"
3704 " <type name=\"uint8\"/>\n"
3705 " <units name=\"meters\"/>\n"
3706 " </md:annotation>\n"
3707 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003708 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003709 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
David Sedlákd2844882019-09-13 16:01:22 +02003710 assert_null(mod->parsed->exts->child->next->child);
3711 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
Radek Krejci90ed21e2021-04-12 14:47:46 +02003712 lys_module_free(mod);
David Sedlákd2844882019-09-13 16:01:22 +02003713 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003714 ly_in_free(in, 0);
David Sedlákd2844882019-09-13 16:01:22 +02003715 mod = NULL;
3716 yin_ctx = NULL;
3717
3718 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003719 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003720 data = "<module name=\"example-foo\""
3721 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3722 " xmlns:foo=\"urn:example:foo\""
3723 " xmlns:myext=\"urn:example:extensions\">\n"
David Sedlák8985a142019-07-31 16:43:06 +02003724
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003725 " <yang-version value=\"1\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003726
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003727 " <namespace uri=\"urn:example:foo\"/>\n"
3728 " <prefix value=\"foo\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003729
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003730 " <import module=\"example-extensions\">\n"
3731 " <prefix value=\"myext\"/>\n"
3732 " </import>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003733
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003734 " <list name=\"interface\">\n"
3735 " <key value=\"name\"/>\n"
3736 " <leaf name=\"name\">\n"
3737 " <type name=\"string\"/>\n"
3738 " </leaf>\n"
3739 " <leaf name=\"mtu\">\n"
3740 " <type name=\"uint32\"/>\n"
3741 " <description>\n"
3742 " <text>The MTU of the interface.</text>\n"
3743 " </description>\n"
3744 " <myext:c-define name=\"MY_MTU\"/>\n"
3745 " </leaf>\n"
3746 " </list>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003747 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003748 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003749 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
Radek Krejci90ed21e2021-04-12 14:47:46 +02003750 lys_module_free(mod);
David Sedlák8985a142019-07-31 16:43:06 +02003751 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003752 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003753 mod = NULL;
3754 yin_ctx = NULL;
3755
3756 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003757 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003758 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3759 " <yang-version value=\"1\"/>\n"
3760 " <namespace uri=\"urn:example:foo\"/>\n"
3761 " <prefix value=\"foo\"/>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003762 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003763 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003764 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
Radek Krejci90ed21e2021-04-12 14:47:46 +02003765 lys_module_free(mod);
David Sedlák6d781b62019-08-02 15:22:52 +02003766 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003767 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003768 mod = NULL;
3769 yin_ctx = NULL;
3770
David Sedlák6d781b62019-08-02 15:22:52 +02003771 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003772 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003773 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlák8985a142019-07-31 16:43:06 +02003774 "</submodule>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003775 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003776 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL);
Radek Iša56ca9e42020-09-08 18:42:00 +02003777 CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
Radek Krejci90ed21e2021-04-12 14:47:46 +02003778 lys_module_free(mod);
David Sedlák8985a142019-07-31 16:43:06 +02003779 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003780 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003781
David Sedlák6d781b62019-08-02 15:22:52 +02003782 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003783 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003784 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3785 " <yang-version value=\"1\"/>\n"
3786 " <namespace uri=\"urn:example:foo\"/>\n"
3787 " <prefix value=\"foo\"/>\n"
3788 "</module>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003789 "<module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003790 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003791 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +02003792 CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
Radek Krejci90ed21e2021-04-12 14:47:46 +02003793 lys_module_free(mod);
David Sedlák6d781b62019-08-02 15:22:52 +02003794 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003795 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003796 mod = NULL;
3797 yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003798}
3799
3800static void
3801test_yin_parse_submodule(void **state)
3802{
David Sedlák8985a142019-07-31 16:43:06 +02003803 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01003804 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003805 struct lysp_submodule *submod = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003806 struct ly_in *in;
David Sedlák8985a142019-07-31 16:43:06 +02003807
Radek Iša56ca9e42020-09-08 18:42:00 +02003808 lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name);
Michal Vaskoc3781c32020-10-06 14:04:08 +02003809
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003810 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003811 "<submodule name=\"asub\""
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003812 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3813 " xmlns:a=\"urn:a\">\n"
3814 " <yang-version value=\"1\"/>\n"
3815 " <belongs-to module=\"a\">\n"
3816 " <prefix value=\"a_pref\"/>\n"
3817 " </belongs-to>\n"
3818 " <include module=\"atop\"/>\n"
3819 " <feature name=\"fox\"/>\n"
3820 " <notification name=\"bar-notif\">\n"
3821 " <if-feature name=\"bar\"/>\n"
3822 " </notification>\n"
3823 " <notification name=\"fox-notif\">\n"
3824 " <if-feature name=\"fox\"/>\n"
3825 " </notification>\n"
3826 " <augment target-node=\"/a_pref:top\">\n"
3827 " <if-feature name=\"bar\"/>\n"
3828 " <container name=\"bar-sub\"/>\n"
3829 " </augment>\n"
3830 " <augment target-node=\"/top\">\n"
3831 " <container name=\"bar-sub2\"/>\n"
3832 " </augment>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003833 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003834 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003835 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003836 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003837 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003838 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003839 yin_ctx = NULL;
3840 submod = NULL;
3841
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003842 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3843 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3844 " <yang-version value=\"1\"/>\n"
3845 " <belongs-to module=\"a\">\n"
3846 " <prefix value=\"a_pref\"/>\n"
3847 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003848 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003849 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003850 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003851 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003852 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003853 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003854 yin_ctx = NULL;
3855 submod = NULL;
3856
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003857 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003858 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
3859 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003860 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003861 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
3862 CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003863 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003864 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003865 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003866 yin_ctx = NULL;
3867 submod = NULL;
3868
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003869 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3870 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3871 " <yang-version value=\"1\"/>\n"
3872 " <belongs-to module=\"a\">\n"
3873 " <prefix value=\"a_pref\"/>\n"
3874 " </belongs-to>\n"
3875 "</submodule>\n"
3876 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3877 " <yang-version value=\"1\"/>\n"
3878 " <belongs-to module=\"a\">\n"
3879 " <prefix value=\"a_pref\"/>\n"
3880 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003881 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003882 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003883 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
3884 CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003885 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003886 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003887 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003888 yin_ctx = NULL;
3889 submod = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003890}
3891
David Sedlák3b4db242018-10-19 16:11:01 +02003892int
3893main(void)
3894{
3895
3896 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +02003897 UTEST(test_yin_match_keyword, setup, teardown),
3898 UTEST(test_yin_parse_element_generic, setup, teardown),
3899 UTEST(test_yin_parse_extension_instance, setup, teardown),
3900 UTEST(test_yin_parse_content, setup, teardown),
3901 UTEST(test_validate_value, setup, teardown),
David Sedlák32488102019-07-15 17:44:10 +02003902
Radek Iša56ca9e42020-09-08 18:42:00 +02003903 UTEST(test_yin_match_argument_name),
3904 cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown),
3905 cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown),
3906 cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown),
3907 cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown),
3908 cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown),
3909 cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown),
3910 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown),
3911 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown),
3912 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown),
3913 cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown),
3914 cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown),
3915 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown),
3916 cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown),
3917 cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown),
3918 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown),
3919 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown),
3920 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown),
3921 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown),
3922 cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown),
3923 cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown),
3924 cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown),
3925 cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown),
3926 cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown),
3927 cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown),
3928 cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown),
3929 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown),
3930 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown),
3931 cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown),
3932 cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown),
3933 cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown),
3934 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown),
3935 cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown),
3936 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown),
3937 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown),
3938 cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown),
3939 cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown),
3940 cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown),
3941 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown),
3942 cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown),
3943 cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown),
3944 cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown),
3945 cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown),
3946 cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown),
3947 cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown),
3948 cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown),
3949 cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown),
3950 cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown),
3951 cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown),
3952 cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown),
3953 cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown),
3954 cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown),
3955 cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown),
3956 cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown),
3957 cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown),
3958 cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown),
3959 cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown),
3960 cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown),
3961 cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown),
David Sedlák8985a142019-07-31 16:43:06 +02003962
Radek Iša56ca9e42020-09-08 18:42:00 +02003963 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown),
3964 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown),
David Sedlák3b4db242018-10-19 16:11:01 +02003965 };
3966
Radek Iša56ca9e42020-09-08 18:42:00 +02003967 return cmocka_run_group_tests(tests, NULL, NULL);
David Sedlák3b4db242018-10-19 16:11:01 +02003968}