diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-20 18:32:09 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-20 18:32:09 +0100 |
commit | faa8c03b69464f31fb419f7e4e4c4c1bd2e6907f (patch) | |
tree | 94dd1b59a5c8c1bceb68dc545a72d0952d6f1502 /src/plugins/filesystem | |
parent | 8755bbe309d2f00c7bc73a6a6304ed8860a9a94d (diff) |
Adapted FileLocator unit tests, searching in the "UNKNOWN" ResourceType search paths directly in ResoruceLocator instead of Registry
Diffstat (limited to 'src/plugins/filesystem')
-rw-r--r-- | src/plugins/filesystem/FileLocator.cpp | 28 | ||||
-rw-r--r-- | src/plugins/filesystem/FileLocator.hpp | 11 | ||||
-rw-r--r-- | src/plugins/filesystem/SpecialPaths.cpp | 8 |
3 files changed, 37 insertions, 10 deletions
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 <iostream> #endif @@ -44,6 +48,7 @@ void FileLocator::addPath(const std::string &path, void FileLocator::addSearchPath(const std::string &path, std::set<ResourceType> 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); diff --git a/src/plugins/filesystem/FileLocator.hpp b/src/plugins/filesystem/FileLocator.hpp index 6d3bbf0..16fa3f7 100644 --- a/src/plugins/filesystem/FileLocator.hpp +++ b/src/plugins/filesystem/FileLocator.hpp @@ -122,6 +122,17 @@ public: void addDefaultSearchPaths(); /** + * Adds a search path for a unit test. This function should not be used + * outside the code in the "test" folder. + * + * @param subdir is the subdirectory in the "testdata" directory that should + * be added. + * @param type is a single type for which the path should be added. + */ + void addUnittestSearchPath(const std::string &subdir, + ResourceType type = ResourceType::UNKNOWN); + + /** * Returns the backing map containing all search paths for a given type. * This is read-only. */ diff --git a/src/plugins/filesystem/SpecialPaths.cpp b/src/plugins/filesystem/SpecialPaths.cpp index 97bdb9c..47ac0f0 100644 --- a/src/plugins/filesystem/SpecialPaths.cpp +++ b/src/plugins/filesystem/SpecialPaths.cpp @@ -59,8 +59,12 @@ std::string SpecialPaths::getDebugDataDir() std::string SpecialPaths::getDebugTestdataDir() { - fs::path debug{OUSIA_DEBUG_DIR}; - return (debug / "testdata").generic_string(); + std::string debug{OUSIA_DEBUG_DIR}; + if (debug.empty()) { + return "./testdata"; + } else { + return (fs::path{debug} / "testdata").generic_string(); + } } } |