blob: 64abbf2ab4fbc1543cfef407fd390bf280181e40 [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"))}},
Václav Kubernát2984f442020-02-20 17:43:35 +010073 }});
74
Václav Kubernát07204242018-06-04 18:12:09 +020075 Parser parser(schema);
76 std::string input;
77 std::ostringstream errorStream;
78
79 SECTION("valid input")
80 {
81 set_ expected;
82
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010083 SECTION("set mod:leafString \"some_data\"")
Václav Kubernát07204242018-06-04 18:12:09 +020084 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010085 input = "set mod:leafString \'some_data\'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020086 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +020087 expected.m_data = std::string("some_data");
Václav Kubernát07204242018-06-04 18:12:09 +020088 }
89
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010090 SECTION("set mod:contA/leafInCont 'more_data'")
Václav Kubernát07204242018-06-04 18:12:09 +020091 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010092 input = "set mod:contA/leafInCont 'more_data'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020093 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
94 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
Václav Kubernátebca2552018-06-08 19:06:02 +020095 expected.m_data = std::string("more_data");
96 }
97
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010098 SECTION("set mod:contA/leafInCont \"data with' a quote\"")
Václav Kubernátc18ffac2020-01-10 16:06:06 +010099 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100100 input = "set mod:contA/leafInCont \"data with' a quote\"";
101 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
102 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
103 expected.m_data = std::string("data with' a quote");
104 }
105
106 SECTION("set mod:contA/leafInCont 'data with\" a quote'")
107 {
108 input = "set mod:contA/leafInCont 'data with\" a quote'";
109 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
110 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
111 expected.m_data = std::string("data with\" a quote");
112 }
113
114 SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string
115 {
116 input = "set mod:contA/leafInCont 'more d\tata'";
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100117 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
118 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
119 expected.m_data = std::string("more d\tata");
120 }
121
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100122 SECTION("set mod:list[number=1]/leafInList \"another_data\"")
Václav Kubernátebca2552018-06-08 19:06:02 +0200123 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100124 input = "set mod:list[number=1]/leafInList \"another_data\"";
Václav Kubernát7707cae2020-01-16 12:04:53 +0100125 auto keys = std::map<std::string, leaf_data_>{
126 {"number", int32_t{1}}};
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200127 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
128 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200129 expected.m_data = std::string("another_data");
130 }
131
132 SECTION("data types")
133 {
134 SECTION("string")
135 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100136 input = "set mod:leafString \"somedata\"";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200137 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200138 expected.m_data = std::string("somedata");
139 }
140
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200141 SECTION("int8")
Václav Kubernátebca2552018-06-08 19:06:02 +0200142 {
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200143 input = "set mod:leafInt8 2";
144 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
145 expected.m_data = int8_t{2};
146 }
147
148 SECTION("negative int8")
149 {
150 input = "set mod:leafInt8 -10";
151 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
152 expected.m_data = int8_t{-10};
153 }
154
155 SECTION("uint8")
156 {
157 input = "set mod:leafUint8 2";
158 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")});
159 expected.m_data = uint8_t{2};
160 }
161
162 SECTION("int16")
163 {
164 input = "set mod:leafInt16 30000";
165 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")});
166 expected.m_data = int16_t{30'000};
167 }
168
169 SECTION("uint16")
170 {
171 input = "set mod:leafUint16 30000";
172 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")});
173 expected.m_data = uint16_t{30'000};
174 }
175
176 SECTION("int32")
177 {
178 input = "set mod:leafInt32 30000";
179 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
180 expected.m_data = int32_t{30'000};
181 }
182
183 SECTION("uint32")
184 {
185 input = "set mod:leafUint32 30000";
186 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")});
187 expected.m_data = uint32_t{30'000};
188 }
189
190 SECTION("int32")
191 {
192 input = "set mod:leafInt32 30000";
193 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
194 expected.m_data = int32_t{30'000};
195 }
196
197 SECTION("uint64")
198 {
199 input = "set mod:leafUint64 30000";
200 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")});
201 expected.m_data = uint64_t{30'000};
Václav Kubernátebca2552018-06-08 19:06:02 +0200202 }
203
204 SECTION("decimal")
205 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200206 input = "set mod:leafDecimal 3.14159";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200207 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200208 expected.m_data = 3.14159;
209 }
210
211 SECTION("enum")
212 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200213 input = "set mod:leafEnum coze";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200214 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200215 expected.m_data = enum_("coze");
216 }
217
218 SECTION("bool")
219 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200220 input = "set mod:leafBool true";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200221 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200222 expected.m_data = true;
223 }
Václav Kubernátab538992019-03-06 15:30:50 +0100224
Václav Kubernát2984f442020-02-20 17:43:35 +0100225 SECTION("union")
226 {
227 SECTION("int")
228 {
229 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")});
230 input = "set mod:intOrString 90";
231 expected.m_data = int32_t{90};
232 }
233 SECTION("string")
234 {
235 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")});
236 input = "set mod:intOrString \"test\"";
237 expected.m_data = std::string{"test"};
238 }
239
240 SECTION("union with two integral types")
241 {
242 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("twoInts")});
243 SECTION("uint8")
244 {
245 input = "set mod:twoInts 100";
246 expected.m_data = uint8_t{100};
247 }
248 SECTION("int16")
249 {
250 input = "set mod:twoInts 6666";
251 expected.m_data = int16_t{6666};
252 }
253 }
254
255 SECTION("union with enum and leafref to enum")
256 {
257 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("unionStringEnumLeafref")});
258 SECTION("string")
259 {
260 input = "set mod:unionStringEnumLeafref \"AHOJ\"";
261 expected.m_data = std::string{"AHOJ"};
262 }
263 SECTION("enum")
264 {
265 input = "set mod:unionStringEnumLeafref bar";
266 expected.m_data = enum_("bar");
267 }
268 SECTION("enum leafref")
269 {
270 input = "set mod:unionStringEnumLeafref coze";
271 expected.m_data = enum_("coze");
272 }
273 }
274
275 SECTION("activePort")
276 {
277 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("activePort")});
278 input = "set mod:activePort ";
279 SECTION("1. anonymous enum")
280 {
281 SECTION("wlan0")
282 {
283 input += "wlan0";
284 expected.m_data = enum_("wlan0");
285 }
286 SECTION("wlan1")
287 {
288 input += "wlan1";
289 expected.m_data = enum_("wlan1");
290 }
291 }
292 SECTION("2. leafref to enum")
293 {
294 SECTION("eth0")
295 {
296 input += "eth0";
297 expected.m_data = enum_("eth0");
298 }
299 SECTION("eth1")
300 {
301 input += "eth1";
302 expected.m_data = enum_("eth1");
303 }
304 SECTION("eth2")
305 {
306 input += "eth2";
307 expected.m_data = enum_("eth2");
308 }
309 }
310 SECTION("3. leafref to leafref")
311 {
312 SECTION("utf1")
313 {
314 input += "utf1";
315 expected.m_data = enum_("utf1");
316 }
317 SECTION("utf2")
318 {
319 input += "utf2";
320 expected.m_data = enum_("utf2");
321 }
322 SECTION("utf3")
323 {
324 input += "utf3";
325 expected.m_data = enum_("utf3");
326 }
327 }
328 }
329 }
330
Václav Kubernátab538992019-03-06 15:30:50 +0100331 SECTION("binary")
332 {
333 SECTION("zero ending '='")
334 {
335 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++";
336 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"};
337 }
338
339 SECTION("one ending '='")
340 {
341 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=";
342 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="};
343 }
344
345 SECTION("two ending '='")
346 {
347 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++==";
348 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="};
349 }
350 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")});
351 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100352
353 SECTION("identityRef")
354 {
355 SECTION("foodIdentRef")
356 {
357 input = "set mod:foodIdentRef ";
358 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")});
359
360 SECTION("food")
361 {
362 input += "food";
363 expected.m_data = identityRef_("food");
364 }
365 SECTION("mod:food")
366 {
367 input += "mod:food";
368 expected.m_data = identityRef_("mod", "food");
369 }
370 SECTION("pizza")
371 {
372 input += "pizza";
373 expected.m_data = identityRef_("pizza");
374 }
375 SECTION("mod:pizza")
376 {
377 input += "mod:pizza";
378 expected.m_data = identityRef_("mod", "pizza");
379 }
380 SECTION("pizza-module:hawaii")
381 {
382 input += "pizza-module:hawaii";
383 expected.m_data = identityRef_("pizza-module", "hawaii");
384 }
385 }
386 SECTION("pizzaIdentRef")
387 {
388 input = "set mod:pizzaIdentRef ";
389 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")});
390 SECTION("pizza")
391 {
392 input += "pizza";
393 expected.m_data = identityRef_("pizza");
394 }
395 SECTION("mod:pizza")
396 {
397 input += "mod:pizza";
398 expected.m_data = identityRef_("mod", "pizza");
399 }
400 SECTION("pizza-module:hawaii")
401 {
402 input += "pizza-module:hawaii";
403 expected.m_data = identityRef_("pizza-module", "hawaii");
404 }
405 }
406 SECTION("mod:contA/identInCont")
407 {
408 input = "set mod:contA/identInCont ";
409 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
410 expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont")));
411 SECTION("pizza")
412 {
413 input += "pizza";
414 expected.m_data = identityRef_("pizza");
415 }
416 SECTION("mod:pizza")
417 {
418 input += "mod:pizza";
419 expected.m_data = identityRef_("mod", "pizza");
420 }
421 SECTION("pizza-module:hawaii")
422 {
423 input += "pizza-module:hawaii";
424 expected.m_data = identityRef_("pizza-module", "hawaii");
425 }
426 }
427 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200428 SECTION("leafRef")
429 {
430 SECTION("refToString")
431 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100432 input = "set mod:refToString \"blabal\"";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200433 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")});
434 expected.m_data = std::string("blabal");
435 }
436
437 SECTION("refToInt8")
438 {
439 input = "set mod:refToInt8 42";
440 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")});
441 expected.m_data = int8_t{42};
442 }
Václav Kubernát2d7b05c2020-04-05 14:02:37 +0200443
444 SECTION("refToLeafInCont")
445 {
446 input = "set mod:refToLeafInCont pizza";
447 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")});
448 expected.m_data = identityRef_{"pizza"};
449 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200450 }
Václav Kubernát07204242018-06-04 18:12:09 +0200451 }
452
453 command_ command = parser.parseCommand(input, errorStream);
454 REQUIRE(command.type() == typeid(set_));
455 REQUIRE(boost::get<set_>(command) == expected);
456 }
457
458 SECTION("invalid input")
459 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100460 std::string expectedError;
Václav Kubernát07204242018-06-04 18:12:09 +0200461 SECTION("missing space between a command and its arguments")
462 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100463 SECTION("setmod:leafString some_data")
Václav Kubernát07204242018-06-04 18:12:09 +0200464 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100465 input = "setmod:leafString 'some_data'";
Václav Kubernát07204242018-06-04 18:12:09 +0200466 }
467 }
468
469 SECTION("missing space between arguments")
470 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100471 SECTION("set mod:leafString'lol'")
Václav Kubernát07204242018-06-04 18:12:09 +0200472 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100473 input = "set mod:leafString'lol'";
Václav Kubernát07204242018-06-04 18:12:09 +0200474 }
475 }
476
477 SECTION("non-leaf identifiers")
478 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100479 SECTION("set mod:nonexistent 'blabla'")
Václav Kubernát07204242018-06-04 18:12:09 +0200480 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100481 input = "set mod:nonexistent 'blabla'";
Václav Kubernát07204242018-06-04 18:12:09 +0200482 }
483
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100484 SECTION("set mod:contA 'abde'")
Václav Kubernát07204242018-06-04 18:12:09 +0200485 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100486 input = "set mod:contA 'abde'";
Václav Kubernát07204242018-06-04 18:12:09 +0200487 }
488 }
489
Václav Kubernátebca2552018-06-08 19:06:02 +0200490 SECTION("wrong types")
491 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100492 expectedError = "leaf data type mismatch";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100493 SECTION("set mod:leafBool 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200494 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100495 input = "set mod:leafBool 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200496 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100497 SECTION("set mod:leafUint8 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200498 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100499 input = "set mod:leafUint8 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200500 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100501 SECTION("set mod:leafUint8 -5")
Václav Kubernátebca2552018-06-08 19:06:02 +0200502 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100503 input = "set mod:leafUint8 -5";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200504 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100505 SECTION("set mod:leafInt8 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200506 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100507 input = "set mod:leafInt8 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200508 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100509 SECTION("set mod:leafInt8 130")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200510 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100511 input = "set mod:leafInt8 130";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200512 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100513 SECTION("set mod:leafUint16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200514 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100515 input = "set mod:leafUint16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200516 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100517 SECTION("set mod:leafInt16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200518 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100519 input = "set mod:leafInt16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200520 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100521 SECTION("set mod:leafUint32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200522 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100523 input = "set mod:leafUint32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200524 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100525 SECTION("set mod:leafInt32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200526 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100527 input = "set mod:leafInt32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200528 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100529 SECTION("set mod:leafUint64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200530 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100531 input = "set mod:leafUint64 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200532 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100533 SECTION("set mod:leafInt64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200534 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100535 input = "set mod:leafInt64 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200536 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100537 SECTION("set mod:leafEnum 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200538 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100539 input = "set mod:leafEnum 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200540 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100541 SECTION("set mod:refToInt8 'blabla'")
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200542 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100543 input = "set mod:refToInt8 'blabla'";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200544 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200545 }
546
Václav Kubernátab538992019-03-06 15:30:50 +0100547 SECTION("wrong base64 strings")
548 {
549 SECTION("invalid character")
Václav Kubernát777704d2020-01-15 18:48:06 +0100550 input = "set mod:leafBinary dbahj-";
Václav Kubernátab538992019-03-06 15:30:50 +0100551 SECTION("equal sign in the middle")
Václav Kubernát777704d2020-01-15 18:48:06 +0100552 input = "set mod:leafBinary db=ahj";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100553 SECTION("enclosing in quotes")
554 input = "set mod:leafBinary 'dbahj'";
Václav Kubernátab538992019-03-06 15:30:50 +0100555 }
556
Václav Kubernáteeb38842019-03-20 19:46:05 +0100557 SECTION("non-existing identity")
558 {
559 input = "set mod:foodIdentRef identityBLABLA";
560 }
561
562 SECTION("setting identities with wrong bases")
563 {
564 SECTION("set mod:foodIdentRef mod:vehicle")
565 {
566 input = "set mod:foodIdentRef mod:vehicle";
567 }
568 SECTION("set mod:pizzaIdentRef mod:food")
569 {
570 input = "set mod:pizzaIdentRef mod:food";
571 }
572 }
573 SECTION("setting different module identities without prefix")
574 {
575 input = "set mod:pizzaIdentRef hawaii";
576 }
577 SECTION("identity prefix without name")
578 {
579 input = "set mod:contA/identInCont pizza-module:";
580 }
581
Václav Kubernát2984f442020-02-20 17:43:35 +0100582 SECTION("set a union path to a wrong type")
583 {
584 input = "set mod:intOrString true";
585 }
586
Jan Kundrátc381e632019-03-14 13:39:11 +0100587 REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
Václav Kubernát777704d2020-01-15 18:48:06 +0100588 REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
Václav Kubernát07204242018-06-04 18:12:09 +0200589 }
590}