blob: 1720d79914f839d8dfab1c28289ac7903d96fde0 [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 }
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100174 description "This is a restricted enum typedef.";
Václav Kubernát6a713d62018-10-03 18:47:34 +0200175 }
176
177 leaf leafEnumTypedef {
178 type enumTypedef;
179 }
180
181 leaf leafEnumTypedefRestricted {
182 type enumTypedef {
183 enum data;
184 enum coze;
185 }
186 }
187
188 leaf leafEnumTypedefRestricted2 {
189 type enumTypedefRestricted;
190 }
191
Václav Kubernáteeb38842019-03-20 19:46:05 +0100192 leaf foodIdentLeaf {
193 type identityref {
194 base "food";
195 }
196 }
197
198 leaf pizzaIdentLeaf {
199 type identityref {
200 base "pizza";
201 }
202 }
203
204 leaf foodDrinkIdentLeaf {
205 type identityref {
206 base "food";
207 base "drink";
208 }
209 }
210
Václav Kubernát0d4db442018-07-18 17:18:43 +0200211 list _list {
212 key number;
213
214 leaf number {
215 type int32;
216 }
217
218 container contInList {
219 presence true;
220 }
221 }
222
223 list twoKeyList {
224 key "name number";
225
226 leaf number {
227 type int32;
228 }
229
230 leaf name {
231 type string;
232 }
233 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200234
235 grouping arithmeticFlags {
236 leaf carry {
237 type boolean;
238 }
239 leaf zero {
240 type boolean;
241 }
242 }
243
244 grouping flags {
245 leaf direction {
246 type boolean;
247 }
248 leaf interrupt {
249 type boolean;
250 }
251
252 uses arithmeticFlags;
253 }
254
255 uses flags;
Václav Kubernát280df4a2019-11-01 14:46:34 +0100256
257 choice interface {
258 case caseLoopback {
259 container loopback {
260 leaf ip {
261 type string;
262 }
263 }
264 }
265
266 case caseEthernet {
267 container ethernet {
268 leaf ip {
269 type string;
270 }
271 }
272 }
273 }
274
Václav Kubernáta38d4172019-11-04 12:36:39 +0100275 feature bigPizzas;
276
277 leaf pizzaSize {
278 type enumeration {
279 enum large {
280 if-feature "bigPizzas";
281 }
282 enum medium;
283 enum small;
284 }
285 }
286
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100287 leaf length {
288 type int32;
289 units "m";
290 }
291
292 leaf wavelength {
293 type decimal64 {
294 fraction-digits 10;
295 }
296 units "nm";
297 }
298
299 typedef seconds {
300 type int32;
301 units "s";
302 }
303
304 leaf duration {
305 type seconds;
306 }
307
308 leaf another-duration {
309 type seconds;
310 units "vt";
311 }
312
Václav Kubernátbd5e3c22020-02-19 15:22:00 +0100313 leaf activeNumber {
314 type leafref {
315 path "/_list/number";
316 }
317 }
318
Václav Kubernátfa81c8c2020-02-13 17:22:46 +0100319 rpc myRpc {}
320
Václav Kubernátd8408e02020-12-02 05:13:27 +0100321 rpc rpcOneOutput {
322 output {
323 leaf ahoj {
324 type string;
325 }
326 }
327 }
328
329 rpc rpcOneInput {
330 input {
331 leaf ahoj {
332 type string;
333 }
334 }
335 }
336
Václav Kubernát2984f442020-02-20 17:43:35 +0100337 leaf numberOrString {
338 type union {
339 type int32;
340 type string;
341 }
342 description "Can be an int32 or a string.";
343 }
344
345 list portSettings {
346 key "port";
347 leaf port {
348 type enumeration {
349 enum eth0;
350 enum eth1;
351 enum eth2;
352 }
353 }
Václav Kubernáta8789602020-07-20 15:18:19 +0200354 action shutdown {
355 output {
356 leaf success {
357 type boolean;
358 }
359 }
360 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100361 }
362
363 feature weirdPortNames;
364
365 list portMapping {
366 key "port";
367 leaf port {
368 type enumeration {
369 enum WEIRD {
370 if-feature "weirdPortNames";
371 }
372 enum utf2;
373 enum utf3;
374 }
375 }
376 }
377
378 leaf activeMappedPort {
379 type leafref {
380 path "../portMapping/port";
381 }
382 }
383
384 leaf activePort {
385 type union {
386 type enumeration {
387 enum wlan0;
388 enum wlan1;
389 }
390 type leafref {
391 path "../portSettings/port";
392 }
393 type leafref {
394 path "../activeMappedPort";
395 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200396 type empty;
Václav Kubernát2984f442020-02-20 17:43:35 +0100397 }
398 }
399
Jan Kundrát379bb572020-05-07 03:23:13 +0200400 leaf dummyLeaf {
401 type empty;
402 }
403
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200404 leaf clockSpeed {
405 type int64;
406 config false;
407 }
408
409 container systemStats {
410 config false;
411 leaf upTime {
412 type uint64;
413 }
414 }
415
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200416 leaf obsoleteLeaf {
417 type int32;
418 status obsolete;
419 }
420
421 leaf deprecatedLeaf {
422 type int32;
423 status deprecated;
424 }
425
426 typedef deprecatedType {
427 type int32;
428 status deprecated;
429 }
430
431 leaf obsoleteLeafWithDeprecatedType {
432 type deprecatedType;
433 status obsolete;
434 }
435
436 typedef obsoleteType {
437 type int32;
438 status obsolete;
439 }
440
441 leaf obsoleteLeafWithObsoleteType {
442 type deprecatedType;
443 status obsolete;
444 }
445
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200446 leaf-list addresses {
447 type string;
448 }
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100449
450 leaf flagBits {
451 type bits {
452 bit carry;
453 bit sign;
454 bit overflow;
455 }
456 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200457})";
458
459TEST_CASE("yangschema")
460{
Václav Kubernát82d74632020-05-11 15:59:53 +0200461 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100462 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200463 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200464 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
465 if (modName != "example-schema"sv) {
466 throw std::logic_error("unrecognized module "s + modName);
467 }
468 if (subModule == nullptr) {
469 return example_schema;
470 }
471 if (subModule == "sub-module"sv) {
472 return included_submodule;
473 }
474
475 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100476 });
477 ys.addSchemaString(second_schema);
478
Václav Kubernátefcac932020-01-10 15:26:32 +0100479 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200480 ModuleNodePair node;
481
482 SECTION("positive")
483 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200484 SECTION("isModule")
485 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100486 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200487 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100488
Václav Kubernát0d4db442018-07-18 17:18:43 +0200489 SECTION("listHasKey")
490 {
491 std::string key;
492
493 SECTION("_list")
494 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200495 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200496 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200497 {
498 key = "number";
499 }
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 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200506 {
507 key = "number";
508 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200509 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200510 {
511 key = "name";
512 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200513 }
514
Václav Kubernát912b9492020-05-29 02:03:40 +0200515 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200516 }
517 SECTION("listKeys")
518 {
519 std::set<std::string> set;
520
521 SECTION("_list")
522 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200523 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200524 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200525 }
526
527 SECTION("twoKeyList")
528 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200529 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200530 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200531 }
532
Václav Kubernát912b9492020-05-29 02:03:40 +0200533 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200534 }
535 SECTION("leafType")
536 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200537 yang::LeafDataType type;
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100538 std::optional<std::string> expectedDescription;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200539
540 SECTION("leafString")
541 {
542 node.first = "example-schema";
543 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200544 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200545 }
546
547 SECTION("leafDecimal")
548 {
549 node.first = "example-schema";
550 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200551 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200552 }
553
554 SECTION("leafBool")
555 {
556 node.first = "example-schema";
557 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200558 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200559 }
560
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200561 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200562 {
563 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200564 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200565 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200566 }
567
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200568 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200569 {
570 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200571 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200572 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200573 }
574
Václav Kubernátb6d02752020-04-03 00:25:10 +0200575 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200576 {
577 node.first = "example-schema";
578 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200579 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200580 }
581
582 SECTION("leafUint16")
583 {
584 node.first = "example-schema";
585 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200586 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200587 }
588
589 SECTION("leafInt32")
590 {
591 node.first = "example-schema";
592 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200593 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200594 }
595
596 SECTION("leafUint32")
597 {
598 node.first = "example-schema";
599 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200600 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200601 }
602
603 SECTION("leafInt64")
604 {
605 node.first = "example-schema";
606 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200607 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200608 }
609
610 SECTION("leafUint64")
611 {
612 node.first = "example-schema";
613 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200614 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200615 }
616
617 SECTION("leafEnum")
618 {
619 node.first = "example-schema";
620 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200621 type = createEnum({"lol", "data", "coze"});
622 }
623
624 SECTION("leafEnumTypedef")
625 {
626 node.first = "example-schema";
627 node.second = "leafEnumTypedef";
628 type = createEnum({"lol", "data", "coze"});
629 }
630
631 SECTION("leafEnumTypedefRestricted")
632 {
633 node.first = "example-schema";
634 node.second = "leafEnumTypedefRestricted";
635 type = createEnum({"data", "coze"});
636 }
637
638 SECTION("leafEnumTypedefRestricted2")
639 {
640 node.first = "example-schema";
641 node.second = "leafEnumTypedefRestricted2";
642 type = createEnum({"lol", "data"});
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100643 expectedDescription = "This is a restricted enum typedef.";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200644 }
645
646 SECTION("pizzaSize")
647 {
648 node.first = "example-schema";
649 node.second = "pizzaSize";
650
651 SECTION("bigPizzas disabled")
652 {
653 type = createEnum({"small", "medium"});
654 }
655 SECTION("bigPizzas enabled")
656 {
657 ys.enableFeature("example-schema", "bigPizzas");
658 type = createEnum({"small", "medium", "large"});
659 }
660 }
661
662 SECTION("foodIdentLeaf")
663 {
664 node.first = "example-schema";
665 node.second = "foodIdentLeaf";
666 type = yang::IdentityRef{{{"second-schema", "pineapple"},
667 {"example-schema", "food"},
668 {"example-schema", "pizza"},
669 {"example-schema", "hawaii"},
670 {"example-schema", "fruit"}}};
671 }
672
673 SECTION("pizzaIdentLeaf")
674 {
675 node.first = "example-schema";
676 node.second = "pizzaIdentLeaf";
677
678 type = yang::IdentityRef{{
679 {"example-schema", "pizza"},
680 {"example-schema", "hawaii"},
681 }};
682 }
683
684 SECTION("foodDrinkIdentLeaf")
685 {
686 node.first = "example-schema";
687 node.second = "foodDrinkIdentLeaf";
688
689 type = yang::IdentityRef{{
690 {"example-schema", "food"},
691 {"example-schema", "drink"},
692 {"example-schema", "fruit"},
693 {"example-schema", "hawaii"},
694 {"example-schema", "pizza"},
695 {"example-schema", "voda"},
696 {"second-schema", "pineapple"},
697 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200698 }
699
Václav Kubernátb6d02752020-04-03 00:25:10 +0200700 SECTION("activeNumber")
701 {
702 node.first = "example-schema";
703 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200704 type.emplace<yang::LeafRef>(
705 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200706 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200707 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200708 }
709
Václav Kubernát2984f442020-02-20 17:43:35 +0100710 SECTION("activePort")
711 {
712 node.first = "example-schema";
713 node.second = "activePort";
714
Václav Kubernát1dc9e3e2020-06-09 15:22:39 +0200715 yang::Enum enums({});
716 SECTION("weird ports disabled")
717 {
718 enums = createEnum({"utf2", "utf3"});
719 }
720 SECTION("weird ports enabled")
721 {
722 ys.enableFeature("example-schema", "weirdPortNames");
723 enums = createEnum({"WEIRD", "utf2", "utf3"});
724 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100725
726 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200727 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
728 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100729 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200730 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
731 }},
732 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100733 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200734 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100735 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200736 std::make_unique<yang::TypeInfo>(enums)
737 })
738 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200739 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100740 }};
741 }
742
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200743 SECTION("addresses")
744 {
745 node.first = "example-schema";
746 node.second = "addresses";
747 type.emplace<yang::String>();
748 }
749
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100750 SECTION("flagBits")
751 {
752 node.first = "example-schema";
753 node.second = "flagBits";
754 type = yang::Bits{{"carry", "sign", "overflow"}};
755 }
756
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200757
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100758 REQUIRE(ys.leafType(path, node) == yang::TypeInfo(type, std::nullopt, expectedDescription));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200759 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200760 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200761 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200762 // TODO: merge "path" and "module" sections and add recursive versions to the path section
763 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200764 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200765 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200766
Václav Kubernát95b08872020-04-28 01:04:17 +0200767 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200768 SECTION("<root>")
769 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200770 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
771 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
772 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
773 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
774 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
775 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
776 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
777 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
778 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
779 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
780 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
781 {"example-schema"s, "interrupt"},
782 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
783 {"example-schema"s, "pizzaSize"},
784 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
785 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
786 {"example-schema"s, "activeNumber"},
787 {"example-schema"s, "numberOrString"},
788 {"example-schema"s, "portSettings"},
789 {"example-schema"s, "portMapping"},
790 {"example-schema"s, "activeMappedPort"},
791 {"example-schema"s, "activePort"},
792 {"example-schema"s, "clockSpeed"},
793 {"example-schema"s, "deprecatedLeaf"},
794 {"example-schema"s, "obsoleteLeaf"},
795 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
796 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200797 {"example-schema"s, "myRpc"},
Václav Kubernátd8408e02020-12-02 05:13:27 +0100798 {"example-schema"s, "rpcOneOutput"},
799 {"example-schema"s, "rpcOneInput"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200800 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200801 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200802 {"example-schema"s, "addresses"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100803 {"example-schema"s, "subLeaf"},
804 {"example-schema"s, "flagBits"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200805 }
806
807 SECTION("example-schema:a")
808 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200809 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200810 set = {
811 {boost::none, "a2"},
812 {boost::none, "leafa"},
813 {"second-schema"s, "augmentedContainer"}
814 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200815 }
816
817 SECTION("example-schema:ethernet")
818 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200819 path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200820 set = {{boost::none, "ip"}};
821 }
822
823 SECTION("second-schema:bla")
824 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200825 path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200826 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200827 }
828
829 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200830 }
831
Václav Kubernát3a823f42020-04-29 23:40:21 +0200832 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200833 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200834 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200835 std::set<ModuleNodePair> expectedNonRecursive;
836 std::set<ModuleNodePair> expectedRecursive;
837 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200838 SECTION("example-schema")
839 {
840 module = "example-schema";
841 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200842 {"example-schema"s, "_list"},
843 {"example-schema"s, "a"},
844 {"example-schema"s, "activeMappedPort"},
845 {"example-schema"s, "activeNumber"},
846 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200847 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200848 {"example-schema"s, "another-duration"},
849 {"example-schema"s, "b"},
850 {"example-schema"s, "carry"},
851 {"example-schema"s, "clockSpeed"},
852 {"example-schema"s, "deprecatedLeaf"},
853 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200854 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200855 {"example-schema"s, "duration"},
856 {"example-schema"s, "ethernet"},
857 {"example-schema"s, "foodDrinkIdentLeaf"},
858 {"example-schema"s, "foodIdentLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100859 {"example-schema"s, "flagBits"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200860 {"example-schema"s, "interrupt"},
861 {"example-schema"s, "leafBool"},
862 {"example-schema"s, "leafDecimal"},
863 {"example-schema"s, "leafEnum"},
864 {"example-schema"s, "leafEnumTypedef"},
865 {"example-schema"s, "leafEnumTypedefRestricted"},
866 {"example-schema"s, "leafEnumTypedefRestricted2"},
867 {"example-schema"s, "leafInt16"},
868 {"example-schema"s, "leafInt32"},
869 {"example-schema"s, "leafInt64"},
870 {"example-schema"s, "leafInt8"},
871 {"example-schema"s, "leafString"},
872 {"example-schema"s, "leafUint16"},
873 {"example-schema"s, "leafUint32"},
874 {"example-schema"s, "leafUint64"},
875 {"example-schema"s, "leafUint8"},
876 {"example-schema"s, "length"},
877 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200878 {"example-schema"s, "myRpc"},
Václav Kubernátd8408e02020-12-02 05:13:27 +0100879 {"example-schema"s, "rpcOneOutput"},
880 {"example-schema"s, "rpcOneInput"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200881 {"example-schema"s, "numberOrString"},
882 {"example-schema"s, "obsoleteLeaf"},
883 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
884 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
885 {"example-schema"s, "pizzaIdentLeaf"},
886 {"example-schema"s, "pizzaSize"},
887 {"example-schema"s, "portMapping"},
888 {"example-schema"s, "portSettings"},
889 {"example-schema"s, "systemStats"},
890 {"example-schema"s, "twoKeyList"},
891 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200892 {"example-schema"s, "zero"},
893 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200894 };
895 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200896 {boost::none, "/example-schema:_list"},
897 {boost::none, "/example-schema:_list/contInList"},
898 {boost::none, "/example-schema:_list/number"},
899 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200900 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200901 {boost::none, "/example-schema:a/a2"},
902 {boost::none, "/example-schema:a/a2/a3"},
903 {boost::none, "/example-schema:a/leafa"},
904 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
905 {boost::none, "/example-schema:activeMappedPort"},
906 {boost::none, "/example-schema:activeNumber"},
907 {boost::none, "/example-schema:activePort"},
908 {boost::none, "/example-schema:another-duration"},
909 {boost::none, "/example-schema:b"},
910 {boost::none, "/example-schema:b/b2"},
911 {boost::none, "/example-schema:b/b2/b3"},
912 {boost::none, "/example-schema:carry"},
913 {boost::none, "/example-schema:clockSpeed"},
914 {boost::none, "/example-schema:deprecatedLeaf"},
915 {boost::none, "/example-schema:direction"},
916 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200917 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100918 {boost::none, "/example-schema:flagBits"},
919 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200920 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
921 {boost::none, "/example-schema:foodIdentLeaf"},
922 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
923 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
924 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
925 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
926 {boost::none, "/example-schema:interrupt"},
927 {boost::none, "/example-schema:leafBool"},
928 {boost::none, "/example-schema:leafDecimal"},
929 {boost::none, "/example-schema:leafEnum"},
930 {boost::none, "/example-schema:leafEnumTypedef"},
931 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
932 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
933 {boost::none, "/example-schema:leafInt16"},
934 {boost::none, "/example-schema:leafInt32"},
935 {boost::none, "/example-schema:leafInt64"},
936 {boost::none, "/example-schema:leafInt8"},
937 {boost::none, "/example-schema:leafString"},
938 {boost::none, "/example-schema:leafUint16"},
939 {boost::none, "/example-schema:leafUint32"},
940 {boost::none, "/example-schema:leafUint64"},
941 {boost::none, "/example-schema:leafUint8"},
942 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200943 {boost::none, "/example-schema:myRpc"},
944 {boost::none, "/example-schema:myRpc/input"},
945 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernátd8408e02020-12-02 05:13:27 +0100946 {boost::none, "/example-schema:rpcOneOutput"},
947 {boost::none, "/example-schema:rpcOneOutput/input"},
948 {boost::none, "/example-schema:rpcOneOutput/output"},
949 {boost::none, "/example-schema:rpcOneOutput/output/ahoj"},
950 {boost::none, "/example-schema:rpcOneInput"},
951 {boost::none, "/example-schema:rpcOneInput/input"},
952 {boost::none, "/example-schema:rpcOneInput/input/ahoj"},
953 {boost::none, "/example-schema:rpcOneInput/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200954 {boost::none, "/example-schema:numberOrString"},
955 {boost::none, "/example-schema:obsoleteLeaf"},
956 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
957 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
958 {boost::none, "/example-schema:pizzaIdentLeaf"},
959 {boost::none, "/example-schema:pizzaSize"},
960 {boost::none, "/example-schema:portMapping"},
961 {boost::none, "/example-schema:portMapping/port"},
962 {boost::none, "/example-schema:portSettings"},
963 {boost::none, "/example-schema:portSettings/port"},
Václav Kubernáta8789602020-07-20 15:18:19 +0200964 {boost::none, "/example-schema:portSettings/shutdown"},
965 {boost::none, "/example-schema:portSettings/shutdown/input"},
966 {boost::none, "/example-schema:portSettings/shutdown/output"},
967 {boost::none, "/example-schema:portSettings/shutdown/output/success"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200968 {boost::none, "/example-schema:systemStats"},
969 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200970 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200971 {boost::none, "/example-schema:twoKeyList"},
972 {boost::none, "/example-schema:twoKeyList/name"},
973 {boost::none, "/example-schema:twoKeyList/number"},
974 {boost::none, "/example-schema:wavelength"},
975 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200976 };
977 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200978 SECTION("second-schema")
979 {
980 module = "second-schema";
981 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200982 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200983 };
984 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200985 {boost::none, "/second-schema:bla"},
986 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200987 };
988 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200989
Václav Kubernát3a823f42020-04-29 23:40:21 +0200990 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
991 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +0100992 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200993 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100994 SECTION("nodeType")
995 {
996 yang::NodeTypes expected;
997 SECTION("leafInt32")
998 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200999 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001000 expected = yang::NodeTypes::Leaf;
1001 }
1002
1003 SECTION("a")
1004 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001005 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001006 expected = yang::NodeTypes::Container;
1007 }
1008
1009 SECTION("a/a2/a3")
1010 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001011 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1012 path.m_nodes.emplace_back(container_("a2"));
1013 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001014 expected = yang::NodeTypes::PresenceContainer;
1015 }
1016
1017 SECTION("_list")
1018 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001019 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001020 expected = yang::NodeTypes::List;
1021 }
1022
Václav Kubernát82d74632020-05-11 15:59:53 +02001023 SECTION("subLeaf")
1024 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001025 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf"));
Václav Kubernát82d74632020-05-11 15:59:53 +02001026 expected = yang::NodeTypes::Leaf;
1027 }
1028
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001029 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1030 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001031
1032 SECTION("description")
1033 {
1034 std::optional<std::string> expected;
1035 SECTION("leafInt32")
1036 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001037 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001038 expected = "A 32-bit integer leaf.";
1039 }
1040
1041 SECTION("leafString")
1042 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001043 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001044 }
1045
Václav Kubernát2984f442020-02-20 17:43:35 +01001046 SECTION("numberOrString")
1047 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001048 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +01001049 expected = "Can be an int32 or a string.";
1050 }
1051
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001052 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1053 }
1054
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001055 SECTION("status")
1056 {
1057 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1058 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1059 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1060 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1061 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1062 }
1063
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001064 SECTION("units")
1065 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001066 yang::LeafDataType expectedType;
1067 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001068 SECTION("length")
1069 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001070 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001071 expectedType.emplace<yang::Int32>();
1072 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001073 }
1074
1075 SECTION("wavelength")
1076 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001077 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001078 expectedType.emplace<yang::Decimal>();
1079 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001080 }
1081
1082 SECTION("leafInt32")
1083 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001084 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001085 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001086 }
1087
1088 SECTION("duration")
1089 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001090 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001091 expectedType.emplace<yang::Int32>();
1092 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001093 }
1094
1095 SECTION("another-duration")
1096 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001097 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001098 expectedType.emplace<yang::Int32>();
1099 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001100 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001101 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1102 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001103 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001104 }
1105
Václav Kubernát1ae24f42020-12-01 02:32:04 +01001106 SECTION("type description")
1107 {
1108 yang::LeafDataType expectedType = createEnum({"lol", "data"});
1109 std::optional<std::string> expectedDescription;
1110
1111 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafEnumTypedefRestricted2"));
1112 expectedDescription = "This is a restricted enum typedef.";
1113 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, std::nullopt, expectedDescription});
1114 }
1115
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001116 SECTION("nodeType")
1117 {
1118 yang::NodeTypes expected;
1119 SECTION("leafInt32")
1120 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001121 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001122 expected = yang::NodeTypes::Leaf;
1123 }
1124
1125 SECTION("a")
1126 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001127 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001128 expected = yang::NodeTypes::Container;
1129 }
1130
1131 SECTION("a/a2/a3")
1132 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001133 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1134 path.m_nodes.emplace_back(container_("a2"));
1135 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001136 expected = yang::NodeTypes::PresenceContainer;
1137 }
1138
1139 SECTION("_list")
1140 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001141 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001142 expected = yang::NodeTypes::List;
1143 }
1144
1145 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1146 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001147
1148 SECTION("leafrefPath")
1149 {
1150 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1151 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001152
1153 SECTION("isConfig")
1154 {
1155 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1156 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1157 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1158 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1159 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001160
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001161 SECTION("defaultValue")
1162 {
1163 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1164 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1165 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1166 }
1167
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001168 SECTION("leafTypeName")
1169 {
1170 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1171 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1172 }
Václav Kubernáta8789602020-07-20 15:18:19 +02001173
1174 SECTION("dataPathToSchemaPath")
1175 {
1176 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings");
1177 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown");
1178 }
Václav Kubernátd8408e02020-12-02 05:13:27 +01001179
1180 SECTION("has input nodes")
1181 {
1182 bool expected;
1183 SECTION("example-schema:myRpc")
1184 {
1185 path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"myRpc"});
1186 expected = false;
1187 }
1188
1189 SECTION("example-schema:rpcOneInput")
1190 {
1191 path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"rpcOneInput"});
1192 expected = true;
1193 }
1194
1195 SECTION("example-schema:rpcOneOutput")
1196 {
1197 path.m_nodes.emplace_back(module_{"example-schema"}, rpcNode_{"rpcOneOutput"});
1198 expected = false;
1199 }
1200
1201 REQUIRE(ys.hasInputNodes(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1202 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001203 }
1204
1205 SECTION("negative")
1206 {
1207 SECTION("nonexistent nodes")
1208 {
1209 SECTION("example-schema:coze")
1210 {
1211 node.first = "example-schema";
1212 node.second = "coze";
1213 }
1214
1215 SECTION("example-schema:a/nevim")
1216 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001217 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001218 node.second = "nevim";
1219 }
1220
1221 SECTION("modul:a/nevim")
1222 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001223 path.m_nodes.emplace_back(module_{"modul"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001224 node.second = "nevim";
1225 }
1226
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001227 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001228 }
1229
1230 SECTION("nodetype-specific methods called with different nodetypes")
1231 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001232 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1233 path.m_nodes.emplace_back(container_("a2"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001234
Václav Kubernát912b9492020-05-29 02:03:40 +02001235 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001236 }
1237
1238 SECTION("nonexistent module")
1239 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001240 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001241 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001242
Václav Kubernát7d82da72019-04-11 15:16:38 +02001243 SECTION("grouping is not a node")
1244 {
1245 SECTION("example-schema:arithmeticFlags")
1246 {
1247 node.first = "example-schema";
1248 node.second = "arithmeticFlags";
1249 }
1250
1251 SECTION("example-schema:flags")
1252 {
1253 node.first = "example-schema";
1254 node.second = "startAndStop";
1255 }
1256
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001257 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát7d82da72019-04-11 15:16:38 +02001258 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001259
1260 SECTION("choice is not a node")
1261 {
1262 SECTION("example-schema:interface")
1263 {
1264 node.first = "example-schema";
1265 node.second = "interface";
1266 }
1267
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001268 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001269 }
1270
1271 SECTION("case is not a node")
1272 {
1273 SECTION("example-schema:caseLoopback")
1274 {
1275 node.first = "example-schema";
1276 node.second = "caseLoopback";
1277 }
1278
1279 SECTION("example-schema:caseEthernet")
1280 {
1281 node.first = "example-schema";
1282 node.second = "caseEthernet";
1283 }
1284
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001285 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001286 }
Václav Kubernátf44bdda2020-06-22 15:58:41 +02001287
1288 SECTION("enableFeature - non existing module")
1289 {
1290 REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error);
1291 }
Václav Kubernát7aaf6dc2020-06-26 18:03:57 +02001292
1293 SECTION("enableFeature - non existing feature")
1294 {
1295 REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error);
1296 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001297 }
1298}