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