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