FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1 | /* |
| 2 | * @file test_printer_yin.c |
| 3 | * @author: Fred Gan <ganshaolong@vip.qq.com> |
| 4 | * @brief unit tests for functions from printer_yin.c |
| 5 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 6 | * Copyright (c) 2019-2020 CESNET, z.s.p.o. |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 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 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #define _UTEST_MAIN_ |
| 15 | #include "utests.h" |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 16 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 17 | #include "common.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 18 | #include "context.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 19 | #include "out.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 20 | #include "printer_schema.h" |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 21 | #include "tree_schema.h" |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 22 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 23 | static void |
| 24 | test_module(void **state) |
| 25 | { |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 26 | const struct lys_module *mod; |
| 27 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 28 | const char *orig = |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 29 | "module all {\n" |
| 30 | " yang-version 1.1;\n" |
| 31 | " namespace \"urn:all\";\n" |
| 32 | " prefix all_mod;\n\n" |
| 33 | " import ietf-yang-types {\n" |
| 34 | " prefix yt;\n" |
| 35 | " revision-date 2013-07-15;\n" |
| 36 | " description\n" |
| 37 | " \"YANG types\";\n" |
| 38 | " reference\n" |
| 39 | " \"RFC reference\";\n" |
| 40 | " }\n\n" |
| 41 | " feature feat1 {\n" |
| 42 | " if-feature \"feat2\";\n" |
| 43 | " status obsolete;\n" |
| 44 | " }\n\n" |
| 45 | " feature feat2;\n" |
| 46 | " feature feat3;\n\n" |
| 47 | " identity ident2 {\n" |
| 48 | " base ident1;\n" |
| 49 | " }\n\n" |
| 50 | " identity ident1;\n\n" |
| 51 | " typedef tdef1 {\n" |
| 52 | " type tdef2 {\n" |
| 53 | " length \"3..9 | 30..40\";\n" |
| 54 | " pattern \"[ac]*\";\n" |
| 55 | " }\n" |
| 56 | " units \"none\";\n" |
| 57 | " default \"aaa\";\n" |
| 58 | " }\n\n" |
| 59 | " typedef tdef2 {\n" |
| 60 | " type string {\n" |
| 61 | " length \"2..10 | 20..50\";\n" |
| 62 | " pattern \"[ab]*\";\n" |
| 63 | " }\n" |
| 64 | " }\n\n" |
| 65 | " grouping group1 {\n" |
| 66 | " leaf leaf1 {\n" |
| 67 | " type int8;\n" |
| 68 | " }\n" |
| 69 | " }\n\n" |
| 70 | " container cont1 {\n" |
| 71 | " leaf leaf2 {\n" |
| 72 | " if-feature \"feat1\";\n" |
| 73 | " type int16;\n" |
| 74 | " status obsolete;\n" |
| 75 | " }\n\n" |
| 76 | " uses group1 {\n" |
| 77 | " if-feature \"feat2\";\n" |
| 78 | " refine \"leaf1\" {\n" |
| 79 | " if-feature \"feat3\";\n" |
| 80 | " must \"24 - 4 = number('20')\";\n" |
| 81 | " default \"25\";\n" |
| 82 | " config true;\n" |
| 83 | " mandatory false;\n" |
| 84 | " description\n" |
| 85 | " \"dsc\";\n" |
| 86 | " reference\n" |
| 87 | " \"none\";\n" |
| 88 | " }\n" |
| 89 | " }\n\n" |
| 90 | " leaf leaf3 {\n" |
| 91 | " type int32;\n" |
| 92 | " }\n\n" |
| 93 | " leaf leaf4 {\n" |
| 94 | " type int64 {\n" |
| 95 | " range \"1000 .. 50000\" {\n" |
| 96 | " error-message\n" |
| 97 | " \"Special error message.\";\n" |
| 98 | " error-app-tag \"special-tag\";\n" |
| 99 | " }\n" |
| 100 | " }\n" |
| 101 | " }\n\n" |
| 102 | " leaf leaf5 {\n" |
| 103 | " type uint8;\n" |
| 104 | " }\n\n" |
| 105 | " leaf leaf6 {\n" |
| 106 | " type uint16;\n" |
| 107 | " }\n\n" |
| 108 | " leaf leaf7 {\n" |
| 109 | " type uint32;\n" |
| 110 | " }\n\n" |
| 111 | " leaf leaf8 {\n" |
| 112 | " type uint64;\n" |
| 113 | " }\n\n" |
| 114 | " choice choic1 {\n" |
| 115 | " default \"leaf9b\";\n" |
| 116 | " leaf leaf9a {\n" |
| 117 | " type decimal64 {\n" |
| 118 | " fraction-digits 9;\n" |
| 119 | " }\n" |
| 120 | " }\n\n" |
| 121 | " leaf leaf9b {\n" |
| 122 | " type boolean;\n" |
| 123 | " default \"false\";\n" |
| 124 | " }\n" |
| 125 | " }\n\n" |
| 126 | " leaf leaf10 {\n" |
| 127 | " type boolean;\n" |
| 128 | " }\n\n" |
| 129 | " leaf leaf11 {\n" |
| 130 | " type enumeration {\n" |
| 131 | " enum \"one\";\n" |
| 132 | " enum \"two\";\n" |
| 133 | " enum \"five\" {\n" |
| 134 | " value 5;\n" |
| 135 | " }\n" |
| 136 | " }\n" |
| 137 | " }\n\n" |
| 138 | " leaf leaf12 {\n" |
| 139 | " type bits {\n" |
| 140 | " bit flag0 {\n" |
| 141 | " position 0;\n" |
| 142 | " }\n" |
| 143 | " bit flag1;\n" |
| 144 | " bit flag2 {\n" |
| 145 | " position 2;\n" |
| 146 | " }\n" |
| 147 | " bit flag3 {\n" |
| 148 | " position 3;\n" |
| 149 | " }\n" |
| 150 | " }\n" |
| 151 | " default \"flag0 flag3\";\n" |
| 152 | " }\n\n" |
| 153 | " leaf leaf13 {\n" |
| 154 | " type binary;\n" |
| 155 | " }\n\n" |
| 156 | " leaf leaf14 {\n" |
| 157 | " type leafref {\n" |
| 158 | " path \"/cont1/leaf17\";\n" |
| 159 | " }\n" |
| 160 | " }\n\n" |
| 161 | " leaf leaf15 {\n" |
| 162 | " type empty;\n" |
| 163 | " }\n\n" |
| 164 | " leaf leaf16 {\n" |
| 165 | " type union {\n" |
| 166 | " type instance-identifier {\n" |
| 167 | " require-instance true;\n" |
| 168 | " }\n" |
| 169 | " type int8;\n" |
| 170 | " }\n" |
| 171 | " }\n\n" |
| 172 | " list list1 {\n" |
| 173 | " key \"leaf18\";\n" |
| 174 | " unique \"leaf19\";\n" |
| 175 | " min-elements 1;\n" |
| 176 | " max-elements 20;\n" |
| 177 | " leaf leaf18 {\n" |
| 178 | " type string;\n" |
| 179 | " }\n\n" |
| 180 | " leaf leaf19 {\n" |
| 181 | " type uint32;\n" |
| 182 | " }\n\n" |
| 183 | " anyxml axml1;\n" |
| 184 | " anydata adata1;\n\n" |
| 185 | " action act1 {\n" |
| 186 | " input {\n" |
| 187 | " leaf leaf24 {\n" |
| 188 | " type string;\n" |
| 189 | " }\n" |
| 190 | " }\n\n" |
| 191 | " output {\n" |
| 192 | " leaf leaf25 {\n" |
| 193 | " type string;\n" |
| 194 | " }\n" |
| 195 | " }\n" |
| 196 | " }\n\n" |
| 197 | " notification notif1 {\n" |
| 198 | " leaf leaf26 {\n" |
| 199 | " type string;\n" |
| 200 | " }\n" |
| 201 | " }\n" |
| 202 | " }\n\n" |
| 203 | " leaf-list llist1 {\n" |
| 204 | " type tdef1;\n" |
| 205 | " ordered-by user;\n" |
| 206 | " }\n\n" |
| 207 | " list list2 {\n" |
| 208 | " key \"leaf27 leaf28\";\n" |
| 209 | " leaf leaf27 {\n" |
| 210 | " type uint8;\n" |
| 211 | " }\n\n" |
| 212 | " leaf leaf28 {\n" |
| 213 | " type uint8;\n" |
| 214 | " }\n" |
| 215 | " }\n\n" |
| 216 | " leaf leaf29 {\n" |
| 217 | " type instance-identifier;\n" |
| 218 | " }\n\n" |
| 219 | " container must-deviations-container {\n" |
| 220 | " presence \"Allows deviations on the leaf\";\n" |
| 221 | " leaf leaf30 {\n" |
| 222 | " type string;\n" |
| 223 | " }\n" |
| 224 | " }\n\n" |
| 225 | " leaf leaf23 {\n" |
| 226 | " type empty;\n" |
| 227 | " }\n" |
| 228 | " }\n\n" |
| 229 | " augment \"/cont1\" {\n" |
| 230 | " leaf leaf17 {\n" |
| 231 | " type string;\n" |
| 232 | " }\n" |
| 233 | " }\n\n" |
| 234 | " rpc rpc1 {\n" |
| 235 | " input {\n" |
| 236 | " leaf leaf20 {\n" |
| 237 | " type tdef1;\n" |
| 238 | " }\n" |
| 239 | " }\n\n" |
| 240 | " output {\n" |
| 241 | " container cont2 {\n" |
| 242 | " leaf leaf21 {\n" |
| 243 | " type empty;\n" |
| 244 | " }\n" |
| 245 | " }\n" |
| 246 | " }\n" |
| 247 | " }\n\n" |
| 248 | " container test-when {\n" |
| 249 | " leaf when-check {\n" |
| 250 | " type boolean;\n" |
| 251 | " }\n\n" |
| 252 | " leaf gated-data {\n" |
| 253 | " when \"../when-check = 'true'\";\n" |
| 254 | " type uint16;\n" |
| 255 | " }\n" |
| 256 | " }\n\n" |
| 257 | " extension c-define {\n" |
| 258 | " description\n" |
| 259 | " \"Takes as an argument a name string.\n" |
| 260 | " Makes the code generator use the given name\n" |
| 261 | " in the #define.\";\n" |
| 262 | " argument \"name\";\n" |
| 263 | " }\n" |
| 264 | "}\n"; |
| 265 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 266 | const char *ori_res = |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 267 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 268 | "<module name=\"all\"\n" |
| 269 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 270 | " xmlns:all_mod=\"urn:all\"\n" |
| 271 | " xmlns:yt=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">\n" |
| 272 | " <yang-version value=\"1.1\"/>\n" |
| 273 | " <namespace uri=\"urn:all\"/>\n" |
| 274 | " <prefix value=\"all_mod\"/>\n" |
| 275 | " <import module=\"ietf-yang-types\">\n" |
| 276 | " <prefix value=\"yt\"/>\n" |
| 277 | " <revision-date date=\"2013-07-15\"/>\n" |
| 278 | " <description>\n" |
| 279 | " <text>YANG types</text>\n" |
| 280 | " </description>\n" |
| 281 | " <reference>\n" |
| 282 | " <text>RFC reference</text>\n" |
| 283 | " </reference>\n" |
| 284 | " </import>\n\n" |
| 285 | " <extension name=\"c-define\">\n" |
| 286 | " <argument name=\"name\"/>\n" |
| 287 | " <description>\n" |
| 288 | " <text>Takes as an argument a name string.\n" |
| 289 | "Makes the code generator use the given name\n" |
| 290 | "in the #define.</text>\n" |
| 291 | " </description>\n" |
| 292 | " </extension>\n" |
| 293 | " <feature name=\"feat1\">\n" |
| 294 | " <if-feature name=\"feat2\"/>\n" |
| 295 | " <status value=\"obsolete\"/>\n" |
| 296 | " </feature>\n" |
| 297 | " <feature name=\"feat2\"/>\n" |
| 298 | " <feature name=\"feat3\"/>\n" |
| 299 | " <identity name=\"ident2\">\n" |
| 300 | " <base name=\"ident1\"/>\n" |
| 301 | " </identity>\n" |
| 302 | " <identity name=\"ident1\"/>\n" |
| 303 | " <typedef name=\"tdef1\">\n" |
| 304 | " <type name=\"tdef2\">\n" |
| 305 | " <length value=\"3..9 | 30..40\"/>\n" |
| 306 | " <pattern value=\"[ac]*\"/>\n" |
| 307 | " </type>\n" |
| 308 | " <units name=\"none\"/>\n" |
| 309 | " <default value=\"aaa\"/>\n" |
| 310 | " </typedef>\n" |
| 311 | " <typedef name=\"tdef2\">\n" |
| 312 | " <type name=\"string\">\n" |
| 313 | " <length value=\"2..10 | 20..50\"/>\n" |
| 314 | " <pattern value=\"[ab]*\"/>\n" |
| 315 | " </type>\n" |
| 316 | " </typedef>\n" |
| 317 | " <grouping name=\"group1\">\n" |
| 318 | " <leaf name=\"leaf1\">\n" |
| 319 | " <type name=\"int8\"/>\n" |
| 320 | " </leaf>\n" |
| 321 | " </grouping>\n" |
| 322 | " <container name=\"cont1\">\n" |
| 323 | " <leaf name=\"leaf2\">\n" |
| 324 | " <if-feature name=\"feat1\"/>\n" |
| 325 | " <type name=\"int16\"/>\n" |
| 326 | " <status value=\"obsolete\"/>\n" |
| 327 | " </leaf>\n" |
| 328 | " <uses name=\"group1\">\n" |
| 329 | " <if-feature name=\"feat2\"/>\n" |
| 330 | " <refine target-node=\"leaf1\">\n" |
| 331 | " <if-feature name=\"feat3\"/>\n" |
| 332 | " <must condition=\"24 - 4 = number('20')\"/>\n" |
| 333 | " <default value=\"25\"/>\n" |
| 334 | " <config value=\"true\"/>\n" |
| 335 | " <mandatory value=\"false\"/>\n" |
| 336 | " <description>\n" |
| 337 | " <text>dsc</text>\n" |
| 338 | " </description>\n" |
| 339 | " <reference>\n" |
| 340 | " <text>none</text>\n" |
| 341 | " </reference>\n" |
| 342 | " </refine>\n" |
| 343 | " </uses>\n" |
| 344 | " <leaf name=\"leaf3\">\n" |
| 345 | " <type name=\"int32\"/>\n" |
| 346 | " </leaf>\n" |
| 347 | " <leaf name=\"leaf4\">\n" |
| 348 | " <type name=\"int64\">\n" |
| 349 | " <range value=\"1000 .. 50000\">\n" |
| 350 | " <error-message>\n" |
| 351 | " <value>Special error message.</value>\n" |
| 352 | " </error-message>\n" |
| 353 | " <error-app-tag value=\"special-tag\"/>\n" |
| 354 | " </range>\n" |
| 355 | " </type>\n" |
| 356 | " </leaf>\n" |
| 357 | " <leaf name=\"leaf5\">\n" |
| 358 | " <type name=\"uint8\"/>\n" |
| 359 | " </leaf>\n" |
| 360 | " <leaf name=\"leaf6\">\n" |
| 361 | " <type name=\"uint16\"/>\n" |
| 362 | " </leaf>\n" |
| 363 | " <leaf name=\"leaf7\">\n" |
| 364 | " <type name=\"uint32\"/>\n" |
| 365 | " </leaf>\n" |
| 366 | " <leaf name=\"leaf8\">\n" |
| 367 | " <type name=\"uint64\"/>\n" |
| 368 | " </leaf>\n" |
| 369 | " <choice name=\"choic1\">\n" |
| 370 | " <default value=\"leaf9b\"/>\n" |
| 371 | " <leaf name=\"leaf9a\">\n" |
| 372 | " <type name=\"decimal64\">\n" |
| 373 | " <fraction-digits value=\"9\"/>\n" |
| 374 | " </type>\n" |
| 375 | " </leaf>\n" |
| 376 | " <leaf name=\"leaf9b\">\n" |
| 377 | " <type name=\"boolean\"/>\n" |
| 378 | " <default value=\"false\"/>\n" |
| 379 | " </leaf>\n" |
| 380 | " </choice>\n" |
| 381 | " <leaf name=\"leaf10\">\n" |
| 382 | " <type name=\"boolean\"/>\n" |
| 383 | " </leaf>\n" |
| 384 | " <leaf name=\"leaf11\">\n" |
| 385 | " <type name=\"enumeration\">\n" |
| 386 | " <enum name=\"one\"/>\n" |
| 387 | " <enum name=\"two\"/>\n" |
| 388 | " <enum name=\"five\">\n" |
| 389 | " <value value=\"5\"/>\n" |
| 390 | " </enum>\n" |
| 391 | " </type>\n" |
| 392 | " </leaf>\n" |
| 393 | " <leaf name=\"leaf12\">\n" |
| 394 | " <type name=\"bits\">\n" |
| 395 | " <bit name=\"flag0\">\n" |
| 396 | " <position value=\"0\"/>\n" |
| 397 | " </bit>\n" |
| 398 | " <bit name=\"flag1\"/>\n" |
| 399 | " <bit name=\"flag2\">\n" |
| 400 | " <position value=\"2\"/>\n" |
| 401 | " </bit>\n" |
| 402 | " <bit name=\"flag3\">\n" |
| 403 | " <position value=\"3\"/>\n" |
| 404 | " </bit>\n" |
| 405 | " </type>\n" |
| 406 | " <default value=\"flag0 flag3\"/>\n" |
| 407 | " </leaf>\n" |
| 408 | " <leaf name=\"leaf13\">\n" |
| 409 | " <type name=\"binary\"/>\n" |
| 410 | " </leaf>\n" |
| 411 | " <leaf name=\"leaf14\">\n" |
| 412 | " <type name=\"leafref\">\n" |
| 413 | " <path value=\"/cont1/leaf17\"/>\n" |
| 414 | " </type>\n" |
| 415 | " </leaf>\n" |
| 416 | " <leaf name=\"leaf15\">\n" |
| 417 | " <type name=\"empty\"/>\n" |
| 418 | " </leaf>\n" |
| 419 | " <leaf name=\"leaf16\">\n" |
| 420 | " <type name=\"union\">\n" |
| 421 | " <type name=\"instance-identifier\">\n" |
| 422 | " <require-instance value=\"true\"/>\n" |
| 423 | " </type>\n" |
| 424 | " <type name=\"int8\"/>\n" |
| 425 | " </type>\n" |
| 426 | " </leaf>\n" |
| 427 | " <list name=\"list1\">\n" |
| 428 | " <key value=\"leaf18\"/>\n" |
| 429 | " <unique tag=\"leaf19\"/>\n" |
| 430 | " <min-elements value=\"1\"/>\n" |
| 431 | " <max-elements value=\"20\"/>\n" |
| 432 | " <leaf name=\"leaf18\">\n" |
| 433 | " <type name=\"string\"/>\n" |
| 434 | " </leaf>\n" |
| 435 | " <leaf name=\"leaf19\">\n" |
| 436 | " <type name=\"uint32\"/>\n" |
| 437 | " </leaf>\n" |
| 438 | " <anyxml name=\"axml1\"/>\n" |
| 439 | " <anydata name=\"adata1\"/>\n" |
| 440 | " <action name=\"act1\">\n" |
| 441 | " <input>\n" |
| 442 | " <leaf name=\"leaf24\">\n" |
| 443 | " <type name=\"string\"/>\n" |
| 444 | " </leaf>\n" |
| 445 | " </input>\n" |
| 446 | " <output>\n" |
| 447 | " <leaf name=\"leaf25\">\n" |
| 448 | " <type name=\"string\"/>\n" |
| 449 | " </leaf>\n" |
| 450 | " </output>\n" |
| 451 | " </action>\n" |
| 452 | " <notification name=\"notif1\">\n" |
| 453 | " <leaf name=\"leaf26\">\n" |
| 454 | " <type name=\"string\"/>\n" |
| 455 | " </leaf>\n" |
| 456 | " </notification>\n" |
| 457 | " </list>\n" |
| 458 | " <leaf-list name=\"llist1\">\n" |
| 459 | " <type name=\"tdef1\"/>\n" |
| 460 | " <ordered-by value=\"user\"/>\n" |
| 461 | " </leaf-list>\n" |
| 462 | " <list name=\"list2\">\n" |
| 463 | " <key value=\"leaf27 leaf28\"/>\n" |
| 464 | " <leaf name=\"leaf27\">\n" |
| 465 | " <type name=\"uint8\"/>\n" |
| 466 | " </leaf>\n" |
| 467 | " <leaf name=\"leaf28\">\n" |
| 468 | " <type name=\"uint8\"/>\n" |
| 469 | " </leaf>\n" |
| 470 | " </list>\n" |
| 471 | " <leaf name=\"leaf29\">\n" |
| 472 | " <type name=\"instance-identifier\"/>\n" |
| 473 | " </leaf>\n" |
| 474 | " <container name=\"must-deviations-container\">\n" |
| 475 | " <presence value=\"Allows deviations on the leaf\"/>\n" |
| 476 | " <leaf name=\"leaf30\">\n" |
| 477 | " <type name=\"string\"/>\n" |
| 478 | " </leaf>\n" |
| 479 | " </container>\n" |
| 480 | " <leaf name=\"leaf23\">\n" |
| 481 | " <type name=\"empty\"/>\n" |
| 482 | " </leaf>\n" |
| 483 | " </container>\n" |
| 484 | " <container name=\"test-when\">\n" |
| 485 | " <leaf name=\"when-check\">\n" |
| 486 | " <type name=\"boolean\"/>\n" |
| 487 | " </leaf>\n" |
| 488 | " <leaf name=\"gated-data\">\n" |
| 489 | " <when condition=\"../when-check = 'true'\"/>\n" |
| 490 | " <type name=\"uint16\"/>\n" |
| 491 | " </leaf>\n" |
| 492 | " </container>\n" |
| 493 | " <augment target-node=\"/cont1\">\n" |
| 494 | " <leaf name=\"leaf17\">\n" |
| 495 | " <type name=\"string\"/>\n" |
| 496 | " </leaf>\n" |
| 497 | " </augment>\n" |
| 498 | " <rpc name=\"rpc1\">\n" |
| 499 | " <input>\n" |
| 500 | " <leaf name=\"leaf20\">\n" |
| 501 | " <type name=\"tdef1\"/>\n" |
| 502 | " </leaf>\n" |
| 503 | " </input>\n" |
| 504 | " <output>\n" |
| 505 | " <container name=\"cont2\">\n" |
| 506 | " <leaf name=\"leaf21\">\n" |
| 507 | " <type name=\"empty\"/>\n" |
| 508 | " </leaf>\n" |
| 509 | " </container>\n" |
| 510 | " </output>\n" |
| 511 | " </rpc>\n" |
| 512 | "</module>\n"; |
| 513 | |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 514 | char *printed; |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 515 | struct ly_out *out; |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 516 | |
Radek Krejci | 84ce7b1 | 2020-06-11 17:28:25 +0200 | [diff] [blame] | 517 | assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out)); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 518 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 519 | UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 520 | assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YIN, 0, 0)); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 521 | assert_int_equal(strlen(ori_res), ly_out_printed(out)); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 522 | assert_string_equal(printed, ori_res); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 523 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 524 | ly_out_free(out, NULL, 1); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 525 | } |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 526 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 527 | static LY_ERR |
| 528 | test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name), |
| 529 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 530 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 531 | { |
| 532 | *module_data = user_data; |
| 533 | *format = LYS_IN_YIN; |
| 534 | *free_module_data = NULL; |
| 535 | return LY_SUCCESS; |
| 536 | } |
| 537 | |
| 538 | static void |
| 539 | test_submodule(void **state) |
| 540 | { |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 541 | const struct lys_module *mod; |
| 542 | |
| 543 | const char *mod_yin = |
| 544 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 545 | "<module name=\"a\"\n" |
| 546 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 547 | " xmlns:a_mod=\"urn:a\">\n" |
| 548 | " <yang-version value=\"1.1\"/>\n" |
| 549 | " <namespace uri=\"urn:a\"/>\n" |
| 550 | " <prefix value=\"a_mod\"/>\n" |
| 551 | " <include module=\"a-sub\"/>\n" |
| 552 | "</module>\n"; |
| 553 | |
| 554 | char *submod_yin = |
| 555 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 556 | "<submodule name=\"a-sub\"\n" |
| 557 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n" |
| 558 | " xmlns:a_mod=\"urn:a\"\n" |
| 559 | " xmlns:yt=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">\n" |
| 560 | " <yang-version value=\"1.1\"/>\n" |
| 561 | " <belongs-to module=\"a\">\n" |
| 562 | " <prefix value=\"a_mod\"/>\n" |
| 563 | " </belongs-to>\n" |
| 564 | " <import module=\"ietf-yang-types\">\n" |
| 565 | " <prefix value=\"yt\"/>\n" |
| 566 | " <revision-date date=\"2013-07-15\"/>\n" |
| 567 | " </import>\n\n" |
| 568 | " <description>\n" |
| 569 | " <text>YANG types</text>\n" |
| 570 | " </description>\n" |
| 571 | " <reference>\n" |
| 572 | " <text>RFC reference</text>\n" |
| 573 | " </reference>\n" |
| 574 | "</submodule>\n"; |
| 575 | |
| 576 | char *printed; |
| 577 | struct ly_out *out; |
| 578 | |
| 579 | assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out)); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 580 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 581 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod_yin); |
| 582 | |
| 583 | UTEST_ADD_MODULE(mod_yin, LYS_IN_YIN, NULL, &mod); |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame^] | 584 | assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod->parsed->includes[0].submodule, LYS_OUT_YIN, 0, 0)); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 585 | assert_int_equal(strlen(submod_yin), ly_out_printed(out)); |
| 586 | assert_string_equal(printed, submod_yin); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 587 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 588 | ly_out_free(out, NULL, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 589 | } |
| 590 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 591 | int |
| 592 | main(void) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 593 | { |
| 594 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 595 | UTEST(test_module), |
| 596 | UTEST(test_submodule), |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 600 | } |