blob: 666c975ac0ec752efc812920fd2ca6e5a16b9274 [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áteeb38842019-03-20 19:46:05 +010040 schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "food"});
41 schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "vehicle"});
42 schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "pizza"});
43 schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "spaghetti"});
44 schema->addIdentity(ModuleValuePair{"mod", "pizza"}, ModuleValuePair{"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át2984f442020-02-20 17:43:35 +010076
Václav Kubernát07204242018-06-04 18:12:09 +020077 Parser parser(schema);
78 std::string input;
79 std::ostringstream errorStream;
80
81 SECTION("valid input")
82 {
83 set_ expected;
84
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010085 SECTION("set mod:leafString \"some_data\"")
Václav Kubernát07204242018-06-04 18:12:09 +020086 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010087 input = "set mod:leafString \'some_data\'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020088 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +020089 expected.m_data = std::string("some_data");
Václav Kubernát07204242018-06-04 18:12:09 +020090 }
91
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010092 SECTION("set mod:contA/leafInCont 'more_data'")
Václav Kubernát07204242018-06-04 18:12:09 +020093 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010094 input = "set mod:contA/leafInCont 'more_data'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020095 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
96 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
Václav Kubernátebca2552018-06-08 19:06:02 +020097 expected.m_data = std::string("more_data");
98 }
99
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100100 SECTION("set mod:contA/leafInCont \"data with' a quote\"")
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100101 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100102 input = "set mod:contA/leafInCont \"data with' a quote\"";
103 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
104 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
105 expected.m_data = std::string("data with' a quote");
106 }
107
108 SECTION("set mod:contA/leafInCont 'data with\" a quote'")
109 {
110 input = "set mod:contA/leafInCont 'data with\" a quote'";
111 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
112 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
113 expected.m_data = std::string("data with\" a quote");
114 }
115
116 SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string
117 {
118 input = "set mod:contA/leafInCont 'more d\tata'";
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100119 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
120 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
121 expected.m_data = std::string("more d\tata");
122 }
123
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100124 SECTION("set mod:list[number=1]/leafInList \"another_data\"")
Václav Kubernátebca2552018-06-08 19:06:02 +0200125 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100126 input = "set mod:list[number=1]/leafInList \"another_data\"";
Václav Kubernát7707cae2020-01-16 12:04:53 +0100127 auto keys = std::map<std::string, leaf_data_>{
128 {"number", int32_t{1}}};
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200129 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
130 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200131 expected.m_data = std::string("another_data");
132 }
133
134 SECTION("data types")
135 {
136 SECTION("string")
137 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100138 input = "set mod:leafString \"somedata\"";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200139 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200140 expected.m_data = std::string("somedata");
141 }
142
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200143 SECTION("int8")
Václav Kubernátebca2552018-06-08 19:06:02 +0200144 {
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200145 input = "set mod:leafInt8 2";
146 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
147 expected.m_data = int8_t{2};
148 }
149
150 SECTION("negative int8")
151 {
152 input = "set mod:leafInt8 -10";
153 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
154 expected.m_data = int8_t{-10};
155 }
156
157 SECTION("uint8")
158 {
159 input = "set mod:leafUint8 2";
160 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")});
161 expected.m_data = uint8_t{2};
162 }
163
164 SECTION("int16")
165 {
166 input = "set mod:leafInt16 30000";
167 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")});
168 expected.m_data = int16_t{30'000};
169 }
170
171 SECTION("uint16")
172 {
173 input = "set mod:leafUint16 30000";
174 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")});
175 expected.m_data = uint16_t{30'000};
176 }
177
178 SECTION("int32")
179 {
180 input = "set mod:leafInt32 30000";
181 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
182 expected.m_data = int32_t{30'000};
183 }
184
185 SECTION("uint32")
186 {
187 input = "set mod:leafUint32 30000";
188 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")});
189 expected.m_data = uint32_t{30'000};
190 }
191
192 SECTION("int32")
193 {
194 input = "set mod:leafInt32 30000";
195 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
196 expected.m_data = int32_t{30'000};
197 }
198
199 SECTION("uint64")
200 {
201 input = "set mod:leafUint64 30000";
202 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")});
203 expected.m_data = uint64_t{30'000};
Václav Kubernátebca2552018-06-08 19:06:02 +0200204 }
205
206 SECTION("decimal")
207 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200208 input = "set mod:leafDecimal 3.14159";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200209 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200210 expected.m_data = 3.14159;
211 }
212
213 SECTION("enum")
214 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200215 input = "set mod:leafEnum coze";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200216 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200217 expected.m_data = enum_("coze");
218 }
219
220 SECTION("bool")
221 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200222 input = "set mod:leafBool true";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200223 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200224 expected.m_data = true;
225 }
Václav Kubernátab538992019-03-06 15:30:50 +0100226
Václav Kubernát2984f442020-02-20 17:43:35 +0100227 SECTION("union")
228 {
229 SECTION("int")
230 {
231 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")});
232 input = "set mod:intOrString 90";
233 expected.m_data = int32_t{90};
234 }
235 SECTION("string")
236 {
237 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")});
238 input = "set mod:intOrString \"test\"";
239 expected.m_data = std::string{"test"};
240 }
241
242 SECTION("union with two integral types")
243 {
244 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("twoInts")});
245 SECTION("uint8")
246 {
247 input = "set mod:twoInts 100";
248 expected.m_data = uint8_t{100};
249 }
250 SECTION("int16")
251 {
252 input = "set mod:twoInts 6666";
253 expected.m_data = int16_t{6666};
254 }
255 }
256
257 SECTION("union with enum and leafref to enum")
258 {
259 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("unionStringEnumLeafref")});
260 SECTION("string")
261 {
262 input = "set mod:unionStringEnumLeafref \"AHOJ\"";
263 expected.m_data = std::string{"AHOJ"};
264 }
265 SECTION("enum")
266 {
267 input = "set mod:unionStringEnumLeafref bar";
268 expected.m_data = enum_("bar");
269 }
270 SECTION("enum leafref")
271 {
272 input = "set mod:unionStringEnumLeafref coze";
273 expected.m_data = enum_("coze");
274 }
275 }
276
277 SECTION("activePort")
278 {
279 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("activePort")});
280 input = "set mod:activePort ";
281 SECTION("1. anonymous enum")
282 {
283 SECTION("wlan0")
284 {
285 input += "wlan0";
286 expected.m_data = enum_("wlan0");
287 }
288 SECTION("wlan1")
289 {
290 input += "wlan1";
291 expected.m_data = enum_("wlan1");
292 }
293 }
294 SECTION("2. leafref to enum")
295 {
296 SECTION("eth0")
297 {
298 input += "eth0";
299 expected.m_data = enum_("eth0");
300 }
301 SECTION("eth1")
302 {
303 input += "eth1";
304 expected.m_data = enum_("eth1");
305 }
306 SECTION("eth2")
307 {
308 input += "eth2";
309 expected.m_data = enum_("eth2");
310 }
311 }
312 SECTION("3. leafref to leafref")
313 {
314 SECTION("utf1")
315 {
316 input += "utf1";
317 expected.m_data = enum_("utf1");
318 }
319 SECTION("utf2")
320 {
321 input += "utf2";
322 expected.m_data = enum_("utf2");
323 }
324 SECTION("utf3")
325 {
326 input += "utf3";
327 expected.m_data = enum_("utf3");
328 }
329 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200330 SECTION("4. empty")
331 {
332 expected.m_data = empty_{};
333 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100334 }
335 }
336
Václav Kubernátab538992019-03-06 15:30:50 +0100337 SECTION("binary")
338 {
339 SECTION("zero ending '='")
340 {
341 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++";
342 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"};
343 }
344
345 SECTION("one ending '='")
346 {
347 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=";
348 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="};
349 }
350
351 SECTION("two ending '='")
352 {
353 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++==";
354 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="};
355 }
356 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")});
357 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100358
359 SECTION("identityRef")
360 {
361 SECTION("foodIdentRef")
362 {
363 input = "set mod:foodIdentRef ";
364 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")});
365
366 SECTION("food")
367 {
368 input += "food";
369 expected.m_data = identityRef_("food");
370 }
371 SECTION("mod:food")
372 {
373 input += "mod:food";
374 expected.m_data = identityRef_("mod", "food");
375 }
376 SECTION("pizza")
377 {
378 input += "pizza";
379 expected.m_data = identityRef_("pizza");
380 }
381 SECTION("mod:pizza")
382 {
383 input += "mod:pizza";
384 expected.m_data = identityRef_("mod", "pizza");
385 }
386 SECTION("pizza-module:hawaii")
387 {
388 input += "pizza-module:hawaii";
389 expected.m_data = identityRef_("pizza-module", "hawaii");
390 }
391 }
392 SECTION("pizzaIdentRef")
393 {
394 input = "set mod:pizzaIdentRef ";
395 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")});
396 SECTION("pizza")
397 {
398 input += "pizza";
399 expected.m_data = identityRef_("pizza");
400 }
401 SECTION("mod:pizza")
402 {
403 input += "mod:pizza";
404 expected.m_data = identityRef_("mod", "pizza");
405 }
406 SECTION("pizza-module:hawaii")
407 {
408 input += "pizza-module:hawaii";
409 expected.m_data = identityRef_("pizza-module", "hawaii");
410 }
411 }
412 SECTION("mod:contA/identInCont")
413 {
414 input = "set mod:contA/identInCont ";
415 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
416 expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont")));
417 SECTION("pizza")
418 {
419 input += "pizza";
420 expected.m_data = identityRef_("pizza");
421 }
422 SECTION("mod:pizza")
423 {
424 input += "mod:pizza";
425 expected.m_data = identityRef_("mod", "pizza");
426 }
427 SECTION("pizza-module:hawaii")
428 {
429 input += "pizza-module:hawaii";
430 expected.m_data = identityRef_("pizza-module", "hawaii");
431 }
432 }
433 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200434 SECTION("leafRef")
435 {
436 SECTION("refToString")
437 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100438 input = "set mod:refToString \"blabal\"";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200439 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")});
440 expected.m_data = std::string("blabal");
441 }
442
443 SECTION("refToInt8")
444 {
445 input = "set mod:refToInt8 42";
446 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")});
447 expected.m_data = int8_t{42};
448 }
Václav Kubernát2d7b05c2020-04-05 14:02:37 +0200449
450 SECTION("refToLeafInCont")
451 {
452 input = "set mod:refToLeafInCont pizza";
453 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")});
454 expected.m_data = identityRef_{"pizza"};
455 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200456 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200457 SECTION("empty")
458 {
459 input = "set mod:dummy ";
460 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("dummy")});
461 expected.m_data = empty_{};
462 }
Václav Kubernát07204242018-06-04 18:12:09 +0200463 }
464
465 command_ command = parser.parseCommand(input, errorStream);
466 REQUIRE(command.type() == typeid(set_));
467 REQUIRE(boost::get<set_>(command) == expected);
468 }
469
470 SECTION("invalid input")
471 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100472 std::string expectedError;
Václav Kubernát07204242018-06-04 18:12:09 +0200473 SECTION("missing space between a command and its arguments")
474 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100475 SECTION("setmod:leafString some_data")
Václav Kubernát07204242018-06-04 18:12:09 +0200476 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100477 input = "setmod:leafString 'some_data'";
Václav Kubernát07204242018-06-04 18:12:09 +0200478 }
479 }
480
481 SECTION("missing space between arguments")
482 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100483 SECTION("set mod:leafString'lol'")
Václav Kubernát07204242018-06-04 18:12:09 +0200484 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100485 input = "set mod:leafString'lol'";
Václav Kubernát07204242018-06-04 18:12:09 +0200486 }
487 }
488
489 SECTION("non-leaf identifiers")
490 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100491 SECTION("set mod:nonexistent 'blabla'")
Václav Kubernát07204242018-06-04 18:12:09 +0200492 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100493 input = "set mod:nonexistent 'blabla'";
Václav Kubernát07204242018-06-04 18:12:09 +0200494 }
495
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100496 SECTION("set mod:contA 'abde'")
Václav Kubernát07204242018-06-04 18:12:09 +0200497 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100498 input = "set mod:contA 'abde'";
Václav Kubernát07204242018-06-04 18:12:09 +0200499 }
500 }
501
Václav Kubernátebca2552018-06-08 19:06:02 +0200502 SECTION("wrong types")
503 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100504 expectedError = "leaf data type mismatch";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100505 SECTION("set mod:leafBool 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200506 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100507 input = "set mod:leafBool 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200508 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100509 SECTION("set mod:leafUint8 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200510 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100511 input = "set mod:leafUint8 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200512 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100513 SECTION("set mod:leafUint8 -5")
Václav Kubernátebca2552018-06-08 19:06:02 +0200514 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100515 input = "set mod:leafUint8 -5";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200516 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100517 SECTION("set mod:leafInt8 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200518 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100519 input = "set mod:leafInt8 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200520 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100521 SECTION("set mod:leafInt8 130")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200522 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100523 input = "set mod:leafInt8 130";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200524 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100525 SECTION("set mod:leafUint16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200526 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100527 input = "set mod:leafUint16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200528 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100529 SECTION("set mod:leafInt16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200530 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100531 input = "set mod:leafInt16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200532 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100533 SECTION("set mod:leafUint32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200534 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100535 input = "set mod:leafUint32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200536 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100537 SECTION("set mod:leafInt32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200538 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100539 input = "set mod:leafInt32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200540 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100541 SECTION("set mod:leafUint64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200542 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100543 input = "set mod:leafUint64 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200544 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100545 SECTION("set mod:leafInt64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200546 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100547 input = "set mod:leafInt64 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200548 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100549 SECTION("set mod:leafEnum 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200550 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100551 input = "set mod:leafEnum 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200552 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100553 SECTION("set mod:refToInt8 'blabla'")
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200554 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100555 input = "set mod:refToInt8 'blabla'";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200556 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200557 }
558
Václav Kubernátab538992019-03-06 15:30:50 +0100559 SECTION("wrong base64 strings")
560 {
561 SECTION("invalid character")
Václav Kubernát777704d2020-01-15 18:48:06 +0100562 input = "set mod:leafBinary dbahj-";
Václav Kubernátab538992019-03-06 15:30:50 +0100563 SECTION("equal sign in the middle")
Václav Kubernát777704d2020-01-15 18:48:06 +0100564 input = "set mod:leafBinary db=ahj";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100565 SECTION("enclosing in quotes")
566 input = "set mod:leafBinary 'dbahj'";
Václav Kubernátab538992019-03-06 15:30:50 +0100567 }
568
Václav Kubernáteeb38842019-03-20 19:46:05 +0100569 SECTION("non-existing identity")
570 {
571 input = "set mod:foodIdentRef identityBLABLA";
572 }
573
574 SECTION("setting identities with wrong bases")
575 {
576 SECTION("set mod:foodIdentRef mod:vehicle")
577 {
578 input = "set mod:foodIdentRef mod:vehicle";
579 }
580 SECTION("set mod:pizzaIdentRef mod:food")
581 {
582 input = "set mod:pizzaIdentRef mod:food";
583 }
584 }
585 SECTION("setting different module identities without prefix")
586 {
587 input = "set mod:pizzaIdentRef hawaii";
588 }
589 SECTION("identity prefix without name")
590 {
591 input = "set mod:contA/identInCont pizza-module:";
592 }
593
Václav Kubernát2984f442020-02-20 17:43:35 +0100594 SECTION("set a union path to a wrong type")
595 {
596 input = "set mod:intOrString true";
597 }
598
Jan Kundrát379bb572020-05-07 03:23:13 +0200599 SECTION("no space for empty data")
600 {
601 input = "set mod:dummy";
602 }
603
Jan Kundrátc381e632019-03-14 13:39:11 +0100604 REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
Václav Kubernát777704d2020-01-15 18:48:06 +0100605 REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
Václav Kubernát07204242018-06-04 18:12:09 +0200606 }
607}