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 | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 321 | leaf numberOrString { |
| 322 | type union { |
| 323 | type int32; |
| 324 | type string; |
| 325 | } |
| 326 | description "Can be an int32 or a string."; |
| 327 | } |
| 328 | |
| 329 | list portSettings { |
| 330 | key "port"; |
| 331 | leaf port { |
| 332 | type enumeration { |
| 333 | enum eth0; |
| 334 | enum eth1; |
| 335 | enum eth2; |
| 336 | } |
| 337 | } |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 338 | action shutdown { |
| 339 | output { |
| 340 | leaf success { |
| 341 | type boolean; |
| 342 | } |
| 343 | } |
| 344 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | feature weirdPortNames; |
| 348 | |
| 349 | list portMapping { |
| 350 | key "port"; |
| 351 | leaf port { |
| 352 | type enumeration { |
| 353 | enum WEIRD { |
| 354 | if-feature "weirdPortNames"; |
| 355 | } |
| 356 | enum utf2; |
| 357 | enum utf3; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | leaf activeMappedPort { |
| 363 | type leafref { |
| 364 | path "../portMapping/port"; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | leaf activePort { |
| 369 | type union { |
| 370 | type enumeration { |
| 371 | enum wlan0; |
| 372 | enum wlan1; |
| 373 | } |
| 374 | type leafref { |
| 375 | path "../portSettings/port"; |
| 376 | } |
| 377 | type leafref { |
| 378 | path "../activeMappedPort"; |
| 379 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 380 | type empty; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 384 | leaf dummyLeaf { |
| 385 | type empty; |
| 386 | } |
| 387 | |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 388 | leaf clockSpeed { |
| 389 | type int64; |
| 390 | config false; |
| 391 | } |
| 392 | |
| 393 | container systemStats { |
| 394 | config false; |
| 395 | leaf upTime { |
| 396 | type uint64; |
| 397 | } |
| 398 | } |
| 399 | |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 400 | leaf obsoleteLeaf { |
| 401 | type int32; |
| 402 | status obsolete; |
| 403 | } |
| 404 | |
| 405 | leaf deprecatedLeaf { |
| 406 | type int32; |
| 407 | status deprecated; |
| 408 | } |
| 409 | |
| 410 | typedef deprecatedType { |
| 411 | type int32; |
| 412 | status deprecated; |
| 413 | } |
| 414 | |
| 415 | leaf obsoleteLeafWithDeprecatedType { |
| 416 | type deprecatedType; |
| 417 | status obsolete; |
| 418 | } |
| 419 | |
| 420 | typedef obsoleteType { |
| 421 | type int32; |
| 422 | status obsolete; |
| 423 | } |
| 424 | |
| 425 | leaf obsoleteLeafWithObsoleteType { |
| 426 | type deprecatedType; |
| 427 | status obsolete; |
| 428 | } |
| 429 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 430 | leaf-list addresses { |
| 431 | type string; |
| 432 | } |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 433 | |
| 434 | leaf flagBits { |
| 435 | type bits { |
| 436 | bit carry; |
| 437 | bit sign; |
| 438 | bit overflow; |
| 439 | } |
| 440 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 441 | })"; |
| 442 | |
| 443 | TEST_CASE("yangschema") |
| 444 | { |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 445 | using namespace std::string_literals; |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 446 | using namespace std::string_view_literals; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 447 | YangSchema ys; |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 448 | ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) { |
| 449 | if (modName != "example-schema"sv) { |
| 450 | throw std::logic_error("unrecognized module "s + modName); |
| 451 | } |
| 452 | if (subModule == nullptr) { |
| 453 | return example_schema; |
| 454 | } |
| 455 | if (subModule == "sub-module"sv) { |
| 456 | return included_submodule; |
| 457 | } |
| 458 | |
| 459 | throw std::logic_error("unrecognized submodule "s + subModule); |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 460 | }); |
| 461 | ys.addSchemaString(second_schema); |
| 462 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 463 | schemaPath_ path{Scope::Absolute, {}}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 464 | ModuleNodePair node; |
| 465 | |
| 466 | SECTION("positive") |
| 467 | { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 468 | SECTION("isModule") |
| 469 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 470 | REQUIRE(ys.isModule("example-schema")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 471 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 472 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 473 | SECTION("listHasKey") |
| 474 | { |
| 475 | std::string key; |
| 476 | |
| 477 | SECTION("_list") |
| 478 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 479 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 480 | SECTION("number") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 481 | { |
| 482 | key = "number"; |
| 483 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | SECTION("twoKeyList") |
| 487 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 488 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 489 | SECTION("number") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 490 | { |
| 491 | key = "number"; |
| 492 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 493 | SECTION("name") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 494 | { |
| 495 | key = "name"; |
| 496 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 499 | REQUIRE(ys.listHasKey(path, key)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 500 | } |
| 501 | SECTION("listKeys") |
| 502 | { |
| 503 | std::set<std::string> set; |
| 504 | |
| 505 | SECTION("_list") |
| 506 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 507 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 508 | set = {"number"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | SECTION("twoKeyList") |
| 512 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 513 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 514 | set = {"number", "name"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 517 | REQUIRE(ys.listKeys(path) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 518 | } |
| 519 | SECTION("leafType") |
| 520 | { |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 521 | yang::LeafDataType type; |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame^] | 522 | std::optional<std::string> expectedDescription; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 523 | |
| 524 | SECTION("leafString") |
| 525 | { |
| 526 | node.first = "example-schema"; |
| 527 | node.second = "leafString"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 528 | type = yang::String{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | SECTION("leafDecimal") |
| 532 | { |
| 533 | node.first = "example-schema"; |
| 534 | node.second = "leafDecimal"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 535 | type = yang::Decimal{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | SECTION("leafBool") |
| 539 | { |
| 540 | node.first = "example-schema"; |
| 541 | node.second = "leafBool"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 542 | type = yang::Bool{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 543 | } |
| 544 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 545 | SECTION("leafInt8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 546 | { |
| 547 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 548 | node.second = "leafInt8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 549 | type = yang::Int8{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 550 | } |
| 551 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 552 | SECTION("leafUint8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 553 | { |
| 554 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 555 | node.second = "leafUint8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 556 | type = yang::Uint8{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 559 | SECTION("leafInt16") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 560 | { |
| 561 | node.first = "example-schema"; |
| 562 | node.second = "leafInt16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 563 | type = yang::Int16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | SECTION("leafUint16") |
| 567 | { |
| 568 | node.first = "example-schema"; |
| 569 | node.second = "leafUint16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 570 | type = yang::Uint16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | SECTION("leafInt32") |
| 574 | { |
| 575 | node.first = "example-schema"; |
| 576 | node.second = "leafInt32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 577 | type = yang::Int32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | SECTION("leafUint32") |
| 581 | { |
| 582 | node.first = "example-schema"; |
| 583 | node.second = "leafUint32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 584 | type = yang::Uint32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | SECTION("leafInt64") |
| 588 | { |
| 589 | node.first = "example-schema"; |
| 590 | node.second = "leafInt64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 591 | type = yang::Int64{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | SECTION("leafUint64") |
| 595 | { |
| 596 | node.first = "example-schema"; |
| 597 | node.second = "leafUint64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 598 | type = yang::Uint64{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | SECTION("leafEnum") |
| 602 | { |
| 603 | node.first = "example-schema"; |
| 604 | node.second = "leafEnum"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 605 | type = createEnum({"lol", "data", "coze"}); |
| 606 | } |
| 607 | |
| 608 | SECTION("leafEnumTypedef") |
| 609 | { |
| 610 | node.first = "example-schema"; |
| 611 | node.second = "leafEnumTypedef"; |
| 612 | type = createEnum({"lol", "data", "coze"}); |
| 613 | } |
| 614 | |
| 615 | SECTION("leafEnumTypedefRestricted") |
| 616 | { |
| 617 | node.first = "example-schema"; |
| 618 | node.second = "leafEnumTypedefRestricted"; |
| 619 | type = createEnum({"data", "coze"}); |
| 620 | } |
| 621 | |
| 622 | SECTION("leafEnumTypedefRestricted2") |
| 623 | { |
| 624 | node.first = "example-schema"; |
| 625 | node.second = "leafEnumTypedefRestricted2"; |
| 626 | type = createEnum({"lol", "data"}); |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame^] | 627 | expectedDescription = "This is a restricted enum typedef."; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | SECTION("pizzaSize") |
| 631 | { |
| 632 | node.first = "example-schema"; |
| 633 | node.second = "pizzaSize"; |
| 634 | |
| 635 | SECTION("bigPizzas disabled") |
| 636 | { |
| 637 | type = createEnum({"small", "medium"}); |
| 638 | } |
| 639 | SECTION("bigPizzas enabled") |
| 640 | { |
| 641 | ys.enableFeature("example-schema", "bigPizzas"); |
| 642 | type = createEnum({"small", "medium", "large"}); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | SECTION("foodIdentLeaf") |
| 647 | { |
| 648 | node.first = "example-schema"; |
| 649 | node.second = "foodIdentLeaf"; |
| 650 | type = yang::IdentityRef{{{"second-schema", "pineapple"}, |
| 651 | {"example-schema", "food"}, |
| 652 | {"example-schema", "pizza"}, |
| 653 | {"example-schema", "hawaii"}, |
| 654 | {"example-schema", "fruit"}}}; |
| 655 | } |
| 656 | |
| 657 | SECTION("pizzaIdentLeaf") |
| 658 | { |
| 659 | node.first = "example-schema"; |
| 660 | node.second = "pizzaIdentLeaf"; |
| 661 | |
| 662 | type = yang::IdentityRef{{ |
| 663 | {"example-schema", "pizza"}, |
| 664 | {"example-schema", "hawaii"}, |
| 665 | }}; |
| 666 | } |
| 667 | |
| 668 | SECTION("foodDrinkIdentLeaf") |
| 669 | { |
| 670 | node.first = "example-schema"; |
| 671 | node.second = "foodDrinkIdentLeaf"; |
| 672 | |
| 673 | type = yang::IdentityRef{{ |
| 674 | {"example-schema", "food"}, |
| 675 | {"example-schema", "drink"}, |
| 676 | {"example-schema", "fruit"}, |
| 677 | {"example-schema", "hawaii"}, |
| 678 | {"example-schema", "pizza"}, |
| 679 | {"example-schema", "voda"}, |
| 680 | {"second-schema", "pineapple"}, |
| 681 | }}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 682 | } |
| 683 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 684 | SECTION("activeNumber") |
| 685 | { |
| 686 | node.first = "example-schema"; |
| 687 | node.second = "activeNumber"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 688 | type.emplace<yang::LeafRef>( |
| 689 | "/example-schema:_list/number", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 690 | 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] | 691 | ); |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 692 | } |
| 693 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 694 | SECTION("activePort") |
| 695 | { |
| 696 | node.first = "example-schema"; |
| 697 | node.second = "activePort"; |
| 698 | |
Václav Kubernát | 1dc9e3e | 2020-06-09 15:22:39 +0200 | [diff] [blame] | 699 | yang::Enum enums({}); |
| 700 | SECTION("weird ports disabled") |
| 701 | { |
| 702 | enums = createEnum({"utf2", "utf3"}); |
| 703 | } |
| 704 | SECTION("weird ports enabled") |
| 705 | { |
| 706 | ys.enableFeature("example-schema", "weirdPortNames"); |
| 707 | enums = createEnum({"WEIRD", "utf2", "utf3"}); |
| 708 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 709 | |
| 710 | type = yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 711 | yang::TypeInfo{createEnum({"wlan0", "wlan1"})}, |
| 712 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 713 | "/example-schema:portSettings/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 714 | std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"})) |
| 715 | }}, |
| 716 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 717 | "/example-schema:activeMappedPort", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 718 | std::make_unique<yang::TypeInfo>(yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 719 | "/example-schema:portMapping/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 720 | std::make_unique<yang::TypeInfo>(enums) |
| 721 | }) |
| 722 | }}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 723 | yang::TypeInfo{yang::Empty{}}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 724 | }}; |
| 725 | } |
| 726 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 727 | SECTION("addresses") |
| 728 | { |
| 729 | node.first = "example-schema"; |
| 730 | node.second = "addresses"; |
| 731 | type.emplace<yang::String>(); |
| 732 | } |
| 733 | |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 734 | SECTION("flagBits") |
| 735 | { |
| 736 | node.first = "example-schema"; |
| 737 | node.second = "flagBits"; |
| 738 | type = yang::Bits{{"carry", "sign", "overflow"}}; |
| 739 | } |
| 740 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 741 | |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame^] | 742 | 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] | 743 | } |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 744 | SECTION("availableNodes") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 745 | { |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 746 | // TODO: merge "path" and "module" sections and add recursive versions to the path section |
| 747 | SECTION("paths") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 748 | { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 749 | std::set<ModuleNodePair> set; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 750 | |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 751 | using namespace std::string_literals; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 752 | SECTION("<root>") |
| 753 | { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 754 | set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"}, |
| 755 | {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"}, |
| 756 | {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"}, |
| 757 | {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"}, |
| 758 | {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"}, |
| 759 | {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"}, |
| 760 | {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"}, |
| 761 | {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"}, |
| 762 | {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"}, |
| 763 | {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"}, |
| 764 | {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"}, |
| 765 | {"example-schema"s, "interrupt"}, |
| 766 | {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"}, |
| 767 | {"example-schema"s, "pizzaSize"}, |
| 768 | {"example-schema"s, "length"}, {"example-schema"s, "wavelength"}, |
| 769 | {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"}, |
| 770 | {"example-schema"s, "activeNumber"}, |
| 771 | {"example-schema"s, "numberOrString"}, |
| 772 | {"example-schema"s, "portSettings"}, |
| 773 | {"example-schema"s, "portMapping"}, |
| 774 | {"example-schema"s, "activeMappedPort"}, |
| 775 | {"example-schema"s, "activePort"}, |
| 776 | {"example-schema"s, "clockSpeed"}, |
| 777 | {"example-schema"s, "deprecatedLeaf"}, |
| 778 | {"example-schema"s, "obsoleteLeaf"}, |
| 779 | {"example-schema"s, "obsoleteLeafWithDeprecatedType"}, |
| 780 | {"example-schema"s, "obsoleteLeafWithObsoleteType"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 781 | {"example-schema"s, "myRpc"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 782 | {"example-schema"s, "systemStats"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 783 | {"example-schema"s, "dummyLeaf"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 784 | {"example-schema"s, "addresses"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 785 | {"example-schema"s, "subLeaf"}, |
| 786 | {"example-schema"s, "flagBits"}}; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | SECTION("example-schema:a") |
| 790 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 791 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 792 | set = { |
| 793 | {boost::none, "a2"}, |
| 794 | {boost::none, "leafa"}, |
| 795 | {"second-schema"s, "augmentedContainer"} |
| 796 | }; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | SECTION("example-schema:ethernet") |
| 800 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 801 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 802 | set = {{boost::none, "ip"}}; |
| 803 | } |
| 804 | |
| 805 | SECTION("second-schema:bla") |
| 806 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 807 | path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 808 | set = {{boost::none, "bla2"}}; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 814 | SECTION("modules") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 815 | { |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 816 | std::string module; |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 817 | std::set<ModuleNodePair> expectedNonRecursive; |
| 818 | std::set<ModuleNodePair> expectedRecursive; |
| 819 | using namespace std::string_literals; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 820 | SECTION("example-schema") |
| 821 | { |
| 822 | module = "example-schema"; |
| 823 | expectedNonRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 824 | {"example-schema"s, "_list"}, |
| 825 | {"example-schema"s, "a"}, |
| 826 | {"example-schema"s, "activeMappedPort"}, |
| 827 | {"example-schema"s, "activeNumber"}, |
| 828 | {"example-schema"s, "activePort"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 829 | {"example-schema"s, "addresses"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 830 | {"example-schema"s, "another-duration"}, |
| 831 | {"example-schema"s, "b"}, |
| 832 | {"example-schema"s, "carry"}, |
| 833 | {"example-schema"s, "clockSpeed"}, |
| 834 | {"example-schema"s, "deprecatedLeaf"}, |
| 835 | {"example-schema"s, "direction"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 836 | {"example-schema"s, "dummyLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 837 | {"example-schema"s, "duration"}, |
| 838 | {"example-schema"s, "ethernet"}, |
| 839 | {"example-schema"s, "foodDrinkIdentLeaf"}, |
| 840 | {"example-schema"s, "foodIdentLeaf"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 841 | {"example-schema"s, "flagBits"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 842 | {"example-schema"s, "interrupt"}, |
| 843 | {"example-schema"s, "leafBool"}, |
| 844 | {"example-schema"s, "leafDecimal"}, |
| 845 | {"example-schema"s, "leafEnum"}, |
| 846 | {"example-schema"s, "leafEnumTypedef"}, |
| 847 | {"example-schema"s, "leafEnumTypedefRestricted"}, |
| 848 | {"example-schema"s, "leafEnumTypedefRestricted2"}, |
| 849 | {"example-schema"s, "leafInt16"}, |
| 850 | {"example-schema"s, "leafInt32"}, |
| 851 | {"example-schema"s, "leafInt64"}, |
| 852 | {"example-schema"s, "leafInt8"}, |
| 853 | {"example-schema"s, "leafString"}, |
| 854 | {"example-schema"s, "leafUint16"}, |
| 855 | {"example-schema"s, "leafUint32"}, |
| 856 | {"example-schema"s, "leafUint64"}, |
| 857 | {"example-schema"s, "leafUint8"}, |
| 858 | {"example-schema"s, "length"}, |
| 859 | {"example-schema"s, "loopback"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 860 | {"example-schema"s, "myRpc"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 861 | {"example-schema"s, "numberOrString"}, |
| 862 | {"example-schema"s, "obsoleteLeaf"}, |
| 863 | {"example-schema"s, "obsoleteLeafWithDeprecatedType"}, |
| 864 | {"example-schema"s, "obsoleteLeafWithObsoleteType"}, |
| 865 | {"example-schema"s, "pizzaIdentLeaf"}, |
| 866 | {"example-schema"s, "pizzaSize"}, |
| 867 | {"example-schema"s, "portMapping"}, |
| 868 | {"example-schema"s, "portSettings"}, |
| 869 | {"example-schema"s, "systemStats"}, |
| 870 | {"example-schema"s, "twoKeyList"}, |
| 871 | {"example-schema"s, "wavelength"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 872 | {"example-schema"s, "zero"}, |
| 873 | {"example-schema"s, "subLeaf"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 874 | }; |
| 875 | expectedRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 876 | {boost::none, "/example-schema:_list"}, |
| 877 | {boost::none, "/example-schema:_list/contInList"}, |
| 878 | {boost::none, "/example-schema:_list/number"}, |
| 879 | {boost::none, "/example-schema:a"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 880 | {boost::none, "/example-schema:addresses"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 881 | {boost::none, "/example-schema:a/a2"}, |
| 882 | {boost::none, "/example-schema:a/a2/a3"}, |
| 883 | {boost::none, "/example-schema:a/leafa"}, |
| 884 | {boost::none, "/example-schema:a/second-schema:augmentedContainer"}, |
| 885 | {boost::none, "/example-schema:activeMappedPort"}, |
| 886 | {boost::none, "/example-schema:activeNumber"}, |
| 887 | {boost::none, "/example-schema:activePort"}, |
| 888 | {boost::none, "/example-schema:another-duration"}, |
| 889 | {boost::none, "/example-schema:b"}, |
| 890 | {boost::none, "/example-schema:b/b2"}, |
| 891 | {boost::none, "/example-schema:b/b2/b3"}, |
| 892 | {boost::none, "/example-schema:carry"}, |
| 893 | {boost::none, "/example-schema:clockSpeed"}, |
| 894 | {boost::none, "/example-schema:deprecatedLeaf"}, |
| 895 | {boost::none, "/example-schema:direction"}, |
| 896 | {boost::none, "/example-schema:duration"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 897 | {boost::none, "/example-schema:dummyLeaf"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 898 | {boost::none, "/example-schema:flagBits"}, |
| 899 | {boost::none, "/example-schema:foodDrinkIdentLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 900 | {boost::none, "/example-schema:foodDrinkIdentLeaf"}, |
| 901 | {boost::none, "/example-schema:foodIdentLeaf"}, |
| 902 | {boost::none, "/example-schema:interface/caseEthernet/ethernet"}, |
| 903 | {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"}, |
| 904 | {boost::none, "/example-schema:interface/caseLoopback/loopback"}, |
| 905 | {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"}, |
| 906 | {boost::none, "/example-schema:interrupt"}, |
| 907 | {boost::none, "/example-schema:leafBool"}, |
| 908 | {boost::none, "/example-schema:leafDecimal"}, |
| 909 | {boost::none, "/example-schema:leafEnum"}, |
| 910 | {boost::none, "/example-schema:leafEnumTypedef"}, |
| 911 | {boost::none, "/example-schema:leafEnumTypedefRestricted"}, |
| 912 | {boost::none, "/example-schema:leafEnumTypedefRestricted2"}, |
| 913 | {boost::none, "/example-schema:leafInt16"}, |
| 914 | {boost::none, "/example-schema:leafInt32"}, |
| 915 | {boost::none, "/example-schema:leafInt64"}, |
| 916 | {boost::none, "/example-schema:leafInt8"}, |
| 917 | {boost::none, "/example-schema:leafString"}, |
| 918 | {boost::none, "/example-schema:leafUint16"}, |
| 919 | {boost::none, "/example-schema:leafUint32"}, |
| 920 | {boost::none, "/example-schema:leafUint64"}, |
| 921 | {boost::none, "/example-schema:leafUint8"}, |
| 922 | {boost::none, "/example-schema:length"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 923 | {boost::none, "/example-schema:myRpc"}, |
| 924 | {boost::none, "/example-schema:myRpc/input"}, |
| 925 | {boost::none, "/example-schema:myRpc/output"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 926 | {boost::none, "/example-schema:numberOrString"}, |
| 927 | {boost::none, "/example-schema:obsoleteLeaf"}, |
| 928 | {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"}, |
| 929 | {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"}, |
| 930 | {boost::none, "/example-schema:pizzaIdentLeaf"}, |
| 931 | {boost::none, "/example-schema:pizzaSize"}, |
| 932 | {boost::none, "/example-schema:portMapping"}, |
| 933 | {boost::none, "/example-schema:portMapping/port"}, |
| 934 | {boost::none, "/example-schema:portSettings"}, |
| 935 | {boost::none, "/example-schema:portSettings/port"}, |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 936 | {boost::none, "/example-schema:portSettings/shutdown"}, |
| 937 | {boost::none, "/example-schema:portSettings/shutdown/input"}, |
| 938 | {boost::none, "/example-schema:portSettings/shutdown/output"}, |
| 939 | {boost::none, "/example-schema:portSettings/shutdown/output/success"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 940 | {boost::none, "/example-schema:systemStats"}, |
| 941 | {boost::none, "/example-schema:systemStats/upTime"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 942 | {boost::none, "/example-schema:subLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 943 | {boost::none, "/example-schema:twoKeyList"}, |
| 944 | {boost::none, "/example-schema:twoKeyList/name"}, |
| 945 | {boost::none, "/example-schema:twoKeyList/number"}, |
| 946 | {boost::none, "/example-schema:wavelength"}, |
| 947 | {boost::none, "/example-schema:zero"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 948 | }; |
| 949 | } |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 950 | SECTION("second-schema") |
| 951 | { |
| 952 | module = "second-schema"; |
| 953 | expectedNonRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 954 | {"second-schema"s, "bla"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 955 | }; |
| 956 | expectedRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 957 | {boost::none, "/second-schema:bla"}, |
| 958 | {boost::none, "/second-schema:bla/bla2"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 959 | }; |
| 960 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 961 | |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 962 | REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive); |
| 963 | REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive); |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 964 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 965 | } |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 966 | SECTION("nodeType") |
| 967 | { |
| 968 | yang::NodeTypes expected; |
| 969 | SECTION("leafInt32") |
| 970 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 971 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 972 | expected = yang::NodeTypes::Leaf; |
| 973 | } |
| 974 | |
| 975 | SECTION("a") |
| 976 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 977 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 978 | expected = yang::NodeTypes::Container; |
| 979 | } |
| 980 | |
| 981 | SECTION("a/a2/a3") |
| 982 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 983 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 984 | path.m_nodes.emplace_back(container_("a2")); |
| 985 | path.m_nodes.emplace_back(container_("a3")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 986 | expected = yang::NodeTypes::PresenceContainer; |
| 987 | } |
| 988 | |
| 989 | SECTION("_list") |
| 990 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 991 | path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 992 | expected = yang::NodeTypes::List; |
| 993 | } |
| 994 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 995 | SECTION("subLeaf") |
| 996 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 997 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf")); |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 998 | expected = yang::NodeTypes::Leaf; |
| 999 | } |
| 1000 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 1001 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1002 | } |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1003 | |
| 1004 | SECTION("description") |
| 1005 | { |
| 1006 | std::optional<std::string> expected; |
| 1007 | SECTION("leafInt32") |
| 1008 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1009 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1010 | expected = "A 32-bit integer leaf."; |
| 1011 | } |
| 1012 | |
| 1013 | SECTION("leafString") |
| 1014 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1015 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 1018 | SECTION("numberOrString") |
| 1019 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1020 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 1021 | expected = "Can be an int32 or a string."; |
| 1022 | } |
| 1023 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1024 | REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1025 | } |
| 1026 | |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 1027 | SECTION("status") |
| 1028 | { |
| 1029 | REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current); |
| 1030 | REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete); |
| 1031 | REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated); |
| 1032 | REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete); |
| 1033 | REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete); |
| 1034 | } |
| 1035 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1036 | SECTION("units") |
| 1037 | { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1038 | yang::LeafDataType expectedType; |
| 1039 | std::optional<std::string> expectedUnits; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1040 | SECTION("length") |
| 1041 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1042 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1043 | expectedType.emplace<yang::Int32>(); |
| 1044 | expectedUnits = "m"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | SECTION("wavelength") |
| 1048 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1049 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1050 | expectedType.emplace<yang::Decimal>(); |
| 1051 | expectedUnits = "nm"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | SECTION("leafInt32") |
| 1055 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1056 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1057 | expectedType.emplace<yang::Int32>(); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | SECTION("duration") |
| 1061 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1062 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1063 | expectedType.emplace<yang::Int32>(); |
| 1064 | expectedUnits = "s"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | SECTION("another-duration") |
| 1068 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1069 | 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] | 1070 | expectedType.emplace<yang::Int32>(); |
| 1071 | expectedUnits = "vt"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1072 | } |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 1073 | auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)); |
| 1074 | REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList)); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1075 | 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] | 1076 | } |
| 1077 | |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame^] | 1078 | SECTION("type description") |
| 1079 | { |
| 1080 | yang::LeafDataType expectedType = createEnum({"lol", "data"}); |
| 1081 | std::optional<std::string> expectedDescription; |
| 1082 | |
| 1083 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafEnumTypedefRestricted2")); |
| 1084 | expectedDescription = "This is a restricted enum typedef."; |
| 1085 | REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, std::nullopt, expectedDescription}); |
| 1086 | } |
| 1087 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1088 | SECTION("nodeType") |
| 1089 | { |
| 1090 | yang::NodeTypes expected; |
| 1091 | SECTION("leafInt32") |
| 1092 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1093 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1094 | expected = yang::NodeTypes::Leaf; |
| 1095 | } |
| 1096 | |
| 1097 | SECTION("a") |
| 1098 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1099 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1100 | expected = yang::NodeTypes::Container; |
| 1101 | } |
| 1102 | |
| 1103 | SECTION("a/a2/a3") |
| 1104 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1105 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1106 | path.m_nodes.emplace_back(container_("a2")); |
| 1107 | path.m_nodes.emplace_back(container_("a3")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1108 | expected = yang::NodeTypes::PresenceContainer; |
| 1109 | } |
| 1110 | |
| 1111 | SECTION("_list") |
| 1112 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1113 | path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1114 | expected = yang::NodeTypes::List; |
| 1115 | } |
| 1116 | |
| 1117 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1118 | } |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 1119 | |
| 1120 | SECTION("leafrefPath") |
| 1121 | { |
| 1122 | REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number"); |
| 1123 | } |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 1124 | |
| 1125 | SECTION("isConfig") |
| 1126 | { |
| 1127 | REQUIRE(ys.isConfig("/example-schema:leafInt32")); |
| 1128 | REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed")); |
| 1129 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats")); |
| 1130 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime")); |
| 1131 | } |
Václav Kubernát | bd0d5c8 | 2020-04-21 10:22:03 +0200 | [diff] [blame] | 1132 | |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 1133 | SECTION("defaultValue") |
| 1134 | { |
| 1135 | REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001"); |
| 1136 | REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data"); |
| 1137 | REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt); |
| 1138 | } |
| 1139 | |
Václav Kubernát | 76ba4ec | 2020-05-18 13:26:56 +0200 | [diff] [blame] | 1140 | SECTION("leafTypeName") |
| 1141 | { |
| 1142 | REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef"); |
| 1143 | REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt); |
| 1144 | } |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 1145 | |
| 1146 | SECTION("dataPathToSchemaPath") |
| 1147 | { |
| 1148 | REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings"); |
| 1149 | REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown"); |
| 1150 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | SECTION("negative") |
| 1154 | { |
| 1155 | SECTION("nonexistent nodes") |
| 1156 | { |
| 1157 | SECTION("example-schema:coze") |
| 1158 | { |
| 1159 | node.first = "example-schema"; |
| 1160 | node.second = "coze"; |
| 1161 | } |
| 1162 | |
| 1163 | SECTION("example-schema:a/nevim") |
| 1164 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1165 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1166 | node.second = "nevim"; |
| 1167 | } |
| 1168 | |
| 1169 | SECTION("modul:a/nevim") |
| 1170 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1171 | path.m_nodes.emplace_back(module_{"modul"}, container_("a")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1172 | node.second = "nevim"; |
| 1173 | } |
| 1174 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1175 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | SECTION("nodetype-specific methods called with different nodetypes") |
| 1179 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1180 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1181 | path.m_nodes.emplace_back(container_("a2")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1182 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 1183 | REQUIRE(!ys.listHasKey(path, "chacha")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | SECTION("nonexistent module") |
| 1187 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 1188 | REQUIRE(!ys.isModule("notAModule")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1189 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 1190 | |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1191 | SECTION("grouping is not a node") |
| 1192 | { |
| 1193 | SECTION("example-schema:arithmeticFlags") |
| 1194 | { |
| 1195 | node.first = "example-schema"; |
| 1196 | node.second = "arithmeticFlags"; |
| 1197 | } |
| 1198 | |
| 1199 | SECTION("example-schema:flags") |
| 1200 | { |
| 1201 | node.first = "example-schema"; |
| 1202 | node.second = "startAndStop"; |
| 1203 | } |
| 1204 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1205 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1206 | } |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1207 | |
| 1208 | SECTION("choice is not a node") |
| 1209 | { |
| 1210 | SECTION("example-schema:interface") |
| 1211 | { |
| 1212 | node.first = "example-schema"; |
| 1213 | node.second = "interface"; |
| 1214 | } |
| 1215 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1216 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | SECTION("case is not a node") |
| 1220 | { |
| 1221 | SECTION("example-schema:caseLoopback") |
| 1222 | { |
| 1223 | node.first = "example-schema"; |
| 1224 | node.second = "caseLoopback"; |
| 1225 | } |
| 1226 | |
| 1227 | SECTION("example-schema:caseEthernet") |
| 1228 | { |
| 1229 | node.first = "example-schema"; |
| 1230 | node.second = "caseEthernet"; |
| 1231 | } |
| 1232 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1233 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1234 | } |
Václav Kubernát | f44bdda | 2020-06-22 15:58:41 +0200 | [diff] [blame] | 1235 | |
| 1236 | SECTION("enableFeature - non existing module") |
| 1237 | { |
| 1238 | REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error); |
| 1239 | } |
Václav Kubernát | 7aaf6dc | 2020-06-26 18:03:57 +0200 | [diff] [blame] | 1240 | |
| 1241 | SECTION("enableFeature - non existing feature") |
| 1242 | { |
| 1243 | REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error); |
| 1244 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1245 | } |
| 1246 | } |