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