Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 10 | #include <experimental/iterator> |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 11 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 12 | #include "pretty_printers.hpp" |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 13 | #include "yang_schema.hpp" |
| 14 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 15 | const char* second_schema = R"( |
| 16 | module second-schema { |
| 17 | namespace "http://example.com/nevim"; |
| 18 | prefix second; |
| 19 | |
| 20 | import example-schema { |
| 21 | prefix "example"; |
| 22 | } |
| 23 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 24 | identity pineapple { |
| 25 | base "example:fruit"; |
| 26 | } |
| 27 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 28 | augment /example:a { |
| 29 | container augmentedContainer { |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | container bla { |
| 34 | container bla2 { |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | )"; |
| 39 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 40 | const char* included_submodule = R"( |
| 41 | submodule sub-module { |
| 42 | yang-version 1.1; |
| 43 | |
| 44 | belongs-to example-schema { |
| 45 | prefix sub; |
| 46 | } |
| 47 | |
| 48 | leaf subLeaf { |
| 49 | type string; |
| 50 | } |
| 51 | } |
| 52 | )"; |
| 53 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 54 | const char* example_schema = R"( |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 55 | module example-schema { |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 56 | yang-version 1.1; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 57 | namespace "http://example.com/example-sports"; |
| 58 | prefix coze; |
| 59 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 60 | include sub-module; |
| 61 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 62 | identity drink { |
| 63 | } |
| 64 | |
| 65 | identity voda { |
| 66 | base "drink"; |
| 67 | } |
| 68 | |
| 69 | identity food { |
| 70 | } |
| 71 | |
| 72 | identity fruit { |
| 73 | base "food"; |
| 74 | } |
| 75 | |
| 76 | identity pizza { |
| 77 | base "food"; |
| 78 | } |
| 79 | |
| 80 | identity hawaii { |
| 81 | base "pizza"; |
| 82 | } |
| 83 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 84 | container a { |
| 85 | container a2 { |
| 86 | container a3 { |
| 87 | presence true; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | leaf leafa { |
| 92 | type string; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | container b { |
| 97 | container b2 { |
| 98 | presence true; |
| 99 | container b3 { |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | leaf leafString { |
| 105 | type string; |
| 106 | } |
| 107 | |
| 108 | leaf leafDecimal { |
| 109 | type decimal64 { |
| 110 | fraction-digits 5; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | leaf leafBool { |
| 115 | type boolean; |
| 116 | } |
| 117 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 118 | leaf leafInt8 { |
| 119 | type int8; |
| 120 | } |
| 121 | |
| 122 | leaf leafUint8 { |
| 123 | type uint8; |
| 124 | } |
| 125 | |
| 126 | leaf leafInt16 { |
| 127 | type int16; |
| 128 | } |
| 129 | |
| 130 | leaf leafUint16 { |
| 131 | type uint16; |
| 132 | } |
| 133 | |
| 134 | leaf leafInt32 { |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 135 | description "A 32-bit integer leaf."; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 136 | type int32; |
| 137 | } |
| 138 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 139 | leaf leafUint32 { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 140 | type uint32; |
| 141 | } |
| 142 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 143 | leaf leafInt64 { |
| 144 | type int64; |
| 145 | } |
| 146 | |
| 147 | leaf leafUint64 { |
| 148 | type uint64; |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 149 | default 9001; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 152 | leaf leafEnum { |
| 153 | type enumeration { |
| 154 | enum lol; |
| 155 | enum data; |
| 156 | enum coze; |
| 157 | } |
| 158 | } |
| 159 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 160 | typedef enumTypedef { |
| 161 | type enumeration { |
| 162 | enum lol; |
| 163 | enum data; |
| 164 | enum coze; |
| 165 | } |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 166 | default data; |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | typedef enumTypedefRestricted { |
| 170 | type enumTypedef { |
| 171 | enum lol; |
| 172 | enum data; |
| 173 | } |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 174 | description "This is a restricted enum typedef."; |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | leaf leafEnumTypedef { |
| 178 | type enumTypedef; |
| 179 | } |
| 180 | |
| 181 | leaf leafEnumTypedefRestricted { |
| 182 | type enumTypedef { |
| 183 | enum data; |
| 184 | enum coze; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | leaf leafEnumTypedefRestricted2 { |
| 189 | type enumTypedefRestricted; |
| 190 | } |
| 191 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 192 | leaf foodIdentLeaf { |
| 193 | type identityref { |
| 194 | base "food"; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | leaf pizzaIdentLeaf { |
| 199 | type identityref { |
| 200 | base "pizza"; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | leaf foodDrinkIdentLeaf { |
| 205 | type identityref { |
| 206 | base "food"; |
| 207 | base "drink"; |
| 208 | } |
| 209 | } |
| 210 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 211 | list _list { |
| 212 | key number; |
| 213 | |
| 214 | leaf number { |
| 215 | type int32; |
| 216 | } |
| 217 | |
| 218 | container contInList { |
| 219 | presence true; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | list twoKeyList { |
| 224 | key "name number"; |
| 225 | |
| 226 | leaf number { |
| 227 | type int32; |
| 228 | } |
| 229 | |
| 230 | leaf name { |
| 231 | type string; |
| 232 | } |
| 233 | } |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 234 | |
| 235 | grouping arithmeticFlags { |
| 236 | leaf carry { |
| 237 | type boolean; |
| 238 | } |
| 239 | leaf zero { |
| 240 | type boolean; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | grouping flags { |
| 245 | leaf direction { |
| 246 | type boolean; |
| 247 | } |
| 248 | leaf interrupt { |
| 249 | type boolean; |
| 250 | } |
| 251 | |
| 252 | uses arithmeticFlags; |
| 253 | } |
| 254 | |
| 255 | uses flags; |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 256 | |
| 257 | choice interface { |
| 258 | case caseLoopback { |
| 259 | container loopback { |
| 260 | leaf ip { |
| 261 | type string; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | case caseEthernet { |
| 267 | container ethernet { |
| 268 | leaf ip { |
| 269 | type string; |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
Václav Kubernát | a38d417 | 2019-11-04 12:36:39 +0100 | [diff] [blame] | 275 | feature bigPizzas; |
| 276 | |
| 277 | leaf pizzaSize { |
| 278 | type enumeration { |
| 279 | enum large { |
| 280 | if-feature "bigPizzas"; |
| 281 | } |
| 282 | enum medium; |
| 283 | enum small; |
| 284 | } |
| 285 | } |
| 286 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 287 | leaf length { |
| 288 | type int32; |
| 289 | units "m"; |
| 290 | } |
| 291 | |
| 292 | leaf wavelength { |
| 293 | type decimal64 { |
| 294 | fraction-digits 10; |
| 295 | } |
| 296 | units "nm"; |
| 297 | } |
| 298 | |
| 299 | typedef seconds { |
| 300 | type int32; |
| 301 | units "s"; |
| 302 | } |
| 303 | |
| 304 | leaf duration { |
| 305 | type seconds; |
| 306 | } |
| 307 | |
| 308 | leaf another-duration { |
| 309 | type seconds; |
| 310 | units "vt"; |
| 311 | } |
| 312 | |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 313 | leaf activeNumber { |
| 314 | type leafref { |
| 315 | path "/_list/number"; |
| 316 | } |
| 317 | } |
| 318 | |
Václav Kubernát | fa81c8c | 2020-02-13 17:22:46 +0100 | [diff] [blame] | 319 | rpc myRpc {} |
| 320 | |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 321 | rpc rpcOneOutput { |
| 322 | output { |
| 323 | leaf ahoj { |
| 324 | type string; |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | rpc rpcOneInput { |
| 330 | input { |
| 331 | leaf ahoj { |
| 332 | type string; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 337 | leaf numberOrString { |
| 338 | type union { |
| 339 | type int32; |
| 340 | type string; |
| 341 | } |
| 342 | description "Can be an int32 or a string."; |
| 343 | } |
| 344 | |
| 345 | list portSettings { |
| 346 | key "port"; |
| 347 | leaf port { |
| 348 | type enumeration { |
| 349 | enum eth0; |
| 350 | enum eth1; |
| 351 | enum eth2; |
| 352 | } |
| 353 | } |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 354 | action shutdown { |
| 355 | output { |
| 356 | leaf success { |
| 357 | type boolean; |
| 358 | } |
| 359 | } |
| 360 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | feature weirdPortNames; |
| 364 | |
| 365 | list portMapping { |
| 366 | key "port"; |
| 367 | leaf port { |
| 368 | type enumeration { |
| 369 | enum WEIRD { |
| 370 | if-feature "weirdPortNames"; |
| 371 | } |
| 372 | enum utf2; |
| 373 | enum utf3; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | leaf activeMappedPort { |
| 379 | type leafref { |
| 380 | path "../portMapping/port"; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | leaf activePort { |
| 385 | type union { |
| 386 | type enumeration { |
| 387 | enum wlan0; |
| 388 | enum wlan1; |
| 389 | } |
| 390 | type leafref { |
| 391 | path "../portSettings/port"; |
| 392 | } |
| 393 | type leafref { |
| 394 | path "../activeMappedPort"; |
| 395 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 396 | type empty; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 400 | leaf dummyLeaf { |
| 401 | type empty; |
| 402 | } |
| 403 | |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 404 | leaf clockSpeed { |
| 405 | type int64; |
| 406 | config false; |
| 407 | } |
| 408 | |
| 409 | container systemStats { |
| 410 | config false; |
| 411 | leaf upTime { |
| 412 | type uint64; |
| 413 | } |
| 414 | } |
| 415 | |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 416 | leaf obsoleteLeaf { |
| 417 | type int32; |
| 418 | status obsolete; |
| 419 | } |
| 420 | |
| 421 | leaf deprecatedLeaf { |
| 422 | type int32; |
| 423 | status deprecated; |
| 424 | } |
| 425 | |
| 426 | typedef deprecatedType { |
| 427 | type int32; |
| 428 | status deprecated; |
| 429 | } |
| 430 | |
| 431 | leaf obsoleteLeafWithDeprecatedType { |
| 432 | type deprecatedType; |
| 433 | status obsolete; |
| 434 | } |
| 435 | |
| 436 | typedef obsoleteType { |
| 437 | type int32; |
| 438 | status obsolete; |
| 439 | } |
| 440 | |
| 441 | leaf obsoleteLeafWithObsoleteType { |
| 442 | type deprecatedType; |
| 443 | status obsolete; |
| 444 | } |
| 445 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 446 | leaf-list addresses { |
| 447 | type string; |
| 448 | } |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 449 | |
| 450 | leaf flagBits { |
| 451 | type bits { |
| 452 | bit carry; |
| 453 | bit sign; |
| 454 | bit overflow; |
| 455 | } |
| 456 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 457 | })"; |
| 458 | |
| 459 | TEST_CASE("yangschema") |
| 460 | { |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 461 | using namespace std::string_literals; |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 462 | using namespace std::string_view_literals; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 463 | YangSchema ys; |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 464 | ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) { |
| 465 | if (modName != "example-schema"sv) { |
| 466 | throw std::logic_error("unrecognized module "s + modName); |
| 467 | } |
| 468 | if (subModule == nullptr) { |
| 469 | return example_schema; |
| 470 | } |
| 471 | if (subModule == "sub-module"sv) { |
| 472 | return included_submodule; |
| 473 | } |
| 474 | |
| 475 | throw std::logic_error("unrecognized submodule "s + subModule); |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 476 | }); |
| 477 | ys.addSchemaString(second_schema); |
| 478 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 479 | schemaPath_ path{Scope::Absolute, {}}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 480 | ModuleNodePair node; |
| 481 | |
| 482 | SECTION("positive") |
| 483 | { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 484 | SECTION("isModule") |
| 485 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 486 | REQUIRE(ys.isModule("example-schema")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 487 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 488 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 489 | SECTION("listHasKey") |
| 490 | { |
| 491 | std::string key; |
| 492 | |
| 493 | SECTION("_list") |
| 494 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 495 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 496 | SECTION("number") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 497 | { |
| 498 | key = "number"; |
| 499 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | SECTION("twoKeyList") |
| 503 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 504 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 505 | SECTION("number") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 506 | { |
| 507 | key = "number"; |
| 508 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 509 | SECTION("name") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 510 | { |
| 511 | key = "name"; |
| 512 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 515 | REQUIRE(ys.listHasKey(path, key)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 516 | } |
| 517 | SECTION("listKeys") |
| 518 | { |
| 519 | std::set<std::string> set; |
| 520 | |
| 521 | SECTION("_list") |
| 522 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 523 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 524 | set = {"number"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | SECTION("twoKeyList") |
| 528 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 529 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 530 | set = {"number", "name"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 533 | REQUIRE(ys.listKeys(path) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 534 | } |
| 535 | SECTION("leafType") |
| 536 | { |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 537 | yang::LeafDataType type; |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 538 | std::optional<std::string> expectedDescription; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 539 | |
| 540 | SECTION("leafString") |
| 541 | { |
| 542 | node.first = "example-schema"; |
| 543 | node.second = "leafString"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 544 | type = yang::String{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | SECTION("leafDecimal") |
| 548 | { |
| 549 | node.first = "example-schema"; |
| 550 | node.second = "leafDecimal"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 551 | type = yang::Decimal{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | SECTION("leafBool") |
| 555 | { |
| 556 | node.first = "example-schema"; |
| 557 | node.second = "leafBool"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 558 | type = yang::Bool{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 561 | SECTION("leafInt8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 562 | { |
| 563 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 564 | node.second = "leafInt8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 565 | type = yang::Int8{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 566 | } |
| 567 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 568 | SECTION("leafUint8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 569 | { |
| 570 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 571 | node.second = "leafUint8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 572 | type = yang::Uint8{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 575 | SECTION("leafInt16") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 576 | { |
| 577 | node.first = "example-schema"; |
| 578 | node.second = "leafInt16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 579 | type = yang::Int16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | SECTION("leafUint16") |
| 583 | { |
| 584 | node.first = "example-schema"; |
| 585 | node.second = "leafUint16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 586 | type = yang::Uint16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | SECTION("leafInt32") |
| 590 | { |
| 591 | node.first = "example-schema"; |
| 592 | node.second = "leafInt32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 593 | type = yang::Int32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | SECTION("leafUint32") |
| 597 | { |
| 598 | node.first = "example-schema"; |
| 599 | node.second = "leafUint32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 600 | type = yang::Uint32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | SECTION("leafInt64") |
| 604 | { |
| 605 | node.first = "example-schema"; |
| 606 | node.second = "leafInt64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 607 | type = yang::Int64{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | SECTION("leafUint64") |
| 611 | { |
| 612 | node.first = "example-schema"; |
| 613 | node.second = "leafUint64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 614 | type = yang::Uint64{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | SECTION("leafEnum") |
| 618 | { |
| 619 | node.first = "example-schema"; |
| 620 | node.second = "leafEnum"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 621 | type = createEnum({"lol", "data", "coze"}); |
| 622 | } |
| 623 | |
| 624 | SECTION("leafEnumTypedef") |
| 625 | { |
| 626 | node.first = "example-schema"; |
| 627 | node.second = "leafEnumTypedef"; |
| 628 | type = createEnum({"lol", "data", "coze"}); |
| 629 | } |
| 630 | |
| 631 | SECTION("leafEnumTypedefRestricted") |
| 632 | { |
| 633 | node.first = "example-schema"; |
| 634 | node.second = "leafEnumTypedefRestricted"; |
| 635 | type = createEnum({"data", "coze"}); |
| 636 | } |
| 637 | |
| 638 | SECTION("leafEnumTypedefRestricted2") |
| 639 | { |
| 640 | node.first = "example-schema"; |
| 641 | node.second = "leafEnumTypedefRestricted2"; |
| 642 | type = createEnum({"lol", "data"}); |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 643 | expectedDescription = "This is a restricted enum typedef."; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | SECTION("pizzaSize") |
| 647 | { |
| 648 | node.first = "example-schema"; |
| 649 | node.second = "pizzaSize"; |
| 650 | |
| 651 | SECTION("bigPizzas disabled") |
| 652 | { |
| 653 | type = createEnum({"small", "medium"}); |
| 654 | } |
| 655 | SECTION("bigPizzas enabled") |
| 656 | { |
| 657 | ys.enableFeature("example-schema", "bigPizzas"); |
| 658 | type = createEnum({"small", "medium", "large"}); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | SECTION("foodIdentLeaf") |
| 663 | { |
| 664 | node.first = "example-schema"; |
| 665 | node.second = "foodIdentLeaf"; |
| 666 | type = yang::IdentityRef{{{"second-schema", "pineapple"}, |
| 667 | {"example-schema", "food"}, |
| 668 | {"example-schema", "pizza"}, |
| 669 | {"example-schema", "hawaii"}, |
| 670 | {"example-schema", "fruit"}}}; |
| 671 | } |
| 672 | |
| 673 | SECTION("pizzaIdentLeaf") |
| 674 | { |
| 675 | node.first = "example-schema"; |
| 676 | node.second = "pizzaIdentLeaf"; |
| 677 | |
| 678 | type = yang::IdentityRef{{ |
| 679 | {"example-schema", "pizza"}, |
| 680 | {"example-schema", "hawaii"}, |
| 681 | }}; |
| 682 | } |
| 683 | |
| 684 | SECTION("foodDrinkIdentLeaf") |
| 685 | { |
| 686 | node.first = "example-schema"; |
| 687 | node.second = "foodDrinkIdentLeaf"; |
| 688 | |
| 689 | type = yang::IdentityRef{{ |
| 690 | {"example-schema", "food"}, |
| 691 | {"example-schema", "drink"}, |
| 692 | {"example-schema", "fruit"}, |
| 693 | {"example-schema", "hawaii"}, |
| 694 | {"example-schema", "pizza"}, |
| 695 | {"example-schema", "voda"}, |
| 696 | {"second-schema", "pineapple"}, |
| 697 | }}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 698 | } |
| 699 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 700 | SECTION("activeNumber") |
| 701 | { |
| 702 | node.first = "example-schema"; |
| 703 | node.second = "activeNumber"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 704 | type.emplace<yang::LeafRef>( |
| 705 | "/example-schema:_list/number", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 706 | std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number")) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 707 | ); |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 710 | SECTION("activePort") |
| 711 | { |
| 712 | node.first = "example-schema"; |
| 713 | node.second = "activePort"; |
| 714 | |
Václav Kubernát | 1dc9e3e | 2020-06-09 15:22:39 +0200 | [diff] [blame] | 715 | yang::Enum enums({}); |
| 716 | SECTION("weird ports disabled") |
| 717 | { |
| 718 | enums = createEnum({"utf2", "utf3"}); |
| 719 | } |
| 720 | SECTION("weird ports enabled") |
| 721 | { |
| 722 | ys.enableFeature("example-schema", "weirdPortNames"); |
| 723 | enums = createEnum({"WEIRD", "utf2", "utf3"}); |
| 724 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 725 | |
| 726 | type = yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 727 | yang::TypeInfo{createEnum({"wlan0", "wlan1"})}, |
| 728 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 729 | "/example-schema:portSettings/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 730 | std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"})) |
| 731 | }}, |
| 732 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 733 | "/example-schema:activeMappedPort", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 734 | std::make_unique<yang::TypeInfo>(yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 735 | "/example-schema:portMapping/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 736 | std::make_unique<yang::TypeInfo>(enums) |
| 737 | }) |
| 738 | }}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 739 | yang::TypeInfo{yang::Empty{}}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 740 | }}; |
| 741 | } |
| 742 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 743 | SECTION("addresses") |
| 744 | { |
| 745 | node.first = "example-schema"; |
| 746 | node.second = "addresses"; |
| 747 | type.emplace<yang::String>(); |
| 748 | } |
| 749 | |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 750 | SECTION("flagBits") |
| 751 | { |
| 752 | node.first = "example-schema"; |
| 753 | node.second = "flagBits"; |
| 754 | type = yang::Bits{{"carry", "sign", "overflow"}}; |
| 755 | } |
| 756 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 757 | |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 758 | REQUIRE(ys.leafType(path, node) == yang::TypeInfo(type, std::nullopt, expectedDescription)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 759 | } |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 760 | SECTION("availableNodes") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 761 | { |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 762 | // TODO: merge "path" and "module" sections and add recursive versions to the path section |
| 763 | SECTION("paths") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 764 | { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 765 | std::set<ModuleNodePair> set; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 766 | |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 767 | using namespace std::string_literals; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 768 | SECTION("<root>") |
| 769 | { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 770 | set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"}, |
| 771 | {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"}, |
| 772 | {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"}, |
| 773 | {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"}, |
| 774 | {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"}, |
| 775 | {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"}, |
| 776 | {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"}, |
| 777 | {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"}, |
| 778 | {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"}, |
| 779 | {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"}, |
| 780 | {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"}, |
| 781 | {"example-schema"s, "interrupt"}, |
| 782 | {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"}, |
| 783 | {"example-schema"s, "pizzaSize"}, |
| 784 | {"example-schema"s, "length"}, {"example-schema"s, "wavelength"}, |
| 785 | {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"}, |
| 786 | {"example-schema"s, "activeNumber"}, |
| 787 | {"example-schema"s, "numberOrString"}, |
| 788 | {"example-schema"s, "portSettings"}, |
| 789 | {"example-schema"s, "portMapping"}, |
| 790 | {"example-schema"s, "activeMappedPort"}, |
| 791 | {"example-schema"s, "activePort"}, |
| 792 | {"example-schema"s, "clockSpeed"}, |
| 793 | {"example-schema"s, "deprecatedLeaf"}, |
| 794 | {"example-schema"s, "obsoleteLeaf"}, |
| 795 | {"example-schema"s, "obsoleteLeafWithDeprecatedType"}, |
| 796 | {"example-schema"s, "obsoleteLeafWithObsoleteType"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 797 | {"example-schema"s, "myRpc"}, |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 798 | {"example-schema"s, "rpcOneOutput"}, |
| 799 | {"example-schema"s, "rpcOneInput"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 800 | {"example-schema"s, "systemStats"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 801 | {"example-schema"s, "dummyLeaf"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 802 | {"example-schema"s, "addresses"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 803 | {"example-schema"s, "subLeaf"}, |
| 804 | {"example-schema"s, "flagBits"}}; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | SECTION("example-schema:a") |
| 808 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 809 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 810 | set = { |
| 811 | {boost::none, "a2"}, |
| 812 | {boost::none, "leafa"}, |
| 813 | {"second-schema"s, "augmentedContainer"} |
| 814 | }; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | SECTION("example-schema:ethernet") |
| 818 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 819 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 820 | set = {{boost::none, "ip"}}; |
| 821 | } |
| 822 | |
| 823 | SECTION("second-schema:bla") |
| 824 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 825 | path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 826 | set = {{boost::none, "bla2"}}; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 830 | } |
| 831 | |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 832 | SECTION("modules") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 833 | { |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 834 | std::string module; |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 835 | std::set<ModuleNodePair> expectedNonRecursive; |
| 836 | std::set<ModuleNodePair> expectedRecursive; |
| 837 | using namespace std::string_literals; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 838 | SECTION("example-schema") |
| 839 | { |
| 840 | module = "example-schema"; |
| 841 | expectedNonRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 842 | {"example-schema"s, "_list"}, |
| 843 | {"example-schema"s, "a"}, |
| 844 | {"example-schema"s, "activeMappedPort"}, |
| 845 | {"example-schema"s, "activeNumber"}, |
| 846 | {"example-schema"s, "activePort"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 847 | {"example-schema"s, "addresses"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 848 | {"example-schema"s, "another-duration"}, |
| 849 | {"example-schema"s, "b"}, |
| 850 | {"example-schema"s, "carry"}, |
| 851 | {"example-schema"s, "clockSpeed"}, |
| 852 | {"example-schema"s, "deprecatedLeaf"}, |
| 853 | {"example-schema"s, "direction"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 854 | {"example-schema"s, "dummyLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 855 | {"example-schema"s, "duration"}, |
| 856 | {"example-schema"s, "ethernet"}, |
| 857 | {"example-schema"s, "foodDrinkIdentLeaf"}, |
| 858 | {"example-schema"s, "foodIdentLeaf"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 859 | {"example-schema"s, "flagBits"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 860 | {"example-schema"s, "interrupt"}, |
| 861 | {"example-schema"s, "leafBool"}, |
| 862 | {"example-schema"s, "leafDecimal"}, |
| 863 | {"example-schema"s, "leafEnum"}, |
| 864 | {"example-schema"s, "leafEnumTypedef"}, |
| 865 | {"example-schema"s, "leafEnumTypedefRestricted"}, |
| 866 | {"example-schema"s, "leafEnumTypedefRestricted2"}, |
| 867 | {"example-schema"s, "leafInt16"}, |
| 868 | {"example-schema"s, "leafInt32"}, |
| 869 | {"example-schema"s, "leafInt64"}, |
| 870 | {"example-schema"s, "leafInt8"}, |
| 871 | {"example-schema"s, "leafString"}, |
| 872 | {"example-schema"s, "leafUint16"}, |
| 873 | {"example-schema"s, "leafUint32"}, |
| 874 | {"example-schema"s, "leafUint64"}, |
| 875 | {"example-schema"s, "leafUint8"}, |
| 876 | {"example-schema"s, "length"}, |
| 877 | {"example-schema"s, "loopback"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 878 | {"example-schema"s, "myRpc"}, |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 879 | {"example-schema"s, "rpcOneOutput"}, |
| 880 | {"example-schema"s, "rpcOneInput"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 881 | {"example-schema"s, "numberOrString"}, |
| 882 | {"example-schema"s, "obsoleteLeaf"}, |
| 883 | {"example-schema"s, "obsoleteLeafWithDeprecatedType"}, |
| 884 | {"example-schema"s, "obsoleteLeafWithObsoleteType"}, |
| 885 | {"example-schema"s, "pizzaIdentLeaf"}, |
| 886 | {"example-schema"s, "pizzaSize"}, |
| 887 | {"example-schema"s, "portMapping"}, |
| 888 | {"example-schema"s, "portSettings"}, |
| 889 | {"example-schema"s, "systemStats"}, |
| 890 | {"example-schema"s, "twoKeyList"}, |
| 891 | {"example-schema"s, "wavelength"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 892 | {"example-schema"s, "zero"}, |
| 893 | {"example-schema"s, "subLeaf"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 894 | }; |
| 895 | expectedRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 896 | {boost::none, "/example-schema:_list"}, |
| 897 | {boost::none, "/example-schema:_list/contInList"}, |
| 898 | {boost::none, "/example-schema:_list/number"}, |
| 899 | {boost::none, "/example-schema:a"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 900 | {boost::none, "/example-schema:addresses"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 901 | {boost::none, "/example-schema:a/a2"}, |
| 902 | {boost::none, "/example-schema:a/a2/a3"}, |
| 903 | {boost::none, "/example-schema:a/leafa"}, |
| 904 | {boost::none, "/example-schema:a/second-schema:augmentedContainer"}, |
| 905 | {boost::none, "/example-schema:activeMappedPort"}, |
| 906 | {boost::none, "/example-schema:activeNumber"}, |
| 907 | {boost::none, "/example-schema:activePort"}, |
| 908 | {boost::none, "/example-schema:another-duration"}, |
| 909 | {boost::none, "/example-schema:b"}, |
| 910 | {boost::none, "/example-schema:b/b2"}, |
| 911 | {boost::none, "/example-schema:b/b2/b3"}, |
| 912 | {boost::none, "/example-schema:carry"}, |
| 913 | {boost::none, "/example-schema:clockSpeed"}, |
| 914 | {boost::none, "/example-schema:deprecatedLeaf"}, |
| 915 | {boost::none, "/example-schema:direction"}, |
| 916 | {boost::none, "/example-schema:duration"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 917 | {boost::none, "/example-schema:dummyLeaf"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 918 | {boost::none, "/example-schema:flagBits"}, |
| 919 | {boost::none, "/example-schema:foodDrinkIdentLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 920 | {boost::none, "/example-schema:foodDrinkIdentLeaf"}, |
| 921 | {boost::none, "/example-schema:foodIdentLeaf"}, |
| 922 | {boost::none, "/example-schema:interface/caseEthernet/ethernet"}, |
| 923 | {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"}, |
| 924 | {boost::none, "/example-schema:interface/caseLoopback/loopback"}, |
| 925 | {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"}, |
| 926 | {boost::none, "/example-schema:interrupt"}, |
| 927 | {boost::none, "/example-schema:leafBool"}, |
| 928 | {boost::none, "/example-schema:leafDecimal"}, |
| 929 | {boost::none, "/example-schema:leafEnum"}, |
| 930 | {boost::none, "/example-schema:leafEnumTypedef"}, |
| 931 | {boost::none, "/example-schema:leafEnumTypedefRestricted"}, |
| 932 | {boost::none, "/example-schema:leafEnumTypedefRestricted2"}, |
| 933 | {boost::none, "/example-schema:leafInt16"}, |
| 934 | {boost::none, "/example-schema:leafInt32"}, |
| 935 | {boost::none, "/example-schema:leafInt64"}, |
| 936 | {boost::none, "/example-schema:leafInt8"}, |
| 937 | {boost::none, "/example-schema:leafString"}, |
| 938 | {boost::none, "/example-schema:leafUint16"}, |
| 939 | {boost::none, "/example-schema:leafUint32"}, |
| 940 | {boost::none, "/example-schema:leafUint64"}, |
| 941 | {boost::none, "/example-schema:leafUint8"}, |
| 942 | {boost::none, "/example-schema:length"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 943 | {boost::none, "/example-schema:myRpc"}, |
| 944 | {boost::none, "/example-schema:myRpc/input"}, |
| 945 | {boost::none, "/example-schema:myRpc/output"}, |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 946 | {boost::none, "/example-schema:rpcOneOutput"}, |
| 947 | {boost::none, "/example-schema:rpcOneOutput/input"}, |
| 948 | {boost::none, "/example-schema:rpcOneOutput/output"}, |
| 949 | {boost::none, "/example-schema:rpcOneOutput/output/ahoj"}, |
| 950 | {boost::none, "/example-schema:rpcOneInput"}, |
| 951 | {boost::none, "/example-schema:rpcOneInput/input"}, |
| 952 | {boost::none, "/example-schema:rpcOneInput/input/ahoj"}, |
| 953 | {boost::none, "/example-schema:rpcOneInput/output"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 954 | {boost::none, "/example-schema:numberOrString"}, |
| 955 | {boost::none, "/example-schema:obsoleteLeaf"}, |
| 956 | {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"}, |
| 957 | {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"}, |
| 958 | {boost::none, "/example-schema:pizzaIdentLeaf"}, |
| 959 | {boost::none, "/example-schema:pizzaSize"}, |
| 960 | {boost::none, "/example-schema:portMapping"}, |
| 961 | {boost::none, "/example-schema:portMapping/port"}, |
| 962 | {boost::none, "/example-schema:portSettings"}, |
| 963 | {boost::none, "/example-schema:portSettings/port"}, |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 964 | {boost::none, "/example-schema:portSettings/shutdown"}, |
| 965 | {boost::none, "/example-schema:portSettings/shutdown/input"}, |
| 966 | {boost::none, "/example-schema:portSettings/shutdown/output"}, |
| 967 | {boost::none, "/example-schema:portSettings/shutdown/output/success"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 968 | {boost::none, "/example-schema:systemStats"}, |
| 969 | {boost::none, "/example-schema:systemStats/upTime"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 970 | {boost::none, "/example-schema:subLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 971 | {boost::none, "/example-schema:twoKeyList"}, |
| 972 | {boost::none, "/example-schema:twoKeyList/name"}, |
| 973 | {boost::none, "/example-schema:twoKeyList/number"}, |
| 974 | {boost::none, "/example-schema:wavelength"}, |
| 975 | {boost::none, "/example-schema:zero"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 976 | }; |
| 977 | } |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 978 | SECTION("second-schema") |
| 979 | { |
| 980 | module = "second-schema"; |
| 981 | expectedNonRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 982 | {"second-schema"s, "bla"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 983 | }; |
| 984 | expectedRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 985 | {boost::none, "/second-schema:bla"}, |
| 986 | {boost::none, "/second-schema:bla/bla2"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 987 | }; |
| 988 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 989 | |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 990 | REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive); |
| 991 | REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive); |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 992 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 993 | } |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 994 | SECTION("nodeType") |
| 995 | { |
| 996 | yang::NodeTypes expected; |
| 997 | SECTION("leafInt32") |
| 998 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 999 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 1000 | expected = yang::NodeTypes::Leaf; |
| 1001 | } |
| 1002 | |
| 1003 | SECTION("a") |
| 1004 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1005 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 1006 | expected = yang::NodeTypes::Container; |
| 1007 | } |
| 1008 | |
| 1009 | SECTION("a/a2/a3") |
| 1010 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1011 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1012 | path.m_nodes.emplace_back(container_("a2")); |
| 1013 | path.m_nodes.emplace_back(container_("a3")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 1014 | expected = yang::NodeTypes::PresenceContainer; |
| 1015 | } |
| 1016 | |
| 1017 | SECTION("_list") |
| 1018 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1019 | path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 1020 | expected = yang::NodeTypes::List; |
| 1021 | } |
| 1022 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 1023 | SECTION("subLeaf") |
| 1024 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1025 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf")); |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 1026 | expected = yang::NodeTypes::Leaf; |
| 1027 | } |
| 1028 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 1029 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1030 | } |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1031 | |
| 1032 | SECTION("description") |
| 1033 | { |
| 1034 | std::optional<std::string> expected; |
| 1035 | SECTION("leafInt32") |
| 1036 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1037 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1038 | expected = "A 32-bit integer leaf."; |
| 1039 | } |
| 1040 | |
| 1041 | SECTION("leafString") |
| 1042 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1043 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 1046 | SECTION("numberOrString") |
| 1047 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1048 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 1049 | expected = "Can be an int32 or a string."; |
| 1050 | } |
| 1051 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1052 | REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1053 | } |
| 1054 | |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 1055 | SECTION("status") |
| 1056 | { |
| 1057 | REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current); |
| 1058 | REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete); |
| 1059 | REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated); |
| 1060 | REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete); |
| 1061 | REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete); |
| 1062 | } |
| 1063 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1064 | SECTION("units") |
| 1065 | { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1066 | yang::LeafDataType expectedType; |
| 1067 | std::optional<std::string> expectedUnits; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1068 | SECTION("length") |
| 1069 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1070 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1071 | expectedType.emplace<yang::Int32>(); |
| 1072 | expectedUnits = "m"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | SECTION("wavelength") |
| 1076 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1077 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1078 | expectedType.emplace<yang::Decimal>(); |
| 1079 | expectedUnits = "nm"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | SECTION("leafInt32") |
| 1083 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1084 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1085 | expectedType.emplace<yang::Int32>(); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | SECTION("duration") |
| 1089 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1090 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1091 | expectedType.emplace<yang::Int32>(); |
| 1092 | expectedUnits = "s"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | SECTION("another-duration") |
| 1096 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1097 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1098 | expectedType.emplace<yang::Int32>(); |
| 1099 | expectedUnits = "vt"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1100 | } |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 1101 | auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)); |
| 1102 | REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList)); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1103 | REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits}); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 1106 | SECTION("type description") |
| 1107 | { |
| 1108 | yang::LeafDataType expectedType = createEnum({"lol", "data"}); |
| 1109 | std::optional<std::string> expectedDescription; |
| 1110 | |
| 1111 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafEnumTypedefRestricted2")); |
| 1112 | expectedDescription = "This is a restricted enum typedef."; |
| 1113 | REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, std::nullopt, expectedDescription}); |
| 1114 | } |
| 1115 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1116 | SECTION("nodeType") |
| 1117 | { |
| 1118 | yang::NodeTypes expected; |
| 1119 | SECTION("leafInt32") |
| 1120 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1121 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1122 | expected = yang::NodeTypes::Leaf; |
| 1123 | } |
| 1124 | |
| 1125 | SECTION("a") |
| 1126 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1127 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1128 | expected = yang::NodeTypes::Container; |
| 1129 | } |
| 1130 | |
| 1131 | SECTION("a/a2/a3") |
| 1132 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1133 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1134 | path.m_nodes.emplace_back(container_("a2")); |
| 1135 | path.m_nodes.emplace_back(container_("a3")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1136 | expected = yang::NodeTypes::PresenceContainer; |
| 1137 | } |
| 1138 | |
| 1139 | SECTION("_list") |
| 1140 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1141 | path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1142 | expected = yang::NodeTypes::List; |
| 1143 | } |
| 1144 | |
| 1145 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1146 | } |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 1147 | |
| 1148 | SECTION("leafrefPath") |
| 1149 | { |
| 1150 | REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number"); |
| 1151 | } |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 1152 | |
| 1153 | SECTION("isConfig") |
| 1154 | { |
| 1155 | REQUIRE(ys.isConfig("/example-schema:leafInt32")); |
| 1156 | REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed")); |
| 1157 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats")); |
| 1158 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime")); |
| 1159 | } |
Václav Kubernát | bd0d5c8 | 2020-04-21 10:22:03 +0200 | [diff] [blame] | 1160 | |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 1161 | SECTION("defaultValue") |
| 1162 | { |
| 1163 | REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001"); |
| 1164 | REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data"); |
| 1165 | REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt); |
| 1166 | } |
| 1167 | |
Václav Kubernát | 76ba4ec | 2020-05-18 13:26:56 +0200 | [diff] [blame] | 1168 | SECTION("leafTypeName") |
| 1169 | { |
| 1170 | REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef"); |
| 1171 | REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt); |
| 1172 | } |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 1173 | |
| 1174 | SECTION("dataPathToSchemaPath") |
| 1175 | { |
| 1176 | REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings"); |
| 1177 | REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown"); |
| 1178 | } |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 1179 | |
| 1180 | SECTION("has input nodes") |
| 1181 | { |
| 1182 | bool expected; |
| 1183 | SECTION("example-schema:myRpc") |
| 1184 | { |
| 1185 | path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"myRpc"}); |
| 1186 | expected = false; |
| 1187 | } |
| 1188 | |
| 1189 | SECTION("example-schema:rpcOneInput") |
| 1190 | { |
| 1191 | path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"rpcOneInput"}); |
| 1192 | expected = true; |
| 1193 | } |
| 1194 | |
| 1195 | SECTION("example-schema:rpcOneOutput") |
| 1196 | { |
| 1197 | path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"rpcOneOutput"}); |
| 1198 | expected = false; |
| 1199 | } |
| 1200 | |
| 1201 | REQUIRE(ys.hasInputNodes(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1202 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | SECTION("negative") |
| 1206 | { |
| 1207 | SECTION("nonexistent nodes") |
| 1208 | { |
| 1209 | SECTION("example-schema:coze") |
| 1210 | { |
| 1211 | node.first = "example-schema"; |
| 1212 | node.second = "coze"; |
| 1213 | } |
| 1214 | |
| 1215 | SECTION("example-schema:a/nevim") |
| 1216 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1217 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1218 | node.second = "nevim"; |
| 1219 | } |
| 1220 | |
| 1221 | SECTION("modul:a/nevim") |
| 1222 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1223 | path.m_nodes.emplace_back(module_{"modul"}, container_("a")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1224 | node.second = "nevim"; |
| 1225 | } |
| 1226 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1227 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | SECTION("nodetype-specific methods called with different nodetypes") |
| 1231 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1232 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1233 | path.m_nodes.emplace_back(container_("a2")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1234 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 1235 | REQUIRE(!ys.listHasKey(path, "chacha")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | SECTION("nonexistent module") |
| 1239 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 1240 | REQUIRE(!ys.isModule("notAModule")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1241 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 1242 | |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1243 | SECTION("grouping is not a node") |
| 1244 | { |
| 1245 | SECTION("example-schema:arithmeticFlags") |
| 1246 | { |
| 1247 | node.first = "example-schema"; |
| 1248 | node.second = "arithmeticFlags"; |
| 1249 | } |
| 1250 | |
| 1251 | SECTION("example-schema:flags") |
| 1252 | { |
| 1253 | node.first = "example-schema"; |
| 1254 | node.second = "startAndStop"; |
| 1255 | } |
| 1256 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1257 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1258 | } |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1259 | |
| 1260 | SECTION("choice is not a node") |
| 1261 | { |
| 1262 | SECTION("example-schema:interface") |
| 1263 | { |
| 1264 | node.first = "example-schema"; |
| 1265 | node.second = "interface"; |
| 1266 | } |
| 1267 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1268 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | SECTION("case is not a node") |
| 1272 | { |
| 1273 | SECTION("example-schema:caseLoopback") |
| 1274 | { |
| 1275 | node.first = "example-schema"; |
| 1276 | node.second = "caseLoopback"; |
| 1277 | } |
| 1278 | |
| 1279 | SECTION("example-schema:caseEthernet") |
| 1280 | { |
| 1281 | node.first = "example-schema"; |
| 1282 | node.second = "caseEthernet"; |
| 1283 | } |
| 1284 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1285 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1286 | } |
Václav Kubernát | f44bdda | 2020-06-22 15:58:41 +0200 | [diff] [blame] | 1287 | |
| 1288 | SECTION("enableFeature - non existing module") |
| 1289 | { |
| 1290 | REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error); |
| 1291 | } |
Václav Kubernát | 7aaf6dc | 2020-06-26 18:03:57 +0200 | [diff] [blame] | 1292 | |
| 1293 | SECTION("enableFeature - non existing feature") |
| 1294 | { |
| 1295 | REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error); |
| 1296 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1297 | } |
| 1298 | } |