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