blob: 9ce5c35e2bbc82d3b11489b0efd9c01fbf5a2e2f [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{});
53 schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafString"))});
54 schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafInt8"))});
Václav Kubernát2d7b05c2020-04-05 14:02:37 +020055 schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:contA/mod:identInCont"))});
Václav Kubernát07204242018-06-04 18:12:09 +020056 Parser parser(schema);
57 std::string input;
58 std::ostringstream errorStream;
59
60 SECTION("valid input")
61 {
62 set_ expected;
63
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010064 SECTION("set mod:leafString \"some_data\"")
Václav Kubernát07204242018-06-04 18:12:09 +020065 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010066 input = "set mod:leafString \'some_data\'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020067 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +020068 expected.m_data = std::string("some_data");
Václav Kubernát07204242018-06-04 18:12:09 +020069 }
70
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010071 SECTION("set mod:contA/leafInCont 'more_data'")
Václav Kubernát07204242018-06-04 18:12:09 +020072 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010073 input = "set mod:contA/leafInCont 'more_data'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020074 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
75 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
Václav Kubernátebca2552018-06-08 19:06:02 +020076 expected.m_data = std::string("more_data");
77 }
78
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010079 SECTION("set mod:contA/leafInCont \"data with' a quote\"")
Václav Kubernátc18ffac2020-01-10 16:06:06 +010080 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010081 input = "set mod:contA/leafInCont \"data with' a quote\"";
82 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
83 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
84 expected.m_data = std::string("data with' a quote");
85 }
86
87 SECTION("set mod:contA/leafInCont 'data with\" a quote'")
88 {
89 input = "set mod:contA/leafInCont 'data with\" a quote'";
90 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
91 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
92 expected.m_data = std::string("data with\" a quote");
93 }
94
95 SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string
96 {
97 input = "set mod:contA/leafInCont 'more d\tata'";
Václav Kubernátc18ffac2020-01-10 16:06:06 +010098 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
99 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
100 expected.m_data = std::string("more d\tata");
101 }
102
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100103 SECTION("set mod:list[number=1]/leafInList \"another_data\"")
Václav Kubernátebca2552018-06-08 19:06:02 +0200104 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100105 input = "set mod:list[number=1]/leafInList \"another_data\"";
Václav Kubernát7707cae2020-01-16 12:04:53 +0100106 auto keys = std::map<std::string, leaf_data_>{
107 {"number", int32_t{1}}};
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200108 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
109 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200110 expected.m_data = std::string("another_data");
111 }
112
113 SECTION("data types")
114 {
115 SECTION("string")
116 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100117 input = "set mod:leafString \"somedata\"";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200118 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200119 expected.m_data = std::string("somedata");
120 }
121
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200122 SECTION("int8")
Václav Kubernátebca2552018-06-08 19:06:02 +0200123 {
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200124 input = "set mod:leafInt8 2";
125 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
126 expected.m_data = int8_t{2};
127 }
128
129 SECTION("negative int8")
130 {
131 input = "set mod:leafInt8 -10";
132 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
133 expected.m_data = int8_t{-10};
134 }
135
136 SECTION("uint8")
137 {
138 input = "set mod:leafUint8 2";
139 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")});
140 expected.m_data = uint8_t{2};
141 }
142
143 SECTION("int16")
144 {
145 input = "set mod:leafInt16 30000";
146 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")});
147 expected.m_data = int16_t{30'000};
148 }
149
150 SECTION("uint16")
151 {
152 input = "set mod:leafUint16 30000";
153 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")});
154 expected.m_data = uint16_t{30'000};
155 }
156
157 SECTION("int32")
158 {
159 input = "set mod:leafInt32 30000";
160 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
161 expected.m_data = int32_t{30'000};
162 }
163
164 SECTION("uint32")
165 {
166 input = "set mod:leafUint32 30000";
167 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")});
168 expected.m_data = uint32_t{30'000};
169 }
170
171 SECTION("int32")
172 {
173 input = "set mod:leafInt32 30000";
174 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
175 expected.m_data = int32_t{30'000};
176 }
177
178 SECTION("uint64")
179 {
180 input = "set mod:leafUint64 30000";
181 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")});
182 expected.m_data = uint64_t{30'000};
Václav Kubernátebca2552018-06-08 19:06:02 +0200183 }
184
185 SECTION("decimal")
186 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200187 input = "set mod:leafDecimal 3.14159";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200188 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200189 expected.m_data = 3.14159;
190 }
191
192 SECTION("enum")
193 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200194 input = "set mod:leafEnum coze";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200195 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200196 expected.m_data = enum_("coze");
197 }
198
199 SECTION("bool")
200 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200201 input = "set mod:leafBool true";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200202 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200203 expected.m_data = true;
204 }
Václav Kubernátab538992019-03-06 15:30:50 +0100205
206 SECTION("binary")
207 {
208 SECTION("zero ending '='")
209 {
210 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++";
211 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"};
212 }
213
214 SECTION("one ending '='")
215 {
216 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=";
217 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="};
218 }
219
220 SECTION("two ending '='")
221 {
222 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++==";
223 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="};
224 }
225 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")});
226 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100227
228 SECTION("identityRef")
229 {
230 SECTION("foodIdentRef")
231 {
232 input = "set mod:foodIdentRef ";
233 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")});
234
235 SECTION("food")
236 {
237 input += "food";
238 expected.m_data = identityRef_("food");
239 }
240 SECTION("mod:food")
241 {
242 input += "mod:food";
243 expected.m_data = identityRef_("mod", "food");
244 }
245 SECTION("pizza")
246 {
247 input += "pizza";
248 expected.m_data = identityRef_("pizza");
249 }
250 SECTION("mod:pizza")
251 {
252 input += "mod:pizza";
253 expected.m_data = identityRef_("mod", "pizza");
254 }
255 SECTION("pizza-module:hawaii")
256 {
257 input += "pizza-module:hawaii";
258 expected.m_data = identityRef_("pizza-module", "hawaii");
259 }
260 }
261 SECTION("pizzaIdentRef")
262 {
263 input = "set mod:pizzaIdentRef ";
264 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")});
265 SECTION("pizza")
266 {
267 input += "pizza";
268 expected.m_data = identityRef_("pizza");
269 }
270 SECTION("mod:pizza")
271 {
272 input += "mod:pizza";
273 expected.m_data = identityRef_("mod", "pizza");
274 }
275 SECTION("pizza-module:hawaii")
276 {
277 input += "pizza-module:hawaii";
278 expected.m_data = identityRef_("pizza-module", "hawaii");
279 }
280 }
281 SECTION("mod:contA/identInCont")
282 {
283 input = "set mod:contA/identInCont ";
284 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
285 expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont")));
286 SECTION("pizza")
287 {
288 input += "pizza";
289 expected.m_data = identityRef_("pizza");
290 }
291 SECTION("mod:pizza")
292 {
293 input += "mod:pizza";
294 expected.m_data = identityRef_("mod", "pizza");
295 }
296 SECTION("pizza-module:hawaii")
297 {
298 input += "pizza-module:hawaii";
299 expected.m_data = identityRef_("pizza-module", "hawaii");
300 }
301 }
302 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200303 SECTION("leafRef")
304 {
305 SECTION("refToString")
306 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100307 input = "set mod:refToString \"blabal\"";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200308 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")});
309 expected.m_data = std::string("blabal");
310 }
311
312 SECTION("refToInt8")
313 {
314 input = "set mod:refToInt8 42";
315 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")});
316 expected.m_data = int8_t{42};
317 }
Václav Kubernát2d7b05c2020-04-05 14:02:37 +0200318
319 SECTION("refToLeafInCont")
320 {
321 input = "set mod:refToLeafInCont pizza";
322 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")});
323 expected.m_data = identityRef_{"pizza"};
324 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200325 }
Václav Kubernát07204242018-06-04 18:12:09 +0200326 }
327
328 command_ command = parser.parseCommand(input, errorStream);
329 REQUIRE(command.type() == typeid(set_));
330 REQUIRE(boost::get<set_>(command) == expected);
331 }
332
333 SECTION("invalid input")
334 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100335 std::string expectedError;
Václav Kubernát07204242018-06-04 18:12:09 +0200336 SECTION("missing space between a command and its arguments")
337 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100338 SECTION("setmod:leafString some_data")
Václav Kubernát07204242018-06-04 18:12:09 +0200339 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100340 input = "setmod:leafString 'some_data'";
Václav Kubernát07204242018-06-04 18:12:09 +0200341 }
342 }
343
344 SECTION("missing space between arguments")
345 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100346 SECTION("set mod:leafString'lol'")
Václav Kubernát07204242018-06-04 18:12:09 +0200347 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100348 input = "set mod:leafString'lol'";
Václav Kubernát07204242018-06-04 18:12:09 +0200349 }
350 }
351
352 SECTION("non-leaf identifiers")
353 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100354 SECTION("set mod:nonexistent 'blabla'")
Václav Kubernát07204242018-06-04 18:12:09 +0200355 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100356 input = "set mod:nonexistent 'blabla'";
Václav Kubernát07204242018-06-04 18:12:09 +0200357 }
358
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100359 SECTION("set mod:contA 'abde'")
Václav Kubernát07204242018-06-04 18:12:09 +0200360 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100361 input = "set mod:contA 'abde'";
Václav Kubernát07204242018-06-04 18:12:09 +0200362 }
363 }
364
Václav Kubernátebca2552018-06-08 19:06:02 +0200365 SECTION("wrong types")
366 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100367 expectedError = "leaf data type mismatch";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100368 SECTION("set mod:leafBool 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200369 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100370 input = "set mod:leafBool 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200371 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100372 SECTION("set mod:leafUint8 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200373 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100374 input = "set mod:leafUint8 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200375 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100376 SECTION("set mod:leafUint8 -5")
Václav Kubernátebca2552018-06-08 19:06:02 +0200377 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100378 input = "set mod:leafUint8 -5";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200379 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100380 SECTION("set mod:leafInt8 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200381 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100382 input = "set mod:leafInt8 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200383 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100384 SECTION("set mod:leafInt8 130")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200385 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100386 input = "set mod:leafInt8 130";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200387 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100388 SECTION("set mod:leafUint16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200389 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100390 input = "set mod:leafUint16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200391 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100392 SECTION("set mod:leafInt16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200393 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100394 input = "set mod:leafInt16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200395 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100396 SECTION("set mod:leafUint32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200397 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100398 input = "set mod:leafUint32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200399 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100400 SECTION("set mod:leafInt32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200401 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100402 input = "set mod:leafInt32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200403 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100404 SECTION("set mod:leafUint64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200405 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100406 input = "set mod:leafUint64 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200407 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100408 SECTION("set mod:leafInt64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200409 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100410 input = "set mod:leafInt64 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200411 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100412 SECTION("set mod:leafEnum 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200413 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100414 input = "set mod:leafEnum 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200415 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100416 SECTION("set mod:refToInt8 'blabla'")
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200417 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100418 input = "set mod:refToInt8 'blabla'";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200419 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200420 }
421
Václav Kubernátab538992019-03-06 15:30:50 +0100422 SECTION("wrong base64 strings")
423 {
424 SECTION("invalid character")
Václav Kubernát777704d2020-01-15 18:48:06 +0100425 input = "set mod:leafBinary dbahj-";
Václav Kubernátab538992019-03-06 15:30:50 +0100426 SECTION("equal sign in the middle")
Václav Kubernát777704d2020-01-15 18:48:06 +0100427 input = "set mod:leafBinary db=ahj";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100428 SECTION("enclosing in quotes")
429 input = "set mod:leafBinary 'dbahj'";
Václav Kubernátab538992019-03-06 15:30:50 +0100430 }
431
Václav Kubernáteeb38842019-03-20 19:46:05 +0100432 SECTION("non-existing identity")
433 {
434 input = "set mod:foodIdentRef identityBLABLA";
435 }
436
437 SECTION("setting identities with wrong bases")
438 {
439 SECTION("set mod:foodIdentRef mod:vehicle")
440 {
441 input = "set mod:foodIdentRef mod:vehicle";
442 }
443 SECTION("set mod:pizzaIdentRef mod:food")
444 {
445 input = "set mod:pizzaIdentRef mod:food";
446 }
447 }
448 SECTION("setting different module identities without prefix")
449 {
450 input = "set mod:pizzaIdentRef hawaii";
451 }
452 SECTION("identity prefix without name")
453 {
454 input = "set mod:contA/identInCont pizza-module:";
455 }
456
Jan Kundrátc381e632019-03-14 13:39:11 +0100457 REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
Václav Kubernát777704d2020-01-15 18:48:06 +0100458 REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
Václav Kubernát07204242018-06-04 18:12:09 +0200459 }
460}