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