blob: a23f23f460f3728c3e3af27ea8bbff514dba3ed6 [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);
Radek Krejci2d7a47b2019-05-16 13:34:10 +020047
48LY_ERR parse_action(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_action **actions);
49LY_ERR parse_any(struct lys_parser_ctx *ctx, const char **data, enum yang_keyword kw, struct lysp_node *parent, struct lysp_node **siblings);
50LY_ERR parse_augment(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_augment **augments);
51LY_ERR parse_case(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
52LY_ERR parse_container(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
53LY_ERR parse_deviate(struct lys_parser_ctx *ctx, const char **data, struct lysp_deviate **deviates);
54LY_ERR parse_deviation(struct lys_parser_ctx *ctx, const char **data, struct lysp_deviation **deviations);
55LY_ERR parse_feature(struct lys_parser_ctx *ctx, const char **data, struct lysp_feature **features);
56LY_ERR parse_grouping(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_grp **groupings);
57LY_ERR parse_choice(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
58LY_ERR parse_identity(struct lys_parser_ctx *ctx, const char **data, struct lysp_ident **identities);
59LY_ERR parse_leaf(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
60LY_ERR parse_leaflist(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
61LY_ERR parse_list(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
62LY_ERR parse_maxelements(struct lys_parser_ctx *ctx, const char **data, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts);
63LY_ERR parse_minelements(struct lys_parser_ctx *ctx, const char **data, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts);
64LY_ERR parse_module(struct lys_parser_ctx *ctx, const char **data, struct lysp_module *mod);
65LY_ERR parse_notif(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_notif **notifs);
66LY_ERR parse_submodule(struct lys_parser_ctx *ctx, const char **data, struct lysp_submodule *submod);
67LY_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 +020068LY_ERR parse_when(struct lys_parser_ctx *ctx, const char **data, struct lysp_when **when_p);
Radek Krejci80dd33e2018-09-26 15:57:18 +020069
70#define BUFSIZE 1024
71char logbuf[BUFSIZE] = {0};
Radek Krejci9ed7a192018-10-31 16:23:51 +010072int store = -1; /* negative for infinite logging, positive for limited logging */
Radek Krejci80dd33e2018-09-26 15:57:18 +020073
74/* set to 0 to printing error messages to stderr instead of checking them in code */
Radek Krejci70853c52018-10-15 14:46:16 +020075#define ENABLE_LOGGER_CHECKING 1
Radek Krejci80dd33e2018-09-26 15:57:18 +020076
Radek Krejcid5f2b5f2018-10-11 10:54:36 +020077#if ENABLE_LOGGER_CHECKING
Radek Krejci80dd33e2018-09-26 15:57:18 +020078static void
79logger(LY_LOG_LEVEL level, const char *msg, const char *path)
80{
81 (void) level; /* unused */
Radek Krejci9ed7a192018-10-31 16:23:51 +010082 if (store) {
83 if (path && path[0]) {
84 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
85 } else {
86 strncpy(logbuf, msg, BUFSIZE - 1);
87 }
88 if (store > 0) {
89 --store;
90 }
Radek Krejci80dd33e2018-09-26 15:57:18 +020091 }
92}
Radek Krejcid5f2b5f2018-10-11 10:54:36 +020093#endif
Radek Krejci80dd33e2018-09-26 15:57:18 +020094
95static int
96logger_setup(void **state)
97{
98 (void) state; /* unused */
99#if ENABLE_LOGGER_CHECKING
100 ly_set_log_clb(logger, 1);
101#endif
102 return 0;
103}
104
Radek Krejcib1a5dcc2018-11-26 14:50:05 +0100105static int
106logger_teardown(void **state)
107{
108 (void) state; /* unused */
109#if ENABLE_LOGGER_CHECKING
110 if (*state) {
111 fprintf(stderr, "%s\n", logbuf);
112 }
113#endif
114 return 0;
115}
116
Radek Krejci80dd33e2018-09-26 15:57:18 +0200117void
118logbuf_clean(void)
119{
120 logbuf[0] = '\0';
121}
122
123#if ENABLE_LOGGER_CHECKING
124# define logbuf_assert(str) assert_string_equal(logbuf, str)
125#else
126# define logbuf_assert(str)
127#endif
128
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200129#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
130 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
131 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
132 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
133 CLEANUP
134
Radek Krejci44ceedc2018-10-02 15:54:31 +0200135static void
136test_helpers(void **state)
137{
138 (void) state; /* unused */
139
140 const char *str;
Radek Krejci404251e2018-10-09 12:06:44 +0200141 char *buf, *p;
Radek Krejci44ceedc2018-10-02 15:54:31 +0200142 size_t len, size;
143 int prefix;
Radek Krejcie7b95092019-05-15 11:03:07 +0200144 struct lys_parser_ctx ctx;
Radek Krejci44ceedc2018-10-02 15:54:31 +0200145 ctx.ctx = NULL;
146 ctx.line = 1;
147
148 /* storing into buffer */
149 str = "abcd";
150 buf = NULL;
151 size = len = 0;
152 assert_int_equal(LY_SUCCESS, buf_add_char(NULL, &str, 2, &buf, &size, &len));
153 assert_int_not_equal(0, size);
154 assert_int_equal(2, len);
155 assert_string_equal("cd", str);
156 assert_false(strncmp("ab", buf, 2));
157 free(buf);
Radek Krejci404251e2018-10-09 12:06:44 +0200158 buf = NULL;
159
160 /* invalid first characters */
161 len = 0;
162 str = "2invalid";
163 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
164 str = ".invalid";
165 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
166 str = "-invalid";
167 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
168 /* invalid following characters */
169 len = 3; /* number of characters read before the str content */
170 str = "!";
171 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
172 str = ":";
173 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
174 /* valid colon for prefixed identifiers */
175 len = size = 0;
176 p = NULL;
177 str = "x:id";
178 assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0));
179 assert_int_equal(1, len);
180 assert_null(buf);
181 assert_string_equal(":id", str);
182 assert_int_equal('x', p[len - 1]);
183 assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1));
184 assert_int_equal(2, len);
185 assert_string_equal("id", str);
186 assert_int_equal(':', p[len - 1]);
187 free(buf);
Radek Krejci44ceedc2018-10-02 15:54:31 +0200188
189 /* checking identifiers */
David Sedlák4ccd7c32019-07-10 12:02:04 +0200190 assert_int_equal(LY_EVALID, lysp_check_identifierchar(&ctx, ':', 0, NULL));
Radek Krejci44ceedc2018-10-02 15:54:31 +0200191 logbuf_assert("Invalid identifier character ':'. Line number 1.");
David Sedlák4ccd7c32019-07-10 12:02:04 +0200192 assert_int_equal(LY_EVALID, lysp_check_identifierchar(&ctx, '#', 1, NULL));
Radek Krejci44ceedc2018-10-02 15:54:31 +0200193 logbuf_assert("Invalid identifier first character '#'. Line number 1.");
194
David Sedlák4ccd7c32019-07-10 12:02:04 +0200195 assert_int_equal(LY_SUCCESS, lysp_check_identifierchar(&ctx, 'a', 1, &prefix));
Radek Krejci44ceedc2018-10-02 15:54:31 +0200196 assert_int_equal(0, prefix);
David Sedlák4ccd7c32019-07-10 12:02:04 +0200197 assert_int_equal(LY_SUCCESS, lysp_check_identifierchar(&ctx, ':', 0, &prefix));
Radek Krejci44ceedc2018-10-02 15:54:31 +0200198 assert_int_equal(1, prefix);
David Sedlák4ccd7c32019-07-10 12:02:04 +0200199 assert_int_equal(LY_EVALID, lysp_check_identifierchar(&ctx, ':', 0, &prefix));
Radek Krejcidcc7b322018-10-11 14:24:02 +0200200 assert_int_equal(1, prefix);
David Sedlák4ccd7c32019-07-10 12:02:04 +0200201 assert_int_equal(LY_SUCCESS, lysp_check_identifierchar(&ctx, 'b', 0, &prefix));
Radek Krejci44ceedc2018-10-02 15:54:31 +0200202 assert_int_equal(2, prefix);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200203 /* second colon is invalid */
David Sedlák4ccd7c32019-07-10 12:02:04 +0200204 assert_int_equal(LY_EVALID, lysp_check_identifierchar(&ctx, ':', 0, &prefix));
Radek Krejcidcc7b322018-10-11 14:24:02 +0200205 logbuf_assert("Invalid identifier character ':'. Line number 1.");
Radek Krejci44ceedc2018-10-02 15:54:31 +0200206}
Radek Krejci80dd33e2018-09-26 15:57:18 +0200207
208static void
209test_comments(void **state)
210{
211 (void) state; /* unused */
212
Radek Krejcie7b95092019-05-15 11:03:07 +0200213 struct lys_parser_ctx ctx;
Radek Krejci80dd33e2018-09-26 15:57:18 +0200214 const char *str, *p;
Radek Krejciefd22f62018-09-27 11:47:58 +0200215 char *word, *buf;
216 size_t len;
Radek Krejci80dd33e2018-09-26 15:57:18 +0200217
Radek Krejci44ceedc2018-10-02 15:54:31 +0200218 ctx.ctx = NULL;
219 ctx.line = 1;
220
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200221 str = " // this is a text of / one * line */ comment\nargument;";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200222 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200223 assert_string_equal("argument;", word);
Radek Krejciefd22f62018-09-27 11:47:58 +0200224 assert_null(buf);
225 assert_int_equal(8, len);
Radek Krejci80dd33e2018-09-26 15:57:18 +0200226
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200227 str = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200228 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200229 assert_string_equal("argument", word);
230 assert_ptr_equal(buf, word);
231 assert_int_equal(8, len);
232 free(word);
Radek Krejci80dd33e2018-09-26 15:57:18 +0200233
234 str = p = " this is one line comment on last line";
Radek Krejci44ceedc2018-10-02 15:54:31 +0200235 assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &str, 1));
Radek Krejci80dd33e2018-09-26 15:57:18 +0200236 assert_true(str[0] == '\0');
237
238 str = p = " this is a not terminated comment x";
Radek Krejci44ceedc2018-10-02 15:54:31 +0200239 assert_int_equal(LY_EVALID, skip_comment(&ctx, &str, 2));
Radek Krejci0a1d0d42019-05-16 15:14:51 +0200240 logbuf_assert("Unexpected end-of-input, non-terminated comment. Line number 5.");
Radek Krejci80dd33e2018-09-26 15:57:18 +0200241 assert_true(str[0] == '\0');
242}
243
Radek Krejciefd22f62018-09-27 11:47:58 +0200244static void
245test_arg(void **state)
246{
247 (void) state; /* unused */
248
Radek Krejcie7b95092019-05-15 11:03:07 +0200249 struct lys_parser_ctx ctx;
Radek Krejciefd22f62018-09-27 11:47:58 +0200250 const char *str;
251 char *word, *buf;
252 size_t len;
253
Radek Krejci44ceedc2018-10-02 15:54:31 +0200254 ctx.ctx = NULL;
255 ctx.line = 1;
256
Radek Krejciefd22f62018-09-27 11:47:58 +0200257 /* missing argument */
258 str = ";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200259 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200260 assert_null(word);
261
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200262 str = "{";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200263 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200264 logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1.");
265
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200266 /* invalid escape sequence */
267 str = "\"\\s\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200268 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200269 logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1.");
270 str = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200271 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200272 assert_int_equal(2, len);
273 assert_string_equal("\\s\'", word);
274 assert_int_equal('\0', str[0]); /* input has been eaten */
275
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200276 /* invalid character after the argument */
277 str = "hello\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200278 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200279 logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
280 str = "hello}";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200282 logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
283
Radek Krejci4e199f52019-05-28 09:09:28 +0200284 str = "\"\";"; /* empty identifier is not allowed */
285 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
286 logbuf_assert("Statement argument is required. Line number 1.");
287 logbuf_clean();
288 str = "\"\";"; /* empty reference identifier is not allowed */
289 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
290 logbuf_assert("Statement argument is required. Line number 1.");
291
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200292 str = "hello/x\t"; /* slash is not an invalid character */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200293 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200294 assert_int_equal(7, len);
295 assert_string_equal("hello/x\t", word);
296
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200297 assert_null(buf);
Radek Krejciefd22f62018-09-27 11:47:58 +0200298
299 /* different quoting */
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200300 str = "hello ";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200301 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200302 assert_null(buf);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200303 assert_int_equal(5, len);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200304 assert_string_equal("hello ", word);
Radek Krejciefd22f62018-09-27 11:47:58 +0200305
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200306 str = "hello/*comment*/\n";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200307 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200308 assert_null(buf);
309 assert_int_equal(5, len);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200310 assert_false(strncmp("hello", word, len));
311
312
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200313 str = "\"hello\\n\\t\\\"\\\\\";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200314 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200315 assert_null(buf);
316 assert_int_equal(9, len);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200317 assert_string_equal("hello\\n\\t\\\"\\\\\";", word);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200318
319 ctx.indent = 14;
320 str = "\"hello \t\n\t\t world!\"";
321 /* - space and tabs before newline are stripped out
322 * - space and tabs after newline (indentation) are stripped out
323 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200325 assert_non_null(buf);
326 assert_ptr_equal(word, buf);
327 assert_int_equal(14, len);
328 assert_string_equal("hello\n world!", word);
329 free(buf);
330
331 ctx.indent = 14;
332 str = "\"hello\n \tworld!\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200333 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200334 assert_non_null(buf);
335 assert_ptr_equal(word, buf);
336 assert_int_equal(12, len);
337 assert_string_equal("hello\nworld!", word);
338 free(buf);
Radek Krejciefd22f62018-09-27 11:47:58 +0200339
340 str = "\'hello\'";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200341 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200342 assert_null(buf);
343 assert_int_equal(5, len);
344 assert_false(strncmp("hello", word, 5));
345
346 str = "\"hel\" +\t\n\"lo\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200347 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200348 assert_ptr_equal(word, buf);
349 assert_int_equal(5, len);
350 assert_string_equal("hello", word);
351 free(buf);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200352 str = "\"hel\" +\t\nlo"; /* unquoted the second part */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200353 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200354 logbuf_assert("Both string parts divided by '+' must be quoted. Line number 5.");
Radek Krejciefd22f62018-09-27 11:47:58 +0200355
356 str = "\'he\'\t\n+ \"llo\"";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200357 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200358 assert_ptr_equal(word, buf);
359 assert_int_equal(5, len);
360 assert_string_equal("hello", word);
361 free(buf);
362
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200363 str = " \t\n\"he\"+\'llo\'";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200364 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200365 assert_ptr_equal(word, buf);
366 assert_int_equal(5, len);
367 assert_string_equal("hello", word);
368 free(buf);
369
Radek Krejci44ceedc2018-10-02 15:54:31 +0200370 /* missing argument */
371 str = ";";
Radek Krejcid3ca0632019-04-16 16:54:54 +0200372 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200373 logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 7.");
Radek Krejcidcc7b322018-10-11 14:24:02 +0200374}
375
376static void
377test_stmts(void **state)
378{
379 (void) state; /* unused */
380
Radek Krejcie7b95092019-05-15 11:03:07 +0200381 struct lys_parser_ctx ctx;
Radek Krejcidcc7b322018-10-11 14:24:02 +0200382 const char *str, *p;
383 enum yang_keyword kw;
384 char *word;
385 size_t len;
386
387 ctx.ctx = NULL;
388 ctx.line = 1;
389
390 str = "\n// comment\n\tinput\t{";
391 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
392 assert_int_equal(YANG_INPUT, kw);
393 assert_int_equal(5, len);
394 assert_string_equal("input\t{", word);
395 assert_string_equal("\t{", str);
396
397 str = "\t /* comment */\t output\n\t{";
398 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
399 assert_int_equal(YANG_OUTPUT, kw);
400 assert_int_equal(6, len);
401 assert_string_equal("output\n\t{", word);
402 assert_string_equal("\n\t{", str);
Radek Krejciabdd8062019-06-11 16:44:19 +0200403 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
404 assert_int_equal(YANG_LEFT_BRACE, kw);
405 assert_int_equal(1, len);
406 assert_string_equal("{", word);
407 assert_string_equal("", str);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200408
409 str = "/input { "; /* invalid slash */
410 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
411 logbuf_assert("Invalid identifier first character '/'. Line number 4.");
412
413 str = "not-a-statement-nor-extension { "; /* invalid identifier */
414 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
415 logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4.");
416
417 str = "path;"; /* missing sep after the keyword */
418 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
419 logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4.");
420
421 str = "action ";
422 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
423 assert_int_equal(YANG_ACTION, kw);
424 assert_int_equal(6, len);
425 str = "anydata ";
426 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
427 assert_int_equal(YANG_ANYDATA, kw);
428 assert_int_equal(7, len);
429 str = "anyxml ";
430 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
431 assert_int_equal(YANG_ANYXML, kw);
432 assert_int_equal(6, len);
433 str = "argument ";
434 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
435 assert_int_equal(YANG_ARGUMENT, kw);
436 assert_int_equal(8, len);
437 str = "augment ";
438 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
439 assert_int_equal(YANG_AUGMENT, kw);
440 assert_int_equal(7, len);
441 str = "base ";
442 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
443 assert_int_equal(YANG_BASE, kw);
444 assert_int_equal(4, len);
445 str = "belongs-to ";
446 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
447 assert_int_equal(YANG_BELONGS_TO, kw);
448 assert_int_equal(10, len);
449 str = "bit ";
450 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
451 assert_int_equal(YANG_BIT, kw);
452 assert_int_equal(3, len);
453 str = "case ";
454 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
455 assert_int_equal(YANG_CASE, kw);
456 assert_int_equal(4, len);
457 str = "choice ";
458 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
459 assert_int_equal(YANG_CHOICE, kw);
460 assert_int_equal(6, len);
461 str = "config ";
462 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
463 assert_int_equal(YANG_CONFIG, kw);
464 assert_int_equal(6, len);
465 str = "contact ";
466 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
467 assert_int_equal(YANG_CONTACT, kw);
468 assert_int_equal(7, len);
469 str = "container ";
470 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
471 assert_int_equal(YANG_CONTAINER, kw);
472 assert_int_equal(9, len);
473 str = "default ";
474 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
475 assert_int_equal(YANG_DEFAULT, kw);
476 assert_int_equal(7, len);
477 str = "description ";
478 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
479 assert_int_equal(YANG_DESCRIPTION, kw);
480 assert_int_equal(11, len);
481 str = "deviate ";
482 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
483 assert_int_equal(YANG_DEVIATE, kw);
484 assert_int_equal(7, len);
485 str = "deviation ";
486 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
487 assert_int_equal(YANG_DEVIATION, kw);
488 assert_int_equal(9, len);
489 str = "enum ";
490 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
491 assert_int_equal(YANG_ENUM, kw);
492 assert_int_equal(4, len);
493 str = "error-app-tag ";
494 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
495 assert_int_equal(YANG_ERROR_APP_TAG, kw);
496 assert_int_equal(13, len);
497 str = "error-message ";
498 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
499 assert_int_equal(YANG_ERROR_MESSAGE, kw);
500 assert_int_equal(13, len);
501 str = "extension ";
502 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
503 assert_int_equal(YANG_EXTENSION, kw);
504 assert_int_equal(9, len);
505 str = "feature ";
506 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
507 assert_int_equal(YANG_FEATURE, kw);
508 assert_int_equal(7, len);
509 str = "fraction-digits ";
510 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
511 assert_int_equal(YANG_FRACTION_DIGITS, kw);
512 assert_int_equal(15, len);
513 str = "grouping ";
514 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
515 assert_int_equal(YANG_GROUPING, kw);
516 assert_int_equal(8, len);
517 str = "identity ";
518 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
519 assert_int_equal(YANG_IDENTITY, kw);
520 assert_int_equal(8, len);
521 str = "if-feature ";
522 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
523 assert_int_equal(YANG_IF_FEATURE, kw);
524 assert_int_equal(10, len);
525 str = "import ";
526 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
527 assert_int_equal(YANG_IMPORT, kw);
528 assert_int_equal(6, len);
529 str = "include ";
530 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
531 assert_int_equal(YANG_INCLUDE, kw);
532 assert_int_equal(7, len);
533 str = "input{";
534 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
535 assert_int_equal(YANG_INPUT, kw);
536 assert_int_equal(5, len);
537 str = "key ";
538 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
539 assert_int_equal(YANG_KEY, kw);
540 assert_int_equal(3, len);
541 str = "leaf ";
542 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
543 assert_int_equal(YANG_LEAF, kw);
544 assert_int_equal(4, len);
545 str = "leaf-list ";
546 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
547 assert_int_equal(YANG_LEAF_LIST, kw);
548 assert_int_equal(9, len);
549 str = "length ";
550 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
551 assert_int_equal(YANG_LENGTH, kw);
552 assert_int_equal(6, len);
553 str = "list ";
554 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
555 assert_int_equal(YANG_LIST, kw);
556 assert_int_equal(4, len);
557 str = "mandatory ";
558 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
559 assert_int_equal(YANG_MANDATORY, kw);
560 assert_int_equal(9, len);
561 str = "max-elements ";
562 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
563 assert_int_equal(YANG_MAX_ELEMENTS, kw);
564 assert_int_equal(12, len);
565 str = "min-elements ";
566 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
567 assert_int_equal(YANG_MIN_ELEMENTS, kw);
568 assert_int_equal(12, len);
569 str = "modifier ";
570 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
571 assert_int_equal(YANG_MODIFIER, kw);
572 assert_int_equal(8, len);
573 str = "module ";
574 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
575 assert_int_equal(YANG_MODULE, kw);
576 assert_int_equal(6, len);
577 str = "must ";
578 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
579 assert_int_equal(YANG_MUST, kw);
580 assert_int_equal(4, len);
581 str = "namespace ";
582 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
583 assert_int_equal(YANG_NAMESPACE, kw);
584 assert_int_equal(9, len);
585 str = "notification ";
586 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
587 assert_int_equal(YANG_NOTIFICATION, kw);
588 assert_int_equal(12, len);
589 str = "ordered-by ";
590 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
591 assert_int_equal(YANG_ORDERED_BY, kw);
592 assert_int_equal(10, len);
593 str = "organization ";
594 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
595 assert_int_equal(YANG_ORGANIZATION, kw);
596 assert_int_equal(12, len);
597 str = "output ";
598 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
599 assert_int_equal(YANG_OUTPUT, kw);
600 assert_int_equal(6, len);
601 str = "path ";
602 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
603 assert_int_equal(YANG_PATH, kw);
604 assert_int_equal(4, len);
605 str = "pattern ";
606 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
607 assert_int_equal(YANG_PATTERN, kw);
608 assert_int_equal(7, len);
609 str = "position ";
610 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
611 assert_int_equal(YANG_POSITION, kw);
612 assert_int_equal(8, len);
613 str = "prefix ";
614 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
615 assert_int_equal(YANG_PREFIX, kw);
616 assert_int_equal(6, len);
617 str = "presence ";
618 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
619 assert_int_equal(YANG_PRESENCE, kw);
620 assert_int_equal(8, len);
621 str = "range ";
622 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
623 assert_int_equal(YANG_RANGE, kw);
624 assert_int_equal(5, len);
625 str = "reference ";
626 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
627 assert_int_equal(YANG_REFERENCE, kw);
628 assert_int_equal(9, len);
629 str = "refine ";
630 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
631 assert_int_equal(YANG_REFINE, kw);
632 assert_int_equal(6, len);
633 str = "require-instance ";
634 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
635 assert_int_equal(YANG_REQUIRE_INSTANCE, kw);
636 assert_int_equal(16, len);
637 str = "revision ";
638 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
639 assert_int_equal(YANG_REVISION, kw);
640 assert_int_equal(8, len);
641 str = "revision-date ";
642 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
643 assert_int_equal(YANG_REVISION_DATE, kw);
644 assert_int_equal(13, len);
645 str = "rpc ";
646 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
647 assert_int_equal(YANG_RPC, kw);
648 assert_int_equal(3, len);
649 str = "status ";
650 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
651 assert_int_equal(YANG_STATUS, kw);
652 assert_int_equal(6, len);
653 str = "submodule ";
654 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
655 assert_int_equal(YANG_SUBMODULE, kw);
656 assert_int_equal(9, len);
657 str = "type ";
658 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
659 assert_int_equal(YANG_TYPE, kw);
660 assert_int_equal(4, len);
661 str = "typedef ";
662 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
663 assert_int_equal(YANG_TYPEDEF, kw);
664 assert_int_equal(7, len);
665 str = "unique ";
666 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
667 assert_int_equal(YANG_UNIQUE, kw);
668 assert_int_equal(6, len);
669 str = "units ";
670 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
671 assert_int_equal(YANG_UNITS, kw);
672 assert_int_equal(5, len);
673 str = "uses ";
674 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
675 assert_int_equal(YANG_USES, kw);
676 assert_int_equal(4, len);
677 str = "value ";
678 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
679 assert_int_equal(YANG_VALUE, kw);
680 assert_int_equal(5, len);
681 str = "when ";
682 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
683 assert_int_equal(YANG_WHEN, kw);
684 assert_int_equal(4, len);
685 str = "yang-version ";
686 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
687 assert_int_equal(YANG_YANG_VERSION, kw);
688 assert_int_equal(12, len);
689 str = "yin-element ";
690 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
691 assert_int_equal(YANG_YIN_ELEMENT, kw);
692 assert_int_equal(11, len);
Radek Krejci626df482018-10-11 15:06:31 +0200693 str = ";config false;";
694 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
695 assert_int_equal(YANG_SEMICOLON, kw);
696 assert_int_equal(1, len);
697 assert_string_equal("config false;", str);
698 str = "{ config false;";
699 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
700 assert_int_equal(YANG_LEFT_BRACE, kw);
701 assert_int_equal(1, len);
702 assert_string_equal(" config false;", str);
703 str = "}";
704 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
705 assert_int_equal(YANG_RIGHT_BRACE, kw);
706 assert_int_equal(1, len);
707 assert_string_equal("", str);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200708
709 /* geenric extension */
710 str = p = "nacm:default-deny-write;";
711 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
712 assert_int_equal(YANG_CUSTOM, kw);
713 assert_int_equal(23, len);
714 assert_ptr_equal(p, word);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200715}
Radek Krejci44ceedc2018-10-02 15:54:31 +0200716
Radek Krejci05b13982018-11-28 16:22:07 +0100717static void
718test_minmax(void **state)
719{
720 *state = test_minmax;
721
Radek Krejcie7b95092019-05-15 11:03:07 +0200722 struct lys_parser_ctx ctx = {0};
Radek Krejci05b13982018-11-28 16:22:07 +0100723 uint16_t flags = 0;
724 uint32_t value = 0;
725 struct lysp_ext_instance *ext = NULL;
726 const char *str;
727
728 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
729 assert_non_null(ctx.ctx);
730 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100731 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci05b13982018-11-28 16:22:07 +0100732
Radek Krejcidf6cad12018-11-28 17:10:55 +0100733 str = " 1invalid; ...";
Radek Krejci05b13982018-11-28 16:22:07 +0100734 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
Radek Krejcidf6cad12018-11-28 17:10:55 +0100735 logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1.");
Radek Krejci05b13982018-11-28 16:22:07 +0100736
737 flags = value = 0;
738 str = " -1; ...";
739 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
740 logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1.");
741
Radek Krejcidf6cad12018-11-28 17:10:55 +0100742 /* implementation limit */
743 flags = value = 0;
744 str = " 4294967296; ...";
745 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
746 logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1.");
747
Radek Krejci05b13982018-11-28 16:22:07 +0100748 flags = value = 0;
749 str = " 1; ...";
750 assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
751 assert_int_equal(LYS_SET_MIN, flags);
752 assert_int_equal(1, value);
753
754 flags = value = 0;
755 str = " 1 {m:ext;} ...";
756 assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
757 assert_int_equal(LYS_SET_MIN, flags);
758 assert_int_equal(1, value);
759 assert_non_null(ext);
760 FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free);
761 ext = NULL;
762
763 flags = value = 0;
764 str = " 1 {config true;} ...";
765 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
766 logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1.");
767
Radek Krejcidf6cad12018-11-28 17:10:55 +0100768 str = " 1invalid; ...";
Radek Krejci05b13982018-11-28 16:22:07 +0100769 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
Radek Krejcidf6cad12018-11-28 17:10:55 +0100770 logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1.");
Radek Krejci05b13982018-11-28 16:22:07 +0100771
772 flags = value = 0;
773 str = " -1; ...";
774 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
775 logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1.");
776
Radek Krejcidf6cad12018-11-28 17:10:55 +0100777 /* implementation limit */
778 flags = value = 0;
779 str = " 4294967296; ...";
780 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
781 logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1.");
782
Radek Krejci05b13982018-11-28 16:22:07 +0100783 flags = value = 0;
784 str = " 1; ...";
785 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
786 assert_int_equal(LYS_SET_MAX, flags);
787 assert_int_equal(1, value);
788
789 flags = value = 0;
790 str = " unbounded; ...";
791 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
792 assert_int_equal(LYS_SET_MAX, flags);
793 assert_int_equal(0, value);
794
795 flags = value = 0;
796 str = " 1 {m:ext;} ...";
797 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
798 assert_int_equal(LYS_SET_MAX, flags);
799 assert_int_equal(1, value);
800 assert_non_null(ext);
801 FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free);
802 ext = NULL;
803
804 flags = value = 0;
805 str = " 1 {config true;} ...";
806 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
807 logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1.");
808
809 *state = NULL;
810 ly_ctx_destroy(ctx.ctx, NULL);
811}
812
Radek Krejci9fcacc12018-10-11 15:59:11 +0200813static struct lysp_module *
Radek Krejcie7b95092019-05-15 11:03:07 +0200814mod_renew(struct lys_parser_ctx *ctx)
Radek Krejci9fcacc12018-10-11 15:59:11 +0200815{
Radek Krejci40544fa2019-01-11 09:38:37 +0100816 struct lysp_module *mod_p;
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100817 static struct lys_module mod = {0};
818
819 lysc_module_free(mod.compiled, NULL);
820 lysp_module_free(mod.parsed);
821 FREE_STRING(mod.ctx, mod.name);
822 FREE_STRING(mod.ctx, mod.ns);
823 FREE_STRING(mod.ctx, mod.prefix);
824 FREE_STRING(mod.ctx, mod.filepath);
825 FREE_STRING(mod.ctx, mod.org);
826 FREE_STRING(mod.ctx, mod.contact);
827 FREE_STRING(mod.ctx, mod.dsc);
828 FREE_STRING(mod.ctx, mod.ref);
829 memset(&mod, 0, sizeof mod);
830 mod.ctx = ctx->ctx;
831
832 mod_p = calloc(1, sizeof *mod_p);
833 mod.parsed = mod_p;
834 mod_p->mod = &mod;
835 assert_non_null(mod_p);
836 return mod_p;
837}
838
839static struct lysp_submodule *
Radek Krejcie7b95092019-05-15 11:03:07 +0200840submod_renew(struct lys_parser_ctx *ctx, struct lysp_submodule *submod)
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100841{
842 lysp_submodule_free(ctx->ctx, submod);
843 submod = calloc(1, sizeof *submod);
844 assert_non_null(submod);
845 return submod;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200846}
847
Radek Krejcid33273d2018-10-25 14:55:52 +0200848static LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
849 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
850 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
851{
852 *module_data = user_data;
853 *format = LYS_IN_YANG;
854 *free_module_data = NULL;
855 return LY_SUCCESS;
856}
857
Radek Krejci9fcacc12018-10-11 15:59:11 +0200858static void
859test_module(void **state)
860{
Radek Krejci40544fa2019-01-11 09:38:37 +0100861 *state = test_module;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200862
Radek Krejcie7b95092019-05-15 11:03:07 +0200863 struct lys_parser_ctx ctx;
Radek Krejci40544fa2019-01-11 09:38:37 +0100864 struct lysp_module *mod = NULL;
865 struct lysp_submodule *submod = NULL;
866 struct lys_module *m;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200867 const char *str;
868
869 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
870 assert_non_null(ctx.ctx);
871 ctx.line = 1;
Radek Krejcia042ea12018-10-13 07:52:15 +0200872 ctx.indent = 0;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200873
Radek Krejci40544fa2019-01-11 09:38:37 +0100874 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200875
876 /* missing mandatory substatements */
877 str = " name {}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100878 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
879 assert_string_equal("name", mod->mod->name);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200880 logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100881 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200882
883 str = " name {namespace urn:x;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100884 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
885 assert_string_equal("urn:x", mod->mod->ns);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200886 logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100887 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200888
889 str = " name {namespace urn:x;prefix \"x\";}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100890 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
891 assert_string_equal("x", mod->mod->prefix);
Radek Krejci40544fa2019-01-11 09:38:37 +0100892 mod = mod_renew(&ctx);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200893
Radek Krejci027d5802018-11-14 16:57:28 +0100894#define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
895#define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";"
Radek Krejcia042ea12018-10-13 07:52:15 +0200896#define TEST_NODE(NODETYPE, INPUT, NAME) \
897 str = SCHEMA_BEGINNING INPUT; \
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100898 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \
Radek Krejcia042ea12018-10-13 07:52:15 +0200899 assert_non_null(mod->data); \
900 assert_int_equal(NODETYPE, mod->data->nodetype); \
901 assert_string_equal(NAME, mod->data->name); \
Radek Krejci40544fa2019-01-11 09:38:37 +0100902 mod = mod_renew(&ctx);
Radek Krejcia042ea12018-10-13 07:52:15 +0200903#define TEST_GENERIC(INPUT, TARGET, TEST) \
904 str = SCHEMA_BEGINNING INPUT; \
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100905 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \
Radek Krejcia042ea12018-10-13 07:52:15 +0200906 assert_non_null(TARGET); \
907 TEST; \
Radek Krejci40544fa2019-01-11 09:38:37 +0100908 mod = mod_renew(&ctx);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100909#define TEST_DUP(MEMBER, VALUE1, VALUE2, LINE) \
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200910 TEST_DUP_GENERIC(SCHEMA_BEGINNING, MEMBER, VALUE1, VALUE2, \
Radek Krejci40544fa2019-01-11 09:38:37 +0100911 parse_module, mod, LINE, mod = mod_renew(&ctx))
Radek Krejcia042ea12018-10-13 07:52:15 +0200912
913 /* duplicated namespace, prefix */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100914 TEST_DUP("namespace", "y", "z", "1");
915 TEST_DUP("prefix", "y", "z", "1");
916 TEST_DUP("contact", "a", "b", "1");
917 TEST_DUP("description", "a", "b", "1");
918 TEST_DUP("organization", "a", "b", "1");
919 TEST_DUP("reference", "a", "b", "1");
Radek Krejcia042ea12018-10-13 07:52:15 +0200920
Radek Krejci70853c52018-10-15 14:46:16 +0200921 /* not allowed in module (submodule-specific) */
922 str = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100923 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci70853c52018-10-15 14:46:16 +0200924 logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100925 mod = mod_renew(&ctx);
Radek Krejci70853c52018-10-15 14:46:16 +0200926
Radek Krejcia042ea12018-10-13 07:52:15 +0200927 /* anydata */
928 TEST_NODE(LYS_ANYDATA, "anydata test;}", "test");
929 /* anyxml */
930 TEST_NODE(LYS_ANYXML, "anyxml test;}", "test");
931 /* augment */
932 TEST_GENERIC("augment /somepath;}", mod->augments,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200933 assert_string_equal("/somepath", mod->augments[0].nodeid));
Radek Krejcia042ea12018-10-13 07:52:15 +0200934 /* choice */
935 TEST_NODE(LYS_CHOICE, "choice test;}", "test");
936 /* contact 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100937 TEST_GENERIC("contact \"firstname\" + \n\t\" surname\";}", mod->mod->contact,
938 assert_string_equal("firstname surname", mod->mod->contact));
Radek Krejcia042ea12018-10-13 07:52:15 +0200939 /* container */
940 TEST_NODE(LYS_CONTAINER, "container test;}", "test");
941 /* description 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100942 TEST_GENERIC("description \'some description\';}", mod->mod->dsc,
943 assert_string_equal("some description", mod->mod->dsc));
Radek Krejcia042ea12018-10-13 07:52:15 +0200944 /* deviation */
945 TEST_GENERIC("deviation /somepath {deviate not-supported;}}", mod->deviations,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200946 assert_string_equal("/somepath", mod->deviations[0].nodeid));
Radek Krejcia042ea12018-10-13 07:52:15 +0200947 /* extension */
948 TEST_GENERIC("extension test;}", mod->extensions,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200949 assert_string_equal("test", mod->extensions[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200950 /* feature */
951 TEST_GENERIC("feature test;}", mod->features,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200952 assert_string_equal("test", mod->features[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200953 /* grouping */
954 TEST_GENERIC("grouping grp;}", mod->groupings,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200955 assert_string_equal("grp", mod->groupings[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200956 /* identity */
957 TEST_GENERIC("identity test;}", mod->identities,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200958 assert_string_equal("test", mod->identities[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200959 /* import */
Radek Krejci086c7132018-10-26 15:29:04 +0200960 ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
961 TEST_GENERIC("import zzz {prefix z;}}", mod->imports,
962 assert_string_equal("zzz", mod->imports[0].name));
Radek Krejci70853c52018-10-15 14:46:16 +0200963
Radek Krejcia042ea12018-10-13 07:52:15 +0200964 /* import - prefix collision */
Radek Krejci086c7132018-10-26 15:29:04 +0200965 str = SCHEMA_BEGINNING "import zzz {prefix x;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100966 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci70853c52018-10-15 14:46:16 +0200967 logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100968 mod = mod_renew(&ctx);
Radek Krejci086c7132018-10-26 15:29:04 +0200969 str = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100970 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci086c7132018-10-26 15:29:04 +0200971 logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
Radek Krejci40544fa2019-01-11 09:38:37 +0100972 mod = mod_renew(&ctx);
Radek Krejci086c7132018-10-26 15:29:04 +0200973 str = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}";
974 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
975 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
976 logbuf_assert("Single revision of the module \"zzz\" referred twice.");
Radek Krejci70853c52018-10-15 14:46:16 +0200977
Radek Krejcia042ea12018-10-13 07:52:15 +0200978 /* include */
Radek Krejci9ed7a192018-10-31 16:23:51 +0100979 store = 1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200980 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 +0200981 str = "module" SCHEMA_BEGINNING "include xxx;}";
982 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
983 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100984 logbuf_assert("Input data contains module in situation when a submodule is expected.");
Radek Krejci9ed7a192018-10-31 16:23:51 +0100985 store = -1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200986
Radek Krejci9ed7a192018-10-31 16:23:51 +0100987 store = 1;
Radek Krejci313d9902018-11-08 09:42:58 +0100988 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 +0200989 str = "module" SCHEMA_BEGINNING "include xxx;}";
990 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
991 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
992 logbuf_assert("Included \"xxx\" submodule from \"name\" belongs-to a different module \"wrong-name\".");
Radek Krejci9ed7a192018-10-31 16:23:51 +0100993 store = -1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200994
Radek Krejci313d9902018-11-08 09:42:58 +0100995 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 +0200996 TEST_GENERIC("include xxx;}", mod->includes,
Radek Krejci086c7132018-10-26 15:29:04 +0200997 assert_string_equal("xxx", mod->includes[0].name));
Radek Krejcid33273d2018-10-25 14:55:52 +0200998
Radek Krejcia042ea12018-10-13 07:52:15 +0200999 /* leaf */
1000 TEST_NODE(LYS_LEAF, "leaf test {type string;}}", "test");
1001 /* leaf-list */
1002 TEST_NODE(LYS_LEAFLIST, "leaf-list test {type string;}}", "test");
1003 /* list */
1004 TEST_NODE(LYS_LIST, "list test {key a;leaf a {type string;}}}", "test");
1005 /* notification */
1006 TEST_GENERIC("notification test;}", mod->notifs,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001007 assert_string_equal("test", mod->notifs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +02001008 /* organization 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001009 TEST_GENERIC("organization \"CESNET a.l.e.\";}", mod->mod->org,
1010 assert_string_equal("CESNET a.l.e.", mod->mod->org));
Radek Krejcia042ea12018-10-13 07:52:15 +02001011 /* reference 0..1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001012 TEST_GENERIC("reference RFC7950;}", mod->mod->ref,
1013 assert_string_equal("RFC7950", mod->mod->ref));
Radek Krejcia042ea12018-10-13 07:52:15 +02001014 /* revision */
1015 TEST_GENERIC("revision 2018-10-12;}", mod->revs,
Radek Krejcib7db73a2018-10-24 14:18:40 +02001016 assert_string_equal("2018-10-12", mod->revs[0].date));
Radek Krejcia042ea12018-10-13 07:52:15 +02001017 /* rpc */
1018 TEST_GENERIC("rpc test;}", mod->rpcs,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001019 assert_string_equal("test", mod->rpcs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +02001020 /* typedef */
1021 TEST_GENERIC("typedef test{type string;}}", mod->typedefs,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001022 assert_string_equal("test", mod->typedefs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +02001023 /* uses */
1024 TEST_NODE(LYS_USES, "uses test;}", "test");
1025 /* yang-version */
Radek Krejci027d5802018-11-14 16:57:28 +01001026 str = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001027 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejcia042ea12018-10-13 07:52:15 +02001028 logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001029 mod = mod_renew(&ctx);
Radek Krejci027d5802018-11-14 16:57:28 +01001030 str = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001031 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejcia042ea12018-10-13 07:52:15 +02001032 logbuf_assert("Duplicate keyword \"yang-version\". Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001033 mod = mod_renew(&ctx);
Radek Krejci027d5802018-11-14 16:57:28 +01001034 str = SCHEMA_BEGINNING2 "yang-version 1.0;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001035 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
1036 assert_int_equal(1, mod->mod->version);
Radek Krejci40544fa2019-01-11 09:38:37 +01001037 mod = mod_renew(&ctx);
Radek Krejci027d5802018-11-14 16:57:28 +01001038 str = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001039 assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
1040 assert_int_equal(2, mod->mod->version);
Radek Krejci40544fa2019-01-11 09:38:37 +01001041 mod = mod_renew(&ctx);
1042
1043 str = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
1044 m = mod->mod;
1045 free(mod);
1046 m->parsed = NULL;
1047 assert_int_equal(LY_EVALID, yang_parse_module(&ctx, str, m));
Radek Krejci0a1d0d42019-05-16 15:14:51 +02001048 logbuf_assert("Trailing garbage \"module q {names...\" after module, expected end-of-input. Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001049 mod = mod_renew(&ctx);
1050
1051 str = "prefix " SCHEMA_BEGINNING "}";
1052 m = mod->mod;
1053 free(mod);
1054 m->parsed = NULL;
1055 assert_int_equal(LY_EVALID, yang_parse_module(&ctx, str, m));
1056 logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 3.");
1057 mod = mod_renew(&ctx);
Radek Krejci09306362018-10-15 15:26:01 +02001058
Radek Krejci156ccaf2018-10-15 15:49:17 +02001059 /* extensions */
1060 TEST_GENERIC("prefix:test;}", mod->exts,
Radek Krejci2c4e7172018-10-19 15:56:26 +02001061 assert_string_equal("prefix:test", mod->exts[0].name);
1062 assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt));
Radek Krejci40544fa2019-01-11 09:38:37 +01001063 mod = mod_renew(&ctx);
Radek Krejci156ccaf2018-10-15 15:49:17 +02001064
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001065 /* invalid substatement */
1066 str = SCHEMA_BEGINNING "must false;}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001067 assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001068 logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001069 mod = mod_renew(&ctx);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001070
Radek Krejci09306362018-10-15 15:26:01 +02001071 /* submodule */
Radek Krejci40544fa2019-01-11 09:38:37 +01001072 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001073
1074 /* missing mandatory substatements */
1075 str = " subname {}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001076 lydict_remove(ctx.ctx, submod->name);
1077 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
1078 assert_string_equal("subname", submod->name);
Radek Krejci09306362018-10-15 15:26:01 +02001079 logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3.");
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001080 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001081
Radek Krejci313d9902018-11-08 09:42:58 +01001082 str = " subname {belongs-to name {prefix x;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001083 lydict_remove(ctx.ctx, submod->name);
1084 assert_int_equal(LY_SUCCESS, parse_submodule(&ctx, &str, submod));
1085 assert_string_equal("name", submod->belongsto);
1086 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001087
1088#undef SCHEMA_BEGINNING
Radek Krejci313d9902018-11-08 09:42:58 +01001089#define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}"
Radek Krejci09306362018-10-15 15:26:01 +02001090
1091 /* duplicated namespace, prefix */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001092 str = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ...";
1093 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); \
1094 logbuf_assert("Duplicate keyword \"belongs-to\". Line number 3."); \
1095 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001096
1097 /* not allowed in submodule (module-specific) */
1098 str = SCHEMA_BEGINNING "namespace \"urn:z\";}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001099 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
Radek Krejci09306362018-10-15 15:26:01 +02001100 logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3.");
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001101 submod = submod_renew(&ctx, submod);
Radek Krejci09306362018-10-15 15:26:01 +02001102 str = SCHEMA_BEGINNING "prefix m;}}";
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001103 assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
Radek Krejci09306362018-10-15 15:26:01 +02001104 logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3.");
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001105 submod = submod_renew(&ctx, submod);
Radek Krejcia042ea12018-10-13 07:52:15 +02001106
Radek Krejci40544fa2019-01-11 09:38:37 +01001107 str = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
1108 lysp_submodule_free(ctx.ctx, submod);
1109 submod = NULL;
1110 assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx, str, &submod));
Radek Krejci0a1d0d42019-05-16 15:14:51 +02001111 logbuf_assert("Trailing garbage \"module q {names...\" after submodule, expected end-of-input. Line number 3.");
Radek Krejci40544fa2019-01-11 09:38:37 +01001112
1113 str = "prefix " SCHEMA_BEGINNING "}";
1114 assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx, str, &submod));
1115 logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 3.");
1116 submod = submod_renew(&ctx, submod);
1117
Radek Krejcia042ea12018-10-13 07:52:15 +02001118#undef TEST_GENERIC
1119#undef TEST_NODE
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001120#undef TEST_DUP
Radek Krejcia042ea12018-10-13 07:52:15 +02001121#undef SCHEMA_BEGINNING
1122
Radek Krejci9fcacc12018-10-11 15:59:11 +02001123 lysp_module_free(mod);
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001124 lysp_submodule_free(ctx.ctx, submod);
Radek Krejci9fcacc12018-10-11 15:59:11 +02001125 ly_ctx_destroy(ctx.ctx, NULL);
Radek Krejci40544fa2019-01-11 09:38:37 +01001126
1127 *state = NULL;
Radek Krejciefd22f62018-09-27 11:47:58 +02001128}
1129
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001130static void
1131test_identity(void **state)
1132{
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001133 *state = test_identity;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001134
Radek Krejcie7b95092019-05-15 11:03:07 +02001135 struct lys_parser_ctx ctx;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001136 struct lysp_ident *ident = NULL;
1137 const char *str;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001138
1139 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1140 assert_non_null(ctx.ctx);
1141 ctx.line = 1;
1142 ctx.indent = 0;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001143 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001144
1145 /* invalid cardinality */
1146#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001147 TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_identity, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001148 &ident, "1", FREE_ARRAY(ctx.ctx, ident, lysp_ident_free); ident = NULL)
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001149
Radek Krejci38222632019-02-12 16:55:05 +01001150 TEST_DUP("description", "a", "b");
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001151 TEST_DUP("reference", "a", "b");
1152 TEST_DUP("status", "current", "obsolete");
1153
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001154 /* full content */
David Sedlák4ccd7c32019-07-10 12:02:04 +02001155 str = " test {base \"a\";base pre:pre:b; description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ...";
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001156 assert_int_equal(LY_SUCCESS, parse_identity(&ctx, &str, &ident));
1157 assert_non_null(ident);
1158 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001159 FREE_ARRAY(ctx.ctx, ident, lysp_ident_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001160 ident = NULL;
1161
1162 /* invalid substatement */
1163 str = " test {organization XXX;}";
1164 assert_int_equal(LY_EVALID, parse_identity(&ctx, &str, &ident));
1165 logbuf_assert("Invalid keyword \"organization\" as a child of \"identity\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001166 FREE_ARRAY(ctx.ctx, ident, lysp_ident_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001167 ident = NULL;
1168
1169#undef TEST_DUP
1170
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001171 *state = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001172 ly_ctx_destroy(ctx.ctx, NULL);
1173}
1174
1175static void
1176test_feature(void **state)
1177{
1178 (void) state; /* unused */
1179
Radek Krejcie7b95092019-05-15 11:03:07 +02001180 struct lys_parser_ctx ctx;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001181 struct lysp_feature *features = NULL;
1182 const char *str;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001183
1184 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1185 assert_non_null(ctx.ctx);
1186 ctx.line = 1;
1187 ctx.indent = 0;
1188
1189 /* invalid cardinality */
1190#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1191 TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_feature, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001192 &features, "1", FREE_ARRAY(ctx.ctx, features, lysp_feature_free); features = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001193
1194 TEST_DUP("description", "a", "b");
1195 TEST_DUP("reference", "a", "b");
1196 TEST_DUP("status", "current", "obsolete");
1197
1198 /* full content */
1199 str = " test {description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ...";
1200 assert_int_equal(LY_SUCCESS, parse_feature(&ctx, &str, &features));
1201 assert_non_null(features);
1202 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001203 FREE_ARRAY(ctx.ctx, features, lysp_feature_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001204 features = NULL;
1205
1206 /* invalid substatement */
1207 str = " test {organization XXX;}";
1208 assert_int_equal(LY_EVALID, parse_feature(&ctx, &str, &features));
1209 logbuf_assert("Invalid keyword \"organization\" as a child of \"feature\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001210 FREE_ARRAY(ctx.ctx, features, lysp_feature_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001211 features = NULL;
1212
1213#undef TEST_DUP
1214
1215 ly_ctx_destroy(ctx.ctx, NULL);
1216}
1217
1218static void
1219test_deviation(void **state)
1220{
1221 (void) state; /* unused */
1222
Radek Krejcie7b95092019-05-15 11:03:07 +02001223 struct lys_parser_ctx ctx;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001224 struct lysp_deviation *d = NULL;
1225 const char *str;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001226
1227 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1228 assert_non_null(ctx.ctx);
1229 ctx.line = 1;
1230 ctx.indent = 0;
1231
1232 /* invalid cardinality */
1233#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1234 TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001235 &d, "1", FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); d = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001236
1237 TEST_DUP("description", "a", "b");
1238 TEST_DUP("reference", "a", "b");
1239
1240 /* full content */
1241 str = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
1242 assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &str, &d));
1243 assert_non_null(d);
1244 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001245 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001246 d = NULL;
1247
1248 /* missing mandatory substatement */
1249 str = " test {description text;}";
1250 assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
1251 logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001252 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001253 d = NULL;
1254
1255 /* invalid substatement */
1256 str = " test {deviate not-supported; status obsolete;}";
1257 assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
1258 logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001259 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001260 d = NULL;
1261
1262#undef TEST_DUP
1263
1264 ly_ctx_destroy(ctx.ctx, NULL);
1265}
1266
1267static void
1268test_deviate(void **state)
1269{
1270 (void) state; /* unused */
1271
Radek Krejcie7b95092019-05-15 11:03:07 +02001272 struct lys_parser_ctx ctx;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001273 struct lysp_deviate *d = NULL;
1274 const char *str;
1275
1276 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1277 assert_non_null(ctx.ctx);
1278 ctx.line = 1;
1279 ctx.indent = 0;
1280
1281 /* invalid cardinality */
1282#define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \
1283 TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001284 &d, "1", lysp_deviate_free(ctx.ctx, d); free(d); d = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001285
1286 TEST_DUP("add", "config", "true", "false");
1287 TEST_DUP("replace", "default", "int8", "uint8");
1288 TEST_DUP("add", "mandatory", "true", "false");
1289 TEST_DUP("add", "max-elements", "1", "2");
1290 TEST_DUP("add", "min-elements", "1", "2");
1291 TEST_DUP("replace", "type", "int8", "uint8");
1292 TEST_DUP("add", "units", "kilometers", "miles");
1293
1294 /* full contents */
1295 str = " not-supported {prefix:ext;} ...";
1296 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1297 assert_non_null(d);
1298 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001299 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001300 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;} ...";
1301 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1302 assert_non_null(d);
1303 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001304 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001305 str = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
1306 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1307 assert_non_null(d);
1308 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001309 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001310 str = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
1311 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1312 assert_non_null(d);
1313 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001314 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001315
1316 /* invalid substatements */
1317#define TEST_NOT_SUP(DEV, STMT, VALUE) \
1318 str = " "DEV" {"STMT" "VALUE";}..."; \
1319 assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); \
1320 logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001321 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001322
1323 TEST_NOT_SUP("not-supported", "units", "meters");
1324 TEST_NOT_SUP("not-supported", "must", "1");
1325 TEST_NOT_SUP("not-supported", "unique", "x");
1326 TEST_NOT_SUP("not-supported", "default", "a");
1327 TEST_NOT_SUP("not-supported", "config", "true");
1328 TEST_NOT_SUP("not-supported", "mandatory", "true");
1329 TEST_NOT_SUP("not-supported", "min-elements", "1");
1330 TEST_NOT_SUP("not-supported", "max-elements", "2");
1331 TEST_NOT_SUP("not-supported", "type", "string");
1332 TEST_NOT_SUP("add", "type", "string");
1333 TEST_NOT_SUP("delete", "config", "true");
1334 TEST_NOT_SUP("delete", "mandatory", "true");
1335 TEST_NOT_SUP("delete", "min-elements", "1");
1336 TEST_NOT_SUP("delete", "max-elements", "2");
1337 TEST_NOT_SUP("delete", "type", "string");
1338 TEST_NOT_SUP("replace", "must", "1");
1339 TEST_NOT_SUP("replace", "unique", "a");
1340
1341 str = " nonsence; ...";
1342 assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d));
1343 logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1.");
1344 assert_null(d);
1345
1346#undef TEST_NOT_SUP
1347#undef TEST_DUP
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001348
1349 ly_ctx_destroy(ctx.ctx, NULL);
1350}
1351
Radek Krejci8c370832018-11-02 15:10:03 +01001352static void
1353test_container(void **state)
1354{
1355 (void) state; /* unused */
1356
Radek Krejcie7b95092019-05-15 11:03:07 +02001357 struct lys_parser_ctx ctx = {0};
Radek Krejci8c370832018-11-02 15:10:03 +01001358 struct lysp_node_container *c = NULL;
1359 const char *str;
1360
1361 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1362 assert_non_null(ctx.ctx);
1363 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001364 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci8c370832018-11-02 15:10:03 +01001365
1366 /* invalid cardinality */
1367#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1368 str = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1369 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); \
1370 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001371 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001372
1373 TEST_DUP("config", "true", "false");
1374 TEST_DUP("description", "text1", "text2");
1375 TEST_DUP("presence", "true", "false");
1376 TEST_DUP("reference", "1", "2");
1377 TEST_DUP("status", "current", "obsolete");
1378 TEST_DUP("when", "true", "false");
1379#undef TEST_DUP
1380
1381 /* full content */
Radek Krejci313d9902018-11-08 09:42:58 +01001382 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;}"
1383 "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 +01001384 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1385 assert_non_null(c);
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001386 assert_int_equal(LYS_CONTAINER, c->nodetype);
1387 assert_string_equal("cont", c->name);
Radek Krejci8c370832018-11-02 15:10:03 +01001388 assert_non_null(c->actions);
1389 assert_non_null(c->child);
1390 assert_string_equal("test", c->dsc);
1391 assert_non_null(c->exts);
1392 assert_non_null(c->groupings);
1393 assert_non_null(c->iffeatures);
1394 assert_non_null(c->musts);
1395 assert_non_null(c->notifs);
1396 assert_string_equal("true", c->presence);
1397 assert_string_equal("test", c->ref);
1398 assert_non_null(c->typedefs);
1399 assert_non_null(c->when);
1400 assert_null(c->parent);
1401 assert_null(c->next);
1402 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags);
Radek Krejci313d9902018-11-08 09:42:58 +01001403 ly_set_erase(&ctx.tpdfs_nodes, NULL);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001404 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001405
1406 /* invalid */
1407 str = " cont {augment /root;} ...";
1408 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1409 logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1.");
Radek Krejci4f28eda2018-11-12 11:46:16 +01001410 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001411 str = " cont {nonsence true;} ...";
1412 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1413 logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1.");
Radek Krejci4f28eda2018-11-12 11:46:16 +01001414 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001415
Radek Krejcif538ce52019-03-05 10:46:14 +01001416 ctx.mod_version = 1; /* simulate YANG 1.0 */
1417 str = " cont {action x;} ...";
1418 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1419 logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1420 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
1421
Radek Krejci8c370832018-11-02 15:10:03 +01001422 ly_ctx_destroy(ctx.ctx, NULL);
1423}
1424
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001425static void
1426test_leaf(void **state)
1427{
1428 *state = test_leaf;
1429
Radek Krejcie7b95092019-05-15 11:03:07 +02001430 struct lys_parser_ctx ctx = {0};
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001431 struct lysp_node_leaf *l = NULL;
1432 const char *str;
1433
1434 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1435 assert_non_null(ctx.ctx);
1436 ctx.line = 1;
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001437 //ctx.mod->version = 2; /* simulate YANG 1.1 */
1438
1439 /* invalid cardinality */
1440#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1441 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1442 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); \
1443 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1444 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1445
1446 TEST_DUP("config", "true", "false");
1447 TEST_DUP("default", "x", "y");
1448 TEST_DUP("description", "text1", "text2");
1449 TEST_DUP("mandatory", "true", "false");
1450 TEST_DUP("reference", "1", "2");
1451 TEST_DUP("status", "current", "obsolete");
Radek Krejci0e5d8382018-11-28 16:37:53 +01001452 TEST_DUP("type", "int8", "uint8");
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001453 TEST_DUP("units", "text1", "text2");
1454 TEST_DUP("when", "true", "false");
1455#undef TEST_DUP
1456
1457 /* full content - without mandatory which is mutual exclusive with default */
1458 str = "l {config false;default \"xxx\";description test;if-feature f;"
1459 "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ...";
1460 assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1461 assert_non_null(l);
1462 assert_int_equal(LYS_LEAF, l->nodetype);
1463 assert_string_equal("l", l->name);
1464 assert_string_equal("test", l->dsc);
1465 assert_string_equal("xxx", l->dflt);
1466 assert_string_equal("yyy", l->units);
1467 assert_string_equal("string", l->type.name);
1468 assert_non_null(l->exts);
1469 assert_non_null(l->iffeatures);
1470 assert_non_null(l->musts);
1471 assert_string_equal("test", l->ref);
1472 assert_non_null(l->when);
1473 assert_null(l->parent);
1474 assert_null(l->next);
1475 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags);
1476 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1477
1478 /* full content - now with mandatory */
1479 str = "l {mandatory true; type string;} ...";
1480 assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1481 assert_non_null(l);
1482 assert_int_equal(LYS_LEAF, l->nodetype);
1483 assert_string_equal("l", l->name);
1484 assert_string_equal("string", l->type.name);
1485 assert_int_equal(LYS_MAND_TRUE, l->flags);
1486 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1487
1488 /* invalid */
1489 str = " l {mandatory true; default xx; type string;} ...";
1490 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
Radek Krejcia9026eb2018-12-12 16:04:47 +01001491 logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"leaf\". Line number 1.");
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001492 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1493
1494 str = " l {description \"missing type\";} ...";
1495 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1496 logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1.");
1497 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1498
1499 *state = NULL;
1500 ly_ctx_destroy(ctx.ctx, NULL);
1501}
1502
Radek Krejci0e5d8382018-11-28 16:37:53 +01001503static void
1504test_leaflist(void **state)
1505{
1506 *state = test_leaf;
1507
Radek Krejcie7b95092019-05-15 11:03:07 +02001508 struct lys_parser_ctx ctx = {0};
Radek Krejci0e5d8382018-11-28 16:37:53 +01001509 struct lysp_node_leaflist *ll = NULL;
1510 const char *str;
1511
1512 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1513 assert_non_null(ctx.ctx);
1514 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001515 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001516
1517 /* invalid cardinality */
1518#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1519 str = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1520 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); \
1521 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1522 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1523
1524 TEST_DUP("config", "true", "false");
1525 TEST_DUP("description", "text1", "text2");
1526 TEST_DUP("max-elements", "10", "20");
1527 TEST_DUP("min-elements", "10", "20");
1528 TEST_DUP("ordered-by", "user", "system");
1529 TEST_DUP("reference", "1", "2");
1530 TEST_DUP("status", "current", "obsolete");
1531 TEST_DUP("type", "int8", "uint8");
1532 TEST_DUP("units", "text1", "text2");
1533 TEST_DUP("when", "true", "false");
1534#undef TEST_DUP
1535
1536 /* full content - without min-elements which is mutual exclusive with default */
1537 str = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
1538 "max-elements 10;must 'expr';ordered-by user;reference test;"
1539 "status current;type string; units zzz;when true;m:ext;} ...";
1540 assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1541 assert_non_null(ll);
1542 assert_int_equal(LYS_LEAFLIST, ll->nodetype);
1543 assert_string_equal("ll", ll->name);
1544 assert_string_equal("test", ll->dsc);
1545 assert_non_null(ll->dflts);
1546 assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts));
1547 assert_string_equal("xxx", ll->dflts[0]);
1548 assert_string_equal("yyy", ll->dflts[1]);
1549 assert_string_equal("zzz", ll->units);
1550 assert_int_equal(10, ll->max);
1551 assert_int_equal(0, ll->min);
1552 assert_string_equal("string", ll->type.name);
1553 assert_non_null(ll->exts);
1554 assert_non_null(ll->iffeatures);
1555 assert_non_null(ll->musts);
1556 assert_string_equal("test", ll->ref);
1557 assert_non_null(ll->when);
1558 assert_null(ll->parent);
1559 assert_null(ll->next);
1560 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
1561 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1562
1563 /* full content - now with min-elements */
1564 str = "ll {min-elements 10; type string;} ...";
1565 assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1566 assert_non_null(ll);
1567 assert_int_equal(LYS_LEAFLIST, ll->nodetype);
1568 assert_string_equal("ll", ll->name);
1569 assert_string_equal("string", ll->type.name);
1570 assert_int_equal(0, ll->max);
1571 assert_int_equal(10, ll->min);
1572 assert_int_equal(LYS_SET_MIN, ll->flags);
1573 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1574
1575 /* invalid */
1576 str = " ll {min-elements 1; default xx; type string;} ...";
1577 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
Radek Krejcia9026eb2018-12-12 16:04:47 +01001578 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 +01001579 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1580
1581 str = " ll {description \"missing type\";} ...";
1582 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1583 logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1.");
1584 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1585
Radek Krejcidf6cad12018-11-28 17:10:55 +01001586 str = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */
1587 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1588 logbuf_assert("Invalid combination of min-elements and max-elements: min value 10 is bigger than the max value 1. Line number 1.");
1589 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1590
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001591 ctx.mod_version = 1; /* simulate YANG 1.0 - default statement is not allowed */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001592 str = " ll {default xx; type string;} ...";
1593 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1594 logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1595 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1596
1597 *state = NULL;
1598 ly_ctx_destroy(ctx.ctx, NULL);
1599}
1600
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001601static void
1602test_list(void **state)
1603{
1604 *state = test_list;
1605
Radek Krejcie7b95092019-05-15 11:03:07 +02001606 struct lys_parser_ctx ctx = {0};
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001607 struct lysp_node_list *l = NULL;
1608 const char *str;
1609
1610 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1611 assert_non_null(ctx.ctx);
1612 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001613 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001614
1615 /* invalid cardinality */
1616#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1617 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1618 assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); \
1619 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1620 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1621
1622 TEST_DUP("config", "true", "false");
1623 TEST_DUP("description", "text1", "text2");
1624 TEST_DUP("key", "one", "two");
1625 TEST_DUP("max-elements", "10", "20");
1626 TEST_DUP("min-elements", "10", "20");
1627 TEST_DUP("ordered-by", "user", "system");
1628 TEST_DUP("reference", "1", "2");
1629 TEST_DUP("status", "current", "obsolete");
1630 TEST_DUP("when", "true", "false");
1631#undef TEST_DUP
1632
1633 /* full content */
1634 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;}"
1635 "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;"
1636 "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ...";
1637 assert_int_equal(LY_SUCCESS, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l));
1638 assert_non_null(l);
1639 assert_int_equal(LYS_LIST, l->nodetype);
1640 assert_string_equal("l", l->name);
1641 assert_string_equal("test", l->dsc);
1642 assert_string_equal("l", l->key);
1643 assert_non_null(l->uniques);
1644 assert_int_equal(2, LY_ARRAY_SIZE(l->uniques));
1645 assert_string_equal("xxx", l->uniques[0]);
1646 assert_string_equal("yyy", l->uniques[1]);
1647 assert_int_equal(10, l->max);
1648 assert_int_equal(1, l->min);
1649 assert_non_null(l->exts);
1650 assert_non_null(l->iffeatures);
1651 assert_non_null(l->musts);
1652 assert_string_equal("test", l->ref);
1653 assert_non_null(l->when);
1654 assert_null(l->parent);
1655 assert_null(l->next);
1656 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, l->flags);
1657 ly_set_erase(&ctx.tpdfs_nodes, NULL);
1658 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1659
Radek Krejcif538ce52019-03-05 10:46:14 +01001660 /* invalid content */
1661 ctx.mod_version = 1; /* simulate YANG 1.0 */
1662 str = "l {action x;} ...";
1663 assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l));
1664 logbuf_assert("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1665 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1666
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001667 *state = NULL;
1668 ly_ctx_destroy(ctx.ctx, NULL);
1669}
1670
Radek Krejci056d0a82018-12-06 16:57:25 +01001671static void
1672test_choice(void **state)
1673{
1674 *state = test_choice;
1675
Radek Krejcie7b95092019-05-15 11:03:07 +02001676 struct lys_parser_ctx ctx = {0};
Radek Krejci056d0a82018-12-06 16:57:25 +01001677 struct lysp_node_choice *ch = NULL;
1678 const char *str;
1679
1680 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1681 assert_non_null(ctx.ctx);
1682 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001683 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci056d0a82018-12-06 16:57:25 +01001684
1685 /* invalid cardinality */
1686#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1687 str = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1688 assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); \
1689 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1690 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1691
1692 TEST_DUP("config", "true", "false");
1693 TEST_DUP("default", "a", "b");
1694 TEST_DUP("description", "text1", "text2");
1695 TEST_DUP("mandatory", "true", "false");
1696 TEST_DUP("reference", "1", "2");
1697 TEST_DUP("status", "current", "obsolete");
1698 TEST_DUP("when", "true", "false");
1699#undef TEST_DUP
1700
Radek Krejcia9026eb2018-12-12 16:04:47 +01001701 /* full content - without default due to a collision with mandatory */
1702 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 +01001703 "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
1704 assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
1705 assert_non_null(ch);
1706 assert_int_equal(LYS_CHOICE, ch->nodetype);
1707 assert_string_equal("ch", ch->name);
1708 assert_string_equal("test", ch->dsc);
1709 assert_non_null(ch->exts);
1710 assert_non_null(ch->iffeatures);
1711 assert_string_equal("test", ch->ref);
1712 assert_non_null(ch->when);
1713 assert_null(ch->parent);
1714 assert_null(ch->next);
1715 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags);
1716 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1717
Radek Krejcia9026eb2018-12-12 16:04:47 +01001718 /* full content - the default missing from the previous node */
1719 str = "ch {default c;case c;} ...";
1720 assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
1721 assert_non_null(ch);
1722 assert_int_equal(LYS_CHOICE, ch->nodetype);
1723 assert_string_equal("ch", ch->name);
1724 assert_string_equal("c", ch->dflt);
1725 assert_int_equal(0, ch->flags);
1726 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1727
1728 /* invalid content */
1729 str = "ch {mandatory true; default c1; case c1 {leaf x{type string;}}} ...";
1730 assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
1731 logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"choice\". Line number 1.");
1732 lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
1733
1734 *state = NULL;
1735 ly_ctx_destroy(ctx.ctx, NULL);
1736}
1737
1738static void
1739test_case(void **state)
1740{
1741 *state = test_case;
1742
Radek Krejcie7b95092019-05-15 11:03:07 +02001743 struct lys_parser_ctx ctx = {0};
Radek Krejcia9026eb2018-12-12 16:04:47 +01001744 struct lysp_node_case *cs = NULL;
1745 const char *str;
1746
1747 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1748 assert_non_null(ctx.ctx);
1749 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001750 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejcia9026eb2018-12-12 16:04:47 +01001751
1752 /* invalid cardinality */
1753#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1754 str = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1755 assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); \
1756 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1757 lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
1758
1759 TEST_DUP("description", "text1", "text2");
1760 TEST_DUP("reference", "1", "2");
1761 TEST_DUP("status", "current", "obsolete");
1762 TEST_DUP("when", "true", "false");
1763#undef TEST_DUP
1764
1765 /* full content */
1766 str = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}"
1767 "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
1768 assert_int_equal(LY_SUCCESS, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs));
1769 assert_non_null(cs);
1770 assert_int_equal(LYS_CASE, cs->nodetype);
1771 assert_string_equal("cs", cs->name);
1772 assert_string_equal("test", cs->dsc);
1773 assert_non_null(cs->exts);
1774 assert_non_null(cs->iffeatures);
1775 assert_string_equal("test", cs->ref);
1776 assert_non_null(cs->when);
1777 assert_null(cs->parent);
1778 assert_null(cs->next);
1779 assert_int_equal(LYS_STATUS_CURR, cs->flags);
1780 lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
1781
1782 /* invalid content */
1783 str = "cs {config true} ...";
1784 assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs));
1785 logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1.");
1786 lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
1787
Radek Krejci056d0a82018-12-06 16:57:25 +01001788 *state = NULL;
1789 ly_ctx_destroy(ctx.ctx, NULL);
1790}
1791
Radek Krejci9800fb82018-12-13 14:26:23 +01001792static void
1793test_any(void **state, enum yang_keyword kw)
1794{
1795 *state = test_any;
1796
Radek Krejcie7b95092019-05-15 11:03:07 +02001797 struct lys_parser_ctx ctx = {0};
Radek Krejci9800fb82018-12-13 14:26:23 +01001798 struct lysp_node_anydata *any = NULL;
1799 const char *str;
1800
1801 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1802 assert_non_null(ctx.ctx);
1803 ctx.line = 1;
Radek Krejci9800fb82018-12-13 14:26:23 +01001804 if (kw == YANG_ANYDATA) {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001805 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci9800fb82018-12-13 14:26:23 +01001806 } else {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001807 ctx.mod_version = 1; /* simulate YANG 1.0 */
Radek Krejci9800fb82018-12-13 14:26:23 +01001808 }
1809
1810 /* invalid cardinality */
1811#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1812 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1813 assert_int_equal(LY_EVALID, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); \
1814 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1815 lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
1816
1817 TEST_DUP("config", "true", "false");
1818 TEST_DUP("description", "text1", "text2");
1819 TEST_DUP("mandatory", "true", "false");
1820 TEST_DUP("reference", "1", "2");
1821 TEST_DUP("status", "current", "obsolete");
1822 TEST_DUP("when", "true", "false");
1823#undef TEST_DUP
1824
1825 /* full content */
1826 str = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
1827 assert_int_equal(LY_SUCCESS, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any));
1828 assert_non_null(any);
1829 assert_int_equal(kw == YANG_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype);
1830 assert_string_equal("any", any->name);
1831 assert_string_equal("test", any->dsc);
1832 assert_non_null(any->exts);
1833 assert_non_null(any->iffeatures);
1834 assert_non_null(any->musts);
1835 assert_string_equal("test", any->ref);
1836 assert_non_null(any->when);
1837 assert_null(any->parent);
1838 assert_null(any->next);
1839 assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags);
1840 lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
1841
1842 *state = NULL;
1843 ly_ctx_destroy(ctx.ctx, NULL);
1844}
1845
1846static void
1847test_anydata(void **state)
1848{
1849 return test_any(state, YANG_ANYDATA);
1850}
1851
1852static void
1853test_anyxml(void **state)
1854{
1855 return test_any(state, YANG_ANYXML);
1856}
1857
Radek Krejcie86bf772018-12-14 11:39:53 +01001858static void
1859test_grouping(void **state)
1860{
1861 *state = test_grouping;
1862
Radek Krejcie7b95092019-05-15 11:03:07 +02001863 struct lys_parser_ctx ctx = {0};
Radek Krejcie86bf772018-12-14 11:39:53 +01001864 struct lysp_grp *grp = NULL;
1865 const char *str;
1866
1867 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1868 assert_non_null(ctx.ctx);
1869 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001870 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejcie86bf772018-12-14 11:39:53 +01001871
1872 /* invalid cardinality */
1873#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1874 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1875 assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); \
1876 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1877 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1878
1879 TEST_DUP("description", "text1", "text2");
1880 TEST_DUP("reference", "1", "2");
1881 TEST_DUP("status", "current", "obsolete");
1882#undef TEST_DUP
1883
1884 /* full content */
1885 str = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}"
1886 "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ...";
1887 assert_int_equal(LY_SUCCESS, parse_grouping(&ctx, &str, NULL, &grp));
1888 assert_non_null(grp);
1889 assert_int_equal(LYS_GROUPING, grp->nodetype);
1890 assert_string_equal("grp", grp->name);
1891 assert_string_equal("test", grp->dsc);
1892 assert_non_null(grp->exts);
1893 assert_string_equal("test", grp->ref);
1894 assert_null(grp->parent);
1895 assert_int_equal( LYS_STATUS_CURR, grp->flags);
1896 ly_set_erase(&ctx.tpdfs_nodes, NULL);
1897 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1898
1899 /* invalid content */
1900 str = "grp {config true} ...";
1901 assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp));
1902 logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1.");
1903 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1904
1905 str = "grp {must 'expr'} ...";
1906 assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp));
1907 logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1.");
1908 FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
1909
1910 *state = NULL;
1911 ly_ctx_destroy(ctx.ctx, NULL);
1912}
1913
1914static void
Radek Krejcif538ce52019-03-05 10:46:14 +01001915test_action(void **state)
1916{
1917 *state = test_action;
1918
Radek Krejcie7b95092019-05-15 11:03:07 +02001919 struct lys_parser_ctx ctx = {0};
Radek Krejcif538ce52019-03-05 10:46:14 +01001920 struct lysp_action *rpcs = NULL;
1921 struct lysp_node_container *c = NULL;
1922 const char *str;
1923
1924 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1925 assert_non_null(ctx.ctx);
1926 ctx.line = 1;
1927 ctx.mod_version = 2; /* simulate YANG 1.1 */
1928
1929 /* invalid cardinality */
1930#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1931 str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1932 assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs)); \
1933 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1934 FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
1935
1936 TEST_DUP("description", "text1", "text2");
1937 TEST_DUP("input", "", "");
1938 TEST_DUP("output", "", "");
1939 TEST_DUP("reference", "1", "2");
1940 TEST_DUP("status", "current", "obsolete");
1941#undef TEST_DUP
1942
1943 /* full content */
1944 str = "top;";
1945 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1946 str = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;"
1947 "input {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
1948 " list li; must 1; typedef mytypei {type int8;} uses grp; m:ext;}"
1949 "output {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
1950 " list li; must 1; typedef mytypeo {type int8;} uses grp; m:ext;}} ...";
1951 assert_int_equal(LY_SUCCESS, parse_action(&ctx, &str, (struct lysp_node*)c, &rpcs));
1952 assert_non_null(rpcs);
1953 assert_int_equal(LYS_ACTION, rpcs->nodetype);
1954 assert_string_equal("func", rpcs->name);
1955 assert_string_equal("test", rpcs->dsc);
1956 assert_non_null(rpcs->exts);
1957 assert_non_null(rpcs->iffeatures);
1958 assert_string_equal("test", rpcs->ref);
1959 assert_non_null(rpcs->groupings);
1960 assert_non_null(rpcs->typedefs);
1961 assert_int_equal(LYS_STATUS_CURR, rpcs->flags);
1962 /* input */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963 assert_int_equal(rpcs->input.nodetype, LYS_INPUT);
Radek Krejcif538ce52019-03-05 10:46:14 +01001964 assert_non_null(rpcs->input.groupings);
1965 assert_non_null(rpcs->input.exts);
1966 assert_non_null(rpcs->input.musts);
1967 assert_non_null(rpcs->input.typedefs);
1968 assert_non_null(rpcs->input.data);
1969 /* output */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970 assert_int_equal(rpcs->output.nodetype, LYS_OUTPUT);
Radek Krejcif538ce52019-03-05 10:46:14 +01001971 assert_non_null(rpcs->output.groupings);
1972 assert_non_null(rpcs->output.exts);
1973 assert_non_null(rpcs->output.musts);
1974 assert_non_null(rpcs->output.typedefs);
1975 assert_non_null(rpcs->output.data);
1976
1977 ly_set_erase(&ctx.tpdfs_nodes, NULL);
1978 FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
1979
1980 /* invalid content */
1981 str = "func {config true} ...";
1982 assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs));
1983 logbuf_assert("Invalid keyword \"config\" as a child of \"rpc\". Line number 1.");
1984 FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
1985
1986 *state = NULL;
1987 lysp_node_free(ctx.ctx, (struct lysp_node*)c);
1988 ly_ctx_destroy(ctx.ctx, NULL);
1989}
1990
1991static void
Radek Krejcifc11bd72019-04-11 16:00:05 +02001992test_notification(void **state)
1993{
1994 *state = test_notification;
1995
Radek Krejcie7b95092019-05-15 11:03:07 +02001996 struct lys_parser_ctx ctx = {0};
Radek Krejcifc11bd72019-04-11 16:00:05 +02001997 struct lysp_notif *notifs = NULL;
1998 struct lysp_node_container *c = NULL;
1999 const char *str;
2000
2001 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2002 assert_non_null(ctx.ctx);
2003 ctx.line = 1;
2004 ctx.mod_version = 2; /* simulate YANG 1.1 */
2005
2006 /* invalid cardinality */
2007#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2008 str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2009 assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, &notifs)); \
2010 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
2011 FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
2012
2013 TEST_DUP("description", "text1", "text2");
2014 TEST_DUP("reference", "1", "2");
2015 TEST_DUP("status", "current", "obsolete");
2016#undef TEST_DUP
2017
2018 /* full content */
2019 str = "top;";
2020 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
2021 str = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}"
2022 "leaf-list ll {type int8;} list li; must 1; reference test; status current; typedef mytype {type int8;} uses grp; m:ext;}";
2023 assert_int_equal(LY_SUCCESS, parse_notif(&ctx, &str, (struct lysp_node*)c, &notifs));
2024 assert_non_null(notifs);
2025 assert_int_equal(LYS_NOTIF, notifs->nodetype);
2026 assert_string_equal("ntf", notifs->name);
2027 assert_string_equal("test", notifs->dsc);
2028 assert_non_null(notifs->exts);
2029 assert_non_null(notifs->iffeatures);
2030 assert_string_equal("test", notifs->ref);
2031 assert_non_null(notifs->groupings);
2032 assert_non_null(notifs->typedefs);
2033 assert_non_null(notifs->musts);
2034 assert_non_null(notifs->data);
2035 assert_int_equal(LYS_STATUS_CURR, notifs->flags);
2036
2037 ly_set_erase(&ctx.tpdfs_nodes, NULL);
2038 FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
2039
2040 /* invalid content */
2041 str = "ntf {config true} ...";
2042 assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, &notifs));
2043 logbuf_assert("Invalid keyword \"config\" as a child of \"notification\". Line number 1.");
2044 FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
2045
2046 *state = NULL;
2047 lysp_node_free(ctx.ctx, (struct lysp_node*)c);
2048 ly_ctx_destroy(ctx.ctx, NULL);
2049}
2050
2051static void
Radek Krejcie86bf772018-12-14 11:39:53 +01002052test_uses(void **state)
2053{
2054 *state = test_uses;
2055
Radek Krejcie7b95092019-05-15 11:03:07 +02002056 struct lys_parser_ctx ctx = {0};
Radek Krejcie86bf772018-12-14 11:39:53 +01002057 struct lysp_node_uses *u = NULL;
2058 const char *str;
2059
2060 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2061 assert_non_null(ctx.ctx);
2062 ctx.line = 1;
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002063 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejcie86bf772018-12-14 11:39:53 +01002064
2065 /* invalid cardinality */
2066#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2067 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2068 assert_int_equal(LY_EVALID, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); \
2069 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
2070 lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL;
2071
2072 TEST_DUP("description", "text1", "text2");
2073 TEST_DUP("reference", "1", "2");
2074 TEST_DUP("status", "current", "obsolete");
2075 TEST_DUP("when", "true", "false");
2076#undef TEST_DUP
2077
2078 /* full content */
2079 str = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ...";
2080 assert_int_equal(LY_SUCCESS, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u));
2081 assert_non_null(u);
2082 assert_int_equal(LYS_USES, u->nodetype);
2083 assert_string_equal("grpref", u->name);
2084 assert_string_equal("test", u->dsc);
2085 assert_non_null(u->exts);
2086 assert_non_null(u->iffeatures);
2087 assert_string_equal("test", u->ref);
2088 assert_non_null(u->augments);
2089 assert_non_null(u->refines);
2090 assert_non_null(u->when);
2091 assert_null(u->parent);
2092 assert_null(u->next);
2093 assert_int_equal(LYS_STATUS_CURR, u->flags);
2094 lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL;
2095
2096 *state = NULL;
2097 ly_ctx_destroy(ctx.ctx, NULL);
2098}
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002099
2100
2101static void
2102test_augment(void **state)
2103{
2104 *state = test_augment;
2105
Radek Krejcie7b95092019-05-15 11:03:07 +02002106 struct lys_parser_ctx ctx = {0};
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002107 struct lysp_augment *a = NULL;
2108 const char *str;
2109
2110 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2111 assert_non_null(ctx.ctx);
2112 ctx.line = 1;
Radek Krejcib4adbf12019-02-25 13:35:22 +01002113 ctx.mod_version = 2; /* simulate YANG 1.1 */
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002114
2115 /* invalid cardinality */
2116#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2117 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2118 assert_int_equal(LY_EVALID, parse_augment(&ctx, &str, NULL, &a)); \
2119 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
Radek Krejcib4adbf12019-02-25 13:35:22 +01002120 FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL;
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002121
2122 TEST_DUP("description", "text1", "text2");
2123 TEST_DUP("reference", "1", "2");
2124 TEST_DUP("status", "current", "obsolete");
2125 TEST_DUP("when", "true", "false");
2126#undef TEST_DUP
2127
2128 /* full content */
2129 str = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}"
2130 "leaf-list ll {type string;} list li;notification not;reference test;status current;uses g;when true;m:ext;} ...";
2131 assert_int_equal(LY_SUCCESS, parse_augment(&ctx, &str, NULL, &a));
2132 assert_non_null(a);
2133 assert_int_equal(LYS_AUGMENT, a->nodetype);
2134 assert_string_equal("/target/nodeid", a->nodeid);
2135 assert_string_equal("test", a->dsc);
2136 assert_non_null(a->exts);
2137 assert_non_null(a->iffeatures);
2138 assert_string_equal("test", a->ref);
2139 assert_non_null(a->when);
2140 assert_null(a->parent);
2141 assert_int_equal(LYS_STATUS_CURR, a->flags);
Radek Krejcib4adbf12019-02-25 13:35:22 +01002142 FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL;
Radek Krejci5a7c4a52019-02-12 15:45:11 +01002143
2144 *state = NULL;
2145 ly_ctx_destroy(ctx.ctx, NULL);
2146}
2147
Radek Krejcif09e4e82019-06-14 15:08:11 +02002148static void
2149test_when(void **state)
2150{
2151 *state = test_when;
2152
2153 struct lys_parser_ctx ctx = {0};
2154 struct lysp_when *w = NULL;
2155 const char *str;
2156
2157 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
2158 assert_non_null(ctx.ctx);
2159 ctx.line = 1;
2160 ctx.mod_version = 2; /* simulate YANG 1.1 */
2161
2162 /* invalid cardinality */
2163#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
2164 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
2165 assert_int_equal(LY_EVALID, parse_when(&ctx, &str, &w)); \
2166 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
2167 FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
2168
2169 TEST_DUP("description", "text1", "text2");
2170 TEST_DUP("reference", "1", "2");
2171#undef TEST_DUP
2172
2173 /* full content */
2174 str = "expression {description test;reference test;m:ext;} ...";
2175 assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w));
2176 assert_non_null(w);
2177 assert_string_equal("expression", w->cond);
2178 assert_string_equal("test", w->dsc);
2179 assert_string_equal("test", w->ref);
2180 assert_non_null(w->exts);
2181 FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
2182
2183 /* empty condition */
2184 str = "\"\";";
2185 assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w));
2186 logbuf_assert("Empty argument of when statement does not make sense.");
2187 assert_non_null(w);
2188 assert_string_equal("", w->cond);
2189 FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
2190
2191 *state = NULL;
2192 ly_ctx_destroy(ctx.ctx, NULL);
2193}
2194
Radek Krejci80dd33e2018-09-26 15:57:18 +02002195int main(void)
2196{
2197 const struct CMUnitTest tests[] = {
Radek Krejci44ceedc2018-10-02 15:54:31 +02002198 cmocka_unit_test_setup(test_helpers, logger_setup),
Radek Krejci80dd33e2018-09-26 15:57:18 +02002199 cmocka_unit_test_setup(test_comments, logger_setup),
Radek Krejciefd22f62018-09-27 11:47:58 +02002200 cmocka_unit_test_setup(test_arg, logger_setup),
Radek Krejcidcc7b322018-10-11 14:24:02 +02002201 cmocka_unit_test_setup(test_stmts, logger_setup),
Radek Krejci05b13982018-11-28 16:22:07 +01002202 cmocka_unit_test_setup_teardown(test_minmax, logger_setup, logger_teardown),
Radek Krejci40544fa2019-01-11 09:38:37 +01002203 cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002204 cmocka_unit_test_setup_teardown(test_identity, logger_setup, logger_teardown),
Radek Krejci2c02f3e2018-10-16 10:54:38 +02002205 cmocka_unit_test_setup(test_feature, logger_setup),
2206 cmocka_unit_test_setup(test_deviation, logger_setup),
2207 cmocka_unit_test_setup(test_deviate, logger_setup),
Radek Krejci8c370832018-11-02 15:10:03 +01002208 cmocka_unit_test_setup(test_container, logger_setup),
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01002209 cmocka_unit_test_setup_teardown(test_leaf, logger_setup, logger_teardown),
Radek Krejci0e5d8382018-11-28 16:37:53 +01002210 cmocka_unit_test_setup_teardown(test_leaflist, logger_setup, logger_teardown),
Radek Krejci9bb94eb2018-12-04 16:48:35 +01002211 cmocka_unit_test_setup_teardown(test_list, logger_setup, logger_teardown),
Radek Krejci056d0a82018-12-06 16:57:25 +01002212 cmocka_unit_test_setup_teardown(test_choice, logger_setup, logger_teardown),
Radek Krejcia9026eb2018-12-12 16:04:47 +01002213 cmocka_unit_test_setup_teardown(test_case, logger_setup, logger_teardown),
Radek Krejci9800fb82018-12-13 14:26:23 +01002214 cmocka_unit_test_setup_teardown(test_anydata, logger_setup, logger_teardown),
2215 cmocka_unit_test_setup_teardown(test_anyxml, logger_setup, logger_teardown),
Radek Krejcif538ce52019-03-05 10:46:14 +01002216 cmocka_unit_test_setup_teardown(test_action, logger_setup, logger_teardown),
Radek Krejcifc11bd72019-04-11 16:00:05 +02002217 cmocka_unit_test_setup_teardown(test_notification, logger_setup, logger_teardown),
Radek Krejcie86bf772018-12-14 11:39:53 +01002218 cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown),
2219 cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown),
Radek Krejcib4adbf12019-02-25 13:35:22 +01002220 cmocka_unit_test_setup_teardown(test_augment, logger_setup, logger_teardown),
Radek Krejcif09e4e82019-06-14 15:08:11 +02002221 cmocka_unit_test_setup_teardown(test_when, logger_setup, logger_teardown),
Radek Krejci80dd33e2018-09-26 15:57:18 +02002222 };
2223
2224 return cmocka_run_group_tests(tests, NULL, NULL);
2225}