Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file test_lyb.c |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief Cmocka tests for LYB binary data format. |
| 5 | * |
| 6 | * Copyright (c) 2020 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 15 | #include "hash_table.h" |
| 16 | #include "libyang.h" |
| 17 | #include "tests/config.h" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 18 | #include "utests.h" |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 19 | |
| 20 | struct state { |
| 21 | struct ly_ctx *ctx; |
| 22 | struct lyd_node *dt1, *dt2; |
| 23 | char *mem; |
| 24 | }; |
| 25 | |
| 26 | static void |
| 27 | check_data_tree_next(struct lyd_node **start, struct lyd_node **next, struct lyd_node **elem) |
| 28 | { |
| 29 | if (*elem) { |
| 30 | goto loop_next; |
| 31 | } |
| 32 | |
| 33 | loop_begin: |
Michal Vasko | 56daf73 | 2020-08-10 10:57:18 +0200 | [diff] [blame] | 34 | /* LYD_TREE_DFS_BEGIN */ |
| 35 | for (*elem = *next = *start; *elem; *elem = *next) { |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 36 | return; |
| 37 | loop_next: |
Michal Vasko | 56daf73 | 2020-08-10 10:57:18 +0200 | [diff] [blame] | 38 | /* LYD_TREE_DFS_END */ |
| 39 | |
| 40 | /* select element for the next run - children first */ |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 41 | *next = lyd_child(*elem); |
Michal Vasko | 56daf73 | 2020-08-10 10:57:18 +0200 | [diff] [blame] | 42 | if (!*next) { |
| 43 | /* no children */ |
| 44 | if (*elem == *start) { |
| 45 | /* we are done, (START) has no children */ |
| 46 | break; |
| 47 | } |
| 48 | /* try siblings */ |
| 49 | *next = (*elem)->next; |
| 50 | } |
| 51 | while (!*next) { |
| 52 | /* parent is already processed, go to its sibling */ |
| 53 | *elem = (struct lyd_node *)(*elem)->parent; |
| 54 | /* no siblings, go back through parents */ |
| 55 | if ((*elem)->parent == (*start)->parent) { |
| 56 | /* we are done, no next element to process */ |
| 57 | break; |
| 58 | } |
| 59 | *next = (*elem)->next; |
| 60 | } |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | if (!*next) { |
| 64 | /* top-level siblings */ |
| 65 | *start = (*start)->next; |
| 66 | if (!(*start)) { |
| 67 | *elem = NULL; |
| 68 | return; |
| 69 | } |
| 70 | goto loop_begin; |
| 71 | } |
| 72 | |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | static void |
| 77 | check_data_tree(struct lyd_node *root1, struct lyd_node *root2) |
| 78 | { |
| 79 | struct lyd_node *next1, *next2, *elem1 = NULL, *elem2 = NULL, *iter; |
| 80 | struct lyd_meta *meta1, *meta2; |
| 81 | struct lyd_node_inner *in1, *in2; |
| 82 | uint32_t i1, i2; |
| 83 | |
| 84 | for (check_data_tree_next(&root1, &next1, &elem1), check_data_tree_next(&root2, &next2, &elem2); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 85 | elem1 && elem2; |
| 86 | check_data_tree_next(&root1, &next1, &elem1), check_data_tree_next(&root2, &next2, &elem2)) { |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 87 | |
| 88 | if (elem1->schema != elem2->schema) { |
| 89 | fprintf(stderr, "Schema mismatch (\"%s\" and \"%s\").\n", elem1->schema->name, elem2->schema->name); |
| 90 | fail(); |
| 91 | } |
| 92 | |
| 93 | /* check common data node attributes */ |
| 94 | if (elem1->flags != elem2->flags) { |
| 95 | fprintf(stderr, "\"%s\": flags mismatch (\"%u\" and \"%u\").\n", elem1->schema->name, elem1->flags, elem2->flags); |
| 96 | fail(); |
| 97 | } |
| 98 | |
| 99 | /* check data node attributes */ |
| 100 | for (meta1 = elem1->meta, meta2 = elem2->meta; meta1 && meta2; meta1 = meta1->next, meta2 = meta2->next) { |
| 101 | if (meta1->annotation != meta2->annotation) { |
| 102 | fprintf(stderr, "\"%s\": meta annotation mismatch.\n", elem1->schema->name); |
| 103 | fail(); |
| 104 | } |
| 105 | if (strcmp(meta1->name, meta2->name)) { |
| 106 | fprintf(stderr, "\"%s\": meta name mismatch (\"%s\" and \"%s\").\n", elem1->schema->name, meta1->name, meta2->name); |
| 107 | fail(); |
| 108 | } |
| 109 | if (lyd_compare_meta(meta1, meta2)) { |
| 110 | fprintf(stderr, "\"%s\": meta value mismatch.\n", elem1->schema->name); |
| 111 | fail(); |
| 112 | } |
| 113 | } |
| 114 | if (meta1) { |
| 115 | fprintf(stderr, "\"%s\": meta mismatch (\"%s\" and \"NULL\").\n", elem1->schema->name, meta1->name); |
| 116 | fail(); |
| 117 | } |
| 118 | if (meta2) { |
| 119 | fprintf(stderr, "\"%s\": meta mismatch (\"NULL\" and \"%s\").\n", elem1->schema->name, meta2->name); |
| 120 | fail(); |
| 121 | } |
| 122 | |
| 123 | /* check specific data node attributes */ |
| 124 | switch (elem1->schema->nodetype) { |
| 125 | case LYS_CONTAINER: |
| 126 | case LYS_LIST: |
| 127 | case LYS_RPC: |
| 128 | case LYS_ACTION: |
| 129 | case LYS_NOTIF: |
| 130 | in1 = (struct lyd_node_inner *)elem1; |
| 131 | in2 = (struct lyd_node_inner *)elem2; |
| 132 | |
| 133 | i1 = 0; |
| 134 | LY_LIST_FOR(in1->child, iter) { |
| 135 | ++i1; |
| 136 | } |
| 137 | |
| 138 | i2 = 0; |
| 139 | LY_LIST_FOR(in2->child, iter) { |
| 140 | ++i2; |
| 141 | } |
| 142 | |
| 143 | if (i1 != i2) { |
| 144 | fprintf(stderr, "\"%s\": child count mismatch (%u and %u).\n", elem1->schema->name, i1, i2); |
| 145 | fail(); |
| 146 | } |
| 147 | |
| 148 | if (i1 >= LYD_HT_MIN_ITEMS) { |
| 149 | if (!in1->children_ht || !in2->children_ht) { |
| 150 | fprintf(stderr, "\"%s\": missing hash table (%p and %p).\n", elem1->schema->name, in1->children_ht, |
| 151 | in2->children_ht); |
| 152 | fail(); |
| 153 | } |
| 154 | |
| 155 | LY_LIST_FOR(in1->child, iter) { |
| 156 | if (lyht_find(in1->children_ht, &iter, iter->hash, NULL)) { |
| 157 | fprintf(stderr, "\"%s\": missing child \"%s\" in the hash table 1.\n", elem1->schema->name, iter->schema->name); |
| 158 | fail(); |
| 159 | } |
| 160 | } |
| 161 | LY_LIST_FOR(in2->child, iter) { |
| 162 | if (lyht_find(in2->children_ht, &iter, iter->hash, NULL)) { |
| 163 | fprintf(stderr, "\"%s\": missing child \"%s\" in the hash table 2.\n", elem1->schema->name, iter->schema->name); |
| 164 | fail(); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | break; |
| 169 | case LYS_LEAF: |
| 170 | case LYS_LEAFLIST: |
| 171 | case LYS_ANYDATA: |
| 172 | case LYS_ANYXML: |
Michal Vasko | 8f359bf | 2020-07-28 10:41:15 +0200 | [diff] [blame] | 173 | if (lyd_compare_single(elem1, elem2, 0)) { |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 174 | fprintf(stderr, "\"%s\": value mismatch.\n", elem1->schema->name); |
| 175 | fail(); |
| 176 | } |
| 177 | break; |
| 178 | default: |
| 179 | fprintf(stderr, "Unexpected data node type.\n"); |
| 180 | fail(); |
| 181 | } |
| 182 | |
| 183 | if (!elem1->hash) { |
| 184 | fprintf(stderr, "\"%s\": hash not calculated.\n", elem1->schema->name); |
| 185 | fail(); |
| 186 | } |
| 187 | if (elem1->hash != elem2->hash) { |
| 188 | fprintf(stderr, "\"%s\": hashes do not match (%u and %u).\n", elem1->schema->name, elem1->hash, elem2->hash); |
| 189 | fail(); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | if (elem1) { |
| 194 | fprintf(stderr, "Schema mismatch (\"%s\" and \"NULL\").\n", elem1->schema->name); |
| 195 | fail(); |
| 196 | } |
| 197 | if (elem2) { |
| 198 | fprintf(stderr, "Schema mismatch (\"NULL\" and \"%s\").\n", elem2->schema->name); |
| 199 | fail(); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | static int |
| 204 | setup_f(void **state) |
| 205 | { |
| 206 | struct state *st; |
| 207 | |
| 208 | (*state) = st = calloc(1, sizeof *st); |
| 209 | assert_non_null(st); |
| 210 | |
| 211 | /* libyang context */ |
| 212 | assert_int_equal(ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &st->ctx), LY_SUCCESS); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static int |
| 218 | teardown_f(void **state) |
| 219 | { |
| 220 | struct state *st = (*state); |
| 221 | |
| 222 | lyd_free_siblings(st->dt1); |
| 223 | lyd_free_siblings(st->dt2); |
| 224 | ly_ctx_destroy(st->ctx, NULL); |
| 225 | free(st->mem); |
| 226 | free(st); |
| 227 | (*state) = NULL; |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static void |
| 233 | test_ietf_interfaces(void **state) |
| 234 | { |
| 235 | struct state *st = (*state); |
| 236 | int ret; |
| 237 | const char *data_xml = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 238 | "<interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 239 | " <interface>\n" |
| 240 | " <name>eth0</name>\n" |
| 241 | " <description>Ethernet 0</description>\n" |
| 242 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 243 | " <enabled>true</enabled>\n" |
| 244 | " <ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">\n" |
| 245 | " <enabled>true</enabled>\n" |
| 246 | " <mtu>1500</mtu>\n" |
| 247 | " <address>\n" |
| 248 | " <ip>192.168.2.100</ip>\n" |
| 249 | " <prefix-length>24</prefix-length>\n" |
| 250 | " </address>\n" |
| 251 | " </ipv4>\n" |
| 252 | " </interface>\n" |
| 253 | " <interface>\n" |
| 254 | " <name>eth1</name>\n" |
| 255 | " <description>Ethernet 1</description>\n" |
| 256 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 257 | " <enabled>true</enabled>\n" |
| 258 | " <ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">\n" |
| 259 | " <enabled>true</enabled>\n" |
| 260 | " <mtu>1500</mtu>\n" |
| 261 | " <address>\n" |
| 262 | " <ip>10.10.1.5</ip>\n" |
| 263 | " <prefix-length>16</prefix-length>\n" |
| 264 | " </address>\n" |
| 265 | " </ipv4>\n" |
| 266 | " </interface>\n" |
| 267 | " <interface>\n" |
| 268 | " <name>gigaeth0</name>\n" |
| 269 | " <description>GigabitEthernet 0</description>\n" |
| 270 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 271 | " <enabled>false</enabled>\n" |
| 272 | " </interface>\n" |
| 273 | "</interfaces>\n"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 274 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 275 | assert_non_null(ly_ctx_load_module(st->ctx, "ietf-ip", NULL, NULL)); |
| 276 | assert_non_null(ly_ctx_load_module(st->ctx, "iana-if-type", NULL, NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 277 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 278 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 279 | assert_ptr_not_equal(st->dt1, NULL); |
| 280 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 281 | ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 282 | assert_int_equal(ret, 0); |
| 283 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 284 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 285 | assert_ptr_not_equal(st->dt2, NULL); |
| 286 | |
| 287 | check_data_tree(st->dt1, st->dt2); |
| 288 | } |
| 289 | |
| 290 | static void |
| 291 | test_origin(void **state) |
| 292 | { |
| 293 | struct state *st = (*state); |
| 294 | int ret; |
| 295 | const char *origin_yang = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 296 | "module test-origin {" |
| 297 | " namespace \"urn:test-origin\";" |
| 298 | " prefix to;" |
| 299 | " import ietf-origin {" |
| 300 | " prefix or;" |
| 301 | " }" |
| 302 | "" |
| 303 | " container cont {" |
| 304 | " leaf leaf1 {" |
| 305 | " type string;" |
| 306 | " }" |
| 307 | " leaf leaf2 {" |
| 308 | " type string;" |
| 309 | " }" |
| 310 | " leaf leaf3 {" |
| 311 | " type uint8;" |
| 312 | " }" |
| 313 | " }" |
| 314 | "}"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 315 | const char *data_xml = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 316 | "<cont xmlns=\"urn:test-origin\">\n" |
| 317 | " <leaf1 xmlns:or=\"urn:ietf:params:xml:ns:yang:ietf-origin\" or:origin=\"or:default\">value1</leaf1>\n" |
| 318 | " <leaf2>value2</leaf2>\n" |
| 319 | " <leaf3 xmlns:or=\"urn:ietf:params:xml:ns:yang:ietf-origin\" or:origin=\"or:system\">125</leaf3>\n" |
| 320 | "</cont>\n"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 321 | |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 322 | assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, origin_yang, LYS_IN_YANG, NULL)); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 323 | lys_set_implemented(ly_ctx_get_module_latest(st->ctx, "ietf-origin"), NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 324 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 325 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 326 | assert_ptr_not_equal(st->dt1, NULL); |
| 327 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 328 | ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 329 | assert_int_equal(ret, 0); |
| 330 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 331 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 332 | assert_ptr_not_equal(st->dt2, NULL); |
| 333 | |
| 334 | check_data_tree(st->dt1, st->dt2); |
| 335 | } |
| 336 | |
| 337 | static void |
| 338 | test_statements(void **state) |
| 339 | { |
| 340 | struct state *st = (*state); |
| 341 | int ret; |
| 342 | const char *links_yang = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 343 | "module links {\n" |
| 344 | " yang-version 1.1;\n" |
| 345 | " namespace \"urn:module2\";\n" |
| 346 | " prefix mod2;\n" |
| 347 | "\n" |
| 348 | " identity just-another-identity;\n" |
| 349 | "\n" |
| 350 | " leaf one-leaf {\n" |
| 351 | " type string;\n" |
| 352 | " }\n" |
| 353 | "\n" |
| 354 | " list list-for-augment {\n" |
| 355 | " key keyleaf;\n" |
| 356 | "\n" |
| 357 | " leaf keyleaf {\n" |
| 358 | " type string;\n" |
| 359 | " }\n" |
| 360 | "\n" |
| 361 | " leaf just-leaf {\n" |
| 362 | " type int32;\n" |
| 363 | " }\n" |
| 364 | " }\n" |
| 365 | "\n" |
| 366 | " leaf rleaf {\n" |
| 367 | " type string;\n" |
| 368 | " }\n" |
| 369 | "\n" |
| 370 | " leaf-list llist {\n" |
| 371 | " type string;\n" |
| 372 | " min-elements 0;\n" |
| 373 | " max-elements 100;\n" |
| 374 | " ordered-by user;\n" |
| 375 | " }\n" |
| 376 | "\n" |
| 377 | " grouping rgroup {\n" |
| 378 | " leaf rg1 {\n" |
| 379 | " type string;\n" |
| 380 | " }\n" |
| 381 | "\n" |
| 382 | " leaf rg2 {\n" |
| 383 | " type string;\n" |
| 384 | " }\n" |
| 385 | " }\n" |
| 386 | "}\n"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 387 | |
| 388 | const char *statements_yang = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 389 | "module statements {\n" |
| 390 | " namespace \"urn:module\";\n" |
| 391 | " prefix mod;\n" |
| 392 | " yang-version 1.1;\n" |
| 393 | "\n" |
| 394 | " import links {\n" |
| 395 | " prefix mod2;\n" |
| 396 | " }\n" |
| 397 | "\n" |
| 398 | " identity random-identity {\n" |
| 399 | " base \"mod2:just-another-identity\";\n" |
| 400 | " base \"another-identity\";\n" |
| 401 | " }\n" |
| 402 | "\n" |
| 403 | " identity another-identity {\n" |
| 404 | " base \"mod2:just-another-identity\";\n" |
| 405 | " }\n" |
| 406 | "\n" |
| 407 | " typedef percent {\n" |
| 408 | " type uint8 {\n" |
| 409 | " range \"0 .. 100\";\n" |
| 410 | " }\n" |
| 411 | " units percent;\n" |
| 412 | " }\n" |
| 413 | "\n" |
| 414 | " container ice-cream-shop {\n" |
| 415 | " container employees {\n" |
| 416 | " list employee {\n" |
| 417 | " config true;\n" |
| 418 | " key id;\n" |
| 419 | " unique name;\n" |
| 420 | " min-elements 0;\n" |
| 421 | " max-elements 100;\n" |
| 422 | "\n" |
| 423 | " leaf id {\n" |
| 424 | " type uint64;\n" |
| 425 | " mandatory true;\n" |
| 426 | " }\n" |
| 427 | "\n" |
| 428 | " leaf name {\n" |
| 429 | " type string;\n" |
| 430 | " }\n" |
| 431 | "\n" |
| 432 | " leaf age {\n" |
| 433 | " type uint32;\n" |
| 434 | " }\n" |
| 435 | " }\n" |
| 436 | " }\n" |
| 437 | " }\n" |
| 438 | "\n" |
| 439 | " container random {\n" |
| 440 | " choice switch {\n" |
| 441 | " case a {\n" |
| 442 | " leaf aleaf {\n" |
| 443 | " type string;\n" |
| 444 | " default aaa;\n" |
| 445 | " }\n" |
| 446 | " }\n" |
| 447 | "\n" |
| 448 | " case c {\n" |
| 449 | " leaf cleaf {\n" |
| 450 | " type string;\n" |
| 451 | " }\n" |
| 452 | " }\n" |
| 453 | " }\n" |
| 454 | "\n" |
| 455 | " anyxml xml-data;\n" |
| 456 | " anydata any-data;\n" |
| 457 | " leaf-list leaflist {\n" |
| 458 | " type string;\n" |
| 459 | " min-elements 0;\n" |
| 460 | " max-elements 20;\n" |
| 461 | " ordered-by system;\n" |
| 462 | " }\n" |
| 463 | "\n" |
| 464 | " grouping group {\n" |
| 465 | " leaf g1 {\n" |
| 466 | " mandatory false;\n" |
| 467 | " type percent;\n" |
| 468 | " }\n" |
| 469 | "\n" |
| 470 | " leaf g2 {\n" |
| 471 | " type string;\n" |
| 472 | " }\n" |
| 473 | " }\n" |
| 474 | "\n" |
| 475 | " uses group;\n" |
| 476 | " uses mod2:rgroup;\n" |
| 477 | "\n" |
| 478 | " leaf lref {\n" |
| 479 | " type leafref {\n" |
| 480 | " path \"/mod2:one-leaf\";\n" |
| 481 | " }\n" |
| 482 | " }\n" |
| 483 | "\n" |
| 484 | " leaf iref {\n" |
| 485 | " type identityref {\n" |
| 486 | " base \"mod2:just-another-identity\";\n" |
| 487 | " }\n" |
| 488 | " }\n" |
| 489 | " }\n" |
| 490 | "\n" |
| 491 | " augment \"/random\" {\n" |
| 492 | " leaf aug-leaf {\n" |
| 493 | " type string;\n" |
| 494 | " }\n" |
| 495 | " }\n" |
| 496 | "}\n"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 497 | |
| 498 | const char *data_xml = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 499 | "<ice-cream-shop xmlns=\"urn:module\">\n" |
| 500 | " <employees>\n" |
| 501 | " <employee>\n" |
| 502 | " <id>0</id>\n" |
| 503 | " <name>John Doe</name>\n" |
| 504 | " <age>28</age>\n" |
| 505 | " </employee>\n" |
| 506 | " <employee>\n" |
| 507 | " <id>1</id>\n" |
| 508 | " <name>Dohn Joe</name>\n" |
| 509 | " <age>20</age>\n" |
| 510 | " </employee>\n" |
| 511 | " </employees>\n" |
| 512 | "</ice-cream-shop>\n" |
| 513 | "<one-leaf xmlns=\"urn:module2\">reference leaf</one-leaf>\n" |
| 514 | "<random xmlns=\"urn:module\">\n" |
| 515 | " <aleaf>string</aleaf>\n" |
| 516 | " <xml-data><anyxml>data</anyxml></xml-data>\n" |
| 517 | " <any-data><data>any data</data></any-data>\n" |
| 518 | " <leaflist>l0</leaflist>\n" |
| 519 | " <leaflist>l1</leaflist>\n" |
| 520 | " <leaflist>l2</leaflist>\n" |
| 521 | " <g1>40</g1>\n" |
| 522 | " <g2>string</g2>\n" |
| 523 | " <aug-leaf>string</aug-leaf>\n" |
| 524 | " <rg1>string</rg1>\n" |
| 525 | " <rg2>string</rg2>\n" |
| 526 | " <lref>reference leaf</lref>\n" |
| 527 | " <iref>random-identity</iref>\n" |
| 528 | "</random>\n"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 529 | |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 530 | assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, links_yang, LYS_IN_YANG, NULL)); |
| 531 | assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, statements_yang, LYS_IN_YANG, NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 532 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 533 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 534 | assert_ptr_not_equal(st->dt1, NULL); |
| 535 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 536 | ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 537 | assert_int_equal(ret, 0); |
| 538 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 539 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 540 | assert_ptr_not_equal(st->dt2, NULL); |
| 541 | |
| 542 | check_data_tree(st->dt1, st->dt2); |
| 543 | } |
| 544 | |
| 545 | // static void |
| 546 | // test_types(void **state) |
| 547 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 548 | // struct state *st = (*state); |
| 549 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 550 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 551 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 552 | // assert_non_null(ly_ctx_load_module(st->ctx, "types", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 553 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 554 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/types.xml", LYD_XML, LYD_OPT_CONFIG); |
| 555 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 556 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 557 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 558 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 559 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 560 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 561 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 562 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 563 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 564 | // } |
| 565 | // |
| 566 | // static void |
| 567 | // test_annotations(void **state) |
| 568 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 569 | // struct state *st = (*state); |
| 570 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 571 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 572 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 573 | // assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 574 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 575 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/annotations.xml", LYD_XML, LYD_OPT_CONFIG); |
| 576 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 577 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 578 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 579 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 580 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 581 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 582 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 583 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 584 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 585 | // } |
| 586 | // |
| 587 | // static void |
| 588 | // test_similar_annot_names(void **state) |
| 589 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 590 | // struct state *st = (*state); |
| 591 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 592 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 593 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 594 | // assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 595 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 596 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/similar-annot-names.xml", LYD_XML, LYD_OPT_CONFIG); |
| 597 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 598 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 599 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 600 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 601 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 602 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 603 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 604 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 605 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 606 | // } |
| 607 | // |
| 608 | // static void |
| 609 | // test_many_child_annot(void **state) |
| 610 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 611 | // struct state *st = (*state); |
| 612 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 613 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 614 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 615 | // assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 616 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 617 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/many-childs-annot.xml", LYD_XML, LYD_OPT_CONFIG); |
| 618 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 619 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 620 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 621 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 622 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 623 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 624 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 625 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 626 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 627 | // } |
| 628 | // |
| 629 | // static void |
| 630 | // test_union(void **state) |
| 631 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 632 | // struct state *st = (*state); |
| 633 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 634 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 635 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 636 | // assert_non_null(ly_ctx_load_module(st->ctx, "union", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 637 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 638 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/union.xml", LYD_XML, LYD_OPT_CONFIG); |
| 639 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 640 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 641 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 642 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 643 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 644 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 645 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 646 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 647 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 648 | // } |
| 649 | // |
| 650 | // static void |
| 651 | // test_union2(void **state) |
| 652 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 653 | // struct state *st = (*state); |
| 654 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 655 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 656 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 657 | // assert_non_null(ly_ctx_load_module(st->ctx, "statements", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 658 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 659 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/union2.xml", LYD_XML, LYD_OPT_CONFIG); |
| 660 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 661 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 662 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 663 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 664 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 665 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 666 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 667 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 668 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 669 | // } |
| 670 | // |
| 671 | // static void |
| 672 | // test_collisions(void **state) |
| 673 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 674 | // struct state *st = (*state); |
| 675 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 676 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 677 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 678 | // assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 679 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 680 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/collisions.xml", LYD_XML, LYD_OPT_CONFIG); |
| 681 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 682 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 683 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 684 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 685 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 686 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 687 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 688 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 689 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 690 | // } |
| 691 | // |
| 692 | // static void |
| 693 | // test_anydata(void **state) |
| 694 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 695 | // struct state *st = (*state); |
| 696 | // const struct lys_module *mod; |
| 697 | // int ret; |
| 698 | // const char *test_anydata = |
| 699 | // "module test-anydata {" |
| 700 | // " namespace \"urn:test-anydata\";" |
| 701 | // " prefix ya;" |
| 702 | // "" |
| 703 | // " container cont {" |
| 704 | // " anydata ntf;" |
| 705 | // " }" |
| 706 | // "}"; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 707 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 708 | // assert_non_null(ly_ctx_load_module(st->ctx, "ietf-netconf-notifications", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 709 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 710 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL); |
| 711 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 712 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 713 | /// * get notification in LYB format to set as anydata content */ |
| 714 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 715 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 716 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 717 | // lyd_free_withsiblings(st->dt1); |
| 718 | // st->dt1 = NULL; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 719 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 720 | /// * now comes the real test, test anydata */ |
| 721 | // mod = lys_parse_mem(st->ctx, test_anydata, LYS_YANG); |
| 722 | // assert_non_null(mod); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 723 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 724 | // st->dt1 = lyd_new(NULL, mod, "cont"); |
| 725 | // assert_non_null(st->dt1); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 726 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 727 | // assert_non_null(lyd_new_anydata(st->dt1, NULL, "ntf", st->mem, LYD_ANYDATA_LYBD)); |
| 728 | // st->mem = NULL; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 729 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 730 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 731 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 732 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 733 | // ret = lyd_validate(&st->dt1, LYD_OPT_CONFIG, NULL); |
| 734 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 735 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 736 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 737 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 738 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 739 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 740 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 741 | /// * and also test the embedded notification itself */ |
| 742 | // free(st->mem); |
| 743 | // ret = lyd_lyb_data_length(((struct lyd_node_anydata *)st->dt1->child)->value.mem); |
| 744 | // st->mem = malloc(ret); |
| 745 | // memcpy(st->mem, ((struct lyd_node_anydata *)st->dt1->child)->value.mem, ret); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 746 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 747 | // lyd_free_withsiblings(st->dt2); |
| 748 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_NOTIF | LYD_OPT_STRICT | LYD_OPT_NOEXTDEPS, NULL); |
| 749 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 750 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 751 | /// * parse the JSON again for this comparison */ |
| 752 | // lyd_free_withsiblings(st->dt1); |
| 753 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL); |
| 754 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 755 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 756 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 757 | // } |
| 758 | // |
| 759 | // static void |
| 760 | // test_submodule_feature(void **state) |
| 761 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 762 | // struct state *st = (*state); |
| 763 | // const struct lys_module *mod; |
| 764 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 765 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 766 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 767 | // mod = ly_ctx_load_module(st->ctx, "feature-submodule-main", NULL); |
| 768 | // assert_non_null(mod); |
| 769 | // assert_int_equal(lys_features_enable(mod, "test-submodule-feature"), 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 770 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 771 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/test-submodule-feature.json", LYD_JSON, LYD_OPT_CONFIG); |
| 772 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 773 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 774 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 775 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 776 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 777 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 778 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 779 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 780 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 781 | // } |
| 782 | // |
| 783 | // static void |
| 784 | // test_coliding_augments(void **state) |
| 785 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 786 | // struct state *st = (*state); |
| 787 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 788 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 789 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 790 | // assert_non_null(ly_ctx_load_module(st->ctx, "augment-target", NULL)); |
| 791 | // assert_non_null(ly_ctx_load_module(st->ctx, "augment0", NULL)); |
| 792 | // assert_non_null(ly_ctx_load_module(st->ctx, "augment1", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 793 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 794 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/augment.xml", LYD_XML, LYD_OPT_CONFIG); |
| 795 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 796 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 797 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 798 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 799 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 800 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 801 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 802 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 803 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 804 | // } |
| 805 | // |
| 806 | // static void |
| 807 | // test_leafrefs(void **state) |
| 808 | // { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 809 | // struct state *st = (*state); |
| 810 | // int ret; |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 811 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 812 | // ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files"); |
| 813 | // assert_non_null(ly_ctx_load_module(st->ctx, "leafrefs2", NULL)); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 814 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 815 | // st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/leafrefs2.json", LYD_JSON, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 816 | // assert_ptr_not_equal(st->dt1, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 817 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 818 | // ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS); |
| 819 | // assert_int_equal(ret, 0); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 820 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 821 | // st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT); |
| 822 | // assert_ptr_not_equal(st->dt2, NULL); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 823 | // |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 824 | // check_data_tree(st->dt1, st->dt2); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 825 | // } |
| 826 | |
| 827 | int |
| 828 | main(void) |
| 829 | { |
| 830 | const struct CMUnitTest tests[] = { |
| 831 | cmocka_unit_test_setup_teardown(test_ietf_interfaces, setup_f, teardown_f), |
| 832 | cmocka_unit_test_setup_teardown(test_origin, setup_f, teardown_f), |
| 833 | cmocka_unit_test_setup_teardown(test_statements, setup_f, teardown_f), |
| 834 | /*cmocka_unit_test_setup_teardown(test_types, setup_f, teardown_f), |
| 835 | cmocka_unit_test_setup_teardown(test_annotations, setup_f, teardown_f), |
| 836 | cmocka_unit_test_setup_teardown(test_similar_annot_names, setup_f, teardown_f), |
| 837 | cmocka_unit_test_setup_teardown(test_many_child_annot, setup_f, teardown_f), |
| 838 | cmocka_unit_test_setup_teardown(test_union, setup_f, teardown_f), |
| 839 | cmocka_unit_test_setup_teardown(test_union2, setup_f, teardown_f), |
| 840 | cmocka_unit_test_setup_teardown(test_collisions, setup_f, teardown_f), |
| 841 | cmocka_unit_test_setup_teardown(test_anydata, setup_f, teardown_f), |
| 842 | cmocka_unit_test_setup_teardown(test_submodule_feature, setup_f, teardown_f), |
| 843 | cmocka_unit_test_setup_teardown(test_coliding_augments, setup_f, teardown_f), |
| 844 | cmocka_unit_test_setup_teardown(test_leafrefs, setup_f, teardown_f),*/ |
| 845 | }; |
| 846 | |
| 847 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 848 | } |