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 | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 14 | #include "pretty_printers.hpp" |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 15 | #include "static_schema.hpp" |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 16 | #include "utils.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 17 | |
| 18 | TEST_CASE("leaf editing") |
| 19 | { |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 20 | auto schema = std::make_shared<StaticSchema>(); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 21 | schema->addModule("mod"); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 22 | schema->addModule("pizza-module"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 23 | schema->addContainer("/", "mod:contA"); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 24 | schema->addLeaf("/", "mod:leafString", yang::String{}); |
| 25 | schema->addLeaf("/", "mod:leafDecimal", yang::Decimal{}); |
| 26 | schema->addLeaf("/", "mod:leafBool", yang::Bool{}); |
| 27 | schema->addLeaf("/", "mod:leafInt8", yang::Int8{}); |
| 28 | schema->addLeaf("/", "mod:leafInt16", yang::Int16{}); |
| 29 | schema->addLeaf("/", "mod:leafInt32", yang::Int32{}); |
| 30 | schema->addLeaf("/", "mod:leafInt64", yang::Int64{}); |
| 31 | schema->addLeaf("/", "mod:leafUint8", yang::Uint8{}); |
| 32 | schema->addLeaf("/", "mod:leafUint16", yang::Uint16{}); |
| 33 | schema->addLeaf("/", "mod:leafUint32", yang::Uint32{}); |
| 34 | schema->addLeaf("/", "mod:leafUint64", yang::Uint64{}); |
| 35 | schema->addLeaf("/", "mod:leafBinary", yang::Binary{}); |
Václav Kubernát | 222ecff | 2020-05-14 23:14:35 +0200 | [diff] [blame] | 36 | schema->addIdentity(std::nullopt, identityRef_{"mod", "food"}); |
| 37 | schema->addIdentity(std::nullopt, identityRef_{"mod", "vehicle"}); |
| 38 | schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "pizza"}); |
| 39 | schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "spaghetti"}); |
| 40 | schema->addIdentity(identityRef_{"mod", "pizza"}, identityRef_{"pizza-module", "hawaii"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 41 | schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")}); |
| 42 | schema->addLeaf("/", "mod:pizzaIdentRef", yang::IdentityRef{schema->validIdentities("mod", "pizza")}); |
| 43 | schema->addLeaf("/mod:contA", "mod:identInCont", yang::IdentityRef{schema->validIdentities("mod", "pizza")}); |
| 44 | schema->addLeaf("/", "mod:leafEnum", createEnum({"lol", "data", "coze"})); |
| 45 | schema->addLeaf("/mod:contA", "mod:leafInCont", yang::String{}); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 46 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 47 | schema->addLeaf("/mod:list", "mod:number", yang::Int32{}); |
| 48 | schema->addLeaf("/mod:list", "mod:leafInList", yang::String{}); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 49 | schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafString"))}); |
| 50 | schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafInt8"))}); |
| 51 | schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:contA/mod:identInCont"))}); |
| 52 | schema->addLeaf("/", "mod:intOrString", yang::Union{{yang::TypeInfo{yang::Int32{}}, yang::TypeInfo{yang::String{}}}}); |
| 53 | schema->addLeaf("/", "mod:twoInts", yang::Union{{yang::TypeInfo{yang::Uint8{}}, yang::TypeInfo{yang::Int16{}}}}); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 54 | schema->addLeaf("/", "mod:unionStringEnumLeafref", yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 55 | yang::LeafDataType{yang::String{}}, |
| 56 | yang::LeafDataType{createEnum({"foo", "bar"})}, |
| 57 | yang::LeafDataType{yang::LeafRef{"/mod:leafEnum", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafEnum"))}} |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 58 | }}); |
| 59 | |
| 60 | schema->addList("/", "mod:portSettings", {"port"}); |
| 61 | schema->addLeaf("/mod:portSettings", "mod:port", createEnum({"eth0", "eth1", "eth2"})); |
| 62 | schema->addList("/", "mod:portMapping", {"port"}); |
| 63 | schema->addLeaf("/mod:portMapping", "mod:port", createEnum({"utf1", "utf2", "utf3"})); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 64 | schema->addLeaf("/", "mod:activeMappedPort", yang::LeafRef{"/mod:portMapping/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portMapping/mod:port"))}); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 65 | schema->addLeaf("/", "mod:activePort", yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 66 | yang::TypeInfo{createEnum({"wlan0", "wlan1"})}, |
| 67 | yang::TypeInfo{yang::LeafRef{"/mod:portSettings/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portSettings/mod:port"))}}, |
| 68 | yang::TypeInfo{yang::LeafRef{"/mod:activeMappedPort", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:activeMappedPort"))}}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 69 | yang::TypeInfo{yang::Empty{}}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 70 | }}); |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 71 | schema->addLeaf("/", "mod:dummy", yang::Empty{}); |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 72 | schema->addLeaf("/", "mod:readonly", yang::Int32{}, yang::AccessType::ReadOnly); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 73 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 74 | Parser parser(schema); |
| 75 | std::string input; |
| 76 | std::ostringstream errorStream; |
| 77 | |
| 78 | SECTION("valid input") |
| 79 | { |
| 80 | set_ expected; |
| 81 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 82 | SECTION("set mod:leafString \"some_data\"") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 83 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 84 | input = "set mod:leafString \'some_data\'"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 85 | 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] | 86 | expected.m_data = std::string("some_data"); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 89 | SECTION("set mod:contA/leafInCont 'more_data'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 90 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 91 | input = "set mod:contA/leafInCont 'more_data'"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 92 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 93 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 94 | expected.m_data = std::string("more_data"); |
| 95 | } |
| 96 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 97 | SECTION("set mod:contA/leafInCont \"data with' a quote\"") |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 98 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 99 | input = "set mod:contA/leafInCont \"data with' a quote\""; |
| 100 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 101 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
| 102 | expected.m_data = std::string("data with' a quote"); |
| 103 | } |
| 104 | |
| 105 | SECTION("set mod:contA/leafInCont 'data with\" a quote'") |
| 106 | { |
| 107 | input = "set mod:contA/leafInCont 'data with\" a quote'"; |
| 108 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 109 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
| 110 | expected.m_data = std::string("data with\" a quote"); |
| 111 | } |
| 112 | |
| 113 | SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string |
| 114 | { |
| 115 | input = "set mod:contA/leafInCont 'more d\tata'"; |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 116 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 117 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
| 118 | expected.m_data = std::string("more d\tata"); |
| 119 | } |
| 120 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 121 | SECTION("set mod:list[number=1]/leafInList \"another_data\"") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 122 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 123 | input = "set mod:list[number=1]/leafInList \"another_data\""; |
Václav Kubernát | c15fe82 | 2020-06-04 11:28:39 +0200 | [diff] [blame] | 124 | auto keys = ListInstance { |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 125 | {"number", int32_t{1}}}; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 126 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)}); |
| 127 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 128 | expected.m_data = std::string("another_data"); |
| 129 | } |
| 130 | |
| 131 | SECTION("data types") |
| 132 | { |
| 133 | SECTION("string") |
| 134 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 135 | input = "set mod:leafString \"somedata\""; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 136 | 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] | 137 | expected.m_data = std::string("somedata"); |
| 138 | } |
| 139 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 140 | SECTION("int8") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 141 | { |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 142 | input = "set mod:leafInt8 2"; |
| 143 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")}); |
| 144 | expected.m_data = int8_t{2}; |
| 145 | } |
| 146 | |
| 147 | SECTION("negative int8") |
| 148 | { |
| 149 | input = "set mod:leafInt8 -10"; |
| 150 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")}); |
| 151 | expected.m_data = int8_t{-10}; |
| 152 | } |
| 153 | |
| 154 | SECTION("uint8") |
| 155 | { |
| 156 | input = "set mod:leafUint8 2"; |
| 157 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")}); |
| 158 | expected.m_data = uint8_t{2}; |
| 159 | } |
| 160 | |
| 161 | SECTION("int16") |
| 162 | { |
| 163 | input = "set mod:leafInt16 30000"; |
| 164 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")}); |
| 165 | expected.m_data = int16_t{30'000}; |
| 166 | } |
| 167 | |
| 168 | SECTION("uint16") |
| 169 | { |
| 170 | input = "set mod:leafUint16 30000"; |
| 171 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")}); |
| 172 | expected.m_data = uint16_t{30'000}; |
| 173 | } |
| 174 | |
| 175 | SECTION("int32") |
| 176 | { |
| 177 | input = "set mod:leafInt32 30000"; |
| 178 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")}); |
| 179 | expected.m_data = int32_t{30'000}; |
| 180 | } |
| 181 | |
| 182 | SECTION("uint32") |
| 183 | { |
| 184 | input = "set mod:leafUint32 30000"; |
| 185 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")}); |
| 186 | expected.m_data = uint32_t{30'000}; |
| 187 | } |
| 188 | |
| 189 | SECTION("int32") |
| 190 | { |
| 191 | input = "set mod:leafInt32 30000"; |
| 192 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")}); |
| 193 | expected.m_data = int32_t{30'000}; |
| 194 | } |
| 195 | |
| 196 | SECTION("uint64") |
| 197 | { |
| 198 | input = "set mod:leafUint64 30000"; |
| 199 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")}); |
| 200 | expected.m_data = uint64_t{30'000}; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | SECTION("decimal") |
| 204 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 205 | input = "set mod:leafDecimal 3.14159"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 206 | 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] | 207 | expected.m_data = 3.14159; |
| 208 | } |
| 209 | |
| 210 | SECTION("enum") |
| 211 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 212 | input = "set mod:leafEnum coze"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 213 | 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] | 214 | expected.m_data = enum_("coze"); |
| 215 | } |
| 216 | |
| 217 | SECTION("bool") |
| 218 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 219 | input = "set mod:leafBool true"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 220 | 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] | 221 | expected.m_data = true; |
| 222 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 223 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 224 | SECTION("union") |
| 225 | { |
| 226 | SECTION("int") |
| 227 | { |
| 228 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")}); |
| 229 | input = "set mod:intOrString 90"; |
| 230 | expected.m_data = int32_t{90}; |
| 231 | } |
| 232 | SECTION("string") |
| 233 | { |
| 234 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("intOrString")}); |
| 235 | input = "set mod:intOrString \"test\""; |
| 236 | expected.m_data = std::string{"test"}; |
| 237 | } |
| 238 | |
| 239 | SECTION("union with two integral types") |
| 240 | { |
| 241 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("twoInts")}); |
| 242 | SECTION("uint8") |
| 243 | { |
| 244 | input = "set mod:twoInts 100"; |
| 245 | expected.m_data = uint8_t{100}; |
| 246 | } |
| 247 | SECTION("int16") |
| 248 | { |
| 249 | input = "set mod:twoInts 6666"; |
| 250 | expected.m_data = int16_t{6666}; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | SECTION("union with enum and leafref to enum") |
| 255 | { |
| 256 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("unionStringEnumLeafref")}); |
| 257 | SECTION("string") |
| 258 | { |
| 259 | input = "set mod:unionStringEnumLeafref \"AHOJ\""; |
| 260 | expected.m_data = std::string{"AHOJ"}; |
| 261 | } |
| 262 | SECTION("enum") |
| 263 | { |
| 264 | input = "set mod:unionStringEnumLeafref bar"; |
| 265 | expected.m_data = enum_("bar"); |
| 266 | } |
| 267 | SECTION("enum leafref") |
| 268 | { |
| 269 | input = "set mod:unionStringEnumLeafref coze"; |
| 270 | expected.m_data = enum_("coze"); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | SECTION("activePort") |
| 275 | { |
| 276 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("activePort")}); |
| 277 | input = "set mod:activePort "; |
| 278 | SECTION("1. anonymous enum") |
| 279 | { |
| 280 | SECTION("wlan0") |
| 281 | { |
| 282 | input += "wlan0"; |
| 283 | expected.m_data = enum_("wlan0"); |
| 284 | } |
| 285 | SECTION("wlan1") |
| 286 | { |
| 287 | input += "wlan1"; |
| 288 | expected.m_data = enum_("wlan1"); |
| 289 | } |
| 290 | } |
| 291 | SECTION("2. leafref to enum") |
| 292 | { |
| 293 | SECTION("eth0") |
| 294 | { |
| 295 | input += "eth0"; |
| 296 | expected.m_data = enum_("eth0"); |
| 297 | } |
| 298 | SECTION("eth1") |
| 299 | { |
| 300 | input += "eth1"; |
| 301 | expected.m_data = enum_("eth1"); |
| 302 | } |
| 303 | SECTION("eth2") |
| 304 | { |
| 305 | input += "eth2"; |
| 306 | expected.m_data = enum_("eth2"); |
| 307 | } |
| 308 | } |
| 309 | SECTION("3. leafref to leafref") |
| 310 | { |
| 311 | SECTION("utf1") |
| 312 | { |
| 313 | input += "utf1"; |
| 314 | expected.m_data = enum_("utf1"); |
| 315 | } |
| 316 | SECTION("utf2") |
| 317 | { |
| 318 | input += "utf2"; |
| 319 | expected.m_data = enum_("utf2"); |
| 320 | } |
| 321 | SECTION("utf3") |
| 322 | { |
| 323 | input += "utf3"; |
| 324 | expected.m_data = enum_("utf3"); |
| 325 | } |
| 326 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 327 | SECTION("4. empty") |
| 328 | { |
| 329 | expected.m_data = empty_{}; |
| 330 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 334 | SECTION("binary") |
| 335 | { |
| 336 | SECTION("zero ending '='") |
| 337 | { |
| 338 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++"; |
| 339 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"}; |
| 340 | } |
| 341 | |
| 342 | SECTION("one ending '='") |
| 343 | { |
| 344 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++="; |
| 345 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="}; |
| 346 | } |
| 347 | |
| 348 | SECTION("two ending '='") |
| 349 | { |
| 350 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=="; |
| 351 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="}; |
| 352 | } |
| 353 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")}); |
| 354 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 355 | |
| 356 | SECTION("identityRef") |
| 357 | { |
| 358 | SECTION("foodIdentRef") |
| 359 | { |
| 360 | input = "set mod:foodIdentRef "; |
| 361 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")}); |
| 362 | |
| 363 | SECTION("food") |
| 364 | { |
| 365 | input += "food"; |
| 366 | expected.m_data = identityRef_("food"); |
| 367 | } |
| 368 | SECTION("mod:food") |
| 369 | { |
| 370 | input += "mod:food"; |
| 371 | expected.m_data = identityRef_("mod", "food"); |
| 372 | } |
| 373 | SECTION("pizza") |
| 374 | { |
| 375 | input += "pizza"; |
| 376 | expected.m_data = identityRef_("pizza"); |
| 377 | } |
| 378 | SECTION("mod:pizza") |
| 379 | { |
| 380 | input += "mod:pizza"; |
| 381 | expected.m_data = identityRef_("mod", "pizza"); |
| 382 | } |
| 383 | SECTION("pizza-module:hawaii") |
| 384 | { |
| 385 | input += "pizza-module:hawaii"; |
| 386 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 387 | } |
| 388 | } |
| 389 | SECTION("pizzaIdentRef") |
| 390 | { |
| 391 | input = "set mod:pizzaIdentRef "; |
| 392 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")}); |
| 393 | SECTION("pizza") |
| 394 | { |
| 395 | input += "pizza"; |
| 396 | expected.m_data = identityRef_("pizza"); |
| 397 | } |
| 398 | SECTION("mod:pizza") |
| 399 | { |
| 400 | input += "mod:pizza"; |
| 401 | expected.m_data = identityRef_("mod", "pizza"); |
| 402 | } |
| 403 | SECTION("pizza-module:hawaii") |
| 404 | { |
| 405 | input += "pizza-module:hawaii"; |
| 406 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 407 | } |
| 408 | } |
| 409 | SECTION("mod:contA/identInCont") |
| 410 | { |
| 411 | input = "set mod:contA/identInCont "; |
| 412 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 413 | expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont"))); |
| 414 | SECTION("pizza") |
| 415 | { |
| 416 | input += "pizza"; |
| 417 | expected.m_data = identityRef_("pizza"); |
| 418 | } |
| 419 | SECTION("mod:pizza") |
| 420 | { |
| 421 | input += "mod:pizza"; |
| 422 | expected.m_data = identityRef_("mod", "pizza"); |
| 423 | } |
| 424 | SECTION("pizza-module:hawaii") |
| 425 | { |
| 426 | input += "pizza-module:hawaii"; |
| 427 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 428 | } |
| 429 | } |
| 430 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 431 | SECTION("leafRef") |
| 432 | { |
| 433 | SECTION("refToString") |
| 434 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 435 | input = "set mod:refToString \"blabal\""; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 436 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")}); |
| 437 | expected.m_data = std::string("blabal"); |
| 438 | } |
| 439 | |
| 440 | SECTION("refToInt8") |
| 441 | { |
| 442 | input = "set mod:refToInt8 42"; |
| 443 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")}); |
| 444 | expected.m_data = int8_t{42}; |
| 445 | } |
Václav Kubernát | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame] | 446 | |
| 447 | SECTION("refToLeafInCont") |
| 448 | { |
| 449 | input = "set mod:refToLeafInCont pizza"; |
| 450 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")}); |
| 451 | expected.m_data = identityRef_{"pizza"}; |
| 452 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 453 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 454 | SECTION("empty") |
| 455 | { |
| 456 | input = "set mod:dummy "; |
| 457 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("dummy")}); |
| 458 | expected.m_data = empty_{}; |
| 459 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | command_ command = parser.parseCommand(input, errorStream); |
| 463 | REQUIRE(command.type() == typeid(set_)); |
| 464 | REQUIRE(boost::get<set_>(command) == expected); |
| 465 | } |
| 466 | |
| 467 | SECTION("invalid input") |
| 468 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 469 | std::string expectedError; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 470 | SECTION("missing space between a command and its arguments") |
| 471 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 472 | SECTION("setmod:leafString some_data") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 473 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 474 | input = "setmod:leafString 'some_data'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | SECTION("missing space between arguments") |
| 479 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 480 | SECTION("set mod:leafString'lol'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 481 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 482 | input = "set mod:leafString'lol'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | SECTION("non-leaf identifiers") |
| 487 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 488 | SECTION("set mod:nonexistent 'blabla'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 489 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 490 | input = "set mod:nonexistent 'blabla'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 493 | SECTION("set mod:contA 'abde'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 494 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 495 | input = "set mod:contA 'abde'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 499 | SECTION("wrong types") |
| 500 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 501 | expectedError = "leaf data type mismatch"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 502 | SECTION("set mod:leafBool 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 503 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 504 | input = "set mod:leafBool 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 505 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 506 | SECTION("set mod:leafUint8 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 507 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 508 | input = "set mod:leafUint8 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 509 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 510 | SECTION("set mod:leafUint8 -5") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 511 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 512 | input = "set mod:leafUint8 -5"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 513 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 514 | SECTION("set mod:leafInt8 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 515 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 516 | input = "set mod:leafInt8 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 517 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 518 | SECTION("set mod:leafInt8 130") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 519 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 520 | input = "set mod:leafInt8 130"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 521 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 522 | SECTION("set mod:leafUint16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 523 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 524 | input = "set mod:leafUint16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 525 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 526 | SECTION("set mod:leafInt16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 527 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 528 | input = "set mod:leafInt16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 529 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 530 | SECTION("set mod:leafUint32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 531 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 532 | input = "set mod:leafUint32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 533 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 534 | SECTION("set mod:leafInt32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 535 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 536 | input = "set mod:leafInt32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 537 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 538 | SECTION("set mod:leafUint64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 539 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 540 | input = "set mod:leafUint64 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 541 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 542 | SECTION("set mod:leafInt64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 543 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 544 | input = "set mod:leafInt64 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 545 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 546 | SECTION("set mod:leafEnum 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 547 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 548 | input = "set mod:leafEnum 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 549 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 550 | SECTION("set mod:refToInt8 'blabla'") |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 551 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 552 | input = "set mod:refToInt8 'blabla'"; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 553 | } |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 556 | SECTION("wrong base64 strings") |
| 557 | { |
| 558 | SECTION("invalid character") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 559 | input = "set mod:leafBinary dbahj-"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 560 | SECTION("equal sign in the middle") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 561 | input = "set mod:leafBinary db=ahj"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 562 | SECTION("enclosing in quotes") |
| 563 | input = "set mod:leafBinary 'dbahj'"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 566 | SECTION("non-existing identity") |
| 567 | { |
| 568 | input = "set mod:foodIdentRef identityBLABLA"; |
| 569 | } |
| 570 | |
Václav Kubernát | f365ecf | 2020-06-09 16:22:43 +0200 | [diff] [blame] | 571 | SECTION("identity with non-existing module") |
| 572 | { |
| 573 | expectedError = "Invalid module name"; |
| 574 | input = "set mod:foodIdentRef xd:haha"; |
| 575 | } |
| 576 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 577 | SECTION("setting identities with wrong bases") |
| 578 | { |
| 579 | SECTION("set mod:foodIdentRef mod:vehicle") |
| 580 | { |
| 581 | input = "set mod:foodIdentRef mod:vehicle"; |
| 582 | } |
| 583 | SECTION("set mod:pizzaIdentRef mod:food") |
| 584 | { |
| 585 | input = "set mod:pizzaIdentRef mod:food"; |
| 586 | } |
| 587 | } |
| 588 | SECTION("setting different module identities without prefix") |
| 589 | { |
| 590 | input = "set mod:pizzaIdentRef hawaii"; |
| 591 | } |
| 592 | SECTION("identity prefix without name") |
| 593 | { |
| 594 | input = "set mod:contA/identInCont pizza-module:"; |
| 595 | } |
| 596 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 597 | SECTION("set a union path to a wrong type") |
| 598 | { |
| 599 | input = "set mod:intOrString true"; |
| 600 | } |
| 601 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 602 | SECTION("no space for empty data") |
| 603 | { |
| 604 | input = "set mod:dummy"; |
| 605 | } |
| 606 | |
Václav Kubernát | 0d42c51 | 2020-05-20 21:18:39 +0200 | [diff] [blame] | 607 | SECTION("empty path") |
| 608 | { |
| 609 | input = "set "; |
| 610 | } |
| 611 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 612 | SECTION("setting readonly data") |
| 613 | { |
| 614 | input = "set mod:readonly 123"; |
| 615 | } |
| 616 | |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 617 | REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException); |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 618 | REQUIRE(errorStream.str().find(expectedError) != std::string::npos); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 619 | } |
| 620 | } |