Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 1 | /* |
| 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 Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 15 | #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 Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 20 | #include "../../src/parser_yang.c" |
Radek Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 21 | #include "../../src/context.c" |
| 22 | #include "../../src/tree_schema_helpers.c" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 23 | #include "../../src/tree_schema_free.c" |
| 24 | #include "../../src/tree_schema_compile.c" |
Radek Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 25 | #include "../../src/tree_schema.c" |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 26 | |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 27 | #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 Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 36 | |
| 37 | #define BUFSIZE 1024 |
| 38 | char logbuf[BUFSIZE] = {0}; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 39 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 40 | |
| 41 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 42 | #define ENABLE_LOGGER_CHECKING 1 |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 43 | |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 44 | #if ENABLE_LOGGER_CHECKING |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 45 | static void |
| 46 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 47 | { |
| 48 | (void) level; /* unused */ |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 49 | 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 Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 58 | } |
| 59 | } |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 60 | #endif |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 61 | |
| 62 | static int |
| 63 | logger_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 Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 72 | static int |
| 73 | logger_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 Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 84 | void |
| 85 | logbuf_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 Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 96 | #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 Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 102 | static void |
| 103 | test_helpers(void **state) |
| 104 | { |
| 105 | (void) state; /* unused */ |
| 106 | |
| 107 | const char *str; |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 108 | char *buf, *p; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 109 | 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 Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 125 | 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 Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 155 | |
| 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 Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 166 | assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, &prefix)); |
| 167 | assert_int_equal(1, prefix); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 168 | assert_int_equal(LY_SUCCESS, check_identifierchar(&ctx, 'b', 0, &prefix)); |
| 169 | assert_int_equal(2, prefix); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 170 | /* 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 Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 173 | } |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 174 | |
| 175 | static void |
| 176 | test_comments(void **state) |
| 177 | { |
| 178 | (void) state; /* unused */ |
| 179 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 180 | struct ly_parser_ctx ctx; |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 181 | const char *str, *p; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 182 | char *word, *buf; |
| 183 | size_t len; |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 184 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 185 | ctx.ctx = NULL; |
| 186 | ctx.line = 1; |
| 187 | |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 188 | str = " // this is a text of / one * line */ comment\nargument"; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 189 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 190 | assert_string_equal("argument", word); |
| 191 | assert_null(buf); |
| 192 | assert_int_equal(8, len); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 193 | |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 194 | str = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\""; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 195 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 196 | assert_string_equal("argument", word); |
| 197 | assert_ptr_equal(buf, word); |
| 198 | assert_int_equal(8, len); |
| 199 | free(word); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 200 | |
| 201 | str = p = " this is one line comment on last line"; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 202 | assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &str, 1)); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 203 | assert_true(str[0] == '\0'); |
| 204 | |
| 205 | str = p = " this is a not terminated comment x"; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 206 | assert_int_equal(LY_EVALID, skip_comment(&ctx, &str, 2)); |
| 207 | logbuf_assert("Unexpected end-of-file, non-terminated comment. Line number 5."); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 208 | assert_true(str[0] == '\0'); |
| 209 | } |
| 210 | |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 211 | static void |
| 212 | test_arg(void **state) |
| 213 | { |
| 214 | (void) state; /* unused */ |
| 215 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 216 | struct ly_parser_ctx ctx; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 217 | const char *str; |
| 218 | char *word, *buf; |
| 219 | size_t len; |
| 220 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 221 | ctx.ctx = NULL; |
| 222 | ctx.line = 1; |
| 223 | |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 224 | /* missing argument */ |
| 225 | str = ";"; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 226 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_MAYBE_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 227 | assert_null(word); |
| 228 | |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 229 | str = "{"; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 230 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 231 | logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1."); |
| 232 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 233 | /* invalid escape sequence */ |
| 234 | str = "\"\\s\""; |
| 235 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 236 | 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 Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 238 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 239 | assert_int_equal(2, len); |
| 240 | assert_string_equal("\\s\'", word); |
| 241 | assert_int_equal('\0', str[0]); /* input has been eaten */ |
| 242 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 243 | /* 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 Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 256 | assert_null(buf); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 257 | |
| 258 | /* different quoting */ |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 259 | str = "hello "; |
| 260 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 261 | assert_null(buf); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 262 | assert_int_equal(5, len); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 263 | assert_string_equal("hello ", word); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 264 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 265 | str = "hello/*comment*/\n"; |
| 266 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 267 | assert_null(buf); |
| 268 | assert_int_equal(5, len); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 269 | assert_false(strncmp("hello", word, len)); |
| 270 | |
| 271 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 272 | str = "\"hello\\n\\t\\\"\\\\\";"; |
| 273 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 274 | assert_null(buf); |
| 275 | assert_int_equal(9, len); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 276 | assert_string_equal("hello\\n\\t\\\"\\\\\";", word); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 277 | |
| 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 Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 283 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 284 | 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 Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 292 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 293 | 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 Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 298 | |
| 299 | str = "\'hello\'"; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 300 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 301 | assert_null(buf); |
| 302 | assert_int_equal(5, len); |
| 303 | assert_false(strncmp("hello", word, 5)); |
| 304 | |
| 305 | str = "\"hel\" +\t\n\"lo\""; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 306 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 307 | assert_ptr_equal(word, buf); |
| 308 | assert_int_equal(5, len); |
| 309 | assert_string_equal("hello", word); |
| 310 | free(buf); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 311 | 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 Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 314 | |
| 315 | str = "\'he\'\t\n+ \"llo\""; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 316 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 317 | assert_ptr_equal(word, buf); |
| 318 | assert_int_equal(5, len); |
| 319 | assert_string_equal("hello", word); |
| 320 | free(buf); |
| 321 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 322 | str = " \t\n\"he\"+\'llo\'"; |
| 323 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 324 | assert_ptr_equal(word, buf); |
| 325 | assert_int_equal(5, len); |
| 326 | assert_string_equal("hello", word); |
| 327 | free(buf); |
| 328 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 329 | /* missing argument */ |
| 330 | str = ";"; |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 331 | 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 Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | static void |
| 336 | test_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 Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 647 | 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 Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 662 | |
| 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 Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 669 | } |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 670 | |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 671 | static void |
| 672 | test_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 Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 689 | str = " 1invalid; ..."; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 690 | assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 691 | logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1."); |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 692 | |
| 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 Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 698 | /* 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 Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 704 | 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 Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 724 | str = " 1invalid; ..."; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 725 | assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 726 | logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1."); |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 727 | |
| 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 Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 733 | /* 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 Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 739 | 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 Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 769 | static struct lysp_module * |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 770 | mod_renew(struct ly_parser_ctx *ctx, struct lysp_module *mod, uint8_t submodule) |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 771 | { |
| 772 | lysp_module_free(mod); |
| 773 | mod = calloc(1, sizeof *mod); |
| 774 | mod->ctx = ctx->ctx; |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 775 | mod->submodule = submodule; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 776 | assert_non_null(mod); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 777 | ctx->mod = mod; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 778 | return mod; |
| 779 | } |
| 780 | |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 781 | static 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 Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 791 | static void |
| 792 | test_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 Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 803 | ctx.indent = 0; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 804 | |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 805 | mod = mod_renew(&ctx, NULL, 0); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 806 | |
| 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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 812 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 813 | |
| 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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 818 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 819 | |
| 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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 823 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 824 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 825 | #define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";" |
| 826 | #define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";" |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 827 | #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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 833 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 834 | #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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 839 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 840 | #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 Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 843 | |
| 844 | /* duplicated namespace, prefix */ |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 845 | 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 Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 851 | |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 852 | /* 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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 856 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 857 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 858 | /* 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 Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 864 | assert_string_equal("/somepath", mod->augments[0].nodeid)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 865 | /* 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 Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 877 | assert_string_equal("/somepath", mod->deviations[0].nodeid)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 878 | /* extension */ |
| 879 | TEST_GENERIC("extension test;}", mod->extensions, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 880 | assert_string_equal("test", mod->extensions[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 881 | /* feature */ |
| 882 | TEST_GENERIC("feature test;}", mod->features, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 883 | assert_string_equal("test", mod->features[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 884 | /* grouping */ |
| 885 | TEST_GENERIC("grouping grp;}", mod->groupings, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 886 | assert_string_equal("grp", mod->groupings[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 887 | /* identity */ |
| 888 | TEST_GENERIC("identity test;}", mod->identities, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 889 | assert_string_equal("test", mod->identities[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 890 | /* import */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 891 | 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 Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 894 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 895 | /* import - prefix collision */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 896 | str = SCHEMA_BEGINNING "import zzz {prefix x;}}"; |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 897 | assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod)); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 898 | logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2."); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 899 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 900 | str = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}"; |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 901 | assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod)); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 902 | logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2."); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 903 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 904 | 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 Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 908 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 909 | /* include */ |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 910 | store = 1; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 911 | ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}"); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 912 | 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 Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 916 | store = -1; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 917 | |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 918 | store = 1; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 919 | ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}"); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 920 | 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 Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 924 | store = -1; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 925 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 926 | ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}"); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 927 | TEST_GENERIC("include xxx;}", mod->includes, |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 928 | assert_string_equal("xxx", mod->includes[0].name)); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 929 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 930 | /* 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 Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 938 | assert_string_equal("test", mod->notifs[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 939 | /* 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 Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 947 | assert_string_equal("2018-10-12", mod->revs[0].date)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 948 | /* rpc */ |
| 949 | TEST_GENERIC("rpc test;}", mod->rpcs, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 950 | assert_string_equal("test", mod->rpcs[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 951 | /* typedef */ |
| 952 | TEST_GENERIC("typedef test{type string;}}", mod->typedefs, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 953 | assert_string_equal("test", mod->typedefs[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 954 | /* uses */ |
| 955 | TEST_NODE(LYS_USES, "uses test;}", "test"); |
| 956 | /* yang-version */ |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 957 | str = SCHEMA_BEGINNING2 "\n\tyang-version 10;}"; |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 958 | assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod)); |
| 959 | logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3."); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 960 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 961 | str = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}"; |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 962 | assert_int_equal(LY_EVALID, parse_sub_module(&ctx, &str, mod)); |
| 963 | logbuf_assert("Duplicate keyword \"yang-version\". Line number 3."); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 964 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 965 | str = SCHEMA_BEGINNING2 "yang-version 1.0;}"; |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 966 | assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod)); |
| 967 | assert_int_equal(1, mod->version); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 968 | mod = mod_renew(&ctx, mod, 0); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 969 | str = SCHEMA_BEGINNING2 "yang-version \"1.1\";}"; |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 970 | assert_int_equal(LY_SUCCESS, parse_sub_module(&ctx, &str, mod)); |
| 971 | assert_int_equal(2, mod->version); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 972 | mod = mod_renew(&ctx, mod, 0); |
| 973 | |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 974 | /* extensions */ |
| 975 | TEST_GENERIC("prefix:test;}", mod->exts, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 976 | assert_string_equal("prefix:test", mod->exts[0].name); |
| 977 | assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt)); |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 978 | mod = mod_renew(&ctx, mod, 0); |
| 979 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 980 | /* 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 Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 986 | /* submodule */ |
| 987 | mod->submodule = 1; |
| 988 | |
| 989 | /* missing mandatory substatements */ |
| 990 | str = " subname {}"; |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 991 | lydict_remove(ctx.ctx, mod->name); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 992 | 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 Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 997 | str = " subname {belongs-to name {prefix x;}}"; |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 998 | lydict_remove(ctx.ctx, mod->name); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 999 | 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 Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1004 | #define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}" |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1005 | |
| 1006 | /* duplicated namespace, prefix */ |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1007 | TEST_DUP("belongs-to", "module1", "module2", "3", 1); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1008 | |
| 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 Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1018 | |
| 1019 | #undef TEST_GENERIC |
| 1020 | #undef TEST_NODE |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1021 | #undef TEST_DUP |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1022 | #undef SCHEMA_BEGINNING |
| 1023 | |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 1024 | lysp_module_free(mod); |
| 1025 | ly_ctx_destroy(ctx.ctx, NULL); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1028 | static void |
| 1029 | test_identity(void **state) |
| 1030 | { |
| 1031 | (void) state; /* unused */ |
| 1032 | |
| 1033 | struct ly_parser_ctx ctx; |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 1034 | struct lysp_module m = {0}; |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1035 | struct lysp_ident *ident = NULL; |
| 1036 | const char *str; |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1037 | |
| 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 Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1042 | ctx.mod = &m; |
| 1043 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1044 | |
| 1045 | /* invalid cardinality */ |
| 1046 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1047 | TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_identity, \ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1048 | &ident, "1", FREE_ARRAY(ctx.ctx, ident, lysp_ident_free); ident = NULL) |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1049 | |
| 1050 | TEST_DUP("description", "a", "b"); |
| 1051 | TEST_DUP("reference", "a", "b"); |
| 1052 | TEST_DUP("status", "current", "obsolete"); |
| 1053 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1054 | /* 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 Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1056 | assert_int_equal(LY_SUCCESS, parse_identity(&ctx, &str, &ident)); |
| 1057 | assert_non_null(ident); |
| 1058 | assert_string_equal(" ...", str); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1059 | FREE_ARRAY(ctx.ctx, ident, lysp_ident_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1060 | 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 Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1066 | FREE_ARRAY(ctx.ctx, ident, lysp_ident_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1067 | ident = NULL; |
| 1068 | |
| 1069 | #undef TEST_DUP |
| 1070 | |
| 1071 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1072 | } |
| 1073 | |
| 1074 | static void |
| 1075 | test_feature(void **state) |
| 1076 | { |
| 1077 | (void) state; /* unused */ |
| 1078 | |
| 1079 | struct ly_parser_ctx ctx; |
| 1080 | struct lysp_feature *features = NULL; |
| 1081 | const char *str; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1082 | |
| 1083 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1084 | assert_non_null(ctx.ctx); |
| 1085 | ctx.line = 1; |
| 1086 | ctx.indent = 0; |
| 1087 | |
| 1088 | /* invalid cardinality */ |
| 1089 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1090 | TEST_DUP_GENERIC(" test {", MEMBER, VALUE1, VALUE2, parse_feature, \ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1091 | &features, "1", FREE_ARRAY(ctx.ctx, features, lysp_feature_free); features = NULL) |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1092 | |
| 1093 | TEST_DUP("description", "a", "b"); |
| 1094 | TEST_DUP("reference", "a", "b"); |
| 1095 | TEST_DUP("status", "current", "obsolete"); |
| 1096 | |
| 1097 | /* full content */ |
| 1098 | str = " test {description text;reference \'another text\';status current; if-feature x;if-feature y;prefix:ext;} ..."; |
| 1099 | assert_int_equal(LY_SUCCESS, parse_feature(&ctx, &str, &features)); |
| 1100 | assert_non_null(features); |
| 1101 | assert_string_equal(" ...", str); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1102 | FREE_ARRAY(ctx.ctx, features, lysp_feature_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1103 | features = NULL; |
| 1104 | |
| 1105 | /* invalid substatement */ |
| 1106 | str = " test {organization XXX;}"; |
| 1107 | assert_int_equal(LY_EVALID, parse_feature(&ctx, &str, &features)); |
| 1108 | logbuf_assert("Invalid keyword \"organization\" as a child of \"feature\". Line number 1."); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1109 | FREE_ARRAY(ctx.ctx, features, lysp_feature_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1110 | features = NULL; |
| 1111 | |
| 1112 | #undef TEST_DUP |
| 1113 | |
| 1114 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1115 | } |
| 1116 | |
| 1117 | static void |
| 1118 | test_deviation(void **state) |
| 1119 | { |
| 1120 | (void) state; /* unused */ |
| 1121 | |
| 1122 | struct ly_parser_ctx ctx; |
| 1123 | struct lysp_deviation *d = NULL; |
| 1124 | const char *str; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1125 | |
| 1126 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1127 | assert_non_null(ctx.ctx); |
| 1128 | ctx.line = 1; |
| 1129 | ctx.indent = 0; |
| 1130 | |
| 1131 | /* invalid cardinality */ |
| 1132 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1133 | TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1134 | &d, "1", FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); d = NULL) |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1135 | |
| 1136 | TEST_DUP("description", "a", "b"); |
| 1137 | TEST_DUP("reference", "a", "b"); |
| 1138 | |
| 1139 | /* full content */ |
| 1140 | str = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ..."; |
| 1141 | assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &str, &d)); |
| 1142 | assert_non_null(d); |
| 1143 | assert_string_equal(" ...", str); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1144 | FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1145 | d = NULL; |
| 1146 | |
| 1147 | /* missing mandatory substatement */ |
| 1148 | str = " test {description text;}"; |
| 1149 | assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d)); |
| 1150 | logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1."); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1151 | FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1152 | d = NULL; |
| 1153 | |
| 1154 | /* invalid substatement */ |
| 1155 | str = " test {deviate not-supported; status obsolete;}"; |
| 1156 | assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d)); |
| 1157 | logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1."); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1158 | FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1159 | d = NULL; |
| 1160 | |
| 1161 | #undef TEST_DUP |
| 1162 | |
| 1163 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1164 | } |
| 1165 | |
| 1166 | static void |
| 1167 | test_deviate(void **state) |
| 1168 | { |
| 1169 | (void) state; /* unused */ |
| 1170 | |
| 1171 | struct ly_parser_ctx ctx; |
| 1172 | struct lysp_deviate *d = NULL; |
| 1173 | const char *str; |
| 1174 | |
| 1175 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1176 | assert_non_null(ctx.ctx); |
| 1177 | ctx.line = 1; |
| 1178 | ctx.indent = 0; |
| 1179 | |
| 1180 | /* invalid cardinality */ |
| 1181 | #define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \ |
| 1182 | TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1183 | &d, "1", lysp_deviate_free(ctx.ctx, d); free(d); d = NULL) |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1184 | |
| 1185 | TEST_DUP("add", "config", "true", "false"); |
| 1186 | TEST_DUP("replace", "default", "int8", "uint8"); |
| 1187 | TEST_DUP("add", "mandatory", "true", "false"); |
| 1188 | TEST_DUP("add", "max-elements", "1", "2"); |
| 1189 | TEST_DUP("add", "min-elements", "1", "2"); |
| 1190 | TEST_DUP("replace", "type", "int8", "uint8"); |
| 1191 | TEST_DUP("add", "units", "kilometers", "miles"); |
| 1192 | |
| 1193 | /* full contents */ |
| 1194 | str = " not-supported {prefix:ext;} ..."; |
| 1195 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1196 | assert_non_null(d); |
| 1197 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1198 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1199 | 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;} ..."; |
| 1200 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1201 | assert_non_null(d); |
| 1202 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1203 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1204 | str = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ..."; |
| 1205 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1206 | assert_non_null(d); |
| 1207 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1208 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1209 | str = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ..."; |
| 1210 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1211 | assert_non_null(d); |
| 1212 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1213 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1214 | |
| 1215 | /* invalid substatements */ |
| 1216 | #define TEST_NOT_SUP(DEV, STMT, VALUE) \ |
| 1217 | str = " "DEV" {"STMT" "VALUE";}..."; \ |
| 1218 | assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); \ |
| 1219 | logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1220 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1221 | |
| 1222 | TEST_NOT_SUP("not-supported", "units", "meters"); |
| 1223 | TEST_NOT_SUP("not-supported", "must", "1"); |
| 1224 | TEST_NOT_SUP("not-supported", "unique", "x"); |
| 1225 | TEST_NOT_SUP("not-supported", "default", "a"); |
| 1226 | TEST_NOT_SUP("not-supported", "config", "true"); |
| 1227 | TEST_NOT_SUP("not-supported", "mandatory", "true"); |
| 1228 | TEST_NOT_SUP("not-supported", "min-elements", "1"); |
| 1229 | TEST_NOT_SUP("not-supported", "max-elements", "2"); |
| 1230 | TEST_NOT_SUP("not-supported", "type", "string"); |
| 1231 | TEST_NOT_SUP("add", "type", "string"); |
| 1232 | TEST_NOT_SUP("delete", "config", "true"); |
| 1233 | TEST_NOT_SUP("delete", "mandatory", "true"); |
| 1234 | TEST_NOT_SUP("delete", "min-elements", "1"); |
| 1235 | TEST_NOT_SUP("delete", "max-elements", "2"); |
| 1236 | TEST_NOT_SUP("delete", "type", "string"); |
| 1237 | TEST_NOT_SUP("replace", "must", "1"); |
| 1238 | TEST_NOT_SUP("replace", "unique", "a"); |
| 1239 | |
| 1240 | str = " nonsence; ..."; |
| 1241 | assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); |
| 1242 | logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1."); |
| 1243 | assert_null(d); |
| 1244 | |
| 1245 | #undef TEST_NOT_SUP |
| 1246 | #undef TEST_DUP |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1247 | |
| 1248 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1249 | } |
| 1250 | |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1251 | static void |
| 1252 | test_container(void **state) |
| 1253 | { |
| 1254 | (void) state; /* unused */ |
| 1255 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1256 | struct lysp_module mod = {0}; |
| 1257 | struct ly_parser_ctx ctx = {0}; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1258 | struct lysp_node_container *c = NULL; |
| 1259 | const char *str; |
| 1260 | |
| 1261 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1262 | assert_non_null(ctx.ctx); |
| 1263 | ctx.line = 1; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1264 | ctx.mod = &mod; |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1265 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1266 | |
| 1267 | /* invalid cardinality */ |
| 1268 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1269 | str = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1270 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); \ |
| 1271 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1272 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1273 | |
| 1274 | TEST_DUP("config", "true", "false"); |
| 1275 | TEST_DUP("description", "text1", "text2"); |
| 1276 | TEST_DUP("presence", "true", "false"); |
| 1277 | TEST_DUP("reference", "1", "2"); |
| 1278 | TEST_DUP("status", "current", "obsolete"); |
| 1279 | TEST_DUP("when", "true", "false"); |
| 1280 | #undef TEST_DUP |
| 1281 | |
| 1282 | /* full content */ |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1283 | 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;}" |
| 1284 | "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 Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1285 | assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1286 | assert_non_null(c); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1287 | assert_int_equal(LYS_CONTAINER, c->nodetype); |
| 1288 | assert_string_equal("cont", c->name); |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1289 | assert_non_null(c->actions); |
| 1290 | assert_non_null(c->child); |
| 1291 | assert_string_equal("test", c->dsc); |
| 1292 | assert_non_null(c->exts); |
| 1293 | assert_non_null(c->groupings); |
| 1294 | assert_non_null(c->iffeatures); |
| 1295 | assert_non_null(c->musts); |
| 1296 | assert_non_null(c->notifs); |
| 1297 | assert_string_equal("true", c->presence); |
| 1298 | assert_string_equal("test", c->ref); |
| 1299 | assert_non_null(c->typedefs); |
| 1300 | assert_non_null(c->when); |
| 1301 | assert_null(c->parent); |
| 1302 | assert_null(c->next); |
| 1303 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags); |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1304 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1305 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1306 | |
| 1307 | /* invalid */ |
| 1308 | str = " cont {augment /root;} ..."; |
| 1309 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1310 | logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1."); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1311 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1312 | str = " cont {nonsence true;} ..."; |
| 1313 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1314 | logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1."); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1315 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1316 | |
| 1317 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1318 | } |
| 1319 | |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1320 | static void |
| 1321 | test_leaf(void **state) |
| 1322 | { |
| 1323 | *state = test_leaf; |
| 1324 | |
| 1325 | struct lysp_module mod = {0}; |
| 1326 | struct ly_parser_ctx ctx = {0}; |
| 1327 | struct lysp_node_leaf *l = NULL; |
| 1328 | const char *str; |
| 1329 | |
| 1330 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1331 | assert_non_null(ctx.ctx); |
| 1332 | ctx.line = 1; |
| 1333 | ctx.mod = &mod; |
| 1334 | //ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1335 | |
| 1336 | /* invalid cardinality */ |
| 1337 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1338 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1339 | assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); \ |
| 1340 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1341 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1342 | |
| 1343 | TEST_DUP("config", "true", "false"); |
| 1344 | TEST_DUP("default", "x", "y"); |
| 1345 | TEST_DUP("description", "text1", "text2"); |
| 1346 | TEST_DUP("mandatory", "true", "false"); |
| 1347 | TEST_DUP("reference", "1", "2"); |
| 1348 | TEST_DUP("status", "current", "obsolete"); |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1349 | TEST_DUP("type", "int8", "uint8"); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1350 | TEST_DUP("units", "text1", "text2"); |
| 1351 | TEST_DUP("when", "true", "false"); |
| 1352 | #undef TEST_DUP |
| 1353 | |
| 1354 | /* full content - without mandatory which is mutual exclusive with default */ |
| 1355 | str = "l {config false;default \"xxx\";description test;if-feature f;" |
| 1356 | "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ..."; |
| 1357 | assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1358 | assert_non_null(l); |
| 1359 | assert_int_equal(LYS_LEAF, l->nodetype); |
| 1360 | assert_string_equal("l", l->name); |
| 1361 | assert_string_equal("test", l->dsc); |
| 1362 | assert_string_equal("xxx", l->dflt); |
| 1363 | assert_string_equal("yyy", l->units); |
| 1364 | assert_string_equal("string", l->type.name); |
| 1365 | assert_non_null(l->exts); |
| 1366 | assert_non_null(l->iffeatures); |
| 1367 | assert_non_null(l->musts); |
| 1368 | assert_string_equal("test", l->ref); |
| 1369 | assert_non_null(l->when); |
| 1370 | assert_null(l->parent); |
| 1371 | assert_null(l->next); |
| 1372 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags); |
| 1373 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1374 | |
| 1375 | /* full content - now with mandatory */ |
| 1376 | str = "l {mandatory true; type string;} ..."; |
| 1377 | assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1378 | assert_non_null(l); |
| 1379 | assert_int_equal(LYS_LEAF, l->nodetype); |
| 1380 | assert_string_equal("l", l->name); |
| 1381 | assert_string_equal("string", l->type.name); |
| 1382 | assert_int_equal(LYS_MAND_TRUE, l->flags); |
| 1383 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1384 | |
| 1385 | /* invalid */ |
| 1386 | str = " l {mandatory true; default xx; type string;} ..."; |
| 1387 | assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1388 | logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"leaf\". Line number 1."); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1389 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1390 | |
| 1391 | str = " l {description \"missing type\";} ..."; |
| 1392 | assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1393 | logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1."); |
| 1394 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1395 | |
| 1396 | *state = NULL; |
| 1397 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1398 | } |
| 1399 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1400 | static void |
| 1401 | test_leaflist(void **state) |
| 1402 | { |
| 1403 | *state = test_leaf; |
| 1404 | |
| 1405 | struct lysp_module mod = {0}; |
| 1406 | struct ly_parser_ctx ctx = {0}; |
| 1407 | struct lysp_node_leaflist *ll = NULL; |
| 1408 | const char *str; |
| 1409 | |
| 1410 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1411 | assert_non_null(ctx.ctx); |
| 1412 | ctx.line = 1; |
| 1413 | ctx.mod = &mod; |
| 1414 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1415 | |
| 1416 | /* invalid cardinality */ |
| 1417 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1418 | str = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1419 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); \ |
| 1420 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1421 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1422 | |
| 1423 | TEST_DUP("config", "true", "false"); |
| 1424 | TEST_DUP("description", "text1", "text2"); |
| 1425 | TEST_DUP("max-elements", "10", "20"); |
| 1426 | TEST_DUP("min-elements", "10", "20"); |
| 1427 | TEST_DUP("ordered-by", "user", "system"); |
| 1428 | TEST_DUP("reference", "1", "2"); |
| 1429 | TEST_DUP("status", "current", "obsolete"); |
| 1430 | TEST_DUP("type", "int8", "uint8"); |
| 1431 | TEST_DUP("units", "text1", "text2"); |
| 1432 | TEST_DUP("when", "true", "false"); |
| 1433 | #undef TEST_DUP |
| 1434 | |
| 1435 | /* full content - without min-elements which is mutual exclusive with default */ |
| 1436 | str = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;" |
| 1437 | "max-elements 10;must 'expr';ordered-by user;reference test;" |
| 1438 | "status current;type string; units zzz;when true;m:ext;} ..."; |
| 1439 | assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1440 | assert_non_null(ll); |
| 1441 | assert_int_equal(LYS_LEAFLIST, ll->nodetype); |
| 1442 | assert_string_equal("ll", ll->name); |
| 1443 | assert_string_equal("test", ll->dsc); |
| 1444 | assert_non_null(ll->dflts); |
| 1445 | assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts)); |
| 1446 | assert_string_equal("xxx", ll->dflts[0]); |
| 1447 | assert_string_equal("yyy", ll->dflts[1]); |
| 1448 | assert_string_equal("zzz", ll->units); |
| 1449 | assert_int_equal(10, ll->max); |
| 1450 | assert_int_equal(0, ll->min); |
| 1451 | assert_string_equal("string", ll->type.name); |
| 1452 | assert_non_null(ll->exts); |
| 1453 | assert_non_null(ll->iffeatures); |
| 1454 | assert_non_null(ll->musts); |
| 1455 | assert_string_equal("test", ll->ref); |
| 1456 | assert_non_null(ll->when); |
| 1457 | assert_null(ll->parent); |
| 1458 | assert_null(ll->next); |
| 1459 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags); |
| 1460 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1461 | |
| 1462 | /* full content - now with min-elements */ |
| 1463 | str = "ll {min-elements 10; type string;} ..."; |
| 1464 | assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1465 | assert_non_null(ll); |
| 1466 | assert_int_equal(LYS_LEAFLIST, ll->nodetype); |
| 1467 | assert_string_equal("ll", ll->name); |
| 1468 | assert_string_equal("string", ll->type.name); |
| 1469 | assert_int_equal(0, ll->max); |
| 1470 | assert_int_equal(10, ll->min); |
| 1471 | assert_int_equal(LYS_SET_MIN, ll->flags); |
| 1472 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1473 | |
| 1474 | /* invalid */ |
| 1475 | str = " ll {min-elements 1; default xx; type string;} ..."; |
| 1476 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1477 | logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1."); |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1478 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1479 | |
| 1480 | str = " ll {description \"missing type\";} ..."; |
| 1481 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1482 | logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1."); |
| 1483 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1484 | |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 1485 | str = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */ |
| 1486 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1487 | logbuf_assert("Invalid combination of min-elements and max-elements: min value 10 is bigger than the max value 1. Line number 1."); |
| 1488 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1489 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1490 | ctx.mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */ |
| 1491 | str = " ll {default xx; type string;} ..."; |
| 1492 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1493 | logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 1494 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1495 | |
| 1496 | *state = NULL; |
| 1497 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1498 | } |
| 1499 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1500 | static void |
| 1501 | test_list(void **state) |
| 1502 | { |
| 1503 | *state = test_list; |
| 1504 | |
| 1505 | struct lysp_module mod = {0}; |
| 1506 | struct ly_parser_ctx ctx = {0}; |
| 1507 | struct lysp_node_list *l = NULL; |
| 1508 | const char *str; |
| 1509 | |
| 1510 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1511 | assert_non_null(ctx.ctx); |
| 1512 | ctx.line = 1; |
| 1513 | ctx.mod = &mod; |
| 1514 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1515 | |
| 1516 | /* invalid cardinality */ |
| 1517 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1518 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1519 | assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); \ |
| 1520 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1521 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1522 | |
| 1523 | TEST_DUP("config", "true", "false"); |
| 1524 | TEST_DUP("description", "text1", "text2"); |
| 1525 | TEST_DUP("key", "one", "two"); |
| 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("when", "true", "false"); |
| 1532 | #undef TEST_DUP |
| 1533 | |
| 1534 | /* full content */ |
| 1535 | 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;}" |
| 1536 | "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;" |
| 1537 | "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ..."; |
| 1538 | assert_int_equal(LY_SUCCESS, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1539 | assert_non_null(l); |
| 1540 | assert_int_equal(LYS_LIST, l->nodetype); |
| 1541 | assert_string_equal("l", l->name); |
| 1542 | assert_string_equal("test", l->dsc); |
| 1543 | assert_string_equal("l", l->key); |
| 1544 | assert_non_null(l->uniques); |
| 1545 | assert_int_equal(2, LY_ARRAY_SIZE(l->uniques)); |
| 1546 | assert_string_equal("xxx", l->uniques[0]); |
| 1547 | assert_string_equal("yyy", l->uniques[1]); |
| 1548 | assert_int_equal(10, l->max); |
| 1549 | assert_int_equal(1, l->min); |
| 1550 | assert_non_null(l->exts); |
| 1551 | assert_non_null(l->iffeatures); |
| 1552 | assert_non_null(l->musts); |
| 1553 | assert_string_equal("test", l->ref); |
| 1554 | assert_non_null(l->when); |
| 1555 | assert_null(l->parent); |
| 1556 | assert_null(l->next); |
| 1557 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, l->flags); |
| 1558 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
| 1559 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1560 | |
| 1561 | *state = NULL; |
| 1562 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1563 | } |
| 1564 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1565 | static void |
| 1566 | test_choice(void **state) |
| 1567 | { |
| 1568 | *state = test_choice; |
| 1569 | |
| 1570 | struct lysp_module mod = {0}; |
| 1571 | struct ly_parser_ctx ctx = {0}; |
| 1572 | struct lysp_node_choice *ch = NULL; |
| 1573 | const char *str; |
| 1574 | |
| 1575 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1576 | assert_non_null(ctx.ctx); |
| 1577 | ctx.line = 1; |
| 1578 | ctx.mod = &mod; |
| 1579 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1580 | |
| 1581 | /* invalid cardinality */ |
| 1582 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1583 | str = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1584 | assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); \ |
| 1585 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1586 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1587 | |
| 1588 | TEST_DUP("config", "true", "false"); |
| 1589 | TEST_DUP("default", "a", "b"); |
| 1590 | TEST_DUP("description", "text1", "text2"); |
| 1591 | TEST_DUP("mandatory", "true", "false"); |
| 1592 | TEST_DUP("reference", "1", "2"); |
| 1593 | TEST_DUP("status", "current", "obsolete"); |
| 1594 | TEST_DUP("when", "true", "false"); |
| 1595 | #undef TEST_DUP |
| 1596 | |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1597 | /* full content - without default due to a collision with mandatory */ |
| 1598 | str = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;description test;if-feature f;leaf l {type string;}" |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1599 | "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ..."; |
| 1600 | assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); |
| 1601 | assert_non_null(ch); |
| 1602 | assert_int_equal(LYS_CHOICE, ch->nodetype); |
| 1603 | assert_string_equal("ch", ch->name); |
| 1604 | assert_string_equal("test", ch->dsc); |
| 1605 | assert_non_null(ch->exts); |
| 1606 | assert_non_null(ch->iffeatures); |
| 1607 | assert_string_equal("test", ch->ref); |
| 1608 | assert_non_null(ch->when); |
| 1609 | assert_null(ch->parent); |
| 1610 | assert_null(ch->next); |
| 1611 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags); |
| 1612 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1613 | |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1614 | /* full content - the default missing from the previous node */ |
| 1615 | str = "ch {default c;case c;} ..."; |
| 1616 | assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); |
| 1617 | assert_non_null(ch); |
| 1618 | assert_int_equal(LYS_CHOICE, ch->nodetype); |
| 1619 | assert_string_equal("ch", ch->name); |
| 1620 | assert_string_equal("c", ch->dflt); |
| 1621 | assert_int_equal(0, ch->flags); |
| 1622 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1623 | |
| 1624 | /* invalid content */ |
| 1625 | str = "ch {mandatory true; default c1; case c1 {leaf x{type string;}}} ..."; |
| 1626 | assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); |
| 1627 | logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"choice\". Line number 1."); |
| 1628 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1629 | |
| 1630 | *state = NULL; |
| 1631 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1632 | } |
| 1633 | |
| 1634 | static void |
| 1635 | test_case(void **state) |
| 1636 | { |
| 1637 | *state = test_case; |
| 1638 | |
| 1639 | struct lysp_module mod = {0}; |
| 1640 | struct ly_parser_ctx ctx = {0}; |
| 1641 | struct lysp_node_case *cs = NULL; |
| 1642 | const char *str; |
| 1643 | |
| 1644 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1645 | assert_non_null(ctx.ctx); |
| 1646 | ctx.line = 1; |
| 1647 | ctx.mod = &mod; |
| 1648 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1649 | |
| 1650 | /* invalid cardinality */ |
| 1651 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1652 | str = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1653 | assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); \ |
| 1654 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1655 | lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL; |
| 1656 | |
| 1657 | TEST_DUP("description", "text1", "text2"); |
| 1658 | TEST_DUP("reference", "1", "2"); |
| 1659 | TEST_DUP("status", "current", "obsolete"); |
| 1660 | TEST_DUP("when", "true", "false"); |
| 1661 | #undef TEST_DUP |
| 1662 | |
| 1663 | /* full content */ |
| 1664 | str = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}" |
| 1665 | "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ..."; |
| 1666 | assert_int_equal(LY_SUCCESS, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); |
| 1667 | assert_non_null(cs); |
| 1668 | assert_int_equal(LYS_CASE, cs->nodetype); |
| 1669 | assert_string_equal("cs", cs->name); |
| 1670 | assert_string_equal("test", cs->dsc); |
| 1671 | assert_non_null(cs->exts); |
| 1672 | assert_non_null(cs->iffeatures); |
| 1673 | assert_string_equal("test", cs->ref); |
| 1674 | assert_non_null(cs->when); |
| 1675 | assert_null(cs->parent); |
| 1676 | assert_null(cs->next); |
| 1677 | assert_int_equal(LYS_STATUS_CURR, cs->flags); |
| 1678 | lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL; |
| 1679 | |
| 1680 | /* invalid content */ |
| 1681 | str = "cs {config true} ..."; |
| 1682 | assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); |
| 1683 | logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1."); |
| 1684 | lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL; |
| 1685 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1686 | *state = NULL; |
| 1687 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1688 | } |
| 1689 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1690 | static void |
| 1691 | test_any(void **state, enum yang_keyword kw) |
| 1692 | { |
| 1693 | *state = test_any; |
| 1694 | |
| 1695 | struct lysp_module mod = {0}; |
| 1696 | struct ly_parser_ctx ctx = {0}; |
| 1697 | struct lysp_node_anydata *any = NULL; |
| 1698 | const char *str; |
| 1699 | |
| 1700 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1701 | assert_non_null(ctx.ctx); |
| 1702 | ctx.line = 1; |
| 1703 | ctx.mod = &mod; |
| 1704 | if (kw == YANG_ANYDATA) { |
| 1705 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1706 | } else { |
| 1707 | ctx.mod->version = 1; /* simulate YANG 1.0 */ |
| 1708 | } |
| 1709 | |
| 1710 | /* invalid cardinality */ |
| 1711 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1712 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1713 | assert_int_equal(LY_EVALID, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); \ |
| 1714 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1715 | lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL; |
| 1716 | |
| 1717 | TEST_DUP("config", "true", "false"); |
| 1718 | TEST_DUP("description", "text1", "text2"); |
| 1719 | TEST_DUP("mandatory", "true", "false"); |
| 1720 | TEST_DUP("reference", "1", "2"); |
| 1721 | TEST_DUP("status", "current", "obsolete"); |
| 1722 | TEST_DUP("when", "true", "false"); |
| 1723 | #undef TEST_DUP |
| 1724 | |
| 1725 | /* full content */ |
| 1726 | str = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ..."; |
| 1727 | assert_int_equal(LY_SUCCESS, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); |
| 1728 | assert_non_null(any); |
| 1729 | assert_int_equal(kw == YANG_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype); |
| 1730 | assert_string_equal("any", any->name); |
| 1731 | assert_string_equal("test", any->dsc); |
| 1732 | assert_non_null(any->exts); |
| 1733 | assert_non_null(any->iffeatures); |
| 1734 | assert_non_null(any->musts); |
| 1735 | assert_string_equal("test", any->ref); |
| 1736 | assert_non_null(any->when); |
| 1737 | assert_null(any->parent); |
| 1738 | assert_null(any->next); |
| 1739 | assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags); |
| 1740 | lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL; |
| 1741 | |
| 1742 | *state = NULL; |
| 1743 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1744 | } |
| 1745 | |
| 1746 | static void |
| 1747 | test_anydata(void **state) |
| 1748 | { |
| 1749 | return test_any(state, YANG_ANYDATA); |
| 1750 | } |
| 1751 | |
| 1752 | static void |
| 1753 | test_anyxml(void **state) |
| 1754 | { |
| 1755 | return test_any(state, YANG_ANYXML); |
| 1756 | } |
| 1757 | |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame^] | 1758 | static void |
| 1759 | test_grouping(void **state) |
| 1760 | { |
| 1761 | *state = test_grouping; |
| 1762 | |
| 1763 | struct lysp_module mod = {0}; |
| 1764 | struct ly_parser_ctx ctx = {0}; |
| 1765 | struct lysp_grp *grp = NULL; |
| 1766 | const char *str; |
| 1767 | |
| 1768 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1769 | assert_non_null(ctx.ctx); |
| 1770 | ctx.line = 1; |
| 1771 | ctx.mod = &mod; |
| 1772 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1773 | |
| 1774 | /* invalid cardinality */ |
| 1775 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1776 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1777 | assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); \ |
| 1778 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1779 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1780 | |
| 1781 | TEST_DUP("description", "text1", "text2"); |
| 1782 | TEST_DUP("reference", "1", "2"); |
| 1783 | TEST_DUP("status", "current", "obsolete"); |
| 1784 | #undef TEST_DUP |
| 1785 | |
| 1786 | /* full content */ |
| 1787 | str = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}" |
| 1788 | "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ..."; |
| 1789 | assert_int_equal(LY_SUCCESS, parse_grouping(&ctx, &str, NULL, &grp)); |
| 1790 | assert_non_null(grp); |
| 1791 | assert_int_equal(LYS_GROUPING, grp->nodetype); |
| 1792 | assert_string_equal("grp", grp->name); |
| 1793 | assert_string_equal("test", grp->dsc); |
| 1794 | assert_non_null(grp->exts); |
| 1795 | assert_string_equal("test", grp->ref); |
| 1796 | assert_null(grp->parent); |
| 1797 | assert_int_equal( LYS_STATUS_CURR, grp->flags); |
| 1798 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
| 1799 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1800 | |
| 1801 | /* invalid content */ |
| 1802 | str = "grp {config true} ..."; |
| 1803 | assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); |
| 1804 | logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1."); |
| 1805 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1806 | |
| 1807 | str = "grp {must 'expr'} ..."; |
| 1808 | assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); |
| 1809 | logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1."); |
| 1810 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1811 | |
| 1812 | *state = NULL; |
| 1813 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1814 | } |
| 1815 | |
| 1816 | static void |
| 1817 | test_uses(void **state) |
| 1818 | { |
| 1819 | *state = test_uses; |
| 1820 | |
| 1821 | struct lysp_module mod = {0}; |
| 1822 | struct ly_parser_ctx ctx = {0}; |
| 1823 | struct lysp_node_uses *u = NULL; |
| 1824 | const char *str; |
| 1825 | |
| 1826 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1827 | assert_non_null(ctx.ctx); |
| 1828 | ctx.line = 1; |
| 1829 | ctx.mod = &mod; |
| 1830 | ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1831 | |
| 1832 | /* invalid cardinality */ |
| 1833 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1834 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1835 | assert_int_equal(LY_EVALID, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); \ |
| 1836 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1837 | lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL; |
| 1838 | |
| 1839 | TEST_DUP("description", "text1", "text2"); |
| 1840 | TEST_DUP("reference", "1", "2"); |
| 1841 | TEST_DUP("status", "current", "obsolete"); |
| 1842 | TEST_DUP("when", "true", "false"); |
| 1843 | #undef TEST_DUP |
| 1844 | |
| 1845 | /* full content */ |
| 1846 | str = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ..."; |
| 1847 | assert_int_equal(LY_SUCCESS, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); |
| 1848 | assert_non_null(u); |
| 1849 | assert_int_equal(LYS_USES, u->nodetype); |
| 1850 | assert_string_equal("grpref", u->name); |
| 1851 | assert_string_equal("test", u->dsc); |
| 1852 | assert_non_null(u->exts); |
| 1853 | assert_non_null(u->iffeatures); |
| 1854 | assert_string_equal("test", u->ref); |
| 1855 | assert_non_null(u->augments); |
| 1856 | assert_non_null(u->refines); |
| 1857 | assert_non_null(u->when); |
| 1858 | assert_null(u->parent); |
| 1859 | assert_null(u->next); |
| 1860 | assert_int_equal(LYS_STATUS_CURR, u->flags); |
| 1861 | lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL; |
| 1862 | |
| 1863 | *state = NULL; |
| 1864 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1865 | } |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 1866 | int main(void) |
| 1867 | { |
| 1868 | const struct CMUnitTest tests[] = { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 1869 | cmocka_unit_test_setup(test_helpers, logger_setup), |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 1870 | cmocka_unit_test_setup(test_comments, logger_setup), |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1871 | cmocka_unit_test_setup(test_arg, logger_setup), |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 1872 | cmocka_unit_test_setup(test_stmts, logger_setup), |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 1873 | cmocka_unit_test_setup_teardown(test_minmax, logger_setup, logger_teardown), |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 1874 | cmocka_unit_test_setup(test_module, logger_setup), |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1875 | cmocka_unit_test_setup(test_identity, logger_setup), |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1876 | cmocka_unit_test_setup(test_feature, logger_setup), |
| 1877 | cmocka_unit_test_setup(test_deviation, logger_setup), |
| 1878 | cmocka_unit_test_setup(test_deviate, logger_setup), |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1879 | cmocka_unit_test_setup(test_container, logger_setup), |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1880 | cmocka_unit_test_setup_teardown(test_leaf, logger_setup, logger_teardown), |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1881 | cmocka_unit_test_setup_teardown(test_leaflist, logger_setup, logger_teardown), |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1882 | cmocka_unit_test_setup_teardown(test_list, logger_setup, logger_teardown), |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1883 | cmocka_unit_test_setup_teardown(test_choice, logger_setup, logger_teardown), |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1884 | cmocka_unit_test_setup_teardown(test_case, logger_setup, logger_teardown), |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1885 | cmocka_unit_test_setup_teardown(test_anydata, logger_setup, logger_teardown), |
| 1886 | cmocka_unit_test_setup_teardown(test_anyxml, logger_setup, logger_teardown), |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame^] | 1887 | cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown), |
| 1888 | cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown), |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 1889 | }; |
| 1890 | |
| 1891 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 1892 | } |