Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1 | /** |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 2 | * @file test_schema_mount.c |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 3 | * @author Tadeas Vintrlik <xvintr04@stud.fit.vutbr.cz> |
| 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 5 | * @brief unit tests for Schema Mount extension support |
| 6 | * |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 7 | * Copyright (c) 2021 - 2022 CESNET, z.s.p.o. |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [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 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 15 | |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 16 | #define _UTEST_MAIN_ |
| 17 | #include "utests.h" |
| 18 | |
| 19 | #include "libyang.h" |
| 20 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 21 | void **glob_state; |
| 22 | |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 23 | static int |
| 24 | setup(void **state) |
| 25 | { |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 26 | const char *schema = |
| 27 | "module sm {yang-version 1.1;namespace \"urn:sm\";prefix \"sm\";" |
| 28 | "import ietf-yang-schema-mount {prefix yangmnt;}" |
| 29 | "import ietf-interfaces {prefix if;}" |
| 30 | "container root {yangmnt:mount-point \"root\";}" |
| 31 | "container root2 {yangmnt:mount-point \"root\";}" |
| 32 | "container root3 {" |
| 33 | " list ls { key name; leaf name {type string;}" |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 34 | " yangmnt:mount-point \"mnt-root\";" |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 35 | " }" |
| 36 | "}" |
| 37 | "leaf target{type string;}" |
| 38 | "augment /if:interfaces/if:interface {" |
| 39 | " leaf sm-name {type leafref {path \"/sm:target\";}}" |
| 40 | "}" |
| 41 | "}"; |
| 42 | |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 43 | UTEST_SETUP; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 44 | glob_state = state; |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 45 | |
| 46 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG)); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 47 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); |
| 48 | assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "iana-if-type", NULL, NULL)); |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static void |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 54 | test_schema(void **state) |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 55 | { |
| 56 | struct lys_module *mod; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 57 | const char *schema; |
| 58 | char *str; |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 59 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 60 | /* invalid */ |
| 61 | schema = |
| 62 | "module sm {\n" |
| 63 | " namespace \"urn:sm\";\n" |
| 64 | " prefix sm;\n" |
| 65 | "\n" |
| 66 | " import ietf-yang-schema-mount {\n" |
| 67 | " prefix yangmnt;\n" |
| 68 | " }\n" |
| 69 | "\n" |
| 70 | " container root {\n" |
| 71 | " yangmnt:mount-point \"root\";\n" |
| 72 | " }\n" |
| 73 | "}\n"; |
| 74 | assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); |
| 75 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 76 | "Extension \"yangmnt:mount-point\" instance not allowed in YANG version 1 module.", |
| 77 | "/sm:root/{extension='yangmnt:mount-point'}/root"); |
| 78 | |
| 79 | schema = |
| 80 | "module sm {\n" |
| 81 | " yang-version 1.1;\n" |
| 82 | " namespace \"urn:sm\";\n" |
| 83 | " prefix sm;\n" |
| 84 | "\n" |
| 85 | " import ietf-yang-schema-mount {\n" |
| 86 | " prefix yangmnt;\n" |
| 87 | " }\n" |
| 88 | "\n" |
| 89 | " yangmnt:mount-point \"root\";\n" |
| 90 | "}\n"; |
| 91 | assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); |
| 92 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 93 | "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.", |
| 94 | "/sm:{extension='yangmnt:mount-point'}/root"); |
| 95 | |
| 96 | schema = |
| 97 | "module sm {\n" |
| 98 | " yang-version 1.1;\n" |
| 99 | " namespace \"urn:sm\";\n" |
| 100 | " prefix sm;\n" |
| 101 | "\n" |
| 102 | " import ietf-yang-schema-mount {\n" |
| 103 | " prefix yangmnt;\n" |
| 104 | " }\n" |
| 105 | "\n" |
| 106 | " container root {\n" |
| 107 | " leaf l {\n" |
| 108 | " type empty;\n" |
| 109 | " yangmnt:mount-point \"root\";\n" |
| 110 | " }\n" |
| 111 | " }\n" |
| 112 | "}\n"; |
| 113 | assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); |
| 114 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 115 | "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.", |
| 116 | "/sm:root/l/{extension='yangmnt:mount-point'}/root"); |
| 117 | |
| 118 | schema = |
| 119 | "module sm {\n" |
| 120 | " yang-version 1.1;\n" |
| 121 | " namespace \"urn:sm\";\n" |
| 122 | " prefix sm;\n" |
| 123 | "\n" |
| 124 | " import ietf-yang-schema-mount {\n" |
| 125 | " prefix yangmnt;\n" |
| 126 | " }\n" |
| 127 | "\n" |
| 128 | " list l {\n" |
| 129 | " key \"k\";\n" |
| 130 | " leaf k {\n" |
| 131 | " type string;\n" |
| 132 | " }\n" |
| 133 | " yangmnt:mount-point \"root\";\n" |
| 134 | " yangmnt:mount-point \"root2\";\n" |
| 135 | " }\n" |
| 136 | "}\n"; |
| 137 | assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); |
| 138 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 139 | "Multiple extension \"yangmnt:mount-point\" instances.", |
| 140 | "/sm:l/{extension='yangmnt:mount-point'}/root2"); |
| 141 | |
| 142 | /* valid */ |
| 143 | schema = |
| 144 | "module sm {\n" |
| 145 | " yang-version 1.1;\n" |
| 146 | " namespace \"urn:sm\";\n" |
| 147 | " prefix sm;\n" |
| 148 | "\n" |
| 149 | " import ietf-yang-schema-mount {\n" |
| 150 | " prefix yangmnt;\n" |
| 151 | " }\n" |
| 152 | "\n" |
| 153 | " container root {\n" |
| 154 | " yangmnt:mount-point \"root\";\n" |
| 155 | " }\n" |
| 156 | "}\n"; |
| 157 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod)); |
| 158 | lys_print_mem(&str, mod, LYS_YIN, 0); |
| 159 | assert_string_equal(str, schema); |
| 160 | free(str); |
| 161 | } |
| 162 | |
| 163 | static LY_ERR |
| 164 | test_ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free) |
| 165 | { |
| 166 | void **state = glob_state; |
| 167 | struct lyd_node *data = NULL; |
| 168 | |
| 169 | (void)ext; |
| 170 | |
| 171 | if (user_data) { |
| 172 | CHECK_PARSE_LYD_PARAM(user_data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 173 | } |
| 174 | |
| 175 | *ext_data = data; |
| 176 | *ext_data_free = 1; |
| 177 | return LY_SUCCESS; |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 181 | test_parse_invalid(void **state) |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 182 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 183 | const char *xml, *json; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 184 | struct lyd_node *data; |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 185 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 186 | /* no callback set */ |
| 187 | xml = |
| 188 | "<root xmlns=\"urn:sm\">" |
| 189 | " <unknown xmlns=\"unknown\">" |
| 190 | " <interface>" |
| 191 | " <name>bu</name>" |
| 192 | " <type xmlns:ii=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ii:ethernetCsmacd</type>" |
| 193 | " </interface>" |
| 194 | " </unknown>" |
| 195 | "</root>"; |
| 196 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data); |
| 197 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": Failed to get extension data, no callback set.", |
| 198 | NULL); |
| 199 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 200 | json = |
| 201 | "{" |
| 202 | " \"sm:root\": {" |
| 203 | " \"unknown:unknown\": {" |
| 204 | " \"interface\": [" |
| 205 | " {" |
| 206 | " \"name\": \"bu\"," |
| 207 | " \"type\": \"iana-if-type:ethernetCsmacd\"" |
| 208 | " }" |
| 209 | " ]" |
| 210 | " }" |
| 211 | " }" |
| 212 | "}"; |
| 213 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data); |
| 214 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": Failed to get extension data, no callback set.", |
| 215 | NULL); |
| 216 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 217 | /* unknown data */ |
| 218 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, NULL); |
| 219 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 220 | assert_string_equal(LYD_NAME(data), "root"); |
| 221 | assert_null(lyd_child(data)); |
| 222 | assert_non_null(data->next); |
| 223 | assert_true(data->next->flags & LYD_DEFAULT); |
| 224 | lyd_free_siblings(data); |
| 225 | |
| 226 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 227 | CHECK_LOG_CTX("No module with namespace \"unknown\" in the context.", |
| 228 | "Schema location /sm:root, data location /sm:root, line number 1."); |
| 229 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 230 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 231 | assert_string_equal(LYD_NAME(data), "root"); |
| 232 | assert_null(lyd_child(data)); |
| 233 | assert_non_null(data->next); |
| 234 | assert_true(data->next->flags & LYD_DEFAULT); |
| 235 | lyd_free_siblings(data); |
| 236 | |
| 237 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 238 | CHECK_LOG_CTX("No module named \"unknown\" in the context.", |
| 239 | "Schema location /sm:root, data location /sm:root, line number 1."); |
| 240 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 241 | /* missing required callback data */ |
| 242 | xml = |
| 243 | "<root xmlns=\"urn:sm\">" |
| 244 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">" |
| 245 | " <interface>" |
| 246 | " <name>bu</name>" |
| 247 | " </interface>" |
| 248 | " </interfaces>" |
| 249 | "</root>"; |
| 250 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 251 | CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", |
| 252 | "Schema location /sm:root, data location /sm:root, line number 1."); |
| 253 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 254 | json = |
| 255 | "{" |
| 256 | " \"sm:root\": {" |
| 257 | " \"ietf-interfaces:interfaces\": {" |
| 258 | " \"interface\": [" |
| 259 | " {" |
| 260 | " \"name\": \"bu\"" |
| 261 | " }" |
| 262 | " ]" |
| 263 | " }" |
| 264 | " }" |
| 265 | "}"; |
| 266 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 267 | CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", |
| 268 | "Schema location /sm:root, data location /sm:root, line number 1."); |
| 269 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 270 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 271 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 272 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 273 | " <module-set>" |
| 274 | " <name>test-set</name>" |
| 275 | " <module>" |
| 276 | " <name>ietf-yang-library</name>" |
| 277 | " <revision>2019-01-04</revision>" |
| 278 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 279 | " </module>" |
| 280 | " </module-set>" |
| 281 | " <schema>" |
| 282 | " <name>test-schema</name>" |
| 283 | " <module-set>test-set</module-set>" |
| 284 | " </schema>" |
| 285 | " <datastore>" |
| 286 | " <name>ds:running</name>" |
| 287 | " <schema>test-schema</schema>" |
| 288 | " </datastore>" |
| 289 | " <datastore>" |
| 290 | " <name>ds:operational</name>" |
| 291 | " <schema>test-schema</schema>" |
| 292 | " </datastore>" |
| 293 | " <content-id>1</content-id>" |
| 294 | "</yang-library>" |
| 295 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 296 | " <module-set-id>1</module-set-id>" |
| 297 | "</modules-state>"); |
| 298 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 299 | CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 300 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 301 | CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 302 | |
| 303 | /* missing module in yang-library data */ |
| 304 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 305 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 306 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 307 | " <module-set>" |
| 308 | " <name>test-set</name>" |
| 309 | " <module>" |
| 310 | " <name>ietf-yang-library</name>" |
| 311 | " <revision>2019-01-04</revision>" |
| 312 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 313 | " </module>" |
| 314 | " </module-set>" |
| 315 | " <schema>" |
| 316 | " <name>test-schema</name>" |
| 317 | " <module-set>test-set</module-set>" |
| 318 | " </schema>" |
| 319 | " <datastore>" |
| 320 | " <name>ds:running</name>" |
| 321 | " <schema>test-schema</schema>" |
| 322 | " </datastore>" |
| 323 | " <datastore>" |
| 324 | " <name>ds:operational</name>" |
| 325 | " <schema>test-schema</schema>" |
| 326 | " </datastore>" |
| 327 | " <content-id>1</content-id>" |
| 328 | "</yang-library>" |
| 329 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 330 | " <module-set-id>1</module-set-id>" |
| 331 | "</modules-state>" |
| 332 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 333 | " <mount-point>" |
| 334 | " <module>sm</module>" |
| 335 | " <label>root</label>" |
| 336 | " <inline/>" |
| 337 | " </mount-point>" |
| 338 | "</schema-mounts>"); |
| 339 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 340 | CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 341 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 342 | CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 343 | |
| 344 | /* callback data correct, invalid YANG data */ |
| 345 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 346 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 347 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 348 | " <module-set>" |
| 349 | " <name>test-set</name>" |
| 350 | " <module>" |
| 351 | " <name>ietf-datastores</name>" |
| 352 | " <revision>2018-02-14</revision>" |
| 353 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 354 | " </module>" |
| 355 | " <module>" |
| 356 | " <name>ietf-yang-library</name>" |
| 357 | " <revision>2019-01-04</revision>" |
| 358 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 359 | " </module>" |
| 360 | " <module>" |
| 361 | " <name>ietf-yang-schema-mount</name>" |
| 362 | " <revision>2019-01-14</revision>" |
| 363 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 364 | " </module>" |
| 365 | " <module>" |
| 366 | " <name>ietf-interfaces</name>" |
| 367 | " <revision>2014-05-08</revision>" |
| 368 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 369 | " </module>" |
| 370 | " <module>" |
| 371 | " <name>iana-if-type</name>" |
| 372 | " <revision>2014-05-08</revision>" |
| 373 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 374 | " </module>" |
| 375 | " <import-only-module>" |
| 376 | " <name>ietf-yang-types</name>" |
| 377 | " <revision>2013-07-15</revision>" |
| 378 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 379 | " </import-only-module>" |
| 380 | " </module-set>" |
| 381 | " <schema>" |
| 382 | " <name>test-schema</name>" |
| 383 | " <module-set>test-set</module-set>" |
| 384 | " </schema>" |
| 385 | " <datastore>" |
| 386 | " <name>ds:running</name>" |
| 387 | " <schema>test-schema</schema>" |
| 388 | " </datastore>" |
| 389 | " <datastore>" |
| 390 | " <name>ds:operational</name>" |
| 391 | " <schema>test-schema</schema>" |
| 392 | " </datastore>" |
| 393 | " <content-id>1</content-id>" |
| 394 | "</yang-library>" |
| 395 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 396 | " <module-set-id>1</module-set-id>" |
| 397 | "</modules-state>" |
| 398 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 399 | " <mount-point>" |
| 400 | " <module>sm</module>" |
| 401 | " <label>root</label>" |
| 402 | " <inline/>" |
| 403 | " </mount-point>" |
| 404 | "</schema-mounts>"); |
| 405 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 406 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 407 | "Mandatory node \"type\" instance does not exist.", |
| 408 | "Schema location /ietf-interfaces:interfaces/interface/type."); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 409 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 410 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 411 | "Mandatory node \"type\" instance does not exist.", |
| 412 | "Schema location /ietf-interfaces:interfaces/interface/type."); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 413 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 414 | /* same validation fail in separate validation */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 415 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data); |
| 416 | assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 417 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 418 | "Mandatory node \"type\" instance does not exist.", |
| 419 | "Schema location /ietf-interfaces:interfaces/interface/type."); |
| 420 | lyd_free_siblings(data); |
| 421 | |
| 422 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data); |
| 423 | assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL)); |
| 424 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 425 | "Mandatory node \"type\" instance does not exist.", |
| 426 | "Schema location /ietf-interfaces:interfaces/interface/type."); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 427 | lyd_free_siblings(data); |
| 428 | |
| 429 | /* success */ |
| 430 | xml = |
| 431 | "<root xmlns=\"urn:sm\">\n" |
| 432 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 433 | " <interface>\n" |
| 434 | " <name>bu</name>\n" |
| 435 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 436 | " </interface>\n" |
| 437 | " </interfaces>\n" |
| 438 | "</root>\n"; |
| 439 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 440 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 441 | lyd_free_siblings(data); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 442 | |
| 443 | json = |
| 444 | "{\n" |
| 445 | " \"sm:root\": {\n" |
| 446 | " \"ietf-interfaces:interfaces\": {\n" |
| 447 | " \"interface\": [\n" |
| 448 | " {\n" |
| 449 | " \"name\": \"bu\",\n" |
| 450 | " \"type\": \"iana-if-type:ethernetCsmacd\"\n" |
| 451 | " }\n" |
| 452 | " ]\n" |
| 453 | " }\n" |
| 454 | " }\n" |
| 455 | "}\n"; |
| 456 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 457 | CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS); |
| 458 | lyd_free_siblings(data); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 462 | test_parse_inline(void **state) |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 463 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 464 | const char *xml, *json; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 465 | struct lyd_node *data; |
| 466 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 467 | /* valid */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 468 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 469 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 470 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 471 | " <module-set>" |
| 472 | " <name>test-set</name>" |
| 473 | " <module>" |
| 474 | " <name>ietf-datastores</name>" |
| 475 | " <revision>2018-02-14</revision>" |
| 476 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 477 | " </module>" |
| 478 | " <module>" |
| 479 | " <name>ietf-yang-library</name>" |
| 480 | " <revision>2019-01-04</revision>" |
| 481 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 482 | " </module>" |
| 483 | " <module>" |
| 484 | " <name>ietf-yang-schema-mount</name>" |
| 485 | " <revision>2019-01-14</revision>" |
| 486 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 487 | " </module>" |
| 488 | " <module>" |
| 489 | " <name>ietf-interfaces</name>" |
| 490 | " <revision>2014-05-08</revision>" |
| 491 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 492 | " </module>" |
| 493 | " <module>" |
| 494 | " <name>iana-if-type</name>" |
| 495 | " <revision>2014-05-08</revision>" |
| 496 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 497 | " </module>" |
| 498 | " <import-only-module>" |
| 499 | " <name>ietf-yang-types</name>" |
| 500 | " <revision>2013-07-15</revision>" |
| 501 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 502 | " </import-only-module>" |
| 503 | " </module-set>" |
| 504 | " <schema>" |
| 505 | " <name>test-schema</name>" |
| 506 | " <module-set>test-set</module-set>" |
| 507 | " </schema>" |
| 508 | " <datastore>" |
| 509 | " <name>ds:running</name>" |
| 510 | " <schema>test-schema</schema>" |
| 511 | " </datastore>" |
| 512 | " <datastore>" |
| 513 | " <name>ds:operational</name>" |
| 514 | " <schema>test-schema</schema>" |
| 515 | " </datastore>" |
| 516 | " <content-id>1</content-id>" |
| 517 | "</yang-library>" |
| 518 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 519 | " <module-set-id>1</module-set-id>" |
| 520 | "</modules-state>" |
| 521 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 522 | " <mount-point>" |
| 523 | " <module>sm</module>" |
| 524 | " <label>root</label>" |
| 525 | " <inline/>" |
| 526 | " </mount-point>" |
| 527 | "</schema-mounts>"); |
| 528 | xml = |
| 529 | "<root xmlns=\"urn:sm\">\n" |
| 530 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 531 | " <interface>\n" |
| 532 | " <name>bu</name>\n" |
| 533 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 534 | " </interface>\n" |
| 535 | " </interfaces>\n" |
| 536 | " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 537 | " <interface>\n" |
| 538 | " <name>bu</name>\n" |
| 539 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 540 | " <oper-status>not-present</oper-status>\n" |
| 541 | " <statistics>\n" |
| 542 | " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n" |
| 543 | " </statistics>\n" |
| 544 | " </interface>\n" |
| 545 | " </interfaces-state>\n" |
| 546 | "</root>\n"; |
| 547 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 548 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 549 | lyd_free_siblings(data); |
| 550 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 551 | json = |
| 552 | "{\n" |
| 553 | " \"sm:root\": {\n" |
| 554 | " \"ietf-interfaces:interfaces\": {\n" |
| 555 | " \"interface\": [\n" |
| 556 | " {\n" |
| 557 | " \"name\": \"bu\",\n" |
| 558 | " \"type\": \"iana-if-type:ethernetCsmacd\"\n" |
| 559 | " }\n" |
| 560 | " ]\n" |
| 561 | " },\n" |
| 562 | " \"ietf-interfaces:interfaces-state\": {\n" |
| 563 | " \"interface\": [\n" |
| 564 | " {\n" |
| 565 | " \"name\": \"bu\",\n" |
| 566 | " \"type\": \"iana-if-type:ethernetCsmacd\",\n" |
| 567 | " \"oper-status\": \"not-present\",\n" |
| 568 | " \"statistics\": {\n" |
| 569 | " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n" |
| 570 | " }\n" |
| 571 | " }\n" |
| 572 | " ]\n" |
| 573 | " }\n" |
| 574 | " }\n" |
| 575 | "}\n"; |
| 576 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 577 | CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS); |
| 578 | lyd_free_siblings(data); |
| 579 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 580 | /* different yang-lib data */ |
| 581 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 582 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 583 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 584 | " <module-set>" |
| 585 | " <name>test-set</name>" |
| 586 | " <module>" |
| 587 | " <name>ietf-datastores</name>" |
| 588 | " <revision>2018-02-14</revision>" |
| 589 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 590 | " </module>" |
| 591 | " <module>" |
| 592 | " <name>ietf-yang-library</name>" |
| 593 | " <revision>2019-01-04</revision>" |
| 594 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 595 | " </module>" |
| 596 | " <module>" |
| 597 | " <name>ietf-yang-schema-mount</name>" |
| 598 | " <revision>2019-01-14</revision>" |
| 599 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 600 | " </module>" |
| 601 | " <module>" |
| 602 | " <name>ietf-interfaces</name>" |
| 603 | " <revision>2014-05-08</revision>" |
| 604 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 605 | " </module>" |
| 606 | " <module>" |
| 607 | " <name>ietf-ip</name>" |
| 608 | " <revision>2014-06-16</revision>" |
| 609 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 610 | " </module>" |
| 611 | " <module>" |
| 612 | " <name>iana-if-type</name>" |
| 613 | " <revision>2014-05-08</revision>" |
| 614 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 615 | " </module>" |
| 616 | " <import-only-module>" |
| 617 | " <name>ietf-yang-types</name>" |
| 618 | " <revision>2013-07-15</revision>" |
| 619 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 620 | " </import-only-module>" |
| 621 | " </module-set>" |
| 622 | " <schema>" |
| 623 | " <name>test-schema</name>" |
| 624 | " <module-set>test-set</module-set>" |
| 625 | " </schema>" |
| 626 | " <datastore>" |
| 627 | " <name>ds:running</name>" |
| 628 | " <schema>test-schema</schema>" |
| 629 | " </datastore>" |
| 630 | " <datastore>" |
| 631 | " <name>ds:operational</name>" |
| 632 | " <schema>test-schema</schema>" |
| 633 | " </datastore>" |
| 634 | " <content-id>1</content-id>" |
| 635 | "</yang-library>" |
| 636 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 637 | " <module-set-id>1</module-set-id>" |
| 638 | "</modules-state>" |
| 639 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 640 | " <mount-point>" |
| 641 | " <module>sm</module>" |
| 642 | " <label>root</label>" |
| 643 | " <inline/>" |
| 644 | " </mount-point>" |
| 645 | "</schema-mounts>"); |
| 646 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 647 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 648 | lyd_free_siblings(data); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 649 | |
| 650 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 651 | CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS); |
| 652 | lyd_free_siblings(data); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 656 | test_parse_shared(void **state) |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 657 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 658 | const char *xml, *json; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 659 | struct lyd_node *data; |
| 660 | |
| 661 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 662 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 663 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 664 | " <module-set>" |
| 665 | " <name>test-set</name>" |
| 666 | " <module>" |
| 667 | " <name>ietf-datastores</name>" |
| 668 | " <revision>2018-02-14</revision>" |
| 669 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 670 | " </module>" |
| 671 | " <module>" |
| 672 | " <name>ietf-yang-library</name>" |
| 673 | " <revision>2019-01-04</revision>" |
| 674 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 675 | " </module>" |
| 676 | " <module>" |
| 677 | " <name>ietf-yang-schema-mount</name>" |
| 678 | " <revision>2019-01-14</revision>" |
| 679 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 680 | " </module>" |
| 681 | " <module>" |
| 682 | " <name>ietf-interfaces</name>" |
| 683 | " <revision>2014-05-08</revision>" |
| 684 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 685 | " </module>" |
| 686 | " <module>" |
| 687 | " <name>iana-if-type</name>" |
| 688 | " <revision>2014-05-08</revision>" |
| 689 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 690 | " </module>" |
| 691 | " <import-only-module>" |
| 692 | " <name>ietf-yang-types</name>" |
| 693 | " <revision>2013-07-15</revision>" |
| 694 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 695 | " </import-only-module>" |
| 696 | " </module-set>" |
| 697 | " <schema>" |
| 698 | " <name>test-schema</name>" |
| 699 | " <module-set>test-set</module-set>" |
| 700 | " </schema>" |
| 701 | " <datastore>" |
| 702 | " <name>ds:running</name>" |
| 703 | " <schema>test-schema</schema>" |
| 704 | " </datastore>" |
| 705 | " <datastore>" |
| 706 | " <name>ds:operational</name>" |
| 707 | " <schema>test-schema</schema>" |
| 708 | " </datastore>" |
| 709 | " <content-id>1</content-id>" |
| 710 | "</yang-library>" |
| 711 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 712 | " <module-set-id>1</module-set-id>" |
| 713 | "</modules-state>" |
| 714 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 715 | " <mount-point>" |
| 716 | " <module>sm</module>" |
| 717 | " <label>root</label>" |
| 718 | " <shared-schema/>" |
| 719 | " </mount-point>" |
| 720 | "</schema-mounts>"); |
| 721 | xml = |
| 722 | "<root xmlns=\"urn:sm\">\n" |
| 723 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 724 | " <interface>\n" |
| 725 | " <name>bu</name>\n" |
| 726 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 727 | " </interface>\n" |
| 728 | " </interfaces>\n" |
| 729 | " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 730 | " <interface>\n" |
| 731 | " <name>bu</name>\n" |
| 732 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 733 | " <oper-status>not-present</oper-status>\n" |
| 734 | " <statistics>\n" |
| 735 | " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n" |
| 736 | " </statistics>\n" |
| 737 | " </interface>\n" |
| 738 | " </interfaces-state>\n" |
| 739 | "</root>\n"; |
| 740 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 741 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 742 | lyd_free_siblings(data); |
| 743 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 744 | json = |
| 745 | "{\n" |
| 746 | " \"sm:root\": {\n" |
| 747 | " \"ietf-interfaces:interfaces\": {\n" |
| 748 | " \"interface\": [\n" |
| 749 | " {\n" |
| 750 | " \"name\": \"bu\",\n" |
| 751 | " \"type\": \"iana-if-type:ethernetCsmacd\"\n" |
| 752 | " }\n" |
| 753 | " ]\n" |
| 754 | " },\n" |
| 755 | " \"ietf-interfaces:interfaces-state\": {\n" |
| 756 | " \"interface\": [\n" |
| 757 | " {\n" |
| 758 | " \"name\": \"bu\",\n" |
| 759 | " \"type\": \"iana-if-type:ethernetCsmacd\",\n" |
| 760 | " \"oper-status\": \"not-present\",\n" |
| 761 | " \"statistics\": {\n" |
| 762 | " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n" |
| 763 | " }\n" |
| 764 | " }\n" |
| 765 | " ]\n" |
| 766 | " }\n" |
| 767 | " }\n" |
| 768 | "}\n"; |
| 769 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 770 | CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS); |
| 771 | lyd_free_siblings(data); |
| 772 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 773 | /* different yang-lib data */ |
| 774 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 775 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 776 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 777 | " <module-set>" |
| 778 | " <name>test-set</name>" |
| 779 | " <module>" |
| 780 | " <name>ietf-datastores</name>" |
| 781 | " <revision>2018-02-14</revision>" |
| 782 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 783 | " </module>" |
| 784 | " <module>" |
| 785 | " <name>ietf-yang-library</name>" |
| 786 | " <revision>2019-01-04</revision>" |
| 787 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 788 | " </module>" |
| 789 | " <module>" |
| 790 | " <name>ietf-yang-schema-mount</name>" |
| 791 | " <revision>2019-01-14</revision>" |
| 792 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 793 | " </module>" |
| 794 | " <module>" |
| 795 | " <name>ietf-interfaces</name>" |
| 796 | " <revision>2014-05-08</revision>" |
| 797 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 798 | " </module>" |
| 799 | " <module>" |
| 800 | " <name>ietf-ip</name>" |
| 801 | " <revision>2014-06-16</revision>" |
| 802 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 803 | " </module>" |
| 804 | " <module>" |
| 805 | " <name>iana-if-type</name>" |
| 806 | " <revision>2014-05-08</revision>" |
| 807 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 808 | " </module>" |
| 809 | " <import-only-module>" |
| 810 | " <name>ietf-yang-types</name>" |
| 811 | " <revision>2013-07-15</revision>" |
| 812 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 813 | " </import-only-module>" |
| 814 | " </module-set>" |
| 815 | " <schema>" |
| 816 | " <name>test-schema</name>" |
| 817 | " <module-set>test-set</module-set>" |
| 818 | " </schema>" |
| 819 | " <datastore>" |
| 820 | " <name>ds:running</name>" |
| 821 | " <schema>test-schema</schema>" |
| 822 | " </datastore>" |
| 823 | " <datastore>" |
| 824 | " <name>ds:operational</name>" |
| 825 | " <schema>test-schema</schema>" |
| 826 | " </datastore>" |
| 827 | " <content-id>2</content-id>" |
| 828 | "</yang-library>" |
| 829 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 830 | " <module-set-id>1</module-set-id>" |
| 831 | "</modules-state>" |
| 832 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 833 | " <mount-point>" |
| 834 | " <module>sm</module>" |
| 835 | " <label>root</label>" |
| 836 | " <shared-schema/>" |
| 837 | " </mount-point>" |
| 838 | "</schema-mounts>"); |
| 839 | xml = |
| 840 | "<root2 xmlns=\"urn:sm\">\n" |
| 841 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 842 | " <interface>\n" |
| 843 | " <name>bu</name>\n" |
| 844 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 845 | " </interface>\n" |
| 846 | " </interfaces>\n" |
| 847 | " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 848 | " <interface>\n" |
| 849 | " <name>bu</name>\n" |
| 850 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 851 | " <oper-status>not-present</oper-status>\n" |
| 852 | " <statistics>\n" |
| 853 | " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n" |
| 854 | " </statistics>\n" |
| 855 | " </interface>\n" |
| 856 | " </interfaces-state>\n" |
| 857 | "</root2>\n"; |
| 858 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 859 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 860 | "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.", |
| 861 | "/ietf-yang-library:yang-library/content-id"); |
| 862 | |
| 863 | /* data for 2 mount points */ |
| 864 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 865 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 866 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 867 | " <module-set>" |
| 868 | " <name>test-set</name>" |
| 869 | " <module>" |
| 870 | " <name>ietf-datastores</name>" |
| 871 | " <revision>2018-02-14</revision>" |
| 872 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 873 | " </module>" |
| 874 | " <module>" |
| 875 | " <name>ietf-yang-library</name>" |
| 876 | " <revision>2019-01-04</revision>" |
| 877 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 878 | " </module>" |
| 879 | " <module>" |
| 880 | " <name>ietf-yang-schema-mount</name>" |
| 881 | " <revision>2019-01-14</revision>" |
| 882 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 883 | " </module>" |
| 884 | " <module>" |
| 885 | " <name>ietf-interfaces</name>" |
| 886 | " <revision>2014-05-08</revision>" |
| 887 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 888 | " </module>" |
| 889 | " <module>" |
| 890 | " <name>iana-if-type</name>" |
| 891 | " <revision>2014-05-08</revision>" |
| 892 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 893 | " </module>" |
| 894 | " <import-only-module>" |
| 895 | " <name>ietf-yang-types</name>" |
| 896 | " <revision>2013-07-15</revision>" |
| 897 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 898 | " </import-only-module>" |
| 899 | " </module-set>" |
| 900 | " <schema>" |
| 901 | " <name>test-schema</name>" |
| 902 | " <module-set>test-set</module-set>" |
| 903 | " </schema>" |
| 904 | " <datastore>" |
| 905 | " <name>ds:running</name>" |
| 906 | " <schema>test-schema</schema>" |
| 907 | " </datastore>" |
| 908 | " <datastore>" |
| 909 | " <name>ds:operational</name>" |
| 910 | " <schema>test-schema</schema>" |
| 911 | " </datastore>" |
| 912 | " <content-id>1</content-id>" |
| 913 | "</yang-library>" |
| 914 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 915 | " <module-set-id>1</module-set-id>" |
| 916 | "</modules-state>" |
| 917 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 918 | " <mount-point>" |
| 919 | " <module>sm</module>" |
| 920 | " <label>root</label>" |
| 921 | " <shared-schema/>" |
| 922 | " </mount-point>" |
| 923 | "</schema-mounts>"); |
| 924 | xml = |
| 925 | "<root xmlns=\"urn:sm\">\n" |
| 926 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 927 | " <interface>\n" |
| 928 | " <name>bu</name>\n" |
| 929 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 930 | " </interface>\n" |
| 931 | " </interfaces>\n" |
| 932 | " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 933 | " <interface>\n" |
| 934 | " <name>bu</name>\n" |
| 935 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 936 | " <oper-status>not-present</oper-status>\n" |
| 937 | " <statistics>\n" |
| 938 | " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n" |
| 939 | " </statistics>\n" |
| 940 | " </interface>\n" |
| 941 | " </interfaces-state>\n" |
| 942 | "</root>\n" |
| 943 | "<root2 xmlns=\"urn:sm\">\n" |
| 944 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 945 | " <interface>\n" |
| 946 | " <name>fu</name>\n" |
| 947 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n" |
| 948 | " </interface>\n" |
| 949 | " </interfaces>\n" |
| 950 | " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 951 | " <interface>\n" |
| 952 | " <name>fu</name>\n" |
| 953 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n" |
| 954 | " <oper-status>down</oper-status>\n" |
| 955 | " <statistics>\n" |
| 956 | " <discontinuity-time>2020-01-01T10:00:00-00:00</discontinuity-time>\n" |
| 957 | " </statistics>\n" |
| 958 | " </interface>\n" |
| 959 | " </interfaces-state>\n" |
| 960 | "</root2>\n"; |
| 961 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 962 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 963 | lyd_free_siblings(data); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 964 | |
| 965 | json = |
| 966 | "{\n" |
| 967 | " \"sm:root\": {\n" |
| 968 | " \"ietf-interfaces:interfaces\": {\n" |
| 969 | " \"interface\": [\n" |
| 970 | " {\n" |
| 971 | " \"name\": \"bu\",\n" |
| 972 | " \"type\": \"iana-if-type:ethernetCsmacd\"\n" |
| 973 | " }\n" |
| 974 | " ]\n" |
| 975 | " },\n" |
| 976 | " \"ietf-interfaces:interfaces-state\": {\n" |
| 977 | " \"interface\": [\n" |
| 978 | " {\n" |
| 979 | " \"name\": \"bu\",\n" |
| 980 | " \"type\": \"iana-if-type:ethernetCsmacd\",\n" |
| 981 | " \"oper-status\": \"not-present\",\n" |
| 982 | " \"statistics\": {\n" |
| 983 | " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n" |
| 984 | " }\n" |
| 985 | " }\n" |
| 986 | " ]\n" |
| 987 | " }\n" |
| 988 | " },\n" |
| 989 | " \"sm:root2\": {\n" |
| 990 | " \"ietf-interfaces:interfaces\": {\n" |
| 991 | " \"interface\": [\n" |
| 992 | " {\n" |
| 993 | " \"name\": \"fu\",\n" |
| 994 | " \"type\": \"iana-if-type:fddi\"\n" |
| 995 | " }\n" |
| 996 | " ]\n" |
| 997 | " },\n" |
| 998 | " \"ietf-interfaces:interfaces-state\": {\n" |
| 999 | " \"interface\": [\n" |
| 1000 | " {\n" |
| 1001 | " \"name\": \"fu\",\n" |
| 1002 | " \"type\": \"iana-if-type:fddi\",\n" |
| 1003 | " \"oper-status\": \"down\",\n" |
| 1004 | " \"statistics\": {\n" |
| 1005 | " \"discontinuity-time\": \"2020-01-01T10:00:00-00:00\"\n" |
| 1006 | " }\n" |
| 1007 | " }\n" |
| 1008 | " ]\n" |
| 1009 | " }\n" |
| 1010 | " }\n" |
| 1011 | "}\n"; |
| 1012 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 1013 | CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS); |
| 1014 | lyd_free_siblings(data); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1018 | test_parse_shared_parent_ref(void **state) |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1019 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1020 | const char *xml, *json; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1021 | struct lyd_node *data; |
| 1022 | |
| 1023 | /* wrong leafref value */ |
| 1024 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 1025 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 1026 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 1027 | " <module-set>" |
| 1028 | " <name>test-set</name>" |
| 1029 | " <module>" |
| 1030 | " <name>ietf-datastores</name>" |
| 1031 | " <revision>2018-02-14</revision>" |
| 1032 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 1033 | " </module>" |
| 1034 | " <module>" |
| 1035 | " <name>ietf-yang-library</name>" |
| 1036 | " <revision>2019-01-04</revision>" |
| 1037 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 1038 | " </module>" |
| 1039 | " <module>" |
| 1040 | " <name>ietf-yang-schema-mount</name>" |
| 1041 | " <revision>2019-01-14</revision>" |
| 1042 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 1043 | " </module>" |
| 1044 | " <module>" |
| 1045 | " <name>sm</name>" |
| 1046 | " <namespace>urn:sm</namespace>" |
| 1047 | " </module>" |
| 1048 | " <module>" |
| 1049 | " <name>ietf-interfaces</name>" |
| 1050 | " <revision>2014-05-08</revision>" |
| 1051 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 1052 | " </module>" |
| 1053 | " <module>" |
| 1054 | " <name>iana-if-type</name>" |
| 1055 | " <revision>2014-05-08</revision>" |
| 1056 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 1057 | " </module>" |
| 1058 | " <import-only-module>" |
| 1059 | " <name>ietf-yang-types</name>" |
| 1060 | " <revision>2013-07-15</revision>" |
| 1061 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 1062 | " </import-only-module>" |
| 1063 | " </module-set>" |
| 1064 | " <schema>" |
| 1065 | " <name>test-schema</name>" |
| 1066 | " <module-set>test-set</module-set>" |
| 1067 | " </schema>" |
| 1068 | " <datastore>" |
| 1069 | " <name>ds:running</name>" |
| 1070 | " <schema>test-schema</schema>" |
| 1071 | " </datastore>" |
| 1072 | " <datastore>" |
| 1073 | " <name>ds:operational</name>" |
| 1074 | " <schema>test-schema</schema>" |
| 1075 | " </datastore>" |
| 1076 | " <content-id>1</content-id>" |
| 1077 | "</yang-library>" |
| 1078 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 1079 | " <module-set-id>1</module-set-id>" |
| 1080 | "</modules-state>" |
| 1081 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 1082 | " <namespace>" |
| 1083 | " <prefix>smp</prefix>" |
| 1084 | " <uri>urn:sm</uri>" |
| 1085 | " </namespace>" |
| 1086 | " <mount-point>" |
| 1087 | " <module>sm</module>" |
| 1088 | " <label>mnt-root</label>" |
| 1089 | " <shared-schema>" |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1090 | " <parent-reference>/smp:target[. = current()/smp:name]</parent-reference>" |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1091 | " </shared-schema>" |
| 1092 | " </mount-point>" |
| 1093 | "</schema-mounts>"); |
| 1094 | xml = |
| 1095 | "<root3 xmlns=\"urn:sm\">\n" |
| 1096 | " <ls>\n" |
| 1097 | " <name>target-value</name>\n" |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1098 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 1099 | " <interface>\n" |
| 1100 | " <name>bu</name>\n" |
| 1101 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 1102 | " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n" |
| 1103 | " </interface>\n" |
| 1104 | " </interfaces>\n" |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1105 | " </ls>\n" |
| 1106 | "</root3>\n" |
| 1107 | "<target xmlns=\"urn:sm\">wrong-target-value</target>\n"; |
| 1108 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 1109 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 1110 | "Invalid leafref value \"target-value\" - no existing target instance \"/sm:target\".", |
| 1111 | "Schema location /ietf-interfaces:interfaces/interface/sm:sm-name, " |
| 1112 | "data location /ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name."); |
| 1113 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1114 | json = |
| 1115 | "{\n" |
| 1116 | " \"sm:root3\": {\n" |
| 1117 | " \"ls\": [" |
| 1118 | " {\n" |
| 1119 | " \"name\": \"target-value\",\n" |
| 1120 | " \"ietf-interfaces:interfaces\": {\n" |
| 1121 | " \"interface\": [\n" |
| 1122 | " {\n" |
| 1123 | " \"name\": \"bu\",\n" |
| 1124 | " \"type\": \"iana-if-type:ethernetCsmacd\",\n" |
| 1125 | " \"sm:sm-name\": \"target-value\"\n" |
| 1126 | " }\n" |
| 1127 | " ]\n" |
| 1128 | " }\n" |
| 1129 | " }\n" |
| 1130 | " ]\n" |
| 1131 | " },\n" |
| 1132 | " \"sm:target\": \"wrong-target-value\"\n" |
| 1133 | "}\n"; |
| 1134 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); |
| 1135 | CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": " |
| 1136 | "Invalid leafref value \"target-value\" - no existing target instance \"/sm:target\".", |
| 1137 | "Schema location /ietf-interfaces:interfaces/interface/sm:sm-name, " |
| 1138 | "data location /ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name."); |
| 1139 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1140 | /* success */ |
| 1141 | xml = |
| 1142 | "<root3 xmlns=\"urn:sm\">\n" |
| 1143 | " <ls>\n" |
| 1144 | " <name>target-value</name>\n" |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1145 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 1146 | " <interface>\n" |
| 1147 | " <name>bu</name>\n" |
| 1148 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 1149 | " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n" |
| 1150 | " </interface>\n" |
| 1151 | " </interfaces>\n" |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1152 | " </ls>\n" |
| 1153 | "</root3>\n" |
| 1154 | "<target xmlns=\"urn:sm\">target-value</target>\n"; |
| 1155 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 1156 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 1157 | lyd_free_siblings(data); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1158 | |
| 1159 | json = |
| 1160 | "{\n" |
| 1161 | " \"sm:root3\": {\n" |
| 1162 | " \"ls\": [\n" |
| 1163 | " {\n" |
| 1164 | " \"name\": \"target-value\",\n" |
| 1165 | " \"ietf-interfaces:interfaces\": {\n" |
| 1166 | " \"interface\": [\n" |
| 1167 | " {\n" |
| 1168 | " \"name\": \"bu\",\n" |
| 1169 | " \"type\": \"iana-if-type:ethernetCsmacd\",\n" |
| 1170 | " \"sm:sm-name\": \"target-value\"\n" |
| 1171 | " }\n" |
| 1172 | " ]\n" |
| 1173 | " }\n" |
| 1174 | " }\n" |
| 1175 | " ]\n" |
| 1176 | " },\n" |
| 1177 | " \"sm:target\": \"target-value\"\n" |
| 1178 | "}\n"; |
| 1179 | CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 1180 | CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS); |
| 1181 | lyd_free_siblings(data); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1185 | test_parse_config(void **state) |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1186 | { |
| 1187 | const char *xml; |
| 1188 | struct lyd_node *data; |
| 1189 | const struct lyd_node *node; |
| 1190 | |
| 1191 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, |
| 1192 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" " |
| 1193 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">" |
| 1194 | " <module-set>" |
| 1195 | " <name>test-set</name>" |
| 1196 | " <module>" |
| 1197 | " <name>ietf-datastores</name>" |
| 1198 | " <revision>2018-02-14</revision>" |
| 1199 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>" |
| 1200 | " </module>" |
| 1201 | " <module>" |
| 1202 | " <name>ietf-yang-library</name>" |
| 1203 | " <revision>2019-01-04</revision>" |
| 1204 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>" |
| 1205 | " </module>" |
| 1206 | " <module>" |
| 1207 | " <name>ietf-yang-schema-mount</name>" |
| 1208 | " <revision>2019-01-14</revision>" |
| 1209 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>" |
| 1210 | " </module>" |
| 1211 | " <module>" |
| 1212 | " <name>ietf-interfaces</name>" |
| 1213 | " <revision>2014-05-08</revision>" |
| 1214 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>" |
| 1215 | " </module>" |
| 1216 | " <module>" |
| 1217 | " <name>iana-if-type</name>" |
| 1218 | " <revision>2014-05-08</revision>" |
| 1219 | " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>" |
| 1220 | " </module>" |
| 1221 | " <import-only-module>" |
| 1222 | " <name>ietf-yang-types</name>" |
| 1223 | " <revision>2013-07-15</revision>" |
| 1224 | " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>" |
| 1225 | " </import-only-module>" |
| 1226 | " </module-set>" |
| 1227 | " <schema>" |
| 1228 | " <name>test-schema</name>" |
| 1229 | " <module-set>test-set</module-set>" |
| 1230 | " </schema>" |
| 1231 | " <datastore>" |
| 1232 | " <name>ds:running</name>" |
| 1233 | " <schema>test-schema</schema>" |
| 1234 | " </datastore>" |
| 1235 | " <datastore>" |
| 1236 | " <name>ds:operational</name>" |
| 1237 | " <schema>test-schema</schema>" |
| 1238 | " </datastore>" |
| 1239 | " <content-id>1</content-id>" |
| 1240 | "</yang-library>" |
| 1241 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">" |
| 1242 | " <module-set-id>1</module-set-id>" |
| 1243 | "</modules-state>" |
| 1244 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">" |
| 1245 | " <mount-point>" |
| 1246 | " <module>sm</module>" |
| 1247 | " <label>root</label>" |
| 1248 | " <config>false</config>" |
| 1249 | " <inline/>" |
| 1250 | " </mount-point>" |
| 1251 | "</schema-mounts>"); |
| 1252 | xml = |
| 1253 | "<root xmlns=\"urn:sm\">\n" |
| 1254 | " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" |
| 1255 | " <interface>\n" |
| 1256 | " <name>bu</name>\n" |
| 1257 | " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" |
| 1258 | " <enabled>true</enabled>\n" |
| 1259 | " </interface>\n" |
| 1260 | " </interfaces>\n" |
| 1261 | "</root>\n"; |
| 1262 | CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data); |
| 1263 | CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS); |
| 1264 | |
| 1265 | node = lyd_child(data); |
| 1266 | assert_string_equal(LYD_NAME(node), "interfaces"); |
| 1267 | assert_true(node->schema->flags & LYS_CONFIG_R); |
| 1268 | node = lyd_child(node); |
| 1269 | assert_string_equal(LYD_NAME(node), "interface"); |
| 1270 | assert_true(node->schema->flags & LYS_CONFIG_R); |
| 1271 | node = lyd_child(node); |
| 1272 | assert_string_equal(LYD_NAME(node), "name"); |
| 1273 | assert_true(node->schema->flags & LYS_CONFIG_R); |
| 1274 | node = node->next; |
| 1275 | assert_string_equal(LYD_NAME(node), "type"); |
| 1276 | assert_true(node->schema->flags & LYS_CONFIG_R); |
| 1277 | |
| 1278 | lyd_free_siblings(data); |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | int |
| 1282 | main(void) |
| 1283 | { |
| 1284 | const struct CMUnitTest tests[] = { |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1285 | UTEST(test_schema), |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 1286 | UTEST(test_parse_invalid, setup), |
| 1287 | UTEST(test_parse_inline, setup), |
| 1288 | UTEST(test_parse_shared, setup), |
| 1289 | UTEST(test_parse_shared_parent_ref, setup), |
| 1290 | UTEST(test_parse_config, setup), |
tadeas-vintrlik | 2aa36b4 | 2021-11-03 13:07:34 +0100 | [diff] [blame] | 1291 | }; |
| 1292 | |
| 1293 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 1294 | } |