| 280 | }; |
| 281 | |
| 282 | void testResourceTree(Module* module) |
| 283 | { |
| 284 | ModuleResource res = module->GetResource(""); |
| 285 | US_TEST_CONDITION(res.GetResourcePath() == "/", "Check root file path") |
| 286 | US_TEST_CONDITION(res.IsDir() == true, "Check type") |
| 287 | |
| 288 | std::vector<std::string> children = res.GetChildren(); |
| 289 | std::sort(children.begin(), children.end()); |
| 290 | US_TEST_CONDITION_REQUIRED(children.size() == 5, "Check child count") |
| 291 | US_TEST_CONDITION(children[0] == "foo.txt", "Check child name") |
| 292 | US_TEST_CONDITION(children[1] == "foo2.txt", "Check child name") |
| 293 | US_TEST_CONDITION(children[2] == "icons/", "Check child name") |
| 294 | US_TEST_CONDITION(children[3] == "special_chars.dummy.txt", "Check child name") |
| 295 | US_TEST_CONDITION(children[4] == "test.xml", "Check child name") |
| 296 | |
| 297 | US_TEST_CONDITION(module->FindResources("!$noexist=?", std::string(), "true").empty(), "Check not existant path"); |
| 298 | |
| 299 | |
| 300 | ModuleResource readme = module->GetResource("/icons/readme.txt"); |
| 301 | US_TEST_CONDITION(readme.IsFile() && readme.GetChildren().empty(), "Check file resource") |
| 302 | |
| 303 | ModuleResource icons = module->GetResource("icons/"); |
| 304 | US_TEST_CONDITION(icons.IsDir() && !icons.IsFile() && !icons.GetChildren().empty(), "Check directory resource") |
| 305 | |
| 306 | children = icons.GetChildren(); |
| 307 | US_TEST_CONDITION_REQUIRED(children.size() == 3, "Check icons child count") |
| 308 | std::sort(children.begin(), children.end()); |
| 309 | US_TEST_CONDITION(children[0] == "compressable.bmp", "Check child name") |
| 310 | US_TEST_CONDITION(children[1] == "cppmicroservices.png", "Check child name") |
| 311 | US_TEST_CONDITION(children[2] == "readme.txt", "Check child name") |
| 312 | |
| 313 | ResourceComparator resourceComparator; |
| 314 | |
| 315 | // find all .txt files |
| 316 | std::vector<ModuleResource> nodes = module->FindResources("", "*.txt", false); |
| 317 | std::sort(nodes.begin(), nodes.end(), resourceComparator); |
| 318 | US_TEST_CONDITION_REQUIRED(nodes.size() == 3, "Found child count") |
| 319 | US_TEST_CONDITION(nodes[0].GetResourcePath() == "/foo.txt", "Check child name") |
| 320 | US_TEST_CONDITION(nodes[1].GetResourcePath() == "/foo2.txt", "Check child name") |
| 321 | US_TEST_CONDITION(nodes[2].GetResourcePath() == "/special_chars.dummy.txt", "Check child name") |
| 322 | |
| 323 | nodes = module->FindResources("", "*.txt", true); |
| 324 | std::sort(nodes.begin(), nodes.end(), resourceComparator); |
| 325 | US_TEST_CONDITION_REQUIRED(nodes.size() == 4, "Found child count") |
| 326 | US_TEST_CONDITION(nodes[0].GetResourcePath() == "/foo.txt", "Check child name") |
| 327 | US_TEST_CONDITION(nodes[1].GetResourcePath() == "/foo2.txt", "Check child name") |
| 328 | US_TEST_CONDITION(nodes[2].GetResourcePath() == "/icons/readme.txt", "Check child name") |
| 329 | US_TEST_CONDITION(nodes[3].GetResourcePath() == "/special_chars.dummy.txt", "Check child name") |
| 330 | |
| 331 | // find all resources |
| 332 | nodes = module->FindResources("", "", true); |
| 333 | US_TEST_CONDITION(nodes.size() == 8, "Total resource number") |
| 334 | nodes = module->FindResources("", "**", true); |
| 335 | US_TEST_CONDITION(nodes.size() == 8, "Total resource number") |
| 336 | |
| 337 | |
| 338 | // test pattern matching |
| 339 | nodes.clear(); |
no test coverage detected