blob: 7c726ff98f5aeb9cdca20f92e51ea58e5a77b03c [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 Krejci859a15a2021-03-05 20:56:59 +010025#include "tree_edit.h"
Radek Krejci70593c12020-06-13 20:48:09 +020026#include "tree_schema.h"
27#include "tree_schema_internal.h"
28#include "xml.h"
29#include "xpath.h"
David Sedlák3b4db242018-10-19 16:11:01 +020030
Michal Vaskoafac7822020-10-20 14:22:26 +020031/* copied from parser_yin.c */
32enum yin_argument {
33 YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */
34 YIN_ARG_NAME, /**< argument name */
35 YIN_ARG_TARGET_NODE, /**< argument target-node */
36 YIN_ARG_MODULE, /**< argument module */
37 YIN_ARG_VALUE, /**< argument value */
38 YIN_ARG_TEXT, /**< argument text */
39 YIN_ARG_CONDITION, /**< argument condition */
40 YIN_ARG_URI, /**< argument uri */
41 YIN_ARG_DATE, /**< argument data */
42 YIN_ARG_TAG, /**< argument tag */
43 YIN_ARG_NONE /**< empty (special value) */
44};
45
46struct yin_subelement {
47 enum ly_stmt type; /**< type of keyword */
48 void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */
49 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 */
50};
51
52struct import_meta {
53 const char *prefix; /**< module prefix. */
54 struct lysp_import **imports; /**< imports to add to. */
55};
56
57struct yin_argument_meta {
58 uint16_t *flags; /**< Argument flags */
59 const char **argument; /**< Argument value */
60};
61
62struct tree_node_meta {
63 struct lysp_node *parent; /**< parent node */
64 struct lysp_node **nodes; /**< linked list of siblings */
65};
66
67struct include_meta {
68 const char *name; /**< Module/submodule name. */
69 struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */
70};
71
72struct inout_meta {
73 struct lysp_node *parent; /**< Parent node. */
Radek Krejci2a9fc652021-01-22 17:44:34 +010074 struct lysp_node_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */
Michal Vaskoafac7822020-10-20 14:22:26 +020075};
76
77struct minmax_dev_meta {
78 uint32_t *lim; /**< min/max value to write to. */
79 uint16_t *flags; /**< min/max flags to write to. */
80 struct lysp_ext_instance **exts; /**< extension instances to add to. */
81};
82
83#define YIN_SUBELEM_MANDATORY 0x01
84#define YIN_SUBELEM_UNIQUE 0x02
85#define YIN_SUBELEM_FIRST 0x04
86#define YIN_SUBELEM_VER2 0x08
87
88#define YIN_SUBELEM_PARSED 0x80
89
David Sedlák555c7202019-07-04 12:14:12 +020090/* prototypes of static functions */
Michal Vaskoafac7822020-10-20 14:22:26 +020091enum yin_argument yin_match_argument_name(const char *name, size_t len);
92LY_ERR yin_parse_content(struct lys_yin_parser_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size,
93 enum ly_stmt current_element, const char **text_content, struct lysp_ext_instance **exts);
94LY_ERR yin_validate_value(struct lys_yin_parser_ctx *ctx, enum yang_arg val_type);
95enum ly_stmt yin_match_keyword(struct lys_yin_parser_ctx *ctx, const char *name, size_t name_len,
96 const char *prefix, size_t prefix_len, enum ly_stmt parrent);
Radek Krejcifc596f92021-02-26 22:40:26 +010097LY_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 +020098 struct lysp_ext_instance **exts);
99LY_ERR yin_parse_element_generic(struct lys_yin_parser_ctx *ctx, enum ly_stmt parent, struct lysp_stmt **element);
100LY_ERR yin_parse_mod(struct lys_yin_parser_ctx *ctx, struct lysp_module *mod);
101LY_ERR yin_parse_submod(struct lys_yin_parser_ctx *ctx, struct lysp_submodule *submod);
102
David Sedlák555c7202019-07-04 12:14:12 +0200103void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +0200104void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +0200105void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +0200106void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +0200107void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +0200108void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +0200109void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +0200110void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +0200111void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +0200112void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +0200113void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100114void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp);
115void lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +0200116void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +0200117void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +0200118void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +0200119
David Sedláke6cd89e2019-08-07 12:46:02 +0200120/* wrapping element used for mocking has nothing to do with real module structure */
121#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
122#define ELEMENT_WRAPPER_END "</status>"
123
Radek Iša56ca9e42020-09-08 18:42:00 +0200124#define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\
Radek Krejci85ac8312021-03-03 20:21:33 +0100125 CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, INSUBSTMT, 0, "myext:c-define", LY_PREF_XML)
David Sedlák872c7b42018-10-26 13:15:20 +0200126
Radek Iša56ca9e42020-09-08 18:42:00 +0200127struct lys_yin_parser_ctx *YCTX;
David Sedlák8e7bda82019-07-16 17:57:50 +0200128
129static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200130setup_ctx(void **state)
David Sedlák8e7bda82019-07-16 17:57:50 +0200131{
David Sedlák619db942019-07-03 14:47:30 +0200132 /* allocate parser context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200133 YCTX = calloc(1, sizeof(*YCTX));
134 YCTX->format = LYS_IN_YIN;
David Sedlák8f5bce02019-06-03 16:41:08 +0200135
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200136 /* allocate new parsed module */
Radek Iša56ca9e42020-09-08 18:42:00 +0200137 YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200138
139 /* allocate new module */
Radek Iša56ca9e42020-09-08 18:42:00 +0200140 YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
141 YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
142 YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200143
Radek Iša56ca9e42020-09-08 18:42:00 +0200144 return 0;
David Sedlák3b4db242018-10-19 16:11:01 +0200145}
146
147static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200148setup(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100149{
Radek Iša56ca9e42020-09-08 18:42:00 +0200150 UTEST_SETUP;
David Sedlák68a1af12019-03-08 13:46:54 +0100151
Radek Iša56ca9e42020-09-08 18:42:00 +0200152 setup_ctx(state);
David Sedlák79e50cb2019-06-05 16:33:09 +0200153
Radek Iša56ca9e42020-09-08 18:42:00 +0200154 return 0;
David Sedlák79e50cb2019-06-05 16:33:09 +0200155}
156
David Sedlák8985a142019-07-31 16:43:06 +0200157static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200158teardown_ctx(void **UNUSED(state))
David Sedlák8985a142019-07-31 16:43:06 +0200159{
Radek Iša56ca9e42020-09-08 18:42:00 +0200160 lyxml_ctx_free(YCTX->xmlctx);
161 lys_module_free(YCTX->parsed_mod->mod, NULL);
162 free(YCTX);
163 YCTX = NULL;
David Sedlák8985a142019-07-31 16:43:06 +0200164
Radek Iša56ca9e42020-09-08 18:42:00 +0200165 return 0;
David Sedlák8985a142019-07-31 16:43:06 +0200166}
167
Radek Iša56ca9e42020-09-08 18:42:00 +0200168static int
169teardown(void **state)
170{
171 teardown_ctx(state);
172
173 UTEST_TEARDOWN;
174
175 return 0;
176}
177
178#define RESET_STATE \
179 ly_in_free(UTEST_IN, 0); \
180 UTEST_IN = NULL; \
181 teardown_ctx(state); \
182 setup_ctx(state)
183
David Sedlák68a1af12019-03-08 13:46:54 +0100184static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200185test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200186{
Michal Vaskob36053d2020-03-26 15:49:30 +0100187 const char *prefix;
188 size_t prefix_len;
Radek Iša56ca9e42020-09-08 18:42:00 +0200189
David Sedlák8f7a1172019-06-20 14:42:18 +0200190 /* create mock yin namespace in xml context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200191 ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN);
192 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
193 prefix = YCTX->xmlctx->prefix;
194 prefix_len = YCTX->xmlctx->prefix_len;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100195
Radek Iša56ca9e42020-09-08 18:42:00 +0200196 assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
197 assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
198 assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
199 assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
200 assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
201 assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
202 assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
203 assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
204 assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
205 assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
206 assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
207 assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
208 assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
209 assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
210 assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
211 assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
212 assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
213 assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
214 assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
215 assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
216 assert_int_equal(yin_match_keyword(YCTX, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
217 assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
218 assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
219 assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
220 assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
221 assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
222 assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
223 assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
224 assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
225 assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
226 assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
227 assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
228 assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
229 assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
230 assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
231 assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
232 assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
233 assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
234 assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
235 assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
236 assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
237 assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
238 assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
239 assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
240 assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
241 assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
242 assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
243 assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
244 assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
245 assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
246 assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
247 assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
248 assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
249 assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
250 assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
251 assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
252 assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
253 assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
254 assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
255 assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
256 assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
257 assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
258 assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
259 assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
260 assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
261 assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
262 assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
263 assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
264 assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
265 assert_int_equal(yin_match_keyword(YCTX, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
David Sedlák872c7b42018-10-26 13:15:20 +0200266}
David Sedlák3b4db242018-10-19 16:11:01 +0200267
David Sedlák872c7b42018-10-26 13:15:20 +0200268static void
Radek Iša56ca9e42020-09-08 18:42:00 +0200269test_yin_match_argument_name(void **UNUSED(state))
David Sedlák872c7b42018-10-26 13:15:20 +0200270{
David Sedlák060b00e2019-06-19 11:12:06 +0200271 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
272 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
273 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
274 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
275 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
276 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
277 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
278 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
279 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
280 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
281 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
282 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200283}
284
David Sedlák68a1af12019-03-08 13:46:54 +0100285static void
David Sedlákb1a78352019-06-28 16:16:29 +0200286test_yin_parse_element_generic(void **state)
287{
David Sedlákb1a78352019-06-28 16:16:29 +0200288 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200289 LY_ERR ret;
Radek Iša56ca9e42020-09-08 18:42:00 +0200290 const char *arg;
291 const char *stmt;
292 const char *data;
David Sedlákb1a78352019-06-28 16:16:29 +0200293
294 memset(&exts, 0, sizeof(exts));
295
Radek Iša56ca9e42020-09-08 18:42:00 +0200296 data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
297 ly_in_new_memory(data, &UTEST_IN);
298 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100299
Radek Iša56ca9e42020-09-08 18:42:00 +0200300 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200301 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200302 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100303 stmt = "myext:elem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200304 arg = "text_value";
Radek Krejci996f0772021-02-05 19:39:41 +0100305 CHECK_LYSP_STMT(exts.child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200306 stmt = "attr";
307 arg = "value";
308 CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt);
309 lysp_ext_instance_free(UTEST_LYCTX, &exts);
310 RESET_STATE;
David Sedlák5392a212019-07-01 09:19:10 +0200311
David Sedlákb0ca07d2019-09-11 11:54:05 +0200312 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200313 ly_in_new_memory(data, &UTEST_IN);
314 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100315
Radek Iša56ca9e42020-09-08 18:42:00 +0200316 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200317 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200318 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100319 stmt = "myext:elem";
Radek Krejci996f0772021-02-05 19:39:41 +0100320 CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200321 lysp_ext_instance_free(UTEST_LYCTX, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200322}
323
324static void
325test_yin_parse_extension_instance(void **state)
326{
327 LY_ERR ret;
David Sedlákb1a78352019-06-28 16:16:29 +0200328 struct lysp_ext_instance *exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200329 struct lysp_stmt *act_child;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200330 const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200331 const char *stmt = "value1";
332 const char *arg = "test";
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100333
Radek Iša56ca9e42020-09-08 18:42:00 +0200334 ly_in_new_memory(data, &UTEST_IN);
335 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100336
Radek Krejcifc596f92021-02-26 22:40:26 +0100337 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200338 assert_int_equal(ret, LY_SUCCESS);
Radek Krejci85ac8312021-03-03 20:21:33 +0100339 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, LY_STMT_CONTACT, 0, "myext:ext", LY_PREF_XML);
David Sedlákb1a78352019-06-28 16:16:29 +0200340
Radek Iša56ca9e42020-09-08 18:42:00 +0200341 CHECK_LYSP_STMT(exts->child, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
342 stmt = "value";
343 arg = "test2";
344 CHECK_LYSP_STMT(exts->child->next, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100345 stmt = "myext:subelem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200346 arg = "text";
Radek Krejci996f0772021-02-05 19:39:41 +0100347 CHECK_LYSP_STMT(exts->child->next->next, arg, 0, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200348 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200349 LY_ARRAY_FREE(exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200350 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200351 RESET_STATE;
David Sedlákf250ecf2019-07-01 11:02:05 +0200352
David Sedlákb0ca07d2019-09-11 11:54:05 +0200353 data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
Radek Iša56ca9e42020-09-08 18:42:00 +0200354 ly_in_new_memory(data, &UTEST_IN);
355 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100356
Radek Krejcifc596f92021-02-26 22:40:26 +0100357 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200358 assert_int_equal(ret, LY_SUCCESS);
Radek Krejci85ac8312021-03-03 20:21:33 +0100359 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 0, LY_STMT_CONTACT, 0, "myext:extension-elem", LY_PREF_XML);
Radek Iša56ca9e42020-09-08 18:42:00 +0200360 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200361 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200362 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200363 RESET_STATE;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200364
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100365 data =
366 "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n"
367 " <myext:ext-sub1/>\n"
368 " <myext:ext-sub2 sattr1=\"stext2\">\n"
369 " <myext:ext-sub21>\n"
370 " <myext:ext-sub211 sattr21=\"text21\"/>\n"
371 " </myext:ext-sub21>\n"
372 " </myext:ext-sub2>\n"
373 " <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n"
374 "</myext:ext>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200375 ly_in_new_memory(data, &UTEST_IN);
376 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100377
Radek Krejcifc596f92021-02-26 22:40:26 +0100378 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200379 assert_int_equal(ret, LY_SUCCESS);
380
Radek Krejci85ac8312021-03-03 20:21:33 +0100381 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, LY_STMT_CONTACT, 0, "myext:ext", LY_PREF_XML);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200382
Radek Iša56ca9e42020-09-08 18:42:00 +0200383 stmt = "attr1";
384 arg = "text1";
385 act_child = exts->child;
386 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
387 stmt = "attr2";
388 arg = "text2";
389 act_child = act_child->next;
390 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100391 stmt = "myext:ext-sub1";
Radek Iša56ca9e42020-09-08 18:42:00 +0200392 arg = NULL;
393 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100394 CHECK_LYSP_STMT(act_child, arg, NULL, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100395 stmt = "myext:ext-sub2";
Radek Iša56ca9e42020-09-08 18:42:00 +0200396 arg = NULL;
397 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100398 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200399
Radek Iša56ca9e42020-09-08 18:42:00 +0200400 stmt = "sattr1";
401 arg = "stext2";
402 act_child = act_child->child;
403 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100404 stmt = "myext:ext-sub21";
Radek Iša56ca9e42020-09-08 18:42:00 +0200405 arg = NULL;
406 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100407 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200408
Michal Vaskofc2cd072021-02-24 13:17:17 +0100409 stmt = "myext:ext-sub211";
Radek Iša56ca9e42020-09-08 18:42:00 +0200410 arg = NULL;
411 act_child = act_child->child;
Radek Krejci996f0772021-02-05 19:39:41 +0100412 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200413
Radek Iša56ca9e42020-09-08 18:42:00 +0200414 stmt = "sattr21";
415 arg = "text21";
416 act_child = act_child->child;
417 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200418
Michal Vaskofc2cd072021-02-24 13:17:17 +0100419 stmt = "myext:ext-sub3";
Radek Iša56ca9e42020-09-08 18:42:00 +0200420 arg = NULL;
421 act_child = exts->child->next->next->next->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100422 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200423 stmt = "attr3";
424 arg = "text3";
425 act_child = act_child->child;
426 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200427
Radek Iša56ca9e42020-09-08 18:42:00 +0200428 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200429 LY_ARRAY_FREE(exts);
430 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200431 RESET_STATE;
David Sedlákaa98bba2019-09-12 11:52:14 +0200432
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100433 data =
434 "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
435 " <yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>\n"
436 " <yin:augment target-node=\"target\"/>\n"
437 " <yin:status value=\"value\"/>\n"
438 " <yin:include module=\"mod\"/>\n"
439 " <yin:input />\n"
440 " <yin:must condition=\"cond\"/>\n"
441 " <yin:namespace uri=\"uri\"/>\n"
442 " <yin:revision date=\"data\"/>\n"
443 " <yin:unique tag=\"tag\"/>\n"
444 " <yin:description><yin:text>contact-val</yin:text></yin:description>\n"
445 " <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n"
446 "</myext:extension-elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200447 ly_in_new_memory(data, &UTEST_IN);
448 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100449
Radek Krejcifc596f92021-02-26 22:40:26 +0100450 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200451 assert_int_equal(ret, LY_SUCCESS);
452 assert_string_equal(exts->child->arg, "act-name");
453 assert_string_equal(exts->child->next->arg, "target");
454 assert_string_equal(exts->child->next->next->arg, "value");
455 assert_string_equal(exts->child->next->next->next->arg, "mod");
456 assert_null(exts->child->next->next->next->next->arg);
457 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
458 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
459 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
460 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
461 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
Radek Iša56ca9e42020-09-08 18:42:00 +0200462 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200463 LY_ARRAY_FREE(exts);
464 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200465 RESET_STATE;
David Sedlákb1a78352019-06-28 16:16:29 +0200466}
467
David Sedlák555c7202019-07-04 12:14:12 +0200468static void
469test_yin_parse_content(void **state)
470{
David Sedlák555c7202019-07-04 12:14:12 +0200471 LY_ERR ret = LY_SUCCESS;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100472 const char *data =
473 "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
474 " <myext:custom xmlns:myext=\"urn:example:extensions\">totally amazing extension</myext:custom>\n"
475 " <extension name=\"ext\">\n"
476 " <argument name=\"argname\"></argument>\n"
477 " <description><text>desc</text></description>\n"
478 " <reference><text>ref</text></reference>\n"
479 " <status value=\"deprecated\"></status>\n"
480 " </extension>\n"
481 " <text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>\n"
482 " <if-feature name=\"foo\"></if-feature>\n"
483 " <when condition=\"condition...\">\n"
484 " <reference><text>when_ref</text></reference>\n"
485 " <description><text>when_desc</text></description>\n"
486 " </when>\n"
487 " <config value=\"true\"/>\n"
488 " <error-message>\n"
489 " <value>error-msg</value>\n"
490 " </error-message>\n"
491 " <error-app-tag value=\"err-app-tag\"/>\n"
492 " <units name=\"radians\"></units>\n"
493 " <default value=\"default-value\"/>\n"
494 " <position value=\"25\"></position>\n"
495 " <value value=\"-5\"/>\n"
496 " <require-instance value=\"true\"></require-instance>\n"
497 " <range value=\"5..10\" />\n"
498 " <length value=\"baf\"/>\n"
499 " <pattern value='pattern'>\n"
500 " <modifier value='invert-match'/>\n"
501 " </pattern>\n"
502 " <enum name=\"yay\">\n"
503 " </enum>\n"
504 "</prefix>";
David Sedlák555c7202019-07-04 12:14:12 +0200505 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200506 const char **if_features = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200507 const char *value, *error_message, *app_tag, *units;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200508 struct lysp_qname def = {0};
David Sedlák986cb412019-07-04 13:10:11 +0200509 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200510 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200511 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200512 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
Juraj Vijtiukf6a07372020-10-29 21:13:33 +0100513 uint16_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200514
Radek Iša56ca9e42020-09-08 18:42:00 +0200515 ly_in_new_memory(data, &UTEST_IN);
516 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
517 lyxml_ctx_next(YCTX->xmlctx);
518 lyxml_ctx_next(YCTX->xmlctx);
519 lyxml_ctx_next(YCTX->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200520
David Sedlákfd5b9c32019-07-12 15:33:13 +0200521 struct yin_subelement subelems[17] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100522 {LY_STMT_CONFIG, &config, 0},
523 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
524 {LY_STMT_ENUM, &enum_type, 0},
525 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
Radek Iša56ca9e42020-09-08 18:42:00 +0200526 {LY_STMT_ERROR_MESSAGE, &error_message, 0},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100527 {LY_STMT_EXTENSION, &ext_def, 0},
528 {LY_STMT_IF_FEATURE, &if_features, 0},
529 {LY_STMT_LENGTH, &len_type, 0},
530 {LY_STMT_PATTERN, &patter_type, 0},
531 {LY_STMT_POSITION, &pos_enum, 0},
532 {LY_STMT_RANGE, &range_type, 0},
533 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
534 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
535 {LY_STMT_VALUE, &val_enum, 0},
536 {LY_STMT_WHEN, &when_p, 0},
537 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
538 {LY_STMT_ARG_TEXT, &value, 0}
539 };
540
Radek Iša56ca9e42020-09-08 18:42:00 +0200541 ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200542 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200543 /* check parsed values */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200544 assert_string_equal(def.str, "default-value");
Michal Vaskofc2cd072021-02-24 13:17:17 +0100545 const char *exts_name = "myext:custom";
Radek Iša56ca9e42020-09-08 18:42:00 +0200546 const char *exts_arg = "totally amazing extension";
547
Radek Krejci85ac8312021-03-03 20:21:33 +0100548 CHECK_LYSP_EXT_INSTANCE(exts, exts_arg, 0, LY_STMT_PREFIX, 0, exts_name, LY_PREF_XML);
David Sedlák555c7202019-07-04 12:14:12 +0200549 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200550 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200551 assert_string_equal(when_p->cond, "condition...");
552 assert_string_equal(when_p->dsc, "when_desc");
553 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200554 assert_int_equal(config, LYS_CONFIG_W);
Radek Iša56ca9e42020-09-08 18:42:00 +0200555 CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25);
556 CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5);
David Sedlákcf5569a2019-07-11 13:31:34 +0200557 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200558 assert_true(req_type.flags &= LYS_SET_REQINST);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200559 assert_string_equal(range_type.range->arg.str, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200560 assert_true(range_type.flags & LYS_SET_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +0200561 assert_string_equal(error_message, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200562 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200563 assert_string_equal(enum_type.enums->name, "yay");
Radek Iša56ca9e42020-09-08 18:42:00 +0200564 CHECK_LYSP_RESTR(len_type.length, "baf", NULL,
565 NULL, NULL, 0, NULL);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200566 assert_true(len_type.flags & LYS_SET_LENGTH);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200567 assert_string_equal(patter_type.patterns->arg.str, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200568 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200569 /* cleanup */
Radek Iša56ca9e42020-09-08 18:42:00 +0200570 lysp_ext_instance_free(UTEST_LYCTX, exts);
571 lysp_when_free(UTEST_LYCTX, when_p);
572 lysp_ext_free(UTEST_LYCTX, ext_def);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100573 lydict_remove(UTEST_LYCTX, *if_features);
574 lydict_remove(UTEST_LYCTX, error_message);
575 lydict_remove(UTEST_LYCTX, app_tag);
576 lydict_remove(UTEST_LYCTX, units);
577 lydict_remove(UTEST_LYCTX, patter_type.patterns->arg.str);
578 lydict_remove(UTEST_LYCTX, def.str);
579 lydict_remove(UTEST_LYCTX, range_type.range->arg.str);
580 lydict_remove(UTEST_LYCTX, len_type.length->arg.str);
581 lydict_remove(UTEST_LYCTX, enum_type.enums->name);
582 lydict_remove(UTEST_LYCTX, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200583 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200584 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200585 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200586 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200587 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200588 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200589 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200590 free(len_type.length);
Radek Iša56ca9e42020-09-08 18:42:00 +0200591 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200592
593 /* test unique subelem */
594 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200595 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100596 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
597
David Sedláke6cd89e2019-08-07 12:46:02 +0200598 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100599 "<prefix value=\"inv_mod\" />"
600 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
601 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
602 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200603 ly_in_new_memory(data, &UTEST_IN);
604 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
605 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100606
Radek Iša56ca9e42020-09-08 18:42:00 +0200607 ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200608 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200609 CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1.");
610 lydict_remove(UTEST_LYCTX, prefix_value);
611 lydict_remove(UTEST_LYCTX, value);
612 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200613
614 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200615 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100616 "<prefix value=\"inv_mod\" />"
617 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
618 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
619 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200620 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100621 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
622
Radek Iša56ca9e42020-09-08 18:42:00 +0200623 ly_in_new_memory(data, &UTEST_IN);
624 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
625 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100626
Radek Iša56ca9e42020-09-08 18:42:00 +0200627 ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200628 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200629 CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1.");
630 lydict_remove(UTEST_LYCTX, prefix_value);
631 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200632
633 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200634 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200635 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100636
Radek Iša56ca9e42020-09-08 18:42:00 +0200637 ly_in_new_memory(data, &UTEST_IN);
638 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
639 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100640
Radek Iša56ca9e42020-09-08 18:42:00 +0200641 ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200642 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200643 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200644}
645
David Sedlák92147b02019-07-09 14:01:01 +0200646static void
David Sedlák4a650532019-07-10 11:55:18 +0200647test_validate_value(void **state)
648{
Michal Vaskob36053d2020-03-26 15:49:30 +0100649 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
650
651 /* create some XML context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200652 ly_in_new_memory(data, &UTEST_IN);
653 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
654 YCTX->xmlctx->status = LYXML_ELEM_CONTENT;
655 YCTX->xmlctx->dynamic = 0;
Michal Vaskob36053d2020-03-26 15:49:30 +0100656
Radek Iša56ca9e42020-09-08 18:42:00 +0200657 YCTX->xmlctx->value = "#invalid";
658 YCTX->xmlctx->value_len = 8;
659 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
Radek Iša2eac74c2021-03-15 15:53:08 +0100660 CHECK_LOG_CTX("Invalid identifier first character '#' (0x0023).", "Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100661
Radek Iša56ca9e42020-09-08 18:42:00 +0200662 YCTX->xmlctx->value = "";
663 YCTX->xmlctx->value_len = 0;
664 assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100665
Radek Iša56ca9e42020-09-08 18:42:00 +0200666 YCTX->xmlctx->value = "pre:b";
667 YCTX->xmlctx->value_len = 5;
668 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
669 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100670
Radek Iša56ca9e42020-09-08 18:42:00 +0200671 YCTX->xmlctx->value = "pre:pre:b";
672 YCTX->xmlctx->value_len = 9;
673 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200674}
675
David Sedlák32488102019-07-15 17:44:10 +0200676/* helper function to simplify unit test of each element using parse_content function */
677LY_ERR
Radek Iša56ca9e42020-09-08 18:42:00 +0200678test_element_helper(void **state, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
David Sedlák32488102019-07-15 17:44:10 +0200679{
David Sedlákc5b20842019-08-13 10:18:31 +0200680 const char *name, *prefix;
681 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200682 LY_ERR ret = LY_SUCCESS;
683 struct yin_subelement subelems[71] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100684 {LY_STMT_ACTION, dest, 0},
685 {LY_STMT_ANYDATA, dest, 0},
686 {LY_STMT_ANYXML, dest, 0},
687 {LY_STMT_ARGUMENT, dest, 0},
688 {LY_STMT_AUGMENT, dest, 0},
689 {LY_STMT_BASE, dest, 0},
690 {LY_STMT_BELONGS_TO, dest, 0},
691 {LY_STMT_BIT, dest, 0},
692 {LY_STMT_CASE, dest, 0},
693 {LY_STMT_CHOICE, dest, 0},
694 {LY_STMT_CONFIG, dest, 0},
695 {LY_STMT_CONTACT, dest, 0},
696 {LY_STMT_CONTAINER, dest, 0},
697 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
698 {LY_STMT_DESCRIPTION, dest, 0},
699 {LY_STMT_DEVIATE, dest, 0},
700 {LY_STMT_DEVIATION, dest, 0},
701 {LY_STMT_ENUM, dest, 0},
702 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
703 {LY_STMT_ERROR_MESSAGE, dest, 0},
704 {LY_STMT_EXTENSION, dest, 0},
705 {LY_STMT_FEATURE, dest, 0},
706 {LY_STMT_FRACTION_DIGITS, dest, 0},
707 {LY_STMT_GROUPING, dest, 0},
708 {LY_STMT_IDENTITY, dest, 0},
709 {LY_STMT_IF_FEATURE, dest, 0},
710 {LY_STMT_IMPORT, dest, 0},
711 {LY_STMT_INCLUDE, dest, 0},
712 {LY_STMT_INPUT, dest, 0},
713 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
714 {LY_STMT_LEAF, dest, 0},
715 {LY_STMT_LEAF_LIST, dest, 0},
716 {LY_STMT_LENGTH, dest, 0},
717 {LY_STMT_LIST, dest, 0},
718 {LY_STMT_MANDATORY, dest, 0},
719 {LY_STMT_MAX_ELEMENTS, dest, 0},
720 {LY_STMT_MIN_ELEMENTS, dest, 0},
721 {LY_STMT_MODIFIER, dest, 0},
722 {LY_STMT_MODULE, dest, 0},
723 {LY_STMT_MUST, dest, 0},
724 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
725 {LY_STMT_NOTIFICATION, dest, 0},
726 {LY_STMT_ORDERED_BY, dest, 0},
727 {LY_STMT_ORGANIZATION, dest, 0},
728 {LY_STMT_OUTPUT, dest, 0},
729 {LY_STMT_PATH, dest, 0},
730 {LY_STMT_PATTERN, dest, 0},
731 {LY_STMT_POSITION, dest, 0},
732 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
733 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
734 {LY_STMT_RANGE, dest, 0},
735 {LY_STMT_REFERENCE, dest, 0},
736 {LY_STMT_REFINE, dest, 0},
737 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
738 {LY_STMT_REVISION, dest, 0},
739 {LY_STMT_REVISION_DATE, dest, 0},
740 {LY_STMT_RPC, dest, 0},
741 {LY_STMT_STATUS, dest, 0},
742 {LY_STMT_SUBMODULE, dest, 0},
743 {LY_STMT_TYPE, dest, 0},
744 {LY_STMT_TYPEDEF, dest, 0},
745 {LY_STMT_UNIQUE, dest, 0},
746 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
747 {LY_STMT_USES, dest, 0},
748 {LY_STMT_VALUE, dest, 0},
749 {LY_STMT_WHEN, dest, 0},
750 {LY_STMT_YANG_VERSION, dest, 0},
751 {LY_STMT_YIN_ELEMENT, dest, 0},
752 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
753 {LY_STMT_ARG_TEXT, dest, 0},
754 {LY_STMT_ARG_VALUE, dest, 0}
755 };
756
Radek Iša56ca9e42020-09-08 18:42:00 +0200757 ly_in_new_memory(data, &UTEST_IN);
758 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
759 prefix = YCTX->xmlctx->prefix;
760 prefix_len = YCTX->xmlctx->prefix_len;
761 name = YCTX->xmlctx->name;
762 name_len = YCTX->xmlctx->name_len;
763 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100764
Radek Iša56ca9e42020-09-08 18:42:00 +0200765 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 +0100766
Michal Vasko63f3d842020-07-08 10:10:14 +0200767 /* free parser and input */
Radek Iša56ca9e42020-09-08 18:42:00 +0200768 lyxml_ctx_free(YCTX->xmlctx);
769 YCTX->xmlctx = NULL;
770 ly_in_free(UTEST_IN, 0);
771 UTEST_IN = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200772 return ret;
773}
774
David Sedlákd1144562019-08-06 12:36:14 +0200775#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
776
David Sedlák32488102019-07-15 17:44:10 +0200777static void
David Sedlák43801c92019-08-05 15:58:54 +0200778test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200779{
David Sedlák32488102019-07-15 17:44:10 +0200780 struct lysp_type type = {};
781 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100782
David Sedlák32488102019-07-15 17:44:10 +0200783 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100784 "<enum name=\"enum-name\">\n"
785 " <if-feature name=\"feature\" />\n"
786 " <value value=\"55\" />\n"
787 " <status value=\"deprecated\" />\n"
788 " <description><text>desc...</text></description>\n"
789 " <reference><text>ref...</text></reference>\n"
790 " " EXT_SUBELEM "\n"
791 "</enum>"
792 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200793 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
794 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
795
796 CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200797 assert_string_equal(type.enums->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100798 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LY_STMT_ENUM);
Radek Iša56ca9e42020-09-08 18:42:00 +0200799 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200800 memset(&type, 0, sizeof type);
801
802 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100803 "<enum name=\"enum-name\"></enum>"
804 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200805 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200806 assert_string_equal(type.enums->name, "enum-name");
Radek Iša56ca9e42020-09-08 18:42:00 +0200807 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák32488102019-07-15 17:44:10 +0200808 memset(&type, 0, sizeof type);
David Sedlák43801c92019-08-05 15:58:54 +0200809}
810
811static void
812test_bit_elem(void **state)
813{
David Sedlák43801c92019-08-05 15:58:54 +0200814 struct lysp_type type = {};
815 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100816
David Sedlák43801c92019-08-05 15:58:54 +0200817 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100818 "<bit name=\"bit-name\">\n"
819 " <if-feature name=\"feature\" />\n"
820 " <position value=\"55\" />\n"
821 " <status value=\"deprecated\" />\n"
822 " <description><text>desc...</text></description>\n"
823 " <reference><text>ref...</text></reference>\n"
824 EXT_SUBELEM
825 "</bit>"
826 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200827 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
828 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
829
830 CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200831 assert_string_equal(type.bits->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100832 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LY_STMT_BIT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200833 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200834 memset(&type, 0, sizeof type);
835
836 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100837 "<bit name=\"bit-name\"> </bit>"
838 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200839 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
840 CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
841 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák43801c92019-08-05 15:58:54 +0200842 memset(&type, 0, sizeof type);
David Sedlák32488102019-07-15 17:44:10 +0200843}
844
845static void
846test_meta_elem(void **state)
847{
David Sedlák32488102019-07-15 17:44:10 +0200848 char *value = NULL;
849 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200850 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200851
852 /* organization element */
853 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100854 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
855 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200856 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100857 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORGANIZATION);
858 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LY_STMT_ORGANIZATION);
Radek Iša56ca9e42020-09-08 18:42:00 +0200859
David Sedlák32488102019-07-15 17:44:10 +0200860 assert_string_equal(value, "organization...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100861 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200862 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200863 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200864 exts = NULL;
865
David Sedlák32488102019-07-15 17:44:10 +0200866 /* contact element */
867 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100868 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
869 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200870 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100871 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200872 assert_string_equal(value, "contact...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100873 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200874 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200875 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200876 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200877
David Sedlák32488102019-07-15 17:44:10 +0200878 /* description element */
879 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100880 "<description><text>description...</text>" EXT_SUBELEM "</description>"
881 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200882 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100883 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200884 assert_string_equal(value, "description...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100885 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200886 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200887 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200888 exts = NULL;
889
David Sedlák32488102019-07-15 17:44:10 +0200890 /* reference element */
891 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100892 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
893 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200894 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200895 assert_string_equal(value, "reference...");
Radek Krejcifc596f92021-02-26 22:40:26 +0100896 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REFERENCE);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100897 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200898 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200899 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200900 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200901
David Sedlákdf2a9732019-08-07 13:23:16 +0200902 /* reference element */
903 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100904 "<reference invalid=\"text\"><text>reference...</text>" "</reference>"
905 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200906 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
907 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100908 lydict_remove(UTEST_LYCTX, value);
David Sedlákdf2a9732019-08-07 13:23:16 +0200909 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200910 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákdf2a9732019-08-07 13:23:16 +0200911 exts = NULL;
912
David Sedlák32488102019-07-15 17:44:10 +0200913 /* missing text subelement */
914 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100915 "<reference>reference...</reference>"
916 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200917 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
918 CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +0200919
David Sedlákd1144562019-08-06 12:36:14 +0200920 /* reference element */
921 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100922 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
923 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200924 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
925 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 +0100926 lydict_remove(UTEST_LYCTX, value);
David Sedlákd1144562019-08-06 12:36:14 +0200927 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200928 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200929 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200930}
931
932static void
933test_import_elem(void **state)
934{
David Sedlák32488102019-07-15 17:44:10 +0200935 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +0200936 struct lysp_import *imports = NULL;
937 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +0200938
939 /* max subelems */
940 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100941 "<import module=\"a\">\n"
942 EXT_SUBELEM
943 " <prefix value=\"a_mod\"/>\n"
944 " <revision-date date=\"2015-01-01\"></revision-date>\n"
945 " <description><text>import description</text></description>\n"
946 " <reference><text>import reference</text></reference>\n"
947 "</import>"
948 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200949 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
950 CHECK_LYSP_IMPORT(imports, "import description", 1, "a",
951 "a_mod", "import reference", "2015-01-01");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100952 TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LY_STMT_IMPORT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200953 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200954 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200955
956 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +0200957 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100958 "<import module=\"a\">\n"
959 " <prefix value=\"a_mod\"/>\n"
960 "</import>"
961 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200962 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
963 CHECK_LYSP_IMPORT(imports, NULL, 0, "a",
964 "a_mod", NULL, "");
965 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200966 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200967
968 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +0200969 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200970 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
971 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1.");
972 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200973 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200974
975 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +0200976 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100977 "<import module=\"a\">\n"
978 " <prefix value=\"prefix\"/>\n"
979 "</import>"
980 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200981 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
982 CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3.");
983 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200984 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200985
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100986 data = ELEMENT_WRAPPER_START
987 "<import module=\"a\">\n"
988 " <prefix value=\"a\"/>\n"
989 "</import>\n"
990 "<import module=\"a\">\n"
991 " <prefix value=\"a\"/>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200992 "</import>\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100993 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200994 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
995 CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6.");
996 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100997 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200998}
999
1000static void
1001test_status_elem(void **state)
1002{
David Sedlák32488102019-07-15 17:44:10 +02001003 const char *data;
1004 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001005 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001006
1007 /* test valid values */
1008 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001009 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001010 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001011
1012 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001013 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001014 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001015
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001016 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001017 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001018 assert_true(flags & LYS_STATUS_OBSLT);
Radek Krejcifc596f92021-02-26 22:40:26 +01001019 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_STATUS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001020 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001021 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001022
1023 /* test invalid value */
1024 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001025 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1026 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. "
1027 "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001028}
1029
1030static void
1031test_ext_elem(void **state)
1032{
David Sedlák32488102019-07-15 17:44:10 +02001033 const char *data;
1034 struct lysp_ext *ext = NULL;
1035
1036 /* max subelems */
1037 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001038 "<extension name=\"ext_name\">\n"
1039 " <argument name=\"arg\"></argument>\n"
1040 " <status value=\"current\"/>\n"
1041 " <description><text>ext_desc</text></description>\n"
1042 " <reference><text>ext_ref</text></reference>\n"
1043 EXT_SUBELEM
1044 "</extension>"
1045 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001046 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1047 CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001048 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LY_STMT_EXTENSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001049 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001050 LY_ARRAY_FREE(ext);
1051 ext = NULL;
1052
1053 /* min subelems */
1054 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001055 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1056 CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL);
1057 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001058 LY_ARRAY_FREE(ext);
1059 ext = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001060}
1061
1062static void
1063test_yin_element_elem(void **state)
1064{
David Sedlák32488102019-07-15 17:44:10 +02001065 const char *data;
1066 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001067 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001068
1069 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001070 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001071 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001072
David Sedlákd1144562019-08-06 12:36:14 +02001073 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001074 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001075 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001076 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YIN_ELEMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001077 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001078
1079 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001080 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001081 assert_true(flags & LYS_YINELEM_TRUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001082 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. "
1083 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001084}
1085
1086static void
1087test_yangversion_elem(void **state)
1088{
David Sedlák32488102019-07-15 17:44:10 +02001089 const char *data;
1090 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001091 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001092
1093 /* valid values */
Radek Krejci96e48da2020-09-04 13:18:06 +02001094 data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001095 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001096 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001097
David Sedlákd1144562019-08-06 12:36:14 +02001098 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001099 assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001100 assert_true(version & LYS_VERSION_1_1);
Radek Krejcifc596f92021-02-26 22:40:26 +01001101 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YANG_VERSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001102 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001103
1104 /* invalid value */
1105 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001106 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID);
1107 CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. "
1108 "Valid values are \"1\" and \"1.1\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001109}
1110
1111static void
1112test_mandatory_elem(void **state)
1113{
David Sedlák32488102019-07-15 17:44:10 +02001114 const char *data;
1115 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001116 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001117
1118 /* valid values */
1119 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001120 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001121 assert_int_equal(man, LYS_MAND_TRUE);
1122 man = 0;
1123
David Sedlákd1144562019-08-06 12:36:14 +02001124 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001125 assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001126 assert_int_equal(man, LYS_MAND_FALSE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001127 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MANDATORY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001128 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001129
1130 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001131 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID);
1132 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. "
1133 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001134}
1135
David Sedlák8e7bda82019-07-16 17:57:50 +02001136static void
1137test_argument_elem(void **state)
1138{
David Sedlák8e7bda82019-07-16 17:57:50 +02001139 const char *data;
1140 uint16_t flags = 0;
1141 const char *arg;
1142 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001143 struct lysp_ext_instance *exts = NULL;
1144
David Sedlák8e7bda82019-07-16 17:57:50 +02001145 /* max subelems */
1146 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001147 "<argument name=\"arg-name\">\n"
1148 " <yin-element value=\"true\" />\n"
1149 EXT_SUBELEM
1150 "</argument>"
1151 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001152 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001153 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001154 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001155 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ARGUMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001156 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001157 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001158 flags = 0;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001159 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001160 arg = NULL;
1161
1162 /* min subelems */
1163 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001164 "<argument name=\"arg\">"
1165 "</argument>"
1166 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001167 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001168 assert_string_equal(arg, "arg");
1169 assert_true(flags == 0);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001170 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001171}
1172
1173static void
1174test_base_elem(void **state)
1175{
David Sedlák8e7bda82019-07-16 17:57:50 +02001176 const char *data;
1177 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001178 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001179 struct lysp_type type = {};
1180
1181 /* as identity subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001182 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1183 " <base name=\"base-name\">\n"
1184 EXT_SUBELEM
1185 " </base>\n"
1186 "</identity>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001187 assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001188 assert_string_equal(*bases, "base-name");
Radek Krejcifc596f92021-02-26 22:40:26 +01001189 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001190 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001191 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001192 lydict_remove(UTEST_LYCTX, *bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001193 LY_ARRAY_FREE(bases);
1194
1195 /* as type subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001196 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1197 " <base name=\"base-name\">\n"
1198 EXT_SUBELEM
1199 " </base>\n"
1200 "</type>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001201 assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001202 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001203 assert_true(type.flags & LYS_SET_BASE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001204 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001205 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001206 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001207 lydict_remove(UTEST_LYCTX, *type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001208 LY_ARRAY_FREE(type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001209}
1210
1211static void
1212test_belongsto_elem(void **state)
1213{
David Sedlák8e7bda82019-07-16 17:57:50 +02001214 const char *data;
1215 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001216 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001217
Radek Iša56ca9e42020-09-08 18:42:00 +02001218 lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name);
1219
David Sedlák8e7bda82019-07-16 17:57:50 +02001220 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001221 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
1222 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001223 assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001224 assert_string_equal(submod.prefix, "pref");
Radek Krejcifc596f92021-02-26 22:40:26 +01001225 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BELONGS_TO);
Radek Iša56ca9e42020-09-08 18:42:00 +02001226 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001227 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001228 lydict_remove(UTEST_LYCTX, submod.prefix);
David Sedlák8e7bda82019-07-16 17:57:50 +02001229
1230 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001231 assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID);
1232 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001233}
1234
1235static void
1236test_config_elem(void **state)
1237{
David Sedlák8e7bda82019-07-16 17:57:50 +02001238 const char *data;
1239 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001240 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001241
David Sedlákd1144562019-08-06 12:36:14 +02001242 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001243 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001244 assert_true(flags & LYS_CONFIG_W);
Radek Krejcifc596f92021-02-26 22:40:26 +01001245 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONFIG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001246 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001247 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001248 flags = 0;
1249
1250 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001251 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001252 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001253 flags = 0;
1254
1255 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001256 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1257 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. "
1258 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001259}
1260
1261static void
1262test_default_elem(void **state)
1263{
David Sedlák8e7bda82019-07-16 17:57:50 +02001264 const char *data;
Michal Vasko7f45cf22020-10-01 12:49:44 +02001265 struct lysp_qname val = {0};
David Sedlákd1144562019-08-06 12:36:14 +02001266 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001267
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001268 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001269 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001270 assert_string_equal(val.str, "defaul-value");
Radek Krejcifc596f92021-02-26 22:40:26 +01001271 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DEFAULT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001272 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001273 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001274 lydict_remove(UTEST_LYCTX, val.str);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001275 val.str = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001276
1277 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001278 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1279 CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001280}
1281
1282static void
1283test_err_app_tag_elem(void **state)
1284{
David Sedlák8e7bda82019-07-16 17:57:50 +02001285 const char *data;
1286 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001287 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001288
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001289 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 +02001290 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001291 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001292 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_APP_TAG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001293 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001294 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001295 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001296 val = NULL;
1297
1298 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001299 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1300 CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001301}
1302
1303static void
1304test_err_msg_elem(void **state)
1305{
David Sedlák8e7bda82019-07-16 17:57:50 +02001306 const char *data;
1307 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001308 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001309
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001310 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001311 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001312 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001313 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_MESSAGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001314 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001315 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001316 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001317
1318 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001319 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1320 CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001321
David Sedlákdf2a9732019-08-07 13:23:16 +02001322 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001323 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1324 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001325}
1326
1327static void
1328test_fracdigits_elem(void **state)
1329{
David Sedlák8e7bda82019-07-16 17:57:50 +02001330 const char *data;
1331 struct lysp_type type = {};
1332
1333 /* valid value */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001334 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001335 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
Radek Krejci5984d222021-02-26 23:01:45 +01001336 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_FRACTION_DIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001337 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001338 assert_true(type.flags & LYS_SET_FRDIGITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001339 FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001340
1341 /* invalid values */
1342 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001343 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1344 CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001345
1346 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001347 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1348 CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001349
1350 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001351 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1352 CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001353
1354 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001355 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1356 CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001357
1358 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001359 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1360 CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001361}
1362
1363static void
1364test_iffeature_elem(void **state)
1365{
David Sedlák8e7bda82019-07-16 17:57:50 +02001366 const char *data;
1367 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001368 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001369
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001370 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001371 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001372 assert_string_equal(*iffeatures, "local-storage");
Radek Krejci5984d222021-02-26 23:01:45 +01001373 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_IF_FEATURE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001374 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001375 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001376 lydict_remove(UTEST_LYCTX, *iffeatures);
David Sedlák8e7bda82019-07-16 17:57:50 +02001377 LY_ARRAY_FREE(iffeatures);
1378 iffeatures = NULL;
1379
1380 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001381 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID);
1382 CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001383 LY_ARRAY_FREE(iffeatures);
1384 iffeatures = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001385}
1386
1387static void
1388test_length_elem(void **state)
1389{
David Sedlák8e7bda82019-07-16 17:57:50 +02001390 const char *data;
1391 struct lysp_type type = {};
1392
1393 /* max subelems */
1394 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001395 "<length value=\"length-str\">\n"
1396 " <error-message><value>err-msg</value></error-message>\n"
1397 " <error-app-tag value=\"err-app-tag\"/>\n"
1398 " <description><text>desc</text></description>\n"
1399 " <reference><text>ref</text></reference>\n"
1400 EXT_SUBELEM
1401 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001402 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001403 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1404 CHECK_LYSP_RESTR(type.length, "length-str", "desc",
1405 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001406 assert_true(type.flags & LYS_SET_LENGTH);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001407 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LY_STMT_LENGTH);
Radek Iša56ca9e42020-09-08 18:42:00 +02001408 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001409 memset(&type, 0, sizeof(type));
1410
1411 /* min subelems */
1412 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001413 "<length value=\"length-str\">"
1414 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001415 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001416 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1417 CHECK_LYSP_RESTR(type.length, "length-str", NULL,
1418 NULL, NULL, 0, NULL);
1419 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001420 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001421 memset(&type, 0, sizeof(type));
1422
1423 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001424 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1425 CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
1426 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001427 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001428}
1429
1430static void
1431test_modifier_elem(void **state)
1432{
David Sedlák8e7bda82019-07-16 17:57:50 +02001433 const char *data;
Radek Krejci011e4aa2020-09-04 15:22:31 +02001434 const char *pat;
David Sedlákd1144562019-08-06 12:36:14 +02001435 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001436
Radek Iša56ca9e42020-09-08 18:42:00 +02001437 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlákd1144562019-08-06 12:36:14 +02001438 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001439 assert_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001440 assert_string_equal(pat, "\x015pattern");
Radek Krejci5984d222021-02-26 23:01:45 +01001441 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MODIFIER);
Radek Iša56ca9e42020-09-08 18:42:00 +02001442 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001443 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001444 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001445
Radek Iša56ca9e42020-09-08 18:42:00 +02001446 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlák8e7bda82019-07-16 17:57:50 +02001447 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001448 assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID);
1449 CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. "
1450 "Only valid value is \"invert-match\".", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001451 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001452}
1453
1454static void
1455test_namespace_elem(void **state)
1456{
David Sedlák8e7bda82019-07-16 17:57:50 +02001457 const char *data;
1458 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001459 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001460
David Sedlákd1144562019-08-06 12:36:14 +02001461 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001462 assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001463 assert_string_equal(ns, "ns");
Radek Krejci5984d222021-02-26 23:01:45 +01001464 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_NAMESPACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001465 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001466 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001467 lydict_remove(UTEST_LYCTX, ns);
David Sedlák8e7bda82019-07-16 17:57:50 +02001468
1469 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001470 assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID);
1471 CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001472}
1473
1474static void
David Sedlák8e7bda82019-07-16 17:57:50 +02001475test_pattern_elem(void **state)
1476{
David Sedlák8e7bda82019-07-16 17:57:50 +02001477 const char *data;
1478 struct lysp_type type = {};
1479
1480 /* max subelems */
1481 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001482 "<pattern value=\"super_pattern\">\n"
1483 " <modifier value=\"invert-match\"/>\n"
1484 " <error-message><value>err-msg-value</value></error-message>\n"
1485 " <error-app-tag value=\"err-app-tag-value\"/>\n"
1486 " <description><text>&quot;pattern-desc&quot;</text></description>\n"
1487 " <reference><text>pattern-ref</text></reference>\n"
1488 EXT_SUBELEM
1489 "</pattern>"
1490 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001491 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001492 assert_true(type.flags & LYS_SET_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001493 CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
1494 "err-app-tag-value", "err-msg-value", 1, "pattern-ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001495 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LY_STMT_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001496 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001497 memset(&type, 0, sizeof(type));
1498
1499 /* min subelems */
1500 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001501 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1502 CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
1503 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001504 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001505}
1506
1507static void
1508test_value_position_elem(void **state)
1509{
David Sedlák8e7bda82019-07-16 17:57:50 +02001510 const char *data;
1511 struct lysp_type_enum en = {};
1512
1513 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001514 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001515 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1516 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001517 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_VALUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001518 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001519 memset(&en, 0, sizeof(en));
1520
1521 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001522 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1523 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55);
David Sedlák8e7bda82019-07-16 17:57:50 +02001524 memset(&en, 0, sizeof(en));
1525
1526 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" 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, 0);
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 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001537 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001538 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1539 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001540 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_POSITION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001541 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001542 memset(&en, 0, sizeof(en));
1543
1544 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001545 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1546 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001547 memset(&en, 0, sizeof(en));
1548
1549 /* invalid values */
1550 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001551 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1552 CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001553
1554 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001555 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1556 CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001557
David Sedlák69f01612019-07-17 11:41:08 +02001558 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001559 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1560 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001561
David Sedlák8e7bda82019-07-16 17:57:50 +02001562 /*invalid positions */
1563 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" 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 \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001566
1567 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001568 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1569 CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001570
1571 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001572 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1573 CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001574
David Sedlák69f01612019-07-17 11:41:08 +02001575 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001576 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1577 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001578}
1579
1580static void
1581test_prefix_elem(void **state)
1582{
David Sedlák69f01612019-07-17 11:41:08 +02001583 const char *data;
1584 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001585 struct lysp_ext_instance *exts = NULL;
1586
1587 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001588 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001589 assert_string_equal(value, "pref");
Radek Krejci5984d222021-02-26 23:01:45 +01001590 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PREFIX);
Radek Iša56ca9e42020-09-08 18:42:00 +02001591 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001592 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001593 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001594
1595 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001596 assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001597 assert_string_equal(value, "pref");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001598 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001599}
1600
1601static void
1602test_range_elem(void **state)
1603{
David Sedlák69f01612019-07-17 11:41:08 +02001604 const char *data;
1605 struct lysp_type type = {};
1606
1607 /* max subelems */
1608 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001609 "<range value=\"range-str\">\n"
1610 " <error-message><value>err-msg</value></error-message>\n"
1611 " <error-app-tag value=\"err-app-tag\" />\n"
1612 " <description><text>desc</text></description>\n"
1613 " <reference><text>ref</text></reference>\n"
1614 EXT_SUBELEM
1615 "</range>"
1616 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001617 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1618 CHECK_LYSP_RESTR(type.range, "range-str", "desc",
1619 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001620 assert_true(type.flags & LYS_SET_RANGE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001621 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LY_STMT_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001622 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001623 memset(&type, 0, sizeof(type));
1624
1625 /* min subelems */
1626 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001627 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1628 CHECK_LYSP_RESTR(type.range, "range-str", NULL,
1629 NULL, NULL, 0, NULL);
1630 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001631 memset(&type, 0, sizeof(type));
David Sedlák69f01612019-07-17 11:41:08 +02001632}
1633
1634static void
1635test_reqinstance_elem(void **state)
1636{
David Sedlák69f01612019-07-17 11:41:08 +02001637 const char *data;
1638 struct lysp_type type = {};
1639
David Sedlákd1144562019-08-06 12:36:14 +02001640 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001641 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001642 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001643 assert_true(type.flags & LYS_SET_REQINST);
Radek Krejci5984d222021-02-26 23:01:45 +01001644 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_REQUIRE_INSTANCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001645 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001646 memset(&type, 0, sizeof(type));
1647
1648 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001649 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001650 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001651 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001652 memset(&type, 0, sizeof(type));
1653
1654 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001655 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001656 memset(&type, 0, sizeof(type));
Radek Iša56ca9e42020-09-08 18:42:00 +02001657 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. "
1658 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001659}
1660
1661static void
1662test_revision_date_elem(void **state)
1663{
David Sedlák69f01612019-07-17 11:41:08 +02001664 const char *data;
1665 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001666 struct lysp_ext_instance *exts = NULL;
1667
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001668 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 +02001669 assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001670 assert_string_equal(rev, "2000-01-01");
Radek Krejci5984d222021-02-26 23:01:45 +01001671 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REVISION_DATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001672 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001673
1674 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001675 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001676 assert_string_equal(rev, "2000-01-01");
1677
1678 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001679 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID);
1680 CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001681}
1682
1683static void
1684test_unique_elem(void **state)
1685{
David Sedlák69f01612019-07-17 11:41:08 +02001686 const char *data;
1687 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001688 struct lysp_ext_instance *exts = NULL;
1689
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001690 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001691 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001692 assert_string_equal(*values, "tag");
Radek Krejci5984d222021-02-26 23:01:45 +01001693 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNIQUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001694 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001695 lydict_remove(UTEST_LYCTX, *values);
David Sedlákd1144562019-08-06 12:36:14 +02001696 LY_ARRAY_FREE(values);
1697 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001698
1699 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001700 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001701 assert_string_equal(*values, "tag");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001702 lydict_remove(UTEST_LYCTX, *values);
David Sedlák69f01612019-07-17 11:41:08 +02001703 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001704 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001705}
1706
1707static void
1708test_units_elem(void **state)
1709{
David Sedlák69f01612019-07-17 11:41:08 +02001710 const char *data;
1711 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001712 struct lysp_ext_instance *exts = NULL;
1713
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001714 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001715 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001716 assert_string_equal(values, "name");
Radek Krejci5984d222021-02-26 23:01:45 +01001717 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001718 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001719 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001720 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001721
1722 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001723 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001724 assert_string_equal(values, "name");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001725 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001726 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001727}
1728
1729static void
1730test_when_elem(void **state)
1731{
David Sedlák69f01612019-07-17 11:41:08 +02001732 const char *data;
1733 struct lysp_when *when = NULL;
1734
1735 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001736 "<when condition=\"cond\">\n"
1737 " <description><text>desc</text></description>\n"
1738 " <reference><text>ref</text></reference>\n"
1739 EXT_SUBELEM
1740 "</when>"
1741 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001742 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1743 CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001744 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]), LY_STMT_WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001745 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001746 free(when);
1747 when = NULL;
1748
1749 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001750 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1751 CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL);
1752 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001753 free(when);
1754 when = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001755}
1756
1757static void
1758test_yin_text_value_elem(void **state)
1759{
David Sedlák69f01612019-07-17 11:41:08 +02001760 const char *data;
1761 const char *val;
1762
1763 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001764 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001765 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001766 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001767
1768 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 +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 = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
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);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001776 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001777}
David Sedlák32488102019-07-15 17:44:10 +02001778
David Sedlák374d2b32019-07-17 15:06:55 +02001779static void
1780test_type_elem(void **state)
1781{
David Sedlák374d2b32019-07-17 15:06:55 +02001782 const char *data;
1783 struct lysp_type type = {};
1784
1785 /* max subelems */
1786 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001787 "<type name=\"type-name\">\n"
1788 " <base name=\"base-name\"/>\n"
1789 " <bit name=\"bit\"/>\n"
1790 " <enum name=\"enum\"/>\n"
1791 " <fraction-digits value=\"2\"/>\n"
1792 " <length value=\"length\"/>\n"
1793 " <path value=\"/path\"/>\n"
1794 " <pattern value=\"pattern\"/>\n"
1795 " <range value=\"range\" />\n"
1796 " <require-instance value=\"true\"/>\n"
1797 " <type name=\"sub-type-name\"/>\n"
1798 EXT_SUBELEM
1799 "</type>"
1800 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001801 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02001802 assert_string_equal(type.name, "type-name");
1803 assert_string_equal(*type.bases, "base-name");
1804 assert_string_equal(type.bits->name, "bit");
1805 assert_string_equal(type.enums->name, "enum");
1806 assert_int_equal(type.fraction_digits, 2);
Radek Iša56ca9e42020-09-08 18:42:00 +02001807 CHECK_LYSP_RESTR(type.length, "length", NULL,
1808 NULL, NULL, 0, NULL);
Michal Vaskocb8c6d42020-10-16 11:58:30 +02001809 assert_string_equal(type.path->expr, "/path");
Radek Iša56ca9e42020-09-08 18:42:00 +02001810 CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL,
1811 NULL, NULL, 0, NULL);
1812 CHECK_LYSP_RESTR(type.range, "range", NULL,
1813 NULL, NULL, 0, NULL);
David Sedlák374d2b32019-07-17 15:06:55 +02001814 assert_int_equal(type.require_instance, 1);
1815 assert_string_equal(type.types->name, "sub-type-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001816 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_TYPE);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001817 assert_true(type.flags & LYS_SET_BASE);
1818 assert_true(type.flags & LYS_SET_BIT);
1819 assert_true(type.flags & LYS_SET_ENUM);
1820 assert_true(type.flags & LYS_SET_FRDIGITS);
1821 assert_true(type.flags & LYS_SET_LENGTH);
1822 assert_true(type.flags & LYS_SET_PATH);
1823 assert_true(type.flags & LYS_SET_PATTERN);
1824 assert_true(type.flags & LYS_SET_RANGE);
1825 assert_true(type.flags & LYS_SET_REQINST);
1826 assert_true(type.flags & LYS_SET_TYPE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001827 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001828 memset(&type, 0, sizeof(type));
1829
1830 /* min subelems */
1831 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001832 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1833 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001834 memset(&type, 0, sizeof(type));
David Sedlák374d2b32019-07-17 15:06:55 +02001835}
1836
David Sedlák1af868e2019-07-17 17:03:14 +02001837static void
1838test_max_elems_elem(void **state)
1839{
David Sedlák1af868e2019-07-17 17:03:14 +02001840 const char *data;
1841 struct lysp_node_list list = {};
1842 struct lysp_node_leaflist llist = {};
1843 struct lysp_refine refine = {};
1844
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001845 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 +02001846 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001847 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001848 assert_true(refine.flags & LYS_SET_MAX);
Radek Krejci5984d222021-02-26 23:01:45 +01001849 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001850 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001851
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001852 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 +02001853 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001854 assert_int_equal(list.max, 5);
Radek Iša56ca9e42020-09-08 18:42:00 +02001855 CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001856 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001857 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001858
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001859 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 +02001860 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001861 assert_int_equal(llist.max, 85);
Radek Iša56ca9e42020-09-08 18:42:00 +02001862 CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001863 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001864 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001865
1866 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001867 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001868 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001869 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001870
1871 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001872 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1873 CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001874
1875 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001876 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1877 CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001878
1879 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001880 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1881 CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001882
1883 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001884 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1885 CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001886}
1887
David Sedlák09e18c92019-07-18 11:17:11 +02001888static void
1889test_min_elems_elem(void **state)
1890{
David Sedlák09e18c92019-07-18 11:17:11 +02001891 const char *data;
1892 struct lysp_node_list list = {};
1893 struct lysp_node_leaflist llist = {};
1894 struct lysp_refine refine = {};
1895
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001896 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 +02001897 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001898 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001899 assert_true(refine.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001900 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001901 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001902
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001903 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 +02001904 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001905 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001906 assert_true(list.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001907 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001908 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001909
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001910 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 +02001911 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001912 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001913 assert_true(llist.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001914 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001915 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001916
1917 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 +02001918 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1919 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 +02001920
1921 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 +02001922 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1923 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 +02001924
1925 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 +02001926 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1927 CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001928
1929 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 +02001930 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1931 CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001932}
1933
David Sedláka2dad212019-07-18 12:45:19 +02001934static void
1935test_ordby_elem(void **state)
1936{
David Sedláka2dad212019-07-18 12:45:19 +02001937 const char *data;
1938 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001939 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02001940
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001941 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001942 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001943 assert_true(flags & LYS_ORDBY_SYSTEM);
Radek Krejci5984d222021-02-26 23:01:45 +01001944 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORDERED_BY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001945 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02001946
1947 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001948 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001949 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001950
1951 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001952 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1953 CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. "
1954 "Valid values are \"system\" and \"user\".", "Line number 1.");
David Sedláka2dad212019-07-18 12:45:19 +02001955}
1956
David Sedlák8a83bbb2019-07-18 14:46:00 +02001957static void
1958test_any_elem(void **state)
1959{
David Sedlák8a83bbb2019-07-18 14:46:00 +02001960 const char *data;
1961 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02001962 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02001963 struct lysp_node_anydata *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02001964 uint16_t flags;
David Sedlák8a83bbb2019-07-18 14:46:00 +02001965
1966 /* anyxml max subelems */
1967 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001968 "<anyxml name=\"any-name\">\n"
1969 " <config value=\"true\" />\n"
1970 " <description><text>desc</text></description>\n"
1971 " <if-feature name=\"feature\" />\n"
1972 " <mandatory value=\"true\" />\n"
1973 " <must condition=\"must-cond\" />\n"
1974 " <reference><text>ref</text></reference>\n"
1975 " <status value=\"deprecated\"/>\n"
1976 " <when condition=\"when-cond\"/>\n"
1977 EXT_SUBELEM
1978 "</anyxml>"
1979 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001980 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001981 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02001982 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
1983 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
1984 "any-name", 0, LYS_ANYXML, 0, "ref", 1);
1985 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001986 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001987 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYXML);
Radek Iša56ca9e42020-09-08 18:42:00 +02001988 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001989 siblings = NULL;
1990
1991 /* anydata max subelems */
1992 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001993 "<anydata name=\"any-name\">\n"
1994 " <config value=\"true\" />\n"
1995 " <description><text>desc</text></description>\n"
1996 " <if-feature name=\"feature\" />\n"
1997 " <mandatory value=\"true\" />\n"
1998 " <must condition=\"must-cond\" />\n"
1999 " <reference><text>ref</text></reference>\n"
2000 " <status value=\"deprecated\"/>\n"
2001 " <when condition=\"when-cond\"/>\n"
2002 EXT_SUBELEM
2003 "</anydata>"
2004 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002005 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002006 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002007 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2008 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2009 "any-name", 0, LYS_ANYDATA, 0, "ref", 1);
2010 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002011 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002012 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYDATA);
Radek Iša56ca9e42020-09-08 18:42:00 +02002013 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002014 siblings = NULL;
2015
2016 /* min subelems */
2017 node_meta.parent = (void *)0x10;
2018 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002019 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002020 parsed = (struct lysp_node_anydata *)siblings;
2021 assert_ptr_equal(parsed->parent, node_meta.parent);
Radek Iša56ca9e42020-09-08 18:42:00 +02002022 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2023 "any-name", 0, LYS_ANYDATA, 1, NULL, 0);
2024 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002025}
2026
David Sedlák203ca3a2019-07-18 15:26:25 +02002027static void
2028test_leaf_elem(void **state)
2029{
David Sedlák203ca3a2019-07-18 15:26:25 +02002030 const char *data;
2031 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002032 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002033 struct lysp_node_leaf *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002034 uint16_t flags;
David Sedlák203ca3a2019-07-18 15:26:25 +02002035
2036 /* max elements */
2037 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002038 "<leaf name=\"leaf\">\n"
2039 " <config value=\"true\" />\n"
2040 " <default value=\"def-val\"/>\n"
2041 " <description><text>desc</text></description>\n"
2042 " <if-feature name=\"feature\" />\n"
2043 " <mandatory value=\"true\" />\n"
2044 " <must condition=\"must-cond\" />\n"
2045 " <reference><text>ref</text></reference>\n"
2046 " <status value=\"deprecated\"/>\n"
2047 " <type name=\"type\"/>\n"
2048 " <units name=\"uni\"/>\n"
2049 " <when condition=\"when-cond\"/>\n"
2050 EXT_SUBELEM
2051 "</leaf>"
David Sedlák203ca3a2019-07-18 15:26:25 +02002052 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002053 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002054 parsed = (struct lysp_node_leaf *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002055 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2056 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2057 "leaf", 0, LYS_LEAF, 0, "ref", 1);
2058 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002059 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002060 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002061 assert_string_equal(parsed->musts->arg.str, "must-cond");
David Sedlák203ca3a2019-07-18 15:26:25 +02002062 assert_string_equal(parsed->type.name, "type");
2063 assert_string_equal(parsed->units, "uni");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002064 assert_string_equal(parsed->dflt.str, "def-val");
Radek Iša56ca9e42020-09-08 18:42:00 +02002065 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002066 siblings = NULL;
2067
2068 /* min elements */
2069 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002070 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002071 parsed = (struct lysp_node_leaf *)siblings;
2072 assert_string_equal(parsed->name, "leaf");
2073 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002074 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002075 siblings = NULL;
David Sedlák203ca3a2019-07-18 15:26:25 +02002076}
2077
David Sedlákc3da3ef2019-07-19 12:56:08 +02002078static void
2079test_leaf_list_elem(void **state)
2080{
David Sedlákc3da3ef2019-07-19 12:56:08 +02002081 const char *data;
2082 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002083 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002084 struct lysp_node_leaflist *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002085 uint16_t flags;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002086
2087 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002088 "<leaf-list name=\"llist\">\n"
2089 " <config value=\"true\" />\n"
2090 " <default value=\"def-val0\"/>\n"
2091 " <default value=\"def-val1\"/>\n"
2092 " <description><text>desc</text></description>\n"
2093 " <if-feature name=\"feature\"/>\n"
2094 " <max-elements value=\"5\"/>\n"
2095 " <must condition=\"must-cond\"/>\n"
2096 " <ordered-by value=\"user\" />\n"
2097 " <reference><text>ref</text></reference>\n"
2098 " <status value=\"current\"/>\n"
2099 " <type name=\"type\"/>\n"
2100 " <units name=\"uni\"/>\n"
2101 " <when condition=\"when-cond\"/>\n"
2102 EXT_SUBELEM
2103 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002104 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002105 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002106 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002107 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX;
2108 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2109 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2110 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002111 assert_string_equal(parsed->dflts[0].str, "def-val0");
2112 assert_string_equal(parsed->dflts[1].str, "def-val1");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002113 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002114 assert_int_equal(parsed->max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002115 assert_string_equal(parsed->type.name, "type");
2116 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002117 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002118 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002119 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002120 siblings = NULL;
2121
2122 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002123 "<leaf-list name=\"llist\">\n"
2124 " <config value=\"true\" />\n"
2125 " <description><text>desc</text></description>\n"
2126 " <if-feature name=\"feature\"/>\n"
2127 " <min-elements value=\"5\"/>\n"
2128 " <must condition=\"must-cond\"/>\n"
2129 " <ordered-by value=\"user\" />\n"
2130 " <reference><text>ref</text></reference>\n"
2131 " <status value=\"current\"/>\n"
2132 " <type name=\"type\"/>\n"
2133 " <units name=\"uni\"/>\n"
2134 " <when condition=\"when-cond\"/>\n"
2135 EXT_SUBELEM
2136 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002137 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002138 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002139 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002140 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN;
2141 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2142 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2143 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2144 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002145 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002146 assert_int_equal(parsed->min, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002147 assert_string_equal(parsed->type.name, "type");
2148 assert_string_equal(parsed->units, "uni");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002149 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002150 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002151 siblings = NULL;
2152
2153 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002154 "<leaf-list name=\"llist\">\n"
2155 " <config value=\"true\" />\n"
2156 " <description><text>desc</text></description>\n"
2157 " <if-feature name=\"feature\"/>\n"
2158 " <max-elements value=\"15\"/>\n"
2159 " <min-elements value=\"5\"/>\n"
2160 " <must condition=\"must-cond\"/>\n"
2161 " <ordered-by value=\"user\" />\n"
2162 " <reference><text>ref</text></reference>\n"
2163 " <status value=\"current\"/>\n"
2164 " <type name=\"type\"/>\n"
2165 " <units name=\"uni\"/>\n"
2166 " <when condition=\"when-cond\"/>\n"
2167 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002168 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002169 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002170 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002171 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX;
2172 CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1,
2173 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2174 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2175 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002176 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002177 assert_int_equal(parsed->min, 5);
2178 assert_int_equal(parsed->max, 15);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002179 assert_string_equal(parsed->type.name, "type");
2180 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002181 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002182 siblings = NULL;
2183
2184 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002185 "<leaf-list name=\"llist\">\n"
2186 " <type name=\"type\"/>\n"
2187 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002188 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002189 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002190 parsed = (struct lysp_node_leaflist *)siblings;
2191 assert_string_equal(parsed->name, "llist");
2192 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002193 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002194 siblings = NULL;
2195
2196 /* invalid combinations */
2197 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002198 "<leaf-list name=\"llist\">\n"
2199 " <max-elements value=\"5\"/>\n"
2200 " <min-elements value=\"15\"/>\n"
2201 " <type name=\"type\"/>"
2202 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002203 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002204 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2205 CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
2206 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002207 siblings = NULL;
2208
2209 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002210 "<leaf-list name=\"llist\">\n"
2211 " <default value=\"def-val1\"/>\n"
2212 " <min-elements value=\"15\"/>\n"
2213 " <type name=\"type\"/>\n"
2214 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002215 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002216 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2217 CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
2218 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002219 siblings = NULL;
2220
2221 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002222 "<leaf-list name=\"llist\">"
2223 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002224 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002225 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2226 CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
2227 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002228 siblings = NULL;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002229}
2230
David Sedlákcb39f642019-07-19 13:19:55 +02002231static void
2232test_presence_elem(void **state)
2233{
David Sedlákcb39f642019-07-19 13:19:55 +02002234 const char *data;
2235 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002236 struct lysp_ext_instance *exts = NULL;
2237
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002238 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002239 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002240 assert_string_equal(val, "presence-val");
Radek Krejci5984d222021-02-26 23:01:45 +01002241 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PRESENCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002242 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002243 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002244
2245 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002246 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002247 assert_string_equal(val, "presence-val");
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/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002251 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2252 CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1.");
David Sedlákcb39f642019-07-19 13:19:55 +02002253}
2254
David Sedlák12470a82019-07-19 13:44:36 +02002255static void
2256test_key_elem(void **state)
2257{
David Sedlák12470a82019-07-19 13:44:36 +02002258 const char *data;
2259 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002260 struct lysp_ext_instance *exts = NULL;
2261
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002262 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002263 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002264 assert_string_equal(val, "key-value");
Radek Krejci5984d222021-02-26 23:01:45 +01002265 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_KEY);
Radek Iša56ca9e42020-09-08 18:42:00 +02002266 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002267 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002268
2269 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002270 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002271 assert_string_equal(val, "key-value");
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/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002275 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2276 CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1.");
David Sedlák12470a82019-07-19 13:44:36 +02002277}
2278
David Sedlák04e17b22019-07-19 15:29:48 +02002279static void
2280test_typedef_elem(void **state)
2281{
David Sedlák04e17b22019-07-19 15:29:48 +02002282 const char *data;
2283 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002284 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002285
2286 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002287 "<typedef name=\"tpdf-name\">\n"
2288 " <default value=\"def-val\"/>\n"
2289 " <description><text>desc-text</text></description>\n"
2290 " <reference><text>ref-text</text></reference>\n"
2291 " <status value=\"current\"/>\n"
2292 " <type name=\"type\"/>\n"
2293 " <units name=\"uni\"/>\n"
2294 EXT_SUBELEM
2295 "</typedef>"
2296 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002297 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002298 assert_string_equal(tpdfs[0].dflt.str, "def-val");
David Sedlák04e17b22019-07-19 15:29:48 +02002299 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002300 assert_string_equal(tpdfs[0].name, "tpdf-name");
2301 assert_string_equal(tpdfs[0].ref, "ref-text");
2302 assert_string_equal(tpdfs[0].type.name, "type");
2303 assert_string_equal(tpdfs[0].units, "uni");
2304 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002305 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]), LY_STMT_TYPEDEF);
Radek Iša56ca9e42020-09-08 18:42:00 +02002306 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002307 tpdfs = NULL;
2308
2309 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002310 "<typedef name=\"tpdf-name\">\n"
2311 " <type name=\"type\"/>\n"
2312 "</typedef>"
2313 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002314 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002315 assert_string_equal(tpdfs[0].name, "tpdf-name");
2316 assert_string_equal(tpdfs[0].type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002317 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002318 tpdfs = NULL;
David Sedlák04e17b22019-07-19 15:29:48 +02002319}
2320
David Sedlákd2d676a2019-07-22 11:28:19 +02002321static void
2322test_refine_elem(void **state)
2323{
David Sedlákd2d676a2019-07-22 11:28:19 +02002324 const char *data;
2325 struct lysp_refine *refines = NULL;
2326
2327 /* max subelems */
2328 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002329 "<refine target-node=\"target\">\n"
2330 " <if-feature name=\"feature\" />\n"
2331 " <must condition=\"cond\" />\n"
2332 " <presence value=\"presence\" />\n"
2333 " <default value=\"def\" />\n"
2334 " <config value=\"true\" />\n"
2335 " <mandatory value=\"true\" />\n"
2336 " <min-elements value=\"10\" />\n"
2337 " <max-elements value=\"20\" />\n"
2338 " <description><text>desc</text></description>\n"
2339 " <reference><text>ref</text></reference>\n"
2340 EXT_SUBELEM
2341 "</refine>"
2342 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002343 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002344 assert_string_equal(refines->nodeid, "target");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002345 assert_string_equal(refines->dflts[0].str, "def");
David Sedlákd2d676a2019-07-22 11:28:19 +02002346 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002347 assert_true(refines->flags & LYS_CONFIG_W);
2348 assert_true(refines->flags & LYS_MAND_TRUE);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002349 assert_string_equal(refines->iffeatures[0].str, "feature");
David Sedlákd2d676a2019-07-22 11:28:19 +02002350 assert_int_equal(refines->max, 20);
2351 assert_int_equal(refines->min, 10);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002352 assert_string_equal(refines->musts->arg.str, "cond");
David Sedlákd2d676a2019-07-22 11:28:19 +02002353 assert_string_equal(refines->presence, "presence");
2354 assert_string_equal(refines->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002355 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]), LY_STMT_REFINE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002356 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002357 refines = NULL;
2358
2359 /* min subelems */
2360 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002361 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002362 assert_string_equal(refines->nodeid, "target");
Radek Iša56ca9e42020-09-08 18:42:00 +02002363 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002364 refines = NULL;
David Sedlákd2d676a2019-07-22 11:28:19 +02002365}
2366
David Sedlák0d6de5a2019-07-22 13:25:44 +02002367static void
2368test_uses_elem(void **state)
2369{
David Sedlák0d6de5a2019-07-22 13:25:44 +02002370 const char *data;
2371 struct lysp_node *siblings = NULL;
2372 struct tree_node_meta node_meta = {NULL, &siblings};
2373 struct lysp_node_uses *parsed = NULL;
2374
2375 /* max subelems */
2376 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002377 "<uses name=\"uses-name\">\n"
2378 " <when condition=\"cond\" />\n"
2379 " <if-feature name=\"feature\" />\n"
2380 " <status value=\"obsolete\" />\n"
2381 " <description><text>desc</text></description>\n"
2382 " <reference><text>ref</text></reference>\n"
2383 " <refine target-node=\"target\"/>\n"
2384 " <augment target-node=\"target\" />\n"
2385 EXT_SUBELEM
2386 "</uses>"
2387 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002388 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002389 parsed = (struct lysp_node_uses *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002390 CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1,
2391 "uses-name", 0, LYS_USES, 0, "ref", 1);
2392 CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002393 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002394 assert_string_equal(parsed->refines->nodeid, "target");
David Sedlák992fb7c2019-07-24 16:51:01 +02002395 assert_string_equal(parsed->augments->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002396 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_USES);
Radek Iša56ca9e42020-09-08 18:42:00 +02002397 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002398 siblings = NULL;
2399
2400 /* min subelems */
2401 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002402 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002403 assert_string_equal(siblings[0].name, "uses-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002404 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002405 siblings = NULL;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002406}
2407
David Sedlákaa854b02019-07-22 14:17:10 +02002408static void
2409test_revision_elem(void **state)
2410{
David Sedlákaa854b02019-07-22 14:17:10 +02002411 const char *data;
2412 struct lysp_revision *revs = NULL;
2413
2414 /* max subelems */
2415 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002416 "<revision date=\"2018-12-25\">\n"
2417 " <description><text>desc</text></description>\n"
2418 " <reference><text>ref</text></reference>\n"
2419 EXT_SUBELEM
2420 "</revision>"
2421 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002422 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002423 assert_string_equal(revs->date, "2018-12-25");
2424 assert_string_equal(revs->dsc, "desc");
2425 assert_string_equal(revs->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002426 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]), LY_STMT_REVISION);
Radek Iša56ca9e42020-09-08 18:42:00 +02002427 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002428 revs = NULL;
2429
2430 /* min subelems */
2431 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002432 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002433 assert_string_equal(revs->date, "2005-05-05");
Radek Iša56ca9e42020-09-08 18:42:00 +02002434 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002435 revs = NULL;
2436
2437 /* invalid value */
2438 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002439 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID);
2440 CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1.");
2441 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002442 revs = NULL;
David Sedlákaa854b02019-07-22 14:17:10 +02002443}
2444
David Sedlák0c2bab92019-07-22 15:33:19 +02002445static void
2446test_include_elem(void **state)
2447{
David Sedlák0c2bab92019-07-22 15:33:19 +02002448 const char *data;
2449 struct lysp_include *includes = NULL;
2450 struct include_meta inc_meta = {"module-name", &includes};
2451
2452 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002453 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák0c2bab92019-07-22 15:33:19 +02002454 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002455 "<include module=\"mod\">\n"
2456 " <description><text>desc</text></description>\n"
2457 " <reference><text>ref</text></reference>\n"
2458 " <revision-date date=\"1999-09-09\"/>\n"
2459 EXT_SUBELEM
2460 "</include>"
2461 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002462 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002463 assert_string_equal(includes->name, "mod");
2464 assert_string_equal(includes->dsc, "desc");
2465 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002466 assert_string_equal(includes->rev, "1999-09-09");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002467 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]), LY_STMT_INCLUDE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002468 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002469 includes = NULL;
2470
2471 /* min subelems */
2472 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002473 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002474 assert_string_equal(includes->name, "mod");
Radek Iša56ca9e42020-09-08 18:42:00 +02002475 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002476 includes = NULL;
2477
2478 /* invalid combinations */
Radek Iša56ca9e42020-09-08 18:42:00 +02002479 YCTX->parsed_mod->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002480 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002481 "<include module=\"mod\">\n"
2482 " <description><text>desc</text></description>\n"
2483 " <revision-date date=\"1999-09-09\"/>\n"
2484 "</include>"
2485 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002486 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2487 CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2488 "Line number 2.");
2489 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002490 includes = NULL;
2491
Radek Iša56ca9e42020-09-08 18:42:00 +02002492 YCTX->parsed_mod->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002493 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002494 "<include module=\"mod\">\n"
2495 " <reference><text>ref</text></reference>\n"
2496 " <revision-date date=\"1999-09-09\"/>\n"
2497 "</include>"
2498 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002499 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2500 CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2501 "Line number 2.");
2502 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002503 includes = NULL;
David Sedlák0c2bab92019-07-22 15:33:19 +02002504}
2505
David Sedlák5e13dea2019-07-22 16:06:45 +02002506static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002507test_list_elem(void **state)
2508{
David Sedlákaf536aa2019-07-23 13:42:23 +02002509 const char *data;
2510 struct lysp_node *siblings = NULL;
2511 struct tree_node_meta node_meta = {NULL, &siblings};
2512 struct lysp_node_list *parsed = NULL;
2513
2514 /* max subelems */
2515 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002516 "<list name=\"list-name\">\n"
2517 " <when condition=\"when\"/>\n"
2518 " <if-feature name=\"iff\"/>\n"
2519 " <must condition=\"must-cond\"/>\n"
2520 " <key value=\"key\"/>\n"
2521 " <unique tag=\"utag\"/>\n"
2522 " <config value=\"true\"/>\n"
2523 " <min-elements value=\"10\"/>\n"
2524 " <ordered-by value=\"user\"/>\n"
2525 " <status value=\"deprecated\"/>\n"
2526 " <description><text>desc</text></description>\n"
2527 " <reference><text>ref</text></reference>\n"
2528 " <anydata name=\"anyd\"/>\n"
2529 " <anyxml name=\"anyx\"/>\n"
2530 " <container name=\"cont\"/>\n"
2531 " <choice name=\"choice\"/>\n"
2532 " <action name=\"action\"/>\n"
2533 " <grouping name=\"grp\"/>\n"
2534 " <notification name=\"notf\"/>\n"
2535 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2536 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2537 " <list name=\"sub-list\"/>\n"
2538 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2539 " <uses name=\"uses-name\"/>\n"
2540 EXT_SUBELEM
2541 "</list>"
2542 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002543 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002544 parsed = (struct lysp_node_list *)&siblings[0];
David Sedlákaf536aa2019-07-23 13:42:23 +02002545 assert_string_equal(parsed->child->name, "anyd");
2546 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2547 assert_string_equal(parsed->child->next->name, "anyx");
2548 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002549 assert_string_equal(parsed->child->next->next->name, "cont");
2550 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002551 assert_string_equal(parsed->child->next->next->next->name, "choice");
2552 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002553 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2554 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2555 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2556 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2557 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2558 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2559 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2560 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2561 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Iša56ca9e42020-09-08 18:42:00 +02002562 uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN;
2563
2564 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2565 "list-name", 0, LYS_LIST, 0, "ref", 1);
2566 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2567 CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002568 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002569 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002570 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002571 assert_string_equal(parsed->notifs->name, "notf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002572 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákaf536aa2019-07-23 13:42:23 +02002573 assert_string_equal(parsed->key, "key");
2574 assert_int_equal(parsed->min, 10);
David Sedlákaf536aa2019-07-23 13:42:23 +02002575 assert_string_equal(parsed->typedefs->name, "tpdf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002576 assert_string_equal(parsed->uniques->str, "utag");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002577 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002578 lysp_node_free(UTEST_LYCTX, siblings);
2579 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedlákaf536aa2019-07-23 13:42:23 +02002580 siblings = NULL;
2581
2582 /* min subelems */
2583 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002584 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002585 parsed = (struct lysp_node_list *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002586 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2587 "list-name", 0, LYS_LIST, 0, NULL, 0);
2588 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákaf536aa2019-07-23 13:42:23 +02002589 siblings = NULL;
David Sedlákaf536aa2019-07-23 13:42:23 +02002590}
2591
David Sedlák031b9e72019-07-23 15:19:37 +02002592static void
2593test_notification_elem(void **state)
2594{
David Sedlák031b9e72019-07-23 15:19:37 +02002595 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002596 struct lysp_node_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002597 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002598
2599 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002600 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák031b9e72019-07-23 15:19:37 +02002601 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002602 "<notification name=\"notif-name\">\n"
2603 " <anydata name=\"anyd\"/>\n"
2604 " <anyxml name=\"anyx\"/>\n"
2605 " <description><text>desc</text></description>\n"
2606 " <if-feature name=\"iff\"/>\n"
2607 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2608 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2609 " <list name=\"sub-list\"/>\n"
2610 " <must condition=\"cond\"/>\n"
2611 " <reference><text>ref</text></reference>\n"
2612 " <status value=\"deprecated\"/>\n"
2613 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2614 " <uses name=\"uses-name\"/>\n"
2615 " <container name=\"cont\"/>\n"
2616 " <choice name=\"choice\"/>\n"
2617 " <grouping name=\"grp\"/>\n"
2618 EXT_SUBELEM
2619 "</notification>"
2620 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002621 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002622 assert_string_equal(notifs->name, "notif-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002623 assert_string_equal(notifs->child->name, "anyd");
2624 assert_int_equal(notifs->child->nodetype, LYS_ANYDATA);
2625 assert_string_equal(notifs->child->next->name, "anyx");
2626 assert_int_equal(notifs->child->next->nodetype, LYS_ANYXML);
2627 assert_string_equal(notifs->child->next->next->name, "leaf");
2628 assert_int_equal(notifs->child->next->next->nodetype, LYS_LEAF);
2629 assert_string_equal(notifs->child->next->next->next->name, "llist");
2630 assert_int_equal(notifs->child->next->next->next->nodetype, LYS_LEAFLIST);
2631 assert_string_equal(notifs->child->next->next->next->next->name, "sub-list");
2632 assert_int_equal(notifs->child->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02002633 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002634 assert_string_equal(notifs->groupings->name, "grp");
2635 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
Radek Krejci01180ac2021-01-27 08:48:22 +01002636 assert_string_equal(notifs->child->next->next->next->next->next->name, "uses-name");
2637 assert_int_equal(notifs->child->next->next->next->next->next->nodetype, LYS_USES);
2638 assert_string_equal(notifs->child->next->next->next->next->next->next->name, "cont");
2639 assert_int_equal(notifs->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2640 assert_int_equal(notifs->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2641 assert_string_equal(notifs->child->next->next->next->next->next->next->next->name, "choice");
2642 assert_null(notifs->child->next->next->next->next->next->next->next->next);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002643 assert_string_equal(notifs->iffeatures[0].str, "iff");
2644 assert_string_equal(notifs->musts->arg.str, "cond");
David Sedlák031b9e72019-07-23 15:19:37 +02002645 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2646 assert_null(notifs->parent);
2647 assert_string_equal(notifs->ref, "ref");
2648 assert_string_equal(notifs->typedefs->name, "tpdf");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002649 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LY_STMT_NOTIFICATION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002650 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedlák031b9e72019-07-23 15:19:37 +02002651 notifs = NULL;
2652
2653 /* min subelems */
2654 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002655 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002656 assert_string_equal(notifs->name, "notif-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002657 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002658 notifs = NULL;
David Sedláke3ce9ef2019-07-23 16:34:30 +02002659}
2660
2661static void
2662test_grouping_elem(void **state)
2663{
David Sedláke3ce9ef2019-07-23 16:34:30 +02002664 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002665 struct lysp_node_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002666 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02002667
2668 /* max subelems */
2669 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002670 "<grouping name=\"grp-name\">\n"
2671 " <anydata name=\"anyd\"/>\n"
2672 " <anyxml name=\"anyx\"/>\n"
2673 " <description><text>desc</text></description>\n"
2674 " <grouping name=\"sub-grp\"/>\n"
2675 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2676 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2677 " <list name=\"list\"/>\n"
2678 " <notification name=\"notf\"/>\n"
2679 " <reference><text>ref</text></reference>\n"
2680 " <status value=\"current\"/>\n"
2681 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2682 " <uses name=\"uses-name\"/>\n"
2683 " <action name=\"act\"/>\n"
2684 " <container name=\"cont\"/>\n"
2685 " <choice name=\"choice\"/>\n"
2686 EXT_SUBELEM
2687 "</grouping>"
2688 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002689 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002690 assert_string_equal(grps->name, "grp-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002691 assert_string_equal(grps->child->name, "anyd");
2692 assert_string_equal(grps->child->next->name, "anyx");
2693 assert_string_equal(grps->child->next->next->name, "leaf");
2694 assert_string_equal(grps->child->next->next->next->name, "llist");
2695 assert_string_equal(grps->child->next->next->next->next->name, "list");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002696 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002697 assert_true(grps->flags & LYS_STATUS_CURR);
2698 assert_string_equal(grps->groupings->name, "sub-grp");
2699 assert_int_equal(grps->nodetype, LYS_GROUPING);
2700 assert_string_equal(grps->notifs->name, "notf");
2701 assert_null(grps->parent);
2702 assert_string_equal(grps->ref, "ref");
2703 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002704 assert_string_equal(grps->actions->name, "act");
Radek Krejci01180ac2021-01-27 08:48:22 +01002705 assert_string_equal(grps->child->next->next->next->next->next->name, "uses-name");
2706 assert_int_equal(grps->child->next->next->next->next->next->nodetype, LYS_USES);
2707 assert_string_equal(grps->child->next->next->next->next->next->next->name, "cont");
2708 assert_int_equal(grps->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2709 assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice");
2710 assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002711 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LY_STMT_GROUPING);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002712 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002713 grps = NULL;
2714
2715 /* min subelems */
2716 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002717 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002718 assert_string_equal(grps->name, "grp-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002719 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002720 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002721}
2722
David Sedlákf111bcb2019-07-23 17:15:51 +02002723static void
2724test_container_elem(void **state)
2725{
David Sedlákf111bcb2019-07-23 17:15:51 +02002726 const char *data;
2727 struct lysp_node *siblings = NULL;
2728 struct tree_node_meta node_meta = {NULL, &siblings};
2729 struct lysp_node_container *parsed = NULL;
2730
2731 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002732 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedláke2dc9e92019-07-24 09:59:21 +02002733 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002734 "<container name=\"cont-name\">\n"
2735 " <anydata name=\"anyd\"/>\n"
2736 " <anyxml name=\"anyx\"/>\n"
2737 " <config value=\"true\"/>\n"
2738 " <container name=\"subcont\"/>\n"
2739 " <description><text>desc</text></description>\n"
2740 " <grouping name=\"sub-grp\"/>\n"
2741 " <if-feature name=\"iff\"/>\n"
2742 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2743 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2744 " <list name=\"list\"/>\n"
2745 " <must condition=\"cond\"/>\n"
2746 " <notification name=\"notf\"/>\n"
2747 " <presence value=\"presence\"/>\n"
2748 " <reference><text>ref</text></reference>\n"
2749 " <status value=\"current\"/>\n"
2750 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2751 " <uses name=\"uses-name\"/>\n"
2752 " <when condition=\"when-cond\"/>\n"
2753 " <action name=\"act\"/>\n"
2754 " <choice name=\"choice\"/>\n"
2755 EXT_SUBELEM
2756 "</container>"
2757 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002758 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02002759 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002760 uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR;
2761
2762 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2763 "cont-name", 0, LYS_CONTAINER, 0, "ref", 1);
2764 CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL);
2765 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
2766
Michal Vasko7f45cf22020-10-01 12:49:44 +02002767 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02002768 assert_string_equal(parsed->presence, "presence");
2769 assert_string_equal(parsed->typedefs->name, "tpdf");
2770 assert_string_equal(parsed->groupings->name, "sub-grp");
2771 assert_string_equal(parsed->child->name, "anyd");
2772 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2773 assert_string_equal(parsed->child->next->name, "anyx");
2774 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2775 assert_string_equal(parsed->child->next->next->name, "subcont");
2776 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2777 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2778 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2779 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2780 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2781 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2782 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2783 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2784 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002785 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2786 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2787 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02002788 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002789 assert_string_equal(parsed->actions->name, "act");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002790 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CONTAINER);
Radek Iša56ca9e42020-09-08 18:42:00 +02002791 lysp_node_free(UTEST_LYCTX, siblings);
2792 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedláke2dc9e92019-07-24 09:59:21 +02002793 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002794
2795 /* min subelems */
2796 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002797 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02002798 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002799 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2800 "cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
2801 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákf111bcb2019-07-23 17:15:51 +02002802 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002803}
2804
David Sedlák5379d392019-07-24 10:42:03 +02002805static void
2806test_case_elem(void **state)
2807{
David Sedlák5379d392019-07-24 10:42:03 +02002808 const char *data;
2809 struct lysp_node *siblings = NULL;
2810 struct tree_node_meta node_meta = {NULL, &siblings};
2811 struct lysp_node_case *parsed = NULL;
2812
2813 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002814 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák5379d392019-07-24 10:42:03 +02002815 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002816 "<case name=\"case-name\">\n"
2817 " <anydata name=\"anyd\"/>\n"
2818 " <anyxml name=\"anyx\"/>\n"
2819 " <container name=\"subcont\"/>\n"
2820 " <description><text>desc</text></description>\n"
2821 " <if-feature name=\"iff\"/>\n"
2822 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2823 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2824 " <list name=\"list\"/>\n"
2825 " <reference><text>ref</text></reference>\n"
2826 " <status value=\"current\"/>\n"
2827 " <uses name=\"uses-name\"/>\n"
2828 " <when condition=\"when-cond\"/>\n"
2829 " <choice name=\"choice\"/>\n"
2830 EXT_SUBELEM
2831 "</case>"
2832 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002833 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002834 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002835 uint16_t flags = LYS_STATUS_CURR;
2836
2837 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2838 "case-name", 0, LYS_CASE, 0, "ref", 1);
2839 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002840 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02002841 assert_string_equal(parsed->child->name, "anyd");
2842 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2843 assert_string_equal(parsed->child->next->name, "anyx");
2844 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2845 assert_string_equal(parsed->child->next->next->name, "subcont");
2846 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2847 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2848 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2849 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2850 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2851 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2852 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2853 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2854 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002855 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2856 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2857 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002858 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002859 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002860 siblings = NULL;
2861
2862 /* min subelems */
2863 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002864 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002865 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002866 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2867 "case-name", 0, LYS_CASE, 0, NULL, 0);
2868 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002869 siblings = NULL;
David Sedlák5379d392019-07-24 10:42:03 +02002870}
2871
David Sedlákb7abcfa2019-07-24 12:33:35 +02002872static void
2873test_choice_elem(void **state)
2874{
David Sedlákb7abcfa2019-07-24 12:33:35 +02002875 const char *data;
2876 struct lysp_node *siblings = NULL;
2877 struct tree_node_meta node_meta = {NULL, &siblings};
2878 struct lysp_node_choice *parsed = NULL;
2879
2880 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002881 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002882 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002883 "<choice name=\"choice-name\">\n"
2884 " <anydata name=\"anyd\"/>\n"
2885 " <anyxml name=\"anyx\"/>\n"
2886 " <case name=\"sub-case\"/>\n"
2887 " <choice name=\"choice\"/>\n"
2888 " <config value=\"true\"/>\n"
2889 " <container name=\"subcont\"/>\n"
2890 " <default value=\"def\"/>\n"
2891 " <description><text>desc</text></description>\n"
2892 " <if-feature name=\"iff\"/>\n"
2893 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2894 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2895 " <list name=\"list\"/>\n"
2896 " <mandatory value=\"true\" />\n"
2897 " <reference><text>ref</text></reference>\n"
2898 " <status value=\"current\"/>\n"
2899 " <when condition=\"when-cond\"/>\n"
2900 EXT_SUBELEM
2901 "</choice>"
2902 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002903 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002904 parsed = (struct lysp_node_choice *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002905 uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR;
2906
2907 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2908 "choice-name", 0, LYS_CHOICE, 0, "ref", 1);
2909 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002910 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002911 assert_string_equal(parsed->child->name, "anyd");
2912 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2913 assert_string_equal(parsed->child->next->name, "anyx");
2914 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2915 assert_string_equal(parsed->child->next->next->name, "sub-case");
2916 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
2917 assert_string_equal(parsed->child->next->next->next->name, "choice");
2918 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2919 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
2920 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
2921 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
2922 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
2923 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
2924 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2925 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
2926 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
2927 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002928 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CHOICE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002929 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002930 siblings = NULL;
2931
2932 /* min subelems */
2933 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002934 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002935 parsed = (struct lysp_node_choice *)siblings;
2936 assert_string_equal(parsed->name, "choice-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002937 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2938 "choice-name", 0, LYS_CHOICE, 0, NULL, 0);
2939 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002940 siblings = NULL;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002941}
2942
David Sedlák05404f62019-07-24 14:11:53 +02002943static void
2944test_inout_elem(void **state)
2945{
David Sedlák05404f62019-07-24 14:11:53 +02002946 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002947 struct lysp_node_action_inout inout = {};
David Sedlák05404f62019-07-24 14:11:53 +02002948 struct inout_meta inout_meta = {NULL, &inout};
2949
2950 /* max subelements */
Radek Iša56ca9e42020-09-08 18:42:00 +02002951 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002952 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002953 "<input>\n"
2954 " <anydata name=\"anyd\"/>\n"
2955 " <anyxml name=\"anyx\"/>\n"
2956 " <choice name=\"choice\"/>\n"
2957 " <container name=\"subcont\"/>\n"
2958 " <grouping name=\"sub-grp\"/>\n"
2959 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2960 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2961 " <list name=\"list\"/>\n"
2962 " <must condition=\"cond\"/>\n"
2963 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2964 " <uses name=\"uses-name\"/>\n"
2965 EXT_SUBELEM
2966 "</input>"
2967 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002968 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
2969 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1);
2970 CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL);
David Sedlák05404f62019-07-24 14:11:53 +02002971 assert_string_equal(inout.typedefs->name, "tpdf");
2972 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01002973 assert_string_equal(inout.child->name, "anyd");
2974 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
2975 assert_string_equal(inout.child->next->name, "anyx");
2976 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
2977 assert_string_equal(inout.child->next->next->name, "choice");
2978 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
2979 assert_string_equal(inout.child->next->next->next->name, "subcont");
2980 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
2981 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
2982 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
2983 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
2984 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2985 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
2986 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
2987 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
2988 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2989 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002990 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_INPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002991 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02002992 memset(&inout, 0, sizeof inout);
2993
2994 /* max subelements */
Radek Iša56ca9e42020-09-08 18:42:00 +02002995 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002996 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002997 "<output>\n"
2998 " <anydata name=\"anyd\"/>\n"
2999 " <anyxml name=\"anyx\"/>\n"
3000 " <choice name=\"choice\"/>\n"
3001 " <container name=\"subcont\"/>\n"
3002 " <grouping name=\"sub-grp\"/>\n"
3003 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3004 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3005 " <list name=\"list\"/>\n"
3006 " <must condition=\"cond\"/>\n"
3007 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3008 " <uses name=\"uses-name\"/>\n"
3009 EXT_SUBELEM
3010 "</output>"
3011 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003012 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
3013 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1);
Michal Vasko7f45cf22020-10-01 12:49:44 +02003014 assert_string_equal(inout.musts->arg.str, "cond");
David Sedlák05404f62019-07-24 14:11:53 +02003015 assert_string_equal(inout.typedefs->name, "tpdf");
3016 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01003017 assert_string_equal(inout.child->name, "anyd");
3018 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
3019 assert_string_equal(inout.child->next->name, "anyx");
3020 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
3021 assert_string_equal(inout.child->next->next->name, "choice");
3022 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
3023 assert_string_equal(inout.child->next->next->next->name, "subcont");
3024 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
3025 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
3026 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
3027 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
3028 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3029 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
3030 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
3031 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
3032 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3033 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003034 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_OUTPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003035 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003036 memset(&inout, 0, sizeof inout);
3037
3038 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003039 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003040 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003041 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003042 memset(&inout, 0, sizeof inout);
3043
Michal Vaskob83af8a2020-01-06 09:49:22 +01003044 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" 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
3049 /* invalid combinations */
3050 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003051 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
Radek Krejci9a3823e2021-01-27 20:26:46 +01003052 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
Radek Iša56ca9e42020-09-08 18:42:00 +02003053 CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003054 memset(&inout, 0, sizeof inout);
David Sedlák05404f62019-07-24 14:11:53 +02003055}
3056
David Sedlák85d0eca2019-07-24 15:15:21 +02003057static void
3058test_action_elem(void **state)
3059{
David Sedlák85d0eca2019-07-24 15:15:21 +02003060 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003061 struct lysp_node_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003062 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
Radek Iša56ca9e42020-09-08 18:42:00 +02003063 uint16_t flags;
David Sedlák85d0eca2019-07-24 15:15:21 +02003064
3065 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003066 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák85d0eca2019-07-24 15:15:21 +02003067 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003068 "<action name=\"act\">\n"
3069 " <description><text>desc</text></description>\n"
3070 " <grouping name=\"grouping\"/>\n"
3071 " <if-feature name=\"iff\"/>\n"
3072 " <input><uses name=\"uses-name\"/></input>\n"
3073 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3074 " <reference><text>ref</text></reference>\n"
3075 " <status value=\"deprecated\"/>\n"
3076 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3077 EXT_SUBELEM
3078 "</action>"
3079 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003080 /* there must be parent for action */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003081 act_meta.parent = (void *)1;
Radek Iša56ca9e42020-09-08 18:42:00 +02003082 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003083 act_meta.parent = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003084 flags = LYS_STATUS_DEPRC;
3085 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3086 1, 0, 0, 0,\
3087 1, 0,\
3088 "act", LYS_ACTION, \
3089 1, 0, 0, 1,\
3090 1, 0,\
3091 1, "ref", 1);
3092
Michal Vasko7f45cf22020-10-01 12:49:44 +02003093 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlák85d0eca2019-07-24 15:15:21 +02003094 assert_string_equal(actions->typedefs->name, "tpdf");
3095 assert_string_equal(actions->groupings->name, "grouping");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003096 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci01180ac2021-01-27 08:48:22 +01003097 assert_string_equal(actions->input.child->name, "uses-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003098 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_ACTION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003099 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003100 actions = NULL;
3101
Radek Iša56ca9e42020-09-08 18:42:00 +02003102 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlákeaa45792019-07-24 15:25:01 +02003103 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003104 "<rpc name=\"act\">\n"
3105 " <description><text>desc</text></description>\n"
3106 " <grouping name=\"grouping\"/>\n"
3107 " <if-feature name=\"iff\"/>\n"
3108 " <input><uses name=\"uses-name\"/></input>\n"
3109 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3110 " <reference><text>ref</text></reference>\n"
3111 " <status value=\"deprecated\"/>\n"
3112 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3113 EXT_SUBELEM
3114 "</rpc>"
3115 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003116 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
3117 flags = LYS_STATUS_DEPRC;
3118 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3119 1, 0, 0, 0,\
3120 1, 0,\
3121 "act", LYS_RPC, \
3122 1, 0, 0, 1,\
3123 1, 0,\
3124 0, "ref", 1);
3125
Michal Vasko7f45cf22020-10-01 12:49:44 +02003126 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlákeaa45792019-07-24 15:25:01 +02003127 assert_string_equal(actions->typedefs->name, "tpdf");
3128 assert_string_equal(actions->groupings->name, "grouping");
Radek Krejci01180ac2021-01-27 08:48:22 +01003129 assert_string_equal(actions->input.child->name, "uses-name");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003130 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003131 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_RPC);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003132 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlákeaa45792019-07-24 15:25:01 +02003133 actions = NULL;
3134
David Sedlák85d0eca2019-07-24 15:15:21 +02003135 /* min subelems */
3136 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003137 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003138 assert_string_equal(actions->name, "act");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003139 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003140 actions = NULL;
David Sedlák85d0eca2019-07-24 15:15:21 +02003141}
3142
David Sedlák992fb7c2019-07-24 16:51:01 +02003143static void
3144test_augment_elem(void **state)
3145{
David Sedlák992fb7c2019-07-24 16:51:01 +02003146 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003147 struct lysp_node_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003148 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003149
Radek Iša56ca9e42020-09-08 18:42:00 +02003150 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák992fb7c2019-07-24 16:51:01 +02003151 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003152 "<augment target-node=\"target\">\n"
3153 " <action name=\"action\"/>\n"
3154 " <anydata name=\"anyd\"/>\n"
3155 " <anyxml name=\"anyx\"/>\n"
3156 " <case name=\"case\"/>\n"
3157 " <choice name=\"choice\"/>\n"
3158 " <container name=\"subcont\"/>\n"
3159 " <description><text>desc</text></description>\n"
3160 " <if-feature name=\"iff\"/>\n"
3161 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3162 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3163 " <list name=\"list\"/>\n"
3164 " <notification name=\"notif\"/>\n"
3165 " <reference><text>ref</text></reference>\n"
3166 " <status value=\"current\"/>\n"
3167 " <uses name=\"uses\"/>\n"
3168 " <when condition=\"when-cond\"/>\n"
3169 EXT_SUBELEM
3170 "</augment>"
3171 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003172 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003173 assert_string_equal(augments->nodeid, "target");
3174 assert_null(augments->parent);
3175 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3176 assert_true(augments->flags & LYS_STATUS_CURR);
3177 assert_string_equal(augments->dsc, "desc");
3178 assert_string_equal(augments->ref, "ref");
3179 assert_string_equal(augments->when->cond, "when-cond");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003180 assert_string_equal(augments->iffeatures[0].str, "iff");
David Sedlák992fb7c2019-07-24 16:51:01 +02003181 assert_string_equal(augments->child->name, "anyd");
3182 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3183 assert_string_equal(augments->child->next->name, "anyx");
3184 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3185 assert_string_equal(augments->child->next->next->name, "case");
3186 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3187 assert_string_equal(augments->child->next->next->next->name, "choice");
3188 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3189 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3190 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3191 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3192 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3193 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3194 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3195 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3196 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3197 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3198 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3199 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3200 assert_string_equal(augments->actions->name, "action");
3201 assert_string_equal(augments->notifs->name, "notif");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003202 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003203 lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003204 augments = NULL;
3205
3206 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003207 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003208 assert_string_equal(augments->nodeid, "target");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003209 lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003210 augments = NULL;
David Sedlák992fb7c2019-07-24 16:51:01 +02003211}
3212
David Sedlák4ffcec82019-07-25 15:10:21 +02003213static void
3214test_deviate_elem(void **state)
3215{
David Sedlák4ffcec82019-07-25 15:10:21 +02003216 const char *data;
3217 struct lysp_deviate *deviates = NULL;
3218 struct lysp_deviate_add *d_add;
3219 struct lysp_deviate_rpl *d_rpl;
3220 struct lysp_deviate_del *d_del;
3221
3222 /* all valid arguments with min subelems */
3223 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003224 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003225 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003226 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003227 free(deviates);
3228 deviates = NULL;
3229
3230 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003231 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003232 assert_int_equal(deviates->mod, LYS_DEV_ADD);
Radek Iša56ca9e42020-09-08 18:42:00 +02003233 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003234 free(deviates);
3235 deviates = NULL;
3236
3237 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003238 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003239 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003240 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003241 free(deviates);
3242 deviates = NULL;
3243
3244 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003245 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003246 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003247 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003248 free(deviates);
3249 deviates = NULL;
3250
3251 /* max subelems and valid arguments */
3252 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003253 "<deviate value=\"not-supported\">"
3254 EXT_SUBELEM
3255 "</deviate>"
3256 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003257 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003258 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003259 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003260 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003261 free(deviates);
3262 deviates = NULL;
3263
3264 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003265 "<deviate value=\"add\">\n"
3266 " <units name=\"units\"/>\n"
3267 " <must condition=\"cond\"/>\n"
3268 " <unique tag=\"utag\"/>\n"
3269 " <default value=\"def\"/>\n"
3270 " <config value=\"true\"/>\n"
3271 " <mandatory value=\"true\"/>\n"
3272 " <min-elements value=\"5\"/>\n"
3273 " <max-elements value=\"15\"/>\n"
3274 EXT_SUBELEM
3275 "</deviate>"
3276 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003277 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003278 d_add = (struct lysp_deviate_add *)deviates;
3279 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3280 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003281 assert_string_equal(d_add->units, "units");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003282 assert_string_equal(d_add->musts->arg.str, "cond");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003283 assert_string_equal(d_add->uniques[0].str, "utag");
3284 assert_string_equal(d_add->dflts[0].str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003285 assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003286 assert_int_equal(d_add->min, 5);
3287 assert_int_equal(d_add->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003288 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003289 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003290 free(deviates);
3291 deviates = NULL;
3292
3293 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003294 "<deviate value=\"replace\">\n"
3295 " <type name=\"newtype\"/>\n"
3296 " <units name=\"uni\"/>\n"
3297 " <default value=\"def\"/>\n"
3298 " <config value=\"true\"/>\n"
3299 " <mandatory value=\"true\"/>\n"
3300 " <min-elements value=\"5\"/>\n"
3301 " <max-elements value=\"15\"/>\n"
3302 EXT_SUBELEM
3303 "</deviate>"
3304 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003305 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003306 d_rpl = (struct lysp_deviate_rpl *)deviates;
3307 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3308 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003309 assert_string_equal(d_rpl->type->name, "newtype");
3310 assert_string_equal(d_rpl->units, "uni");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003311 assert_string_equal(d_rpl->dflt.str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003312 assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003313 assert_int_equal(d_rpl->min, 5);
3314 assert_int_equal(d_rpl->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003315 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003316 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003317 free(deviates);
3318 deviates = NULL;
3319
3320 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003321 "<deviate value=\"delete\">\n"
3322 " <units name=\"u\"/>\n"
3323 " <must condition=\"c\"/>\n"
3324 " <unique tag=\"tag\"/>\n"
3325 " <default value=\"default\"/>\n"
3326 EXT_SUBELEM
3327 "</deviate>"
3328 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003329 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003330 d_del = (struct lysp_deviate_del *)deviates;
3331 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3332 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003333 assert_string_equal(d_del->units, "u");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003334 assert_string_equal(d_del->musts->arg.str, "c");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003335 assert_string_equal(d_del->uniques[0].str, "tag");
3336 assert_string_equal(d_del->dflts[0].str, "default");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003337 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003338 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003339 free(deviates);
3340 deviates = NULL;
3341
3342 /* invalid arguments */
3343 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003344 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3345 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. "
3346 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003347 deviates = NULL;
3348
3349 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003350 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3351 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. "
3352 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003353 deviates = NULL;
3354
3355 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003356 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3357 CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. "
3358 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003359 deviates = NULL;
3360
3361 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003362 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3363 CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. "
3364 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003365 deviates = NULL;
3366
3367 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003368 "<deviate value=\"not-supported\">\n"
3369 " <must condition=\"c\"/>\n"
3370 "</deviate>"
3371 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003372 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3373 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 +02003374}
3375
David Sedlák8b754462019-07-25 16:22:13 +02003376static void
3377test_deviation_elem(void **state)
3378{
David Sedlák8b754462019-07-25 16:22:13 +02003379 const char *data;
3380 struct lysp_deviation *deviations = NULL;
3381
3382 /* min subelems */
3383 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003384 "<deviation target-node=\"target\">\n"
3385 " <deviate value=\"not-supported\"/>\n"
3386 "</deviation>"
3387 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003388 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003389 assert_string_equal(deviations->nodeid, "target");
3390 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003391 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003392 deviations = NULL;
3393
3394 /* max subelems */
3395 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003396 "<deviation target-node=\"target\">\n"
3397 " <reference><text>ref</text></reference>\n"
3398 " <description><text>desc</text></description>\n"
3399 " <deviate value=\"add\"/>\n"
3400 EXT_SUBELEM
3401 "</deviation>"
3402 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003403 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003404 assert_string_equal(deviations->nodeid, "target");
3405 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3406 assert_string_equal(deviations->ref, "ref");
3407 assert_string_equal(deviations->dsc, "desc");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003408 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]), LY_STMT_DEVIATION);
Radek Iša56ca9e42020-09-08 18:42:00 +02003409 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003410 deviations = NULL;
3411
3412 /* invalid */
3413 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003414 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID);
3415 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003416 deviations = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003417 CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1.");
3418 /* TODO */}
David Sedlák8b754462019-07-25 16:22:13 +02003419
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003420static struct lysp_module *
3421mod_renew(struct lys_yin_parser_ctx *ctx)
3422{
3423 struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
3424
3425 lys_module_free(ctx->parsed_mod->mod, NULL);
3426 ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod);
3427 ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
3428 ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
3429 ctx->parsed_mod->mod->ctx = ly_ctx;
3430
3431 return ctx->parsed_mod;
3432}
3433
David Sedlák4f03b932019-07-26 13:01:47 +02003434static void
3435test_module_elem(void **state)
3436{
Michal Vaskob36053d2020-03-26 15:49:30 +01003437 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003438 struct lysp_module *lysp_mod = mod_renew(YCTX);
David Sedlák4f03b932019-07-26 13:01:47 +02003439
3440 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003441 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003442 " <yang-version value=\"1.1\"/>\n"
3443 " <namespace uri=\"ns\"/>\n"
3444 " <prefix value=\"pref\"/>\n"
3445 " <include module=\"b-mod\"/>\n"
3446 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3447 " <organization><text>org</text></organization>\n"
3448 " <contact><text>contact</text></contact>\n"
3449 " <description><text>desc</text></description>\n"
3450 " <reference><text>ref</text></reference>\n"
3451 " <revision date=\"2019-02-02\"/>\n"
3452 " <anydata name=\"anyd\"/>\n"
3453 " <anyxml name=\"anyx\"/>\n"
3454 " <choice name=\"choice\"/>\n"
3455 " <container name=\"cont\"/>\n"
3456 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3457 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3458 " <list name=\"sub-list\"/>\n"
3459 " <uses name=\"uses-name\"/>\n"
3460 " <augment target-node=\"target\"/>\n"
3461 " <deviation target-node=\"target\">\n"
3462 " <deviate value=\"not-supported\"/>\n"
3463 " </deviation>\n"
3464 " <extension name=\"ext\"/>\n"
3465 " <feature name=\"feature\"/>\n"
3466 " <grouping name=\"grp\"/>\n"
3467 " <identity name=\"ident-name\"/>\n"
3468 " <notification name=\"notf\"/>\n"
3469 " <rpc name=\"rpc-name\"/>\n"
3470 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3471 EXT_SUBELEM "\n"
3472 "</module>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003473 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3474 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003475
Radek Iša56ca9e42020-09-08 18:42:00 +02003476 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003477 assert_string_equal(lysp_mod->mod->name, "mod");
3478 assert_string_equal(lysp_mod->revs, "2019-02-02");
3479 assert_string_equal(lysp_mod->mod->ns, "ns");
3480 assert_string_equal(lysp_mod->mod->prefix, "pref");
3481 assert_null(lysp_mod->mod->filepath);
3482 assert_string_equal(lysp_mod->mod->org, "org");
3483 assert_string_equal(lysp_mod->mod->contact, "contact");
3484 assert_string_equal(lysp_mod->mod->dsc, "desc");
3485 assert_string_equal(lysp_mod->mod->ref, "ref");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003486 assert_int_equal(lysp_mod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003487 CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod",
3488 "imp-pref", NULL, "");
David Sedlák4f03b932019-07-26 13:01:47 +02003489 assert_string_equal(lysp_mod->includes->name, "b-mod");
3490 assert_string_equal(lysp_mod->extensions->name, "ext");
3491 assert_string_equal(lysp_mod->features->name, "feature");
3492 assert_string_equal(lysp_mod->identities->name, "ident-name");
3493 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3494 assert_string_equal(lysp_mod->groupings->name, "grp");
3495 assert_string_equal(lysp_mod->data->name, "anyd");
3496 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3497 assert_string_equal(lysp_mod->data->next->name, "anyx");
3498 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3499 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3500 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3501 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3502 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3503 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3504 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3505 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3506 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3507 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3508 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3509 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3510 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3511 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3512 assert_string_equal(lysp_mod->augments->nodeid, "target");
3513 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3514 assert_string_equal(lysp_mod->notifs->name, "notf");
3515 assert_string_equal(lysp_mod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003516 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LY_STMT_MODULE);
David Sedlák4f03b932019-07-26 13:01:47 +02003517
3518 /* min subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003519 ly_in_free(UTEST_IN, 0);
3520 lyxml_ctx_free(YCTX->xmlctx);
3521 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003522 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3523 " <namespace uri=\"ns\"/>\n"
3524 " <prefix value=\"pref\"/>\n"
3525 " <yang-version value=\"1.1\"/>\n"
3526 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003527 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3528 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3529 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003530 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák298ff6d2019-07-26 14:29:03 +02003531
David Sedláke6cd89e2019-08-07 12:46:02 +02003532 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003533 ly_in_free(UTEST_IN, 0);
3534 lyxml_ctx_free(YCTX->xmlctx);
3535 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003536 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3537 " <feature name=\"feature\"/>\n"
3538 " <namespace uri=\"ns\"/>\n"
3539 " <prefix value=\"pref\"/>\n"
3540 " <yang-version value=\"1.1\"/>\n"
3541 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003542 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3543 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3544 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID);
3545 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 +02003546}
3547
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003548static struct lysp_submodule *
3549submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to)
3550{
3551 struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
3552
3553 lys_module_free(ctx->parsed_mod->mod, NULL);
3554 ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule));
3555 ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
3556 lydict_insert(ly_ctx, belongs_to, 0, &ctx->parsed_mod->mod->name);
3557 ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
3558 ctx->parsed_mod->mod->ctx = ly_ctx;
3559
3560 return (struct lysp_submodule *)ctx->parsed_mod;
3561}
3562
David Sedlák298ff6d2019-07-26 14:29:03 +02003563static void
3564test_submodule_elem(void **state)
3565{
Michal Vaskob36053d2020-03-26 15:49:30 +01003566 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003567 struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name");
David Sedlák298ff6d2019-07-26 14:29:03 +02003568
3569 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02003570 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003571 " <yang-version value=\"1.1\"/>\n"
3572 " <belongs-to module=\"module-name\">\n"
3573 " <prefix value=\"pref\"/>\n"
3574 " </belongs-to>\n"
3575 " <include module=\"b-mod\"/>\n"
3576 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3577 " <organization><text>org</text></organization>\n"
3578 " <contact><text>contact</text></contact>\n"
3579 " <description><text>desc</text></description>\n"
3580 " <reference><text>ref</text></reference>\n"
3581 " <revision date=\"2019-02-02\"/>\n"
3582 " <anydata name=\"anyd\"/>\n"
3583 " <anyxml name=\"anyx\"/>\n"
3584 " <choice name=\"choice\"/>\n"
3585 " <container name=\"cont\"/>\n"
3586 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3587 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3588 " <list name=\"sub-list\"/>\n"
3589 " <uses name=\"uses-name\"/>\n"
3590 " <augment target-node=\"target\"/>\n"
3591 " <deviation target-node=\"target\">\n"
3592 " <deviate value=\"not-supported\"/>\n"
3593 " </deviation>\n"
3594 " <extension name=\"ext\"/>\n"
3595 " <feature name=\"feature\"/>\n"
3596 " <grouping name=\"grp\"/>\n"
3597 " <identity name=\"ident-name\"/>\n"
3598 " <notification name=\"notf\"/>\n"
3599 " <rpc name=\"rpc-name\"/>\n"
3600 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3601 EXT_SUBELEM "\n"
3602 "</submodule>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003603 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3604 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003605
Radek Iša56ca9e42020-09-08 18:42:00 +02003606 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003607 assert_string_equal(lysp_submod->name, "mod");
3608 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02003609 assert_string_equal(lysp_submod->prefix, "pref");
3610 assert_null(lysp_submod->filepath);
3611 assert_string_equal(lysp_submod->org, "org");
3612 assert_string_equal(lysp_submod->contact, "contact");
3613 assert_string_equal(lysp_submod->dsc, "desc");
3614 assert_string_equal(lysp_submod->ref, "ref");
3615 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003616 CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod",
3617 "imp-pref", NULL, "");
David Sedlák298ff6d2019-07-26 14:29:03 +02003618 assert_string_equal(lysp_submod->includes->name, "b-mod");
3619 assert_string_equal(lysp_submod->extensions->name, "ext");
3620 assert_string_equal(lysp_submod->features->name, "feature");
3621 assert_string_equal(lysp_submod->identities->name, "ident-name");
3622 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
3623 assert_string_equal(lysp_submod->groupings->name, "grp");
3624 assert_string_equal(lysp_submod->data->name, "anyd");
3625 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
3626 assert_string_equal(lysp_submod->data->next->name, "anyx");
3627 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
3628 assert_string_equal(lysp_submod->data->next->next->name, "choice");
3629 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
3630 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
3631 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
3632 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
3633 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
3634 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
3635 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3636 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
3637 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3638 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
3639 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3640 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
3641 assert_string_equal(lysp_submod->augments->nodeid, "target");
3642 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
3643 assert_string_equal(lysp_submod->notifs->name, "notf");
3644 assert_string_equal(lysp_submod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003645 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LY_STMT_SUBMODULE);
David Sedlák298ff6d2019-07-26 14:29:03 +02003646
David Sedlák298ff6d2019-07-26 14:29:03 +02003647 /* min subelemnts */
Radek Iša56ca9e42020-09-08 18:42:00 +02003648 ly_in_free(UTEST_IN, 0);
3649 lyxml_ctx_free(YCTX->xmlctx);
3650 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003651 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3652 " <yang-version value=\"1\"/>\n"
3653 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3654 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003655 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3656 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3657 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003658 assert_string_equal(lysp_submod->prefix, "pref");
David Sedlák298ff6d2019-07-26 14:29:03 +02003659 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
David Sedlák298ff6d2019-07-26 14:29:03 +02003660
David Sedláke6cd89e2019-08-07 12:46:02 +02003661 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003662 ly_in_free(UTEST_IN, 0);
3663 lyxml_ctx_free(YCTX->xmlctx);
3664 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003665 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3666 " <yang-version value=\"1\"/>\n"
3667 " <reference><text>ref</text></reference>\n"
3668 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3669 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003670 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3671 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3672 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID);
3673 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 +02003674}
3675
David Sedlák8985a142019-07-31 16:43:06 +02003676static void
3677test_yin_parse_module(void **state)
3678{
David Sedlák8985a142019-07-31 16:43:06 +02003679 const char *data;
3680 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01003681 struct lys_yin_parser_ctx *yin_ctx = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003682 struct ly_in *in = NULL;
Michal Vasko405cc9e2020-12-01 12:01:27 +01003683 struct lys_glob_unres unres = {0};
David Sedlák8985a142019-07-31 16:43:06 +02003684
3685 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003686 mod->ctx = UTEST_LYCTX;
David Sedlákd2844882019-09-13 16:01:22 +02003687 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003688 " <yang-version value=\"1.1\"/>\n"
3689 " <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
3690 " <prefix value=\"a\"/>\n"
3691 " <import module=\"ietf-yang-metadata\">\n"
3692 " <prefix value=\"md\"/>\n"
3693 " </import>\n"
3694 " <feature name=\"f\"/>\n"
3695 " <md:annotation name=\"x\">\n"
3696 " <description>\n"
3697 " <text>test</text>\n"
3698 " </description>\n"
3699 " <reference>\n"
3700 " <text>test</text>\n"
3701 " </reference>\n"
3702 " <if-feature name=\"f\"/>\n"
3703 " <status value=\"current\"/>\n"
3704 " <type name=\"uint8\"/>\n"
3705 " <units name=\"meters\"/>\n"
3706 " </md:annotation>\n"
3707 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003708 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003709 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
David Sedlákd2844882019-09-13 16:01:22 +02003710 assert_null(mod->parsed->exts->child->next->child);
3711 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
Radek Iša56ca9e42020-09-08 18:42:00 +02003712 lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
David Sedlákd2844882019-09-13 16:01:22 +02003713 lys_module_free(mod, NULL);
3714 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003715 ly_in_free(in, 0);
David Sedlákd2844882019-09-13 16:01:22 +02003716 mod = NULL;
3717 yin_ctx = NULL;
3718
3719 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003720 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003721 data = "<module name=\"example-foo\""
3722 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3723 " xmlns:foo=\"urn:example:foo\""
3724 " xmlns:myext=\"urn:example:extensions\">\n"
David Sedlák8985a142019-07-31 16:43:06 +02003725
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003726 " <yang-version value=\"1\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003727
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003728 " <namespace uri=\"urn:example:foo\"/>\n"
3729 " <prefix value=\"foo\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003730
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003731 " <import module=\"example-extensions\">\n"
3732 " <prefix value=\"myext\"/>\n"
3733 " </import>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003734
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003735 " <list name=\"interface\">\n"
3736 " <key value=\"name\"/>\n"
3737 " <leaf name=\"name\">\n"
3738 " <type name=\"string\"/>\n"
3739 " </leaf>\n"
3740 " <leaf name=\"mtu\">\n"
3741 " <type name=\"uint32\"/>\n"
3742 " <description>\n"
3743 " <text>The MTU of the interface.</text>\n"
3744 " </description>\n"
3745 " <myext:c-define name=\"MY_MTU\"/>\n"
3746 " </leaf>\n"
3747 " </list>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003748 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003749 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003750 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003751 lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
David Sedlák8985a142019-07-31 16:43:06 +02003752 lys_module_free(mod, NULL);
3753 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003754 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003755 mod = NULL;
3756 yin_ctx = NULL;
3757
3758 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003759 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003760 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3761 " <yang-version value=\"1\"/>\n"
3762 " <namespace uri=\"urn:example:foo\"/>\n"
3763 " <prefix value=\"foo\"/>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003764 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003765 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003766 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003767 lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
David Sedlák6d781b62019-08-02 15:22:52 +02003768 lys_module_free(mod, NULL);
3769 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003770 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003771 mod = NULL;
3772 yin_ctx = NULL;
3773
David Sedlák6d781b62019-08-02 15:22:52 +02003774 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003775 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003776 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlák8985a142019-07-31 16:43:06 +02003777 "</submodule>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003778 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003779 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EINVAL);
Radek Iša56ca9e42020-09-08 18:42:00 +02003780 CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
David Sedlák8985a142019-07-31 16:43:06 +02003781 lys_module_free(mod, NULL);
3782 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003783 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003784
David Sedlák6d781b62019-08-02 15:22:52 +02003785 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003786 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003787 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3788 " <yang-version value=\"1\"/>\n"
3789 " <namespace uri=\"urn:example:foo\"/>\n"
3790 " <prefix value=\"foo\"/>\n"
3791 "</module>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003792 "<module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003793 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003794 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +02003795 CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
David Sedlák6d781b62019-08-02 15:22:52 +02003796 lys_module_free(mod, NULL);
3797 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003798 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003799 mod = NULL;
3800 yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003801}
3802
3803static void
3804test_yin_parse_submodule(void **state)
3805{
David Sedlák8985a142019-07-31 16:43:06 +02003806 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01003807 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003808 struct lysp_submodule *submod = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003809 struct ly_in *in;
David Sedlák8985a142019-07-31 16:43:06 +02003810
Radek Iša56ca9e42020-09-08 18:42:00 +02003811 lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name);
Michal Vaskoc3781c32020-10-06 14:04:08 +02003812
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003813 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003814 "<submodule name=\"asub\""
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003815 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3816 " xmlns:a=\"urn:a\">\n"
3817 " <yang-version value=\"1\"/>\n"
3818 " <belongs-to module=\"a\">\n"
3819 " <prefix value=\"a_pref\"/>\n"
3820 " </belongs-to>\n"
3821 " <include module=\"atop\"/>\n"
3822 " <feature name=\"fox\"/>\n"
3823 " <notification name=\"bar-notif\">\n"
3824 " <if-feature name=\"bar\"/>\n"
3825 " </notification>\n"
3826 " <notification name=\"fox-notif\">\n"
3827 " <if-feature name=\"fox\"/>\n"
3828 " </notification>\n"
3829 " <augment target-node=\"/a_pref:top\">\n"
3830 " <if-feature name=\"bar\"/>\n"
3831 " <container name=\"bar-sub\"/>\n"
3832 " </augment>\n"
3833 " <augment target-node=\"/top\">\n"
3834 " <container name=\"bar-sub2\"/>\n"
3835 " </augment>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003836 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003837 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003838 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 +02003839 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003840 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003841 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003842 yin_ctx = NULL;
3843 submod = NULL;
3844
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003845 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3846 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3847 " <yang-version value=\"1\"/>\n"
3848 " <belongs-to module=\"a\">\n"
3849 " <prefix value=\"a_pref\"/>\n"
3850 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003851 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003852 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003853 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 +02003854 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003855 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003856 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003857 yin_ctx = NULL;
3858 submod = NULL;
3859
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003860 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003861 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
3862 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003863 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003864 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
3865 CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003866 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003867 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003868 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003869 yin_ctx = NULL;
3870 submod = NULL;
3871
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003872 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3873 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3874 " <yang-version value=\"1\"/>\n"
3875 " <belongs-to module=\"a\">\n"
3876 " <prefix value=\"a_pref\"/>\n"
3877 " </belongs-to>\n"
3878 "</submodule>\n"
3879 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3880 " <yang-version value=\"1\"/>\n"
3881 " <belongs-to module=\"a\">\n"
3882 " <prefix value=\"a_pref\"/>\n"
3883 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003884 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003885 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003886 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
3887 CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003888 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003889 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003890 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003891 yin_ctx = NULL;
3892 submod = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003893}
3894
David Sedlák3b4db242018-10-19 16:11:01 +02003895int
3896main(void)
3897{
3898
3899 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +02003900 UTEST(test_yin_match_keyword, setup, teardown),
3901 UTEST(test_yin_parse_element_generic, setup, teardown),
3902 UTEST(test_yin_parse_extension_instance, setup, teardown),
3903 UTEST(test_yin_parse_content, setup, teardown),
3904 UTEST(test_validate_value, setup, teardown),
David Sedlák32488102019-07-15 17:44:10 +02003905
Radek Iša56ca9e42020-09-08 18:42:00 +02003906 UTEST(test_yin_match_argument_name),
3907 cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown),
3908 cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown),
3909 cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown),
3910 cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown),
3911 cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown),
3912 cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown),
3913 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown),
3914 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown),
3915 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown),
3916 cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown),
3917 cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown),
3918 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown),
3919 cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown),
3920 cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown),
3921 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown),
3922 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown),
3923 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown),
3924 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown),
3925 cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown),
3926 cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown),
3927 cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown),
3928 cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown),
3929 cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown),
3930 cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown),
3931 cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown),
3932 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown),
3933 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown),
3934 cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown),
3935 cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown),
3936 cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown),
3937 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown),
3938 cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown),
3939 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown),
3940 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown),
3941 cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown),
3942 cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown),
3943 cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown),
3944 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown),
3945 cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown),
3946 cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown),
3947 cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown),
3948 cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown),
3949 cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown),
3950 cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown),
3951 cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown),
3952 cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown),
3953 cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown),
3954 cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown),
3955 cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown),
3956 cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown),
3957 cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown),
3958 cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown),
3959 cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown),
3960 cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown),
3961 cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown),
3962 cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown),
3963 cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown),
3964 cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown),
David Sedlák8985a142019-07-31 16:43:06 +02003965
Radek Iša56ca9e42020-09-08 18:42:00 +02003966 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown),
3967 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown),
David Sedlák3b4db242018-10-19 16:11:01 +02003968 };
3969
Radek Iša56ca9e42020-09-08 18:42:00 +02003970 return cmocka_run_group_tests(tests, NULL, NULL);
David Sedlák3b4db242018-10-19 16:11:01 +02003971}