blob: ed46b794f0d4129b6882e6cada32da51a2cd967b [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 Krejcif3f47842018-11-15 11:22:15 +010015#include "../../src/common.c"
16#include "../../src/set.c"
17#include "../../src/log.c"
18#include "../../src/hash_table.c"
19#include "../../src/xpath.c"
Radek Krejci86d106e2018-10-18 09:53:19 +020020#include "../../src/parser_yang.c"
Radek Krejcif3f47842018-11-15 11:22:15 +010021#include "../../src/context.c"
22#include "../../src/tree_schema_helpers.c"
Radek Krejci19a96102018-11-15 13:38:09 +010023#include "../../src/tree_schema_free.c"
24#include "../../src/tree_schema_compile.c"
Radek Krejcif3f47842018-11-15 11:22:15 +010025#include "../../src/tree_schema.c"
Radek Krejci86d106e2018-10-18 09:53:19 +020026
Radek Krejci80dd33e2018-09-26 15:57:18 +020027#include <stdarg.h>
28#include <stddef.h>
29#include <setjmp.h>
30#include <cmocka.h>
31
32#include <stdio.h>
33#include <string.h>
34
35#include "libyang.h"
Radek Krejci80dd33e2018-09-26 15:57:18 +020036
37#define BUFSIZE 1024
38char logbuf[BUFSIZE] = {0};
Radek Krejci9ed7a192018-10-31 16:23:51 +010039int store = -1; /* negative for infinite logging, positive for limited logging */
Radek Krejci80dd33e2018-09-26 15:57:18 +020040
41/* set to 0 to printing error messages to stderr instead of checking them in code */
Radek Krejci70853c52018-10-15 14:46:16 +020042#define ENABLE_LOGGER_CHECKING 1
Radek Krejci80dd33e2018-09-26 15:57:18 +020043
Radek Krejcid5f2b5f2018-10-11 10:54:36 +020044#if ENABLE_LOGGER_CHECKING
Radek Krejci80dd33e2018-09-26 15:57:18 +020045static void
46logger(LY_LOG_LEVEL level, const char *msg, const char *path)
47{
48 (void) level; /* unused */
Radek Krejci9ed7a192018-10-31 16:23:51 +010049 if (store) {
50 if (path && path[0]) {
51 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
52 } else {
53 strncpy(logbuf, msg, BUFSIZE - 1);
54 }
55 if (store > 0) {
56 --store;
57 }
Radek Krejci80dd33e2018-09-26 15:57:18 +020058 }
59}
Radek Krejcid5f2b5f2018-10-11 10:54:36 +020060#endif
Radek Krejci80dd33e2018-09-26 15:57:18 +020061
62static int
63logger_setup(void **state)
64{
65 (void) state; /* unused */
66#if ENABLE_LOGGER_CHECKING
67 ly_set_log_clb(logger, 1);
68#endif
69 return 0;
70}
71
Radek Krejcib1a5dcc2018-11-26 14:50:05 +010072static int
73logger_teardown(void **state)
74{
75 (void) state; /* unused */
76#if ENABLE_LOGGER_CHECKING
77 if (*state) {
78 fprintf(stderr, "%s\n", logbuf);
79 }
80#endif
81 return 0;
82}
83
Radek Krejci80dd33e2018-09-26 15:57:18 +020084void
85logbuf_clean(void)
86{
87 logbuf[0] = '\0';
88}
89
90#if ENABLE_LOGGER_CHECKING
91# define logbuf_assert(str) assert_string_equal(logbuf, str)
92#else
93# define logbuf_assert(str)
94#endif
95
Radek Krejci2c02f3e2018-10-16 10:54:38 +020096#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
97 str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
98 assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
99 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
100 CLEANUP
101
Radek Krejci44ceedc2018-10-02 15:54:31 +0200102static void
103test_helpers(void **state)
104{
105 (void) state; /* unused */
106
107 const char *str;
Radek Krejci404251e2018-10-09 12:06:44 +0200108 char *buf, *p;
Radek Krejci44ceedc2018-10-02 15:54:31 +0200109 size_t len, size;
110 int prefix;
111 struct ly_parser_ctx ctx;
112 ctx.ctx = NULL;
113 ctx.line = 1;
114
115 /* storing into buffer */
116 str = "abcd";
117 buf = NULL;
118 size = len = 0;
119 assert_int_equal(LY_SUCCESS, buf_add_char(NULL, &str, 2, &buf, &size, &len));
120 assert_int_not_equal(0, size);
121 assert_int_equal(2, len);
122 assert_string_equal("cd", str);
123 assert_false(strncmp("ab", buf, 2));
124 free(buf);
Radek Krejci404251e2018-10-09 12:06:44 +0200125 buf = NULL;
126
127 /* invalid first characters */
128 len = 0;
129 str = "2invalid";
130 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
131 str = ".invalid";
132 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
133 str = "-invalid";
134 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
135 /* invalid following characters */
136 len = 3; /* number of characters read before the str content */
137 str = "!";
138 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
139 str = ":";
140 assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
141 /* valid colon for prefixed identifiers */
142 len = size = 0;
143 p = NULL;
144 str = "x:id";
145 assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0));
146 assert_int_equal(1, len);
147 assert_null(buf);
148 assert_string_equal(":id", str);
149 assert_int_equal('x', p[len - 1]);
150 assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1));
151 assert_int_equal(2, len);
152 assert_string_equal("id", str);
153 assert_int_equal(':', p[len - 1]);
154 free(buf);
Radek Krejci44ceedc2018-10-02 15:54:31 +0200155
156 /* checking identifiers */
157 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, NULL));
158 logbuf_assert("Invalid identifier character ':'. Line number 1.");
159 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, '#', 1, NULL));
160 logbuf_assert("Invalid identifier first character '#'. Line number 1.");
161
162 assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, 'a', 1, &prefix));
163 assert_int_equal(0, prefix);
164 assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, ':', 0, &prefix));
165 assert_int_equal(1, prefix);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200166 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, &prefix));
167 assert_int_equal(1, prefix);
Radek Krejci44ceedc2018-10-02 15:54:31 +0200168 assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, 'b', 0, &prefix));
169 assert_int_equal(2, prefix);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200170 /* second colon is invalid */
171 assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, &prefix));
172 logbuf_assert("Invalid identifier character ':'. Line number 1.");
Radek Krejci44ceedc2018-10-02 15:54:31 +0200173}
Radek Krejci80dd33e2018-09-26 15:57:18 +0200174
175static void
176test_comments(void **state)
177{
178 (void) state; /* unused */
179
Radek Krejci44ceedc2018-10-02 15:54:31 +0200180 struct ly_parser_ctx ctx;
Radek Krejci80dd33e2018-09-26 15:57:18 +0200181 const char *str, *p;
Radek Krejciefd22f62018-09-27 11:47:58 +0200182 char *word, *buf;
183 size_t len;
Radek Krejci80dd33e2018-09-26 15:57:18 +0200184
Radek Krejci44ceedc2018-10-02 15:54:31 +0200185 ctx.ctx = NULL;
186 ctx.line = 1;
187
Radek Krejciefd22f62018-09-27 11:47:58 +0200188 str = " // this is a text of / one * line */ comment\nargument";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200189 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200190 assert_string_equal("argument", word);
191 assert_null(buf);
192 assert_int_equal(8, len);
Radek Krejci80dd33e2018-09-26 15:57:18 +0200193
Radek Krejciefd22f62018-09-27 11:47:58 +0200194 str = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\"";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200195 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200196 assert_string_equal("argument", word);
197 assert_ptr_equal(buf, word);
198 assert_int_equal(8, len);
199 free(word);
Radek Krejci80dd33e2018-09-26 15:57:18 +0200200
201 str = p = " this is one line comment on last line";
Radek Krejci44ceedc2018-10-02 15:54:31 +0200202 assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &str, 1));
Radek Krejci80dd33e2018-09-26 15:57:18 +0200203 assert_true(str[0] == '\0');
204
205 str = p = " this is a not terminated comment x";
Radek Krejci44ceedc2018-10-02 15:54:31 +0200206 assert_int_equal(LY_EVALID, skip_comment(&ctx, &str, 2));
207 logbuf_assert("Unexpected end-of-file, non-terminated comment. Line number 5.");
Radek Krejci80dd33e2018-09-26 15:57:18 +0200208 assert_true(str[0] == '\0');
209}
210
Radek Krejciefd22f62018-09-27 11:47:58 +0200211static void
212test_arg(void **state)
213{
214 (void) state; /* unused */
215
Radek Krejci44ceedc2018-10-02 15:54:31 +0200216 struct ly_parser_ctx ctx;
Radek Krejciefd22f62018-09-27 11:47:58 +0200217 const char *str;
218 char *word, *buf;
219 size_t len;
220
Radek Krejci44ceedc2018-10-02 15:54:31 +0200221 ctx.ctx = NULL;
222 ctx.line = 1;
223
Radek Krejciefd22f62018-09-27 11:47:58 +0200224 /* missing argument */
225 str = ";";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200226 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_MAYBE_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200227 assert_null(word);
228
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200229 str = "{";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200230 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200231 logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1.");
232
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200233 /* invalid escape sequence */
234 str = "\"\\s\"";
235 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200236 logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1.");
237 str = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200238 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200239 assert_int_equal(2, len);
240 assert_string_equal("\\s\'", word);
241 assert_int_equal('\0', str[0]); /* input has been eaten */
242
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200243 /* invalid character after the argument */
244 str = "hello\"";
245 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
246 logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
247 str = "hello}";
248 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
249 logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
250
251 str = "hello/x\t"; /* slash is not an invalid character */
252 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
253 assert_int_equal(7, len);
254 assert_string_equal("hello/x\t", word);
255
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200256 assert_null(buf);
Radek Krejciefd22f62018-09-27 11:47:58 +0200257
258 /* different quoting */
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200259 str = "hello ";
260 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200261 assert_null(buf);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200262 assert_int_equal(5, len);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200263 assert_string_equal("hello ", word);
Radek Krejciefd22f62018-09-27 11:47:58 +0200264
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200265 str = "hello/*comment*/\n";
266 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200267 assert_null(buf);
268 assert_int_equal(5, len);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200269 assert_false(strncmp("hello", word, len));
270
271
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200272 str = "\"hello\\n\\t\\\"\\\\\";";
273 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200274 assert_null(buf);
275 assert_int_equal(9, len);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200276 assert_string_equal("hello\\n\\t\\\"\\\\\";", word);
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200277
278 ctx.indent = 14;
279 str = "\"hello \t\n\t\t world!\"";
280 /* - space and tabs before newline are stripped out
281 * - space and tabs after newline (indentation) are stripped out
282 */
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200283 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200284 assert_non_null(buf);
285 assert_ptr_equal(word, buf);
286 assert_int_equal(14, len);
287 assert_string_equal("hello\n world!", word);
288 free(buf);
289
290 ctx.indent = 14;
291 str = "\"hello\n \tworld!\"";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200292 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejcid5f2b5f2018-10-11 10:54:36 +0200293 assert_non_null(buf);
294 assert_ptr_equal(word, buf);
295 assert_int_equal(12, len);
296 assert_string_equal("hello\nworld!", word);
297 free(buf);
Radek Krejciefd22f62018-09-27 11:47:58 +0200298
299 str = "\'hello\'";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200300 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200301 assert_null(buf);
302 assert_int_equal(5, len);
303 assert_false(strncmp("hello", word, 5));
304
305 str = "\"hel\" +\t\n\"lo\"";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200306 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200307 assert_ptr_equal(word, buf);
308 assert_int_equal(5, len);
309 assert_string_equal("hello", word);
310 free(buf);
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200311 str = "\"hel\" +\t\nlo"; /* unquoted the second part */
312 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
313 logbuf_assert("Both string parts divided by '+' must be quoted. Line number 5.");
Radek Krejciefd22f62018-09-27 11:47:58 +0200314
315 str = "\'he\'\t\n+ \"llo\"";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200316 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200317 assert_ptr_equal(word, buf);
318 assert_int_equal(5, len);
319 assert_string_equal("hello", word);
320 free(buf);
321
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200322 str = " \t\n\"he\"+\'llo\'";
323 assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
Radek Krejciefd22f62018-09-27 11:47:58 +0200324 assert_ptr_equal(word, buf);
325 assert_int_equal(5, len);
326 assert_string_equal("hello", word);
327 free(buf);
328
Radek Krejci44ceedc2018-10-02 15:54:31 +0200329 /* missing argument */
330 str = ";";
Radek Krejcifc62d7e2018-10-11 12:56:42 +0200331 assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len));
332 logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 7.");
Radek Krejcidcc7b322018-10-11 14:24:02 +0200333}
334
335static void
336test_stmts(void **state)
337{
338 (void) state; /* unused */
339
340 struct ly_parser_ctx ctx;
341 const char *str, *p;
342 enum yang_keyword kw;
343 char *word;
344 size_t len;
345
346 ctx.ctx = NULL;
347 ctx.line = 1;
348
349 str = "\n// comment\n\tinput\t{";
350 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
351 assert_int_equal(YANG_INPUT, kw);
352 assert_int_equal(5, len);
353 assert_string_equal("input\t{", word);
354 assert_string_equal("\t{", str);
355
356 str = "\t /* comment */\t output\n\t{";
357 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
358 assert_int_equal(YANG_OUTPUT, kw);
359 assert_int_equal(6, len);
360 assert_string_equal("output\n\t{", word);
361 assert_string_equal("\n\t{", str);
362
363 str = "/input { "; /* invalid slash */
364 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
365 logbuf_assert("Invalid identifier first character '/'. Line number 4.");
366
367 str = "not-a-statement-nor-extension { "; /* invalid identifier */
368 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
369 logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4.");
370
371 str = "path;"; /* missing sep after the keyword */
372 assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
373 logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4.");
374
375 str = "action ";
376 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
377 assert_int_equal(YANG_ACTION, kw);
378 assert_int_equal(6, len);
379 str = "anydata ";
380 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
381 assert_int_equal(YANG_ANYDATA, kw);
382 assert_int_equal(7, len);
383 str = "anyxml ";
384 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
385 assert_int_equal(YANG_ANYXML, kw);
386 assert_int_equal(6, len);
387 str = "argument ";
388 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
389 assert_int_equal(YANG_ARGUMENT, kw);
390 assert_int_equal(8, len);
391 str = "augment ";
392 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
393 assert_int_equal(YANG_AUGMENT, kw);
394 assert_int_equal(7, len);
395 str = "base ";
396 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
397 assert_int_equal(YANG_BASE, kw);
398 assert_int_equal(4, len);
399 str = "belongs-to ";
400 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
401 assert_int_equal(YANG_BELONGS_TO, kw);
402 assert_int_equal(10, len);
403 str = "bit ";
404 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
405 assert_int_equal(YANG_BIT, kw);
406 assert_int_equal(3, len);
407 str = "case ";
408 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
409 assert_int_equal(YANG_CASE, kw);
410 assert_int_equal(4, len);
411 str = "choice ";
412 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
413 assert_int_equal(YANG_CHOICE, kw);
414 assert_int_equal(6, len);
415 str = "config ";
416 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
417 assert_int_equal(YANG_CONFIG, kw);
418 assert_int_equal(6, len);
419 str = "contact ";
420 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
421 assert_int_equal(YANG_CONTACT, kw);
422 assert_int_equal(7, len);
423 str = "container ";
424 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
425 assert_int_equal(YANG_CONTAINER, kw);
426 assert_int_equal(9, len);
427 str = "default ";
428 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
429 assert_int_equal(YANG_DEFAULT, kw);
430 assert_int_equal(7, len);
431 str = "description ";
432 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
433 assert_int_equal(YANG_DESCRIPTION, kw);
434 assert_int_equal(11, len);
435 str = "deviate ";
436 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
437 assert_int_equal(YANG_DEVIATE, kw);
438 assert_int_equal(7, len);
439 str = "deviation ";
440 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
441 assert_int_equal(YANG_DEVIATION, kw);
442 assert_int_equal(9, len);
443 str = "enum ";
444 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
445 assert_int_equal(YANG_ENUM, kw);
446 assert_int_equal(4, len);
447 str = "error-app-tag ";
448 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
449 assert_int_equal(YANG_ERROR_APP_TAG, kw);
450 assert_int_equal(13, len);
451 str = "error-message ";
452 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
453 assert_int_equal(YANG_ERROR_MESSAGE, kw);
454 assert_int_equal(13, len);
455 str = "extension ";
456 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
457 assert_int_equal(YANG_EXTENSION, kw);
458 assert_int_equal(9, len);
459 str = "feature ";
460 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
461 assert_int_equal(YANG_FEATURE, kw);
462 assert_int_equal(7, len);
463 str = "fraction-digits ";
464 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
465 assert_int_equal(YANG_FRACTION_DIGITS, kw);
466 assert_int_equal(15, len);
467 str = "grouping ";
468 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
469 assert_int_equal(YANG_GROUPING, kw);
470 assert_int_equal(8, len);
471 str = "identity ";
472 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
473 assert_int_equal(YANG_IDENTITY, kw);
474 assert_int_equal(8, len);
475 str = "if-feature ";
476 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
477 assert_int_equal(YANG_IF_FEATURE, kw);
478 assert_int_equal(10, len);
479 str = "import ";
480 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
481 assert_int_equal(YANG_IMPORT, kw);
482 assert_int_equal(6, len);
483 str = "include ";
484 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
485 assert_int_equal(YANG_INCLUDE, kw);
486 assert_int_equal(7, len);
487 str = "input{";
488 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
489 assert_int_equal(YANG_INPUT, kw);
490 assert_int_equal(5, len);
491 str = "key ";
492 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
493 assert_int_equal(YANG_KEY, kw);
494 assert_int_equal(3, len);
495 str = "leaf ";
496 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
497 assert_int_equal(YANG_LEAF, kw);
498 assert_int_equal(4, len);
499 str = "leaf-list ";
500 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
501 assert_int_equal(YANG_LEAF_LIST, kw);
502 assert_int_equal(9, len);
503 str = "length ";
504 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
505 assert_int_equal(YANG_LENGTH, kw);
506 assert_int_equal(6, len);
507 str = "list ";
508 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
509 assert_int_equal(YANG_LIST, kw);
510 assert_int_equal(4, len);
511 str = "mandatory ";
512 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
513 assert_int_equal(YANG_MANDATORY, kw);
514 assert_int_equal(9, len);
515 str = "max-elements ";
516 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
517 assert_int_equal(YANG_MAX_ELEMENTS, kw);
518 assert_int_equal(12, len);
519 str = "min-elements ";
520 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
521 assert_int_equal(YANG_MIN_ELEMENTS, kw);
522 assert_int_equal(12, len);
523 str = "modifier ";
524 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
525 assert_int_equal(YANG_MODIFIER, kw);
526 assert_int_equal(8, len);
527 str = "module ";
528 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
529 assert_int_equal(YANG_MODULE, kw);
530 assert_int_equal(6, len);
531 str = "must ";
532 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
533 assert_int_equal(YANG_MUST, kw);
534 assert_int_equal(4, len);
535 str = "namespace ";
536 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
537 assert_int_equal(YANG_NAMESPACE, kw);
538 assert_int_equal(9, len);
539 str = "notification ";
540 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
541 assert_int_equal(YANG_NOTIFICATION, kw);
542 assert_int_equal(12, len);
543 str = "ordered-by ";
544 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
545 assert_int_equal(YANG_ORDERED_BY, kw);
546 assert_int_equal(10, len);
547 str = "organization ";
548 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
549 assert_int_equal(YANG_ORGANIZATION, kw);
550 assert_int_equal(12, len);
551 str = "output ";
552 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
553 assert_int_equal(YANG_OUTPUT, kw);
554 assert_int_equal(6, len);
555 str = "path ";
556 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
557 assert_int_equal(YANG_PATH, kw);
558 assert_int_equal(4, len);
559 str = "pattern ";
560 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
561 assert_int_equal(YANG_PATTERN, kw);
562 assert_int_equal(7, len);
563 str = "position ";
564 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
565 assert_int_equal(YANG_POSITION, kw);
566 assert_int_equal(8, len);
567 str = "prefix ";
568 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
569 assert_int_equal(YANG_PREFIX, kw);
570 assert_int_equal(6, len);
571 str = "presence ";
572 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
573 assert_int_equal(YANG_PRESENCE, kw);
574 assert_int_equal(8, len);
575 str = "range ";
576 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
577 assert_int_equal(YANG_RANGE, kw);
578 assert_int_equal(5, len);
579 str = "reference ";
580 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
581 assert_int_equal(YANG_REFERENCE, kw);
582 assert_int_equal(9, len);
583 str = "refine ";
584 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
585 assert_int_equal(YANG_REFINE, kw);
586 assert_int_equal(6, len);
587 str = "require-instance ";
588 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
589 assert_int_equal(YANG_REQUIRE_INSTANCE, kw);
590 assert_int_equal(16, len);
591 str = "revision ";
592 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
593 assert_int_equal(YANG_REVISION, kw);
594 assert_int_equal(8, len);
595 str = "revision-date ";
596 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
597 assert_int_equal(YANG_REVISION_DATE, kw);
598 assert_int_equal(13, len);
599 str = "rpc ";
600 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
601 assert_int_equal(YANG_RPC, kw);
602 assert_int_equal(3, len);
603 str = "status ";
604 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
605 assert_int_equal(YANG_STATUS, kw);
606 assert_int_equal(6, len);
607 str = "submodule ";
608 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
609 assert_int_equal(YANG_SUBMODULE, kw);
610 assert_int_equal(9, len);
611 str = "type ";
612 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
613 assert_int_equal(YANG_TYPE, kw);
614 assert_int_equal(4, len);
615 str = "typedef ";
616 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
617 assert_int_equal(YANG_TYPEDEF, kw);
618 assert_int_equal(7, len);
619 str = "unique ";
620 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
621 assert_int_equal(YANG_UNIQUE, kw);
622 assert_int_equal(6, len);
623 str = "units ";
624 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
625 assert_int_equal(YANG_UNITS, kw);
626 assert_int_equal(5, len);
627 str = "uses ";
628 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
629 assert_int_equal(YANG_USES, kw);
630 assert_int_equal(4, len);
631 str = "value ";
632 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
633 assert_int_equal(YANG_VALUE, kw);
634 assert_int_equal(5, len);
635 str = "when ";
636 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
637 assert_int_equal(YANG_WHEN, kw);
638 assert_int_equal(4, len);
639 str = "yang-version ";
640 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
641 assert_int_equal(YANG_YANG_VERSION, kw);
642 assert_int_equal(12, len);
643 str = "yin-element ";
644 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
645 assert_int_equal(YANG_YIN_ELEMENT, kw);
646 assert_int_equal(11, len);
Radek Krejci626df482018-10-11 15:06:31 +0200647 str = ";config false;";
648 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
649 assert_int_equal(YANG_SEMICOLON, kw);
650 assert_int_equal(1, len);
651 assert_string_equal("config false;", str);
652 str = "{ config false;";
653 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
654 assert_int_equal(YANG_LEFT_BRACE, kw);
655 assert_int_equal(1, len);
656 assert_string_equal(" config false;", str);
657 str = "}";
658 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
659 assert_int_equal(YANG_RIGHT_BRACE, kw);
660 assert_int_equal(1, len);
661 assert_string_equal("", str);
Radek Krejcidcc7b322018-10-11 14:24:02 +0200662
663 /* geenric extension */
664 str = p = "nacm:default-deny-write;";
665 assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
666 assert_int_equal(YANG_CUSTOM, kw);
667 assert_int_equal(23, len);
668 assert_ptr_equal(p, word);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200669}
Radek Krejci44ceedc2018-10-02 15:54:31 +0200670
Radek Krejci05b13982018-11-28 16:22:07 +0100671static void
672test_minmax(void **state)
673{
674 *state = test_minmax;
675
676 struct lysp_module mod = {0};
677 struct ly_parser_ctx ctx = {0};
678 uint16_t flags = 0;
679 uint32_t value = 0;
680 struct lysp_ext_instance *ext = NULL;
681 const char *str;
682
683 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
684 assert_non_null(ctx.ctx);
685 ctx.line = 1;
686 ctx.mod = &mod;
687 ctx.mod->version = 2; /* simulate YANG 1.1 */
688
Radek Krejcidf6cad12018-11-28 17:10:55 +0100689 str = " 1invalid; ...";
Radek Krejci05b13982018-11-28 16:22:07 +0100690 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
Radek Krejcidf6cad12018-11-28 17:10:55 +0100691 logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1.");
Radek Krejci05b13982018-11-28 16:22:07 +0100692
693 flags = value = 0;
694 str = " -1; ...";
695 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
696 logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1.");
697
Radek Krejcidf6cad12018-11-28 17:10:55 +0100698 /* implementation limit */
699 flags = value = 0;
700 str = " 4294967296; ...";
701 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
702 logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1.");
703
Radek Krejci05b13982018-11-28 16:22:07 +0100704 flags = value = 0;
705 str = " 1; ...";
706 assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
707 assert_int_equal(LYS_SET_MIN, flags);
708 assert_int_equal(1, value);
709
710 flags = value = 0;
711 str = " 1 {m:ext;} ...";
712 assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
713 assert_int_equal(LYS_SET_MIN, flags);
714 assert_int_equal(1, value);
715 assert_non_null(ext);
716 FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free);
717 ext = NULL;
718
719 flags = value = 0;
720 str = " 1 {config true;} ...";
721 assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
722 logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1.");
723
Radek Krejcidf6cad12018-11-28 17:10:55 +0100724 str = " 1invalid; ...";
Radek Krejci05b13982018-11-28 16:22:07 +0100725 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
Radek Krejcidf6cad12018-11-28 17:10:55 +0100726 logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1.");
Radek Krejci05b13982018-11-28 16:22:07 +0100727
728 flags = value = 0;
729 str = " -1; ...";
730 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
731 logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1.");
732
Radek Krejcidf6cad12018-11-28 17:10:55 +0100733 /* implementation limit */
734 flags = value = 0;
735 str = " 4294967296; ...";
736 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
737 logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1.");
738
Radek Krejci05b13982018-11-28 16:22:07 +0100739 flags = value = 0;
740 str = " 1; ...";
741 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
742 assert_int_equal(LYS_SET_MAX, flags);
743 assert_int_equal(1, value);
744
745 flags = value = 0;
746 str = " unbounded; ...";
747 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
748 assert_int_equal(LYS_SET_MAX, flags);
749 assert_int_equal(0, value);
750
751 flags = value = 0;
752 str = " 1 {m:ext;} ...";
753 assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
754 assert_int_equal(LYS_SET_MAX, flags);
755 assert_int_equal(1, value);
756 assert_non_null(ext);
757 FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free);
758 ext = NULL;
759
760 flags = value = 0;
761 str = " 1 {config true;} ...";
762 assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
763 logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1.");
764
765 *state = NULL;
766 ly_ctx_destroy(ctx.ctx, NULL);
767}
768
Radek Krejci9fcacc12018-10-11 15:59:11 +0200769static struct lysp_module *
Radek Krejci09306362018-10-15 15:26:01 +0200770mod_renew(struct ly_parser_ctx *ctx, struct lysp_module *mod, uint8_t submodule)
Radek Krejci9fcacc12018-10-11 15:59:11 +0200771{
772 lysp_module_free(mod);
773 mod = calloc(1, sizeof *mod);
774 mod->ctx = ctx->ctx;
Radek Krejci09306362018-10-15 15:26:01 +0200775 mod->submodule = submodule;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200776 assert_non_null(mod);
Radek Krejcifaa1eac2018-10-30 14:34:55 +0100777 ctx->mod = mod;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200778 return mod;
779}
780
Radek Krejcid33273d2018-10-25 14:55:52 +0200781static LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
782 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
783 const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
784{
785 *module_data = user_data;
786 *format = LYS_IN_YANG;
787 *free_module_data = NULL;
788 return LY_SUCCESS;
789}
790
Radek Krejci9fcacc12018-10-11 15:59:11 +0200791static void
792test_module(void **state)
793{
794 (void) state; /* unused */
795
796 struct ly_parser_ctx ctx;
797 struct lysp_module *mod;
798 const char *str;
799
800 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
801 assert_non_null(ctx.ctx);
802 ctx.line = 1;
Radek Krejcia042ea12018-10-13 07:52:15 +0200803 ctx.indent = 0;
Radek Krejci9fcacc12018-10-11 15:59:11 +0200804
Radek Krejci09306362018-10-15 15:26:01 +0200805 mod = mod_renew(&ctx, NULL, 0);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200806
807 /* missing mandatory substatements */
808 str = " name {}";
809 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
810 assert_string_equal("name", mod->name);
811 logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1.");
Radek Krejci09306362018-10-15 15:26:01 +0200812 mod = mod_renew(&ctx, mod, 0);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200813
814 str = " name {namespace urn:x;}";
815 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
816 assert_string_equal("urn:x", mod->ns);
817 logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1.");
Radek Krejci09306362018-10-15 15:26:01 +0200818 mod = mod_renew(&ctx, mod, 0);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200819
820 str = " name {namespace urn:x;prefix \"x\";}";
821 assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod));
822 assert_string_equal("x", mod->prefix);
Radek Krejci09306362018-10-15 15:26:01 +0200823 mod = mod_renew(&ctx, mod, 0);
Radek Krejci9fcacc12018-10-11 15:59:11 +0200824
Radek Krejci027d5802018-11-14 16:57:28 +0100825#define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
826#define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";"
Radek Krejcia042ea12018-10-13 07:52:15 +0200827#define TEST_NODE(NODETYPE, INPUT, NAME) \
828 str = SCHEMA_BEGINNING INPUT; \
829 assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod)); \
830 assert_non_null(mod->data); \
831 assert_int_equal(NODETYPE, mod->data->nodetype); \
832 assert_string_equal(NAME, mod->data->name); \
Radek Krejci09306362018-10-15 15:26:01 +0200833 mod = mod_renew(&ctx, mod, 0);
Radek Krejcia042ea12018-10-13 07:52:15 +0200834#define TEST_GENERIC(INPUT, TARGET, TEST) \
835 str = SCHEMA_BEGINNING INPUT; \
836 assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod)); \
837 assert_non_null(TARGET); \
838 TEST; \
Radek Krejci09306362018-10-15 15:26:01 +0200839 mod = mod_renew(&ctx, mod, 0);
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200840#define TEST_DUP(MEMBER, VALUE1, VALUE2, LINE, SUBMODULE) \
841 TEST_DUP_GENERIC(SCHEMA_BEGINNING, MEMBER, VALUE1, VALUE2, \
842 parse_sub_module, mod, LINE, mod = mod_renew(&ctx, mod, SUBMODULE))
Radek Krejcia042ea12018-10-13 07:52:15 +0200843
844 /* duplicated namespace, prefix */
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200845 TEST_DUP("namespace", "y", "z", "1", 0);
846 TEST_DUP("prefix", "y", "z", "1", 0);
847 TEST_DUP("contact", "a", "b", "1", 0);
848 TEST_DUP("description", "a", "b", "1", 0);
849 TEST_DUP("organization", "a", "b", "1", 0);
850 TEST_DUP("reference", "a", "b", "1", 0);
Radek Krejcia042ea12018-10-13 07:52:15 +0200851
Radek Krejci70853c52018-10-15 14:46:16 +0200852 /* not allowed in module (submodule-specific) */
853 str = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
854 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
855 logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1.");
Radek Krejci09306362018-10-15 15:26:01 +0200856 mod = mod_renew(&ctx, mod, 0);
Radek Krejci70853c52018-10-15 14:46:16 +0200857
Radek Krejcia042ea12018-10-13 07:52:15 +0200858 /* anydata */
859 TEST_NODE(LYS_ANYDATA, "anydata test;}", "test");
860 /* anyxml */
861 TEST_NODE(LYS_ANYXML, "anyxml test;}", "test");
862 /* augment */
863 TEST_GENERIC("augment /somepath;}", mod->augments,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200864 assert_string_equal("/somepath", mod->augments[0].nodeid));
Radek Krejcia042ea12018-10-13 07:52:15 +0200865 /* choice */
866 TEST_NODE(LYS_CHOICE, "choice test;}", "test");
867 /* contact 0..1 */
868 TEST_GENERIC("contact \"firstname\" + \n\t\" surname\";}", mod->contact,
869 assert_string_equal("firstname surname", mod->contact));
870 /* container */
871 TEST_NODE(LYS_CONTAINER, "container test;}", "test");
872 /* description 0..1 */
873 TEST_GENERIC("description \'some description\';}", mod->dsc,
874 assert_string_equal("some description", mod->dsc));
875 /* deviation */
876 TEST_GENERIC("deviation /somepath {deviate not-supported;}}", mod->deviations,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200877 assert_string_equal("/somepath", mod->deviations[0].nodeid));
Radek Krejcia042ea12018-10-13 07:52:15 +0200878 /* extension */
879 TEST_GENERIC("extension test;}", mod->extensions,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200880 assert_string_equal("test", mod->extensions[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200881 /* feature */
882 TEST_GENERIC("feature test;}", mod->features,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200883 assert_string_equal("test", mod->features[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200884 /* grouping */
885 TEST_GENERIC("grouping grp;}", mod->groupings,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200886 assert_string_equal("grp", mod->groupings[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200887 /* identity */
888 TEST_GENERIC("identity test;}", mod->identities,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200889 assert_string_equal("test", mod->identities[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200890 /* import */
Radek Krejci086c7132018-10-26 15:29:04 +0200891 ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
892 TEST_GENERIC("import zzz {prefix z;}}", mod->imports,
893 assert_string_equal("zzz", mod->imports[0].name));
Radek Krejci70853c52018-10-15 14:46:16 +0200894
Radek Krejcia042ea12018-10-13 07:52:15 +0200895 /* import - prefix collision */
Radek Krejci086c7132018-10-26 15:29:04 +0200896 str = SCHEMA_BEGINNING "import zzz {prefix x;}}";
Radek Krejcia042ea12018-10-13 07:52:15 +0200897 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
Radek Krejci70853c52018-10-15 14:46:16 +0200898 logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2.");
Radek Krejci09306362018-10-15 15:26:01 +0200899 mod = mod_renew(&ctx, mod, 0);
Radek Krejci086c7132018-10-26 15:29:04 +0200900 str = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
Radek Krejci86d106e2018-10-18 09:53:19 +0200901 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
Radek Krejci086c7132018-10-26 15:29:04 +0200902 logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
Radek Krejci86d106e2018-10-18 09:53:19 +0200903 mod = mod_renew(&ctx, mod, 0);
Radek Krejci086c7132018-10-26 15:29:04 +0200904 str = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}";
905 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
906 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
907 logbuf_assert("Single revision of the module \"zzz\" referred twice.");
Radek Krejci70853c52018-10-15 14:46:16 +0200908
Radek Krejcia042ea12018-10-13 07:52:15 +0200909 /* include */
Radek Krejci9ed7a192018-10-31 16:23:51 +0100910 store = 1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200911 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 +0200912 str = "module" SCHEMA_BEGINNING "include xxx;}";
913 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
914 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
915 logbuf_assert("Included \"xxx\" schema from \"name\" is actually not a submodule.");
Radek Krejci9ed7a192018-10-31 16:23:51 +0100916 store = -1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200917
Radek Krejci9ed7a192018-10-31 16:23:51 +0100918 store = 1;
Radek Krejci313d9902018-11-08 09:42:58 +0100919 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 +0200920 str = "module" SCHEMA_BEGINNING "include xxx;}";
921 assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
922 assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
923 logbuf_assert("Included \"xxx\" submodule from \"name\" belongs-to a different module \"wrong-name\".");
Radek Krejci9ed7a192018-10-31 16:23:51 +0100924 store = -1;
Radek Krejcid33273d2018-10-25 14:55:52 +0200925
Radek Krejci313d9902018-11-08 09:42:58 +0100926 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 +0200927 TEST_GENERIC("include xxx;}", mod->includes,
Radek Krejci086c7132018-10-26 15:29:04 +0200928 assert_string_equal("xxx", mod->includes[0].name));
Radek Krejcid33273d2018-10-25 14:55:52 +0200929
Radek Krejcia042ea12018-10-13 07:52:15 +0200930 /* leaf */
931 TEST_NODE(LYS_LEAF, "leaf test {type string;}}", "test");
932 /* leaf-list */
933 TEST_NODE(LYS_LEAFLIST, "leaf-list test {type string;}}", "test");
934 /* list */
935 TEST_NODE(LYS_LIST, "list test {key a;leaf a {type string;}}}", "test");
936 /* notification */
937 TEST_GENERIC("notification test;}", mod->notifs,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200938 assert_string_equal("test", mod->notifs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200939 /* organization 0..1 */
940 TEST_GENERIC("organization \"CESNET a.l.e.\";}", mod->org,
941 assert_string_equal("CESNET a.l.e.", mod->org));
942 /* reference 0..1 */
943 TEST_GENERIC("reference RFC7950;}", mod->ref,
944 assert_string_equal("RFC7950", mod->ref));
945 /* revision */
946 TEST_GENERIC("revision 2018-10-12;}", mod->revs,
Radek Krejcib7db73a2018-10-24 14:18:40 +0200947 assert_string_equal("2018-10-12", mod->revs[0].date));
Radek Krejcia042ea12018-10-13 07:52:15 +0200948 /* rpc */
949 TEST_GENERIC("rpc test;}", mod->rpcs,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200950 assert_string_equal("test", mod->rpcs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200951 /* typedef */
952 TEST_GENERIC("typedef test{type string;}}", mod->typedefs,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200953 assert_string_equal("test", mod->typedefs[0].name));
Radek Krejcia042ea12018-10-13 07:52:15 +0200954 /* uses */
955 TEST_NODE(LYS_USES, "uses test;}", "test");
956 /* yang-version */
Radek Krejci027d5802018-11-14 16:57:28 +0100957 str = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
Radek Krejcia042ea12018-10-13 07:52:15 +0200958 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
959 logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3.");
Radek Krejci09306362018-10-15 15:26:01 +0200960 mod = mod_renew(&ctx, mod, 0);
Radek Krejci027d5802018-11-14 16:57:28 +0100961 str = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}";
Radek Krejcia042ea12018-10-13 07:52:15 +0200962 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
963 logbuf_assert("Duplicate keyword \"yang-version\". Line number 3.");
Radek Krejci09306362018-10-15 15:26:01 +0200964 mod = mod_renew(&ctx, mod, 0);
Radek Krejci027d5802018-11-14 16:57:28 +0100965 str = SCHEMA_BEGINNING2 "yang-version 1.0;}";
Radek Krejcia042ea12018-10-13 07:52:15 +0200966 assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod));
967 assert_int_equal(1, mod->version);
Radek Krejci09306362018-10-15 15:26:01 +0200968 mod = mod_renew(&ctx, mod, 0);
Radek Krejci027d5802018-11-14 16:57:28 +0100969 str = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
Radek Krejcia042ea12018-10-13 07:52:15 +0200970 assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod));
971 assert_int_equal(2, mod->version);
Radek Krejci09306362018-10-15 15:26:01 +0200972 mod = mod_renew(&ctx, mod, 0);
973
Radek Krejci156ccaf2018-10-15 15:49:17 +0200974 /* extensions */
975 TEST_GENERIC("prefix:test;}", mod->exts,
Radek Krejci2c4e7172018-10-19 15:56:26 +0200976 assert_string_equal("prefix:test", mod->exts[0].name);
977 assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt));
Radek Krejci156ccaf2018-10-15 15:49:17 +0200978 mod = mod_renew(&ctx, mod, 0);
979
Radek Krejci2c02f3e2018-10-16 10:54:38 +0200980 /* invalid substatement */
981 str = SCHEMA_BEGINNING "must false;}";
982 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
983 logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3.");
984 mod = mod_renew(&ctx, mod, 0);
985
Radek Krejci09306362018-10-15 15:26:01 +0200986 /* submodule */
987 mod->submodule = 1;
988
989 /* missing mandatory substatements */
990 str = " subname {}";
Radek Krejcifaa1eac2018-10-30 14:34:55 +0100991 lydict_remove(ctx.ctx, mod->name);
Radek Krejci09306362018-10-15 15:26:01 +0200992 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
993 assert_string_equal("subname", mod->name);
994 logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3.");
995 mod = mod_renew(&ctx, mod, 1);
996
Radek Krejci313d9902018-11-08 09:42:58 +0100997 str = " subname {belongs-to name {prefix x;}}";
Radek Krejcifaa1eac2018-10-30 14:34:55 +0100998 lydict_remove(ctx.ctx, mod->name);
Radek Krejci09306362018-10-15 15:26:01 +0200999 assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod));
1000 assert_string_equal("name", mod->belongsto);
1001 mod = mod_renew(&ctx, mod, 1);
1002
1003#undef SCHEMA_BEGINNING
Radek Krejci313d9902018-11-08 09:42:58 +01001004#define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}"
Radek Krejci09306362018-10-15 15:26:01 +02001005
1006 /* duplicated namespace, prefix */
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001007 TEST_DUP("belongs-to", "module1", "module2", "3", 1);
Radek Krejci09306362018-10-15 15:26:01 +02001008
1009 /* not allowed in submodule (module-specific) */
1010 str = SCHEMA_BEGINNING "namespace \"urn:z\";}";
1011 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
1012 logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3.");
1013 mod = mod_renew(&ctx, mod, 1);
1014 str = SCHEMA_BEGINNING "prefix m;}}";
1015 assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod));
1016 logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3.");
1017 mod = mod_renew(&ctx, mod, 1);
Radek Krejcia042ea12018-10-13 07:52:15 +02001018
1019#undef TEST_GENERIC
1020#undef TEST_NODE
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001021#undef TEST_DUP
Radek Krejcia042ea12018-10-13 07:52:15 +02001022#undef SCHEMA_BEGINNING
1023
Radek Krejci9fcacc12018-10-11 15:59:11 +02001024 lysp_module_free(mod);
1025 ly_ctx_destroy(ctx.ctx, NULL);
Radek Krejciefd22f62018-09-27 11:47:58 +02001026}
1027
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001028static void
1029test_identity(void **state)
1030{
1031 (void) state; /* unused */
1032
1033 struct ly_parser_ctx ctx;
Radek Krejci027d5802018-11-14 16:57:28 +01001034 struct lysp_module *mod = NULL, m = {0};
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001035 struct lysp_ident *ident = NULL;
1036 const char *str;
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001037
1038 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1039 assert_non_null(ctx.ctx);
1040 ctx.line = 1;
1041 ctx.indent = 0;
Radek Krejci027d5802018-11-14 16:57:28 +01001042 ctx.mod = &m;
1043 ctx.mod->version = 2; /* simulate YANG 1.1 */
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001044
1045 /* invalid cardinality */
1046#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001047 TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_identity, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001048 &ident, "1", FREE_ARRAY(ctx.ctx, ident, lysp_ident_free); ident = NULL)
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001049
1050 TEST_DUP("description", "a", "b");
1051 TEST_DUP("reference", "a", "b");
1052 TEST_DUP("status", "current", "obsolete");
1053
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001054 /* full content */
1055 str = " test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ...";
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001056 assert_int_equal(LY_SUCCESS, parse_identity(&ctx, &str, &ident));
1057 assert_non_null(ident);
1058 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001059 FREE_ARRAY(ctx.ctx, ident, lysp_ident_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001060 ident = NULL;
1061
1062 /* invalid substatement */
1063 str = " test {organization XXX;}";
1064 assert_int_equal(LY_EVALID, parse_identity(&ctx, &str, &ident));
1065 logbuf_assert("Invalid keyword \"organization\" as a child of \"identity\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001066 FREE_ARRAY(ctx.ctx, ident, lysp_ident_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001067 ident = NULL;
1068
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001069 /* identity duplication */
1070 str = "module a {namespace urn:a; prefix a; identity a; identity a;}";
Radek Krejci313d9902018-11-08 09:42:58 +01001071 assert_int_equal(LY_EVALID, yang_parse(&ctx, str, &mod));
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001072 logbuf_assert("Duplicate identifier \"a\" of identity statement. Line number 1.");
1073 assert_null(mod);
1074
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001075#undef TEST_DUP
1076
1077 ly_ctx_destroy(ctx.ctx, NULL);
1078}
1079
1080static void
1081test_feature(void **state)
1082{
1083 (void) state; /* unused */
1084
1085 struct ly_parser_ctx ctx;
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001086 struct lysp_module *mod = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001087 struct lysp_feature *features = NULL;
1088 const char *str;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001089
1090 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1091 assert_non_null(ctx.ctx);
1092 ctx.line = 1;
1093 ctx.indent = 0;
1094
1095 /* invalid cardinality */
1096#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1097 TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_feature, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001098 &features, "1", FREE_ARRAY(ctx.ctx, features, lysp_feature_free); features = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001099
1100 TEST_DUP("description", "a", "b");
1101 TEST_DUP("reference", "a", "b");
1102 TEST_DUP("status", "current", "obsolete");
1103
1104 /* full content */
1105 str = " test {description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ...";
1106 assert_int_equal(LY_SUCCESS, parse_feature(&ctx, &str, &features));
1107 assert_non_null(features);
1108 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001109 FREE_ARRAY(ctx.ctx, features, lysp_feature_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001110 features = NULL;
1111
1112 /* invalid substatement */
1113 str = " test {organization XXX;}";
1114 assert_int_equal(LY_EVALID, parse_feature(&ctx, &str, &features));
1115 logbuf_assert("Invalid keyword \"organization\" as a child of \"feature\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001116 FREE_ARRAY(ctx.ctx, features, lysp_feature_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001117 features = NULL;
1118
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001119 /* feature duplication */
1120 str = "module a {namespace urn:a; prefix a; feature a; feature a;}";
Radek Krejci313d9902018-11-08 09:42:58 +01001121 assert_int_equal(LY_EVALID, yang_parse(&ctx, str, &mod));
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001122 logbuf_assert("Duplicate identifier \"a\" of feature statement. Line number 1.");
1123 assert_null(mod);
1124
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001125#undef TEST_DUP
1126
1127 ly_ctx_destroy(ctx.ctx, NULL);
1128}
1129
1130static void
1131test_deviation(void **state)
1132{
1133 (void) state; /* unused */
1134
1135 struct ly_parser_ctx ctx;
1136 struct lysp_deviation *d = NULL;
1137 const char *str;
Radek Krejci2c02f3e2018-10-16 10:54:38 +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;
1143
1144 /* invalid cardinality */
1145#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1146 TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001147 &d, "1", FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); d = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001148
1149 TEST_DUP("description", "a", "b");
1150 TEST_DUP("reference", "a", "b");
1151
1152 /* full content */
1153 str = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
1154 assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &str, &d));
1155 assert_non_null(d);
1156 assert_string_equal(" ...", str);
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001157 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001158 d = NULL;
1159
1160 /* missing mandatory substatement */
1161 str = " test {description text;}";
1162 assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
1163 logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001164 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001165 d = NULL;
1166
1167 /* invalid substatement */
1168 str = " test {deviate not-supported; status obsolete;}";
1169 assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
1170 logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1.");
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001171 FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001172 d = NULL;
1173
1174#undef TEST_DUP
1175
1176 ly_ctx_destroy(ctx.ctx, NULL);
1177}
1178
1179static void
1180test_deviate(void **state)
1181{
1182 (void) state; /* unused */
1183
1184 struct ly_parser_ctx ctx;
1185 struct lysp_deviate *d = NULL;
1186 const char *str;
1187
1188 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1189 assert_non_null(ctx.ctx);
1190 ctx.line = 1;
1191 ctx.indent = 0;
1192
1193 /* invalid cardinality */
1194#define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \
1195 TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001196 &d, "1", lysp_deviate_free(ctx.ctx, d); free(d); d = NULL)
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001197
1198 TEST_DUP("add", "config", "true", "false");
1199 TEST_DUP("replace", "default", "int8", "uint8");
1200 TEST_DUP("add", "mandatory", "true", "false");
1201 TEST_DUP("add", "max-elements", "1", "2");
1202 TEST_DUP("add", "min-elements", "1", "2");
1203 TEST_DUP("replace", "type", "int8", "uint8");
1204 TEST_DUP("add", "units", "kilometers", "miles");
1205
1206 /* full contents */
1207 str = " not-supported {prefix:ext;} ...";
1208 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1209 assert_non_null(d);
1210 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001211 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001212 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;} ...";
1213 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1214 assert_non_null(d);
1215 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001216 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001217 str = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
1218 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1219 assert_non_null(d);
1220 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001221 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001222 str = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
1223 assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
1224 assert_non_null(d);
1225 assert_string_equal(" ...", str);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001226 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001227
1228 /* invalid substatements */
1229#define TEST_NOT_SUP(DEV, STMT, VALUE) \
1230 str = " "DEV" {"STMT" "VALUE";}..."; \
1231 assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); \
1232 logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001233 lysp_deviate_free(ctx.ctx, d); free(d); d = NULL
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001234
1235 TEST_NOT_SUP("not-supported", "units", "meters");
1236 TEST_NOT_SUP("not-supported", "must", "1");
1237 TEST_NOT_SUP("not-supported", "unique", "x");
1238 TEST_NOT_SUP("not-supported", "default", "a");
1239 TEST_NOT_SUP("not-supported", "config", "true");
1240 TEST_NOT_SUP("not-supported", "mandatory", "true");
1241 TEST_NOT_SUP("not-supported", "min-elements", "1");
1242 TEST_NOT_SUP("not-supported", "max-elements", "2");
1243 TEST_NOT_SUP("not-supported", "type", "string");
1244 TEST_NOT_SUP("add", "type", "string");
1245 TEST_NOT_SUP("delete", "config", "true");
1246 TEST_NOT_SUP("delete", "mandatory", "true");
1247 TEST_NOT_SUP("delete", "min-elements", "1");
1248 TEST_NOT_SUP("delete", "max-elements", "2");
1249 TEST_NOT_SUP("delete", "type", "string");
1250 TEST_NOT_SUP("replace", "must", "1");
1251 TEST_NOT_SUP("replace", "unique", "a");
1252
1253 str = " nonsence; ...";
1254 assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d));
1255 logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1.");
1256 assert_null(d);
1257
1258#undef TEST_NOT_SUP
1259#undef TEST_DUP
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001260
1261 ly_ctx_destroy(ctx.ctx, NULL);
1262}
1263
Radek Krejci8c370832018-11-02 15:10:03 +01001264static void
1265test_container(void **state)
1266{
1267 (void) state; /* unused */
1268
Radek Krejci313d9902018-11-08 09:42:58 +01001269 struct lysp_module mod = {0};
1270 struct ly_parser_ctx ctx = {0};
Radek Krejci8c370832018-11-02 15:10:03 +01001271 struct lysp_node_container *c = NULL;
1272 const char *str;
1273
1274 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1275 assert_non_null(ctx.ctx);
1276 ctx.line = 1;
Radek Krejci313d9902018-11-08 09:42:58 +01001277 ctx.mod = &mod;
Radek Krejci027d5802018-11-14 16:57:28 +01001278 ctx.mod->version = 2; /* simulate YANG 1.1 */
Radek Krejci8c370832018-11-02 15:10:03 +01001279
1280 /* invalid cardinality */
1281#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1282 str = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1283 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); \
1284 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
Radek Krejci4f28eda2018-11-12 11:46:16 +01001285 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001286
1287 TEST_DUP("config", "true", "false");
1288 TEST_DUP("description", "text1", "text2");
1289 TEST_DUP("presence", "true", "false");
1290 TEST_DUP("reference", "1", "2");
1291 TEST_DUP("status", "current", "obsolete");
1292 TEST_DUP("when", "true", "false");
1293#undef TEST_DUP
1294
1295 /* full content */
Radek Krejci313d9902018-11-08 09:42:58 +01001296 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;}"
1297 "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 +01001298 assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1299 assert_non_null(c);
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001300 assert_int_equal(LYS_CONTAINER, c->nodetype);
1301 assert_string_equal("cont", c->name);
Radek Krejci8c370832018-11-02 15:10:03 +01001302 assert_non_null(c->actions);
1303 assert_non_null(c->child);
1304 assert_string_equal("test", c->dsc);
1305 assert_non_null(c->exts);
1306 assert_non_null(c->groupings);
1307 assert_non_null(c->iffeatures);
1308 assert_non_null(c->musts);
1309 assert_non_null(c->notifs);
1310 assert_string_equal("true", c->presence);
1311 assert_string_equal("test", c->ref);
1312 assert_non_null(c->typedefs);
1313 assert_non_null(c->when);
1314 assert_null(c->parent);
1315 assert_null(c->next);
1316 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags);
Radek Krejci313d9902018-11-08 09:42:58 +01001317 ly_set_erase(&ctx.tpdfs_nodes, NULL);
Radek Krejci4f28eda2018-11-12 11:46:16 +01001318 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001319
1320 /* invalid */
1321 str = " cont {augment /root;} ...";
1322 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1323 logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1.");
Radek Krejci4f28eda2018-11-12 11:46:16 +01001324 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001325 str = " cont {nonsence true;} ...";
1326 assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
1327 logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1.");
Radek Krejci4f28eda2018-11-12 11:46:16 +01001328 lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
Radek Krejci8c370832018-11-02 15:10:03 +01001329
1330 ly_ctx_destroy(ctx.ctx, NULL);
1331}
1332
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001333static void
1334test_leaf(void **state)
1335{
1336 *state = test_leaf;
1337
1338 struct lysp_module mod = {0};
1339 struct ly_parser_ctx ctx = {0};
1340 struct lysp_node_leaf *l = NULL;
1341 const char *str;
1342
1343 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1344 assert_non_null(ctx.ctx);
1345 ctx.line = 1;
1346 ctx.mod = &mod;
1347 //ctx.mod->version = 2; /* simulate YANG 1.1 */
1348
1349 /* invalid cardinality */
1350#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1351 str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1352 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); \
1353 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1354 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1355
1356 TEST_DUP("config", "true", "false");
1357 TEST_DUP("default", "x", "y");
1358 TEST_DUP("description", "text1", "text2");
1359 TEST_DUP("mandatory", "true", "false");
1360 TEST_DUP("reference", "1", "2");
1361 TEST_DUP("status", "current", "obsolete");
Radek Krejci0e5d8382018-11-28 16:37:53 +01001362 TEST_DUP("type", "int8", "uint8");
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001363 TEST_DUP("units", "text1", "text2");
1364 TEST_DUP("when", "true", "false");
1365#undef TEST_DUP
1366
1367 /* full content - without mandatory which is mutual exclusive with default */
1368 str = "l {config false;default \"xxx\";description test;if-feature f;"
1369 "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ...";
1370 assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1371 assert_non_null(l);
1372 assert_int_equal(LYS_LEAF, l->nodetype);
1373 assert_string_equal("l", l->name);
1374 assert_string_equal("test", l->dsc);
1375 assert_string_equal("xxx", l->dflt);
1376 assert_string_equal("yyy", l->units);
1377 assert_string_equal("string", l->type.name);
1378 assert_non_null(l->exts);
1379 assert_non_null(l->iffeatures);
1380 assert_non_null(l->musts);
1381 assert_string_equal("test", l->ref);
1382 assert_non_null(l->when);
1383 assert_null(l->parent);
1384 assert_null(l->next);
1385 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags);
1386 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1387
1388 /* full content - now with mandatory */
1389 str = "l {mandatory true; type string;} ...";
1390 assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1391 assert_non_null(l);
1392 assert_int_equal(LYS_LEAF, l->nodetype);
1393 assert_string_equal("l", l->name);
1394 assert_string_equal("string", l->type.name);
1395 assert_int_equal(LYS_MAND_TRUE, l->flags);
1396 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1397
1398 /* invalid */
1399 str = " l {mandatory true; default xx; type string;} ...";
1400 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1401 logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as children of \"leaf\". Line number 1.");
1402 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1403
1404 str = " l {description \"missing type\";} ...";
1405 assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
1406 logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1.");
1407 lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
1408
1409 *state = NULL;
1410 ly_ctx_destroy(ctx.ctx, NULL);
1411}
1412
Radek Krejci0e5d8382018-11-28 16:37:53 +01001413static void
1414test_leaflist(void **state)
1415{
1416 *state = test_leaf;
1417
1418 struct lysp_module mod = {0};
1419 struct ly_parser_ctx ctx = {0};
1420 struct lysp_node_leaflist *ll = NULL;
1421 const char *str;
1422
1423 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
1424 assert_non_null(ctx.ctx);
1425 ctx.line = 1;
1426 ctx.mod = &mod;
1427 ctx.mod->version = 2; /* simulate YANG 1.1 */
1428
1429 /* invalid cardinality */
1430#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
1431 str = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
1432 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); \
1433 logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
1434 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1435
1436 TEST_DUP("config", "true", "false");
1437 TEST_DUP("description", "text1", "text2");
1438 TEST_DUP("max-elements", "10", "20");
1439 TEST_DUP("min-elements", "10", "20");
1440 TEST_DUP("ordered-by", "user", "system");
1441 TEST_DUP("reference", "1", "2");
1442 TEST_DUP("status", "current", "obsolete");
1443 TEST_DUP("type", "int8", "uint8");
1444 TEST_DUP("units", "text1", "text2");
1445 TEST_DUP("when", "true", "false");
1446#undef TEST_DUP
1447
1448 /* full content - without min-elements which is mutual exclusive with default */
1449 str = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
1450 "max-elements 10;must 'expr';ordered-by user;reference test;"
1451 "status current;type string; units zzz;when true;m:ext;} ...";
1452 assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1453 assert_non_null(ll);
1454 assert_int_equal(LYS_LEAFLIST, ll->nodetype);
1455 assert_string_equal("ll", ll->name);
1456 assert_string_equal("test", ll->dsc);
1457 assert_non_null(ll->dflts);
1458 assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts));
1459 assert_string_equal("xxx", ll->dflts[0]);
1460 assert_string_equal("yyy", ll->dflts[1]);
1461 assert_string_equal("zzz", ll->units);
1462 assert_int_equal(10, ll->max);
1463 assert_int_equal(0, ll->min);
1464 assert_string_equal("string", ll->type.name);
1465 assert_non_null(ll->exts);
1466 assert_non_null(ll->iffeatures);
1467 assert_non_null(ll->musts);
1468 assert_string_equal("test", ll->ref);
1469 assert_non_null(ll->when);
1470 assert_null(ll->parent);
1471 assert_null(ll->next);
1472 assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
1473 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1474
1475 /* full content - now with min-elements */
1476 str = "ll {min-elements 10; type string;} ...";
1477 assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1478 assert_non_null(ll);
1479 assert_int_equal(LYS_LEAFLIST, ll->nodetype);
1480 assert_string_equal("ll", ll->name);
1481 assert_string_equal("string", ll->type.name);
1482 assert_int_equal(0, ll->max);
1483 assert_int_equal(10, ll->min);
1484 assert_int_equal(LYS_SET_MIN, ll->flags);
1485 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1486
1487 /* invalid */
1488 str = " ll {min-elements 1; default xx; type string;} ...";
1489 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1490 logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as children of \"leaf-list\". Line number 1.");
1491 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1492
1493 str = " ll {description \"missing type\";} ...";
1494 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1495 logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1.");
1496 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1497
Radek Krejcidf6cad12018-11-28 17:10:55 +01001498 str = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */
1499 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1500 logbuf_assert("Invalid combination of min-elements and max-elements: min value 10 is bigger than the max value 1. Line number 1.");
1501 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1502
Radek Krejci0e5d8382018-11-28 16:37:53 +01001503 ctx.mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
1504 str = " ll {default xx; type string;} ...";
1505 assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
1506 logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
1507 lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
1508
1509 *state = NULL;
1510 ly_ctx_destroy(ctx.ctx, NULL);
1511}
1512
Radek Krejci80dd33e2018-09-26 15:57:18 +02001513int main(void)
1514{
1515 const struct CMUnitTest tests[] = {
Radek Krejci44ceedc2018-10-02 15:54:31 +02001516 cmocka_unit_test_setup(test_helpers, logger_setup),
Radek Krejci80dd33e2018-09-26 15:57:18 +02001517 cmocka_unit_test_setup(test_comments, logger_setup),
Radek Krejciefd22f62018-09-27 11:47:58 +02001518 cmocka_unit_test_setup(test_arg, logger_setup),
Radek Krejcidcc7b322018-10-11 14:24:02 +02001519 cmocka_unit_test_setup(test_stmts, logger_setup),
Radek Krejci05b13982018-11-28 16:22:07 +01001520 cmocka_unit_test_setup_teardown(test_minmax, logger_setup, logger_teardown),
Radek Krejci9fcacc12018-10-11 15:59:11 +02001521 cmocka_unit_test_setup(test_module, logger_setup),
Radek Krejci4c6d9bd2018-10-15 16:43:06 +02001522 cmocka_unit_test_setup(test_identity, logger_setup),
Radek Krejci2c02f3e2018-10-16 10:54:38 +02001523 cmocka_unit_test_setup(test_feature, logger_setup),
1524 cmocka_unit_test_setup(test_deviation, logger_setup),
1525 cmocka_unit_test_setup(test_deviate, logger_setup),
Radek Krejci8c370832018-11-02 15:10:03 +01001526 cmocka_unit_test_setup(test_container, logger_setup),
Radek Krejcib1a5dcc2018-11-26 14:50:05 +01001527 cmocka_unit_test_setup_teardown(test_leaf, logger_setup, logger_teardown),
Radek Krejci0e5d8382018-11-28 16:37:53 +01001528 cmocka_unit_test_setup_teardown(test_leaflist, logger_setup, logger_teardown),
Radek Krejci80dd33e2018-09-26 15:57:18 +02001529 };
1530
1531 return cmocka_run_group_tests(tests, NULL, NULL);
1532}