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