aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * @file test_printer_tree.c |
| 3 | * @author: Adam Piecek <piecek@cesnet.cz> |
| 4 | * @brief unit tests for functions from printer_tree.c |
| 5 | * |
| 6 | * Copyright (c) 2019-2021 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | #define _UTEST_MAIN_ |
| 15 | #include "utests.h" |
| 16 | |
| 17 | #include "common.h" |
| 18 | #include "context.h" |
| 19 | #include "out.h" |
| 20 | #include "printer_schema.h" |
| 21 | #include "tree_schema.h" |
| 22 | |
| 23 | #define TEST_LOCAL_SETUP \ |
| 24 | char *printed; \ |
Michal Vasko | 4de7d07 | 2021-07-09 09:13:18 +0200 | [diff] [blame] | 25 | struct lys_module *mod; \ |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 26 | const char *orig; \ |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 27 | const char *expect; \ |
| 28 | assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 29 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 30 | #define TEST_LOCAL_PRINT(MOD, LINE_LENGTH) \ |
| 31 | assert_int_equal(LY_SUCCESS, lys_print_module(UTEST_OUT, MOD, LYS_OUT_TREE, LINE_LENGTH, 0)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 32 | |
| 33 | #define TEST_LOCAL_TEARDOWN \ |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 34 | ly_out_free(UTEST_OUT, NULL, 1); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 35 | |
| 36 | static void |
| 37 | base_sections(void **state) |
| 38 | { |
| 39 | TEST_LOCAL_SETUP; |
Michal Vasko | 4de7d07 | 2021-07-09 09:13:18 +0200 | [diff] [blame] | 40 | struct lys_module *modxx; |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 41 | |
| 42 | orig = |
| 43 | "module a01xx {\n" |
| 44 | " yang-version 1.1;\n" |
| 45 | " namespace \"xx:y\";\n" |
| 46 | " prefix xx;\n" |
| 47 | " container c;\n" |
| 48 | " container d;\n" |
| 49 | "}\n"; |
| 50 | |
aPiecek | 34fa377 | 2021-05-21 12:35:46 +0200 | [diff] [blame] | 51 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &modxx); |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 52 | |
| 53 | /* module with import statement */ |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 54 | orig = |
| 55 | "module a01 {\n" |
| 56 | " yang-version 1.1;\n" |
| 57 | " namespace \"x:y\";\n" |
| 58 | " prefix x;\n" |
| 59 | "\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 60 | " import a01xx {\n" |
| 61 | " prefix xx;\n" |
| 62 | " }\n" |
| 63 | "\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 64 | " grouping g1;\n" |
| 65 | "\n" |
| 66 | " grouping g2;\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 67 | " container g;\n" |
| 68 | " augment \"/xx:c\" {\n" |
| 69 | " container e;\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 70 | " }\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 71 | " augment \"/xx:d\" {\n" |
| 72 | " container f;\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 73 | " }\n" |
| 74 | " rpc rpc1;\n" |
| 75 | " rpc rpc2;\n" |
| 76 | " notification n1;\n" |
| 77 | " notification n2;\n" |
| 78 | "}\n"; |
| 79 | |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 80 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 81 | |
| 82 | /* from pyang */ |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 83 | expect = |
| 84 | "module: a01\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 85 | " +--rw g\n" |
| 86 | "\n" |
| 87 | " augment /xx:c:\n" |
| 88 | " +--rw e\n" |
| 89 | " augment /xx:d:\n" |
| 90 | " +--rw f\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 91 | "\n" |
| 92 | " rpcs:\n" |
| 93 | " +---x rpc1\n" |
| 94 | " +---x rpc2\n" |
| 95 | "\n" |
| 96 | " notifications:\n" |
| 97 | " +---n n1\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 98 | " +---n n2\n" |
| 99 | "\n" |
| 100 | " grouping g1\n" |
| 101 | " grouping g2\n"; |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 102 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 103 | TEST_LOCAL_PRINT(mod, 72); |
| 104 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 105 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 106 | |
| 107 | ly_out_reset(UTEST_OUT); |
| 108 | |
| 109 | /* from pyang */ |
| 110 | expect = |
| 111 | "module: a01\n" |
| 112 | " +--rw g\n" |
| 113 | "\n" |
| 114 | " augment /xx:c:\n" |
| 115 | " +--rw e\n" |
| 116 | " augment /xx:d:\n" |
| 117 | " +--rw f\n" |
| 118 | "\n" |
| 119 | " rpcs:\n" |
| 120 | " +---x rpc1\n" |
| 121 | " +---x rpc2\n" |
| 122 | "\n" |
| 123 | " notifications:\n" |
| 124 | " +---n n1\n" |
| 125 | " +---n n2\n"; |
| 126 | |
| 127 | /* using lysc tree */ |
| 128 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 129 | TEST_LOCAL_PRINT(mod, 72); |
| 130 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 131 | assert_string_equal(printed, expect); |
aPiecek | 34fa377 | 2021-05-21 12:35:46 +0200 | [diff] [blame] | 132 | |
| 133 | ly_out_reset(UTEST_OUT); |
| 134 | |
| 135 | /* from pyang */ |
| 136 | expect = |
| 137 | "module: a01xx\n" |
| 138 | " +--rw c\n" |
| 139 | " | +--rw x:e\n" |
| 140 | " +--rw d\n" |
| 141 | " +--rw x:f\n"; |
| 142 | |
| 143 | TEST_LOCAL_PRINT(modxx, 72); |
| 144 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 145 | assert_string_equal(printed, expect); |
| 146 | |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 147 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 148 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 149 | TEST_LOCAL_TEARDOWN; |
| 150 | } |
| 151 | |
| 152 | static void |
| 153 | node_status(void **state) |
| 154 | { |
| 155 | TEST_LOCAL_SETUP; |
| 156 | orig = |
| 157 | "module a02 {\n" |
| 158 | " yang-version 1.1;\n" |
| 159 | " namespace \"x:y\";\n" |
| 160 | " prefix x;\n" |
| 161 | " container l {\n" |
| 162 | " status current;\n" |
| 163 | " }\n" |
| 164 | " container m {\n" |
| 165 | " status deprecated;\n" |
| 166 | " }\n" |
| 167 | " container n {\n" |
| 168 | " status obsolete;\n" |
| 169 | " }\n" |
| 170 | "}\n"; |
| 171 | |
| 172 | /* from pyang */ |
| 173 | expect = |
| 174 | "module: a02\n" |
| 175 | " +--rw l\n" |
| 176 | " x--rw m\n" |
| 177 | " o--rw n\n"; |
| 178 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 179 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 180 | TEST_LOCAL_PRINT(mod, 72); |
| 181 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 182 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 183 | |
| 184 | ly_out_reset(UTEST_OUT); |
| 185 | /* using lysc tree */ |
| 186 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 187 | TEST_LOCAL_PRINT(mod, 72); |
| 188 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 189 | assert_string_equal(printed, expect); |
| 190 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 191 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 192 | TEST_LOCAL_TEARDOWN; |
| 193 | } |
| 194 | |
| 195 | static void |
| 196 | node_config_flags(void **state) |
| 197 | { |
| 198 | TEST_LOCAL_SETUP; |
| 199 | orig = |
| 200 | "module a03 {\n" |
| 201 | " yang-version 1.1;\n" |
| 202 | " namespace \"x:y\";\n" |
| 203 | " prefix x;\n" |
| 204 | " container l {\n" |
| 205 | " config true;\n" |
| 206 | " }\n" |
| 207 | " container m {\n" |
| 208 | " config false;\n" |
| 209 | " }\n" |
| 210 | "}\n"; |
| 211 | |
| 212 | /* from pyang */ |
| 213 | expect = |
| 214 | "module: a03\n" |
| 215 | " +--rw l\n" |
| 216 | " +--ro m\n"; |
| 217 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 218 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 219 | TEST_LOCAL_PRINT(mod, 72); |
| 220 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 221 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 222 | |
| 223 | ly_out_reset(UTEST_OUT); |
| 224 | /* using lysc tree */ |
| 225 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 226 | TEST_LOCAL_PRINT(mod, 72); |
| 227 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 228 | assert_string_equal(printed, expect); |
| 229 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 230 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 231 | TEST_LOCAL_TEARDOWN; |
| 232 | } |
| 233 | |
| 234 | static void |
| 235 | node_rpcs_flags(void **state) |
| 236 | { |
| 237 | TEST_LOCAL_SETUP; |
| 238 | orig = |
| 239 | "module a04 {\n" |
| 240 | " yang-version 1.1;\n" |
| 241 | " namespace \"x:y\";\n" |
| 242 | " prefix x;\n" |
| 243 | " container cont {\n" |
| 244 | " action rpc1 {\n" |
| 245 | "\n" |
| 246 | " input {\n" |
| 247 | " leaf in {\n" |
| 248 | " type string;\n" |
| 249 | " }\n" |
| 250 | " }\n" |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 251 | "\n" |
| 252 | " output {\n" |
| 253 | " leaf out {\n" |
| 254 | " type string;\n" |
| 255 | " }\n" |
| 256 | " }\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 257 | " }\n" |
| 258 | " }\n" |
| 259 | "}\n"; |
| 260 | |
| 261 | /* from pyang */ |
| 262 | expect = |
| 263 | "module: a04\n" |
| 264 | " +--rw cont\n" |
| 265 | " +---x rpc1\n" |
| 266 | " +---w input\n" |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 267 | " | +---w in? string\n" |
| 268 | " +--ro output\n" |
| 269 | " +--ro out? string\n"; |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 270 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 271 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 272 | TEST_LOCAL_PRINT(mod, 72); |
| 273 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 274 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 275 | |
| 276 | ly_out_reset(UTEST_OUT); |
| 277 | /* using lysc tree */ |
| 278 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 279 | TEST_LOCAL_PRINT(mod, 72); |
| 280 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 281 | assert_string_equal(printed, expect); |
| 282 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 283 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 284 | TEST_LOCAL_TEARDOWN; |
| 285 | } |
| 286 | |
| 287 | static void |
| 288 | node_grouping_flags(void **state) |
| 289 | { |
| 290 | TEST_LOCAL_SETUP; |
| 291 | orig = |
| 292 | "module a05 {\n" |
| 293 | " yang-version 1.1;\n" |
| 294 | " namespace \"x:y\";\n" |
| 295 | " prefix x;\n" |
| 296 | "\n" |
| 297 | " grouping g {\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 298 | " leaf a {\n" |
| 299 | " type string;\n" |
| 300 | " config true;\n" |
| 301 | " }\n" |
| 302 | " leaf b {\n" |
| 303 | " type string;\n" |
| 304 | " config false;\n" |
| 305 | " }\n" |
| 306 | " leaf c {\n" |
| 307 | " type string;\n" |
| 308 | " }\n" |
| 309 | " container d {\n" |
| 310 | " config false;\n" |
| 311 | " leaf e {\n" |
| 312 | " type string;\n" |
| 313 | " }\n" |
| 314 | " }\n" |
| 315 | " container f {\n" |
| 316 | " leaf g {\n" |
| 317 | " type string;\n" |
| 318 | " }\n" |
| 319 | " }\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 320 | " }\n" |
| 321 | " container d {\n" |
| 322 | " uses g;\n" |
| 323 | " }\n" |
| 324 | "}\n"; |
| 325 | |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 326 | /* from yanglint1 */ |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 327 | expect = |
| 328 | "module: a05\n" |
| 329 | " +--rw d\n" |
| 330 | " +---u g\n" |
| 331 | "\n" |
| 332 | " grouping g:\n" |
aPiecek | dc8fd57 | 2021-04-19 10:47:23 +0200 | [diff] [blame] | 333 | " +--rw a? string\n" |
| 334 | " +--ro b? string\n" |
| 335 | " +---- c? string\n" |
| 336 | " +--ro d\n" |
| 337 | " | +--ro e? string\n" |
| 338 | " +---- f\n" |
| 339 | " +---- g? string\n"; |
| 340 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 341 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 342 | TEST_LOCAL_PRINT(mod, 72); |
| 343 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 344 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 345 | |
| 346 | /* from pyang */ |
| 347 | expect = |
| 348 | "module: a05\n" |
| 349 | " +--rw d\n" |
| 350 | " +--rw a? string\n" |
| 351 | " +--ro b? string\n" |
| 352 | " +--rw c? string\n" |
| 353 | " +--ro d\n" |
| 354 | " | +--ro e? string\n" |
| 355 | " +--rw f\n" |
| 356 | " +--rw g? string\n"; |
| 357 | |
| 358 | ly_out_reset(UTEST_OUT); |
| 359 | /* using lysc tree */ |
| 360 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 361 | TEST_LOCAL_PRINT(mod, 72); |
| 362 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 363 | assert_string_equal(printed, expect); |
| 364 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 365 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 366 | TEST_LOCAL_TEARDOWN; |
| 367 | } |
| 368 | |
| 369 | static void |
| 370 | notif_inside_container(void **state) |
| 371 | { |
| 372 | TEST_LOCAL_SETUP; |
| 373 | orig = |
| 374 | "module a06 {\n" |
| 375 | " yang-version 1.1;\n" |
| 376 | " namespace \"x:y\";\n" |
| 377 | " prefix x;\n" |
| 378 | " container c {\n" |
| 379 | " notification notif;\n" |
| 380 | " }\n" |
| 381 | "}\n"; |
| 382 | |
| 383 | /* from pyang */ |
| 384 | expect = |
| 385 | "module: a06\n" |
| 386 | " +--rw c\n" |
| 387 | " +---n notif\n"; |
| 388 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 389 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 390 | TEST_LOCAL_PRINT(mod, 72); |
| 391 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 392 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 393 | |
| 394 | ly_out_reset(UTEST_OUT); |
| 395 | /* using lysc tree */ |
| 396 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 397 | TEST_LOCAL_PRINT(mod, 72); |
| 398 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 399 | assert_string_equal(printed, expect); |
| 400 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 401 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 402 | TEST_LOCAL_TEARDOWN; |
| 403 | } |
| 404 | |
| 405 | static void |
| 406 | node_choice(void **state) |
| 407 | { |
| 408 | TEST_LOCAL_SETUP; |
| 409 | orig = |
| 410 | "module a07 {\n" |
| 411 | " yang-version 1.1;\n" |
| 412 | " namespace \"x:y\";\n" |
| 413 | " prefix x;\n" |
| 414 | " choice my_choice;\n" |
| 415 | "}\n"; |
| 416 | |
| 417 | /* from pyang */ |
| 418 | expect = |
| 419 | "module: a07\n" |
| 420 | " +--rw (my_choice)?\n"; |
| 421 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 422 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 423 | TEST_LOCAL_PRINT(mod, 72); |
| 424 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 425 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 426 | |
| 427 | ly_out_reset(UTEST_OUT); |
| 428 | /* using lysc tree */ |
| 429 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 430 | TEST_LOCAL_PRINT(mod, 72); |
| 431 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 432 | assert_string_equal(printed, expect); |
| 433 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 434 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 435 | TEST_LOCAL_TEARDOWN; |
| 436 | } |
| 437 | |
| 438 | static void |
| 439 | node_case(void **state) |
| 440 | { |
| 441 | TEST_LOCAL_SETUP; |
| 442 | orig = |
| 443 | "module a08 {\n" |
| 444 | " yang-version 1.1;\n" |
| 445 | " namespace \"x:y\";\n" |
| 446 | " prefix x;\n" |
aPiecek | 7a28e2f | 2021-05-21 07:27:03 +0200 | [diff] [blame] | 447 | "\n" |
| 448 | " feature foo;\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 449 | " choice my_choice {\n" |
| 450 | " case my_case;\n" |
| 451 | " }\n" |
aPiecek | 082c7dc | 2021-05-20 08:55:07 +0200 | [diff] [blame] | 452 | " choice shorthand {\n" |
aPiecek | 7a28e2f | 2021-05-21 07:27:03 +0200 | [diff] [blame] | 453 | " container cont1 {\n" |
| 454 | " if-feature \"foo\";\n" |
aPiecek | aa320c9 | 2021-05-21 07:34:24 +0200 | [diff] [blame] | 455 | " status obsolete;\n" |
aPiecek | 7a28e2f | 2021-05-21 07:27:03 +0200 | [diff] [blame] | 456 | " }\n" |
aPiecek | 082c7dc | 2021-05-20 08:55:07 +0200 | [diff] [blame] | 457 | " container cont2 {\n" |
| 458 | " container cont3;\n" |
| 459 | " }\n" |
| 460 | " }\n" |
| 461 | " container top {\n" |
| 462 | " choice shorthand1 {\n" |
| 463 | " container cont1;\n" |
| 464 | " }\n" |
| 465 | " choice shorthand2 {\n" |
| 466 | " container cont2 {\n" |
| 467 | " container cont3;\n" |
| 468 | " }\n" |
| 469 | " }\n" |
| 470 | " }\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 471 | "}\n"; |
| 472 | |
| 473 | /* from pyang */ |
| 474 | expect = |
| 475 | "module: a08\n" |
| 476 | " +--rw (my_choice)?\n" |
aPiecek | 082c7dc | 2021-05-20 08:55:07 +0200 | [diff] [blame] | 477 | " | +--:(my_case)\n" |
| 478 | " +--rw (shorthand)?\n" |
aPiecek | aa320c9 | 2021-05-21 07:34:24 +0200 | [diff] [blame] | 479 | " | o--:(cont1)\n" |
| 480 | " | | o--rw cont1 {foo}?\n" |
aPiecek | 082c7dc | 2021-05-20 08:55:07 +0200 | [diff] [blame] | 481 | " | +--:(cont2)\n" |
| 482 | " | +--rw cont2\n" |
| 483 | " | +--rw cont3\n" |
| 484 | " +--rw top\n" |
| 485 | " +--rw (shorthand1)?\n" |
| 486 | " | +--:(cont1)\n" |
| 487 | " | +--rw cont1\n" |
| 488 | " +--rw (shorthand2)?\n" |
| 489 | " +--:(cont2)\n" |
| 490 | " +--rw cont2\n" |
| 491 | " +--rw cont3\n"; |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 492 | |
aPiecek | 7a28e2f | 2021-05-21 07:27:03 +0200 | [diff] [blame] | 493 | const char *feats[] = {"foo", NULL}; |
| 494 | |
| 495 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 496 | TEST_LOCAL_PRINT(mod, 72); |
| 497 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 498 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 499 | |
| 500 | ly_out_reset(UTEST_OUT); |
| 501 | /* using lysc tree */ |
| 502 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 503 | TEST_LOCAL_PRINT(mod, 72); |
| 504 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 505 | assert_string_equal(printed, expect); |
| 506 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 507 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 508 | TEST_LOCAL_TEARDOWN; |
| 509 | } |
| 510 | |
| 511 | static void |
| 512 | optional_opts(void **state) |
| 513 | { |
| 514 | TEST_LOCAL_SETUP; |
| 515 | /* throws libyang warn: Use of anydata to define configuration data is not recommended... */ |
| 516 | orig = |
| 517 | "module a09 {\n" |
| 518 | " yang-version 1.1;\n" |
| 519 | " namespace \"x:y\";\n" |
| 520 | " prefix x;\n" |
| 521 | " leaf l1 {\n" |
| 522 | " type string;\n" |
| 523 | " mandatory true;\n" |
| 524 | " }\n" |
| 525 | " leaf l2 {\n" |
| 526 | " type string;\n" |
| 527 | " mandatory false;\n" |
| 528 | " }\n" |
| 529 | " choice c1 {\n" |
| 530 | " mandatory true;\n" |
| 531 | " }\n" |
| 532 | " choice c2 {\n" |
| 533 | " mandatory false;\n" |
| 534 | " }\n" |
| 535 | " anydata a1 {\n" |
| 536 | " mandatory true;\n" |
| 537 | " }\n" |
| 538 | " anydata a2 {\n" |
| 539 | " mandatory false;\n" |
| 540 | " }\n" |
| 541 | " anyxml x1 {\n" |
| 542 | " mandatory true;\n" |
| 543 | " }\n" |
| 544 | " anyxml x2 {\n" |
| 545 | " mandatory false;\n" |
| 546 | " }\n" |
| 547 | "}\n"; |
| 548 | |
| 549 | /* from yanglint 1 */ |
| 550 | expect = |
| 551 | "module: a09\n" |
| 552 | " +--rw l1 string\n" |
| 553 | " +--rw l2? string\n" |
| 554 | " +--rw (c1)\n" |
| 555 | " +--rw (c2)?\n" |
| 556 | " +--rw a1 anydata\n" |
| 557 | " +--rw a2? anydata\n" |
| 558 | " +--rw x1 anyxml\n" |
| 559 | " +--rw x2? anyxml\n"; |
| 560 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 561 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 562 | TEST_LOCAL_PRINT(mod, 72); |
| 563 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 564 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 565 | |
| 566 | ly_out_reset(UTEST_OUT); |
| 567 | /* using lysc tree */ |
| 568 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 569 | TEST_LOCAL_PRINT(mod, 72); |
| 570 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 571 | assert_string_equal(printed, expect); |
| 572 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 573 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 574 | TEST_LOCAL_TEARDOWN; |
| 575 | } |
| 576 | |
| 577 | static void |
| 578 | presence_container(void **state) |
| 579 | { |
| 580 | TEST_LOCAL_SETUP; |
| 581 | orig = |
| 582 | "module a10 {\n" |
| 583 | " yang-version 1.1;\n" |
| 584 | " namespace \"x:y\";\n" |
| 585 | " prefix x;\n" |
| 586 | " container c;\n" |
| 587 | " container d {\n" |
| 588 | " presence \"str1\";\n" |
| 589 | " }\n" |
| 590 | "}\n"; |
| 591 | |
| 592 | /* from pyang */ |
| 593 | expect = |
| 594 | "module: a10\n" |
| 595 | " +--rw c\n" |
| 596 | " +--rw d!\n"; |
| 597 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 598 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 599 | TEST_LOCAL_PRINT(mod, 72); |
| 600 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 601 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 602 | |
| 603 | ly_out_reset(UTEST_OUT); |
| 604 | /* using lysc tree */ |
| 605 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 606 | TEST_LOCAL_PRINT(mod, 72); |
| 607 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 608 | assert_string_equal(printed, expect); |
| 609 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 610 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 611 | TEST_LOCAL_TEARDOWN; |
| 612 | } |
| 613 | |
| 614 | static void |
| 615 | node_keys(void **state) |
| 616 | { |
| 617 | TEST_LOCAL_SETUP; |
| 618 | orig = |
| 619 | "module a11 {\n" |
| 620 | " yang-version 1.1;\n" |
| 621 | " namespace \"x:y\";\n" |
| 622 | " prefix x;\n" |
| 623 | " list l1 {\n" |
| 624 | " key \"a\";\n" |
| 625 | " leaf a {\n" |
| 626 | " type string;\n" |
| 627 | " }\n" |
| 628 | " }\n" |
| 629 | " list l2 {\n" |
| 630 | " key \"a b\";\n" |
| 631 | " leaf a {\n" |
| 632 | " type string;\n" |
| 633 | " }\n" |
| 634 | " leaf b {\n" |
| 635 | " type string;\n" |
| 636 | " }\n" |
| 637 | " }\n" |
| 638 | " leaf-list ll {\n" |
| 639 | " type string;\n" |
| 640 | " }\n" |
| 641 | "}\n"; |
| 642 | |
| 643 | /* from pyang */ |
| 644 | expect = |
| 645 | "module: a11\n" |
| 646 | " +--rw l1* [a]\n" |
| 647 | " | +--rw a string\n" |
| 648 | " +--rw l2* [a b]\n" |
| 649 | " | +--rw a string\n" |
| 650 | " | +--rw b string\n" |
| 651 | " +--rw ll* string\n"; |
| 652 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 653 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 654 | TEST_LOCAL_PRINT(mod, 72); |
| 655 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 656 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 657 | |
| 658 | ly_out_reset(UTEST_OUT); |
| 659 | /* using lysc tree */ |
| 660 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 661 | TEST_LOCAL_PRINT(mod, 72); |
| 662 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 663 | assert_string_equal(printed, expect); |
| 664 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 665 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 666 | TEST_LOCAL_TEARDOWN; |
| 667 | } |
| 668 | |
| 669 | static void |
| 670 | node_type_target(void **state) |
| 671 | { |
| 672 | TEST_LOCAL_SETUP; |
| 673 | orig = |
| 674 | "module a12 {\n" |
| 675 | " yang-version 1.1;\n" |
| 676 | " namespace \"x:y\";\n" |
| 677 | " prefix x;\n" |
| 678 | " leaf a {\n" |
| 679 | " type leafref {\n" |
| 680 | " path \"/x:b\";\n" |
| 681 | " }\n" |
| 682 | " }\n" |
| 683 | " leaf b {\n" |
| 684 | " type string;\n" |
| 685 | " }\n" |
| 686 | "}\n"; |
| 687 | |
| 688 | /* from yanglint 1 */ |
| 689 | expect = |
| 690 | "module: a12\n" |
| 691 | " +--rw a? -> /x:b\n" |
| 692 | " +--rw b? string\n"; |
| 693 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 694 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 695 | TEST_LOCAL_PRINT(mod, 72); |
| 696 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 697 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 698 | |
| 699 | ly_out_reset(UTEST_OUT); |
| 700 | /* using lysc tree */ |
| 701 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 702 | TEST_LOCAL_PRINT(mod, 72); |
| 703 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 704 | assert_string_equal(printed, expect); |
| 705 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 706 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 707 | TEST_LOCAL_TEARDOWN; |
| 708 | } |
| 709 | |
| 710 | static void |
| 711 | node_type_leafref(void **state) |
| 712 | { |
| 713 | TEST_LOCAL_SETUP; |
| 714 | orig = |
| 715 | "module a13 {\n" |
| 716 | " yang-version 1.1;\n" |
| 717 | " namespace \"x:y\";\n" |
| 718 | " prefix x;\n" |
| 719 | " leaf pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters {\n" |
| 720 | " type string;\n" |
| 721 | " }\n" |
| 722 | " leaf a {\n" |
| 723 | " type leafref {\n" |
| 724 | " path \"/x:pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters\";\n" |
| 725 | " }\n" |
| 726 | " }\n" |
| 727 | "}\n"; |
| 728 | |
| 729 | /* yanglint --tree-no-leafref-target --tree-line-length=72 */ |
| 730 | expect = |
| 731 | "module: a13\n" |
| 732 | " +--rw pretty-long-identifier-name-which-should-exceed-the-limit-of-72-characters?\n" |
| 733 | " | string\n" |
| 734 | " +--rw a?\n" |
| 735 | " leafref\n"; |
| 736 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 737 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 738 | TEST_LOCAL_PRINT(mod, 72); |
| 739 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 740 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 741 | |
| 742 | ly_out_reset(UTEST_OUT); |
| 743 | /* using lysc tree */ |
| 744 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 745 | TEST_LOCAL_PRINT(mod, 72); |
| 746 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 747 | assert_string_equal(printed, expect); |
| 748 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 749 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 750 | TEST_LOCAL_TEARDOWN; |
| 751 | } |
| 752 | |
| 753 | static void |
| 754 | node_iffeatures(void **state) |
| 755 | { |
| 756 | TEST_LOCAL_SETUP; |
| 757 | orig = |
| 758 | "module a14 {\n" |
| 759 | " yang-version 1.1;\n" |
| 760 | " namespace \"x:y\";\n" |
| 761 | " prefix x;\n" |
| 762 | "\n" |
| 763 | " feature foo;\n" |
| 764 | "\n" |
| 765 | " feature bar;\n" |
| 766 | " container c {\n" |
| 767 | " if-feature \"foo or bar\";\n" |
| 768 | " }\n" |
| 769 | "}\n"; |
| 770 | |
| 771 | /* from pyang */ |
| 772 | expect = |
| 773 | "module: a14\n" |
| 774 | " +--rw c {foo or bar}?\n"; |
| 775 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 776 | const char *feats[] = {"foo", NULL}; |
| 777 | |
| 778 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 779 | TEST_LOCAL_PRINT(mod, 72); |
| 780 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 781 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 782 | |
| 783 | ly_out_reset(UTEST_OUT); |
| 784 | /* using lysc tree */ |
| 785 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 786 | TEST_LOCAL_PRINT(mod, 72); |
| 787 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 788 | assert_string_equal(printed, expect); |
| 789 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 790 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 791 | TEST_LOCAL_TEARDOWN; |
| 792 | } |
| 793 | |
| 794 | static void |
| 795 | indent_wrapper(void **state) |
| 796 | { |
| 797 | TEST_LOCAL_SETUP; |
| 798 | orig = |
| 799 | "module a15 {\n" |
| 800 | " yang-version 1.1;\n" |
| 801 | " namespace \"x:y\";\n" |
| 802 | " prefix x;\n" |
| 803 | " container a {\n" |
| 804 | " container b;\n" |
| 805 | " }\n" |
| 806 | " container c {\n" |
| 807 | " container d {\n" |
| 808 | " container e;\n" |
| 809 | " }\n" |
| 810 | " container f {\n" |
| 811 | " container g;\n" |
| 812 | " }\n" |
| 813 | " }\n" |
| 814 | " container h;\n" |
| 815 | " container i {\n" |
| 816 | " container j;\n" |
| 817 | " container k;\n" |
| 818 | " }\n" |
| 819 | "}\n"; |
| 820 | |
| 821 | /* from pyang */ |
| 822 | expect = |
| 823 | "module: a15\n" |
| 824 | " +--rw a\n" |
| 825 | " | +--rw b\n" |
| 826 | " +--rw c\n" |
| 827 | " | +--rw d\n" |
| 828 | " | | +--rw e\n" |
| 829 | " | +--rw f\n" |
| 830 | " | +--rw g\n" |
| 831 | " +--rw h\n" |
| 832 | " +--rw i\n" |
| 833 | " +--rw j\n" |
| 834 | " +--rw k\n"; |
| 835 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 836 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 837 | TEST_LOCAL_PRINT(mod, 72); |
| 838 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 839 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 840 | |
| 841 | ly_out_reset(UTEST_OUT); |
| 842 | /* using lysc tree */ |
| 843 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 844 | TEST_LOCAL_PRINT(mod, 72); |
| 845 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 846 | assert_string_equal(printed, expect); |
| 847 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 848 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 849 | TEST_LOCAL_TEARDOWN; |
| 850 | } |
| 851 | |
| 852 | static void |
| 853 | line_length_twiddling(void **state) |
| 854 | { |
| 855 | TEST_LOCAL_SETUP; |
| 856 | /* node_fits_tight */ |
| 857 | |
| 858 | orig = |
| 859 | "module a16 {\n" |
| 860 | " yang-version 1.1;\n" |
| 861 | " namespace \"x:y\";\n" |
| 862 | " prefix x;\n" |
| 863 | "\n" |
| 864 | " feature f;\n" |
| 865 | "\n" |
| 866 | " typedef some-long-type {\n" |
| 867 | " type string;\n" |
| 868 | " }\n" |
| 869 | " list my-list-name {\n" |
| 870 | " key \"key\";\n" |
| 871 | " leaf key {\n" |
| 872 | " type string;\n" |
| 873 | " }\n" |
| 874 | " leaf nod-leaf {\n" |
| 875 | " if-feature \"f\";\n" |
| 876 | " type some-long-type;\n" |
| 877 | " }\n" |
| 878 | " leaf nos-leaf {\n" |
| 879 | " if-feature \"f\";\n" |
| 880 | " type int32;\n" |
| 881 | " }\n" |
| 882 | " }\n" |
| 883 | "}\n"; |
| 884 | |
| 885 | /* pyang --tree-line-length 42 */ |
| 886 | expect = |
| 887 | "module: a16\n" |
| 888 | " +--rw my-list-name* [key]\n" |
| 889 | " +--rw key string\n" |
| 890 | " +--rw nod-leaf? some-long-type {f}?\n" |
| 891 | " +--rw nos-leaf? int32 {f}?\n"; |
| 892 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 893 | const char *feats[] = {"f", NULL}; |
| 894 | |
| 895 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 896 | TEST_LOCAL_PRINT(mod, 42); |
| 897 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 898 | assert_string_equal(printed, expect); |
| 899 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 900 | ly_out_reset(UTEST_OUT); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 901 | /* using lysc tree */ |
| 902 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 903 | TEST_LOCAL_PRINT(mod, 42); |
| 904 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 905 | assert_string_equal(printed, expect); |
| 906 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 907 | |
| 908 | ly_out_reset(UTEST_OUT); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 909 | /* break_before_iffeature */ |
| 910 | |
| 911 | /* pyang --tree-line-length 41 */ |
| 912 | expect = |
| 913 | "module: a16\n" |
| 914 | " +--rw my-list-name* [key]\n" |
| 915 | " +--rw key string\n" |
| 916 | " +--rw nod-leaf? some-long-type\n" |
| 917 | " | {f}?\n" |
| 918 | " +--rw nos-leaf? int32 {f}?\n"; |
| 919 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 920 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 921 | TEST_LOCAL_PRINT(mod, 41); |
| 922 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 923 | assert_string_equal(printed, expect); |
| 924 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 925 | ly_out_reset(UTEST_OUT); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 926 | /* using lysc tree */ |
| 927 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 928 | TEST_LOCAL_PRINT(mod, 41); |
| 929 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 930 | assert_string_equal(printed, expect); |
| 931 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 932 | |
| 933 | ly_out_reset(UTEST_OUT); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 934 | /* break_before_type */ |
| 935 | |
| 936 | /* pyang --tree-line-length 29 */ |
| 937 | expect = |
| 938 | "module: a16\n" |
| 939 | " +--rw my-list-name* [key]\n" |
| 940 | " +--rw key string\n" |
| 941 | " +--rw nod-leaf?\n" |
| 942 | " | some-long-type\n" |
| 943 | " | {f}?\n" |
| 944 | " +--rw nos-leaf? int32\n" |
| 945 | " {f}?\n"; |
| 946 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 947 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 948 | TEST_LOCAL_PRINT(mod, 29); |
| 949 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 950 | assert_string_equal(printed, expect); |
| 951 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 952 | ly_out_reset(UTEST_OUT); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 953 | /* using lysc tree */ |
| 954 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 955 | TEST_LOCAL_PRINT(mod, 29); |
| 956 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 957 | assert_string_equal(printed, expect); |
| 958 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 959 | |
| 960 | ly_out_reset(UTEST_OUT); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 961 | /* break_before_keys */ |
| 962 | |
| 963 | /* pyang --tree-line-length 23 */ |
| 964 | expect = |
| 965 | "module: a16\n" |
| 966 | " +--rw my-list-name*\n" |
| 967 | " [key]\n" |
| 968 | " +--rw key\n" |
| 969 | " | string\n" |
| 970 | " +--rw nod-leaf?\n" |
| 971 | " | some-long-type\n" |
| 972 | " | {f}?\n" |
| 973 | " +--rw nos-leaf?\n" |
| 974 | " int32 {f}?\n"; |
| 975 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 976 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 977 | TEST_LOCAL_PRINT(mod, 23); |
| 978 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 979 | assert_string_equal(printed, expect); |
| 980 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 981 | ly_out_reset(UTEST_OUT); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 982 | /* using lysc tree */ |
| 983 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 984 | TEST_LOCAL_PRINT(mod, 23); |
| 985 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 986 | assert_string_equal(printed, expect); |
| 987 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 988 | |
| 989 | ly_out_reset(UTEST_OUT); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 990 | /* every_node_name_is_too_long */ |
| 991 | |
| 992 | /* pyang --tree-line-length 14 */ |
| 993 | expect = |
| 994 | "module: a16\n" |
| 995 | " +--rw my-list-name*\n" |
| 996 | " [key]\n" |
| 997 | " +--rw key\n" |
| 998 | " | string\n" |
| 999 | " +--rw nod-leaf?\n" |
| 1000 | " | some-long-type\n" |
| 1001 | " | {f}?\n" |
| 1002 | " +--rw nos-leaf?\n" |
| 1003 | " int32\n" |
| 1004 | " {f}?\n"; |
| 1005 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1006 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 1007 | TEST_LOCAL_PRINT(mod, 14); |
| 1008 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1009 | assert_string_equal(printed, expect); |
| 1010 | |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1011 | ly_out_reset(UTEST_OUT); |
| 1012 | /* using lysc tree */ |
| 1013 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1014 | TEST_LOCAL_PRINT(mod, 14); |
| 1015 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1016 | assert_string_equal(printed, expect); |
| 1017 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1018 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1019 | TEST_LOCAL_TEARDOWN; |
| 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | break_before_leafref(void **state) |
| 1024 | { |
| 1025 | TEST_LOCAL_SETUP; |
| 1026 | orig = |
| 1027 | "module a17 {\n" |
| 1028 | " yang-version 1.1;\n" |
| 1029 | " namespace \"x:y\";\n" |
| 1030 | " prefix x;\n" |
| 1031 | " leaf e {\n" |
| 1032 | " type string;\n" |
| 1033 | " }\n" |
| 1034 | " leaf abcd {\n" |
| 1035 | " type leafref {\n" |
| 1036 | " path \"/x:e\";\n" |
| 1037 | " }\n" |
| 1038 | " }\n" |
| 1039 | "}\n"; |
| 1040 | |
| 1041 | /* yanglint --tree-line-length 14 */ |
| 1042 | expect = |
| 1043 | "module: a17\n" |
| 1044 | " +--rw e?\n" |
| 1045 | " | string\n" |
| 1046 | " +--rw abcd?\n" |
| 1047 | " -> /x:e\n"; |
| 1048 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1049 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1050 | TEST_LOCAL_PRINT(mod, 14); |
| 1051 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1052 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1053 | |
| 1054 | ly_out_reset(UTEST_OUT); |
| 1055 | /* using lysc tree */ |
| 1056 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1057 | TEST_LOCAL_PRINT(mod, 14); |
| 1058 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1059 | assert_string_equal(printed, expect); |
| 1060 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1061 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1062 | TEST_LOCAL_TEARDOWN; |
| 1063 | } |
| 1064 | |
| 1065 | static void |
| 1066 | break_before_leafref_and_iffeature(void **state) |
| 1067 | { |
| 1068 | TEST_LOCAL_SETUP; |
| 1069 | orig = |
| 1070 | "module a18 {\n" |
| 1071 | " yang-version 1.1;\n" |
| 1072 | " namespace \"x:y\";\n" |
| 1073 | " prefix x;\n" |
| 1074 | "\n" |
| 1075 | " feature f;\n" |
| 1076 | " leaf some-long-id {\n" |
| 1077 | " type string;\n" |
| 1078 | " }\n" |
| 1079 | " leaf a {\n" |
| 1080 | " if-feature \"f\";\n" |
| 1081 | " type leafref {\n" |
| 1082 | " path \"/x:some-long-id\";\n" |
| 1083 | " }\n" |
| 1084 | " }\n" |
| 1085 | "}\n"; |
| 1086 | |
| 1087 | /* yanglint --tree-no-leafref-target --tree-line-length=20 */ |
| 1088 | expect = |
| 1089 | "module: a18\n" |
| 1090 | " +--rw some-long-id?\n" |
| 1091 | " | string\n" |
| 1092 | " +--rw a?\n" |
| 1093 | " leafref\n" |
| 1094 | " {f}?\n"; |
| 1095 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1096 | const char *feats[] = {"f", NULL}; |
| 1097 | |
| 1098 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, feats, &mod); |
| 1099 | TEST_LOCAL_PRINT(mod, 20); |
| 1100 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1101 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1102 | |
| 1103 | ly_out_reset(UTEST_OUT); |
| 1104 | /* using lysc tree */ |
| 1105 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1106 | TEST_LOCAL_PRINT(mod, 20); |
| 1107 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1108 | assert_string_equal(printed, expect); |
| 1109 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1110 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1111 | TEST_LOCAL_TEARDOWN; |
| 1112 | } |
| 1113 | |
| 1114 | static void |
| 1115 | basic_unified_indent_before_type(void **state) |
| 1116 | { |
| 1117 | TEST_LOCAL_SETUP; |
| 1118 | orig = |
| 1119 | "module a19 {\n" |
| 1120 | " yang-version 1.1;\n" |
| 1121 | " namespace \"x:y\";\n" |
| 1122 | " prefix x;\n" |
| 1123 | "\n" |
| 1124 | " typedef longType {\n" |
| 1125 | " type string;\n" |
| 1126 | " }\n" |
| 1127 | " container A {\n" |
| 1128 | " leaf Bnode {\n" |
| 1129 | " type int8;\n" |
| 1130 | " }\n" |
| 1131 | " leaf Cnode {\n" |
| 1132 | " type int8;\n" |
| 1133 | " mandatory true;\n" |
| 1134 | " }\n" |
| 1135 | " leaf Dnode {\n" |
| 1136 | " type int8;\n" |
| 1137 | " mandatory true;\n" |
| 1138 | " }\n" |
| 1139 | " leaf E {\n" |
| 1140 | " type longType;\n" |
| 1141 | " mandatory true;\n" |
| 1142 | " }\n" |
| 1143 | " leaf G {\n" |
| 1144 | " type int8;\n" |
| 1145 | " }\n" |
| 1146 | " }\n" |
| 1147 | "}\n"; |
| 1148 | |
| 1149 | /* from pyang */ |
| 1150 | expect = |
| 1151 | "module: a19\n" |
| 1152 | " +--rw A\n" |
| 1153 | " +--rw Bnode? int8\n" |
| 1154 | " +--rw Cnode int8\n" |
| 1155 | " +--rw Dnode int8\n" |
| 1156 | " +--rw E longType\n" |
| 1157 | " +--rw G? int8\n"; |
| 1158 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1159 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1160 | TEST_LOCAL_PRINT(mod, 72); |
| 1161 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1162 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1163 | |
| 1164 | ly_out_reset(UTEST_OUT); |
| 1165 | /* using lysc tree */ |
| 1166 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1167 | TEST_LOCAL_PRINT(mod, 72); |
| 1168 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1169 | assert_string_equal(printed, expect); |
| 1170 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1171 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1172 | TEST_LOCAL_TEARDOWN; |
| 1173 | } |
| 1174 | |
| 1175 | static void |
| 1176 | twiddling_unified_indent_before_type(void **state) |
| 1177 | { |
| 1178 | TEST_LOCAL_SETUP; |
| 1179 | /* basic_functionality */ |
| 1180 | |
| 1181 | orig = |
| 1182 | "module a20 {\n" |
| 1183 | " yang-version 1.1;\n" |
| 1184 | " namespace \"x:y\";\n" |
| 1185 | " prefix x;\n" |
| 1186 | "\n" |
| 1187 | " typedef longType {\n" |
| 1188 | " type string;\n" |
| 1189 | " }\n" |
| 1190 | " container A {\n" |
| 1191 | " leaf Bnode {\n" |
| 1192 | " type int8;\n" |
| 1193 | " }\n" |
| 1194 | " leaf CnodeIsBigger {\n" |
| 1195 | " type int8;\n" |
| 1196 | " mandatory true;\n" |
| 1197 | " }\n" |
| 1198 | " leaf Dnode {\n" |
| 1199 | " type int8;\n" |
| 1200 | " mandatory true;\n" |
| 1201 | " }\n" |
| 1202 | " leaf E {\n" |
| 1203 | " type longType;\n" |
| 1204 | " mandatory true;\n" |
| 1205 | " }\n" |
| 1206 | " leaf G {\n" |
| 1207 | " type int8;\n" |
| 1208 | " }\n" |
| 1209 | " }\n" |
| 1210 | "}\n"; |
| 1211 | |
| 1212 | /* pyang --tree-line-length 36 */ |
| 1213 | expect = |
| 1214 | "module: a20\n" |
| 1215 | " +--rw A\n" |
| 1216 | " +--rw Bnode? int8\n" |
| 1217 | " +--rw CnodeIsBigger int8\n" |
| 1218 | " +--rw Dnode int8\n" |
| 1219 | " +--rw E longType\n" |
| 1220 | " +--rw G? int8\n"; |
| 1221 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1222 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1223 | TEST_LOCAL_PRINT(mod, 36); |
| 1224 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1225 | assert_string_equal(printed, expect); |
| 1226 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1227 | ly_out_reset(UTEST_OUT); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1228 | /* using lysc tree */ |
| 1229 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1230 | TEST_LOCAL_PRINT(mod, 36); |
| 1231 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1232 | assert_string_equal(printed, expect); |
| 1233 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1234 | |
| 1235 | ly_out_reset(UTEST_OUT); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1236 | /* unified_indent_before_type_long_node_name */ |
| 1237 | |
| 1238 | /* pyang --tree-line-length 32 */ |
| 1239 | expect = |
| 1240 | "module: a20\n" |
| 1241 | " +--rw A\n" |
| 1242 | " +--rw Bnode? int8\n" |
| 1243 | " +--rw CnodeIsBigger int8\n" |
| 1244 | " +--rw Dnode int8\n" |
| 1245 | " +--rw E\n" |
| 1246 | " | longType\n" |
| 1247 | " +--rw G? int8\n"; |
| 1248 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1249 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1250 | TEST_LOCAL_PRINT(mod, 32); |
| 1251 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1252 | assert_string_equal(printed, expect); |
| 1253 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1254 | ly_out_reset(UTEST_OUT); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1255 | /* using lysc tree */ |
| 1256 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1257 | TEST_LOCAL_PRINT(mod, 32); |
| 1258 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1259 | assert_string_equal(printed, expect); |
| 1260 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1261 | |
| 1262 | ly_out_reset(UTEST_OUT); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1263 | /* unified_indent_before_type_long_node_type */ |
| 1264 | |
| 1265 | /* pyang --tree-line-length 31 */ |
| 1266 | expect = |
| 1267 | "module: a20\n" |
| 1268 | " +--rw A\n" |
| 1269 | " +--rw Bnode?\n" |
| 1270 | " | int8\n" |
| 1271 | " +--rw CnodeIsBigger\n" |
| 1272 | " | int8\n" |
| 1273 | " +--rw Dnode\n" |
| 1274 | " | int8\n" |
| 1275 | " +--rw E\n" |
| 1276 | " | longType\n" |
| 1277 | " +--rw G?\n" |
| 1278 | " int8\n"; |
| 1279 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1280 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1281 | TEST_LOCAL_PRINT(mod, 31); |
| 1282 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1283 | assert_string_equal(printed, expect); |
| 1284 | |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1285 | ly_out_reset(UTEST_OUT); |
| 1286 | /* using lysc tree */ |
| 1287 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1288 | TEST_LOCAL_PRINT(mod, 31); |
| 1289 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1290 | assert_string_equal(printed, expect); |
| 1291 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1292 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1293 | TEST_LOCAL_TEARDOWN; |
| 1294 | } |
| 1295 | |
| 1296 | static void |
| 1297 | inheritance_of_config_flag(void **state) |
| 1298 | { |
| 1299 | TEST_LOCAL_SETUP; |
| 1300 | orig = |
| 1301 | "module a21 {\n" |
| 1302 | " yang-version 1.1;\n" |
| 1303 | " namespace \"x:y\";\n" |
| 1304 | " prefix x;\n" |
| 1305 | " container a {\n" |
| 1306 | " config false;\n" |
| 1307 | " leaf b {\n" |
| 1308 | " type string;\n" |
| 1309 | " }\n" |
| 1310 | " }\n" |
| 1311 | "}\n"; |
| 1312 | |
| 1313 | /* from pyang */ |
| 1314 | expect = |
| 1315 | "module: a21\n" |
| 1316 | " +--ro a\n" |
| 1317 | " +--ro b? string\n"; |
| 1318 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1319 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1320 | TEST_LOCAL_PRINT(mod, 72); |
| 1321 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1322 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1323 | |
| 1324 | ly_out_reset(UTEST_OUT); |
| 1325 | /* using lysc tree */ |
| 1326 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1327 | TEST_LOCAL_PRINT(mod, 72); |
| 1328 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1329 | assert_string_equal(printed, expect); |
| 1330 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1331 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1332 | TEST_LOCAL_TEARDOWN; |
| 1333 | } |
| 1334 | |
| 1335 | static void |
| 1336 | inheritance_of_status_flag(void **state) |
| 1337 | { |
| 1338 | TEST_LOCAL_SETUP; |
| 1339 | /* throws libyang warn: Missing explicit "..." status that was already specified in parent, inheriting. */ |
| 1340 | orig = |
| 1341 | "module a22 {\n" |
| 1342 | " yang-version 1.1;\n" |
| 1343 | " namespace \"x:y\";\n" |
| 1344 | " prefix x;\n" |
| 1345 | " container a {\n" |
| 1346 | " status current;\n" |
| 1347 | " container b {\n" |
| 1348 | " status deprecated;\n" |
| 1349 | " leaf f {\n" |
| 1350 | " type string;\n" |
| 1351 | " }\n" |
| 1352 | " }\n" |
| 1353 | " container c {\n" |
| 1354 | " status obsolete;\n" |
| 1355 | " leaf g {\n" |
| 1356 | " type string;\n" |
| 1357 | " }\n" |
| 1358 | " }\n" |
| 1359 | " }\n" |
| 1360 | " container d {\n" |
| 1361 | " status deprecated;\n" |
| 1362 | " container h {\n" |
| 1363 | " status obsolete;\n" |
| 1364 | " leaf e {\n" |
| 1365 | " type string;\n" |
| 1366 | " }\n" |
| 1367 | " }\n" |
| 1368 | " }\n" |
| 1369 | "}\n"; |
| 1370 | |
| 1371 | /* from yanglint 1 */ |
| 1372 | expect = |
| 1373 | "module: a22\n" |
| 1374 | " +--rw a\n" |
| 1375 | " | x--rw b\n" |
| 1376 | " | | x--rw f? string\n" |
| 1377 | " | o--rw c\n" |
| 1378 | " | o--rw g? string\n" |
| 1379 | " x--rw d\n" |
| 1380 | " o--rw h\n" |
| 1381 | " o--rw e? string\n"; |
| 1382 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1383 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1384 | TEST_LOCAL_PRINT(mod, 72); |
| 1385 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1386 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1387 | |
| 1388 | ly_out_reset(UTEST_OUT); |
| 1389 | /* using lysc tree */ |
| 1390 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1391 | TEST_LOCAL_PRINT(mod, 72); |
| 1392 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1393 | assert_string_equal(printed, expect); |
| 1394 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1395 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1396 | TEST_LOCAL_TEARDOWN; |
| 1397 | } |
| 1398 | |
| 1399 | static void |
| 1400 | key_leaf_is_always_mandatory_true(void **state) |
| 1401 | { |
| 1402 | TEST_LOCAL_SETUP; |
| 1403 | orig = |
| 1404 | "module a23 {\n" |
| 1405 | " yang-version 1.1;\n" |
| 1406 | " namespace \"x:y\";\n" |
| 1407 | " prefix x;\n" |
| 1408 | " list a {\n" |
| 1409 | " key \"k1\";\n" |
| 1410 | " list b {\n" |
| 1411 | " key \"k2\";\n" |
| 1412 | " leaf k1 {\n" |
| 1413 | " type string;\n" |
| 1414 | " }\n" |
| 1415 | " leaf k2 {\n" |
| 1416 | " type string;\n" |
| 1417 | " }\n" |
| 1418 | " }\n" |
| 1419 | " leaf k1 {\n" |
| 1420 | " type string;\n" |
| 1421 | " }\n" |
| 1422 | " }\n" |
| 1423 | "}\n"; |
| 1424 | |
| 1425 | /* from pyang */ |
| 1426 | expect = |
| 1427 | "module: a23\n" |
| 1428 | " +--rw a* [k1]\n" |
| 1429 | " +--rw b* [k2]\n" |
| 1430 | " | +--rw k1? string\n" |
| 1431 | " | +--rw k2 string\n" |
| 1432 | " +--rw k1 string\n"; |
| 1433 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1434 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1435 | TEST_LOCAL_PRINT(mod, 72); |
| 1436 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1437 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1438 | |
| 1439 | ly_out_reset(UTEST_OUT); |
| 1440 | |
| 1441 | /* from pyang but with some swapped lines */ |
| 1442 | expect = |
| 1443 | "module: a23\n" |
| 1444 | " +--rw a* [k1]\n" |
| 1445 | " +--rw k1 string\n" |
| 1446 | " +--rw b* [k2]\n" |
| 1447 | " +--rw k2 string\n" |
| 1448 | " +--rw k1? string\n"; |
| 1449 | |
| 1450 | /* using lysc tree */ |
| 1451 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1452 | TEST_LOCAL_PRINT(mod, 72); |
| 1453 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1454 | assert_string_equal(printed, expect); |
| 1455 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1456 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1457 | TEST_LOCAL_TEARDOWN; |
| 1458 | } |
| 1459 | |
| 1460 | static void |
| 1461 | transition_between_rpc_and_notif(void **state) |
| 1462 | { |
| 1463 | TEST_LOCAL_SETUP; |
| 1464 | orig = |
| 1465 | "module a24 {\n" |
| 1466 | " yang-version 1.1;\n" |
| 1467 | " namespace \"x:y\";\n" |
| 1468 | " prefix x;\n" |
| 1469 | " container top {\n" |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1470 | " leaf g {\n" |
| 1471 | " type string;\n" |
| 1472 | " }\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1473 | " action rpc1 {\n" |
| 1474 | "\n" |
| 1475 | " input {\n" |
| 1476 | " leaf in {\n" |
| 1477 | " type string;\n" |
| 1478 | " }\n" |
| 1479 | " }\n" |
| 1480 | " }\n" |
| 1481 | " action rpc2 {\n" |
| 1482 | "\n" |
| 1483 | " input {\n" |
| 1484 | " leaf in {\n" |
| 1485 | " type string;\n" |
| 1486 | " }\n" |
| 1487 | " }\n" |
| 1488 | "\n" |
| 1489 | " output {\n" |
| 1490 | " leaf out {\n" |
| 1491 | " type string;\n" |
| 1492 | " }\n" |
| 1493 | " }\n" |
| 1494 | " }\n" |
| 1495 | " notification n1;\n" |
| 1496 | " notification n2;\n" |
| 1497 | " }\n" |
| 1498 | "}\n"; |
| 1499 | |
aPiecek | b352de7 | 2021-05-21 09:04:04 +0200 | [diff] [blame] | 1500 | /* from pyang */ |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1501 | expect = |
| 1502 | "module: a24\n" |
| 1503 | " +--rw top\n" |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1504 | " +--rw g? string\n" |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1505 | " +---x rpc1\n" |
| 1506 | " | +---w input\n" |
| 1507 | " | +---w in? string\n" |
| 1508 | " +---x rpc2\n" |
| 1509 | " | +---w input\n" |
| 1510 | " | | +---w in? string\n" |
| 1511 | " | +--ro output\n" |
| 1512 | " | +--ro out? string\n" |
| 1513 | " +---n n1\n" |
| 1514 | " +---n n2\n"; |
| 1515 | |
aPiecek | e376b92 | 2021-04-19 08:08:14 +0200 | [diff] [blame] | 1516 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1517 | TEST_LOCAL_PRINT(mod, 72); |
| 1518 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1519 | assert_string_equal(printed, expect); |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 1520 | |
| 1521 | ly_out_reset(UTEST_OUT); |
| 1522 | /* using lysc tree */ |
| 1523 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1524 | TEST_LOCAL_PRINT(mod, 72); |
| 1525 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1526 | assert_string_equal(printed, expect); |
| 1527 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1528 | |
| 1529 | TEST_LOCAL_TEARDOWN; |
| 1530 | } |
| 1531 | |
| 1532 | static void |
| 1533 | local_augment(void **state) |
| 1534 | { |
| 1535 | TEST_LOCAL_SETUP; |
| 1536 | |
| 1537 | orig = |
| 1538 | "module a25 {\n" |
| 1539 | " yang-version 1.1;\n" |
| 1540 | " namespace \"x:y\";\n" |
| 1541 | " prefix x;\n" |
| 1542 | " container g;\n" |
| 1543 | " augment \"/x:g\" {\n" |
| 1544 | " container e;\n" |
| 1545 | " }\n" |
| 1546 | "}\n"; |
| 1547 | |
| 1548 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1549 | |
| 1550 | /* from pyang */ |
| 1551 | expect = |
| 1552 | "module: a25\n" |
| 1553 | " +--rw g\n" |
| 1554 | " +--rw e\n"; |
| 1555 | |
| 1556 | /* using lysc tree */ |
| 1557 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1558 | TEST_LOCAL_PRINT(mod, 72); |
| 1559 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1560 | assert_string_equal(printed, expect); |
| 1561 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1562 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 1563 | TEST_LOCAL_TEARDOWN; |
| 1564 | } |
| 1565 | |
aPiecek | 7745b28 | 2021-04-20 13:54:52 +0200 | [diff] [blame] | 1566 | static void |
| 1567 | print_compiled_node(void **state) |
| 1568 | { |
| 1569 | TEST_LOCAL_SETUP; |
| 1570 | const struct lysc_node *node; |
| 1571 | |
| 1572 | orig = |
| 1573 | "module a26 {\n" |
| 1574 | " yang-version 1.1;\n" |
| 1575 | " namespace \"x:y\";\n" |
| 1576 | " prefix x;\n" |
aPiecek | fa3f687 | 2023-03-29 11:33:32 +0200 | [diff] [blame^] | 1577 | "\n" |
aPiecek | 7745b28 | 2021-04-20 13:54:52 +0200 | [diff] [blame] | 1578 | " container g {\n" |
| 1579 | " leaf a {\n" |
| 1580 | " type string;\n" |
| 1581 | " }\n" |
| 1582 | " container h {\n" |
| 1583 | " leaf b {\n" |
| 1584 | " type string;\n" |
| 1585 | " mandatory true;\n" |
| 1586 | " }\n" |
| 1587 | " leaf c {\n" |
| 1588 | " type string;\n" |
| 1589 | " }\n" |
aPiecek | fa3f687 | 2023-03-29 11:33:32 +0200 | [diff] [blame^] | 1590 | " list l {\n" |
| 1591 | " key \"ip\";\n" |
| 1592 | " leaf ip {\n" |
| 1593 | " type string;\n" |
| 1594 | " }\n" |
| 1595 | " }\n" |
aPiecek | 7745b28 | 2021-04-20 13:54:52 +0200 | [diff] [blame] | 1596 | " }\n" |
| 1597 | " }\n" |
| 1598 | "}\n"; |
| 1599 | |
| 1600 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1601 | |
| 1602 | /* pyang -f tree --tree-path /g/h/c */ |
| 1603 | expect = |
| 1604 | "module: a26\n" |
| 1605 | " +--rw g\n" |
| 1606 | " +--rw h\n" |
| 1607 | " +--rw c? string\n"; |
| 1608 | |
| 1609 | /* using lysc tree */ |
| 1610 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1611 | |
| 1612 | node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h/c", 0); |
| 1613 | CHECK_POINTER(node, 1); |
| 1614 | assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0)); |
| 1615 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1616 | assert_string_equal(printed, expect); |
| 1617 | |
| 1618 | ly_out_reset(UTEST_OUT); |
| 1619 | |
aPiecek | fa3f687 | 2023-03-29 11:33:32 +0200 | [diff] [blame^] | 1620 | /* pyang -f tree --tree-path /g/h/l */ |
| 1621 | expect = |
| 1622 | "module: a26\n" |
| 1623 | " +--rw g\n" |
| 1624 | " +--rw h\n" |
| 1625 | " +--rw l* [ip]\n" |
| 1626 | " +--rw ip string\n"; |
| 1627 | |
| 1628 | node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h/l", 0); |
| 1629 | CHECK_POINTER(node, 1); |
| 1630 | assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0)); |
| 1631 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1632 | assert_string_equal(printed, expect); |
| 1633 | |
| 1634 | ly_out_reset(UTEST_OUT); |
| 1635 | |
aPiecek | 7745b28 | 2021-04-20 13:54:52 +0200 | [diff] [blame] | 1636 | /* pyang -f tree --tree-path /g/h */ |
| 1637 | expect = |
| 1638 | "module: a26\n" |
| 1639 | " +--rw g\n" |
| 1640 | " +--rw h\n" |
| 1641 | " +--rw b string\n" |
aPiecek | fa3f687 | 2023-03-29 11:33:32 +0200 | [diff] [blame^] | 1642 | " +--rw c? string\n" |
| 1643 | " +--rw l* [ip]\n" |
| 1644 | " +--rw ip string\n"; |
aPiecek | 7745b28 | 2021-04-20 13:54:52 +0200 | [diff] [blame] | 1645 | |
| 1646 | node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0); |
| 1647 | CHECK_POINTER(node, 1); |
| 1648 | assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, 0)); |
| 1649 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1650 | assert_string_equal(printed, expect); |
| 1651 | |
| 1652 | ly_out_reset(UTEST_OUT); |
| 1653 | |
| 1654 | /* pyang whose output is adjusted manually */ |
| 1655 | expect = |
| 1656 | "module: a26\n" |
| 1657 | " +--rw g\n" |
| 1658 | " +--rw h\n"; |
| 1659 | |
| 1660 | node = lys_find_path(UTEST_LYCTX, NULL, "/a26:g/h", 0); |
| 1661 | CHECK_POINTER(node, 1); |
| 1662 | assert_int_equal(LY_SUCCESS, lys_print_node(UTEST_OUT, node, LYS_OUT_TREE, 72, LYS_PRINT_NO_SUBSTMT)); |
| 1663 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1664 | assert_string_equal(printed, expect); |
| 1665 | |
| 1666 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1667 | |
| 1668 | TEST_LOCAL_TEARDOWN; |
| 1669 | } |
| 1670 | |
aPiecek | aecf751 | 2021-04-21 08:34:35 +0200 | [diff] [blame] | 1671 | static LY_ERR |
| 1672 | local_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name), |
| 1673 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 1674 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 1675 | { |
| 1676 | *module_data = user_data; |
| 1677 | *format = LYS_IN_YANG; |
| 1678 | *free_module_data = NULL; |
| 1679 | return LY_SUCCESS; |
| 1680 | } |
| 1681 | |
| 1682 | static void |
| 1683 | print_parsed_submodule(void **state) |
| 1684 | { |
| 1685 | TEST_LOCAL_SETUP; |
| 1686 | |
| 1687 | orig = "module a27 {\n" |
| 1688 | " yang-version 1.1;\n" |
| 1689 | " namespace \"x:y\";\n" |
| 1690 | " prefix x;\n" |
| 1691 | "\n" |
| 1692 | " include \"a27-sub\";\n" |
| 1693 | "}\n"; |
| 1694 | |
| 1695 | char *submodule = |
| 1696 | "submodule a27-sub {\n" |
| 1697 | " yang-version 1.1;\n" |
| 1698 | " belongs-to a27 {\n" |
| 1699 | " prefix x;\n" |
| 1700 | " }\n" |
| 1701 | "\n" |
| 1702 | " container h {\n" |
| 1703 | " leaf b {\n" |
| 1704 | " type string;\n" |
| 1705 | " }\n" |
| 1706 | " }\n" |
| 1707 | "}\n"; |
| 1708 | |
| 1709 | /* edited pyang output */ |
| 1710 | expect = |
| 1711 | "submodule: a27-sub\n" |
| 1712 | " +--rw h\n" |
| 1713 | " +--rw b? string\n"; |
| 1714 | |
| 1715 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, local_imp_clb, submodule); |
| 1716 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1717 | assert_int_equal(LY_SUCCESS, lys_print_submodule(UTEST_OUT, mod->parsed->includes[0].submodule, LYS_OUT_TREE, 72, 0)); |
| 1718 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1719 | assert_string_equal(printed, expect); |
| 1720 | |
| 1721 | TEST_LOCAL_TEARDOWN; |
| 1722 | } |
| 1723 | |
aPiecek | b8e43f1 | 2021-04-23 12:52:22 +0200 | [diff] [blame] | 1724 | static void |
| 1725 | yang_data(void **state) |
| 1726 | { |
| 1727 | TEST_LOCAL_SETUP; |
| 1728 | |
| 1729 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG)); |
| 1730 | assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-restconf", "2017-01-26", NULL)); |
| 1731 | |
| 1732 | orig = |
| 1733 | "module a28 {\n" |
| 1734 | " yang-version 1.1;\n" |
| 1735 | " namespace \"x:y\";\n" |
| 1736 | " prefix x;\n" |
| 1737 | "\n" |
| 1738 | " import ietf-restconf {\n" |
| 1739 | " prefix rc;\n" |
| 1740 | " revision-date 2017-01-26;\n" |
| 1741 | " }\n" |
| 1742 | "\n" |
| 1743 | " rc:yang-data \"tmp1\" {\n" |
| 1744 | " container cont1 {\n" |
| 1745 | " leaf lf {\n" |
| 1746 | " type string;\n" |
| 1747 | " }\n" |
| 1748 | " list l2 {\n" |
| 1749 | " key\n" |
| 1750 | " \"a b\";\n" |
| 1751 | " leaf a {\n" |
| 1752 | " type string;\n" |
| 1753 | " }\n" |
| 1754 | " leaf b {\n" |
| 1755 | " type string;\n" |
| 1756 | " }\n" |
| 1757 | " }\n" |
| 1758 | " }\n" |
| 1759 | " }\n" |
| 1760 | " rc:yang-data \"tmp2\" {\n" |
| 1761 | " container con2 {\n" |
| 1762 | " leaf lf {\n" |
| 1763 | " type string;\n" |
| 1764 | " }\n" |
| 1765 | " }\n" |
| 1766 | " }\n" |
| 1767 | " rc:yang-data \"tmp3\" {\n" |
| 1768 | " uses g1;\n" |
| 1769 | " uses g2;\n" |
| 1770 | " }\n" |
| 1771 | " rc:yang-data \"tmp4\" {\n" |
| 1772 | " choice x {\n" |
| 1773 | " case a {\n" |
| 1774 | " container z;\n" |
| 1775 | " }\n" |
| 1776 | " case b {\n" |
| 1777 | " container y;\n" |
| 1778 | " }\n" |
| 1779 | " }\n" |
| 1780 | " }\n" |
| 1781 | "\n" |
| 1782 | " grouping g1 {\n" |
| 1783 | " description\n" |
| 1784 | " \"Some Text\";\n" |
| 1785 | " }\n" |
| 1786 | "\n" |
| 1787 | " grouping g2 {\n" |
| 1788 | " container cont3;\n" |
| 1789 | " }\n" |
| 1790 | " container mont;\n" |
| 1791 | "}\n"; |
| 1792 | |
aPiecek | b352de7 | 2021-05-21 09:04:04 +0200 | [diff] [blame] | 1793 | /* from pyang (--tree-print-yang-data --tree-print-groupings -p "...") |
| 1794 | * but with these adjustments: |
aPiecek | b8e43f1 | 2021-04-23 12:52:22 +0200 | [diff] [blame] | 1795 | * - <flags> is always '--' for yang-data nodes |
| 1796 | * - yang-data tmp3 has two 'uses' nodes |
| 1797 | * - grouping g2 has ':' character at the end |
| 1798 | */ |
| 1799 | expect = |
| 1800 | "module: a28\n" |
| 1801 | " +--rw mont\n" |
| 1802 | "\n" |
| 1803 | " grouping g1\n" |
| 1804 | " grouping g2:\n" |
| 1805 | " +---- cont3\n" |
| 1806 | "\n" |
| 1807 | " yang-data tmp1:\n" |
| 1808 | " +---- cont1\n" |
| 1809 | " +---- lf? string\n" |
| 1810 | " +---- l2* [a b]\n" |
| 1811 | " +---- a string\n" |
| 1812 | " +---- b string\n" |
| 1813 | " yang-data tmp2:\n" |
| 1814 | " +---- con2\n" |
| 1815 | " +---- lf? string\n" |
| 1816 | " yang-data tmp3:\n" |
| 1817 | " +---u g1\n" |
| 1818 | " +---u g2\n" |
| 1819 | " yang-data tmp4:\n" |
| 1820 | " +---- (x)?\n" |
| 1821 | " +--:(a)\n" |
| 1822 | " | +---- z\n" |
| 1823 | " +--:(b)\n" |
| 1824 | " +---- y\n"; |
| 1825 | |
| 1826 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1827 | TEST_LOCAL_PRINT(mod, 72); |
| 1828 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1829 | assert_string_equal(printed, expect); |
| 1830 | |
| 1831 | ly_out_reset(UTEST_OUT); |
| 1832 | |
aPiecek | b352de7 | 2021-05-21 09:04:04 +0200 | [diff] [blame] | 1833 | /* from pyang (--tree-print-yang-data -p "...") |
| 1834 | * but with these adjustments: |
aPiecek | b8e43f1 | 2021-04-23 12:52:22 +0200 | [diff] [blame] | 1835 | * <flags> is always '--' for yang-data nodes |
| 1836 | */ |
| 1837 | expect = |
| 1838 | "module: a28\n" |
| 1839 | " +--rw mont\n" |
| 1840 | "\n" |
| 1841 | " yang-data tmp1:\n" |
| 1842 | " +---- cont1\n" |
| 1843 | " +---- lf? string\n" |
| 1844 | " +---- l2* [a b]\n" |
| 1845 | " +---- a string\n" |
| 1846 | " +---- b string\n" |
| 1847 | " yang-data tmp2:\n" |
| 1848 | " +---- con2\n" |
| 1849 | " +---- lf? string\n" |
| 1850 | " yang-data tmp3:\n" |
| 1851 | " +---- cont3\n" |
| 1852 | " yang-data tmp4:\n" |
| 1853 | " +---- (x)?\n" |
| 1854 | " +--:(a)\n" |
| 1855 | " | +---- z\n" |
| 1856 | " +--:(b)\n" |
| 1857 | " +---- y\n"; |
| 1858 | |
| 1859 | /* using lysc tree */ |
| 1860 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1861 | TEST_LOCAL_PRINT(mod, 72); |
| 1862 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1863 | assert_string_equal(printed, expect); |
| 1864 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 1865 | |
| 1866 | TEST_LOCAL_TEARDOWN; |
| 1867 | } |
| 1868 | |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1869 | static LY_ERR |
| 1870 | getter(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free) |
| 1871 | { |
| 1872 | struct ly_ctx *ctx; |
| 1873 | struct lyd_node *data = NULL; |
| 1874 | |
| 1875 | ctx = ext->module->ctx; |
| 1876 | if (user_data) { |
| 1877 | assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, user_data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &data)); |
| 1878 | } |
| 1879 | |
| 1880 | *ext_data = data; |
| 1881 | *ext_data_free = 1; |
| 1882 | return LY_SUCCESS; |
| 1883 | } |
| 1884 | |
| 1885 | #define SM_MODNAME_EXT "sm-extension" |
| 1886 | #define SM_MOD_EXT_NAMESPACE "urn:sm-ext" |
| 1887 | #define SM_PREF "sm" |
| 1888 | #define SCHEMA_REF_INLINE "<inline></inline>" |
| 1889 | #define SCHEMA_REF_SHARED(REF) "<shared-schema>"REF"</shared-schema>" |
| 1890 | |
| 1891 | #define EXT_DATA(MPMOD_NAME, MODULES, SCHEMA_REF) \ |
| 1892 | "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"\n" \ |
| 1893 | " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">\n" \ |
| 1894 | "<module-set>\n" \ |
| 1895 | " <name>test-set</name>\n" \ |
| 1896 | " <module>\n" \ |
| 1897 | " <name>"SM_MODNAME_EXT"</name>\n" \ |
| 1898 | " <namespace>"SM_MOD_EXT_NAMESPACE"</namespace>\n" \ |
| 1899 | " </module>\n" \ |
| 1900 | MODULES \ |
| 1901 | "</module-set>\n" \ |
| 1902 | "<content-id>1</content-id>\n" \ |
| 1903 | "</yang-library>\n" \ |
| 1904 | "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">\n" \ |
| 1905 | "<module-set-id>1</module-set-id>\n" \ |
| 1906 | "</modules-state>\n" \ |
| 1907 | "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">\n" \ |
| 1908 | "<namespace>\n" \ |
| 1909 | " <prefix>"SM_PREF"</prefix>\n" \ |
| 1910 | " <uri>x:"MPMOD_NAME"</uri>\n" \ |
| 1911 | "</namespace>\n" \ |
| 1912 | "<mount-point>\n" \ |
| 1913 | " <module>"MPMOD_NAME"</module>\n" \ |
| 1914 | " <label>mnt-root</label>\n" \ |
| 1915 | SCHEMA_REF \ |
| 1916 | "</mount-point>\n" \ |
| 1917 | "</schema-mounts>" |
| 1918 | |
| 1919 | #define SM_MOD_MAIN(NAME, BODY) \ |
| 1920 | "module "NAME" {\n" \ |
| 1921 | " yang-version 1.1;\n" \ |
| 1922 | " namespace \"x:"NAME"\";\n" \ |
| 1923 | " prefix \"x\";\n" \ |
| 1924 | " import ietf-yang-schema-mount {\n" \ |
| 1925 | " prefix yangmnt;\n" \ |
| 1926 | " }\n" \ |
| 1927 | BODY \ |
| 1928 | "}" |
| 1929 | |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1930 | static void |
| 1931 | mount_point(void **state) |
| 1932 | { |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1933 | char *data; |
| 1934 | |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1935 | TEST_LOCAL_SETUP; |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1936 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1937 | |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1938 | /* interested in sm-extension.yang and sm-mod.yang */ |
| 1939 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG)); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1940 | |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1941 | /* |
| 1942 | * 'mp' flag for list and container |
| 1943 | */ |
| 1944 | orig = SM_MOD_MAIN("a29", |
| 1945 | "list lt {\n" |
| 1946 | " key \"name\";\n" |
| 1947 | " leaf name {\n" |
| 1948 | " type string;\n" |
| 1949 | " }\n" |
| 1950 | " yangmnt:mount-point \"mnt-root\";\n" |
| 1951 | "}\n" |
| 1952 | "container cont {\n" |
| 1953 | " yangmnt:mount-point \"mnt-root\";\n" |
| 1954 | "}\n"); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1955 | expect = |
Michal Vasko | 8bb6e7e | 2022-10-10 09:05:14 +0200 | [diff] [blame] | 1956 | "module: a29\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1957 | " +--mp lt* [name]\n" |
Michal Vasko | 8bb6e7e | 2022-10-10 09:05:14 +0200 | [diff] [blame] | 1958 | " | +--rw name string\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1959 | " +--mp cont\n"; |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1960 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 1961 | TEST_LOCAL_PRINT(mod, 72); |
| 1962 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1963 | assert_string_equal(printed, expect); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1964 | ly_out_reset(UTEST_OUT); |
| 1965 | |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1966 | /* |
| 1967 | * mount schema by 'inline' schema-ref |
| 1968 | */ |
| 1969 | orig = SM_MOD_MAIN("a30", |
| 1970 | "list lt {\n" |
| 1971 | " key \"name\";\n" |
| 1972 | " leaf name {\n" |
| 1973 | " type string;\n" |
| 1974 | " }\n" |
| 1975 | " yangmnt:mount-point \"mnt-root\";\n" |
| 1976 | "}\n"); |
| 1977 | expect = |
| 1978 | "module: a30\n" |
| 1979 | " +--mp lt* [name]\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 1980 | " +--rw tlist/* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1981 | " | +--rw name uint32\n" |
| 1982 | " +--rw tcont/\n" |
| 1983 | " | +--rw tleaf? uint32\n" |
| 1984 | " +--rw name string\n"; |
| 1985 | data = EXT_DATA("a30", "", SCHEMA_REF_INLINE); |
| 1986 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 1987 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1988 | TEST_LOCAL_PRINT(mod, 72); |
| 1989 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 1990 | assert_string_equal(printed, expect); |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1991 | ly_out_reset(UTEST_OUT); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 1992 | |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 1993 | /* |
| 1994 | * mount schema into empty container |
| 1995 | */ |
| 1996 | orig = SM_MOD_MAIN("a31", |
| 1997 | "container cont {\n" |
| 1998 | " yangmnt:mount-point \"mnt-root\";\n" |
| 1999 | "}\n" |
| 2000 | "leaf lf {\n" |
| 2001 | " type string;\n" |
| 2002 | "}\n"); |
| 2003 | expect = |
| 2004 | "module: a31\n" |
| 2005 | " +--mp cont\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2006 | " | +--rw tlist/* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2007 | " | | +--rw name uint32\n" |
| 2008 | " | +--rw tcont/\n" |
| 2009 | " | +--rw tleaf? uint32\n" |
| 2010 | " +--rw lf? string\n"; |
| 2011 | data = EXT_DATA("a31", "", SCHEMA_REF_INLINE); |
| 2012 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2013 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2014 | TEST_LOCAL_PRINT(mod, 72); |
| 2015 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2016 | assert_string_equal(printed, expect); |
| 2017 | ly_out_reset(UTEST_OUT); |
| 2018 | |
| 2019 | /* |
| 2020 | * mount schema into non-empty container |
| 2021 | */ |
| 2022 | orig = SM_MOD_MAIN("a32", |
| 2023 | "container cont {\n" |
| 2024 | " leaf lf1 {\n" |
| 2025 | " type string;\n" |
| 2026 | " }\n" |
| 2027 | " yangmnt:mount-point \"mnt-root\";\n" |
| 2028 | " leaf lf2 {\n" |
| 2029 | " type string;\n" |
| 2030 | " }\n" |
| 2031 | "}\n"); |
| 2032 | expect = |
| 2033 | "module: a32\n" |
| 2034 | " +--mp cont\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2035 | " +--rw tlist/* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2036 | " | +--rw name uint32\n" |
| 2037 | " +--rw tcont/\n" |
| 2038 | " | +--rw tleaf? uint32\n" |
| 2039 | " +--rw lf1? string\n" |
| 2040 | " +--rw lf2? string\n"; |
| 2041 | data = EXT_DATA("a32", "", SCHEMA_REF_INLINE); |
| 2042 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2043 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2044 | TEST_LOCAL_PRINT(mod, 72); |
| 2045 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2046 | assert_string_equal(printed, expect); |
| 2047 | ly_out_reset(UTEST_OUT); |
| 2048 | |
| 2049 | /* |
| 2050 | * mounting with parent-reference |
| 2051 | */ |
| 2052 | orig = SM_MOD_MAIN("a33", |
| 2053 | "list pr {\n" |
| 2054 | " key \"name\";\n" |
| 2055 | " leaf name {\n" |
| 2056 | " type string;\n" |
| 2057 | " }\n" |
| 2058 | " leaf prlf {\n" |
| 2059 | " type string;\n" |
| 2060 | " }\n" |
| 2061 | "}\n" |
| 2062 | "leaf lf {\n" |
| 2063 | " type string;\n" |
| 2064 | "}\n" |
| 2065 | "container cont {\n" |
| 2066 | " yangmnt:mount-point \"mnt-root\";\n" |
| 2067 | " list lt {\n" |
| 2068 | " key \"name\";\n" |
| 2069 | " leaf name {\n" |
| 2070 | " type string;\n" |
| 2071 | " }\n" |
| 2072 | " }\n" |
| 2073 | "}\n"); |
| 2074 | expect = |
| 2075 | "module: a33\n" |
| 2076 | " +--rw pr* [name]\n" |
| 2077 | " | +--rw name string\n" |
| 2078 | " | +--rw prlf? string\n" |
| 2079 | " +--rw lf? string\n" |
| 2080 | " +--mp cont\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2081 | " +--rw tlist/* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2082 | " | +--rw name uint32\n" |
| 2083 | " +--rw tcont/\n" |
| 2084 | " | +--rw tleaf? uint32\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2085 | " +--rw pr@* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2086 | " | +--rw prlf? string\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2087 | " +--rw lf@? string\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2088 | " +--rw lt* [name]\n" |
| 2089 | " +--rw name string\n"; |
| 2090 | data = EXT_DATA("a33", "", SCHEMA_REF_SHARED( |
| 2091 | "<parent-reference>/"SM_PREF ":pr/"SM_PREF ":prlf</parent-reference>\n" |
| 2092 | "<parent-reference>/"SM_PREF ":lf</parent-reference>\n")); |
| 2093 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2094 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2095 | TEST_LOCAL_PRINT(mod, 72); |
| 2096 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2097 | assert_string_equal(printed, expect); |
| 2098 | ly_out_reset(UTEST_OUT); |
| 2099 | |
| 2100 | /* |
| 2101 | * mounting with parent-reference into empty container |
| 2102 | */ |
| 2103 | orig = SM_MOD_MAIN("a34", |
| 2104 | "container cont {\n" |
| 2105 | " yangmnt:mount-point \"mnt-root\";\n" |
| 2106 | "}\n" |
| 2107 | "leaf lf {\n" |
| 2108 | " type string;\n" |
| 2109 | "}\n"); |
| 2110 | expect = |
| 2111 | "module: a34\n" |
| 2112 | " +--mp cont\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2113 | " | +--rw tlist/* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2114 | " | | +--rw name uint32\n" |
| 2115 | " | +--rw tcont/\n" |
| 2116 | " | | +--rw tleaf? uint32\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2117 | " | +--rw lf@? string\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2118 | " +--rw lf? string\n"; |
| 2119 | data = EXT_DATA("a34", "", |
| 2120 | SCHEMA_REF_SHARED( |
| 2121 | "<parent-reference>/"SM_PREF ":lf</parent-reference>\n")); |
| 2122 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2123 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2124 | TEST_LOCAL_PRINT(mod, 72); |
| 2125 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2126 | assert_string_equal(printed, expect); |
| 2127 | ly_out_reset(UTEST_OUT); |
| 2128 | |
| 2129 | /* |
| 2130 | * mounting module which is only parsed |
| 2131 | */ |
| 2132 | orig = SM_MOD_MAIN("a35", |
| 2133 | "import sm-mod {\n" |
| 2134 | " prefix smm;\n" |
| 2135 | "}\n" |
| 2136 | "container pr {\n" |
| 2137 | " leaf prlf {\n" |
| 2138 | " type uint32;\n" |
| 2139 | " }\n" |
| 2140 | "}\n" |
| 2141 | "list lt {\n" |
| 2142 | " key \"name\";\n" |
| 2143 | " yangmnt:mount-point \"mnt-root\";\n" |
| 2144 | " leaf name {\n" |
| 2145 | " type string;\n" |
| 2146 | " }\n" |
| 2147 | "}\n"); |
| 2148 | expect = |
| 2149 | "module: a35\n" |
| 2150 | " +--rw pr\n" |
| 2151 | " | +--rw prlf? uint32\n" |
| 2152 | " +--mp lt* [name]\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2153 | " +--rw tlist/* [name]\n" |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2154 | " | +--rw name uint32\n" |
| 2155 | " +--rw tcont/\n" |
| 2156 | " | +--rw tleaf? uint32\n" |
| 2157 | " +--mp ncmp/\n" |
| 2158 | " +--rw not-compiled/\n" |
| 2159 | " | +--rw first? string\n" |
| 2160 | " | +--rw second? string\n" |
| 2161 | " +--rw pr@\n" |
| 2162 | " | +--rw prlf? uint32\n" |
| 2163 | " +--rw name string\n"; |
| 2164 | data = EXT_DATA("a35", |
| 2165 | "<module>\n" |
| 2166 | " <name>sm-mod</name>\n" |
| 2167 | " <namespace>urn:sm-mod</namespace>\n" |
| 2168 | "</module>\n", |
| 2169 | SCHEMA_REF_SHARED( |
| 2170 | "<parent-reference>/"SM_PREF ":pr/"SM_PREF ":prlf</parent-reference>\n")); |
| 2171 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2172 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2173 | TEST_LOCAL_PRINT(mod, 72); |
| 2174 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2175 | assert_string_equal(printed, expect); |
| 2176 | ly_out_reset(UTEST_OUT); |
| 2177 | |
aPiecek | 36f8223 | 2022-10-14 10:08:38 +0200 | [diff] [blame] | 2178 | /* |
| 2179 | * notifications and rpcs in mounted module |
| 2180 | */ |
| 2181 | orig = SM_MOD_MAIN("a36", |
| 2182 | "container cont {\n" |
| 2183 | " yangmnt:mount-point \"mnt-root\";\n" |
| 2184 | "}\n"); |
| 2185 | expect = |
| 2186 | "module: a36\n" |
| 2187 | " +--mp cont\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2188 | " +--rw tlist/* [name]\n" |
aPiecek | 36f8223 | 2022-10-14 10:08:38 +0200 | [diff] [blame] | 2189 | " | +--rw name uint32\n" |
| 2190 | " +--rw tcont/\n" |
| 2191 | " | +--rw tleaf? uint32\n" |
| 2192 | " +--rw cont/\n" |
| 2193 | " | +---x cr\n" |
| 2194 | " | | +---w input\n" |
| 2195 | " | | | +---w in? string\n" |
| 2196 | " | | +--ro output\n" |
| 2197 | " | | +--ro out? string\n" |
| 2198 | " | +---n cn\n" |
| 2199 | " +---x r1/\n" |
| 2200 | " +---x r2/\n" |
| 2201 | " +---n n1/\n" |
| 2202 | " +---n n2/\n"; |
| 2203 | data = EXT_DATA("a36", |
| 2204 | "<module>\n" |
| 2205 | " <name>sm-rpcnotif</name>\n" |
| 2206 | " <namespace>urn:rpcnotif</namespace>\n" |
| 2207 | "</module>\n", |
| 2208 | SCHEMA_REF_INLINE); |
| 2209 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2210 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2211 | TEST_LOCAL_PRINT(mod, 72); |
| 2212 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2213 | assert_string_equal(printed, expect); |
| 2214 | ly_out_reset(UTEST_OUT); |
| 2215 | |
aPiecek | 8f1073c | 2022-10-17 16:44:49 +0200 | [diff] [blame] | 2216 | /* |
| 2217 | * parent-ref composes the '@' subtree |
| 2218 | */ |
| 2219 | orig = SM_MOD_MAIN("a37", |
| 2220 | "container pr {\n" |
| 2221 | " leaf ignored_node {\n" |
| 2222 | " type string;\n" |
| 2223 | " }\n" |
| 2224 | " container cont {\n" |
| 2225 | " leaf ignored_lf {\n" |
| 2226 | " type uint32;\n" |
| 2227 | " }\n" |
| 2228 | " }\n" |
| 2229 | " container ignored_subtree {\n" |
| 2230 | " leaf ignored_lf {\n" |
| 2231 | " type uint32;\n" |
| 2232 | " }\n" |
| 2233 | " }\n" |
| 2234 | " container cont_sibl {\n" |
| 2235 | " leaf slf {\n" |
| 2236 | " type string;\n" |
| 2237 | " }\n" |
| 2238 | " }\n" |
| 2239 | " leaf lf {\n" |
| 2240 | " type uint32;\n" |
| 2241 | " }\n" |
| 2242 | "}\n" |
| 2243 | "container cont_mount {\n" |
| 2244 | " yangmnt:mount-point \"mnt-root\";\n" |
| 2245 | "}\n"); |
| 2246 | expect = |
| 2247 | "module: a37\n" |
| 2248 | " +--rw pr\n" |
| 2249 | " | +--rw ignored_node? string\n" |
| 2250 | " | +--rw cont\n" |
| 2251 | " | | +--rw ignored_lf? uint32\n" |
| 2252 | " | +--rw ignored_subtree\n" |
| 2253 | " | | +--rw ignored_lf? uint32\n" |
| 2254 | " | +--rw cont_sibl\n" |
| 2255 | " | | +--rw slf? string\n" |
| 2256 | " | +--rw lf? uint32\n" |
| 2257 | " +--mp cont_mount\n" |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2258 | " +--rw tlist/* [name]\n" |
aPiecek | 8f1073c | 2022-10-17 16:44:49 +0200 | [diff] [blame] | 2259 | " | +--rw name uint32\n" |
| 2260 | " +--rw tcont/\n" |
| 2261 | " | +--rw tleaf? uint32\n" |
| 2262 | " +--rw pr@\n" |
| 2263 | " +--rw cont\n" |
| 2264 | " +--rw cont_sibl\n" |
| 2265 | " | +--rw slf? string\n" |
| 2266 | " +--rw lf? uint32\n"; |
| 2267 | data = EXT_DATA("a37", "", SCHEMA_REF_SHARED( |
| 2268 | "<parent-reference>/"SM_PREF ":pr/"SM_PREF ":cont_sibl/slf</parent-reference>\n" |
| 2269 | "<parent-reference>/"SM_PREF ":pr/"SM_PREF ":cont</parent-reference>\n" |
| 2270 | "<parent-reference>/"SM_PREF ":pr/"SM_PREF ":lf</parent-reference>\n")); |
| 2271 | ly_ctx_set_ext_data_clb(UTEST_LYCTX, getter, data); |
| 2272 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2273 | TEST_LOCAL_PRINT(mod, 72); |
| 2274 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2275 | assert_string_equal(printed, expect); |
| 2276 | ly_out_reset(UTEST_OUT); |
| 2277 | |
aPiecek | 85cda2a | 2022-10-13 13:47:05 +0200 | [diff] [blame] | 2278 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
ekinzie | 0ab8b30 | 2022-10-10 03:03:57 -0400 | [diff] [blame] | 2279 | TEST_LOCAL_TEARDOWN; |
| 2280 | } |
| 2281 | |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2282 | static void |
| 2283 | structure(void **state) |
| 2284 | { |
| 2285 | TEST_LOCAL_SETUP; |
| 2286 | |
| 2287 | orig = |
| 2288 | "module example-module {\n" |
| 2289 | " yang-version 1.1;\n" |
| 2290 | " namespace \"urn:example:example-module\";\n" |
| 2291 | " prefix exm;\n" |
| 2292 | "\n" |
| 2293 | " import ietf-yang-structure-ext {\n" |
| 2294 | " prefix sx;\n" |
| 2295 | " }\n" |
| 2296 | "\n" |
| 2297 | " sx:structure address-book {\n" |
| 2298 | " list address {\n" |
| 2299 | " key \"last first\";\n" |
| 2300 | " leaf last {\n" |
| 2301 | " type string;\n" |
| 2302 | " }\n" |
| 2303 | " leaf first {\n" |
| 2304 | " type string;\n" |
| 2305 | " }\n" |
| 2306 | " leaf street {\n" |
| 2307 | " type string;\n" |
| 2308 | " }\n" |
| 2309 | " leaf city {\n" |
| 2310 | " type string;\n" |
| 2311 | " }\n" |
| 2312 | " leaf state {\n" |
| 2313 | " type string;\n" |
| 2314 | " }\n" |
| 2315 | " }\n" |
| 2316 | " }\n" |
| 2317 | "}\n"; |
| 2318 | |
| 2319 | /* from RFC 8791, Appendix A.1 */ |
| 2320 | expect = |
| 2321 | "module: example-module\n" |
| 2322 | "\n" |
| 2323 | " structure address-book:\n" |
| 2324 | " +-- address* [last first]\n" |
| 2325 | " +-- last string\n" |
| 2326 | " +-- first string\n" |
| 2327 | " +-- street? string\n" |
| 2328 | " +-- city? string\n" |
| 2329 | " +-- state? string\n"; |
| 2330 | |
| 2331 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2332 | TEST_LOCAL_PRINT(mod, 72); |
| 2333 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2334 | assert_string_equal(printed, expect); |
| 2335 | ly_out_reset(UTEST_OUT); |
| 2336 | |
| 2337 | /* using lysc tree */ |
| 2338 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 2339 | TEST_LOCAL_PRINT(mod, 72); |
| 2340 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2341 | assert_string_equal(printed, expect); |
| 2342 | ly_out_reset(UTEST_OUT); |
| 2343 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 2344 | |
| 2345 | orig = |
| 2346 | "module example-module-aug {\n" |
| 2347 | " yang-version 1.1;\n" |
| 2348 | " namespace \"urn:example:example-module-aug\";\n" |
| 2349 | " prefix exma;\n" |
| 2350 | "\n" |
| 2351 | " import ietf-yang-structure-ext {\n" |
| 2352 | " prefix sx;\n" |
| 2353 | " }\n" |
| 2354 | " import example-module {\n" |
| 2355 | " prefix exm;\n" |
| 2356 | " }\n" |
| 2357 | "\n" |
| 2358 | " sx:augment-structure \"/exm:address-book/exm:address\" {\n" |
| 2359 | " leaf county {\n" |
| 2360 | " type string;\n" |
| 2361 | " }\n" |
| 2362 | " leaf zipcode {\n" |
| 2363 | " type string;\n" |
| 2364 | " }\n" |
| 2365 | " }\n" |
| 2366 | "}\n"; |
| 2367 | |
| 2368 | /* from RFC 8791, Appendix A.2 */ |
| 2369 | expect = |
| 2370 | "module: example-module-aug\n" |
| 2371 | "\n" |
| 2372 | " augment-structure /exm:address-book/exm:address:\n" |
| 2373 | " +-- county? string\n" |
| 2374 | " +-- zipcode? string\n"; |
| 2375 | |
| 2376 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2377 | TEST_LOCAL_PRINT(mod, 72); |
| 2378 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2379 | assert_string_equal(printed, expect); |
| 2380 | ly_out_reset(UTEST_OUT); |
| 2381 | |
| 2382 | /* using lysc tree */ |
| 2383 | ly_ctx_set_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 2384 | TEST_LOCAL_PRINT(mod, 72); |
| 2385 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2386 | assert_string_equal(printed, expect); |
| 2387 | ly_out_reset(UTEST_OUT); |
| 2388 | ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_SET_PRIV_PARSED); |
| 2389 | |
| 2390 | TEST_LOCAL_TEARDOWN; |
| 2391 | } |
| 2392 | |
aPiecek | ba67462 | 2023-03-28 10:57:00 +0200 | [diff] [blame] | 2393 | static void |
| 2394 | annotation(void **state) |
| 2395 | { |
| 2396 | TEST_LOCAL_SETUP; |
| 2397 | |
| 2398 | orig = |
| 2399 | "module ann {\n" |
| 2400 | " yang-version 1.1;\n" |
| 2401 | " namespace \"urn:example:ann\";\n" |
| 2402 | " prefix an;\n" |
| 2403 | "\n" |
| 2404 | " import ietf-yang-metadata {\n" |
| 2405 | " prefix md;\n" |
| 2406 | " }\n" |
| 2407 | "\n" |
| 2408 | " leaf lf1 {\n" |
| 2409 | " type string;\n" |
| 2410 | " }\n" |
| 2411 | " md:annotation avalue {\n" |
| 2412 | " type string;\n" |
| 2413 | " }\n" |
| 2414 | "}\n"; |
| 2415 | |
| 2416 | expect = |
| 2417 | "module: ann\n" |
| 2418 | " +--rw lf1? string\n"; |
| 2419 | |
| 2420 | /* annotation is ignored without error message */ |
| 2421 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
| 2422 | TEST_LOCAL_PRINT(mod, 72); |
| 2423 | assert_int_equal(strlen(expect), ly_out_printed(UTEST_OUT)); |
| 2424 | assert_string_equal(printed, expect); |
| 2425 | ly_out_reset(UTEST_OUT); |
| 2426 | |
| 2427 | TEST_LOCAL_TEARDOWN; |
| 2428 | } |
| 2429 | |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 2430 | int |
| 2431 | main(void) |
| 2432 | { |
| 2433 | const struct CMUnitTest tests[] = { |
| 2434 | UTEST(base_sections), |
| 2435 | UTEST(node_status), |
| 2436 | UTEST(node_config_flags), |
| 2437 | UTEST(node_rpcs_flags), |
| 2438 | UTEST(node_grouping_flags), |
| 2439 | UTEST(notif_inside_container), |
| 2440 | UTEST(node_choice), |
| 2441 | UTEST(node_case), |
| 2442 | UTEST(optional_opts), |
| 2443 | UTEST(presence_container), |
| 2444 | UTEST(node_keys), |
| 2445 | UTEST(node_type_target), |
| 2446 | UTEST(node_type_leafref), |
| 2447 | UTEST(node_iffeatures), |
| 2448 | UTEST(indent_wrapper), |
| 2449 | UTEST(line_length_twiddling), |
| 2450 | UTEST(break_before_leafref), |
| 2451 | UTEST(break_before_leafref_and_iffeature), |
| 2452 | UTEST(basic_unified_indent_before_type), |
| 2453 | UTEST(twiddling_unified_indent_before_type), |
| 2454 | UTEST(inheritance_of_config_flag), |
| 2455 | UTEST(inheritance_of_status_flag), |
| 2456 | UTEST(key_leaf_is_always_mandatory_true), |
| 2457 | UTEST(transition_between_rpc_and_notif), |
aPiecek | 9e50592 | 2021-04-19 13:45:08 +0200 | [diff] [blame] | 2458 | UTEST(local_augment), |
aPiecek | 7745b28 | 2021-04-20 13:54:52 +0200 | [diff] [blame] | 2459 | UTEST(print_compiled_node), |
aPiecek | aecf751 | 2021-04-21 08:34:35 +0200 | [diff] [blame] | 2460 | UTEST(print_parsed_submodule), |
aPiecek | b8e43f1 | 2021-04-23 12:52:22 +0200 | [diff] [blame] | 2461 | UTEST(yang_data), |
aPiecek | 03cb487 | 2022-10-24 10:31:51 +0200 | [diff] [blame] | 2462 | UTEST(mount_point), |
| 2463 | UTEST(structure), |
aPiecek | ba67462 | 2023-03-28 10:57:00 +0200 | [diff] [blame] | 2464 | UTEST(annotation), |
aPiecek | 20ddf8b | 2021-01-08 11:50:37 +0100 | [diff] [blame] | 2465 | }; |
| 2466 | |
| 2467 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 2468 | } |