blob: 1ec6507f6ed2a4b45c0d46ad1f425a725dcf265d [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á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átdab73ca2020-10-26 23:44:43 +0100432
433 leaf flagBits {
434 type bits {
435 bit carry;
436 bit sign;
437 bit overflow;
438 }
439 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200440})";
441
442TEST_CASE("yangschema")
443{
Václav Kubernát82d74632020-05-11 15:59:53 +0200444 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100445 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200446 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200447 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
448 if (modName != "example-schema"sv) {
449 throw std::logic_error("unrecognized module "s + modName);
450 }
451 if (subModule == nullptr) {
452 return example_schema;
453 }
454 if (subModule == "sub-module"sv) {
455 return included_submodule;
456 }
457
458 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100459 });
460 ys.addSchemaString(second_schema);
461
Václav Kubernátefcac932020-01-10 15:26:32 +0100462 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200463 ModuleNodePair node;
464
465 SECTION("positive")
466 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200467 SECTION("isModule")
468 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100469 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200470 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100471
Václav Kubernát0d4db442018-07-18 17:18:43 +0200472 SECTION("listHasKey")
473 {
474 std::string key;
475
476 SECTION("_list")
477 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200478 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200479 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200480 {
481 key = "number";
482 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200483 }
484
485 SECTION("twoKeyList")
486 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200487 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200488 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200489 {
490 key = "number";
491 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200492 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200493 {
494 key = "name";
495 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200496 }
497
Václav Kubernát912b9492020-05-29 02:03:40 +0200498 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200499 }
500 SECTION("listKeys")
501 {
502 std::set<std::string> set;
503
504 SECTION("_list")
505 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200506 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200507 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200508 }
509
510 SECTION("twoKeyList")
511 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200512 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200513 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200514 }
515
Václav Kubernát912b9492020-05-29 02:03:40 +0200516 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200517 }
518 SECTION("leafType")
519 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200520 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200521
522 SECTION("leafString")
523 {
524 node.first = "example-schema";
525 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200526 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200527 }
528
529 SECTION("leafDecimal")
530 {
531 node.first = "example-schema";
532 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200533 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200534 }
535
536 SECTION("leafBool")
537 {
538 node.first = "example-schema";
539 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200540 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200541 }
542
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200543 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200544 {
545 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200546 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200547 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200548 }
549
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200550 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200551 {
552 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200553 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200554 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200555 }
556
Václav Kubernátb6d02752020-04-03 00:25:10 +0200557 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200558 {
559 node.first = "example-schema";
560 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200561 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200562 }
563
564 SECTION("leafUint16")
565 {
566 node.first = "example-schema";
567 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200568 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200569 }
570
571 SECTION("leafInt32")
572 {
573 node.first = "example-schema";
574 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200575 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200576 }
577
578 SECTION("leafUint32")
579 {
580 node.first = "example-schema";
581 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200582 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200583 }
584
585 SECTION("leafInt64")
586 {
587 node.first = "example-schema";
588 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200589 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200590 }
591
592 SECTION("leafUint64")
593 {
594 node.first = "example-schema";
595 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200596 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200597 }
598
599 SECTION("leafEnum")
600 {
601 node.first = "example-schema";
602 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200603 type = createEnum({"lol", "data", "coze"});
604 }
605
606 SECTION("leafEnumTypedef")
607 {
608 node.first = "example-schema";
609 node.second = "leafEnumTypedef";
610 type = createEnum({"lol", "data", "coze"});
611 }
612
613 SECTION("leafEnumTypedefRestricted")
614 {
615 node.first = "example-schema";
616 node.second = "leafEnumTypedefRestricted";
617 type = createEnum({"data", "coze"});
618 }
619
620 SECTION("leafEnumTypedefRestricted2")
621 {
622 node.first = "example-schema";
623 node.second = "leafEnumTypedefRestricted2";
624 type = createEnum({"lol", "data"});
625 }
626
627 SECTION("pizzaSize")
628 {
629 node.first = "example-schema";
630 node.second = "pizzaSize";
631
632 SECTION("bigPizzas disabled")
633 {
634 type = createEnum({"small", "medium"});
635 }
636 SECTION("bigPizzas enabled")
637 {
638 ys.enableFeature("example-schema", "bigPizzas");
639 type = createEnum({"small", "medium", "large"});
640 }
641 }
642
643 SECTION("foodIdentLeaf")
644 {
645 node.first = "example-schema";
646 node.second = "foodIdentLeaf";
647 type = yang::IdentityRef{{{"second-schema", "pineapple"},
648 {"example-schema", "food"},
649 {"example-schema", "pizza"},
650 {"example-schema", "hawaii"},
651 {"example-schema", "fruit"}}};
652 }
653
654 SECTION("pizzaIdentLeaf")
655 {
656 node.first = "example-schema";
657 node.second = "pizzaIdentLeaf";
658
659 type = yang::IdentityRef{{
660 {"example-schema", "pizza"},
661 {"example-schema", "hawaii"},
662 }};
663 }
664
665 SECTION("foodDrinkIdentLeaf")
666 {
667 node.first = "example-schema";
668 node.second = "foodDrinkIdentLeaf";
669
670 type = yang::IdentityRef{{
671 {"example-schema", "food"},
672 {"example-schema", "drink"},
673 {"example-schema", "fruit"},
674 {"example-schema", "hawaii"},
675 {"example-schema", "pizza"},
676 {"example-schema", "voda"},
677 {"second-schema", "pineapple"},
678 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200679 }
680
Václav Kubernátb6d02752020-04-03 00:25:10 +0200681 SECTION("activeNumber")
682 {
683 node.first = "example-schema";
684 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200685 type.emplace<yang::LeafRef>(
686 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200687 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200688 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200689 }
690
Václav Kubernát2984f442020-02-20 17:43:35 +0100691 SECTION("activePort")
692 {
693 node.first = "example-schema";
694 node.second = "activePort";
695
Václav Kubernát1dc9e3e2020-06-09 15:22:39 +0200696 yang::Enum enums({});
697 SECTION("weird ports disabled")
698 {
699 enums = createEnum({"utf2", "utf3"});
700 }
701 SECTION("weird ports enabled")
702 {
703 ys.enableFeature("example-schema", "weirdPortNames");
704 enums = createEnum({"WEIRD", "utf2", "utf3"});
705 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100706
707 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200708 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
709 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100710 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200711 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
712 }},
713 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100714 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200715 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100716 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200717 std::make_unique<yang::TypeInfo>(enums)
718 })
719 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200720 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100721 }};
722 }
723
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200724 SECTION("addresses")
725 {
726 node.first = "example-schema";
727 node.second = "addresses";
728 type.emplace<yang::String>();
729 }
730
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100731 SECTION("flagBits")
732 {
733 node.first = "example-schema";
734 node.second = "flagBits";
735 type = yang::Bits{{"carry", "sign", "overflow"}};
736 }
737
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200738
Václav Kubernát0d4db442018-07-18 17:18:43 +0200739 REQUIRE(ys.leafType(path, node) == type);
740 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200741 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200742 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200743 // TODO: merge "path" and "module" sections and add recursive versions to the path section
744 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200745 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200746 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200747
Václav Kubernát95b08872020-04-28 01:04:17 +0200748 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200749 SECTION("<root>")
750 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200751 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
752 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
753 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
754 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
755 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
756 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
757 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
758 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
759 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
760 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
761 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
762 {"example-schema"s, "interrupt"},
763 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
764 {"example-schema"s, "pizzaSize"},
765 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
766 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
767 {"example-schema"s, "activeNumber"},
768 {"example-schema"s, "numberOrString"},
769 {"example-schema"s, "portSettings"},
770 {"example-schema"s, "portMapping"},
771 {"example-schema"s, "activeMappedPort"},
772 {"example-schema"s, "activePort"},
773 {"example-schema"s, "clockSpeed"},
774 {"example-schema"s, "deprecatedLeaf"},
775 {"example-schema"s, "obsoleteLeaf"},
776 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
777 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200778 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200779 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200780 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200781 {"example-schema"s, "addresses"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100782 {"example-schema"s, "subLeaf"},
783 {"example-schema"s, "flagBits"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200784 }
785
786 SECTION("example-schema:a")
787 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200788 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200789 set = {
790 {boost::none, "a2"},
791 {boost::none, "leafa"},
792 {"second-schema"s, "augmentedContainer"}
793 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200794 }
795
796 SECTION("example-schema:ethernet")
797 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200798 path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200799 set = {{boost::none, "ip"}};
800 }
801
802 SECTION("second-schema:bla")
803 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200804 path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200805 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200806 }
807
808 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200809 }
810
Václav Kubernát3a823f42020-04-29 23:40:21 +0200811 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200812 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200813 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200814 std::set<ModuleNodePair> expectedNonRecursive;
815 std::set<ModuleNodePair> expectedRecursive;
816 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200817 SECTION("example-schema")
818 {
819 module = "example-schema";
820 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200821 {"example-schema"s, "_list"},
822 {"example-schema"s, "a"},
823 {"example-schema"s, "activeMappedPort"},
824 {"example-schema"s, "activeNumber"},
825 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200826 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200827 {"example-schema"s, "another-duration"},
828 {"example-schema"s, "b"},
829 {"example-schema"s, "carry"},
830 {"example-schema"s, "clockSpeed"},
831 {"example-schema"s, "deprecatedLeaf"},
832 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200833 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200834 {"example-schema"s, "duration"},
835 {"example-schema"s, "ethernet"},
836 {"example-schema"s, "foodDrinkIdentLeaf"},
837 {"example-schema"s, "foodIdentLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100838 {"example-schema"s, "flagBits"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200839 {"example-schema"s, "interrupt"},
840 {"example-schema"s, "leafBool"},
841 {"example-schema"s, "leafDecimal"},
842 {"example-schema"s, "leafEnum"},
843 {"example-schema"s, "leafEnumTypedef"},
844 {"example-schema"s, "leafEnumTypedefRestricted"},
845 {"example-schema"s, "leafEnumTypedefRestricted2"},
846 {"example-schema"s, "leafInt16"},
847 {"example-schema"s, "leafInt32"},
848 {"example-schema"s, "leafInt64"},
849 {"example-schema"s, "leafInt8"},
850 {"example-schema"s, "leafString"},
851 {"example-schema"s, "leafUint16"},
852 {"example-schema"s, "leafUint32"},
853 {"example-schema"s, "leafUint64"},
854 {"example-schema"s, "leafUint8"},
855 {"example-schema"s, "length"},
856 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200857 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200858 {"example-schema"s, "numberOrString"},
859 {"example-schema"s, "obsoleteLeaf"},
860 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
861 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
862 {"example-schema"s, "pizzaIdentLeaf"},
863 {"example-schema"s, "pizzaSize"},
864 {"example-schema"s, "portMapping"},
865 {"example-schema"s, "portSettings"},
866 {"example-schema"s, "systemStats"},
867 {"example-schema"s, "twoKeyList"},
868 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200869 {"example-schema"s, "zero"},
870 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200871 };
872 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200873 {boost::none, "/example-schema:_list"},
874 {boost::none, "/example-schema:_list/contInList"},
875 {boost::none, "/example-schema:_list/number"},
876 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200877 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200878 {boost::none, "/example-schema:a/a2"},
879 {boost::none, "/example-schema:a/a2/a3"},
880 {boost::none, "/example-schema:a/leafa"},
881 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
882 {boost::none, "/example-schema:activeMappedPort"},
883 {boost::none, "/example-schema:activeNumber"},
884 {boost::none, "/example-schema:activePort"},
885 {boost::none, "/example-schema:another-duration"},
886 {boost::none, "/example-schema:b"},
887 {boost::none, "/example-schema:b/b2"},
888 {boost::none, "/example-schema:b/b2/b3"},
889 {boost::none, "/example-schema:carry"},
890 {boost::none, "/example-schema:clockSpeed"},
891 {boost::none, "/example-schema:deprecatedLeaf"},
892 {boost::none, "/example-schema:direction"},
893 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200894 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100895 {boost::none, "/example-schema:flagBits"},
896 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200897 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
898 {boost::none, "/example-schema:foodIdentLeaf"},
899 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
900 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
901 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
902 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
903 {boost::none, "/example-schema:interrupt"},
904 {boost::none, "/example-schema:leafBool"},
905 {boost::none, "/example-schema:leafDecimal"},
906 {boost::none, "/example-schema:leafEnum"},
907 {boost::none, "/example-schema:leafEnumTypedef"},
908 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
909 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
910 {boost::none, "/example-schema:leafInt16"},
911 {boost::none, "/example-schema:leafInt32"},
912 {boost::none, "/example-schema:leafInt64"},
913 {boost::none, "/example-schema:leafInt8"},
914 {boost::none, "/example-schema:leafString"},
915 {boost::none, "/example-schema:leafUint16"},
916 {boost::none, "/example-schema:leafUint32"},
917 {boost::none, "/example-schema:leafUint64"},
918 {boost::none, "/example-schema:leafUint8"},
919 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200920 {boost::none, "/example-schema:myRpc"},
921 {boost::none, "/example-schema:myRpc/input"},
922 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200923 {boost::none, "/example-schema:numberOrString"},
924 {boost::none, "/example-schema:obsoleteLeaf"},
925 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
926 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
927 {boost::none, "/example-schema:pizzaIdentLeaf"},
928 {boost::none, "/example-schema:pizzaSize"},
929 {boost::none, "/example-schema:portMapping"},
930 {boost::none, "/example-schema:portMapping/port"},
931 {boost::none, "/example-schema:portSettings"},
932 {boost::none, "/example-schema:portSettings/port"},
Václav Kubernáta8789602020-07-20 15:18:19 +0200933 {boost::none, "/example-schema:portSettings/shutdown"},
934 {boost::none, "/example-schema:portSettings/shutdown/input"},
935 {boost::none, "/example-schema:portSettings/shutdown/output"},
936 {boost::none, "/example-schema:portSettings/shutdown/output/success"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200937 {boost::none, "/example-schema:systemStats"},
938 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200939 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200940 {boost::none, "/example-schema:twoKeyList"},
941 {boost::none, "/example-schema:twoKeyList/name"},
942 {boost::none, "/example-schema:twoKeyList/number"},
943 {boost::none, "/example-schema:wavelength"},
944 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200945 };
946 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200947 SECTION("second-schema")
948 {
949 module = "second-schema";
950 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200951 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200952 };
953 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200954 {boost::none, "/second-schema:bla"},
955 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200956 };
957 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200958
Václav Kubernát3a823f42020-04-29 23:40:21 +0200959 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
960 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +0100961 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200962 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100963 SECTION("nodeType")
964 {
965 yang::NodeTypes expected;
966 SECTION("leafInt32")
967 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200968 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100969 expected = yang::NodeTypes::Leaf;
970 }
971
972 SECTION("a")
973 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200974 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100975 expected = yang::NodeTypes::Container;
976 }
977
978 SECTION("a/a2/a3")
979 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200980 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
981 path.m_nodes.emplace_back(container_("a2"));
982 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100983 expected = yang::NodeTypes::PresenceContainer;
984 }
985
986 SECTION("_list")
987 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200988 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100989 expected = yang::NodeTypes::List;
990 }
991
Václav Kubernát82d74632020-05-11 15:59:53 +0200992 SECTION("subLeaf")
993 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200994 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf"));
Václav Kubernát82d74632020-05-11 15:59:53 +0200995 expected = yang::NodeTypes::Leaf;
996 }
997
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100998 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
999 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001000
1001 SECTION("description")
1002 {
1003 std::optional<std::string> expected;
1004 SECTION("leafInt32")
1005 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001006 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001007 expected = "A 32-bit integer leaf.";
1008 }
1009
1010 SECTION("leafString")
1011 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001012 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001013 }
1014
Václav Kubernát2984f442020-02-20 17:43:35 +01001015 SECTION("numberOrString")
1016 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001017 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +01001018 expected = "Can be an int32 or a string.";
1019 }
1020
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001021 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1022 }
1023
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001024 SECTION("status")
1025 {
1026 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1027 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1028 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1029 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1030 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1031 }
1032
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001033 SECTION("units")
1034 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001035 yang::LeafDataType expectedType;
1036 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001037 SECTION("length")
1038 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001039 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001040 expectedType.emplace<yang::Int32>();
1041 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001042 }
1043
1044 SECTION("wavelength")
1045 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001046 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001047 expectedType.emplace<yang::Decimal>();
1048 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001049 }
1050
1051 SECTION("leafInt32")
1052 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001053 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001054 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001055 }
1056
1057 SECTION("duration")
1058 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001059 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001060 expectedType.emplace<yang::Int32>();
1061 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001062 }
1063
1064 SECTION("another-duration")
1065 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001066 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001067 expectedType.emplace<yang::Int32>();
1068 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001069 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001070 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1071 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001072 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001073 }
1074
1075 SECTION("nodeType")
1076 {
1077 yang::NodeTypes expected;
1078 SECTION("leafInt32")
1079 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001080 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001081 expected = yang::NodeTypes::Leaf;
1082 }
1083
1084 SECTION("a")
1085 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001086 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001087 expected = yang::NodeTypes::Container;
1088 }
1089
1090 SECTION("a/a2/a3")
1091 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001092 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1093 path.m_nodes.emplace_back(container_("a2"));
1094 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001095 expected = yang::NodeTypes::PresenceContainer;
1096 }
1097
1098 SECTION("_list")
1099 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001100 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001101 expected = yang::NodeTypes::List;
1102 }
1103
1104 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1105 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001106
1107 SECTION("leafrefPath")
1108 {
1109 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1110 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001111
1112 SECTION("isConfig")
1113 {
1114 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1115 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1116 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1117 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1118 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001119
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001120 SECTION("defaultValue")
1121 {
1122 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1123 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1124 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1125 }
1126
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001127 SECTION("leafTypeName")
1128 {
1129 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1130 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1131 }
Václav Kubernáta8789602020-07-20 15:18:19 +02001132
1133 SECTION("dataPathToSchemaPath")
1134 {
1135 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings");
1136 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown");
1137 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001138 }
1139
1140 SECTION("negative")
1141 {
1142 SECTION("nonexistent nodes")
1143 {
1144 SECTION("example-schema:coze")
1145 {
1146 node.first = "example-schema";
1147 node.second = "coze";
1148 }
1149
1150 SECTION("example-schema:a/nevim")
1151 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001152 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001153 node.second = "nevim";
1154 }
1155
1156 SECTION("modul:a/nevim")
1157 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001158 path.m_nodes.emplace_back(module_{"modul"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001159 node.second = "nevim";
1160 }
1161
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001162 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001163 }
1164
1165 SECTION("nodetype-specific methods called with different nodetypes")
1166 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001167 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1168 path.m_nodes.emplace_back(container_("a2"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001169
Václav Kubernát912b9492020-05-29 02:03:40 +02001170 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001171 }
1172
1173 SECTION("nonexistent module")
1174 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001175 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001176 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001177
Václav Kubernát7d82da72019-04-11 15:16:38 +02001178 SECTION("grouping is not a node")
1179 {
1180 SECTION("example-schema:arithmeticFlags")
1181 {
1182 node.first = "example-schema";
1183 node.second = "arithmeticFlags";
1184 }
1185
1186 SECTION("example-schema:flags")
1187 {
1188 node.first = "example-schema";
1189 node.second = "startAndStop";
1190 }
1191
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001192 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát7d82da72019-04-11 15:16:38 +02001193 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001194
1195 SECTION("choice is not a node")
1196 {
1197 SECTION("example-schema:interface")
1198 {
1199 node.first = "example-schema";
1200 node.second = "interface";
1201 }
1202
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001203 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001204 }
1205
1206 SECTION("case is not a node")
1207 {
1208 SECTION("example-schema:caseLoopback")
1209 {
1210 node.first = "example-schema";
1211 node.second = "caseLoopback";
1212 }
1213
1214 SECTION("example-schema:caseEthernet")
1215 {
1216 node.first = "example-schema";
1217 node.second = "caseEthernet";
1218 }
1219
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001220 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001221 }
Václav Kubernátf44bdda2020-06-22 15:58:41 +02001222
1223 SECTION("enableFeature - non existing module")
1224 {
1225 REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error);
1226 }
Václav Kubernát7aaf6dc2020-06-26 18:03:57 +02001227
1228 SECTION("enableFeature - non existing feature")
1229 {
1230 REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error);
1231 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001232 }
1233}