blob: 699a05ce4700115d9d0689a9aa831b7a773f3fd7 [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át2984f442020-02-20 17:43:35 +0100321 leaf numberOrString {
322 type union {
323 type int32;
324 type string;
325 }
326 description "Can be an int32 or a string.";
327 }
328
329 list portSettings {
330 key "port";
331 leaf port {
332 type enumeration {
333 enum eth0;
334 enum eth1;
335 enum eth2;
336 }
337 }
Václav Kubernáta8789602020-07-20 15:18:19 +0200338 action shutdown {
339 output {
340 leaf success {
341 type boolean;
342 }
343 }
344 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100345 }
346
347 feature weirdPortNames;
348
349 list portMapping {
350 key "port";
351 leaf port {
352 type enumeration {
353 enum WEIRD {
354 if-feature "weirdPortNames";
355 }
356 enum utf2;
357 enum utf3;
358 }
359 }
360 }
361
362 leaf activeMappedPort {
363 type leafref {
364 path "../portMapping/port";
365 }
366 }
367
368 leaf activePort {
369 type union {
370 type enumeration {
371 enum wlan0;
372 enum wlan1;
373 }
374 type leafref {
375 path "../portSettings/port";
376 }
377 type leafref {
378 path "../activeMappedPort";
379 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200380 type empty;
Václav Kubernát2984f442020-02-20 17:43:35 +0100381 }
382 }
383
Jan Kundrát379bb572020-05-07 03:23:13 +0200384 leaf dummyLeaf {
385 type empty;
386 }
387
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200388 leaf clockSpeed {
389 type int64;
390 config false;
391 }
392
393 container systemStats {
394 config false;
395 leaf upTime {
396 type uint64;
397 }
398 }
399
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200400 leaf obsoleteLeaf {
401 type int32;
402 status obsolete;
403 }
404
405 leaf deprecatedLeaf {
406 type int32;
407 status deprecated;
408 }
409
410 typedef deprecatedType {
411 type int32;
412 status deprecated;
413 }
414
415 leaf obsoleteLeafWithDeprecatedType {
416 type deprecatedType;
417 status obsolete;
418 }
419
420 typedef obsoleteType {
421 type int32;
422 status obsolete;
423 }
424
425 leaf obsoleteLeafWithObsoleteType {
426 type deprecatedType;
427 status obsolete;
428 }
429
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200430 leaf-list addresses {
431 type string;
432 }
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100433
434 leaf flagBits {
435 type bits {
436 bit carry;
437 bit sign;
438 bit overflow;
439 }
440 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200441})";
442
443TEST_CASE("yangschema")
444{
Václav Kubernát82d74632020-05-11 15:59:53 +0200445 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100446 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200447 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200448 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
449 if (modName != "example-schema"sv) {
450 throw std::logic_error("unrecognized module "s + modName);
451 }
452 if (subModule == nullptr) {
453 return example_schema;
454 }
455 if (subModule == "sub-module"sv) {
456 return included_submodule;
457 }
458
459 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100460 });
461 ys.addSchemaString(second_schema);
462
Václav Kubernátefcac932020-01-10 15:26:32 +0100463 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200464 ModuleNodePair node;
465
466 SECTION("positive")
467 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200468 SECTION("isModule")
469 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100470 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200471 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100472
Václav Kubernát0d4db442018-07-18 17:18:43 +0200473 SECTION("listHasKey")
474 {
475 std::string key;
476
477 SECTION("_list")
478 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200479 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
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 }
485
486 SECTION("twoKeyList")
487 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200488 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200489 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200490 {
491 key = "number";
492 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200493 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200494 {
495 key = "name";
496 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200497 }
498
Václav Kubernát912b9492020-05-29 02:03:40 +0200499 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200500 }
501 SECTION("listKeys")
502 {
503 std::set<std::string> set;
504
505 SECTION("_list")
506 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200507 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200508 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200509 }
510
511 SECTION("twoKeyList")
512 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200513 path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200514 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200515 }
516
Václav Kubernát912b9492020-05-29 02:03:40 +0200517 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200518 }
519 SECTION("leafType")
520 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200521 yang::LeafDataType type;
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100522 std::optional<std::string> expectedDescription;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200523
524 SECTION("leafString")
525 {
526 node.first = "example-schema";
527 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200528 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200529 }
530
531 SECTION("leafDecimal")
532 {
533 node.first = "example-schema";
534 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200535 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200536 }
537
538 SECTION("leafBool")
539 {
540 node.first = "example-schema";
541 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200542 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200543 }
544
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200545 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200546 {
547 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200548 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200549 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200550 }
551
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200552 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200553 {
554 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200555 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200556 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200557 }
558
Václav Kubernátb6d02752020-04-03 00:25:10 +0200559 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200560 {
561 node.first = "example-schema";
562 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200563 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200564 }
565
566 SECTION("leafUint16")
567 {
568 node.first = "example-schema";
569 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200570 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200571 }
572
573 SECTION("leafInt32")
574 {
575 node.first = "example-schema";
576 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200577 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200578 }
579
580 SECTION("leafUint32")
581 {
582 node.first = "example-schema";
583 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200584 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200585 }
586
587 SECTION("leafInt64")
588 {
589 node.first = "example-schema";
590 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200591 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200592 }
593
594 SECTION("leafUint64")
595 {
596 node.first = "example-schema";
597 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200598 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200599 }
600
601 SECTION("leafEnum")
602 {
603 node.first = "example-schema";
604 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200605 type = createEnum({"lol", "data", "coze"});
606 }
607
608 SECTION("leafEnumTypedef")
609 {
610 node.first = "example-schema";
611 node.second = "leafEnumTypedef";
612 type = createEnum({"lol", "data", "coze"});
613 }
614
615 SECTION("leafEnumTypedefRestricted")
616 {
617 node.first = "example-schema";
618 node.second = "leafEnumTypedefRestricted";
619 type = createEnum({"data", "coze"});
620 }
621
622 SECTION("leafEnumTypedefRestricted2")
623 {
624 node.first = "example-schema";
625 node.second = "leafEnumTypedefRestricted2";
626 type = createEnum({"lol", "data"});
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100627 expectedDescription = "This is a restricted enum typedef.";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200628 }
629
630 SECTION("pizzaSize")
631 {
632 node.first = "example-schema";
633 node.second = "pizzaSize";
634
635 SECTION("bigPizzas disabled")
636 {
637 type = createEnum({"small", "medium"});
638 }
639 SECTION("bigPizzas enabled")
640 {
641 ys.enableFeature("example-schema", "bigPizzas");
642 type = createEnum({"small", "medium", "large"});
643 }
644 }
645
646 SECTION("foodIdentLeaf")
647 {
648 node.first = "example-schema";
649 node.second = "foodIdentLeaf";
650 type = yang::IdentityRef{{{"second-schema", "pineapple"},
651 {"example-schema", "food"},
652 {"example-schema", "pizza"},
653 {"example-schema", "hawaii"},
654 {"example-schema", "fruit"}}};
655 }
656
657 SECTION("pizzaIdentLeaf")
658 {
659 node.first = "example-schema";
660 node.second = "pizzaIdentLeaf";
661
662 type = yang::IdentityRef{{
663 {"example-schema", "pizza"},
664 {"example-schema", "hawaii"},
665 }};
666 }
667
668 SECTION("foodDrinkIdentLeaf")
669 {
670 node.first = "example-schema";
671 node.second = "foodDrinkIdentLeaf";
672
673 type = yang::IdentityRef{{
674 {"example-schema", "food"},
675 {"example-schema", "drink"},
676 {"example-schema", "fruit"},
677 {"example-schema", "hawaii"},
678 {"example-schema", "pizza"},
679 {"example-schema", "voda"},
680 {"second-schema", "pineapple"},
681 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200682 }
683
Václav Kubernátb6d02752020-04-03 00:25:10 +0200684 SECTION("activeNumber")
685 {
686 node.first = "example-schema";
687 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200688 type.emplace<yang::LeafRef>(
689 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200690 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200691 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200692 }
693
Václav Kubernát2984f442020-02-20 17:43:35 +0100694 SECTION("activePort")
695 {
696 node.first = "example-schema";
697 node.second = "activePort";
698
Václav Kubernát1dc9e3e2020-06-09 15:22:39 +0200699 yang::Enum enums({});
700 SECTION("weird ports disabled")
701 {
702 enums = createEnum({"utf2", "utf3"});
703 }
704 SECTION("weird ports enabled")
705 {
706 ys.enableFeature("example-schema", "weirdPortNames");
707 enums = createEnum({"WEIRD", "utf2", "utf3"});
708 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100709
710 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200711 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
712 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100713 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200714 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
715 }},
716 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100717 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200718 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100719 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200720 std::make_unique<yang::TypeInfo>(enums)
721 })
722 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200723 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100724 }};
725 }
726
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200727 SECTION("addresses")
728 {
729 node.first = "example-schema";
730 node.second = "addresses";
731 type.emplace<yang::String>();
732 }
733
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100734 SECTION("flagBits")
735 {
736 node.first = "example-schema";
737 node.second = "flagBits";
738 type = yang::Bits{{"carry", "sign", "overflow"}};
739 }
740
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200741
Václav Kubernát1ae24f42020-12-01 02:32:04 +0100742 REQUIRE(ys.leafType(path, node) == yang::TypeInfo(type, std::nullopt, expectedDescription));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200743 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200744 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200745 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200746 // TODO: merge "path" and "module" sections and add recursive versions to the path section
747 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200748 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200749 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200750
Václav Kubernát95b08872020-04-28 01:04:17 +0200751 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200752 SECTION("<root>")
753 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200754 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
755 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
756 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
757 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
758 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
759 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
760 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
761 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
762 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
763 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
764 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
765 {"example-schema"s, "interrupt"},
766 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
767 {"example-schema"s, "pizzaSize"},
768 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
769 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
770 {"example-schema"s, "activeNumber"},
771 {"example-schema"s, "numberOrString"},
772 {"example-schema"s, "portSettings"},
773 {"example-schema"s, "portMapping"},
774 {"example-schema"s, "activeMappedPort"},
775 {"example-schema"s, "activePort"},
776 {"example-schema"s, "clockSpeed"},
777 {"example-schema"s, "deprecatedLeaf"},
778 {"example-schema"s, "obsoleteLeaf"},
779 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
780 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200781 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200782 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200783 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200784 {"example-schema"s, "addresses"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100785 {"example-schema"s, "subLeaf"},
786 {"example-schema"s, "flagBits"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200787 }
788
789 SECTION("example-schema:a")
790 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200791 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200792 set = {
793 {boost::none, "a2"},
794 {boost::none, "leafa"},
795 {"second-schema"s, "augmentedContainer"}
796 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200797 }
798
799 SECTION("example-schema:ethernet")
800 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200801 path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200802 set = {{boost::none, "ip"}};
803 }
804
805 SECTION("second-schema:bla")
806 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200807 path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla"));
Václav Kubernát95b08872020-04-28 01:04:17 +0200808 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200809 }
810
811 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200812 }
813
Václav Kubernát3a823f42020-04-29 23:40:21 +0200814 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200815 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200816 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200817 std::set<ModuleNodePair> expectedNonRecursive;
818 std::set<ModuleNodePair> expectedRecursive;
819 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200820 SECTION("example-schema")
821 {
822 module = "example-schema";
823 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200824 {"example-schema"s, "_list"},
825 {"example-schema"s, "a"},
826 {"example-schema"s, "activeMappedPort"},
827 {"example-schema"s, "activeNumber"},
828 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200829 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200830 {"example-schema"s, "another-duration"},
831 {"example-schema"s, "b"},
832 {"example-schema"s, "carry"},
833 {"example-schema"s, "clockSpeed"},
834 {"example-schema"s, "deprecatedLeaf"},
835 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200836 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200837 {"example-schema"s, "duration"},
838 {"example-schema"s, "ethernet"},
839 {"example-schema"s, "foodDrinkIdentLeaf"},
840 {"example-schema"s, "foodIdentLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100841 {"example-schema"s, "flagBits"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200842 {"example-schema"s, "interrupt"},
843 {"example-schema"s, "leafBool"},
844 {"example-schema"s, "leafDecimal"},
845 {"example-schema"s, "leafEnum"},
846 {"example-schema"s, "leafEnumTypedef"},
847 {"example-schema"s, "leafEnumTypedefRestricted"},
848 {"example-schema"s, "leafEnumTypedefRestricted2"},
849 {"example-schema"s, "leafInt16"},
850 {"example-schema"s, "leafInt32"},
851 {"example-schema"s, "leafInt64"},
852 {"example-schema"s, "leafInt8"},
853 {"example-schema"s, "leafString"},
854 {"example-schema"s, "leafUint16"},
855 {"example-schema"s, "leafUint32"},
856 {"example-schema"s, "leafUint64"},
857 {"example-schema"s, "leafUint8"},
858 {"example-schema"s, "length"},
859 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200860 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200861 {"example-schema"s, "numberOrString"},
862 {"example-schema"s, "obsoleteLeaf"},
863 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
864 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
865 {"example-schema"s, "pizzaIdentLeaf"},
866 {"example-schema"s, "pizzaSize"},
867 {"example-schema"s, "portMapping"},
868 {"example-schema"s, "portSettings"},
869 {"example-schema"s, "systemStats"},
870 {"example-schema"s, "twoKeyList"},
871 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200872 {"example-schema"s, "zero"},
873 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200874 };
875 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200876 {boost::none, "/example-schema:_list"},
877 {boost::none, "/example-schema:_list/contInList"},
878 {boost::none, "/example-schema:_list/number"},
879 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200880 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200881 {boost::none, "/example-schema:a/a2"},
882 {boost::none, "/example-schema:a/a2/a3"},
883 {boost::none, "/example-schema:a/leafa"},
884 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
885 {boost::none, "/example-schema:activeMappedPort"},
886 {boost::none, "/example-schema:activeNumber"},
887 {boost::none, "/example-schema:activePort"},
888 {boost::none, "/example-schema:another-duration"},
889 {boost::none, "/example-schema:b"},
890 {boost::none, "/example-schema:b/b2"},
891 {boost::none, "/example-schema:b/b2/b3"},
892 {boost::none, "/example-schema:carry"},
893 {boost::none, "/example-schema:clockSpeed"},
894 {boost::none, "/example-schema:deprecatedLeaf"},
895 {boost::none, "/example-schema:direction"},
896 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200897 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100898 {boost::none, "/example-schema:flagBits"},
899 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200900 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
901 {boost::none, "/example-schema:foodIdentLeaf"},
902 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
903 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
904 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
905 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
906 {boost::none, "/example-schema:interrupt"},
907 {boost::none, "/example-schema:leafBool"},
908 {boost::none, "/example-schema:leafDecimal"},
909 {boost::none, "/example-schema:leafEnum"},
910 {boost::none, "/example-schema:leafEnumTypedef"},
911 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
912 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
913 {boost::none, "/example-schema:leafInt16"},
914 {boost::none, "/example-schema:leafInt32"},
915 {boost::none, "/example-schema:leafInt64"},
916 {boost::none, "/example-schema:leafInt8"},
917 {boost::none, "/example-schema:leafString"},
918 {boost::none, "/example-schema:leafUint16"},
919 {boost::none, "/example-schema:leafUint32"},
920 {boost::none, "/example-schema:leafUint64"},
921 {boost::none, "/example-schema:leafUint8"},
922 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200923 {boost::none, "/example-schema:myRpc"},
924 {boost::none, "/example-schema:myRpc/input"},
925 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200926 {boost::none, "/example-schema:numberOrString"},
927 {boost::none, "/example-schema:obsoleteLeaf"},
928 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
929 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
930 {boost::none, "/example-schema:pizzaIdentLeaf"},
931 {boost::none, "/example-schema:pizzaSize"},
932 {boost::none, "/example-schema:portMapping"},
933 {boost::none, "/example-schema:portMapping/port"},
934 {boost::none, "/example-schema:portSettings"},
935 {boost::none, "/example-schema:portSettings/port"},
Václav Kubernáta8789602020-07-20 15:18:19 +0200936 {boost::none, "/example-schema:portSettings/shutdown"},
937 {boost::none, "/example-schema:portSettings/shutdown/input"},
938 {boost::none, "/example-schema:portSettings/shutdown/output"},
939 {boost::none, "/example-schema:portSettings/shutdown/output/success"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200940 {boost::none, "/example-schema:systemStats"},
941 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200942 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200943 {boost::none, "/example-schema:twoKeyList"},
944 {boost::none, "/example-schema:twoKeyList/name"},
945 {boost::none, "/example-schema:twoKeyList/number"},
946 {boost::none, "/example-schema:wavelength"},
947 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200948 };
949 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200950 SECTION("second-schema")
951 {
952 module = "second-schema";
953 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200954 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200955 };
956 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200957 {boost::none, "/second-schema:bla"},
958 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200959 };
960 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200961
Václav Kubernát3a823f42020-04-29 23:40:21 +0200962 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
963 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +0100964 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200965 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100966 SECTION("nodeType")
967 {
968 yang::NodeTypes expected;
969 SECTION("leafInt32")
970 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200971 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100972 expected = yang::NodeTypes::Leaf;
973 }
974
975 SECTION("a")
976 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200977 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100978 expected = yang::NodeTypes::Container;
979 }
980
981 SECTION("a/a2/a3")
982 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200983 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
984 path.m_nodes.emplace_back(container_("a2"));
985 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100986 expected = yang::NodeTypes::PresenceContainer;
987 }
988
989 SECTION("_list")
990 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200991 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100992 expected = yang::NodeTypes::List;
993 }
994
Václav Kubernát82d74632020-05-11 15:59:53 +0200995 SECTION("subLeaf")
996 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200997 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf"));
Václav Kubernát82d74632020-05-11 15:59:53 +0200998 expected = yang::NodeTypes::Leaf;
999 }
1000
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001001 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1002 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001003
1004 SECTION("description")
1005 {
1006 std::optional<std::string> expected;
1007 SECTION("leafInt32")
1008 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001009 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001010 expected = "A 32-bit integer leaf.";
1011 }
1012
1013 SECTION("leafString")
1014 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001015 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001016 }
1017
Václav Kubernát2984f442020-02-20 17:43:35 +01001018 SECTION("numberOrString")
1019 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001020 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +01001021 expected = "Can be an int32 or a string.";
1022 }
1023
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001024 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1025 }
1026
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001027 SECTION("status")
1028 {
1029 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1030 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1031 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1032 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1033 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1034 }
1035
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001036 SECTION("units")
1037 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001038 yang::LeafDataType expectedType;
1039 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001040 SECTION("length")
1041 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001042 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001043 expectedType.emplace<yang::Int32>();
1044 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001045 }
1046
1047 SECTION("wavelength")
1048 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001049 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001050 expectedType.emplace<yang::Decimal>();
1051 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001052 }
1053
1054 SECTION("leafInt32")
1055 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001056 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001057 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001058 }
1059
1060 SECTION("duration")
1061 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001062 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001063 expectedType.emplace<yang::Int32>();
1064 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001065 }
1066
1067 SECTION("another-duration")
1068 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001069 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration"));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001070 expectedType.emplace<yang::Int32>();
1071 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001072 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001073 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1074 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001075 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001076 }
1077
Václav Kubernát1ae24f42020-12-01 02:32:04 +01001078 SECTION("type description")
1079 {
1080 yang::LeafDataType expectedType = createEnum({"lol", "data"});
1081 std::optional<std::string> expectedDescription;
1082
1083 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafEnumTypedefRestricted2"));
1084 expectedDescription = "This is a restricted enum typedef.";
1085 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, std::nullopt, expectedDescription});
1086 }
1087
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001088 SECTION("nodeType")
1089 {
1090 yang::NodeTypes expected;
1091 SECTION("leafInt32")
1092 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001093 path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001094 expected = yang::NodeTypes::Leaf;
1095 }
1096
1097 SECTION("a")
1098 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001099 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001100 expected = yang::NodeTypes::Container;
1101 }
1102
1103 SECTION("a/a2/a3")
1104 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001105 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1106 path.m_nodes.emplace_back(container_("a2"));
1107 path.m_nodes.emplace_back(container_("a3"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001108 expected = yang::NodeTypes::PresenceContainer;
1109 }
1110
1111 SECTION("_list")
1112 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001113 path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list"));
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001114 expected = yang::NodeTypes::List;
1115 }
1116
1117 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1118 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001119
1120 SECTION("leafrefPath")
1121 {
1122 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1123 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001124
1125 SECTION("isConfig")
1126 {
1127 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1128 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1129 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1130 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1131 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001132
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001133 SECTION("defaultValue")
1134 {
1135 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1136 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1137 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1138 }
1139
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001140 SECTION("leafTypeName")
1141 {
1142 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1143 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1144 }
Václav Kubernáta8789602020-07-20 15:18:19 +02001145
1146 SECTION("dataPathToSchemaPath")
1147 {
1148 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings");
1149 REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown");
1150 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001151 }
1152
1153 SECTION("negative")
1154 {
1155 SECTION("nonexistent nodes")
1156 {
1157 SECTION("example-schema:coze")
1158 {
1159 node.first = "example-schema";
1160 node.second = "coze";
1161 }
1162
1163 SECTION("example-schema:a/nevim")
1164 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001165 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001166 node.second = "nevim";
1167 }
1168
1169 SECTION("modul:a/nevim")
1170 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001171 path.m_nodes.emplace_back(module_{"modul"}, container_("a"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001172 node.second = "nevim";
1173 }
1174
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001175 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001176 }
1177
1178 SECTION("nodetype-specific methods called with different nodetypes")
1179 {
Václav Kubernátfaacd022020-07-08 16:44:38 +02001180 path.m_nodes.emplace_back(module_{"example-schema"}, container_("a"));
1181 path.m_nodes.emplace_back(container_("a2"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001182
Václav Kubernát912b9492020-05-29 02:03:40 +02001183 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001184 }
1185
1186 SECTION("nonexistent module")
1187 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001188 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001189 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001190
Václav Kubernát7d82da72019-04-11 15:16:38 +02001191 SECTION("grouping is not a node")
1192 {
1193 SECTION("example-schema:arithmeticFlags")
1194 {
1195 node.first = "example-schema";
1196 node.second = "arithmeticFlags";
1197 }
1198
1199 SECTION("example-schema:flags")
1200 {
1201 node.first = "example-schema";
1202 node.second = "startAndStop";
1203 }
1204
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001205 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát7d82da72019-04-11 15:16:38 +02001206 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001207
1208 SECTION("choice is not a node")
1209 {
1210 SECTION("example-schema:interface")
1211 {
1212 node.first = "example-schema";
1213 node.second = "interface";
1214 }
1215
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001216 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001217 }
1218
1219 SECTION("case is not a node")
1220 {
1221 SECTION("example-schema:caseLoopback")
1222 {
1223 node.first = "example-schema";
1224 node.second = "caseLoopback";
1225 }
1226
1227 SECTION("example-schema:caseEthernet")
1228 {
1229 node.first = "example-schema";
1230 node.second = "caseEthernet";
1231 }
1232
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001233 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001234 }
Václav Kubernátf44bdda2020-06-22 15:58:41 +02001235
1236 SECTION("enableFeature - non existing module")
1237 {
1238 REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error);
1239 }
Václav Kubernát7aaf6dc2020-06-26 18:03:57 +02001240
1241 SECTION("enableFeature - non existing feature")
1242 {
1243 REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error);
1244 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001245 }
1246}