From faa8c03b69464f31fb419f7e4e4c4c1bd2e6907f Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 20 Jan 2015 18:32:09 +0100 Subject: Adapted FileLocator unit tests, searching in the "UNKNOWN" ResourceType search paths directly in ResoruceLocator instead of Registry --- src/plugins/filesystem/FileLocator.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/plugins/filesystem/FileLocator.cpp') diff --git a/src/plugins/filesystem/FileLocator.cpp b/src/plugins/filesystem/FileLocator.cpp index 7bb3a58..9a558eb 100644 --- a/src/plugins/filesystem/FileLocator.cpp +++ b/src/plugins/filesystem/FileLocator.cpp @@ -17,6 +17,10 @@ */ #ifndef NDEBUG +//#define FILELOCATOR_DEBUG_PRINT +#endif + +#ifdef FILELOCATOR_DEBUG_PRINT #include #endif @@ -44,6 +48,7 @@ void FileLocator::addPath(const std::string &path, void FileLocator::addSearchPath(const std::string &path, std::set types) { + // Skip empty or non-existant paths if (path.empty() || !fs::exists(path)) { return; } @@ -51,7 +56,7 @@ void FileLocator::addSearchPath(const std::string &path, // Canonicalize the given path, check whether it exists std::string canonicalPath = fs::canonical(path).generic_string(); -#ifndef NDEBUG +#ifdef FILELOCATOR_DEBUG_PRINT std::cout << "FileLocator: Adding search path " << canonicalPath << std::endl; #endif @@ -99,14 +104,22 @@ void FileLocator::addDefaultSearchPaths() addDefaultSearchPaths(SpecialPaths::getLocalDataDir()); #ifndef NDEBUG addDefaultSearchPaths(SpecialPaths::getDebugDataDir()); - addDefaultSearchPaths(SpecialPaths::getDebugTestdataDir()); #endif } +void FileLocator::addUnittestSearchPath(const std::string &subdir, ResourceType type) +{ + addSearchPath((fs::path{SpecialPaths::getDebugTestdataDir()} / subdir) + .generic_string(), type); +} + bool FileLocator::doLocate(Resource &resource, const std::string &path, const ResourceType type, const std::string &relativeTo) const { +#ifdef FILELOCATOR_DEBUG_PRINT + std::cout << "FileLocator: Searching for \"" << path << "\"" << std::endl; +#endif if (!relativeTo.empty()) { fs::path base(relativeTo); if (fs::exists(base)) { @@ -122,7 +135,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, // If we already found a fitting resource there, use that. if (fs::exists(base)) { std::string location = fs::canonical(base).generic_string(); -#ifndef NDEBUG +#ifdef FILELOCATOR_DEBUG_PRINT std::cout << "FileLocator: Found \"" << path << "\" at " << location << std::endl; #endif @@ -138,16 +151,15 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, if (it != searchPaths.end()) { const auto &paths = it->second; for (auto it = paths.rbegin(); it != paths.rend(); it++) { -#ifndef NDEBUG - std::cout << "FileLocator: Searching for \"" << path << "\" in " - << *it << std::endl; +#ifdef FILELOCATOR_DEBUG_PRINT + std::cout << "FileLocator: Entering " << *it << std::endl; #endif fs::path p{*it}; p /= path; if (fs::exists(p)) { std::string location = fs::canonical(p).generic_string(); -#ifndef NDEBUG - std::cout << "FileLocator: Found \"" << path << "\" at " +#ifdef FILELOCATOR_DEBUG_PRINT + std::cout << "FileLocator: Found \"" << path << "\" in " << location << std::endl; #endif resource = Resource(true, *this, type, location); -- cgit v1.2.3