blob: c5ae62aeb58da5824f79a40590ab6961db91ffd5 [file] [log] [blame]
Václav Kubernát0d4db442018-07-18 17:18:43 +02001/*
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átb4e5b182020-11-16 19:55:09 +01009#include "trompeloeil_doctest.hpp"
Václav Kubernát47a3f672019-11-08 15:42:43 +010010#include <experimental/iterator>
Václav Kubernát3a99f002020-03-31 02:27:41 +020011#include "leaf_data_helpers.hpp"
Václav Kubernát1e09bd62020-02-17 15:13:38 +010012#include "pretty_printers.hpp"
Václav Kubernát0d4db442018-07-18 17:18:43 +020013#include "yang_schema.hpp"
14
Václav Kubernát4f77a252019-02-19 16:51:30 +010015const char* second_schema = R"(
16module second-schema {
17 namespace "http://example.com/nevim";
18 prefix second;
19
20 import example-schema {
21 prefix "example";
22 }
23
Václav Kubernáteeb38842019-03-20 19:46:05 +010024 identity pineapple {
25 base "example:fruit";
26 }
27
Václav Kubernát4f77a252019-02-19 16:51:30 +010028 augment /example:a {
29 container augmentedContainer {
30 }
31 }
32
33 container bla {
34 container bla2 {
35 }
36 }
37}
38)";
39
Václav Kubernát82d74632020-05-11 15:59:53 +020040const char* included_submodule = R"(
41submodule 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át4f77a252019-02-19 16:51:30 +010054const char* example_schema = R"(
Václav Kubernát0d4db442018-07-18 17:18:43 +020055module example-schema {
Václav Kubernát6a713d62018-10-03 18:47:34 +020056 yang-version 1.1;
Václav Kubernát0d4db442018-07-18 17:18:43 +020057 namespace "http://example.com/example-sports";
58 prefix coze;
59
Václav Kubernát82d74632020-05-11 15:59:53 +020060 include sub-module;
61
Václav Kubernáteeb38842019-03-20 19:46:05 +010062 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át0d4db442018-07-18 17:18:43 +020084 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á88c78ca2019-07-02 18:40:07 +0200118 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át1e09bd62020-02-17 15:13:38 +0100135 description "A 32-bit integer leaf.";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200136 type int32;
137 }
138
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200139 leaf leafUint32 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200140 type uint32;
141 }
142
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200143 leaf leafInt64 {
144 type int64;
145 }
146
147 leaf leafUint64 {
148 type uint64;
Václav Kubernátb1a75c62020-04-21 15:20:16 +0200149 default 9001;
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200150 }
151
Václav Kubernát0d4db442018-07-18 17:18:43 +0200152 leaf leafEnum {
153 type enumeration {
154 enum lol;
155 enum data;
156 enum coze;
157 }
158 }
159
Václav Kubernát6a713d62018-10-03 18:47:34 +0200160 typedef enumTypedef {
161 type enumeration {
162 enum lol;
163 enum data;
164 enum coze;
165 }
Václav Kubernátb1a75c62020-04-21 15:20:16 +0200166 default data;
Václav Kubernát6a713d62018-10-03 18:47:34 +0200167 }
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áteeb38842019-03-20 19:46:05 +0100191 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át0d4db442018-07-18 17:18:43 +0200210 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át7d82da72019-04-11 15:16:38 +0200233
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át280df4a2019-11-01 14:46:34 +0100255
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áta38d4172019-11-04 12:36:39 +0100274 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át1e09bd62020-02-17 15:13:38 +0100286 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átbd5e3c22020-02-19 15:22:00 +0100312 leaf activeNumber {
313 type leafref {
314 path "/_list/number";
315 }
316 }
317
Václav Kubernátfa81c8c2020-02-13 17:22:46 +0100318 rpc myRpc {}
319
Václav Kubernátd8408e02020-12-02 05:13:27 +0100320 rpc rpcOneOutput {
321 output {
322 leaf ahoj {
323 type string;
324 }
325 }
326 }
327
328 rpc rpcOneInput {
329 input {
330 leaf ahoj {
331 type string;
332 }
333 }
334 }
335
Václav Kubernát2984f442020-02-20 17:43:35 +0100336 leaf numberOrString {
337 type union {
338 type int32;
339 type string;
340 }
341 description "Can be an int32 or a string.";
342 }
343
344 list portSettings {
345 key "port";
346 leaf port {
347 type enumeration {
348 enum eth0;
349 enum eth1;
350 enum eth2;
351 }
352 }
Václav Kubernáta8789602020-07-20 15:18:19 +0200353 action shutdown {
354 output {
355 leaf success {
356 type boolean;
357 }
358 }
359 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100360 }
361
362 feature weirdPortNames;
363
364 list portMapping {
365 key "port";
366 leaf port {
367 type enumeration {
368 enum WEIRD {
369 if-feature "weirdPortNames";
370 }
371 enum utf2;
372 enum utf3;
373 }
374 }
375 }
376
377 leaf activeMappedPort {
378 type leafref {
379 path "../portMapping/port";
380 }
381 }
382
383 leaf activePort {
384 type union {
385 type enumeration {
386 enum wlan0;
387 enum wlan1;
388 }
389 type leafref {
390 path "../portSettings/port";
391 }
392 type leafref {
393 path "../activeMappedPort";
394 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200395 type empty;
Václav Kubernát2984f442020-02-20 17:43:35 +0100396 }
397 }
398
Jan Kundrát379bb572020-05-07 03:23:13 +0200399 leaf dummyLeaf {
400 type empty;
401 }
402
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200403 leaf clockSpeed {
404 type int64;
405 config false;
406 }
407
408 container systemStats {
409 config false;
410 leaf upTime {
411 type uint64;
412 }
413 }
414
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200415 leaf obsoleteLeaf {
416 type int32;
417 status obsolete;
418 }
419
420 leaf deprecatedLeaf {
421 type int32;
422 status deprecated;
423 }
424
425 typedef deprecatedType {
426 type int32;
427 status deprecated;
428 }
429
430 leaf obsoleteLeafWithDeprecatedType {
431 type deprecatedType;
432 status obsolete;
433 }
434
435 typedef obsoleteType {
436 type int32;
437 status obsolete;
438 }
439
440 leaf obsoleteLeafWithObsoleteType {
441 type deprecatedType;
442 status obsolete;
443 }
444
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200445 leaf-list addresses {
446 type string;
447 }
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100448
449 leaf flagBits {
450 type bits {
451 bit carry;
452 bit sign;
453 bit overflow;
454 }
455 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200456})";
457
458TEST_CASE("yangschema")
459{
Václav Kubernát82d74632020-05-11 15:59:53 +0200460 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100461 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200462 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200463 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
464 if (modName != "example-schema"sv) {
465 throw std::logic_error("unrecognized module "s + modName);
466 }
467 if (subModule == nullptr) {
468 return example_schema;
469 }
470 if (subModule == "sub-module"sv) {
471 return included_submodule;
472 }
473
474 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100475 });
476 ys.addSchemaString(second_schema);
477
Václav Kubernátefcac932020-01-10 15:26:32 +0100478 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200479 ModuleNodePair node;
480
481 SECTION("positive")
482 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200483 SECTION("isModule")
484 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100485 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200486 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100487
Václav Kubernát0d4db442018-07-18 17:18:43 +0200488 SECTION("listHasKey")
489 {
490 std::string key;
491
492 SECTION("_list")
493 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200494 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200495 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200496 {
497 key = "number";
498 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200499 }
500
501 SECTION("twoKeyList")
502 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200503 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200504 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200505 {
506 key = "number";
507 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200508 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200509 {
510 key = "name";
511 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200512 }
513
Václav Kubernát912b9492020-05-29 02:03:40 +0200514 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200515 }
516 SECTION("listKeys")
517 {
518 std::set<std::string> set;
519
520 SECTION("_list")
521 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200522 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200523 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200524 }
525
526 SECTION("twoKeyList")
527 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200528 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200529 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200530 }
531
Václav Kubernát912b9492020-05-29 02:03:40 +0200532 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200533 }
534 SECTION("leafType")
535 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200536 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200537
538 SECTION("leafString")
539 {
540 node.first = "example-schema";
541 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200542 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200543 }
544
545 SECTION("leafDecimal")
546 {
547 node.first = "example-schema";
548 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200549 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200550 }
551
552 SECTION("leafBool")
553 {
554 node.first = "example-schema";
555 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200556 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200557 }
558
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200559 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200560 {
561 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200562 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200563 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200564 }
565
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200566 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200567 {
568 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200569 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200570 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200571 }
572
Václav Kubernátb6d02752020-04-03 00:25:10 +0200573 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200574 {
575 node.first = "example-schema";
576 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200577 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200578 }
579
580 SECTION("leafUint16")
581 {
582 node.first = "example-schema";
583 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200584 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200585 }
586
587 SECTION("leafInt32")
588 {
589 node.first = "example-schema";
590 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200591 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200592 }
593
594 SECTION("leafUint32")
595 {
596 node.first = "example-schema";
597 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200598 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200599 }
600
601 SECTION("leafInt64")
602 {
603 node.first = "example-schema";
604 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200605 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200606 }
607
608 SECTION("leafUint64")
609 {
610 node.first = "example-schema";
611 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200612 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200613 }
614
615 SECTION("leafEnum")
616 {
617 node.first = "example-schema";
618 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200619 type = createEnum({"lol", "data", "coze"});
620 }
621
622 SECTION("leafEnumTypedef")
623 {
624 node.first = "example-schema";
625 node.second = "leafEnumTypedef";
626 type = createEnum({"lol", "data", "coze"});
627 }
628
629 SECTION("leafEnumTypedefRestricted")
630 {
631 node.first = "example-schema";
632 node.second = "leafEnumTypedefRestricted";
633 type = createEnum({"data", "coze"});
634 }
635
636 SECTION("leafEnumTypedefRestricted2")
637 {
638 node.first = "example-schema";
639 node.second = "leafEnumTypedefRestricted2";
640 type = createEnum({"lol", "data"});
641 }
642
643 SECTION("pizzaSize")
644 {
645 node.first = "example-schema";
646 node.second = "pizzaSize";
647
648 SECTION("bigPizzas disabled")
649 {
650 type = createEnum({"small", "medium"});
651 }
652 SECTION("bigPizzas enabled")
653 {
654 ys.enableFeature("example-schema", "bigPizzas");
655 type = createEnum({"small", "medium", "large"});
656 }
657 }
658
659 SECTION("foodIdentLeaf")
660 {
661 node.first = "example-schema";
662 node.second = "foodIdentLeaf";
663 type = yang::IdentityRef{{{"second-schema", "pineapple"},
664 {"example-schema", "food"},
665 {"example-schema", "pizza"},
666 {"example-schema", "hawaii"},
667 {"example-schema", "fruit"}}};
668 }
669
670 SECTION("pizzaIdentLeaf")
671 {
672 node.first = "example-schema";
673 node.second = "pizzaIdentLeaf";
674
675 type = yang::IdentityRef{{
676 {"example-schema", "pizza"},
677 {"example-schema", "hawaii"},
678 }};
679 }
680
681 SECTION("foodDrinkIdentLeaf")
682 {
683 node.first = "example-schema";
684 node.second = "foodDrinkIdentLeaf";
685
686 type = yang::IdentityRef{{
687 {"example-schema", "food"},
688 {"example-schema", "drink"},
689 {"example-schema", "fruit"},
690 {"example-schema", "hawaii"},
691 {"example-schema", "pizza"},
692 {"example-schema", "voda"},
693 {"second-schema", "pineapple"},
694 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200695 }
696
Václav Kubernátb6d02752020-04-03 00:25:10 +0200697 SECTION("activeNumber")
698 {
699 node.first = "example-schema";
700 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200701 type.emplace<yang::LeafRef>(
702 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200703 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200704 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200705 }
706
Václav Kubernát2984f442020-02-20 17:43:35 +0100707 SECTION("activePort")
708 {
709 node.first = "example-schema";
710 node.second = "activePort";
711
Václav Kubernát1dc9e3e2020-06-09 15:22:39 +0200712 yang::Enum enums({});
713 SECTION("weird ports disabled")
714 {
715 enums = createEnum({"utf2", "utf3"});
716 }
717 SECTION("weird ports enabled")
718 {
719 ys.enableFeature("example-schema", "weirdPortNames");
720 enums = createEnum({"WEIRD", "utf2", "utf3"});
721 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100722
723 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200724 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
725 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100726 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200727 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
728 }},
729 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100730 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200731 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100732 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200733 std::make_unique<yang::TypeInfo>(enums)
734 })
735 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200736 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100737 }};
738 }
739
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200740 SECTION("addresses")
741 {
742 node.first = "example-schema";
743 node.second = "addresses";
744 type.emplace<yang::String>();
745 }
746
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100747 SECTION("flagBits")
748 {
749 node.first = "example-schema";
750 node.second = "flagBits";
751 type = yang::Bits{{"carry", "sign", "overflow"}};
752 }
753
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200754
Václav Kubernát0d4db442018-07-18 17:18:43 +0200755 REQUIRE(ys.leafType(path, node) == type);
756 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200757 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200758 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200759 // TODO: merge "path" and "module" sections and add recursive versions to the path section
760 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200761 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200762 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200763
Václav Kubernát95b08872020-04-28 01:04:17 +0200764 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200765 SECTION("<root>")
766 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200767 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
768 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
769 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
770 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
771 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
772 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
773 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
774 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
775 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
776 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
777 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
778 {"example-schema"s, "interrupt"},
779 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
780 {"example-schema"s, "pizzaSize"},
781 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
782 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
783 {"example-schema"s, "activeNumber"},
784 {"example-schema"s, "numberOrString"},
785 {"example-schema"s, "portSettings"},
786 {"example-schema"s, "portMapping"},
787 {"example-schema"s, "activeMappedPort"},
788 {"example-schema"s, "activePort"},
789 {"example-schema"s, "clockSpeed"},
790 {"example-schema"s, "deprecatedLeaf"},
791 {"example-schema"s, "obsoleteLeaf"},
792 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
793 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200794 {"example-schema"s, "myRpc"},
Václav Kubernátd8408e02020-12-02 05:13:27 +0100795 {"example-schema"s, "rpcOneOutput"},
796 {"example-schema"s, "rpcOneInput"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200797 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200798 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200799 {"example-schema"s, "addresses"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100800 {"example-schema"s, "subLeaf"},
801 {"example-schema"s, "flagBits"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200802 }
803
804 SECTION("example-schema:a")
805 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200806 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200807 set = {
808 {boost::none, "a2"},
809 {boost::none, "leafa"},
810 {"second-schema"s, "augmentedContainer"}
811 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200812 }
813
814 SECTION("example-schema:ethernet")
815 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200816 path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200817 set = {{boost::none, "ip"}};
818 }
819
820 SECTION("second-schema:bla")
821 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200822 path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200823 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200824 }
825
826 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200827 }
828
Václav Kubernát3a823f42020-04-29 23:40:21 +0200829 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200830 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200831 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200832 std::set<ModuleNodePair> expectedNonRecursive;
833 std::set<ModuleNodePair> expectedRecursive;
834 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200835 SECTION("example-schema")
836 {
837 module = "example-schema";
838 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200839 {"example-schema"s, "_list"},
840 {"example-schema"s, "a"},
841 {"example-schema"s, "activeMappedPort"},
842 {"example-schema"s, "activeNumber"},
843 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200844 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200845 {"example-schema"s, "another-duration"},
846 {"example-schema"s, "b"},
847 {"example-schema"s, "carry"},
848 {"example-schema"s, "clockSpeed"},
849 {"example-schema"s, "deprecatedLeaf"},
850 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200851 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200852 {"example-schema"s, "duration"},
853 {"example-schema"s, "ethernet"},
854 {"example-schema"s, "foodDrinkIdentLeaf"},
855 {"example-schema"s, "foodIdentLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100856 {"example-schema"s, "flagBits"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200857 {"example-schema"s, "interrupt"},
858 {"example-schema"s, "leafBool"},
859 {"example-schema"s, "leafDecimal"},
860 {"example-schema"s, "leafEnum"},
861 {"example-schema"s, "leafEnumTypedef"},
862 {"example-schema"s, "leafEnumTypedefRestricted"},
863 {"example-schema"s, "leafEnumTypedefRestricted2"},
864 {"example-schema"s, "leafInt16"},
865 {"example-schema"s, "leafInt32"},
866 {"example-schema"s, "leafInt64"},
867 {"example-schema"s, "leafInt8"},
868 {"example-schema"s, "leafString"},
869 {"example-schema"s, "leafUint16"},
870 {"example-schema"s, "leafUint32"},
871 {"example-schema"s, "leafUint64"},
872 {"example-schema"s, "leafUint8"},
873 {"example-schema"s, "length"},
874 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200875 {"example-schema"s, "myRpc"},
Václav Kubernátd8408e02020-12-02 05:13:27 +0100876 {"example-schema"s, "rpcOneOutput"},
877 {"example-schema"s, "rpcOneInput"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200878 {"example-schema"s, "numberOrString"},
879 {"example-schema"s, "obsoleteLeaf"},
880 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
881 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
882 {"example-schema"s, "pizzaIdentLeaf"},
883 {"example-schema"s, "pizzaSize"},
884 {"example-schema"s, "portMapping"},
885 {"example-schema"s, "portSettings"},
886 {"example-schema"s, "systemStats"},
887 {"example-schema"s, "twoKeyList"},
888 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200889 {"example-schema"s, "zero"},
890 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200891 };
892 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200893 {boost::none, "/example-schema:_list"},
894 {boost::none, "/example-schema:_list/contInList"},
895 {boost::none, "/example-schema:_list/number"},
896 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200897 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200898 {boost::none, "/example-schema:a/a2"},
899 {boost::none, "/example-schema:a/a2/a3"},
900 {boost::none, "/example-schema:a/leafa"},
901 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
902 {boost::none, "/example-schema:activeMappedPort"},
903 {boost::none, "/example-schema:activeNumber"},
904 {boost::none, "/example-schema:activePort"},
905 {boost::none, "/example-schema:another-duration"},
906 {boost::none, "/example-schema:b"},
907 {boost::none, "/example-schema:b/b2"},
908 {boost::none, "/example-schema:b/b2/b3"},
909 {boost::none, "/example-schema:carry"},
910 {boost::none, "/example-schema:clockSpeed"},
911 {boost::none, "/example-schema:deprecatedLeaf"},
912 {boost::none, "/example-schema:direction"},
913 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200914 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100915 {boost::none, "/example-schema:flagBits"},
916 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200917 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
918 {boost::none, "/example-schema:foodIdentLeaf"},
919 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
920 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
921 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
922 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
923 {boost::none, "/example-schema:interrupt"},
924 {boost::none, "/example-schema:leafBool"},
925 {boost::none, "/example-schema:leafDecimal"},
926 {boost::none, "/example-schema:leafEnum"},
927 {boost::none, "/example-schema:leafEnumTypedef"},
928 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
929 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
930 {boost::none, "/example-schema:leafInt16"},
931 {boost::none, "/example-schema:leafInt32"},
932 {boost::none, "/example-schema:leafInt64"},
933 {boost::none, "/example-schema:leafInt8"},
934 {boost::none, "/example-schema:leafString"},
935 {boost::none, "/example-schema:leafUint16"},
936 {boost::none, "/example-schema:leafUint32"},
937 {boost::none, "/example-schema:leafUint64"},
938 {boost::none, "/example-schema:leafUint8"},
939 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200940 {boost::none, "/example-schema:myRpc"},
941 {boost::none, "/example-schema:myRpc/input"},
942 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernátd8408e02020-12-02 05:13:27 +0100943 {boost::none, "/example-schema:rpcOneOutput"},
944 {boost::none, "/example-schema:rpcOneOutput/input"},
945 {boost::none, "/example-schema:rpcOneOutput/output"},
946 {boost::none, "/example-schema:rpcOneOutput/output/ahoj"},
947 {boost::none, "/example-schema:rpcOneInput"},
948 {boost::none, "/example-schema:rpcOneInput/input"},
949 {boost::none, "/example-schema:rpcOneInput/input/ahoj"},
950 {boost::none, "/example-schema:rpcOneInput/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200951 {boost::none, "/example-schema:numberOrString"},
952 {boost::none, "/example-schema:obsoleteLeaf"},
953 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
954 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
955 {boost::none, "/example-schema:pizzaIdentLeaf"},
956 {boost::none, "/example-schema:pizzaSize"},
957 {boost::none, "/example-schema:portMapping"},
958 {boost::none, "/example-schema:portMapping/port"},
959 {boost::none, "/example-schema:portSettings"},
960 {boost::none, "/example-schema:portSettings/port"},
Václav Kubernáta8789602020-07-20 15:18:19 +0200961 {boost::none, "/example-schema:portSettings/shutdown"},
962 {boost::none, "/example-schema:portSettings/shutdown/input"},
963 {boost::none, "/example-schema:portSettings/shutdown/output"},
964 {boost::none, "/example-schema:portSettings/shutdown/output/success"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200965 {boost::none, "/example-schema:systemStats"},
966 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200967 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200968 {boost::none, "/example-schema:twoKeyList"},
969 {boost::none, "/example-schema:twoKeyList/name"},
970 {boost::none, "/example-schema:twoKeyList/number"},
971 {boost::none, "/example-schema:wavelength"},
972 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200973 };
974 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200975 SECTION("second-schema")
976 {
977 module = "second-schema";
978 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200979 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200980 };
981 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200982 {boost::none, "/second-schema:bla"},
983 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200984 };
985 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200986
Václav Kubernát3a823f42020-04-29 23:40:21 +0200987 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
988 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +0100989 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200990 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100991 SECTION("nodeType")
992 {
993 yang::NodeTypes expected;
994 SECTION("leafInt32")
995 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200996 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100997 expected = yang::NodeTypes::Leaf;
998 }
999
1000 SECTION("a")
1001 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001002 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001003 expected = yang::NodeTypes::Container;
1004 }
1005
1006 SECTION("a/a2/a3")
1007 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001008 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1009 path.m_nodes.emplace_back(container_("a2"));
1010 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001011 expected = yang::NodeTypes::PresenceContainer;
1012 }
1013
1014 SECTION("_list")
1015 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001016 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001017 expected = yang::NodeTypes::List;
1018 }
1019
Václav Kubernát82d74632020-05-11 15:59:53 +02001020 SECTION("subLeaf")
1021 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001022 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf"));
Václav Kubernát82d74632020-05-11 15:59:53 +02001023 expected = yang::NodeTypes::Leaf;
1024 }
1025
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001026 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1027 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001028
1029 SECTION("description")
1030 {
1031 std::optional<std::string> expected;
1032 SECTION("leafInt32")
1033 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001034 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001035 expected = "A 32-bit integer leaf.";
1036 }
1037
1038 SECTION("leafString")
1039 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001040 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001041 }
1042
Václav Kubernát2984f442020-02-20 17:43:35 +01001043 SECTION("numberOrString")
1044 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001045 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +01001046 expected = "Can be an int32 or a string.";
1047 }
1048
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001049 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1050 }
1051
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001052 SECTION("status")
1053 {
1054 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1055 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1056 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1057 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1058 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1059 }
1060
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001061 SECTION("units")
1062 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001063 yang::LeafDataType expectedType;
1064 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001065 SECTION("length")
1066 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001067 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001068 expectedType.emplace<yang::Int32>();
1069 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001070 }
1071
1072 SECTION("wavelength")
1073 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001074 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001075 expectedType.emplace<yang::Decimal>();
1076 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001077 }
1078
1079 SECTION("leafInt32")
1080 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001081 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001082 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001083 }
1084
1085 SECTION("duration")
1086 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001087 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001088 expectedType.emplace<yang::Int32>();
1089 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001090 }
1091
1092 SECTION("another-duration")
1093 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001094 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001095 expectedType.emplace<yang::Int32>();
1096 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001097 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001098 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1099 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001100 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001101 }
1102
1103 SECTION("nodeType")
1104 {
1105 yang::NodeTypes expected;
1106 SECTION("leafInt32")
1107 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001108 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001109 expected = yang::NodeTypes::Leaf;
1110 }
1111
1112 SECTION("a")
1113 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001114 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001115 expected = yang::NodeTypes::Container;
1116 }
1117
1118 SECTION("a/a2/a3")
1119 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001120 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1121 path.m_nodes.emplace_back(container_("a2"));
1122 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001123 expected = yang::NodeTypes::PresenceContainer;
1124 }
1125
1126 SECTION("_list")
1127 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001128 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001129 expected = yang::NodeTypes::List;
1130 }
1131
1132 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1133 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001134
1135 SECTION("leafrefPath")
1136 {
1137 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1138 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001139
1140 SECTION("isConfig")
1141 {
1142 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1143 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1144 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1145 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1146 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001147
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001148 SECTION("defaultValue")
1149 {
1150 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1151 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1152 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1153 }
1154
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001155 SECTION("leafTypeName")
1156 {
1157 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1158 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1159 }
Václav Kubernáta8789602020-07-20 15:18:19 +02001160
1161 SECTION("dataPathToSchemaPath")
1162 {
1163 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings");
1164 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown");
1165 }
Václav Kubernátd8408e02020-12-02 05:13:27 +01001166
1167 SECTION("has input nodes")
1168 {
1169 bool expected;
1170 SECTION("example-schema:myRpc")
1171 {
1172 path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"myRpc"});
1173 expected = false;
1174 }
1175
1176 SECTION("example-schema:rpcOneInput")
1177 {
1178 path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"rpcOneInput"});
1179 expected = true;
1180 }
1181
1182 SECTION("example-schema:rpcOneOutput")
1183 {
1184 path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"rpcOneOutput"});
1185 expected = false;
1186 }
1187
1188 REQUIRE(ys.hasInputNodes(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1189 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001190 }
1191
1192 SECTION("negative")
1193 {
1194 SECTION("nonexistent nodes")
1195 {
1196 SECTION("example-schema:coze")
1197 {
1198 node.first = "example-schema";
1199 node.second = "coze";
1200 }
1201
1202 SECTION("example-schema:a/nevim")
1203 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001204 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001205 node.second = "nevim";
1206 }
1207
1208 SECTION("modul:a/nevim")
1209 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001210 path.m_nodes.emplace_back(module_{"modul"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001211 node.second = "nevim";
1212 }
1213
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001214 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001215 }
1216
1217 SECTION("nodetype-specific methods called with different nodetypes")
1218 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001219 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1220 path.m_nodes.emplace_back(container_("a2"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001221
Václav Kubernát912b9492020-05-29 02:03:40 +02001222 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001223 }
1224
1225 SECTION("nonexistent module")
1226 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001227 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001228 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001229
Václav Kubernát7d82da72019-04-11 15:16:38 +02001230 SECTION("grouping is not a node")
1231 {
1232 SECTION("example-schema:arithmeticFlags")
1233 {
1234 node.first = "example-schema";
1235 node.second = "arithmeticFlags";
1236 }
1237
1238 SECTION("example-schema:flags")
1239 {
1240 node.first = "example-schema";
1241 node.second = "startAndStop";
1242 }
1243
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001244 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát7d82da72019-04-11 15:16:38 +02001245 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001246
1247 SECTION("choice is not a node")
1248 {
1249 SECTION("example-schema:interface")
1250 {
1251 node.first = "example-schema";
1252 node.second = "interface";
1253 }
1254
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001255 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001256 }
1257
1258 SECTION("case is not a node")
1259 {
1260 SECTION("example-schema:caseLoopback")
1261 {
1262 node.first = "example-schema";
1263 node.second = "caseLoopback";
1264 }
1265
1266 SECTION("example-schema:caseEthernet")
1267 {
1268 node.first = "example-schema";
1269 node.second = "caseEthernet";
1270 }
1271
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001272 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001273 }
Václav Kubernátf44bdda2020-06-22 15:58:41 +02001274
1275 SECTION("enableFeature - non existing module")
1276 {
1277 REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error);
1278 }
Václav Kubernát7aaf6dc2020-06-26 18:03:57 +02001279
1280 SECTION("enableFeature - non existing feature")
1281 {
1282 REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error);
1283 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001284 }
1285}