summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/RegistryTest.cpp48
-rw-r--r--test/core/ResourceLocatorTest.cpp69
-rw-r--r--test/core/parser/StandaloneParserContext.hpp6
-rw-r--r--test/core/resource/ResourceLocatorTest.cpp52
-rw-r--r--test/plugins/boost/FileLocatorTest.cpp89
-rw-r--r--test/plugins/xml/XmlParserTest.cpp23
6 files changed, 131 insertions, 156 deletions
diff --git a/test/core/RegistryTest.cpp b/test/core/RegistryTest.cpp
index 8280188..45e09d3 100644
--- a/test/core/RegistryTest.cpp
+++ b/test/core/RegistryTest.cpp
@@ -18,46 +18,26 @@
#include <gtest/gtest.h>
-#include <core/Registry.hpp>
-
#include <sstream>
-#include <core/common/Logger.hpp>
+#include <core/resource/ResourceLocator.hpp>
+#include <core/Registry.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(Registry, locateResource)
{
- TestResourceLocator locator;
- Logger logger;
- Registry instance {logger};
- instance.registerResourceLocator(&locator);
-
- ResourceLocator::Location location =
- instance.locateResource("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");
+
+ Registry registry;
+ registry.registerResourceLocator(locator);
+
+ Resource res;
+ ASSERT_TRUE(
+ registry.locateResource(res, "path", ResourceType::DOMAIN_DESC));
+ ASSERT_TRUE(res.isValid());
+ ASSERT_EQ(ResourceType::DOMAIN_DESC, res.getType());
+ ASSERT_EQ("path", res.getLocation());
}
-
}
diff --git a/test/core/ResourceLocatorTest.cpp b/test/core/ResourceLocatorTest.cpp
deleted file mode 100644
index ebb164d..0000000
--- a/test/core/ResourceLocatorTest.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- Ousía
- Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <gtest/gtest.h>
-
-#include <core/ResourceLocator.hpp>
-
-#include <sstream>
-
-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)
-{
- 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);
-}
-
-TEST(ResourceLocator, stream)
-{
- TestResourceLocator instance;
- ResourceLocator::Location location =
- instance.locate("path", "", ResourceLocator::Type::DOMAIN_DESC);
- std::unique_ptr<std::istream> is = location.stream();
-
- std::string str;
- *is >> str;
-
- ASSERT_EQ("test", str);
-}
-}
diff --git a/test/core/parser/StandaloneParserContext.hpp b/test/core/parser/StandaloneParserContext.hpp
index aca056e..347d34f 100644
--- a/test/core/parser/StandaloneParserContext.hpp
+++ b/test/core/parser/StandaloneParserContext.hpp
@@ -37,15 +37,13 @@ public:
ParserContext context;
StandaloneParserContext()
- : registry(logger),
- project(new model::Project(manager)),
+ : project(new model::Project(manager)),
context(scope, registry, logger, manager, project)
{
}
StandaloneParserContext(Logger &externalLogger)
- : registry(externalLogger),
- project(new model::Project(manager)),
+ : project(new model::Project(manager)),
context(scope, registry, externalLogger, manager, project){};
};
}
diff --git a/test/core/resource/ResourceLocatorTest.cpp b/test/core/resource/ResourceLocatorTest.cpp
new file mode 100644
index 0000000..d009883
--- /dev/null
+++ b/test/core/resource/ResourceLocatorTest.cpp
@@ -0,0 +1,52 @@
+/*
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <gtest/gtest.h>
+
+#include <core/resource/ResourceLocator.hpp>
+
+namespace ousia {
+
+TEST(StaticResourceLocator, locate)
+{
+ 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(StaticResourceLocator, stream)
+{
+ StaticResourceLocator locator;
+ locator.store("path", "test");
+
+ Resource res;
+ ASSERT_TRUE(locator.locate(res, "path"));
+
+ auto is = res.stream();
+
+ std::string str;
+ *is >> str;
+
+ ASSERT_EQ("test", str);
+}
+}
diff --git a/test/plugins/boost/FileLocatorTest.cpp b/test/plugins/boost/FileLocatorTest.cpp
index 2057a9f..473b15e 100644
--- a/test/plugins/boost/FileLocatorTest.cpp
+++ b/test/plugins/boost/FileLocatorTest.cpp
@@ -20,67 +20,75 @@
#include <plugins/boost/FileLocator.hpp>
+#include <boost/filesystem.hpp>
+
namespace ousia {
TEST(FileLocator, testAddSearchPath)
{
FileLocator instance;
- ASSERT_EQ(0, instance.getSearchPaths().size());
+ ASSERT_EQ(0U, instance.getSearchPaths().size());
+
+ // Read the canonical path of "."
+ std::string canonicalPath =
+ boost::filesystem::canonical(".").generic_string();
// Add one path for three types.
- instance.addSearchPath(
- ".", {ResourceLocator::Type::DOMAIN_DESC, ResourceLocator::Type::SCRIPT,
- ResourceLocator::Type::TYPESYS});
+ instance.addSearchPath(".",
+ {ResourceType::DOMAIN_DESC, ResourceType::SCRIPT,
+ ResourceType::TYPESYSTEM});
- ASSERT_EQ(3, instance.getSearchPaths().size());
+ ASSERT_EQ(3U, instance.getSearchPaths().size());
- auto it =
- instance.getSearchPaths().find(ResourceLocator::Type::DOMAIN_DESC);
+ auto it = instance.getSearchPaths().find(ResourceType::DOMAIN_DESC);
- ASSERT_EQ(1, it->second.size());
- ASSERT_EQ(".", it->second[0].generic_string());
+ ASSERT_EQ(1U, it->second.size());
+ ASSERT_EQ(canonicalPath, it->second[0]);
- it = instance.getSearchPaths().find(ResourceLocator::Type::SCRIPT);
+ it = instance.getSearchPaths().find(ResourceType::SCRIPT);
- ASSERT_EQ(1, it->second.size());
- ASSERT_EQ(".", it->second[0].generic_string());
+ ASSERT_EQ(1U, it->second.size());
+ ASSERT_EQ(canonicalPath, it->second[0]);
- it = instance.getSearchPaths().find(ResourceLocator::Type::TYPESYS);
+ it = instance.getSearchPaths().find(ResourceType::TYPESYSTEM);
- ASSERT_EQ(1, it->second.size());
- ASSERT_EQ(".", it->second[0].generic_string());
+ ASSERT_EQ(1U, it->second.size());
+ ASSERT_EQ(canonicalPath, it->second[0]);
// Add another path for only one of those types.
- instance.addSearchPath("..", {ResourceLocator::Type::DOMAIN_DESC});
+ std::string canonicalPath2 =
+ boost::filesystem::canonical("..").generic_string();
+
+ instance.addSearchPath("..", {ResourceType::DOMAIN_DESC});
- ASSERT_EQ(3, instance.getSearchPaths().size());
+ ASSERT_EQ(3U, instance.getSearchPaths().size());
- it = instance.getSearchPaths().find(ResourceLocator::Type::DOMAIN_DESC);
+ it = instance.getSearchPaths().find(ResourceType::DOMAIN_DESC);
- ASSERT_EQ(2, it->second.size());
- ASSERT_EQ(".", it->second[0].generic_string());
- ASSERT_EQ("..", it->second[1].generic_string());
+ ASSERT_EQ(2U, it->second.size());
+ ASSERT_EQ(canonicalPath, it->second[0]);
+ ASSERT_EQ(canonicalPath2, it->second[1]);
}
-void assert_located(
- const FileLocator &instance, const std::string &path,
- const std::string &relativeTo,
- ResourceLocator::Type type = ResourceLocator::Type::DOMAIN_DESC)
+void assert_located(const FileLocator &instance, const std::string &path,
+ const std::string &relativeTo,
+ ResourceType type = ResourceType::DOMAIN_DESC)
{
- ResourceLocator::Location loc = instance.locate(path, relativeTo, type);
- ASSERT_TRUE(loc.found);
- boost::filesystem::path p(loc.location);
+ Resource res;
+ ASSERT_TRUE(instance.locate(res, path, type, relativeTo));
+ ASSERT_TRUE(res.isValid());
+ boost::filesystem::path p(res.getLocation());
ASSERT_TRUE(boost::filesystem::exists(p));
ASSERT_EQ(path, p.filename());
}
-void assert_not_located(
- const FileLocator &instance, const std::string &path,
- const std::string &relativeTo,
- ResourceLocator::Type type = ResourceLocator::Type::DOMAIN_DESC)
+void assert_not_located(const FileLocator &instance, const std::string &path,
+ const std::string &relativeTo,
+ ResourceType type = ResourceType::DOMAIN_DESC)
{
- ResourceLocator::Location loc = instance.locate(path, relativeTo, type);
- ASSERT_FALSE(loc.found);
+ Resource res;
+ ASSERT_FALSE(instance.locate(res, path, type, relativeTo));
+ ASSERT_FALSE(res.isValid());
}
TEST(FileLocator, testLocate)
@@ -106,14 +114,14 @@ TEST(FileLocator, testLocate)
assert_not_located(instance, "FileLocator.hpp", relativeTo);
// Add the respective search path.
- instance.addSearchPath(start / "src/plugins/boost",
- {ResourceLocator::Type::DOMAIN_DESC});
+ instance.addSearchPath((start / "src/plugins/boost").generic_string(),
+ {ResourceType::DOMAIN_DESC});
// Now we should be able to find both.
assert_located(instance, "CMakeLists.txt", relativeTo);
assert_located(instance, "FileLocator.hpp", relativeTo);
// but only with the correct type.
assert_not_located(instance, "FileLocator.hpp", relativeTo,
- ResourceLocator::Type::SCRIPT);
+ ResourceType::SCRIPT);
}
TEST(FileLocator, testStream)
@@ -133,10 +141,11 @@ TEST(FileLocator, testStream)
}
FileLocator instance;
// Locate the CMakeLists.txt
- ResourceLocator::Location loc = instance.locate(
- "CMakeLists.txt", relativeTo, ResourceLocator::Type::DOMAIN_DESC);
+ Resource res;
+ instance.locate(res, "CMakeLists.txt", ResourceType::DOMAIN_DESC,
+ relativeTo);
// Stream the content.
- auto is_ptr = loc.stream();
+ auto is_ptr = res.stream();
// get the beginning.
char buf[256];
is_ptr->getline(buf, 256);
diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp
index 6ac2fc1..f1956e0 100644
--- a/test/plugins/xml/XmlParserTest.cpp
+++ b/test/plugins/xml/XmlParserTest.cpp
@@ -53,22 +53,26 @@ const char *TEST_DATA =
" <head>\n"
" <typesystem name=\"color\">\n"
" <types>\n"
- " <struct name=\"color\" parent=\"blub\">\n"
- " <field name=\"r\" type=\"int\"/>\n"
- " <field name=\"g\" type=\"int\"/>\n"
- " <field name=\"b\" type=\"int\"/>\n"
+ " <struct name=\"rgb\">\n"
+ " <field name=\"r\" type=\"double\"/>\n"
+ " <field name=\"g\" type=\"double\"/>\n"
+ " <field name=\"b\" type=\"double\"/>\n"
" </struct>\n"
- " <struct name=\"blub\">\n"
- " <field name=\"a\" type=\"int\"/>\n"
+ " <struct name=\"rgba\" parent=\"rgb\">\n"
+ " <field name=\"a\" type=\"double\" default=\"0xf3\"/>\n"
" </struct>\n"
- " <struct name=\"blub\">\n"
- " <field name=\"a\" type=\"int\"/>\n"
+ " </types>\n"
+ " </typesystem>\n"
+ " <typesystem name=\"color2\">\n"
+ " <types>\n"
+ " <struct name=\"rgba\" parent=\"rgb\">\n"
+ " <field name=\"a\" type=\"bla\" default=\"0xf3\"/>\n"
" </struct>\n"
" </types>\n"
" </typesystem>\n"
" </head>\n"
" <body xmlAttr=\"blub\">\n"
- " <book>Dies ist ein Test&gt;</book>\n"
+ " <!--<book>Dies ist ein Test&gt;</book>-->\n"
" </body>\n"
"</document>\n";
@@ -86,6 +90,7 @@ TEST(XmlParser, namespaces)
catch (LoggableException ex) {
logger.log(ex);
}
+ ctx.manager.exportGraphviz("xmlDocument.dot");
}
}
}