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