David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 1 | /** |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 2 | * @file test_yin.c |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 3 | * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz> |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 5 | * @brief unit tests for YIN parser and printer |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 6 | * |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 15 | #define _UTEST_MAIN_ |
| 16 | #include "utests.h" |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 17 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 18 | #include <stdbool.h> |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <string.h> |
| 21 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 22 | #include "common.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 23 | #include "in.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 24 | #include "parser_internal.h" |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 25 | #include "schema_compile.h" |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 26 | #include "tree.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 27 | #include "tree_edit.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 28 | #include "tree_schema.h" |
| 29 | #include "tree_schema_internal.h" |
| 30 | #include "xml.h" |
| 31 | #include "xpath.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 32 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 33 | /* copied from parser_yin.c */ |
| 34 | enum yin_argument { |
| 35 | YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */ |
| 36 | YIN_ARG_NAME, /**< argument name */ |
| 37 | YIN_ARG_TARGET_NODE, /**< argument target-node */ |
| 38 | YIN_ARG_MODULE, /**< argument module */ |
| 39 | YIN_ARG_VALUE, /**< argument value */ |
| 40 | YIN_ARG_TEXT, /**< argument text */ |
| 41 | YIN_ARG_CONDITION, /**< argument condition */ |
| 42 | YIN_ARG_URI, /**< argument uri */ |
| 43 | YIN_ARG_DATE, /**< argument data */ |
| 44 | YIN_ARG_TAG, /**< argument tag */ |
| 45 | YIN_ARG_NONE /**< empty (special value) */ |
| 46 | }; |
| 47 | |
| 48 | struct yin_subelement { |
| 49 | enum ly_stmt type; /**< type of keyword */ |
| 50 | void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */ |
| 51 | uint16_t flags; /**< describes constraints of subelement can be set to YIN_SUBELEM_MANDATORY, YIN_SUBELEM_UNIQUE, YIN_SUBELEM_FIRST, YIN_SUBELEM_VER2, and YIN_SUBELEM_DEFAULT_TEXT */ |
| 52 | }; |
| 53 | |
| 54 | struct import_meta { |
| 55 | const char *prefix; /**< module prefix. */ |
| 56 | struct lysp_import **imports; /**< imports to add to. */ |
| 57 | }; |
| 58 | |
| 59 | struct yin_argument_meta { |
| 60 | uint16_t *flags; /**< Argument flags */ |
| 61 | const char **argument; /**< Argument value */ |
| 62 | }; |
| 63 | |
| 64 | struct tree_node_meta { |
| 65 | struct lysp_node *parent; /**< parent node */ |
| 66 | struct lysp_node **nodes; /**< linked list of siblings */ |
| 67 | }; |
| 68 | |
| 69 | struct include_meta { |
| 70 | const char *name; /**< Module/submodule name. */ |
| 71 | struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */ |
| 72 | }; |
| 73 | |
| 74 | struct inout_meta { |
| 75 | struct lysp_node *parent; /**< Parent node. */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 76 | struct lysp_node_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct minmax_dev_meta { |
| 80 | uint32_t *lim; /**< min/max value to write to. */ |
| 81 | uint16_t *flags; /**< min/max flags to write to. */ |
| 82 | struct lysp_ext_instance **exts; /**< extension instances to add to. */ |
| 83 | }; |
| 84 | |
| 85 | #define YIN_SUBELEM_MANDATORY 0x01 |
| 86 | #define YIN_SUBELEM_UNIQUE 0x02 |
| 87 | #define YIN_SUBELEM_FIRST 0x04 |
| 88 | #define YIN_SUBELEM_VER2 0x08 |
| 89 | |
| 90 | #define YIN_SUBELEM_PARSED 0x80 |
| 91 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 92 | /* prototypes of static functions */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 93 | enum yin_argument yin_match_argument_name(const char *name, size_t len); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 94 | LY_ERR yin_parse_content(struct lysp_yin_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 95 | const void *parent, enum ly_stmt parent_stmt, const char **text_content, struct lysp_ext_instance **exts); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 96 | LY_ERR yin_validate_value(struct lysp_yin_ctx *ctx, enum yang_arg val_type); |
| 97 | enum ly_stmt yin_match_keyword(struct lysp_yin_ctx *ctx, const char *name, size_t name_len, |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 98 | const char *prefix, size_t prefix_len, enum ly_stmt parrent); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 99 | LY_ERR yin_parse_extension_instance(struct lysp_yin_ctx *ctx, const void *parent, enum ly_stmt parent_stmt, |
| 100 | LY_ARRAY_COUNT_TYPE parent_stmt_index, struct lysp_ext_instance **exts); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 101 | LY_ERR yin_parse_element_generic(struct lysp_yin_ctx *ctx, enum ly_stmt parent, struct lysp_stmt **element); |
| 102 | LY_ERR yin_parse_mod(struct lysp_yin_ctx *ctx, struct lysp_module *mod); |
| 103 | LY_ERR yin_parse_submod(struct lysp_yin_ctx *ctx, struct lysp_submodule *submod); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 104 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 105 | /* wrapping element used for mocking has nothing to do with real module structure */ |
| 106 | #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 107 | #define ELEMENT_WRAPPER_END "</status>" |
| 108 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 109 | #define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 110 | CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, INSUBSTMT, 0, "myext:c-define", LY_VALUE_XML) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 111 | |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 112 | struct lysp_yin_ctx *YCTX; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 113 | struct lysf_ctx fctx; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 114 | |
| 115 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 116 | setup_ctx(void **state) |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 117 | { |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 118 | struct lysp_module *pmod; |
| 119 | |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 120 | /* allocate parser context */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 121 | YCTX = calloc(1, sizeof(*YCTX)); |
Michal Vasko | c8806c8 | 2022-12-06 10:31:24 +0100 | [diff] [blame] | 122 | YCTX->main_ctx = (struct lysp_ctx *)YCTX; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 123 | YCTX->format = LYS_IN_YIN; |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 124 | ly_set_new(&YCTX->parsed_mods); |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 125 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 126 | /* allocate new parsed module */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 127 | pmod = calloc(1, sizeof *pmod); |
| 128 | ly_set_add(YCTX->parsed_mods, pmod, 1, NULL); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 129 | |
| 130 | /* allocate new module */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 131 | pmod->mod = calloc(1, sizeof *pmod->mod); |
| 132 | pmod->mod->ctx = UTEST_LYCTX; |
| 133 | pmod->mod->parsed = pmod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 134 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 135 | return 0; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 139 | setup(void **state) |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 140 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 141 | UTEST_SETUP; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 142 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 143 | setup_ctx(state); |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 144 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 145 | fctx.ctx = UTEST_LYCTX; |
| 146 | fctx.mod = PARSER_CUR_PMOD(YCTX)->mod; |
| 147 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 148 | return 0; |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 149 | } |
| 150 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 151 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 152 | teardown_ctx(void **UNUSED(state)) |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 153 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 154 | lys_module_free(&fctx, PARSER_CUR_PMOD(YCTX)->mod, 0); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 155 | lysp_yin_ctx_free(YCTX); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 156 | YCTX = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 157 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 158 | return 0; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 161 | static int |
| 162 | teardown(void **state) |
| 163 | { |
| 164 | teardown_ctx(state); |
| 165 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 166 | lysf_ctx_erase(&fctx); |
| 167 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 168 | UTEST_TEARDOWN; |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | #define RESET_STATE \ |
| 174 | ly_in_free(UTEST_IN, 0); \ |
| 175 | UTEST_IN = NULL; \ |
| 176 | teardown_ctx(state); \ |
| 177 | setup_ctx(state) |
| 178 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 179 | static void |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 180 | test_yin_match_keyword(void **state) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 181 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 182 | const char *prefix; |
| 183 | size_t prefix_len; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 184 | |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 185 | /* create mock yin namespace in xml context */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 186 | ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN); |
| 187 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 188 | prefix = YCTX->xmlctx->prefix; |
| 189 | prefix_len = YCTX->xmlctx->prefix_len; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 190 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 191 | assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 192 | assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 193 | assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 194 | assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA); |
| 195 | assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML); |
| 196 | assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT); |
| 197 | assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT); |
| 198 | assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE); |
| 199 | assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO); |
| 200 | assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT); |
| 201 | assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE); |
| 202 | assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE); |
| 203 | assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG); |
| 204 | assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT); |
| 205 | assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER); |
| 206 | assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT); |
| 207 | assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION); |
| 208 | assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE); |
| 209 | assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION); |
| 210 | assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM); |
| 211 | assert_int_equal(yin_match_keyword(YCTX, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG); |
| 212 | assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE); |
| 213 | assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION); |
| 214 | assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE); |
| 215 | assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS); |
| 216 | assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING); |
| 217 | assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY); |
| 218 | assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE); |
| 219 | assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT); |
| 220 | assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE); |
| 221 | assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT); |
| 222 | assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY); |
| 223 | assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF); |
| 224 | assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST); |
| 225 | assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH); |
| 226 | assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST); |
| 227 | assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY); |
| 228 | assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS); |
| 229 | assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS); |
| 230 | assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER); |
| 231 | assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE); |
| 232 | assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST); |
| 233 | assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE); |
| 234 | assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION); |
| 235 | assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY); |
| 236 | assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION); |
| 237 | assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT); |
| 238 | assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH); |
| 239 | assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN); |
| 240 | assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION); |
| 241 | assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX); |
| 242 | assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE); |
| 243 | assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE); |
| 244 | assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE); |
| 245 | assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE); |
| 246 | assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE); |
| 247 | assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION); |
| 248 | assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE); |
| 249 | assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC); |
| 250 | assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS); |
| 251 | assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE); |
| 252 | assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE); |
| 253 | assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF); |
| 254 | assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE); |
| 255 | assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS); |
| 256 | assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES); |
| 257 | assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE); |
| 258 | assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN); |
| 259 | assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION); |
| 260 | assert_int_equal(yin_match_keyword(YCTX, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 261 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 262 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 263 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 264 | test_yin_match_argument_name(void **UNUSED(state)) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 265 | { |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 266 | assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN); |
| 267 | assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN); |
| 268 | assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN); |
| 269 | assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION); |
| 270 | assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE); |
| 271 | assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE); |
| 272 | assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME); |
| 273 | assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG); |
| 274 | assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE); |
| 275 | assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT); |
| 276 | assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI); |
| 277 | assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 278 | } |
| 279 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 280 | static void |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 281 | test_yin_parse_content(void **state) |
| 282 | { |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 283 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 284 | const char *data = |
| 285 | "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 286 | " <myext:custom xmlns:myext=\"urn:example:extensions\">totally amazing extension</myext:custom>\n" |
| 287 | " <extension name=\"ext\">\n" |
| 288 | " <argument name=\"argname\"></argument>\n" |
| 289 | " <description><text>desc</text></description>\n" |
| 290 | " <reference><text>ref</text></reference>\n" |
| 291 | " <status value=\"deprecated\"></status>\n" |
| 292 | " </extension>\n" |
| 293 | " <text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>\n" |
| 294 | " <if-feature name=\"foo\"></if-feature>\n" |
| 295 | " <when condition=\"condition...\">\n" |
| 296 | " <reference><text>when_ref</text></reference>\n" |
| 297 | " <description><text>when_desc</text></description>\n" |
| 298 | " </when>\n" |
| 299 | " <config value=\"true\"/>\n" |
| 300 | " <error-message>\n" |
| 301 | " <value>error-msg</value>\n" |
| 302 | " </error-message>\n" |
| 303 | " <error-app-tag value=\"err-app-tag\"/>\n" |
| 304 | " <units name=\"radians\"></units>\n" |
| 305 | " <default value=\"default-value\"/>\n" |
| 306 | " <position value=\"25\"></position>\n" |
| 307 | " <value value=\"-5\"/>\n" |
| 308 | " <require-instance value=\"true\"></require-instance>\n" |
| 309 | " <range value=\"5..10\" />\n" |
| 310 | " <length value=\"baf\"/>\n" |
| 311 | " <pattern value='pattern'>\n" |
| 312 | " <modifier value='invert-match'/>\n" |
| 313 | " </pattern>\n" |
| 314 | " <enum name=\"yay\">\n" |
| 315 | " </enum>\n" |
| 316 | "</prefix>"; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 317 | struct lysp_ext_instance *exts = NULL; |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 318 | const char *value; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 319 | |
| 320 | /* test unique subelem */ |
| 321 | const char *prefix_value; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 322 | struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 323 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}}; |
| 324 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 325 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 326 | "<prefix value=\"inv_mod\" />" |
| 327 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 328 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 329 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 330 | ly_in_new_memory(data, &UTEST_IN); |
| 331 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 332 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 333 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 334 | ret = yin_parse_content(YCTX, subelems2, 2, NULL, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 335 | assert_int_equal(ret, LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 336 | CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1."); |
| 337 | lydict_remove(UTEST_LYCTX, prefix_value); |
| 338 | lydict_remove(UTEST_LYCTX, value); |
| 339 | RESET_STATE; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 340 | |
| 341 | /* test first subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 342 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 343 | "<prefix value=\"inv_mod\" />" |
| 344 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 345 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 346 | ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 347 | struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 348 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}}; |
| 349 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 350 | ly_in_new_memory(data, &UTEST_IN); |
| 351 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 352 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 353 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 354 | ret = yin_parse_content(YCTX, subelems3, 2, NULL, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 355 | assert_int_equal(ret, LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 356 | CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1."); |
| 357 | lydict_remove(UTEST_LYCTX, prefix_value); |
| 358 | RESET_STATE; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 359 | |
| 360 | /* test mandatory subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 361 | data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 362 | struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}}; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 363 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 364 | ly_in_new_memory(data, &UTEST_IN); |
| 365 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 366 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 367 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 368 | ret = yin_parse_content(YCTX, subelems4, 1, NULL, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 369 | assert_int_equal(ret, LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 370 | CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 371 | } |
| 372 | |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 373 | static void |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 374 | test_validate_value(void **state) |
| 375 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 376 | const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
| 377 | |
| 378 | /* create some XML context */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 379 | ly_in_new_memory(data, &UTEST_IN); |
| 380 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 381 | YCTX->xmlctx->status = LYXML_ELEM_CONTENT; |
| 382 | YCTX->xmlctx->dynamic = 0; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 383 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 384 | YCTX->xmlctx->value = "#invalid"; |
| 385 | YCTX->xmlctx->value_len = 8; |
| 386 | assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID); |
Radek Iša | 2eac74c | 2021-03-15 15:53:08 +0100 | [diff] [blame] | 387 | CHECK_LOG_CTX("Invalid identifier first character '#' (0x0023).", "Line number 1."); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 388 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 389 | YCTX->xmlctx->value = ""; |
| 390 | YCTX->xmlctx->value_len = 0; |
| 391 | assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 392 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 393 | YCTX->xmlctx->value = "pre:b"; |
| 394 | YCTX->xmlctx->value_len = 5; |
| 395 | assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID); |
| 396 | assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 397 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 398 | YCTX->xmlctx->value = "pre:pre:b"; |
| 399 | YCTX->xmlctx->value_len = 9; |
| 400 | assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 403 | static void |
| 404 | test_valid_module(void **state) |
| 405 | { |
| 406 | struct lys_module *mod; |
| 407 | char *printed; |
| 408 | const char *links_yin = |
| 409 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 410 | "<module name=\"links\"\n" |
| 411 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 412 | " xmlns:mod2=\"urn:module2\">\n" |
| 413 | " <yang-version value=\"1.1\"/>\n" |
| 414 | " <namespace uri=\"urn:module2\"/>\n" |
| 415 | " <prefix value=\"mod2\"/>\n" |
| 416 | " <identity name=\"just-another-identity\"/>\n" |
| 417 | " <grouping name=\"rgroup\">\n" |
| 418 | " <leaf name=\"rg1\">\n" |
| 419 | " <type name=\"string\"/>\n" |
| 420 | " </leaf>\n" |
| 421 | " <leaf name=\"rg2\">\n" |
| 422 | " <type name=\"string\"/>\n" |
| 423 | " </leaf>\n" |
| 424 | " </grouping>\n" |
| 425 | " <leaf name=\"one-leaf\">\n" |
| 426 | " <type name=\"string\"/>\n" |
| 427 | " </leaf>\n" |
| 428 | " <list name=\"list-for-augment\">\n" |
| 429 | " <key value=\"keyleaf\"/>\n" |
| 430 | " <leaf name=\"keyleaf\">\n" |
| 431 | " <type name=\"string\"/>\n" |
| 432 | " </leaf>\n" |
| 433 | " <leaf name=\"just-leaf\">\n" |
| 434 | " <type name=\"int32\"/>\n" |
| 435 | " </leaf>\n" |
| 436 | " </list>\n" |
| 437 | " <leaf name=\"rleaf\">\n" |
| 438 | " <type name=\"string\"/>\n" |
| 439 | " </leaf>\n" |
| 440 | " <leaf-list name=\"llist\">\n" |
| 441 | " <type name=\"string\"/>\n" |
| 442 | " <min-elements value=\"0\"/>\n" |
| 443 | " <max-elements value=\"100\"/>\n" |
| 444 | " <ordered-by value=\"user\"/>\n" |
| 445 | " </leaf-list>\n" |
| 446 | "</module>\n"; |
| 447 | const char *statements_yin = |
| 448 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 449 | "<module name=\"statements\"\n" |
| 450 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 451 | " xmlns:mod=\"urn:module\"\n" |
| 452 | " xmlns:mod2=\"urn:module2\">\n" |
| 453 | " <yang-version value=\"1.1\"/>\n" |
| 454 | " <namespace uri=\"urn:module\"/>\n" |
| 455 | " <prefix value=\"mod\"/>\n" |
| 456 | " <import module=\"links\">\n" |
| 457 | " <prefix value=\"mod2\"/>\n" |
| 458 | " </import>\n" |
| 459 | " <extension name=\"ext\"/>\n" |
| 460 | " <identity name=\"random-identity\">\n" |
| 461 | " <base name=\"mod2:just-another-identity\"/>\n" |
| 462 | " <base name=\"another-identity\"/>\n" |
| 463 | " </identity>\n" |
| 464 | " <identity name=\"another-identity\">\n" |
| 465 | " <base name=\"mod2:just-another-identity\"/>\n" |
| 466 | " </identity>\n" |
| 467 | " <typedef name=\"percent\">\n" |
| 468 | " <type name=\"uint8\">\n" |
| 469 | " <range value=\"0 .. 100\"/>\n" |
| 470 | " </type>\n" |
| 471 | " <units name=\"percent\"/>\n" |
| 472 | " </typedef>\n" |
| 473 | " <list name=\"list1\">\n" |
| 474 | " <key value=\"a\"/>\n" |
| 475 | " <leaf name=\"a\">\n" |
| 476 | " <type name=\"string\"/>\n" |
| 477 | " </leaf>\n" |
| 478 | " <leaf name=\"x\">\n" |
| 479 | " <type name=\"string\"/>\n" |
| 480 | " </leaf>\n" |
| 481 | " <leaf name=\"y\">\n" |
| 482 | " <type name=\"string\"/>\n" |
| 483 | " </leaf>\n" |
| 484 | " </list>\n" |
| 485 | " <container name=\"ice-cream-shop\">\n" |
| 486 | " <container name=\"employees\">\n" |
| 487 | " <when condition=\"/list1/x\"/>\n" |
| 488 | " <list name=\"employee\">\n" |
| 489 | " <key value=\"id\"/>\n" |
| 490 | " <unique tag=\"name\"/>\n" |
| 491 | " <config value=\"true\"/>\n" |
| 492 | " <min-elements value=\"0\">\n" |
| 493 | " <mod:ext/>\n" |
| 494 | " </min-elements>\n" |
| 495 | " <max-elements value=\"unbounded\"/>\n" |
| 496 | " <leaf name=\"id\">\n" |
| 497 | " <type name=\"uint64\"/>\n" |
| 498 | " <mandatory value=\"true\"/>\n" |
| 499 | " </leaf>\n" |
| 500 | " <leaf name=\"name\">\n" |
| 501 | " <type name=\"string\"/>\n" |
| 502 | " </leaf>\n" |
| 503 | " <leaf name=\"age\">\n" |
| 504 | " <type name=\"uint32\"/>\n" |
| 505 | " </leaf>\n" |
| 506 | " </list>\n" |
| 507 | " </container>\n" |
| 508 | " </container>\n" |
| 509 | " <container name=\"random\">\n" |
| 510 | " <grouping name=\"group\">\n" |
| 511 | " <leaf name=\"g1\">\n" |
| 512 | " <type name=\"percent\"/>\n" |
| 513 | " <mandatory value=\"false\"/>\n" |
| 514 | " </leaf>\n" |
| 515 | " <leaf name=\"g2\">\n" |
| 516 | " <type name=\"string\"/>\n" |
| 517 | " </leaf>\n" |
| 518 | " </grouping>\n" |
| 519 | " <choice name=\"switch\">\n" |
| 520 | " <case name=\"a\">\n" |
| 521 | " <leaf name=\"aleaf\">\n" |
| 522 | " <type name=\"string\"/>\n" |
| 523 | " <default value=\"aaa\"/>\n" |
| 524 | " </leaf>\n" |
| 525 | " </case>\n" |
| 526 | " <case name=\"c\">\n" |
| 527 | " <leaf name=\"cleaf\">\n" |
| 528 | " <type name=\"string\"/>\n" |
| 529 | " </leaf>\n" |
| 530 | " </case>\n" |
| 531 | " </choice>\n" |
| 532 | " <anyxml name=\"xml-data\"/>\n" |
| 533 | " <anydata name=\"any-data\"/>\n" |
| 534 | " <leaf-list name=\"leaflist\">\n" |
| 535 | " <type name=\"string\"/>\n" |
| 536 | " <min-elements value=\"0\"/>\n" |
| 537 | " <max-elements value=\"20\"/>\n" |
| 538 | " </leaf-list>\n" |
| 539 | " <uses name=\"group\"/>\n" |
| 540 | " <uses name=\"mod2:rgroup\"/>\n" |
| 541 | " <leaf name=\"lref\">\n" |
| 542 | " <type name=\"leafref\">\n" |
| 543 | " <path value=\"/mod2:one-leaf\"/>\n" |
| 544 | " </type>\n" |
| 545 | " </leaf>\n" |
| 546 | " <leaf name=\"iref\">\n" |
| 547 | " <type name=\"identityref\">\n" |
| 548 | " <base name=\"mod2:just-another-identity\"/>\n" |
| 549 | " </type>\n" |
| 550 | " </leaf>\n" |
| 551 | " </container>\n" |
| 552 | " <augment target-node=\"/random\">\n" |
| 553 | " <leaf name=\"aug-leaf\">\n" |
| 554 | " <type name=\"string\"/>\n" |
| 555 | " </leaf>\n" |
| 556 | " </augment>\n" |
| 557 | " <notification name=\"notif\"/>\n" |
| 558 | " <deviation target-node=\"/mod:ice-cream-shop/mod:employees/mod:employee/mod:age\">\n" |
| 559 | " <deviate value=\"not-supported\">\n" |
| 560 | " <mod:ext/>\n" |
| 561 | " </deviate>\n" |
| 562 | " </deviation>\n" |
| 563 | " <deviation target-node=\"/mod:list1\">\n" |
| 564 | " <deviate value=\"add\">\n" |
| 565 | " <mod:ext/>\n" |
| 566 | " <must condition=\"1\"/>\n" |
| 567 | " <must condition=\"2\"/>\n" |
| 568 | " <unique tag=\"x\"/>\n" |
| 569 | " <unique tag=\"y\"/>\n" |
| 570 | " <config value=\"true\"/>\n" |
| 571 | " <min-elements value=\"1\"/>\n" |
| 572 | " <max-elements value=\"2\"/>\n" |
| 573 | " </deviate>\n" |
| 574 | " </deviation>\n" |
| 575 | " <deviation target-node=\"/mod:ice-cream-shop/mod:employees/mod:employee\">\n" |
| 576 | " <deviate value=\"delete\">\n" |
| 577 | " <unique tag=\"name\"/>\n" |
| 578 | " </deviate>\n" |
| 579 | " </deviation>\n" |
| 580 | " <deviation target-node=\"/mod:random/mod:leaflist\">\n" |
| 581 | " <deviate value=\"replace\">\n" |
| 582 | " <type name=\"uint32\"/>\n" |
| 583 | " <min-elements value=\"10\"/>\n" |
| 584 | " <max-elements value=\"15\"/>\n" |
| 585 | " </deviate>\n" |
| 586 | " </deviation>\n" |
| 587 | "</module>\n"; |
| 588 | |
| 589 | UTEST_ADD_MODULE(links_yin, LYS_IN_YIN, NULL, NULL); |
| 590 | UTEST_ADD_MODULE(statements_yin, LYS_IN_YIN, NULL, &mod); |
| 591 | lys_print_mem(&printed, mod, LYS_OUT_YIN, 0); |
| 592 | assert_string_equal(printed, statements_yin); |
| 593 | free(printed); |
| 594 | } |
| 595 | |
| 596 | static void |
| 597 | test_print_module(void **state) |
| 598 | { |
| 599 | struct lys_module *mod; |
| 600 | |
| 601 | char *orig = malloc(8096); |
| 602 | |
| 603 | strcpy(orig, |
| 604 | "module all {\n" |
| 605 | " yang-version 1.1;\n" |
| 606 | " namespace \"urn:all\";\n" |
| 607 | " prefix all_mod;\n\n" |
| 608 | " import ietf-yang-types {\n" |
| 609 | " prefix yt;\n" |
| 610 | " revision-date 2013-07-15;\n" |
| 611 | " description\n" |
| 612 | " \"YANG types\";\n" |
| 613 | " reference\n" |
| 614 | " \"RFC reference\";\n" |
| 615 | " }\n\n" |
| 616 | " feature feat1 {\n" |
| 617 | " if-feature \"feat2\";\n" |
| 618 | " status obsolete;\n" |
| 619 | " }\n\n" |
| 620 | " feature feat2;\n" |
| 621 | " feature feat3;\n\n" |
| 622 | " identity ident2 {\n" |
| 623 | " base ident1;\n" |
| 624 | " }\n\n" |
| 625 | " identity ident1;\n\n" |
| 626 | " typedef tdef1 {\n" |
| 627 | " type tdef2 {\n" |
| 628 | " length \"3..9 | 30..40\";\n" |
| 629 | " pattern \"[ac]*\";\n" |
| 630 | " }\n" |
| 631 | " units \"none\";\n" |
| 632 | " default \"aaa\";\n" |
| 633 | " }\n\n" |
| 634 | " typedef tdef2 {\n" |
| 635 | " type string {\n" |
| 636 | " length \"2..10 | 20..50\";\n" |
| 637 | " pattern \"[ab]*\";\n" |
| 638 | " }\n" |
| 639 | " }\n\n" |
| 640 | " grouping group1 {\n" |
| 641 | " leaf leaf1 {\n" |
| 642 | " type int8;\n" |
| 643 | " }\n" |
| 644 | " }\n\n" |
| 645 | " container cont1 {\n" |
| 646 | " leaf leaf2 {\n" |
| 647 | " if-feature \"feat1\";\n" |
| 648 | " type int16;\n" |
| 649 | " status obsolete;\n" |
| 650 | " }\n\n" |
| 651 | " uses group1 {\n" |
| 652 | " if-feature \"feat2\";\n" |
| 653 | " refine \"leaf1\" {\n" |
| 654 | " if-feature \"feat3\";\n" |
| 655 | " must \"24 - 4 = number('20')\";\n" |
| 656 | " default \"25\";\n" |
| 657 | " config true;\n" |
| 658 | " mandatory false;\n" |
| 659 | " description\n" |
| 660 | " \"dsc\";\n" |
| 661 | " reference\n" |
| 662 | " \"none\";\n" |
| 663 | " }\n" |
| 664 | " }\n\n" |
| 665 | " leaf leaf3 {\n" |
| 666 | " type int32;\n" |
| 667 | " }\n\n" |
| 668 | " leaf leaf4 {\n" |
| 669 | " type int64 {\n" |
| 670 | " range \"1000 .. 50000\" {\n" |
| 671 | " error-message\n" |
| 672 | " \"Special error message.\";\n" |
| 673 | " error-app-tag \"special-tag\";\n" |
| 674 | " }\n" |
| 675 | " }\n" |
| 676 | " }\n\n" |
| 677 | " leaf leaf5 {\n" |
| 678 | " type uint8;\n" |
| 679 | " }\n\n" |
| 680 | " leaf leaf6 {\n" |
| 681 | " type uint16;\n" |
| 682 | " }\n\n" |
| 683 | " leaf leaf7 {\n" |
| 684 | " type uint32;\n" |
| 685 | " }\n\n" |
| 686 | " leaf leaf8 {\n" |
| 687 | " type uint64;\n" |
| 688 | " }\n\n" |
| 689 | " choice choic1 {\n" |
| 690 | " default \"leaf9b\";\n" |
| 691 | " leaf leaf9a {\n" |
| 692 | " type decimal64 {\n" |
| 693 | " fraction-digits 9;\n" |
| 694 | " }\n" |
| 695 | " }\n\n" |
| 696 | " leaf leaf9b {\n" |
| 697 | " type boolean;\n" |
| 698 | " default \"false\";\n" |
| 699 | " }\n" |
| 700 | " }\n\n" |
| 701 | " leaf leaf10 {\n" |
| 702 | " type boolean;\n" |
| 703 | " }\n\n"); |
| 704 | strcpy(orig + strlen(orig), |
| 705 | " leaf leaf11 {\n" |
| 706 | " type enumeration {\n" |
| 707 | " enum \"one\";\n" |
| 708 | " enum \"two\";\n" |
| 709 | " enum \"five\" {\n" |
| 710 | " value 5;\n" |
| 711 | " }\n" |
| 712 | " }\n" |
| 713 | " }\n\n" |
| 714 | " leaf leaf12 {\n" |
| 715 | " type bits {\n" |
| 716 | " bit flag0 {\n" |
| 717 | " position 0;\n" |
| 718 | " }\n" |
| 719 | " bit flag1;\n" |
| 720 | " bit flag2 {\n" |
| 721 | " position 2;\n" |
| 722 | " }\n" |
| 723 | " bit flag3 {\n" |
| 724 | " position 3;\n" |
| 725 | " }\n" |
| 726 | " }\n" |
| 727 | " default \"flag0 flag3\";\n" |
| 728 | " }\n\n" |
| 729 | " leaf leaf13 {\n" |
| 730 | " type binary;\n" |
| 731 | " }\n\n" |
| 732 | " leaf leaf14 {\n" |
| 733 | " type leafref {\n" |
| 734 | " path \"/cont1/leaf17\";\n" |
| 735 | " }\n" |
| 736 | " }\n\n" |
| 737 | " leaf leaf15 {\n" |
| 738 | " type empty;\n" |
| 739 | " }\n\n" |
| 740 | " leaf leaf16 {\n" |
| 741 | " type union {\n" |
| 742 | " type instance-identifier {\n" |
| 743 | " require-instance true;\n" |
| 744 | " }\n" |
| 745 | " type int8;\n" |
| 746 | " }\n" |
| 747 | " }\n\n" |
| 748 | " list list1 {\n" |
| 749 | " key \"leaf18\";\n" |
| 750 | " unique \"leaf19\";\n" |
| 751 | " min-elements 1;\n" |
| 752 | " max-elements 20;\n" |
| 753 | " leaf leaf18 {\n" |
| 754 | " type string;\n" |
| 755 | " }\n\n" |
| 756 | " leaf leaf19 {\n" |
| 757 | " type uint32;\n" |
| 758 | " }\n\n" |
| 759 | " anyxml axml1;\n" |
| 760 | " anydata adata1;\n\n" |
| 761 | " action act1 {\n" |
| 762 | " input {\n" |
| 763 | " leaf leaf24 {\n" |
| 764 | " type string;\n" |
| 765 | " }\n" |
| 766 | " }\n\n" |
| 767 | " output {\n" |
| 768 | " leaf leaf25 {\n" |
| 769 | " type string;\n" |
| 770 | " }\n" |
| 771 | " }\n" |
| 772 | " }\n\n" |
| 773 | " notification notif1 {\n" |
| 774 | " leaf leaf26 {\n" |
| 775 | " type string;\n" |
| 776 | " }\n" |
| 777 | " }\n" |
| 778 | " }\n\n" |
| 779 | " leaf-list llist1 {\n" |
| 780 | " type tdef1;\n" |
| 781 | " ordered-by user;\n" |
| 782 | " }\n\n" |
| 783 | " list list2 {\n" |
| 784 | " key \"leaf27 leaf28\";\n" |
| 785 | " leaf leaf27 {\n" |
| 786 | " type uint8;\n" |
| 787 | " }\n\n" |
| 788 | " leaf leaf28 {\n" |
| 789 | " type uint8;\n" |
| 790 | " }\n" |
| 791 | " }\n\n" |
| 792 | " leaf leaf29 {\n" |
| 793 | " type instance-identifier;\n" |
| 794 | " }\n\n" |
| 795 | " container must-deviations-container {\n" |
| 796 | " presence \"Allows deviations on the leaf\";\n" |
| 797 | " leaf leaf30 {\n" |
| 798 | " type string;\n" |
| 799 | " }\n" |
| 800 | " }\n\n" |
| 801 | " leaf leaf23 {\n" |
| 802 | " type empty;\n" |
| 803 | " }\n" |
| 804 | " }\n\n" |
| 805 | " augment \"/cont1\" {\n" |
| 806 | " leaf leaf17 {\n" |
| 807 | " type string;\n" |
| 808 | " }\n" |
| 809 | " }\n\n" |
| 810 | " rpc rpc1 {\n" |
| 811 | " input {\n" |
| 812 | " leaf leaf20 {\n" |
| 813 | " type tdef1;\n" |
| 814 | " }\n" |
| 815 | " }\n\n" |
| 816 | " output {\n" |
| 817 | " container cont2 {\n" |
| 818 | " leaf leaf21 {\n" |
| 819 | " type empty;\n" |
| 820 | " }\n" |
| 821 | " }\n" |
| 822 | " }\n" |
| 823 | " }\n\n" |
| 824 | " container test-when {\n" |
| 825 | " leaf when-check {\n" |
| 826 | " type boolean;\n" |
| 827 | " }\n\n" |
| 828 | " leaf gated-data {\n" |
| 829 | " when \"../when-check = 'true'\";\n" |
| 830 | " type uint16;\n" |
| 831 | " }\n" |
| 832 | " }\n\n" |
| 833 | " extension c-define {\n" |
| 834 | " description\n" |
| 835 | " \"Takes as an argument a name string.\n" |
| 836 | " Makes the code generator use the given name\n" |
| 837 | " in the #define.\";\n" |
| 838 | " argument \"name\";\n" |
| 839 | " }\n" |
| 840 | "}\n"); |
| 841 | |
| 842 | char *ori_res = malloc(8096); |
| 843 | |
| 844 | strcpy(ori_res, |
| 845 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 846 | "<module name=\"all\"\n" |
| 847 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 848 | " xmlns:all_mod=\"urn:all\"\n" |
| 849 | " xmlns:yt=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">\n" |
| 850 | " <yang-version value=\"1.1\"/>\n" |
| 851 | " <namespace uri=\"urn:all\"/>\n" |
| 852 | " <prefix value=\"all_mod\"/>\n" |
| 853 | " <import module=\"ietf-yang-types\">\n" |
| 854 | " <prefix value=\"yt\"/>\n" |
| 855 | " <revision-date date=\"2013-07-15\"/>\n" |
| 856 | " <description>\n" |
| 857 | " <text>YANG types</text>\n" |
| 858 | " </description>\n" |
| 859 | " <reference>\n" |
| 860 | " <text>RFC reference</text>\n" |
| 861 | " </reference>\n" |
| 862 | " </import>\n" |
| 863 | " <extension name=\"c-define\">\n" |
| 864 | " <argument name=\"name\"/>\n" |
| 865 | " <description>\n" |
| 866 | " <text>Takes as an argument a name string.\n" |
| 867 | "Makes the code generator use the given name\n" |
| 868 | "in the #define.</text>\n" |
| 869 | " </description>\n" |
| 870 | " </extension>\n" |
| 871 | " <feature name=\"feat1\">\n" |
| 872 | " <if-feature name=\"feat2\"/>\n" |
| 873 | " <status value=\"obsolete\"/>\n" |
| 874 | " </feature>\n" |
| 875 | " <feature name=\"feat2\"/>\n" |
| 876 | " <feature name=\"feat3\"/>\n" |
| 877 | " <identity name=\"ident2\">\n" |
| 878 | " <base name=\"ident1\"/>\n" |
| 879 | " </identity>\n" |
| 880 | " <identity name=\"ident1\"/>\n" |
| 881 | " <typedef name=\"tdef1\">\n" |
| 882 | " <type name=\"tdef2\">\n" |
| 883 | " <length value=\"3..9 | 30..40\"/>\n" |
| 884 | " <pattern value=\"[ac]*\"/>\n" |
| 885 | " </type>\n" |
| 886 | " <units name=\"none\"/>\n" |
| 887 | " <default value=\"aaa\"/>\n" |
| 888 | " </typedef>\n" |
| 889 | " <typedef name=\"tdef2\">\n" |
| 890 | " <type name=\"string\">\n" |
| 891 | " <length value=\"2..10 | 20..50\"/>\n" |
| 892 | " <pattern value=\"[ab]*\"/>\n" |
| 893 | " </type>\n" |
| 894 | " </typedef>\n" |
| 895 | " <grouping name=\"group1\">\n" |
| 896 | " <leaf name=\"leaf1\">\n" |
| 897 | " <type name=\"int8\"/>\n" |
| 898 | " </leaf>\n" |
| 899 | " </grouping>\n" |
| 900 | " <container name=\"cont1\">\n" |
| 901 | " <leaf name=\"leaf2\">\n" |
| 902 | " <if-feature name=\"feat1\"/>\n" |
| 903 | " <type name=\"int16\"/>\n" |
| 904 | " <status value=\"obsolete\"/>\n" |
| 905 | " </leaf>\n" |
| 906 | " <uses name=\"group1\">\n" |
| 907 | " <if-feature name=\"feat2\"/>\n" |
| 908 | " <refine target-node=\"leaf1\">\n" |
| 909 | " <if-feature name=\"feat3\"/>\n" |
| 910 | " <must condition=\"24 - 4 = number('20')\"/>\n" |
| 911 | " <default value=\"25\"/>\n" |
| 912 | " <config value=\"true\"/>\n" |
| 913 | " <mandatory value=\"false\"/>\n" |
| 914 | " <description>\n" |
| 915 | " <text>dsc</text>\n" |
| 916 | " </description>\n" |
| 917 | " <reference>\n" |
| 918 | " <text>none</text>\n" |
| 919 | " </reference>\n" |
| 920 | " </refine>\n" |
| 921 | " </uses>\n" |
| 922 | " <leaf name=\"leaf3\">\n" |
| 923 | " <type name=\"int32\"/>\n" |
| 924 | " </leaf>\n" |
| 925 | " <leaf name=\"leaf4\">\n" |
| 926 | " <type name=\"int64\">\n" |
| 927 | " <range value=\"1000 .. 50000\">\n" |
| 928 | " <error-message>\n" |
| 929 | " <value>Special error message.</value>\n" |
| 930 | " </error-message>\n" |
| 931 | " <error-app-tag value=\"special-tag\"/>\n" |
| 932 | " </range>\n" |
| 933 | " </type>\n" |
| 934 | " </leaf>\n" |
| 935 | " <leaf name=\"leaf5\">\n" |
| 936 | " <type name=\"uint8\"/>\n" |
| 937 | " </leaf>\n" |
| 938 | " <leaf name=\"leaf6\">\n" |
| 939 | " <type name=\"uint16\"/>\n" |
| 940 | " </leaf>\n" |
| 941 | " <leaf name=\"leaf7\">\n" |
| 942 | " <type name=\"uint32\"/>\n" |
| 943 | " </leaf>\n" |
| 944 | " <leaf name=\"leaf8\">\n" |
| 945 | " <type name=\"uint64\"/>\n" |
| 946 | " </leaf>\n" |
| 947 | " <choice name=\"choic1\">\n" |
| 948 | " <default value=\"leaf9b\"/>\n" |
| 949 | " <leaf name=\"leaf9a\">\n" |
| 950 | " <type name=\"decimal64\">\n" |
| 951 | " <fraction-digits value=\"9\"/>\n" |
| 952 | " </type>\n" |
| 953 | " </leaf>\n" |
| 954 | " <leaf name=\"leaf9b\">\n" |
| 955 | " <type name=\"boolean\"/>\n" |
| 956 | " <default value=\"false\"/>\n" |
| 957 | " </leaf>\n" |
| 958 | " </choice>\n" |
| 959 | " <leaf name=\"leaf10\">\n" |
| 960 | " <type name=\"boolean\"/>\n" |
| 961 | " </leaf>\n"); |
| 962 | strcpy(ori_res + strlen(ori_res), |
| 963 | " <leaf name=\"leaf11\">\n" |
| 964 | " <type name=\"enumeration\">\n" |
| 965 | " <enum name=\"one\"/>\n" |
| 966 | " <enum name=\"two\"/>\n" |
| 967 | " <enum name=\"five\">\n" |
| 968 | " <value value=\"5\"/>\n" |
| 969 | " </enum>\n" |
| 970 | " </type>\n" |
| 971 | " </leaf>\n" |
| 972 | " <leaf name=\"leaf12\">\n" |
| 973 | " <type name=\"bits\">\n" |
| 974 | " <bit name=\"flag0\">\n" |
| 975 | " <position value=\"0\"/>\n" |
| 976 | " </bit>\n" |
| 977 | " <bit name=\"flag1\"/>\n" |
| 978 | " <bit name=\"flag2\">\n" |
| 979 | " <position value=\"2\"/>\n" |
| 980 | " </bit>\n" |
| 981 | " <bit name=\"flag3\">\n" |
| 982 | " <position value=\"3\"/>\n" |
| 983 | " </bit>\n" |
| 984 | " </type>\n" |
| 985 | " <default value=\"flag0 flag3\"/>\n" |
| 986 | " </leaf>\n" |
| 987 | " <leaf name=\"leaf13\">\n" |
| 988 | " <type name=\"binary\"/>\n" |
| 989 | " </leaf>\n" |
| 990 | " <leaf name=\"leaf14\">\n" |
| 991 | " <type name=\"leafref\">\n" |
| 992 | " <path value=\"/cont1/leaf17\"/>\n" |
| 993 | " </type>\n" |
| 994 | " </leaf>\n" |
| 995 | " <leaf name=\"leaf15\">\n" |
| 996 | " <type name=\"empty\"/>\n" |
| 997 | " </leaf>\n" |
| 998 | " <leaf name=\"leaf16\">\n" |
| 999 | " <type name=\"union\">\n" |
| 1000 | " <type name=\"instance-identifier\">\n" |
| 1001 | " <require-instance value=\"true\"/>\n" |
| 1002 | " </type>\n" |
| 1003 | " <type name=\"int8\"/>\n" |
| 1004 | " </type>\n" |
| 1005 | " </leaf>\n" |
| 1006 | " <list name=\"list1\">\n" |
| 1007 | " <key value=\"leaf18\"/>\n" |
| 1008 | " <unique tag=\"leaf19\"/>\n" |
| 1009 | " <min-elements value=\"1\"/>\n" |
| 1010 | " <max-elements value=\"20\"/>\n" |
| 1011 | " <leaf name=\"leaf18\">\n" |
| 1012 | " <type name=\"string\"/>\n" |
| 1013 | " </leaf>\n" |
| 1014 | " <leaf name=\"leaf19\">\n" |
| 1015 | " <type name=\"uint32\"/>\n" |
| 1016 | " </leaf>\n" |
| 1017 | " <anyxml name=\"axml1\"/>\n" |
| 1018 | " <anydata name=\"adata1\"/>\n" |
| 1019 | " <action name=\"act1\">\n" |
| 1020 | " <input>\n" |
| 1021 | " <leaf name=\"leaf24\">\n" |
| 1022 | " <type name=\"string\"/>\n" |
| 1023 | " </leaf>\n" |
| 1024 | " </input>\n" |
| 1025 | " <output>\n" |
| 1026 | " <leaf name=\"leaf25\">\n" |
| 1027 | " <type name=\"string\"/>\n" |
| 1028 | " </leaf>\n" |
| 1029 | " </output>\n" |
| 1030 | " </action>\n" |
| 1031 | " <notification name=\"notif1\">\n" |
| 1032 | " <leaf name=\"leaf26\">\n" |
| 1033 | " <type name=\"string\"/>\n" |
| 1034 | " </leaf>\n" |
| 1035 | " </notification>\n" |
| 1036 | " </list>\n" |
| 1037 | " <leaf-list name=\"llist1\">\n" |
| 1038 | " <type name=\"tdef1\"/>\n" |
| 1039 | " <ordered-by value=\"user\"/>\n" |
| 1040 | " </leaf-list>\n" |
| 1041 | " <list name=\"list2\">\n" |
| 1042 | " <key value=\"leaf27 leaf28\"/>\n" |
| 1043 | " <leaf name=\"leaf27\">\n" |
| 1044 | " <type name=\"uint8\"/>\n" |
| 1045 | " </leaf>\n" |
| 1046 | " <leaf name=\"leaf28\">\n" |
| 1047 | " <type name=\"uint8\"/>\n" |
| 1048 | " </leaf>\n" |
| 1049 | " </list>\n" |
| 1050 | " <leaf name=\"leaf29\">\n" |
| 1051 | " <type name=\"instance-identifier\"/>\n" |
| 1052 | " </leaf>\n" |
| 1053 | " <container name=\"must-deviations-container\">\n" |
| 1054 | " <presence value=\"Allows deviations on the leaf\"/>\n" |
| 1055 | " <leaf name=\"leaf30\">\n" |
| 1056 | " <type name=\"string\"/>\n" |
| 1057 | " </leaf>\n" |
| 1058 | " </container>\n" |
| 1059 | " <leaf name=\"leaf23\">\n" |
| 1060 | " <type name=\"empty\"/>\n" |
| 1061 | " </leaf>\n" |
| 1062 | " </container>\n" |
| 1063 | " <container name=\"test-when\">\n" |
| 1064 | " <leaf name=\"when-check\">\n" |
| 1065 | " <type name=\"boolean\"/>\n" |
| 1066 | " </leaf>\n" |
| 1067 | " <leaf name=\"gated-data\">\n" |
| 1068 | " <when condition=\"../when-check = 'true'\"/>\n" |
| 1069 | " <type name=\"uint16\"/>\n" |
| 1070 | " </leaf>\n" |
| 1071 | " </container>\n" |
| 1072 | " <augment target-node=\"/cont1\">\n" |
| 1073 | " <leaf name=\"leaf17\">\n" |
| 1074 | " <type name=\"string\"/>\n" |
| 1075 | " </leaf>\n" |
| 1076 | " </augment>\n" |
| 1077 | " <rpc name=\"rpc1\">\n" |
| 1078 | " <input>\n" |
| 1079 | " <leaf name=\"leaf20\">\n" |
| 1080 | " <type name=\"tdef1\"/>\n" |
| 1081 | " </leaf>\n" |
| 1082 | " </input>\n" |
| 1083 | " <output>\n" |
| 1084 | " <container name=\"cont2\">\n" |
| 1085 | " <leaf name=\"leaf21\">\n" |
| 1086 | " <type name=\"empty\"/>\n" |
| 1087 | " </leaf>\n" |
| 1088 | " </container>\n" |
| 1089 | " </output>\n" |
| 1090 | " </rpc>\n" |
| 1091 | "</module>\n"); |
| 1092 | |
| 1093 | char *printed; |
| 1094 | struct ly_out *out; |
| 1095 | |
| 1096 | assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out)); |
| 1097 | |
| 1098 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1099 | assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YIN, 0, 0)); |
| 1100 | assert_int_equal(strlen(ori_res), ly_out_printed(out)); |
| 1101 | assert_string_equal(printed, ori_res); |
| 1102 | |
| 1103 | ly_out_free(out, NULL, 1); |
| 1104 | free(orig); |
| 1105 | free(ori_res); |
| 1106 | } |
| 1107 | |
| 1108 | static LY_ERR |
| 1109 | test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name), |
| 1110 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 1111 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 1112 | { |
| 1113 | *module_data = user_data; |
| 1114 | *format = LYS_IN_YIN; |
| 1115 | *free_module_data = NULL; |
| 1116 | return LY_SUCCESS; |
| 1117 | } |
| 1118 | |
| 1119 | static void |
| 1120 | test_print_submodule(void **state) |
| 1121 | { |
| 1122 | struct lys_module *mod; |
| 1123 | |
| 1124 | const char *mod_yin = |
| 1125 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 1126 | "<module name=\"a\"\n" |
| 1127 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 1128 | " xmlns:a_mod=\"urn:a\">\n" |
| 1129 | " <yang-version value=\"1.1\"/>\n" |
| 1130 | " <namespace uri=\"urn:a\"/>\n" |
| 1131 | " <prefix value=\"a_mod\"/>\n" |
| 1132 | " <include module=\"a-sub\"/>\n" |
| 1133 | "</module>\n"; |
| 1134 | |
| 1135 | char *submod_yin = |
| 1136 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 1137 | "<submodule name=\"a-sub\"\n" |
| 1138 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 1139 | " xmlns:a_mod=\"urn:a\"\n" |
| 1140 | " xmlns:yt=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">\n" |
| 1141 | " <yang-version value=\"1.1\"/>\n" |
| 1142 | " <belongs-to module=\"a\">\n" |
| 1143 | " <prefix value=\"a_mod\"/>\n" |
| 1144 | " </belongs-to>\n" |
| 1145 | " <import module=\"ietf-yang-types\">\n" |
| 1146 | " <prefix value=\"yt\"/>\n" |
| 1147 | " <revision-date date=\"2013-07-15\"/>\n" |
| 1148 | " </import>\n\n" |
| 1149 | " <description>\n" |
| 1150 | " <text>YANG types</text>\n" |
| 1151 | " </description>\n" |
| 1152 | " <reference>\n" |
| 1153 | " <text>RFC reference</text>\n" |
| 1154 | " </reference>\n" |
| 1155 | "</submodule>\n"; |
| 1156 | |
| 1157 | char *printed; |
| 1158 | struct ly_out *out; |
| 1159 | |
| 1160 | assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out)); |
| 1161 | |
| 1162 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod_yin); |
| 1163 | |
| 1164 | UTEST_ADD_MODULE(mod_yin, LYS_IN_YIN, NULL, &mod); |
| 1165 | assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod->parsed->includes[0].submodule, LYS_OUT_YIN, 0, 0)); |
| 1166 | assert_int_equal(strlen(submod_yin), ly_out_printed(out)); |
| 1167 | assert_string_equal(printed, submod_yin); |
| 1168 | |
| 1169 | ly_out_free(out, NULL, 1); |
| 1170 | } |
| 1171 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1172 | /* helper function to simplify unit test of each element using parse_content function */ |
| 1173 | LY_ERR |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1174 | test_element_helper(void **state, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1175 | { |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 1176 | const char *name, *prefix; |
| 1177 | size_t name_len, prefix_len; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1178 | LY_ERR ret = LY_SUCCESS; |
| 1179 | struct yin_subelement subelems[71] = { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1180 | {LY_STMT_ACTION, dest, 0}, |
| 1181 | {LY_STMT_ANYDATA, dest, 0}, |
| 1182 | {LY_STMT_ANYXML, dest, 0}, |
| 1183 | {LY_STMT_ARGUMENT, dest, 0}, |
| 1184 | {LY_STMT_AUGMENT, dest, 0}, |
| 1185 | {LY_STMT_BASE, dest, 0}, |
| 1186 | {LY_STMT_BELONGS_TO, dest, 0}, |
| 1187 | {LY_STMT_BIT, dest, 0}, |
| 1188 | {LY_STMT_CASE, dest, 0}, |
| 1189 | {LY_STMT_CHOICE, dest, 0}, |
| 1190 | {LY_STMT_CONFIG, dest, 0}, |
| 1191 | {LY_STMT_CONTACT, dest, 0}, |
| 1192 | {LY_STMT_CONTAINER, dest, 0}, |
| 1193 | {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE}, |
| 1194 | {LY_STMT_DESCRIPTION, dest, 0}, |
| 1195 | {LY_STMT_DEVIATE, dest, 0}, |
| 1196 | {LY_STMT_DEVIATION, dest, 0}, |
| 1197 | {LY_STMT_ENUM, dest, 0}, |
| 1198 | {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE}, |
| 1199 | {LY_STMT_ERROR_MESSAGE, dest, 0}, |
| 1200 | {LY_STMT_EXTENSION, dest, 0}, |
| 1201 | {LY_STMT_FEATURE, dest, 0}, |
| 1202 | {LY_STMT_FRACTION_DIGITS, dest, 0}, |
| 1203 | {LY_STMT_GROUPING, dest, 0}, |
| 1204 | {LY_STMT_IDENTITY, dest, 0}, |
| 1205 | {LY_STMT_IF_FEATURE, dest, 0}, |
| 1206 | {LY_STMT_IMPORT, dest, 0}, |
| 1207 | {LY_STMT_INCLUDE, dest, 0}, |
| 1208 | {LY_STMT_INPUT, dest, 0}, |
| 1209 | {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE}, |
| 1210 | {LY_STMT_LEAF, dest, 0}, |
| 1211 | {LY_STMT_LEAF_LIST, dest, 0}, |
| 1212 | {LY_STMT_LENGTH, dest, 0}, |
| 1213 | {LY_STMT_LIST, dest, 0}, |
| 1214 | {LY_STMT_MANDATORY, dest, 0}, |
| 1215 | {LY_STMT_MAX_ELEMENTS, dest, 0}, |
| 1216 | {LY_STMT_MIN_ELEMENTS, dest, 0}, |
| 1217 | {LY_STMT_MODIFIER, dest, 0}, |
| 1218 | {LY_STMT_MODULE, dest, 0}, |
| 1219 | {LY_STMT_MUST, dest, 0}, |
| 1220 | {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE}, |
| 1221 | {LY_STMT_NOTIFICATION, dest, 0}, |
| 1222 | {LY_STMT_ORDERED_BY, dest, 0}, |
| 1223 | {LY_STMT_ORGANIZATION, dest, 0}, |
| 1224 | {LY_STMT_OUTPUT, dest, 0}, |
| 1225 | {LY_STMT_PATH, dest, 0}, |
| 1226 | {LY_STMT_PATTERN, dest, 0}, |
| 1227 | {LY_STMT_POSITION, dest, 0}, |
| 1228 | {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE}, |
| 1229 | {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE}, |
| 1230 | {LY_STMT_RANGE, dest, 0}, |
| 1231 | {LY_STMT_REFERENCE, dest, 0}, |
| 1232 | {LY_STMT_REFINE, dest, 0}, |
| 1233 | {LY_STMT_REQUIRE_INSTANCE, dest, 0}, |
| 1234 | {LY_STMT_REVISION, dest, 0}, |
| 1235 | {LY_STMT_REVISION_DATE, dest, 0}, |
| 1236 | {LY_STMT_RPC, dest, 0}, |
| 1237 | {LY_STMT_STATUS, dest, 0}, |
| 1238 | {LY_STMT_SUBMODULE, dest, 0}, |
| 1239 | {LY_STMT_TYPE, dest, 0}, |
| 1240 | {LY_STMT_TYPEDEF, dest, 0}, |
| 1241 | {LY_STMT_UNIQUE, dest, 0}, |
| 1242 | {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE}, |
| 1243 | {LY_STMT_USES, dest, 0}, |
| 1244 | {LY_STMT_VALUE, dest, 0}, |
| 1245 | {LY_STMT_WHEN, dest, 0}, |
| 1246 | {LY_STMT_YANG_VERSION, dest, 0}, |
| 1247 | {LY_STMT_YIN_ELEMENT, dest, 0}, |
| 1248 | {LY_STMT_EXTENSION_INSTANCE, dest, 0}, |
| 1249 | {LY_STMT_ARG_TEXT, dest, 0}, |
| 1250 | {LY_STMT_ARG_VALUE, dest, 0} |
| 1251 | }; |
| 1252 | |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1253 | YCTX->main_ctx = (struct lysp_ctx *)YCTX; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1254 | ly_in_new_memory(data, &UTEST_IN); |
| 1255 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 1256 | prefix = YCTX->xmlctx->prefix; |
| 1257 | prefix_len = YCTX->xmlctx->prefix_len; |
| 1258 | name = YCTX->xmlctx->name; |
| 1259 | name_len = YCTX->xmlctx->name_len; |
| 1260 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1261 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1262 | ret = yin_parse_content(YCTX, subelems, 71, NULL, |
| 1263 | yin_match_keyword(YCTX, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1264 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 1265 | /* free parser and input */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1266 | lyxml_ctx_free(YCTX->xmlctx); |
| 1267 | YCTX->xmlctx = NULL; |
| 1268 | ly_in_free(UTEST_IN, 0); |
| 1269 | UTEST_IN = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1270 | return ret; |
| 1271 | } |
| 1272 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1273 | #define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>" |
| 1274 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1275 | static void |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 1276 | test_enum_elem(void **state) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1277 | { |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1278 | struct lysp_type type = {0}; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1279 | const char *data; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1280 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1281 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1282 | "<enum name=\"enum-name\">\n" |
| 1283 | " <if-feature name=\"feature\" />\n" |
| 1284 | " <value value=\"55\" />\n" |
| 1285 | " <status value=\"deprecated\" />\n" |
| 1286 | " <description><text>desc...</text></description>\n" |
| 1287 | " <reference><text>ref...</text></reference>\n" |
| 1288 | " " EXT_SUBELEM "\n" |
| 1289 | "</enum>" |
| 1290 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1291 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1292 | uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE; |
| 1293 | |
| 1294 | CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1295 | assert_string_equal(type.enums->iffeatures[0].str, "feature"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1296 | TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LY_STMT_ENUM); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1297 | lysp_type_free(&fctx, &type); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1298 | memset(&type, 0, sizeof type); |
| 1299 | |
| 1300 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1301 | "<enum name=\"enum-name\"></enum>" |
| 1302 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1303 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1304 | assert_string_equal(type.enums->name, "enum-name"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1305 | lysp_type_free(&fctx, &type); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1306 | memset(&type, 0, sizeof type); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | static void |
| 1310 | test_bit_elem(void **state) |
| 1311 | { |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1312 | struct lysp_type type = {0}; |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 1313 | const char *data; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1314 | |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 1315 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1316 | "<bit name=\"bit-name\">\n" |
| 1317 | " <if-feature name=\"feature\" />\n" |
| 1318 | " <position value=\"55\" />\n" |
| 1319 | " <status value=\"deprecated\" />\n" |
| 1320 | " <description><text>desc...</text></description>\n" |
| 1321 | " <reference><text>ref...</text></reference>\n" |
| 1322 | EXT_SUBELEM |
| 1323 | "</bit>" |
| 1324 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1325 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1326 | uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE; |
| 1327 | |
| 1328 | CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1329 | assert_string_equal(type.bits->iffeatures[0].str, "feature"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1330 | TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LY_STMT_BIT); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1331 | lysp_type_free(&fctx, &type); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1332 | memset(&type, 0, sizeof type); |
| 1333 | |
| 1334 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1335 | "<bit name=\"bit-name\"> </bit>" |
| 1336 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1337 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1338 | CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1339 | lysp_type_free(&fctx, &type); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 1340 | memset(&type, 0, sizeof type); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | static void |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1344 | test_status_elem(void **state) |
| 1345 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1346 | const char *data; |
| 1347 | uint16_t flags = 0; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1348 | |
| 1349 | /* test invalid value */ |
| 1350 | data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1351 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
| 1352 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. " |
| 1353 | "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static void |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1357 | test_yin_element_elem(void **state) |
| 1358 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1359 | const char *data; |
| 1360 | uint16_t flags = 0; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1361 | |
| 1362 | data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1363 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1364 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. " |
| 1365 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | static void |
| 1369 | test_yangversion_elem(void **state) |
| 1370 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1371 | const char *data; |
| 1372 | uint8_t version = 0; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1373 | |
| 1374 | /* invalid value */ |
| 1375 | data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1376 | assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID); |
| 1377 | CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. " |
| 1378 | "Valid values are \"1\" and \"1.1\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static void |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1382 | test_argument_elem(void **state) |
| 1383 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1384 | const char *data; |
| 1385 | uint16_t flags = 0; |
| 1386 | const char *arg; |
| 1387 | struct yin_argument_meta arg_meta = {&flags, &arg}; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1388 | |
| 1389 | /* min subelems */ |
| 1390 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1391 | "<argument name=\"arg\">" |
| 1392 | "</argument>" |
| 1393 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1394 | assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1395 | assert_string_equal(arg, "arg"); |
| 1396 | assert_true(flags == 0); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1397 | lydict_remove(UTEST_LYCTX, arg); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static void |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1401 | test_belongsto_elem(void **state) |
| 1402 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1403 | const char *data; |
| 1404 | struct lysp_submodule submod; |
| 1405 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1406 | lydict_insert(UTEST_LYCTX, "module-name", 0, &PARSER_CUR_PMOD(YCTX)->mod->name); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1407 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1408 | data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1409 | assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID); |
| 1410 | CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | static void |
| 1414 | test_config_elem(void **state) |
| 1415 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1416 | const char *data; |
| 1417 | uint16_t flags = 0; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1418 | |
| 1419 | data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1420 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1421 | assert_true(flags & LYS_CONFIG_R); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1422 | flags = 0; |
| 1423 | |
| 1424 | data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1425 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
| 1426 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. " |
| 1427 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | static void |
| 1431 | test_default_elem(void **state) |
| 1432 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1433 | const char *data; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1434 | struct lysp_qname val = {0}; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1435 | |
| 1436 | data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1437 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1438 | CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | static void |
| 1442 | test_err_app_tag_elem(void **state) |
| 1443 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1444 | const char *data; |
| 1445 | const char *val = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1446 | |
| 1447 | data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1448 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1449 | CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | static void |
| 1453 | test_err_msg_elem(void **state) |
| 1454 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1455 | const char *data; |
| 1456 | const char *val = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1457 | |
| 1458 | data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1459 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1460 | CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1461 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1462 | data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1463 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1464 | CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | static void |
| 1468 | test_fracdigits_elem(void **state) |
| 1469 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1470 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1471 | struct lysp_type type = {0}; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1472 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1473 | /* invalid values */ |
| 1474 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1475 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1476 | CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1477 | |
| 1478 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1479 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1480 | CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1481 | |
| 1482 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1483 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1484 | CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1485 | |
| 1486 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1487 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1488 | CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1489 | |
| 1490 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1491 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1492 | CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | static void |
| 1496 | test_iffeature_elem(void **state) |
| 1497 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1498 | const char *data; |
| 1499 | const char **iffeatures = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1500 | |
| 1501 | data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1502 | assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID); |
| 1503 | CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1504 | LY_ARRAY_FREE(iffeatures); |
| 1505 | iffeatures = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | static void |
| 1509 | test_length_elem(void **state) |
| 1510 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1511 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1512 | struct lysp_type type = {0}; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1513 | |
| 1514 | /* max subelems */ |
| 1515 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1516 | "<length value=\"length-str\">\n" |
| 1517 | " <error-message><value>err-msg</value></error-message>\n" |
| 1518 | " <error-app-tag value=\"err-app-tag\"/>\n" |
| 1519 | " <description><text>desc</text></description>\n" |
| 1520 | " <reference><text>ref</text></reference>\n" |
| 1521 | EXT_SUBELEM |
| 1522 | "</length>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1523 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1524 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1525 | CHECK_LYSP_RESTR(type.length, "length-str", "desc", |
| 1526 | "err-app-tag", "err-msg", 1, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1527 | assert_true(type.flags & LYS_SET_LENGTH); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1528 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LY_STMT_LENGTH); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1529 | lysp_type_free(&fctx, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1530 | memset(&type, 0, sizeof(type)); |
| 1531 | |
| 1532 | /* min subelems */ |
| 1533 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1534 | "<length value=\"length-str\">" |
| 1535 | "</length>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1536 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1537 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1538 | CHECK_LYSP_RESTR(type.length, "length-str", NULL, |
| 1539 | NULL, NULL, 0, NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1540 | lysp_type_free(&fctx, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1541 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1542 | memset(&type, 0, sizeof(type)); |
| 1543 | |
| 1544 | data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1545 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1546 | CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1."); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1547 | lysp_type_free(&fctx, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1548 | memset(&type, 0, sizeof(type)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | static void |
| 1552 | test_modifier_elem(void **state) |
| 1553 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1554 | const char *data; |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1555 | const char *pat; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1556 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1557 | assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1558 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1559 | assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID); |
| 1560 | CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. " |
| 1561 | "Only valid value is \"invert-match\".", "Line number 1."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1562 | lydict_remove(UTEST_LYCTX, pat); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | static void |
| 1566 | test_namespace_elem(void **state) |
| 1567 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1568 | const char *data; |
| 1569 | const char *ns; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1570 | |
| 1571 | data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1572 | assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID); |
| 1573 | CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | static void |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1577 | test_pattern_elem(void **state) |
| 1578 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1579 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1580 | struct lysp_type type = {0}; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1581 | |
| 1582 | /* max subelems */ |
| 1583 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1584 | "<pattern value=\"super_pattern\">\n" |
| 1585 | " <modifier value=\"invert-match\"/>\n" |
| 1586 | " <error-message><value>err-msg-value</value></error-message>\n" |
| 1587 | " <error-app-tag value=\"err-app-tag-value\"/>\n" |
| 1588 | " <description><text>"pattern-desc"</text></description>\n" |
| 1589 | " <reference><text>pattern-ref</text></reference>\n" |
| 1590 | EXT_SUBELEM |
| 1591 | "</pattern>" |
| 1592 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1593 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1594 | assert_true(type.flags & LYS_SET_PATTERN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1595 | CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"", |
| 1596 | "err-app-tag-value", "err-msg-value", 1, "pattern-ref"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1597 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LY_STMT_PATTERN); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1598 | lysp_type_free(&fctx, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1599 | memset(&type, 0, sizeof(type)); |
| 1600 | |
| 1601 | /* min subelems */ |
| 1602 | data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1603 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1604 | CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1605 | lysp_type_free(&fctx, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1606 | memset(&type, 0, sizeof(type)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | static void |
| 1610 | test_value_position_elem(void **state) |
| 1611 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1612 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1613 | struct lysp_type_enum en = {0}; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1614 | |
| 1615 | /* valid values */ |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1616 | data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1617 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1618 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1619 | memset(&en, 0, sizeof(en)); |
| 1620 | |
| 1621 | data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1622 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1623 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1624 | memset(&en, 0, sizeof(en)); |
| 1625 | |
| 1626 | data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1627 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1628 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1629 | memset(&en, 0, sizeof(en)); |
| 1630 | |
| 1631 | /* valid positions */ |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1632 | data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1633 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1634 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1635 | memset(&en, 0, sizeof(en)); |
| 1636 | |
| 1637 | /* invalid values */ |
| 1638 | data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1639 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1640 | CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1641 | |
| 1642 | data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1643 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1644 | CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1645 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1646 | data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1647 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1648 | CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1649 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1650 | /*invalid positions */ |
| 1651 | data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1652 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1653 | CHECK_LOG_CTX("Invalid value \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1654 | |
| 1655 | data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1656 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1657 | CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1658 | |
| 1659 | data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1660 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1661 | CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1662 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1663 | data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1664 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1665 | CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | static void |
| 1669 | test_prefix_elem(void **state) |
| 1670 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1671 | const char *data; |
| 1672 | const char *value = NULL; |
| 1673 | |
| 1674 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1675 | assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1676 | assert_string_equal(value, "pref"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1677 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | static void |
| 1681 | test_range_elem(void **state) |
| 1682 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1683 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1684 | struct lysp_type type = {0}; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1685 | |
| 1686 | /* max subelems */ |
| 1687 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1688 | "<range value=\"range-str\">\n" |
| 1689 | " <error-message><value>err-msg</value></error-message>\n" |
| 1690 | " <error-app-tag value=\"err-app-tag\" />\n" |
| 1691 | " <description><text>desc</text></description>\n" |
| 1692 | " <reference><text>ref</text></reference>\n" |
| 1693 | EXT_SUBELEM |
| 1694 | "</range>" |
| 1695 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1696 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1697 | CHECK_LYSP_RESTR(type.range, "range-str", "desc", |
| 1698 | "err-app-tag", "err-msg", 1, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1699 | assert_true(type.flags & LYS_SET_RANGE); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1700 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LY_STMT_RANGE); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1701 | lysp_type_free(&fctx, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1702 | memset(&type, 0, sizeof(type)); |
| 1703 | |
| 1704 | /* min subelems */ |
| 1705 | data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1706 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1707 | CHECK_LYSP_RESTR(type.range, "range-str", NULL, |
| 1708 | NULL, NULL, 0, NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1709 | lysp_type_free(&fctx, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1710 | memset(&type, 0, sizeof(type)); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | static void |
| 1714 | test_reqinstance_elem(void **state) |
| 1715 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1716 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1717 | struct lysp_type type = {0}; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1718 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1719 | data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1720 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1721 | assert_int_equal(type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1722 | assert_true(type.flags & LYS_SET_REQINST); |
Radek Krejci | 5984d22 | 2021-02-26 23:01:45 +0100 | [diff] [blame] | 1723 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_REQUIRE_INSTANCE); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1724 | lysp_type_free(&fctx, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1725 | memset(&type, 0, sizeof(type)); |
| 1726 | |
| 1727 | data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1728 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1729 | assert_int_equal(type.require_instance, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1730 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1731 | memset(&type, 0, sizeof(type)); |
| 1732 | |
| 1733 | data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1734 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1735 | memset(&type, 0, sizeof(type)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1736 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. " |
| 1737 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | static void |
| 1741 | test_revision_date_elem(void **state) |
| 1742 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1743 | const char *data; |
| 1744 | char rev[LY_REV_SIZE]; |
| 1745 | |
| 1746 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1747 | assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1748 | assert_string_equal(rev, "2000-01-01"); |
| 1749 | |
| 1750 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1751 | assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID); |
| 1752 | CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | static void |
| 1756 | test_unique_elem(void **state) |
| 1757 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1758 | const char *data; |
| 1759 | const char **values = NULL; |
| 1760 | |
| 1761 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1762 | assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1763 | assert_string_equal(*values, "tag"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1764 | lydict_remove(UTEST_LYCTX, *values); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1765 | LY_ARRAY_FREE(values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1766 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | static void |
| 1770 | test_units_elem(void **state) |
| 1771 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1772 | const char *data; |
| 1773 | const char *values = NULL; |
| 1774 | |
| 1775 | data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1776 | assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1777 | assert_string_equal(values, "name"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1778 | lydict_remove(UTEST_LYCTX, values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1779 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static void |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1783 | test_yin_text_value_elem(void **state) |
| 1784 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1785 | const char *data; |
| 1786 | const char *val; |
| 1787 | |
| 1788 | data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1789 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1790 | assert_string_equal(val, "text"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1791 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1792 | |
| 1793 | data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1794 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1795 | assert_string_equal(val, "text"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1796 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1797 | |
| 1798 | data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1799 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1800 | assert_string_equal("", val); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1801 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1802 | } |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1803 | |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1804 | static void |
| 1805 | test_type_elem(void **state) |
| 1806 | { |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1807 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1808 | struct lysp_type type = {0}; |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1809 | |
| 1810 | /* max subelems */ |
| 1811 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1812 | "<type name=\"type-name\">\n" |
| 1813 | " <base name=\"base-name\"/>\n" |
| 1814 | " <bit name=\"bit\"/>\n" |
| 1815 | " <enum name=\"enum\"/>\n" |
| 1816 | " <fraction-digits value=\"2\"/>\n" |
| 1817 | " <length value=\"length\"/>\n" |
| 1818 | " <path value=\"/path\"/>\n" |
| 1819 | " <pattern value=\"pattern\"/>\n" |
| 1820 | " <range value=\"range\" />\n" |
| 1821 | " <require-instance value=\"true\"/>\n" |
| 1822 | " <type name=\"sub-type-name\"/>\n" |
| 1823 | EXT_SUBELEM |
| 1824 | "</type>" |
| 1825 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1826 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1827 | assert_string_equal(type.name, "type-name"); |
| 1828 | assert_string_equal(*type.bases, "base-name"); |
| 1829 | assert_string_equal(type.bits->name, "bit"); |
| 1830 | assert_string_equal(type.enums->name, "enum"); |
| 1831 | assert_int_equal(type.fraction_digits, 2); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1832 | CHECK_LYSP_RESTR(type.length, "length", NULL, |
| 1833 | NULL, NULL, 0, NULL); |
Michal Vasko | cb8c6d4 | 2020-10-16 11:58:30 +0200 | [diff] [blame] | 1834 | assert_string_equal(type.path->expr, "/path"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1835 | CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL, |
| 1836 | NULL, NULL, 0, NULL); |
| 1837 | CHECK_LYSP_RESTR(type.range, "range", NULL, |
| 1838 | NULL, NULL, 0, NULL); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1839 | assert_int_equal(type.require_instance, 1); |
| 1840 | assert_string_equal(type.types->name, "sub-type-name"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1841 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_TYPE); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1842 | assert_true(type.flags & LYS_SET_BASE); |
| 1843 | assert_true(type.flags & LYS_SET_BIT); |
| 1844 | assert_true(type.flags & LYS_SET_ENUM); |
| 1845 | assert_true(type.flags & LYS_SET_FRDIGITS); |
| 1846 | assert_true(type.flags & LYS_SET_LENGTH); |
| 1847 | assert_true(type.flags & LYS_SET_PATH); |
| 1848 | assert_true(type.flags & LYS_SET_PATTERN); |
| 1849 | assert_true(type.flags & LYS_SET_RANGE); |
| 1850 | assert_true(type.flags & LYS_SET_REQINST); |
| 1851 | assert_true(type.flags & LYS_SET_TYPE); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1852 | lysp_type_free(&fctx, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1853 | memset(&type, 0, sizeof(type)); |
| 1854 | |
| 1855 | /* min subelems */ |
| 1856 | data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1857 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1858 | lysp_type_free(&fctx, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1859 | memset(&type, 0, sizeof(type)); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1860 | } |
| 1861 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1862 | static void |
| 1863 | test_max_elems_elem(void **state) |
| 1864 | { |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1865 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1866 | struct lysp_node_list list = {0}; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1867 | struct lysp_refine refine = {0}; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1868 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1869 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1870 | assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1871 | assert_int_equal(refine.max, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1872 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1873 | |
| 1874 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1875 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1876 | CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1877 | |
| 1878 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1879 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1880 | CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1881 | |
| 1882 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1883 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1884 | CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1885 | |
| 1886 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1887 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1888 | CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1889 | } |
| 1890 | |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1891 | static void |
| 1892 | test_min_elems_elem(void **state) |
| 1893 | { |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1894 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 1895 | struct lysp_node_leaflist llist = {0}; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1896 | |
| 1897 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1898 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1899 | CHECK_LOG_CTX("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1900 | |
| 1901 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1902 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1903 | CHECK_LOG_CTX("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1904 | |
| 1905 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1906 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1907 | CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1908 | |
| 1909 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1910 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1911 | CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1914 | static void |
| 1915 | test_ordby_elem(void **state) |
| 1916 | { |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1917 | const char *data; |
| 1918 | uint16_t flags = 0; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1919 | |
| 1920 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1921 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1922 | assert_true(flags & LYS_ORDBY_USER); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1923 | |
| 1924 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1925 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
| 1926 | CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. " |
| 1927 | "Valid values are \"system\" and \"user\".", "Line number 1."); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1928 | } |
| 1929 | |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1930 | static void |
| 1931 | test_any_elem(void **state) |
| 1932 | { |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1933 | const char *data; |
| 1934 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1935 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1936 | struct lysp_node_anydata *parsed = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1937 | uint16_t flags; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1938 | |
| 1939 | /* anyxml max subelems */ |
| 1940 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1941 | "<anyxml name=\"any-name\">\n" |
| 1942 | " <config value=\"true\" />\n" |
| 1943 | " <description><text>desc</text></description>\n" |
| 1944 | " <if-feature name=\"feature\" />\n" |
| 1945 | " <mandatory value=\"true\" />\n" |
| 1946 | " <must condition=\"must-cond\" />\n" |
| 1947 | " <reference><text>ref</text></reference>\n" |
| 1948 | " <status value=\"deprecated\"/>\n" |
| 1949 | " <when condition=\"when-cond\"/>\n" |
| 1950 | EXT_SUBELEM |
| 1951 | "</anyxml>" |
| 1952 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1953 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1954 | parsed = (struct lysp_node_anydata *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1955 | flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC; |
| 1956 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 1957 | "any-name", 0, LYS_ANYXML, 0, "ref", 1); |
| 1958 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1959 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1960 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYXML); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1961 | lysp_node_free(&fctx, siblings); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1962 | siblings = NULL; |
| 1963 | |
| 1964 | /* anydata max subelems */ |
| 1965 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1966 | "<anydata name=\"any-name\">\n" |
| 1967 | " <config value=\"true\" />\n" |
| 1968 | " <description><text>desc</text></description>\n" |
| 1969 | " <if-feature name=\"feature\" />\n" |
| 1970 | " <mandatory value=\"true\" />\n" |
| 1971 | " <must condition=\"must-cond\" />\n" |
| 1972 | " <reference><text>ref</text></reference>\n" |
| 1973 | " <status value=\"deprecated\"/>\n" |
| 1974 | " <when condition=\"when-cond\"/>\n" |
| 1975 | EXT_SUBELEM |
| 1976 | "</anydata>" |
| 1977 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1978 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1979 | parsed = (struct lysp_node_anydata *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1980 | flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC; |
| 1981 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 1982 | "any-name", 0, LYS_ANYDATA, 0, "ref", 1); |
| 1983 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1984 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 1985 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYDATA); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1986 | lysp_node_free(&fctx, siblings); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1987 | siblings = NULL; |
| 1988 | |
| 1989 | /* min subelems */ |
| 1990 | node_meta.parent = (void *)0x10; |
| 1991 | data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1992 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1993 | parsed = (struct lysp_node_anydata *)siblings; |
| 1994 | assert_ptr_equal(parsed->parent, node_meta.parent); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1995 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 1996 | "any-name", 0, LYS_ANYDATA, 1, NULL, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1997 | lysp_node_free(&fctx, siblings); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1998 | } |
| 1999 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2000 | static void |
| 2001 | test_leaf_elem(void **state) |
| 2002 | { |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2003 | const char *data; |
| 2004 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2005 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2006 | struct lysp_node_leaf *parsed = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2007 | uint16_t flags; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2008 | |
| 2009 | /* max elements */ |
| 2010 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2011 | "<leaf name=\"leaf\">\n" |
| 2012 | " <config value=\"true\" />\n" |
| 2013 | " <default value=\"def-val\"/>\n" |
| 2014 | " <description><text>desc</text></description>\n" |
| 2015 | " <if-feature name=\"feature\" />\n" |
| 2016 | " <mandatory value=\"true\" />\n" |
| 2017 | " <must condition=\"must-cond\" />\n" |
| 2018 | " <reference><text>ref</text></reference>\n" |
| 2019 | " <status value=\"deprecated\"/>\n" |
| 2020 | " <type name=\"type\"/>\n" |
| 2021 | " <units name=\"uni\"/>\n" |
| 2022 | " <when condition=\"when-cond\"/>\n" |
| 2023 | EXT_SUBELEM |
| 2024 | "</leaf>" |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2025 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2026 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2027 | parsed = (struct lysp_node_leaf *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2028 | flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC; |
| 2029 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2030 | "leaf", 0, LYS_LEAF, 0, "ref", 1); |
| 2031 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2032 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2033 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2034 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2035 | assert_string_equal(parsed->type.name, "type"); |
| 2036 | assert_string_equal(parsed->units, "uni"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2037 | assert_string_equal(parsed->dflt.str, "def-val"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2038 | lysp_node_free(&fctx, siblings); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2039 | siblings = NULL; |
| 2040 | |
| 2041 | /* min elements */ |
| 2042 | data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2043 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2044 | parsed = (struct lysp_node_leaf *)siblings; |
| 2045 | assert_string_equal(parsed->name, "leaf"); |
| 2046 | assert_string_equal(parsed->type.name, "type"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2047 | lysp_node_free(&fctx, siblings); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2048 | siblings = NULL; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2049 | } |
| 2050 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2051 | static void |
| 2052 | test_leaf_list_elem(void **state) |
| 2053 | { |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2054 | const char *data; |
| 2055 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2056 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2057 | struct lysp_node_leaflist *parsed = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2058 | uint16_t flags; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2059 | |
| 2060 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2061 | "<leaf-list name=\"llist\">\n" |
| 2062 | " <config value=\"true\" />\n" |
| 2063 | " <default value=\"def-val0\"/>\n" |
| 2064 | " <default value=\"def-val1\"/>\n" |
| 2065 | " <description><text>desc</text></description>\n" |
| 2066 | " <if-feature name=\"feature\"/>\n" |
| 2067 | " <max-elements value=\"5\"/>\n" |
| 2068 | " <must condition=\"must-cond\"/>\n" |
| 2069 | " <ordered-by value=\"user\" />\n" |
| 2070 | " <reference><text>ref</text></reference>\n" |
| 2071 | " <status value=\"current\"/>\n" |
| 2072 | " <type name=\"type\"/>\n" |
| 2073 | " <units name=\"uni\"/>\n" |
| 2074 | " <when condition=\"when-cond\"/>\n" |
| 2075 | EXT_SUBELEM |
| 2076 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2077 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2078 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2079 | parsed = (struct lysp_node_leaflist *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2080 | flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX; |
| 2081 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2082 | "llist", 0, LYS_LEAFLIST, 0, "ref", 1); |
| 2083 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2084 | assert_string_equal(parsed->dflts[0].str, "def-val0"); |
| 2085 | assert_string_equal(parsed->dflts[1].str, "def-val1"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2086 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2087 | assert_int_equal(parsed->max, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2088 | assert_string_equal(parsed->type.name, "type"); |
| 2089 | assert_string_equal(parsed->units, "uni"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2090 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2091 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2092 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2093 | siblings = NULL; |
| 2094 | |
| 2095 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2096 | "<leaf-list name=\"llist\">\n" |
| 2097 | " <config value=\"true\" />\n" |
| 2098 | " <description><text>desc</text></description>\n" |
| 2099 | " <if-feature name=\"feature\"/>\n" |
| 2100 | " <min-elements value=\"5\"/>\n" |
| 2101 | " <must condition=\"must-cond\"/>\n" |
| 2102 | " <ordered-by value=\"user\" />\n" |
| 2103 | " <reference><text>ref</text></reference>\n" |
| 2104 | " <status value=\"current\"/>\n" |
| 2105 | " <type name=\"type\"/>\n" |
| 2106 | " <units name=\"uni\"/>\n" |
| 2107 | " <when condition=\"when-cond\"/>\n" |
| 2108 | EXT_SUBELEM |
| 2109 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2110 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2111 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2112 | parsed = (struct lysp_node_leaflist *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2113 | flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN; |
| 2114 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2115 | "llist", 0, LYS_LEAFLIST, 0, "ref", 1); |
| 2116 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
| 2117 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2118 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2119 | assert_int_equal(parsed->min, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2120 | assert_string_equal(parsed->type.name, "type"); |
| 2121 | assert_string_equal(parsed->units, "uni"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2122 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2123 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2124 | siblings = NULL; |
| 2125 | |
| 2126 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2127 | "<leaf-list name=\"llist\">\n" |
| 2128 | " <config value=\"true\" />\n" |
| 2129 | " <description><text>desc</text></description>\n" |
| 2130 | " <if-feature name=\"feature\"/>\n" |
| 2131 | " <max-elements value=\"15\"/>\n" |
| 2132 | " <min-elements value=\"5\"/>\n" |
| 2133 | " <must condition=\"must-cond\"/>\n" |
| 2134 | " <ordered-by value=\"user\" />\n" |
| 2135 | " <reference><text>ref</text></reference>\n" |
| 2136 | " <status value=\"current\"/>\n" |
| 2137 | " <type name=\"type\"/>\n" |
| 2138 | " <units name=\"uni\"/>\n" |
| 2139 | " <when condition=\"when-cond\"/>\n" |
| 2140 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2141 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2142 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2143 | parsed = (struct lysp_node_leaflist *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2144 | flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX; |
| 2145 | CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1, |
| 2146 | "llist", 0, LYS_LEAFLIST, 0, "ref", 1); |
| 2147 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
| 2148 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2149 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2150 | assert_int_equal(parsed->min, 5); |
| 2151 | assert_int_equal(parsed->max, 15); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2152 | assert_string_equal(parsed->type.name, "type"); |
| 2153 | assert_string_equal(parsed->units, "uni"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2154 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2155 | siblings = NULL; |
| 2156 | |
| 2157 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2158 | "<leaf-list name=\"llist\">\n" |
| 2159 | " <type name=\"type\"/>\n" |
| 2160 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2161 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2162 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2163 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2164 | assert_string_equal(parsed->name, "llist"); |
| 2165 | assert_string_equal(parsed->type.name, "type"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2166 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2167 | siblings = NULL; |
| 2168 | |
| 2169 | /* invalid combinations */ |
| 2170 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2171 | "<leaf-list name=\"llist\">\n" |
| 2172 | " <max-elements value=\"5\"/>\n" |
| 2173 | " <min-elements value=\"15\"/>\n" |
| 2174 | " <type name=\"type\"/>" |
| 2175 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2176 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2177 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID); |
| 2178 | CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4."); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2179 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2180 | siblings = NULL; |
| 2181 | |
| 2182 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2183 | "<leaf-list name=\"llist\">\n" |
| 2184 | " <default value=\"def-val1\"/>\n" |
| 2185 | " <min-elements value=\"15\"/>\n" |
| 2186 | " <type name=\"type\"/>\n" |
| 2187 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2188 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2189 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID); |
| 2190 | CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5."); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2191 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2192 | siblings = NULL; |
| 2193 | |
| 2194 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2195 | "<leaf-list name=\"llist\">" |
| 2196 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2197 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2198 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID); |
| 2199 | CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1."); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2200 | lysp_node_free(&fctx, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2201 | siblings = NULL; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2202 | } |
| 2203 | |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2204 | static void |
| 2205 | test_presence_elem(void **state) |
| 2206 | { |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2207 | const char *data; |
| 2208 | const char *val; |
| 2209 | |
| 2210 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2211 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2212 | assert_string_equal(val, "presence-val"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2213 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2214 | |
| 2215 | data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2216 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 2217 | CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1."); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2218 | } |
| 2219 | |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2220 | static void |
| 2221 | test_key_elem(void **state) |
| 2222 | { |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2223 | const char *data; |
| 2224 | const char *val; |
| 2225 | |
| 2226 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2227 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2228 | assert_string_equal(val, "key-value"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2229 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2230 | |
| 2231 | data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2232 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 2233 | CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1."); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2234 | } |
| 2235 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2236 | static void |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2237 | test_uses_elem(void **state) |
| 2238 | { |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2239 | const char *data; |
| 2240 | struct lysp_node *siblings = NULL; |
| 2241 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2242 | struct lysp_node_uses *parsed = NULL; |
| 2243 | |
| 2244 | /* max subelems */ |
| 2245 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2246 | "<uses name=\"uses-name\">\n" |
| 2247 | " <when condition=\"cond\" />\n" |
| 2248 | " <if-feature name=\"feature\" />\n" |
| 2249 | " <status value=\"obsolete\" />\n" |
| 2250 | " <description><text>desc</text></description>\n" |
| 2251 | " <reference><text>ref</text></reference>\n" |
| 2252 | " <refine target-node=\"target\"/>\n" |
| 2253 | " <augment target-node=\"target\" />\n" |
| 2254 | EXT_SUBELEM |
| 2255 | "</uses>" |
| 2256 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2257 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2258 | parsed = (struct lysp_node_uses *)&siblings[0]; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2259 | CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1, |
| 2260 | "uses-name", 0, LYS_USES, 0, "ref", 1); |
| 2261 | CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2262 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2263 | assert_string_equal(parsed->refines->nodeid, "target"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2264 | assert_string_equal(parsed->augments->nodeid, "target"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2265 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_USES); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2266 | lysp_node_free(&fctx, siblings); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2267 | siblings = NULL; |
| 2268 | |
| 2269 | /* min subelems */ |
| 2270 | data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2271 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2272 | assert_string_equal(siblings[0].name, "uses-name"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2273 | lysp_node_free(&fctx, siblings); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2274 | siblings = NULL; |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2275 | } |
| 2276 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2277 | static void |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2278 | test_list_elem(void **state) |
| 2279 | { |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2280 | const char *data; |
| 2281 | struct lysp_node *siblings = NULL; |
| 2282 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2283 | struct lysp_node_list *parsed = NULL; |
| 2284 | |
| 2285 | /* max subelems */ |
| 2286 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2287 | "<list name=\"list-name\">\n" |
| 2288 | " <when condition=\"when\"/>\n" |
| 2289 | " <if-feature name=\"iff\"/>\n" |
| 2290 | " <must condition=\"must-cond\"/>\n" |
| 2291 | " <key value=\"key\"/>\n" |
| 2292 | " <unique tag=\"utag\"/>\n" |
| 2293 | " <config value=\"true\"/>\n" |
| 2294 | " <min-elements value=\"10\"/>\n" |
| 2295 | " <ordered-by value=\"user\"/>\n" |
| 2296 | " <status value=\"deprecated\"/>\n" |
| 2297 | " <description><text>desc</text></description>\n" |
| 2298 | " <reference><text>ref</text></reference>\n" |
| 2299 | " <anydata name=\"anyd\"/>\n" |
| 2300 | " <anyxml name=\"anyx\"/>\n" |
| 2301 | " <container name=\"cont\"/>\n" |
| 2302 | " <choice name=\"choice\"/>\n" |
| 2303 | " <action name=\"action\"/>\n" |
| 2304 | " <grouping name=\"grp\"/>\n" |
| 2305 | " <notification name=\"notf\"/>\n" |
| 2306 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2307 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2308 | " <list name=\"sub-list\"/>\n" |
| 2309 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2310 | " <uses name=\"uses-name\"/>\n" |
| 2311 | EXT_SUBELEM |
| 2312 | "</list>" |
| 2313 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2314 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2315 | parsed = (struct lysp_node_list *)&siblings[0]; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2316 | assert_string_equal(parsed->child->name, "anyd"); |
| 2317 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2318 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2319 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2320 | assert_string_equal(parsed->child->next->next->name, "cont"); |
| 2321 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2322 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2323 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2324 | assert_string_equal(parsed->child->next->next->next->next->name, "leaf"); |
| 2325 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF); |
| 2326 | assert_string_equal(parsed->child->next->next->next->next->next->name, "llist"); |
| 2327 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2328 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list"); |
| 2329 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2330 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2331 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2332 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2333 | uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN; |
| 2334 | |
| 2335 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2336 | "list-name", 0, LYS_LIST, 0, "ref", 1); |
| 2337 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
| 2338 | CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2339 | assert_string_equal(parsed->groupings->name, "grp"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2340 | assert_string_equal(parsed->actions->name, "action"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2341 | assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2342 | assert_string_equal(parsed->notifs->name, "notf"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2343 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2344 | assert_string_equal(parsed->key, "key"); |
| 2345 | assert_int_equal(parsed->min, 10); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2346 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2347 | assert_string_equal(parsed->uniques->str, "utag"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2348 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LIST); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2349 | lysp_node_free(&fctx, siblings); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2350 | ly_set_erase(&YCTX->tpdfs_nodes, NULL); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2351 | siblings = NULL; |
| 2352 | |
| 2353 | /* min subelems */ |
| 2354 | data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2355 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2356 | parsed = (struct lysp_node_list *)&siblings[0]; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2357 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2358 | "list-name", 0, LYS_LIST, 0, NULL, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2359 | lysp_node_free(&fctx, siblings); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2360 | siblings = NULL; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2361 | } |
| 2362 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2363 | static void |
| 2364 | test_notification_elem(void **state) |
| 2365 | { |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2366 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2367 | struct lysp_node_notif *notifs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2368 | struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)¬ifs}; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2369 | |
| 2370 | /* max subelems */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2371 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2372 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2373 | "<notification name=\"notif-name\">\n" |
| 2374 | " <anydata name=\"anyd\"/>\n" |
| 2375 | " <anyxml name=\"anyx\"/>\n" |
| 2376 | " <description><text>desc</text></description>\n" |
| 2377 | " <if-feature name=\"iff\"/>\n" |
| 2378 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2379 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2380 | " <list name=\"sub-list\"/>\n" |
| 2381 | " <must condition=\"cond\"/>\n" |
| 2382 | " <reference><text>ref</text></reference>\n" |
| 2383 | " <status value=\"deprecated\"/>\n" |
| 2384 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2385 | " <uses name=\"uses-name\"/>\n" |
| 2386 | " <container name=\"cont\"/>\n" |
| 2387 | " <choice name=\"choice\"/>\n" |
| 2388 | " <grouping name=\"grp\"/>\n" |
| 2389 | EXT_SUBELEM |
| 2390 | "</notification>" |
| 2391 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2392 | assert_int_equal(test_element_helper(state, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2393 | assert_string_equal(notifs->name, "notif-name"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2394 | assert_string_equal(notifs->child->name, "anyd"); |
| 2395 | assert_int_equal(notifs->child->nodetype, LYS_ANYDATA); |
| 2396 | assert_string_equal(notifs->child->next->name, "anyx"); |
| 2397 | assert_int_equal(notifs->child->next->nodetype, LYS_ANYXML); |
| 2398 | assert_string_equal(notifs->child->next->next->name, "leaf"); |
| 2399 | assert_int_equal(notifs->child->next->next->nodetype, LYS_LEAF); |
| 2400 | assert_string_equal(notifs->child->next->next->next->name, "llist"); |
| 2401 | assert_int_equal(notifs->child->next->next->next->nodetype, LYS_LEAFLIST); |
| 2402 | assert_string_equal(notifs->child->next->next->next->next->name, "sub-list"); |
| 2403 | assert_int_equal(notifs->child->next->next->next->next->nodetype, LYS_LIST); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2404 | assert_true(notifs->flags & LYS_STATUS_DEPRC); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2405 | assert_string_equal(notifs->groupings->name, "grp"); |
| 2406 | assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2407 | assert_string_equal(notifs->child->next->next->next->next->next->name, "uses-name"); |
| 2408 | assert_int_equal(notifs->child->next->next->next->next->next->nodetype, LYS_USES); |
| 2409 | assert_string_equal(notifs->child->next->next->next->next->next->next->name, "cont"); |
| 2410 | assert_int_equal(notifs->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2411 | assert_int_equal(notifs->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2412 | assert_string_equal(notifs->child->next->next->next->next->next->next->next->name, "choice"); |
| 2413 | assert_null(notifs->child->next->next->next->next->next->next->next->next); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2414 | assert_string_equal(notifs->iffeatures[0].str, "iff"); |
| 2415 | assert_string_equal(notifs->musts->arg.str, "cond"); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2416 | assert_int_equal(notifs->nodetype, LYS_NOTIF); |
| 2417 | assert_null(notifs->parent); |
| 2418 | assert_string_equal(notifs->ref, "ref"); |
| 2419 | assert_string_equal(notifs->typedefs->name, "tpdf"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2420 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LY_STMT_NOTIFICATION); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2421 | lysp_node_free(&fctx, (struct lysp_node *)notifs); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2422 | notifs = NULL; |
| 2423 | |
| 2424 | /* min subelems */ |
| 2425 | data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2426 | assert_int_equal(test_element_helper(state, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2427 | assert_string_equal(notifs->name, "notif-name"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2428 | lysp_node_free(&fctx, (struct lysp_node *)notifs); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2429 | notifs = NULL; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | static void |
| 2433 | test_grouping_elem(void **state) |
| 2434 | { |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2435 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2436 | struct lysp_node_grp *grps = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2437 | struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps}; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2438 | |
| 2439 | /* max subelems */ |
| 2440 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2441 | "<grouping name=\"grp-name\">\n" |
| 2442 | " <anydata name=\"anyd\"/>\n" |
| 2443 | " <anyxml name=\"anyx\"/>\n" |
| 2444 | " <description><text>desc</text></description>\n" |
| 2445 | " <grouping name=\"sub-grp\"/>\n" |
| 2446 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2447 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2448 | " <list name=\"list\"/>\n" |
| 2449 | " <notification name=\"notf\"/>\n" |
| 2450 | " <reference><text>ref</text></reference>\n" |
| 2451 | " <status value=\"current\"/>\n" |
| 2452 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2453 | " <uses name=\"uses-name\"/>\n" |
| 2454 | " <action name=\"act\"/>\n" |
| 2455 | " <container name=\"cont\"/>\n" |
| 2456 | " <choice name=\"choice\"/>\n" |
| 2457 | EXT_SUBELEM |
| 2458 | "</grouping>" |
| 2459 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2460 | assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2461 | assert_string_equal(grps->name, "grp-name"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2462 | assert_string_equal(grps->child->name, "anyd"); |
| 2463 | assert_string_equal(grps->child->next->name, "anyx"); |
| 2464 | assert_string_equal(grps->child->next->next->name, "leaf"); |
| 2465 | assert_string_equal(grps->child->next->next->next->name, "llist"); |
| 2466 | assert_string_equal(grps->child->next->next->next->next->name, "list"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2467 | assert_string_equal(grps->dsc, "desc"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2468 | assert_true(grps->flags & LYS_STATUS_CURR); |
| 2469 | assert_string_equal(grps->groupings->name, "sub-grp"); |
| 2470 | assert_int_equal(grps->nodetype, LYS_GROUPING); |
| 2471 | assert_string_equal(grps->notifs->name, "notf"); |
| 2472 | assert_null(grps->parent); |
| 2473 | assert_string_equal(grps->ref, "ref"); |
| 2474 | assert_string_equal(grps->typedefs->name, "tpdf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2475 | assert_string_equal(grps->actions->name, "act"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2476 | assert_string_equal(grps->child->next->next->next->next->next->name, "uses-name"); |
| 2477 | assert_int_equal(grps->child->next->next->next->next->next->nodetype, LYS_USES); |
| 2478 | assert_string_equal(grps->child->next->next->next->next->next->next->name, "cont"); |
| 2479 | assert_int_equal(grps->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2480 | assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice"); |
| 2481 | assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2482 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LY_STMT_GROUPING); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2483 | lysp_node_free(&fctx, &grps->node); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2484 | grps = NULL; |
| 2485 | |
| 2486 | /* min subelems */ |
| 2487 | data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2488 | assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2489 | assert_string_equal(grps->name, "grp-name"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2490 | lysp_node_free(&fctx, &grps->node); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2491 | grps = NULL; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2492 | } |
| 2493 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2494 | static void |
| 2495 | test_container_elem(void **state) |
| 2496 | { |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2497 | const char *data; |
| 2498 | struct lysp_node *siblings = NULL; |
| 2499 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2500 | struct lysp_node_container *parsed = NULL; |
| 2501 | |
| 2502 | /* max subelems */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2503 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2504 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2505 | "<container name=\"cont-name\">\n" |
| 2506 | " <anydata name=\"anyd\"/>\n" |
| 2507 | " <anyxml name=\"anyx\"/>\n" |
| 2508 | " <config value=\"true\"/>\n" |
| 2509 | " <container name=\"subcont\"/>\n" |
| 2510 | " <description><text>desc</text></description>\n" |
| 2511 | " <grouping name=\"sub-grp\"/>\n" |
| 2512 | " <if-feature name=\"iff\"/>\n" |
| 2513 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2514 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2515 | " <list name=\"list\"/>\n" |
| 2516 | " <must condition=\"cond\"/>\n" |
| 2517 | " <notification name=\"notf\"/>\n" |
| 2518 | " <presence value=\"presence\"/>\n" |
| 2519 | " <reference><text>ref</text></reference>\n" |
| 2520 | " <status value=\"current\"/>\n" |
| 2521 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2522 | " <uses name=\"uses-name\"/>\n" |
| 2523 | " <when condition=\"when-cond\"/>\n" |
| 2524 | " <action name=\"act\"/>\n" |
| 2525 | " <choice name=\"choice\"/>\n" |
| 2526 | EXT_SUBELEM |
| 2527 | "</container>" |
| 2528 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2529 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2530 | parsed = (struct lysp_node_container *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2531 | uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR; |
| 2532 | |
| 2533 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2534 | "cont-name", 0, LYS_CONTAINER, 0, "ref", 1); |
| 2535 | CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL); |
| 2536 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
| 2537 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2538 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2539 | assert_string_equal(parsed->presence, "presence"); |
| 2540 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 2541 | assert_string_equal(parsed->groupings->name, "sub-grp"); |
| 2542 | assert_string_equal(parsed->child->name, "anyd"); |
| 2543 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2544 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2545 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2546 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 2547 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 2548 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 2549 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 2550 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 2551 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2552 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 2553 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 2554 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 2555 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2556 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 2557 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2558 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2559 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2560 | assert_string_equal(parsed->actions->name, "act"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2561 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CONTAINER); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2562 | lysp_node_free(&fctx, siblings); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2563 | ly_set_erase(&YCTX->tpdfs_nodes, NULL); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2564 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2565 | |
| 2566 | /* min subelems */ |
| 2567 | data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2568 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2569 | parsed = (struct lysp_node_container *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2570 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2571 | "cont-name", 0, LYS_CONTAINER, 0, NULL, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2572 | lysp_node_free(&fctx, siblings); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2573 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2574 | } |
| 2575 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2576 | static void |
| 2577 | test_case_elem(void **state) |
| 2578 | { |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2579 | const char *data; |
| 2580 | struct lysp_node *siblings = NULL; |
| 2581 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2582 | struct lysp_node_case *parsed = NULL; |
| 2583 | |
| 2584 | /* max subelems */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2585 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2586 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2587 | "<case name=\"case-name\">\n" |
| 2588 | " <anydata name=\"anyd\"/>\n" |
| 2589 | " <anyxml name=\"anyx\"/>\n" |
| 2590 | " <container name=\"subcont\"/>\n" |
| 2591 | " <description><text>desc</text></description>\n" |
| 2592 | " <if-feature name=\"iff\"/>\n" |
| 2593 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2594 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2595 | " <list name=\"list\"/>\n" |
| 2596 | " <reference><text>ref</text></reference>\n" |
| 2597 | " <status value=\"current\"/>\n" |
| 2598 | " <uses name=\"uses-name\"/>\n" |
| 2599 | " <when condition=\"when-cond\"/>\n" |
| 2600 | " <choice name=\"choice\"/>\n" |
| 2601 | EXT_SUBELEM |
| 2602 | "</case>" |
| 2603 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2604 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2605 | parsed = (struct lysp_node_case *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2606 | uint16_t flags = LYS_STATUS_CURR; |
| 2607 | |
| 2608 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2609 | "case-name", 0, LYS_CASE, 0, "ref", 1); |
| 2610 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2611 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2612 | assert_string_equal(parsed->child->name, "anyd"); |
| 2613 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2614 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2615 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2616 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 2617 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 2618 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 2619 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 2620 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 2621 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2622 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 2623 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 2624 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 2625 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2626 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 2627 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2628 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2629 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CASE); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2630 | lysp_node_free(&fctx, siblings); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2631 | siblings = NULL; |
| 2632 | |
| 2633 | /* min subelems */ |
| 2634 | data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2635 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2636 | parsed = (struct lysp_node_case *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2637 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2638 | "case-name", 0, LYS_CASE, 0, NULL, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2639 | lysp_node_free(&fctx, siblings); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2640 | siblings = NULL; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2641 | } |
| 2642 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2643 | static void |
| 2644 | test_choice_elem(void **state) |
| 2645 | { |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2646 | const char *data; |
| 2647 | struct lysp_node *siblings = NULL; |
| 2648 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2649 | struct lysp_node_choice *parsed = NULL; |
| 2650 | |
| 2651 | /* max subelems */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2652 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2653 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2654 | "<choice name=\"choice-name\">\n" |
| 2655 | " <anydata name=\"anyd\"/>\n" |
| 2656 | " <anyxml name=\"anyx\"/>\n" |
| 2657 | " <case name=\"sub-case\"/>\n" |
| 2658 | " <choice name=\"choice\"/>\n" |
| 2659 | " <config value=\"true\"/>\n" |
| 2660 | " <container name=\"subcont\"/>\n" |
| 2661 | " <default value=\"def\"/>\n" |
| 2662 | " <description><text>desc</text></description>\n" |
| 2663 | " <if-feature name=\"iff\"/>\n" |
| 2664 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2665 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2666 | " <list name=\"list\"/>\n" |
| 2667 | " <mandatory value=\"true\" />\n" |
| 2668 | " <reference><text>ref</text></reference>\n" |
| 2669 | " <status value=\"current\"/>\n" |
| 2670 | " <when condition=\"when-cond\"/>\n" |
| 2671 | EXT_SUBELEM |
| 2672 | "</choice>" |
| 2673 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2674 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2675 | parsed = (struct lysp_node_choice *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2676 | uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR; |
| 2677 | |
| 2678 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2679 | "choice-name", 0, LYS_CHOICE, 0, "ref", 1); |
| 2680 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2681 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2682 | assert_string_equal(parsed->child->name, "anyd"); |
| 2683 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2684 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2685 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2686 | assert_string_equal(parsed->child->next->next->name, "sub-case"); |
| 2687 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE); |
| 2688 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2689 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
| 2690 | assert_string_equal(parsed->child->next->next->next->next->name, "subcont"); |
| 2691 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2692 | assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf"); |
| 2693 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 2694 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist"); |
| 2695 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2696 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list"); |
| 2697 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2698 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2699 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CHOICE); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2700 | lysp_node_free(&fctx, siblings); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2701 | siblings = NULL; |
| 2702 | |
| 2703 | /* min subelems */ |
| 2704 | data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2705 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2706 | parsed = (struct lysp_node_choice *)siblings; |
| 2707 | assert_string_equal(parsed->name, "choice-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2708 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2709 | "choice-name", 0, LYS_CHOICE, 0, NULL, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2710 | lysp_node_free(&fctx, siblings); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2711 | siblings = NULL; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2712 | } |
| 2713 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2714 | static void |
| 2715 | test_inout_elem(void **state) |
| 2716 | { |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2717 | const char *data; |
Michal Vasko | 2a6c53f | 2021-09-22 12:20:05 +0200 | [diff] [blame] | 2718 | struct lysp_node_action_inout inout = {0}; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2719 | struct inout_meta inout_meta = {NULL, &inout}; |
| 2720 | |
| 2721 | /* max subelements */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2722 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2723 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2724 | "<input>\n" |
| 2725 | " <anydata name=\"anyd\"/>\n" |
| 2726 | " <anyxml name=\"anyx\"/>\n" |
| 2727 | " <choice name=\"choice\"/>\n" |
| 2728 | " <container name=\"subcont\"/>\n" |
| 2729 | " <grouping name=\"sub-grp\"/>\n" |
| 2730 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2731 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2732 | " <list name=\"list\"/>\n" |
| 2733 | " <must condition=\"cond\"/>\n" |
| 2734 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2735 | " <uses name=\"uses-name\"/>\n" |
| 2736 | EXT_SUBELEM |
| 2737 | "</input>" |
| 2738 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2739 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
| 2740 | CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1); |
| 2741 | CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2742 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 2743 | assert_string_equal(inout.groupings->name, "sub-grp"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2744 | assert_string_equal(inout.child->name, "anyd"); |
| 2745 | assert_int_equal(inout.child->nodetype, LYS_ANYDATA); |
| 2746 | assert_string_equal(inout.child->next->name, "anyx"); |
| 2747 | assert_int_equal(inout.child->next->nodetype, LYS_ANYXML); |
| 2748 | assert_string_equal(inout.child->next->next->name, "choice"); |
| 2749 | assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE); |
| 2750 | assert_string_equal(inout.child->next->next->next->name, "subcont"); |
| 2751 | assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER); |
| 2752 | assert_string_equal(inout.child->next->next->next->next->name, "leaf"); |
| 2753 | assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF); |
| 2754 | assert_string_equal(inout.child->next->next->next->next->next->name, "llist"); |
| 2755 | assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2756 | assert_string_equal(inout.child->next->next->next->next->next->next->name, "list"); |
| 2757 | assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2758 | assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2759 | assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2760 | assert_null(inout.child->next->next->next->next->next->next->next->next); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2761 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_INPUT); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2762 | lysp_node_free(&fctx, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2763 | memset(&inout, 0, sizeof inout); |
| 2764 | |
| 2765 | /* max subelements */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2766 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2767 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2768 | "<output>\n" |
| 2769 | " <anydata name=\"anyd\"/>\n" |
| 2770 | " <anyxml name=\"anyx\"/>\n" |
| 2771 | " <choice name=\"choice\"/>\n" |
| 2772 | " <container name=\"subcont\"/>\n" |
| 2773 | " <grouping name=\"sub-grp\"/>\n" |
| 2774 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2775 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2776 | " <list name=\"list\"/>\n" |
| 2777 | " <must condition=\"cond\"/>\n" |
| 2778 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2779 | " <uses name=\"uses-name\"/>\n" |
| 2780 | EXT_SUBELEM |
| 2781 | "</output>" |
| 2782 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2783 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
| 2784 | CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2785 | assert_string_equal(inout.musts->arg.str, "cond"); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2786 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 2787 | assert_string_equal(inout.groupings->name, "sub-grp"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2788 | assert_string_equal(inout.child->name, "anyd"); |
| 2789 | assert_int_equal(inout.child->nodetype, LYS_ANYDATA); |
| 2790 | assert_string_equal(inout.child->next->name, "anyx"); |
| 2791 | assert_int_equal(inout.child->next->nodetype, LYS_ANYXML); |
| 2792 | assert_string_equal(inout.child->next->next->name, "choice"); |
| 2793 | assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE); |
| 2794 | assert_string_equal(inout.child->next->next->next->name, "subcont"); |
| 2795 | assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER); |
| 2796 | assert_string_equal(inout.child->next->next->next->next->name, "leaf"); |
| 2797 | assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF); |
| 2798 | assert_string_equal(inout.child->next->next->next->next->next->name, "llist"); |
| 2799 | assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2800 | assert_string_equal(inout.child->next->next->next->next->next->next->name, "list"); |
| 2801 | assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2802 | assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2803 | assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2804 | assert_null(inout.child->next->next->next->next->next->next->next->next); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2805 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_OUTPUT); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2806 | lysp_node_free(&fctx, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2807 | memset(&inout, 0, sizeof inout); |
| 2808 | |
| 2809 | /* min subelems */ |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2810 | data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2811 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2812 | lysp_node_free(&fctx, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2813 | memset(&inout, 0, sizeof inout); |
| 2814 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2815 | data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2816 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2817 | lysp_node_free(&fctx, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2818 | memset(&inout, 0, sizeof inout); |
| 2819 | |
| 2820 | /* invalid combinations */ |
| 2821 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2822 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2823 | lysp_node_free(&fctx, (struct lysp_node *)&inout); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2824 | CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1."); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2825 | memset(&inout, 0, sizeof inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2826 | } |
| 2827 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2828 | static void |
| 2829 | test_action_elem(void **state) |
| 2830 | { |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2831 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2832 | struct lysp_node_action *actions = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2833 | struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions}; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2834 | uint16_t flags; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2835 | |
| 2836 | /* max subelems */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2837 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2838 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2839 | "<action name=\"act\">\n" |
| 2840 | " <description><text>desc</text></description>\n" |
| 2841 | " <grouping name=\"grouping\"/>\n" |
| 2842 | " <if-feature name=\"iff\"/>\n" |
| 2843 | " <input><uses name=\"uses-name\"/></input>\n" |
| 2844 | " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n" |
| 2845 | " <reference><text>ref</text></reference>\n" |
| 2846 | " <status value=\"deprecated\"/>\n" |
| 2847 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2848 | EXT_SUBELEM |
| 2849 | "</action>" |
| 2850 | ELEMENT_WRAPPER_END; |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2851 | /* there must be parent for action */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2852 | act_meta.parent = (void *)1; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2853 | assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2854 | act_meta.parent = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2855 | flags = LYS_STATUS_DEPRC; |
| 2856 | CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\ |
| 2857 | 1, 0, 0, 0,\ |
| 2858 | 1, 0,\ |
| 2859 | "act", LYS_ACTION, \ |
| 2860 | 1, 0, 0, 1,\ |
| 2861 | 1, 0,\ |
| 2862 | 1, "ref", 1); |
| 2863 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2864 | assert_string_equal(actions->iffeatures[0].str, "iff"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2865 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 2866 | assert_string_equal(actions->groupings->name, "grouping"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2867 | assert_string_equal(actions->output.musts->arg.str, "cond"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2868 | assert_string_equal(actions->input.child->name, "uses-name"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2869 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_ACTION); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2870 | lysp_node_free(&fctx, (struct lysp_node *)actions); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2871 | actions = NULL; |
| 2872 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2873 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 2874 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2875 | "<rpc name=\"act\">\n" |
| 2876 | " <description><text>desc</text></description>\n" |
| 2877 | " <grouping name=\"grouping\"/>\n" |
| 2878 | " <if-feature name=\"iff\"/>\n" |
| 2879 | " <input><uses name=\"uses-name\"/></input>\n" |
| 2880 | " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n" |
| 2881 | " <reference><text>ref</text></reference>\n" |
| 2882 | " <status value=\"deprecated\"/>\n" |
| 2883 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2884 | EXT_SUBELEM |
| 2885 | "</rpc>" |
| 2886 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2887 | assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS); |
| 2888 | flags = LYS_STATUS_DEPRC; |
| 2889 | CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\ |
| 2890 | 1, 0, 0, 0,\ |
| 2891 | 1, 0,\ |
| 2892 | "act", LYS_RPC, \ |
| 2893 | 1, 0, 0, 1,\ |
| 2894 | 1, 0,\ |
| 2895 | 0, "ref", 1); |
| 2896 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2897 | assert_string_equal(actions->iffeatures[0].str, "iff"); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 2898 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 2899 | assert_string_equal(actions->groupings->name, "grouping"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2900 | assert_string_equal(actions->input.child->name, "uses-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2901 | assert_string_equal(actions->output.musts->arg.str, "cond"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2902 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_RPC); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2903 | lysp_node_free(&fctx, (struct lysp_node *)actions); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 2904 | actions = NULL; |
| 2905 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2906 | /* min subelems */ |
| 2907 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2908 | assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2909 | assert_string_equal(actions->name, "act"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2910 | lysp_node_free(&fctx, (struct lysp_node *)actions); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2911 | actions = NULL; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2912 | } |
| 2913 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2914 | static void |
| 2915 | test_augment_elem(void **state) |
| 2916 | { |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2917 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2918 | struct lysp_node_augment *augments = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2919 | struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments}; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2920 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 2921 | PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2922 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2923 | "<augment target-node=\"target\">\n" |
| 2924 | " <action name=\"action\"/>\n" |
| 2925 | " <anydata name=\"anyd\"/>\n" |
| 2926 | " <anyxml name=\"anyx\"/>\n" |
| 2927 | " <case name=\"case\"/>\n" |
| 2928 | " <choice name=\"choice\"/>\n" |
| 2929 | " <container name=\"subcont\"/>\n" |
| 2930 | " <description><text>desc</text></description>\n" |
| 2931 | " <if-feature name=\"iff\"/>\n" |
| 2932 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2933 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2934 | " <list name=\"list\"/>\n" |
| 2935 | " <notification name=\"notif\"/>\n" |
| 2936 | " <reference><text>ref</text></reference>\n" |
| 2937 | " <status value=\"current\"/>\n" |
| 2938 | " <uses name=\"uses\"/>\n" |
| 2939 | " <when condition=\"when-cond\"/>\n" |
| 2940 | EXT_SUBELEM |
| 2941 | "</augment>" |
| 2942 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2943 | assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2944 | assert_string_equal(augments->nodeid, "target"); |
| 2945 | assert_null(augments->parent); |
| 2946 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 2947 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 2948 | assert_string_equal(augments->dsc, "desc"); |
| 2949 | assert_string_equal(augments->ref, "ref"); |
| 2950 | assert_string_equal(augments->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2951 | assert_string_equal(augments->iffeatures[0].str, "iff"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2952 | assert_string_equal(augments->child->name, "anyd"); |
| 2953 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 2954 | assert_string_equal(augments->child->next->name, "anyx"); |
| 2955 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 2956 | assert_string_equal(augments->child->next->next->name, "case"); |
| 2957 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 2958 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 2959 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 2960 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 2961 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2962 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 2963 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 2964 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 2965 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2966 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 2967 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2968 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 2969 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2970 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 2971 | assert_string_equal(augments->actions->name, "action"); |
| 2972 | assert_string_equal(augments->notifs->name, "notif"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2973 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2974 | lysp_node_free(&fctx, (struct lysp_node *)augments); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2975 | augments = NULL; |
| 2976 | |
| 2977 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2978 | assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2979 | assert_string_equal(augments->nodeid, "target"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2980 | lysp_node_free(&fctx, (struct lysp_node *)augments); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2981 | augments = NULL; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2982 | } |
| 2983 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2984 | static void |
| 2985 | test_deviate_elem(void **state) |
| 2986 | { |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2987 | const char *data; |
| 2988 | struct lysp_deviate *deviates = NULL; |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2989 | |
| 2990 | /* invalid arguments */ |
| 2991 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2992 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 2993 | CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. " |
| 2994 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2995 | deviates = NULL; |
| 2996 | |
| 2997 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2998 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 2999 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. " |
| 3000 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3001 | deviates = NULL; |
| 3002 | |
| 3003 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3004 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3005 | CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. " |
| 3006 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3007 | deviates = NULL; |
| 3008 | |
| 3009 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3010 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3011 | CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. " |
| 3012 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3013 | deviates = NULL; |
| 3014 | |
| 3015 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3016 | "<deviate value=\"not-supported\">\n" |
| 3017 | " <must condition=\"c\"/>\n" |
| 3018 | "</deviate>" |
| 3019 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3020 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3021 | CHECK_LOG_CTX("Deviate of this type doesn't allow \"must\" as it's sub-element.", "Line number 2."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3022 | } |
| 3023 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3024 | static void |
| 3025 | test_deviation_elem(void **state) |
| 3026 | { |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3027 | const char *data; |
| 3028 | struct lysp_deviation *deviations = NULL; |
| 3029 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3030 | /* invalid */ |
| 3031 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3032 | assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3033 | CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1."); |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 3034 | } |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3035 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3036 | static struct lysp_module * |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3037 | mod_renew(struct lysp_yin_ctx *ctx) |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3038 | { |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3039 | struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx; |
| 3040 | struct lysp_module *pmod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3041 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3042 | lys_module_free(&fctx, PARSER_CUR_PMOD(ctx)->mod, 0); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3043 | pmod = calloc(1, sizeof *pmod); |
| 3044 | ctx->parsed_mods->objs[0] = pmod; |
| 3045 | pmod->mod = calloc(1, sizeof *pmod->mod); |
| 3046 | pmod->mod->parsed = pmod; |
| 3047 | pmod->mod->ctx = ly_ctx; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3048 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3049 | fctx.mod = pmod->mod; |
| 3050 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3051 | return pmod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3052 | } |
| 3053 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3054 | static void |
| 3055 | test_module_elem(void **state) |
| 3056 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3057 | const char *data; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3058 | struct lysp_module *lysp_mod = mod_renew(YCTX); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3059 | |
| 3060 | /* max subelems */ |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3061 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3062 | " <yang-version value=\"1.1\"/>\n" |
| 3063 | " <namespace uri=\"ns\"/>\n" |
| 3064 | " <prefix value=\"pref\"/>\n" |
| 3065 | " <include module=\"b-mod\"/>\n" |
| 3066 | " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3067 | " <organization><text>org</text></organization>\n" |
| 3068 | " <contact><text>contact</text></contact>\n" |
| 3069 | " <description><text>desc</text></description>\n" |
| 3070 | " <reference><text>ref</text></reference>\n" |
| 3071 | " <revision date=\"2019-02-02\"/>\n" |
| 3072 | " <anydata name=\"anyd\"/>\n" |
| 3073 | " <anyxml name=\"anyx\"/>\n" |
| 3074 | " <choice name=\"choice\"/>\n" |
| 3075 | " <container name=\"cont\"/>\n" |
| 3076 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3077 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3078 | " <list name=\"sub-list\"/>\n" |
| 3079 | " <uses name=\"uses-name\"/>\n" |
| 3080 | " <augment target-node=\"target\"/>\n" |
| 3081 | " <deviation target-node=\"target\">\n" |
| 3082 | " <deviate value=\"not-supported\"/>\n" |
| 3083 | " </deviation>\n" |
| 3084 | " <extension name=\"ext\"/>\n" |
| 3085 | " <feature name=\"feature\"/>\n" |
| 3086 | " <grouping name=\"grp\"/>\n" |
| 3087 | " <identity name=\"ident-name\"/>\n" |
| 3088 | " <notification name=\"notf\"/>\n" |
| 3089 | " <rpc name=\"rpc-name\"/>\n" |
| 3090 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3091 | EXT_SUBELEM "\n" |
| 3092 | "</module>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3093 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3094 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3095 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3096 | assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3097 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 3098 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 3099 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 3100 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 3101 | assert_null(lysp_mod->mod->filepath); |
| 3102 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 3103 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 3104 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 3105 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3106 | assert_int_equal(lysp_mod->version, LYS_VERSION_1_1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3107 | CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod", |
| 3108 | "imp-pref", NULL, ""); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3109 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 3110 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 3111 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 3112 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 3113 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 3114 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 3115 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 3116 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 3117 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 3118 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 3119 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 3120 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 3121 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 3122 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3123 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 3124 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3125 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 3126 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3127 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3128 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3129 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3130 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3131 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 3132 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 3133 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 3134 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 3135 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 3136 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LY_STMT_MODULE); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3137 | |
| 3138 | /* min subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3139 | ly_in_free(UTEST_IN, 0); |
| 3140 | lyxml_ctx_free(YCTX->xmlctx); |
| 3141 | lysp_mod = mod_renew(YCTX); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3142 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3143 | " <namespace uri=\"ns\"/>\n" |
| 3144 | " <prefix value=\"pref\"/>\n" |
| 3145 | " <yang-version value=\"1.1\"/>\n" |
| 3146 | "</module>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3147 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3148 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3149 | assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3150 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3151 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3152 | /* incorrect subelem order */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3153 | ly_in_free(UTEST_IN, 0); |
| 3154 | lyxml_ctx_free(YCTX->xmlctx); |
| 3155 | lysp_mod = mod_renew(YCTX); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3156 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3157 | " <feature name=\"feature\"/>\n" |
| 3158 | " <namespace uri=\"ns\"/>\n" |
| 3159 | " <prefix value=\"pref\"/>\n" |
| 3160 | " <yang-version value=\"1.1\"/>\n" |
| 3161 | "</module>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3162 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3163 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3164 | assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID); |
| 3165 | CHECK_LOG_CTX("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\".", "Line number 3."); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3166 | } |
| 3167 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3168 | static struct lysp_submodule * |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3169 | submod_renew(struct lysp_yin_ctx *ctx, const char *belongs_to) |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3170 | { |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3171 | struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx; |
| 3172 | struct lysp_submodule *submod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3173 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3174 | lys_module_free(&fctx, PARSER_CUR_PMOD(ctx)->mod, 0); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3175 | submod = calloc(1, sizeof *submod); |
| 3176 | ctx->parsed_mods->objs[0] = submod; |
| 3177 | submod->mod = calloc(1, sizeof *submod->mod); |
| 3178 | lydict_insert(ly_ctx, belongs_to, 0, &submod->mod->name); |
| 3179 | submod->mod->parsed = (struct lysp_module *)submod; |
| 3180 | submod->mod->ctx = ly_ctx; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3181 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3182 | fctx.mod = submod->mod; |
| 3183 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3184 | return submod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3185 | } |
| 3186 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3187 | static void |
| 3188 | test_submodule_elem(void **state) |
| 3189 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3190 | const char *data; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3191 | struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3192 | |
| 3193 | /* max subelements */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3194 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3195 | " <yang-version value=\"1.1\"/>\n" |
| 3196 | " <belongs-to module=\"module-name\">\n" |
| 3197 | " <prefix value=\"pref\"/>\n" |
| 3198 | " </belongs-to>\n" |
| 3199 | " <include module=\"b-mod\"/>\n" |
| 3200 | " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3201 | " <organization><text>org</text></organization>\n" |
| 3202 | " <contact><text>contact</text></contact>\n" |
| 3203 | " <description><text>desc</text></description>\n" |
| 3204 | " <reference><text>ref</text></reference>\n" |
| 3205 | " <revision date=\"2019-02-02\"/>\n" |
| 3206 | " <anydata name=\"anyd\"/>\n" |
| 3207 | " <anyxml name=\"anyx\"/>\n" |
| 3208 | " <choice name=\"choice\"/>\n" |
| 3209 | " <container name=\"cont\"/>\n" |
| 3210 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3211 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3212 | " <list name=\"sub-list\"/>\n" |
| 3213 | " <uses name=\"uses-name\"/>\n" |
| 3214 | " <augment target-node=\"target\"/>\n" |
| 3215 | " <deviation target-node=\"target\">\n" |
| 3216 | " <deviate value=\"not-supported\"/>\n" |
| 3217 | " </deviation>\n" |
| 3218 | " <extension name=\"ext\"/>\n" |
| 3219 | " <feature name=\"feature\"/>\n" |
| 3220 | " <grouping name=\"grp\"/>\n" |
| 3221 | " <identity name=\"ident-name\"/>\n" |
| 3222 | " <notification name=\"notf\"/>\n" |
| 3223 | " <rpc name=\"rpc-name\"/>\n" |
| 3224 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3225 | EXT_SUBELEM "\n" |
| 3226 | "</submodule>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3227 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3228 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3229 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3230 | assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3231 | assert_string_equal(lysp_submod->name, "mod"); |
| 3232 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3233 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 3234 | assert_null(lysp_submod->filepath); |
| 3235 | assert_string_equal(lysp_submod->org, "org"); |
| 3236 | assert_string_equal(lysp_submod->contact, "contact"); |
| 3237 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 3238 | assert_string_equal(lysp_submod->ref, "ref"); |
| 3239 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3240 | CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod", |
| 3241 | "imp-pref", NULL, ""); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3242 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 3243 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 3244 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 3245 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 3246 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 3247 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 3248 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 3249 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 3250 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 3251 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 3252 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 3253 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 3254 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 3255 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3256 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 3257 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3258 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 3259 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3260 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3261 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3262 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3263 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3264 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 3265 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 3266 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 3267 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 3268 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 3269 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LY_STMT_SUBMODULE); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3270 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3271 | /* min subelemnts */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3272 | ly_in_free(UTEST_IN, 0); |
| 3273 | lyxml_ctx_free(YCTX->xmlctx); |
| 3274 | lysp_submod = submod_renew(YCTX, "module-name"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3275 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n" |
| 3276 | " <yang-version value=\"1\"/>\n" |
| 3277 | " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n" |
| 3278 | "</submodule>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3279 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3280 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3281 | assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3282 | assert_string_equal(lysp_submod->prefix, "pref"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3283 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3284 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3285 | /* incorrect subelem order */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3286 | ly_in_free(UTEST_IN, 0); |
| 3287 | lyxml_ctx_free(YCTX->xmlctx); |
| 3288 | lysp_submod = submod_renew(YCTX, "module-name"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3289 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n" |
| 3290 | " <yang-version value=\"1\"/>\n" |
| 3291 | " <reference><text>ref</text></reference>\n" |
| 3292 | " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n" |
| 3293 | "</submodule>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3294 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3295 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3296 | assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID); |
| 3297 | CHECK_LOG_CTX("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\".", "Line number 4."); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3298 | } |
| 3299 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3300 | static void |
| 3301 | test_yin_parse_module(void **state) |
| 3302 | { |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3303 | const char *data; |
| 3304 | struct lys_module *mod; |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3305 | struct lysp_yin_ctx *yin_ctx = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3306 | struct ly_in *in = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3307 | |
| 3308 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3309 | mod->ctx = UTEST_LYCTX; |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3310 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3311 | " <yang-version value=\"1.1\"/>\n" |
| 3312 | " <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n" |
| 3313 | " <prefix value=\"a\"/>\n" |
| 3314 | " <import module=\"ietf-yang-metadata\">\n" |
| 3315 | " <prefix value=\"md\"/>\n" |
| 3316 | " </import>\n" |
| 3317 | " <feature name=\"f\"/>\n" |
| 3318 | " <md:annotation name=\"x\">\n" |
| 3319 | " <description>\n" |
| 3320 | " <text>test</text>\n" |
| 3321 | " </description>\n" |
| 3322 | " <reference>\n" |
| 3323 | " <text>test</text>\n" |
| 3324 | " </reference>\n" |
| 3325 | " <if-feature name=\"f\"/>\n" |
| 3326 | " <status value=\"current\"/>\n" |
| 3327 | " <type name=\"uint8\"/>\n" |
| 3328 | " <units name=\"meters\"/>\n" |
| 3329 | " </md:annotation>\n" |
| 3330 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3331 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 3332 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3333 | assert_null(mod->parsed->exts->child->next->child); |
| 3334 | assert_string_equal(mod->parsed->exts->child->next->arg, "test"); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3335 | lys_module_free(&fctx, mod, 0); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3336 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3337 | ly_in_free(in, 0); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3338 | mod = NULL; |
| 3339 | yin_ctx = NULL; |
| 3340 | |
| 3341 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3342 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3343 | data = "<module name=\"example-foo\"" |
| 3344 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 3345 | " xmlns:foo=\"urn:example:foo\"" |
| 3346 | " xmlns:myext=\"urn:example:extensions\">\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3347 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3348 | " <yang-version value=\"1\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3349 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3350 | " <namespace uri=\"urn:example:foo\"/>\n" |
| 3351 | " <prefix value=\"foo\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3352 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3353 | " <import module=\"example-extensions\">\n" |
| 3354 | " <prefix value=\"myext\"/>\n" |
| 3355 | " </import>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3356 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3357 | " <list name=\"interface\">\n" |
| 3358 | " <key value=\"name\"/>\n" |
| 3359 | " <leaf name=\"name\">\n" |
| 3360 | " <type name=\"string\"/>\n" |
| 3361 | " </leaf>\n" |
| 3362 | " <leaf name=\"mtu\">\n" |
| 3363 | " <type name=\"uint32\"/>\n" |
| 3364 | " <description>\n" |
| 3365 | " <text>The MTU of the interface.</text>\n" |
| 3366 | " </description>\n" |
| 3367 | " <myext:c-define name=\"MY_MTU\"/>\n" |
| 3368 | " </leaf>\n" |
| 3369 | " </list>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3370 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3371 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 3372 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3373 | lys_module_free(&fctx, mod, 0); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3374 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3375 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3376 | mod = NULL; |
| 3377 | yin_ctx = NULL; |
| 3378 | |
| 3379 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3380 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3381 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3382 | " <yang-version value=\"1\"/>\n" |
| 3383 | " <namespace uri=\"urn:example:foo\"/>\n" |
| 3384 | " <prefix value=\"foo\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3385 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3386 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 3387 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3388 | lys_module_free(&fctx, mod, 0); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3389 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3390 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3391 | mod = NULL; |
| 3392 | yin_ctx = NULL; |
| 3393 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3394 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3395 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3396 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3397 | "</submodule>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3398 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 3399 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3400 | CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3401 | lys_module_free(&fctx, mod, 0); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3402 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3403 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3404 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3405 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3406 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3407 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3408 | " <yang-version value=\"1\"/>\n" |
| 3409 | " <namespace uri=\"urn:example:foo\"/>\n" |
| 3410 | " <prefix value=\"foo\"/>\n" |
| 3411 | "</module>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3412 | "<module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3413 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 3414 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3415 | CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6."); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3416 | lys_module_free(&fctx, mod, 0); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3417 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3418 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3419 | mod = NULL; |
| 3420 | yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | static void |
| 3424 | test_yin_parse_submodule(void **state) |
| 3425 | { |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3426 | const char *data; |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3427 | struct lysp_yin_ctx *yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3428 | struct lysp_submodule *submod = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3429 | struct ly_in *in; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3430 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3431 | lydict_insert(UTEST_LYCTX, "a", 0, &PARSER_CUR_PMOD(YCTX)->mod->name); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 3432 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3433 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3434 | "<submodule name=\"asub\"" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3435 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 3436 | " xmlns:a=\"urn:a\">\n" |
| 3437 | " <yang-version value=\"1\"/>\n" |
| 3438 | " <belongs-to module=\"a\">\n" |
| 3439 | " <prefix value=\"a_pref\"/>\n" |
| 3440 | " </belongs-to>\n" |
| 3441 | " <include module=\"atop\"/>\n" |
| 3442 | " <feature name=\"fox\"/>\n" |
| 3443 | " <notification name=\"bar-notif\">\n" |
| 3444 | " <if-feature name=\"bar\"/>\n" |
| 3445 | " </notification>\n" |
| 3446 | " <notification name=\"fox-notif\">\n" |
| 3447 | " <if-feature name=\"fox\"/>\n" |
| 3448 | " </notification>\n" |
| 3449 | " <augment target-node=\"/a_pref:top\">\n" |
| 3450 | " <if-feature name=\"bar\"/>\n" |
| 3451 | " <container name=\"bar-sub\"/>\n" |
| 3452 | " </augment>\n" |
| 3453 | " <augment target-node=\"/top\">\n" |
| 3454 | " <container name=\"bar-sub2\"/>\n" |
| 3455 | " </augment>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3456 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3457 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3458 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lysp_ctx *)YCTX, in, &submod), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3459 | lysp_module_free(&fctx, (struct lysp_module *)submod); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3460 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3461 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3462 | yin_ctx = NULL; |
| 3463 | submod = NULL; |
| 3464 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3465 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3466 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3467 | " <yang-version value=\"1\"/>\n" |
| 3468 | " <belongs-to module=\"a\">\n" |
| 3469 | " <prefix value=\"a_pref\"/>\n" |
| 3470 | " </belongs-to>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3471 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3472 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3473 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lysp_ctx *)YCTX, in, &submod), LY_SUCCESS); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3474 | lysp_module_free(&fctx, (struct lysp_module *)submod); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3475 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3476 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3477 | yin_ctx = NULL; |
| 3478 | submod = NULL; |
| 3479 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3480 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3481 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 3482 | "</module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3483 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3484 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lysp_ctx *)YCTX, in, &submod), LY_EINVAL); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3485 | CHECK_LOG_CTX("Input data contains module when a submodule is expected.", NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3486 | lysp_module_free(&fctx, (struct lysp_module *)submod); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3487 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3488 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3489 | yin_ctx = NULL; |
| 3490 | submod = NULL; |
| 3491 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3492 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3493 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3494 | " <yang-version value=\"1\"/>\n" |
| 3495 | " <belongs-to module=\"a\">\n" |
| 3496 | " <prefix value=\"a_pref\"/>\n" |
| 3497 | " </belongs-to>\n" |
| 3498 | "</submodule>\n" |
| 3499 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3500 | " <yang-version value=\"1\"/>\n" |
| 3501 | " <belongs-to module=\"a\">\n" |
| 3502 | " <prefix value=\"a_pref\"/>\n" |
| 3503 | " </belongs-to>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3504 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3505 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3506 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lysp_ctx *)YCTX, in, &submod), LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3507 | CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8."); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3508 | lysp_module_free(&fctx, (struct lysp_module *)submod); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3509 | lysp_yin_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3510 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3511 | yin_ctx = NULL; |
| 3512 | submod = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3513 | } |
| 3514 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3515 | int |
| 3516 | main(void) |
| 3517 | { |
| 3518 | |
| 3519 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3520 | UTEST(test_yin_match_keyword, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3521 | UTEST(test_yin_parse_content, setup, teardown), |
| 3522 | UTEST(test_validate_value, setup, teardown), |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 3523 | UTEST(test_valid_module), |
| 3524 | UTEST(test_print_module), |
| 3525 | UTEST(test_print_submodule), |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 3526 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3527 | UTEST(test_yin_match_argument_name), |
| 3528 | cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown), |
| 3529 | cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3530 | cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3531 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown), |
| 3532 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3533 | cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3534 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown), |
| 3535 | cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown), |
| 3536 | cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown), |
| 3537 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown), |
| 3538 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown), |
| 3539 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown), |
| 3540 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown), |
| 3541 | cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown), |
| 3542 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown), |
| 3543 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown), |
| 3544 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown), |
| 3545 | cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown), |
| 3546 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown), |
| 3547 | cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown), |
| 3548 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown), |
| 3549 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown), |
| 3550 | cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown), |
| 3551 | cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3552 | cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown), |
| 3553 | cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown), |
| 3554 | cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown), |
| 3555 | cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown), |
| 3556 | cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown), |
| 3557 | cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown), |
| 3558 | cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown), |
| 3559 | cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown), |
| 3560 | cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown), |
| 3561 | cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3562 | cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3563 | cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown), |
| 3564 | cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown), |
| 3565 | cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown), |
| 3566 | cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown), |
| 3567 | cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown), |
| 3568 | cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown), |
| 3569 | cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown), |
| 3570 | cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown), |
| 3571 | cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown), |
| 3572 | cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown), |
| 3573 | cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown), |
| 3574 | cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown), |
| 3575 | cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown), |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3576 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3577 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown), |
| 3578 | cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown), |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3579 | }; |
| 3580 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3581 | return cmocka_run_group_tests(tests, NULL, NULL); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3582 | } |