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 | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 34 | " list l1 { key \"a b c\"; leaf a {type string;} leaf b {type string;} leaf c {type int16;}" |
| 35 | " leaf d {type string;}" |
| 36 | " container cont {leaf e {type boolean;}}" |
| 37 | " }" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 38 | " leaf foo { type string;}\n" |
| 39 | " container c {\n" |
| 40 | " leaf x {type string;}\n" |
| 41 | " action act { input { leaf al {type string;} } output { leaf al {type uint8;} } }\n" |
| 42 | " notification n1 { leaf nl {type string;}}}\n" |
| 43 | " container cp {presence \"container switch\"; leaf y {type string;} leaf z {type int8;}}\n" |
| 44 | " anydata any {config false;}\n" |
| 45 | " leaf foo2 { type string; default \"default-val\"; }\n" |
| 46 | " leaf foo3 { type uint32; }\n" |
| 47 | " notification n2;}"; |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 48 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 49 | UTEST_SETUP; |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 50 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 51 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); |
| 52 | 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] | 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 57 | #define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \ |
| 58 | 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] | 59 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 60 | #define PARSER_CHECK_ERROR(INPUT, PARSE_OPTION, VALIDATE_OPTION, MODEL, RET_VAL, ERR_MESSAGE, ERR_PATH) \ |
| 61 | assert_int_equal(RET_VAL, lyd_parse_data_mem(UTEST_LYCTX, INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, &MODEL));\ |
| 62 | CHECK_LOG_CTX(ERR_MESSAGE, ERR_PATH);\ |
| 63 | assert_null(MODEL) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 64 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 65 | #define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \ |
| 66 | CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, PRINT_OPTION) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 67 | |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 68 | static void |
| 69 | test_leaf(void **state) |
| 70 | { |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 71 | const char *data = "<foo xmlns=\"urn:tests:a\">foo value</foo>"; |
| 72 | struct lyd_node *tree; |
| 73 | struct lyd_node_term *leaf; |
| 74 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 75 | 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] | 76 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 77 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 78 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0); |
| 79 | leaf = (struct lyd_node_term *)tree; |
| 80 | CHECK_LYD_VALUE(leaf->value, STRING, "foo value"); |
| 81 | |
| 82 | CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2", |
| 83 | 1, LYS_LEAF, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 84 | leaf = (struct lyd_node_term *)tree->next->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 85 | CHECK_LYD_VALUE(leaf->value, STRING, "default-val"); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 86 | assert_true(leaf->flags & LYD_DEFAULT); |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 87 | lyd_free_all(tree); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 88 | |
| 89 | /* make foo2 explicit */ |
| 90 | data = "<foo2 xmlns=\"urn:tests:a\">default-val</foo2>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 91 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 92 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 93 | tree = tree->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 94 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2", |
| 95 | 1, LYS_LEAF, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 96 | leaf = (struct lyd_node_term *)tree; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 97 | CHECK_LYD_VALUE(leaf->value, STRING, "default-val"); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 98 | assert_false(leaf->flags & LYD_DEFAULT); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 99 | lyd_free_all(tree); |
| 100 | |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 101 | /* 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] | 102 | data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" " |
| 103 | "wd:default=\"true\" xmlns:x=\"urn:x\" x:xxx=\"false\">default-val</foo2>"; |
| 104 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 105 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 106 | tree = tree->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 107 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2", |
| 108 | 1, LYS_LEAF, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 109 | leaf = (struct lyd_node_term *)tree; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 110 | CHECK_LYD_VALUE(leaf->value, STRING, "default-val"); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 111 | assert_true(leaf->flags & LYD_DEFAULT); |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 112 | lyd_free_all(tree); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 113 | |
| 114 | /* invalid value */ |
| 115 | data = "<l1 xmlns=\"urn:tests:a\"><a>val-a</a><b>val-b</b><c>1</c><cont><e>0</e></cont></l1>"; |
| 116 | PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
| 117 | "Invalid boolean value \"0\".", |
| 118 | "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] | 119 | } |
| 120 | |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 121 | static void |
| 122 | test_anydata(void **state) |
| 123 | { |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 124 | const char *data; |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 125 | struct lyd_node *tree; |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 126 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 127 | data = "<any xmlns=\"urn:tests:a\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 128 | " <element1>\n" |
| 129 | " <x:element2 x:attr2=\"test\" xmlns:a=\"urn:tests:a\" xmlns:x=\"urn:x\">a:data</x:element2>\n" |
| 130 | " </element1>\n" |
| 131 | " <element1a/>\n" |
| 132 | "</any>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 133 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 134 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 135 | tree = tree->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 136 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_SET_CONFIG, 1, "any", |
| 137 | 1, LYS_ANYDATA, 0, 0, NULL, 0); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 138 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 139 | const char *data_expected = |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 140 | "<any xmlns=\"urn:tests:a\">\n" |
| 141 | " <element1>\n" |
| 142 | " <element2 xmlns=\"urn:x\" xmlns:x=\"urn:x\" x:attr2=\"test\" xmlns:a=\"urn:tests:a\">a:data</element2>\n" |
| 143 | " </element1>\n" |
| 144 | " <element1a/>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 145 | "</any>\n"; |
| 146 | |
| 147 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected); |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 148 | lyd_free_all(tree); |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 151 | static void |
| 152 | test_list(void **state) |
| 153 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 154 | const char *data; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 155 | struct lyd_node *tree, *iter; |
| 156 | struct lyd_node_inner *list; |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 157 | struct lyd_node_term *leaf; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 158 | |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 159 | /* check hashes */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 160 | data = "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>1</c></l1>"; |
| 161 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 162 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", |
| 163 | 1, LYS_LIST, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 164 | list = (struct lyd_node_inner *)tree; |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 165 | LY_LIST_FOR(list->child, iter) { |
| 166 | assert_int_not_equal(0, iter->hash); |
| 167 | } |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 168 | lyd_free_all(tree); |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 169 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 170 | /* missing keys */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 171 | 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] | 172 | "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] | 173 | 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] | 174 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 175 | 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] | 176 | "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] | 177 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 178 | 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] | 179 | "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] | 180 | 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] | 181 | |
| 182 | /* key duplicate */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 183 | 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] | 184 | "Duplicate instance of \"c\".", |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 185 | "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] | 186 | CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL); |
| 187 | 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] | 188 | |
Radek Krejci | 710226d | 2019-07-24 17:24:59 +0200 | [diff] [blame] | 189 | /* keys order */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 190 | 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); |
| 191 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", |
| 192 | 1, LYS_LIST, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 193 | list = (struct lyd_node_inner *)tree; |
| 194 | assert_non_null(leaf = (struct lyd_node_term *)list->child); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 195 | 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] | 196 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 197 | 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] | 198 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 199 | 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] | 200 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 201 | 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] | 202 | 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] | 203 | lyd_free_all(tree); |
| 204 | |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 205 | 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] | 206 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 207 | 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] | 208 | list = (struct lyd_node_inner *)tree; |
| 209 | assert_non_null(leaf = (struct lyd_node_term *)list->child); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 210 | 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] | 211 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 212 | 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] | 213 | assert_non_null(leaf = (struct lyd_node_term *)leaf->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 214 | CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0); |
| 215 | 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] | 216 | 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] | 217 | lyd_free_all(tree); |
| 218 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 219 | 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] | 220 | "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] | 221 | } |
| 222 | |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 223 | static void |
| 224 | test_container(void **state) |
| 225 | { |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 226 | struct lyd_node *tree; |
| 227 | struct lyd_node_inner *cont; |
| 228 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 229 | CHECK_PARSE_LYD("<c xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree); |
| 230 | 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] | 231 | cont = (struct lyd_node_inner *)tree; |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 232 | assert_true(cont->flags & LYD_DEFAULT); |
| 233 | lyd_free_all(tree); |
| 234 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 235 | 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] | 236 | assert_non_null(tree); |
Michal Vasko | 2612319 | 2020-11-09 21:02:34 +0100 | [diff] [blame] | 237 | tree = tree->next; |
Michal Vasko | e16c7b7 | 2021-02-26 10:39:06 +0100 | [diff] [blame] | 238 | 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] | 239 | 1, LYS_CONTAINER, 0, 0, NULL, 0); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 240 | cont = (struct lyd_node_inner *)tree; |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 241 | assert_false(cont->flags & LYD_DEFAULT); |
| 242 | lyd_free_all(tree); |
Radek Krejci | b6f7ae5 | 2019-07-19 10:31:42 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 245 | static void |
| 246 | test_opaq(void **state) |
| 247 | { |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 248 | const char *data; |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 249 | struct lyd_node *tree; |
| 250 | |
| 251 | /* invalid value, no flags */ |
| 252 | data = "<foo3 xmlns=\"urn:tests:a\"/>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 253 | PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 959f8d8 | 2022-06-16 07:51:50 +0200 | [diff] [blame] | 254 | "Invalid type uint32 empty value.", "Schema location \"/a:foo3\", line number 1."); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 255 | |
| 256 | /* opaq flag */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 257 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 258 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_XML, "foo3", 0, 0, NULL, 0, ""); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 259 | 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] | 260 | lyd_free_all(tree); |
| 261 | |
Michal Vasko | da8fbbf | 2021-06-16 11:44:44 +0200 | [diff] [blame] | 262 | /* list, opaq flag */ |
| 263 | data = "<l1 xmlns=\"urn:tests:a\"/>"; |
| 264 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
| 265 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_XML, "l1", 0, 0, NULL, 0, ""); |
| 266 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, "<l1 xmlns=\"urn:tests:a\"/>\n"); |
| 267 | lyd_free_all(tree); |
| 268 | |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 269 | /* missing key, no flags */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 270 | data = "<l1 xmlns=\"urn:tests:a\">\n" |
| 271 | " <a>val_a</a>\n" |
| 272 | " <b>val_b</b>\n" |
| 273 | " <d>val_d</d>\n" |
| 274 | "</l1>\n"; |
| 275 | PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 959f8d8 | 2022-06-16 07:51:50 +0200 | [diff] [blame] | 276 | "List instance is missing its key \"c\".", |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 277 | "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] | 278 | |
| 279 | /* opaq flag */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 280 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 281 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 0, ""); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 282 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 283 | lyd_free_all(tree); |
| 284 | |
| 285 | /* invalid key, no flags */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 286 | data = "<l1 xmlns=\"urn:tests:a\">\n" |
| 287 | " <a>val_a</a>\n" |
| 288 | " <b>val_b</b>\n" |
| 289 | " <c>val_c</c>\n" |
| 290 | "</l1>\n"; |
| 291 | PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, |
Michal Vasko | 959f8d8 | 2022-06-16 07:51:50 +0200 | [diff] [blame] | 292 | "Invalid type int16 value \"val_c\".", |
Michal Vasko | a4dfb3c | 2022-10-25 14:59:31 +0200 | [diff] [blame] | 293 | "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] | 294 | |
| 295 | /* opaq flag */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 296 | CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 297 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 0, ""); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 298 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 299 | lyd_free_all(tree); |
| 300 | |
Michal Vasko | 413c7f2 | 2020-05-05 12:34:06 +0200 | [diff] [blame] | 301 | /* opaq flag and fail */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 302 | assert_int_equal(LY_EVALID, lyd_parse_data_mem(UTEST_LYCTX, |
| 303 | "<a xmlns=\"ns\">\n" |
| 304 | " <b>x</b>\n" |
Michal Vasko | e137fc4 | 2021-07-22 11:53:13 +0200 | [diff] [blame] | 305 | " <c xmld:id=\"D\">1</c>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 306 | "</a>\n", |
| 307 | LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree)); |
Michal Vasko | e137fc4 | 2021-07-22 11:53:13 +0200 | [diff] [blame] | 308 | CHECK_LOG_CTX("Unknown XML prefix \"xmld\".", "Line number 3."); |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 311 | static void |
| 312 | test_rpc(void **state) |
| 313 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 314 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 315 | struct ly_in *in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 316 | struct lyd_node *tree, *op; |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 317 | const struct lyd_node *node; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 318 | const char *dsc = "The <edit-config> operation loads all or part of a specified\n" |
| 319 | "configuration to the specified target configuration."; |
| 320 | const char *ref = "RFC 6241, Section 7.2"; |
| 321 | const char *feats[] = {"writable-running", NULL}; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 322 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 323 | 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] | 324 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 325 | data = "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 326 | " <target>\n" |
| 327 | " <running/>\n" |
| 328 | " </target>\n" |
| 329 | " <config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 330 | " <l1 xmlns=\"urn:tests:a\" nc:operation=\"replace\">\n" |
| 331 | " <a>val_a</a>\n" |
| 332 | " <b>val_b</b>\n" |
| 333 | " <c>val_c</c>\n" |
| 334 | " </l1>\n" |
| 335 | " <cp xmlns=\"urn:tests:a\">\n" |
| 336 | " <z nc:operation=\"delete\"/>\n" |
| 337 | " </cp>\n" |
| 338 | " </config>\n" |
| 339 | "</edit-config>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 340 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 341 | 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] | 342 | ly_in_free(in, 0); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 343 | |
| 344 | assert_non_null(op); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 345 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 346 | 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] | 347 | 1, 0, 0, 1, "edit-config", LYS_RPC, |
| 348 | 0, 0, 0, 0, 0, ref, 0); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 349 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 350 | assert_non_null(tree); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 351 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 352 | node = tree; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 353 | 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] | 354 | 1, 0, 0, 1, "edit-config", LYS_RPC, |
| 355 | 0, 0, 0, 0, 0, ref, 0); |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 356 | node = lyd_child(node)->next; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 357 | dsc = "Inline Config content."; |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 358 | 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] | 359 | |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 360 | node = ((struct lyd_node_any *)node)->value.tree; |
Michal Vasko | e16c7b7 | 2021-02-26 10:39:06 +0100 | [diff] [blame] | 361 | 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] | 362 | 1, LYS_CONTAINER, 0, 0, NULL, 0); |
| 363 | |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 364 | node = lyd_child(node); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 365 | /* z has no value */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 366 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_XML, "z", 0, 0, NULL, 0, ""); |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 367 | node = node->parent->next; |
| 368 | /* l1 key c has invalid value so it is at the end */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 369 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 0, ""); |
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 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 372 | "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 373 | " <target>\n" |
| 374 | " <running/>\n" |
| 375 | " </target>\n" |
| 376 | " <config>\n" |
| 377 | " <cp xmlns=\"urn:tests:a\">\n" |
| 378 | " <z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"delete\"/>\n" |
| 379 | " </cp>\n" |
| 380 | " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">\n" |
| 381 | " <a>val_a</a>\n" |
| 382 | " <b>val_b</b>\n" |
| 383 | " <c>val_c</c>\n" |
| 384 | " </l1>\n" |
| 385 | " </config>\n" |
| 386 | "</edit-config>\n"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 387 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 388 | lyd_free_all(tree); |
| 389 | |
| 390 | /* wrong namespace, element name, whatever... */ |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 391 | /* TODO */ |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void |
| 395 | test_action(void **state) |
| 396 | { |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 397 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 398 | struct ly_in *in; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 399 | struct lyd_node *tree, *op; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 400 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 401 | data = "<c xmlns=\"urn:tests:a\">\n" |
| 402 | " <act>\n" |
| 403 | " <al>value</al>\n" |
| 404 | " </act>\n" |
| 405 | "</c>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 406 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 407 | 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] | 408 | ly_in_free(in, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 409 | |
| 410 | assert_non_null(op); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 411 | 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] | 412 | 1, 0, 0, 1, "act", LYS_ACTION, |
| 413 | 1, 0, 0, 1, 0, NULL, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +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 | "<c xmlns=\"urn:tests:a\">\n" |
| 417 | " <act>\n" |
| 418 | " <al>value</al>\n" |
| 419 | " </act>\n" |
| 420 | "</c>\n"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 421 | |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 422 | lyd_free_all(tree); |
| 423 | |
| 424 | /* wrong namespace, element name, whatever... */ |
| 425 | /* TODO */ |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static void |
| 429 | test_notification(void **state) |
| 430 | { |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 431 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 432 | struct ly_in *in; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 433 | struct lyd_node *tree, *ntf; |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 434 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 435 | data = "<c xmlns=\"urn:tests:a\">\n" |
| 436 | " <n1>\n" |
| 437 | " <nl>value</nl>\n" |
| 438 | " </n1>\n" |
| 439 | "</c>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 440 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 441 | 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] | 442 | ly_in_free(in, 0); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 443 | |
| 444 | assert_non_null(ntf); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 445 | 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] | 446 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 447 | 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] | 448 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 449 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 450 | lyd_free_all(tree); |
| 451 | |
| 452 | /* top-level notif without envelope */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 453 | data = "<n2 xmlns=\"urn:tests:a\"/>\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_NOTIF_YANG, &tree, &ntf)); |
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(ntf); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 459 | 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] | 460 | |
| 461 | assert_non_null(tree); |
| 462 | assert_ptr_equal(ntf, tree); |
| 463 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 464 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 465 | lyd_free_all(tree); |
| 466 | |
| 467 | /* wrong namespace, element name, whatever... */ |
| 468 | /* TODO */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 471 | static void |
| 472 | test_reply(void **state) |
| 473 | { |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 474 | const char *data; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 475 | struct ly_in *in; |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 476 | struct lyd_node *tree, *op; |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 477 | const struct lyd_node *node; |
| 478 | |
Michal Vasko | 79135ae | 2020-12-16 10:08:35 +0100 | [diff] [blame] | 479 | data = "<c xmlns=\"urn:tests:a\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 480 | " <act>\n" |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 481 | " <al>25</al>\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 482 | " </act>\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_REPLY_YANG, &tree, &op)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 486 | ly_in_free(in, 0); |
| 487 | |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 488 | assert_non_null(op); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 489 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 490 | 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] | 491 | 1, 0, 0, 1, "act", LYS_ACTION, |
| 492 | 1, 0, 0, 1, 0, NULL, 0); |
Radek Krejci | a1c1e54 | 2020-09-29 16:06:52 +0200 | [diff] [blame] | 493 | node = lyd_child(op); |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 494 | 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] | 495 | |
Michal Vasko | 2552ea3 | 2020-12-08 15:32:34 +0100 | [diff] [blame] | 496 | 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] | 497 | |
| 498 | /* TODO print only rpc-reply node and then output subtree */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 499 | 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] | 500 | lyd_free_all(tree); |
| 501 | |
| 502 | /* wrong namespace, element name, whatever... */ |
| 503 | /* TODO */ |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 504 | } |
| 505 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 506 | static void |
| 507 | test_netconf_rpc(void **state) |
| 508 | { |
| 509 | const char *data; |
| 510 | struct ly_in *in; |
| 511 | struct lyd_node *tree, *op; |
| 512 | const struct lyd_node *node; |
| 513 | const char *dsc = "The <edit-config> operation loads all or part of a specified\n" |
| 514 | "configuration to the specified target configuration."; |
| 515 | const char *ref = "RFC 6241, Section 7.2"; |
| 516 | const char *feats[] = {"writable-running", NULL}; |
| 517 | |
| 518 | assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats))); |
| 519 | |
| 520 | data = "<rpc message-id=\"25\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" |
| 521 | "<edit-config>\n" |
| 522 | " <target>\n" |
| 523 | " <running/>\n" |
| 524 | " </target>\n" |
| 525 | " <config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 526 | " <l1 xmlns=\"urn:tests:a\" nc:operation=\"replace\">\n" |
| 527 | " <a>val_a</a>\n" |
| 528 | " <b>val_b</b>\n" |
| 529 | " <c>val_c</c>\n" |
| 530 | " </l1>\n" |
| 531 | " <cp xmlns=\"urn:tests:a\">\n" |
| 532 | " <z nc:operation=\"delete\"/>\n" |
| 533 | " </cp>\n" |
| 534 | " </config>\n" |
| 535 | "</edit-config>\n" |
| 536 | "</rpc>\n"; |
| 537 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 538 | 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] | 539 | ly_in_free(in, 0); |
| 540 | |
| 541 | assert_non_null(op); |
| 542 | |
| 543 | node = tree; |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 544 | 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] | 545 | |
| 546 | assert_non_null(tree); |
| 547 | |
| 548 | node = op; |
| 549 | CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR, |
| 550 | 1, 0, 0, 1, "edit-config", LYS_RPC, |
| 551 | 0, 0, 0, 0, 0, ref, 0); |
| 552 | node = lyd_child(node)->next; |
| 553 | dsc = "Inline Config content."; |
| 554 | CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0); |
| 555 | |
| 556 | node = ((struct lyd_node_any *)node)->value.tree; |
Michal Vasko | e16c7b7 | 2021-02-26 10:39:06 +0100 | [diff] [blame] | 557 | 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] | 558 | 1, LYS_CONTAINER, 0, 0, NULL, 0); |
| 559 | |
| 560 | node = lyd_child(node); |
| 561 | /* z has no value */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 562 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_XML, "z", 0, 0, NULL, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 563 | node = node->parent->next; |
| 564 | /* l1 key c has invalid value so it is at the end */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 565 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 0, ""); |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 566 | |
| 567 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 568 | "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"25\"/>\n"); |
| 569 | CHECK_LYD_STRING(op, LYD_PRINT_WITHSIBLINGS, |
| 570 | "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 571 | " <target>\n" |
| 572 | " <running/>\n" |
| 573 | " </target>\n" |
| 574 | " <config>\n" |
| 575 | " <cp xmlns=\"urn:tests:a\">\n" |
| 576 | " <z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"delete\"/>\n" |
| 577 | " </cp>\n" |
| 578 | " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">\n" |
| 579 | " <a>val_a</a>\n" |
| 580 | " <b>val_b</b>\n" |
| 581 | " <c>val_c</c>\n" |
| 582 | " </l1>\n" |
| 583 | " </config>\n" |
| 584 | "</edit-config>\n"); |
| 585 | |
| 586 | lyd_free_all(tree); |
| 587 | lyd_free_all(op); |
| 588 | |
| 589 | /* wrong namespace, element name, whatever... */ |
| 590 | /* TODO */ |
| 591 | } |
| 592 | |
| 593 | static void |
| 594 | test_netconf_action(void **state) |
| 595 | { |
| 596 | const char *data; |
| 597 | struct ly_in *in; |
| 598 | struct lyd_node *tree, *op; |
| 599 | |
| 600 | data = "<rpc message-id=\"25\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" |
| 601 | "<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">" |
| 602 | "<c xmlns=\"urn:tests:a\">\n" |
| 603 | " <act>\n" |
| 604 | " <al>value</al>\n" |
| 605 | " </act>\n" |
| 606 | "</c>\n" |
| 607 | "</action>\n" |
| 608 | "</rpc>\n"; |
| 609 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 610 | 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] | 611 | ly_in_free(in, 0); |
| 612 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 613 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc", 0, 0, 0, 0, ""); |
| 614 | 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] | 615 | |
| 616 | assert_non_null(op); |
| 617 | CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR, |
| 618 | 1, 0, 0, 1, "act", LYS_ACTION, |
| 619 | 1, 0, 0, 1, 0, NULL, 0); |
| 620 | |
| 621 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 622 | "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"25\">\n" |
| 623 | " <action xmlns=\"urn:ietf:params:xml:ns:yang:1\"/>\n" |
| 624 | "</rpc>\n"); |
| 625 | CHECK_LYD_STRING(op, LYD_PRINT_WITHSIBLINGS, |
| 626 | "<act xmlns=\"urn:tests:a\">\n" |
| 627 | " <al>value</al>\n" |
| 628 | "</act>\n"); |
| 629 | |
| 630 | lyd_free_all(tree); |
| 631 | lyd_free_all(op); |
| 632 | |
| 633 | /* wrong namespace, element name, whatever... */ |
| 634 | /* TODO */ |
| 635 | } |
| 636 | |
| 637 | static void |
| 638 | test_netconf_reply_or_notification(void **state) |
| 639 | { |
| 640 | const char *data; |
| 641 | struct ly_in *in; |
| 642 | struct lyd_node *action, *tree, *op, *op2; |
| 643 | |
| 644 | /* parse the action */ |
| 645 | data = "<c xmlns=\"urn:tests:a\">\n" |
| 646 | " <act>\n" |
| 647 | " <al>value</al>\n" |
| 648 | " </act>\n" |
| 649 | "</c>\n"; |
| 650 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 651 | 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] | 652 | ly_in_free(in, 0); |
| 653 | |
| 654 | /* parse notification first */ |
| 655 | data = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 656 | "<eventTime>2010-12-06T08:00:01Z</eventTime>\n" |
| 657 | "<c xmlns=\"urn:tests:a\">\n" |
| 658 | " <n1>\n" |
| 659 | " <nl>value</nl>\n" |
| 660 | " </n1>\n" |
| 661 | "</c>\n" |
| 662 | "</notification>\n"; |
| 663 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 664 | 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] | 665 | ly_in_free(in, 0); |
| 666 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 667 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 1, LY_VALUE_XML, "notification", 0, 0, 0, 0, ""); |
| 668 | 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] | 669 | "2010-12-06T08:00:01Z"); |
| 670 | |
| 671 | assert_non_null(op2); |
| 672 | CHECK_LYSC_NOTIF((struct lysc_node_notif *)op2->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0); |
| 673 | |
| 674 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 675 | "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 676 | " <eventTime>2010-12-06T08:00:01Z</eventTime>\n" |
| 677 | "</notification>\n"); |
| 678 | CHECK_LYD_STRING(op2, LYD_PRINT_WITHSIBLINGS, |
| 679 | "<n1 xmlns=\"urn:tests:a\">\n" |
| 680 | " <nl>value</nl>\n" |
| 681 | "</n1>\n"); |
| 682 | |
| 683 | lyd_free_all(tree); |
| 684 | lyd_free_all(op2); |
| 685 | |
| 686 | /* parse a data reply */ |
| 687 | data = "<rpc-reply message-id=\"55\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 688 | " <al xmlns=\"urn:tests:a\">25</al>\n" |
| 689 | "</rpc-reply>\n"; |
| 690 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 691 | 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] | 692 | ly_in_free(in, 0); |
| 693 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 694 | 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] | 695 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 696 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, |
| 697 | "<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] | 698 | |
| 699 | lyd_free_all(tree); |
| 700 | /* it was connected to the action, do not free */ |
| 701 | |
| 702 | /* parse an ok reply */ |
| 703 | data = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\">\n" |
| 704 | " <ok/>\n" |
| 705 | "</rpc-reply>\n"; |
| 706 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 707 | 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] | 708 | ly_in_free(in, 0); |
| 709 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 710 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, ""); |
| 711 | 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] | 712 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 713 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
| 714 | |
| 715 | lyd_free_all(tree); |
| 716 | |
| 717 | /* parse an error reply */ |
| 718 | data = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\">\n" |
| 719 | " <rpc-error>\n" |
| 720 | " <error-type>rpc</error-type>\n" |
| 721 | " <error-tag>missing-attribute</error-tag>\n" |
| 722 | " <error-severity>error</error-severity>\n" |
| 723 | " <error-info>\n" |
| 724 | " <bad-attribute>message-id</bad-attribute>\n" |
| 725 | " <bad-element>rpc</bad-element>\n" |
| 726 | " </error-info>\n" |
| 727 | " </rpc-error>\n" |
| 728 | "</rpc-reply>\n"; |
| 729 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 730 | 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] | 731 | ly_in_free(in, 0); |
| 732 | |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 733 | CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, ""); |
| 734 | 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] | 735 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 736 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
| 737 | |
| 738 | lyd_free_all(tree); |
| 739 | |
| 740 | lyd_free_all(action); |
| 741 | |
| 742 | /* wrong namespace, element name, whatever... */ |
| 743 | /* TODO */ |
| 744 | } |
| 745 | |
aPiecek | 9cdb9e6 | 2021-05-18 09:46:20 +0200 | [diff] [blame] | 746 | static void |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 747 | test_filter_attributes(void **state) |
| 748 | { |
| 749 | const char *data; |
| 750 | struct ly_in *in; |
| 751 | struct lyd_node *tree; |
| 752 | const struct lyd_node *node; |
| 753 | const char *dsc; |
| 754 | const char *ref = "RFC 6241, Section 7.7"; |
| 755 | const char *feats[] = {"writable-running", NULL}; |
| 756 | |
| 757 | 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] | 758 | 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] | 759 | |
| 760 | data = "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" |
| 761 | " <filter type=\"xpath\" select=\"/*\"/>\n" |
| 762 | "</get>\n"; |
| 763 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 764 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL)); |
| 765 | ly_in_free(in, 0); |
| 766 | assert_non_null(tree); |
| 767 | |
| 768 | node = tree; |
| 769 | dsc = "Retrieve running configuration and device state information."; |
| 770 | CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR, |
| 771 | 1, 0, 0, 1, "get", LYS_RPC, |
| 772 | 1, 0, 0, 0, 0, ref, 0); |
| 773 | node = lyd_child(node); |
| 774 | dsc = "This parameter specifies the portion of the system\nconfiguration and state data to retrieve."; |
| 775 | CHECK_LYSC_NODE(node->schema, dsc, 1, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "filter", 0, LYS_ANYXML, 1, 0, NULL, 0); |
| 776 | |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 777 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
| 778 | lyd_free_all(tree); |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 779 | |
Michal Vasko | 1b2a3f4 | 2022-12-20 09:38:28 +0100 | [diff] [blame] | 780 | data = "<create-subscription xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" |
| 781 | " <filter type=\"subtree\">\n" |
| 782 | " <inner-node xmlns=\"my:urn\"/>\n" |
| 783 | " </filter>\n" |
| 784 | "</create-subscription>\n"; |
| 785 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in)); |
| 786 | assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL)); |
| 787 | ly_in_free(in, 0); |
| 788 | assert_non_null(tree); |
| 789 | |
| 790 | CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data); |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 791 | lyd_free_all(tree); |
| 792 | } |
| 793 | |
| 794 | static void |
aPiecek | 9cdb9e6 | 2021-05-18 09:46:20 +0200 | [diff] [blame] | 795 | test_data_skip(void **state) |
| 796 | { |
| 797 | const char *data; |
| 798 | struct lyd_node *tree; |
| 799 | struct lyd_node_term *leaf; |
| 800 | |
| 801 | /* add invalid data to a module that is not implemented */ |
| 802 | data = "<foo xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\"><u/></foo>"; |
| 803 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
| 804 | assert_null(tree); |
| 805 | |
| 806 | /* add invalid data to a module that is implemented */ |
| 807 | data = "<fooX xmlns=\"urn:tests:a\"><u/><list><value/></list></fooX>"; |
| 808 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); |
| 809 | assert_null(tree); |
| 810 | |
| 811 | /* first invalid, next valid */ |
| 812 | data = "<fooX xmlns=\"urn:tests:a\"><u/></fooX> <foo xmlns=\"urn:tests:a\">foo value</foo>"; |
| 813 | CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); |
| 814 | CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0); |
| 815 | leaf = (struct lyd_node_term *)tree; |
| 816 | CHECK_LYD_VALUE(leaf->value, STRING, "foo value"); |
| 817 | lyd_free_all(tree); |
| 818 | } |
| 819 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 820 | int |
| 821 | main(void) |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 822 | { |
| 823 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 824 | UTEST(test_leaf, setup), |
| 825 | UTEST(test_anydata, setup), |
| 826 | UTEST(test_list, setup), |
| 827 | UTEST(test_container, setup), |
| 828 | UTEST(test_opaq, setup), |
| 829 | UTEST(test_rpc, setup), |
| 830 | UTEST(test_action, setup), |
| 831 | UTEST(test_notification, setup), |
| 832 | UTEST(test_reply, setup), |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 833 | UTEST(test_netconf_rpc, setup), |
| 834 | UTEST(test_netconf_action, setup), |
| 835 | UTEST(test_netconf_reply_or_notification, setup), |
Michal Vasko | 45791ad | 2021-06-17 08:45:03 +0200 | [diff] [blame] | 836 | UTEST(test_filter_attributes, setup), |
aPiecek | 9cdb9e6 | 2021-05-18 09:46:20 +0200 | [diff] [blame] | 837 | UTEST(test_data_skip, setup), |
Radek Krejci | 509e259 | 2019-05-15 16:30:48 +0200 | [diff] [blame] | 838 | }; |
| 839 | |
| 840 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 841 | } |