blob: 12db5e84bd73b22dbead052e39a5011a74198cd4 [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 Krejci70593c12020-06-13 20:48:09 +020025#include "tree_schema.h"
26#include "tree_schema_internal.h"
27#include "xml.h"
28#include "xpath.h"
David Sedlák3b4db242018-10-19 16:11:01 +020029
Michal Vaskoafac7822020-10-20 14:22:26 +020030/* copied from parser_yin.c */
31enum yin_argument {
32 YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */
33 YIN_ARG_NAME, /**< argument name */
34 YIN_ARG_TARGET_NODE, /**< argument target-node */
35 YIN_ARG_MODULE, /**< argument module */
36 YIN_ARG_VALUE, /**< argument value */
37 YIN_ARG_TEXT, /**< argument text */
38 YIN_ARG_CONDITION, /**< argument condition */
39 YIN_ARG_URI, /**< argument uri */
40 YIN_ARG_DATE, /**< argument data */
41 YIN_ARG_TAG, /**< argument tag */
42 YIN_ARG_NONE /**< empty (special value) */
43};
44
45struct yin_subelement {
46 enum ly_stmt type; /**< type of keyword */
47 void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */
48 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 */
49};
50
51struct import_meta {
52 const char *prefix; /**< module prefix. */
53 struct lysp_import **imports; /**< imports to add to. */
54};
55
56struct yin_argument_meta {
57 uint16_t *flags; /**< Argument flags */
58 const char **argument; /**< Argument value */
59};
60
61struct tree_node_meta {
62 struct lysp_node *parent; /**< parent node */
63 struct lysp_node **nodes; /**< linked list of siblings */
64};
65
66struct include_meta {
67 const char *name; /**< Module/submodule name. */
68 struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */
69};
70
71struct inout_meta {
72 struct lysp_node *parent; /**< Parent node. */
Radek Krejci2a9fc652021-01-22 17:44:34 +010073 struct lysp_node_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */
Michal Vaskoafac7822020-10-20 14:22:26 +020074};
75
76struct minmax_dev_meta {
77 uint32_t *lim; /**< min/max value to write to. */
78 uint16_t *flags; /**< min/max flags to write to. */
79 struct lysp_ext_instance **exts; /**< extension instances to add to. */
80};
81
82#define YIN_SUBELEM_MANDATORY 0x01
83#define YIN_SUBELEM_UNIQUE 0x02
84#define YIN_SUBELEM_FIRST 0x04
85#define YIN_SUBELEM_VER2 0x08
86
87#define YIN_SUBELEM_PARSED 0x80
88
David Sedlák555c7202019-07-04 12:14:12 +020089/* prototypes of static functions */
Michal Vaskoafac7822020-10-20 14:22:26 +020090enum yin_argument yin_match_argument_name(const char *name, size_t len);
91LY_ERR yin_parse_content(struct lys_yin_parser_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size,
92 enum ly_stmt current_element, const char **text_content, struct lysp_ext_instance **exts);
93LY_ERR yin_validate_value(struct lys_yin_parser_ctx *ctx, enum yang_arg val_type);
94enum ly_stmt yin_match_keyword(struct lys_yin_parser_ctx *ctx, const char *name, size_t name_len,
95 const char *prefix, size_t prefix_len, enum ly_stmt parrent);
Radek Krejcifc596f92021-02-26 22:40:26 +010096LY_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 +020097 struct lysp_ext_instance **exts);
98LY_ERR yin_parse_element_generic(struct lys_yin_parser_ctx *ctx, enum ly_stmt parent, struct lysp_stmt **element);
99LY_ERR yin_parse_mod(struct lys_yin_parser_ctx *ctx, struct lysp_module *mod);
100LY_ERR yin_parse_submod(struct lys_yin_parser_ctx *ctx, struct lysp_submodule *submod);
101
David Sedlák555c7202019-07-04 12:14:12 +0200102void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
David Sedlák986cb412019-07-04 13:10:11 +0200103void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
David Sedlák32eee7b2019-07-09 12:38:44 +0200104void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
David Sedlák32488102019-07-15 17:44:10 +0200105void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type);
David Sedlák8a83bbb2019-07-18 14:46:00 +0200106void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
David Sedlák04e17b22019-07-19 15:29:48 +0200107void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf);
David Sedlákd2d676a2019-07-22 11:28:19 +0200108void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
David Sedlákaa854b02019-07-22 14:17:10 +0200109void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
David Sedlák0c2bab92019-07-22 15:33:19 +0200110void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
David Sedlák5e13dea2019-07-22 16:06:45 +0200111void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
David Sedlák28794f22019-07-22 16:45:00 +0200112void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100113void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp);
114void lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment);
David Sedlák4ffcec82019-07-25 15:10:21 +0200115void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
David Sedlák8b754462019-07-25 16:22:13 +0200116void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
David Sedlák298ff6d2019-07-26 14:29:03 +0200117void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import);
David Sedlák555c7202019-07-04 12:14:12 +0200118
David Sedláke6cd89e2019-08-07 12:46:02 +0200119/* wrapping element used for mocking has nothing to do with real module structure */
120#define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
121#define ELEMENT_WRAPPER_END "</status>"
122
Radek Iša56ca9e42020-09-08 18:42:00 +0200123#define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\
Michal Vaskofc2cd072021-02-24 13:17:17 +0100124 CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, NULL, INSUBSTMT, 0, "myext:c-define", 0, 0x2, LY_PREF_XML)
David Sedlák872c7b42018-10-26 13:15:20 +0200125
Radek Iša56ca9e42020-09-08 18:42:00 +0200126struct lys_yin_parser_ctx *YCTX;
David Sedlák8e7bda82019-07-16 17:57:50 +0200127
128static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200129setup_ctx(void **state)
David Sedlák8e7bda82019-07-16 17:57:50 +0200130{
David Sedlák619db942019-07-03 14:47:30 +0200131 /* allocate parser context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200132 YCTX = calloc(1, sizeof(*YCTX));
133 YCTX->format = LYS_IN_YIN;
David Sedlák8f5bce02019-06-03 16:41:08 +0200134
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200135 /* allocate new parsed module */
Radek Iša56ca9e42020-09-08 18:42:00 +0200136 YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200137
138 /* allocate new module */
Radek Iša56ca9e42020-09-08 18:42:00 +0200139 YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
140 YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
141 YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200142
Radek Iša56ca9e42020-09-08 18:42:00 +0200143 return 0;
David Sedlák3b4db242018-10-19 16:11:01 +0200144}
145
146static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200147setup(void **state)
David Sedlák68a1af12019-03-08 13:46:54 +0100148{
Radek Iša56ca9e42020-09-08 18:42:00 +0200149 UTEST_SETUP;
David Sedlák68a1af12019-03-08 13:46:54 +0100150
Radek Iša56ca9e42020-09-08 18:42:00 +0200151 setup_ctx(state);
David Sedlák79e50cb2019-06-05 16:33:09 +0200152
Radek Iša56ca9e42020-09-08 18:42:00 +0200153 return 0;
David Sedlák79e50cb2019-06-05 16:33:09 +0200154}
155
David Sedlák8985a142019-07-31 16:43:06 +0200156static int
Radek Iša56ca9e42020-09-08 18:42:00 +0200157teardown_ctx(void **UNUSED(state))
David Sedlák8985a142019-07-31 16:43:06 +0200158{
Radek Iša56ca9e42020-09-08 18:42:00 +0200159 lyxml_ctx_free(YCTX->xmlctx);
160 lys_module_free(YCTX->parsed_mod->mod, NULL);
161 free(YCTX);
162 YCTX = NULL;
David Sedlák8985a142019-07-31 16:43:06 +0200163
Radek Iša56ca9e42020-09-08 18:42:00 +0200164 return 0;
David Sedlák8985a142019-07-31 16:43:06 +0200165}
166
Radek Iša56ca9e42020-09-08 18:42:00 +0200167static int
168teardown(void **state)
169{
170 teardown_ctx(state);
171
172 UTEST_TEARDOWN;
173
174 return 0;
175}
176
177#define RESET_STATE \
178 ly_in_free(UTEST_IN, 0); \
179 UTEST_IN = NULL; \
180 teardown_ctx(state); \
181 setup_ctx(state)
182
David Sedlák68a1af12019-03-08 13:46:54 +0100183static void
David Sedlák1bccdfa2019-06-17 15:55:27 +0200184test_yin_match_keyword(void **state)
David Sedlák3b4db242018-10-19 16:11:01 +0200185{
Michal Vaskob36053d2020-03-26 15:49:30 +0100186 const char *prefix;
187 size_t prefix_len;
Radek Iša56ca9e42020-09-08 18:42:00 +0200188
David Sedlák8f7a1172019-06-20 14:42:18 +0200189 /* create mock yin namespace in xml context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200190 ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN);
191 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
192 prefix = YCTX->xmlctx->prefix;
193 prefix_len = YCTX->xmlctx->prefix_len;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100194
Radek Iša56ca9e42020-09-08 18:42:00 +0200195 assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
196 assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
197 assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
198 assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
199 assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
200 assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
201 assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
202 assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
203 assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
204 assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
205 assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
206 assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
207 assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
208 assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
209 assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
210 assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
211 assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
212 assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
213 assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
214 assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
215 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);
216 assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
217 assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
218 assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
219 assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
220 assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
221 assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
222 assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
223 assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
224 assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
225 assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
226 assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
227 assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
228 assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
229 assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
230 assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
231 assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
232 assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
233 assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
234 assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
235 assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
236 assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
237 assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
238 assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
239 assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
240 assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
241 assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
242 assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
243 assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
244 assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
245 assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
246 assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
247 assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
248 assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
249 assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
250 assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
251 assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
252 assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
253 assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
254 assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
255 assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
256 assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
257 assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
258 assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
259 assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
260 assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
261 assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
262 assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
263 assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
264 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 +0200265}
David Sedlák3b4db242018-10-19 16:11:01 +0200266
David Sedlák872c7b42018-10-26 13:15:20 +0200267static void
Radek Iša56ca9e42020-09-08 18:42:00 +0200268test_yin_match_argument_name(void **UNUSED(state))
David Sedlák872c7b42018-10-26 13:15:20 +0200269{
David Sedlák060b00e2019-06-19 11:12:06 +0200270 assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
271 assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
272 assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
273 assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION);
274 assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE);
275 assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE);
276 assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME);
277 assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG);
278 assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
279 assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT);
280 assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI);
281 assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200282}
283
David Sedlák68a1af12019-03-08 13:46:54 +0100284static void
David Sedlákb1a78352019-06-28 16:16:29 +0200285test_yin_parse_element_generic(void **state)
286{
David Sedlákb1a78352019-06-28 16:16:29 +0200287 struct lysp_ext_instance exts;
David Sedlákb1a78352019-06-28 16:16:29 +0200288 LY_ERR ret;
Radek Iša56ca9e42020-09-08 18:42:00 +0200289 const char *arg;
290 const char *stmt;
291 const char *data;
David Sedlákb1a78352019-06-28 16:16:29 +0200292
293 memset(&exts, 0, sizeof(exts));
294
Radek Iša56ca9e42020-09-08 18:42:00 +0200295 data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
296 ly_in_new_memory(data, &UTEST_IN);
297 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100298
Radek Iša56ca9e42020-09-08 18:42:00 +0200299 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlákb1a78352019-06-28 16:16:29 +0200300 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200301 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100302 stmt = "myext:elem";
Radek Iša56ca9e42020-09-08 18:42:00 +0200303 arg = "text_value";
Radek Krejci996f0772021-02-05 19:39:41 +0100304 CHECK_LYSP_STMT(exts.child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200305 stmt = "attr";
306 arg = "value";
307 CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt);
308 lysp_ext_instance_free(UTEST_LYCTX, &exts);
309 RESET_STATE;
David Sedlák5392a212019-07-01 09:19:10 +0200310
David Sedlákb0ca07d2019-09-11 11:54:05 +0200311 data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200312 ly_in_new_memory(data, &UTEST_IN);
313 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100314
Radek Iša56ca9e42020-09-08 18:42:00 +0200315 ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
David Sedlák5392a212019-07-01 09:19:10 +0200316 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200317 assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100318 stmt = "myext:elem";
Radek Krejci996f0772021-02-05 19:39:41 +0100319 CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200320 lysp_ext_instance_free(UTEST_LYCTX, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200321}
322
323static void
324test_yin_parse_extension_instance(void **state)
325{
326 LY_ERR ret;
David Sedlákb1a78352019-06-28 16:16:29 +0200327 struct lysp_ext_instance *exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200328 struct lysp_stmt *act_child;
David Sedlákb0ca07d2019-09-11 11:54:05 +0200329 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 +0200330 const char *stmt = "value1";
331 const char *arg = "test";
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100332
Radek Iša56ca9e42020-09-08 18:42:00 +0200333 ly_in_new_memory(data, &UTEST_IN);
334 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100335
Radek Krejcifc596f92021-02-26 22:40:26 +0100336 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákb1a78352019-06-28 16:16:29 +0200337 assert_int_equal(ret, LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +0200338 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL,
Radek Krejcifc596f92021-02-26 22:40:26 +0100339 LY_STMT_CONTACT, 0, "myext:ext", 0, LYS_CHOICE, 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 Iša56ca9e42020-09-08 18:42:00 +0200359 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 0, NULL,
Radek Krejcifc596f92021-02-26 22:40:26 +0100360 LY_STMT_CONTACT, 0, "myext:extension-elem", 0, LYS_CHOICE, LY_PREF_XML);
Radek Iša56ca9e42020-09-08 18:42:00 +0200361 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákf250ecf2019-07-01 11:02:05 +0200362 LY_ARRAY_FREE(exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200363 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200364 RESET_STATE;
David Sedlákadd0c2e2019-08-16 10:49:12 +0200365
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100366 data =
367 "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n"
368 " <myext:ext-sub1/>\n"
369 " <myext:ext-sub2 sattr1=\"stext2\">\n"
370 " <myext:ext-sub21>\n"
371 " <myext:ext-sub211 sattr21=\"text21\"/>\n"
372 " </myext:ext-sub21>\n"
373 " </myext:ext-sub2>\n"
374 " <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n"
375 "</myext:ext>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200376 ly_in_new_memory(data, &UTEST_IN);
377 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100378
Radek Krejcifc596f92021-02-26 22:40:26 +0100379 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200380 assert_int_equal(ret, LY_SUCCESS);
381
Radek Iša56ca9e42020-09-08 18:42:00 +0200382 CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL,
Radek Krejcifc596f92021-02-26 22:40:26 +0100383 LY_STMT_CONTACT, 0, "myext:ext", 0, LYS_CHOICE, LY_PREF_XML);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200384
Radek Iša56ca9e42020-09-08 18:42:00 +0200385 stmt = "attr1";
386 arg = "text1";
387 act_child = exts->child;
388 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
389 stmt = "attr2";
390 arg = "text2";
391 act_child = act_child->next;
392 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100393 stmt = "myext:ext-sub1";
Radek Iša56ca9e42020-09-08 18:42:00 +0200394 arg = NULL;
395 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100396 CHECK_LYSP_STMT(act_child, arg, NULL, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100397 stmt = "myext:ext-sub2";
Radek Iša56ca9e42020-09-08 18:42:00 +0200398 arg = NULL;
399 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100400 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 1, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200401
Radek Iša56ca9e42020-09-08 18:42:00 +0200402 stmt = "sattr1";
403 arg = "stext2";
404 act_child = act_child->child;
405 CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt);
Michal Vaskofc2cd072021-02-24 13:17:17 +0100406 stmt = "myext:ext-sub21";
Radek Iša56ca9e42020-09-08 18:42:00 +0200407 arg = NULL;
408 act_child = act_child->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100409 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200410
Michal Vaskofc2cd072021-02-24 13:17:17 +0100411 stmt = "myext:ext-sub211";
Radek Iša56ca9e42020-09-08 18:42:00 +0200412 arg = NULL;
413 act_child = act_child->child;
Radek Krejci996f0772021-02-05 19:39:41 +0100414 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200415
Radek Iša56ca9e42020-09-08 18:42:00 +0200416 stmt = "sattr21";
417 arg = "text21";
418 act_child = act_child->child;
419 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200420
Michal Vaskofc2cd072021-02-24 13:17:17 +0100421 stmt = "myext:ext-sub3";
Radek Iša56ca9e42020-09-08 18:42:00 +0200422 arg = NULL;
423 act_child = exts->child->next->next->next->next;
Radek Krejci996f0772021-02-05 19:39:41 +0100424 CHECK_LYSP_STMT(act_child, arg, 1, 0, LY_STMT_EXTENSION_INSTANCE, 0, stmt);
Radek Iša56ca9e42020-09-08 18:42:00 +0200425 stmt = "attr3";
426 arg = "text3";
427 act_child = act_child->child;
428 CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200429
Radek Iša56ca9e42020-09-08 18:42:00 +0200430 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákadd0c2e2019-08-16 10:49:12 +0200431 LY_ARRAY_FREE(exts);
432 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200433 RESET_STATE;
David Sedlákaa98bba2019-09-12 11:52:14 +0200434
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100435 data =
436 "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
437 " <yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>\n"
438 " <yin:augment target-node=\"target\"/>\n"
439 " <yin:status value=\"value\"/>\n"
440 " <yin:include module=\"mod\"/>\n"
441 " <yin:input />\n"
442 " <yin:must condition=\"cond\"/>\n"
443 " <yin:namespace uri=\"uri\"/>\n"
444 " <yin:revision date=\"data\"/>\n"
445 " <yin:unique tag=\"tag\"/>\n"
446 " <yin:description><yin:text>contact-val</yin:text></yin:description>\n"
447 " <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n"
448 "</myext:extension-elem>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200449 ly_in_new_memory(data, &UTEST_IN);
450 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100451
Radek Krejcifc596f92021-02-26 22:40:26 +0100452 ret = yin_parse_extension_instance(YCTX, LY_STMT_CONTACT, 0, &exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200453 assert_int_equal(ret, LY_SUCCESS);
454 assert_string_equal(exts->child->arg, "act-name");
455 assert_string_equal(exts->child->next->arg, "target");
456 assert_string_equal(exts->child->next->next->arg, "value");
457 assert_string_equal(exts->child->next->next->next->arg, "mod");
458 assert_null(exts->child->next->next->next->next->arg);
459 assert_string_equal(exts->child->next->next->next->next->next->arg, "cond");
460 assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri");
461 assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
462 assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
463 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 +0200464 lysp_ext_instance_free(UTEST_LYCTX, exts);
David Sedlákaa98bba2019-09-12 11:52:14 +0200465 LY_ARRAY_FREE(exts);
466 exts = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200467 RESET_STATE;
David Sedlákb1a78352019-06-28 16:16:29 +0200468}
469
David Sedlák555c7202019-07-04 12:14:12 +0200470static void
471test_yin_parse_content(void **state)
472{
David Sedlák555c7202019-07-04 12:14:12 +0200473 LY_ERR ret = LY_SUCCESS;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100474 const char *data =
475 "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
476 " <myext:custom xmlns:myext=\"urn:example:extensions\">totally amazing extension</myext:custom>\n"
477 " <extension name=\"ext\">\n"
478 " <argument name=\"argname\"></argument>\n"
479 " <description><text>desc</text></description>\n"
480 " <reference><text>ref</text></reference>\n"
481 " <status value=\"deprecated\"></status>\n"
482 " </extension>\n"
483 " <text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>\n"
484 " <if-feature name=\"foo\"></if-feature>\n"
485 " <when condition=\"condition...\">\n"
486 " <reference><text>when_ref</text></reference>\n"
487 " <description><text>when_desc</text></description>\n"
488 " </when>\n"
489 " <config value=\"true\"/>\n"
490 " <error-message>\n"
491 " <value>error-msg</value>\n"
492 " </error-message>\n"
493 " <error-app-tag value=\"err-app-tag\"/>\n"
494 " <units name=\"radians\"></units>\n"
495 " <default value=\"default-value\"/>\n"
496 " <position value=\"25\"></position>\n"
497 " <value value=\"-5\"/>\n"
498 " <require-instance value=\"true\"></require-instance>\n"
499 " <range value=\"5..10\" />\n"
500 " <length value=\"baf\"/>\n"
501 " <pattern value='pattern'>\n"
502 " <modifier value='invert-match'/>\n"
503 " </pattern>\n"
504 " <enum name=\"yay\">\n"
505 " </enum>\n"
506 "</prefix>";
David Sedlák555c7202019-07-04 12:14:12 +0200507 struct lysp_ext_instance *exts = NULL;
David Sedlák5f8191e2019-07-08 16:35:52 +0200508 const char **if_features = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200509 const char *value, *error_message, *app_tag, *units;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200510 struct lysp_qname def = {0};
David Sedlák986cb412019-07-04 13:10:11 +0200511 struct lysp_ext *ext_def = NULL;
David Sedlák32eee7b2019-07-09 12:38:44 +0200512 struct lysp_when *when_p = NULL;
David Sedlákcf5569a2019-07-11 13:31:34 +0200513 struct lysp_type_enum pos_enum = {}, val_enum = {};
David Sedlákfd5b9c32019-07-12 15:33:13 +0200514 struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
Juraj Vijtiukf6a07372020-10-29 21:13:33 +0100515 uint16_t config = 0;
David Sedlák555c7202019-07-04 12:14:12 +0200516
Radek Iša56ca9e42020-09-08 18:42:00 +0200517 ly_in_new_memory(data, &UTEST_IN);
518 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
519 lyxml_ctx_next(YCTX->xmlctx);
520 lyxml_ctx_next(YCTX->xmlctx);
521 lyxml_ctx_next(YCTX->xmlctx);
David Sedlák555c7202019-07-04 12:14:12 +0200522
David Sedlákfd5b9c32019-07-12 15:33:13 +0200523 struct yin_subelement subelems[17] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100524 {LY_STMT_CONFIG, &config, 0},
525 {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
526 {LY_STMT_ENUM, &enum_type, 0},
527 {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
Radek Iša56ca9e42020-09-08 18:42:00 +0200528 {LY_STMT_ERROR_MESSAGE, &error_message, 0},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100529 {LY_STMT_EXTENSION, &ext_def, 0},
530 {LY_STMT_IF_FEATURE, &if_features, 0},
531 {LY_STMT_LENGTH, &len_type, 0},
532 {LY_STMT_PATTERN, &patter_type, 0},
533 {LY_STMT_POSITION, &pos_enum, 0},
534 {LY_STMT_RANGE, &range_type, 0},
535 {LY_STMT_REQUIRE_INSTANCE, &req_type, 0},
536 {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE},
537 {LY_STMT_VALUE, &val_enum, 0},
538 {LY_STMT_WHEN, &when_p, 0},
539 {LY_STMT_EXTENSION_INSTANCE, NULL, 0},
540 {LY_STMT_ARG_TEXT, &value, 0}
541 };
542
Radek Iša56ca9e42020-09-08 18:42:00 +0200543 ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200544 assert_int_equal(ret, LY_SUCCESS);
David Sedlák2ce1be62019-07-10 16:15:09 +0200545 /* check parsed values */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200546 assert_string_equal(def.str, "default-value");
Michal Vaskofc2cd072021-02-24 13:17:17 +0100547 const char *exts_name = "myext:custom";
Radek Iša56ca9e42020-09-08 18:42:00 +0200548 const char *exts_arg = "totally amazing extension";
549
550 CHECK_LYSP_EXT_INSTANCE(exts, exts_arg, 0, NULL,
Radek Krejcifc596f92021-02-26 22:40:26 +0100551 LY_STMT_PREFIX, 0, exts_name, 0, 0x1, LY_PREF_XML);
David Sedlák555c7202019-07-04 12:14:12 +0200552 assert_string_equal(value, "wsefsdf");
David Sedláka5b1d382019-07-10 16:31:09 +0200553 assert_string_equal(units, "radians");
David Sedlák32eee7b2019-07-09 12:38:44 +0200554 assert_string_equal(when_p->cond, "condition...");
555 assert_string_equal(when_p->dsc, "when_desc");
556 assert_string_equal(when_p->ref, "when_ref");
David Sedláke1a30302019-07-10 13:49:38 +0200557 assert_int_equal(config, LYS_CONFIG_W);
Radek Iša56ca9e42020-09-08 18:42:00 +0200558 CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25);
559 CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5);
David Sedlákcf5569a2019-07-11 13:31:34 +0200560 assert_int_equal(req_type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200561 assert_true(req_type.flags &= LYS_SET_REQINST);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200562 assert_string_equal(range_type.range->arg.str, "5..10");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200563 assert_true(range_type.flags & LYS_SET_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +0200564 assert_string_equal(error_message, "error-msg");
David Sedlák2ce1be62019-07-10 16:15:09 +0200565 assert_string_equal(app_tag, "err-app-tag");
David Sedlákfd5b9c32019-07-12 15:33:13 +0200566 assert_string_equal(enum_type.enums->name, "yay");
Radek Iša56ca9e42020-09-08 18:42:00 +0200567 CHECK_LYSP_RESTR(len_type.length, "baf", NULL,
568 NULL, NULL, 0, NULL);
David Sedlákc3da3ef2019-07-19 12:56:08 +0200569 assert_true(len_type.flags & LYS_SET_LENGTH);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200570 assert_string_equal(patter_type.patterns->arg.str, "\x015pattern");
David Sedlákc3da3ef2019-07-19 12:56:08 +0200571 assert_true(patter_type.flags & LYS_SET_PATTERN);
David Sedlák2ce1be62019-07-10 16:15:09 +0200572 /* cleanup */
Radek Iša56ca9e42020-09-08 18:42:00 +0200573 lysp_ext_instance_free(UTEST_LYCTX, exts);
574 lysp_when_free(UTEST_LYCTX, when_p);
575 lysp_ext_free(UTEST_LYCTX, ext_def);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100576 lydict_remove(UTEST_LYCTX, *if_features);
577 lydict_remove(UTEST_LYCTX, error_message);
578 lydict_remove(UTEST_LYCTX, app_tag);
579 lydict_remove(UTEST_LYCTX, units);
580 lydict_remove(UTEST_LYCTX, patter_type.patterns->arg.str);
581 lydict_remove(UTEST_LYCTX, def.str);
582 lydict_remove(UTEST_LYCTX, range_type.range->arg.str);
583 lydict_remove(UTEST_LYCTX, len_type.length->arg.str);
584 lydict_remove(UTEST_LYCTX, enum_type.enums->name);
585 lydict_remove(UTEST_LYCTX, value);
David Sedlák5f8191e2019-07-08 16:35:52 +0200586 LY_ARRAY_FREE(if_features);
David Sedlák555c7202019-07-04 12:14:12 +0200587 LY_ARRAY_FREE(exts);
David Sedlák986cb412019-07-04 13:10:11 +0200588 LY_ARRAY_FREE(ext_def);
David Sedlákd3983112019-07-12 11:20:56 +0200589 LY_ARRAY_FREE(patter_type.patterns);
David Sedlákfd5b9c32019-07-12 15:33:13 +0200590 LY_ARRAY_FREE(enum_type.enums);
David Sedlák32eee7b2019-07-09 12:38:44 +0200591 free(when_p);
David Sedlákb7296dd2019-07-11 14:58:38 +0200592 free(range_type.range);
David Sedlák438ae432019-07-11 15:36:54 +0200593 free(len_type.length);
Radek Iša56ca9e42020-09-08 18:42:00 +0200594 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200595
596 /* test unique subelem */
597 const char *prefix_value;
Radek Krejcid6b76452019-09-03 17:03:03 +0200598 struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100599 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}};
600
David Sedláke6cd89e2019-08-07 12:46:02 +0200601 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100602 "<prefix value=\"inv_mod\" />"
603 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
604 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
605 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200606 ly_in_new_memory(data, &UTEST_IN);
607 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
608 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100609
Radek Iša56ca9e42020-09-08 18:42:00 +0200610 ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200611 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200612 CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1.");
613 lydict_remove(UTEST_LYCTX, prefix_value);
614 lydict_remove(UTEST_LYCTX, value);
615 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200616
617 /* test first subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200618 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100619 "<prefix value=\"inv_mod\" />"
620 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
621 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
622 ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200623 struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100624 {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
625
Radek Iša56ca9e42020-09-08 18:42:00 +0200626 ly_in_new_memory(data, &UTEST_IN);
627 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
628 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100629
Radek Iša56ca9e42020-09-08 18:42:00 +0200630 ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200631 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200632 CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1.");
633 lydict_remove(UTEST_LYCTX, prefix_value);
634 RESET_STATE;
David Sedlák555c7202019-07-04 12:14:12 +0200635
636 /* test mandatory subelem */
David Sedláke6cd89e2019-08-07 12:46:02 +0200637 data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
Radek Krejcid6b76452019-09-03 17:03:03 +0200638 struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100639
Radek Iša56ca9e42020-09-08 18:42:00 +0200640 ly_in_new_memory(data, &UTEST_IN);
641 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
642 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100643
Radek Iša56ca9e42020-09-08 18:42:00 +0200644 ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
David Sedlák555c7202019-07-04 12:14:12 +0200645 assert_int_equal(ret, LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +0200646 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1.");
David Sedlák555c7202019-07-04 12:14:12 +0200647}
648
David Sedlák92147b02019-07-09 14:01:01 +0200649static void
David Sedlák4a650532019-07-10 11:55:18 +0200650test_validate_value(void **state)
651{
Michal Vaskob36053d2020-03-26 15:49:30 +0100652 const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
653
654 /* create some XML context */
Radek Iša56ca9e42020-09-08 18:42:00 +0200655 ly_in_new_memory(data, &UTEST_IN);
656 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
657 YCTX->xmlctx->status = LYXML_ELEM_CONTENT;
658 YCTX->xmlctx->dynamic = 0;
Michal Vaskob36053d2020-03-26 15:49:30 +0100659
Radek Iša56ca9e42020-09-08 18:42:00 +0200660 YCTX->xmlctx->value = "#invalid";
661 YCTX->xmlctx->value_len = 8;
662 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
663 CHECK_LOG_CTX("Invalid identifier character '#' (0x0023).", "Line number 1.");
Michal Vaskob36053d2020-03-26 15:49:30 +0100664
Radek Iša56ca9e42020-09-08 18:42:00 +0200665 YCTX->xmlctx->value = "";
666 YCTX->xmlctx->value_len = 0;
667 assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100668
Radek Iša56ca9e42020-09-08 18:42:00 +0200669 YCTX->xmlctx->value = "pre:b";
670 YCTX->xmlctx->value_len = 5;
671 assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
672 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +0100673
Radek Iša56ca9e42020-09-08 18:42:00 +0200674 YCTX->xmlctx->value = "pre:pre:b";
675 YCTX->xmlctx->value_len = 9;
676 assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID);
David Sedlák4a650532019-07-10 11:55:18 +0200677}
678
David Sedlák32488102019-07-15 17:44:10 +0200679/* helper function to simplify unit test of each element using parse_content function */
680LY_ERR
Radek Iša56ca9e42020-09-08 18:42:00 +0200681test_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 +0200682{
David Sedlákc5b20842019-08-13 10:18:31 +0200683 const char *name, *prefix;
684 size_t name_len, prefix_len;
David Sedlák32488102019-07-15 17:44:10 +0200685 LY_ERR ret = LY_SUCCESS;
686 struct yin_subelement subelems[71] = {
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100687 {LY_STMT_ACTION, dest, 0},
688 {LY_STMT_ANYDATA, dest, 0},
689 {LY_STMT_ANYXML, dest, 0},
690 {LY_STMT_ARGUMENT, dest, 0},
691 {LY_STMT_AUGMENT, dest, 0},
692 {LY_STMT_BASE, dest, 0},
693 {LY_STMT_BELONGS_TO, dest, 0},
694 {LY_STMT_BIT, dest, 0},
695 {LY_STMT_CASE, dest, 0},
696 {LY_STMT_CHOICE, dest, 0},
697 {LY_STMT_CONFIG, dest, 0},
698 {LY_STMT_CONTACT, dest, 0},
699 {LY_STMT_CONTAINER, dest, 0},
700 {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE},
701 {LY_STMT_DESCRIPTION, dest, 0},
702 {LY_STMT_DEVIATE, dest, 0},
703 {LY_STMT_DEVIATION, dest, 0},
704 {LY_STMT_ENUM, dest, 0},
705 {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE},
706 {LY_STMT_ERROR_MESSAGE, dest, 0},
707 {LY_STMT_EXTENSION, dest, 0},
708 {LY_STMT_FEATURE, dest, 0},
709 {LY_STMT_FRACTION_DIGITS, dest, 0},
710 {LY_STMT_GROUPING, dest, 0},
711 {LY_STMT_IDENTITY, dest, 0},
712 {LY_STMT_IF_FEATURE, dest, 0},
713 {LY_STMT_IMPORT, dest, 0},
714 {LY_STMT_INCLUDE, dest, 0},
715 {LY_STMT_INPUT, dest, 0},
716 {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE},
717 {LY_STMT_LEAF, dest, 0},
718 {LY_STMT_LEAF_LIST, dest, 0},
719 {LY_STMT_LENGTH, dest, 0},
720 {LY_STMT_LIST, dest, 0},
721 {LY_STMT_MANDATORY, dest, 0},
722 {LY_STMT_MAX_ELEMENTS, dest, 0},
723 {LY_STMT_MIN_ELEMENTS, dest, 0},
724 {LY_STMT_MODIFIER, dest, 0},
725 {LY_STMT_MODULE, dest, 0},
726 {LY_STMT_MUST, dest, 0},
727 {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE},
728 {LY_STMT_NOTIFICATION, dest, 0},
729 {LY_STMT_ORDERED_BY, dest, 0},
730 {LY_STMT_ORGANIZATION, dest, 0},
731 {LY_STMT_OUTPUT, dest, 0},
732 {LY_STMT_PATH, dest, 0},
733 {LY_STMT_PATTERN, dest, 0},
734 {LY_STMT_POSITION, dest, 0},
735 {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE},
736 {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE},
737 {LY_STMT_RANGE, dest, 0},
738 {LY_STMT_REFERENCE, dest, 0},
739 {LY_STMT_REFINE, dest, 0},
740 {LY_STMT_REQUIRE_INSTANCE, dest, 0},
741 {LY_STMT_REVISION, dest, 0},
742 {LY_STMT_REVISION_DATE, dest, 0},
743 {LY_STMT_RPC, dest, 0},
744 {LY_STMT_STATUS, dest, 0},
745 {LY_STMT_SUBMODULE, dest, 0},
746 {LY_STMT_TYPE, dest, 0},
747 {LY_STMT_TYPEDEF, dest, 0},
748 {LY_STMT_UNIQUE, dest, 0},
749 {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE},
750 {LY_STMT_USES, dest, 0},
751 {LY_STMT_VALUE, dest, 0},
752 {LY_STMT_WHEN, dest, 0},
753 {LY_STMT_YANG_VERSION, dest, 0},
754 {LY_STMT_YIN_ELEMENT, dest, 0},
755 {LY_STMT_EXTENSION_INSTANCE, dest, 0},
756 {LY_STMT_ARG_TEXT, dest, 0},
757 {LY_STMT_ARG_VALUE, dest, 0}
758 };
759
Radek Iša56ca9e42020-09-08 18:42:00 +0200760 ly_in_new_memory(data, &UTEST_IN);
761 lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
762 prefix = YCTX->xmlctx->prefix;
763 prefix_len = YCTX->xmlctx->prefix_len;
764 name = YCTX->xmlctx->name;
765 name_len = YCTX->xmlctx->name_len;
766 lyxml_ctx_next(YCTX->xmlctx);
Michal Vaskob36053d2020-03-26 15:49:30 +0100767
Radek Iša56ca9e42020-09-08 18:42:00 +0200768 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 +0100769
Michal Vasko63f3d842020-07-08 10:10:14 +0200770 /* free parser and input */
Radek Iša56ca9e42020-09-08 18:42:00 +0200771 lyxml_ctx_free(YCTX->xmlctx);
772 YCTX->xmlctx = NULL;
773 ly_in_free(UTEST_IN, 0);
774 UTEST_IN = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200775 return ret;
776}
777
David Sedlákd1144562019-08-06 12:36:14 +0200778#define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>"
779
David Sedlák32488102019-07-15 17:44:10 +0200780static void
David Sedlák43801c92019-08-05 15:58:54 +0200781test_enum_elem(void **state)
David Sedlák32488102019-07-15 17:44:10 +0200782{
David Sedlák32488102019-07-15 17:44:10 +0200783 struct lysp_type type = {};
784 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100785
David Sedlák32488102019-07-15 17:44:10 +0200786 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100787 "<enum name=\"enum-name\">\n"
788 " <if-feature name=\"feature\" />\n"
789 " <value value=\"55\" />\n"
790 " <status value=\"deprecated\" />\n"
791 " <description><text>desc...</text></description>\n"
792 " <reference><text>ref...</text></reference>\n"
793 " " EXT_SUBELEM "\n"
794 "</enum>"
795 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200796 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
797 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
798
799 CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200800 assert_string_equal(type.enums->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100801 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LY_STMT_ENUM);
Radek Iša56ca9e42020-09-08 18:42:00 +0200802 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200803 memset(&type, 0, sizeof type);
804
805 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100806 "<enum name=\"enum-name\"></enum>"
807 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200808 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +0200809 assert_string_equal(type.enums->name, "enum-name");
Radek Iša56ca9e42020-09-08 18:42:00 +0200810 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák32488102019-07-15 17:44:10 +0200811 memset(&type, 0, sizeof type);
David Sedlák43801c92019-08-05 15:58:54 +0200812}
813
814static void
815test_bit_elem(void **state)
816{
David Sedlák43801c92019-08-05 15:58:54 +0200817 struct lysp_type type = {};
818 const char *data;
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100819
David Sedlák43801c92019-08-05 15:58:54 +0200820 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100821 "<bit name=\"bit-name\">\n"
822 " <if-feature name=\"feature\" />\n"
823 " <position value=\"55\" />\n"
824 " <status value=\"deprecated\" />\n"
825 " <description><text>desc...</text></description>\n"
826 " <reference><text>ref...</text></reference>\n"
827 EXT_SUBELEM
828 "</bit>"
829 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200830 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
831 uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
832
833 CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
Michal Vasko7f45cf22020-10-01 12:49:44 +0200834 assert_string_equal(type.bits->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100835 TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LY_STMT_BIT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200836 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákd1144562019-08-06 12:36:14 +0200837 memset(&type, 0, sizeof type);
838
839 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100840 "<bit name=\"bit-name\"> </bit>"
841 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200842 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
843 CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
844 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák43801c92019-08-05 15:58:54 +0200845 memset(&type, 0, sizeof type);
David Sedlák32488102019-07-15 17:44:10 +0200846}
847
848static void
849test_meta_elem(void **state)
850{
David Sedlák32488102019-07-15 17:44:10 +0200851 char *value = NULL;
852 const char *data;
David Sedlákd1144562019-08-06 12:36:14 +0200853 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200854
855 /* organization element */
856 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100857 "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
858 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200859 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100860 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORGANIZATION);
861 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LY_STMT_ORGANIZATION);
Radek Iša56ca9e42020-09-08 18:42:00 +0200862
David Sedlák32488102019-07-15 17:44:10 +0200863 assert_string_equal(value, "organization...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100864 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200865 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +0200866 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200867 exts = NULL;
868
David Sedlák32488102019-07-15 17:44:10 +0200869 /* contact element */
870 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100871 "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
872 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200873 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100874 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONTACT);
David Sedlák32488102019-07-15 17:44:10 +0200875 assert_string_equal(value, "contact...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100876 lydict_remove(UTEST_LYCTX, value);
Radek Iša56ca9e42020-09-08 18:42:00 +0200877 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200878 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200879 value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +0200880
David Sedlák32488102019-07-15 17:44:10 +0200881 /* description element */
882 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100883 "<description><text>description...</text>" EXT_SUBELEM "</description>"
884 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200885 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
Radek Krejcifc596f92021-02-26 22:40:26 +0100886 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DESCRIPTION);
David Sedlák32488102019-07-15 17:44:10 +0200887 assert_string_equal(value, "description...");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100888 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200889 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200890 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200891 exts = NULL;
892
David Sedlák32488102019-07-15 17:44:10 +0200893 /* reference element */
894 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100895 "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
896 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200897 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +0200898 assert_string_equal(value, "reference...");
Radek Krejcifc596f92021-02-26 22:40:26 +0100899 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REFERENCE);
Michal Vaskoe180ed02021-02-05 16:31:20 +0100900 lydict_remove(UTEST_LYCTX, value);
David Sedlák32488102019-07-15 17:44:10 +0200901 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200902 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200903 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200904
David Sedlákdf2a9732019-08-07 13:23:16 +0200905 /* reference element */
906 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100907 "<reference invalid=\"text\"><text>reference...</text>" "</reference>"
908 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200909 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
910 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +0100911 lydict_remove(UTEST_LYCTX, value);
David Sedlákdf2a9732019-08-07 13:23:16 +0200912 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200913 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákdf2a9732019-08-07 13:23:16 +0200914 exts = NULL;
915
David Sedlák32488102019-07-15 17:44:10 +0200916 /* missing text subelement */
917 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100918 "<reference>reference...</reference>"
919 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200920 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
921 CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +0200922
David Sedlákd1144562019-08-06 12:36:14 +0200923 /* reference element */
924 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100925 "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
926 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200927 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
928 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 +0100929 lydict_remove(UTEST_LYCTX, value);
David Sedlákd1144562019-08-06 12:36:14 +0200930 value = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +0200931 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +0200932 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200933}
934
935static void
936test_import_elem(void **state)
937{
David Sedlák32488102019-07-15 17:44:10 +0200938 const char *data;
David Sedlák298ff6d2019-07-26 14:29:03 +0200939 struct lysp_import *imports = NULL;
940 struct import_meta imp_meta = {"prefix", &imports};
David Sedlák32488102019-07-15 17:44:10 +0200941
942 /* max subelems */
943 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100944 "<import module=\"a\">\n"
945 EXT_SUBELEM
946 " <prefix value=\"a_mod\"/>\n"
947 " <revision-date date=\"2015-01-01\"></revision-date>\n"
948 " <description><text>import description</text></description>\n"
949 " <reference><text>import reference</text></reference>\n"
950 "</import>"
951 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200952 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
953 CHECK_LYSP_IMPORT(imports, "import description", 1, "a",
954 "a_mod", "import reference", "2015-01-01");
Radek Krejci39b7fc22021-02-26 23:29:18 +0100955 TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LY_STMT_IMPORT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200956 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200957 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200958
959 /* min subelems */
David Sedlák32488102019-07-15 17:44:10 +0200960 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100961 "<import module=\"a\">\n"
962 " <prefix value=\"a_mod\"/>\n"
963 "</import>"
964 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200965 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
966 CHECK_LYSP_IMPORT(imports, NULL, 0, "a",
967 "a_mod", NULL, "");
968 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200969 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200970
971 /* invalid (missing prefix) */
David Sedlák298ff6d2019-07-26 14:29:03 +0200972 data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200973 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
974 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1.");
975 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200976 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200977
978 /* invalid reused prefix */
David Sedlák32488102019-07-15 17:44:10 +0200979 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100980 "<import module=\"a\">\n"
981 " <prefix value=\"prefix\"/>\n"
982 "</import>"
983 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200984 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
985 CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3.");
986 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
David Sedlák298ff6d2019-07-26 14:29:03 +0200987 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +0200988
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100989 data = ELEMENT_WRAPPER_START
990 "<import module=\"a\">\n"
991 " <prefix value=\"a\"/>\n"
992 "</import>\n"
993 "<import module=\"a\">\n"
994 " <prefix value=\"a\"/>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200995 "</import>\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100996 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +0200997 assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
998 CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6.");
999 FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001000 imports = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001001}
1002
1003static void
1004test_status_elem(void **state)
1005{
David Sedlák32488102019-07-15 17:44:10 +02001006 const char *data;
1007 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001008 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001009
1010 /* test valid values */
1011 data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001012 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001013 assert_true(flags & LYS_STATUS_CURR);
David Sedlák32488102019-07-15 17:44:10 +02001014
1015 data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001016 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001017 assert_true(flags & LYS_STATUS_DEPRC);
David Sedlák32488102019-07-15 17:44:10 +02001018
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001019 data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001020 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001021 assert_true(flags & LYS_STATUS_OBSLT);
Radek Krejcifc596f92021-02-26 22:40:26 +01001022 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_STATUS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001023 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001024 exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001025
1026 /* test invalid value */
1027 data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001028 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1029 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. "
1030 "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001031}
1032
1033static void
1034test_ext_elem(void **state)
1035{
David Sedlák32488102019-07-15 17:44:10 +02001036 const char *data;
1037 struct lysp_ext *ext = NULL;
1038
1039 /* max subelems */
1040 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001041 "<extension name=\"ext_name\">\n"
1042 " <argument name=\"arg\"></argument>\n"
1043 " <status value=\"current\"/>\n"
1044 " <description><text>ext_desc</text></description>\n"
1045 " <reference><text>ext_ref</text></reference>\n"
1046 EXT_SUBELEM
1047 "</extension>"
1048 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001049 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1050 CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001051 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LY_STMT_EXTENSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001052 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001053 LY_ARRAY_FREE(ext);
1054 ext = NULL;
1055
1056 /* min subelems */
1057 data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001058 assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
1059 CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL);
1060 lysp_ext_free(UTEST_LYCTX, ext);
David Sedlák32488102019-07-15 17:44:10 +02001061 LY_ARRAY_FREE(ext);
1062 ext = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001063}
1064
1065static void
1066test_yin_element_elem(void **state)
1067{
David Sedlák32488102019-07-15 17:44:10 +02001068 const char *data;
1069 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001070 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001071
1072 data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001073 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001074 assert_true(flags & LYS_YINELEM_TRUE);
David Sedlák32488102019-07-15 17:44:10 +02001075
David Sedlákd1144562019-08-06 12:36:14 +02001076 data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001077 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001078 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001079 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YIN_ELEMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001080 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001081
1082 data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001083 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001084 assert_true(flags & LYS_YINELEM_TRUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001085 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. "
1086 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001087}
1088
1089static void
1090test_yangversion_elem(void **state)
1091{
David Sedlák32488102019-07-15 17:44:10 +02001092 const char *data;
1093 uint8_t version = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001094 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001095
1096 /* valid values */
Radek Krejci96e48da2020-09-04 13:18:06 +02001097 data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001098 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001099 assert_true(version & LYS_VERSION_1_0);
David Sedlák32488102019-07-15 17:44:10 +02001100
David Sedlákd1144562019-08-06 12:36:14 +02001101 data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001102 assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001103 assert_true(version & LYS_VERSION_1_1);
Radek Krejcifc596f92021-02-26 22:40:26 +01001104 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_YANG_VERSION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001105 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001106
1107 /* invalid value */
1108 data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001109 assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID);
1110 CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. "
1111 "Valid values are \"1\" and \"1.1\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001112}
1113
1114static void
1115test_mandatory_elem(void **state)
1116{
David Sedlák32488102019-07-15 17:44:10 +02001117 const char *data;
1118 uint16_t man = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001119 struct lysp_ext_instance *exts = NULL;
David Sedlák32488102019-07-15 17:44:10 +02001120
1121 /* valid values */
1122 data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001123 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001124 assert_int_equal(man, LYS_MAND_TRUE);
1125 man = 0;
1126
David Sedlákd1144562019-08-06 12:36:14 +02001127 data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001128 assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS);
David Sedlák32488102019-07-15 17:44:10 +02001129 assert_int_equal(man, LYS_MAND_FALSE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001130 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MANDATORY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001131 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák32488102019-07-15 17:44:10 +02001132
1133 data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001134 assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID);
1135 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. "
1136 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák32488102019-07-15 17:44:10 +02001137}
1138
David Sedlák8e7bda82019-07-16 17:57:50 +02001139static void
1140test_argument_elem(void **state)
1141{
David Sedlák8e7bda82019-07-16 17:57:50 +02001142 const char *data;
1143 uint16_t flags = 0;
1144 const char *arg;
1145 struct yin_argument_meta arg_meta = {&flags, &arg};
David Sedlákd1144562019-08-06 12:36:14 +02001146 struct lysp_ext_instance *exts = NULL;
1147
David Sedlák8e7bda82019-07-16 17:57:50 +02001148 /* max subelems */
1149 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001150 "<argument name=\"arg-name\">\n"
1151 " <yin-element value=\"true\" />\n"
1152 EXT_SUBELEM
1153 "</argument>"
1154 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001155 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001156 assert_string_equal(arg, "arg-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001157 assert_true(flags & LYS_YINELEM_TRUE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001158 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ARGUMENT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001159 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001160 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001161 flags = 0;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001162 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001163 arg = NULL;
1164
1165 /* min subelems */
1166 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001167 "<argument name=\"arg\">"
1168 "</argument>"
1169 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001170 assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001171 assert_string_equal(arg, "arg");
1172 assert_true(flags == 0);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001173 lydict_remove(UTEST_LYCTX, arg);
David Sedlák8e7bda82019-07-16 17:57:50 +02001174}
1175
1176static void
1177test_base_elem(void **state)
1178{
David Sedlák8e7bda82019-07-16 17:57:50 +02001179 const char *data;
1180 const char **bases = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001181 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001182 struct lysp_type type = {};
1183
1184 /* as identity subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001185 data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1186 " <base name=\"base-name\">\n"
1187 EXT_SUBELEM
1188 " </base>\n"
1189 "</identity>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001190 assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001191 assert_string_equal(*bases, "base-name");
Radek Krejcifc596f92021-02-26 22:40:26 +01001192 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001193 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001194 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001195 lydict_remove(UTEST_LYCTX, *bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001196 LY_ARRAY_FREE(bases);
1197
1198 /* as type subelement */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001199 data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
1200 " <base name=\"base-name\">\n"
1201 EXT_SUBELEM
1202 " </base>\n"
1203 "</type>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001204 assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001205 assert_string_equal(*type.bases, "base-name");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001206 assert_true(type.flags & LYS_SET_BASE);
Radek Krejcifc596f92021-02-26 22:40:26 +01001207 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001208 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001209 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001210 lydict_remove(UTEST_LYCTX, *type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001211 LY_ARRAY_FREE(type.bases);
David Sedlák8e7bda82019-07-16 17:57:50 +02001212}
1213
1214static void
1215test_belongsto_elem(void **state)
1216{
David Sedlák8e7bda82019-07-16 17:57:50 +02001217 const char *data;
1218 struct lysp_submodule submod;
David Sedlákd1144562019-08-06 12:36:14 +02001219 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001220
Radek Iša56ca9e42020-09-08 18:42:00 +02001221 lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name);
1222
David Sedlák8e7bda82019-07-16 17:57:50 +02001223 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001224 "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
1225 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001226 assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001227 assert_string_equal(submod.prefix, "pref");
Radek Krejcifc596f92021-02-26 22:40:26 +01001228 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_BELONGS_TO);
Radek Iša56ca9e42020-09-08 18:42:00 +02001229 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001230 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001231 lydict_remove(UTEST_LYCTX, submod.prefix);
David Sedlák8e7bda82019-07-16 17:57:50 +02001232
1233 data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001234 assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID);
1235 CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001236}
1237
1238static void
1239test_config_elem(void **state)
1240{
David Sedlák8e7bda82019-07-16 17:57:50 +02001241 const char *data;
1242 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001243 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001244
David Sedlákd1144562019-08-06 12:36:14 +02001245 data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001246 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001247 assert_true(flags & LYS_CONFIG_W);
Radek Krejcifc596f92021-02-26 22:40:26 +01001248 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_CONFIG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001249 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001250 exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001251 flags = 0;
1252
1253 data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001254 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001255 assert_true(flags & LYS_CONFIG_R);
David Sedlák8e7bda82019-07-16 17:57:50 +02001256 flags = 0;
1257
1258 data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001259 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1260 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. "
1261 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001262}
1263
1264static void
1265test_default_elem(void **state)
1266{
David Sedlák8e7bda82019-07-16 17:57:50 +02001267 const char *data;
Michal Vasko7f45cf22020-10-01 12:49:44 +02001268 struct lysp_qname val = {0};
David Sedlákd1144562019-08-06 12:36:14 +02001269 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001270
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001271 data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001272 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001273 assert_string_equal(val.str, "defaul-value");
Radek Krejcifc596f92021-02-26 22:40:26 +01001274 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_DEFAULT);
Radek Iša56ca9e42020-09-08 18:42:00 +02001275 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001276 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001277 lydict_remove(UTEST_LYCTX, val.str);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001278 val.str = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001279
1280 data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001281 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1282 CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001283}
1284
1285static void
1286test_err_app_tag_elem(void **state)
1287{
David Sedlák8e7bda82019-07-16 17:57:50 +02001288 const char *data;
1289 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001290 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001291
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001292 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 +02001293 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001294 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001295 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_APP_TAG);
Radek Iša56ca9e42020-09-08 18:42:00 +02001296 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001297 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001298 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001299 val = NULL;
1300
1301 data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001302 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1303 CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001304}
1305
1306static void
1307test_err_msg_elem(void **state)
1308{
David Sedlák8e7bda82019-07-16 17:57:50 +02001309 const char *data;
1310 const char *val = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001311 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001312
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001313 data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001314 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001315 assert_string_equal(val, "val");
Radek Krejci5984d222021-02-26 23:01:45 +01001316 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ERROR_MESSAGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001317 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001318 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001319 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001320
1321 data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001322 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1323 CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001324
David Sedlákdf2a9732019-08-07 13:23:16 +02001325 data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001326 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
1327 CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001328}
1329
1330static void
1331test_fracdigits_elem(void **state)
1332{
David Sedlák8e7bda82019-07-16 17:57:50 +02001333 const char *data;
1334 struct lysp_type type = {};
1335
1336 /* valid value */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001337 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001338 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
Radek Krejci5984d222021-02-26 23:01:45 +01001339 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_FRACTION_DIGITS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001340 assert_int_equal(type.fraction_digits, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001341 assert_true(type.flags & LYS_SET_FRDIGITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001342 FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001343
1344 /* invalid values */
1345 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001346 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1347 CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001348
1349 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001350 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1351 CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001352
1353 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001354 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1355 CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001356
1357 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001358 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1359 CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001360
1361 data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001362 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1363 CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001364}
1365
1366static void
1367test_iffeature_elem(void **state)
1368{
David Sedlák8e7bda82019-07-16 17:57:50 +02001369 const char *data;
1370 const char **iffeatures = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001371 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001372
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001373 data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001374 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001375 assert_string_equal(*iffeatures, "local-storage");
Radek Krejci5984d222021-02-26 23:01:45 +01001376 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_IF_FEATURE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001377 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001378 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001379 lydict_remove(UTEST_LYCTX, *iffeatures);
David Sedlák8e7bda82019-07-16 17:57:50 +02001380 LY_ARRAY_FREE(iffeatures);
1381 iffeatures = NULL;
1382
1383 data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001384 assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID);
1385 CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001386 LY_ARRAY_FREE(iffeatures);
1387 iffeatures = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001388}
1389
1390static void
1391test_length_elem(void **state)
1392{
David Sedlák8e7bda82019-07-16 17:57:50 +02001393 const char *data;
1394 struct lysp_type type = {};
1395
1396 /* max subelems */
1397 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001398 "<length value=\"length-str\">\n"
1399 " <error-message><value>err-msg</value></error-message>\n"
1400 " <error-app-tag value=\"err-app-tag\"/>\n"
1401 " <description><text>desc</text></description>\n"
1402 " <reference><text>ref</text></reference>\n"
1403 EXT_SUBELEM
1404 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001405 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001406 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1407 CHECK_LYSP_RESTR(type.length, "length-str", "desc",
1408 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001409 assert_true(type.flags & LYS_SET_LENGTH);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001410 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LY_STMT_LENGTH);
Radek Iša56ca9e42020-09-08 18:42:00 +02001411 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001412 memset(&type, 0, sizeof(type));
1413
1414 /* min subelems */
1415 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001416 "<length value=\"length-str\">"
1417 "</length>"
David Sedlák8e7bda82019-07-16 17:57:50 +02001418 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001419 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1420 CHECK_LYSP_RESTR(type.length, "length-str", NULL,
1421 NULL, NULL, 0, NULL);
1422 lysp_type_free(UTEST_LYCTX, &type);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001423 assert_true(type.flags & LYS_SET_LENGTH);
David Sedlák8e7bda82019-07-16 17:57:50 +02001424 memset(&type, 0, sizeof(type));
1425
1426 data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001427 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
1428 CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
1429 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001430 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001431}
1432
1433static void
1434test_modifier_elem(void **state)
1435{
David Sedlák8e7bda82019-07-16 17:57:50 +02001436 const char *data;
Radek Krejci011e4aa2020-09-04 15:22:31 +02001437 const char *pat;
David Sedlákd1144562019-08-06 12:36:14 +02001438 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001439
Radek Iša56ca9e42020-09-08 18:42:00 +02001440 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlákd1144562019-08-06 12:36:14 +02001441 data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001442 assert_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001443 assert_string_equal(pat, "\x015pattern");
Radek Krejci5984d222021-02-26 23:01:45 +01001444 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_MODIFIER);
Radek Iša56ca9e42020-09-08 18:42:00 +02001445 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001446 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001447 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001448
Radek Iša56ca9e42020-09-08 18:42:00 +02001449 assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
David Sedlák8e7bda82019-07-16 17:57:50 +02001450 data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001451 assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID);
1452 CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. "
1453 "Only valid value is \"invert-match\".", "Line number 1.");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001454 lydict_remove(UTEST_LYCTX, pat);
David Sedlák8e7bda82019-07-16 17:57:50 +02001455}
1456
1457static void
1458test_namespace_elem(void **state)
1459{
David Sedlák8e7bda82019-07-16 17:57:50 +02001460 const char *data;
1461 const char *ns;
David Sedlákd1144562019-08-06 12:36:14 +02001462 struct lysp_ext_instance *exts = NULL;
David Sedlák8e7bda82019-07-16 17:57:50 +02001463
David Sedlákd1144562019-08-06 12:36:14 +02001464 data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001465 assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS);
David Sedlák8e7bda82019-07-16 17:57:50 +02001466 assert_string_equal(ns, "ns");
Radek Krejci5984d222021-02-26 23:01:45 +01001467 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_NAMESPACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001468 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001469 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001470 lydict_remove(UTEST_LYCTX, ns);
David Sedlák8e7bda82019-07-16 17:57:50 +02001471
1472 data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001473 assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID);
1474 CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001475}
1476
1477static void
David Sedlák8e7bda82019-07-16 17:57:50 +02001478test_pattern_elem(void **state)
1479{
David Sedlák8e7bda82019-07-16 17:57:50 +02001480 const char *data;
1481 struct lysp_type type = {};
1482
1483 /* max subelems */
1484 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001485 "<pattern value=\"super_pattern\">\n"
1486 " <modifier value=\"invert-match\"/>\n"
1487 " <error-message><value>err-msg-value</value></error-message>\n"
1488 " <error-app-tag value=\"err-app-tag-value\"/>\n"
1489 " <description><text>&quot;pattern-desc&quot;</text></description>\n"
1490 " <reference><text>pattern-ref</text></reference>\n"
1491 EXT_SUBELEM
1492 "</pattern>"
1493 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001494 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001495 assert_true(type.flags & LYS_SET_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001496 CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
1497 "err-app-tag-value", "err-msg-value", 1, "pattern-ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001498 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LY_STMT_PATTERN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001499 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001500 memset(&type, 0, sizeof(type));
1501
1502 /* min subelems */
1503 data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001504 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1505 CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
1506 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák8e7bda82019-07-16 17:57:50 +02001507 memset(&type, 0, sizeof(type));
David Sedlák8e7bda82019-07-16 17:57:50 +02001508}
1509
1510static void
1511test_value_position_elem(void **state)
1512{
David Sedlák8e7bda82019-07-16 17:57:50 +02001513 const char *data;
1514 struct lysp_type_enum en = {};
1515
1516 /* valid values */
David Sedlákd1144562019-08-06 12:36:14 +02001517 data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001518 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1519 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001520 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_VALUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001521 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001522 memset(&en, 0, sizeof(en));
1523
1524 data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001525 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1526 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55);
David Sedlák8e7bda82019-07-16 17:57:50 +02001527 memset(&en, 0, sizeof(en));
1528
1529 data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001530 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1531 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001532 memset(&en, 0, sizeof(en));
1533
1534 data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001535 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1536 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001537 memset(&en, 0, sizeof(en));
1538
1539 /* valid positions */
David Sedlák8d552d62019-08-06 15:29:05 +02001540 data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001541 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1542 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
Radek Krejci5984d222021-02-26 23:01:45 +01001543 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LY_STMT_POSITION);
Radek Iša56ca9e42020-09-08 18:42:00 +02001544 FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
David Sedlák8e7bda82019-07-16 17:57:50 +02001545 memset(&en, 0, sizeof(en));
1546
1547 data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001548 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
1549 CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
David Sedlák8e7bda82019-07-16 17:57:50 +02001550 memset(&en, 0, sizeof(en));
1551
1552 /* invalid values */
1553 data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001554 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1555 CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001556
1557 data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001558 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1559 CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001560
David Sedlák69f01612019-07-17 11:41:08 +02001561 data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001562 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1563 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001564
David Sedlák8e7bda82019-07-16 17:57:50 +02001565 /*invalid positions */
1566 data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001567 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1568 CHECK_LOG_CTX("Invalid value \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001569
1570 data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001571 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1572 CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001573
1574 data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001575 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1576 CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák8e7bda82019-07-16 17:57:50 +02001577
David Sedlák69f01612019-07-17 11:41:08 +02001578 data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001579 assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
1580 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001581}
1582
1583static void
1584test_prefix_elem(void **state)
1585{
David Sedlák69f01612019-07-17 11:41:08 +02001586 const char *data;
1587 const char *value = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001588 struct lysp_ext_instance *exts = NULL;
1589
1590 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001591 assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001592 assert_string_equal(value, "pref");
Radek Krejci5984d222021-02-26 23:01:45 +01001593 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PREFIX);
Radek Iša56ca9e42020-09-08 18:42:00 +02001594 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlákd1144562019-08-06 12:36:14 +02001595 exts = NULL;
Michal Vaskoe180ed02021-02-05 16:31:20 +01001596 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001597
1598 data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001599 assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001600 assert_string_equal(value, "pref");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001601 lydict_remove(UTEST_LYCTX, value);
David Sedlák69f01612019-07-17 11:41:08 +02001602}
1603
1604static void
1605test_range_elem(void **state)
1606{
David Sedlák69f01612019-07-17 11:41:08 +02001607 const char *data;
1608 struct lysp_type type = {};
1609
1610 /* max subelems */
1611 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001612 "<range value=\"range-str\">\n"
1613 " <error-message><value>err-msg</value></error-message>\n"
1614 " <error-app-tag value=\"err-app-tag\" />\n"
1615 " <description><text>desc</text></description>\n"
1616 " <reference><text>ref</text></reference>\n"
1617 EXT_SUBELEM
1618 "</range>"
1619 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001620 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1621 CHECK_LYSP_RESTR(type.range, "range-str", "desc",
1622 "err-app-tag", "err-msg", 1, "ref");
David Sedlákc3da3ef2019-07-19 12:56:08 +02001623 assert_true(type.flags & LYS_SET_RANGE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001624 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LY_STMT_RANGE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001625 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001626 memset(&type, 0, sizeof(type));
1627
1628 /* min subelems */
1629 data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001630 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1631 CHECK_LYSP_RESTR(type.range, "range-str", NULL,
1632 NULL, NULL, 0, NULL);
1633 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001634 memset(&type, 0, sizeof(type));
David Sedlák69f01612019-07-17 11:41:08 +02001635}
1636
1637static void
1638test_reqinstance_elem(void **state)
1639{
David Sedlák69f01612019-07-17 11:41:08 +02001640 const char *data;
1641 struct lysp_type type = {};
1642
David Sedlákd1144562019-08-06 12:36:14 +02001643 data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001644 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001645 assert_int_equal(type.require_instance, 1);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001646 assert_true(type.flags & LYS_SET_REQINST);
Radek Krejci5984d222021-02-26 23:01:45 +01001647 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_REQUIRE_INSTANCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001648 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák69f01612019-07-17 11:41:08 +02001649 memset(&type, 0, sizeof(type));
1650
1651 data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001652 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001653 assert_int_equal(type.require_instance, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001654 assert_true(type.flags & LYS_SET_REQINST);
David Sedlák69f01612019-07-17 11:41:08 +02001655 memset(&type, 0, sizeof(type));
1656
1657 data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001658 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
David Sedlák69f01612019-07-17 11:41:08 +02001659 memset(&type, 0, sizeof(type));
Radek Iša56ca9e42020-09-08 18:42:00 +02001660 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. "
1661 "Valid values are \"true\" and \"false\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001662}
1663
1664static void
1665test_revision_date_elem(void **state)
1666{
David Sedlák69f01612019-07-17 11:41:08 +02001667 const char *data;
1668 char rev[LY_REV_SIZE];
David Sedlákd1144562019-08-06 12:36:14 +02001669 struct lysp_ext_instance *exts = NULL;
1670
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001671 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 +02001672 assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001673 assert_string_equal(rev, "2000-01-01");
Radek Krejci5984d222021-02-26 23:01:45 +01001674 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_REVISION_DATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001675 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedlák69f01612019-07-17 11:41:08 +02001676
1677 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001678 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001679 assert_string_equal(rev, "2000-01-01");
1680
1681 data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001682 assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID);
1683 CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1.");
David Sedlák69f01612019-07-17 11:41:08 +02001684}
1685
1686static void
1687test_unique_elem(void **state)
1688{
David Sedlák69f01612019-07-17 11:41:08 +02001689 const char *data;
1690 const char **values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001691 struct lysp_ext_instance *exts = NULL;
1692
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001693 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001694 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001695 assert_string_equal(*values, "tag");
Radek Krejci5984d222021-02-26 23:01:45 +01001696 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNIQUE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001697 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001698 lydict_remove(UTEST_LYCTX, *values);
David Sedlákd1144562019-08-06 12:36:14 +02001699 LY_ARRAY_FREE(values);
1700 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001701
1702 data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001703 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001704 assert_string_equal(*values, "tag");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001705 lydict_remove(UTEST_LYCTX, *values);
David Sedlák69f01612019-07-17 11:41:08 +02001706 LY_ARRAY_FREE(values);
David Sedlákd1144562019-08-06 12:36:14 +02001707 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001708}
1709
1710static void
1711test_units_elem(void **state)
1712{
David Sedlák69f01612019-07-17 11:41:08 +02001713 const char *data;
1714 const char *values = NULL;
David Sedlákd1144562019-08-06 12:36:14 +02001715 struct lysp_ext_instance *exts = NULL;
1716
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001717 data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001718 assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02001719 assert_string_equal(values, "name");
Radek Krejci5984d222021-02-26 23:01:45 +01001720 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_UNITS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001721 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001722 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001723 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001724
1725 data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001726 assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001727 assert_string_equal(values, "name");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001728 lydict_remove(UTEST_LYCTX, values);
David Sedlákd1144562019-08-06 12:36:14 +02001729 values = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001730}
1731
1732static void
1733test_when_elem(void **state)
1734{
David Sedlák69f01612019-07-17 11:41:08 +02001735 const char *data;
1736 struct lysp_when *when = NULL;
1737
1738 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001739 "<when condition=\"cond\">\n"
1740 " <description><text>desc</text></description>\n"
1741 " <reference><text>ref</text></reference>\n"
1742 EXT_SUBELEM
1743 "</when>"
1744 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001745 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1746 CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001747 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]), LY_STMT_WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +02001748 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001749 free(when);
1750 when = NULL;
1751
1752 data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001753 assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
1754 CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL);
1755 lysp_when_free(UTEST_LYCTX, when);
David Sedlák69f01612019-07-17 11:41:08 +02001756 free(when);
1757 when = NULL;
David Sedlák69f01612019-07-17 11:41:08 +02001758}
1759
1760static void
1761test_yin_text_value_elem(void **state)
1762{
David Sedlák69f01612019-07-17 11:41:08 +02001763 const char *data;
1764 const char *val;
1765
1766 data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001767 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001768 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001769 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001770
1771 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 +02001772 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001773 assert_string_equal(val, "text");
Michal Vaskoe180ed02021-02-05 16:31:20 +01001774 lydict_remove(UTEST_LYCTX, val);
David Sedlák69f01612019-07-17 11:41:08 +02001775
1776 data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001777 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák69f01612019-07-17 11:41:08 +02001778 assert_string_equal("", val);
Michal Vaskoe180ed02021-02-05 16:31:20 +01001779 lydict_remove(UTEST_LYCTX, val);
David Sedlák8e7bda82019-07-16 17:57:50 +02001780}
David Sedlák32488102019-07-15 17:44:10 +02001781
David Sedlák374d2b32019-07-17 15:06:55 +02001782static void
1783test_type_elem(void **state)
1784{
David Sedlák374d2b32019-07-17 15:06:55 +02001785 const char *data;
1786 struct lysp_type type = {};
1787
1788 /* max subelems */
1789 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001790 "<type name=\"type-name\">\n"
1791 " <base name=\"base-name\"/>\n"
1792 " <bit name=\"bit\"/>\n"
1793 " <enum name=\"enum\"/>\n"
1794 " <fraction-digits value=\"2\"/>\n"
1795 " <length value=\"length\"/>\n"
1796 " <path value=\"/path\"/>\n"
1797 " <pattern value=\"pattern\"/>\n"
1798 " <range value=\"range\" />\n"
1799 " <require-instance value=\"true\"/>\n"
1800 " <type name=\"sub-type-name\"/>\n"
1801 EXT_SUBELEM
1802 "</type>"
1803 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001804 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
David Sedlák374d2b32019-07-17 15:06:55 +02001805 assert_string_equal(type.name, "type-name");
1806 assert_string_equal(*type.bases, "base-name");
1807 assert_string_equal(type.bits->name, "bit");
1808 assert_string_equal(type.enums->name, "enum");
1809 assert_int_equal(type.fraction_digits, 2);
Radek Iša56ca9e42020-09-08 18:42:00 +02001810 CHECK_LYSP_RESTR(type.length, "length", NULL,
1811 NULL, NULL, 0, NULL);
Michal Vaskocb8c6d42020-10-16 11:58:30 +02001812 assert_string_equal(type.path->expr, "/path");
Radek Iša56ca9e42020-09-08 18:42:00 +02001813 CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL,
1814 NULL, NULL, 0, NULL);
1815 CHECK_LYSP_RESTR(type.range, "range", NULL,
1816 NULL, NULL, 0, NULL);
David Sedlák374d2b32019-07-17 15:06:55 +02001817 assert_int_equal(type.require_instance, 1);
1818 assert_string_equal(type.types->name, "sub-type-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001819 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_TYPE);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001820 assert_true(type.flags & LYS_SET_BASE);
1821 assert_true(type.flags & LYS_SET_BIT);
1822 assert_true(type.flags & LYS_SET_ENUM);
1823 assert_true(type.flags & LYS_SET_FRDIGITS);
1824 assert_true(type.flags & LYS_SET_LENGTH);
1825 assert_true(type.flags & LYS_SET_PATH);
1826 assert_true(type.flags & LYS_SET_PATTERN);
1827 assert_true(type.flags & LYS_SET_RANGE);
1828 assert_true(type.flags & LYS_SET_REQINST);
1829 assert_true(type.flags & LYS_SET_TYPE);
Radek Iša56ca9e42020-09-08 18:42:00 +02001830 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001831 memset(&type, 0, sizeof(type));
1832
1833 /* min subelems */
1834 data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001835 assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
1836 lysp_type_free(UTEST_LYCTX, &type);
David Sedlák374d2b32019-07-17 15:06:55 +02001837 memset(&type, 0, sizeof(type));
David Sedlák374d2b32019-07-17 15:06:55 +02001838}
1839
David Sedlák1af868e2019-07-17 17:03:14 +02001840static void
1841test_max_elems_elem(void **state)
1842{
David Sedlák1af868e2019-07-17 17:03:14 +02001843 const char *data;
1844 struct lysp_node_list list = {};
1845 struct lysp_node_leaflist llist = {};
1846 struct lysp_refine refine = {};
1847
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001848 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 +02001849 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001850 assert_int_equal(refine.max, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001851 assert_true(refine.flags & LYS_SET_MAX);
Radek Krejci5984d222021-02-26 23:01:45 +01001852 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001853 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001854
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001855 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 +02001856 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001857 assert_int_equal(list.max, 5);
Radek Iša56ca9e42020-09-08 18:42:00 +02001858 CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001859 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001860 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001861
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001862 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 +02001863 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001864 assert_int_equal(llist.max, 85);
Radek Iša56ca9e42020-09-08 18:42:00 +02001865 CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
Radek Krejci5984d222021-02-26 23:01:45 +01001866 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MAX_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001867 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák1af868e2019-07-17 17:03:14 +02001868
1869 data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001870 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák1af868e2019-07-17 17:03:14 +02001871 assert_int_equal(refine.max, 10);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001872 assert_true(refine.flags & LYS_SET_MAX);
David Sedlák1af868e2019-07-17 17:03:14 +02001873
1874 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001875 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1876 CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001877
1878 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001879 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1880 CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001881
1882 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001883 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1884 CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001885
1886 data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
Radek Iša56ca9e42020-09-08 18:42:00 +02001887 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
1888 CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
David Sedlák1af868e2019-07-17 17:03:14 +02001889}
1890
David Sedlák09e18c92019-07-18 11:17:11 +02001891static void
1892test_min_elems_elem(void **state)
1893{
David Sedlák09e18c92019-07-18 11:17:11 +02001894 const char *data;
1895 struct lysp_node_list list = {};
1896 struct lysp_node_leaflist llist = {};
1897 struct lysp_refine refine = {};
1898
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001899 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 +02001900 assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001901 assert_int_equal(refine.min, 0);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001902 assert_true(refine.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001903 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001904 FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001905
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001906 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 +02001907 assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001908 assert_int_equal(list.min, 41);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001909 assert_true(list.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001910 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001911 FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001912
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001913 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 +02001914 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
David Sedlák09e18c92019-07-18 11:17:11 +02001915 assert_int_equal(llist.min, 50);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001916 assert_true(llist.flags & LYS_SET_MIN);
Radek Krejci5984d222021-02-26 23:01:45 +01001917 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LY_STMT_MIN_ELEMENTS);
Radek Iša56ca9e42020-09-08 18:42:00 +02001918 FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
David Sedlák09e18c92019-07-18 11:17:11 +02001919
1920 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 +02001921 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1922 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 +02001923
1924 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 +02001925 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1926 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 +02001927
1928 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 +02001929 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1930 CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001931
1932 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 +02001933 assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
1934 CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
David Sedlák09e18c92019-07-18 11:17:11 +02001935}
1936
David Sedláka2dad212019-07-18 12:45:19 +02001937static void
1938test_ordby_elem(void **state)
1939{
David Sedláka2dad212019-07-18 12:45:19 +02001940 const char *data;
1941 uint16_t flags = 0;
David Sedlákd1144562019-08-06 12:36:14 +02001942 struct lysp_ext_instance *exts = NULL;
David Sedláka2dad212019-07-18 12:45:19 +02001943
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001944 data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001945 assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001946 assert_true(flags & LYS_ORDBY_SYSTEM);
Radek Krejci5984d222021-02-26 23:01:45 +01001947 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_ORDERED_BY);
Radek Iša56ca9e42020-09-08 18:42:00 +02001948 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
David Sedláka2dad212019-07-18 12:45:19 +02001949
1950 data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001951 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02001952 assert_true(flags & LYS_ORDBY_USER);
David Sedláka2dad212019-07-18 12:45:19 +02001953
1954 data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001955 assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
1956 CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. "
1957 "Valid values are \"system\" and \"user\".", "Line number 1.");
David Sedláka2dad212019-07-18 12:45:19 +02001958}
1959
David Sedlák8a83bbb2019-07-18 14:46:00 +02001960static void
1961test_any_elem(void **state)
1962{
David Sedlák8a83bbb2019-07-18 14:46:00 +02001963 const char *data;
1964 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02001965 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák8a83bbb2019-07-18 14:46:00 +02001966 struct lysp_node_anydata *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02001967 uint16_t flags;
David Sedlák8a83bbb2019-07-18 14:46:00 +02001968
1969 /* anyxml max subelems */
1970 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001971 "<anyxml name=\"any-name\">\n"
1972 " <config value=\"true\" />\n"
1973 " <description><text>desc</text></description>\n"
1974 " <if-feature name=\"feature\" />\n"
1975 " <mandatory value=\"true\" />\n"
1976 " <must condition=\"must-cond\" />\n"
1977 " <reference><text>ref</text></reference>\n"
1978 " <status value=\"deprecated\"/>\n"
1979 " <when condition=\"when-cond\"/>\n"
1980 EXT_SUBELEM
1981 "</anyxml>"
1982 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02001983 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001984 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02001985 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
1986 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
1987 "any-name", 0, LYS_ANYXML, 0, "ref", 1);
1988 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001989 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01001990 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYXML);
Radek Iša56ca9e42020-09-08 18:42:00 +02001991 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02001992 siblings = NULL;
1993
1994 /* anydata max subelems */
1995 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01001996 "<anydata name=\"any-name\">\n"
1997 " <config value=\"true\" />\n"
1998 " <description><text>desc</text></description>\n"
1999 " <if-feature name=\"feature\" />\n"
2000 " <mandatory value=\"true\" />\n"
2001 " <must condition=\"must-cond\" />\n"
2002 " <reference><text>ref</text></reference>\n"
2003 " <status value=\"deprecated\"/>\n"
2004 " <when condition=\"when-cond\"/>\n"
2005 EXT_SUBELEM
2006 "</anydata>"
2007 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002008 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002009 parsed = (struct lysp_node_anydata *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002010 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2011 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2012 "any-name", 0, LYS_ANYDATA, 0, "ref", 1);
2013 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002014 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002015 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYDATA);
Radek Iša56ca9e42020-09-08 18:42:00 +02002016 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002017 siblings = NULL;
2018
2019 /* min subelems */
2020 node_meta.parent = (void *)0x10;
2021 data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002022 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002023 parsed = (struct lysp_node_anydata *)siblings;
2024 assert_ptr_equal(parsed->parent, node_meta.parent);
Radek Iša56ca9e42020-09-08 18:42:00 +02002025 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2026 "any-name", 0, LYS_ANYDATA, 1, NULL, 0);
2027 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák8a83bbb2019-07-18 14:46:00 +02002028}
2029
David Sedlák203ca3a2019-07-18 15:26:25 +02002030static void
2031test_leaf_elem(void **state)
2032{
David Sedlák203ca3a2019-07-18 15:26:25 +02002033 const char *data;
2034 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002035 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlák203ca3a2019-07-18 15:26:25 +02002036 struct lysp_node_leaf *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002037 uint16_t flags;
David Sedlák203ca3a2019-07-18 15:26:25 +02002038
2039 /* max elements */
2040 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002041 "<leaf name=\"leaf\">\n"
2042 " <config value=\"true\" />\n"
2043 " <default value=\"def-val\"/>\n"
2044 " <description><text>desc</text></description>\n"
2045 " <if-feature name=\"feature\" />\n"
2046 " <mandatory value=\"true\" />\n"
2047 " <must condition=\"must-cond\" />\n"
2048 " <reference><text>ref</text></reference>\n"
2049 " <status value=\"deprecated\"/>\n"
2050 " <type name=\"type\"/>\n"
2051 " <units name=\"uni\"/>\n"
2052 " <when condition=\"when-cond\"/>\n"
2053 EXT_SUBELEM
2054 "</leaf>"
David Sedlák203ca3a2019-07-18 15:26:25 +02002055 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002056 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002057 parsed = (struct lysp_node_leaf *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002058 flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
2059 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2060 "leaf", 0, LYS_LEAF, 0, "ref", 1);
2061 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002062 assert_string_equal(parsed->iffeatures[0].str, "feature");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002063 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002064 assert_string_equal(parsed->musts->arg.str, "must-cond");
David Sedlák203ca3a2019-07-18 15:26:25 +02002065 assert_string_equal(parsed->type.name, "type");
2066 assert_string_equal(parsed->units, "uni");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002067 assert_string_equal(parsed->dflt.str, "def-val");
Radek Iša56ca9e42020-09-08 18:42:00 +02002068 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002069 siblings = NULL;
2070
2071 /* min elements */
2072 data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002073 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák203ca3a2019-07-18 15:26:25 +02002074 parsed = (struct lysp_node_leaf *)siblings;
2075 assert_string_equal(parsed->name, "leaf");
2076 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002077 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák203ca3a2019-07-18 15:26:25 +02002078 siblings = NULL;
David Sedlák203ca3a2019-07-18 15:26:25 +02002079}
2080
David Sedlákc3da3ef2019-07-19 12:56:08 +02002081static void
2082test_leaf_list_elem(void **state)
2083{
David Sedlákc3da3ef2019-07-19 12:56:08 +02002084 const char *data;
2085 struct lysp_node *siblings = NULL;
David Sedlákbf8a2b72019-08-14 16:48:10 +02002086 struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
David Sedlákc3da3ef2019-07-19 12:56:08 +02002087 struct lysp_node_leaflist *parsed = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02002088 uint16_t flags;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002089
2090 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002091 "<leaf-list name=\"llist\">\n"
2092 " <config value=\"true\" />\n"
2093 " <default value=\"def-val0\"/>\n"
2094 " <default value=\"def-val1\"/>\n"
2095 " <description><text>desc</text></description>\n"
2096 " <if-feature name=\"feature\"/>\n"
2097 " <max-elements value=\"5\"/>\n"
2098 " <must condition=\"must-cond\"/>\n"
2099 " <ordered-by value=\"user\" />\n"
2100 " <reference><text>ref</text></reference>\n"
2101 " <status value=\"current\"/>\n"
2102 " <type name=\"type\"/>\n"
2103 " <units name=\"uni\"/>\n"
2104 " <when condition=\"when-cond\"/>\n"
2105 EXT_SUBELEM
2106 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002107 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002108 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002109 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002110 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX;
2111 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2112 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2113 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002114 assert_string_equal(parsed->dflts[0].str, "def-val0");
2115 assert_string_equal(parsed->dflts[1].str, "def-val1");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002116 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002117 assert_int_equal(parsed->max, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002118 assert_string_equal(parsed->type.name, "type");
2119 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002120 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002121 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002122 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002123 siblings = NULL;
2124
2125 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002126 "<leaf-list name=\"llist\">\n"
2127 " <config value=\"true\" />\n"
2128 " <description><text>desc</text></description>\n"
2129 " <if-feature name=\"feature\"/>\n"
2130 " <min-elements value=\"5\"/>\n"
2131 " <must condition=\"must-cond\"/>\n"
2132 " <ordered-by value=\"user\" />\n"
2133 " <reference><text>ref</text></reference>\n"
2134 " <status value=\"current\"/>\n"
2135 " <type name=\"type\"/>\n"
2136 " <units name=\"uni\"/>\n"
2137 " <when condition=\"when-cond\"/>\n"
2138 EXT_SUBELEM
2139 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002140 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002141 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002142 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002143 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN;
2144 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2145 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2146 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2147 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002148 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002149 assert_int_equal(parsed->min, 5);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002150 assert_string_equal(parsed->type.name, "type");
2151 assert_string_equal(parsed->units, "uni");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002152 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002153 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002154 siblings = NULL;
2155
2156 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002157 "<leaf-list name=\"llist\">\n"
2158 " <config value=\"true\" />\n"
2159 " <description><text>desc</text></description>\n"
2160 " <if-feature name=\"feature\"/>\n"
2161 " <max-elements value=\"15\"/>\n"
2162 " <min-elements value=\"5\"/>\n"
2163 " <must condition=\"must-cond\"/>\n"
2164 " <ordered-by value=\"user\" />\n"
2165 " <reference><text>ref</text></reference>\n"
2166 " <status value=\"current\"/>\n"
2167 " <type name=\"type\"/>\n"
2168 " <units name=\"uni\"/>\n"
2169 " <when condition=\"when-cond\"/>\n"
2170 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002171 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002172 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002173 parsed = (struct lysp_node_leaflist *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002174 flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX;
2175 CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1,
2176 "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
2177 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2178 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002179 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlákc3da3ef2019-07-19 12:56:08 +02002180 assert_int_equal(parsed->min, 5);
2181 assert_int_equal(parsed->max, 15);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002182 assert_string_equal(parsed->type.name, "type");
2183 assert_string_equal(parsed->units, "uni");
Radek Iša56ca9e42020-09-08 18:42:00 +02002184 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002185 siblings = NULL;
2186
2187 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002188 "<leaf-list name=\"llist\">\n"
2189 " <type name=\"type\"/>\n"
2190 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002191 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002192 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002193 parsed = (struct lysp_node_leaflist *)siblings;
2194 assert_string_equal(parsed->name, "llist");
2195 assert_string_equal(parsed->type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002196 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002197 siblings = NULL;
2198
2199 /* invalid combinations */
2200 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002201 "<leaf-list name=\"llist\">\n"
2202 " <max-elements value=\"5\"/>\n"
2203 " <min-elements value=\"15\"/>\n"
2204 " <type name=\"type\"/>"
2205 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002206 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002207 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2208 CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
2209 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002210 siblings = NULL;
2211
2212 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002213 "<leaf-list name=\"llist\">\n"
2214 " <default value=\"def-val1\"/>\n"
2215 " <min-elements value=\"15\"/>\n"
2216 " <type name=\"type\"/>\n"
2217 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002218 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002219 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2220 CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
2221 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002222 siblings = NULL;
2223
2224 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002225 "<leaf-list name=\"llist\">"
2226 "</leaf-list>"
David Sedlákc3da3ef2019-07-19 12:56:08 +02002227 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002228 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
2229 CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
2230 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákc3da3ef2019-07-19 12:56:08 +02002231 siblings = NULL;
David Sedlákc3da3ef2019-07-19 12:56:08 +02002232}
2233
David Sedlákcb39f642019-07-19 13:19:55 +02002234static void
2235test_presence_elem(void **state)
2236{
David Sedlákcb39f642019-07-19 13:19:55 +02002237 const char *data;
2238 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002239 struct lysp_ext_instance *exts = NULL;
2240
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002241 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002242 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002243 assert_string_equal(val, "presence-val");
Radek Krejci5984d222021-02-26 23:01:45 +01002244 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_PRESENCE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002245 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002246 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002247
2248 data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002249 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlákcb39f642019-07-19 13:19:55 +02002250 assert_string_equal(val, "presence-val");
Michal Vaskoe180ed02021-02-05 16:31:20 +01002251 lydict_remove(UTEST_LYCTX, val);
David Sedlákcb39f642019-07-19 13:19:55 +02002252
2253 data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002254 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2255 CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1.");
David Sedlákcb39f642019-07-19 13:19:55 +02002256}
2257
David Sedlák12470a82019-07-19 13:44:36 +02002258static void
2259test_key_elem(void **state)
2260{
David Sedlák12470a82019-07-19 13:44:36 +02002261 const char *data;
2262 const char *val;
David Sedlákd1144562019-08-06 12:36:14 +02002263 struct lysp_ext_instance *exts = NULL;
2264
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002265 data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002266 assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
David Sedlákd1144562019-08-06 12:36:14 +02002267 assert_string_equal(val, "key-value");
Radek Krejci5984d222021-02-26 23:01:45 +01002268 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LY_STMT_KEY);
Radek Iša56ca9e42020-09-08 18:42:00 +02002269 FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
Michal Vaskoe180ed02021-02-05 16:31:20 +01002270 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002271
2272 data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002273 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
David Sedlák12470a82019-07-19 13:44:36 +02002274 assert_string_equal(val, "key-value");
Michal Vaskoe180ed02021-02-05 16:31:20 +01002275 lydict_remove(UTEST_LYCTX, val);
David Sedlák12470a82019-07-19 13:44:36 +02002276
2277 data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002278 assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
2279 CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1.");
David Sedlák12470a82019-07-19 13:44:36 +02002280}
2281
David Sedlák04e17b22019-07-19 15:29:48 +02002282static void
2283test_typedef_elem(void **state)
2284{
David Sedlák04e17b22019-07-19 15:29:48 +02002285 const char *data;
2286 struct lysp_tpdf *tpdfs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002287 struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
David Sedlák04e17b22019-07-19 15:29:48 +02002288
2289 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002290 "<typedef name=\"tpdf-name\">\n"
2291 " <default value=\"def-val\"/>\n"
2292 " <description><text>desc-text</text></description>\n"
2293 " <reference><text>ref-text</text></reference>\n"
2294 " <status value=\"current\"/>\n"
2295 " <type name=\"type\"/>\n"
2296 " <units name=\"uni\"/>\n"
2297 EXT_SUBELEM
2298 "</typedef>"
2299 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002300 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002301 assert_string_equal(tpdfs[0].dflt.str, "def-val");
David Sedlák04e17b22019-07-19 15:29:48 +02002302 assert_string_equal(tpdfs[0].dsc, "desc-text");
David Sedlák04e17b22019-07-19 15:29:48 +02002303 assert_string_equal(tpdfs[0].name, "tpdf-name");
2304 assert_string_equal(tpdfs[0].ref, "ref-text");
2305 assert_string_equal(tpdfs[0].type.name, "type");
2306 assert_string_equal(tpdfs[0].units, "uni");
2307 assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002308 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]), LY_STMT_TYPEDEF);
Radek Iša56ca9e42020-09-08 18:42:00 +02002309 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002310 tpdfs = NULL;
2311
2312 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002313 "<typedef name=\"tpdf-name\">\n"
2314 " <type name=\"type\"/>\n"
2315 "</typedef>"
2316 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002317 assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
David Sedlák04e17b22019-07-19 15:29:48 +02002318 assert_string_equal(tpdfs[0].name, "tpdf-name");
2319 assert_string_equal(tpdfs[0].type.name, "type");
Radek Iša56ca9e42020-09-08 18:42:00 +02002320 FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
David Sedlák04e17b22019-07-19 15:29:48 +02002321 tpdfs = NULL;
David Sedlák04e17b22019-07-19 15:29:48 +02002322}
2323
David Sedlákd2d676a2019-07-22 11:28:19 +02002324static void
2325test_refine_elem(void **state)
2326{
David Sedlákd2d676a2019-07-22 11:28:19 +02002327 const char *data;
2328 struct lysp_refine *refines = NULL;
2329
2330 /* max subelems */
2331 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002332 "<refine target-node=\"target\">\n"
2333 " <if-feature name=\"feature\" />\n"
2334 " <must condition=\"cond\" />\n"
2335 " <presence value=\"presence\" />\n"
2336 " <default value=\"def\" />\n"
2337 " <config value=\"true\" />\n"
2338 " <mandatory value=\"true\" />\n"
2339 " <min-elements value=\"10\" />\n"
2340 " <max-elements value=\"20\" />\n"
2341 " <description><text>desc</text></description>\n"
2342 " <reference><text>ref</text></reference>\n"
2343 EXT_SUBELEM
2344 "</refine>"
2345 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002346 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002347 assert_string_equal(refines->nodeid, "target");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002348 assert_string_equal(refines->dflts[0].str, "def");
David Sedlákd2d676a2019-07-22 11:28:19 +02002349 assert_string_equal(refines->dsc, "desc");
David Sedlákd2d676a2019-07-22 11:28:19 +02002350 assert_true(refines->flags & LYS_CONFIG_W);
2351 assert_true(refines->flags & LYS_MAND_TRUE);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002352 assert_string_equal(refines->iffeatures[0].str, "feature");
David Sedlákd2d676a2019-07-22 11:28:19 +02002353 assert_int_equal(refines->max, 20);
2354 assert_int_equal(refines->min, 10);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002355 assert_string_equal(refines->musts->arg.str, "cond");
David Sedlákd2d676a2019-07-22 11:28:19 +02002356 assert_string_equal(refines->presence, "presence");
2357 assert_string_equal(refines->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002358 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]), LY_STMT_REFINE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002359 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002360 refines = NULL;
2361
2362 /* min subelems */
2363 data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002364 assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
David Sedlákd2d676a2019-07-22 11:28:19 +02002365 assert_string_equal(refines->nodeid, "target");
Radek Iša56ca9e42020-09-08 18:42:00 +02002366 FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
David Sedlákd2d676a2019-07-22 11:28:19 +02002367 refines = NULL;
David Sedlákd2d676a2019-07-22 11:28:19 +02002368}
2369
David Sedlák0d6de5a2019-07-22 13:25:44 +02002370static void
2371test_uses_elem(void **state)
2372{
David Sedlák0d6de5a2019-07-22 13:25:44 +02002373 const char *data;
2374 struct lysp_node *siblings = NULL;
2375 struct tree_node_meta node_meta = {NULL, &siblings};
2376 struct lysp_node_uses *parsed = NULL;
2377
2378 /* max subelems */
2379 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002380 "<uses name=\"uses-name\">\n"
2381 " <when condition=\"cond\" />\n"
2382 " <if-feature name=\"feature\" />\n"
2383 " <status value=\"obsolete\" />\n"
2384 " <description><text>desc</text></description>\n"
2385 " <reference><text>ref</text></reference>\n"
2386 " <refine target-node=\"target\"/>\n"
2387 " <augment target-node=\"target\" />\n"
2388 EXT_SUBELEM
2389 "</uses>"
2390 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002391 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002392 parsed = (struct lysp_node_uses *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002393 CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1,
2394 "uses-name", 0, LYS_USES, 0, "ref", 1);
2395 CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002396 assert_string_equal(parsed->iffeatures[0].str, "feature");
David Sedlák0d6de5a2019-07-22 13:25:44 +02002397 assert_string_equal(parsed->refines->nodeid, "target");
David Sedlák992fb7c2019-07-24 16:51:01 +02002398 assert_string_equal(parsed->augments->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002399 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_USES);
Radek Iša56ca9e42020-09-08 18:42:00 +02002400 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002401 siblings = NULL;
2402
2403 /* min subelems */
2404 data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002405 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002406 assert_string_equal(siblings[0].name, "uses-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002407 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák0d6de5a2019-07-22 13:25:44 +02002408 siblings = NULL;
David Sedlák0d6de5a2019-07-22 13:25:44 +02002409}
2410
David Sedlákaa854b02019-07-22 14:17:10 +02002411static void
2412test_revision_elem(void **state)
2413{
David Sedlákaa854b02019-07-22 14:17:10 +02002414 const char *data;
2415 struct lysp_revision *revs = NULL;
2416
2417 /* max subelems */
2418 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002419 "<revision date=\"2018-12-25\">\n"
2420 " <description><text>desc</text></description>\n"
2421 " <reference><text>ref</text></reference>\n"
2422 EXT_SUBELEM
2423 "</revision>"
2424 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002425 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002426 assert_string_equal(revs->date, "2018-12-25");
2427 assert_string_equal(revs->dsc, "desc");
2428 assert_string_equal(revs->ref, "ref");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002429 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]), LY_STMT_REVISION);
Radek Iša56ca9e42020-09-08 18:42:00 +02002430 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002431 revs = NULL;
2432
2433 /* min subelems */
2434 data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002435 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
David Sedlákaa854b02019-07-22 14:17:10 +02002436 assert_string_equal(revs->date, "2005-05-05");
Radek Iša56ca9e42020-09-08 18:42:00 +02002437 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002438 revs = NULL;
2439
2440 /* invalid value */
2441 data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002442 assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID);
2443 CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1.");
2444 FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
David Sedlákaa854b02019-07-22 14:17:10 +02002445 revs = NULL;
David Sedlákaa854b02019-07-22 14:17:10 +02002446}
2447
David Sedlák0c2bab92019-07-22 15:33:19 +02002448static void
2449test_include_elem(void **state)
2450{
David Sedlák0c2bab92019-07-22 15:33:19 +02002451 const char *data;
2452 struct lysp_include *includes = NULL;
2453 struct include_meta inc_meta = {"module-name", &includes};
2454
2455 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002456 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák0c2bab92019-07-22 15:33:19 +02002457 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002458 "<include module=\"mod\">\n"
2459 " <description><text>desc</text></description>\n"
2460 " <reference><text>ref</text></reference>\n"
2461 " <revision-date date=\"1999-09-09\"/>\n"
2462 EXT_SUBELEM
2463 "</include>"
2464 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002465 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002466 assert_string_equal(includes->name, "mod");
2467 assert_string_equal(includes->dsc, "desc");
2468 assert_string_equal(includes->ref, "ref");
David Sedlák0c2bab92019-07-22 15:33:19 +02002469 assert_string_equal(includes->rev, "1999-09-09");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002470 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]), LY_STMT_INCLUDE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002471 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002472 includes = NULL;
2473
2474 /* min subelems */
2475 data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002476 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
David Sedlák0c2bab92019-07-22 15:33:19 +02002477 assert_string_equal(includes->name, "mod");
Radek Iša56ca9e42020-09-08 18:42:00 +02002478 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002479 includes = NULL;
2480
2481 /* invalid combinations */
Radek Iša56ca9e42020-09-08 18:42:00 +02002482 YCTX->parsed_mod->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002483 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002484 "<include module=\"mod\">\n"
2485 " <description><text>desc</text></description>\n"
2486 " <revision-date date=\"1999-09-09\"/>\n"
2487 "</include>"
2488 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002489 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2490 CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2491 "Line number 2.");
2492 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002493 includes = NULL;
2494
Radek Iša56ca9e42020-09-08 18:42:00 +02002495 YCTX->parsed_mod->version = LYS_VERSION_1_0;
David Sedlák0c2bab92019-07-22 15:33:19 +02002496 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002497 "<include module=\"mod\">\n"
2498 " <reference><text>ref</text></reference>\n"
2499 " <revision-date date=\"1999-09-09\"/>\n"
2500 "</include>"
2501 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002502 assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
2503 CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
2504 "Line number 2.");
2505 FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
David Sedlák0c2bab92019-07-22 15:33:19 +02002506 includes = NULL;
David Sedlák0c2bab92019-07-22 15:33:19 +02002507}
2508
David Sedlák5e13dea2019-07-22 16:06:45 +02002509static void
David Sedlákaf536aa2019-07-23 13:42:23 +02002510test_list_elem(void **state)
2511{
David Sedlákaf536aa2019-07-23 13:42:23 +02002512 const char *data;
2513 struct lysp_node *siblings = NULL;
2514 struct tree_node_meta node_meta = {NULL, &siblings};
2515 struct lysp_node_list *parsed = NULL;
2516
2517 /* max subelems */
2518 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002519 "<list name=\"list-name\">\n"
2520 " <when condition=\"when\"/>\n"
2521 " <if-feature name=\"iff\"/>\n"
2522 " <must condition=\"must-cond\"/>\n"
2523 " <key value=\"key\"/>\n"
2524 " <unique tag=\"utag\"/>\n"
2525 " <config value=\"true\"/>\n"
2526 " <min-elements value=\"10\"/>\n"
2527 " <ordered-by value=\"user\"/>\n"
2528 " <status value=\"deprecated\"/>\n"
2529 " <description><text>desc</text></description>\n"
2530 " <reference><text>ref</text></reference>\n"
2531 " <anydata name=\"anyd\"/>\n"
2532 " <anyxml name=\"anyx\"/>\n"
2533 " <container name=\"cont\"/>\n"
2534 " <choice name=\"choice\"/>\n"
2535 " <action name=\"action\"/>\n"
2536 " <grouping name=\"grp\"/>\n"
2537 " <notification name=\"notf\"/>\n"
2538 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2539 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2540 " <list name=\"sub-list\"/>\n"
2541 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2542 " <uses name=\"uses-name\"/>\n"
2543 EXT_SUBELEM
2544 "</list>"
2545 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002546 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002547 parsed = (struct lysp_node_list *)&siblings[0];
David Sedlákaf536aa2019-07-23 13:42:23 +02002548 assert_string_equal(parsed->child->name, "anyd");
2549 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2550 assert_string_equal(parsed->child->next->name, "anyx");
2551 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
David Sedlákf111bcb2019-07-23 17:15:51 +02002552 assert_string_equal(parsed->child->next->next->name, "cont");
2553 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002554 assert_string_equal(parsed->child->next->next->next->name, "choice");
2555 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
David Sedlák85d0eca2019-07-24 15:15:21 +02002556 assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
2557 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
2558 assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
2559 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2560 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
2561 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
2562 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
2563 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2564 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Iša56ca9e42020-09-08 18:42:00 +02002565 uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN;
2566
2567 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2568 "list-name", 0, LYS_LIST, 0, "ref", 1);
2569 CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
2570 CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002571 assert_string_equal(parsed->groupings->name, "grp");
David Sedlák85d0eca2019-07-24 15:15:21 +02002572 assert_string_equal(parsed->actions->name, "action");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002573 assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
David Sedlák031b9e72019-07-23 15:19:37 +02002574 assert_string_equal(parsed->notifs->name, "notf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002575 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákaf536aa2019-07-23 13:42:23 +02002576 assert_string_equal(parsed->key, "key");
2577 assert_int_equal(parsed->min, 10);
David Sedlákaf536aa2019-07-23 13:42:23 +02002578 assert_string_equal(parsed->typedefs->name, "tpdf");
Michal Vasko7f45cf22020-10-01 12:49:44 +02002579 assert_string_equal(parsed->uniques->str, "utag");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002580 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LIST);
Radek Iša56ca9e42020-09-08 18:42:00 +02002581 lysp_node_free(UTEST_LYCTX, siblings);
2582 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedlákaf536aa2019-07-23 13:42:23 +02002583 siblings = NULL;
2584
2585 /* min subelems */
2586 data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002587 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákaf536aa2019-07-23 13:42:23 +02002588 parsed = (struct lysp_node_list *)&siblings[0];
Radek Iša56ca9e42020-09-08 18:42:00 +02002589 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2590 "list-name", 0, LYS_LIST, 0, NULL, 0);
2591 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákaf536aa2019-07-23 13:42:23 +02002592 siblings = NULL;
David Sedlákaf536aa2019-07-23 13:42:23 +02002593}
2594
David Sedlák031b9e72019-07-23 15:19:37 +02002595static void
2596test_notification_elem(void **state)
2597{
David Sedlák031b9e72019-07-23 15:19:37 +02002598 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002599 struct lysp_node_notif *notifs = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002600 struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
David Sedlák031b9e72019-07-23 15:19:37 +02002601
2602 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002603 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák031b9e72019-07-23 15:19:37 +02002604 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002605 "<notification name=\"notif-name\">\n"
2606 " <anydata name=\"anyd\"/>\n"
2607 " <anyxml name=\"anyx\"/>\n"
2608 " <description><text>desc</text></description>\n"
2609 " <if-feature name=\"iff\"/>\n"
2610 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2611 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2612 " <list name=\"sub-list\"/>\n"
2613 " <must condition=\"cond\"/>\n"
2614 " <reference><text>ref</text></reference>\n"
2615 " <status value=\"deprecated\"/>\n"
2616 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2617 " <uses name=\"uses-name\"/>\n"
2618 " <container name=\"cont\"/>\n"
2619 " <choice name=\"choice\"/>\n"
2620 " <grouping name=\"grp\"/>\n"
2621 EXT_SUBELEM
2622 "</notification>"
2623 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002624 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002625 assert_string_equal(notifs->name, "notif-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002626 assert_string_equal(notifs->child->name, "anyd");
2627 assert_int_equal(notifs->child->nodetype, LYS_ANYDATA);
2628 assert_string_equal(notifs->child->next->name, "anyx");
2629 assert_int_equal(notifs->child->next->nodetype, LYS_ANYXML);
2630 assert_string_equal(notifs->child->next->next->name, "leaf");
2631 assert_int_equal(notifs->child->next->next->nodetype, LYS_LEAF);
2632 assert_string_equal(notifs->child->next->next->next->name, "llist");
2633 assert_int_equal(notifs->child->next->next->next->nodetype, LYS_LEAFLIST);
2634 assert_string_equal(notifs->child->next->next->next->next->name, "sub-list");
2635 assert_int_equal(notifs->child->next->next->next->next->nodetype, LYS_LIST);
David Sedlák031b9e72019-07-23 15:19:37 +02002636 assert_true(notifs->flags & LYS_STATUS_DEPRC);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002637 assert_string_equal(notifs->groupings->name, "grp");
2638 assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING);
Radek Krejci01180ac2021-01-27 08:48:22 +01002639 assert_string_equal(notifs->child->next->next->next->next->next->name, "uses-name");
2640 assert_int_equal(notifs->child->next->next->next->next->next->nodetype, LYS_USES);
2641 assert_string_equal(notifs->child->next->next->next->next->next->next->name, "cont");
2642 assert_int_equal(notifs->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2643 assert_int_equal(notifs->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2644 assert_string_equal(notifs->child->next->next->next->next->next->next->next->name, "choice");
2645 assert_null(notifs->child->next->next->next->next->next->next->next->next);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002646 assert_string_equal(notifs->iffeatures[0].str, "iff");
2647 assert_string_equal(notifs->musts->arg.str, "cond");
David Sedlák031b9e72019-07-23 15:19:37 +02002648 assert_int_equal(notifs->nodetype, LYS_NOTIF);
2649 assert_null(notifs->parent);
2650 assert_string_equal(notifs->ref, "ref");
2651 assert_string_equal(notifs->typedefs->name, "tpdf");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002652 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LY_STMT_NOTIFICATION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002653 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedlák031b9e72019-07-23 15:19:37 +02002654 notifs = NULL;
2655
2656 /* min subelems */
2657 data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002658 assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
David Sedlák031b9e72019-07-23 15:19:37 +02002659 assert_string_equal(notifs->name, "notif-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002660 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002661 notifs = NULL;
David Sedláke3ce9ef2019-07-23 16:34:30 +02002662}
2663
2664static void
2665test_grouping_elem(void **state)
2666{
David Sedláke3ce9ef2019-07-23 16:34:30 +02002667 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002668 struct lysp_node_grp *grps = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02002669 struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
David Sedláke3ce9ef2019-07-23 16:34:30 +02002670
2671 /* max subelems */
2672 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002673 "<grouping name=\"grp-name\">\n"
2674 " <anydata name=\"anyd\"/>\n"
2675 " <anyxml name=\"anyx\"/>\n"
2676 " <description><text>desc</text></description>\n"
2677 " <grouping name=\"sub-grp\"/>\n"
2678 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2679 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2680 " <list name=\"list\"/>\n"
2681 " <notification name=\"notf\"/>\n"
2682 " <reference><text>ref</text></reference>\n"
2683 " <status value=\"current\"/>\n"
2684 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2685 " <uses name=\"uses-name\"/>\n"
2686 " <action name=\"act\"/>\n"
2687 " <container name=\"cont\"/>\n"
2688 " <choice name=\"choice\"/>\n"
2689 EXT_SUBELEM
2690 "</grouping>"
2691 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002692 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002693 assert_string_equal(grps->name, "grp-name");
Radek Krejci01180ac2021-01-27 08:48:22 +01002694 assert_string_equal(grps->child->name, "anyd");
2695 assert_string_equal(grps->child->next->name, "anyx");
2696 assert_string_equal(grps->child->next->next->name, "leaf");
2697 assert_string_equal(grps->child->next->next->next->name, "llist");
2698 assert_string_equal(grps->child->next->next->next->next->name, "list");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002699 assert_string_equal(grps->dsc, "desc");
David Sedláke3ce9ef2019-07-23 16:34:30 +02002700 assert_true(grps->flags & LYS_STATUS_CURR);
2701 assert_string_equal(grps->groupings->name, "sub-grp");
2702 assert_int_equal(grps->nodetype, LYS_GROUPING);
2703 assert_string_equal(grps->notifs->name, "notf");
2704 assert_null(grps->parent);
2705 assert_string_equal(grps->ref, "ref");
2706 assert_string_equal(grps->typedefs->name, "tpdf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002707 assert_string_equal(grps->actions->name, "act");
Radek Krejci01180ac2021-01-27 08:48:22 +01002708 assert_string_equal(grps->child->next->next->next->next->next->name, "uses-name");
2709 assert_int_equal(grps->child->next->next->next->next->next->nodetype, LYS_USES);
2710 assert_string_equal(grps->child->next->next->next->next->next->next->name, "cont");
2711 assert_int_equal(grps->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
2712 assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice");
2713 assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002714 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LY_STMT_GROUPING);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002715 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002716 grps = NULL;
2717
2718 /* min subelems */
2719 data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002720 assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002721 assert_string_equal(grps->name, "grp-name");
Radek Krejci2a9fc652021-01-22 17:44:34 +01002722 lysp_node_free(UTEST_LYCTX, &grps->node);
David Sedláke3ce9ef2019-07-23 16:34:30 +02002723 grps = NULL;
David Sedlák031b9e72019-07-23 15:19:37 +02002724}
2725
David Sedlákf111bcb2019-07-23 17:15:51 +02002726static void
2727test_container_elem(void **state)
2728{
David Sedlákf111bcb2019-07-23 17:15:51 +02002729 const char *data;
2730 struct lysp_node *siblings = NULL;
2731 struct tree_node_meta node_meta = {NULL, &siblings};
2732 struct lysp_node_container *parsed = NULL;
2733
2734 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002735 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedláke2dc9e92019-07-24 09:59:21 +02002736 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002737 "<container name=\"cont-name\">\n"
2738 " <anydata name=\"anyd\"/>\n"
2739 " <anyxml name=\"anyx\"/>\n"
2740 " <config value=\"true\"/>\n"
2741 " <container name=\"subcont\"/>\n"
2742 " <description><text>desc</text></description>\n"
2743 " <grouping name=\"sub-grp\"/>\n"
2744 " <if-feature name=\"iff\"/>\n"
2745 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2746 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2747 " <list name=\"list\"/>\n"
2748 " <must condition=\"cond\"/>\n"
2749 " <notification name=\"notf\"/>\n"
2750 " <presence value=\"presence\"/>\n"
2751 " <reference><text>ref</text></reference>\n"
2752 " <status value=\"current\"/>\n"
2753 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2754 " <uses name=\"uses-name\"/>\n"
2755 " <when condition=\"when-cond\"/>\n"
2756 " <action name=\"act\"/>\n"
2757 " <choice name=\"choice\"/>\n"
2758 EXT_SUBELEM
2759 "</container>"
2760 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002761 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedláke2dc9e92019-07-24 09:59:21 +02002762 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002763 uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR;
2764
2765 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2766 "cont-name", 0, LYS_CONTAINER, 0, "ref", 1);
2767 CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL);
2768 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
2769
Michal Vasko7f45cf22020-10-01 12:49:44 +02002770 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedláke2dc9e92019-07-24 09:59:21 +02002771 assert_string_equal(parsed->presence, "presence");
2772 assert_string_equal(parsed->typedefs->name, "tpdf");
2773 assert_string_equal(parsed->groupings->name, "sub-grp");
2774 assert_string_equal(parsed->child->name, "anyd");
2775 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2776 assert_string_equal(parsed->child->next->name, "anyx");
2777 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2778 assert_string_equal(parsed->child->next->next->name, "subcont");
2779 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2780 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2781 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2782 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2783 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2784 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2785 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2786 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2787 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002788 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2789 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2790 assert_null(parsed->child->next->next->next->next->next->next->next->next);
David Sedláke2dc9e92019-07-24 09:59:21 +02002791 assert_string_equal(parsed->notifs->name, "notf");
David Sedlák85d0eca2019-07-24 15:15:21 +02002792 assert_string_equal(parsed->actions->name, "act");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002793 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CONTAINER);
Radek Iša56ca9e42020-09-08 18:42:00 +02002794 lysp_node_free(UTEST_LYCTX, siblings);
2795 ly_set_erase(&YCTX->tpdfs_nodes, NULL);
David Sedláke2dc9e92019-07-24 09:59:21 +02002796 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002797
2798 /* min subelems */
2799 data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002800 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákf111bcb2019-07-23 17:15:51 +02002801 parsed = (struct lysp_node_container *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002802 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2803 "cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
2804 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákf111bcb2019-07-23 17:15:51 +02002805 siblings = NULL;
David Sedlákf111bcb2019-07-23 17:15:51 +02002806}
2807
David Sedlák5379d392019-07-24 10:42:03 +02002808static void
2809test_case_elem(void **state)
2810{
David Sedlák5379d392019-07-24 10:42:03 +02002811 const char *data;
2812 struct lysp_node *siblings = NULL;
2813 struct tree_node_meta node_meta = {NULL, &siblings};
2814 struct lysp_node_case *parsed = NULL;
2815
2816 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002817 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák5379d392019-07-24 10:42:03 +02002818 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002819 "<case name=\"case-name\">\n"
2820 " <anydata name=\"anyd\"/>\n"
2821 " <anyxml name=\"anyx\"/>\n"
2822 " <container name=\"subcont\"/>\n"
2823 " <description><text>desc</text></description>\n"
2824 " <if-feature name=\"iff\"/>\n"
2825 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2826 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2827 " <list name=\"list\"/>\n"
2828 " <reference><text>ref</text></reference>\n"
2829 " <status value=\"current\"/>\n"
2830 " <uses name=\"uses-name\"/>\n"
2831 " <when condition=\"when-cond\"/>\n"
2832 " <choice name=\"choice\"/>\n"
2833 EXT_SUBELEM
2834 "</case>"
2835 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002836 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002837 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002838 uint16_t flags = LYS_STATUS_CURR;
2839
2840 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2841 "case-name", 0, LYS_CASE, 0, "ref", 1);
2842 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002843 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlák5379d392019-07-24 10:42:03 +02002844 assert_string_equal(parsed->child->name, "anyd");
2845 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2846 assert_string_equal(parsed->child->next->name, "anyx");
2847 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2848 assert_string_equal(parsed->child->next->next->name, "subcont");
2849 assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
2850 assert_string_equal(parsed->child->next->next->next->name, "leaf");
2851 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF);
2852 assert_string_equal(parsed->child->next->next->next->next->name, "llist");
2853 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST);
2854 assert_string_equal(parsed->child->next->next->next->next->next->name, "list");
2855 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST);
2856 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name");
2857 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002858 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
2859 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
2860 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002861 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CASE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002862 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002863 siblings = NULL;
2864
2865 /* min subelems */
2866 data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002867 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlák5379d392019-07-24 10:42:03 +02002868 parsed = (struct lysp_node_case *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002869 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2870 "case-name", 0, LYS_CASE, 0, NULL, 0);
2871 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlák5379d392019-07-24 10:42:03 +02002872 siblings = NULL;
David Sedlák5379d392019-07-24 10:42:03 +02002873}
2874
David Sedlákb7abcfa2019-07-24 12:33:35 +02002875static void
2876test_choice_elem(void **state)
2877{
David Sedlákb7abcfa2019-07-24 12:33:35 +02002878 const char *data;
2879 struct lysp_node *siblings = NULL;
2880 struct tree_node_meta node_meta = {NULL, &siblings};
2881 struct lysp_node_choice *parsed = NULL;
2882
2883 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02002884 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002885 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002886 "<choice name=\"choice-name\">\n"
2887 " <anydata name=\"anyd\"/>\n"
2888 " <anyxml name=\"anyx\"/>\n"
2889 " <case name=\"sub-case\"/>\n"
2890 " <choice name=\"choice\"/>\n"
2891 " <config value=\"true\"/>\n"
2892 " <container name=\"subcont\"/>\n"
2893 " <default value=\"def\"/>\n"
2894 " <description><text>desc</text></description>\n"
2895 " <if-feature name=\"iff\"/>\n"
2896 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2897 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2898 " <list name=\"list\"/>\n"
2899 " <mandatory value=\"true\" />\n"
2900 " <reference><text>ref</text></reference>\n"
2901 " <status value=\"current\"/>\n"
2902 " <when condition=\"when-cond\"/>\n"
2903 EXT_SUBELEM
2904 "</choice>"
2905 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002906 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002907 parsed = (struct lysp_node_choice *)siblings;
Radek Iša56ca9e42020-09-08 18:42:00 +02002908 uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR;
2909
2910 CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
2911 "choice-name", 0, LYS_CHOICE, 0, "ref", 1);
2912 CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
Michal Vasko7f45cf22020-10-01 12:49:44 +02002913 assert_string_equal(parsed->iffeatures[0].str, "iff");
David Sedlákb7abcfa2019-07-24 12:33:35 +02002914 assert_string_equal(parsed->child->name, "anyd");
2915 assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
2916 assert_string_equal(parsed->child->next->name, "anyx");
2917 assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML);
2918 assert_string_equal(parsed->child->next->next->name, "sub-case");
2919 assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE);
2920 assert_string_equal(parsed->child->next->next->next->name, "choice");
2921 assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
2922 assert_string_equal(parsed->child->next->next->next->next->name, "subcont");
2923 assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER);
2924 assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf");
2925 assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF);
2926 assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist");
2927 assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2928 assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
2929 assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
2930 assert_null(parsed->child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002931 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CHOICE);
Radek Iša56ca9e42020-09-08 18:42:00 +02002932 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002933 siblings = NULL;
2934
2935 /* min subelems */
2936 data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002937 assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002938 parsed = (struct lysp_node_choice *)siblings;
2939 assert_string_equal(parsed->name, "choice-name");
Radek Iša56ca9e42020-09-08 18:42:00 +02002940 CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
2941 "choice-name", 0, LYS_CHOICE, 0, NULL, 0);
2942 lysp_node_free(UTEST_LYCTX, siblings);
David Sedlákb7abcfa2019-07-24 12:33:35 +02002943 siblings = NULL;
David Sedlákb7abcfa2019-07-24 12:33:35 +02002944}
2945
David Sedlák05404f62019-07-24 14:11:53 +02002946static void
2947test_inout_elem(void **state)
2948{
David Sedlák05404f62019-07-24 14:11:53 +02002949 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002950 struct lysp_node_action_inout inout = {};
David Sedlák05404f62019-07-24 14:11:53 +02002951 struct inout_meta inout_meta = {NULL, &inout};
2952
2953 /* max subelements */
Radek Iša56ca9e42020-09-08 18:42:00 +02002954 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002955 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01002956 "<input>\n"
2957 " <anydata name=\"anyd\"/>\n"
2958 " <anyxml name=\"anyx\"/>\n"
2959 " <choice name=\"choice\"/>\n"
2960 " <container name=\"subcont\"/>\n"
2961 " <grouping name=\"sub-grp\"/>\n"
2962 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
2963 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
2964 " <list name=\"list\"/>\n"
2965 " <must condition=\"cond\"/>\n"
2966 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
2967 " <uses name=\"uses-name\"/>\n"
2968 EXT_SUBELEM
2969 "</input>"
2970 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02002971 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
2972 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1);
2973 CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL);
David Sedlák05404f62019-07-24 14:11:53 +02002974 assert_string_equal(inout.typedefs->name, "tpdf");
2975 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01002976 assert_string_equal(inout.child->name, "anyd");
2977 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
2978 assert_string_equal(inout.child->next->name, "anyx");
2979 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
2980 assert_string_equal(inout.child->next->next->name, "choice");
2981 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
2982 assert_string_equal(inout.child->next->next->next->name, "subcont");
2983 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
2984 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
2985 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
2986 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
2987 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
2988 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
2989 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
2990 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
2991 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
2992 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01002993 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_INPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01002994 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02002995 memset(&inout, 0, sizeof inout);
2996
2997 /* max subelements */
Radek Iša56ca9e42020-09-08 18:42:00 +02002998 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák05404f62019-07-24 14:11:53 +02002999 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003000 "<output>\n"
3001 " <anydata name=\"anyd\"/>\n"
3002 " <anyxml name=\"anyx\"/>\n"
3003 " <choice name=\"choice\"/>\n"
3004 " <container name=\"subcont\"/>\n"
3005 " <grouping name=\"sub-grp\"/>\n"
3006 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3007 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3008 " <list name=\"list\"/>\n"
3009 " <must condition=\"cond\"/>\n"
3010 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3011 " <uses name=\"uses-name\"/>\n"
3012 EXT_SUBELEM
3013 "</output>"
3014 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003015 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
3016 CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1);
Michal Vasko7f45cf22020-10-01 12:49:44 +02003017 assert_string_equal(inout.musts->arg.str, "cond");
David Sedlák05404f62019-07-24 14:11:53 +02003018 assert_string_equal(inout.typedefs->name, "tpdf");
3019 assert_string_equal(inout.groupings->name, "sub-grp");
Radek Krejci01180ac2021-01-27 08:48:22 +01003020 assert_string_equal(inout.child->name, "anyd");
3021 assert_int_equal(inout.child->nodetype, LYS_ANYDATA);
3022 assert_string_equal(inout.child->next->name, "anyx");
3023 assert_int_equal(inout.child->next->nodetype, LYS_ANYXML);
3024 assert_string_equal(inout.child->next->next->name, "choice");
3025 assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE);
3026 assert_string_equal(inout.child->next->next->next->name, "subcont");
3027 assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER);
3028 assert_string_equal(inout.child->next->next->next->next->name, "leaf");
3029 assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF);
3030 assert_string_equal(inout.child->next->next->next->next->next->name, "llist");
3031 assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3032 assert_string_equal(inout.child->next->next->next->next->next->next->name, "list");
3033 assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST);
3034 assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name");
3035 assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
3036 assert_null(inout.child->next->next->next->next->next->next->next->next);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003037 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_OUTPUT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003038 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003039 memset(&inout, 0, sizeof inout);
3040
3041 /* min subelems */
Michal Vaskob83af8a2020-01-06 09:49:22 +01003042 data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003043 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003044 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003045 memset(&inout, 0, sizeof inout);
3046
Michal Vaskob83af8a2020-01-06 09:49:22 +01003047 data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003048 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003049 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
David Sedlák05404f62019-07-24 14:11:53 +02003050 memset(&inout, 0, sizeof inout);
3051
3052 /* invalid combinations */
3053 data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003054 assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
Radek Krejci9a3823e2021-01-27 20:26:46 +01003055 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
Radek Iša56ca9e42020-09-08 18:42:00 +02003056 CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
David Sedlák05404f62019-07-24 14:11:53 +02003057 memset(&inout, 0, sizeof inout);
David Sedlák05404f62019-07-24 14:11:53 +02003058}
3059
David Sedlák85d0eca2019-07-24 15:15:21 +02003060static void
3061test_action_elem(void **state)
3062{
David Sedlák85d0eca2019-07-24 15:15:21 +02003063 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003064 struct lysp_node_action *actions = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003065 struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
Radek Iša56ca9e42020-09-08 18:42:00 +02003066 uint16_t flags;
David Sedlák85d0eca2019-07-24 15:15:21 +02003067
3068 /* max subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003069 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák85d0eca2019-07-24 15:15:21 +02003070 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003071 "<action name=\"act\">\n"
3072 " <description><text>desc</text></description>\n"
3073 " <grouping name=\"grouping\"/>\n"
3074 " <if-feature name=\"iff\"/>\n"
3075 " <input><uses name=\"uses-name\"/></input>\n"
3076 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3077 " <reference><text>ref</text></reference>\n"
3078 " <status value=\"deprecated\"/>\n"
3079 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3080 EXT_SUBELEM
3081 "</action>"
3082 ELEMENT_WRAPPER_END;
Michal Vasko1bf09392020-03-27 12:38:10 +01003083 /* there must be parent for action */
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003084 act_meta.parent = (void *)1;
Radek Iša56ca9e42020-09-08 18:42:00 +02003085 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
Michal Vasko1bf09392020-03-27 12:38:10 +01003086 act_meta.parent = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003087 flags = LYS_STATUS_DEPRC;
3088 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3089 1, 0, 0, 0,\
3090 1, 0,\
3091 "act", LYS_ACTION, \
3092 1, 0, 0, 1,\
3093 1, 0,\
3094 1, "ref", 1);
3095
Michal Vasko7f45cf22020-10-01 12:49:44 +02003096 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlák85d0eca2019-07-24 15:15:21 +02003097 assert_string_equal(actions->typedefs->name, "tpdf");
3098 assert_string_equal(actions->groupings->name, "grouping");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003099 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci01180ac2021-01-27 08:48:22 +01003100 assert_string_equal(actions->input.child->name, "uses-name");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003101 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_ACTION);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003102 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003103 actions = NULL;
3104
Radek Iša56ca9e42020-09-08 18:42:00 +02003105 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlákeaa45792019-07-24 15:25:01 +02003106 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003107 "<rpc name=\"act\">\n"
3108 " <description><text>desc</text></description>\n"
3109 " <grouping name=\"grouping\"/>\n"
3110 " <if-feature name=\"iff\"/>\n"
3111 " <input><uses name=\"uses-name\"/></input>\n"
3112 " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n"
3113 " <reference><text>ref</text></reference>\n"
3114 " <status value=\"deprecated\"/>\n"
3115 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3116 EXT_SUBELEM
3117 "</rpc>"
3118 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003119 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
3120 flags = LYS_STATUS_DEPRC;
3121 CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
3122 1, 0, 0, 0,\
3123 1, 0,\
3124 "act", LYS_RPC, \
3125 1, 0, 0, 1,\
3126 1, 0,\
3127 0, "ref", 1);
3128
Michal Vasko7f45cf22020-10-01 12:49:44 +02003129 assert_string_equal(actions->iffeatures[0].str, "iff");
David Sedlákeaa45792019-07-24 15:25:01 +02003130 assert_string_equal(actions->typedefs->name, "tpdf");
3131 assert_string_equal(actions->groupings->name, "grouping");
Radek Krejci01180ac2021-01-27 08:48:22 +01003132 assert_string_equal(actions->input.child->name, "uses-name");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003133 assert_string_equal(actions->output.musts->arg.str, "cond");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003134 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_RPC);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003135 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlákeaa45792019-07-24 15:25:01 +02003136 actions = NULL;
3137
David Sedlák85d0eca2019-07-24 15:15:21 +02003138 /* min subelems */
3139 data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003140 assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
David Sedlák85d0eca2019-07-24 15:15:21 +02003141 assert_string_equal(actions->name, "act");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003142 lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
David Sedlák85d0eca2019-07-24 15:15:21 +02003143 actions = NULL;
David Sedlák85d0eca2019-07-24 15:15:21 +02003144}
3145
David Sedlák992fb7c2019-07-24 16:51:01 +02003146static void
3147test_augment_elem(void **state)
3148{
David Sedlák992fb7c2019-07-24 16:51:01 +02003149 const char *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01003150 struct lysp_node_augment *augments = NULL;
David Sedlák6881b512019-08-13 12:52:00 +02003151 struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
David Sedlák992fb7c2019-07-24 16:51:01 +02003152
Radek Iša56ca9e42020-09-08 18:42:00 +02003153 YCTX->parsed_mod->version = LYS_VERSION_1_1;
David Sedlák992fb7c2019-07-24 16:51:01 +02003154 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003155 "<augment target-node=\"target\">\n"
3156 " <action name=\"action\"/>\n"
3157 " <anydata name=\"anyd\"/>\n"
3158 " <anyxml name=\"anyx\"/>\n"
3159 " <case name=\"case\"/>\n"
3160 " <choice name=\"choice\"/>\n"
3161 " <container name=\"subcont\"/>\n"
3162 " <description><text>desc</text></description>\n"
3163 " <if-feature name=\"iff\"/>\n"
3164 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3165 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3166 " <list name=\"list\"/>\n"
3167 " <notification name=\"notif\"/>\n"
3168 " <reference><text>ref</text></reference>\n"
3169 " <status value=\"current\"/>\n"
3170 " <uses name=\"uses\"/>\n"
3171 " <when condition=\"when-cond\"/>\n"
3172 EXT_SUBELEM
3173 "</augment>"
3174 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003175 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003176 assert_string_equal(augments->nodeid, "target");
3177 assert_null(augments->parent);
3178 assert_int_equal(augments->nodetype, LYS_AUGMENT);
3179 assert_true(augments->flags & LYS_STATUS_CURR);
3180 assert_string_equal(augments->dsc, "desc");
3181 assert_string_equal(augments->ref, "ref");
3182 assert_string_equal(augments->when->cond, "when-cond");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003183 assert_string_equal(augments->iffeatures[0].str, "iff");
David Sedlák992fb7c2019-07-24 16:51:01 +02003184 assert_string_equal(augments->child->name, "anyd");
3185 assert_int_equal(augments->child->nodetype, LYS_ANYDATA);
3186 assert_string_equal(augments->child->next->name, "anyx");
3187 assert_int_equal(augments->child->next->nodetype, LYS_ANYXML);
3188 assert_string_equal(augments->child->next->next->name, "case");
3189 assert_int_equal(augments->child->next->next->nodetype, LYS_CASE);
3190 assert_string_equal(augments->child->next->next->next->name, "choice");
3191 assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE);
3192 assert_string_equal(augments->child->next->next->next->next->name, "subcont");
3193 assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER);
3194 assert_string_equal(augments->child->next->next->next->next->next->name, "leaf");
3195 assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF);
3196 assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist");
3197 assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3198 assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list");
3199 assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
3200 assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses");
3201 assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES);
3202 assert_null(augments->child->next->next->next->next->next->next->next->next->next);
3203 assert_string_equal(augments->actions->name, "action");
3204 assert_string_equal(augments->notifs->name, "notif");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003205 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT);
Radek Krejci2a9fc652021-01-22 17:44:34 +01003206 lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003207 augments = NULL;
3208
3209 data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003210 assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
David Sedlák992fb7c2019-07-24 16:51:01 +02003211 assert_string_equal(augments->nodeid, "target");
Radek Krejci2a9fc652021-01-22 17:44:34 +01003212 lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
David Sedlák992fb7c2019-07-24 16:51:01 +02003213 augments = NULL;
David Sedlák992fb7c2019-07-24 16:51:01 +02003214}
3215
David Sedlák4ffcec82019-07-25 15:10:21 +02003216static void
3217test_deviate_elem(void **state)
3218{
David Sedlák4ffcec82019-07-25 15:10:21 +02003219 const char *data;
3220 struct lysp_deviate *deviates = NULL;
3221 struct lysp_deviate_add *d_add;
3222 struct lysp_deviate_rpl *d_rpl;
3223 struct lysp_deviate_del *d_del;
3224
3225 /* all valid arguments with min subelems */
3226 data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003227 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003228 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003229 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003230 free(deviates);
3231 deviates = NULL;
3232
3233 data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003234 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003235 assert_int_equal(deviates->mod, LYS_DEV_ADD);
Radek Iša56ca9e42020-09-08 18:42:00 +02003236 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003237 free(deviates);
3238 deviates = NULL;
3239
3240 data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003241 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003242 assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003243 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003244 free(deviates);
3245 deviates = NULL;
3246
3247 data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003248 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003249 assert_int_equal(deviates->mod, LYS_DEV_DELETE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003250 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003251 free(deviates);
3252 deviates = NULL;
3253
3254 /* max subelems and valid arguments */
3255 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003256 "<deviate value=\"not-supported\">"
3257 EXT_SUBELEM
3258 "</deviate>"
3259 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003260 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003261 assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003262 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003263 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003264 free(deviates);
3265 deviates = NULL;
3266
3267 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003268 "<deviate value=\"add\">\n"
3269 " <units name=\"units\"/>\n"
3270 " <must condition=\"cond\"/>\n"
3271 " <unique tag=\"utag\"/>\n"
3272 " <default value=\"def\"/>\n"
3273 " <config value=\"true\"/>\n"
3274 " <mandatory value=\"true\"/>\n"
3275 " <min-elements value=\"5\"/>\n"
3276 " <max-elements value=\"15\"/>\n"
3277 EXT_SUBELEM
3278 "</deviate>"
3279 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003280 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003281 d_add = (struct lysp_deviate_add *)deviates;
3282 assert_int_equal(d_add->mod, LYS_DEV_ADD);
3283 assert_null(d_add->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003284 assert_string_equal(d_add->units, "units");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003285 assert_string_equal(d_add->musts->arg.str, "cond");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003286 assert_string_equal(d_add->uniques[0].str, "utag");
3287 assert_string_equal(d_add->dflts[0].str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003288 assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003289 assert_int_equal(d_add->min, 5);
3290 assert_int_equal(d_add->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003291 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003292 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003293 free(deviates);
3294 deviates = NULL;
3295
3296 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003297 "<deviate value=\"replace\">\n"
3298 " <type name=\"newtype\"/>\n"
3299 " <units name=\"uni\"/>\n"
3300 " <default value=\"def\"/>\n"
3301 " <config value=\"true\"/>\n"
3302 " <mandatory value=\"true\"/>\n"
3303 " <min-elements value=\"5\"/>\n"
3304 " <max-elements value=\"15\"/>\n"
3305 EXT_SUBELEM
3306 "</deviate>"
3307 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003308 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003309 d_rpl = (struct lysp_deviate_rpl *)deviates;
3310 assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
3311 assert_null(d_rpl->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003312 assert_string_equal(d_rpl->type->name, "newtype");
3313 assert_string_equal(d_rpl->units, "uni");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003314 assert_string_equal(d_rpl->dflt.str, "def");
Radek Iša56ca9e42020-09-08 18:42:00 +02003315 assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W));
David Sedlák4ffcec82019-07-25 15:10:21 +02003316 assert_int_equal(d_rpl->min, 5);
3317 assert_int_equal(d_rpl->max, 15);
Radek Krejci39b7fc22021-02-26 23:29:18 +01003318 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003319 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003320 free(deviates);
3321 deviates = NULL;
3322
3323 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003324 "<deviate value=\"delete\">\n"
3325 " <units name=\"u\"/>\n"
3326 " <must condition=\"c\"/>\n"
3327 " <unique tag=\"tag\"/>\n"
3328 " <default value=\"default\"/>\n"
3329 EXT_SUBELEM
3330 "</deviate>"
3331 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003332 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
David Sedlák4ffcec82019-07-25 15:10:21 +02003333 d_del = (struct lysp_deviate_del *)deviates;
3334 assert_int_equal(d_del->mod, LYS_DEV_DELETE);
3335 assert_null(d_del->next);
David Sedlák4ffcec82019-07-25 15:10:21 +02003336 assert_string_equal(d_del->units, "u");
Michal Vasko7f45cf22020-10-01 12:49:44 +02003337 assert_string_equal(d_del->musts->arg.str, "c");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003338 assert_string_equal(d_del->uniques[0].str, "tag");
3339 assert_string_equal(d_del->dflts[0].str, "default");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003340 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LY_STMT_DEVIATE);
Radek Iša56ca9e42020-09-08 18:42:00 +02003341 lysp_deviate_free(UTEST_LYCTX, deviates);
David Sedlák4ffcec82019-07-25 15:10:21 +02003342 free(deviates);
3343 deviates = NULL;
3344
3345 /* invalid arguments */
3346 data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003347 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3348 CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. "
3349 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003350 deviates = NULL;
3351
3352 data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003353 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3354 CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. "
3355 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003356 deviates = NULL;
3357
3358 data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003359 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3360 CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. "
3361 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003362 deviates = NULL;
3363
3364 data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003365 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3366 CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. "
3367 "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
David Sedlák4ffcec82019-07-25 15:10:21 +02003368 deviates = NULL;
3369
3370 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003371 "<deviate value=\"not-supported\">\n"
3372 " <must condition=\"c\"/>\n"
3373 "</deviate>"
3374 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003375 assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
3376 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 +02003377}
3378
David Sedlák8b754462019-07-25 16:22:13 +02003379static void
3380test_deviation_elem(void **state)
3381{
David Sedlák8b754462019-07-25 16:22:13 +02003382 const char *data;
3383 struct lysp_deviation *deviations = NULL;
3384
3385 /* min subelems */
3386 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003387 "<deviation target-node=\"target\">\n"
3388 " <deviate value=\"not-supported\"/>\n"
3389 "</deviation>"
3390 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003391 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003392 assert_string_equal(deviations->nodeid, "target");
3393 assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
Radek Iša56ca9e42020-09-08 18:42:00 +02003394 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003395 deviations = NULL;
3396
3397 /* max subelems */
3398 data = ELEMENT_WRAPPER_START
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003399 "<deviation target-node=\"target\">\n"
3400 " <reference><text>ref</text></reference>\n"
3401 " <description><text>desc</text></description>\n"
3402 " <deviate value=\"add\"/>\n"
3403 EXT_SUBELEM
3404 "</deviation>"
3405 ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003406 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
David Sedlák8b754462019-07-25 16:22:13 +02003407 assert_string_equal(deviations->nodeid, "target");
3408 assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
3409 assert_string_equal(deviations->ref, "ref");
3410 assert_string_equal(deviations->dsc, "desc");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003411 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]), LY_STMT_DEVIATION);
Radek Iša56ca9e42020-09-08 18:42:00 +02003412 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003413 deviations = NULL;
3414
3415 /* invalid */
3416 data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
Radek Iša56ca9e42020-09-08 18:42:00 +02003417 assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID);
3418 FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
David Sedlák8b754462019-07-25 16:22:13 +02003419 deviations = NULL;
Radek Iša56ca9e42020-09-08 18:42:00 +02003420 CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1.");
3421 /* TODO */}
David Sedlák8b754462019-07-25 16:22:13 +02003422
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003423static struct lysp_module *
3424mod_renew(struct lys_yin_parser_ctx *ctx)
3425{
3426 struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
3427
3428 lys_module_free(ctx->parsed_mod->mod, NULL);
3429 ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod);
3430 ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
3431 ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
3432 ctx->parsed_mod->mod->ctx = ly_ctx;
3433
3434 return ctx->parsed_mod;
3435}
3436
David Sedlák4f03b932019-07-26 13:01:47 +02003437static void
3438test_module_elem(void **state)
3439{
Michal Vaskob36053d2020-03-26 15:49:30 +01003440 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003441 struct lysp_module *lysp_mod = mod_renew(YCTX);
David Sedlák4f03b932019-07-26 13:01:47 +02003442
3443 /* max subelems */
David Sedlák4f03b932019-07-26 13:01:47 +02003444 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003445 " <yang-version value=\"1.1\"/>\n"
3446 " <namespace uri=\"ns\"/>\n"
3447 " <prefix value=\"pref\"/>\n"
3448 " <include module=\"b-mod\"/>\n"
3449 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3450 " <organization><text>org</text></organization>\n"
3451 " <contact><text>contact</text></contact>\n"
3452 " <description><text>desc</text></description>\n"
3453 " <reference><text>ref</text></reference>\n"
3454 " <revision date=\"2019-02-02\"/>\n"
3455 " <anydata name=\"anyd\"/>\n"
3456 " <anyxml name=\"anyx\"/>\n"
3457 " <choice name=\"choice\"/>\n"
3458 " <container name=\"cont\"/>\n"
3459 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3460 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3461 " <list name=\"sub-list\"/>\n"
3462 " <uses name=\"uses-name\"/>\n"
3463 " <augment target-node=\"target\"/>\n"
3464 " <deviation target-node=\"target\">\n"
3465 " <deviate value=\"not-supported\"/>\n"
3466 " </deviation>\n"
3467 " <extension name=\"ext\"/>\n"
3468 " <feature name=\"feature\"/>\n"
3469 " <grouping name=\"grp\"/>\n"
3470 " <identity name=\"ident-name\"/>\n"
3471 " <notification name=\"notf\"/>\n"
3472 " <rpc name=\"rpc-name\"/>\n"
3473 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3474 EXT_SUBELEM "\n"
3475 "</module>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003476 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3477 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
Michal Vaskob36053d2020-03-26 15:49:30 +01003478
Radek Iša56ca9e42020-09-08 18:42:00 +02003479 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák4f03b932019-07-26 13:01:47 +02003480 assert_string_equal(lysp_mod->mod->name, "mod");
3481 assert_string_equal(lysp_mod->revs, "2019-02-02");
3482 assert_string_equal(lysp_mod->mod->ns, "ns");
3483 assert_string_equal(lysp_mod->mod->prefix, "pref");
3484 assert_null(lysp_mod->mod->filepath);
3485 assert_string_equal(lysp_mod->mod->org, "org");
3486 assert_string_equal(lysp_mod->mod->contact, "contact");
3487 assert_string_equal(lysp_mod->mod->dsc, "desc");
3488 assert_string_equal(lysp_mod->mod->ref, "ref");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003489 assert_int_equal(lysp_mod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003490 CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod",
3491 "imp-pref", NULL, "");
David Sedlák4f03b932019-07-26 13:01:47 +02003492 assert_string_equal(lysp_mod->includes->name, "b-mod");
3493 assert_string_equal(lysp_mod->extensions->name, "ext");
3494 assert_string_equal(lysp_mod->features->name, "feature");
3495 assert_string_equal(lysp_mod->identities->name, "ident-name");
3496 assert_string_equal(lysp_mod->typedefs->name, "tpdf");
3497 assert_string_equal(lysp_mod->groupings->name, "grp");
3498 assert_string_equal(lysp_mod->data->name, "anyd");
3499 assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA);
3500 assert_string_equal(lysp_mod->data->next->name, "anyx");
3501 assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML);
3502 assert_string_equal(lysp_mod->data->next->next->name, "choice");
3503 assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE);
3504 assert_string_equal(lysp_mod->data->next->next->next->name, "cont");
3505 assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER);
3506 assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf");
3507 assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF);
3508 assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist");
3509 assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3510 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list");
3511 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3512 assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name");
3513 assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3514 assert_null(lysp_mod->data->next->next->next->next->next->next->next->next);
3515 assert_string_equal(lysp_mod->augments->nodeid, "target");
3516 assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
3517 assert_string_equal(lysp_mod->notifs->name, "notf");
3518 assert_string_equal(lysp_mod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003519 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LY_STMT_MODULE);
David Sedlák4f03b932019-07-26 13:01:47 +02003520
3521 /* min subelems */
Radek Iša56ca9e42020-09-08 18:42:00 +02003522 ly_in_free(UTEST_IN, 0);
3523 lyxml_ctx_free(YCTX->xmlctx);
3524 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003525 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3526 " <namespace uri=\"ns\"/>\n"
3527 " <prefix value=\"pref\"/>\n"
3528 " <yang-version value=\"1.1\"/>\n"
3529 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003530 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3531 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3532 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003533 assert_string_equal(lysp_mod->mod->name, "mod");
David Sedlák298ff6d2019-07-26 14:29:03 +02003534
David Sedláke6cd89e2019-08-07 12:46:02 +02003535 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003536 ly_in_free(UTEST_IN, 0);
3537 lyxml_ctx_free(YCTX->xmlctx);
3538 lysp_mod = mod_renew(YCTX);
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003539 data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
3540 " <feature name=\"feature\"/>\n"
3541 " <namespace uri=\"ns\"/>\n"
3542 " <prefix value=\"pref\"/>\n"
3543 " <yang-version value=\"1.1\"/>\n"
3544 "</module>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003545 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3546 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3547 assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID);
3548 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 +02003549}
3550
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003551static struct lysp_submodule *
3552submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to)
3553{
3554 struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
3555
3556 lys_module_free(ctx->parsed_mod->mod, NULL);
3557 ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule));
3558 ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
3559 lydict_insert(ly_ctx, belongs_to, 0, &ctx->parsed_mod->mod->name);
3560 ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
3561 ctx->parsed_mod->mod->ctx = ly_ctx;
3562
3563 return (struct lysp_submodule *)ctx->parsed_mod;
3564}
3565
David Sedlák298ff6d2019-07-26 14:29:03 +02003566static void
3567test_submodule_elem(void **state)
3568{
Michal Vaskob36053d2020-03-26 15:49:30 +01003569 const char *data;
Radek Iša56ca9e42020-09-08 18:42:00 +02003570 struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name");
David Sedlák298ff6d2019-07-26 14:29:03 +02003571
3572 /* max subelements */
David Sedlák298ff6d2019-07-26 14:29:03 +02003573 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003574 " <yang-version value=\"1.1\"/>\n"
3575 " <belongs-to module=\"module-name\">\n"
3576 " <prefix value=\"pref\"/>\n"
3577 " </belongs-to>\n"
3578 " <include module=\"b-mod\"/>\n"
3579 " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n"
3580 " <organization><text>org</text></organization>\n"
3581 " <contact><text>contact</text></contact>\n"
3582 " <description><text>desc</text></description>\n"
3583 " <reference><text>ref</text></reference>\n"
3584 " <revision date=\"2019-02-02\"/>\n"
3585 " <anydata name=\"anyd\"/>\n"
3586 " <anyxml name=\"anyx\"/>\n"
3587 " <choice name=\"choice\"/>\n"
3588 " <container name=\"cont\"/>\n"
3589 " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n"
3590 " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n"
3591 " <list name=\"sub-list\"/>\n"
3592 " <uses name=\"uses-name\"/>\n"
3593 " <augment target-node=\"target\"/>\n"
3594 " <deviation target-node=\"target\">\n"
3595 " <deviate value=\"not-supported\"/>\n"
3596 " </deviation>\n"
3597 " <extension name=\"ext\"/>\n"
3598 " <feature name=\"feature\"/>\n"
3599 " <grouping name=\"grp\"/>\n"
3600 " <identity name=\"ident-name\"/>\n"
3601 " <notification name=\"notf\"/>\n"
3602 " <rpc name=\"rpc-name\"/>\n"
3603 " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
3604 EXT_SUBELEM "\n"
3605 "</submodule>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +02003606 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3607 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003608
Radek Iša56ca9e42020-09-08 18:42:00 +02003609 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003610 assert_string_equal(lysp_submod->name, "mod");
3611 assert_string_equal(lysp_submod->revs, "2019-02-02");
David Sedlák298ff6d2019-07-26 14:29:03 +02003612 assert_string_equal(lysp_submod->prefix, "pref");
3613 assert_null(lysp_submod->filepath);
3614 assert_string_equal(lysp_submod->org, "org");
3615 assert_string_equal(lysp_submod->contact, "contact");
3616 assert_string_equal(lysp_submod->dsc, "desc");
3617 assert_string_equal(lysp_submod->ref, "ref");
3618 assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
Radek Iša56ca9e42020-09-08 18:42:00 +02003619 CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod",
3620 "imp-pref", NULL, "");
David Sedlák298ff6d2019-07-26 14:29:03 +02003621 assert_string_equal(lysp_submod->includes->name, "b-mod");
3622 assert_string_equal(lysp_submod->extensions->name, "ext");
3623 assert_string_equal(lysp_submod->features->name, "feature");
3624 assert_string_equal(lysp_submod->identities->name, "ident-name");
3625 assert_string_equal(lysp_submod->typedefs->name, "tpdf");
3626 assert_string_equal(lysp_submod->groupings->name, "grp");
3627 assert_string_equal(lysp_submod->data->name, "anyd");
3628 assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA);
3629 assert_string_equal(lysp_submod->data->next->name, "anyx");
3630 assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML);
3631 assert_string_equal(lysp_submod->data->next->next->name, "choice");
3632 assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE);
3633 assert_string_equal(lysp_submod->data->next->next->next->name, "cont");
3634 assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER);
3635 assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf");
3636 assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF);
3637 assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist");
3638 assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST);
3639 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list");
3640 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST);
3641 assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name");
3642 assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES);
3643 assert_null(lysp_submod->data->next->next->next->next->next->next->next->next);
3644 assert_string_equal(lysp_submod->augments->nodeid, "target");
3645 assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
3646 assert_string_equal(lysp_submod->notifs->name, "notf");
3647 assert_string_equal(lysp_submod->deviations->nodeid, "target");
Radek Krejci39b7fc22021-02-26 23:29:18 +01003648 TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LY_STMT_SUBMODULE);
David Sedlák298ff6d2019-07-26 14:29:03 +02003649
David Sedlák298ff6d2019-07-26 14:29:03 +02003650 /* min subelemnts */
Radek Iša56ca9e42020-09-08 18:42:00 +02003651 ly_in_free(UTEST_IN, 0);
3652 lyxml_ctx_free(YCTX->xmlctx);
3653 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003654 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3655 " <yang-version value=\"1\"/>\n"
3656 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3657 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003658 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3659 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3660 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
David Sedlák298ff6d2019-07-26 14:29:03 +02003661 assert_string_equal(lysp_submod->prefix, "pref");
David Sedlák298ff6d2019-07-26 14:29:03 +02003662 assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
David Sedlák298ff6d2019-07-26 14:29:03 +02003663
David Sedláke6cd89e2019-08-07 12:46:02 +02003664 /* incorrect subelem order */
Radek Iša56ca9e42020-09-08 18:42:00 +02003665 ly_in_free(UTEST_IN, 0);
3666 lyxml_ctx_free(YCTX->xmlctx);
3667 lysp_submod = submod_renew(YCTX, "module-name");
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003668 data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
3669 " <yang-version value=\"1\"/>\n"
3670 " <reference><text>ref</text></reference>\n"
3671 " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
3672 "</submodule>";
Radek Iša56ca9e42020-09-08 18:42:00 +02003673 assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
3674 assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
3675 assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID);
3676 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 +02003677}
3678
David Sedlák8985a142019-07-31 16:43:06 +02003679static void
3680test_yin_parse_module(void **state)
3681{
David Sedlák8985a142019-07-31 16:43:06 +02003682 const char *data;
3683 struct lys_module *mod;
Michal Vaskob36053d2020-03-26 15:49:30 +01003684 struct lys_yin_parser_ctx *yin_ctx = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003685 struct ly_in *in = NULL;
Michal Vasko405cc9e2020-12-01 12:01:27 +01003686 struct lys_glob_unres unres = {0};
David Sedlák8985a142019-07-31 16:43:06 +02003687
3688 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003689 mod->ctx = UTEST_LYCTX;
David Sedlákd2844882019-09-13 16:01:22 +02003690 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 +01003691 " <yang-version value=\"1.1\"/>\n"
3692 " <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
3693 " <prefix value=\"a\"/>\n"
3694 " <import module=\"ietf-yang-metadata\">\n"
3695 " <prefix value=\"md\"/>\n"
3696 " </import>\n"
3697 " <feature name=\"f\"/>\n"
3698 " <md:annotation name=\"x\">\n"
3699 " <description>\n"
3700 " <text>test</text>\n"
3701 " </description>\n"
3702 " <reference>\n"
3703 " <text>test</text>\n"
3704 " </reference>\n"
3705 " <if-feature name=\"f\"/>\n"
3706 " <status value=\"current\"/>\n"
3707 " <type name=\"uint8\"/>\n"
3708 " <units name=\"meters\"/>\n"
3709 " </md:annotation>\n"
3710 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003711 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003712 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
David Sedlákd2844882019-09-13 16:01:22 +02003713 assert_null(mod->parsed->exts->child->next->child);
3714 assert_string_equal(mod->parsed->exts->child->next->arg, "test");
Radek Iša56ca9e42020-09-08 18:42:00 +02003715 lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
David Sedlákd2844882019-09-13 16:01:22 +02003716 lys_module_free(mod, NULL);
3717 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003718 ly_in_free(in, 0);
David Sedlákd2844882019-09-13 16:01:22 +02003719 mod = NULL;
3720 yin_ctx = NULL;
3721
3722 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003723 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003724 data = "<module name=\"example-foo\""
3725 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3726 " xmlns:foo=\"urn:example:foo\""
3727 " xmlns:myext=\"urn:example:extensions\">\n"
David Sedlák8985a142019-07-31 16:43:06 +02003728
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003729 " <yang-version value=\"1\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003730
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003731 " <namespace uri=\"urn:example:foo\"/>\n"
3732 " <prefix value=\"foo\"/>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003733
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003734 " <import module=\"example-extensions\">\n"
3735 " <prefix value=\"myext\"/>\n"
3736 " </import>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003737
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003738 " <list name=\"interface\">\n"
3739 " <key value=\"name\"/>\n"
3740 " <leaf name=\"name\">\n"
3741 " <type name=\"string\"/>\n"
3742 " </leaf>\n"
3743 " <leaf name=\"mtu\">\n"
3744 " <type name=\"uint32\"/>\n"
3745 " <description>\n"
3746 " <text>The MTU of the interface.</text>\n"
3747 " </description>\n"
3748 " <myext:c-define name=\"MY_MTU\"/>\n"
3749 " </leaf>\n"
3750 " </list>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003751 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003752 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003753 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003754 lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
David Sedlák8985a142019-07-31 16:43:06 +02003755 lys_module_free(mod, NULL);
3756 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003757 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003758 mod = NULL;
3759 yin_ctx = NULL;
3760
3761 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003762 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003763 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3764 " <yang-version value=\"1\"/>\n"
3765 " <namespace uri=\"urn:example:foo\"/>\n"
3766 " <prefix value=\"foo\"/>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003767 "</module>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003768 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003769 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003770 lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
David Sedlák6d781b62019-08-02 15:22:52 +02003771 lys_module_free(mod, NULL);
3772 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003773 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003774 mod = NULL;
3775 yin_ctx = NULL;
3776
David Sedlák6d781b62019-08-02 15:22:52 +02003777 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003778 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003779 data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
David Sedlák8985a142019-07-31 16:43:06 +02003780 "</submodule>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +02003781 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003782 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EINVAL);
Radek Iša56ca9e42020-09-08 18:42:00 +02003783 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 +02003784 lys_module_free(mod, NULL);
3785 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003786 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003787
David Sedlák6d781b62019-08-02 15:22:52 +02003788 mod = calloc(1, sizeof *mod);
Radek Iša56ca9e42020-09-08 18:42:00 +02003789 mod->ctx = UTEST_LYCTX;
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003790 data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3791 " <yang-version value=\"1\"/>\n"
3792 " <namespace uri=\"urn:example:foo\"/>\n"
3793 " <prefix value=\"foo\"/>\n"
3794 "</module>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003795 "<module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003796 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Michal Vasko405cc9e2020-12-01 12:01:27 +01003797 assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EVALID);
Radek Iša56ca9e42020-09-08 18:42:00 +02003798 CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
David Sedlák6d781b62019-08-02 15:22:52 +02003799 lys_module_free(mod, NULL);
3800 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003801 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003802 mod = NULL;
3803 yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003804}
3805
3806static void
3807test_yin_parse_submodule(void **state)
3808{
David Sedlák8985a142019-07-31 16:43:06 +02003809 const char *data;
Michal Vaskob36053d2020-03-26 15:49:30 +01003810 struct lys_yin_parser_ctx *yin_ctx = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003811 struct lysp_submodule *submod = NULL;
Michal Vasko63f3d842020-07-08 10:10:14 +02003812 struct ly_in *in;
David Sedlák8985a142019-07-31 16:43:06 +02003813
Radek Iša56ca9e42020-09-08 18:42:00 +02003814 lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name);
Michal Vaskoc3781c32020-10-06 14:04:08 +02003815
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003816 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003817 "<submodule name=\"asub\""
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003818 " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
3819 " xmlns:a=\"urn:a\">\n"
3820 " <yang-version value=\"1\"/>\n"
3821 " <belongs-to module=\"a\">\n"
3822 " <prefix value=\"a_pref\"/>\n"
3823 " </belongs-to>\n"
3824 " <include module=\"atop\"/>\n"
3825 " <feature name=\"fox\"/>\n"
3826 " <notification name=\"bar-notif\">\n"
3827 " <if-feature name=\"bar\"/>\n"
3828 " </notification>\n"
3829 " <notification name=\"fox-notif\">\n"
3830 " <if-feature name=\"fox\"/>\n"
3831 " </notification>\n"
3832 " <augment target-node=\"/a_pref:top\">\n"
3833 " <if-feature name=\"bar\"/>\n"
3834 " <container name=\"bar-sub\"/>\n"
3835 " </augment>\n"
3836 " <augment target-node=\"/top\">\n"
3837 " <container name=\"bar-sub2\"/>\n"
3838 " </augment>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003839 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003840 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003841 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 +02003842 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003843 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003844 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003845 yin_ctx = NULL;
3846 submod = NULL;
3847
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003848 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3849 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3850 " <yang-version value=\"1\"/>\n"
3851 " <belongs-to module=\"a\">\n"
3852 " <prefix value=\"a_pref\"/>\n"
3853 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003854 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003855 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003856 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 +02003857 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003858 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003859 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003860 yin_ctx = NULL;
3861 submod = NULL;
3862
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003863 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
David Sedlák8985a142019-07-31 16:43:06 +02003864 "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
3865 "</module>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003866 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003867 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
3868 CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003869 lysp_module_free((struct lysp_module *)submod);
David Sedlák8985a142019-07-31 16:43:06 +02003870 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003871 ly_in_free(in, 0);
David Sedlák8985a142019-07-31 16:43:06 +02003872 yin_ctx = NULL;
3873 submod = NULL;
3874
Radek Krejcib4ac5a92020-11-23 17:54:33 +01003875 data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3876 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3877 " <yang-version value=\"1\"/>\n"
3878 " <belongs-to module=\"a\">\n"
3879 " <prefix value=\"a_pref\"/>\n"
3880 " </belongs-to>\n"
3881 "</submodule>\n"
3882 "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
3883 " <yang-version value=\"1\"/>\n"
3884 " <belongs-to module=\"a\">\n"
3885 " <prefix value=\"a_pref\"/>\n"
3886 " </belongs-to>\n"
David Sedlák6d781b62019-08-02 15:22:52 +02003887 "</submodule>";
Michal Vasko63f3d842020-07-08 10:10:14 +02003888 assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
Radek Iša56ca9e42020-09-08 18:42:00 +02003889 assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
3890 CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
Michal Vasko5d24f6c2020-10-13 13:49:06 +02003891 lysp_module_free((struct lysp_module *)submod);
David Sedlák6d781b62019-08-02 15:22:52 +02003892 yin_parser_ctx_free(yin_ctx);
Michal Vasko63f3d842020-07-08 10:10:14 +02003893 ly_in_free(in, 0);
David Sedlák6d781b62019-08-02 15:22:52 +02003894 yin_ctx = NULL;
3895 submod = NULL;
David Sedlák8985a142019-07-31 16:43:06 +02003896}
3897
David Sedlák3b4db242018-10-19 16:11:01 +02003898int
3899main(void)
3900{
3901
3902 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +02003903 UTEST(test_yin_match_keyword, setup, teardown),
3904 UTEST(test_yin_parse_element_generic, setup, teardown),
3905 UTEST(test_yin_parse_extension_instance, setup, teardown),
3906 UTEST(test_yin_parse_content, setup, teardown),
3907 UTEST(test_validate_value, setup, teardown),
David Sedlák32488102019-07-15 17:44:10 +02003908
Radek Iša56ca9e42020-09-08 18:42:00 +02003909 UTEST(test_yin_match_argument_name),
3910 cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown),
3911 cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown),
3912 cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown),
3913 cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown),
3914 cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown),
3915 cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown),
3916 cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown),
3917 cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown),
3918 cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown),
3919 cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown),
3920 cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown),
3921 cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown),
3922 cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown),
3923 cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown),
3924 cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown),
3925 cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown),
3926 cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown),
3927 cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown),
3928 cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown),
3929 cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown),
3930 cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown),
3931 cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown),
3932 cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown),
3933 cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown),
3934 cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown),
3935 cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown),
3936 cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown),
3937 cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown),
3938 cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown),
3939 cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown),
3940 cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown),
3941 cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown),
3942 cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown),
3943 cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown),
3944 cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown),
3945 cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown),
3946 cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown),
3947 cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown),
3948 cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown),
3949 cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown),
3950 cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown),
3951 cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown),
3952 cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown),
3953 cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown),
3954 cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown),
3955 cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown),
3956 cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown),
3957 cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown),
3958 cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown),
3959 cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown),
3960 cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown),
3961 cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown),
3962 cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown),
3963 cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown),
3964 cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown),
3965 cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown),
3966 cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown),
3967 cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown),
David Sedlák8985a142019-07-31 16:43:06 +02003968
Radek Iša56ca9e42020-09-08 18:42:00 +02003969 cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown),
3970 cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown),
David Sedlák3b4db242018-10-19 16:11:01 +02003971 };
3972
Radek Iša56ca9e42020-09-08 18:42:00 +02003973 return cmocka_run_group_tests(tests, NULL, NULL);
David Sedlák3b4db242018-10-19 16:11:01 +02003974}