blob: 61704f60be43bf9c6cf69d2bf1d0778b128a20b5 [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
Jan Kundráta33cf082019-03-28 11:55:57 +01009#include "trompeloeil_doctest.h"
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át07204242018-06-04 18:12:09 +020012#include "parser.hpp"
Václav Kubernátbddbb172018-06-13 16:27:39 +020013#include "static_schema.hpp"
Václav Kubernát509ce652019-05-29 19:46:44 +020014#include "utils.hpp"
Václav Kubernát07204242018-06-04 18:12:09 +020015
Jan Kundrát76b3ddc2019-07-03 10:31:27 +020016std::ostream& operator<<(std::ostream& s, const set_ cmd)
17{
Václav Kubernátefcac932020-01-10 15:26:32 +010018 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 +020019}
20
Václav Kubernát07204242018-06-04 18:12:09 +020021TEST_CASE("leaf editing")
22{
Václav Kubernátbddbb172018-06-13 16:27:39 +020023 auto schema = std::make_shared<StaticSchema>();
Václav Kubernát744f57f2018-06-29 22:46:26 +020024 schema->addModule("mod");
Václav Kubernáteeb38842019-03-20 19:46:05 +010025 schema->addModule("pizza-module");
Václav Kubernátefcac932020-01-10 15:26:32 +010026 schema->addContainer("/", "mod:contA");
27 schema->addLeaf("/", "mod:leafString", yang::LeafDataTypes::String);
28 schema->addLeaf("/", "mod:leafDecimal", yang::LeafDataTypes::Decimal);
29 schema->addLeaf("/", "mod:leafBool", yang::LeafDataTypes::Bool);
30 schema->addLeaf("/", "mod:leafInt8", yang::LeafDataTypes::Int8);
31 schema->addLeaf("/", "mod:leafInt16", yang::LeafDataTypes::Int16);
32 schema->addLeaf("/", "mod:leafInt32", yang::LeafDataTypes::Int32);
33 schema->addLeaf("/", "mod:leafInt64", yang::LeafDataTypes::Int64);
34 schema->addLeaf("/", "mod:leafUint8", yang::LeafDataTypes::Uint8);
35 schema->addLeaf("/", "mod:leafUint16", yang::LeafDataTypes::Uint16);
36 schema->addLeaf("/", "mod:leafUint32", yang::LeafDataTypes::Uint32);
37 schema->addLeaf("/", "mod:leafUint64", yang::LeafDataTypes::Uint64);
38 schema->addLeaf("/", "mod:leafBinary", yang::LeafDataTypes::Binary);
Václav Kubernáteeb38842019-03-20 19:46:05 +010039 schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "food"});
40 schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "vehicle"});
41 schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "pizza"});
42 schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "spaghetti"});
43 schema->addIdentity(ModuleValuePair{"mod", "pizza"}, ModuleValuePair{"pizza-module", "hawaii"});
Václav Kubernátefcac932020-01-10 15:26:32 +010044 schema->addLeafIdentityRef("/", "mod:foodIdentRef", ModuleValuePair{"mod", "food"});
45 schema->addLeafIdentityRef("/", "mod:pizzaIdentRef", ModuleValuePair{"mod", "pizza"});
46 schema->addLeafIdentityRef("/mod:contA", "mod:identInCont", ModuleValuePair{"mod", "pizza"});
47 schema->addLeafEnum("/", "mod:leafEnum", {"lol", "data", "coze"});
48 schema->addLeaf("/mod:contA", "mod:leafInCont", yang::LeafDataTypes::String);
49 schema->addList("/", "mod:list", {"number"});
Václav Kubernát7707cae2020-01-16 12:04:53 +010050 schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32);
Václav Kubernátefcac932020-01-10 15:26:32 +010051 schema->addLeaf("/mod:list", "mod:leafInList", yang::LeafDataTypes::String);
52 schema->addLeafRef("/", "mod:refToString", "/mod:leafString");
53 schema->addLeafRef("/", "mod:refToInt8", "/mod:leafInt8");
Václav Kubernát07204242018-06-04 18:12:09 +020054 Parser parser(schema);
55 std::string input;
56 std::ostringstream errorStream;
57
58 SECTION("valid input")
59 {
60 set_ expected;
61
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010062 SECTION("set mod:leafString \"some_data\"")
Václav Kubernát07204242018-06-04 18:12:09 +020063 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010064 input = "set mod:leafString \'some_data\'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020065 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +020066 expected.m_data = std::string("some_data");
Václav Kubernát07204242018-06-04 18:12:09 +020067 }
68
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010069 SECTION("set mod:contA/leafInCont 'more_data'")
Václav Kubernát07204242018-06-04 18:12:09 +020070 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010071 input = "set mod:contA/leafInCont 'more_data'";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020072 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
73 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
Václav Kubernátebca2552018-06-08 19:06:02 +020074 expected.m_data = std::string("more_data");
75 }
76
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010077 SECTION("set mod:contA/leafInCont \"data with' a quote\"")
Václav Kubernátc18ffac2020-01-10 16:06:06 +010078 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010079 input = "set mod:contA/leafInCont \"data with' a quote\"";
80 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
81 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
82 expected.m_data = std::string("data with' a quote");
83 }
84
85 SECTION("set mod:contA/leafInCont 'data with\" a quote'")
86 {
87 input = "set mod:contA/leafInCont 'data with\" a quote'";
88 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
89 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
90 expected.m_data = std::string("data with\" a quote");
91 }
92
93 SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string
94 {
95 input = "set mod:contA/leafInCont 'more d\tata'";
Václav Kubernátc18ffac2020-01-10 16:06:06 +010096 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
97 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
98 expected.m_data = std::string("more d\tata");
99 }
100
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100101 SECTION("set mod:list[number=1]/leafInList \"another_data\"")
Václav Kubernátebca2552018-06-08 19:06:02 +0200102 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100103 input = "set mod:list[number=1]/leafInList \"another_data\"";
Václav Kubernát7707cae2020-01-16 12:04:53 +0100104 auto keys = std::map<std::string, leaf_data_>{
105 {"number", int32_t{1}}};
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200106 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
107 expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200108 expected.m_data = std::string("another_data");
109 }
110
111 SECTION("data types")
112 {
113 SECTION("string")
114 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100115 input = "set mod:leafString \"somedata\"";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200116 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200117 expected.m_data = std::string("somedata");
118 }
119
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200120 SECTION("int8")
Václav Kubernátebca2552018-06-08 19:06:02 +0200121 {
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200122 input = "set mod:leafInt8 2";
123 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
124 expected.m_data = int8_t{2};
125 }
126
127 SECTION("negative int8")
128 {
129 input = "set mod:leafInt8 -10";
130 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")});
131 expected.m_data = int8_t{-10};
132 }
133
134 SECTION("uint8")
135 {
136 input = "set mod:leafUint8 2";
137 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")});
138 expected.m_data = uint8_t{2};
139 }
140
141 SECTION("int16")
142 {
143 input = "set mod:leafInt16 30000";
144 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")});
145 expected.m_data = int16_t{30'000};
146 }
147
148 SECTION("uint16")
149 {
150 input = "set mod:leafUint16 30000";
151 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")});
152 expected.m_data = uint16_t{30'000};
153 }
154
155 SECTION("int32")
156 {
157 input = "set mod:leafInt32 30000";
158 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
159 expected.m_data = int32_t{30'000};
160 }
161
162 SECTION("uint32")
163 {
164 input = "set mod:leafUint32 30000";
165 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")});
166 expected.m_data = uint32_t{30'000};
167 }
168
169 SECTION("int32")
170 {
171 input = "set mod:leafInt32 30000";
172 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")});
173 expected.m_data = int32_t{30'000};
174 }
175
176 SECTION("uint64")
177 {
178 input = "set mod:leafUint64 30000";
179 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")});
180 expected.m_data = uint64_t{30'000};
Václav Kubernátebca2552018-06-08 19:06:02 +0200181 }
182
183 SECTION("decimal")
184 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200185 input = "set mod:leafDecimal 3.14159";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200186 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200187 expected.m_data = 3.14159;
188 }
189
190 SECTION("enum")
191 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200192 input = "set mod:leafEnum coze";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200193 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200194 expected.m_data = enum_("coze");
195 }
196
197 SECTION("bool")
198 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200199 input = "set mod:leafBool true";
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200200 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")});
Václav Kubernátebca2552018-06-08 19:06:02 +0200201 expected.m_data = true;
202 }
Václav Kubernátab538992019-03-06 15:30:50 +0100203
204 SECTION("binary")
205 {
206 SECTION("zero ending '='")
207 {
208 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++";
209 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"};
210 }
211
212 SECTION("one ending '='")
213 {
214 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=";
215 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="};
216 }
217
218 SECTION("two ending '='")
219 {
220 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++==";
221 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="};
222 }
223 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")});
224 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100225
226 SECTION("identityRef")
227 {
228 SECTION("foodIdentRef")
229 {
230 input = "set mod:foodIdentRef ";
231 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")});
232
233 SECTION("food")
234 {
235 input += "food";
236 expected.m_data = identityRef_("food");
237 }
238 SECTION("mod:food")
239 {
240 input += "mod:food";
241 expected.m_data = identityRef_("mod", "food");
242 }
243 SECTION("pizza")
244 {
245 input += "pizza";
246 expected.m_data = identityRef_("pizza");
247 }
248 SECTION("mod:pizza")
249 {
250 input += "mod:pizza";
251 expected.m_data = identityRef_("mod", "pizza");
252 }
253 SECTION("pizza-module:hawaii")
254 {
255 input += "pizza-module:hawaii";
256 expected.m_data = identityRef_("pizza-module", "hawaii");
257 }
258 }
259 SECTION("pizzaIdentRef")
260 {
261 input = "set mod:pizzaIdentRef ";
262 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")});
263 SECTION("pizza")
264 {
265 input += "pizza";
266 expected.m_data = identityRef_("pizza");
267 }
268 SECTION("mod:pizza")
269 {
270 input += "mod:pizza";
271 expected.m_data = identityRef_("mod", "pizza");
272 }
273 SECTION("pizza-module:hawaii")
274 {
275 input += "pizza-module:hawaii";
276 expected.m_data = identityRef_("pizza-module", "hawaii");
277 }
278 }
279 SECTION("mod:contA/identInCont")
280 {
281 input = "set mod:contA/identInCont ";
282 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
283 expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont")));
284 SECTION("pizza")
285 {
286 input += "pizza";
287 expected.m_data = identityRef_("pizza");
288 }
289 SECTION("mod:pizza")
290 {
291 input += "mod:pizza";
292 expected.m_data = identityRef_("mod", "pizza");
293 }
294 SECTION("pizza-module:hawaii")
295 {
296 input += "pizza-module:hawaii";
297 expected.m_data = identityRef_("pizza-module", "hawaii");
298 }
299 }
300 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200301 SECTION("leafRef")
302 {
303 SECTION("refToString")
304 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100305 input = "set mod:refToString \"blabal\"";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200306 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")});
307 expected.m_data = std::string("blabal");
308 }
309
310 SECTION("refToInt8")
311 {
312 input = "set mod:refToInt8 42";
313 expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")});
314 expected.m_data = int8_t{42};
315 }
316 }
Václav Kubernát07204242018-06-04 18:12:09 +0200317 }
318
319 command_ command = parser.parseCommand(input, errorStream);
320 REQUIRE(command.type() == typeid(set_));
321 REQUIRE(boost::get<set_>(command) == expected);
322 }
323
324 SECTION("invalid input")
325 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100326 std::string expectedError;
Václav Kubernát07204242018-06-04 18:12:09 +0200327 SECTION("missing space between a command and its arguments")
328 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100329 SECTION("setmod:leafString some_data")
Václav Kubernát07204242018-06-04 18:12:09 +0200330 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100331 input = "setmod:leafString 'some_data'";
Václav Kubernát07204242018-06-04 18:12:09 +0200332 }
333 }
334
335 SECTION("missing space between arguments")
336 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100337 SECTION("set mod:leafString'lol'")
Václav Kubernát07204242018-06-04 18:12:09 +0200338 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100339 input = "set mod:leafString'lol'";
Václav Kubernát07204242018-06-04 18:12:09 +0200340 }
341 }
342
343 SECTION("non-leaf identifiers")
344 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100345 SECTION("set mod:nonexistent 'blabla'")
Václav Kubernát07204242018-06-04 18:12:09 +0200346 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100347 input = "set mod:nonexistent 'blabla'";
Václav Kubernát07204242018-06-04 18:12:09 +0200348 }
349
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100350 SECTION("set mod:contA 'abde'")
Václav Kubernát07204242018-06-04 18:12:09 +0200351 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100352 input = "set mod:contA 'abde'";
Václav Kubernát07204242018-06-04 18:12:09 +0200353 }
354 }
355
Václav Kubernátebca2552018-06-08 19:06:02 +0200356 SECTION("wrong types")
357 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100358 expectedError = "leaf data type mismatch";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100359 SECTION("set mod:leafBool 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200360 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100361 input = "set mod:leafBool 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200362 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100363 SECTION("set mod:leafUint8 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200364 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100365 input = "set mod:leafUint8 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200366 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100367 SECTION("set mod:leafUint8 -5")
Václav Kubernátebca2552018-06-08 19:06:02 +0200368 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100369 input = "set mod:leafUint8 -5";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200370 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100371 SECTION("set mod:leafInt8 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200372 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100373 input = "set mod:leafInt8 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200374 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100375 SECTION("set mod:leafInt8 130")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200376 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100377 input = "set mod:leafInt8 130";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200378 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100379 SECTION("set mod:leafUint16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200380 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100381 input = "set mod:leafUint16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200382 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100383 SECTION("set mod:leafInt16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200384 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100385 input = "set mod:leafInt16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200386 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100387 SECTION("set mod:leafUint32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200388 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100389 input = "set mod:leafUint32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200390 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100391 SECTION("set mod:leafInt32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200392 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100393 input = "set mod:leafInt32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200394 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100395 SECTION("set mod:leafUint64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200396 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100397 input = "set mod:leafUint64 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200398 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100399 SECTION("set mod:leafInt64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200400 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100401 input = "set mod:leafInt64 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200402 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100403 SECTION("set mod:leafEnum 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200404 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100405 input = "set mod:leafEnum 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200406 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100407 SECTION("set mod:refToInt8 'blabla'")
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200408 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100409 input = "set mod:refToInt8 'blabla'";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200410 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200411 }
412
Václav Kubernátab538992019-03-06 15:30:50 +0100413 SECTION("wrong base64 strings")
414 {
415 SECTION("invalid character")
Václav Kubernát777704d2020-01-15 18:48:06 +0100416 input = "set mod:leafBinary dbahj-";
Václav Kubernátab538992019-03-06 15:30:50 +0100417 SECTION("equal sign in the middle")
Václav Kubernát777704d2020-01-15 18:48:06 +0100418 input = "set mod:leafBinary db=ahj";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100419 SECTION("enclosing in quotes")
420 input = "set mod:leafBinary 'dbahj'";
Václav Kubernátab538992019-03-06 15:30:50 +0100421 }
422
Václav Kubernáteeb38842019-03-20 19:46:05 +0100423 SECTION("non-existing identity")
424 {
425 input = "set mod:foodIdentRef identityBLABLA";
426 }
427
428 SECTION("setting identities with wrong bases")
429 {
430 SECTION("set mod:foodIdentRef mod:vehicle")
431 {
432 input = "set mod:foodIdentRef mod:vehicle";
433 }
434 SECTION("set mod:pizzaIdentRef mod:food")
435 {
436 input = "set mod:pizzaIdentRef mod:food";
437 }
438 }
439 SECTION("setting different module identities without prefix")
440 {
441 input = "set mod:pizzaIdentRef hawaii";
442 }
443 SECTION("identity prefix without name")
444 {
445 input = "set mod:contA/identInCont pizza-module:";
446 }
447
Jan Kundrátc381e632019-03-14 13:39:11 +0100448 REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
Václav Kubernát777704d2020-01-15 18:48:06 +0100449 REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
Václav Kubernát07204242018-06-04 18:12:09 +0200450 }
451}