Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 1 | /* |
| 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át | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.hpp" |
Jan Kundrát | 76b3ddc | 2019-07-03 10:31:27 +0200 | [diff] [blame] | 10 | #include <boost/core/demangle.hpp> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 11 | #include "ast_commands.hpp" |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 12 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 13 | #include "parser.hpp" |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 14 | #include "static_schema.hpp" |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 15 | #include "utils.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 16 | |
Jan Kundrát | 76b3ddc | 2019-07-03 10:31:27 +0200 | [diff] [blame] | 17 | std::ostream& operator<<(std::ostream& s, const set_ cmd) |
| 18 | { |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 19 | 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át | 76b3ddc | 2019-07-03 10:31:27 +0200 | [diff] [blame] | 20 | } |
| 21 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 22 | TEST_CASE("leaf editing") |
| 23 | { |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 24 | auto schema = std::make_shared<StaticSchema>(); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 25 | schema->addModule("mod"); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 26 | schema->addModule("pizza-module"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 27 | schema->addContainer("/", "mod:contA"); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 28 | 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át | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 40 | 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át | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 45 | 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át | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 50 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 51 | 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át | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame] | 55 | schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:contA/mod:identInCont"))}); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame^] | 56 | schema->addLeaf("/", "mod:intOrString", yang::Union{{yang::Int32{}, yang::String{}}}); |
| 57 | schema->addLeaf("/", "mod:twoInts", yang::Union{{yang::Uint8{}, yang::Int16{}}}); |
| 58 | schema->addLeaf("/", "mod:unionStringEnumLeafref", yang::Union{{ |
| 59 | yang::String{}, |
| 60 | createEnum({"foo", "bar"}), |
| 61 | yang::LeafRef{"/mod:leafEnum", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafEnum"))} |
| 62 | }}); |
| 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"})); |
| 68 | schema->addLeaf("/", "mod:activeMappedPort", yang::LeafRef{"/mod:portMapping/mod:port", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:portMapping/mod:port"))}); |
| 69 | schema->addLeaf("/", "mod:activePort", yang::Union{{ |
| 70 | createEnum({"wlan0", "wlan1"}), |
| 71 | yang::LeafRef{"/mod:portSettings/mod:port", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:portSettings/mod:port"))}, |
| 72 | yang::LeafRef{"/mod:activeMappedPort", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:activeMappedPort"))}, |
| 73 | }}); |
| 74 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 75 | Parser parser(schema); |
| 76 | std::string input; |
| 77 | std::ostringstream errorStream; |
| 78 | |
| 79 | SECTION("valid input") |
| 80 | { |
| 81 | set_ expected; |
| 82 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 83 | SECTION("set mod:leafString \"some_data\"") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 84 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 85 | input = "set mod:leafString \'some_data\'"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 86 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 87 | expected.m_data = std::string("some_data"); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 90 | SECTION("set mod:contA/leafInCont 'more_data'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 91 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 92 | input = "set mod:contA/leafInCont 'more_data'"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 93 | 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át | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 95 | expected.m_data = std::string("more_data"); |
| 96 | } |
| 97 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 98 | SECTION("set mod:contA/leafInCont \"data with' a quote\"") |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 99 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 100 | 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át | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 117 | 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át | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 122 | SECTION("set mod:list[number=1]/leafInList \"another_data\"") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 123 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 124 | input = "set mod:list[number=1]/leafInList \"another_data\""; |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 125 | auto keys = std::map<std::string, leaf_data_>{ |
| 126 | {"number", int32_t{1}}}; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 127 | 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át | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 129 | expected.m_data = std::string("another_data"); |
| 130 | } |
| 131 | |
| 132 | SECTION("data types") |
| 133 | { |
| 134 | SECTION("string") |
| 135 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 136 | input = "set mod:leafString \"somedata\""; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 137 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 138 | expected.m_data = std::string("somedata"); |
| 139 | } |
| 140 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 141 | SECTION("int8") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 142 | { |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 143 | 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át | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | SECTION("decimal") |
| 205 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 206 | input = "set mod:leafDecimal 3.14159"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 207 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 208 | expected.m_data = 3.14159; |
| 209 | } |
| 210 | |
| 211 | SECTION("enum") |
| 212 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 213 | input = "set mod:leafEnum coze"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 214 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 215 | expected.m_data = enum_("coze"); |
| 216 | } |
| 217 | |
| 218 | SECTION("bool") |
| 219 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 220 | input = "set mod:leafBool true"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 221 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 222 | expected.m_data = true; |
| 223 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 224 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame^] | 225 | 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át | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 331 | 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át | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 352 | |
| 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át | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 428 | SECTION("leafRef") |
| 429 | { |
| 430 | SECTION("refToString") |
| 431 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 432 | input = "set mod:refToString \"blabal\""; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 433 | 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át | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame] | 443 | |
| 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át | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 450 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 451 | } |
| 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át | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 460 | std::string expectedError; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 461 | SECTION("missing space between a command and its arguments") |
| 462 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 463 | SECTION("setmod:leafString some_data") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 464 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 465 | input = "setmod:leafString 'some_data'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | SECTION("missing space between arguments") |
| 470 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 471 | SECTION("set mod:leafString'lol'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 472 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 473 | input = "set mod:leafString'lol'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | SECTION("non-leaf identifiers") |
| 478 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 479 | SECTION("set mod:nonexistent 'blabla'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 480 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 481 | input = "set mod:nonexistent 'blabla'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 482 | } |
| 483 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 484 | SECTION("set mod:contA 'abde'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 485 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 486 | input = "set mod:contA 'abde'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 490 | SECTION("wrong types") |
| 491 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 492 | expectedError = "leaf data type mismatch"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 493 | SECTION("set mod:leafBool 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 494 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 495 | input = "set mod:leafBool 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 496 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 497 | SECTION("set mod:leafUint8 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 498 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 499 | input = "set mod:leafUint8 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 500 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 501 | SECTION("set mod:leafUint8 -5") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 502 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 503 | input = "set mod:leafUint8 -5"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 504 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 505 | SECTION("set mod:leafInt8 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 506 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 507 | input = "set mod:leafInt8 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 508 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 509 | SECTION("set mod:leafInt8 130") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 510 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 511 | input = "set mod:leafInt8 130"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 512 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 513 | SECTION("set mod:leafUint16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 514 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 515 | input = "set mod:leafUint16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 516 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 517 | SECTION("set mod:leafInt16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 518 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 519 | input = "set mod:leafInt16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 520 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 521 | SECTION("set mod:leafUint32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 522 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 523 | input = "set mod:leafUint32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 524 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 525 | SECTION("set mod:leafInt32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 526 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 527 | input = "set mod:leafInt32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 528 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 529 | SECTION("set mod:leafUint64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 530 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 531 | input = "set mod:leafUint64 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 532 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 533 | SECTION("set mod:leafInt64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 534 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 535 | input = "set mod:leafInt64 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 536 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 537 | SECTION("set mod:leafEnum 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 538 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 539 | input = "set mod:leafEnum 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 540 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 541 | SECTION("set mod:refToInt8 'blabla'") |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 542 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 543 | input = "set mod:refToInt8 'blabla'"; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 544 | } |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 545 | } |
| 546 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 547 | SECTION("wrong base64 strings") |
| 548 | { |
| 549 | SECTION("invalid character") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 550 | input = "set mod:leafBinary dbahj-"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 551 | SECTION("equal sign in the middle") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 552 | input = "set mod:leafBinary db=ahj"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 553 | SECTION("enclosing in quotes") |
| 554 | input = "set mod:leafBinary 'dbahj'"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 555 | } |
| 556 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 557 | 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át | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame^] | 582 | SECTION("set a union path to a wrong type") |
| 583 | { |
| 584 | input = "set mod:intOrString true"; |
| 585 | } |
| 586 | |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 587 | REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException); |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 588 | REQUIRE(errorStream.str().find(expectedError) != std::string::npos); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 589 | } |
| 590 | } |