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