Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 1 | /** |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 2 | * @file test_parser_xml.c |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 5 | * @brief unit tests for functions from parser_xml.c |
| 6 | * |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 7 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +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" |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 17 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 18 | #include "context.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 19 | #include "in.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 20 | #include "out.h" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 21 | #include "parser_data.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 22 | #include "printer_data.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 23 | #include "tree_data_internal.h" |
| 24 | #include "tree_schema.h" |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 25 | |
| 26 | static int |
| 27 | setup(void **state) |
| 28 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 29 | const char *schema = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 30 | "module a {\n" |
| 31 | " namespace urn:tests:a;\n" |
| 32 | " prefix a;\n" |
| 33 | " yang-version 1.1;\n" |
Michal Vasko | dd03ff1 | 2023-09-11 10:30:48 +0200 | [diff] [blame] | 34 | " import ietf-yang-metadata {prefix md;}" |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 35 | " list l1 { key \"a b c\"; leaf a {type string;} leaf b {type string;} leaf c {type int16;}" |
| 36 | " leaf d {type string;}" |
| 37 | " container cont {leaf e {type boolean;}}" |
| 38 | " }" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 39 | " leaf foo { type string;}\n" |
| 40 | " container c {\n" |
| 41 | " leaf x {type string;}\n" |
| 42 | " action act { input { leaf al {type string;} } output { leaf al {type uint8;} } }\n" |
| 43 | " notification n1 { leaf nl {type string;}}}\n" |
| 44 | " container cp {presence \"container switch\"; leaf y {type string;} leaf z {type int8;}}\n" |
| 45 | " anydata any {config false;}\n" |
Michal Vasko | 5b414dd | 2023-04-13 10:29:58 +0200 | [diff] [blame] | 46 | " anyxml anyx;\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 47 | " leaf foo2 { type string; default \"default-val\"; }\n" |
| 48 | " leaf foo3 { type uint32; }\n" |
Michal Vasko | dd03ff1 | 2023-09-11 10:30:48 +0200 | [diff] [blame] | 49 | " notification n2;" |
| 50 | " md:annotation attr {type enumeration {enum val;}}" |
| 51 | "}"; |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 52 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 53 | UTEST_SETUP; |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 54 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 55 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); |
| 56 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG)); |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 61 | #define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \ |
| 62 | CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 63 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 64 | #define PARSER_CHECK_ERROR(INPUT, PARSE_OPTION, VALIDATE_OPTION, MODEL, RET_VAL, ERR_MESSAGE, ERR_PATH, ERR_LINE) \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 65 | assert_int_equal(RET_VAL, lyd_parse_data_mem(UTEST_LYCTX, INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, &MODEL));\ |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 66 | CHECK_LOG_CTX(ERR_MESSAGE, ERR_PATH, ERR_LINE);\ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 67 | assert_null(MODEL) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 68 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 69 | #define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \ |
| 70 | CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, PRINT_OPTION) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 71 | |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 72 | static void |
| 73 | test_leaf(void **state) |
| 74 | { |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 75 | const char *data = "<foo xmlns=\"urn:tests:a\">foo value</foo>"; |
| 76 | struct lyd_node *tree; |
| 77 | struct lyd_node_term *leaf; |
| 78 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 79 | assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL)); |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 80 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 81 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 82 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0); |
| 83 | leaf = (struct lyd_node_term *)tree; |
| 84 | CHECK_LYD_VALUE(leaf->value, STRING, "foo value"); |
| 85 | |
| 86 | CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2", |
| 87 | 1, LYS_LEAF, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 88 | leaf = (struct lyd_node_term *)tree->next->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 89 | CHECK_LYD_VALUE(leaf->value, STRING, "default-val"); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 90 | assert_true(leaf->flags & LYD_DEFAULT); |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 91 | lyd_free_all(tree); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 92 | |
| 93 | /* make foo2 explicit */ |
| 94 | data = "<foo2 xmlns=\"urn:tests:a\">default-val</foo2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 95 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 96 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 97 | tree = tree->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 98 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2", |
| 99 | 1, LYS_LEAF, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 100 | leaf = (struct lyd_node_term *)tree; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 101 | CHECK_LYD_VALUE(leaf->value, STRING, "default-val"); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 102 | assert_false(leaf->flags & LYD_DEFAULT); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 103 | lyd_free_all(tree); |
| 104 | |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 105 | /* parse foo2 but make it implicit, skip metadata xxx from missing schema */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 106 | data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" " |
| 107 | "wd:default=\"true\" xmlns:x=\"urn:x\" x:xxx=\"false\">default-val</foo2>"; |
| 108 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 109 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 110 | tree = tree->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 111 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2", |
| 112 | 1, LYS_LEAF, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 113 | leaf = (struct lyd_node_term *)tree; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 114 | CHECK_LYD_VALUE(leaf->value, STRING, "default-val"); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 115 | assert_true(leaf->flags & LYD_DEFAULT); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 116 | lyd_free_all(tree); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 117 | |
| 118 | /* invalid value */ |
| 119 | data = "<l1 xmlns=\"urn:tests:a\"><a>val-a</a><b>val-b</b><c>1</c><cont><e>0</e></cont></l1>"; |
| 120 | PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 121 | "Invalid boolean value \"0\".", "/a:l1[a='val-a'][b='val-b'][c='1']/cont/e", 1); |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 124 | static void |
| 125 | test_anydata(void **state) |
| 126 | { |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 127 | const char *data; |
Michal Vasko | 5b414dd | 2023-04-13 10:29:58 +0200 | [diff] [blame] | 128 | char *str; |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 129 | struct lyd_node *tree; |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 130 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 131 | data = "<any xmlns=\"urn:tests:a\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 132 | " <element1>\n" |
| 133 | " <x:element2 x:attr2=\"test\" xmlns:a=\"urn:tests:a\" xmlns:x=\"urn:x\">a:data</x:element2>\n" |
| 134 | " </element1>\n" |
| 135 | " <element1a/>\n" |
| 136 | "</any>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 137 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 138 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 139 | tree = tree->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 140 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_SET_CONFIG, 1, "any", |
| 141 | 1, LYS_ANYDATA, 0, 0, NULL, 0); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 142 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 143 | const char *data_expected = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 144 | "<any xmlns=\"urn:tests:a\">\n" |
| 145 | " <element1>\n" |
| 146 | " <element2 xmlns=\"urn:x\" xmlns:x=\"urn:x\" x:attr2=\"test\" xmlns:a=\"urn:tests:a\">a:data</element2>\n" |
| 147 | " </element1>\n" |
| 148 | " <element1a/>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 149 | "</any>\n"; |
| 150 | |
| 151 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected); |
Michal Vasko | 5b414dd | 2023-04-13 10:29:58 +0200 | [diff] [blame] | 152 | |
| 153 | assert_int_equal(LY_SUCCESS, lyd_any_value_str(tree, &str)); |
| 154 | lyd_free_all(tree); |
| 155 | |
| 156 | assert_int_equal(LY_SUCCESS, lyd_new_path2(NULL, UTEST_LYCTX, "/a:any", str, strlen(str), LYD_ANYDATA_XML, 0, &tree, NULL)); |
| 157 | free(str); |
| 158 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected); |
| 159 | lyd_free_all(tree); |
| 160 | } |
| 161 | |
| 162 | static void |
| 163 | test_anyxml(void **state) |
| 164 | { |
| 165 | const char *data; |
| 166 | char *str; |
| 167 | struct lyd_node *tree; |
| 168 | |
| 169 | data = "<anyx xmlns=\"urn:tests:a\">\n" |
| 170 | " <element1>\n" |
| 171 | " <element2 x:attr2=\"test\" xmlns:x=\"urn:x\">data</element2>\n" |
| 172 | " </element1>\n" |
| 173 | " <element1a/>\n" |
| 174 | "</anyx>\n"; |
| 175 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 176 | assert_non_null(tree); |
| 177 | tree = tree->next; |
| 178 | |
| 179 | const char *data_expected = |
| 180 | "<anyx xmlns=\"urn:tests:a\">\n" |
| 181 | " <element1>\n" |
| 182 | " <element2 xmlns:x=\"urn:x\" x:attr2=\"test\">data</element2>\n" |
| 183 | " </element1>\n" |
| 184 | " <element1a/>\n" |
| 185 | "</anyx>\n"; |
| 186 | |
| 187 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected); |
| 188 | |
| 189 | assert_int_equal(LY_SUCCESS, lyd_any_value_str(tree, &str)); |
| 190 | lyd_free_all(tree); |
| 191 | |
| 192 | assert_int_equal(LY_SUCCESS, lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", str, strlen(str), LYD_ANYDATA_XML, 0, &tree, NULL)); |
| 193 | free(str); |
| 194 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected); |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 195 | lyd_free_all(tree); |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 198 | static void |
| 199 | test_list(void **state) |
| 200 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 201 | const char *data; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 202 | struct lyd_node *tree, *iter; |
| 203 | struct lyd_node_inner *list; |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 204 | struct lyd_node_term *leaf; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 205 | |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 206 | /* check hashes */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 207 | data = "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>1</c></l1>"; |
| 208 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 209 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", |
| 210 | 1, LYS_LIST, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 211 | list = (struct lyd_node_inner *)tree; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 212 | LY_LIST_FOR(list->child, iter) { |
| 213 | assert_int_not_equal(0, iter->hash); |
| 214 | } |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 215 | lyd_free_all(tree); |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 216 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 217 | /* missing keys */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 218 | PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 219 | "List instance is missing its key \"a\".", "/a:l1[b='b'][c='1']", 1); |
| 220 | CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL, 0); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 221 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 222 | PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><a>a</a></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 223 | "List instance is missing its key \"b\".", "/a:l1[a='a']", 1); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 224 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 225 | PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><b>b</b><a>a</a></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 226 | "List instance is missing its key \"c\".", "/a:l1[a='a'][b='b']", 1); |
| 227 | CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL, 0); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 228 | |
| 229 | /* key duplicate */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 230 | PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a><c>1</c></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 231 | "Duplicate instance of \"c\".", "/a:l1[a='a'][b='b'][c='1'][c='1']/c", 1); |
| 232 | CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL, 0); |
| 233 | CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL, 0); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 234 | |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 235 | /* keys order */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 236 | CHECK_PARSE_LYD("<l1 xmlns=\"urn:tests:a\"><d>d</d><a>a</a><c>1</c><b>b</b></l1>", 0, LYD_VALIDATE_PRESENT, tree); |
| 237 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", |
| 238 | 1, LYS_LIST, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 239 | list = (struct lyd_node_inner *)tree; |
| 240 | assert_non_null(leaf = (struct lyd_node_term *)list->child); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 241 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 242 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 243 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b", 1, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 244 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 245 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 246 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 247 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "d", 1, LYS_LEAF, 1, 0, NULL, 0); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 248 | CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL, 0); |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 249 | lyd_free_all(tree); |
| 250 | |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 251 | data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a></l1>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 252 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 253 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", 1, LYS_LIST, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 254 | list = (struct lyd_node_inner *)tree; |
| 255 | assert_non_null(leaf = (struct lyd_node_term *)list->child); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 256 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 257 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 258 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b", 1, LYS_LEAF, 1, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 259 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 260 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 261 | CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL, 0); |
| 262 | CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL, 0); |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 263 | lyd_free_all(tree); |
| 264 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 265 | PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 266 | "Invalid position of the key \"b\" in a list.", "/a:l1[c='1']/b", 1); |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 269 | static void |
| 270 | test_container(void **state) |
| 271 | { |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 272 | struct lyd_node *tree; |
| 273 | struct lyd_node_inner *cont; |
| 274 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 275 | CHECK_PARSE_LYD("<c xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree); |
| 276 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 277 | cont = (struct lyd_node_inner *)tree; |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 278 | assert_true(cont->flags & LYD_DEFAULT); |
| 279 | lyd_free_all(tree); |
| 280 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 281 | CHECK_PARSE_LYD("<cp xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree); |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 282 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 283 | tree = tree->next; |
Michal Vasko | e16c7b7 | 2021-02-26 10:39:06 +0100 | [diff] [blame] | 284 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp", |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 285 | 1, LYS_CONTAINER, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 286 | cont = (struct lyd_node_inner *)tree; |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 287 | assert_false(cont->flags & LYD_DEFAULT); |
| 288 | lyd_free_all(tree); |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 291 | static void |
| 292 | test_opaq(void **state) |
| 293 | { |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 294 | const char *data; |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 295 | struct lyd_node *tree; |
| 296 | |
| 297 | /* invalid value, no flags */ |
| 298 | data = "<foo3 xmlns=\"urn:tests:a\"/>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 299 | PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 300 | "Invalid type uint32 empty value.", "/a:foo3", 1); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 301 | |
| 302 | /* opaq flag */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 303 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 304 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_XML, "foo3", 0, 0, NULL, 1, ""); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 305 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, "<foo3 xmlns=\"urn:tests:a\"/>\n"); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 306 | lyd_free_all(tree); |
| 307 | |
Michal Vasko | da8fbbf | 2021-06-16 11:44:44 +0200 | [diff] [blame] | 308 | /* list, opaq flag */ |
| 309 | data = "<l1 xmlns=\"urn:tests:a\"/>"; |
| 310 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 311 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_XML, "l1", 0, 0, NULL, 1, ""); |
Michal Vasko | da8fbbf | 2021-06-16 11:44:44 +0200 | [diff] [blame] | 312 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, "<l1 xmlns=\"urn:tests:a\"/>\n"); |
| 313 | lyd_free_all(tree); |
| 314 | |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 315 | /* missing key, no flags */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 316 | data = "<l1 xmlns=\"urn:tests:a\">\n" |
| 317 | " <a>val_a</a>\n" |
| 318 | " <b>val_b</b>\n" |
| 319 | " <d>val_d</d>\n" |
| 320 | "</l1>\n"; |
| 321 | PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 322 | "List instance is missing its key \"c\".", "/a:l1[a='val_a'][b='val_b']", 5); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 323 | |
| 324 | /* opaq flag */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 325 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 326 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, ""); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 327 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 328 | lyd_free_all(tree); |
| 329 | |
| 330 | /* invalid key, no flags */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 331 | data = "<l1 xmlns=\"urn:tests:a\">\n" |
| 332 | " <a>val_a</a>\n" |
| 333 | " <b>val_b</b>\n" |
| 334 | " <c>val_c</c>\n" |
| 335 | "</l1>\n"; |
| 336 | PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 337 | "Invalid type int16 value \"val_c\".", "/a:l1[a='val_a'][b='val_b']/c", 4); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 338 | |
| 339 | /* opaq flag */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 340 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 341 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, ""); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 342 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 343 | lyd_free_all(tree); |
| 344 | |
Michal Vasko | 413c7f2 | 2020-05-05 12:34:06 +0200 | [diff] [blame] | 345 | /* opaq flag and fail */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 346 | assert_int_equal(LY_EVALID, lyd_parse_data_mem(UTEST_LYCTX, |
| 347 | "<a xmlns=\"ns\">\n" |
| 348 | " <b>x</b>\n" |
Michal Vasko | e137fc4 | 2021-07-22 11:53:13 +0200 | [diff] [blame] | 349 | " <c xmld:id=\"D\">1</c>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 350 | "</a>\n", |
| 351 | LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 352 | CHECK_LOG_CTX("Unknown XML prefix \"xmld\".", "/a", 3); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 355 | static void |
| 356 | test_rpc(void **state) |
| 357 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 358 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 359 | struct ly_in *in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 360 | struct lyd_node *tree, *op; |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 361 | const struct lyd_node *node; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 362 | const char *dsc = "The <edit-config> operation loads all or part of a specified\n" |
| 363 | "configuration to the specified target configuration."; |
| 364 | const char *ref = "RFC 6241, Section 7.2"; |
| 365 | const char *feats[] = {"writable-running", NULL}; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 366 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 367 | assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats))); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 368 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 369 | data = "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 370 | " <target>\n" |
| 371 | " <running/>\n" |
| 372 | " </target>\n" |
| 373 | " <config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 374 | " <l1 xmlns=\"urn:tests:a\" nc:operation=\"replace\">\n" |
| 375 | " <a>val_a</a>\n" |
| 376 | " <b>val_b</b>\n" |
| 377 | " <c>val_c</c>\n" |
| 378 | " </l1>\n" |
| 379 | " <cp xmlns=\"urn:tests:a\">\n" |
| 380 | " <z nc:operation=\"delete\"/>\n" |
| 381 | " </cp>\n" |
| 382 | " </config>\n" |
| 383 | "</edit-config>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 384 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 385 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, &op)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 386 | ly_in_free(in, 0); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 387 | |
| 388 | assert_non_null(op); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 389 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 390 | CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, dsc, 0, LYS_STATUS_CURR, |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 391 | 1, 0, 0, 1, "edit-config", LYS_RPC, |
| 392 | 0, 0, 0, 0, 0, ref, 0); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 393 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 394 | assert_non_null(tree); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 395 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 396 | node = tree; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 397 | CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR, |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 398 | 1, 0, 0, 1, "edit-config", LYS_RPC, |
| 399 | 0, 0, 0, 0, 0, ref, 0); |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 400 | node = lyd_child(node)->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 401 | dsc = "Inline Config content."; |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 402 | CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0); |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 403 | |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 404 | node = ((struct lyd_node_any *)node)->value.tree; |
Michal Vasko | e16c7b7 | 2021-02-26 10:39:06 +0100 | [diff] [blame] | 405 | CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp", |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 406 | 1, LYS_CONTAINER, 0, 0, NULL, 0); |
| 407 | |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 408 | node = lyd_child(node); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 409 | /* z has no value */ |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 410 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_XML, "z", 0, 0, NULL, 1, ""); |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 411 | node = node->parent->next; |
| 412 | /* l1 key c has invalid value so it is at the end */ |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 413 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, ""); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 414 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 415 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 416 | "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 417 | " <target>\n" |
| 418 | " <running/>\n" |
| 419 | " </target>\n" |
| 420 | " <config>\n" |
| 421 | " <cp xmlns=\"urn:tests:a\">\n" |
| 422 | " <z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"delete\"/>\n" |
| 423 | " </cp>\n" |
| 424 | " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">\n" |
| 425 | " <a>val_a</a>\n" |
| 426 | " <b>val_b</b>\n" |
| 427 | " <c>val_c</c>\n" |
| 428 | " </l1>\n" |
| 429 | " </config>\n" |
| 430 | "</edit-config>\n"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 431 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 432 | lyd_free_all(tree); |
| 433 | |
| 434 | /* wrong namespace, element name, whatever... */ |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 435 | /* TODO */ |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static void |
| 439 | test_action(void **state) |
| 440 | { |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 441 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 442 | struct ly_in *in; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 443 | struct lyd_node *tree, *op; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 444 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 445 | data = "<c xmlns=\"urn:tests:a\">\n" |
| 446 | " <act>\n" |
| 447 | " <al>value</al>\n" |
| 448 | " </act>\n" |
| 449 | "</c>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 450 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 451 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, &op)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 452 | ly_in_free(in, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 453 | |
| 454 | assert_non_null(op); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 455 | CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR, |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 456 | 1, 0, 0, 1, "act", LYS_ACTION, |
| 457 | 1, 0, 0, 1, 0, NULL, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 458 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 459 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 460 | "<c xmlns=\"urn:tests:a\">\n" |
| 461 | " <act>\n" |
| 462 | " <al>value</al>\n" |
| 463 | " </act>\n" |
| 464 | "</c>\n"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 465 | |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 466 | lyd_free_all(tree); |
| 467 | |
| 468 | /* wrong namespace, element name, whatever... */ |
| 469 | /* TODO */ |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static void |
| 473 | test_notification(void **state) |
| 474 | { |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 475 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 476 | struct ly_in *in; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 477 | struct lyd_node *tree, *ntf; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 478 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 479 | data = "<c xmlns=\"urn:tests:a\">\n" |
| 480 | " <n1>\n" |
| 481 | " <nl>value</nl>\n" |
| 482 | " </n1>\n" |
| 483 | "</c>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 484 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 485 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_YANG, &tree, &ntf)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 486 | ly_in_free(in, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 487 | |
| 488 | assert_non_null(ntf); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 489 | CHECK_LYSC_NOTIF((struct lysc_node_notif *)ntf->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 490 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 491 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 492 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 493 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 494 | lyd_free_all(tree); |
| 495 | |
| 496 | /* top-level notif without envelope */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 497 | data = "<n2 xmlns=\"urn:tests:a\"/>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 498 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 499 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_YANG, &tree, &ntf)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 500 | ly_in_free(in, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 501 | |
| 502 | assert_non_null(ntf); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 503 | CHECK_LYSC_NOTIF((struct lysc_node_notif *)ntf->schema, 0, NULL, 0, 0x4, 1, 0, "n2", 0, 0, NULL, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 504 | |
| 505 | assert_non_null(tree); |
| 506 | assert_ptr_equal(ntf, tree); |
| 507 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 508 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 509 | lyd_free_all(tree); |
| 510 | |
| 511 | /* wrong namespace, element name, whatever... */ |
| 512 | /* TODO */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 515 | static void |
| 516 | test_reply(void **state) |
| 517 | { |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 518 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 519 | struct ly_in *in; |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 520 | struct lyd_node *tree, *op; |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 521 | const struct lyd_node *node; |
| 522 | |
Michal Vasko | 79135ae | 2020-12-16 10:08:35 +0100 | [diff] [blame] | 523 | data = "<c xmlns=\"urn:tests:a\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 524 | " <act>\n" |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 525 | " <al>25</al>\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 526 | " </act>\n" |
| 527 | "</c>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 528 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 529 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_REPLY_YANG, &tree, &op)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 530 | ly_in_free(in, 0); |
| 531 | |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 532 | assert_non_null(op); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 533 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 534 | CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR, |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 535 | 1, 0, 0, 1, "act", LYS_ACTION, |
| 536 | 1, 0, 0, 1, 0, NULL, 0); |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 537 | node = lyd_child(op); |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 538 | CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_STATUS_CURR | LYS_IS_OUTPUT, 1, "al", 0, LYS_LEAF, 1, 0, NULL, 0); |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 539 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 540 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0); |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 541 | |
| 542 | /* TODO print only rpc-reply node and then output subtree */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 543 | CHECK_LYD_STRING(lyd_child(op), LYD_PRINT_WITHSIBLINGS, "<al xmlns=\"urn:tests:a\">25</al>\n"); |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 544 | lyd_free_all(tree); |
| 545 | |
| 546 | /* wrong namespace, element name, whatever... */ |
| 547 | /* TODO */ |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 550 | static void |
| 551 | test_netconf_rpc(void **state) |
| 552 | { |
| 553 | const char *data; |
| 554 | struct ly_in *in; |
| 555 | struct lyd_node *tree, *op; |
| 556 | const struct lyd_node *node; |
| 557 | const char *dsc = "The <edit-config> operation loads all or part of a specified\n" |
| 558 | "configuration to the specified target configuration."; |
| 559 | const char *ref = "RFC 6241, Section 7.2"; |
| 560 | const char *feats[] = {"writable-running", NULL}; |
| 561 | |
| 562 | assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats))); |
| 563 | |
| 564 | data = "<rpc message-id=\"25\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" |
| 565 | "<edit-config>\n" |
| 566 | " <target>\n" |
| 567 | " <running/>\n" |
| 568 | " </target>\n" |
| 569 | " <config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 570 | " <l1 xmlns=\"urn:tests:a\" nc:operation=\"replace\">\n" |
| 571 | " <a>val_a</a>\n" |
| 572 | " <b>val_b</b>\n" |
| 573 | " <c>val_c</c>\n" |
| 574 | " </l1>\n" |
| 575 | " <cp xmlns=\"urn:tests:a\">\n" |
| 576 | " <z nc:operation=\"delete\"/>\n" |
| 577 | " </cp>\n" |
| 578 | " </config>\n" |
| 579 | "</edit-config>\n" |
| 580 | "</rpc>\n"; |
| 581 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 582 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_NETCONF, &tree, &op)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 583 | ly_in_free(in, 0); |
| 584 | |
| 585 | assert_non_null(op); |
| 586 | |
| 587 | node = tree; |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 588 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 1, 0, LY_VALUE_XML, "rpc", 0, 0, 0, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 589 | |
| 590 | assert_non_null(tree); |
| 591 | |
| 592 | node = op; |
| 593 | CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR, |
| 594 | 1, 0, 0, 1, "edit-config", LYS_RPC, |
| 595 | 0, 0, 0, 0, 0, ref, 0); |
| 596 | node = lyd_child(node)->next; |
| 597 | dsc = "Inline Config content."; |
| 598 | CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0); |
| 599 | |
| 600 | node = ((struct lyd_node_any *)node)->value.tree; |
Michal Vasko | e16c7b7 | 2021-02-26 10:39:06 +0100 | [diff] [blame] | 601 | CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp", |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 602 | 1, LYS_CONTAINER, 0, 0, NULL, 0); |
| 603 | |
| 604 | node = lyd_child(node); |
| 605 | /* z has no value */ |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 606 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_XML, "z", 0, 0, NULL, 1, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 607 | node = node->parent->next; |
| 608 | /* l1 key c has invalid value so it is at the end */ |
Michal Vasko | 535d21c | 2023-08-09 10:41:44 +0200 | [diff] [blame] | 609 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 610 | |
| 611 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 612 | "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"25\"/>\n"); |
| 613 | CHECK_LYD_STRING(op, LYD_PRINT_WITHSIBLINGS, |
| 614 | "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 615 | " <target>\n" |
| 616 | " <running/>\n" |
| 617 | " </target>\n" |
| 618 | " <config>\n" |
| 619 | " <cp xmlns=\"urn:tests:a\">\n" |
| 620 | " <z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"delete\"/>\n" |
| 621 | " </cp>\n" |
| 622 | " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">\n" |
| 623 | " <a>val_a</a>\n" |
| 624 | " <b>val_b</b>\n" |
| 625 | " <c>val_c</c>\n" |
| 626 | " </l1>\n" |
| 627 | " </config>\n" |
| 628 | "</edit-config>\n"); |
| 629 | |
| 630 | lyd_free_all(tree); |
| 631 | lyd_free_all(op); |
| 632 | |
Michal Vasko | 85be65e | 2023-06-13 09:44:17 +0200 | [diff] [blame] | 633 | /* invalid anyxml nested metadata value */ |
| 634 | data = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\" pid=\"4114692032\">\n" |
| 635 | " <copy-config>\n" |
| 636 | " <target>\n" |
| 637 | " <running/>\n" |
| 638 | " </target>\n" |
| 639 | " <source>\n" |
| 640 | " <config>\n" |
| 641 | " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 642 | " <a>val_a</a>\n" |
| 643 | " <b>val_b</b>\n" |
| 644 | " <c>5</c>\n" |
| 645 | " <cont nc:operation=\"merge\">\n" |
| 646 | " <e nc:operation=\"merge2\">false</e>\n" |
| 647 | " </cont>\n" |
| 648 | " </l1>\n" |
| 649 | " </config>\n" |
| 650 | " </source>\n" |
| 651 | " </copy-config>\n" |
| 652 | "</rpc>\n"; |
| 653 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 654 | assert_int_equal(LY_EVALID, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_NETCONF, &tree, &op)); |
| 655 | ly_in_free(in, 0); |
| 656 | CHECK_LOG_CTX("Invalid enumeration value \"merge2\".", |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 657 | "/ietf-netconf:copy-config/source/config/a:l1[a='val_a'][b='val_b'][c='5']/cont/e/@ietf-netconf:operation", 13); |
Michal Vasko | 85be65e | 2023-06-13 09:44:17 +0200 | [diff] [blame] | 658 | lyd_free_all(tree); |
| 659 | assert_null(op); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static void |
| 663 | test_netconf_action(void **state) |
| 664 | { |
| 665 | const char *data; |
| 666 | struct ly_in *in; |
| 667 | struct lyd_node *tree, *op; |
| 668 | |
| 669 | data = "<rpc message-id=\"25\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" |
| 670 | "<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">" |
| 671 | "<c xmlns=\"urn:tests:a\">\n" |
| 672 | " <act>\n" |
| 673 | " <al>value</al>\n" |
| 674 | " </act>\n" |
| 675 | "</c>\n" |
| 676 | "</action>\n" |
| 677 | "</rpc>\n"; |
| 678 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 679 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_NETCONF, &tree, &op)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 680 | ly_in_free(in, 0); |
| 681 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 682 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc", 0, 0, 0, 0, ""); |
| 683 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 0, LY_VALUE_XML, "action", 0, 0, 0, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 684 | |
| 685 | assert_non_null(op); |
| 686 | CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR, |
| 687 | 1, 0, 0, 1, "act", LYS_ACTION, |
| 688 | 1, 0, 0, 1, 0, NULL, 0); |
| 689 | |
| 690 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 691 | "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"25\">\n" |
| 692 | " <action xmlns=\"urn:ietf:params:xml:ns:yang:1\"/>\n" |
| 693 | "</rpc>\n"); |
| 694 | CHECK_LYD_STRING(op, LYD_PRINT_WITHSIBLINGS, |
| 695 | "<act xmlns=\"urn:tests:a\">\n" |
| 696 | " <al>value</al>\n" |
| 697 | "</act>\n"); |
| 698 | |
| 699 | lyd_free_all(tree); |
| 700 | lyd_free_all(op); |
| 701 | |
| 702 | /* wrong namespace, element name, whatever... */ |
| 703 | /* TODO */ |
| 704 | } |
| 705 | |
| 706 | static void |
| 707 | test_netconf_reply_or_notification(void **state) |
| 708 | { |
| 709 | const char *data; |
| 710 | struct ly_in *in; |
| 711 | struct lyd_node *action, *tree, *op, *op2; |
| 712 | |
| 713 | /* parse the action */ |
| 714 | data = "<c xmlns=\"urn:tests:a\">\n" |
| 715 | " <act>\n" |
| 716 | " <al>value</al>\n" |
| 717 | " </act>\n" |
| 718 | "</c>\n"; |
| 719 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 720 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &action, &op)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 721 | ly_in_free(in, 0); |
| 722 | |
| 723 | /* parse notification first */ |
| 724 | data = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 725 | "<eventTime>2010-12-06T08:00:01Z</eventTime>\n" |
| 726 | "<c xmlns=\"urn:tests:a\">\n" |
| 727 | " <n1>\n" |
| 728 | " <nl>value</nl>\n" |
| 729 | " </n1>\n" |
| 730 | "</c>\n" |
| 731 | "</notification>\n"; |
| 732 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 733 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_NETCONF, &tree, &op2)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 734 | ly_in_free(in, 0); |
| 735 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 736 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 1, LY_VALUE_XML, "notification", 0, 0, 0, 0, ""); |
| 737 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 0, LY_VALUE_XML, "eventTime", 0, 0, 0, 0, |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 738 | "2010-12-06T08:00:01Z"); |
| 739 | |
| 740 | assert_non_null(op2); |
| 741 | CHECK_LYSC_NOTIF((struct lysc_node_notif *)op2->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0); |
| 742 | |
| 743 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 744 | "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 745 | " <eventTime>2010-12-06T08:00:01Z</eventTime>\n" |
| 746 | "</notification>\n"); |
| 747 | CHECK_LYD_STRING(op2, LYD_PRINT_WITHSIBLINGS, |
| 748 | "<n1 xmlns=\"urn:tests:a\">\n" |
| 749 | " <nl>value</nl>\n" |
| 750 | "</n1>\n"); |
| 751 | |
| 752 | lyd_free_all(tree); |
| 753 | lyd_free_all(op2); |
| 754 | |
Michal Vasko | 4a1e3e8 | 2023-09-05 08:45:01 +0200 | [diff] [blame] | 755 | /* notification with a different order */ |
| 756 | data = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 757 | "<c xmlns=\"urn:tests:a\">\n" |
| 758 | " <n1>\n" |
| 759 | " <nl>value</nl>\n" |
| 760 | " </n1>\n" |
| 761 | "</c>\n" |
| 762 | "<eventTime>2010-12-06T08:00:01Z</eventTime>\n" |
| 763 | "</notification>\n"; |
| 764 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 765 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_NETCONF, &tree, &op2)); |
| 766 | ly_in_free(in, 0); |
| 767 | |
| 768 | lyd_free_all(tree); |
| 769 | lyd_free_all(op2); |
| 770 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 771 | /* parse a data reply */ |
| 772 | data = "<rpc-reply message-id=\"55\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 773 | " <al xmlns=\"urn:tests:a\">25</al>\n" |
| 774 | "</rpc-reply>\n"; |
| 775 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 776 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, op, in, LYD_XML, LYD_TYPE_REPLY_NETCONF, &tree, NULL)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 777 | ly_in_free(in, 0); |
| 778 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 779 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 0, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 780 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 781 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 782 | "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\"/>\n"); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 783 | |
| 784 | lyd_free_all(tree); |
| 785 | /* it was connected to the action, do not free */ |
| 786 | |
| 787 | /* parse an ok reply */ |
| 788 | data = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\">\n" |
| 789 | " <ok/>\n" |
| 790 | "</rpc-reply>\n"; |
| 791 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 792 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, op, in, LYD_XML, LYD_TYPE_REPLY_NETCONF, &tree, NULL)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 793 | ly_in_free(in, 0); |
| 794 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 795 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, ""); |
| 796 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 0, LY_VALUE_XML, "ok", 0, 0, 0, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 797 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 798 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
| 799 | |
| 800 | lyd_free_all(tree); |
| 801 | |
| 802 | /* parse an error reply */ |
| 803 | data = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\">\n" |
| 804 | " <rpc-error>\n" |
| 805 | " <error-type>rpc</error-type>\n" |
| 806 | " <error-tag>missing-attribute</error-tag>\n" |
| 807 | " <error-severity>error</error-severity>\n" |
| 808 | " <error-info>\n" |
| 809 | " <bad-attribute>message-id</bad-attribute>\n" |
| 810 | " <bad-element>rpc</bad-element>\n" |
| 811 | " </error-info>\n" |
| 812 | " </rpc-error>\n" |
| 813 | "</rpc-reply>\n"; |
| 814 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 815 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, op, in, LYD_XML, LYD_TYPE_REPLY_NETCONF, &tree, NULL)); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 816 | ly_in_free(in, 0); |
| 817 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 818 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, ""); |
| 819 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 1, LY_VALUE_XML, "rpc-error", 0, 0, 0, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 820 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 821 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
| 822 | |
| 823 | lyd_free_all(tree); |
| 824 | |
| 825 | lyd_free_all(action); |
| 826 | |
| 827 | /* wrong namespace, element name, whatever... */ |
| 828 | /* TODO */ |
| 829 | } |
| 830 | |
aPiecek | 9cdb9e6 | 2021-05-18 09:46:20 +0200 | [diff] [blame] | 831 | static void |
Michal Vasko | 820efe8 | 2023-05-12 15:47:43 +0200 | [diff] [blame] | 832 | test_restconf_rpc(void **state) |
| 833 | { |
| 834 | const char *data; |
| 835 | struct ly_in *in; |
| 836 | struct lyd_node *tree, *envp; |
| 837 | |
| 838 | assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-nmda", "2019-01-07", NULL))); |
| 839 | |
| 840 | assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX, "/ietf-netconf-nmda:edit-data", NULL, 0, &tree)); |
| 841 | |
| 842 | data = "<input xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-nmda\">" |
| 843 | "<datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore>" |
| 844 | "<config>" |
| 845 | "<cp xmlns=\"urn:tests:a\"><z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\"/></cp>" |
| 846 | "<l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">" |
| 847 | "<a>val_a</a><b>val_b</b><c>val_c</c>" |
| 848 | "</l1>" |
| 849 | "</config></input>"; |
| 850 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 851 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, tree, in, LYD_XML, LYD_TYPE_RPC_RESTCONF, &envp, NULL)); |
| 852 | ly_in_free(in, 0); |
| 853 | |
| 854 | /* the same just connected to the edit-data RPC */ |
| 855 | data = "<edit-data xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-nmda\">" |
| 856 | "<datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore>" |
| 857 | "<config>" |
| 858 | "<cp xmlns=\"urn:tests:a\"><z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\"/></cp>" |
| 859 | "<l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">" |
| 860 | "<a>val_a</a><b>val_b</b><c>val_c</c>" |
| 861 | "</l1>" |
| 862 | "</config></edit-data>"; |
| 863 | CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data); |
| 864 | lyd_free_all(tree); |
| 865 | lyd_free_all(envp); |
| 866 | } |
| 867 | |
| 868 | static void |
| 869 | test_restconf_reply(void **state) |
| 870 | { |
| 871 | const char *data; |
| 872 | struct ly_in *in; |
| 873 | struct lyd_node *tree, *envp; |
| 874 | |
| 875 | assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX, "/a:c/act", NULL, 0, &tree)); |
| 876 | |
| 877 | data = "<output xmlns=\"urn:tests:a\"><al>25</al></output>"; |
| 878 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 879 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, lyd_child(tree), in, LYD_XML, LYD_TYPE_REPLY_RESTCONF, &envp, NULL)); |
| 880 | ly_in_free(in, 0); |
| 881 | |
| 882 | /* connected to the RPC with the parent */ |
| 883 | data = "<c xmlns=\"urn:tests:a\"><act><al>25</al></act></c>"; |
| 884 | CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data); |
| 885 | lyd_free_all(tree); |
| 886 | lyd_free_all(envp); |
| 887 | } |
| 888 | |
| 889 | static void |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 890 | test_filter_attributes(void **state) |
| 891 | { |
| 892 | const char *data; |
| 893 | struct ly_in *in; |
| 894 | struct lyd_node *tree; |
| 895 | const struct lyd_node *node; |
| 896 | const char *dsc; |
| 897 | const char *ref = "RFC 6241, Section 7.7"; |
| 898 | const char *feats[] = {"writable-running", NULL}; |
| 899 | |
| 900 | assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats))); |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 901 | assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "notifications", "2008-07-14", NULL))); |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 902 | |
| 903 | data = "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 904 | " <filter type=\"xpath\" select=\"/*\"/>\n" |
| 905 | "</get>\n"; |
| 906 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 907 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL)); |
| 908 | ly_in_free(in, 0); |
| 909 | assert_non_null(tree); |
| 910 | |
| 911 | node = tree; |
| 912 | dsc = "Retrieve running configuration and device state information."; |
| 913 | CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR, |
| 914 | 1, 0, 0, 1, "get", LYS_RPC, |
| 915 | 1, 0, 0, 0, 0, ref, 0); |
| 916 | node = lyd_child(node); |
| 917 | dsc = "This parameter specifies the portion of the system\nconfiguration and state data to retrieve."; |
| 918 | CHECK_LYSC_NODE(node->schema, dsc, 1, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "filter", 0, LYS_ANYXML, 1, 0, NULL, 0); |
| 919 | |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 920 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
| 921 | lyd_free_all(tree); |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 922 | |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 923 | data = "<create-subscription xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 924 | " <filter type=\"subtree\">\n" |
| 925 | " <inner-node xmlns=\"my:urn\"/>\n" |
| 926 | " </filter>\n" |
| 927 | "</create-subscription>\n"; |
| 928 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 929 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL)); |
| 930 | ly_in_free(in, 0); |
| 931 | assert_non_null(tree); |
| 932 | |
| 933 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 934 | lyd_free_all(tree); |
| 935 | } |
| 936 | |
| 937 | static void |
aPiecek | 9cdb9e6 | 2021-05-18 09:46:20 +0200 | [diff] [blame] | 938 | test_data_skip(void **state) |
| 939 | { |
| 940 | const char *data; |
| 941 | struct lyd_node *tree; |
| 942 | struct lyd_node_term *leaf; |
| 943 | |
| 944 | /* add invalid data to a module that is not implemented */ |
| 945 | data = "<foo xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\"><u/></foo>"; |
| 946 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
| 947 | assert_null(tree); |
| 948 | |
| 949 | /* add invalid data to a module that is implemented */ |
| 950 | data = "<fooX xmlns=\"urn:tests:a\"><u/><list><value/></list></fooX>"; |
| 951 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
| 952 | assert_null(tree); |
| 953 | |
| 954 | /* first invalid, next valid */ |
| 955 | data = "<fooX xmlns=\"urn:tests:a\"><u/></fooX> <foo xmlns=\"urn:tests:a\">foo value</foo>"; |
| 956 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 957 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0); |
| 958 | leaf = (struct lyd_node_term *)tree; |
| 959 | CHECK_LYD_VALUE(leaf->value, STRING, "foo value"); |
| 960 | lyd_free_all(tree); |
| 961 | } |
| 962 | |
Michal Vasko | dd03ff1 | 2023-09-11 10:30:48 +0200 | [diff] [blame] | 963 | static void |
| 964 | test_metadata(void **state) |
| 965 | { |
| 966 | const char *data; |
| 967 | struct lyd_node *tree; |
| 968 | |
| 969 | /* invalid metadata value */ |
| 970 | data = "<c xmlns=\"urn:tests:a\" xmlns:a=\"urn:tests:a\"><x a:attr=\"value\">xval</x></c>"; |
| 971 | assert_int_equal(LY_EVALID, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
| 972 | assert_null(tree); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 973 | CHECK_LOG_CTX("Invalid enumeration value \"value\".", "/a:c/x/@a:attr", 1); |
Michal Vasko | dd03ff1 | 2023-09-11 10:30:48 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Michal Vasko | a6139e0 | 2023-10-03 14:13:22 +0200 | [diff] [blame] | 976 | static void |
| 977 | test_subtree(void **state) |
| 978 | { |
| 979 | const char *data; |
| 980 | struct ly_in *in; |
| 981 | struct lyd_node *tree; |
| 982 | |
| 983 | /* prepare data with the parent */ |
| 984 | data = "<l1 xmlns=\"urn:tests:a\">\n" |
| 985 | " <a>val_a</a>\n" |
| 986 | " <b>val_b</b>\n" |
| 987 | " <c>1</c>\n" |
| 988 | "</l1>\n"; |
| 989 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
| 990 | |
| 991 | /* parse a subtree of it */ |
| 992 | data = "<cont xmlns=\"urn:tests:a\">\n" |
| 993 | " <e>true</e>\n" |
| 994 | "</cont>\n"; |
| 995 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 996 | assert_int_equal(LY_SUCCESS, lyd_parse_data(UTEST_LYCTX, tree, in, LYD_XML, 0, LYD_VALIDATE_PRESENT, NULL)); |
| 997 | ly_in_free(in, 0); |
| 998 | |
| 999 | /* parse another container, fails */ |
| 1000 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 1001 | assert_int_equal(LY_EVALID, lyd_parse_data(UTEST_LYCTX, tree, in, LYD_XML, 0, LYD_VALIDATE_PRESENT, NULL)); |
| 1002 | ly_in_free(in, 0); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame^] | 1003 | CHECK_LOG_CTX("Duplicate instance of \"cont\".", "/a:l1[a='val_a'][b='val_b'][c='1']/cont", 0); |
Michal Vasko | a6139e0 | 2023-10-03 14:13:22 +0200 | [diff] [blame] | 1004 | |
| 1005 | lyd_free_all(tree); |
| 1006 | } |
| 1007 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1008 | int |
| 1009 | main(void) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 1010 | { |
| 1011 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1012 | UTEST(test_leaf, setup), |
| 1013 | UTEST(test_anydata, setup), |
Michal Vasko | 5b414dd | 2023-04-13 10:29:58 +0200 | [diff] [blame] | 1014 | UTEST(test_anyxml, setup), |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1015 | UTEST(test_list, setup), |
| 1016 | UTEST(test_container, setup), |
| 1017 | UTEST(test_opaq, setup), |
| 1018 | UTEST(test_rpc, setup), |
| 1019 | UTEST(test_action, setup), |
| 1020 | UTEST(test_notification, setup), |
| 1021 | UTEST(test_reply, setup), |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 1022 | UTEST(test_netconf_rpc, setup), |
| 1023 | UTEST(test_netconf_action, setup), |
| 1024 | UTEST(test_netconf_reply_or_notification, setup), |
Michal Vasko | 820efe8 | 2023-05-12 15:47:43 +0200 | [diff] [blame] | 1025 | UTEST(test_restconf_rpc, setup), |
| 1026 | UTEST(test_restconf_reply, setup), |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 1027 | UTEST(test_filter_attributes, setup), |
aPiecek | 9cdb9e6 | 2021-05-18 09:46:20 +0200 | [diff] [blame] | 1028 | UTEST(test_data_skip, setup), |
Michal Vasko | dd03ff1 | 2023-09-11 10:30:48 +0200 | [diff] [blame] | 1029 | UTEST(test_metadata, setup), |
Michal Vasko | a6139e0 | 2023-10-03 14:13:22 +0200 | [diff] [blame] | 1030 | UTEST(test_subtree, setup), |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 1031 | }; |
| 1032 | |
| 1033 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 1034 | } |