David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 1 | #include <stdarg.h> |
| 2 | #include <stddef.h> |
| 3 | #include <setjmp.h> |
| 4 | #include <cmocka.h> |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | |
David Sedlák | ecf5eb8 | 2019-06-03 14:12:44 +0200 | [diff] [blame] | 9 | #include "../../src/common.h" |
| 10 | #include "../../src/tree_schema.h" |
| 11 | #include "../../src/tree_schema_internal.h" |
| 12 | #include "../../src/parser_yin.h" |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 13 | #include "../../src/xml.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 14 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 15 | struct state { |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 16 | struct ly_ctx *ctx; |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 17 | struct lys_module *mod; |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 18 | struct lyxml_context *xml_ctx; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 19 | }; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 20 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 21 | static int |
| 22 | setup_f(void **state) |
| 23 | { |
| 24 | struct state *st = NULL; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 25 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 26 | /* allocate state variable */ |
| 27 | (*state) = st = calloc(1, sizeof(*st)); |
| 28 | if (!st) { |
| 29 | fprintf(stderr, "Memmory allocation failed"); |
| 30 | return EXIT_FAILURE; |
| 31 | } |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 32 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 33 | /* create new libyang context */ |
| 34 | ly_ctx_new(NULL, 0, &st->ctx); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 35 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 36 | /* allocate new module */ |
| 37 | st->mod = calloc(1, sizeof(*st->mod)); |
| 38 | st->mod->ctx = st->ctx; |
| 39 | |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 40 | st->xml_ctx = calloc(1, sizeof(struct lys_parser_ctx)); |
| 41 | st->xml_ctx->ctx = st->ctx; |
| 42 | st->xml_ctx->line = 1; |
| 43 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 44 | return EXIT_SUCCESS; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static int |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 48 | teardown_f(void **state) |
| 49 | { |
| 50 | struct state *st = *(struct state **)state; |
| 51 | |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 52 | lyxml_context_clear(st->xml_ctx); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 53 | lys_module_free(st->mod, NULL); |
| 54 | ly_ctx_destroy(st->ctx, NULL); |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 55 | free(st->xml_ctx); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 56 | free(st); |
| 57 | |
| 58 | return EXIT_SUCCESS; |
| 59 | } |
| 60 | |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 61 | static struct state* |
| 62 | reset_state(void **state) |
| 63 | { |
| 64 | teardown_f(state); |
| 65 | setup_f(state); |
| 66 | |
| 67 | return *state; |
| 68 | } |
| 69 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 70 | static void |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 71 | test_yin_parse_module(void **state) |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 72 | { |
| 73 | LY_ERR ret = LY_SUCCESS; |
| 74 | struct state *st = *state; |
| 75 | |
| 76 | ret = yin_parse_module(st->ctx, |
David Sedlák | 1873013 | 2019-03-15 15:51:34 +0100 | [diff] [blame] | 77 | "<module name=\"example-foo\"\ |
| 78 | xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\ |
| 79 | xmlns:foo=\"urn:example:foo\"\ |
| 80 | xmlns:myext=\"urn:example:extensions\">\ |
David Sedlák | cd0c951 | 2019-03-29 13:23:06 +0100 | [diff] [blame] | 81 | <namespace uri=\"urn:example:foo\" xmlns:myext=\"urn:example:extensions\"/>\ |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 82 | <prefix xmlns:myxt=\"urn:emple:extensions\" value=\"foo\" xmlns:myext=\"urn:example:extensions\"/>\ |
David Sedlák | d9d3a31 | 2019-06-04 09:47:10 +0200 | [diff] [blame] | 83 | </module>", |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 84 | st->mod); |
| 85 | |
| 86 | assert_int_equal(ret, LY_SUCCESS); |
| 87 | assert_string_equal(st->mod->parsed->mod->name, "example-foo"); |
| 88 | assert_string_equal(st->mod->parsed->mod->prefix, "foo"); |
David Sedlák | cd0c951 | 2019-03-29 13:23:06 +0100 | [diff] [blame] | 89 | assert_string_equal(st->mod->parsed->mod->ns, "urn:example:foo"); |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 90 | |
| 91 | st = reset_state(state); |
| 92 | ret = yin_parse_module(st->ctx, |
| 93 | "<module name=\"example-foo\">\ |
| 94 | <invalid-tag uri=\"urn:example:foo\"\"/>\ |
| 95 | </module>", |
| 96 | st->mod); |
| 97 | assert_int_equal(ret, LY_EVALID); |
| 98 | |
| 99 | st = reset_state(state); |
| 100 | ret = yin_parse_module(st->ctx, |
| 101 | "<module>\ |
| 102 | </module>", |
| 103 | st->mod); |
| 104 | assert_int_equal(ret, LY_EVALID); |
| 105 | |
| 106 | st = reset_state(state); |
| 107 | ret = yin_parse_module(st->ctx, |
| 108 | "", |
| 109 | st->mod); |
| 110 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void |
| 114 | test_match_keyword(void **state) |
| 115 | { |
| 116 | (void)state; /* unused */ |
| 117 | |
David Sedlák | 1873013 | 2019-03-15 15:51:34 +0100 | [diff] [blame] | 118 | assert_int_equal(match_keyword("anydatax", strlen("anydatax"), 0), YANG_NONE); |
| 119 | assert_int_equal(match_keyword("asdasd", strlen("asdasd"), 0), YANG_NONE); |
| 120 | assert_int_equal(match_keyword("", 0, 0), YANG_NONE); |
| 121 | assert_int_equal(match_keyword("anydata", strlen("anydata"), 0), YANG_ANYDATA); |
| 122 | assert_int_equal(match_keyword("anyxml", strlen("anyxml"), 0), YANG_ANYXML); |
| 123 | assert_int_equal(match_keyword("argument", strlen("argument"), 0), YANG_ARGUMENT); |
| 124 | assert_int_equal(match_keyword("augment", strlen("augment"), 0), YANG_AUGMENT); |
| 125 | assert_int_equal(match_keyword("base", strlen("base"), 0), YANG_BASE); |
| 126 | assert_int_equal(match_keyword("belongs-to", strlen("belongs-to"), 0), YANG_BELONGS_TO); |
| 127 | assert_int_equal(match_keyword("bit", strlen("bit"), 0), YANG_BIT); |
| 128 | assert_int_equal(match_keyword("case", strlen("case"), 0), YANG_CASE); |
| 129 | assert_int_equal(match_keyword("choice", strlen("choice"), 0), YANG_CHOICE); |
| 130 | assert_int_equal(match_keyword("config", strlen("config"), 0), YANG_CONFIG); |
| 131 | assert_int_equal(match_keyword("contact", strlen("contact"), 0), YANG_CONTACT); |
| 132 | assert_int_equal(match_keyword("container", strlen("container"), 0), YANG_CONTAINER); |
| 133 | assert_int_equal(match_keyword("default", strlen("default"), 0), YANG_DEFAULT); |
| 134 | assert_int_equal(match_keyword("description", strlen("description"), 0), YANG_DESCRIPTION); |
| 135 | assert_int_equal(match_keyword("deviate", strlen("deviate"), 0), YANG_DEVIATE); |
| 136 | assert_int_equal(match_keyword("deviation", strlen("deviation"), 0), YANG_DEVIATION); |
| 137 | assert_int_equal(match_keyword("enum", strlen("enum"), 0), YANG_ENUM); |
| 138 | assert_int_equal(match_keyword("error-app-tag", strlen("error-app-tag"), 0), YANG_ERROR_APP_TAG); |
| 139 | assert_int_equal(match_keyword("error-message", strlen("error-message"), 0), YANG_ERROR_MESSAGE); |
| 140 | assert_int_equal(match_keyword("extension", strlen("extension"), 0), YANG_EXTENSION); |
| 141 | assert_int_equal(match_keyword("feature", strlen("feature"), 0), YANG_FEATURE); |
| 142 | assert_int_equal(match_keyword("fraction-digits", strlen("fraction-digits"), 0), YANG_FRACTION_DIGITS); |
| 143 | assert_int_equal(match_keyword("grouping", strlen("grouping"), 0), YANG_GROUPING); |
| 144 | assert_int_equal(match_keyword("identity", strlen("identity"), 0), YANG_IDENTITY); |
| 145 | assert_int_equal(match_keyword("if-feature", strlen("if-feature"), 0), YANG_IF_FEATURE); |
| 146 | assert_int_equal(match_keyword("import", strlen("import"), 0), YANG_IMPORT); |
| 147 | assert_int_equal(match_keyword("include", strlen("include"), 0), YANG_INCLUDE); |
| 148 | assert_int_equal(match_keyword("input", strlen("input"), 0), YANG_INPUT); |
| 149 | assert_int_equal(match_keyword("key", strlen("key"), 0), YANG_KEY); |
| 150 | assert_int_equal(match_keyword("leaf", strlen("leaf"), 0), YANG_LEAF); |
| 151 | assert_int_equal(match_keyword("leaf-list", strlen("leaf-list"), 0), YANG_LEAF_LIST); |
| 152 | assert_int_equal(match_keyword("length", strlen("length"), 0), YANG_LENGTH); |
| 153 | assert_int_equal(match_keyword("list", strlen("list"), 0), YANG_LIST); |
| 154 | assert_int_equal(match_keyword("mandatory", strlen("mandatory"), 0), YANG_MANDATORY); |
| 155 | assert_int_equal(match_keyword("max-elements", strlen("max-elements"), 0), YANG_MAX_ELEMENTS); |
| 156 | assert_int_equal(match_keyword("min-elements", strlen("min-elements"), 0), YANG_MIN_ELEMENTS); |
| 157 | assert_int_equal(match_keyword("modifier", strlen("modifier"), 0), YANG_MODIFIER); |
| 158 | assert_int_equal(match_keyword("module", strlen("module"), 0), YANG_MODULE); |
| 159 | assert_int_equal(match_keyword("must", strlen("must"), 0), YANG_MUST); |
| 160 | assert_int_equal(match_keyword("namespace", strlen("namespace"), 0), YANG_NAMESPACE); |
| 161 | assert_int_equal(match_keyword("notification", strlen("notification"), 0), YANG_NOTIFICATION); |
| 162 | assert_int_equal(match_keyword("ordered-by", strlen("ordered-by"), 0), YANG_ORDERED_BY); |
| 163 | assert_int_equal(match_keyword("organization", strlen("organization"), 0), YANG_ORGANIZATION); |
| 164 | assert_int_equal(match_keyword("output", strlen("output"), 0), YANG_OUTPUT); |
| 165 | assert_int_equal(match_keyword("path", strlen("path"), 0), YANG_PATH); |
| 166 | assert_int_equal(match_keyword("pattern", strlen("pattern"), 0), YANG_PATTERN); |
| 167 | assert_int_equal(match_keyword("position", strlen("position"), 0), YANG_POSITION); |
| 168 | assert_int_equal(match_keyword("prefix", strlen("prefix"), 0), YANG_PREFIX); |
| 169 | assert_int_equal(match_keyword("presence", strlen("presence"), 0), YANG_PRESENCE); |
| 170 | assert_int_equal(match_keyword("range", strlen("range"), 0), YANG_RANGE); |
| 171 | assert_int_equal(match_keyword("reference", strlen("reference"), 0), YANG_REFERENCE); |
| 172 | assert_int_equal(match_keyword("refine", strlen("refine"), 0), YANG_REFINE); |
| 173 | assert_int_equal(match_keyword("require-instance", strlen("require-instance"), 0), YANG_REQUIRE_INSTANCE); |
| 174 | assert_int_equal(match_keyword("revision", strlen("revision"), 0), YANG_REVISION); |
| 175 | assert_int_equal(match_keyword("revision-date", strlen("revision-date"), 0), YANG_REVISION_DATE); |
| 176 | assert_int_equal(match_keyword("rpc", strlen("rpc"), 0), YANG_RPC); |
| 177 | assert_int_equal(match_keyword("status", strlen("status"), 0), YANG_STATUS); |
| 178 | assert_int_equal(match_keyword("submodule", strlen("submodule"), 0), YANG_SUBMODULE); |
| 179 | assert_int_equal(match_keyword("type", strlen("type"), 0), YANG_TYPE); |
| 180 | assert_int_equal(match_keyword("typedef", strlen("typedef"), 0), YANG_TYPEDEF); |
| 181 | assert_int_equal(match_keyword("unique", strlen("unique"), 0), YANG_UNIQUE); |
| 182 | assert_int_equal(match_keyword("units", strlen("units"), 0), YANG_UNITS); |
| 183 | assert_int_equal(match_keyword("uses", strlen("uses"), 0), YANG_USES); |
| 184 | assert_int_equal(match_keyword("value", strlen("value"), 0), YANG_VALUE); |
| 185 | assert_int_equal(match_keyword("when", strlen("when"), 0), YANG_WHEN); |
| 186 | assert_int_equal(match_keyword("yang-version", strlen("yang-version"), 0), YANG_YANG_VERSION); |
| 187 | assert_int_equal(match_keyword("yin-element", strlen("yin-element"), 0), YANG_YIN_ELEMENT); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 188 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 189 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 190 | static void |
| 191 | test_match_argument(void **state) |
| 192 | { |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 193 | (void)state; /* unused */ |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 194 | |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 195 | assert_int_equal(match_argument_name("", 5), YIN_ARG_UNKNOWN); |
| 196 | assert_int_equal(match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN); |
| 197 | assert_int_equal(match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 198 | assert_int_equal(match_argument_name("condition", 9), YIN_ARG_CONDITION); |
| 199 | assert_int_equal(match_argument_name("date", 4), YIN_ARG_DATE); |
| 200 | assert_int_equal(match_argument_name("module", 6), YIN_ARG_MODULE); |
| 201 | assert_int_equal(match_argument_name("name", 4), YIN_ARG_NAME); |
| 202 | assert_int_equal(match_argument_name("tag", 3), YIN_ARG_TAG); |
| 203 | assert_int_equal(match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE); |
| 204 | assert_int_equal(match_argument_name("text", 4), YIN_ARG_TEXT); |
| 205 | assert_int_equal(match_argument_name("uri", 3), YIN_ARG_URI); |
| 206 | assert_int_equal(match_argument_name("value", 5), YIN_ARG_VALUE); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 207 | } |
| 208 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 209 | static void |
| 210 | test_meta(void **state) |
| 211 | { |
| 212 | LY_ERR ret = LY_SUCCESS; |
| 213 | struct state *st = *state; |
| 214 | |
| 215 | ret = yin_parse_module(st->ctx,"<module name=\"example-foo\">\ |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 216 | <organization xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">organization...</organization>\ |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 217 | <contact>contact...</contact>\ |
| 218 | <description>description...</description>\ |
| 219 | <reference>reference...</reference>\ |
| 220 | </module>", st->mod); |
| 221 | |
| 222 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 223 | assert_string_equal(st->mod->parsed->mod->org, "organization..."); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 224 | assert_string_equal(st->mod->parsed->mod->contact, "contact..."); |
| 225 | assert_string_equal(st->mod->parsed->mod->dsc, "description..."); |
| 226 | assert_string_equal(st->mod->parsed->mod->ref, "reference..."); |
David Sedlák | 6882673 | 2019-06-05 10:50:58 +0200 | [diff] [blame^] | 227 | |
| 228 | st = reset_state(state); |
| 229 | ret = yin_parse_module(st->ctx,"<module name=\"example-foo\">\ |
| 230 | <organization test=\"invalid-argument\">organization...</organization>\ |
| 231 | </module>", st->mod); |
| 232 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 233 | } |
| 234 | |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 235 | static void |
| 236 | test_parse_text_element(void **state) |
| 237 | { |
| 238 | struct state *st = *state; |
| 239 | const char *res = NULL, *prefix = NULL, *name = NULL; |
| 240 | size_t prefix_len = 0, name_len = 0; |
| 241 | LY_ERR ret = LY_SUCCESS; |
| 242 | |
| 243 | const char *data = "<elem>content</elem>"; |
| 244 | lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 245 | parse_text_element(st->xml_ctx, &data, &res); |
| 246 | assert_string_equal(res, "content"); |
| 247 | lydict_remove(st->ctx, "content"); |
| 248 | |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 249 | data = "<elem xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">another-content</elem>"; |
| 250 | lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 251 | parse_text_element(st->xml_ctx, &data, &res); |
| 252 | assert_string_equal(res, "another-content"); |
| 253 | lydict_remove(st->ctx, "another-content"); |
| 254 | |
| 255 | data = "<elem invalid=\"invalid\">text</elem>"; |
| 256 | lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 257 | ret = parse_text_element(st->xml_ctx, &data, &res); |
| 258 | assert_int_equal(ret, LY_EVALID); |
| 259 | } |
| 260 | |
David Sedlák | d9d3a31 | 2019-06-04 09:47:10 +0200 | [diff] [blame] | 261 | static void |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 262 | test_yin_parse_import(void **state) |
| 263 | { |
| 264 | struct state *st = *state; |
| 265 | const char *prefix = NULL, *name = NULL; |
| 266 | size_t prefix_len = 0, name_len = 0; |
| 267 | LY_ERR ret = LY_SUCCESS; |
| 268 | struct lysp_import *imports = NULL; |
| 269 | |
| 270 | const char *data = "<import module=\"a\">\ |
| 271 | <prefix value=\"a_mod\"/>\ |
| 272 | <revision-date date=\"2015-01-01\"/>\ |
David Sedlák | c67dcaa | 2019-06-04 14:49:05 +0200 | [diff] [blame] | 273 | </import>\ |
| 274 | \ |
| 275 | <import module=\"a\">\ |
| 276 | <prefix value=\"a_mod\"/>\ |
| 277 | <revision-date date=\"2015-01-01\"/>\ |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 278 | </import>"; |
| 279 | |
| 280 | lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 281 | ret = yin_parse_import(st->xml_ctx, "b-mod", &data, &imports); |
| 282 | assert_int_equal(ret, LY_SUCCESS); |
| 283 | assert_string_equal(imports->name, "a"); |
| 284 | assert_string_equal(imports->prefix, "a_mod"); |
| 285 | assert_string_equal(imports->rev, "2015-01-01"); |
| 286 | lydict_remove(st->ctx, imports->name); |
| 287 | lydict_remove(st->ctx, imports->prefix); |
| 288 | LY_ARRAY_FREE(imports); |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 289 | imports = NULL; |
David Sedlák | c67dcaa | 2019-06-04 14:49:05 +0200 | [diff] [blame] | 290 | |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 291 | lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 292 | ret = yin_parse_import(st->xml_ctx, "a_mod", &data, &imports); |
| 293 | assert_int_equal(ret, LY_EVALID); |
| 294 | lydict_remove(st->ctx, imports->name); |
| 295 | lydict_remove(st->ctx, imports->prefix); |
| 296 | LY_ARRAY_FREE(imports); |
| 297 | } |
| 298 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 299 | int |
| 300 | main(void) |
| 301 | { |
| 302 | |
| 303 | const struct CMUnitTest tests[] = { |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 304 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f), |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 305 | cmocka_unit_test_setup_teardown(test_meta, setup_f, teardown_f), |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 306 | cmocka_unit_test_setup_teardown(test_parse_text_element, setup_f, teardown_f), |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 307 | cmocka_unit_test_setup_teardown(test_yin_parse_import, setup_f, teardown_f), |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 308 | cmocka_unit_test(test_match_keyword), |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 309 | cmocka_unit_test(test_match_argument), |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 313 | } |