|
3 | 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
4 | 4 | * @brief unit tests for structure extensions support |
5 | 5 | * |
6 | | - * Copyright (c) 2022 - 2025 CESNET, z.s.p.o. |
| 6 | + * Copyright (c) 2022 - 2026 CESNET, z.s.p.o. |
7 | 7 | * |
8 | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
9 | 9 | * You may not use this file except in compliance with the License. |
@@ -339,6 +339,62 @@ test_parse(void **state) |
339 | 339 | LYD_PARSE_STRICT | LYD_PARSE_ANYDATA_STRICT, LYD_VALIDATE_PRESENT, &tree)); |
340 | 340 | CHECK_LOG_CTX("Node \"l2\" not found as a child of \"cont\" node.", |
341 | 341 | "/a:struct/x/struct/x/any/c:cont", 1); |
| 342 | + |
| 343 | + /* patch */ |
| 344 | + ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG); |
| 345 | + assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-yang-patch", NULL, NULL)); |
| 346 | + yang = "module example {yang-version 1.1;namespace \"http://example.tld/example\";prefix ex;" |
| 347 | + " container a {" |
| 348 | + " container b {" |
| 349 | + " container c {" |
| 350 | + " leaf enabled {" |
| 351 | + " type boolean;" |
| 352 | + " default true;" |
| 353 | + " }" |
| 354 | + " leaf blower {" |
| 355 | + " type string;" |
| 356 | + " }" |
| 357 | + " }" |
| 358 | + " }" |
| 359 | + " container b1 { }" |
| 360 | + " leaf something { type string; }" |
| 361 | + " }" |
| 362 | + " container two-leafs {" |
| 363 | + " leaf a { type string; }" |
| 364 | + " leaf b { type string; }" |
| 365 | + " }" |
| 366 | + "}"; |
| 367 | + UTEST_ADD_MODULE(yang, LYS_IN_YANG, NULL, NULL); |
| 368 | + |
| 369 | + json = |
| 370 | + "{\n" |
| 371 | + " \"ietf-yang-patch:yang-patch\": {\n" |
| 372 | + " \"patch-id\": \"patch\",\n" |
| 373 | + " \"edit\": [\n" |
| 374 | + " {\n" |
| 375 | + " \"edit-id\": \"edit\",\n" |
| 376 | + " \"operation\": \"replace\",\n" |
| 377 | + " \"target\": \"/example:a\",\n" |
| 378 | + " \"value\": {\n" |
| 379 | + " \"example:a\": \"aaa\"\n" |
| 380 | + " }\n" |
| 381 | + " },\n" |
| 382 | + " {\n" |
| 383 | + " \"edit-id\": \"edit\",\n" |
| 384 | + " \"operation\": \"replace\",\n" |
| 385 | + " \"target\": \"/example:b\",\n" |
| 386 | + " \"value\": {\n" |
| 387 | + " \"example:b\": \"bbb\"\n" |
| 388 | + " }\n" |
| 389 | + " }\n" |
| 390 | + " ]\n" |
| 391 | + " }\n" |
| 392 | + "}\n"; |
| 393 | + assert_int_equal(LY_SUCCESS, ly_in_new_memory(json, &UTEST_IN)); |
| 394 | + assert_int_equal(LY_SUCCESS, lyd_parse_data(UTEST_LYCTX, NULL, UTEST_IN, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, |
| 395 | + 0, &tree)); |
| 396 | + CHECK_LYD_STRING_PARAM(tree, json, LYD_JSON, LYD_PRINT_SIBLINGS); |
| 397 | + lyd_free_all(tree); |
342 | 398 | } |
343 | 399 |
|
344 | 400 | static void |
|
0 commit comments