blob: f226778b0457badbaa6f54eb7077ac0ca0f7b1f1 [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át47a3f672019-11-08 15:42:43 +01009#include <experimental/iterator>
Václav Kubernát3a99f002020-03-31 02:27:41 +020010#include "leaf_data_helpers.hpp"
Václav Kubernát1e09bd62020-02-17 15:13:38 +010011#include "pretty_printers.hpp"
Václav Kubernát26b56082020-02-03 18:28:56 +010012#include "trompeloeil_doctest.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át2984f442020-02-20 17:43:35 +0100320 leaf numberOrString {
321 type union {
322 type int32;
323 type string;
324 }
325 description "Can be an int32 or a string.";
326 }
327
328 list portSettings {
329 key "port";
330 leaf port {
331 type enumeration {
332 enum eth0;
333 enum eth1;
334 enum eth2;
335 }
336 }
Václav Kubernáta8789602020-07-20 15:18:19 +0200337 action shutdown {
338 output {
339 leaf success {
340 type boolean;
341 }
342 }
343 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100344 }
345
346 feature weirdPortNames;
347
348 list portMapping {
349 key "port";
350 leaf port {
351 type enumeration {
352 enum WEIRD {
353 if-feature "weirdPortNames";
354 }
355 enum utf2;
356 enum utf3;
357 }
358 }
359 }
360
361 leaf activeMappedPort {
362 type leafref {
363 path "../portMapping/port";
364 }
365 }
366
367 leaf activePort {
368 type union {
369 type enumeration {
370 enum wlan0;
371 enum wlan1;
372 }
373 type leafref {
374 path "../portSettings/port";
375 }
376 type leafref {
377 path "../activeMappedPort";
378 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200379 type empty;
Václav Kubernát2984f442020-02-20 17:43:35 +0100380 }
381 }
382
Jan Kundrát379bb572020-05-07 03:23:13 +0200383 leaf dummyLeaf {
384 type empty;
385 }
386
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200387 leaf clockSpeed {
388 type int64;
389 config false;
390 }
391
392 container systemStats {
393 config false;
394 leaf upTime {
395 type uint64;
396 }
397 }
398
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200399 leaf obsoleteLeaf {
400 type int32;
401 status obsolete;
402 }
403
404 leaf deprecatedLeaf {
405 type int32;
406 status deprecated;
407 }
408
409 typedef deprecatedType {
410 type int32;
411 status deprecated;
412 }
413
414 leaf obsoleteLeafWithDeprecatedType {
415 type deprecatedType;
416 status obsolete;
417 }
418
419 typedef obsoleteType {
420 type int32;
421 status obsolete;
422 }
423
424 leaf obsoleteLeafWithObsoleteType {
425 type deprecatedType;
426 status obsolete;
427 }
428
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200429 leaf-list addresses {
430 type string;
431 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200432})";
433
434TEST_CASE("yangschema")
435{
Václav Kubernát82d74632020-05-11 15:59:53 +0200436 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100437 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200438 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200439 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
440 if (modName != "example-schema"sv) {
441 throw std::logic_error("unrecognized module "s + modName);
442 }
443 if (subModule == nullptr) {
444 return example_schema;
445 }
446 if (subModule == "sub-module"sv) {
447 return included_submodule;
448 }
449
450 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100451 });
452 ys.addSchemaString(second_schema);
453
Václav Kubernátefcac932020-01-10 15:26:32 +0100454 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200455 ModuleNodePair node;
456
457 SECTION("positive")
458 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200459 SECTION("isModule")
460 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100461 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200462 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100463
Václav Kubernát0d4db442018-07-18 17:18:43 +0200464 SECTION("listHasKey")
465 {
466 std::string key;
467
468 SECTION("_list")
469 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200470 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200471 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200472 {
473 key = "number";
474 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200475 }
476
477 SECTION("twoKeyList")
478 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200479 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200480 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200481 {
482 key = "number";
483 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200484 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200485 {
486 key = "name";
487 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200488 }
489
Václav Kubernát912b9492020-05-29 02:03:40 +0200490 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200491 }
492 SECTION("listKeys")
493 {
494 std::set<std::string> set;
495
496 SECTION("_list")
497 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200498 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200499 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200500 }
501
502 SECTION("twoKeyList")
503 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200504 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200505 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200506 }
507
Václav Kubernát912b9492020-05-29 02:03:40 +0200508 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200509 }
510 SECTION("leafType")
511 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200512 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200513
514 SECTION("leafString")
515 {
516 node.first = "example-schema";
517 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200518 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200519 }
520
521 SECTION("leafDecimal")
522 {
523 node.first = "example-schema";
524 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200525 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200526 }
527
528 SECTION("leafBool")
529 {
530 node.first = "example-schema";
531 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200532 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200533 }
534
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200535 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200536 {
537 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200538 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200539 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200540 }
541
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200542 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200543 {
544 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200545 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200546 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200547 }
548
Václav Kubernátb6d02752020-04-03 00:25:10 +0200549 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200550 {
551 node.first = "example-schema";
552 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200553 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200554 }
555
556 SECTION("leafUint16")
557 {
558 node.first = "example-schema";
559 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200560 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200561 }
562
563 SECTION("leafInt32")
564 {
565 node.first = "example-schema";
566 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200567 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200568 }
569
570 SECTION("leafUint32")
571 {
572 node.first = "example-schema";
573 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200574 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200575 }
576
577 SECTION("leafInt64")
578 {
579 node.first = "example-schema";
580 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200581 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200582 }
583
584 SECTION("leafUint64")
585 {
586 node.first = "example-schema";
587 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200588 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200589 }
590
591 SECTION("leafEnum")
592 {
593 node.first = "example-schema";
594 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200595 type = createEnum({"lol", "data", "coze"});
596 }
597
598 SECTION("leafEnumTypedef")
599 {
600 node.first = "example-schema";
601 node.second = "leafEnumTypedef";
602 type = createEnum({"lol", "data", "coze"});
603 }
604
605 SECTION("leafEnumTypedefRestricted")
606 {
607 node.first = "example-schema";
608 node.second = "leafEnumTypedefRestricted";
609 type = createEnum({"data", "coze"});
610 }
611
612 SECTION("leafEnumTypedefRestricted2")
613 {
614 node.first = "example-schema";
615 node.second = "leafEnumTypedefRestricted2";
616 type = createEnum({"lol", "data"});
617 }
618
619 SECTION("pizzaSize")
620 {
621 node.first = "example-schema";
622 node.second = "pizzaSize";
623
624 SECTION("bigPizzas disabled")
625 {
626 type = createEnum({"small", "medium"});
627 }
628 SECTION("bigPizzas enabled")
629 {
630 ys.enableFeature("example-schema", "bigPizzas");
631 type = createEnum({"small", "medium", "large"});
632 }
633 }
634
635 SECTION("foodIdentLeaf")
636 {
637 node.first = "example-schema";
638 node.second = "foodIdentLeaf";
639 type = yang::IdentityRef{{{"second-schema", "pineapple"},
640 {"example-schema", "food"},
641 {"example-schema", "pizza"},
642 {"example-schema", "hawaii"},
643 {"example-schema", "fruit"}}};
644 }
645
646 SECTION("pizzaIdentLeaf")
647 {
648 node.first = "example-schema";
649 node.second = "pizzaIdentLeaf";
650
651 type = yang::IdentityRef{{
652 {"example-schema", "pizza"},
653 {"example-schema", "hawaii"},
654 }};
655 }
656
657 SECTION("foodDrinkIdentLeaf")
658 {
659 node.first = "example-schema";
660 node.second = "foodDrinkIdentLeaf";
661
662 type = yang::IdentityRef{{
663 {"example-schema", "food"},
664 {"example-schema", "drink"},
665 {"example-schema", "fruit"},
666 {"example-schema", "hawaii"},
667 {"example-schema", "pizza"},
668 {"example-schema", "voda"},
669 {"second-schema", "pineapple"},
670 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200671 }
672
Václav Kubernátb6d02752020-04-03 00:25:10 +0200673 SECTION("activeNumber")
674 {
675 node.first = "example-schema";
676 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200677 type.emplace<yang::LeafRef>(
678 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200679 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200680 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200681 }
682
Václav Kubernát2984f442020-02-20 17:43:35 +0100683 SECTION("activePort")
684 {
685 node.first = "example-schema";
686 node.second = "activePort";
687
Václav Kubernát1dc9e3e2020-06-09 15:22:39 +0200688 yang::Enum enums({});
689 SECTION("weird ports disabled")
690 {
691 enums = createEnum({"utf2", "utf3"});
692 }
693 SECTION("weird ports enabled")
694 {
695 ys.enableFeature("example-schema", "weirdPortNames");
696 enums = createEnum({"WEIRD", "utf2", "utf3"});
697 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100698
699 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200700 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
701 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100702 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200703 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
704 }},
705 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100706 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200707 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100708 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200709 std::make_unique<yang::TypeInfo>(enums)
710 })
711 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200712 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100713 }};
714 }
715
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200716 SECTION("addresses")
717 {
718 node.first = "example-schema";
719 node.second = "addresses";
720 type.emplace<yang::String>();
721 }
722
723
Václav Kubernát0d4db442018-07-18 17:18:43 +0200724 REQUIRE(ys.leafType(path, node) == type);
725 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200726 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200727 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200728 // TODO: merge "path" and "module" sections and add recursive versions to the path section
729 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200730 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200731 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200732
Václav Kubernát95b08872020-04-28 01:04:17 +0200733 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200734 SECTION("<root>")
735 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200736 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
737 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
738 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
739 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
740 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
741 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
742 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
743 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
744 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
745 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
746 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
747 {"example-schema"s, "interrupt"},
748 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
749 {"example-schema"s, "pizzaSize"},
750 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
751 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
752 {"example-schema"s, "activeNumber"},
753 {"example-schema"s, "numberOrString"},
754 {"example-schema"s, "portSettings"},
755 {"example-schema"s, "portMapping"},
756 {"example-schema"s, "activeMappedPort"},
757 {"example-schema"s, "activePort"},
758 {"example-schema"s, "clockSpeed"},
759 {"example-schema"s, "deprecatedLeaf"},
760 {"example-schema"s, "obsoleteLeaf"},
761 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
762 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200763 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200764 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200765 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200766 {"example-schema"s, "addresses"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200767 {"example-schema"s, "subLeaf"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200768 }
769
770 SECTION("example-schema:a")
771 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200772 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200773 set = {
774 {boost::none, "a2"},
775 {boost::none, "leafa"},
776 {"second-schema"s, "augmentedContainer"}
777 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200778 }
779
780 SECTION("example-schema:ethernet")
781 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200782 path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200783 set = {{boost::none, "ip"}};
784 }
785
786 SECTION("second-schema:bla")
787 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200788 path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200789 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200790 }
791
792 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200793 }
794
Václav Kubernát3a823f42020-04-29 23:40:21 +0200795 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200796 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200797 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200798 std::set<ModuleNodePair> expectedNonRecursive;
799 std::set<ModuleNodePair> expectedRecursive;
800 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200801 SECTION("example-schema")
802 {
803 module = "example-schema";
804 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200805 {"example-schema"s, "_list"},
806 {"example-schema"s, "a"},
807 {"example-schema"s, "activeMappedPort"},
808 {"example-schema"s, "activeNumber"},
809 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200810 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200811 {"example-schema"s, "another-duration"},
812 {"example-schema"s, "b"},
813 {"example-schema"s, "carry"},
814 {"example-schema"s, "clockSpeed"},
815 {"example-schema"s, "deprecatedLeaf"},
816 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200817 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200818 {"example-schema"s, "duration"},
819 {"example-schema"s, "ethernet"},
820 {"example-schema"s, "foodDrinkIdentLeaf"},
821 {"example-schema"s, "foodIdentLeaf"},
822 {"example-schema"s, "interrupt"},
823 {"example-schema"s, "leafBool"},
824 {"example-schema"s, "leafDecimal"},
825 {"example-schema"s, "leafEnum"},
826 {"example-schema"s, "leafEnumTypedef"},
827 {"example-schema"s, "leafEnumTypedefRestricted"},
828 {"example-schema"s, "leafEnumTypedefRestricted2"},
829 {"example-schema"s, "leafInt16"},
830 {"example-schema"s, "leafInt32"},
831 {"example-schema"s, "leafInt64"},
832 {"example-schema"s, "leafInt8"},
833 {"example-schema"s, "leafString"},
834 {"example-schema"s, "leafUint16"},
835 {"example-schema"s, "leafUint32"},
836 {"example-schema"s, "leafUint64"},
837 {"example-schema"s, "leafUint8"},
838 {"example-schema"s, "length"},
839 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200840 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200841 {"example-schema"s, "numberOrString"},
842 {"example-schema"s, "obsoleteLeaf"},
843 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
844 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
845 {"example-schema"s, "pizzaIdentLeaf"},
846 {"example-schema"s, "pizzaSize"},
847 {"example-schema"s, "portMapping"},
848 {"example-schema"s, "portSettings"},
849 {"example-schema"s, "systemStats"},
850 {"example-schema"s, "twoKeyList"},
851 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200852 {"example-schema"s, "zero"},
853 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200854 };
855 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200856 {boost::none, "/example-schema:_list"},
857 {boost::none, "/example-schema:_list/contInList"},
858 {boost::none, "/example-schema:_list/number"},
859 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200860 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200861 {boost::none, "/example-schema:a/a2"},
862 {boost::none, "/example-schema:a/a2/a3"},
863 {boost::none, "/example-schema:a/leafa"},
864 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
865 {boost::none, "/example-schema:activeMappedPort"},
866 {boost::none, "/example-schema:activeNumber"},
867 {boost::none, "/example-schema:activePort"},
868 {boost::none, "/example-schema:another-duration"},
869 {boost::none, "/example-schema:b"},
870 {boost::none, "/example-schema:b/b2"},
871 {boost::none, "/example-schema:b/b2/b3"},
872 {boost::none, "/example-schema:carry"},
873 {boost::none, "/example-schema:clockSpeed"},
874 {boost::none, "/example-schema:deprecatedLeaf"},
875 {boost::none, "/example-schema:direction"},
876 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200877 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200878 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
879 {boost::none, "/example-schema:foodIdentLeaf"},
880 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
881 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
882 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
883 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
884 {boost::none, "/example-schema:interrupt"},
885 {boost::none, "/example-schema:leafBool"},
886 {boost::none, "/example-schema:leafDecimal"},
887 {boost::none, "/example-schema:leafEnum"},
888 {boost::none, "/example-schema:leafEnumTypedef"},
889 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
890 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
891 {boost::none, "/example-schema:leafInt16"},
892 {boost::none, "/example-schema:leafInt32"},
893 {boost::none, "/example-schema:leafInt64"},
894 {boost::none, "/example-schema:leafInt8"},
895 {boost::none, "/example-schema:leafString"},
896 {boost::none, "/example-schema:leafUint16"},
897 {boost::none, "/example-schema:leafUint32"},
898 {boost::none, "/example-schema:leafUint64"},
899 {boost::none, "/example-schema:leafUint8"},
900 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200901 {boost::none, "/example-schema:myRpc"},
902 {boost::none, "/example-schema:myRpc/input"},
903 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200904 {boost::none, "/example-schema:numberOrString"},
905 {boost::none, "/example-schema:obsoleteLeaf"},
906 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
907 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
908 {boost::none, "/example-schema:pizzaIdentLeaf"},
909 {boost::none, "/example-schema:pizzaSize"},
910 {boost::none, "/example-schema:portMapping"},
911 {boost::none, "/example-schema:portMapping/port"},
912 {boost::none, "/example-schema:portSettings"},
913 {boost::none, "/example-schema:portSettings/port"},
Václav Kubernáta8789602020-07-20 15:18:19 +0200914 {boost::none, "/example-schema:portSettings/shutdown"},
915 {boost::none, "/example-schema:portSettings/shutdown/input"},
916 {boost::none, "/example-schema:portSettings/shutdown/output"},
917 {boost::none, "/example-schema:portSettings/shutdown/output/success"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200918 {boost::none, "/example-schema:systemStats"},
919 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200920 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200921 {boost::none, "/example-schema:twoKeyList"},
922 {boost::none, "/example-schema:twoKeyList/name"},
923 {boost::none, "/example-schema:twoKeyList/number"},
924 {boost::none, "/example-schema:wavelength"},
925 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200926 };
927 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200928 SECTION("second-schema")
929 {
930 module = "second-schema";
931 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200932 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200933 };
934 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200935 {boost::none, "/second-schema:bla"},
936 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200937 };
938 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200939
Václav Kubernát3a823f42020-04-29 23:40:21 +0200940 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
941 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +0100942 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200943 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100944 SECTION("nodeType")
945 {
946 yang::NodeTypes expected;
947 SECTION("leafInt32")
948 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200949 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100950 expected = yang::NodeTypes::Leaf;
951 }
952
953 SECTION("a")
954 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200955 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100956 expected = yang::NodeTypes::Container;
957 }
958
959 SECTION("a/a2/a3")
960 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200961 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
962 path.m_nodes.emplace_back(container_("a2"));
963 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100964 expected = yang::NodeTypes::PresenceContainer;
965 }
966
967 SECTION("_list")
968 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200969 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100970 expected = yang::NodeTypes::List;
971 }
972
Václav Kubernát82d74632020-05-11 15:59:53 +0200973 SECTION("subLeaf")
974 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200975 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf"));
Václav Kubernát82d74632020-05-11 15:59:53 +0200976 expected = yang::NodeTypes::Leaf;
977 }
978
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100979 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
980 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100981
982 SECTION("description")
983 {
984 std::optional<std::string> expected;
985 SECTION("leafInt32")
986 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200987 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100988 expected = "A 32-bit integer leaf.";
989 }
990
991 SECTION("leafString")
992 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200993 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100994 }
995
Václav Kubernát2984f442020-02-20 17:43:35 +0100996 SECTION("numberOrString")
997 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200998 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +0100999 expected = "Can be an int32 or a string.";
1000 }
1001
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001002 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1003 }
1004
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001005 SECTION("status")
1006 {
1007 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1008 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1009 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1010 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1011 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1012 }
1013
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001014 SECTION("units")
1015 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001016 yang::LeafDataType expectedType;
1017 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001018 SECTION("length")
1019 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001020 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001021 expectedType.emplace<yang::Int32>();
1022 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001023 }
1024
1025 SECTION("wavelength")
1026 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001027 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001028 expectedType.emplace<yang::Decimal>();
1029 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001030 }
1031
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át13b23d72020-04-16 21:49:51 +02001035 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001036 }
1037
1038 SECTION("duration")
1039 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001040 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001041 expectedType.emplace<yang::Int32>();
1042 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001043 }
1044
1045 SECTION("another-duration")
1046 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001047 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001048 expectedType.emplace<yang::Int32>();
1049 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001050 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001051 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1052 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001053 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001054 }
1055
1056 SECTION("nodeType")
1057 {
1058 yang::NodeTypes expected;
1059 SECTION("leafInt32")
1060 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001061 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001062 expected = yang::NodeTypes::Leaf;
1063 }
1064
1065 SECTION("a")
1066 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001067 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001068 expected = yang::NodeTypes::Container;
1069 }
1070
1071 SECTION("a/a2/a3")
1072 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001073 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1074 path.m_nodes.emplace_back(container_("a2"));
1075 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001076 expected = yang::NodeTypes::PresenceContainer;
1077 }
1078
1079 SECTION("_list")
1080 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001081 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001082 expected = yang::NodeTypes::List;
1083 }
1084
1085 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1086 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001087
1088 SECTION("leafrefPath")
1089 {
1090 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1091 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001092
1093 SECTION("isConfig")
1094 {
1095 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1096 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1097 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1098 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1099 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001100
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001101 SECTION("defaultValue")
1102 {
1103 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1104 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1105 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1106 }
1107
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001108 SECTION("leafTypeName")
1109 {
1110 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1111 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1112 }
Václav Kubernáta8789602020-07-20 15:18:19 +02001113
1114 SECTION("dataPathToSchemaPath")
1115 {
1116 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings");
1117 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown");
1118 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001119 }
1120
1121 SECTION("negative")
1122 {
1123 SECTION("nonexistent nodes")
1124 {
1125 SECTION("example-schema:coze")
1126 {
1127 node.first = "example-schema";
1128 node.second = "coze";
1129 }
1130
1131 SECTION("example-schema:a/nevim")
1132 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001133 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001134 node.second = "nevim";
1135 }
1136
1137 SECTION("modul:a/nevim")
1138 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001139 path.m_nodes.emplace_back(module_{"modul"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001140 node.second = "nevim";
1141 }
1142
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001143 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001144 }
1145
1146 SECTION("nodetype-specific methods called with different nodetypes")
1147 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001148 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1149 path.m_nodes.emplace_back(container_("a2"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001150
Václav Kubernát912b9492020-05-29 02:03:40 +02001151 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001152 }
1153
1154 SECTION("nonexistent module")
1155 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001156 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001157 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001158
Václav Kubernát7d82da72019-04-11 15:16:38 +02001159 SECTION("grouping is not a node")
1160 {
1161 SECTION("example-schema:arithmeticFlags")
1162 {
1163 node.first = "example-schema";
1164 node.second = "arithmeticFlags";
1165 }
1166
1167 SECTION("example-schema:flags")
1168 {
1169 node.first = "example-schema";
1170 node.second = "startAndStop";
1171 }
1172
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001173 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát7d82da72019-04-11 15:16:38 +02001174 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001175
1176 SECTION("choice is not a node")
1177 {
1178 SECTION("example-schema:interface")
1179 {
1180 node.first = "example-schema";
1181 node.second = "interface";
1182 }
1183
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001184 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001185 }
1186
1187 SECTION("case is not a node")
1188 {
1189 SECTION("example-schema:caseLoopback")
1190 {
1191 node.first = "example-schema";
1192 node.second = "caseLoopback";
1193 }
1194
1195 SECTION("example-schema:caseEthernet")
1196 {
1197 node.first = "example-schema";
1198 node.second = "caseEthernet";
1199 }
1200
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001201 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001202 }
Václav Kubernátf44bdda2020-06-22 15:58:41 +02001203
1204 SECTION("enableFeature - non existing module")
1205 {
1206 REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error);
1207 }
Václav Kubernát7aaf6dc2020-06-26 18:03:57 +02001208
1209 SECTION("enableFeature - non existing feature")
1210 {
1211 REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error);
1212 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001213 }
1214}