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