blob: 0d6263d7e1a90260327900c30b6a0d8b1b194a74 [file] [log] [blame]
Radek Krejci80dd33e2018-09-26 15:57:18 +02001/*
2 * @file test_parser_yang.c
3 * @author: Radek Krejci <rkrejci@cesnet.cz>
4 * @brief unit tests for functions from parser_yang.c
5 *
6 * Copyright (c) 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Radek Krejci80dd33e2018-09-26 15:57:18 +020015#include <stdarg.h>
16#include <stddef.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20#include <stdio.h>
21#include <string.h>
22
Radek Krejci2d7a47b2019-05-16 13:34:10 +020023#include "../../src/common.h"
24#include "../../src/tree_schema.h"
25#include "../../src/tree_schema_internal.h"
26
27/* originally static functions from tree_schema_free.c and parser_yang.c */
28void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
29void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
30void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
31void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
32void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
33void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
34void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
35void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
36void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
37void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
Radek Krejcif09e4e82019-06-14 15:08:11 +020038void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
Radek Krejci2d7a47b2019-05-16 13:34:10 +020039
40LY_ERR buf_add_char(struct ly_ctx *ctx, const char **input, size_t len, char **buf, size_t *buf_len, size_t *buf_used);
41LY_ERR buf_store_char(struct lys_parser_ctx *ctx, const char **input, enum yang_arg arg,
42 char **word_p, size_t *word_len, char **word_b, size_t *buf_len, int need_buf);
43LY_ERR get_keyword(struct lys_parser_ctx *ctx, const char **data, enum yang_keyword *kw, char **word_p, size_t *word_len);
44LY_ERR get_argument(struct lys_parser_ctx *ctx, const char **data, enum yang_arg arg,
45 uint16_t *flags, char **word_p, char **word_b, size_t *word_len);
46LY_ERR skip_comment(struct lys_parser_ctx *ctx, const char **data, int comment);
47LY_ERR check_identifierchar(struct lys_parser_ctx *ctx, unsigned int c, int first, int *prefix);
48
49LY_ERR parse_action(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_action **actions);
50LY_ERR parse_any(struct lys_parser_ctx *ctx, const char **data, enum yang_keyword kw, struct lysp_node *parent, struct lysp_node **siblings);
51LY_ERR parse_augment(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_augment **augments);
52LY_ERR parse_case(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
53LY_ERR parse_container(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
54LY_ERR parse_deviate(struct lys_parser_ctx *ctx, const char **data, struct lysp_deviate **deviates);
55LY_ERR parse_deviation(struct lys_parser_ctx *ctx, const char **data, struct lysp_deviation **deviations);
56LY_ERR parse_feature(struct lys_parser_ctx *ctx, const char **data, struct lysp_feature **features);
57LY_ERR parse_grouping(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_grp **groupings);
58LY_ERR parse_choice(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
59LY_ERR parse_identity(struct lys_parser_ctx *ctx, const char **data, struct lysp_ident **identities);
60LY_ERR parse_leaf(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
61LY_ERR parse_leaflist(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
62LY_ERR parse_list(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
63LY_ERR parse_maxelements(struct lys_parser_ctx *ctx, const char **data, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts);
64LY_ERR parse_minelements(struct lys_parser_ctx *ctx, const char **data, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts);
65LY_ERR parse_module(struct lys_parser_ctx *ctx, const char **data, struct lysp_module *mod);
66LY_ERR parse_notif(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_notif **notifs);
67LY_ERR parse_submodule(struct lys_parser_ctx *ctx, const char **data, struct lysp_submodule *submod);
68LY_ERR parse_uses(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
Radek Krejcif09e4e82019-06-14 15:08:11 +020069LY_ERR parse_when(struct lys_parser_ctx *ctx, const char **data, struct lysp_when **when_p);
Radek Krejci80dd33e2018-09-26 15:57:18 +020070
71#define BUFSIZE 1024
72char logbuf[BUFSIZE] = {0};
Radek Krejci9ed7a192018-10-31 16:23:51 +010073int store = -1; /* negative for infinite logging, positive for limited logging */
Radek Krejci80dd33e2018-09-26 15:57:18 +020074
75/* set to 0 to printing error messages to stderr instead of checking them in code */
Radek Krejci70853c52018-10-15 14:46:16 +020076#define ENABLE_LOGGER_CHECKING 1
Radek Krejci80dd33e2018-09-26 15:57:18 +020077
Radek Krejcid5f2b5f2018-10-11 10:54:36 +020078#if ENABLE_LOGGER_CHECKING
Radek Krejci80dd33e2018-09-26 15:57:18 +020079static void
80logger(LY_LOG_LEVEL level, const char *msg, const char *path)
81{
82 (void) level; /* unused */
Radek Krejci9ed7a192018-10-31 16:23:51 +010083 if (store) {
84 if (path && path[0]) {
85 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
86 } else {
87 strncpy(logbuf, msg, BUFSIZE - 1);
88 }
89 if (store > 0) {
90 --store;
91 }
Radek Krejci80dd33e2018-09-26 15:57:18 +020092 }
93}
Radek Krejcid5f2b5f2018-10-11 10:54:36 +020094#endif
Radek Krejci80dd33e2018-09-26 15:57:18 +020095
96static int
97logger_setup(void **state)
98{
99 (void) state; /* unused */
100#if ENABLE_LOGGER_CHECKING
101 ly_set_log_clb(logger, 1);
102#endif
103 return 0;
104}
105
Radek Krejcib1a5dcc2018-11-26 14:50:05 +0100106static int
107logger_teardown(void **state)
108{
109 (void) state; /* unused */
110#if ENABLE_LOGGER_CHECKING
111 if (*state) {
112 fprintf(stderr, "%s\n", logbuf);
113 }
114#endif
115 return 0;
116}
117
Radek Krejci80dd33e2018-09-26 15:57:18 +0200118void
119logbuf_clean(void)
120{
121 logbuf[0] = '\0';
122}
123
124#if ENABLE_LOGGER_CHECKING
125# define logbuf_assert(str) assert_string_equal(logbuf, str)
126#else
127# define logbuf_assert(str)
128#endif
129
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200130#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
131 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
132 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
133 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
134 CLEANUP
135
Radek Krejci44ceedc2018-10-02 15:54:31 +0200136static void
137test_helpers(void **state)
138{
139 (void) state; /* unused */
140
141 const char *str;
Radek Krejci404251e2018-10-09 12:06:44 +0200142 char *buf, *p;
Radek Krejci44ceedc2018-10-02 15:54:31 +0200143 size_t len, size;
144 int prefix;
Radek Krejcie7b95092019-05-15 11:03:07 +0200145 struct lys_parser_ctx ctx;
Radek Krejci44ceedc2018-10-02 15:54:31 +0200146 ctx.ctx = NULL;
147 ctx.line = 1;
148
149 /* storing into buffer */
150 str = "abcd";
151 buf = NULL;
152 size = len = 0;
153 assert_int_equal(LY_SUCCESS, buf_add_char(NULL, &str, 2, &buf, &size, &len));
154 assert_int_not_equal(0, size);
155 assert_int_equal(2, len);
156 assert_string_equal("cd", str);
157 assert_false(strncmp("ab", buf, 2));
158 free(buf);
Radek Krejci404251e2018-10-09 12:06:44 +0200159 buf = NULL;
160
161 /* invalid first characters */
162 len = 0;
163 str = "2invalid";
164 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
165 str = ".invalid";
166 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
167 str = "-invalid";
168 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
169 /* invalid following characters */
170 len = 3; /* number of characters read before the str content */
171 str = "!";
172 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
173 str = ":";
174 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
175 /* valid colon for prefixed identifiers */
176 len = size = 0;
177 p = NULL;
178 str = "x:id";
179 assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0));
180 assert_int_equal(1, len);
181 assert_null(buf);
182 assert_string_equal(":id", str);
183 assert_int_equal('x', p[len - 1]);
184 assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1));
185 assert_int_equal(2, len);
186 assert_string_equal("id", str);
187 assert_int_equal(':', p[len - 1]);
188 free(buf);
Radek Krejci44ceedc2018-10-02 15:54:31 +0200189
190 /* checking identifiers */
191 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, NULL));
192 logbuf_assert("Invalid identifier character ':'. Line number 1.");
193 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, '#', 1, NULL));
194 logbuf_assert("Invalid identifier first character '#'. Line number 1.");
195
196 assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, 'a', 1, &prefix));
197 assert_int_equal(0, prefix);
198 assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, ':', 0, &prefix));
199 assert_int_equal(1, prefix);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200200 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, &prefix));
201 assert_int_equal(1, prefix);
Radek Krejci44ceedc2018-10-02 15:54:31 +0200202 assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, 'b', 0, &prefix));
203 assert_int_equal(2, prefix);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200204 /* second colon is invalid */
205 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, &prefix));
206 logbuf_assert("Invalid identifier character ':'. Line number 1.");
Radek Krejci44ceedc2018-10-02 15:54:31 +0200207}
Radek Krejci80dd33e2018-09-26 15:57:18 +0200208
209static void
210test_comments(void **state)
211{
212 (void) state; /* unused */
213
Radek Krejcie7b95092019-05-15 11:03:07 +0200214 struct lys_parser_ctx ctx;
Radek Krejci80dd33e2018-09-26 15:57:18 +0200215 const char *str, *p;
Radek Krejciefd22f62018-09-27 11:47:58 +0200216 char *word, *buf;
217 size_t len;
Radek Krejci80dd33e2018-09-26 15:57:18 +0200218
Radek Krejci44ceedc2018-10-02 15:54:31 +0200219 ctx.ctx = NULL;
220 ctx.line = 1;
221
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200222 str = " // this is a text of / one * line */ comment\nargument;";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200223 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200224 assert_string_equal("argument;", word);
Radek Krejciefd22f62018-09-27 11:47:58 +0200225 assert_null(buf);
226 assert_int_equal(8, len);
Radek Krejci80dd33e2018-09-26 15:57:18 +0200227
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200228 str = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200229 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200230 assert_string_equal("argument", word);
231 assert_ptr_equal(buf, word);
232 assert_int_equal(8, len);
233 free(word);
Radek Krejci80dd33e2018-09-26 15:57:18 +0200234
235 str = p = " this is one line comment on last line";
Radek Krejci44ceedc2018-10-02 15:54:31 +0200236 assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &str, 1));
Radek Krejci80dd33e2018-09-26 15:57:18 +0200237 assert_true(str[0] == '\0');
238
239 str = p = " this is a not terminated comment x";
Radek Krejci44ceedc2018-10-02 15:54:31 +0200240 assert_int_equal(LY_EVALID, skip_comment(&ctx, &str, 2));
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200241 logbuf_assert("Unexpected end-of-input, non-terminated comment. Line number 5.");
Radek Krejci80dd33e2018-09-26 15:57:18 +0200242 assert_true(str[0] == '\0');
243}
244
Radek Krejciefd22f62018-09-27 11:47:58 +0200245static void
246test_arg(void **state)
247{
248 (void) state; /* unused */
249
Radek Krejcie7b95092019-05-15 11:03:07 +0200250 struct lys_parser_ctx ctx;
Radek Krejciefd22f62018-09-27 11:47:58 +0200251 const char *str;
252 char *word, *buf;
253 size_t len;
254
Radek Krejci44ceedc2018-10-02 15:54:31 +0200255 ctx.ctx = NULL;
256 ctx.line = 1;
257
Radek Krejciefd22f62018-09-27 11:47:58 +0200258 /* missing argument */
259 str = ";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200260 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200261 assert_null(word);
262
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200263 str = "{";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200264 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200265 logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1.");
266
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200267 /* invalid escape sequence */
268 str = "\"\\s\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200269 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200270 logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1.");
271 str = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200272 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200273 assert_int_equal(2, len);
274 assert_string_equal("\\s\'", word);
275 assert_int_equal('\0', str[0]); /* input has been eaten */
276
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200277 /* invalid character after the argument */
278 str = "hello\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200279 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200280 logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
281 str = "hello}";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200282 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200283 logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
284
Radek Krejci4e199f52019-05-28 09:09:28 +0200285 str = "\"\";"; /* empty identifier is not allowed */
286 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
287 logbuf_assert("Statement argument is required. Line number 1.");
288 logbuf_clean();
289 str = "\"\";"; /* empty reference identifier is not allowed */
290 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
291 logbuf_assert("Statement argument is required. Line number 1.");
292
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200293 str = "hello/x\t"; /* slash is not an invalid character */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200294 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200295 assert_int_equal(7, len);
296 assert_string_equal("hello/x\t", word);
297
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200298 assert_null(buf);
Radek Krejciefd22f62018-09-27 11:47:58 +0200299
300 /* different quoting */
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200301 str = "hello ";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200302 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200303 assert_null(buf);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200304 assert_int_equal(5, len);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200305 assert_string_equal("hello ", word);
Radek Krejciefd22f62018-09-27 11:47:58 +0200306
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200307 str = "hello/*comment*/\n";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200308 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200309 assert_null(buf);
310 assert_int_equal(5, len);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200311 assert_false(strncmp("hello", word, len));
312
313
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200314 str = "\"hello\\n\\t\\\"\\\\\";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200315 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200316 assert_null(buf);
317 assert_int_equal(9, len);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200318 assert_string_equal("hello\\n\\t\\\"\\\\\";", word);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200319
320 ctx.indent = 14;
321 str = "\"hello \t\n\t\t world!\"";
322 /* - space and tabs before newline are stripped out
323 * - space and tabs after newline (indentation) are stripped out
324 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200325 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200326 assert_non_null(buf);
327 assert_ptr_equal(word, buf);
328 assert_int_equal(14, len);
329 assert_string_equal("hello\n world!", word);
330 free(buf);
331
332 ctx.indent = 14;
333 str = "\"hello\n \tworld!\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200334 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200335 assert_non_null(buf);
336 assert_ptr_equal(word, buf);
337 assert_int_equal(12, len);
338 assert_string_equal("hello\nworld!", word);
339 free(buf);
Radek Krejciefd22f62018-09-27 11:47:58 +0200340
341 str = "\'hello\'";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200342 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200343 assert_null(buf);
344 assert_int_equal(5, len);
345 assert_false(strncmp("hello", word, 5));
346
347 str = "\"hel\" +\t\n\"lo\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200348 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200349 assert_ptr_equal(word, buf);
350 assert_int_equal(5, len);
351 assert_string_equal("hello", word);
352 free(buf);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200353 str = "\"hel\" +\t\nlo"; /* unquoted the second part */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200354 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200355 logbuf_assert("Both string parts divided by '+' must be quoted. Line number 5.");
Radek Krejciefd22f62018-09-27 11:47:58 +0200356
357 str = "\'he\'\t\n+ \"llo\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200358 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200359 assert_ptr_equal(word, buf);
360 assert_int_equal(5, len);
361 assert_string_equal("hello", word);
362 free(buf);
363
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200364 str = " \t\n\"he\"+\'llo\'";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200365 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200366 assert_ptr_equal(word, buf);
367 assert_int_equal(5, len);
368 assert_string_equal("hello", word);
369 free(buf);
370
Radek Krejci44ceedc2018-10-02 15:54:31 +0200371 /* missing argument */
372 str = ";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200374 logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 7.");
Radek Krejcidcc7b322018-10-11 14:24:02 +0200375}
376
377static void
378test_stmts(void **state)
379{
380 (void) state; /* unused */
381
Radek Krejcie7b95092019-05-15 11:03:07 +0200382 struct lys_parser_ctx ctx;
Radek Krejcidcc7b322018-10-11 14:24:02 +0200383 const char *str, *p;
384 enum yang_keyword kw;
385 char *word;
386 size_t len;
387
388 ctx.ctx = NULL;
389 ctx.line = 1;
390
391 str = "\n// comment\n\tinput\t{";
392 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
393 assert_int_equal(YANG_INPUT, kw);
394 assert_int_equal(5, len);
395 assert_string_equal("input\t{", word);
396 assert_string_equal("\t{", str);
397
398 str = "\t /* comment */\t output\n\t{";
399 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
400 assert_int_equal(YANG_OUTPUT, kw);
401 assert_int_equal(6, len);
402 assert_string_equal("output\n\t{", word);
403 assert_string_equal("\n\t{", str);
Radek Krejciabdd8062019-06-11 16:44:19 +0200404 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
405 assert_int_equal(YANG_LEFT_BRACE, kw);
406 assert_int_equal(1, len);
407 assert_string_equal("{", word);
408 assert_string_equal("", str);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200409
410 str = "/input { "; /* invalid slash */
411 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
412 logbuf_assert("Invalid identifier first character '/'. Line number 4.");
413
414 str = "not-a-statement-nor-extension { "; /* invalid identifier */
415 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
416 logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4.");
417
418 str = "path;"; /* missing sep after the keyword */
419 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
420 logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4.");
421
422 str = "action ";
423 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
424 assert_int_equal(YANG_ACTION, kw);
425 assert_int_equal(6, len);
426 str = "anydata ";
427 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
428 assert_int_equal(YANG_ANYDATA, kw);
429 assert_int_equal(7, len);
430 str = "anyxml ";
431 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
432 assert_int_equal(YANG_ANYXML, kw);
433 assert_int_equal(6, len);
434 str = "argument ";
435 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
436 assert_int_equal(YANG_ARGUMENT, kw);
437 assert_int_equal(8, len);
438 str = "augment ";
439 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
440 assert_int_equal(YANG_AUGMENT, kw);
441 assert_int_equal(7, len);
442 str = "base ";
443 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
444 assert_int_equal(YANG_BASE, kw);
445 assert_int_equal(4, len);
446 str = "belongs-to ";
447 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
448 assert_int_equal(YANG_BELONGS_TO, kw);
449 assert_int_equal(10, len);
450 str = "bit ";
451 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
452 assert_int_equal(YANG_BIT, kw);
453 assert_int_equal(3, len);
454 str = "case ";
455 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
456 assert_int_equal(YANG_CASE, kw);
457 assert_int_equal(4, len);
458 str = "choice ";
459 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
460 assert_int_equal(YANG_CHOICE, kw);
461 assert_int_equal(6, len);
462 str = "config ";
463 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
464 assert_int_equal(YANG_CONFIG, kw);
465 assert_int_equal(6, len);
466 str = "contact ";
467 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
468 assert_int_equal(YANG_CONTACT, kw);
469 assert_int_equal(7, len);
470 str = "container ";
471 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
472 assert_int_equal(YANG_CONTAINER, kw);
473 assert_int_equal(9, len);
474 str = "default ";
475 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
476 assert_int_equal(YANG_DEFAULT, kw);
477 assert_int_equal(7, len);
478 str = "description ";
479 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
480 assert_int_equal(YANG_DESCRIPTION, kw);
481 assert_int_equal(11, len);
482 str = "deviate ";
483 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
484 assert_int_equal(YANG_DEVIATE, kw);
485 assert_int_equal(7, len);
486 str = "deviation ";
487 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
488 assert_int_equal(YANG_DEVIATION, kw);
489 assert_int_equal(9, len);
490 str = "enum ";
491 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
492 assert_int_equal(YANG_ENUM, kw);
493 assert_int_equal(4, len);
494 str = "error-app-tag ";
495 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
496 assert_int_equal(YANG_ERROR_APP_TAG, kw);
497 assert_int_equal(13, len);
498 str = "error-message ";
499 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
500 assert_int_equal(YANG_ERROR_MESSAGE, kw);
501 assert_int_equal(13, len);
502 str = "extension ";
503 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
504 assert_int_equal(YANG_EXTENSION, kw);
505 assert_int_equal(9, len);
506 str = "feature ";
507 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
508 assert_int_equal(YANG_FEATURE, kw);
509 assert_int_equal(7, len);
510 str = "fraction-digits ";
511 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
512 assert_int_equal(YANG_FRACTION_DIGITS, kw);
513 assert_int_equal(15, len);
514 str = "grouping ";
515 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
516 assert_int_equal(YANG_GROUPING, kw);
517 assert_int_equal(8, len);
518 str = "identity ";
519 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
520 assert_int_equal(YANG_IDENTITY, kw);
521 assert_int_equal(8, len);
522 str = "if-feature ";
523 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
524 assert_int_equal(YANG_IF_FEATURE, kw);
525 assert_int_equal(10, len);
526 str = "import ";
527 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
528 assert_int_equal(YANG_IMPORT, kw);
529 assert_int_equal(6, len);
530 str = "include ";
531 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
532 assert_int_equal(YANG_INCLUDE, kw);
533 assert_int_equal(7, len);
534 str = "input{";
535 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
536 assert_int_equal(YANG_INPUT, kw);
537 assert_int_equal(5, len);
538 str = "key ";
539 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
540 assert_int_equal(YANG_KEY, kw);
541 assert_int_equal(3, len);
542 str = "leaf ";
543 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
544 assert_int_equal(YANG_LEAF, kw);
545 assert_int_equal(4, len);
546 str = "leaf-list ";
547 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
548 assert_int_equal(YANG_LEAF_LIST, kw);
549 assert_int_equal(9, len);
550 str = "length ";
551 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
552 assert_int_equal(YANG_LENGTH, kw);
553 assert_int_equal(6, len);
554 str = "list ";
555 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
556 assert_int_equal(YANG_LIST, kw);
557 assert_int_equal(4, len);
558 str = "mandatory ";
559 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
560 assert_int_equal(YANG_MANDATORY, kw);
561 assert_int_equal(9, len);
562 str = "max-elements ";
563 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
564 assert_int_equal(YANG_MAX_ELEMENTS, kw);
565 assert_int_equal(12, len);
566 str = "min-elements ";
567 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
568 assert_int_equal(YANG_MIN_ELEMENTS, kw);
569 assert_int_equal(12, len);
570 str = "modifier ";
571 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
572 assert_int_equal(YANG_MODIFIER, kw);
573 assert_int_equal(8, len);
574 str = "module ";
575 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
576 assert_int_equal(YANG_MODULE, kw);
577 assert_int_equal(6, len);
578 str = "must ";
579 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
580 assert_int_equal(YANG_MUST, kw);
581 assert_int_equal(4, len);
582 str = "namespace ";
583 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
584 assert_int_equal(YANG_NAMESPACE, kw);
585 assert_int_equal(9, len);
586 str = "notification ";
587 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
588 assert_int_equal(YANG_NOTIFICATION, kw);
589 assert_int_equal(12, len);
590 str = "ordered-by ";
591 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
592 assert_int_equal(YANG_ORDERED_BY, kw);
593 assert_int_equal(10, len);
594 str = "organization ";
595 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
596 assert_int_equal(YANG_ORGANIZATION, kw);
597 assert_int_equal(12, len);
598 str = "output ";
599 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
600 assert_int_equal(YANG_OUTPUT, kw);
601 assert_int_equal(6, len);
602 str = "path ";
603 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
604 assert_int_equal(YANG_PATH, kw);
605 assert_int_equal(4, len);
606 str = "pattern ";
607 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
608 assert_int_equal(YANG_PATTERN, kw);
609 assert_int_equal(7, len);
610 str = "position ";
611 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
612 assert_int_equal(YANG_POSITION, kw);
613 assert_int_equal(8, len);
614 str = "prefix ";
615 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
616 assert_int_equal(YANG_PREFIX, kw);
617 assert_int_equal(6, len);
618 str = "presence ";
619 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
620 assert_int_equal(YANG_PRESENCE, kw);
621 assert_int_equal(8, len);
622 str = "range ";
623 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
624 assert_int_equal(YANG_RANGE, kw);
625 assert_int_equal(5, len);
626 str = "reference ";
627 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
628 assert_int_equal(YANG_REFERENCE, kw);
629 assert_int_equal(9, len);
630 str = "refine ";
631 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
632 assert_int_equal(YANG_REFINE, kw);
633 assert_int_equal(6, len);
634 str = "require-instance ";
635 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
636 assert_int_equal(YANG_REQUIRE_INSTANCE, kw);
637 assert_int_equal(16, len);
638 str = "revision ";
639 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
640 assert_int_equal(YANG_REVISION, kw);
641 assert_int_equal(8, len);
642 str = "revision-date ";
643 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
644 assert_int_equal(YANG_REVISION_DATE, kw);
645 assert_int_equal(13, len);
646 str = "rpc ";
647 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
648 assert_int_equal(YANG_RPC, kw);
649 assert_int_equal(3, len);
650 str = "status ";
651 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
652 assert_int_equal(YANG_STATUS, kw);
653 assert_int_equal(6, len);
654 str = "submodule ";
655 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
656 assert_int_equal(YANG_SUBMODULE, kw);
657 assert_int_equal(9, len);
658 str = "type ";
659 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
660 assert_int_equal(YANG_TYPE, kw);
661 assert_int_equal(4, len);
662 str = "typedef ";
663 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
664 assert_int_equal(YANG_TYPEDEF, kw);
665 assert_int_equal(7, len);
666 str = "unique ";
667 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
668 assert_int_equal(YANG_UNIQUE, kw);
669 assert_int_equal(6, len);
670 str = "units ";
671 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
672 assert_int_equal(YANG_UNITS, kw);
673 assert_int_equal(5, len);
674 str = "uses ";
675 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
676 assert_int_equal(YANG_USES, kw);
677 assert_int_equal(4, len);
678 str = "value ";
679 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
680 assert_int_equal(YANG_VALUE, kw);
681 assert_int_equal(5, len);
682 str = "when ";
683 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
684 assert_int_equal(YANG_WHEN, kw);
685 assert_int_equal(4, len);
686 str = "yang-version ";
687 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
688 assert_int_equal(YANG_YANG_VERSION, kw);
689 assert_int_equal(12, len);
690 str = "yin-element ";
691 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
692 assert_int_equal(YANG_YIN_ELEMENT, kw);
693 assert_int_equal(11, len);
Radek Krejci626df482018-10-11 15:06:31 +0200694 str = ";config false;";
695 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
696 assert_int_equal(YANG_SEMICOLON, kw);
697 assert_int_equal(1, len);
698 assert_string_equal("config false;", str);
699 str = "{ config false;";
700 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
701 assert_int_equal(YANG_LEFT_BRACE, kw);
702 assert_int_equal(1, len);
703 assert_string_equal(" config false;", str);
704 str = "}";
705 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
706 assert_int_equal(YANG_RIGHT_BRACE, kw);
707 assert_int_equal(1, len);
708 assert_string_equal("", str);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200709
710 /* geenric extension */
711 str = p = "nacm:default-deny-write;";
712 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
713 assert_int_equal(YANG_CUSTOM, kw);
714 assert_int_equal(23, len);
715 assert_ptr_equal(p, word);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200716}
Radek Krejci44ceedc2018-10-02 15:54:31 +0200717
Radek Krejci05b13982018-11-28 16:22:07 +0100718static void
719test_minmax(void **state)
720{
721 *state = test_minmax;
722
Radek Krejcie7b95092019-05-15 11:03:07 +0200723 struct lys_parser_ctx ctx = {0};
Radek Krejci05b13982018-11-28 16:22:07 +0100724 uint16_t flags = 0;
725 uint32_t value = 0;
726 struct lysp_ext_instance *ext = NULL;
727 const char *str;
728
729 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
730 assert_non_null(ctx.ctx);
731 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100732 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci05b13982018-11-28 16:22:07 +0100733
Radek Krejcidf6cad12018-11-28 17:10:55 +0100734 str = " 1invalid; ...";
Radek Krejci05b13982018-11-28 16:22:07 +0100735 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
Radek Krejcidf6cad12018-11-28 17:10:55 +0100736 logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1.");
Radek Krejci05b13982018-11-28 16:22:07 +0100737
738 flags = value = 0;
739 str = " -1; ...";
740 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
741 logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1.");
742
Radek Krejcidf6cad12018-11-28 17:10:55 +0100743 /* implementation limit */
744 flags = value = 0;
745 str = " 4294967296; ...";
746 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
747 logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1.");
748
Radek Krejci05b13982018-11-28 16:22:07 +0100749 flags = value = 0;
750 str = " 1; ...";
751 assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
752 assert_int_equal(LYS_SET_MIN, flags);
753 assert_int_equal(1, value);
754
755 flags = value = 0;
756 str = " 1 {m:ext;} ...";
757 assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
758 assert_int_equal(LYS_SET_MIN, flags);
759 assert_int_equal(1, value);
760 assert_non_null(ext);
761 FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free);
762 ext = NULL;
763
764 flags = value = 0;
765 str = " 1 {config true;} ...";
766 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
767 logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1.");
768
Radek Krejcidf6cad12018-11-28 17:10:55 +0100769 str = " 1invalid; ...";
Radek Krejci05b13982018-11-28 16:22:07 +0100770 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
Radek Krejcidf6cad12018-11-28 17:10:55 +0100771 logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1.");
Radek Krejci05b13982018-11-28 16:22:07 +0100772
773 flags = value = 0;
774 str = " -1; ...";
775 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
776 logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1.");
777
Radek Krejcidf6cad12018-11-28 17:10:55 +0100778 /* implementation limit */
779 flags = value = 0;
780 str = " 4294967296; ...";
781 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
782 logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1.");
783
Radek Krejci05b13982018-11-28 16:22:07 +0100784 flags = value = 0;
785 str = " 1; ...";
786 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
787 assert_int_equal(LYS_SET_MAX, flags);
788 assert_int_equal(1, value);
789
790 flags = value = 0;
791 str = " unbounded; ...";
792 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
793 assert_int_equal(LYS_SET_MAX, flags);
794 assert_int_equal(0, value);
795
796 flags = value = 0;
797 str = " 1 {m:ext;} ...";
798 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
799 assert_int_equal(LYS_SET_MAX, flags);
800 assert_int_equal(1, value);
801 assert_non_null(ext);
802 FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free);
803 ext = NULL;
804
805 flags = value = 0;
806 str = " 1 {config true;} ...";
807 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
808 logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1.");
809
810 *state = NULL;
811 ly_ctx_destroy(ctx.ctx, NULL);
812}
813
Radek Krejci9fcacc12018-10-11 15:59:11 +0200814static struct lysp_module *
Radek Krejcie7b95092019-05-15 11:03:07 +0200815mod_renew(struct lys_parser_ctx *ctx)
Radek Krejci9fcacc12018-10-11 15:59:11 +0200816{
Radek Krejci40544fa2019-01-11 09:38:37 +0100817 struct lysp_module *mod_p;
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100818 static struct lys_module mod = {0};
819
820 lysc_module_free(mod.compiled, NULL);
821 lysp_module_free(mod.parsed);
822 FREE_STRING(mod.ctx, mod.name);
823 FREE_STRING(mod.ctx, mod.ns);
824 FREE_STRING(mod.ctx, mod.prefix);
825 FREE_STRING(mod.ctx, mod.filepath);
826 FREE_STRING(mod.ctx, mod.org);
827 FREE_STRING(mod.ctx, mod.contact);
828 FREE_STRING(mod.ctx, mod.dsc);
829 FREE_STRING(mod.ctx, mod.ref);
830 memset(&mod, 0, sizeof mod);
831 mod.ctx = ctx->ctx;
832
833 mod_p = calloc(1, sizeof *mod_p);
834 mod.parsed = mod_p;
835 mod_p->mod = &mod;
836 assert_non_null(mod_p);
837 return mod_p;
838}
839
840static struct lysp_submodule *
Radek Krejcie7b95092019-05-15 11:03:07 +0200841submod_renew(struct lys_parser_ctx *ctx, struct lysp_submodule *submod)
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100842{
843 lysp_submodule_free(ctx->ctx, submod);
844 submod = calloc(1, sizeof *submod);
845 assert_non_null(submod);
846 return submod;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200847}
848
Radek Krejcid33273d2018-10-25 14:55:52 +0200849static LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
850 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
851 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
852{
853 *module_data = user_data;
854 *format = LYS_IN_YANG;
855 *free_module_data = NULL;
856 return LY_SUCCESS;
857}
858
Radek Krejci9fcacc12018-10-11 15:59:11 +0200859static void
860test_module(void **state)
861{
Radek Krejci40544fa2019-01-11 09:38:37 +0100862 *state = test_module;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200863
Radek Krejcie7b95092019-05-15 11:03:07 +0200864 struct lys_parser_ctx ctx;
Radek Krejci40544fa2019-01-11 09:38:37 +0100865 struct lysp_module *mod = NULL;
866 struct lysp_submodule *submod = NULL;
867 struct lys_module *m;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200868 const char *str;
869
870 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
871 assert_non_null(ctx.ctx);
872 ctx.line = 1;
Radek Krejcia042ea12018-10-13 07:52:15 +0200873 ctx.indent = 0;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200874
Radek Krejci40544fa2019-01-11 09:38:37 +0100875 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200876
877 /* missing mandatory substatements */
878 str = " name {}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100879 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
880 assert_string_equal("name", mod->mod->name);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200881 logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100882 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200883
884 str = " name {namespace urn:x;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100885 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
886 assert_string_equal("urn:x", mod->mod->ns);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200887 logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100888 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200889
890 str = " name {namespace urn:x;prefix \"x\";}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100891 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
892 assert_string_equal("x", mod->mod->prefix);
Radek Krejci40544fa2019-01-11 09:38:37 +0100893 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200894
Radek Krejci027d5802018-11-14 16:57:28 +0100895#define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
896#define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";"
Radek Krejcia042ea12018-10-13 07:52:15 +0200897#define TEST_NODE(NODETYPE, INPUT, NAME) \
898 str = SCHEMA_BEGINNING INPUT; \
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100899 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \
Radek Krejcia042ea12018-10-13 07:52:15 +0200900 assert_non_null(mod->data); \
901 assert_int_equal(NODETYPE, mod->data->nodetype); \
902 assert_string_equal(NAME, mod->data->name); \
Radek Krejci40544fa2019-01-11 09:38:37 +0100903 mod = mod_renew(&ctx);
Radek Krejcia042ea12018-10-13 07:52:15 +0200904#define TEST_GENERIC(INPUT, TARGET, TEST) \
905 str = SCHEMA_BEGINNING INPUT; \
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100906 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \
Radek Krejcia042ea12018-10-13 07:52:15 +0200907 assert_non_null(TARGET); \
908 TEST; \
Radek Krejci40544fa2019-01-11 09:38:37 +0100909 mod = mod_renew(&ctx);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100910#define TEST_DUP(MEMBER, VALUE1, VALUE2, LINE) \
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200911 TEST_DUP_GENERIC(SCHEMA_BEGINNING, MEMBER, VALUE1, VALUE2, \
Radek Krejci40544fa2019-01-11 09:38:37 +0100912 parse_module, mod, LINE, mod = mod_renew(&ctx))
Radek Krejcia042ea12018-10-13 07:52:15 +0200913
914 /* duplicated namespace, prefix */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100915 TEST_DUP("namespace", "y", "z", "1");
916 TEST_DUP("prefix", "y", "z", "1");
917 TEST_DUP("contact", "a", "b", "1");
918 TEST_DUP("description", "a", "b", "1");
919 TEST_DUP("organization", "a", "b", "1");
920 TEST_DUP("reference", "a", "b", "1");
Radek Krejcia042ea12018-10-13 07:52:15 +0200921
Radek Krejci70853c52018-10-15 14:46:16 +0200922 /* not allowed in module (submodule-specific) */
923 str = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100924 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci70853c52018-10-15 14:46:16 +0200925 logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100926 mod = mod_renew(&ctx);
Radek Krejci70853c52018-10-15 14:46:16 +0200927
Radek Krejcia042ea12018-10-13 07:52:15 +0200928 /* anydata */
929 TEST_NODE(LYS_ANYDATA, "anydata test;}", "test");
930 /* anyxml */
931 TEST_NODE(LYS_ANYXML, "anyxml test;}", "test");
932 /* augment */
933 TEST_GENERIC("augment /somepath;}", mod->augments,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200934 assert_string_equal("/somepath", mod->augments[0].nodeid));
Radek Krejcia042ea12018-10-13 07:52:15 +0200935 /* choice */
936 TEST_NODE(LYS_CHOICE, "choice test;}", "test");
937 /* contact 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100938 TEST_GENERIC("contact \"firstname\" + \n\t\" surname\";}", mod->mod->contact,
939 assert_string_equal("firstname surname", mod->mod->contact));
Radek Krejcia042ea12018-10-13 07:52:15 +0200940 /* container */
941 TEST_NODE(LYS_CONTAINER, "container test;}", "test");
942 /* description 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100943 TEST_GENERIC("description \'some description\';}", mod->mod->dsc,
944 assert_string_equal("some description", mod->mod->dsc));
Radek Krejcia042ea12018-10-13 07:52:15 +0200945 /* deviation */
946 TEST_GENERIC("deviation /somepath {deviate not-supported;}}", mod->deviations,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200947 assert_string_equal("/somepath", mod->deviations[0].nodeid));
Radek Krejcia042ea12018-10-13 07:52:15 +0200948 /* extension */
949 TEST_GENERIC("extension test;}", mod->extensions,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200950 assert_string_equal("test", mod->extensions[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200951 /* feature */
952 TEST_GENERIC("feature test;}", mod->features,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200953 assert_string_equal("test", mod->features[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200954 /* grouping */
955 TEST_GENERIC("grouping grp;}", mod->groupings,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200956 assert_string_equal("grp", mod->groupings[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200957 /* identity */
958 TEST_GENERIC("identity test;}", mod->identities,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200959 assert_string_equal("test", mod->identities[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200960 /* import */
Radek Krejci086c7132018-10-26 15:29:04 +0200961 ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
962 TEST_GENERIC("import zzz {prefix z;}}", mod->imports,
963 assert_string_equal("zzz", mod->imports[0].name));
Radek Krejci70853c52018-10-15 14:46:16 +0200964
Radek Krejcia042ea12018-10-13 07:52:15 +0200965 /* import - prefix collision */
Radek Krejci086c7132018-10-26 15:29:04 +0200966 str = SCHEMA_BEGINNING "import zzz {prefix x;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100967 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci70853c52018-10-15 14:46:16 +0200968 logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100969 mod = mod_renew(&ctx);
Radek Krejci086c7132018-10-26 15:29:04 +0200970 str = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100971 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci086c7132018-10-26 15:29:04 +0200972 logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100973 mod = mod_renew(&ctx);
Radek Krejci086c7132018-10-26 15:29:04 +0200974 str = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}";
975 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
976 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
977 logbuf_assert("Single revision of the module \"zzz\" referred twice.");
Radek Krejci70853c52018-10-15 14:46:16 +0200978
Radek Krejcia042ea12018-10-13 07:52:15 +0200979 /* include */
Radek Krejci9ed7a192018-10-31 16:23:51 +0100980 store = 1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200981 ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
Radek Krejci086c7132018-10-26 15:29:04 +0200982 str = "module" SCHEMA_BEGINNING "include xxx;}";
983 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
984 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100985 logbuf_assert("Input data contains module in situation when a submodule is expected.");
Radek Krejci9ed7a192018-10-31 16:23:51 +0100986 store = -1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200987
Radek Krejci9ed7a192018-10-31 16:23:51 +0100988 store = 1;
Radek Krejci313d9902018-11-08 09:42:58 +0100989 ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
Radek Krejci086c7132018-10-26 15:29:04 +0200990 str = "module" SCHEMA_BEGINNING "include xxx;}";
991 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
992 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
993 logbuf_assert("Included \"xxx\" submodule from \"name\" belongs-to a different module \"wrong-name\".");
Radek Krejci9ed7a192018-10-31 16:23:51 +0100994 store = -1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200995
Radek Krejci313d9902018-11-08 09:42:58 +0100996 ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
Radek Krejcid33273d2018-10-25 14:55:52 +0200997 TEST_GENERIC("include xxx;}", mod->includes,
Radek Krejci086c7132018-10-26 15:29:04 +0200998 assert_string_equal("xxx", mod->includes[0].name));
Radek Krejcid33273d2018-10-25 14:55:52 +0200999
Radek Krejcia042ea12018-10-13 07:52:15 +02001000 /* leaf */
1001 TEST_NODE(LYS_LEAF, "leaf test {type string;}}", "test");
1002 /* leaf-list */
1003 TEST_NODE(LYS_LEAFLIST, "leaf-list test {type string;}}", "test");
1004 /* list */
1005 TEST_NODE(LYS_LIST, "list test {key a;leaf a {type string;}}}", "test");
1006 /* notification */
1007 TEST_GENERIC("notification test;}", mod->notifs,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001008 assert_string_equal("test", mod->notifs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +02001009 /* organization 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001010 TEST_GENERIC("organization \"CESNET a.l.e.\";}", mod->mod->org,
1011 assert_string_equal("CESNET a.l.e.", mod->mod->org));
Radek Krejcia042ea12018-10-13 07:52:15 +02001012 /* reference 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001013 TEST_GENERIC("reference RFC7950;}", mod->mod->ref,
1014 assert_string_equal("RFC7950", mod->mod->ref));
Radek Krejcia042ea12018-10-13 07:52:15 +02001015 /* revision */
1016 TEST_GENERIC("revision 2018-10-12;}", mod->revs,
Radek Krejcib7db73a2018-10-24 14:18:40 +02001017 assert_string_equal("2018-10-12", mod->revs[0].date));
Radek Krejcia042ea12018-10-13 07:52:15 +02001018 /* rpc */
1019 TEST_GENERIC("rpc test;}", mod->rpcs,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001020 assert_string_equal("test", mod->rpcs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +02001021 /* typedef */
1022 TEST_GENERIC("typedef test{type string;}}", mod->typedefs,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001023 assert_string_equal("test", mod->typedefs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +02001024 /* uses */
1025 TEST_NODE(LYS_USES, "uses test;}", "test");
1026 /* yang-version */
Radek Krejci027d5802018-11-14 16:57:28 +01001027 str = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001028 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejcia042ea12018-10-13 07:52:15 +02001029 logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001030 mod = mod_renew(&ctx);
Radek Krejci027d5802018-11-14 16:57:28 +01001031 str = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001032 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejcia042ea12018-10-13 07:52:15 +02001033 logbuf_assert("Duplicate keyword \"yang-version\". Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001034 mod = mod_renew(&ctx);
Radek Krejci027d5802018-11-14 16:57:28 +01001035 str = SCHEMA_BEGINNING2 "yang-version 1.0;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001036 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
1037 assert_int_equal(1, mod->mod->version);
Radek Krejci40544fa2019-01-11 09:38:37 +01001038 mod = mod_renew(&ctx);
Radek Krejci027d5802018-11-14 16:57:28 +01001039 str = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001040 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
1041 assert_int_equal(2, mod->mod->version);
Radek Krejci40544fa2019-01-11 09:38:37 +01001042 mod = mod_renew(&ctx);
1043
1044 str = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
1045 m = mod->mod;
1046 free(mod);
1047 m->parsed = NULL;
1048 assert_int_equal(LY_EVALID, yang_parse_module(&ctx, str, m));
Radek Krejci0a1d0d42019-05-16 15:14:51 +02001049 logbuf_assert("Trailing garbage \"module q {names...\" after module, expected end-of-input. Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001050 mod = mod_renew(&ctx);
1051
1052 str = "prefix " SCHEMA_BEGINNING "}";
1053 m = mod->mod;
1054 free(mod);
1055 m->parsed = NULL;
1056 assert_int_equal(LY_EVALID, yang_parse_module(&ctx, str, m));
1057 logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 3.");
1058 mod = mod_renew(&ctx);
Radek Krejci09306362018-10-15 15:26:01 +02001059
Radek Krejci156ccaf2018-10-15 15:49:17 +02001060 /* extensions */
1061 TEST_GENERIC("prefix:test;}", mod->exts,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001062 assert_string_equal("prefix:test", mod->exts[0].name);
1063 assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt));
Radek Krejci40544fa2019-01-11 09:38:37 +01001064 mod = mod_renew(&ctx);
Radek Krejci156ccaf2018-10-15 15:49:17 +02001065
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001066 /* invalid substatement */
1067 str = SCHEMA_BEGINNING "must false;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001068 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001069 logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001070 mod = mod_renew(&ctx);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001071
Radek Krejci09306362018-10-15 15:26:01 +02001072 /* submodule */
Radek Krejci40544fa2019-01-11 09:38:37 +01001073 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001074
1075 /* missing mandatory substatements */
1076 str = " subname {}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001077 lydict_remove(ctx.ctx, submod->name);
1078 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
1079 assert_string_equal("subname", submod->name);
Radek Krejci09306362018-10-15 15:26:01 +02001080 logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3.");
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001081 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001082
Radek Krejci313d9902018-11-08 09:42:58 +01001083 str = " subname {belongs-to name {prefix x;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001084 lydict_remove(ctx.ctx, submod->name);
1085 assert_int_equal(LY_SUCCESS, parse_submodule(&ctx, &str, submod));
1086 assert_string_equal("name", submod->belongsto);
1087 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001088
1089#undef SCHEMA_BEGINNING
Radek Krejci313d9902018-11-08 09:42:58 +01001090#define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}"
Radek Krejci09306362018-10-15 15:26:01 +02001091
1092 /* duplicated namespace, prefix */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001093 str = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ...";
1094 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); \
1095 logbuf_assert("Duplicate keyword \"belongs-to\". Line number 3."); \
1096 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001097
1098 /* not allowed in submodule (module-specific) */
1099 str = SCHEMA_BEGINNING "namespace \"urn:z\";}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001100 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
Radek Krejci09306362018-10-15 15:26:01 +02001101 logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3.");
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001102 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001103 str = SCHEMA_BEGINNING "prefix m;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001104 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
Radek Krejci09306362018-10-15 15:26:01 +02001105 logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3.");
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001106 submod = submod_renew(&ctx, submod);
Radek Krejcia042ea12018-10-13 07:52:15 +02001107
Radek Krejci40544fa2019-01-11 09:38:37 +01001108 str = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
1109 lysp_submodule_free(ctx.ctx, submod);
1110 submod = NULL;
1111 assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx, str, &submod));
Radek Krejci0a1d0d42019-05-16 15:14:51 +02001112 logbuf_assert("Trailing garbage \"module q {names...\" after submodule, expected end-of-input. Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001113
1114 str = "prefix " SCHEMA_BEGINNING "}";
1115 assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx, str, &submod));
1116 logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 3.");
1117 submod = submod_renew(&ctx, submod);
1118
Radek Krejcia042ea12018-10-13 07:52:15 +02001119#undef TEST_GENERIC
1120#undef TEST_NODE
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001121#undef TEST_DUP
Radek Krejcia042ea12018-10-13 07:52:15 +02001122#undef SCHEMA_BEGINNING
1123
Radek Krejci9fcacc12018-10-11 15:59:11 +02001124 lysp_module_free(mod);
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001125 lysp_submodule_free(ctx.ctx, submod);
Radek Krejci9fcacc12018-10-11 15:59:11 +02001126 ly_ctx_destroy(ctx.ctx, NULL);
Radek Krejci40544fa2019-01-11 09:38:37 +01001127
1128 *state = NULL;
Radek Krejciefd22f62018-09-27 11:47:58 +02001129}
1130
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001131static void
1132test_identity(void **state)
1133{
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001134 *state = test_identity;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001135
Radek Krejcie7b95092019-05-15 11:03:07 +02001136 struct lys_parser_ctx ctx;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001137 struct lysp_ident *ident = NULL;
1138 const char *str;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001139
1140 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1141 assert_non_null(ctx.ctx);
1142 ctx.line = 1;
1143 ctx.indent = 0;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001144 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001145
1146 /* invalid cardinality */
1147#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001148 TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_identity, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001149 &ident, "1", FREE_ARRAY(ctx.ctx, ident, lysp_ident_free); ident = NULL)
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001150
Radek Krejci38222632019-02-12 16:55:05 +01001151 TEST_DUP("description", "a", "b");
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001152 TEST_DUP("reference", "a", "b");
1153 TEST_DUP("status", "current", "obsolete");
1154
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001155 /* full content */
1156 str = " test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ...";
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001157 assert_int_equal(LY_SUCCESS, parse_identity(&ctx, &str, &ident));
1158 assert_non_null(ident);
1159 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001160 FREE_ARRAY(ctx.ctx, ident, lysp_ident_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001161 ident = NULL;
1162
1163 /* invalid substatement */
1164 str = " test {organization XXX;}";
1165 assert_int_equal(LY_EVALID, parse_identity(&ctx, &str, &ident));
1166 logbuf_assert("Invalid keyword \"organization\" as a child of \"identity\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001167 FREE_ARRAY(ctx.ctx, ident, lysp_ident_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001168 ident = NULL;
1169
1170#undef TEST_DUP
1171
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001172 *state = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001173 ly_ctx_destroy(ctx.ctx, NULL);
1174}
1175
1176static void
1177test_feature(void **state)
1178{
1179 (void) state; /* unused */
1180
Radek Krejcie7b95092019-05-15 11:03:07 +02001181 struct lys_parser_ctx ctx;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001182 struct lysp_feature *features = NULL;
1183 const char *str;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001184
1185 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1186 assert_non_null(ctx.ctx);
1187 ctx.line = 1;
1188 ctx.indent = 0;
1189
1190 /* invalid cardinality */
1191#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1192 TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_feature, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001193 &features, "1", FREE_ARRAY(ctx.ctx, features, lysp_feature_free); features = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001194
1195 TEST_DUP("description", "a", "b");
1196 TEST_DUP("reference", "a", "b");
1197 TEST_DUP("status", "current", "obsolete");
1198
1199 /* full content */
1200 str = " test {description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ...";
1201 assert_int_equal(LY_SUCCESS, parse_feature(&ctx, &str, &features));
1202 assert_non_null(features);
1203 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001204 FREE_ARRAY(ctx.ctx, features, lysp_feature_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001205 features = NULL;
1206
1207 /* invalid substatement */
1208 str = " test {organization XXX;}";
1209 assert_int_equal(LY_EVALID, parse_feature(&ctx, &str, &features));
1210 logbuf_assert("Invalid keyword \"organization\" as a child of \"feature\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001211 FREE_ARRAY(ctx.ctx, features, lysp_feature_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001212 features = NULL;
1213
1214#undef TEST_DUP
1215
1216 ly_ctx_destroy(ctx.ctx, NULL);
1217}
1218
1219static void
1220test_deviation(void **state)
1221{
1222 (void) state; /* unused */
1223
Radek Krejcie7b95092019-05-15 11:03:07 +02001224 struct lys_parser_ctx ctx;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001225 struct lysp_deviation *d = NULL;
1226 const char *str;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001227
1228 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1229 assert_non_null(ctx.ctx);
1230 ctx.line = 1;
1231 ctx.indent = 0;
1232
1233 /* invalid cardinality */
1234#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1235 TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001236 &d, "1", FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); d = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001237
1238 TEST_DUP("description", "a", "b");
1239 TEST_DUP("reference", "a", "b");
1240
1241 /* full content */
1242 str = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
1243 assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &str, &d));
1244 assert_non_null(d);
1245 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001246 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001247 d = NULL;
1248
1249 /* missing mandatory substatement */
1250 str = " test {description text;}";
1251 assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
1252 logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001253 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001254 d = NULL;
1255
1256 /* invalid substatement */
1257 str = " test {deviate not-supported; status obsolete;}";
1258 assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
1259 logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001260 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001261 d = NULL;
1262
1263#undef TEST_DUP
1264
1265 ly_ctx_destroy(ctx.ctx, NULL);
1266}
1267
1268static void
1269test_deviate(void **state)
1270{
1271 (void) state; /* unused */
1272
Radek Krejcie7b95092019-05-15 11:03:07 +02001273 struct lys_parser_ctx ctx;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001274 struct lysp_deviate *d = NULL;
1275 const char *str;
1276
1277 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1278 assert_non_null(ctx.ctx);
1279 ctx.line = 1;
1280 ctx.indent = 0;
1281
1282 /* invalid cardinality */
1283#define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \
1284 TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001285 &d, "1", lysp_deviate_free(ctx.ctx, d); free(d); d = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001286
1287 TEST_DUP("add", "config", "true", "false");
1288 TEST_DUP("replace", "default", "int8", "uint8");
1289 TEST_DUP("add", "mandatory", "true", "false");
1290 TEST_DUP("add", "max-elements", "1", "2");
1291 TEST_DUP("add", "min-elements", "1", "2");
1292 TEST_DUP("replace", "type", "int8", "uint8");
1293 TEST_DUP("add", "units", "kilometers", "miles");
1294
1295 /* full contents */
1296 str = " not-supported {prefix:ext;} ...";
1297 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1298 assert_non_null(d);
1299 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001300 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001301 str = " add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
1302 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1303 assert_non_null(d);
1304 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001305 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001306 str = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
1307 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1308 assert_non_null(d);
1309 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001310 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001311 str = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
1312 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1313 assert_non_null(d);
1314 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001315 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001316
1317 /* invalid substatements */
1318#define TEST_NOT_SUP(DEV, STMT, VALUE) \
1319 str = " "DEV" {"STMT" "VALUE";}..."; \
1320 assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); \
1321 logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001322 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001323
1324 TEST_NOT_SUP("not-supported", "units", "meters");
1325 TEST_NOT_SUP("not-supported", "must", "1");
1326 TEST_NOT_SUP("not-supported", "unique", "x");
1327 TEST_NOT_SUP("not-supported", "default", "a");
1328 TEST_NOT_SUP("not-supported", "config", "true");
1329 TEST_NOT_SUP("not-supported", "mandatory", "true");
1330 TEST_NOT_SUP("not-supported", "min-elements", "1");
1331 TEST_NOT_SUP("not-supported", "max-elements", "2");
1332 TEST_NOT_SUP("not-supported", "type", "string");
1333 TEST_NOT_SUP("add", "type", "string");
1334 TEST_NOT_SUP("delete", "config", "true");
1335 TEST_NOT_SUP("delete", "mandatory", "true");
1336 TEST_NOT_SUP("delete", "min-elements", "1");
1337 TEST_NOT_SUP("delete", "max-elements", "2");
1338 TEST_NOT_SUP("delete", "type", "string");
1339 TEST_NOT_SUP("replace", "must", "1");
1340 TEST_NOT_SUP("replace", "unique", "a");
1341
1342 str = " nonsence; ...";
1343 assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d));
1344 logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1.");
1345 assert_null(d);
1346
1347#undef TEST_NOT_SUP
1348#undef TEST_DUP
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001349
1350 ly_ctx_destroy(ctx.ctx, NULL);
1351}
1352
Radek Krejci8c370832018-11-02 15:10:03 +01001353static void
1354test_container(void **state)
1355{
1356 (void) state; /* unused */
1357
Radek Krejcie7b95092019-05-15 11:03:07 +02001358 struct lys_parser_ctx ctx = {0};
Radek Krejci8c370832018-11-02 15:10:03 +01001359 struct lysp_node_container *c = NULL;
1360 const char *str;
1361
1362 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1363 assert_non_null(ctx.ctx);
1364 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001365 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci8c370832018-11-02 15:10:03 +01001366
1367 /* invalid cardinality */
1368#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1369 str = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1370 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); \
1371 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001372 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001373
1374 TEST_DUP("config", "true", "false");
1375 TEST_DUP("description", "text1", "text2");
1376 TEST_DUP("presence", "true", "false");
1377 TEST_DUP("reference", "1", "2");
1378 TEST_DUP("status", "current", "obsolete");
1379 TEST_DUP("when", "true", "false");
1380#undef TEST_DUP
1381
1382 /* full content */
Radek Krejci313d9902018-11-08 09:42:58 +01001383 str = "cont {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; leaf l {type string;}"
1384 "leaf-list ll {type string;} list li;must 'expr';notification not; presence true; reference test;status current;typedef t {type int8;}uses g;when true;m:ext;} ...";
Radek Krejci8c370832018-11-02 15:10:03 +01001385 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1386 assert_non_null(c);
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001387 assert_int_equal(LYS_CONTAINER, c->nodetype);
1388 assert_string_equal("cont", c->name);
Radek Krejci8c370832018-11-02 15:10:03 +01001389 assert_non_null(c->actions);
1390 assert_non_null(c->child);
1391 assert_string_equal("test", c->dsc);
1392 assert_non_null(c->exts);
1393 assert_non_null(c->groupings);
1394 assert_non_null(c->iffeatures);
1395 assert_non_null(c->musts);
1396 assert_non_null(c->notifs);
1397 assert_string_equal("true", c->presence);
1398 assert_string_equal("test", c->ref);
1399 assert_non_null(c->typedefs);
1400 assert_non_null(c->when);
1401 assert_null(c->parent);
1402 assert_null(c->next);
1403 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags);
Radek Krejci313d9902018-11-08 09:42:58 +01001404 ly_set_erase(&ctx.tpdfs_nodes, NULL);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001405 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001406
1407 /* invalid */
1408 str = " cont {augment /root;} ...";
1409 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1410 logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1.");
Radek Krejci4f28eda2018-11-12 11:46:16 +01001411 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001412 str = " cont {nonsence true;} ...";
1413 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1414 logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1.");
Radek Krejci4f28eda2018-11-12 11:46:16 +01001415 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001416
Radek Krejcif538ce52019-03-05 10:46:14 +01001417 ctx.mod_version = 1; /* simulate YANG 1.0 */
1418 str = " cont {action x;} ...";
1419 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1420 logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1421 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
1422
Radek Krejci8c370832018-11-02 15:10:03 +01001423 ly_ctx_destroy(ctx.ctx, NULL);
1424}
1425
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001426static void
1427test_leaf(void **state)
1428{
1429 *state = test_leaf;
1430
Radek Krejcie7b95092019-05-15 11:03:07 +02001431 struct lys_parser_ctx ctx = {0};
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001432 struct lysp_node_leaf *l = NULL;
1433 const char *str;
1434
1435 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1436 assert_non_null(ctx.ctx);
1437 ctx.line = 1;
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001438 //ctx.mod->version = 2; /* simulate YANG 1.1 */
1439
1440 /* invalid cardinality */
1441#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1442 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1443 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); \
1444 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1445 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1446
1447 TEST_DUP("config", "true", "false");
1448 TEST_DUP("default", "x", "y");
1449 TEST_DUP("description", "text1", "text2");
1450 TEST_DUP("mandatory", "true", "false");
1451 TEST_DUP("reference", "1", "2");
1452 TEST_DUP("status", "current", "obsolete");
Radek Krejci0e5d8382018-11-28 16:37:53 +01001453 TEST_DUP("type", "int8", "uint8");
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001454 TEST_DUP("units", "text1", "text2");
1455 TEST_DUP("when", "true", "false");
1456#undef TEST_DUP
1457
1458 /* full content - without mandatory which is mutual exclusive with default */
1459 str = "l {config false;default \"xxx\";description test;if-feature f;"
1460 "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ...";
1461 assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1462 assert_non_null(l);
1463 assert_int_equal(LYS_LEAF, l->nodetype);
1464 assert_string_equal("l", l->name);
1465 assert_string_equal("test", l->dsc);
1466 assert_string_equal("xxx", l->dflt);
1467 assert_string_equal("yyy", l->units);
1468 assert_string_equal("string", l->type.name);
1469 assert_non_null(l->exts);
1470 assert_non_null(l->iffeatures);
1471 assert_non_null(l->musts);
1472 assert_string_equal("test", l->ref);
1473 assert_non_null(l->when);
1474 assert_null(l->parent);
1475 assert_null(l->next);
1476 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags);
1477 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1478
1479 /* full content - now with mandatory */
1480 str = "l {mandatory true; type string;} ...";
1481 assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1482 assert_non_null(l);
1483 assert_int_equal(LYS_LEAF, l->nodetype);
1484 assert_string_equal("l", l->name);
1485 assert_string_equal("string", l->type.name);
1486 assert_int_equal(LYS_MAND_TRUE, l->flags);
1487 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1488
1489 /* invalid */
1490 str = " l {mandatory true; default xx; type string;} ...";
1491 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
Radek Krejcia9026eb2018-12-12 16:04:47 +01001492 logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"leaf\". Line number 1.");
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001493 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1494
1495 str = " l {description \"missing type\";} ...";
1496 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1497 logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1.");
1498 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1499
1500 *state = NULL;
1501 ly_ctx_destroy(ctx.ctx, NULL);
1502}
1503
Radek Krejci0e5d8382018-11-28 16:37:53 +01001504static void
1505test_leaflist(void **state)
1506{
1507 *state = test_leaf;
1508
Radek Krejcie7b95092019-05-15 11:03:07 +02001509 struct lys_parser_ctx ctx = {0};
Radek Krejci0e5d8382018-11-28 16:37:53 +01001510 struct lysp_node_leaflist *ll = NULL;
1511 const char *str;
1512
1513 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1514 assert_non_null(ctx.ctx);
1515 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001516 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001517
1518 /* invalid cardinality */
1519#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1520 str = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1521 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); \
1522 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1523 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1524
1525 TEST_DUP("config", "true", "false");
1526 TEST_DUP("description", "text1", "text2");
1527 TEST_DUP("max-elements", "10", "20");
1528 TEST_DUP("min-elements", "10", "20");
1529 TEST_DUP("ordered-by", "user", "system");
1530 TEST_DUP("reference", "1", "2");
1531 TEST_DUP("status", "current", "obsolete");
1532 TEST_DUP("type", "int8", "uint8");
1533 TEST_DUP("units", "text1", "text2");
1534 TEST_DUP("when", "true", "false");
1535#undef TEST_DUP
1536
1537 /* full content - without min-elements which is mutual exclusive with default */
1538 str = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
1539 "max-elements 10;must 'expr';ordered-by user;reference test;"
1540 "status current;type string; units zzz;when true;m:ext;} ...";
1541 assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1542 assert_non_null(ll);
1543 assert_int_equal(LYS_LEAFLIST, ll->nodetype);
1544 assert_string_equal("ll", ll->name);
1545 assert_string_equal("test", ll->dsc);
1546 assert_non_null(ll->dflts);
1547 assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts));
1548 assert_string_equal("xxx", ll->dflts[0]);
1549 assert_string_equal("yyy", ll->dflts[1]);
1550 assert_string_equal("zzz", ll->units);
1551 assert_int_equal(10, ll->max);
1552 assert_int_equal(0, ll->min);
1553 assert_string_equal("string", ll->type.name);
1554 assert_non_null(ll->exts);
1555 assert_non_null(ll->iffeatures);
1556 assert_non_null(ll->musts);
1557 assert_string_equal("test", ll->ref);
1558 assert_non_null(ll->when);
1559 assert_null(ll->parent);
1560 assert_null(ll->next);
1561 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
1562 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1563
1564 /* full content - now with min-elements */
1565 str = "ll {min-elements 10; type string;} ...";
1566 assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1567 assert_non_null(ll);
1568 assert_int_equal(LYS_LEAFLIST, ll->nodetype);
1569 assert_string_equal("ll", ll->name);
1570 assert_string_equal("string", ll->type.name);
1571 assert_int_equal(0, ll->max);
1572 assert_int_equal(10, ll->min);
1573 assert_int_equal(LYS_SET_MIN, ll->flags);
1574 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1575
1576 /* invalid */
1577 str = " ll {min-elements 1; default xx; type string;} ...";
1578 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
Radek Krejcia9026eb2018-12-12 16:04:47 +01001579 logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1.");
Radek Krejci0e5d8382018-11-28 16:37:53 +01001580 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1581
1582 str = " ll {description \"missing type\";} ...";
1583 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1584 logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1.");
1585 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1586
Radek Krejcidf6cad12018-11-28 17:10:55 +01001587 str = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */
1588 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1589 logbuf_assert("Invalid combination of min-elements and max-elements: min value 10 is bigger than the max value 1. Line number 1.");
1590 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1591
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001592 ctx.mod_version = 1; /* simulate YANG 1.0 - default statement is not allowed */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001593 str = " ll {default xx; type string;} ...";
1594 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1595 logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1596 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1597
1598 *state = NULL;
1599 ly_ctx_destroy(ctx.ctx, NULL);
1600}
1601
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001602static void
1603test_list(void **state)
1604{
1605 *state = test_list;
1606
Radek Krejcie7b95092019-05-15 11:03:07 +02001607 struct lys_parser_ctx ctx = {0};
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001608 struct lysp_node_list *l = NULL;
1609 const char *str;
1610
1611 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1612 assert_non_null(ctx.ctx);
1613 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001614 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001615
1616 /* invalid cardinality */
1617#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1618 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1619 assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); \
1620 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1621 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1622
1623 TEST_DUP("config", "true", "false");
1624 TEST_DUP("description", "text1", "text2");
1625 TEST_DUP("key", "one", "two");
1626 TEST_DUP("max-elements", "10", "20");
1627 TEST_DUP("min-elements", "10", "20");
1628 TEST_DUP("ordered-by", "user", "system");
1629 TEST_DUP("reference", "1", "2");
1630 TEST_DUP("status", "current", "obsolete");
1631 TEST_DUP("when", "true", "false");
1632#undef TEST_DUP
1633
1634 /* full content */
1635 str = "l {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; key l; leaf l {type string;}"
1636 "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;"
1637 "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ...";
1638 assert_int_equal(LY_SUCCESS, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l));
1639 assert_non_null(l);
1640 assert_int_equal(LYS_LIST, l->nodetype);
1641 assert_string_equal("l", l->name);
1642 assert_string_equal("test", l->dsc);
1643 assert_string_equal("l", l->key);
1644 assert_non_null(l->uniques);
1645 assert_int_equal(2, LY_ARRAY_SIZE(l->uniques));
1646 assert_string_equal("xxx", l->uniques[0]);
1647 assert_string_equal("yyy", l->uniques[1]);
1648 assert_int_equal(10, l->max);
1649 assert_int_equal(1, l->min);
1650 assert_non_null(l->exts);
1651 assert_non_null(l->iffeatures);
1652 assert_non_null(l->musts);
1653 assert_string_equal("test", l->ref);
1654 assert_non_null(l->when);
1655 assert_null(l->parent);
1656 assert_null(l->next);
1657 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, l->flags);
1658 ly_set_erase(&ctx.tpdfs_nodes, NULL);
1659 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1660
Radek Krejcif538ce52019-03-05 10:46:14 +01001661 /* invalid content */
1662 ctx.mod_version = 1; /* simulate YANG 1.0 */
1663 str = "l {action x;} ...";
1664 assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l));
1665 logbuf_assert("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1666 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1667
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001668 *state = NULL;
1669 ly_ctx_destroy(ctx.ctx, NULL);
1670}
1671
Radek Krejci056d0a82018-12-06 16:57:25 +01001672static void
1673test_choice(void **state)
1674{
1675 *state = test_choice;
1676
Radek Krejcie7b95092019-05-15 11:03:07 +02001677 struct lys_parser_ctx ctx = {0};
Radek Krejci056d0a82018-12-06 16:57:25 +01001678 struct lysp_node_choice *ch = NULL;
1679 const char *str;
1680
1681 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1682 assert_non_null(ctx.ctx);
1683 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001684 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci056d0a82018-12-06 16:57:25 +01001685
1686 /* invalid cardinality */
1687#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1688 str = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1689 assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); \
1690 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1691 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1692
1693 TEST_DUP("config", "true", "false");
1694 TEST_DUP("default", "a", "b");
1695 TEST_DUP("description", "text1", "text2");
1696 TEST_DUP("mandatory", "true", "false");
1697 TEST_DUP("reference", "1", "2");
1698 TEST_DUP("status", "current", "obsolete");
1699 TEST_DUP("when", "true", "false");
1700#undef TEST_DUP
1701
Radek Krejcia9026eb2018-12-12 16:04:47 +01001702 /* full content - without default due to a collision with mandatory */
1703 str = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;description test;if-feature f;leaf l {type string;}"
Radek Krejci056d0a82018-12-06 16:57:25 +01001704 "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
1705 assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
1706 assert_non_null(ch);
1707 assert_int_equal(LYS_CHOICE, ch->nodetype);
1708 assert_string_equal("ch", ch->name);
1709 assert_string_equal("test", ch->dsc);
1710 assert_non_null(ch->exts);
1711 assert_non_null(ch->iffeatures);
1712 assert_string_equal("test", ch->ref);
1713 assert_non_null(ch->when);
1714 assert_null(ch->parent);
1715 assert_null(ch->next);
1716 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags);
1717 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1718
Radek Krejcia9026eb2018-12-12 16:04:47 +01001719 /* full content - the default missing from the previous node */
1720 str = "ch {default c;case c;} ...";
1721 assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
1722 assert_non_null(ch);
1723 assert_int_equal(LYS_CHOICE, ch->nodetype);
1724 assert_string_equal("ch", ch->name);
1725 assert_string_equal("c", ch->dflt);
1726 assert_int_equal(0, ch->flags);
1727 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1728
1729 /* invalid content */
1730 str = "ch {mandatory true; default c1; case c1 {leaf x{type string;}}} ...";
1731 assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
1732 logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"choice\". Line number 1.");
1733 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1734
1735 *state = NULL;
1736 ly_ctx_destroy(ctx.ctx, NULL);
1737}
1738
1739static void
1740test_case(void **state)
1741{
1742 *state = test_case;
1743
Radek Krejcie7b95092019-05-15 11:03:07 +02001744 struct lys_parser_ctx ctx = {0};
Radek Krejcia9026eb2018-12-12 16:04:47 +01001745 struct lysp_node_case *cs = NULL;
1746 const char *str;
1747
1748 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1749 assert_non_null(ctx.ctx);
1750 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001751 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejcia9026eb2018-12-12 16:04:47 +01001752
1753 /* invalid cardinality */
1754#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1755 str = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1756 assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); \
1757 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1758 lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
1759
1760 TEST_DUP("description", "text1", "text2");
1761 TEST_DUP("reference", "1", "2");
1762 TEST_DUP("status", "current", "obsolete");
1763 TEST_DUP("when", "true", "false");
1764#undef TEST_DUP
1765
1766 /* full content */
1767 str = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}"
1768 "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
1769 assert_int_equal(LY_SUCCESS, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs));
1770 assert_non_null(cs);
1771 assert_int_equal(LYS_CASE, cs->nodetype);
1772 assert_string_equal("cs", cs->name);
1773 assert_string_equal("test", cs->dsc);
1774 assert_non_null(cs->exts);
1775 assert_non_null(cs->iffeatures);
1776 assert_string_equal("test", cs->ref);
1777 assert_non_null(cs->when);
1778 assert_null(cs->parent);
1779 assert_null(cs->next);
1780 assert_int_equal(LYS_STATUS_CURR, cs->flags);
1781 lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
1782
1783 /* invalid content */
1784 str = "cs {config true} ...";
1785 assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs));
1786 logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1.");
1787 lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
1788
Radek Krejci056d0a82018-12-06 16:57:25 +01001789 *state = NULL;
1790 ly_ctx_destroy(ctx.ctx, NULL);
1791}
1792
Radek Krejci9800fb82018-12-13 14:26:23 +01001793static void
1794test_any(void **state, enum yang_keyword kw)
1795{
1796 *state = test_any;
1797
Radek Krejcie7b95092019-05-15 11:03:07 +02001798 struct lys_parser_ctx ctx = {0};
Radek Krejci9800fb82018-12-13 14:26:23 +01001799 struct lysp_node_anydata *any = NULL;
1800 const char *str;
1801
1802 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1803 assert_non_null(ctx.ctx);
1804 ctx.line = 1;
Radek Krejci9800fb82018-12-13 14:26:23 +01001805 if (kw == YANG_ANYDATA) {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001806 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci9800fb82018-12-13 14:26:23 +01001807 } else {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001808 ctx.mod_version = 1; /* simulate YANG 1.0 */
Radek Krejci9800fb82018-12-13 14:26:23 +01001809 }
1810
1811 /* invalid cardinality */
1812#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1813 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1814 assert_int_equal(LY_EVALID, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); \
1815 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1816 lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
1817
1818 TEST_DUP("config", "true", "false");
1819 TEST_DUP("description", "text1", "text2");
1820 TEST_DUP("mandatory", "true", "false");
1821 TEST_DUP("reference", "1", "2");
1822 TEST_DUP("status", "current", "obsolete");
1823 TEST_DUP("when", "true", "false");
1824#undef TEST_DUP
1825
1826 /* full content */
1827 str = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
1828 assert_int_equal(LY_SUCCESS, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any));
1829 assert_non_null(any);
1830 assert_int_equal(kw == YANG_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype);
1831 assert_string_equal("any", any->name);
1832 assert_string_equal("test", any->dsc);
1833 assert_non_null(any->exts);
1834 assert_non_null(any->iffeatures);
1835 assert_non_null(any->musts);
1836 assert_string_equal("test", any->ref);
1837 assert_non_null(any->when);
1838 assert_null(any->parent);
1839 assert_null(any->next);
1840 assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags);
1841 lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
1842
1843 *state = NULL;
1844 ly_ctx_destroy(ctx.ctx, NULL);
1845}
1846
1847static void
1848test_anydata(void **state)
1849{
1850 return test_any(state, YANG_ANYDATA);
1851}
1852
1853static void
1854test_anyxml(void **state)
1855{
1856 return test_any(state, YANG_ANYXML);
1857}
1858
Radek Krejcie86bf772018-12-14 11:39:53 +01001859static void
1860test_grouping(void **state)
1861{
1862 *state = test_grouping;
1863
Radek Krejcie7b95092019-05-15 11:03:07 +02001864 struct lys_parser_ctx ctx = {0};
Radek Krejcie86bf772018-12-14 11:39:53 +01001865 struct lysp_grp *grp = NULL;
1866 const char *str;
1867
1868 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1869 assert_non_null(ctx.ctx);
1870 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001871 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejcie86bf772018-12-14 11:39:53 +01001872
1873 /* invalid cardinality */
1874#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1875 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1876 assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); \
1877 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1878 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1879
1880 TEST_DUP("description", "text1", "text2");
1881 TEST_DUP("reference", "1", "2");
1882 TEST_DUP("status", "current", "obsolete");
1883#undef TEST_DUP
1884
1885 /* full content */
1886 str = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}"
1887 "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ...";
1888 assert_int_equal(LY_SUCCESS, parse_grouping(&ctx, &str, NULL, &grp));
1889 assert_non_null(grp);
1890 assert_int_equal(LYS_GROUPING, grp->nodetype);
1891 assert_string_equal("grp", grp->name);
1892 assert_string_equal("test", grp->dsc);
1893 assert_non_null(grp->exts);
1894 assert_string_equal("test", grp->ref);
1895 assert_null(grp->parent);
1896 assert_int_equal( LYS_STATUS_CURR, grp->flags);
1897 ly_set_erase(&ctx.tpdfs_nodes, NULL);
1898 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1899
1900 /* invalid content */
1901 str = "grp {config true} ...";
1902 assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp));
1903 logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1.");
1904 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1905
1906 str = "grp {must 'expr'} ...";
1907 assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp));
1908 logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1.");
1909 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1910
1911 *state = NULL;
1912 ly_ctx_destroy(ctx.ctx, NULL);
1913}
1914
1915static void
Radek Krejcif538ce52019-03-05 10:46:14 +01001916test_action(void **state)
1917{
1918 *state = test_action;
1919
Radek Krejcie7b95092019-05-15 11:03:07 +02001920 struct lys_parser_ctx ctx = {0};
Radek Krejcif538ce52019-03-05 10:46:14 +01001921 struct lysp_action *rpcs = NULL;
1922 struct lysp_node_container *c = NULL;
1923 const char *str;
1924
1925 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1926 assert_non_null(ctx.ctx);
1927 ctx.line = 1;
1928 ctx.mod_version = 2; /* simulate YANG 1.1 */
1929
1930 /* invalid cardinality */
1931#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1932 str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1933 assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs)); \
1934 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1935 FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
1936
1937 TEST_DUP("description", "text1", "text2");
1938 TEST_DUP("input", "", "");
1939 TEST_DUP("output", "", "");
1940 TEST_DUP("reference", "1", "2");
1941 TEST_DUP("status", "current", "obsolete");
1942#undef TEST_DUP
1943
1944 /* full content */
1945 str = "top;";
1946 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1947 str = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;"
1948 "input {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
1949 " list li; must 1; typedef mytypei {type int8;} uses grp; m:ext;}"
1950 "output {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
1951 " list li; must 1; typedef mytypeo {type int8;} uses grp; m:ext;}} ...";
1952 assert_int_equal(LY_SUCCESS, parse_action(&ctx, &str, (struct lysp_node*)c, &rpcs));
1953 assert_non_null(rpcs);
1954 assert_int_equal(LYS_ACTION, rpcs->nodetype);
1955 assert_string_equal("func", rpcs->name);
1956 assert_string_equal("test", rpcs->dsc);
1957 assert_non_null(rpcs->exts);
1958 assert_non_null(rpcs->iffeatures);
1959 assert_string_equal("test", rpcs->ref);
1960 assert_non_null(rpcs->groupings);
1961 assert_non_null(rpcs->typedefs);
1962 assert_int_equal(LYS_STATUS_CURR, rpcs->flags);
1963 /* input */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001964 assert_int_equal(rpcs->input.nodetype, LYS_INPUT);
Radek Krejcif538ce52019-03-05 10:46:14 +01001965 assert_non_null(rpcs->input.groupings);
1966 assert_non_null(rpcs->input.exts);
1967 assert_non_null(rpcs->input.musts);
1968 assert_non_null(rpcs->input.typedefs);
1969 assert_non_null(rpcs->input.data);
1970 /* output */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001971 assert_int_equal(rpcs->output.nodetype, LYS_OUTPUT);
Radek Krejcif538ce52019-03-05 10:46:14 +01001972 assert_non_null(rpcs->output.groupings);
1973 assert_non_null(rpcs->output.exts);
1974 assert_non_null(rpcs->output.musts);
1975 assert_non_null(rpcs->output.typedefs);
1976 assert_non_null(rpcs->output.data);
1977
1978 ly_set_erase(&ctx.tpdfs_nodes, NULL);
1979 FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
1980
1981 /* invalid content */
1982 str = "func {config true} ...";
1983 assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs));
1984 logbuf_assert("Invalid keyword \"config\" as a child of \"rpc\". Line number 1.");
1985 FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
1986
1987 *state = NULL;
1988 lysp_node_free(ctx.ctx, (struct lysp_node*)c);
1989 ly_ctx_destroy(ctx.ctx, NULL);
1990}
1991
1992static void
Radek Krejcifc11bd72019-04-11 16:00:05 +02001993test_notification(void **state)
1994{
1995 *state = test_notification;
1996
Radek Krejcie7b95092019-05-15 11:03:07 +02001997 struct lys_parser_ctx ctx = {0};
Radek Krejcifc11bd72019-04-11 16:00:05 +02001998 struct lysp_notif *notifs = NULL;
1999 struct lysp_node_container *c = NULL;
2000 const char *str;
2001
2002 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2003 assert_non_null(ctx.ctx);
2004 ctx.line = 1;
2005 ctx.mod_version = 2; /* simulate YANG 1.1 */
2006
2007 /* invalid cardinality */
2008#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2009 str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2010 assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, &notifs)); \
2011 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
2012 FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
2013
2014 TEST_DUP("description", "text1", "text2");
2015 TEST_DUP("reference", "1", "2");
2016 TEST_DUP("status", "current", "obsolete");
2017#undef TEST_DUP
2018
2019 /* full content */
2020 str = "top;";
2021 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
2022 str = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}"
2023 "leaf-list ll {type int8;} list li; must 1; reference test; status current; typedef mytype {type int8;} uses grp; m:ext;}";
2024 assert_int_equal(LY_SUCCESS, parse_notif(&ctx, &str, (struct lysp_node*)c, &notifs));
2025 assert_non_null(notifs);
2026 assert_int_equal(LYS_NOTIF, notifs->nodetype);
2027 assert_string_equal("ntf", notifs->name);
2028 assert_string_equal("test", notifs->dsc);
2029 assert_non_null(notifs->exts);
2030 assert_non_null(notifs->iffeatures);
2031 assert_string_equal("test", notifs->ref);
2032 assert_non_null(notifs->groupings);
2033 assert_non_null(notifs->typedefs);
2034 assert_non_null(notifs->musts);
2035 assert_non_null(notifs->data);
2036 assert_int_equal(LYS_STATUS_CURR, notifs->flags);
2037
2038 ly_set_erase(&ctx.tpdfs_nodes, NULL);
2039 FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
2040
2041 /* invalid content */
2042 str = "ntf {config true} ...";
2043 assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, &notifs));
2044 logbuf_assert("Invalid keyword \"config\" as a child of \"notification\". Line number 1.");
2045 FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
2046
2047 *state = NULL;
2048 lysp_node_free(ctx.ctx, (struct lysp_node*)c);
2049 ly_ctx_destroy(ctx.ctx, NULL);
2050}
2051
2052static void
Radek Krejcie86bf772018-12-14 11:39:53 +01002053test_uses(void **state)
2054{
2055 *state = test_uses;
2056
Radek Krejcie7b95092019-05-15 11:03:07 +02002057 struct lys_parser_ctx ctx = {0};
Radek Krejcie86bf772018-12-14 11:39:53 +01002058 struct lysp_node_uses *u = NULL;
2059 const char *str;
2060
2061 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2062 assert_non_null(ctx.ctx);
2063 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002064 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejcie86bf772018-12-14 11:39:53 +01002065
2066 /* invalid cardinality */
2067#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2068 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2069 assert_int_equal(LY_EVALID, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); \
2070 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
2071 lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL;
2072
2073 TEST_DUP("description", "text1", "text2");
2074 TEST_DUP("reference", "1", "2");
2075 TEST_DUP("status", "current", "obsolete");
2076 TEST_DUP("when", "true", "false");
2077#undef TEST_DUP
2078
2079 /* full content */
2080 str = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ...";
2081 assert_int_equal(LY_SUCCESS, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u));
2082 assert_non_null(u);
2083 assert_int_equal(LYS_USES, u->nodetype);
2084 assert_string_equal("grpref", u->name);
2085 assert_string_equal("test", u->dsc);
2086 assert_non_null(u->exts);
2087 assert_non_null(u->iffeatures);
2088 assert_string_equal("test", u->ref);
2089 assert_non_null(u->augments);
2090 assert_non_null(u->refines);
2091 assert_non_null(u->when);
2092 assert_null(u->parent);
2093 assert_null(u->next);
2094 assert_int_equal(LYS_STATUS_CURR, u->flags);
2095 lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL;
2096
2097 *state = NULL;
2098 ly_ctx_destroy(ctx.ctx, NULL);
2099}
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002100
2101
2102static void
2103test_augment(void **state)
2104{
2105 *state = test_augment;
2106
Radek Krejcie7b95092019-05-15 11:03:07 +02002107 struct lys_parser_ctx ctx = {0};
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002108 struct lysp_augment *a = NULL;
2109 const char *str;
2110
2111 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2112 assert_non_null(ctx.ctx);
2113 ctx.line = 1;
Radek Krejcib4adbf12019-02-25 13:35:22 +01002114 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002115
2116 /* invalid cardinality */
2117#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2118 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2119 assert_int_equal(LY_EVALID, parse_augment(&ctx, &str, NULL, &a)); \
2120 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
Radek Krejcib4adbf12019-02-25 13:35:22 +01002121 FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL;
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002122
2123 TEST_DUP("description", "text1", "text2");
2124 TEST_DUP("reference", "1", "2");
2125 TEST_DUP("status", "current", "obsolete");
2126 TEST_DUP("when", "true", "false");
2127#undef TEST_DUP
2128
2129 /* full content */
2130 str = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}"
2131 "leaf-list ll {type string;} list li;notification not;reference test;status current;uses g;when true;m:ext;} ...";
2132 assert_int_equal(LY_SUCCESS, parse_augment(&ctx, &str, NULL, &a));
2133 assert_non_null(a);
2134 assert_int_equal(LYS_AUGMENT, a->nodetype);
2135 assert_string_equal("/target/nodeid", a->nodeid);
2136 assert_string_equal("test", a->dsc);
2137 assert_non_null(a->exts);
2138 assert_non_null(a->iffeatures);
2139 assert_string_equal("test", a->ref);
2140 assert_non_null(a->when);
2141 assert_null(a->parent);
2142 assert_int_equal(LYS_STATUS_CURR, a->flags);
Radek Krejcib4adbf12019-02-25 13:35:22 +01002143 FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL;
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002144
2145 *state = NULL;
2146 ly_ctx_destroy(ctx.ctx, NULL);
2147}
2148
Radek Krejcif09e4e82019-06-14 15:08:11 +02002149static void
2150test_when(void **state)
2151{
2152 *state = test_when;
2153
2154 struct lys_parser_ctx ctx = {0};
2155 struct lysp_when *w = NULL;
2156 const char *str;
2157
2158 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2159 assert_non_null(ctx.ctx);
2160 ctx.line = 1;
2161 ctx.mod_version = 2; /* simulate YANG 1.1 */
2162
2163 /* invalid cardinality */
2164#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2165 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2166 assert_int_equal(LY_EVALID, parse_when(&ctx, &str, &w)); \
2167 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
2168 FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
2169
2170 TEST_DUP("description", "text1", "text2");
2171 TEST_DUP("reference", "1", "2");
2172#undef TEST_DUP
2173
2174 /* full content */
2175 str = "expression {description test;reference test;m:ext;} ...";
2176 assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w));
2177 assert_non_null(w);
2178 assert_string_equal("expression", w->cond);
2179 assert_string_equal("test", w->dsc);
2180 assert_string_equal("test", w->ref);
2181 assert_non_null(w->exts);
2182 FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
2183
2184 /* empty condition */
2185 str = "\"\";";
2186 assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w));
2187 logbuf_assert("Empty argument of when statement does not make sense.");
2188 assert_non_null(w);
2189 assert_string_equal("", w->cond);
2190 FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
2191
2192 *state = NULL;
2193 ly_ctx_destroy(ctx.ctx, NULL);
2194}
2195
Radek Krejci80dd33e2018-09-26 15:57:18 +02002196int main(void)
2197{
2198 const struct CMUnitTest tests[] = {
Radek Krejci44ceedc2018-10-02 15:54:31 +02002199 cmocka_unit_test_setup(test_helpers, logger_setup),
Radek Krejci80dd33e2018-09-26 15:57:18 +02002200 cmocka_unit_test_setup(test_comments, logger_setup),
Radek Krejciefd22f62018-09-27 11:47:58 +02002201 cmocka_unit_test_setup(test_arg, logger_setup),
Radek Krejcidcc7b322018-10-11 14:24:02 +02002202 cmocka_unit_test_setup(test_stmts, logger_setup),
Radek Krejci05b13982018-11-28 16:22:07 +01002203 cmocka_unit_test_setup_teardown(test_minmax, logger_setup, logger_teardown),
Radek Krejci40544fa2019-01-11 09:38:37 +01002204 cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002205 cmocka_unit_test_setup_teardown(test_identity, logger_setup, logger_teardown),
Radek Krejci2c02f3e2018-10-16 10:54:38 +02002206 cmocka_unit_test_setup(test_feature, logger_setup),
2207 cmocka_unit_test_setup(test_deviation, logger_setup),
2208 cmocka_unit_test_setup(test_deviate, logger_setup),
Radek Krejci8c370832018-11-02 15:10:03 +01002209 cmocka_unit_test_setup(test_container, logger_setup),
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01002210 cmocka_unit_test_setup_teardown(test_leaf, logger_setup, logger_teardown),
Radek Krejci0e5d8382018-11-28 16:37:53 +01002211 cmocka_unit_test_setup_teardown(test_leaflist, logger_setup, logger_teardown),
Radek Krejci9bb94eb2018-12-04 16:48:35 +01002212 cmocka_unit_test_setup_teardown(test_list, logger_setup, logger_teardown),
Radek Krejci056d0a82018-12-06 16:57:25 +01002213 cmocka_unit_test_setup_teardown(test_choice, logger_setup, logger_teardown),
Radek Krejcia9026eb2018-12-12 16:04:47 +01002214 cmocka_unit_test_setup_teardown(test_case, logger_setup, logger_teardown),
Radek Krejci9800fb82018-12-13 14:26:23 +01002215 cmocka_unit_test_setup_teardown(test_anydata, logger_setup, logger_teardown),
2216 cmocka_unit_test_setup_teardown(test_anyxml, logger_setup, logger_teardown),
Radek Krejcif538ce52019-03-05 10:46:14 +01002217 cmocka_unit_test_setup_teardown(test_action, logger_setup, logger_teardown),
Radek Krejcifc11bd72019-04-11 16:00:05 +02002218 cmocka_unit_test_setup_teardown(test_notification, logger_setup, logger_teardown),
Radek Krejcie86bf772018-12-14 11:39:53 +01002219 cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown),
2220 cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown),
Radek Krejcib4adbf12019-02-25 13:35:22 +01002221 cmocka_unit_test_setup_teardown(test_augment, logger_setup, logger_teardown),
Radek Krejcif09e4e82019-06-14 15:08:11 +02002222 cmocka_unit_test_setup_teardown(test_when, logger_setup, logger_teardown),
Radek Krejci80dd33e2018-09-26 15:57:18 +02002223 };
2224
2225 return cmocka_run_group_tests(tests, NULL, NULL);
2226}