blob: 81c4eaef78b66f3fdb14883e490209ffdd411304 [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{
Michal Vasko8a67eff2021-12-07 14:04:47 +0100133 struct lysp_module *pmod;
134
David Sedlák619db942019-07-03 14:47:30 +0200135 /* allocate parser context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200136 YCTX = calloc(1, sizeof(*YCTX));
137 YCTX->format = LYS_IN_YIN;
Michal Vasko8a67eff2021-12-07 14:04:47 +0100138 ly_set_new(&YCTX->parsed_mods);
David Sedlák8f5bce02019-06-03 16:41:08 +0200139
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200140 /* allocate new parsed module */
Michal Vasko8a67eff2021-12-07 14:04:47 +0100141 pmod = calloc(1, sizeof *pmod);
142 ly_set_add(YCTX->parsed_mods, pmod, 1, NULL);
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200143
144 /* allocate new module */
Michal Vasko8a67eff2021-12-07 14:04:47 +0100145 pmod->mod = calloc(1, sizeof *pmod->mod);
146 pmod->mod->ctx = UTEST_LYCTX;
147 pmod->mod->parsed = pmod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200148
Radek Iša56ca9e42020-09-08 18:42:00 +0200149 return 0;
David Sedlák3b4db242018-10-19 16:11:01 +0200150}
151
152static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200153setup(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100154{
Radek Iša56ca9e42020-09-08 18:42:00 +0200155 UTEST_SETUP;
David Sedlák68a1af12019-03-08 13:46:54 +0100156
Radek Iša56ca9e42020-09-08 18:42:00 +0200157 setup_ctx(state);
David Sedlák79e50cb2019-06-05 16:33:09 +0200158
Radek Iša56ca9e42020-09-08 18:42:00 +0200159 return 0;
David Sedlák79e50cb2019-06-05 16:33:09 +0200160}
161
David Sedlák8985a142019-07-31 16:43:06 +0200162static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200163teardown_ctx(void **UNUSED(state))
David Sedlák8985a142019-07-31 16:43:06 +0200164{
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100165 lys_module_free(PARSER_CUR_PMOD(YCTX)->mod, 0);
aPiecek8d4e75d2021-06-24 14:47:06 +0200166 yin_parser_ctx_free(YCTX);
Radek Iša56ca9e42020-09-08 18:42:00 +0200167 YCTX = NULL;
David Sedlák8985a142019-07-31 16:43:06 +0200168
Radek Iša56ca9e42020-09-08 18:42:00 +0200169 return 0;
David Sedlák8985a142019-07-31 16:43:06 +0200170}
171
Radek Iša56ca9e42020-09-08 18:42:00 +0200172static int
173teardown(void **state)
174{
175 teardown_ctx(state);
176
177 UTEST_TEARDOWN;
178
179 return 0;
180}
181
182#define RESET_STATE \
183 ly_in_free(UTEST_IN, 0); \
184 UTEST_IN = NULL; \
185 teardown_ctx(state); \
186 setup_ctx(state)
187
David Sedlák68a1af12019-03-08 13:46:54 +0100188static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200189test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200190{
Michal Vaskob36053d2020-03-26 15:49:30 +0100191 const char *prefix;
192 size_t prefix_len;
Radek Iša56ca9e42020-09-08 18:42:00 +0200193
David Sedlák8f7a1172019-06-20 14:42:18 +0200194 /* create mock yin namespace in xml context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200195 ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN);
196 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
197 prefix = YCTX->xmlctx->prefix;
198 prefix_len = YCTX->xmlctx->prefix_len;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100199
Radek Iša56ca9e42020-09-08 18:42:00 +0200200 assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
201 assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
202 assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
203 assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
204 assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
205 assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
206 assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
207 assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
208 assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
209 assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
210 assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
211 assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
212 assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
213 assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
214 assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
215 assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
216 assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
217 assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
218 assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
219 assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
220 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);
221 assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
222 assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
223 assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
224 assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
225 assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
226 assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
227 assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
228 assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
229 assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
230 assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
231 assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
232 assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
233 assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
234 assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
235 assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
236 assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
237 assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
238 assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
239 assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
240 assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
241 assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
242 assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
243 assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
244 assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
245 assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
246 assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
247 assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
248 assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
249 assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
250 assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
251 assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
252 assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
253 assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
254 assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
255 assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
256 assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
257 assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
258 assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
259 assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
260 assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
261 assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
262 assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
263 assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
264 assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
265 assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
266 assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
267 assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
268 assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
269 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 +0200270}
David Sedlák3b4db242018-10-19 16:11:01 +0200271
David Sedlák872c7b42018-10-26 13:15:20 +0200272static void
Radek Iša56ca9e42020-09-08 18:42:00 +0200273test_yin_match_argument_name(void **UNUSED(state))
David Sedlák872c7b42018-10-26 13:15:20 +0200274{
David Sedlák060b00e2019-06-19 11:12:06 +0200275 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
276 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
277 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
278 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
279 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
280 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
281 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
282 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
283 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
284 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
285 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
286 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200287}
288
David Sedlák68a1af12019-03-08 13:46:54 +0100289static void
David Sedlákb1a78352019-06-28 16:16:29 +0200290test_yin_parse_element_generic(void **state)
291{
David Sedlákb1a78352019-06-28 16:16:29 +0200292 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200293 LY_ERR ret;
Radek Iša56ca9e42020-09-08 18:42:00 +0200294 const char *arg;
295 const char *stmt;
296 const char *data;
David Sedlákb1a78352019-06-28 16:16:29 +0200297
298 memset(&exts, 0, sizeof(exts));
299
Radek Iša56ca9e42020-09-08 18:42:00 +0200300 data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
301 ly_in_new_memory(data, &UTEST_IN);
302 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100303
Radek Iša56ca9e42020-09-08 18:42:00 +0200304 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200305 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200306 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100307 stmt = "myext:elem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200308 arg = "text_value";
Radek Krejci996f0772021-02-05 19:39:41 +0100309 CHECK_LYSP_STMT(exts.child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200310 stmt = "attr";
311 arg = "value";
312 CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt);
313 lysp_ext_instance_free(UTEST_LYCTX, &exts);
314 RESET_STATE;
David Sedlák5392a212019-07-01 09:19:10 +0200315
David Sedlákb0ca07d2019-09-11 11:54:05 +0200316 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200317 ly_in_new_memory(data, &UTEST_IN);
318 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100319
Radek Iša56ca9e42020-09-08 18:42:00 +0200320 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200321 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200322 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100323 stmt = "myext:elem";
Radek Krejci996f0772021-02-05 19:39:41 +0100324 CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200325 lysp_ext_instance_free(UTEST_LYCTX, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200326}
327
328static void
329test_yin_parse_extension_instance(void **state)
330{
331 LY_ERR ret;
David Sedlákb1a78352019-06-28 16:16:29 +0200332 struct lysp_ext_instance *exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200333 struct lysp_stmt *act_child;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200334 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 +0200335 const char *stmt = "value1";
336 const char *arg = "test";
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100337
Radek Iša56ca9e42020-09-08 18:42:00 +0200338 ly_in_new_memory(data, &UTEST_IN);
339 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100340
Radek Krejcifc596f92021-02-26 22:40:26 +0100341 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200342 assert_int_equal(ret, LY_SUCCESS);
Radek Krejci8df109d2021-04-23 12:19:08 +0200343 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, LY_STMT_CONTACT, 0, "myext:ext", LY_VALUE_XML);
David Sedlákb1a78352019-06-28 16:16:29 +0200344
Radek Iša56ca9e42020-09-08 18:42:00 +0200345 CHECK_LYSP_STMT(exts->child, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
346 stmt = "value";
347 arg = "test2";
348 CHECK_LYSP_STMT(exts->child->next, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100349 stmt = "myext:subelem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200350 arg = "text";
Radek Krejci996f0772021-02-05 19:39:41 +0100351 CHECK_LYSP_STMT(exts->child->next->next, arg, 0, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200352 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200353 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200354 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200355 RESET_STATE;
David Sedlákf250ecf2019-07-01 11:02:05 +0200356
David Sedlákb0ca07d2019-09-11 11:54:05 +0200357 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Radek Iša56ca9e42020-09-08 18:42:00 +0200358 ly_in_new_memory(data, &UTEST_IN);
359 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100360
Radek Krejcifc596f92021-02-26 22:40:26 +0100361 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200362 assert_int_equal(ret, LY_SUCCESS);
Radek Krejci8df109d2021-04-23 12:19:08 +0200363 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 +0200364 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200365 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200366 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200367 RESET_STATE;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200368
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100369 data =
370 "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n"
371 " <myext:ext-sub1/>\n"
372 " <myext:ext-sub2 sattr1=\"stext2\">\n"
373 " <myext:ext-sub21>\n"
374 " <myext:ext-sub211 sattr21=\"text21\"/>\n"
375 " </myext:ext-sub21>\n"
376 " </myext:ext-sub2>\n"
377 " <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n"
378 "</myext:ext>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200379 ly_in_new_memory(data, &UTEST_IN);
380 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100381
Radek Krejcifc596f92021-02-26 22:40:26 +0100382 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200383 assert_int_equal(ret, LY_SUCCESS);
384
Radek Krejci8df109d2021-04-23 12:19:08 +0200385 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, LY_STMT_CONTACT, 0, "myext:ext", LY_VALUE_XML);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200386
Radek Iša56ca9e42020-09-08 18:42:00 +0200387 stmt = "attr1";
388 arg = "text1";
389 act_child = exts->child;
390 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
391 stmt = "attr2";
392 arg = "text2";
393 act_child = act_child->next;
394 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100395 stmt = "myext:ext-sub1";
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, NULL, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100399 stmt = "myext:ext-sub2";
Radek Iša56ca9e42020-09-08 18:42:00 +0200400 arg = NULL;
401 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100402 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200403
Radek Iša56ca9e42020-09-08 18:42:00 +0200404 stmt = "sattr1";
405 arg = "stext2";
406 act_child = act_child->child;
407 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100408 stmt = "myext:ext-sub21";
Radek Iša56ca9e42020-09-08 18:42:00 +0200409 arg = NULL;
410 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100411 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200412
Michal Vaskofc2cd072021-02-24 13:17:17 +0100413 stmt = "myext:ext-sub211";
Radek Iša56ca9e42020-09-08 18:42:00 +0200414 arg = NULL;
415 act_child = act_child->child;
Radek Krejci996f0772021-02-05 19:39:41 +0100416 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200417
Radek Iša56ca9e42020-09-08 18:42:00 +0200418 stmt = "sattr21";
419 arg = "text21";
420 act_child = act_child->child;
421 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200422
Michal Vaskofc2cd072021-02-24 13:17:17 +0100423 stmt = "myext:ext-sub3";
Radek Iša56ca9e42020-09-08 18:42:00 +0200424 arg = NULL;
425 act_child = exts->child->next->next->next->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100426 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200427 stmt = "attr3";
428 arg = "text3";
429 act_child = act_child->child;
430 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200431
Radek Iša56ca9e42020-09-08 18:42:00 +0200432 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200433 LY_ARRAY_FREE(exts);
434 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200435 RESET_STATE;
David Sedlákaa98bba2019-09-12 11:52:14 +0200436
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100437 data =
438 "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
439 " <yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>\n"
440 " <yin:augment target-node=\"target\"/>\n"
441 " <yin:status value=\"value\"/>\n"
442 " <yin:include module=\"mod\"/>\n"
443 " <yin:input />\n"
444 " <yin:must condition=\"cond\"/>\n"
445 " <yin:namespace uri=\"uri\"/>\n"
446 " <yin:revision date=\"data\"/>\n"
447 " <yin:unique tag=\"tag\"/>\n"
448 " <yin:description><yin:text>contact-val</yin:text></yin:description>\n"
449 " <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n"
450 "</myext:extension-elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200451 ly_in_new_memory(data, &UTEST_IN);
452 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100453
Radek Krejcifc596f92021-02-26 22:40:26 +0100454 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200455 assert_int_equal(ret, LY_SUCCESS);
456 assert_string_equal(exts->child->arg, "act-name");
457 assert_string_equal(exts->child->next->arg, "target");
458 assert_string_equal(exts->child->next->next->arg, "value");
459 assert_string_equal(exts->child->next->next->next->arg, "mod");
460 assert_null(exts->child->next->next->next->next->arg);
461 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
462 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
463 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
464 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
465 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 +0200466 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200467 LY_ARRAY_FREE(exts);
468 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200469 RESET_STATE;
David Sedlákb1a78352019-06-28 16:16:29 +0200470}
471
David Sedlák555c7202019-07-04 12:14:12 +0200472static void
473test_yin_parse_content(void **state)
474{
David Sedlák555c7202019-07-04 12:14:12 +0200475 LY_ERR ret = LY_SUCCESS;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100476 const char *data =
477 "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
478 " <myext:custom xmlns:myext=\"urn:example:extensions\">totally amazing extension</myext:custom>\n"
479 " <extension name=\"ext\">\n"
480 " <argument name=\"argname\"></argument>\n"
481 " <description><text>desc</text></description>\n"
482 " <reference><text>ref</text></reference>\n"
483 " <status value=\"deprecated\"></status>\n"
484 " </extension>\n"
485 " <text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>\n"
486 " <if-feature name=\"foo\"></if-feature>\n"
487 " <when condition=\"condition...\">\n"
488 " <reference><text>when_ref</text></reference>\n"
489 " <description><text>when_desc</text></description>\n"
490 " </when>\n"
491 " <config value=\"true\"/>\n"
492 " <error-message>\n"
493 " <value>error-msg</value>\n"
494 " </error-message>\n"
495 " <error-app-tag value=\"err-app-tag\"/>\n"
496 " <units name=\"radians\"></units>\n"
497 " <default value=\"default-value\"/>\n"
498 " <position value=\"25\"></position>\n"
499 " <value value=\"-5\"/>\n"
500 " <require-instance value=\"true\"></require-instance>\n"
501 " <range value=\"5..10\" />\n"
502 " <length value=\"baf\"/>\n"
503 " <pattern value='pattern'>\n"
504 " <modifier value='invert-match'/>\n"
505 " </pattern>\n"
506 " <enum name=\"yay\">\n"
507 " </enum>\n"
508 "</prefix>";
David Sedlák555c7202019-07-04 12:14:12 +0200509 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200510 const char **if_features = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200511 const char *value, *error_message, *app_tag, *units;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200512 struct lysp_qname def = {0};
David Sedlák986cb412019-07-04 13:10:11 +0200513 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200514 struct lysp_when *when_p = NULL;
Michal Vasko2a6c53f2021-09-22 12:20:05 +0200515 struct lysp_type_enum pos_enum = {0}, val_enum = {0};
516 struct lysp_type req_type = {0}, range_type = {0}, len_type = {0}, patter_type = {0}, enum_type = {0};
Juraj Vijtiukf6a07372020-10-29 21:13:33 +0100517 uint16_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200518
Radek Iša56ca9e42020-09-08 18:42:00 +0200519 ly_in_new_memory(data, &UTEST_IN);
520 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
521 lyxml_ctx_next(YCTX->xmlctx);
522 lyxml_ctx_next(YCTX->xmlctx);
523 lyxml_ctx_next(YCTX->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200524
David Sedlákfd5b9c32019-07-12 15:33:13 +0200525 struct yin_subelement subelems[17] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100526 {LY_STMT_CONFIG, &config, 0},
527 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
528 {LY_STMT_ENUM, &enum_type, 0},
529 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
Radek Iša56ca9e42020-09-08 18:42:00 +0200530 {LY_STMT_ERROR_MESSAGE, &error_message, 0},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100531 {LY_STMT_EXTENSION, &ext_def, 0},
532 {LY_STMT_IF_FEATURE, &if_features, 0},
533 {LY_STMT_LENGTH, &len_type, 0},
534 {LY_STMT_PATTERN, &patter_type, 0},
535 {LY_STMT_POSITION, &pos_enum, 0},
536 {LY_STMT_RANGE, &range_type, 0},
537 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
538 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
539 {LY_STMT_VALUE, &val_enum, 0},
540 {LY_STMT_WHEN, &when_p, 0},
541 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
542 {LY_STMT_ARG_TEXT, &value, 0}
543 };
544
Radek Iša56ca9e42020-09-08 18:42:00 +0200545 ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200546 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200547 /* check parsed values */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200548 assert_string_equal(def.str, "default-value");
Michal Vaskofc2cd072021-02-24 13:17:17 +0100549 const char *exts_name = "myext:custom";
Radek Iša56ca9e42020-09-08 18:42:00 +0200550 const char *exts_arg = "totally amazing extension";
551
Radek Krejci8df109d2021-04-23 12:19:08 +0200552 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 +0200553 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200554 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200555 assert_string_equal(when_p->cond, "condition...");
556 assert_string_equal(when_p->dsc, "when_desc");
557 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200558 assert_int_equal(config, LYS_CONFIG_W);
Radek Iša56ca9e42020-09-08 18:42:00 +0200559 CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25);
560 CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5);
David Sedlákcf5569a2019-07-11 13:31:34 +0200561 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200562 assert_true(req_type.flags &= LYS_SET_REQINST);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200563 assert_string_equal(range_type.range->arg.str, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200564 assert_true(range_type.flags & LYS_SET_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +0200565 assert_string_equal(error_message, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200566 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200567 assert_string_equal(enum_type.enums->name, "yay");
Radek Iša56ca9e42020-09-08 18:42:00 +0200568 CHECK_LYSP_RESTR(len_type.length, "baf", NULL,
569 NULL, NULL, 0, NULL);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200570 assert_true(len_type.flags & LYS_SET_LENGTH);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200571 assert_string_equal(patter_type.patterns->arg.str, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200572 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200573 /* cleanup */
Radek Iša56ca9e42020-09-08 18:42:00 +0200574 lysp_ext_instance_free(UTEST_LYCTX, exts);
575 lysp_when_free(UTEST_LYCTX, when_p);
576 lysp_ext_free(UTEST_LYCTX, ext_def);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100577 lydict_remove(UTEST_LYCTX, *if_features);
578 lydict_remove(UTEST_LYCTX, error_message);
579 lydict_remove(UTEST_LYCTX, app_tag);
580 lydict_remove(UTEST_LYCTX, units);
581 lydict_remove(UTEST_LYCTX, patter_type.patterns->arg.str);
582 lydict_remove(UTEST_LYCTX, def.str);
583 lydict_remove(UTEST_LYCTX, range_type.range->arg.str);
584 lydict_remove(UTEST_LYCTX, len_type.length->arg.str);
585 lydict_remove(UTEST_LYCTX, enum_type.enums->name);
586 lydict_remove(UTEST_LYCTX, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200587 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200588 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200589 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200590 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200591 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200592 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200593 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200594 free(len_type.length);
Radek Iša56ca9e42020-09-08 18:42:00 +0200595 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200596
597 /* test unique subelem */
598 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200599 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100600 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
601
David Sedláke6cd89e2019-08-07 12:46:02 +0200602 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100603 "<prefix value=\"inv_mod\" />"
604 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
605 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
606 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200607 ly_in_new_memory(data, &UTEST_IN);
608 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
609 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100610
Radek Iša56ca9e42020-09-08 18:42:00 +0200611 ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200612 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200613 CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1.");
614 lydict_remove(UTEST_LYCTX, prefix_value);
615 lydict_remove(UTEST_LYCTX, value);
616 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200617
618 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200619 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100620 "<prefix value=\"inv_mod\" />"
621 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
622 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
623 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200624 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100625 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
626
Radek Iša56ca9e42020-09-08 18:42:00 +0200627 ly_in_new_memory(data, &UTEST_IN);
628 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
629 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100630
Radek Iša56ca9e42020-09-08 18:42:00 +0200631 ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200632 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200633 CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1.");
634 lydict_remove(UTEST_LYCTX, prefix_value);
635 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200636
637 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200638 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200639 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100640
Radek Iša56ca9e42020-09-08 18:42:00 +0200641 ly_in_new_memory(data, &UTEST_IN);
642 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
643 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100644
Radek Iša56ca9e42020-09-08 18:42:00 +0200645 ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200646 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200647 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200648}
649
David Sedlák92147b02019-07-09 14:01:01 +0200650static void
David Sedlák4a650532019-07-10 11:55:18 +0200651test_validate_value(void **state)
652{
Michal Vaskob36053d2020-03-26 15:49:30 +0100653 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
654
655 /* create some XML context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200656 ly_in_new_memory(data, &UTEST_IN);
657 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
658 YCTX->xmlctx->status = LYXML_ELEM_CONTENT;
659 YCTX->xmlctx->dynamic = 0;
Michal Vaskob36053d2020-03-26 15:49:30 +0100660
Radek Iša56ca9e42020-09-08 18:42:00 +0200661 YCTX->xmlctx->value = "#invalid";
662 YCTX->xmlctx->value_len = 8;
663 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
Radek Iša2eac74c2021-03-15 15:53:08 +0100664 CHECK_LOG_CTX("Invalid identifier first character '#' (0x0023).", "Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100665
Radek Iša56ca9e42020-09-08 18:42:00 +0200666 YCTX->xmlctx->value = "";
667 YCTX->xmlctx->value_len = 0;
668 assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100669
Radek Iša56ca9e42020-09-08 18:42:00 +0200670 YCTX->xmlctx->value = "pre:b";
671 YCTX->xmlctx->value_len = 5;
672 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
673 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100674
Radek Iša56ca9e42020-09-08 18:42:00 +0200675 YCTX->xmlctx->value = "pre:pre:b";
676 YCTX->xmlctx->value_len = 9;
677 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200678}
679
David Sedlák32488102019-07-15 17:44:10 +0200680/* helper function to simplify unit test of each element using parse_content function */
681LY_ERR
Radek Iša56ca9e42020-09-08 18:42:00 +0200682test_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 +0200683{
David Sedlákc5b20842019-08-13 10:18:31 +0200684 const char *name, *prefix;
685 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200686 LY_ERR ret = LY_SUCCESS;
687 struct yin_subelement subelems[71] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100688 {LY_STMT_ACTION, dest, 0},
689 {LY_STMT_ANYDATA, dest, 0},
690 {LY_STMT_ANYXML, dest, 0},
691 {LY_STMT_ARGUMENT, dest, 0},
692 {LY_STMT_AUGMENT, dest, 0},
693 {LY_STMT_BASE, dest, 0},
694 {LY_STMT_BELONGS_TO, dest, 0},
695 {LY_STMT_BIT, dest, 0},
696 {LY_STMT_CASE, dest, 0},
697 {LY_STMT_CHOICE, dest, 0},
698 {LY_STMT_CONFIG, dest, 0},
699 {LY_STMT_CONTACT, dest, 0},
700 {LY_STMT_CONTAINER, dest, 0},
701 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
702 {LY_STMT_DESCRIPTION, dest, 0},
703 {LY_STMT_DEVIATE, dest, 0},
704 {LY_STMT_DEVIATION, dest, 0},
705 {LY_STMT_ENUM, dest, 0},
706 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
707 {LY_STMT_ERROR_MESSAGE, dest, 0},
708 {LY_STMT_EXTENSION, dest, 0},
709 {LY_STMT_FEATURE, dest, 0},
710 {LY_STMT_FRACTION_DIGITS, dest, 0},
711 {LY_STMT_GROUPING, dest, 0},
712 {LY_STMT_IDENTITY, dest, 0},
713 {LY_STMT_IF_FEATURE, dest, 0},
714 {LY_STMT_IMPORT, dest, 0},
715 {LY_STMT_INCLUDE, dest, 0},
716 {LY_STMT_INPUT, dest, 0},
717 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
718 {LY_STMT_LEAF, dest, 0},
719 {LY_STMT_LEAF_LIST, dest, 0},
720 {LY_STMT_LENGTH, dest, 0},
721 {LY_STMT_LIST, dest, 0},
722 {LY_STMT_MANDATORY, dest, 0},
723 {LY_STMT_MAX_ELEMENTS, dest, 0},
724 {LY_STMT_MIN_ELEMENTS, dest, 0},
725 {LY_STMT_MODIFIER, dest, 0},
726 {LY_STMT_MODULE, dest, 0},
727 {LY_STMT_MUST, dest, 0},
728 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
729 {LY_STMT_NOTIFICATION, dest, 0},
730 {LY_STMT_ORDERED_BY, dest, 0},
731 {LY_STMT_ORGANIZATION, dest, 0},
732 {LY_STMT_OUTPUT, dest, 0},
733 {LY_STMT_PATH, dest, 0},
734 {LY_STMT_PATTERN, dest, 0},
735 {LY_STMT_POSITION, dest, 0},
736 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
737 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
738 {LY_STMT_RANGE, dest, 0},
739 {LY_STMT_REFERENCE, dest, 0},
740 {LY_STMT_REFINE, dest, 0},
741 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
742 {LY_STMT_REVISION, dest, 0},
743 {LY_STMT_REVISION_DATE, dest, 0},
744 {LY_STMT_RPC, dest, 0},
745 {LY_STMT_STATUS, dest, 0},
746 {LY_STMT_SUBMODULE, dest, 0},
747 {LY_STMT_TYPE, dest, 0},
748 {LY_STMT_TYPEDEF, dest, 0},
749 {LY_STMT_UNIQUE, dest, 0},
750 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
751 {LY_STMT_USES, dest, 0},
752 {LY_STMT_VALUE, dest, 0},
753 {LY_STMT_WHEN, dest, 0},
754 {LY_STMT_YANG_VERSION, dest, 0},
755 {LY_STMT_YIN_ELEMENT, dest, 0},
756 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
757 {LY_STMT_ARG_TEXT, dest, 0},
758 {LY_STMT_ARG_VALUE, dest, 0}
759 };
760
aPiecek8d4e75d2021-06-24 14:47:06 +0200761 YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
Radek Iša56ca9e42020-09-08 18:42:00 +0200762 ly_in_new_memory(data, &UTEST_IN);
763 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
764 prefix = YCTX->xmlctx->prefix;
765 prefix_len = YCTX->xmlctx->prefix_len;
766 name = YCTX->xmlctx->name;
767 name_len = YCTX->xmlctx->name_len;
768 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100769
Radek Iša56ca9e42020-09-08 18:42:00 +0200770 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 +0100771
Michal Vasko63f3d842020-07-08 10:10:14 +0200772 /* free parser and input */
Radek Iša56ca9e42020-09-08 18:42:00 +0200773 lyxml_ctx_free(YCTX->xmlctx);
774 YCTX->xmlctx = NULL;
775 ly_in_free(UTEST_IN, 0);
776 UTEST_IN = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200777 return ret;
778}
779
David Sedlákd1144562019-08-06 12:36:14 +0200780#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
781
David Sedlák32488102019-07-15 17:44:10 +0200782static void
David Sedlák43801c92019-08-05 15:58:54 +0200783test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200784{
Michal Vasko2a6c53f2021-09-22 12:20:05 +0200785 struct lysp_type type = {0};
David Sedlák32488102019-07-15 17:44:10 +0200786 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100787
David Sedlák32488102019-07-15 17:44:10 +0200788 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100789 "<enum name=\"enum-name\">\n"
790 " <if-feature name=\"feature\" />\n"
791 " <value value=\"55\" />\n"
792 " <status value=\"deprecated\" />\n"
793 " <description><text>desc...</text></description>\n"
794 " <reference><text>ref...</text></reference>\n"
795 " " EXT_SUBELEM "\n"
796 "</enum>"
797 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200798 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
799 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
800
801 CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200802 assert_string_equal(type.enums->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100803 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LY_STMT_ENUM);
Radek Iša56ca9e42020-09-08 18:42:00 +0200804 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200805 memset(&type, 0, sizeof type);
806
807 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100808 "<enum name=\"enum-name\"></enum>"
809 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200810 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200811 assert_string_equal(type.enums->name, "enum-name");
Radek Iša56ca9e42020-09-08 18:42:00 +0200812 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák32488102019-07-15 17:44:10 +0200813 memset(&type, 0, sizeof type);
David Sedlák43801c92019-08-05 15:58:54 +0200814}
815
816static void
817test_bit_elem(void **state)
818{
Michal Vasko2a6c53f2021-09-22 12:20:05 +0200819 struct lysp_type type = {0};
David Sedlák43801c92019-08-05 15:58:54 +0200820 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100821
David Sedlák43801c92019-08-05 15:58:54 +0200822 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100823 "<bit name=\"bit-name\">\n"
824 " <if-feature name=\"feature\" />\n"
825 " <position value=\"55\" />\n"
826 " <status value=\"deprecated\" />\n"
827 " <description><text>desc...</text></description>\n"
828 " <reference><text>ref...</text></reference>\n"
829 EXT_SUBELEM
830 "</bit>"
831 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200832 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
833 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
834
835 CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200836 assert_string_equal(type.bits->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100837 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LY_STMT_BIT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200838 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200839 memset(&type, 0, sizeof type);
840
841 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100842 "<bit name=\"bit-name\"> </bit>"
843 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200844 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
845 CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
846 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák43801c92019-08-05 15:58:54 +0200847 memset(&type, 0, sizeof type);
David Sedlák32488102019-07-15 17:44:10 +0200848}
849
850static void
851test_meta_elem(void **state)
852{
David Sedlák32488102019-07-15 17:44:10 +0200853 char *value = NULL;
854 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200855 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200856
857 /* organization element */
858 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100859 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
860 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200861 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100862 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORGANIZATION);
863 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LY_STMT_ORGANIZATION);
Radek Iša56ca9e42020-09-08 18:42:00 +0200864
David Sedlák32488102019-07-15 17:44:10 +0200865 assert_string_equal(value, "organization...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100866 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200867 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200868 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200869 exts = NULL;
870
David Sedlák32488102019-07-15 17:44:10 +0200871 /* contact element */
872 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100873 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
874 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200875 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100876 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200877 assert_string_equal(value, "contact...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100878 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200879 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200880 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200881 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200882
David Sedlák32488102019-07-15 17:44:10 +0200883 /* description element */
884 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100885 "<description><text>description...</text>" EXT_SUBELEM "</description>"
886 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200887 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100888 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200889 assert_string_equal(value, "description...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100890 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200891 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200892 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200893 exts = NULL;
894
David Sedlák32488102019-07-15 17:44:10 +0200895 /* reference element */
896 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100897 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
898 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200899 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200900 assert_string_equal(value, "reference...");
Radek Krejcifc596f92021-02-26 22:40:26 +0100901 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REFERENCE);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100902 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200903 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200904 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200905 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200906
David Sedlákdf2a9732019-08-07 13:23:16 +0200907 /* reference element */
908 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100909 "<reference invalid=\"text\"><text>reference...</text>" "</reference>"
910 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200911 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
912 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100913 lydict_remove(UTEST_LYCTX, value);
David Sedlákdf2a9732019-08-07 13:23:16 +0200914 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200915 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákdf2a9732019-08-07 13:23:16 +0200916 exts = NULL;
917
David Sedlák32488102019-07-15 17:44:10 +0200918 /* missing text subelement */
919 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100920 "<reference>reference...</reference>"
921 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200922 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
923 CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +0200924
David Sedlákd1144562019-08-06 12:36:14 +0200925 /* reference element */
926 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100927 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
928 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200929 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
930 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 +0100931 lydict_remove(UTEST_LYCTX, value);
David Sedlákd1144562019-08-06 12:36:14 +0200932 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200933 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200934 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200935}
936
937static void
938test_import_elem(void **state)
939{
David Sedlák32488102019-07-15 17:44:10 +0200940 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +0200941 struct lysp_import *imports = NULL;
942 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +0200943
944 /* max subelems */
945 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100946 "<import module=\"a\">\n"
947 EXT_SUBELEM
948 " <prefix value=\"a_mod\"/>\n"
949 " <revision-date date=\"2015-01-01\"></revision-date>\n"
950 " <description><text>import description</text></description>\n"
951 " <reference><text>import reference</text></reference>\n"
952 "</import>"
953 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200954 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
955 CHECK_LYSP_IMPORT(imports, "import description", 1, "a",
956 "a_mod", "import reference", "2015-01-01");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100957 TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LY_STMT_IMPORT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200958 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200959 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200960
961 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +0200962 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100963 "<import module=\"a\">\n"
964 " <prefix value=\"a_mod\"/>\n"
965 "</import>"
966 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200967 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
968 CHECK_LYSP_IMPORT(imports, NULL, 0, "a",
969 "a_mod", NULL, "");
970 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200971 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200972
973 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +0200974 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200975 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
976 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1.");
977 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200978 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200979
980 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +0200981 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100982 "<import module=\"a\">\n"
983 " <prefix value=\"prefix\"/>\n"
984 "</import>"
985 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200986 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
987 CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3.");
988 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200989 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200990
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100991 data = ELEMENT_WRAPPER_START
992 "<import module=\"a\">\n"
993 " <prefix value=\"a\"/>\n"
994 "</import>\n"
995 "<import module=\"a\">\n"
996 " <prefix value=\"a\"/>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200997 "</import>\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100998 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200999 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
1000 CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6.");
1001 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001002 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001003}
1004
1005static void
1006test_status_elem(void **state)
1007{
David Sedlák32488102019-07-15 17:44:10 +02001008 const char *data;
1009 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001010 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001011
1012 /* test valid values */
1013 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" 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_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001016
1017 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001018 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001019 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001020
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001021 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001022 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001023 assert_true(flags & LYS_STATUS_OBSLT);
Radek Krejcifc596f92021-02-26 22:40:26 +01001024 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_STATUS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001025 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001026 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001027
1028 /* test invalid value */
1029 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001030 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1031 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. "
1032 "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001033}
1034
1035static void
1036test_ext_elem(void **state)
1037{
David Sedlák32488102019-07-15 17:44:10 +02001038 const char *data;
1039 struct lysp_ext *ext = NULL;
1040
1041 /* max subelems */
1042 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001043 "<extension name=\"ext_name\">\n"
1044 " <argument name=\"arg\"></argument>\n"
1045 " <status value=\"current\"/>\n"
1046 " <description><text>ext_desc</text></description>\n"
1047 " <reference><text>ext_ref</text></reference>\n"
1048 EXT_SUBELEM
1049 "</extension>"
1050 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001051 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1052 CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001053 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LY_STMT_EXTENSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001054 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001055 LY_ARRAY_FREE(ext);
1056 ext = NULL;
1057
1058 /* min subelems */
1059 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001060 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1061 CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL);
1062 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001063 LY_ARRAY_FREE(ext);
1064 ext = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001065}
1066
1067static void
1068test_yin_element_elem(void **state)
1069{
David Sedlák32488102019-07-15 17:44:10 +02001070 const char *data;
1071 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001072 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001073
1074 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001075 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001076 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001077
David Sedlákd1144562019-08-06 12:36:14 +02001078 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001079 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001080 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001081 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YIN_ELEMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001082 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001083
1084 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001085 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001086 assert_true(flags & LYS_YINELEM_TRUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001087 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. "
1088 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001089}
1090
1091static void
1092test_yangversion_elem(void **state)
1093{
David Sedlák32488102019-07-15 17:44:10 +02001094 const char *data;
1095 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001096 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001097
1098 /* valid values */
Radek Krejci96e48da2020-09-04 13:18:06 +02001099 data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001100 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001101 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001102
David Sedlákd1144562019-08-06 12:36:14 +02001103 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001104 assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001105 assert_true(version & LYS_VERSION_1_1);
Radek Krejcifc596f92021-02-26 22:40:26 +01001106 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YANG_VERSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001107 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001108
1109 /* invalid value */
1110 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001111 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID);
1112 CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. "
1113 "Valid values are \"1\" and \"1.1\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001114}
1115
1116static void
1117test_mandatory_elem(void **state)
1118{
David Sedlák32488102019-07-15 17:44:10 +02001119 const char *data;
1120 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001121 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001122
1123 /* valid values */
1124 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001125 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001126 assert_int_equal(man, LYS_MAND_TRUE);
1127 man = 0;
1128
David Sedlákd1144562019-08-06 12:36:14 +02001129 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001130 assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001131 assert_int_equal(man, LYS_MAND_FALSE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001132 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MANDATORY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001133 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001134
1135 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001136 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID);
1137 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. "
1138 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001139}
1140
David Sedlák8e7bda82019-07-16 17:57:50 +02001141static void
1142test_argument_elem(void **state)
1143{
David Sedlák8e7bda82019-07-16 17:57:50 +02001144 const char *data;
1145 uint16_t flags = 0;
1146 const char *arg;
1147 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001148 struct lysp_ext_instance *exts = NULL;
1149
David Sedlák8e7bda82019-07-16 17:57:50 +02001150 /* max subelems */
1151 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001152 "<argument name=\"arg-name\">\n"
1153 " <yin-element value=\"true\" />\n"
1154 EXT_SUBELEM
1155 "</argument>"
1156 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001157 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001158 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001159 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001160 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ARGUMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001161 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001162 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001163 flags = 0;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001164 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001165 arg = NULL;
1166
1167 /* min subelems */
1168 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001169 "<argument name=\"arg\">"
1170 "</argument>"
1171 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001172 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001173 assert_string_equal(arg, "arg");
1174 assert_true(flags == 0);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001175 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001176}
1177
1178static void
1179test_base_elem(void **state)
1180{
David Sedlák8e7bda82019-07-16 17:57:50 +02001181 const char *data;
1182 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001183 struct lysp_ext_instance *exts = NULL;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001184 struct lysp_type type = {0};
David Sedlák8e7bda82019-07-16 17:57:50 +02001185
1186 /* as identity subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001187 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1188 " <base name=\"base-name\">\n"
1189 EXT_SUBELEM
1190 " </base>\n"
1191 "</identity>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001192 assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001193 assert_string_equal(*bases, "base-name");
Radek Krejcifc596f92021-02-26 22:40:26 +01001194 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001195 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001196 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001197 lydict_remove(UTEST_LYCTX, *bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001198 LY_ARRAY_FREE(bases);
1199
1200 /* as type subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001201 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1202 " <base name=\"base-name\">\n"
1203 EXT_SUBELEM
1204 " </base>\n"
1205 "</type>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001206 assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001207 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001208 assert_true(type.flags & LYS_SET_BASE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001209 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001210 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001211 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001212 lydict_remove(UTEST_LYCTX, *type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001213 LY_ARRAY_FREE(type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001214}
1215
1216static void
1217test_belongsto_elem(void **state)
1218{
David Sedlák8e7bda82019-07-16 17:57:50 +02001219 const char *data;
1220 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001221 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001222
Michal Vasko8a67eff2021-12-07 14:04:47 +01001223 lydict_insert(UTEST_LYCTX, "module-name", 0, &PARSER_CUR_PMOD(YCTX)->mod->name);
Radek Iša56ca9e42020-09-08 18:42:00 +02001224
David Sedlák8e7bda82019-07-16 17:57:50 +02001225 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001226 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
1227 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001228 assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001229 assert_string_equal(submod.prefix, "pref");
Radek Krejcifc596f92021-02-26 22:40:26 +01001230 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BELONGS_TO);
Radek Iša56ca9e42020-09-08 18:42:00 +02001231 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001232 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001233 lydict_remove(UTEST_LYCTX, submod.prefix);
David Sedlák8e7bda82019-07-16 17:57:50 +02001234
1235 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001236 assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID);
1237 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001238}
1239
1240static void
1241test_config_elem(void **state)
1242{
David Sedlák8e7bda82019-07-16 17:57:50 +02001243 const char *data;
1244 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001245 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001246
David Sedlákd1144562019-08-06 12:36:14 +02001247 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001248 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001249 assert_true(flags & LYS_CONFIG_W);
Radek Krejcifc596f92021-02-26 22:40:26 +01001250 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONFIG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001251 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001252 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001253 flags = 0;
1254
1255 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001256 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001257 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001258 flags = 0;
1259
1260 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001261 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1262 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. "
1263 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001264}
1265
1266static void
1267test_default_elem(void **state)
1268{
David Sedlák8e7bda82019-07-16 17:57:50 +02001269 const char *data;
Michal Vasko7f45cf22020-10-01 12:49:44 +02001270 struct lysp_qname val = {0};
David Sedlákd1144562019-08-06 12:36:14 +02001271 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001272
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001273 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001274 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001275 assert_string_equal(val.str, "defaul-value");
Radek Krejcifc596f92021-02-26 22:40:26 +01001276 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DEFAULT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001277 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001278 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001279 lydict_remove(UTEST_LYCTX, val.str);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001280 val.str = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001281
1282 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001283 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1284 CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001285}
1286
1287static void
1288test_err_app_tag_elem(void **state)
1289{
David Sedlák8e7bda82019-07-16 17:57:50 +02001290 const char *data;
1291 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001292 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001293
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001294 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 +02001295 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001296 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001297 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_APP_TAG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001298 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001299 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001300 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001301 val = NULL;
1302
1303 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001304 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1305 CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001306}
1307
1308static void
1309test_err_msg_elem(void **state)
1310{
David Sedlák8e7bda82019-07-16 17:57:50 +02001311 const char *data;
1312 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001313 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001314
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001315 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001316 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001317 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001318 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_MESSAGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001319 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001320 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001321 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001322
1323 data = ELEMENT_WRAPPER_START "<error-message></error-message>" 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("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001326
David Sedlákdf2a9732019-08-07 13:23:16 +02001327 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001328 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1329 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001330}
1331
1332static void
1333test_fracdigits_elem(void **state)
1334{
David Sedlák8e7bda82019-07-16 17:57:50 +02001335 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001336 struct lysp_type type = {0};
David Sedlák8e7bda82019-07-16 17:57:50 +02001337
1338 /* valid value */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001339 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001340 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
Radek Krejci5984d222021-02-26 23:01:45 +01001341 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_FRACTION_DIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001342 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001343 assert_true(type.flags & LYS_SET_FRDIGITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001344 FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001345
1346 /* invalid values */
1347 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></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 \"-1\" 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=\"02\"></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 \"02\" 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=\"1p\"></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 \"1p\" 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=\"19\"></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 \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001362
1363 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001364 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1365 CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001366}
1367
1368static void
1369test_iffeature_elem(void **state)
1370{
David Sedlák8e7bda82019-07-16 17:57:50 +02001371 const char *data;
1372 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001373 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001374
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001375 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001376 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001377 assert_string_equal(*iffeatures, "local-storage");
Radek Krejci5984d222021-02-26 23:01:45 +01001378 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_IF_FEATURE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001379 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001380 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001381 lydict_remove(UTEST_LYCTX, *iffeatures);
David Sedlák8e7bda82019-07-16 17:57:50 +02001382 LY_ARRAY_FREE(iffeatures);
1383 iffeatures = NULL;
1384
1385 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001386 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID);
1387 CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001388 LY_ARRAY_FREE(iffeatures);
1389 iffeatures = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001390}
1391
1392static void
1393test_length_elem(void **state)
1394{
David Sedlák8e7bda82019-07-16 17:57:50 +02001395 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001396 struct lysp_type type = {0};
David Sedlák8e7bda82019-07-16 17:57:50 +02001397
1398 /* max subelems */
1399 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001400 "<length value=\"length-str\">\n"
1401 " <error-message><value>err-msg</value></error-message>\n"
1402 " <error-app-tag value=\"err-app-tag\"/>\n"
1403 " <description><text>desc</text></description>\n"
1404 " <reference><text>ref</text></reference>\n"
1405 EXT_SUBELEM
1406 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001407 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001408 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1409 CHECK_LYSP_RESTR(type.length, "length-str", "desc",
1410 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001411 assert_true(type.flags & LYS_SET_LENGTH);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001412 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LY_STMT_LENGTH);
Radek Iša56ca9e42020-09-08 18:42:00 +02001413 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001414 memset(&type, 0, sizeof(type));
1415
1416 /* min subelems */
1417 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001418 "<length value=\"length-str\">"
1419 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001420 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001421 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1422 CHECK_LYSP_RESTR(type.length, "length-str", NULL,
1423 NULL, NULL, 0, NULL);
1424 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001425 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001426 memset(&type, 0, sizeof(type));
1427
1428 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001429 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1430 CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
1431 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001432 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001433}
1434
1435static void
1436test_modifier_elem(void **state)
1437{
David Sedlák8e7bda82019-07-16 17:57:50 +02001438 const char *data;
Radek Krejci011e4aa2020-09-04 15:22:31 +02001439 const char *pat;
David Sedlákd1144562019-08-06 12:36:14 +02001440 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001441
Radek Iša56ca9e42020-09-08 18:42:00 +02001442 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlákd1144562019-08-06 12:36:14 +02001443 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001444 assert_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001445 assert_string_equal(pat, "\x015pattern");
Radek Krejci5984d222021-02-26 23:01:45 +01001446 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MODIFIER);
Radek Iša56ca9e42020-09-08 18:42:00 +02001447 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001448 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001449 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001450
Radek Iša56ca9e42020-09-08 18:42:00 +02001451 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlák8e7bda82019-07-16 17:57:50 +02001452 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001453 assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID);
1454 CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. "
1455 "Only valid value is \"invert-match\".", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001456 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001457}
1458
1459static void
1460test_namespace_elem(void **state)
1461{
David Sedlák8e7bda82019-07-16 17:57:50 +02001462 const char *data;
1463 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001464 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001465
David Sedlákd1144562019-08-06 12:36:14 +02001466 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001467 assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001468 assert_string_equal(ns, "ns");
Radek Krejci5984d222021-02-26 23:01:45 +01001469 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_NAMESPACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001470 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001471 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001472 lydict_remove(UTEST_LYCTX, ns);
David Sedlák8e7bda82019-07-16 17:57:50 +02001473
1474 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001475 assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID);
1476 CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001477}
1478
1479static void
David Sedlák8e7bda82019-07-16 17:57:50 +02001480test_pattern_elem(void **state)
1481{
David Sedlák8e7bda82019-07-16 17:57:50 +02001482 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001483 struct lysp_type type = {0};
David Sedlák8e7bda82019-07-16 17:57:50 +02001484
1485 /* max subelems */
1486 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001487 "<pattern value=\"super_pattern\">\n"
1488 " <modifier value=\"invert-match\"/>\n"
1489 " <error-message><value>err-msg-value</value></error-message>\n"
1490 " <error-app-tag value=\"err-app-tag-value\"/>\n"
1491 " <description><text>&quot;pattern-desc&quot;</text></description>\n"
1492 " <reference><text>pattern-ref</text></reference>\n"
1493 EXT_SUBELEM
1494 "</pattern>"
1495 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001496 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001497 assert_true(type.flags & LYS_SET_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001498 CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
1499 "err-app-tag-value", "err-msg-value", 1, "pattern-ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001500 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LY_STMT_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001501 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001502 memset(&type, 0, sizeof(type));
1503
1504 /* min subelems */
1505 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001506 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1507 CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
1508 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001509 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001510}
1511
1512static void
1513test_value_position_elem(void **state)
1514{
David Sedlák8e7bda82019-07-16 17:57:50 +02001515 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001516 struct lysp_type_enum en = {0};
David Sedlák8e7bda82019-07-16 17:57:50 +02001517
1518 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001519 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001520 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1521 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001522 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_VALUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001523 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001524 memset(&en, 0, sizeof(en));
1525
1526 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001527 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1528 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55);
David Sedlák8e7bda82019-07-16 17:57:50 +02001529 memset(&en, 0, sizeof(en));
1530
1531 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001532 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1533 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001534 memset(&en, 0, sizeof(en));
1535
1536 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001537 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1538 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001539 memset(&en, 0, sizeof(en));
1540
1541 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001542 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001543 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1544 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001545 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_POSITION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001546 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001547 memset(&en, 0, sizeof(en));
1548
1549 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001550 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1551 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001552 memset(&en, 0, sizeof(en));
1553
1554 /* invalid values */
1555 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" 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 \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001558
1559 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" 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 \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001562
David Sedlák69f01612019-07-17 11:41:08 +02001563 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001564 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1565 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001566
David Sedlák8e7bda82019-07-16 17:57:50 +02001567 /*invalid positions */
1568 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" 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 \"-5\" 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=\"-0\"/>" 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 \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001575
1576 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" 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 \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001579
David Sedlák69f01612019-07-17 11:41:08 +02001580 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001581 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1582 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001583}
1584
1585static void
1586test_prefix_elem(void **state)
1587{
David Sedlák69f01612019-07-17 11:41:08 +02001588 const char *data;
1589 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001590 struct lysp_ext_instance *exts = NULL;
1591
1592 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001593 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001594 assert_string_equal(value, "pref");
Radek Krejci5984d222021-02-26 23:01:45 +01001595 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PREFIX);
Radek Iša56ca9e42020-09-08 18:42:00 +02001596 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001597 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001598 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001599
1600 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001601 assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001602 assert_string_equal(value, "pref");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001603 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001604}
1605
1606static void
1607test_range_elem(void **state)
1608{
David Sedlák69f01612019-07-17 11:41:08 +02001609 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001610 struct lysp_type type = {0};
David Sedlák69f01612019-07-17 11:41:08 +02001611
1612 /* max subelems */
1613 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001614 "<range value=\"range-str\">\n"
1615 " <error-message><value>err-msg</value></error-message>\n"
1616 " <error-app-tag value=\"err-app-tag\" />\n"
1617 " <description><text>desc</text></description>\n"
1618 " <reference><text>ref</text></reference>\n"
1619 EXT_SUBELEM
1620 "</range>"
1621 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001622 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1623 CHECK_LYSP_RESTR(type.range, "range-str", "desc",
1624 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001625 assert_true(type.flags & LYS_SET_RANGE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001626 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LY_STMT_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001627 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001628 memset(&type, 0, sizeof(type));
1629
1630 /* min subelems */
1631 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001632 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1633 CHECK_LYSP_RESTR(type.range, "range-str", NULL,
1634 NULL, NULL, 0, NULL);
1635 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001636 memset(&type, 0, sizeof(type));
David Sedlák69f01612019-07-17 11:41:08 +02001637}
1638
1639static void
1640test_reqinstance_elem(void **state)
1641{
David Sedlák69f01612019-07-17 11:41:08 +02001642 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001643 struct lysp_type type = {0};
David Sedlák69f01612019-07-17 11:41:08 +02001644
David Sedlákd1144562019-08-06 12:36:14 +02001645 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001646 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001647 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001648 assert_true(type.flags & LYS_SET_REQINST);
Radek Krejci5984d222021-02-26 23:01:45 +01001649 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_REQUIRE_INSTANCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001650 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001651 memset(&type, 0, sizeof(type));
1652
1653 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001654 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001655 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001656 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001657 memset(&type, 0, sizeof(type));
1658
1659 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001660 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001661 memset(&type, 0, sizeof(type));
Radek Iša56ca9e42020-09-08 18:42:00 +02001662 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. "
1663 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001664}
1665
1666static void
1667test_revision_date_elem(void **state)
1668{
David Sedlák69f01612019-07-17 11:41:08 +02001669 const char *data;
1670 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001671 struct lysp_ext_instance *exts = NULL;
1672
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001673 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 +02001674 assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001675 assert_string_equal(rev, "2000-01-01");
Radek Krejci5984d222021-02-26 23:01:45 +01001676 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REVISION_DATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001677 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001678
1679 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001680 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001681 assert_string_equal(rev, "2000-01-01");
1682
1683 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001684 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID);
1685 CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001686}
1687
1688static void
1689test_unique_elem(void **state)
1690{
David Sedlák69f01612019-07-17 11:41:08 +02001691 const char *data;
1692 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001693 struct lysp_ext_instance *exts = NULL;
1694
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001695 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001696 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001697 assert_string_equal(*values, "tag");
Radek Krejci5984d222021-02-26 23:01:45 +01001698 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNIQUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001699 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001700 lydict_remove(UTEST_LYCTX, *values);
David Sedlákd1144562019-08-06 12:36:14 +02001701 LY_ARRAY_FREE(values);
1702 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001703
1704 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001705 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001706 assert_string_equal(*values, "tag");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001707 lydict_remove(UTEST_LYCTX, *values);
David Sedlák69f01612019-07-17 11:41:08 +02001708 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001709 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001710}
1711
1712static void
1713test_units_elem(void **state)
1714{
David Sedlák69f01612019-07-17 11:41:08 +02001715 const char *data;
1716 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001717 struct lysp_ext_instance *exts = NULL;
1718
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001719 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001720 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001721 assert_string_equal(values, "name");
Radek Krejci5984d222021-02-26 23:01:45 +01001722 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001723 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001724 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001725 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001726
1727 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001728 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001729 assert_string_equal(values, "name");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001730 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001731 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001732}
1733
1734static void
1735test_when_elem(void **state)
1736{
David Sedlák69f01612019-07-17 11:41:08 +02001737 const char *data;
1738 struct lysp_when *when = NULL;
1739
1740 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001741 "<when condition=\"cond\">\n"
1742 " <description><text>desc</text></description>\n"
1743 " <reference><text>ref</text></reference>\n"
1744 EXT_SUBELEM
1745 "</when>"
1746 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001747 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1748 CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001749 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]), LY_STMT_WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001750 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001751 free(when);
1752 when = NULL;
1753
1754 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001755 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1756 CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL);
1757 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001758 free(when);
1759 when = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001760}
1761
1762static void
1763test_yin_text_value_elem(void **state)
1764{
David Sedlák69f01612019-07-17 11:41:08 +02001765 const char *data;
1766 const char *val;
1767
1768 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001769 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001770 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001771 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001772
1773 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 +02001774 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001775 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001776 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001777
1778 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001779 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001780 assert_string_equal("", val);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001781 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001782}
David Sedlák32488102019-07-15 17:44:10 +02001783
David Sedlák374d2b32019-07-17 15:06:55 +02001784static void
1785test_type_elem(void **state)
1786{
David Sedlák374d2b32019-07-17 15:06:55 +02001787 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001788 struct lysp_type type = {0};
David Sedlák374d2b32019-07-17 15:06:55 +02001789
1790 /* max subelems */
1791 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001792 "<type name=\"type-name\">\n"
1793 " <base name=\"base-name\"/>\n"
1794 " <bit name=\"bit\"/>\n"
1795 " <enum name=\"enum\"/>\n"
1796 " <fraction-digits value=\"2\"/>\n"
1797 " <length value=\"length\"/>\n"
1798 " <path value=\"/path\"/>\n"
1799 " <pattern value=\"pattern\"/>\n"
1800 " <range value=\"range\" />\n"
1801 " <require-instance value=\"true\"/>\n"
1802 " <type name=\"sub-type-name\"/>\n"
1803 EXT_SUBELEM
1804 "</type>"
1805 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001806 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02001807 assert_string_equal(type.name, "type-name");
1808 assert_string_equal(*type.bases, "base-name");
1809 assert_string_equal(type.bits->name, "bit");
1810 assert_string_equal(type.enums->name, "enum");
1811 assert_int_equal(type.fraction_digits, 2);
Radek Iša56ca9e42020-09-08 18:42:00 +02001812 CHECK_LYSP_RESTR(type.length, "length", NULL,
1813 NULL, NULL, 0, NULL);
Michal Vaskocb8c6d42020-10-16 11:58:30 +02001814 assert_string_equal(type.path->expr, "/path");
Radek Iša56ca9e42020-09-08 18:42:00 +02001815 CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL,
1816 NULL, NULL, 0, NULL);
1817 CHECK_LYSP_RESTR(type.range, "range", NULL,
1818 NULL, NULL, 0, NULL);
David Sedlák374d2b32019-07-17 15:06:55 +02001819 assert_int_equal(type.require_instance, 1);
1820 assert_string_equal(type.types->name, "sub-type-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001821 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_TYPE);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001822 assert_true(type.flags & LYS_SET_BASE);
1823 assert_true(type.flags & LYS_SET_BIT);
1824 assert_true(type.flags & LYS_SET_ENUM);
1825 assert_true(type.flags & LYS_SET_FRDIGITS);
1826 assert_true(type.flags & LYS_SET_LENGTH);
1827 assert_true(type.flags & LYS_SET_PATH);
1828 assert_true(type.flags & LYS_SET_PATTERN);
1829 assert_true(type.flags & LYS_SET_RANGE);
1830 assert_true(type.flags & LYS_SET_REQINST);
1831 assert_true(type.flags & LYS_SET_TYPE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001832 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001833 memset(&type, 0, sizeof(type));
1834
1835 /* min subelems */
1836 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001837 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1838 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001839 memset(&type, 0, sizeof(type));
David Sedlák374d2b32019-07-17 15:06:55 +02001840}
1841
David Sedlák1af868e2019-07-17 17:03:14 +02001842static void
1843test_max_elems_elem(void **state)
1844{
David Sedlák1af868e2019-07-17 17:03:14 +02001845 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001846 struct lysp_node_list list = {0};
1847 struct lysp_node_leaflist llist = {0};
1848 struct lysp_refine refine = {0};
David Sedlák1af868e2019-07-17 17:03:14 +02001849
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001850 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 +02001851 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001852 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001853 assert_true(refine.flags & LYS_SET_MAX);
Radek Krejci5984d222021-02-26 23:01:45 +01001854 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001855 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001856
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001857 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 +02001858 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001859 assert_int_equal(list.max, 5);
Radek Iša56ca9e42020-09-08 18:42:00 +02001860 CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001861 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001862 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001863
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001864 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 +02001865 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001866 assert_int_equal(llist.max, 85);
Radek Iša56ca9e42020-09-08 18:42:00 +02001867 CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001868 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001869 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001870
1871 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001872 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001873 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001874 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001875
1876 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </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 \"0\" 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=\"-10\"/> </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 \"-10\" 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=\"k\"/> </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 \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001887
1888 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001889 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1890 CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001891}
1892
David Sedlák09e18c92019-07-18 11:17:11 +02001893static void
1894test_min_elems_elem(void **state)
1895{
David Sedlák09e18c92019-07-18 11:17:11 +02001896 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02001897 struct lysp_node_list list = {0};
1898 struct lysp_node_leaflist llist = {0};
1899 struct lysp_refine refine = {0};
David Sedlák09e18c92019-07-18 11:17:11 +02001900
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001901 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 +02001902 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001903 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001904 assert_true(refine.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001905 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001906 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001907
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001908 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 +02001909 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001910 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001911 assert_true(list.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001912 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001913 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001914
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001915 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 +02001916 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001917 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001918 assert_true(llist.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001919 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001920 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
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=\"-5\"/> </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 \"-5\" 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=\"99999999999999999\"/> </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("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "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=\"5k\"/> </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 \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001933
1934 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 +02001935 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1936 CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001937}
1938
David Sedláka2dad212019-07-18 12:45:19 +02001939static void
1940test_ordby_elem(void **state)
1941{
David Sedláka2dad212019-07-18 12:45:19 +02001942 const char *data;
1943 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001944 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02001945
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001946 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001947 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001948 assert_true(flags & LYS_ORDBY_SYSTEM);
Radek Krejci5984d222021-02-26 23:01:45 +01001949 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORDERED_BY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001950 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02001951
1952 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001953 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001954 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001955
1956 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001957 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1958 CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. "
1959 "Valid values are \"system\" and \"user\".", "Line number 1.");
David Sedláka2dad212019-07-18 12:45:19 +02001960}
1961
David Sedlák8a83bbb2019-07-18 14:46:00 +02001962static void
1963test_any_elem(void **state)
1964{
David Sedlák8a83bbb2019-07-18 14:46:00 +02001965 const char *data;
1966 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02001967 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02001968 struct lysp_node_anydata *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02001969 uint16_t flags;
David Sedlák8a83bbb2019-07-18 14:46:00 +02001970
1971 /* anyxml max subelems */
1972 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001973 "<anyxml name=\"any-name\">\n"
1974 " <config value=\"true\" />\n"
1975 " <description><text>desc</text></description>\n"
1976 " <if-feature name=\"feature\" />\n"
1977 " <mandatory value=\"true\" />\n"
1978 " <must condition=\"must-cond\" />\n"
1979 " <reference><text>ref</text></reference>\n"
1980 " <status value=\"deprecated\"/>\n"
1981 " <when condition=\"when-cond\"/>\n"
1982 EXT_SUBELEM
1983 "</anyxml>"
1984 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001985 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001986 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02001987 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
1988 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
1989 "any-name", 0, LYS_ANYXML, 0, "ref", 1);
1990 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001991 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001992 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYXML);
Radek Iša56ca9e42020-09-08 18:42:00 +02001993 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001994 siblings = NULL;
1995
1996 /* anydata max subelems */
1997 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001998 "<anydata name=\"any-name\">\n"
1999 " <config value=\"true\" />\n"
2000 " <description><text>desc</text></description>\n"
2001 " <if-feature name=\"feature\" />\n"
2002 " <mandatory value=\"true\" />\n"
2003 " <must condition=\"must-cond\" />\n"
2004 " <reference><text>ref</text></reference>\n"
2005 " <status value=\"deprecated\"/>\n"
2006 " <when condition=\"when-cond\"/>\n"
2007 EXT_SUBELEM
2008 "</anydata>"
2009 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002010 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002011 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002012 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2013 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2014 "any-name", 0, LYS_ANYDATA, 0, "ref", 1);
2015 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002016 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002017 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYDATA);
Radek Iša56ca9e42020-09-08 18:42:00 +02002018 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002019 siblings = NULL;
2020
2021 /* min subelems */
2022 node_meta.parent = (void *)0x10;
2023 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002024 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002025 parsed = (struct lysp_node_anydata *)siblings;
2026 assert_ptr_equal(parsed->parent, node_meta.parent);
Radek Iša56ca9e42020-09-08 18:42:00 +02002027 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2028 "any-name", 0, LYS_ANYDATA, 1, NULL, 0);
2029 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002030}
2031
David Sedlák203ca3a2019-07-18 15:26:25 +02002032static void
2033test_leaf_elem(void **state)
2034{
David Sedlák203ca3a2019-07-18 15:26:25 +02002035 const char *data;
2036 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002037 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002038 struct lysp_node_leaf *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002039 uint16_t flags;
David Sedlák203ca3a2019-07-18 15:26:25 +02002040
2041 /* max elements */
2042 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002043 "<leaf name=\"leaf\">\n"
2044 " <config value=\"true\" />\n"
2045 " <default value=\"def-val\"/>\n"
2046 " <description><text>desc</text></description>\n"
2047 " <if-feature name=\"feature\" />\n"
2048 " <mandatory value=\"true\" />\n"
2049 " <must condition=\"must-cond\" />\n"
2050 " <reference><text>ref</text></reference>\n"
2051 " <status value=\"deprecated\"/>\n"
2052 " <type name=\"type\"/>\n"
2053 " <units name=\"uni\"/>\n"
2054 " <when condition=\"when-cond\"/>\n"
2055 EXT_SUBELEM
2056 "</leaf>"
David Sedlák203ca3a2019-07-18 15:26:25 +02002057 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002058 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002059 parsed = (struct lysp_node_leaf *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002060 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2061 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2062 "leaf", 0, LYS_LEAF, 0, "ref", 1);
2063 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002064 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002065 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002066 assert_string_equal(parsed->musts->arg.str, "must-cond");
David Sedlák203ca3a2019-07-18 15:26:25 +02002067 assert_string_equal(parsed->type.name, "type");
2068 assert_string_equal(parsed->units, "uni");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002069 assert_string_equal(parsed->dflt.str, "def-val");
Radek Iša56ca9e42020-09-08 18:42:00 +02002070 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002071 siblings = NULL;
2072
2073 /* min elements */
2074 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002075 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002076 parsed = (struct lysp_node_leaf *)siblings;
2077 assert_string_equal(parsed->name, "leaf");
2078 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002079 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002080 siblings = NULL;
David Sedlák203ca3a2019-07-18 15:26:25 +02002081}
2082
David Sedlákc3da3ef2019-07-19 12:56:08 +02002083static void
2084test_leaf_list_elem(void **state)
2085{
David Sedlákc3da3ef2019-07-19 12:56:08 +02002086 const char *data;
2087 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002088 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002089 struct lysp_node_leaflist *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002090 uint16_t flags;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002091
2092 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002093 "<leaf-list name=\"llist\">\n"
2094 " <config value=\"true\" />\n"
2095 " <default value=\"def-val0\"/>\n"
2096 " <default value=\"def-val1\"/>\n"
2097 " <description><text>desc</text></description>\n"
2098 " <if-feature name=\"feature\"/>\n"
2099 " <max-elements value=\"5\"/>\n"
2100 " <must condition=\"must-cond\"/>\n"
2101 " <ordered-by value=\"user\" />\n"
2102 " <reference><text>ref</text></reference>\n"
2103 " <status value=\"current\"/>\n"
2104 " <type name=\"type\"/>\n"
2105 " <units name=\"uni\"/>\n"
2106 " <when condition=\"when-cond\"/>\n"
2107 EXT_SUBELEM
2108 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002109 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002110 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002111 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002112 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX;
2113 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2114 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2115 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002116 assert_string_equal(parsed->dflts[0].str, "def-val0");
2117 assert_string_equal(parsed->dflts[1].str, "def-val1");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002118 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002119 assert_int_equal(parsed->max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002120 assert_string_equal(parsed->type.name, "type");
2121 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002122 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002123 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002124 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002125 siblings = NULL;
2126
2127 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002128 "<leaf-list name=\"llist\">\n"
2129 " <config value=\"true\" />\n"
2130 " <description><text>desc</text></description>\n"
2131 " <if-feature name=\"feature\"/>\n"
2132 " <min-elements value=\"5\"/>\n"
2133 " <must condition=\"must-cond\"/>\n"
2134 " <ordered-by value=\"user\" />\n"
2135 " <reference><text>ref</text></reference>\n"
2136 " <status value=\"current\"/>\n"
2137 " <type name=\"type\"/>\n"
2138 " <units name=\"uni\"/>\n"
2139 " <when condition=\"when-cond\"/>\n"
2140 EXT_SUBELEM
2141 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002142 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002143 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002144 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002145 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN;
2146 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2147 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2148 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2149 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002150 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002151 assert_int_equal(parsed->min, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002152 assert_string_equal(parsed->type.name, "type");
2153 assert_string_equal(parsed->units, "uni");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002154 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002155 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002156 siblings = NULL;
2157
2158 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002159 "<leaf-list name=\"llist\">\n"
2160 " <config value=\"true\" />\n"
2161 " <description><text>desc</text></description>\n"
2162 " <if-feature name=\"feature\"/>\n"
2163 " <max-elements value=\"15\"/>\n"
2164 " <min-elements value=\"5\"/>\n"
2165 " <must condition=\"must-cond\"/>\n"
2166 " <ordered-by value=\"user\" />\n"
2167 " <reference><text>ref</text></reference>\n"
2168 " <status value=\"current\"/>\n"
2169 " <type name=\"type\"/>\n"
2170 " <units name=\"uni\"/>\n"
2171 " <when condition=\"when-cond\"/>\n"
2172 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002173 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002174 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002175 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002176 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX;
2177 CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1,
2178 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2179 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2180 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002181 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002182 assert_int_equal(parsed->min, 5);
2183 assert_int_equal(parsed->max, 15);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002184 assert_string_equal(parsed->type.name, "type");
2185 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002186 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002187 siblings = NULL;
2188
2189 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002190 "<leaf-list name=\"llist\">\n"
2191 " <type name=\"type\"/>\n"
2192 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002193 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002194 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002195 parsed = (struct lysp_node_leaflist *)siblings;
2196 assert_string_equal(parsed->name, "llist");
2197 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002198 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002199 siblings = NULL;
2200
2201 /* invalid combinations */
2202 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002203 "<leaf-list name=\"llist\">\n"
2204 " <max-elements value=\"5\"/>\n"
2205 " <min-elements value=\"15\"/>\n"
2206 " <type name=\"type\"/>"
2207 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002208 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002209 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2210 CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
2211 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002212 siblings = NULL;
2213
2214 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002215 "<leaf-list name=\"llist\">\n"
2216 " <default value=\"def-val1\"/>\n"
2217 " <min-elements value=\"15\"/>\n"
2218 " <type name=\"type\"/>\n"
2219 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002220 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002221 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2222 CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
2223 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002224 siblings = NULL;
2225
2226 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002227 "<leaf-list name=\"llist\">"
2228 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002229 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002230 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2231 CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
2232 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002233 siblings = NULL;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002234}
2235
David Sedlákcb39f642019-07-19 13:19:55 +02002236static void
2237test_presence_elem(void **state)
2238{
David Sedlákcb39f642019-07-19 13:19:55 +02002239 const char *data;
2240 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002241 struct lysp_ext_instance *exts = NULL;
2242
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002243 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002244 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002245 assert_string_equal(val, "presence-val");
Radek Krejci5984d222021-02-26 23:01:45 +01002246 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PRESENCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002247 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002248 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002249
2250 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002251 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002252 assert_string_equal(val, "presence-val");
Michal Vaskoe180ed02021-02-05 16:31:20 +01002253 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002254
2255 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002256 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2257 CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1.");
David Sedlákcb39f642019-07-19 13:19:55 +02002258}
2259
David Sedlák12470a82019-07-19 13:44:36 +02002260static void
2261test_key_elem(void **state)
2262{
David Sedlák12470a82019-07-19 13:44:36 +02002263 const char *data;
2264 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002265 struct lysp_ext_instance *exts = NULL;
2266
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002267 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002268 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002269 assert_string_equal(val, "key-value");
Radek Krejci5984d222021-02-26 23:01:45 +01002270 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_KEY);
Radek Iša56ca9e42020-09-08 18:42:00 +02002271 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002272 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002273
2274 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002275 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002276 assert_string_equal(val, "key-value");
Michal Vaskoe180ed02021-02-05 16:31:20 +01002277 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002278
2279 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002280 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2281 CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1.");
David Sedlák12470a82019-07-19 13:44:36 +02002282}
2283
David Sedlák04e17b22019-07-19 15:29:48 +02002284static void
2285test_typedef_elem(void **state)
2286{
David Sedlák04e17b22019-07-19 15:29:48 +02002287 const char *data;
2288 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002289 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002290
2291 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002292 "<typedef name=\"tpdf-name\">\n"
2293 " <default value=\"def-val\"/>\n"
2294 " <description><text>desc-text</text></description>\n"
2295 " <reference><text>ref-text</text></reference>\n"
2296 " <status value=\"current\"/>\n"
2297 " <type name=\"type\"/>\n"
2298 " <units name=\"uni\"/>\n"
2299 EXT_SUBELEM
2300 "</typedef>"
2301 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002302 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002303 assert_string_equal(tpdfs[0].dflt.str, "def-val");
David Sedlák04e17b22019-07-19 15:29:48 +02002304 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002305 assert_string_equal(tpdfs[0].name, "tpdf-name");
2306 assert_string_equal(tpdfs[0].ref, "ref-text");
2307 assert_string_equal(tpdfs[0].type.name, "type");
2308 assert_string_equal(tpdfs[0].units, "uni");
2309 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002310 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]), LY_STMT_TYPEDEF);
Radek Iša56ca9e42020-09-08 18:42:00 +02002311 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002312 tpdfs = NULL;
2313
2314 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002315 "<typedef name=\"tpdf-name\">\n"
2316 " <type name=\"type\"/>\n"
2317 "</typedef>"
2318 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002319 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002320 assert_string_equal(tpdfs[0].name, "tpdf-name");
2321 assert_string_equal(tpdfs[0].type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002322 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002323 tpdfs = NULL;
David Sedlák04e17b22019-07-19 15:29:48 +02002324}
2325
David Sedlákd2d676a2019-07-22 11:28:19 +02002326static void
2327test_refine_elem(void **state)
2328{
David Sedlákd2d676a2019-07-22 11:28:19 +02002329 const char *data;
2330 struct lysp_refine *refines = NULL;
2331
2332 /* max subelems */
2333 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002334 "<refine target-node=\"target\">\n"
2335 " <if-feature name=\"feature\" />\n"
2336 " <must condition=\"cond\" />\n"
2337 " <presence value=\"presence\" />\n"
2338 " <default value=\"def\" />\n"
2339 " <config value=\"true\" />\n"
2340 " <mandatory value=\"true\" />\n"
2341 " <min-elements value=\"10\" />\n"
2342 " <max-elements value=\"20\" />\n"
2343 " <description><text>desc</text></description>\n"
2344 " <reference><text>ref</text></reference>\n"
2345 EXT_SUBELEM
2346 "</refine>"
2347 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002348 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002349 assert_string_equal(refines->nodeid, "target");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002350 assert_string_equal(refines->dflts[0].str, "def");
David Sedlákd2d676a2019-07-22 11:28:19 +02002351 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002352 assert_true(refines->flags & LYS_CONFIG_W);
2353 assert_true(refines->flags & LYS_MAND_TRUE);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002354 assert_string_equal(refines->iffeatures[0].str, "feature");
David Sedlákd2d676a2019-07-22 11:28:19 +02002355 assert_int_equal(refines->max, 20);
2356 assert_int_equal(refines->min, 10);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002357 assert_string_equal(refines->musts->arg.str, "cond");
David Sedlákd2d676a2019-07-22 11:28:19 +02002358 assert_string_equal(refines->presence, "presence");
2359 assert_string_equal(refines->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002360 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]), LY_STMT_REFINE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002361 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002362 refines = NULL;
2363
2364 /* min subelems */
2365 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002366 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002367 assert_string_equal(refines->nodeid, "target");
Radek Iša56ca9e42020-09-08 18:42:00 +02002368 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002369 refines = NULL;
David Sedlákd2d676a2019-07-22 11:28:19 +02002370}
2371
David Sedlák0d6de5a2019-07-22 13:25:44 +02002372static void
2373test_uses_elem(void **state)
2374{
David Sedlák0d6de5a2019-07-22 13:25:44 +02002375 const char *data;
2376 struct lysp_node *siblings = NULL;
2377 struct tree_node_meta node_meta = {NULL, &siblings};
2378 struct lysp_node_uses *parsed = NULL;
2379
2380 /* max subelems */
2381 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002382 "<uses name=\"uses-name\">\n"
2383 " <when condition=\"cond\" />\n"
2384 " <if-feature name=\"feature\" />\n"
2385 " <status value=\"obsolete\" />\n"
2386 " <description><text>desc</text></description>\n"
2387 " <reference><text>ref</text></reference>\n"
2388 " <refine target-node=\"target\"/>\n"
2389 " <augment target-node=\"target\" />\n"
2390 EXT_SUBELEM
2391 "</uses>"
2392 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002393 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002394 parsed = (struct lysp_node_uses *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002395 CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1,
2396 "uses-name", 0, LYS_USES, 0, "ref", 1);
2397 CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002398 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002399 assert_string_equal(parsed->refines->nodeid, "target");
David Sedlák992fb7c2019-07-24 16:51:01 +02002400 assert_string_equal(parsed->augments->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002401 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_USES);
Radek Iša56ca9e42020-09-08 18:42:00 +02002402 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002403 siblings = NULL;
2404
2405 /* min subelems */
2406 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002407 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002408 assert_string_equal(siblings[0].name, "uses-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002409 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002410 siblings = NULL;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002411}
2412
David Sedlákaa854b02019-07-22 14:17:10 +02002413static void
2414test_revision_elem(void **state)
2415{
David Sedlákaa854b02019-07-22 14:17:10 +02002416 const char *data;
2417 struct lysp_revision *revs = NULL;
2418
2419 /* max subelems */
2420 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002421 "<revision date=\"2018-12-25\">\n"
2422 " <description><text>desc</text></description>\n"
2423 " <reference><text>ref</text></reference>\n"
2424 EXT_SUBELEM
2425 "</revision>"
2426 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002427 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002428 assert_string_equal(revs->date, "2018-12-25");
2429 assert_string_equal(revs->dsc, "desc");
2430 assert_string_equal(revs->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002431 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]), LY_STMT_REVISION);
Radek Iša56ca9e42020-09-08 18:42:00 +02002432 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002433 revs = NULL;
2434
2435 /* min subelems */
2436 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002437 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002438 assert_string_equal(revs->date, "2005-05-05");
Radek Iša56ca9e42020-09-08 18:42:00 +02002439 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002440 revs = NULL;
2441
2442 /* invalid value */
2443 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002444 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID);
2445 CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1.");
2446 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002447 revs = NULL;
David Sedlákaa854b02019-07-22 14:17:10 +02002448}
2449
David Sedlák0c2bab92019-07-22 15:33:19 +02002450static void
2451test_include_elem(void **state)
2452{
David Sedlák0c2bab92019-07-22 15:33:19 +02002453 const char *data;
2454 struct lysp_include *includes = NULL;
2455 struct include_meta inc_meta = {"module-name", &includes};
2456
2457 /* max subelems */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002458 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák0c2bab92019-07-22 15:33:19 +02002459 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002460 "<include module=\"mod\">\n"
2461 " <description><text>desc</text></description>\n"
2462 " <reference><text>ref</text></reference>\n"
2463 " <revision-date date=\"1999-09-09\"/>\n"
2464 EXT_SUBELEM
2465 "</include>"
2466 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002467 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002468 assert_string_equal(includes->name, "mod");
2469 assert_string_equal(includes->dsc, "desc");
2470 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002471 assert_string_equal(includes->rev, "1999-09-09");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002472 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]), LY_STMT_INCLUDE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002473 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002474 includes = NULL;
2475
2476 /* min subelems */
2477 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002478 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002479 assert_string_equal(includes->name, "mod");
Radek Iša56ca9e42020-09-08 18:42:00 +02002480 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002481 includes = NULL;
2482
2483 /* invalid combinations */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002484 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002485 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002486 "<include module=\"mod\">\n"
2487 " <description><text>desc</text></description>\n"
2488 " <revision-date date=\"1999-09-09\"/>\n"
2489 "</include>"
2490 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002491 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2492 CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2493 "Line number 2.");
2494 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002495 includes = NULL;
2496
Michal Vasko8a67eff2021-12-07 14:04:47 +01002497 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002498 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002499 "<include module=\"mod\">\n"
2500 " <reference><text>ref</text></reference>\n"
2501 " <revision-date date=\"1999-09-09\"/>\n"
2502 "</include>"
2503 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002504 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2505 CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2506 "Line number 2.");
2507 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002508 includes = NULL;
David Sedlák0c2bab92019-07-22 15:33:19 +02002509}
2510
David Sedlák5e13dea2019-07-22 16:06:45 +02002511static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002512test_list_elem(void **state)
2513{
David Sedlákaf536aa2019-07-23 13:42:23 +02002514 const char *data;
2515 struct lysp_node *siblings = NULL;
2516 struct tree_node_meta node_meta = {NULL, &siblings};
2517 struct lysp_node_list *parsed = NULL;
2518
2519 /* max subelems */
2520 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002521 "<list name=\"list-name\">\n"
2522 " <when condition=\"when\"/>\n"
2523 " <if-feature name=\"iff\"/>\n"
2524 " <must condition=\"must-cond\"/>\n"
2525 " <key value=\"key\"/>\n"
2526 " <unique tag=\"utag\"/>\n"
2527 " <config value=\"true\"/>\n"
2528 " <min-elements value=\"10\"/>\n"
2529 " <ordered-by value=\"user\"/>\n"
2530 " <status value=\"deprecated\"/>\n"
2531 " <description><text>desc</text></description>\n"
2532 " <reference><text>ref</text></reference>\n"
2533 " <anydata name=\"anyd\"/>\n"
2534 " <anyxml name=\"anyx\"/>\n"
2535 " <container name=\"cont\"/>\n"
2536 " <choice name=\"choice\"/>\n"
2537 " <action name=\"action\"/>\n"
2538 " <grouping name=\"grp\"/>\n"
2539 " <notification name=\"notf\"/>\n"
2540 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2541 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2542 " <list name=\"sub-list\"/>\n"
2543 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2544 " <uses name=\"uses-name\"/>\n"
2545 EXT_SUBELEM
2546 "</list>"
2547 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002548 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002549 parsed = (struct lysp_node_list *)&siblings[0];
David Sedlákaf536aa2019-07-23 13:42:23 +02002550 assert_string_equal(parsed->child->name, "anyd");
2551 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2552 assert_string_equal(parsed->child->next->name, "anyx");
2553 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002554 assert_string_equal(parsed->child->next->next->name, "cont");
2555 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002556 assert_string_equal(parsed->child->next->next->next->name, "choice");
2557 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002558 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2559 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2560 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2561 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2562 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2563 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2564 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2565 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2566 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Iša56ca9e42020-09-08 18:42:00 +02002567 uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN;
2568
2569 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2570 "list-name", 0, LYS_LIST, 0, "ref", 1);
2571 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2572 CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002573 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002574 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002575 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002576 assert_string_equal(parsed->notifs->name, "notf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002577 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákaf536aa2019-07-23 13:42:23 +02002578 assert_string_equal(parsed->key, "key");
2579 assert_int_equal(parsed->min, 10);
David Sedlákaf536aa2019-07-23 13:42:23 +02002580 assert_string_equal(parsed->typedefs->name, "tpdf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002581 assert_string_equal(parsed->uniques->str, "utag");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002582 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002583 lysp_node_free(UTEST_LYCTX, siblings);
2584 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedlákaf536aa2019-07-23 13:42:23 +02002585 siblings = NULL;
2586
2587 /* min subelems */
2588 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002589 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002590 parsed = (struct lysp_node_list *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002591 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2592 "list-name", 0, LYS_LIST, 0, NULL, 0);
2593 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákaf536aa2019-07-23 13:42:23 +02002594 siblings = NULL;
David Sedlákaf536aa2019-07-23 13:42:23 +02002595}
2596
David Sedlák031b9e72019-07-23 15:19:37 +02002597static void
2598test_notification_elem(void **state)
2599{
David Sedlák031b9e72019-07-23 15:19:37 +02002600 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002601 struct lysp_node_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002602 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002603
2604 /* max subelems */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002605 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák031b9e72019-07-23 15:19:37 +02002606 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002607 "<notification name=\"notif-name\">\n"
2608 " <anydata name=\"anyd\"/>\n"
2609 " <anyxml name=\"anyx\"/>\n"
2610 " <description><text>desc</text></description>\n"
2611 " <if-feature name=\"iff\"/>\n"
2612 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2613 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2614 " <list name=\"sub-list\"/>\n"
2615 " <must condition=\"cond\"/>\n"
2616 " <reference><text>ref</text></reference>\n"
2617 " <status value=\"deprecated\"/>\n"
2618 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2619 " <uses name=\"uses-name\"/>\n"
2620 " <container name=\"cont\"/>\n"
2621 " <choice name=\"choice\"/>\n"
2622 " <grouping name=\"grp\"/>\n"
2623 EXT_SUBELEM
2624 "</notification>"
2625 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002626 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002627 assert_string_equal(notifs->name, "notif-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002628 assert_string_equal(notifs->child->name, "anyd");
2629 assert_int_equal(notifs->child->nodetype, LYS_ANYDATA);
2630 assert_string_equal(notifs->child->next->name, "anyx");
2631 assert_int_equal(notifs->child->next->nodetype, LYS_ANYXML);
2632 assert_string_equal(notifs->child->next->next->name, "leaf");
2633 assert_int_equal(notifs->child->next->next->nodetype, LYS_LEAF);
2634 assert_string_equal(notifs->child->next->next->next->name, "llist");
2635 assert_int_equal(notifs->child->next->next->next->nodetype, LYS_LEAFLIST);
2636 assert_string_equal(notifs->child->next->next->next->next->name, "sub-list");
2637 assert_int_equal(notifs->child->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02002638 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002639 assert_string_equal(notifs->groupings->name, "grp");
2640 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
Radek Krejci01180ac2021-01-27 08:48:22 +01002641 assert_string_equal(notifs->child->next->next->next->next->next->name, "uses-name");
2642 assert_int_equal(notifs->child->next->next->next->next->next->nodetype, LYS_USES);
2643 assert_string_equal(notifs->child->next->next->next->next->next->next->name, "cont");
2644 assert_int_equal(notifs->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2645 assert_int_equal(notifs->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2646 assert_string_equal(notifs->child->next->next->next->next->next->next->next->name, "choice");
2647 assert_null(notifs->child->next->next->next->next->next->next->next->next);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002648 assert_string_equal(notifs->iffeatures[0].str, "iff");
2649 assert_string_equal(notifs->musts->arg.str, "cond");
David Sedlák031b9e72019-07-23 15:19:37 +02002650 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2651 assert_null(notifs->parent);
2652 assert_string_equal(notifs->ref, "ref");
2653 assert_string_equal(notifs->typedefs->name, "tpdf");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002654 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LY_STMT_NOTIFICATION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002655 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedlák031b9e72019-07-23 15:19:37 +02002656 notifs = NULL;
2657
2658 /* min subelems */
2659 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002660 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002661 assert_string_equal(notifs->name, "notif-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002662 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002663 notifs = NULL;
David Sedláke3ce9ef2019-07-23 16:34:30 +02002664}
2665
2666static void
2667test_grouping_elem(void **state)
2668{
David Sedláke3ce9ef2019-07-23 16:34:30 +02002669 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002670 struct lysp_node_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002671 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02002672
2673 /* max subelems */
2674 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002675 "<grouping name=\"grp-name\">\n"
2676 " <anydata name=\"anyd\"/>\n"
2677 " <anyxml name=\"anyx\"/>\n"
2678 " <description><text>desc</text></description>\n"
2679 " <grouping name=\"sub-grp\"/>\n"
2680 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2681 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2682 " <list name=\"list\"/>\n"
2683 " <notification name=\"notf\"/>\n"
2684 " <reference><text>ref</text></reference>\n"
2685 " <status value=\"current\"/>\n"
2686 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2687 " <uses name=\"uses-name\"/>\n"
2688 " <action name=\"act\"/>\n"
2689 " <container name=\"cont\"/>\n"
2690 " <choice name=\"choice\"/>\n"
2691 EXT_SUBELEM
2692 "</grouping>"
2693 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002694 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002695 assert_string_equal(grps->name, "grp-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002696 assert_string_equal(grps->child->name, "anyd");
2697 assert_string_equal(grps->child->next->name, "anyx");
2698 assert_string_equal(grps->child->next->next->name, "leaf");
2699 assert_string_equal(grps->child->next->next->next->name, "llist");
2700 assert_string_equal(grps->child->next->next->next->next->name, "list");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002701 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002702 assert_true(grps->flags & LYS_STATUS_CURR);
2703 assert_string_equal(grps->groupings->name, "sub-grp");
2704 assert_int_equal(grps->nodetype, LYS_GROUPING);
2705 assert_string_equal(grps->notifs->name, "notf");
2706 assert_null(grps->parent);
2707 assert_string_equal(grps->ref, "ref");
2708 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002709 assert_string_equal(grps->actions->name, "act");
Radek Krejci01180ac2021-01-27 08:48:22 +01002710 assert_string_equal(grps->child->next->next->next->next->next->name, "uses-name");
2711 assert_int_equal(grps->child->next->next->next->next->next->nodetype, LYS_USES);
2712 assert_string_equal(grps->child->next->next->next->next->next->next->name, "cont");
2713 assert_int_equal(grps->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2714 assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice");
2715 assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002716 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LY_STMT_GROUPING);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002717 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002718 grps = NULL;
2719
2720 /* min subelems */
2721 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002722 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002723 assert_string_equal(grps->name, "grp-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002724 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002725 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002726}
2727
David Sedlákf111bcb2019-07-23 17:15:51 +02002728static void
2729test_container_elem(void **state)
2730{
David Sedlákf111bcb2019-07-23 17:15:51 +02002731 const char *data;
2732 struct lysp_node *siblings = NULL;
2733 struct tree_node_meta node_meta = {NULL, &siblings};
2734 struct lysp_node_container *parsed = NULL;
2735
2736 /* max subelems */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002737 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedláke2dc9e92019-07-24 09:59:21 +02002738 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002739 "<container name=\"cont-name\">\n"
2740 " <anydata name=\"anyd\"/>\n"
2741 " <anyxml name=\"anyx\"/>\n"
2742 " <config value=\"true\"/>\n"
2743 " <container name=\"subcont\"/>\n"
2744 " <description><text>desc</text></description>\n"
2745 " <grouping name=\"sub-grp\"/>\n"
2746 " <if-feature name=\"iff\"/>\n"
2747 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2748 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2749 " <list name=\"list\"/>\n"
2750 " <must condition=\"cond\"/>\n"
2751 " <notification name=\"notf\"/>\n"
2752 " <presence value=\"presence\"/>\n"
2753 " <reference><text>ref</text></reference>\n"
2754 " <status value=\"current\"/>\n"
2755 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2756 " <uses name=\"uses-name\"/>\n"
2757 " <when condition=\"when-cond\"/>\n"
2758 " <action name=\"act\"/>\n"
2759 " <choice name=\"choice\"/>\n"
2760 EXT_SUBELEM
2761 "</container>"
2762 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002763 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02002764 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002765 uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR;
2766
2767 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2768 "cont-name", 0, LYS_CONTAINER, 0, "ref", 1);
2769 CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL);
2770 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
2771
Michal Vasko7f45cf22020-10-01 12:49:44 +02002772 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02002773 assert_string_equal(parsed->presence, "presence");
2774 assert_string_equal(parsed->typedefs->name, "tpdf");
2775 assert_string_equal(parsed->groupings->name, "sub-grp");
2776 assert_string_equal(parsed->child->name, "anyd");
2777 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2778 assert_string_equal(parsed->child->next->name, "anyx");
2779 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2780 assert_string_equal(parsed->child->next->next->name, "subcont");
2781 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2782 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2783 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2784 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2785 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2786 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2787 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2788 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2789 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002790 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2791 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2792 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02002793 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002794 assert_string_equal(parsed->actions->name, "act");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002795 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CONTAINER);
Radek Iša56ca9e42020-09-08 18:42:00 +02002796 lysp_node_free(UTEST_LYCTX, siblings);
2797 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedláke2dc9e92019-07-24 09:59:21 +02002798 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002799
2800 /* min subelems */
2801 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002802 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02002803 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002804 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2805 "cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
2806 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákf111bcb2019-07-23 17:15:51 +02002807 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002808}
2809
David Sedlák5379d392019-07-24 10:42:03 +02002810static void
2811test_case_elem(void **state)
2812{
David Sedlák5379d392019-07-24 10:42:03 +02002813 const char *data;
2814 struct lysp_node *siblings = NULL;
2815 struct tree_node_meta node_meta = {NULL, &siblings};
2816 struct lysp_node_case *parsed = NULL;
2817
2818 /* max subelems */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002819 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák5379d392019-07-24 10:42:03 +02002820 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002821 "<case name=\"case-name\">\n"
2822 " <anydata name=\"anyd\"/>\n"
2823 " <anyxml name=\"anyx\"/>\n"
2824 " <container name=\"subcont\"/>\n"
2825 " <description><text>desc</text></description>\n"
2826 " <if-feature name=\"iff\"/>\n"
2827 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2828 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2829 " <list name=\"list\"/>\n"
2830 " <reference><text>ref</text></reference>\n"
2831 " <status value=\"current\"/>\n"
2832 " <uses name=\"uses-name\"/>\n"
2833 " <when condition=\"when-cond\"/>\n"
2834 " <choice name=\"choice\"/>\n"
2835 EXT_SUBELEM
2836 "</case>"
2837 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002838 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002839 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002840 uint16_t flags = LYS_STATUS_CURR;
2841
2842 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2843 "case-name", 0, LYS_CASE, 0, "ref", 1);
2844 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002845 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02002846 assert_string_equal(parsed->child->name, "anyd");
2847 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2848 assert_string_equal(parsed->child->next->name, "anyx");
2849 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2850 assert_string_equal(parsed->child->next->next->name, "subcont");
2851 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2852 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2853 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2854 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2855 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2856 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2857 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2858 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2859 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002860 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2861 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2862 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002863 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002864 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002865 siblings = NULL;
2866
2867 /* min subelems */
2868 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002869 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002870 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002871 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2872 "case-name", 0, LYS_CASE, 0, NULL, 0);
2873 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002874 siblings = NULL;
David Sedlák5379d392019-07-24 10:42:03 +02002875}
2876
David Sedlákb7abcfa2019-07-24 12:33:35 +02002877static void
2878test_choice_elem(void **state)
2879{
David Sedlákb7abcfa2019-07-24 12:33:35 +02002880 const char *data;
2881 struct lysp_node *siblings = NULL;
2882 struct tree_node_meta node_meta = {NULL, &siblings};
2883 struct lysp_node_choice *parsed = NULL;
2884
2885 /* max subelems */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002886 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002887 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002888 "<choice name=\"choice-name\">\n"
2889 " <anydata name=\"anyd\"/>\n"
2890 " <anyxml name=\"anyx\"/>\n"
2891 " <case name=\"sub-case\"/>\n"
2892 " <choice name=\"choice\"/>\n"
2893 " <config value=\"true\"/>\n"
2894 " <container name=\"subcont\"/>\n"
2895 " <default value=\"def\"/>\n"
2896 " <description><text>desc</text></description>\n"
2897 " <if-feature name=\"iff\"/>\n"
2898 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2899 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2900 " <list name=\"list\"/>\n"
2901 " <mandatory value=\"true\" />\n"
2902 " <reference><text>ref</text></reference>\n"
2903 " <status value=\"current\"/>\n"
2904 " <when condition=\"when-cond\"/>\n"
2905 EXT_SUBELEM
2906 "</choice>"
2907 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002908 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002909 parsed = (struct lysp_node_choice *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002910 uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR;
2911
2912 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2913 "choice-name", 0, LYS_CHOICE, 0, "ref", 1);
2914 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002915 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002916 assert_string_equal(parsed->child->name, "anyd");
2917 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2918 assert_string_equal(parsed->child->next->name, "anyx");
2919 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2920 assert_string_equal(parsed->child->next->next->name, "sub-case");
2921 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
2922 assert_string_equal(parsed->child->next->next->next->name, "choice");
2923 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2924 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
2925 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
2926 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
2927 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
2928 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
2929 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2930 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
2931 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
2932 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002933 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CHOICE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002934 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002935 siblings = NULL;
2936
2937 /* min subelems */
2938 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002939 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002940 parsed = (struct lysp_node_choice *)siblings;
2941 assert_string_equal(parsed->name, "choice-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002942 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2943 "choice-name", 0, LYS_CHOICE, 0, NULL, 0);
2944 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002945 siblings = NULL;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002946}
2947
David Sedlák05404f62019-07-24 14:11:53 +02002948static void
2949test_inout_elem(void **state)
2950{
David Sedlák05404f62019-07-24 14:11:53 +02002951 const char *data;
Michal Vasko2a6c53f2021-09-22 12:20:05 +02002952 struct lysp_node_action_inout inout = {0};
David Sedlák05404f62019-07-24 14:11:53 +02002953 struct inout_meta inout_meta = {NULL, &inout};
2954
2955 /* max subelements */
Michal Vasko8a67eff2021-12-07 14:04:47 +01002956 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002957 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002958 "<input>\n"
2959 " <anydata name=\"anyd\"/>\n"
2960 " <anyxml name=\"anyx\"/>\n"
2961 " <choice name=\"choice\"/>\n"
2962 " <container name=\"subcont\"/>\n"
2963 " <grouping name=\"sub-grp\"/>\n"
2964 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2965 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2966 " <list name=\"list\"/>\n"
2967 " <must condition=\"cond\"/>\n"
2968 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2969 " <uses name=\"uses-name\"/>\n"
2970 EXT_SUBELEM
2971 "</input>"
2972 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002973 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
2974 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1);
2975 CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL);
David Sedlák05404f62019-07-24 14:11:53 +02002976 assert_string_equal(inout.typedefs->name, "tpdf");
2977 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01002978 assert_string_equal(inout.child->name, "anyd");
2979 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
2980 assert_string_equal(inout.child->next->name, "anyx");
2981 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
2982 assert_string_equal(inout.child->next->next->name, "choice");
2983 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
2984 assert_string_equal(inout.child->next->next->next->name, "subcont");
2985 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
2986 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
2987 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
2988 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
2989 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2990 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
2991 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
2992 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
2993 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2994 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002995 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_INPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002996 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02002997 memset(&inout, 0, sizeof inout);
2998
2999 /* max subelements */
Michal Vasko8a67eff2021-12-07 14:04:47 +01003000 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02003001 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003002 "<output>\n"
3003 " <anydata name=\"anyd\"/>\n"
3004 " <anyxml name=\"anyx\"/>\n"
3005 " <choice name=\"choice\"/>\n"
3006 " <container name=\"subcont\"/>\n"
3007 " <grouping name=\"sub-grp\"/>\n"
3008 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3009 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3010 " <list name=\"list\"/>\n"
3011 " <must condition=\"cond\"/>\n"
3012 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3013 " <uses name=\"uses-name\"/>\n"
3014 EXT_SUBELEM
3015 "</output>"
3016 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003017 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
3018 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1);
Michal Vasko7f45cf22020-10-01 12:49:44 +02003019 assert_string_equal(inout.musts->arg.str, "cond");
David Sedlák05404f62019-07-24 14:11:53 +02003020 assert_string_equal(inout.typedefs->name, "tpdf");
3021 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01003022 assert_string_equal(inout.child->name, "anyd");
3023 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
3024 assert_string_equal(inout.child->next->name, "anyx");
3025 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
3026 assert_string_equal(inout.child->next->next->name, "choice");
3027 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
3028 assert_string_equal(inout.child->next->next->next->name, "subcont");
3029 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
3030 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
3031 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
3032 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
3033 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3034 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
3035 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
3036 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
3037 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3038 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003039 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_OUTPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003040 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003041 memset(&inout, 0, sizeof inout);
3042
3043 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003044 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003045 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003046 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003047 memset(&inout, 0, sizeof inout);
3048
Michal Vaskob83af8a2020-01-06 09:49:22 +01003049 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003050 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003051 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003052 memset(&inout, 0, sizeof inout);
3053
3054 /* invalid combinations */
3055 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003056 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
Radek Krejci9a3823e2021-01-27 20:26:46 +01003057 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
Radek Iša56ca9e42020-09-08 18:42:00 +02003058 CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003059 memset(&inout, 0, sizeof inout);
David Sedlák05404f62019-07-24 14:11:53 +02003060}
3061
David Sedlák85d0eca2019-07-24 15:15:21 +02003062static void
3063test_action_elem(void **state)
3064{
David Sedlák85d0eca2019-07-24 15:15:21 +02003065 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003066 struct lysp_node_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003067 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
Radek Iša56ca9e42020-09-08 18:42:00 +02003068 uint16_t flags;
David Sedlák85d0eca2019-07-24 15:15:21 +02003069
3070 /* max subelems */
Michal Vasko8a67eff2021-12-07 14:04:47 +01003071 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák85d0eca2019-07-24 15:15:21 +02003072 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003073 "<action name=\"act\">\n"
3074 " <description><text>desc</text></description>\n"
3075 " <grouping name=\"grouping\"/>\n"
3076 " <if-feature name=\"iff\"/>\n"
3077 " <input><uses name=\"uses-name\"/></input>\n"
3078 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3079 " <reference><text>ref</text></reference>\n"
3080 " <status value=\"deprecated\"/>\n"
3081 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3082 EXT_SUBELEM
3083 "</action>"
3084 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003085 /* there must be parent for action */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003086 act_meta.parent = (void *)1;
Radek Iša56ca9e42020-09-08 18:42:00 +02003087 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003088 act_meta.parent = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003089 flags = LYS_STATUS_DEPRC;
3090 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3091 1, 0, 0, 0,\
3092 1, 0,\
3093 "act", LYS_ACTION, \
3094 1, 0, 0, 1,\
3095 1, 0,\
3096 1, "ref", 1);
3097
Michal Vasko7f45cf22020-10-01 12:49:44 +02003098 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlák85d0eca2019-07-24 15:15:21 +02003099 assert_string_equal(actions->typedefs->name, "tpdf");
3100 assert_string_equal(actions->groupings->name, "grouping");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003101 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci01180ac2021-01-27 08:48:22 +01003102 assert_string_equal(actions->input.child->name, "uses-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003103 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_ACTION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003104 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003105 actions = NULL;
3106
Michal Vasko8a67eff2021-12-07 14:04:47 +01003107 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlákeaa45792019-07-24 15:25:01 +02003108 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003109 "<rpc name=\"act\">\n"
3110 " <description><text>desc</text></description>\n"
3111 " <grouping name=\"grouping\"/>\n"
3112 " <if-feature name=\"iff\"/>\n"
3113 " <input><uses name=\"uses-name\"/></input>\n"
3114 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3115 " <reference><text>ref</text></reference>\n"
3116 " <status value=\"deprecated\"/>\n"
3117 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3118 EXT_SUBELEM
3119 "</rpc>"
3120 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003121 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
3122 flags = LYS_STATUS_DEPRC;
3123 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3124 1, 0, 0, 0,\
3125 1, 0,\
3126 "act", LYS_RPC, \
3127 1, 0, 0, 1,\
3128 1, 0,\
3129 0, "ref", 1);
3130
Michal Vasko7f45cf22020-10-01 12:49:44 +02003131 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlákeaa45792019-07-24 15:25:01 +02003132 assert_string_equal(actions->typedefs->name, "tpdf");
3133 assert_string_equal(actions->groupings->name, "grouping");
Radek Krejci01180ac2021-01-27 08:48:22 +01003134 assert_string_equal(actions->input.child->name, "uses-name");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003135 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003136 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_RPC);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003137 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlákeaa45792019-07-24 15:25:01 +02003138 actions = NULL;
3139
David Sedlák85d0eca2019-07-24 15:15:21 +02003140 /* min subelems */
3141 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003142 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003143 assert_string_equal(actions->name, "act");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003144 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003145 actions = NULL;
David Sedlák85d0eca2019-07-24 15:15:21 +02003146}
3147
David Sedlák992fb7c2019-07-24 16:51:01 +02003148static void
3149test_augment_elem(void **state)
3150{
David Sedlák992fb7c2019-07-24 16:51:01 +02003151 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003152 struct lysp_node_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003153 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003154
Michal Vasko8a67eff2021-12-07 14:04:47 +01003155 PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
David Sedlák992fb7c2019-07-24 16:51:01 +02003156 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003157 "<augment target-node=\"target\">\n"
3158 " <action name=\"action\"/>\n"
3159 " <anydata name=\"anyd\"/>\n"
3160 " <anyxml name=\"anyx\"/>\n"
3161 " <case name=\"case\"/>\n"
3162 " <choice name=\"choice\"/>\n"
3163 " <container name=\"subcont\"/>\n"
3164 " <description><text>desc</text></description>\n"
3165 " <if-feature name=\"iff\"/>\n"
3166 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3167 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3168 " <list name=\"list\"/>\n"
3169 " <notification name=\"notif\"/>\n"
3170 " <reference><text>ref</text></reference>\n"
3171 " <status value=\"current\"/>\n"
3172 " <uses name=\"uses\"/>\n"
3173 " <when condition=\"when-cond\"/>\n"
3174 EXT_SUBELEM
3175 "</augment>"
3176 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003177 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003178 assert_string_equal(augments->nodeid, "target");
3179 assert_null(augments->parent);
3180 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3181 assert_true(augments->flags & LYS_STATUS_CURR);
3182 assert_string_equal(augments->dsc, "desc");
3183 assert_string_equal(augments->ref, "ref");
3184 assert_string_equal(augments->when->cond, "when-cond");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003185 assert_string_equal(augments->iffeatures[0].str, "iff");
David Sedlák992fb7c2019-07-24 16:51:01 +02003186 assert_string_equal(augments->child->name, "anyd");
3187 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3188 assert_string_equal(augments->child->next->name, "anyx");
3189 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3190 assert_string_equal(augments->child->next->next->name, "case");
3191 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3192 assert_string_equal(augments->child->next->next->next->name, "choice");
3193 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3194 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3195 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3196 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3197 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3198 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3199 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3200 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3201 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3202 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3203 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3204 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3205 assert_string_equal(augments->actions->name, "action");
3206 assert_string_equal(augments->notifs->name, "notif");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003207 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT);
Michal Vasko8a67eff2021-12-07 14:04:47 +01003208 lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003209 augments = NULL;
3210
3211 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003212 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003213 assert_string_equal(augments->nodeid, "target");
Michal Vasko8a67eff2021-12-07 14:04:47 +01003214 lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003215 augments = NULL;
David Sedlák992fb7c2019-07-24 16:51:01 +02003216}
3217
David Sedlák4ffcec82019-07-25 15:10:21 +02003218static void
3219test_deviate_elem(void **state)
3220{
David Sedlák4ffcec82019-07-25 15:10:21 +02003221 const char *data;
3222 struct lysp_deviate *deviates = NULL;
3223 struct lysp_deviate_add *d_add;
3224 struct lysp_deviate_rpl *d_rpl;
3225 struct lysp_deviate_del *d_del;
3226
3227 /* all valid arguments with min subelems */
3228 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003229 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003230 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003231 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003232 free(deviates);
3233 deviates = NULL;
3234
3235 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003236 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003237 assert_int_equal(deviates->mod, LYS_DEV_ADD);
Radek Iša56ca9e42020-09-08 18:42:00 +02003238 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003239 free(deviates);
3240 deviates = NULL;
3241
3242 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003243 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003244 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003245 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003246 free(deviates);
3247 deviates = NULL;
3248
3249 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003250 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003251 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003252 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003253 free(deviates);
3254 deviates = NULL;
3255
3256 /* max subelems and valid arguments */
3257 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003258 "<deviate value=\"not-supported\">"
3259 EXT_SUBELEM
3260 "</deviate>"
3261 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003262 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003263 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003264 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003265 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003266 free(deviates);
3267 deviates = NULL;
3268
3269 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003270 "<deviate value=\"add\">\n"
3271 " <units name=\"units\"/>\n"
3272 " <must condition=\"cond\"/>\n"
3273 " <unique tag=\"utag\"/>\n"
3274 " <default value=\"def\"/>\n"
3275 " <config value=\"true\"/>\n"
3276 " <mandatory value=\"true\"/>\n"
3277 " <min-elements value=\"5\"/>\n"
3278 " <max-elements value=\"15\"/>\n"
3279 EXT_SUBELEM
3280 "</deviate>"
3281 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003282 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003283 d_add = (struct lysp_deviate_add *)deviates;
3284 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3285 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003286 assert_string_equal(d_add->units, "units");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003287 assert_string_equal(d_add->musts->arg.str, "cond");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003288 assert_string_equal(d_add->uniques[0].str, "utag");
3289 assert_string_equal(d_add->dflts[0].str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003290 assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003291 assert_int_equal(d_add->min, 5);
3292 assert_int_equal(d_add->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003293 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003294 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003295 free(deviates);
3296 deviates = NULL;
3297
3298 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003299 "<deviate value=\"replace\">\n"
3300 " <type name=\"newtype\"/>\n"
3301 " <units name=\"uni\"/>\n"
3302 " <default value=\"def\"/>\n"
3303 " <config value=\"true\"/>\n"
3304 " <mandatory value=\"true\"/>\n"
3305 " <min-elements value=\"5\"/>\n"
3306 " <max-elements value=\"15\"/>\n"
3307 EXT_SUBELEM
3308 "</deviate>"
3309 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003310 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003311 d_rpl = (struct lysp_deviate_rpl *)deviates;
3312 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3313 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003314 assert_string_equal(d_rpl->type->name, "newtype");
3315 assert_string_equal(d_rpl->units, "uni");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003316 assert_string_equal(d_rpl->dflt.str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003317 assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003318 assert_int_equal(d_rpl->min, 5);
3319 assert_int_equal(d_rpl->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003320 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003321 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003322 free(deviates);
3323 deviates = NULL;
3324
3325 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003326 "<deviate value=\"delete\">\n"
3327 " <units name=\"u\"/>\n"
3328 " <must condition=\"c\"/>\n"
3329 " <unique tag=\"tag\"/>\n"
3330 " <default value=\"default\"/>\n"
3331 EXT_SUBELEM
3332 "</deviate>"
3333 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003334 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003335 d_del = (struct lysp_deviate_del *)deviates;
3336 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3337 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003338 assert_string_equal(d_del->units, "u");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003339 assert_string_equal(d_del->musts->arg.str, "c");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003340 assert_string_equal(d_del->uniques[0].str, "tag");
3341 assert_string_equal(d_del->dflts[0].str, "default");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003342 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003343 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003344 free(deviates);
3345 deviates = NULL;
3346
3347 /* invalid arguments */
3348 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003349 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3350 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. "
3351 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003352 deviates = NULL;
3353
3354 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003355 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3356 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. "
3357 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003358 deviates = NULL;
3359
3360 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003361 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3362 CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. "
3363 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003364 deviates = NULL;
3365
3366 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003367 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3368 CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. "
3369 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003370 deviates = NULL;
3371
3372 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003373 "<deviate value=\"not-supported\">\n"
3374 " <must condition=\"c\"/>\n"
3375 "</deviate>"
3376 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003377 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3378 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 +02003379}
3380
David Sedlák8b754462019-07-25 16:22:13 +02003381static void
3382test_deviation_elem(void **state)
3383{
David Sedlák8b754462019-07-25 16:22:13 +02003384 const char *data;
3385 struct lysp_deviation *deviations = NULL;
3386
3387 /* min subelems */
3388 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003389 "<deviation target-node=\"target\">\n"
3390 " <deviate value=\"not-supported\"/>\n"
3391 "</deviation>"
3392 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003393 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003394 assert_string_equal(deviations->nodeid, "target");
3395 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003396 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003397 deviations = NULL;
3398
3399 /* max subelems */
3400 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003401 "<deviation target-node=\"target\">\n"
3402 " <reference><text>ref</text></reference>\n"
3403 " <description><text>desc</text></description>\n"
3404 " <deviate value=\"add\"/>\n"
3405 EXT_SUBELEM
3406 "</deviation>"
3407 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003408 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003409 assert_string_equal(deviations->nodeid, "target");
3410 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3411 assert_string_equal(deviations->ref, "ref");
3412 assert_string_equal(deviations->dsc, "desc");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003413 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]), LY_STMT_DEVIATION);
Radek Iša56ca9e42020-09-08 18:42:00 +02003414 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003415 deviations = NULL;
3416
3417 /* invalid */
3418 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003419 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID);
3420 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003421 deviations = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003422 CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1.");
3423 /* TODO */}
David Sedlák8b754462019-07-25 16:22:13 +02003424
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003425static struct lysp_module *
3426mod_renew(struct lys_yin_parser_ctx *ctx)
3427{
Michal Vasko8a67eff2021-12-07 14:04:47 +01003428 struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
3429 struct lysp_module *pmod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003430
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003431 lys_module_free(PARSER_CUR_PMOD(ctx)->mod, 0);
Michal Vasko8a67eff2021-12-07 14:04:47 +01003432 pmod = calloc(1, sizeof *pmod);
3433 ctx->parsed_mods->objs[0] = pmod;
3434 pmod->mod = calloc(1, sizeof *pmod->mod);
3435 pmod->mod->parsed = pmod;
3436 pmod->mod->ctx = ly_ctx;
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003437
Michal Vasko8a67eff2021-12-07 14:04:47 +01003438 return pmod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003439}
3440
David Sedlák4f03b932019-07-26 13:01:47 +02003441static void
3442test_module_elem(void **state)
3443{
Michal Vaskob36053d2020-03-26 15:49:30 +01003444 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003445 struct lysp_module *lysp_mod = mod_renew(YCTX);
David Sedlák4f03b932019-07-26 13:01:47 +02003446
3447 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003448 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003449 " <yang-version value=\"1.1\"/>\n"
3450 " <namespace uri=\"ns\"/>\n"
3451 " <prefix value=\"pref\"/>\n"
3452 " <include module=\"b-mod\"/>\n"
3453 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3454 " <organization><text>org</text></organization>\n"
3455 " <contact><text>contact</text></contact>\n"
3456 " <description><text>desc</text></description>\n"
3457 " <reference><text>ref</text></reference>\n"
3458 " <revision date=\"2019-02-02\"/>\n"
3459 " <anydata name=\"anyd\"/>\n"
3460 " <anyxml name=\"anyx\"/>\n"
3461 " <choice name=\"choice\"/>\n"
3462 " <container name=\"cont\"/>\n"
3463 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3464 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3465 " <list name=\"sub-list\"/>\n"
3466 " <uses name=\"uses-name\"/>\n"
3467 " <augment target-node=\"target\"/>\n"
3468 " <deviation target-node=\"target\">\n"
3469 " <deviate value=\"not-supported\"/>\n"
3470 " </deviation>\n"
3471 " <extension name=\"ext\"/>\n"
3472 " <feature name=\"feature\"/>\n"
3473 " <grouping name=\"grp\"/>\n"
3474 " <identity name=\"ident-name\"/>\n"
3475 " <notification name=\"notf\"/>\n"
3476 " <rpc name=\"rpc-name\"/>\n"
3477 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3478 EXT_SUBELEM "\n"
3479 "</module>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003480 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3481 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003482
Radek Iša56ca9e42020-09-08 18:42:00 +02003483 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003484 assert_string_equal(lysp_mod->mod->name, "mod");
3485 assert_string_equal(lysp_mod->revs, "2019-02-02");
3486 assert_string_equal(lysp_mod->mod->ns, "ns");
3487 assert_string_equal(lysp_mod->mod->prefix, "pref");
3488 assert_null(lysp_mod->mod->filepath);
3489 assert_string_equal(lysp_mod->mod->org, "org");
3490 assert_string_equal(lysp_mod->mod->contact, "contact");
3491 assert_string_equal(lysp_mod->mod->dsc, "desc");
3492 assert_string_equal(lysp_mod->mod->ref, "ref");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003493 assert_int_equal(lysp_mod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003494 CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod",
3495 "imp-pref", NULL, "");
David Sedlák4f03b932019-07-26 13:01:47 +02003496 assert_string_equal(lysp_mod->includes->name, "b-mod");
3497 assert_string_equal(lysp_mod->extensions->name, "ext");
3498 assert_string_equal(lysp_mod->features->name, "feature");
3499 assert_string_equal(lysp_mod->identities->name, "ident-name");
3500 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3501 assert_string_equal(lysp_mod->groupings->name, "grp");
3502 assert_string_equal(lysp_mod->data->name, "anyd");
3503 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3504 assert_string_equal(lysp_mod->data->next->name, "anyx");
3505 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3506 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3507 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3508 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3509 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3510 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3511 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3512 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3513 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3514 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3515 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3516 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3517 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3518 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3519 assert_string_equal(lysp_mod->augments->nodeid, "target");
3520 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3521 assert_string_equal(lysp_mod->notifs->name, "notf");
3522 assert_string_equal(lysp_mod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003523 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LY_STMT_MODULE);
David Sedlák4f03b932019-07-26 13:01:47 +02003524
3525 /* min subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003526 ly_in_free(UTEST_IN, 0);
3527 lyxml_ctx_free(YCTX->xmlctx);
3528 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003529 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3530 " <namespace uri=\"ns\"/>\n"
3531 " <prefix value=\"pref\"/>\n"
3532 " <yang-version value=\"1.1\"/>\n"
3533 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003534 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3535 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3536 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003537 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák298ff6d2019-07-26 14:29:03 +02003538
David Sedláke6cd89e2019-08-07 12:46:02 +02003539 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003540 ly_in_free(UTEST_IN, 0);
3541 lyxml_ctx_free(YCTX->xmlctx);
3542 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003543 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3544 " <feature name=\"feature\"/>\n"
3545 " <namespace uri=\"ns\"/>\n"
3546 " <prefix value=\"pref\"/>\n"
3547 " <yang-version value=\"1.1\"/>\n"
3548 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003549 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3550 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3551 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID);
3552 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 +02003553}
3554
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003555static struct lysp_submodule *
3556submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to)
3557{
Michal Vasko8a67eff2021-12-07 14:04:47 +01003558 struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
3559 struct lysp_submodule *submod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003560
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003561 lys_module_free(PARSER_CUR_PMOD(ctx)->mod, 0);
Michal Vasko8a67eff2021-12-07 14:04:47 +01003562 submod = calloc(1, sizeof *submod);
3563 ctx->parsed_mods->objs[0] = submod;
3564 submod->mod = calloc(1, sizeof *submod->mod);
3565 lydict_insert(ly_ctx, belongs_to, 0, &submod->mod->name);
3566 submod->mod->parsed = (struct lysp_module *)submod;
3567 submod->mod->ctx = ly_ctx;
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003568
Michal Vasko8a67eff2021-12-07 14:04:47 +01003569 return submod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003570}
3571
David Sedlák298ff6d2019-07-26 14:29:03 +02003572static void
3573test_submodule_elem(void **state)
3574{
Michal Vaskob36053d2020-03-26 15:49:30 +01003575 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003576 struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name");
David Sedlák298ff6d2019-07-26 14:29:03 +02003577
3578 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02003579 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003580 " <yang-version value=\"1.1\"/>\n"
3581 " <belongs-to module=\"module-name\">\n"
3582 " <prefix value=\"pref\"/>\n"
3583 " </belongs-to>\n"
3584 " <include module=\"b-mod\"/>\n"
3585 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3586 " <organization><text>org</text></organization>\n"
3587 " <contact><text>contact</text></contact>\n"
3588 " <description><text>desc</text></description>\n"
3589 " <reference><text>ref</text></reference>\n"
3590 " <revision date=\"2019-02-02\"/>\n"
3591 " <anydata name=\"anyd\"/>\n"
3592 " <anyxml name=\"anyx\"/>\n"
3593 " <choice name=\"choice\"/>\n"
3594 " <container name=\"cont\"/>\n"
3595 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3596 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3597 " <list name=\"sub-list\"/>\n"
3598 " <uses name=\"uses-name\"/>\n"
3599 " <augment target-node=\"target\"/>\n"
3600 " <deviation target-node=\"target\">\n"
3601 " <deviate value=\"not-supported\"/>\n"
3602 " </deviation>\n"
3603 " <extension name=\"ext\"/>\n"
3604 " <feature name=\"feature\"/>\n"
3605 " <grouping name=\"grp\"/>\n"
3606 " <identity name=\"ident-name\"/>\n"
3607 " <notification name=\"notf\"/>\n"
3608 " <rpc name=\"rpc-name\"/>\n"
3609 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3610 EXT_SUBELEM "\n"
3611 "</submodule>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003612 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3613 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003614
Radek Iša56ca9e42020-09-08 18:42:00 +02003615 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003616 assert_string_equal(lysp_submod->name, "mod");
3617 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02003618 assert_string_equal(lysp_submod->prefix, "pref");
3619 assert_null(lysp_submod->filepath);
3620 assert_string_equal(lysp_submod->org, "org");
3621 assert_string_equal(lysp_submod->contact, "contact");
3622 assert_string_equal(lysp_submod->dsc, "desc");
3623 assert_string_equal(lysp_submod->ref, "ref");
3624 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003625 CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod",
3626 "imp-pref", NULL, "");
David Sedlák298ff6d2019-07-26 14:29:03 +02003627 assert_string_equal(lysp_submod->includes->name, "b-mod");
3628 assert_string_equal(lysp_submod->extensions->name, "ext");
3629 assert_string_equal(lysp_submod->features->name, "feature");
3630 assert_string_equal(lysp_submod->identities->name, "ident-name");
3631 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
3632 assert_string_equal(lysp_submod->groupings->name, "grp");
3633 assert_string_equal(lysp_submod->data->name, "anyd");
3634 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
3635 assert_string_equal(lysp_submod->data->next->name, "anyx");
3636 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
3637 assert_string_equal(lysp_submod->data->next->next->name, "choice");
3638 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
3639 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
3640 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
3641 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
3642 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
3643 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
3644 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3645 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
3646 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3647 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
3648 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3649 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
3650 assert_string_equal(lysp_submod->augments->nodeid, "target");
3651 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
3652 assert_string_equal(lysp_submod->notifs->name, "notf");
3653 assert_string_equal(lysp_submod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003654 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LY_STMT_SUBMODULE);
David Sedlák298ff6d2019-07-26 14:29:03 +02003655
David Sedlák298ff6d2019-07-26 14:29:03 +02003656 /* min subelemnts */
Radek Iša56ca9e42020-09-08 18:42:00 +02003657 ly_in_free(UTEST_IN, 0);
3658 lyxml_ctx_free(YCTX->xmlctx);
3659 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003660 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3661 " <yang-version value=\"1\"/>\n"
3662 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3663 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003664 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3665 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3666 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003667 assert_string_equal(lysp_submod->prefix, "pref");
David Sedlák298ff6d2019-07-26 14:29:03 +02003668 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
David Sedlák298ff6d2019-07-26 14:29:03 +02003669
David Sedláke6cd89e2019-08-07 12:46:02 +02003670 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003671 ly_in_free(UTEST_IN, 0);
3672 lyxml_ctx_free(YCTX->xmlctx);
3673 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003674 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3675 " <yang-version value=\"1\"/>\n"
3676 " <reference><text>ref</text></reference>\n"
3677 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3678 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003679 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3680 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3681 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID);
3682 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 +02003683}
3684
David Sedlák8985a142019-07-31 16:43:06 +02003685static void
3686test_yin_parse_module(void **state)
3687{
David Sedlák8985a142019-07-31 16:43:06 +02003688 const char *data;
3689 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01003690 struct lys_yin_parser_ctx *yin_ctx = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003691 struct ly_in *in = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003692
3693 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003694 mod->ctx = UTEST_LYCTX;
David Sedlákd2844882019-09-13 16:01:22 +02003695 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 +01003696 " <yang-version value=\"1.1\"/>\n"
3697 " <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
3698 " <prefix value=\"a\"/>\n"
3699 " <import module=\"ietf-yang-metadata\">\n"
3700 " <prefix value=\"md\"/>\n"
3701 " </import>\n"
3702 " <feature name=\"f\"/>\n"
3703 " <md:annotation name=\"x\">\n"
3704 " <description>\n"
3705 " <text>test</text>\n"
3706 " </description>\n"
3707 " <reference>\n"
3708 " <text>test</text>\n"
3709 " </reference>\n"
3710 " <if-feature name=\"f\"/>\n"
3711 " <status value=\"current\"/>\n"
3712 " <type name=\"uint8\"/>\n"
3713 " <units name=\"meters\"/>\n"
3714 " </md:annotation>\n"
3715 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003716 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003717 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
David Sedlákd2844882019-09-13 16:01:22 +02003718 assert_null(mod->parsed->exts->child->next->child);
3719 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003720 lys_module_free(mod, 0);
David Sedlákd2844882019-09-13 16:01:22 +02003721 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003722 ly_in_free(in, 0);
David Sedlákd2844882019-09-13 16:01:22 +02003723 mod = NULL;
3724 yin_ctx = NULL;
3725
3726 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003727 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003728 data = "<module name=\"example-foo\""
3729 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3730 " xmlns:foo=\"urn:example:foo\""
3731 " xmlns:myext=\"urn:example:extensions\">\n"
David Sedlák8985a142019-07-31 16:43:06 +02003732
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003733 " <yang-version value=\"1\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003734
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003735 " <namespace uri=\"urn:example:foo\"/>\n"
3736 " <prefix value=\"foo\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003737
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003738 " <import module=\"example-extensions\">\n"
3739 " <prefix value=\"myext\"/>\n"
3740 " </import>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003741
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003742 " <list name=\"interface\">\n"
3743 " <key value=\"name\"/>\n"
3744 " <leaf name=\"name\">\n"
3745 " <type name=\"string\"/>\n"
3746 " </leaf>\n"
3747 " <leaf name=\"mtu\">\n"
3748 " <type name=\"uint32\"/>\n"
3749 " <description>\n"
3750 " <text>The MTU of the interface.</text>\n"
3751 " </description>\n"
3752 " <myext:c-define name=\"MY_MTU\"/>\n"
3753 " </leaf>\n"
3754 " </list>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003755 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003756 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003757 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003758 lys_module_free(mod, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003759 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003760 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003761 mod = NULL;
3762 yin_ctx = NULL;
3763
3764 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003765 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003766 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3767 " <yang-version value=\"1\"/>\n"
3768 " <namespace uri=\"urn:example:foo\"/>\n"
3769 " <prefix value=\"foo\"/>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003770 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003771 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003772 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003773 lys_module_free(mod, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003774 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003775 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003776 mod = NULL;
3777 yin_ctx = NULL;
3778
David Sedlák6d781b62019-08-02 15:22:52 +02003779 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003780 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003781 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlák8985a142019-07-31 16:43:06 +02003782 "</submodule>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003783 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003784 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL);
Radek Iša56ca9e42020-09-08 18:42:00 +02003785 CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003786 lys_module_free(mod, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003787 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003788 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003789
David Sedlák6d781b62019-08-02 15:22:52 +02003790 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003791 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003792 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3793 " <yang-version value=\"1\"/>\n"
3794 " <namespace uri=\"urn:example:foo\"/>\n"
3795 " <prefix value=\"foo\"/>\n"
3796 "</module>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003797 "<module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003798 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
aPiecekc3e26142021-06-22 14:25:49 +02003799 assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +02003800 CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
Michal Vasko4f9da5e2022-03-14 13:11:26 +01003801 lys_module_free(mod, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003802 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003803 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003804 mod = NULL;
3805 yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003806}
3807
3808static void
3809test_yin_parse_submodule(void **state)
3810{
David Sedlák8985a142019-07-31 16:43:06 +02003811 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01003812 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003813 struct lysp_submodule *submod = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003814 struct ly_in *in;
David Sedlák8985a142019-07-31 16:43:06 +02003815
Michal Vasko8a67eff2021-12-07 14:04:47 +01003816 lydict_insert(UTEST_LYCTX, "a", 0, &PARSER_CUR_PMOD(YCTX)->mod->name);
Michal Vaskoc3781c32020-10-06 14:04:08 +02003817
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003818 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003819 "<submodule name=\"asub\""
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003820 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3821 " xmlns:a=\"urn:a\">\n"
3822 " <yang-version value=\"1\"/>\n"
3823 " <belongs-to module=\"a\">\n"
3824 " <prefix value=\"a_pref\"/>\n"
3825 " </belongs-to>\n"
3826 " <include module=\"atop\"/>\n"
3827 " <feature name=\"fox\"/>\n"
3828 " <notification name=\"bar-notif\">\n"
3829 " <if-feature name=\"bar\"/>\n"
3830 " </notification>\n"
3831 " <notification name=\"fox-notif\">\n"
3832 " <if-feature name=\"fox\"/>\n"
3833 " </notification>\n"
3834 " <augment target-node=\"/a_pref:top\">\n"
3835 " <if-feature name=\"bar\"/>\n"
3836 " <container name=\"bar-sub\"/>\n"
3837 " </augment>\n"
3838 " <augment target-node=\"/top\">\n"
3839 " <container name=\"bar-sub2\"/>\n"
3840 " </augment>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003841 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003842 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003843 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 +02003844 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003845 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003846 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003847 yin_ctx = NULL;
3848 submod = NULL;
3849
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003850 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3851 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3852 " <yang-version value=\"1\"/>\n"
3853 " <belongs-to module=\"a\">\n"
3854 " <prefix value=\"a_pref\"/>\n"
3855 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003856 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003857 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003858 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 +02003859 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003860 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003861 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003862 yin_ctx = NULL;
3863 submod = NULL;
3864
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003865 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003866 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
3867 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003868 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003869 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
3870 CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003871 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003872 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003873 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003874 yin_ctx = NULL;
3875 submod = NULL;
3876
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003877 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3878 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3879 " <yang-version value=\"1\"/>\n"
3880 " <belongs-to module=\"a\">\n"
3881 " <prefix value=\"a_pref\"/>\n"
3882 " </belongs-to>\n"
3883 "</submodule>\n"
3884 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3885 " <yang-version value=\"1\"/>\n"
3886 " <belongs-to module=\"a\">\n"
3887 " <prefix value=\"a_pref\"/>\n"
3888 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003889 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003890 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003891 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
3892 CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003893 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003894 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003895 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003896 yin_ctx = NULL;
3897 submod = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003898}
3899
David Sedlák3b4db242018-10-19 16:11:01 +02003900int
3901main(void)
3902{
3903
3904 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +02003905 UTEST(test_yin_match_keyword, setup, teardown),
3906 UTEST(test_yin_parse_element_generic, setup, teardown),
3907 UTEST(test_yin_parse_extension_instance, setup, teardown),
3908 UTEST(test_yin_parse_content, setup, teardown),
3909 UTEST(test_validate_value, setup, teardown),
David Sedlák32488102019-07-15 17:44:10 +02003910
Radek Iša56ca9e42020-09-08 18:42:00 +02003911 UTEST(test_yin_match_argument_name),
3912 cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown),
3913 cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown),
3914 cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown),
3915 cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown),
3916 cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown),
3917 cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown),
3918 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown),
3919 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown),
3920 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown),
3921 cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown),
3922 cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown),
3923 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown),
3924 cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown),
3925 cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown),
3926 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown),
3927 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown),
3928 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown),
3929 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown),
3930 cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown),
3931 cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown),
3932 cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown),
3933 cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown),
3934 cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown),
3935 cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown),
3936 cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown),
3937 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown),
3938 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown),
3939 cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown),
3940 cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown),
3941 cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown),
3942 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown),
3943 cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown),
3944 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown),
3945 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown),
3946 cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown),
3947 cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown),
3948 cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown),
3949 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown),
3950 cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown),
3951 cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown),
3952 cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown),
3953 cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown),
3954 cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown),
3955 cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown),
3956 cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown),
3957 cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown),
3958 cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown),
3959 cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown),
3960 cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown),
3961 cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown),
3962 cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown),
3963 cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown),
3964 cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown),
3965 cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown),
3966 cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown),
3967 cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown),
3968 cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown),
3969 cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown),
David Sedlák8985a142019-07-31 16:43:06 +02003970
Radek Iša56ca9e42020-09-08 18:42:00 +02003971 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown),
3972 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown),
David Sedlák3b4db242018-10-19 16:11:01 +02003973 };
3974
Radek Iša56ca9e42020-09-08 18:42:00 +02003975 return cmocka_run_group_tests(tests, NULL, NULL);
David Sedlák3b4db242018-10-19 16:11:01 +02003976}