Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [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" |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 10 | #include <libyang-cpp/Context.hpp> |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 11 | #include "completion.hpp" |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 12 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 13 | #include "libyang_utils.hpp" |
| 14 | #include "pretty_printers.hpp" |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 15 | #include "utils.hpp" |
| 16 | |
Jan Kundrát | 95c5582 | 2023-05-18 17:12:20 +0200 | [diff] [blame] | 17 | using namespace std::literals; |
| 18 | |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 19 | TEST_CASE("utils") |
| 20 | { |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 21 | SECTION("filterByPrefix") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 22 | { |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 23 | std::set<Completion> set{{"ahoj"}, {"coze"}, {"copak"}, {"aha"}, {"polivka"}}; |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 24 | |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 25 | REQUIRE((filterByPrefix(set, "a") == std::set<Completion>{{"ahoj"}, {"aha"}})); |
| 26 | REQUIRE((filterByPrefix(set, "ah") == std::set<Completion>{{"ahoj"}, {"aha"}})); |
| 27 | REQUIRE((filterByPrefix(set, "aho") == std::set<Completion>{{"ahoj"}})); |
| 28 | REQUIRE((filterByPrefix(set, "polivka") == std::set<Completion>{{"polivka"}})); |
| 29 | REQUIRE((filterByPrefix(set, "polivkax") == std::set<Completion>{})); |
| 30 | REQUIRE((filterByPrefix(set, "co") == std::set<Completion>{{"copak"}, {"coze"}})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 31 | } |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 32 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 33 | SECTION("joinPaths") |
| 34 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 35 | std::string prefix, suffix, result; |
| 36 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 37 | SECTION("regular") |
| 38 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 39 | prefix = "/example:a"; |
| 40 | suffix = "leaf"; |
| 41 | result = "/example:a/leaf"; |
| 42 | } |
| 43 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 44 | SECTION("no prefix - absolute path") |
| 45 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 46 | suffix = "/example:a/leaf"; |
| 47 | result = "/example:a/leaf"; |
| 48 | } |
| 49 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 50 | SECTION("no prefix - relative path") |
| 51 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 52 | suffix = "example:a/leaf"; |
| 53 | result = "example:a/leaf"; |
| 54 | } |
| 55 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 56 | SECTION("no suffix") |
| 57 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 58 | prefix = "/example:a/leaf"; |
| 59 | result = "/example:a/leaf"; |
| 60 | } |
| 61 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 62 | SECTION("at root") |
| 63 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 64 | prefix = "/"; |
| 65 | suffix = "example:a"; |
| 66 | result = "/example:a"; |
| 67 | } |
| 68 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 69 | SECTION("trailing slash") |
| 70 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 71 | prefix = "/example:a"; |
| 72 | suffix = "/"; |
| 73 | result = "/example:a/"; |
| 74 | } |
| 75 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 76 | SECTION("prefix ends with slash") |
| 77 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 78 | prefix = "/example:a/"; |
| 79 | suffix = "leaf"; |
| 80 | result = "/example:a/leaf"; |
| 81 | } |
| 82 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 83 | SECTION("suffix starts with slash") |
| 84 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 85 | prefix = "/example:a"; |
| 86 | suffix = "/leaf"; |
| 87 | result = "/example:a/leaf"; |
| 88 | } |
| 89 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 90 | SECTION("slashes all the way to eleven") |
| 91 | { |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 92 | prefix = "/example:a/"; |
| 93 | suffix = "/leaf"; |
| 94 | result = "/example:a/leaf"; |
| 95 | } |
| 96 | |
| 97 | REQUIRE(joinPaths(prefix, suffix) == result); |
| 98 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 99 | |
| 100 | SECTION("leafDataTypeToString") |
| 101 | { |
| 102 | yang::LeafDataType type; |
| 103 | std::string expected; |
| 104 | SECTION("union") |
| 105 | { |
| 106 | type = yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 107 | yang::TypeInfo{yang::String{}}, |
| 108 | yang::TypeInfo{createEnum({"foo", "bar"})}, |
| 109 | yang::TypeInfo{yang::Int8{}}, |
| 110 | yang::TypeInfo{yang::Int64{}}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 111 | }}; |
| 112 | expected = "a string, an enum, an 8-bit integer, a 64-bit integer"; |
| 113 | } |
| 114 | |
| 115 | REQUIRE(leafDataTypeToString(type) == expected); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 116 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 117 | } |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 118 | |
| 119 | const auto schema = R"( |
| 120 | module test-schema { |
| 121 | namespace "http://example.com/ayyyy"; |
| 122 | prefix AHOJ; |
| 123 | |
| 124 | leaf int8 { |
| 125 | type int8; |
| 126 | } |
| 127 | leaf int16 { |
| 128 | type int16; |
| 129 | } |
| 130 | leaf int32 { |
| 131 | type int32; |
| 132 | } |
| 133 | leaf int64 { |
| 134 | type int64; |
| 135 | } |
| 136 | leaf uint8 { |
| 137 | type uint8; |
| 138 | } |
| 139 | leaf uint16 { |
| 140 | type uint16; |
| 141 | } |
| 142 | leaf uint32 { |
| 143 | type uint32; |
| 144 | } |
| 145 | leaf uint64 { |
| 146 | type uint64; |
| 147 | } |
| 148 | leaf boolean { |
| 149 | type boolean; |
| 150 | } |
| 151 | leaf string { |
| 152 | type string; |
| 153 | } |
| 154 | leaf enum { |
| 155 | type enumeration { |
| 156 | enum A; |
| 157 | enum B; |
| 158 | enum C; |
| 159 | } |
| 160 | } |
| 161 | identity food; |
| 162 | identity apple { |
| 163 | base "food"; |
| 164 | } |
| 165 | leaf identityRef { |
| 166 | type identityref { |
| 167 | base "food"; |
| 168 | } |
| 169 | } |
| 170 | leaf binary { |
| 171 | type binary; |
| 172 | } |
| 173 | leaf empty { |
| 174 | type empty; |
| 175 | } |
| 176 | leaf bits { |
| 177 | type bits { |
| 178 | bit a; |
| 179 | bit b; |
| 180 | bit AHOJ; |
| 181 | } |
| 182 | } |
Václav Kubernát | d4800e5 | 2020-11-09 10:58:12 +0100 | [diff] [blame] | 183 | typedef capabilitiesType { |
| 184 | type bits { |
| 185 | bit router; |
| 186 | bit switch; |
| 187 | bit hub; |
| 188 | } |
| 189 | } |
| 190 | leaf capabilities { |
| 191 | type capabilitiesType; |
| 192 | } |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 193 | leaf dec64 { |
| 194 | type decimal64 { |
| 195 | fraction-digits 5; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | list stuff { |
| 200 | key "name"; |
| 201 | leaf name { |
| 202 | type string; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | leaf leafRefPresent { |
| 207 | type leafref { |
| 208 | path ../stuff/name; |
| 209 | } |
| 210 | } |
| 211 | |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 212 | container users { |
| 213 | config false; |
| 214 | list userList { |
| 215 | leaf name { |
| 216 | type string; |
| 217 | } |
| 218 | } |
| 219 | } |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame^] | 220 | |
| 221 | leaf iid-valid { |
| 222 | type instance-identifier; |
| 223 | } |
| 224 | |
| 225 | leaf iid-relaxed { |
| 226 | type instance-identifier { |
| 227 | require-instance false; |
| 228 | } |
| 229 | } |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 230 | } |
Jan Kundrát | 95c5582 | 2023-05-18 17:12:20 +0200 | [diff] [blame] | 231 | )"s; |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 232 | |
| 233 | const auto data = R"( |
| 234 | { |
| 235 | "test-schema:int8": 8, |
| 236 | "test-schema:int16": 300, |
| 237 | "test-schema:int32": -300, |
Jan Kundrát | 6c34e9f | 2021-01-27 12:58:51 +0100 | [diff] [blame] | 238 | "test-schema:int64": "-999999999999999", |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 239 | "test-schema:uint8": 8, |
| 240 | "test-schema:uint16": 300, |
| 241 | "test-schema:uint32": 300, |
Jan Kundrát | 6c34e9f | 2021-01-27 12:58:51 +0100 | [diff] [blame] | 242 | "test-schema:uint64": "999999999999999", |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 243 | "test-schema:boolean": true, |
| 244 | "test-schema:string": "AHOJ", |
| 245 | "test-schema:enum": "A", |
| 246 | "test-schema:identityRef": "apple", |
| 247 | "test-schema:binary": "QUhPSgo=", |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 248 | "test-schema:empty": [null], |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 249 | "test-schema:bits": "a AHOJ", |
Václav Kubernát | d4800e5 | 2020-11-09 10:58:12 +0100 | [diff] [blame] | 250 | "test-schema:capabilities": "switch hub", |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 251 | "test-schema:dec64": "43242.43260", |
| 252 | "test-schema:stuff": [ |
| 253 | { |
| 254 | "name": "Xaver" |
| 255 | } |
| 256 | ], |
| 257 | "test-schema:leafRefPresent": "Xaver", |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 258 | "test-schema:users": { |
| 259 | "userList": [ |
| 260 | { |
| 261 | "name": "John" |
| 262 | }, |
| 263 | { |
| 264 | "name": "Aneta" |
| 265 | }, |
| 266 | { |
| 267 | "name": "Aneta" |
| 268 | } |
| 269 | ] |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame^] | 270 | }, |
| 271 | "test-schema:iid-valid": "/test-schema:stuff[name='Xaver']/name", |
| 272 | "test-schema:iid-relaxed": "/test-schema:stuff[name='XXX']/name" |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 273 | } |
Jan Kundrát | 95c5582 | 2023-05-18 17:12:20 +0200 | [diff] [blame] | 274 | )"s; |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 275 | |
| 276 | |
| 277 | TEST_CASE("libyang_utils") |
| 278 | { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 279 | libyang::Context ctx; |
Jan Kundrát | 95c5582 | 2023-05-18 17:12:20 +0200 | [diff] [blame] | 280 | ctx.parseModule(schema, libyang::SchemaFormat::YANG); |
| 281 | auto dataNode = ctx.parseData(data, libyang::DataFormat::JSON, std::nullopt, libyang::ValidationOptions::Present); |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 282 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 283 | SECTION("leafValueFromNode") |
| 284 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 285 | std::string path; |
| 286 | leaf_data_ expectedLeafData; |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 287 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 288 | SECTION("test-schema:int8") |
| 289 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 290 | path = "test-schema:int8"; |
| 291 | expectedLeafData = int8_t{8}; |
| 292 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 293 | SECTION("test-schema:int16") |
| 294 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 295 | path = "test-schema:int16"; |
| 296 | expectedLeafData = int16_t{300}; |
| 297 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 298 | SECTION("test-schema:int32") |
| 299 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 300 | path = "test-schema:int32"; |
| 301 | expectedLeafData = int32_t{-300}; |
| 302 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 303 | SECTION("test-schema:int64") |
| 304 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 305 | path = "test-schema:int64"; |
| 306 | expectedLeafData = int64_t{-999999999999999}; |
| 307 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 308 | SECTION("test-schema:uint8") |
| 309 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 310 | path = "test-schema:uint8"; |
| 311 | expectedLeafData = uint8_t{8}; |
| 312 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 313 | SECTION("test-schema:uint16") |
| 314 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 315 | path = "test-schema:uint16"; |
| 316 | expectedLeafData = uint16_t{300}; |
| 317 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 318 | SECTION("test-schema:uint32") |
| 319 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 320 | path = "test-schema:uint32"; |
| 321 | expectedLeafData = uint32_t{300}; |
| 322 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 323 | SECTION("test-schema:uint64") |
| 324 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 325 | path = "test-schema:uint64"; |
| 326 | expectedLeafData = uint64_t{999999999999999}; |
| 327 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 328 | SECTION("test-schema:boolean") |
| 329 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 330 | path = "test-schema:boolean"; |
| 331 | expectedLeafData = true; |
| 332 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 333 | SECTION("test-schema:string") |
| 334 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 335 | path = "test-schema:string"; |
| 336 | expectedLeafData = std::string{"AHOJ"}; |
| 337 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 338 | SECTION("test-schema:enum") |
| 339 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 340 | path = "test-schema:enum"; |
| 341 | expectedLeafData = enum_{"A"}; |
| 342 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 343 | SECTION("test-schema:identityRef") |
| 344 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 345 | path = "test-schema:identityRef"; |
| 346 | expectedLeafData = identityRef_{"test-schema", "apple"}; |
| 347 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 348 | SECTION("test-schema:binary") |
| 349 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 350 | path = "test-schema:binary"; |
| 351 | expectedLeafData = binary_{"QUhPSgo="}; |
| 352 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 353 | SECTION("test-schema:empty") |
| 354 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 355 | path = "test-schema:empty"; |
| 356 | expectedLeafData = empty_{}; |
| 357 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 358 | SECTION("test-schema:bits") |
| 359 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 360 | path = "test-schema:bits"; |
| 361 | expectedLeafData = bits_{{"a", "AHOJ"}}; |
| 362 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 363 | SECTION("test-schema:dec64") |
| 364 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 365 | path = "test-schema:dec64"; |
| 366 | expectedLeafData = 43242.43260; |
| 367 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 368 | SECTION("test-schema:leafRefPresent") |
| 369 | { |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 370 | path = "test-schema:leafRefPresent"; |
| 371 | expectedLeafData = std::string{"Xaver"}; |
| 372 | } |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 373 | |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 374 | auto leaf = dataNode->findPath("/" + path); |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 375 | REQUIRE(leafValueFromNode(leaf->asTerm()) == expectedLeafData); |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 376 | } |
| 377 | |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 378 | SECTION("lyNodesToTree") |
| 379 | { |
| 380 | DatastoreAccess::Tree expected{ |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 381 | {"/test-schema:int8", int8_t{8}}, |
| 382 | {"/test-schema:int16", int16_t{300}}, |
| 383 | {"/test-schema:int32", int32_t{-300}}, |
| 384 | {"/test-schema:int64", int64_t{-999999999999999}}, |
| 385 | {"/test-schema:uint8", uint8_t{8}}, |
| 386 | {"/test-schema:uint16", uint16_t{300}}, |
| 387 | {"/test-schema:uint32", uint32_t{300}}, |
| 388 | {"/test-schema:uint64", uint64_t{999999999999999}}, |
| 389 | {"/test-schema:boolean", true}, |
| 390 | {"/test-schema:string", std::string{"AHOJ"}}, |
| 391 | {"/test-schema:enum", enum_{"A"}}, |
| 392 | {"/test-schema:identityRef", identityRef_{"test-schema", "apple"}}, |
| 393 | {"/test-schema:binary", binary_{"QUhPSgo="}}, |
| 394 | {"/test-schema:empty", empty_{}}, |
| 395 | {"/test-schema:bits", bits_{{"a", "AHOJ"}}}, |
Václav Kubernát | d4800e5 | 2020-11-09 10:58:12 +0100 | [diff] [blame] | 396 | {"/test-schema:capabilities", bits_{{"switch", "hub"}}}, |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 397 | {"/test-schema:dec64", 43242.432600}, |
| 398 | {"/test-schema:stuff[name='Xaver']", special_{SpecialValue::List}}, |
| 399 | {"/test-schema:stuff[name='Xaver']/name", std::string{"Xaver"}}, |
| 400 | {"/test-schema:leafRefPresent", std::string{"Xaver"}}, |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 401 | {"/test-schema:users/userList[1]", special_{SpecialValue::List}}, |
| 402 | {"/test-schema:users/userList[1]/name", std::string{"John"}}, |
| 403 | {"/test-schema:users/userList[2]", special_{SpecialValue::List}}, |
| 404 | {"/test-schema:users/userList[2]/name", std::string{"Aneta"}}, |
| 405 | {"/test-schema:users/userList[3]", special_{SpecialValue::List}}, |
| 406 | {"/test-schema:users/userList[3]/name", std::string{"Aneta"}}, |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame^] | 407 | {"/test-schema:iid-valid", instanceIdentifier_{"/test-schema:stuff[name='Xaver']/name"}}, |
| 408 | {"/test-schema:iid-relaxed", instanceIdentifier_{"/test-schema:stuff[name='XXX']/name"}}, |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | DatastoreAccess::Tree tree; |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 412 | lyNodesToTree(tree, dataNode->siblings()); |
Václav Kubernát | 61d92d7 | 2020-11-06 03:14:18 +0100 | [diff] [blame] | 413 | REQUIRE(tree == expected); |
| 414 | } |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 415 | } |