diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-20 00:53:49 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-20 00:53:49 +0100 |
commit | 47311cc8b211a7fef033d744d9eba9f308726ea8 (patch) | |
tree | 348726aef17297729233b93b6d7eef86f25c7a78 /test/core/resource | |
parent | d836d70ea2352dcf277c6fce91ba1ded3f074b44 (diff) |
Refactored stuff surrounding the ResourceLocator class, implemented StaticResourceLocator which can be used for registering static resources (mainly for testing or if certain resources need to be available from the executable)
Diffstat (limited to 'test/core/resource')
-rw-r--r-- | test/core/resource/ResourceLocatorTest.cpp | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/test/core/resource/ResourceLocatorTest.cpp b/test/core/resource/ResourceLocatorTest.cpp index ebb164d..d009883 100644 --- a/test/core/resource/ResourceLocatorTest.cpp +++ b/test/core/resource/ResourceLocatorTest.cpp @@ -18,48 +18,31 @@ #include <gtest/gtest.h> -#include <core/ResourceLocator.hpp> - -#include <sstream> +#include <core/resource/ResourceLocator.hpp> namespace ousia { -class TestResourceLocator : public ResourceLocator { -public: - ResourceLocator::Location locate( - const std::string &path, const std::string &relativeTo, - const ResourceLocator::Type type) const override - { - // trivial test implementation. - return ResourceLocator::Location(true, *this, type, path); - } - - std::unique_ptr<std::istream> stream( - const std::string &location) const override - { - // trivial test implementation. - std::unique_ptr<std::stringstream> ss(new std::stringstream()); - (*ss) << "test"; - return std::move(ss); - } -}; - -TEST(ResourceLocator, locate) +TEST(StaticResourceLocator, locate) { - TestResourceLocator instance; - ResourceLocator::Location location = - instance.locate("path", "", ResourceLocator::Type::DOMAIN_DESC); - ASSERT_TRUE(location.found); - ASSERT_EQ(ResourceLocator::Type::DOMAIN_DESC, location.type); - ASSERT_EQ("path", location.location); + StaticResourceLocator locator; + locator.store("path", "test"); + + Resource res; + ASSERT_TRUE(locator.locate(res, "path")); + ASSERT_TRUE(res.isValid()); + ASSERT_EQ(ResourceType::UNKNOWN, res.getType()); + ASSERT_EQ("path", res.getLocation()); } -TEST(ResourceLocator, stream) +TEST(StaticResourceLocator, stream) { - TestResourceLocator instance; - ResourceLocator::Location location = - instance.locate("path", "", ResourceLocator::Type::DOMAIN_DESC); - std::unique_ptr<std::istream> is = location.stream(); + StaticResourceLocator locator; + locator.store("path", "test"); + + Resource res; + ASSERT_TRUE(locator.locate(res, "path")); + + auto is = res.stream(); std::string str; *is >> str; |