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 | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 15 | #include <stdarg.h> |
| 16 | #include <stddef.h> |
| 17 | #include <setjmp.h> |
| 18 | #include <cmocka.h> |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame^] | 23 | #include "../../../src/common.h" |
| 24 | #include "../../../src/tree_schema.h" |
| 25 | #include "../../../src/tree_schema_internal.h" |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 26 | |
| 27 | /* originally static functions from tree_schema_free.c and parser_yang.c */ |
| 28 | void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext); |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 29 | void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev); |
| 30 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp); |
| 31 | void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action); |
| 32 | void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif); |
| 33 | void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment); |
| 34 | void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d); |
| 35 | void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node); |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 36 | void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when); |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 37 | |
| 38 | LY_ERR buf_add_char(struct ly_ctx *ctx, const char **input, size_t len, char **buf, size_t *buf_len, size_t *buf_used); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 39 | LY_ERR buf_store_char(struct lys_yang_parser_ctx *ctx, const char **input, enum yang_arg arg, char **word_p, |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 40 | size_t *word_len, char **word_b, size_t *buf_len, int need_buf, int *prefix); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 41 | LY_ERR get_keyword(struct lys_yang_parser_ctx *ctx, const char **data, enum ly_stmt *kw, char **word_p, size_t *word_len); |
| 42 | LY_ERR get_argument(struct lys_yang_parser_ctx *ctx, const char **data, enum yang_arg arg, |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 43 | uint16_t *flags, char **word_p, char **word_b, size_t *word_len); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 44 | LY_ERR skip_comment(struct lys_yang_parser_ctx *ctx, const char **data, int comment); |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 45 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 46 | LY_ERR parse_action(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_action **actions); |
| 47 | LY_ERR parse_any(struct lys_yang_parser_ctx *ctx, const char **data, enum ly_stmt kw, struct lysp_node *parent, struct lysp_node **siblings); |
| 48 | LY_ERR parse_augment(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_augment **augments); |
| 49 | LY_ERR parse_case(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
| 50 | LY_ERR parse_container(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
| 51 | LY_ERR parse_deviate(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_deviate **deviates); |
| 52 | LY_ERR parse_deviation(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_deviation **deviations); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 53 | LY_ERR parse_grouping(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_grp **groupings); |
| 54 | LY_ERR parse_choice(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 55 | LY_ERR parse_leaf(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
| 56 | LY_ERR parse_leaflist(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
| 57 | LY_ERR parse_list(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
| 58 | LY_ERR parse_maxelements(struct lys_yang_parser_ctx *ctx, const char **data, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts); |
| 59 | LY_ERR parse_minelements(struct lys_yang_parser_ctx *ctx, const char **data, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts); |
| 60 | LY_ERR parse_module(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_module *mod); |
| 61 | LY_ERR parse_notif(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_notif **notifs); |
| 62 | LY_ERR parse_submodule(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_submodule *submod); |
| 63 | LY_ERR parse_uses(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings); |
| 64 | LY_ERR parse_when(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_when **when_p); |
| 65 | LY_ERR parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, const char **data, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, struct lysp_ext_instance **exts); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 66 | |
| 67 | #define BUFSIZE 1024 |
| 68 | char logbuf[BUFSIZE] = {0}; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 69 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 70 | |
| 71 | /* 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] | 72 | #define ENABLE_LOGGER_CHECKING 1 |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 73 | |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 74 | #if ENABLE_LOGGER_CHECKING |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 75 | static void |
| 76 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 77 | { |
| 78 | (void) level; /* unused */ |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 79 | if (store) { |
| 80 | if (path && path[0]) { |
| 81 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 82 | } else { |
| 83 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 84 | } |
| 85 | if (store > 0) { |
| 86 | --store; |
| 87 | } |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 88 | } |
| 89 | } |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 90 | #endif |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 91 | |
| 92 | static int |
| 93 | logger_setup(void **state) |
| 94 | { |
| 95 | (void) state; /* unused */ |
| 96 | #if ENABLE_LOGGER_CHECKING |
| 97 | ly_set_log_clb(logger, 1); |
| 98 | #endif |
| 99 | return 0; |
| 100 | } |
| 101 | |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 102 | static int |
| 103 | logger_teardown(void **state) |
| 104 | { |
| 105 | (void) state; /* unused */ |
| 106 | #if ENABLE_LOGGER_CHECKING |
| 107 | if (*state) { |
| 108 | fprintf(stderr, "%s\n", logbuf); |
| 109 | } |
| 110 | #endif |
| 111 | return 0; |
| 112 | } |
| 113 | |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 114 | void |
| 115 | logbuf_clean(void) |
| 116 | { |
| 117 | logbuf[0] = '\0'; |
| 118 | } |
| 119 | |
| 120 | #if ENABLE_LOGGER_CHECKING |
| 121 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 122 | #else |
| 123 | # define logbuf_assert(str) |
| 124 | #endif |
| 125 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 126 | #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \ |
| 127 | str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 128 | assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \ |
| 129 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \ |
| 130 | CLEANUP |
| 131 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 132 | static void |
| 133 | test_helpers(void **state) |
| 134 | { |
| 135 | (void) state; /* unused */ |
| 136 | |
| 137 | const char *str; |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 138 | char *buf, *p; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 139 | size_t len, size; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 140 | struct lys_yang_parser_ctx ctx; |
| 141 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 142 | ctx.ctx = NULL; |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 143 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 144 | ctx.line = 1; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 145 | int prefix = 0; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 146 | |
| 147 | /* storing into buffer */ |
| 148 | str = "abcd"; |
| 149 | buf = NULL; |
| 150 | size = len = 0; |
| 151 | assert_int_equal(LY_SUCCESS, buf_add_char(NULL, &str, 2, &buf, &size, &len)); |
| 152 | assert_int_not_equal(0, size); |
| 153 | assert_int_equal(2, len); |
| 154 | assert_string_equal("cd", str); |
| 155 | assert_false(strncmp("ab", buf, 2)); |
| 156 | free(buf); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 157 | buf = NULL; |
| 158 | |
| 159 | /* invalid first characters */ |
| 160 | len = 0; |
| 161 | str = "2invalid"; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 162 | assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 163 | str = ".invalid"; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 164 | assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 165 | str = "-invalid"; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 166 | assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 167 | /* invalid following characters */ |
| 168 | len = 3; /* number of characters read before the str content */ |
| 169 | str = "!"; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 170 | assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 171 | str = ":"; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 172 | assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 173 | /* valid colon for prefixed identifiers */ |
| 174 | len = size = 0; |
| 175 | p = NULL; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 176 | prefix = 0; |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 177 | str = "x:id"; |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 178 | assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 179 | assert_int_equal(1, len); |
| 180 | assert_null(buf); |
| 181 | assert_string_equal(":id", str); |
| 182 | assert_int_equal('x', p[len - 1]); |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 183 | assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix)); |
Radek Krejci | 404251e | 2018-10-09 12:06:44 +0200 | [diff] [blame] | 184 | assert_int_equal(2, len); |
| 185 | assert_string_equal("id", str); |
| 186 | assert_int_equal(':', p[len - 1]); |
| 187 | free(buf); |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 188 | prefix = 0; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 189 | |
| 190 | /* checking identifiers */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 191 | assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, ':', 0, NULL)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 192 | logbuf_assert("Invalid identifier character ':'. Line number 1."); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 193 | assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, '#', 1, NULL)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 194 | logbuf_assert("Invalid identifier first character '#'. Line number 1."); |
| 195 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 196 | assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, 'a', 1, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 197 | assert_int_equal(0, prefix); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 198 | assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, ':', 0, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 199 | assert_int_equal(1, prefix); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 200 | assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, ':', 0, &prefix)); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 201 | assert_int_equal(1, prefix); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 202 | assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, 'b', 0, &prefix)); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 203 | assert_int_equal(2, prefix); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 204 | /* second colon is invalid */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 205 | assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, ':', 0, &prefix)); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 206 | logbuf_assert("Invalid identifier character ':'. Line number 1."); |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 207 | } |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 208 | |
| 209 | static void |
| 210 | test_comments(void **state) |
| 211 | { |
| 212 | (void) state; /* unused */ |
| 213 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 214 | struct lys_yang_parser_ctx ctx; |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 215 | const char *str, *p; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 216 | char *word, *buf; |
| 217 | size_t len; |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 218 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 219 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 220 | ctx.ctx = NULL; |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 221 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 222 | ctx.line = 1; |
| 223 | |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 224 | str = " // this is a text of / one * line */ comment\nargument;"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 225 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 226 | assert_string_equal("argument;", word); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 227 | assert_null(buf); |
| 228 | assert_int_equal(8, len); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 229 | |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 230 | str = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 231 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 232 | assert_string_equal("argument", word); |
| 233 | assert_ptr_equal(buf, word); |
| 234 | assert_int_equal(8, len); |
| 235 | free(word); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 236 | |
| 237 | str = p = " this is one line comment on last line"; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 238 | assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &str, 1)); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 239 | assert_true(str[0] == '\0'); |
| 240 | |
| 241 | str = p = " this is a not terminated comment x"; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 242 | assert_int_equal(LY_EVALID, skip_comment(&ctx, &str, 2)); |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 243 | logbuf_assert("Unexpected end-of-input, non-terminated comment. Line number 5."); |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 244 | assert_true(str[0] == '\0'); |
| 245 | } |
| 246 | |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 247 | static void |
| 248 | test_arg(void **state) |
| 249 | { |
| 250 | (void) state; /* unused */ |
| 251 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 252 | struct lys_yang_parser_ctx ctx; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 253 | const char *str; |
| 254 | char *word, *buf; |
| 255 | size_t len; |
| 256 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 257 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 258 | ctx.ctx = NULL; |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 259 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 260 | ctx.line = 1; |
| 261 | |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 262 | /* missing argument */ |
| 263 | str = ";"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 264 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 265 | assert_null(word); |
| 266 | |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 267 | str = "{"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 268 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 269 | logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1."); |
| 270 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 271 | /* invalid escape sequence */ |
| 272 | str = "\"\\s\""; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 273 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 274 | logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1."); |
| 275 | str = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 276 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 277 | assert_int_equal(2, len); |
| 278 | assert_string_equal("\\s\'", word); |
| 279 | assert_int_equal('\0', str[0]); /* input has been eaten */ |
| 280 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 281 | /* invalid character after the argument */ |
| 282 | str = "hello\""; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 283 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 284 | logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1."); |
| 285 | str = "hello}"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 286 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 287 | logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1."); |
| 288 | |
David Sedlák | 40bb13b | 2019-07-10 14:34:18 +0200 | [diff] [blame] | 289 | /* invalid identifier-ref-arg-str */ |
| 290 | str = "pre:pre:value"; |
| 291 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len)); |
| 292 | |
Radek Krejci | 4e199f5 | 2019-05-28 09:09:28 +0200 | [diff] [blame] | 293 | str = "\"\";"; /* empty identifier is not allowed */ |
| 294 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_IDENTIF_ARG, NULL, &word, &buf, &len)); |
| 295 | logbuf_assert("Statement argument is required. Line number 1."); |
| 296 | logbuf_clean(); |
| 297 | str = "\"\";"; /* empty reference identifier is not allowed */ |
| 298 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len)); |
| 299 | logbuf_assert("Statement argument is required. Line number 1."); |
| 300 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 301 | str = "hello/x\t"; /* slash is not an invalid character */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 302 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 303 | assert_int_equal(7, len); |
| 304 | assert_string_equal("hello/x\t", word); |
| 305 | |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 306 | assert_null(buf); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 307 | |
| 308 | /* different quoting */ |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 309 | str = "hello "; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 310 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 311 | assert_null(buf); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 312 | assert_int_equal(5, len); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 313 | assert_string_equal("hello ", word); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 314 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 315 | str = "hello/*comment*/\n"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 316 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 317 | assert_null(buf); |
| 318 | assert_int_equal(5, len); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 319 | assert_false(strncmp("hello", word, len)); |
| 320 | |
| 321 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 322 | str = "\"hello\\n\\t\\\"\\\\\";"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 323 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
fredgan | d49fe11 | 2019-10-21 20:51:50 +0800 | [diff] [blame] | 324 | assert_non_null(buf); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 325 | assert_int_equal(9, len); |
fredgan | d49fe11 | 2019-10-21 20:51:50 +0800 | [diff] [blame] | 326 | assert_string_equal("hello\n\t\"\\", word); |
| 327 | free(buf); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 328 | |
| 329 | ctx.indent = 14; |
| 330 | str = "\"hello \t\n\t\t world!\""; |
| 331 | /* - space and tabs before newline are stripped out |
| 332 | * - space and tabs after newline (indentation) are stripped out |
| 333 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 334 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 335 | assert_non_null(buf); |
| 336 | assert_ptr_equal(word, buf); |
| 337 | assert_int_equal(14, len); |
| 338 | assert_string_equal("hello\n world!", word); |
| 339 | free(buf); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 340 | /* In contrast to previous, the backslash-escaped tabs are expanded after trimming, so they are preserved */ |
| 341 | ctx.indent = 14; |
| 342 | str = "\"hello \\t\n\t\\t world!\""; |
| 343 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
| 344 | assert_non_null(buf); |
| 345 | assert_ptr_equal(word, buf); |
| 346 | assert_int_equal(16, len); |
| 347 | assert_string_equal("hello \t\n\t world!", word); |
| 348 | free(buf); |
| 349 | /* Do not handle whitespaces after backslash-escaped newline as indentation */ |
| 350 | ctx.indent = 14; |
| 351 | str = "\"hello\\n\t\t world!\""; |
| 352 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
| 353 | assert_non_null(buf); |
| 354 | assert_ptr_equal(word, buf); |
| 355 | assert_int_equal(15, len); |
| 356 | assert_string_equal("hello\n\t\t world!", word); |
| 357 | free(buf); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 358 | |
| 359 | ctx.indent = 14; |
| 360 | str = "\"hello\n \tworld!\""; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 361 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | d5f2b5f | 2018-10-11 10:54:36 +0200 | [diff] [blame] | 362 | assert_non_null(buf); |
| 363 | assert_ptr_equal(word, buf); |
| 364 | assert_int_equal(12, len); |
| 365 | assert_string_equal("hello\nworld!", word); |
| 366 | free(buf); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 367 | |
| 368 | str = "\'hello\'"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 369 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 370 | assert_null(buf); |
| 371 | assert_int_equal(5, len); |
| 372 | assert_false(strncmp("hello", word, 5)); |
| 373 | |
| 374 | str = "\"hel\" +\t\n\"lo\""; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 375 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 376 | assert_ptr_equal(word, buf); |
| 377 | assert_int_equal(5, len); |
| 378 | assert_string_equal("hello", word); |
| 379 | free(buf); |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 380 | str = "\"hel\" +\t\nlo"; /* unquoted the second part */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 381 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 382 | logbuf_assert("Both string parts divided by '+' must be quoted. Line number 6."); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 383 | |
| 384 | str = "\'he\'\t\n+ \"llo\""; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 385 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 386 | assert_ptr_equal(word, buf); |
| 387 | assert_int_equal(5, len); |
| 388 | assert_string_equal("hello", word); |
| 389 | free(buf); |
| 390 | |
Radek Krejci | fc62d7e | 2018-10-11 12:56:42 +0200 | [diff] [blame] | 391 | str = " \t\n\"he\"+\'llo\'"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 392 | assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 393 | assert_ptr_equal(word, buf); |
| 394 | assert_int_equal(5, len); |
| 395 | assert_string_equal("hello", word); |
| 396 | free(buf); |
| 397 | |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 398 | /* missing argument */ |
| 399 | str = ";"; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 400 | assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len)); |
Radek Krejci | ff13cd1 | 2019-10-25 15:34:24 +0200 | [diff] [blame] | 401 | logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 8."); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static void |
| 405 | test_stmts(void **state) |
| 406 | { |
| 407 | (void) state; /* unused */ |
| 408 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 409 | struct lys_yang_parser_ctx ctx; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 410 | const char *str, *p; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 411 | enum ly_stmt kw; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 412 | char *word; |
| 413 | size_t len; |
| 414 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 415 | ctx.format = LYS_IN_YANG; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 416 | ctx.ctx = NULL; |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 417 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 418 | ctx.line = 1; |
| 419 | |
| 420 | str = "\n// comment\n\tinput\t{"; |
| 421 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 422 | assert_int_equal(LY_STMT_INPUT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 423 | assert_int_equal(5, len); |
| 424 | assert_string_equal("input\t{", word); |
| 425 | assert_string_equal("\t{", str); |
| 426 | |
| 427 | str = "\t /* comment */\t output\n\t{"; |
| 428 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 429 | assert_int_equal(LY_STMT_OUTPUT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 430 | assert_int_equal(6, len); |
| 431 | assert_string_equal("output\n\t{", word); |
| 432 | assert_string_equal("\n\t{", str); |
Radek Krejci | abdd806 | 2019-06-11 16:44:19 +0200 | [diff] [blame] | 433 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 434 | assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw); |
Radek Krejci | abdd806 | 2019-06-11 16:44:19 +0200 | [diff] [blame] | 435 | assert_int_equal(1, len); |
| 436 | assert_string_equal("{", word); |
| 437 | assert_string_equal("", str); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 438 | |
| 439 | str = "/input { "; /* invalid slash */ |
| 440 | assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len)); |
| 441 | logbuf_assert("Invalid identifier first character '/'. Line number 4."); |
| 442 | |
| 443 | str = "not-a-statement-nor-extension { "; /* invalid identifier */ |
| 444 | assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len)); |
| 445 | logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4."); |
| 446 | |
| 447 | str = "path;"; /* missing sep after the keyword */ |
| 448 | assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len)); |
| 449 | logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4."); |
| 450 | |
| 451 | str = "action "; |
| 452 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 453 | assert_int_equal(LY_STMT_ACTION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 454 | assert_int_equal(6, len); |
| 455 | str = "anydata "; |
| 456 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 457 | assert_int_equal(LY_STMT_ANYDATA, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 458 | assert_int_equal(7, len); |
| 459 | str = "anyxml "; |
| 460 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 461 | assert_int_equal(LY_STMT_ANYXML, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 462 | assert_int_equal(6, len); |
| 463 | str = "argument "; |
| 464 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 465 | assert_int_equal(LY_STMT_ARGUMENT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 466 | assert_int_equal(8, len); |
| 467 | str = "augment "; |
| 468 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 469 | assert_int_equal(LY_STMT_AUGMENT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 470 | assert_int_equal(7, len); |
| 471 | str = "base "; |
| 472 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 473 | assert_int_equal(LY_STMT_BASE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 474 | assert_int_equal(4, len); |
| 475 | str = "belongs-to "; |
| 476 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 477 | assert_int_equal(LY_STMT_BELONGS_TO, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 478 | assert_int_equal(10, len); |
| 479 | str = "bit "; |
| 480 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 481 | assert_int_equal(LY_STMT_BIT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 482 | assert_int_equal(3, len); |
| 483 | str = "case "; |
| 484 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 485 | assert_int_equal(LY_STMT_CASE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 486 | assert_int_equal(4, len); |
| 487 | str = "choice "; |
| 488 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 489 | assert_int_equal(LY_STMT_CHOICE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 490 | assert_int_equal(6, len); |
| 491 | str = "config "; |
| 492 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 493 | assert_int_equal(LY_STMT_CONFIG, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 494 | assert_int_equal(6, len); |
| 495 | str = "contact "; |
| 496 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 497 | assert_int_equal(LY_STMT_CONTACT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 498 | assert_int_equal(7, len); |
| 499 | str = "container "; |
| 500 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 501 | assert_int_equal(LY_STMT_CONTAINER, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 502 | assert_int_equal(9, len); |
| 503 | str = "default "; |
| 504 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 505 | assert_int_equal(LY_STMT_DEFAULT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 506 | assert_int_equal(7, len); |
| 507 | str = "description "; |
| 508 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 509 | assert_int_equal(LY_STMT_DESCRIPTION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 510 | assert_int_equal(11, len); |
| 511 | str = "deviate "; |
| 512 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 513 | assert_int_equal(LY_STMT_DEVIATE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 514 | assert_int_equal(7, len); |
| 515 | str = "deviation "; |
| 516 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 517 | assert_int_equal(LY_STMT_DEVIATION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 518 | assert_int_equal(9, len); |
| 519 | str = "enum "; |
| 520 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 521 | assert_int_equal(LY_STMT_ENUM, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 522 | assert_int_equal(4, len); |
| 523 | str = "error-app-tag "; |
| 524 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 525 | assert_int_equal(LY_STMT_ERROR_APP_TAG, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 526 | assert_int_equal(13, len); |
| 527 | str = "error-message "; |
| 528 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 529 | assert_int_equal(LY_STMT_ERROR_MESSAGE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 530 | assert_int_equal(13, len); |
| 531 | str = "extension "; |
| 532 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 533 | assert_int_equal(LY_STMT_EXTENSION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 534 | assert_int_equal(9, len); |
| 535 | str = "feature "; |
| 536 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 537 | assert_int_equal(LY_STMT_FEATURE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 538 | assert_int_equal(7, len); |
| 539 | str = "fraction-digits "; |
| 540 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 541 | assert_int_equal(LY_STMT_FRACTION_DIGITS, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 542 | assert_int_equal(15, len); |
| 543 | str = "grouping "; |
| 544 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 545 | assert_int_equal(LY_STMT_GROUPING, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 546 | assert_int_equal(8, len); |
| 547 | str = "identity "; |
| 548 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 549 | assert_int_equal(LY_STMT_IDENTITY, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 550 | assert_int_equal(8, len); |
| 551 | str = "if-feature "; |
| 552 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 553 | assert_int_equal(LY_STMT_IF_FEATURE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 554 | assert_int_equal(10, len); |
| 555 | str = "import "; |
| 556 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 557 | assert_int_equal(LY_STMT_IMPORT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 558 | assert_int_equal(6, len); |
| 559 | str = "include "; |
| 560 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 561 | assert_int_equal(LY_STMT_INCLUDE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 562 | assert_int_equal(7, len); |
| 563 | str = "input{"; |
| 564 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 565 | assert_int_equal(LY_STMT_INPUT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 566 | assert_int_equal(5, len); |
| 567 | str = "key "; |
| 568 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 569 | assert_int_equal(LY_STMT_KEY, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 570 | assert_int_equal(3, len); |
| 571 | str = "leaf "; |
| 572 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 573 | assert_int_equal(LY_STMT_LEAF, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 574 | assert_int_equal(4, len); |
| 575 | str = "leaf-list "; |
| 576 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 577 | assert_int_equal(LY_STMT_LEAF_LIST, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 578 | assert_int_equal(9, len); |
| 579 | str = "length "; |
| 580 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 581 | assert_int_equal(LY_STMT_LENGTH, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 582 | assert_int_equal(6, len); |
| 583 | str = "list "; |
| 584 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 585 | assert_int_equal(LY_STMT_LIST, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 586 | assert_int_equal(4, len); |
| 587 | str = "mandatory "; |
| 588 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 589 | assert_int_equal(LY_STMT_MANDATORY, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 590 | assert_int_equal(9, len); |
| 591 | str = "max-elements "; |
| 592 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 593 | assert_int_equal(LY_STMT_MAX_ELEMENTS, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 594 | assert_int_equal(12, len); |
| 595 | str = "min-elements "; |
| 596 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 597 | assert_int_equal(LY_STMT_MIN_ELEMENTS, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 598 | assert_int_equal(12, len); |
| 599 | str = "modifier "; |
| 600 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 601 | assert_int_equal(LY_STMT_MODIFIER, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 602 | assert_int_equal(8, len); |
| 603 | str = "module "; |
| 604 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 605 | assert_int_equal(LY_STMT_MODULE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 606 | assert_int_equal(6, len); |
| 607 | str = "must "; |
| 608 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 609 | assert_int_equal(LY_STMT_MUST, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 610 | assert_int_equal(4, len); |
| 611 | str = "namespace "; |
| 612 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 613 | assert_int_equal(LY_STMT_NAMESPACE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 614 | assert_int_equal(9, len); |
| 615 | str = "notification "; |
| 616 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 617 | assert_int_equal(LY_STMT_NOTIFICATION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 618 | assert_int_equal(12, len); |
| 619 | str = "ordered-by "; |
| 620 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 621 | assert_int_equal(LY_STMT_ORDERED_BY, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 622 | assert_int_equal(10, len); |
| 623 | str = "organization "; |
| 624 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 625 | assert_int_equal(LY_STMT_ORGANIZATION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 626 | assert_int_equal(12, len); |
| 627 | str = "output "; |
| 628 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 629 | assert_int_equal(LY_STMT_OUTPUT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 630 | assert_int_equal(6, len); |
| 631 | str = "path "; |
| 632 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 633 | assert_int_equal(LY_STMT_PATH, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 634 | assert_int_equal(4, len); |
| 635 | str = "pattern "; |
| 636 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 637 | assert_int_equal(LY_STMT_PATTERN, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 638 | assert_int_equal(7, len); |
| 639 | str = "position "; |
| 640 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 641 | assert_int_equal(LY_STMT_POSITION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 642 | assert_int_equal(8, len); |
| 643 | str = "prefix "; |
| 644 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 645 | assert_int_equal(LY_STMT_PREFIX, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 646 | assert_int_equal(6, len); |
| 647 | str = "presence "; |
| 648 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 649 | assert_int_equal(LY_STMT_PRESENCE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 650 | assert_int_equal(8, len); |
| 651 | str = "range "; |
| 652 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 653 | assert_int_equal(LY_STMT_RANGE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 654 | assert_int_equal(5, len); |
| 655 | str = "reference "; |
| 656 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 657 | assert_int_equal(LY_STMT_REFERENCE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 658 | assert_int_equal(9, len); |
| 659 | str = "refine "; |
| 660 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 661 | assert_int_equal(LY_STMT_REFINE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 662 | assert_int_equal(6, len); |
| 663 | str = "require-instance "; |
| 664 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 665 | assert_int_equal(LY_STMT_REQUIRE_INSTANCE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 666 | assert_int_equal(16, len); |
| 667 | str = "revision "; |
| 668 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 669 | assert_int_equal(LY_STMT_REVISION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 670 | assert_int_equal(8, len); |
| 671 | str = "revision-date "; |
| 672 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 673 | assert_int_equal(LY_STMT_REVISION_DATE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 674 | assert_int_equal(13, len); |
| 675 | str = "rpc "; |
| 676 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 677 | assert_int_equal(LY_STMT_RPC, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 678 | assert_int_equal(3, len); |
| 679 | str = "status "; |
| 680 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 681 | assert_int_equal(LY_STMT_STATUS, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 682 | assert_int_equal(6, len); |
| 683 | str = "submodule "; |
| 684 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 685 | assert_int_equal(LY_STMT_SUBMODULE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 686 | assert_int_equal(9, len); |
| 687 | str = "type "; |
| 688 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 689 | assert_int_equal(LY_STMT_TYPE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 690 | assert_int_equal(4, len); |
| 691 | str = "typedef "; |
| 692 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 693 | assert_int_equal(LY_STMT_TYPEDEF, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 694 | assert_int_equal(7, len); |
| 695 | str = "unique "; |
| 696 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 697 | assert_int_equal(LY_STMT_UNIQUE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 698 | assert_int_equal(6, len); |
| 699 | str = "units "; |
| 700 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 701 | assert_int_equal(LY_STMT_UNITS, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 702 | assert_int_equal(5, len); |
| 703 | str = "uses "; |
| 704 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 705 | assert_int_equal(LY_STMT_USES, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 706 | assert_int_equal(4, len); |
| 707 | str = "value "; |
| 708 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 709 | assert_int_equal(LY_STMT_VALUE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 710 | assert_int_equal(5, len); |
| 711 | str = "when "; |
| 712 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 713 | assert_int_equal(LY_STMT_WHEN, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 714 | assert_int_equal(4, len); |
| 715 | str = "yang-version "; |
| 716 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 717 | assert_int_equal(LY_STMT_YANG_VERSION, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 718 | assert_int_equal(12, len); |
| 719 | str = "yin-element "; |
| 720 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 721 | assert_int_equal(LY_STMT_YIN_ELEMENT, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 722 | assert_int_equal(11, len); |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 723 | str = ";config false;"; |
| 724 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 725 | assert_int_equal(LY_STMT_SYNTAX_SEMICOLON, kw); |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 726 | assert_int_equal(1, len); |
| 727 | assert_string_equal("config false;", str); |
| 728 | str = "{ config false;"; |
| 729 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 730 | assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw); |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 731 | assert_int_equal(1, len); |
| 732 | assert_string_equal(" config false;", str); |
| 733 | str = "}"; |
| 734 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 735 | assert_int_equal(LY_STMT_SYNTAX_RIGHT_BRACE, kw); |
Radek Krejci | 626df48 | 2018-10-11 15:06:31 +0200 | [diff] [blame] | 736 | assert_int_equal(1, len); |
| 737 | assert_string_equal("", str); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 738 | |
| 739 | /* geenric extension */ |
| 740 | str = p = "nacm:default-deny-write;"; |
| 741 | assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 742 | assert_int_equal(LY_STMT_EXTENSION_INSTANCE, kw); |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 743 | assert_int_equal(23, len); |
| 744 | assert_ptr_equal(p, word); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 745 | } |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 746 | |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 747 | static void |
| 748 | test_minmax(void **state) |
| 749 | { |
| 750 | *state = test_minmax; |
| 751 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 752 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 753 | uint16_t flags = 0; |
| 754 | uint32_t value = 0; |
| 755 | struct lysp_ext_instance *ext = NULL; |
| 756 | const char *str; |
| 757 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 758 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 759 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 760 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 761 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 762 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 763 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 764 | |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 765 | str = " 1invalid; ..."; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 766 | assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 767 | logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1."); |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 768 | |
| 769 | flags = value = 0; |
| 770 | str = " -1; ..."; |
| 771 | assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
| 772 | logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1."); |
| 773 | |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 774 | /* implementation limit */ |
| 775 | flags = value = 0; |
| 776 | str = " 4294967296; ..."; |
| 777 | assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
| 778 | logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1."); |
| 779 | |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 780 | flags = value = 0; |
| 781 | str = " 1; ..."; |
| 782 | assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
| 783 | assert_int_equal(LYS_SET_MIN, flags); |
| 784 | assert_int_equal(1, value); |
| 785 | |
| 786 | flags = value = 0; |
| 787 | str = " 1 {m:ext;} ..."; |
| 788 | assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
| 789 | assert_int_equal(LYS_SET_MIN, flags); |
| 790 | assert_int_equal(1, value); |
| 791 | assert_non_null(ext); |
| 792 | FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free); |
| 793 | ext = NULL; |
| 794 | |
| 795 | flags = value = 0; |
| 796 | str = " 1 {config true;} ..."; |
| 797 | assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext)); |
| 798 | logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1."); |
| 799 | |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 800 | str = " 1invalid; ..."; |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 801 | assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 802 | logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1."); |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 803 | |
| 804 | flags = value = 0; |
| 805 | str = " -1; ..."; |
| 806 | assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
| 807 | logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1."); |
| 808 | |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 809 | /* implementation limit */ |
| 810 | flags = value = 0; |
| 811 | str = " 4294967296; ..."; |
| 812 | assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
| 813 | logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1."); |
| 814 | |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 815 | flags = value = 0; |
| 816 | str = " 1; ..."; |
| 817 | assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
| 818 | assert_int_equal(LYS_SET_MAX, flags); |
| 819 | assert_int_equal(1, value); |
| 820 | |
| 821 | flags = value = 0; |
| 822 | str = " unbounded; ..."; |
| 823 | assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
| 824 | assert_int_equal(LYS_SET_MAX, flags); |
| 825 | assert_int_equal(0, value); |
| 826 | |
| 827 | flags = value = 0; |
| 828 | str = " 1 {m:ext;} ..."; |
| 829 | assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
| 830 | assert_int_equal(LYS_SET_MAX, flags); |
| 831 | assert_int_equal(1, value); |
| 832 | assert_non_null(ext); |
| 833 | FREE_ARRAY(ctx.ctx, ext, lysp_ext_instance_free); |
| 834 | ext = NULL; |
| 835 | |
| 836 | flags = value = 0; |
| 837 | str = " 1 {config true;} ..."; |
| 838 | assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext)); |
| 839 | logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1."); |
| 840 | |
| 841 | *state = NULL; |
| 842 | ly_ctx_destroy(ctx.ctx, NULL); |
| 843 | } |
| 844 | |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 845 | static struct lysp_module * |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 846 | mod_renew(struct lys_yang_parser_ctx *ctx) |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 847 | { |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 848 | struct lysp_module *mod_p; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 849 | static struct lys_module mod = {0}; |
| 850 | |
| 851 | lysc_module_free(mod.compiled, NULL); |
| 852 | lysp_module_free(mod.parsed); |
| 853 | FREE_STRING(mod.ctx, mod.name); |
| 854 | FREE_STRING(mod.ctx, mod.ns); |
| 855 | FREE_STRING(mod.ctx, mod.prefix); |
| 856 | FREE_STRING(mod.ctx, mod.filepath); |
| 857 | FREE_STRING(mod.ctx, mod.org); |
| 858 | FREE_STRING(mod.ctx, mod.contact); |
| 859 | FREE_STRING(mod.ctx, mod.dsc); |
| 860 | FREE_STRING(mod.ctx, mod.ref); |
| 861 | memset(&mod, 0, sizeof mod); |
| 862 | mod.ctx = ctx->ctx; |
| 863 | |
| 864 | mod_p = calloc(1, sizeof *mod_p); |
| 865 | mod.parsed = mod_p; |
| 866 | mod_p->mod = &mod; |
| 867 | assert_non_null(mod_p); |
| 868 | return mod_p; |
| 869 | } |
| 870 | |
| 871 | static struct lysp_submodule * |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 872 | submod_renew(struct lys_yang_parser_ctx *ctx, struct lysp_submodule *submod) |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 873 | { |
| 874 | lysp_submodule_free(ctx->ctx, submod); |
| 875 | submod = calloc(1, sizeof *submod); |
| 876 | assert_non_null(submod); |
| 877 | return submod; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 878 | } |
| 879 | |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 880 | static LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name), |
| 881 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 882 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 883 | { |
| 884 | *module_data = user_data; |
| 885 | *format = LYS_IN_YANG; |
| 886 | *free_module_data = NULL; |
| 887 | return LY_SUCCESS; |
| 888 | } |
| 889 | |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 890 | static void |
| 891 | test_module(void **state) |
| 892 | { |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 893 | *state = test_module; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 894 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 895 | struct lys_yang_parser_ctx ctx; |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 896 | struct lysp_module *mod = NULL; |
| 897 | struct lysp_submodule *submod = NULL; |
| 898 | struct lys_module *m; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 899 | const char *str; |
| 900 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 901 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 902 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 903 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 904 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 905 | ctx.line = 1; |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 906 | ctx.indent = 0; |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 907 | |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 908 | mod = mod_renew(&ctx); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 909 | |
| 910 | /* missing mandatory substatements */ |
| 911 | str = " name {}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 912 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
| 913 | assert_string_equal("name", mod->mod->name); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 914 | logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 915 | mod = mod_renew(&ctx); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 916 | |
| 917 | str = " name {namespace urn:x;}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 918 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
| 919 | assert_string_equal("urn:x", mod->mod->ns); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 920 | logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 921 | mod = mod_renew(&ctx); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 922 | |
| 923 | str = " name {namespace urn:x;prefix \"x\";}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 924 | assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); |
| 925 | assert_string_equal("x", mod->mod->prefix); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 926 | mod = mod_renew(&ctx); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 927 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 928 | #define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";" |
| 929 | #define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";" |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 930 | #define TEST_NODE(NODETYPE, INPUT, NAME) \ |
| 931 | str = SCHEMA_BEGINNING INPUT; \ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 932 | assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \ |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 933 | assert_non_null(mod->data); \ |
| 934 | assert_int_equal(NODETYPE, mod->data->nodetype); \ |
| 935 | assert_string_equal(NAME, mod->data->name); \ |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 936 | mod = mod_renew(&ctx); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 937 | #define TEST_GENERIC(INPUT, TARGET, TEST) \ |
| 938 | str = SCHEMA_BEGINNING INPUT; \ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 939 | assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \ |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 940 | assert_non_null(TARGET); \ |
| 941 | TEST; \ |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 942 | mod = mod_renew(&ctx); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 943 | #define TEST_DUP(MEMBER, VALUE1, VALUE2, LINE) \ |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 944 | TEST_DUP_GENERIC(SCHEMA_BEGINNING, MEMBER, VALUE1, VALUE2, \ |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 945 | parse_module, mod, LINE, mod = mod_renew(&ctx)) |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 946 | |
| 947 | /* duplicated namespace, prefix */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 948 | TEST_DUP("namespace", "y", "z", "1"); |
| 949 | TEST_DUP("prefix", "y", "z", "1"); |
| 950 | TEST_DUP("contact", "a", "b", "1"); |
| 951 | TEST_DUP("description", "a", "b", "1"); |
| 952 | TEST_DUP("organization", "a", "b", "1"); |
| 953 | TEST_DUP("reference", "a", "b", "1"); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 954 | |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 955 | /* not allowed in module (submodule-specific) */ |
| 956 | str = SCHEMA_BEGINNING "belongs-to master {prefix m;}}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 957 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 958 | logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 959 | mod = mod_renew(&ctx); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 960 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 961 | /* anydata */ |
| 962 | TEST_NODE(LYS_ANYDATA, "anydata test;}", "test"); |
| 963 | /* anyxml */ |
| 964 | TEST_NODE(LYS_ANYXML, "anyxml test;}", "test"); |
| 965 | /* augment */ |
| 966 | TEST_GENERIC("augment /somepath;}", mod->augments, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 967 | assert_string_equal("/somepath", mod->augments[0].nodeid)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 968 | /* choice */ |
| 969 | TEST_NODE(LYS_CHOICE, "choice test;}", "test"); |
| 970 | /* contact 0..1 */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 971 | TEST_GENERIC("contact \"firstname\" + \n\t\" surname\";}", mod->mod->contact, |
| 972 | assert_string_equal("firstname surname", mod->mod->contact)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 973 | /* container */ |
| 974 | TEST_NODE(LYS_CONTAINER, "container test;}", "test"); |
| 975 | /* description 0..1 */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 976 | TEST_GENERIC("description \'some description\';}", mod->mod->dsc, |
| 977 | assert_string_equal("some description", mod->mod->dsc)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 978 | /* deviation */ |
| 979 | TEST_GENERIC("deviation /somepath {deviate not-supported;}}", mod->deviations, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 980 | assert_string_equal("/somepath", mod->deviations[0].nodeid)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 981 | /* extension */ |
| 982 | TEST_GENERIC("extension test;}", mod->extensions, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 983 | assert_string_equal("test", mod->extensions[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 984 | /* feature */ |
| 985 | TEST_GENERIC("feature test;}", mod->features, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 986 | assert_string_equal("test", mod->features[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 987 | /* grouping */ |
| 988 | TEST_GENERIC("grouping grp;}", mod->groupings, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 989 | assert_string_equal("grp", mod->groupings[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 990 | /* identity */ |
| 991 | TEST_GENERIC("identity test;}", mod->identities, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 992 | assert_string_equal("test", mod->identities[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 993 | /* import */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 994 | ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}"); |
| 995 | TEST_GENERIC("import zzz {prefix z;}}", mod->imports, |
| 996 | assert_string_equal("zzz", mod->imports[0].name)); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 997 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 998 | /* import - prefix collision */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 999 | str = SCHEMA_BEGINNING "import zzz {prefix x;}}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1000 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 1001 | logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1002 | mod = mod_renew(&ctx); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1003 | str = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1004 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1005 | logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1006 | mod = mod_renew(&ctx); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1007 | str = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}"; |
| 1008 | assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG)); |
| 1009 | assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx)); |
| 1010 | logbuf_assert("Single revision of the module \"zzz\" referred twice."); |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 1011 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1012 | /* include */ |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 1013 | store = 1; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1014 | 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] | 1015 | str = "module" SCHEMA_BEGINNING "include xxx;}"; |
| 1016 | assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG)); |
| 1017 | assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1018 | logbuf_assert("Input data contains module in situation when a submodule is expected."); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 1019 | store = -1; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1020 | |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 1021 | store = 1; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1022 | 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] | 1023 | str = "module" SCHEMA_BEGINNING "include xxx;}"; |
| 1024 | assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG)); |
| 1025 | assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx)); |
| 1026 | 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] | 1027 | store = -1; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1028 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1029 | 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] | 1030 | TEST_GENERIC("include xxx;}", mod->includes, |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 1031 | assert_string_equal("xxx", mod->includes[0].name)); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 1032 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1033 | /* leaf */ |
| 1034 | TEST_NODE(LYS_LEAF, "leaf test {type string;}}", "test"); |
| 1035 | /* leaf-list */ |
| 1036 | TEST_NODE(LYS_LEAFLIST, "leaf-list test {type string;}}", "test"); |
| 1037 | /* list */ |
| 1038 | TEST_NODE(LYS_LIST, "list test {key a;leaf a {type string;}}}", "test"); |
| 1039 | /* notification */ |
| 1040 | TEST_GENERIC("notification test;}", mod->notifs, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1041 | assert_string_equal("test", mod->notifs[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1042 | /* organization 0..1 */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1043 | TEST_GENERIC("organization \"CESNET a.l.e.\";}", mod->mod->org, |
| 1044 | assert_string_equal("CESNET a.l.e.", mod->mod->org)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1045 | /* reference 0..1 */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1046 | TEST_GENERIC("reference RFC7950;}", mod->mod->ref, |
| 1047 | assert_string_equal("RFC7950", mod->mod->ref)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1048 | /* revision */ |
| 1049 | TEST_GENERIC("revision 2018-10-12;}", mod->revs, |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 1050 | assert_string_equal("2018-10-12", mod->revs[0].date)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1051 | /* rpc */ |
| 1052 | TEST_GENERIC("rpc test;}", mod->rpcs, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1053 | assert_string_equal("test", mod->rpcs[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1054 | /* typedef */ |
| 1055 | TEST_GENERIC("typedef test{type string;}}", mod->typedefs, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1056 | assert_string_equal("test", mod->typedefs[0].name)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1057 | /* uses */ |
| 1058 | TEST_NODE(LYS_USES, "uses test;}", "test"); |
| 1059 | /* yang-version */ |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1060 | str = SCHEMA_BEGINNING2 "\n\tyang-version 10;}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1061 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1062 | logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1063 | mod = mod_renew(&ctx); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1064 | str = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1065 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1066 | logbuf_assert("Duplicate keyword \"yang-version\". Line number 3."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1067 | mod = mod_renew(&ctx); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1068 | str = SCHEMA_BEGINNING2 "yang-version 1.0;}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1069 | assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); |
| 1070 | assert_int_equal(1, mod->mod->version); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1071 | mod = mod_renew(&ctx); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1072 | str = SCHEMA_BEGINNING2 "yang-version \"1.1\";}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1073 | assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); |
| 1074 | assert_int_equal(2, mod->mod->version); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1075 | mod = mod_renew(&ctx); |
| 1076 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1077 | struct lys_yang_parser_ctx *ctx_p = NULL; |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1078 | str = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}"; |
| 1079 | m = mod->mod; |
| 1080 | free(mod); |
| 1081 | m->parsed = NULL; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1082 | assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, str, m)); |
| 1083 | logbuf_assert("Trailing garbage \"module q {names...\" after module, expected end-of-input. Line number 1."); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1084 | yang_parser_ctx_free(ctx_p); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1085 | mod = mod_renew(&ctx); |
| 1086 | |
| 1087 | str = "prefix " SCHEMA_BEGINNING "}"; |
| 1088 | m = mod->mod; |
| 1089 | free(mod); |
| 1090 | m->parsed = NULL; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1091 | assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, str, m)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1092 | yang_parser_ctx_free(ctx_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1093 | logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1094 | mod = mod_renew(&ctx); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1095 | |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1096 | str = "module " SCHEMA_BEGINNING "}"; |
| 1097 | str = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}"; |
| 1098 | m = mod->mod; |
| 1099 | free(mod); |
| 1100 | m->parsed = NULL; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1101 | assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, str, m)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1102 | yang_parser_ctx_free(ctx_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1103 | logbuf_assert("Invalid keyword \"position\" as a child of \"enum\". Line number 1."); |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1104 | mod = mod_renew(&ctx); |
| 1105 | |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 1106 | /* extensions */ |
| 1107 | TEST_GENERIC("prefix:test;}", mod->exts, |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 1108 | assert_string_equal("prefix:test", mod->exts[0].name); |
| 1109 | assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt)); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1110 | mod = mod_renew(&ctx); |
Radek Krejci | 156ccaf | 2018-10-15 15:49:17 +0200 | [diff] [blame] | 1111 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1112 | /* invalid substatement */ |
| 1113 | str = SCHEMA_BEGINNING "must false;}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1114 | assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod)); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1115 | logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1116 | mod = mod_renew(&ctx); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1117 | |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1118 | /* submodule */ |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1119 | submod = submod_renew(&ctx, submod); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1120 | |
| 1121 | /* missing mandatory substatements */ |
| 1122 | str = " subname {}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1123 | lydict_remove(ctx.ctx, submod->name); |
| 1124 | assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); |
| 1125 | assert_string_equal("subname", submod->name); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1126 | logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1127 | submod = submod_renew(&ctx, submod); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1128 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1129 | str = " subname {belongs-to name {prefix x;}}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1130 | lydict_remove(ctx.ctx, submod->name); |
| 1131 | assert_int_equal(LY_SUCCESS, parse_submodule(&ctx, &str, submod)); |
| 1132 | assert_string_equal("name", submod->belongsto); |
| 1133 | submod = submod_renew(&ctx, submod); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1134 | |
| 1135 | #undef SCHEMA_BEGINNING |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1136 | #define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}" |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1137 | |
| 1138 | /* duplicated namespace, prefix */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1139 | str = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ..."; |
| 1140 | assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); \ |
| 1141 | logbuf_assert("Duplicate keyword \"belongs-to\". Line number 3."); \ |
| 1142 | submod = submod_renew(&ctx, submod); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1143 | |
| 1144 | /* not allowed in submodule (module-specific) */ |
| 1145 | str = SCHEMA_BEGINNING "namespace \"urn:z\";}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1146 | assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1147 | logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1148 | submod = submod_renew(&ctx, submod); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1149 | str = SCHEMA_BEGINNING "prefix m;}}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1150 | assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); |
Radek Krejci | 0930636 | 2018-10-15 15:26:01 +0200 | [diff] [blame] | 1151 | logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1152 | submod = submod_renew(&ctx, submod); |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1153 | |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1154 | str = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}"; |
| 1155 | lysp_submodule_free(ctx.ctx, submod); |
| 1156 | submod = NULL; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1157 | assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx.ctx, (struct lys_parser_ctx *)&ctx, str, &submod)); |
| 1158 | yang_parser_ctx_free(ctx_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1159 | logbuf_assert("Trailing garbage \"module q {names...\" after submodule, expected end-of-input. Line number 1."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1160 | |
| 1161 | str = "prefix " SCHEMA_BEGINNING "}"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1162 | assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx.ctx, (struct lys_parser_ctx *)&ctx, str, &submod)); |
| 1163 | yang_parser_ctx_free(ctx_p); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 1164 | logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1."); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1165 | submod = submod_renew(&ctx, submod); |
| 1166 | |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1167 | #undef TEST_GENERIC |
| 1168 | #undef TEST_NODE |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1169 | #undef TEST_DUP |
Radek Krejci | a042ea1 | 2018-10-13 07:52:15 +0200 | [diff] [blame] | 1170 | #undef SCHEMA_BEGINNING |
| 1171 | |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 1172 | lysp_module_free(mod); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1173 | lysp_submodule_free(ctx.ctx, submod); |
Radek Krejci | 9fcacc1 | 2018-10-11 15:59:11 +0200 | [diff] [blame] | 1174 | ly_ctx_destroy(ctx.ctx, NULL); |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 1175 | |
| 1176 | *state = NULL; |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 1177 | } |
| 1178 | |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1179 | |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1180 | |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1181 | |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1182 | |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1183 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1184 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1185 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1186 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1187 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1188 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1189 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1190 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1191 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1192 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1193 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1194 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1195 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame^] | 1196 | |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1197 | |
| 1198 | static void |
| 1199 | test_deviation(void **state) |
| 1200 | { |
| 1201 | (void) state; /* unused */ |
| 1202 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1203 | struct lys_yang_parser_ctx ctx; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1204 | struct lysp_deviation *d = NULL; |
| 1205 | const char *str; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1206 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1207 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1208 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1209 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1210 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1211 | ctx.line = 1; |
| 1212 | ctx.indent = 0; |
| 1213 | |
| 1214 | /* invalid cardinality */ |
| 1215 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1216 | TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1217 | &d, "1", FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); d = NULL) |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1218 | |
| 1219 | TEST_DUP("description", "a", "b"); |
| 1220 | TEST_DUP("reference", "a", "b"); |
| 1221 | |
| 1222 | /* full content */ |
| 1223 | str = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ..."; |
| 1224 | assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &str, &d)); |
| 1225 | assert_non_null(d); |
| 1226 | assert_string_equal(" ...", str); |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 1227 | FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1228 | d = NULL; |
| 1229 | |
| 1230 | /* missing mandatory substatement */ |
| 1231 | str = " test {description text;}"; |
| 1232 | assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d)); |
| 1233 | 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] | 1234 | FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1235 | d = NULL; |
| 1236 | |
| 1237 | /* invalid substatement */ |
| 1238 | str = " test {deviate not-supported; status obsolete;}"; |
| 1239 | assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d)); |
| 1240 | 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] | 1241 | FREE_ARRAY(ctx.ctx, d, lysp_deviation_free); |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1242 | d = NULL; |
| 1243 | |
| 1244 | #undef TEST_DUP |
| 1245 | |
| 1246 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1247 | } |
| 1248 | |
| 1249 | static void |
| 1250 | test_deviate(void **state) |
| 1251 | { |
| 1252 | (void) state; /* unused */ |
| 1253 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1254 | struct lys_yang_parser_ctx ctx; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1255 | struct lysp_deviate *d = NULL; |
| 1256 | const char *str; |
| 1257 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1258 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1259 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1260 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1261 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1262 | ctx.line = 1; |
| 1263 | ctx.indent = 0; |
| 1264 | |
| 1265 | /* invalid cardinality */ |
| 1266 | #define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \ |
| 1267 | TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1268 | &d, "1", lysp_deviate_free(ctx.ctx, d); free(d); d = NULL) |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1269 | |
| 1270 | TEST_DUP("add", "config", "true", "false"); |
| 1271 | TEST_DUP("replace", "default", "int8", "uint8"); |
| 1272 | TEST_DUP("add", "mandatory", "true", "false"); |
| 1273 | TEST_DUP("add", "max-elements", "1", "2"); |
| 1274 | TEST_DUP("add", "min-elements", "1", "2"); |
| 1275 | TEST_DUP("replace", "type", "int8", "uint8"); |
| 1276 | TEST_DUP("add", "units", "kilometers", "miles"); |
| 1277 | |
| 1278 | /* full contents */ |
| 1279 | str = " not-supported {prefix:ext;} ..."; |
| 1280 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1281 | assert_non_null(d); |
| 1282 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1283 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1284 | 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;} ..."; |
| 1285 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1286 | assert_non_null(d); |
| 1287 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1288 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1289 | str = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ..."; |
| 1290 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1291 | assert_non_null(d); |
| 1292 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1293 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1294 | str = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ..."; |
| 1295 | assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d)); |
| 1296 | assert_non_null(d); |
| 1297 | assert_string_equal(" ...", str); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1298 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL; |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1299 | |
| 1300 | /* invalid substatements */ |
| 1301 | #define TEST_NOT_SUP(DEV, STMT, VALUE) \ |
| 1302 | str = " "DEV" {"STMT" "VALUE";}..."; \ |
| 1303 | assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); \ |
| 1304 | logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1305 | lysp_deviate_free(ctx.ctx, d); free(d); d = NULL |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 1306 | |
| 1307 | TEST_NOT_SUP("not-supported", "units", "meters"); |
| 1308 | TEST_NOT_SUP("not-supported", "must", "1"); |
| 1309 | TEST_NOT_SUP("not-supported", "unique", "x"); |
| 1310 | TEST_NOT_SUP("not-supported", "default", "a"); |
| 1311 | TEST_NOT_SUP("not-supported", "config", "true"); |
| 1312 | TEST_NOT_SUP("not-supported", "mandatory", "true"); |
| 1313 | TEST_NOT_SUP("not-supported", "min-elements", "1"); |
| 1314 | TEST_NOT_SUP("not-supported", "max-elements", "2"); |
| 1315 | TEST_NOT_SUP("not-supported", "type", "string"); |
| 1316 | TEST_NOT_SUP("add", "type", "string"); |
| 1317 | TEST_NOT_SUP("delete", "config", "true"); |
| 1318 | TEST_NOT_SUP("delete", "mandatory", "true"); |
| 1319 | TEST_NOT_SUP("delete", "min-elements", "1"); |
| 1320 | TEST_NOT_SUP("delete", "max-elements", "2"); |
| 1321 | TEST_NOT_SUP("delete", "type", "string"); |
| 1322 | TEST_NOT_SUP("replace", "must", "1"); |
| 1323 | TEST_NOT_SUP("replace", "unique", "a"); |
| 1324 | |
| 1325 | str = " nonsence; ..."; |
| 1326 | assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); |
| 1327 | logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1."); |
| 1328 | assert_null(d); |
| 1329 | |
| 1330 | #undef TEST_NOT_SUP |
| 1331 | #undef TEST_DUP |
Radek Krejci | 4c6d9bd | 2018-10-15 16:43:06 +0200 | [diff] [blame] | 1332 | |
| 1333 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1334 | } |
| 1335 | |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1336 | static void |
| 1337 | test_container(void **state) |
| 1338 | { |
| 1339 | (void) state; /* unused */ |
| 1340 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1341 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1342 | struct lysp_node_container *c = NULL; |
| 1343 | const char *str; |
| 1344 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1345 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1346 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1347 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1348 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1349 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1350 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1351 | |
| 1352 | /* invalid cardinality */ |
| 1353 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1354 | str = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1355 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); \ |
| 1356 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1357 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1358 | |
| 1359 | TEST_DUP("config", "true", "false"); |
| 1360 | TEST_DUP("description", "text1", "text2"); |
| 1361 | TEST_DUP("presence", "true", "false"); |
| 1362 | TEST_DUP("reference", "1", "2"); |
| 1363 | TEST_DUP("status", "current", "obsolete"); |
| 1364 | TEST_DUP("when", "true", "false"); |
| 1365 | #undef TEST_DUP |
| 1366 | |
| 1367 | /* full content */ |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1368 | 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;}" |
| 1369 | "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] | 1370 | assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1371 | assert_non_null(c); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1372 | assert_int_equal(LYS_CONTAINER, c->nodetype); |
| 1373 | assert_string_equal("cont", c->name); |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1374 | assert_non_null(c->actions); |
| 1375 | assert_non_null(c->child); |
| 1376 | assert_string_equal("test", c->dsc); |
| 1377 | assert_non_null(c->exts); |
| 1378 | assert_non_null(c->groupings); |
| 1379 | assert_non_null(c->iffeatures); |
| 1380 | assert_non_null(c->musts); |
| 1381 | assert_non_null(c->notifs); |
| 1382 | assert_string_equal("true", c->presence); |
| 1383 | assert_string_equal("test", c->ref); |
| 1384 | assert_non_null(c->typedefs); |
| 1385 | assert_non_null(c->when); |
| 1386 | assert_null(c->parent); |
| 1387 | assert_null(c->next); |
| 1388 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags); |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 1389 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1390 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1391 | |
| 1392 | /* invalid */ |
| 1393 | str = " cont {augment /root;} ..."; |
| 1394 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1395 | 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] | 1396 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1397 | str = " cont {nonsence true;} ..."; |
| 1398 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1399 | logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1."); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1400 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1401 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1402 | ctx.mod_version = 1; /* simulate YANG 1.0 */ |
| 1403 | str = " cont {action x;} ..."; |
| 1404 | assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1405 | logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 1406 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL; |
| 1407 | |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 1408 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1409 | } |
| 1410 | |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1411 | static void |
| 1412 | test_leaf(void **state) |
| 1413 | { |
| 1414 | *state = test_leaf; |
| 1415 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1416 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1417 | struct lysp_node_leaf *l = NULL; |
| 1418 | const char *str; |
| 1419 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1420 | ctx.format = LYS_IN_YANG; |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1421 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1422 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1423 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1424 | ctx.line = 1; |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1425 | //ctx.mod->version = 2; /* simulate YANG 1.1 */ |
| 1426 | |
| 1427 | /* invalid cardinality */ |
| 1428 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1429 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1430 | assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); \ |
| 1431 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1432 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1433 | |
| 1434 | TEST_DUP("config", "true", "false"); |
| 1435 | TEST_DUP("default", "x", "y"); |
| 1436 | TEST_DUP("description", "text1", "text2"); |
| 1437 | TEST_DUP("mandatory", "true", "false"); |
| 1438 | TEST_DUP("reference", "1", "2"); |
| 1439 | TEST_DUP("status", "current", "obsolete"); |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1440 | TEST_DUP("type", "int8", "uint8"); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1441 | TEST_DUP("units", "text1", "text2"); |
| 1442 | TEST_DUP("when", "true", "false"); |
| 1443 | #undef TEST_DUP |
| 1444 | |
| 1445 | /* full content - without mandatory which is mutual exclusive with default */ |
| 1446 | str = "l {config false;default \"xxx\";description test;if-feature f;" |
| 1447 | "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ..."; |
| 1448 | assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1449 | assert_non_null(l); |
| 1450 | assert_int_equal(LYS_LEAF, l->nodetype); |
| 1451 | assert_string_equal("l", l->name); |
| 1452 | assert_string_equal("test", l->dsc); |
| 1453 | assert_string_equal("xxx", l->dflt); |
| 1454 | assert_string_equal("yyy", l->units); |
| 1455 | assert_string_equal("string", l->type.name); |
| 1456 | assert_non_null(l->exts); |
| 1457 | assert_non_null(l->iffeatures); |
| 1458 | assert_non_null(l->musts); |
| 1459 | assert_string_equal("test", l->ref); |
| 1460 | assert_non_null(l->when); |
| 1461 | assert_null(l->parent); |
| 1462 | assert_null(l->next); |
| 1463 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags); |
| 1464 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1465 | |
| 1466 | /* full content - now with mandatory */ |
| 1467 | str = "l {mandatory true; type string;} ..."; |
| 1468 | assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1469 | assert_non_null(l); |
| 1470 | assert_int_equal(LYS_LEAF, l->nodetype); |
| 1471 | assert_string_equal("l", l->name); |
| 1472 | assert_string_equal("string", l->type.name); |
| 1473 | assert_int_equal(LYS_MAND_TRUE, l->flags); |
| 1474 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1475 | |
| 1476 | /* invalid */ |
| 1477 | str = " l {mandatory true; default xx; type string;} ..."; |
| 1478 | 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] | 1479 | 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] | 1480 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1481 | |
| 1482 | str = " l {description \"missing type\";} ..."; |
| 1483 | assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1484 | logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1."); |
| 1485 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1486 | |
| 1487 | *state = NULL; |
| 1488 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1489 | } |
| 1490 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1491 | static void |
| 1492 | test_leaflist(void **state) |
| 1493 | { |
| 1494 | *state = test_leaf; |
| 1495 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1496 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1497 | struct lysp_node_leaflist *ll = NULL; |
| 1498 | const char *str; |
| 1499 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1500 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1501 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1502 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1503 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1504 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1505 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1506 | |
| 1507 | /* invalid cardinality */ |
| 1508 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1509 | str = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1510 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); \ |
| 1511 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1512 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1513 | |
| 1514 | TEST_DUP("config", "true", "false"); |
| 1515 | TEST_DUP("description", "text1", "text2"); |
| 1516 | TEST_DUP("max-elements", "10", "20"); |
| 1517 | TEST_DUP("min-elements", "10", "20"); |
| 1518 | TEST_DUP("ordered-by", "user", "system"); |
| 1519 | TEST_DUP("reference", "1", "2"); |
| 1520 | TEST_DUP("status", "current", "obsolete"); |
| 1521 | TEST_DUP("type", "int8", "uint8"); |
| 1522 | TEST_DUP("units", "text1", "text2"); |
| 1523 | TEST_DUP("when", "true", "false"); |
| 1524 | #undef TEST_DUP |
| 1525 | |
| 1526 | /* full content - without min-elements which is mutual exclusive with default */ |
| 1527 | str = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;" |
| 1528 | "max-elements 10;must 'expr';ordered-by user;reference test;" |
| 1529 | "status current;type string; units zzz;when true;m:ext;} ..."; |
| 1530 | assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1531 | assert_non_null(ll); |
| 1532 | assert_int_equal(LYS_LEAFLIST, ll->nodetype); |
| 1533 | assert_string_equal("ll", ll->name); |
| 1534 | assert_string_equal("test", ll->dsc); |
| 1535 | assert_non_null(ll->dflts); |
| 1536 | assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts)); |
| 1537 | assert_string_equal("xxx", ll->dflts[0]); |
| 1538 | assert_string_equal("yyy", ll->dflts[1]); |
| 1539 | assert_string_equal("zzz", ll->units); |
| 1540 | assert_int_equal(10, ll->max); |
| 1541 | assert_int_equal(0, ll->min); |
| 1542 | assert_string_equal("string", ll->type.name); |
| 1543 | assert_non_null(ll->exts); |
| 1544 | assert_non_null(ll->iffeatures); |
| 1545 | assert_non_null(ll->musts); |
| 1546 | assert_string_equal("test", ll->ref); |
| 1547 | assert_non_null(ll->when); |
| 1548 | assert_null(ll->parent); |
| 1549 | assert_null(ll->next); |
| 1550 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags); |
| 1551 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1552 | |
| 1553 | /* full content - now with min-elements */ |
| 1554 | str = "ll {min-elements 10; type string;} ..."; |
| 1555 | assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1556 | assert_non_null(ll); |
| 1557 | assert_int_equal(LYS_LEAFLIST, ll->nodetype); |
| 1558 | assert_string_equal("ll", ll->name); |
| 1559 | assert_string_equal("string", ll->type.name); |
| 1560 | assert_int_equal(0, ll->max); |
| 1561 | assert_int_equal(10, ll->min); |
| 1562 | assert_int_equal(LYS_SET_MIN, ll->flags); |
| 1563 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1564 | |
| 1565 | /* invalid */ |
| 1566 | str = " ll {min-elements 1; default xx; type string;} ..."; |
| 1567 | 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] | 1568 | 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] | 1569 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1570 | |
| 1571 | str = " ll {description \"missing type\";} ..."; |
| 1572 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1573 | logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1."); |
| 1574 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1575 | |
Radek Krejci | df6cad1 | 2018-11-28 17:10:55 +0100 | [diff] [blame] | 1576 | str = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */ |
| 1577 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1578 | logbuf_assert("Invalid combination of min-elements and max-elements: min value 10 is bigger than the max value 1. Line number 1."); |
| 1579 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1580 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1581 | ctx.mod_version = 1; /* simulate YANG 1.0 - default statement is not allowed */ |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1582 | str = " ll {default xx; type string;} ..."; |
| 1583 | assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); |
| 1584 | logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 1585 | lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL; |
| 1586 | |
| 1587 | *state = NULL; |
| 1588 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1589 | } |
| 1590 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1591 | static void |
| 1592 | test_list(void **state) |
| 1593 | { |
| 1594 | *state = test_list; |
| 1595 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1596 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1597 | struct lysp_node_list *l = NULL; |
| 1598 | const char *str; |
| 1599 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1600 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1601 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1602 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1603 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1604 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1605 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1606 | |
| 1607 | /* invalid cardinality */ |
| 1608 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1609 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1610 | assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); \ |
| 1611 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1612 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1613 | |
| 1614 | TEST_DUP("config", "true", "false"); |
| 1615 | TEST_DUP("description", "text1", "text2"); |
| 1616 | TEST_DUP("key", "one", "two"); |
| 1617 | TEST_DUP("max-elements", "10", "20"); |
| 1618 | TEST_DUP("min-elements", "10", "20"); |
| 1619 | TEST_DUP("ordered-by", "user", "system"); |
| 1620 | TEST_DUP("reference", "1", "2"); |
| 1621 | TEST_DUP("status", "current", "obsolete"); |
| 1622 | TEST_DUP("when", "true", "false"); |
| 1623 | #undef TEST_DUP |
| 1624 | |
| 1625 | /* full content */ |
| 1626 | 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;}" |
| 1627 | "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;" |
| 1628 | "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ..."; |
| 1629 | assert_int_equal(LY_SUCCESS, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1630 | assert_non_null(l); |
| 1631 | assert_int_equal(LYS_LIST, l->nodetype); |
| 1632 | assert_string_equal("l", l->name); |
| 1633 | assert_string_equal("test", l->dsc); |
| 1634 | assert_string_equal("l", l->key); |
| 1635 | assert_non_null(l->uniques); |
| 1636 | assert_int_equal(2, LY_ARRAY_SIZE(l->uniques)); |
| 1637 | assert_string_equal("xxx", l->uniques[0]); |
| 1638 | assert_string_equal("yyy", l->uniques[1]); |
| 1639 | assert_int_equal(10, l->max); |
| 1640 | assert_int_equal(1, l->min); |
| 1641 | assert_non_null(l->exts); |
| 1642 | assert_non_null(l->iffeatures); |
| 1643 | assert_non_null(l->musts); |
| 1644 | assert_string_equal("test", l->ref); |
| 1645 | assert_non_null(l->when); |
| 1646 | assert_null(l->parent); |
| 1647 | assert_null(l->next); |
| 1648 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, l->flags); |
| 1649 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
| 1650 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1651 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1652 | /* invalid content */ |
| 1653 | ctx.mod_version = 1; /* simulate YANG 1.0 */ |
| 1654 | str = "l {action x;} ..."; |
| 1655 | assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); |
| 1656 | logbuf_assert("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 1657 | lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL; |
| 1658 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1659 | *state = NULL; |
| 1660 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1661 | } |
| 1662 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1663 | static void |
| 1664 | test_choice(void **state) |
| 1665 | { |
| 1666 | *state = test_choice; |
| 1667 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1668 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1669 | struct lysp_node_choice *ch = NULL; |
| 1670 | const char *str; |
| 1671 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1672 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1673 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1674 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1675 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1676 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1677 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1678 | |
| 1679 | /* invalid cardinality */ |
| 1680 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1681 | str = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1682 | assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); \ |
| 1683 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1684 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1685 | |
| 1686 | TEST_DUP("config", "true", "false"); |
| 1687 | TEST_DUP("default", "a", "b"); |
| 1688 | TEST_DUP("description", "text1", "text2"); |
| 1689 | TEST_DUP("mandatory", "true", "false"); |
| 1690 | TEST_DUP("reference", "1", "2"); |
| 1691 | TEST_DUP("status", "current", "obsolete"); |
| 1692 | TEST_DUP("when", "true", "false"); |
| 1693 | #undef TEST_DUP |
| 1694 | |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1695 | /* full content - without default due to a collision with mandatory */ |
| 1696 | 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] | 1697 | "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ..."; |
| 1698 | assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); |
| 1699 | assert_non_null(ch); |
| 1700 | assert_int_equal(LYS_CHOICE, ch->nodetype); |
| 1701 | assert_string_equal("ch", ch->name); |
| 1702 | assert_string_equal("test", ch->dsc); |
| 1703 | assert_non_null(ch->exts); |
| 1704 | assert_non_null(ch->iffeatures); |
| 1705 | assert_string_equal("test", ch->ref); |
| 1706 | assert_non_null(ch->when); |
| 1707 | assert_null(ch->parent); |
| 1708 | assert_null(ch->next); |
| 1709 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags); |
| 1710 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1711 | |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1712 | /* full content - the default missing from the previous node */ |
| 1713 | str = "ch {default c;case c;} ..."; |
| 1714 | assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); |
| 1715 | assert_non_null(ch); |
| 1716 | assert_int_equal(LYS_CHOICE, ch->nodetype); |
| 1717 | assert_string_equal("ch", ch->name); |
| 1718 | assert_string_equal("c", ch->dflt); |
| 1719 | assert_int_equal(0, ch->flags); |
| 1720 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1721 | |
| 1722 | /* invalid content */ |
| 1723 | str = "ch {mandatory true; default c1; case c1 {leaf x{type string;}}} ..."; |
| 1724 | assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); |
| 1725 | logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"choice\". Line number 1."); |
| 1726 | lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL; |
| 1727 | |
| 1728 | *state = NULL; |
| 1729 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1730 | } |
| 1731 | |
| 1732 | static void |
| 1733 | test_case(void **state) |
| 1734 | { |
| 1735 | *state = test_case; |
| 1736 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1737 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1738 | struct lysp_node_case *cs = NULL; |
| 1739 | const char *str; |
| 1740 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1741 | ctx.format = LYS_IN_YANG; |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1742 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1743 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1744 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1745 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1746 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 1747 | |
| 1748 | /* invalid cardinality */ |
| 1749 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1750 | str = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1751 | assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); \ |
| 1752 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1753 | lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL; |
| 1754 | |
| 1755 | TEST_DUP("description", "text1", "text2"); |
| 1756 | TEST_DUP("reference", "1", "2"); |
| 1757 | TEST_DUP("status", "current", "obsolete"); |
| 1758 | TEST_DUP("when", "true", "false"); |
| 1759 | #undef TEST_DUP |
| 1760 | |
| 1761 | /* full content */ |
| 1762 | str = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}" |
| 1763 | "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ..."; |
| 1764 | assert_int_equal(LY_SUCCESS, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); |
| 1765 | assert_non_null(cs); |
| 1766 | assert_int_equal(LYS_CASE, cs->nodetype); |
| 1767 | assert_string_equal("cs", cs->name); |
| 1768 | assert_string_equal("test", cs->dsc); |
| 1769 | assert_non_null(cs->exts); |
| 1770 | assert_non_null(cs->iffeatures); |
| 1771 | assert_string_equal("test", cs->ref); |
| 1772 | assert_non_null(cs->when); |
| 1773 | assert_null(cs->parent); |
| 1774 | assert_null(cs->next); |
| 1775 | assert_int_equal(LYS_STATUS_CURR, cs->flags); |
| 1776 | lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL; |
| 1777 | |
| 1778 | /* invalid content */ |
| 1779 | str = "cs {config true} ..."; |
| 1780 | assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); |
| 1781 | logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1."); |
| 1782 | lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL; |
| 1783 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1784 | *state = NULL; |
| 1785 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1786 | } |
| 1787 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1788 | static void |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1789 | test_any(void **state, enum ly_stmt kw) |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1790 | { |
| 1791 | *state = test_any; |
| 1792 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1793 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1794 | struct lysp_node_anydata *any = NULL; |
| 1795 | const char *str; |
| 1796 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1797 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1798 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1799 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1800 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1801 | ctx.line = 1; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1802 | if (kw == LY_STMT_ANYDATA) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1803 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1804 | } else { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1805 | ctx.mod_version = 1; /* simulate YANG 1.0 */ |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | /* invalid cardinality */ |
| 1809 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1810 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1811 | assert_int_equal(LY_EVALID, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); \ |
| 1812 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1813 | lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL; |
| 1814 | |
| 1815 | TEST_DUP("config", "true", "false"); |
| 1816 | TEST_DUP("description", "text1", "text2"); |
| 1817 | TEST_DUP("mandatory", "true", "false"); |
| 1818 | TEST_DUP("reference", "1", "2"); |
| 1819 | TEST_DUP("status", "current", "obsolete"); |
| 1820 | TEST_DUP("when", "true", "false"); |
| 1821 | #undef TEST_DUP |
| 1822 | |
| 1823 | /* full content */ |
| 1824 | str = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ..."; |
| 1825 | assert_int_equal(LY_SUCCESS, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); |
| 1826 | assert_non_null(any); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1827 | assert_int_equal(kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1828 | assert_string_equal("any", any->name); |
| 1829 | assert_string_equal("test", any->dsc); |
| 1830 | assert_non_null(any->exts); |
| 1831 | assert_non_null(any->iffeatures); |
| 1832 | assert_non_null(any->musts); |
| 1833 | assert_string_equal("test", any->ref); |
| 1834 | assert_non_null(any->when); |
| 1835 | assert_null(any->parent); |
| 1836 | assert_null(any->next); |
| 1837 | assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags); |
| 1838 | lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL; |
| 1839 | |
| 1840 | *state = NULL; |
| 1841 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1842 | } |
| 1843 | |
| 1844 | static void |
| 1845 | test_anydata(void **state) |
| 1846 | { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1847 | return test_any(state, LY_STMT_ANYDATA); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | static void |
| 1851 | test_anyxml(void **state) |
| 1852 | { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1853 | return test_any(state, LY_STMT_ANYXML); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1854 | } |
| 1855 | |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 1856 | static void |
| 1857 | test_grouping(void **state) |
| 1858 | { |
| 1859 | *state = test_grouping; |
| 1860 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1861 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 1862 | struct lysp_grp *grp = NULL; |
| 1863 | const char *str; |
| 1864 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1865 | ctx.format = LYS_IN_YANG; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 1866 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1867 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1868 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 1869 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1870 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 1871 | |
| 1872 | /* invalid cardinality */ |
| 1873 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1874 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1875 | assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); \ |
| 1876 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1877 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1878 | |
| 1879 | TEST_DUP("description", "text1", "text2"); |
| 1880 | TEST_DUP("reference", "1", "2"); |
| 1881 | TEST_DUP("status", "current", "obsolete"); |
| 1882 | #undef TEST_DUP |
| 1883 | |
| 1884 | /* full content */ |
| 1885 | str = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}" |
| 1886 | "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ..."; |
| 1887 | assert_int_equal(LY_SUCCESS, parse_grouping(&ctx, &str, NULL, &grp)); |
| 1888 | assert_non_null(grp); |
| 1889 | assert_int_equal(LYS_GROUPING, grp->nodetype); |
| 1890 | assert_string_equal("grp", grp->name); |
| 1891 | assert_string_equal("test", grp->dsc); |
| 1892 | assert_non_null(grp->exts); |
| 1893 | assert_string_equal("test", grp->ref); |
| 1894 | assert_null(grp->parent); |
| 1895 | assert_int_equal( LYS_STATUS_CURR, grp->flags); |
| 1896 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
| 1897 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1898 | |
| 1899 | /* invalid content */ |
| 1900 | str = "grp {config true} ..."; |
| 1901 | assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); |
| 1902 | logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1."); |
| 1903 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1904 | |
| 1905 | str = "grp {must 'expr'} ..."; |
| 1906 | assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); |
| 1907 | logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1."); |
| 1908 | FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL; |
| 1909 | |
| 1910 | *state = NULL; |
| 1911 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1912 | } |
| 1913 | |
| 1914 | static void |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1915 | test_action(void **state) |
| 1916 | { |
| 1917 | *state = test_action; |
| 1918 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1919 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1920 | struct lysp_action *rpcs = NULL; |
| 1921 | struct lysp_node_container *c = NULL; |
| 1922 | const char *str; |
| 1923 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1924 | ctx.format = LYS_IN_YANG; |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1925 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 1926 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 1927 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1928 | ctx.line = 1; |
| 1929 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
| 1930 | |
| 1931 | /* invalid cardinality */ |
| 1932 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 1933 | str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 1934 | assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs)); \ |
| 1935 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 1936 | FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL; |
| 1937 | |
| 1938 | TEST_DUP("description", "text1", "text2"); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 1939 | TEST_DUP("input", "{leaf l1 {type empty;}} description a", "{leaf l2 {type empty;}} description a"); |
| 1940 | TEST_DUP("output", "{leaf l1 {type empty;}} description a", "{leaf l2 {type empty;}} description a"); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1941 | TEST_DUP("reference", "1", "2"); |
| 1942 | TEST_DUP("status", "current", "obsolete"); |
| 1943 | #undef TEST_DUP |
| 1944 | |
| 1945 | /* full content */ |
| 1946 | str = "top;"; |
| 1947 | assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 1948 | str = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;" |
| 1949 | "input {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}" |
| 1950 | " list li; must 1; typedef mytypei {type int8;} uses grp; m:ext;}" |
| 1951 | "output {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}" |
| 1952 | " list li; must 1; typedef mytypeo {type int8;} uses grp; m:ext;}} ..."; |
| 1953 | assert_int_equal(LY_SUCCESS, parse_action(&ctx, &str, (struct lysp_node*)c, &rpcs)); |
| 1954 | assert_non_null(rpcs); |
| 1955 | assert_int_equal(LYS_ACTION, rpcs->nodetype); |
| 1956 | assert_string_equal("func", rpcs->name); |
| 1957 | assert_string_equal("test", rpcs->dsc); |
| 1958 | assert_non_null(rpcs->exts); |
| 1959 | assert_non_null(rpcs->iffeatures); |
| 1960 | assert_string_equal("test", rpcs->ref); |
| 1961 | assert_non_null(rpcs->groupings); |
| 1962 | assert_non_null(rpcs->typedefs); |
| 1963 | assert_int_equal(LYS_STATUS_CURR, rpcs->flags); |
| 1964 | /* input */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1965 | assert_int_equal(rpcs->input.nodetype, LYS_INPUT); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1966 | assert_non_null(rpcs->input.groupings); |
| 1967 | assert_non_null(rpcs->input.exts); |
| 1968 | assert_non_null(rpcs->input.musts); |
| 1969 | assert_non_null(rpcs->input.typedefs); |
| 1970 | assert_non_null(rpcs->input.data); |
| 1971 | /* output */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1972 | assert_int_equal(rpcs->output.nodetype, LYS_OUTPUT); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1973 | assert_non_null(rpcs->output.groupings); |
| 1974 | assert_non_null(rpcs->output.exts); |
| 1975 | assert_non_null(rpcs->output.musts); |
| 1976 | assert_non_null(rpcs->output.typedefs); |
| 1977 | assert_non_null(rpcs->output.data); |
| 1978 | |
| 1979 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
| 1980 | FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL; |
| 1981 | |
| 1982 | /* invalid content */ |
| 1983 | str = "func {config true} ..."; |
| 1984 | assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs)); |
| 1985 | logbuf_assert("Invalid keyword \"config\" as a child of \"rpc\". Line number 1."); |
| 1986 | FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL; |
| 1987 | |
| 1988 | *state = NULL; |
| 1989 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); |
| 1990 | ly_ctx_destroy(ctx.ctx, NULL); |
| 1991 | } |
| 1992 | |
| 1993 | static void |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 1994 | test_notification(void **state) |
| 1995 | { |
| 1996 | *state = test_notification; |
| 1997 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1998 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 1999 | struct lysp_notif *notifs = NULL; |
| 2000 | struct lysp_node_container *c = NULL; |
| 2001 | const char *str; |
| 2002 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2003 | ctx.format = LYS_IN_YANG; |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 2004 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 2005 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 2006 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 2007 | ctx.line = 1; |
| 2008 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
| 2009 | |
| 2010 | /* invalid cardinality */ |
| 2011 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 2012 | str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 2013 | assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, ¬ifs)); \ |
| 2014 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 2015 | FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL; |
| 2016 | |
| 2017 | TEST_DUP("description", "text1", "text2"); |
| 2018 | TEST_DUP("reference", "1", "2"); |
| 2019 | TEST_DUP("status", "current", "obsolete"); |
| 2020 | #undef TEST_DUP |
| 2021 | |
| 2022 | /* full content */ |
| 2023 | str = "top;"; |
| 2024 | assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); |
| 2025 | str = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}" |
| 2026 | "leaf-list ll {type int8;} list li; must 1; reference test; status current; typedef mytype {type int8;} uses grp; m:ext;}"; |
| 2027 | assert_int_equal(LY_SUCCESS, parse_notif(&ctx, &str, (struct lysp_node*)c, ¬ifs)); |
| 2028 | assert_non_null(notifs); |
| 2029 | assert_int_equal(LYS_NOTIF, notifs->nodetype); |
| 2030 | assert_string_equal("ntf", notifs->name); |
| 2031 | assert_string_equal("test", notifs->dsc); |
| 2032 | assert_non_null(notifs->exts); |
| 2033 | assert_non_null(notifs->iffeatures); |
| 2034 | assert_string_equal("test", notifs->ref); |
| 2035 | assert_non_null(notifs->groupings); |
| 2036 | assert_non_null(notifs->typedefs); |
| 2037 | assert_non_null(notifs->musts); |
| 2038 | assert_non_null(notifs->data); |
| 2039 | assert_int_equal(LYS_STATUS_CURR, notifs->flags); |
| 2040 | |
| 2041 | ly_set_erase(&ctx.tpdfs_nodes, NULL); |
| 2042 | FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL; |
| 2043 | |
| 2044 | /* invalid content */ |
| 2045 | str = "ntf {config true} ..."; |
| 2046 | assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, ¬ifs)); |
| 2047 | logbuf_assert("Invalid keyword \"config\" as a child of \"notification\". Line number 1."); |
| 2048 | FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL; |
| 2049 | |
| 2050 | *state = NULL; |
| 2051 | lysp_node_free(ctx.ctx, (struct lysp_node*)c); |
| 2052 | ly_ctx_destroy(ctx.ctx, NULL); |
| 2053 | } |
| 2054 | |
| 2055 | static void |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2056 | test_uses(void **state) |
| 2057 | { |
| 2058 | *state = test_uses; |
| 2059 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2060 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2061 | struct lysp_node_uses *u = NULL; |
| 2062 | const char *str; |
| 2063 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2064 | ctx.format = LYS_IN_YANG; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2065 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 2066 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 2067 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2068 | ctx.line = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 2069 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2070 | |
| 2071 | /* invalid cardinality */ |
| 2072 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 2073 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 2074 | assert_int_equal(LY_EVALID, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); \ |
| 2075 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 2076 | lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL; |
| 2077 | |
| 2078 | TEST_DUP("description", "text1", "text2"); |
| 2079 | TEST_DUP("reference", "1", "2"); |
| 2080 | TEST_DUP("status", "current", "obsolete"); |
| 2081 | TEST_DUP("when", "true", "false"); |
| 2082 | #undef TEST_DUP |
| 2083 | |
| 2084 | /* full content */ |
| 2085 | str = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ..."; |
| 2086 | assert_int_equal(LY_SUCCESS, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); |
| 2087 | assert_non_null(u); |
| 2088 | assert_int_equal(LYS_USES, u->nodetype); |
| 2089 | assert_string_equal("grpref", u->name); |
| 2090 | assert_string_equal("test", u->dsc); |
| 2091 | assert_non_null(u->exts); |
| 2092 | assert_non_null(u->iffeatures); |
| 2093 | assert_string_equal("test", u->ref); |
| 2094 | assert_non_null(u->augments); |
| 2095 | assert_non_null(u->refines); |
| 2096 | assert_non_null(u->when); |
| 2097 | assert_null(u->parent); |
| 2098 | assert_null(u->next); |
| 2099 | assert_int_equal(LYS_STATUS_CURR, u->flags); |
| 2100 | lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL; |
| 2101 | |
| 2102 | *state = NULL; |
| 2103 | ly_ctx_destroy(ctx.ctx, NULL); |
| 2104 | } |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2105 | |
| 2106 | |
| 2107 | static void |
| 2108 | test_augment(void **state) |
| 2109 | { |
| 2110 | *state = test_augment; |
| 2111 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2112 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2113 | struct lysp_augment *a = NULL; |
| 2114 | const char *str; |
| 2115 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2116 | ctx.format = LYS_IN_YANG; |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2117 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 2118 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 2119 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2120 | ctx.line = 1; |
Radek Krejci | b4adbf1 | 2019-02-25 13:35:22 +0100 | [diff] [blame] | 2121 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2122 | |
| 2123 | /* invalid cardinality */ |
| 2124 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 2125 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 2126 | assert_int_equal(LY_EVALID, parse_augment(&ctx, &str, NULL, &a)); \ |
| 2127 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
Radek Krejci | b4adbf1 | 2019-02-25 13:35:22 +0100 | [diff] [blame] | 2128 | FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL; |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2129 | |
| 2130 | TEST_DUP("description", "text1", "text2"); |
| 2131 | TEST_DUP("reference", "1", "2"); |
| 2132 | TEST_DUP("status", "current", "obsolete"); |
| 2133 | TEST_DUP("when", "true", "false"); |
| 2134 | #undef TEST_DUP |
| 2135 | |
| 2136 | /* full content */ |
| 2137 | str = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}" |
| 2138 | "leaf-list ll {type string;} list li;notification not;reference test;status current;uses g;when true;m:ext;} ..."; |
| 2139 | assert_int_equal(LY_SUCCESS, parse_augment(&ctx, &str, NULL, &a)); |
| 2140 | assert_non_null(a); |
| 2141 | assert_int_equal(LYS_AUGMENT, a->nodetype); |
| 2142 | assert_string_equal("/target/nodeid", a->nodeid); |
| 2143 | assert_string_equal("test", a->dsc); |
| 2144 | assert_non_null(a->exts); |
| 2145 | assert_non_null(a->iffeatures); |
| 2146 | assert_string_equal("test", a->ref); |
| 2147 | assert_non_null(a->when); |
| 2148 | assert_null(a->parent); |
| 2149 | assert_int_equal(LYS_STATUS_CURR, a->flags); |
Radek Krejci | b4adbf1 | 2019-02-25 13:35:22 +0100 | [diff] [blame] | 2150 | FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL; |
Radek Krejci | 5a7c4a5 | 2019-02-12 15:45:11 +0100 | [diff] [blame] | 2151 | |
| 2152 | *state = NULL; |
| 2153 | ly_ctx_destroy(ctx.ctx, NULL); |
| 2154 | } |
| 2155 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 2156 | static void |
| 2157 | test_when(void **state) |
| 2158 | { |
| 2159 | *state = test_when; |
| 2160 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2161 | struct lys_yang_parser_ctx ctx = {0}; |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 2162 | struct lysp_when *w = NULL; |
| 2163 | const char *str; |
| 2164 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2165 | ctx.format = LYS_IN_YANG; |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 2166 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 2167 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 2168 | ctx.pos_type = LY_VLOG_LINE; |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 2169 | ctx.line = 1; |
| 2170 | ctx.mod_version = 2; /* simulate YANG 1.1 */ |
| 2171 | |
| 2172 | /* invalid cardinality */ |
| 2173 | #define TEST_DUP(MEMBER, VALUE1, VALUE2) \ |
| 2174 | str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 2175 | assert_int_equal(LY_EVALID, parse_when(&ctx, &str, &w)); \ |
| 2176 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \ |
| 2177 | FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL; |
| 2178 | |
| 2179 | TEST_DUP("description", "text1", "text2"); |
| 2180 | TEST_DUP("reference", "1", "2"); |
| 2181 | #undef TEST_DUP |
| 2182 | |
| 2183 | /* full content */ |
| 2184 | str = "expression {description test;reference test;m:ext;} ..."; |
| 2185 | assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w)); |
| 2186 | assert_non_null(w); |
| 2187 | assert_string_equal("expression", w->cond); |
| 2188 | assert_string_equal("test", w->dsc); |
| 2189 | assert_string_equal("test", w->ref); |
| 2190 | assert_non_null(w->exts); |
| 2191 | FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL; |
| 2192 | |
| 2193 | /* empty condition */ |
| 2194 | str = "\"\";"; |
| 2195 | assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w)); |
| 2196 | logbuf_assert("Empty argument of when statement does not make sense."); |
| 2197 | assert_non_null(w); |
| 2198 | assert_string_equal("", w->cond); |
| 2199 | FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL; |
| 2200 | |
| 2201 | *state = NULL; |
| 2202 | ly_ctx_destroy(ctx.ctx, NULL); |
| 2203 | } |
| 2204 | |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2205 | static void |
| 2206 | test_value(void **state) |
| 2207 | { |
| 2208 | *state = test_value; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2209 | struct lys_yang_parser_ctx ctx; |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2210 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2211 | ctx.format = LYS_IN_YANG; |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2212 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 2213 | assert_non_null(ctx.ctx); |
Radek Krejci | 9943524 | 2019-09-05 16:19:15 +0200 | [diff] [blame] | 2214 | ctx.pos_type = LY_VLOG_LINE; |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2215 | ctx.line = 1; |
| 2216 | ctx.indent = 0; |
| 2217 | int64_t val = 0; |
| 2218 | uint16_t flags = 0; |
| 2219 | |
| 2220 | const char *data = "-0;"; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2221 | assert_int_equal(parse_type_enum_value_pos(&ctx, &data, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS); |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2222 | assert_int_equal(val, 0); |
| 2223 | |
| 2224 | data = "-0;"; |
| 2225 | flags = 0; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2226 | assert_int_equal(parse_type_enum_value_pos(&ctx, &data, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID); |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2227 | logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1."); |
| 2228 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2229 | *state = NULL; |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2230 | ly_ctx_destroy(ctx.ctx, NULL); |
| 2231 | } |
| 2232 | |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 2233 | int main(void) |
| 2234 | { |
| 2235 | const struct CMUnitTest tests[] = { |
Radek Krejci | 44ceedc | 2018-10-02 15:54:31 +0200 | [diff] [blame] | 2236 | cmocka_unit_test_setup(test_helpers, logger_setup), |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 2237 | cmocka_unit_test_setup(test_comments, logger_setup), |
Radek Krejci | efd22f6 | 2018-09-27 11:47:58 +0200 | [diff] [blame] | 2238 | cmocka_unit_test_setup(test_arg, logger_setup), |
Radek Krejci | dcc7b32 | 2018-10-11 14:24:02 +0200 | [diff] [blame] | 2239 | cmocka_unit_test_setup(test_stmts, logger_setup), |
Radek Krejci | 05b1398 | 2018-11-28 16:22:07 +0100 | [diff] [blame] | 2240 | cmocka_unit_test_setup_teardown(test_minmax, logger_setup, logger_teardown), |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 2241 | cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown), |
Radek Krejci | 2c02f3e | 2018-10-16 10:54:38 +0200 | [diff] [blame] | 2242 | cmocka_unit_test_setup(test_deviation, logger_setup), |
| 2243 | cmocka_unit_test_setup(test_deviate, logger_setup), |
Radek Krejci | 8c37083 | 2018-11-02 15:10:03 +0100 | [diff] [blame] | 2244 | cmocka_unit_test_setup(test_container, logger_setup), |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 2245 | cmocka_unit_test_setup_teardown(test_leaf, logger_setup, logger_teardown), |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 2246 | cmocka_unit_test_setup_teardown(test_leaflist, logger_setup, logger_teardown), |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 2247 | cmocka_unit_test_setup_teardown(test_list, logger_setup, logger_teardown), |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 2248 | cmocka_unit_test_setup_teardown(test_choice, logger_setup, logger_teardown), |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 2249 | cmocka_unit_test_setup_teardown(test_case, logger_setup, logger_teardown), |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 2250 | cmocka_unit_test_setup_teardown(test_anydata, logger_setup, logger_teardown), |
| 2251 | cmocka_unit_test_setup_teardown(test_anyxml, logger_setup, logger_teardown), |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2252 | cmocka_unit_test_setup_teardown(test_action, logger_setup, logger_teardown), |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 2253 | cmocka_unit_test_setup_teardown(test_notification, logger_setup, logger_teardown), |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2254 | cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown), |
| 2255 | cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown), |
Radek Krejci | b4adbf1 | 2019-02-25 13:35:22 +0100 | [diff] [blame] | 2256 | cmocka_unit_test_setup_teardown(test_augment, logger_setup, logger_teardown), |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 2257 | cmocka_unit_test_setup_teardown(test_when, logger_setup, logger_teardown), |
David Sedlák | d6ce6d7 | 2019-07-16 17:30:18 +0200 | [diff] [blame] | 2258 | cmocka_unit_test_setup_teardown(test_value, logger_setup, logger_teardown), |
Radek Krejci | 80dd33e | 2018-09-26 15:57:18 +0200 | [diff] [blame] | 2259 | }; |
| 2260 | |
| 2261 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 2262 | } |