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