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 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.h" |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 10 | #include "yang_schema.hpp" |
| 11 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 12 | const char* second_schema = R"( |
| 13 | module second-schema { |
| 14 | namespace "http://example.com/nevim"; |
| 15 | prefix second; |
| 16 | |
| 17 | import example-schema { |
| 18 | prefix "example"; |
| 19 | } |
| 20 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 21 | identity pineapple { |
| 22 | base "example:fruit"; |
| 23 | } |
| 24 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 25 | augment /example:a { |
| 26 | container augmentedContainer { |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | container bla { |
| 31 | container bla2 { |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | )"; |
| 36 | |
| 37 | const char* example_schema = R"( |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 38 | module example-schema { |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 39 | yang-version 1.1; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 40 | namespace "http://example.com/example-sports"; |
| 41 | prefix coze; |
| 42 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 43 | identity drink { |
| 44 | } |
| 45 | |
| 46 | identity voda { |
| 47 | base "drink"; |
| 48 | } |
| 49 | |
| 50 | identity food { |
| 51 | } |
| 52 | |
| 53 | identity fruit { |
| 54 | base "food"; |
| 55 | } |
| 56 | |
| 57 | identity pizza { |
| 58 | base "food"; |
| 59 | } |
| 60 | |
| 61 | identity hawaii { |
| 62 | base "pizza"; |
| 63 | } |
| 64 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 65 | container a { |
| 66 | container a2 { |
| 67 | container a3 { |
| 68 | presence true; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | leaf leafa { |
| 73 | type string; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | container b { |
| 78 | container b2 { |
| 79 | presence true; |
| 80 | container b3 { |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | leaf leafString { |
| 86 | type string; |
| 87 | } |
| 88 | |
| 89 | leaf leafDecimal { |
| 90 | type decimal64 { |
| 91 | fraction-digits 5; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | leaf leafBool { |
| 96 | type boolean; |
| 97 | } |
| 98 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 99 | leaf leafInt8 { |
| 100 | type int8; |
| 101 | } |
| 102 | |
| 103 | leaf leafUint8 { |
| 104 | type uint8; |
| 105 | } |
| 106 | |
| 107 | leaf leafInt16 { |
| 108 | type int16; |
| 109 | } |
| 110 | |
| 111 | leaf leafUint16 { |
| 112 | type uint16; |
| 113 | } |
| 114 | |
| 115 | leaf leafInt32 { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 116 | type int32; |
| 117 | } |
| 118 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 119 | leaf leafUint32 { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 120 | type uint32; |
| 121 | } |
| 122 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 123 | leaf leafInt64 { |
| 124 | type int64; |
| 125 | } |
| 126 | |
| 127 | leaf leafUint64 { |
| 128 | type uint64; |
| 129 | } |
| 130 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 131 | leaf leafEnum { |
| 132 | type enumeration { |
| 133 | enum lol; |
| 134 | enum data; |
| 135 | enum coze; |
| 136 | } |
| 137 | } |
| 138 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 139 | typedef enumTypedef { |
| 140 | type enumeration { |
| 141 | enum lol; |
| 142 | enum data; |
| 143 | enum coze; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | typedef enumTypedefRestricted { |
| 148 | type enumTypedef { |
| 149 | enum lol; |
| 150 | enum data; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | leaf leafEnumTypedef { |
| 155 | type enumTypedef; |
| 156 | } |
| 157 | |
| 158 | leaf leafEnumTypedefRestricted { |
| 159 | type enumTypedef { |
| 160 | enum data; |
| 161 | enum coze; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | leaf leafEnumTypedefRestricted2 { |
| 166 | type enumTypedefRestricted; |
| 167 | } |
| 168 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 169 | leaf foodIdentLeaf { |
| 170 | type identityref { |
| 171 | base "food"; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | leaf pizzaIdentLeaf { |
| 176 | type identityref { |
| 177 | base "pizza"; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | leaf foodDrinkIdentLeaf { |
| 182 | type identityref { |
| 183 | base "food"; |
| 184 | base "drink"; |
| 185 | } |
| 186 | } |
| 187 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 188 | list _list { |
| 189 | key number; |
| 190 | |
| 191 | leaf number { |
| 192 | type int32; |
| 193 | } |
| 194 | |
| 195 | container contInList { |
| 196 | presence true; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | list twoKeyList { |
| 201 | key "name number"; |
| 202 | |
| 203 | leaf number { |
| 204 | type int32; |
| 205 | } |
| 206 | |
| 207 | leaf name { |
| 208 | type string; |
| 209 | } |
| 210 | } |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 211 | |
| 212 | grouping arithmeticFlags { |
| 213 | leaf carry { |
| 214 | type boolean; |
| 215 | } |
| 216 | leaf zero { |
| 217 | type boolean; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | grouping flags { |
| 222 | leaf direction { |
| 223 | type boolean; |
| 224 | } |
| 225 | leaf interrupt { |
| 226 | type boolean; |
| 227 | } |
| 228 | |
| 229 | uses arithmeticFlags; |
| 230 | } |
| 231 | |
| 232 | uses flags; |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 233 | |
| 234 | choice interface { |
| 235 | case caseLoopback { |
| 236 | container loopback { |
| 237 | leaf ip { |
| 238 | type string; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | case caseEthernet { |
| 244 | container ethernet { |
| 245 | leaf ip { |
| 246 | type string; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 252 | })"; |
| 253 | |
| 254 | TEST_CASE("yangschema") |
| 255 | { |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 256 | using namespace std::string_view_literals; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 257 | YangSchema ys; |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 258 | ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto) { |
| 259 | assert("example-schema"sv == modName); |
| 260 | return example_schema; |
| 261 | }); |
| 262 | ys.addSchemaString(second_schema); |
| 263 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 264 | schemaPath_ path; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 265 | ModuleNodePair node; |
| 266 | |
| 267 | SECTION("positive") |
| 268 | { |
| 269 | SECTION("isContainer") |
| 270 | { |
| 271 | SECTION("example-schema:a") |
| 272 | { |
| 273 | node.first = "example-schema"; |
| 274 | node.second = "a"; |
| 275 | } |
| 276 | |
| 277 | SECTION("example-schema:a/a2") |
| 278 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 279 | 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] | 280 | node.second = "a2"; |
| 281 | } |
| 282 | |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 283 | SECTION("example-schema:ethernet") |
| 284 | { |
| 285 | node.first = "example-schema"; |
| 286 | node.second = "ethernet"; |
| 287 | } |
| 288 | |
| 289 | SECTION("example-schema:loopback") |
| 290 | { |
| 291 | node.first = "example-schema"; |
| 292 | node.second = "loopback"; |
| 293 | } |
| 294 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 295 | REQUIRE(ys.isContainer(path, node)); |
| 296 | } |
| 297 | SECTION("isLeaf") |
| 298 | { |
| 299 | SECTION("example-schema:leafString") |
| 300 | { |
| 301 | node.first = "example-schema"; |
| 302 | node.second = "leafString"; |
| 303 | } |
| 304 | |
| 305 | SECTION("example-schema:a/leafa") |
| 306 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 307 | 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] | 308 | node.first = "example-schema"; |
| 309 | node.second = "leafa"; |
| 310 | } |
| 311 | |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 312 | SECTION("example-schema:carry") |
| 313 | { |
| 314 | node.first = "example-schema"; |
| 315 | node.second = "carry"; |
| 316 | } |
| 317 | |
| 318 | SECTION("example-schema:zero") |
| 319 | { |
| 320 | node.first = "example-schema"; |
| 321 | node.second = "zero"; |
| 322 | } |
| 323 | |
| 324 | SECTION("example-schema:direction") |
| 325 | { |
| 326 | node.first = "example-schema"; |
| 327 | node.second = "direction"; |
| 328 | } |
| 329 | |
| 330 | SECTION("example-schema:interrupt") |
| 331 | { |
| 332 | node.first = "example-schema"; |
| 333 | node.second = "interrupt"; |
| 334 | } |
| 335 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 336 | REQUIRE(ys.isLeaf(path, node)); |
| 337 | } |
| 338 | SECTION("isModule") |
| 339 | { |
| 340 | REQUIRE(ys.isModule(path, "example-schema")); |
| 341 | } |
| 342 | SECTION("isList") |
| 343 | { |
| 344 | SECTION("example-schema:_list") |
| 345 | { |
| 346 | node.first = "example-schema"; |
| 347 | node.second = "_list"; |
| 348 | } |
| 349 | |
| 350 | SECTION("example-schema:twoKeyList") |
| 351 | { |
| 352 | node.first = "example-schema"; |
| 353 | node.second = "twoKeyList"; |
| 354 | } |
| 355 | |
| 356 | REQUIRE(ys.isList(path, node)); |
| 357 | } |
| 358 | SECTION("isPresenceContainer") |
| 359 | { |
| 360 | SECTION("example-schema:a/a2/a3") |
| 361 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 362 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
| 363 | 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] | 364 | node.second = "a3"; |
| 365 | } |
| 366 | |
| 367 | REQUIRE(ys.isPresenceContainer(path, node)); |
| 368 | } |
| 369 | SECTION("leafEnumHasValue") |
| 370 | { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 371 | std::string value; |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 372 | SECTION("leafEnum") |
| 373 | { |
| 374 | node.first = "example-schema"; |
| 375 | node.second = "leafEnum"; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 376 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 377 | SECTION("lol") |
| 378 | value = "lol"; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 379 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 380 | SECTION("data") |
| 381 | value = "data"; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 382 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 383 | SECTION("coze") |
| 384 | value = "coze"; |
| 385 | } |
| 386 | |
| 387 | SECTION("leafEnumTypedef") |
| 388 | { |
| 389 | node.first = "example-schema"; |
| 390 | node.second = "leafEnumTypedef"; |
| 391 | |
| 392 | SECTION("lol") |
| 393 | value = "lol"; |
| 394 | |
| 395 | SECTION("data") |
| 396 | value = "data"; |
| 397 | |
| 398 | SECTION("coze") |
| 399 | value = "coze"; |
| 400 | } |
| 401 | |
| 402 | SECTION("leafEnumTypedefRestricted") |
| 403 | { |
| 404 | node.first = "example-schema"; |
| 405 | node.second = "leafEnumTypedefRestricted"; |
| 406 | |
| 407 | SECTION("data") |
| 408 | value = "data"; |
| 409 | |
| 410 | SECTION("coze") |
| 411 | value = "coze"; |
| 412 | } |
| 413 | |
| 414 | SECTION("leafEnumTypedefRestricted2") |
| 415 | { |
| 416 | node.first = "example-schema"; |
| 417 | node.second = "leafEnumTypedefRestricted2"; |
| 418 | |
| 419 | SECTION("lol") |
| 420 | value = "lol"; |
| 421 | |
| 422 | SECTION("data") |
| 423 | value = "data"; |
| 424 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 425 | |
| 426 | REQUIRE(ys.leafEnumHasValue(path, node, value)); |
| 427 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 428 | SECTION("leafIdentityIsValid") |
| 429 | { |
| 430 | ModuleValuePair value; |
| 431 | |
| 432 | SECTION("foodIdentLeaf") |
| 433 | { |
| 434 | node.first = "example-schema"; |
| 435 | node.second = "foodIdentLeaf"; |
| 436 | |
| 437 | SECTION("food") |
| 438 | { |
| 439 | value.second = "food"; |
| 440 | } |
| 441 | SECTION("example-schema:food") |
| 442 | { |
| 443 | value.first = "example-schema"; |
| 444 | value.second = "food"; |
| 445 | } |
| 446 | SECTION("pizza") |
| 447 | { |
| 448 | value.second = "pizza"; |
| 449 | } |
| 450 | SECTION("example-schema:pizza") |
| 451 | { |
| 452 | value.first = "example-schema"; |
| 453 | value.second = "pizza"; |
| 454 | } |
| 455 | SECTION("hawaii") |
| 456 | { |
| 457 | value.second = "hawaii"; |
| 458 | } |
| 459 | SECTION("example-schema:hawaii") |
| 460 | { |
| 461 | value.first = "example-schema"; |
| 462 | value.second = "hawaii"; |
| 463 | } |
| 464 | SECTION("fruit") |
| 465 | { |
| 466 | value.second = "fruit"; |
| 467 | } |
| 468 | SECTION("example-schema:fruit") |
| 469 | { |
| 470 | value.first = "example-schema"; |
| 471 | value.second = "fruit"; |
| 472 | } |
| 473 | SECTION("second-schema:pineapple") |
| 474 | { |
| 475 | value.first = "second-schema"; |
| 476 | value.second = "pineapple"; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | SECTION("pizzaIdentLeaf") |
| 481 | { |
| 482 | node.first = "example-schema"; |
| 483 | node.second = "pizzaIdentLeaf"; |
| 484 | |
| 485 | SECTION("pizza") |
| 486 | { |
| 487 | value.second = "pizza"; |
| 488 | } |
| 489 | SECTION("example-schema:pizza") |
| 490 | { |
| 491 | value.first = "example-schema"; |
| 492 | value.second = "pizza"; |
| 493 | } |
| 494 | SECTION("hawaii") |
| 495 | { |
| 496 | value.second = "hawaii"; |
| 497 | } |
| 498 | SECTION("example-schema:hawaii") |
| 499 | { |
| 500 | value.first = "example-schema"; |
| 501 | value.second = "hawaii"; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | SECTION("foodDrinkIdentLeaf") |
| 506 | { |
| 507 | node.first = "example-schema"; |
| 508 | node.second = "foodDrinkIdentLeaf"; |
| 509 | |
| 510 | SECTION("food") |
| 511 | { |
| 512 | value.second = "food"; |
| 513 | } |
| 514 | SECTION("example-schema:food") |
| 515 | { |
| 516 | value.first = "example-schema"; |
| 517 | value.second = "food"; |
| 518 | } |
| 519 | SECTION("drink") |
| 520 | { |
| 521 | value.second = "drink"; |
| 522 | } |
| 523 | SECTION("example-schema:drink") |
| 524 | { |
| 525 | value.first = "example-schema"; |
| 526 | value.second = "drink"; |
| 527 | } |
| 528 | } |
| 529 | REQUIRE(ys.leafIdentityIsValid(path, node, value)); |
| 530 | } |
| 531 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 532 | SECTION("listHasKey") |
| 533 | { |
| 534 | std::string key; |
| 535 | |
| 536 | SECTION("_list") |
| 537 | { |
| 538 | node.first = "example-schema"; |
| 539 | node.second = "_list"; |
| 540 | SECTION("number") |
| 541 | key = "number"; |
| 542 | } |
| 543 | |
| 544 | SECTION("twoKeyList") |
| 545 | { |
| 546 | node.first = "example-schema"; |
| 547 | node.second = "twoKeyList"; |
| 548 | SECTION("number") |
| 549 | key = "number"; |
| 550 | SECTION("name") |
| 551 | key = "name"; |
| 552 | } |
| 553 | |
| 554 | REQUIRE(ys.listHasKey(path, node, key)); |
| 555 | } |
| 556 | SECTION("listKeys") |
| 557 | { |
| 558 | std::set<std::string> set; |
| 559 | |
| 560 | SECTION("_list") |
| 561 | { |
| 562 | set = {"number"}; |
| 563 | node.first = "example-schema"; |
| 564 | node.second = "_list"; |
| 565 | } |
| 566 | |
| 567 | SECTION("twoKeyList") |
| 568 | { |
| 569 | set = {"number", "name"}; |
| 570 | node.first = "example-schema"; |
| 571 | node.second = "twoKeyList"; |
| 572 | } |
| 573 | |
| 574 | REQUIRE(ys.listKeys(path, node) == set); |
| 575 | } |
| 576 | SECTION("leafType") |
| 577 | { |
| 578 | yang::LeafDataTypes type; |
| 579 | |
| 580 | SECTION("leafString") |
| 581 | { |
| 582 | node.first = "example-schema"; |
| 583 | node.second = "leafString"; |
| 584 | type = yang::LeafDataTypes::String; |
| 585 | } |
| 586 | |
| 587 | SECTION("leafDecimal") |
| 588 | { |
| 589 | node.first = "example-schema"; |
| 590 | node.second = "leafDecimal"; |
| 591 | type = yang::LeafDataTypes::Decimal; |
| 592 | } |
| 593 | |
| 594 | SECTION("leafBool") |
| 595 | { |
| 596 | node.first = "example-schema"; |
| 597 | node.second = "leafBool"; |
| 598 | type = yang::LeafDataTypes::Bool; |
| 599 | } |
| 600 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 601 | SECTION("leafInt8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 602 | { |
| 603 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 604 | node.second = "leafInt8"; |
| 605 | type = yang::LeafDataTypes::Int8; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 608 | SECTION("leafUint8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 609 | { |
| 610 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 611 | node.second = "leafUint8"; |
| 612 | type = yang::LeafDataTypes::Uint8; |
| 613 | } |
| 614 | |
| 615 | SECTION("leafInt15") |
| 616 | { |
| 617 | node.first = "example-schema"; |
| 618 | node.second = "leafInt16"; |
| 619 | type = yang::LeafDataTypes::Int16; |
| 620 | } |
| 621 | |
| 622 | SECTION("leafUint16") |
| 623 | { |
| 624 | node.first = "example-schema"; |
| 625 | node.second = "leafUint16"; |
| 626 | type = yang::LeafDataTypes::Uint16; |
| 627 | } |
| 628 | |
| 629 | SECTION("leafInt32") |
| 630 | { |
| 631 | node.first = "example-schema"; |
| 632 | node.second = "leafInt32"; |
| 633 | type = yang::LeafDataTypes::Int32; |
| 634 | } |
| 635 | |
| 636 | SECTION("leafUint32") |
| 637 | { |
| 638 | node.first = "example-schema"; |
| 639 | node.second = "leafUint32"; |
| 640 | type = yang::LeafDataTypes::Uint32; |
| 641 | } |
| 642 | |
| 643 | SECTION("leafInt64") |
| 644 | { |
| 645 | node.first = "example-schema"; |
| 646 | node.second = "leafInt64"; |
| 647 | type = yang::LeafDataTypes::Int64; |
| 648 | } |
| 649 | |
| 650 | SECTION("leafUint64") |
| 651 | { |
| 652 | node.first = "example-schema"; |
| 653 | node.second = "leafUint64"; |
| 654 | type = yang::LeafDataTypes::Uint64; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | SECTION("leafEnum") |
| 658 | { |
| 659 | node.first = "example-schema"; |
| 660 | node.second = "leafEnum"; |
| 661 | type = yang::LeafDataTypes::Enum; |
| 662 | } |
| 663 | |
| 664 | REQUIRE(ys.leafType(path, node) == type); |
| 665 | } |
| 666 | SECTION("childNodes") |
| 667 | { |
| 668 | std::set<std::string> set; |
| 669 | |
| 670 | SECTION("<root>") |
| 671 | { |
| 672 | set = {"example-schema:a", "example-schema:b", "example-schema:leafString", |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 673 | "example-schema:leafDecimal", "example-schema:leafBool", |
| 674 | "example-schema:leafInt8", "example-schema:leafUint8", |
| 675 | "example-schema:leafInt16", "example-schema:leafUint16", |
| 676 | "example-schema:leafInt32", "example-schema:leafUint32", |
| 677 | "example-schema:leafInt64", "example-schema:leafUint64", |
| 678 | "example-schema:leafEnum", "example-schema:leafEnumTypedef", |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 679 | "example-schema:leafEnumTypedefRestricted", "example-schema:leafEnumTypedefRestricted2", |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 680 | "example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf", |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 681 | "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla", |
| 682 | "example-schema:carry", "example-schema:zero", "example-schema:direction", |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 683 | "example-schema:interrupt", |
| 684 | "example-schema:ethernet", "example-schema:loopback"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 687 | SECTION("example-schema:a") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 688 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 689 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 690 | set = {"a2", "leafa", "second-schema:augmentedContainer"}; |
| 691 | } |
| 692 | |
| 693 | SECTION("second-schema:bla") |
| 694 | { |
| 695 | path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla"))); |
| 696 | set = {"bla2"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 697 | } |
| 698 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 699 | REQUIRE(ys.childNodes(path, Recursion::NonRecursive) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | SECTION("negative") |
| 704 | { |
| 705 | SECTION("nonexistent nodes") |
| 706 | { |
| 707 | SECTION("example-schema:coze") |
| 708 | { |
| 709 | node.first = "example-schema"; |
| 710 | node.second = "coze"; |
| 711 | } |
| 712 | |
| 713 | SECTION("example-schema:a/nevim") |
| 714 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 715 | 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] | 716 | node.second = "nevim"; |
| 717 | } |
| 718 | |
| 719 | SECTION("modul:a/nevim") |
| 720 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 721 | path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 722 | node.second = "nevim"; |
| 723 | } |
| 724 | |
| 725 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 726 | REQUIRE(!ys.isList(path, node)); |
| 727 | REQUIRE(!ys.isLeaf(path, node)); |
| 728 | REQUIRE(!ys.isContainer(path, node)); |
| 729 | } |
| 730 | |
| 731 | SECTION("\"is\" methods return false for existing nodes for different nodetypes") |
| 732 | { |
| 733 | SECTION("example-schema:a") |
| 734 | { |
| 735 | node.first = "example-schema"; |
| 736 | node.second = "a"; |
| 737 | } |
| 738 | |
| 739 | SECTION("example-schema:a/a2") |
| 740 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 741 | 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] | 742 | node.second = "a2"; |
| 743 | } |
| 744 | |
| 745 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 746 | REQUIRE(!ys.isList(path, node)); |
| 747 | REQUIRE(!ys.isLeaf(path, node)); |
| 748 | } |
| 749 | |
| 750 | SECTION("nodetype-specific methods called with different nodetypes") |
| 751 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 752 | 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] | 753 | node.second = "a2"; |
| 754 | |
| 755 | REQUIRE(!ys.leafEnumHasValue(path, node, "haha")); |
| 756 | REQUIRE(!ys.listHasKey(path, node, "chacha")); |
| 757 | } |
| 758 | |
| 759 | SECTION("nonexistent module") |
| 760 | { |
| 761 | REQUIRE(!ys.isModule(path, "notAModule")); |
| 762 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 763 | |
| 764 | SECTION("leafIdentityIsValid") |
| 765 | { |
| 766 | ModuleValuePair value; |
| 767 | SECTION("pizzaIdentLeaf") |
| 768 | { |
| 769 | node.first = "example-schema"; |
| 770 | node.second = "pizzaIdentLeaf"; |
| 771 | |
| 772 | SECTION("wrong base ident") |
| 773 | { |
| 774 | SECTION("food") |
| 775 | { |
| 776 | value.second = "food"; |
| 777 | } |
| 778 | SECTION("fruit") |
| 779 | { |
| 780 | value.second = "fruit"; |
| 781 | } |
| 782 | } |
| 783 | SECTION("non-existent identity") |
| 784 | { |
| 785 | value.second = "nonexistent"; |
| 786 | } |
| 787 | SECTION("weird module") |
| 788 | { |
| 789 | value.first = "ahahaha"; |
| 790 | value.second = "pizza"; |
| 791 | } |
| 792 | } |
| 793 | SECTION("different module identity, but withotu prefix") |
| 794 | { |
| 795 | node.first = "example-schema"; |
| 796 | node.second = "foodIdentLeaf"; |
| 797 | value.second = "pineapple"; |
| 798 | } |
| 799 | REQUIRE_FALSE(ys.leafIdentityIsValid(path, node, value)); |
| 800 | } |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 801 | |
| 802 | SECTION("grouping is not a node") |
| 803 | { |
| 804 | SECTION("example-schema:arithmeticFlags") |
| 805 | { |
| 806 | node.first = "example-schema"; |
| 807 | node.second = "arithmeticFlags"; |
| 808 | } |
| 809 | |
| 810 | SECTION("example-schema:flags") |
| 811 | { |
| 812 | node.first = "example-schema"; |
| 813 | node.second = "startAndStop"; |
| 814 | } |
| 815 | |
| 816 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 817 | REQUIRE(!ys.isList(path, node)); |
| 818 | REQUIRE(!ys.isLeaf(path, node)); |
| 819 | REQUIRE(!ys.isContainer(path, node)); |
| 820 | } |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 821 | |
| 822 | SECTION("choice is not a node") |
| 823 | { |
| 824 | SECTION("example-schema:interface") |
| 825 | { |
| 826 | node.first = "example-schema"; |
| 827 | node.second = "interface"; |
| 828 | } |
| 829 | |
| 830 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 831 | REQUIRE(!ys.isList(path, node)); |
| 832 | REQUIRE(!ys.isLeaf(path, node)); |
| 833 | REQUIRE(!ys.isContainer(path, node)); |
| 834 | } |
| 835 | |
| 836 | SECTION("case is not a node") |
| 837 | { |
| 838 | SECTION("example-schema:caseLoopback") |
| 839 | { |
| 840 | node.first = "example-schema"; |
| 841 | node.second = "caseLoopback"; |
| 842 | } |
| 843 | |
| 844 | SECTION("example-schema:caseEthernet") |
| 845 | { |
| 846 | node.first = "example-schema"; |
| 847 | node.second = "caseEthernet"; |
| 848 | } |
| 849 | |
| 850 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 851 | REQUIRE(!ys.isList(path, node)); |
| 852 | REQUIRE(!ys.isLeaf(path, node)); |
| 853 | REQUIRE(!ys.isContainer(path, node)); |
| 854 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 855 | } |
| 856 | } |