blob: ca5c8d6a3cd02040b2ddf153a8316765a30f6bf6 [file] [log] [blame]
Václav Kubernát07204242018-06-04 18:12:09 +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át26b56082020-02-03 18:28:56 +01009#include "trompeloeil_doctest.hpp"
Jan Kundrát76b3ddc2019-07-03 10:31:27 +020010#include <boost/core/demangle.hpp>
Václav Kubernát24df80e2018-06-06 15:18:03 +020011#include "ast_commands.hpp"
Václav Kubernát3a99f002020-03-31 02:27:41 +020012#include "leaf_data_helpers.hpp"
Václav Kubernát07204242018-06-04 18:12:09 +020013#include "parser.hpp"
Václav Kubernátbddbb172018-06-13 16:27:39 +020014#include "static_schema.hpp"
Václav Kubernát509ce652019-05-29 19:46:44 +020015#include "utils.hpp"
Václav Kubernát07204242018-06-04 18:12:09 +020016
Jan Kundrát76b3ddc2019-07-03 10:31:27 +020017std::ostream& operator<<(std::ostream& s, const set_ cmd)
18{
Václav Kubernátefcac932020-01-10 15:26:32 +010019 return s << "Command SET {path: " << pathToSchemaString(cmd.m_path, Prefixes::Always) << ", type " << boost::core::demangle(cmd.m_data.type().name()) << ", data: " << leafDataToString(cmd.m_data) << "}";
Jan Kundrát76b3ddc2019-07-03 10:31:27 +020020}
21
Václav Kubernát07204242018-06-04 18:12:09 +020022TEST_CASE("leaf editing")
23{
Václav Kubernátbddbb172018-06-13 16:27:39 +020024 auto schema = std::make_shared<StaticSchema>();
Václav Kubernát744f57f2018-06-29 22:46:26 +020025 schema->addModule("mod");
Václav Kubernáteeb38842019-03-20 19:46:05 +010026 schema->addModule("pizza-module");
Václav Kubernátefcac932020-01-10 15:26:32 +010027 schema->addContainer("/", "mod:contA");
Václav Kubernát3a99f002020-03-31 02:27:41 +020028 schema->addLeaf("/", "mod:leafString", yang::String{});
29 schema->addLeaf("/", "mod:leafDecimal", yang::Decimal{});
30 schema->addLeaf("/", "mod:leafBool", yang::Bool{});
31 schema->addLeaf("/", "mod:leafInt8", yang::Int8{});
32 schema->addLeaf("/", "mod:leafInt16", yang::Int16{});
33 schema->addLeaf("/", "mod:leafInt32", yang::Int32{});
34 schema->addLeaf("/", "mod:leafInt64", yang::Int64{});
35 schema->addLeaf("/", "mod:leafUint8", yang::Uint8{});
36 schema->addLeaf("/", "mod:leafUint16", yang::Uint16{});
37 schema->addLeaf("/", "mod:leafUint32", yang::Uint32{});
38 schema->addLeaf("/", "mod:leafUint64", yang::Uint64{});
39 schema->addLeaf("/", "mod:leafBinary", yang::Binary{});
Václav Kubernát222ecff2020-05-14 23:14:35 +020040 schema->addIdentity(std::nullopt, identityRef_{"mod", "food"});
41 schema->addIdentity(std::nullopt, identityRef_{"mod", "vehicle"});
42 schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "pizza"});
43 schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "spaghetti"});
44 schema->addIdentity(identityRef_{"mod", "pizza"}, identityRef_{"pizza-module", "hawaii"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020045 schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")});
46 schema->addLeaf("/", "mod:pizzaIdentRef", yang::IdentityRef{schema->validIdentities("mod", "pizza")});
47 schema->addLeaf("/mod:contA", "mod:identInCont", yang::IdentityRef{schema->validIdentities("mod", "pizza")});
48 schema->addLeaf("/", "mod:leafEnum", createEnum({"lol", "data", "coze"}));
49 schema->addLeaf("/mod:contA", "mod:leafInCont", yang::String{});
Václav Kubernátefcac932020-01-10 15:26:32 +010050 schema->addList("/", "mod:list", {"number"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020051 schema->addLeaf("/mod:list", "mod:number", yang::Int32{});
52 schema->addLeaf("/mod:list", "mod:leafInList", yang::String{});
Václav Kubernát13b23d72020-04-16 21:49:51 +020053 schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafString"))});
54 schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafInt8"))});
55 schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:contA/mod:identInCont"))});
56 schema->addLeaf("/", "mod:intOrString", yang::Union{{yang::TypeInfo{yang::Int32{}}, yang::TypeInfo{yang::String{}}}});
57 schema->addLeaf("/", "mod:twoInts", yang::Union{{yang::TypeInfo{yang::Uint8{}}, yang::TypeInfo{yang::Int16{}}}});
Václav Kubernát2984f442020-02-20 17:43:35 +010058 schema->addLeaf("/", "mod:unionStringEnumLeafref", yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +020059 yang::LeafDataType{yang::String{}},
60 yang::LeafDataType{createEnum({"foo", "bar"})},
61 yang::LeafDataType{yang::LeafRef{"/mod:leafEnum", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafEnum"))}}
Václav Kubernát2984f442020-02-20 17:43:35 +010062 }});
63
64 schema->addList("/", "mod:portSettings", {"port"});
65 schema->addLeaf("/mod:portSettings", "mod:port", createEnum({"eth0", "eth1", "eth2"}));
66 schema->addList("/", "mod:portMapping", {"port"});
67 schema->addLeaf("/mod:portMapping", "mod:port", createEnum({"utf1", "utf2", "utf3"}));
Václav Kubernát13b23d72020-04-16 21:49:51 +020068 schema->addLeaf("/", "mod:activeMappedPort", yang::LeafRef{"/mod:portMapping/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portMapping/mod:port"))});
Václav Kubernát2984f442020-02-20 17:43:35 +010069 schema->addLeaf("/", "mod:activePort", yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +020070 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
71 yang::TypeInfo{yang::LeafRef{"/mod:portSettings/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portSettings/mod:port"))}},
72 yang::TypeInfo{yang::LeafRef{"/mod:activeMappedPort", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:activeMappedPort"))}},
Jan Kundrát379bb572020-05-07 03:23:13 +020073 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +010074 }});
Jan Kundrát379bb572020-05-07 03:23:13 +020075 schema->addLeaf("/", "mod:dummy", yang::Empty{});
Václav Kubernátabf52802020-05-19 01:31:17 +020076 schema->addLeaf("/", "mod:readonly", yang::Int32{}, yang::AccessType::ReadOnly);
Václav Kubernát2984f442020-02-20 17:43:35 +010077
Václav Kubernát07204242018-06-04 18:12:09 +020078 Parser parser(schema);
79 std::string input;
80 std::ostringstream errorStream;
81
82 SECTION("valid input")
83 {
84 set_ expected;
85
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010086 SECTION("set mod:leafString \"some_data\"")
Václav Kubernát07204242018-06-04 18:12:09 +020087 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010088 input = "set mod:leafString \'some_data\'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020089 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +020090 expected.m_data = std::string("some_data");
Václav Kubernát07204242018-06-04 18:12:09 +020091 }
92
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010093 SECTION("set mod:contA/leafInCont 'more_data'")
Václav Kubernát07204242018-06-04 18:12:09 +020094 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010095 input = "set mod:contA/leafInCont 'more_data'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020096 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
97 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
Václav Kubernátebca2552018-06-08 19:06:02 +020098 expected.m_data = std::string("more_data");
99 }
100
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100101 SECTION("set mod:contA/leafInCont \"data with' a quote\"")
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100102 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100103 input = "set mod:contA/leafInCont \"data with' a quote\"";
104 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
105 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
106 expected.m_data = std::string("data with' a quote");
107 }
108
109 SECTION("set mod:contA/leafInCont 'data with\" a quote'")
110 {
111 input = "set mod:contA/leafInCont 'data with\" a quote'";
112 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
113 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
114 expected.m_data = std::string("data with\" a quote");
115 }
116
117 SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string
118 {
119 input = "set mod:contA/leafInCont 'more d\tata'";
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100120 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
121 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
122 expected.m_data = std::string("more d\tata");
123 }
124
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100125 SECTION("set mod:list[number=1]/leafInList \"another_data\"")
Václav Kubernátebca2552018-06-08 19:06:02 +0200126 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100127 input = "set mod:list[number=1]/leafInList \"another_data\"";
Václav Kubernátc15fe822020-06-04 11:28:39 +0200128 auto keys = ListInstance {
Václav Kubernát7707cae2020-01-16 12:04:53 +0100129 {"number", int32_t{1}}};
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200130 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
131 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200132 expected.m_data = std::string("another_data");
133 }
134
135 SECTION("data types")
136 {
137 SECTION("string")
138 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100139 input = "set mod:leafString \"somedata\"";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200140 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200141 expected.m_data = std::string("somedata");
142 }
143
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200144 SECTION("int8")
Václav Kubernátebca2552018-06-08 19:06:02 +0200145 {
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200146 input = "set mod:leafInt8 2";
147 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
148 expected.m_data = int8_t{2};
149 }
150
151 SECTION("negative int8")
152 {
153 input = "set mod:leafInt8 -10";
154 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
155 expected.m_data = int8_t{-10};
156 }
157
158 SECTION("uint8")
159 {
160 input = "set mod:leafUint8 2";
161 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")});
162 expected.m_data = uint8_t{2};
163 }
164
165 SECTION("int16")
166 {
167 input = "set mod:leafInt16 30000";
168 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")});
169 expected.m_data = int16_t{30'000};
170 }
171
172 SECTION("uint16")
173 {
174 input = "set mod:leafUint16 30000";
175 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")});
176 expected.m_data = uint16_t{30'000};
177 }
178
179 SECTION("int32")
180 {
181 input = "set mod:leafInt32 30000";
182 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
183 expected.m_data = int32_t{30'000};
184 }
185
186 SECTION("uint32")
187 {
188 input = "set mod:leafUint32 30000";
189 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")});
190 expected.m_data = uint32_t{30'000};
191 }
192
193 SECTION("int32")
194 {
195 input = "set mod:leafInt32 30000";
196 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
197 expected.m_data = int32_t{30'000};
198 }
199
200 SECTION("uint64")
201 {
202 input = "set mod:leafUint64 30000";
203 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")});
204 expected.m_data = uint64_t{30'000};
Václav Kubernátebca2552018-06-08 19:06:02 +0200205 }
206
207 SECTION("decimal")
208 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200209 input = "set mod:leafDecimal 3.14159";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200210 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200211 expected.m_data = 3.14159;
212 }
213
214 SECTION("enum")
215 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200216 input = "set mod:leafEnum coze";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200217 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200218 expected.m_data = enum_("coze");
219 }
220
221 SECTION("bool")
222 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200223 input = "set mod:leafBool true";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200224 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200225 expected.m_data = true;
226 }
Václav Kubernátab538992019-03-06 15:30:50 +0100227
Václav Kubernát2984f442020-02-20 17:43:35 +0100228 SECTION("union")
229 {
230 SECTION("int")
231 {
232 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")});
233 input = "set mod:intOrString 90";
234 expected.m_data = int32_t{90};
235 }
236 SECTION("string")
237 {
238 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")});
239 input = "set mod:intOrString \"test\"";
240 expected.m_data = std::string{"test"};
241 }
242
243 SECTION("union with two integral types")
244 {
245 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("twoInts")});
246 SECTION("uint8")
247 {
248 input = "set mod:twoInts 100";
249 expected.m_data = uint8_t{100};
250 }
251 SECTION("int16")
252 {
253 input = "set mod:twoInts 6666";
254 expected.m_data = int16_t{6666};
255 }
256 }
257
258 SECTION("union with enum and leafref to enum")
259 {
260 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("unionStringEnumLeafref")});
261 SECTION("string")
262 {
263 input = "set mod:unionStringEnumLeafref \"AHOJ\"";
264 expected.m_data = std::string{"AHOJ"};
265 }
266 SECTION("enum")
267 {
268 input = "set mod:unionStringEnumLeafref bar";
269 expected.m_data = enum_("bar");
270 }
271 SECTION("enum leafref")
272 {
273 input = "set mod:unionStringEnumLeafref coze";
274 expected.m_data = enum_("coze");
275 }
276 }
277
278 SECTION("activePort")
279 {
280 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("activePort")});
281 input = "set mod:activePort ";
282 SECTION("1. anonymous enum")
283 {
284 SECTION("wlan0")
285 {
286 input += "wlan0";
287 expected.m_data = enum_("wlan0");
288 }
289 SECTION("wlan1")
290 {
291 input += "wlan1";
292 expected.m_data = enum_("wlan1");
293 }
294 }
295 SECTION("2. leafref to enum")
296 {
297 SECTION("eth0")
298 {
299 input += "eth0";
300 expected.m_data = enum_("eth0");
301 }
302 SECTION("eth1")
303 {
304 input += "eth1";
305 expected.m_data = enum_("eth1");
306 }
307 SECTION("eth2")
308 {
309 input += "eth2";
310 expected.m_data = enum_("eth2");
311 }
312 }
313 SECTION("3. leafref to leafref")
314 {
315 SECTION("utf1")
316 {
317 input += "utf1";
318 expected.m_data = enum_("utf1");
319 }
320 SECTION("utf2")
321 {
322 input += "utf2";
323 expected.m_data = enum_("utf2");
324 }
325 SECTION("utf3")
326 {
327 input += "utf3";
328 expected.m_data = enum_("utf3");
329 }
330 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200331 SECTION("4. empty")
332 {
333 expected.m_data = empty_{};
334 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100335 }
336 }
337
Václav Kubernátab538992019-03-06 15:30:50 +0100338 SECTION("binary")
339 {
340 SECTION("zero ending '='")
341 {
342 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++";
343 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"};
344 }
345
346 SECTION("one ending '='")
347 {
348 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=";
349 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="};
350 }
351
352 SECTION("two ending '='")
353 {
354 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++==";
355 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="};
356 }
357 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")});
358 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100359
360 SECTION("identityRef")
361 {
362 SECTION("foodIdentRef")
363 {
364 input = "set mod:foodIdentRef ";
365 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")});
366
367 SECTION("food")
368 {
369 input += "food";
370 expected.m_data = identityRef_("food");
371 }
372 SECTION("mod:food")
373 {
374 input += "mod:food";
375 expected.m_data = identityRef_("mod", "food");
376 }
377 SECTION("pizza")
378 {
379 input += "pizza";
380 expected.m_data = identityRef_("pizza");
381 }
382 SECTION("mod:pizza")
383 {
384 input += "mod:pizza";
385 expected.m_data = identityRef_("mod", "pizza");
386 }
387 SECTION("pizza-module:hawaii")
388 {
389 input += "pizza-module:hawaii";
390 expected.m_data = identityRef_("pizza-module", "hawaii");
391 }
392 }
393 SECTION("pizzaIdentRef")
394 {
395 input = "set mod:pizzaIdentRef ";
396 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")});
397 SECTION("pizza")
398 {
399 input += "pizza";
400 expected.m_data = identityRef_("pizza");
401 }
402 SECTION("mod:pizza")
403 {
404 input += "mod:pizza";
405 expected.m_data = identityRef_("mod", "pizza");
406 }
407 SECTION("pizza-module:hawaii")
408 {
409 input += "pizza-module:hawaii";
410 expected.m_data = identityRef_("pizza-module", "hawaii");
411 }
412 }
413 SECTION("mod:contA/identInCont")
414 {
415 input = "set mod:contA/identInCont ";
416 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
417 expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont")));
418 SECTION("pizza")
419 {
420 input += "pizza";
421 expected.m_data = identityRef_("pizza");
422 }
423 SECTION("mod:pizza")
424 {
425 input += "mod:pizza";
426 expected.m_data = identityRef_("mod", "pizza");
427 }
428 SECTION("pizza-module:hawaii")
429 {
430 input += "pizza-module:hawaii";
431 expected.m_data = identityRef_("pizza-module", "hawaii");
432 }
433 }
434 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200435 SECTION("leafRef")
436 {
437 SECTION("refToString")
438 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100439 input = "set mod:refToString \"blabal\"";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200440 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")});
441 expected.m_data = std::string("blabal");
442 }
443
444 SECTION("refToInt8")
445 {
446 input = "set mod:refToInt8 42";
447 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")});
448 expected.m_data = int8_t{42};
449 }
Václav Kubernát2d7b05c2020-04-05 14:02:37 +0200450
451 SECTION("refToLeafInCont")
452 {
453 input = "set mod:refToLeafInCont pizza";
454 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")});
455 expected.m_data = identityRef_{"pizza"};
456 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200457 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200458 SECTION("empty")
459 {
460 input = "set mod:dummy ";
461 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("dummy")});
462 expected.m_data = empty_{};
463 }
Václav Kubernát07204242018-06-04 18:12:09 +0200464 }
465
466 command_ command = parser.parseCommand(input, errorStream);
467 REQUIRE(command.type() == typeid(set_));
468 REQUIRE(boost::get<set_>(command) == expected);
469 }
470
471 SECTION("invalid input")
472 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100473 std::string expectedError;
Václav Kubernát07204242018-06-04 18:12:09 +0200474 SECTION("missing space between a command and its arguments")
475 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100476 SECTION("setmod:leafString some_data")
Václav Kubernát07204242018-06-04 18:12:09 +0200477 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100478 input = "setmod:leafString 'some_data'";
Václav Kubernát07204242018-06-04 18:12:09 +0200479 }
480 }
481
482 SECTION("missing space between arguments")
483 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100484 SECTION("set mod:leafString'lol'")
Václav Kubernát07204242018-06-04 18:12:09 +0200485 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100486 input = "set mod:leafString'lol'";
Václav Kubernát07204242018-06-04 18:12:09 +0200487 }
488 }
489
490 SECTION("non-leaf identifiers")
491 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100492 SECTION("set mod:nonexistent 'blabla'")
Václav Kubernát07204242018-06-04 18:12:09 +0200493 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100494 input = "set mod:nonexistent 'blabla'";
Václav Kubernát07204242018-06-04 18:12:09 +0200495 }
496
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100497 SECTION("set mod:contA 'abde'")
Václav Kubernát07204242018-06-04 18:12:09 +0200498 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100499 input = "set mod:contA 'abde'";
Václav Kubernát07204242018-06-04 18:12:09 +0200500 }
501 }
502
Václav Kubernátebca2552018-06-08 19:06:02 +0200503 SECTION("wrong types")
504 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100505 expectedError = "leaf data type mismatch";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100506 SECTION("set mod:leafBool 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200507 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100508 input = "set mod:leafBool 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200509 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100510 SECTION("set mod:leafUint8 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200511 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100512 input = "set mod:leafUint8 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200513 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100514 SECTION("set mod:leafUint8 -5")
Václav Kubernátebca2552018-06-08 19:06:02 +0200515 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100516 input = "set mod:leafUint8 -5";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200517 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100518 SECTION("set mod:leafInt8 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200519 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100520 input = "set mod:leafInt8 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200521 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100522 SECTION("set mod:leafInt8 130")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200523 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100524 input = "set mod:leafInt8 130";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200525 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100526 SECTION("set mod:leafUint16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200527 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100528 input = "set mod:leafUint16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200529 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100530 SECTION("set mod:leafInt16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200531 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100532 input = "set mod:leafInt16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200533 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100534 SECTION("set mod:leafUint32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200535 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100536 input = "set mod:leafUint32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200537 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100538 SECTION("set mod:leafInt32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200539 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100540 input = "set mod:leafInt32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200541 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100542 SECTION("set mod:leafUint64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200543 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100544 input = "set mod:leafUint64 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200545 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100546 SECTION("set mod:leafInt64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200547 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100548 input = "set mod:leafInt64 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200549 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100550 SECTION("set mod:leafEnum 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200551 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100552 input = "set mod:leafEnum 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200553 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100554 SECTION("set mod:refToInt8 'blabla'")
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200555 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100556 input = "set mod:refToInt8 'blabla'";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200557 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200558 }
559
Václav Kubernátab538992019-03-06 15:30:50 +0100560 SECTION("wrong base64 strings")
561 {
562 SECTION("invalid character")
Václav Kubernát777704d2020-01-15 18:48:06 +0100563 input = "set mod:leafBinary dbahj-";
Václav Kubernátab538992019-03-06 15:30:50 +0100564 SECTION("equal sign in the middle")
Václav Kubernát777704d2020-01-15 18:48:06 +0100565 input = "set mod:leafBinary db=ahj";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100566 SECTION("enclosing in quotes")
567 input = "set mod:leafBinary 'dbahj'";
Václav Kubernátab538992019-03-06 15:30:50 +0100568 }
569
Václav Kubernáteeb38842019-03-20 19:46:05 +0100570 SECTION("non-existing identity")
571 {
572 input = "set mod:foodIdentRef identityBLABLA";
573 }
574
575 SECTION("setting identities with wrong bases")
576 {
577 SECTION("set mod:foodIdentRef mod:vehicle")
578 {
579 input = "set mod:foodIdentRef mod:vehicle";
580 }
581 SECTION("set mod:pizzaIdentRef mod:food")
582 {
583 input = "set mod:pizzaIdentRef mod:food";
584 }
585 }
586 SECTION("setting different module identities without prefix")
587 {
588 input = "set mod:pizzaIdentRef hawaii";
589 }
590 SECTION("identity prefix without name")
591 {
592 input = "set mod:contA/identInCont pizza-module:";
593 }
594
Václav Kubernát2984f442020-02-20 17:43:35 +0100595 SECTION("set a union path to a wrong type")
596 {
597 input = "set mod:intOrString true";
598 }
599
Jan Kundrát379bb572020-05-07 03:23:13 +0200600 SECTION("no space for empty data")
601 {
602 input = "set mod:dummy";
603 }
604
Václav Kubernát0d42c512020-05-20 21:18:39 +0200605 SECTION("empty path")
606 {
607 input = "set ";
608 }
609
Václav Kubernátabf52802020-05-19 01:31:17 +0200610 SECTION("setting readonly data")
611 {
612 input = "set mod:readonly 123";
613 }
614
Jan Kundrátc381e632019-03-14 13:39:11 +0100615 REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
Václav Kubernát777704d2020-01-15 18:48:06 +0100616 REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
Václav Kubernát07204242018-06-04 18:12:09 +0200617 }
618}