summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-25 18:52:37 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-25 18:52:37 +0100
commit9436db19a79fab0cad1c3b9dbc2628e1d4ed6e51 (patch)
tree6664d13d7b22da8dca414d73f76f8e3c307c1856 /test
parentbe66642ba83c1e238ba89d8cb562eb0e4b5c280c (diff)
Replaced stupid static ResourceUtils class with shiny new ResourceRequest class and corresponding (unfinished) test
Diffstat (limited to 'test')
-rw-r--r--test/core/resource/ResourceRequestTest.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/test/core/resource/ResourceRequestTest.cpp b/test/core/resource/ResourceRequestTest.cpp
new file mode 100644
index 0000000..0bb34be
--- /dev/null
+++ b/test/core/resource/ResourceRequestTest.cpp
@@ -0,0 +1,149 @@
+/*
+ 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 <iostream>
+
+#include <core/common/Logger.hpp>
+#include <core/common/Rtti.hpp>
+#include <core/frontend/TerminalLogger.hpp>
+#include <core/parser/Parser.hpp>
+#include <core/resource/ResourceRequest.hpp>
+#include <core/Registry.hpp>
+
+namespace ousia {
+
+namespace RttiTypes {
+extern const Rtti Document;
+extern const Rtti Domain;
+extern const Rtti Typesystem;
+}
+
+static TerminalLogger logger(std::cerr, true);
+// static ConcreteLogger logger;
+
+namespace {
+class ModuleParser : public Parser {
+protected:
+ Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override
+ {
+ return nullptr; // Stub
+ }
+};
+
+class DocumentParser : public Parser {
+protected:
+ Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override
+ {
+ return nullptr; // Stub
+ }
+};
+
+struct TestSetup {
+ ModuleParser pModule;
+ DocumentParser pDocument;
+ Registry registry;
+
+ TestSetup()
+ {
+ registry.registerExtension("domain", "application/domain");
+ registry.registerExtension("typesystem", "application/typesystem");
+ registry.registerExtension("document", "application/document");
+ registry.registerParser(
+ {"application/domain", "application/typesystem"},
+ {&RttiTypes::Domain, &RttiTypes::Typesystem}, &pModule);
+ registry.registerParser({"application/document"},
+ {&RttiTypes::Document}, &pDocument);
+ }
+};
+}
+
+TEST(ResourceRequest, deduction)
+{
+ TestSetup t;
+
+ ResourceRequest req("test.domain", "", "", {&RttiTypes::Domain});
+
+ ASSERT_TRUE(req.deduce(t.registry, logger));
+
+ ASSERT_EQ("test.domain", req.getPath());
+ ASSERT_EQ("application/domain", req.getMimetype());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain}), req.getSupportedTypes());
+ ASSERT_EQ(ResourceType::DOMAIN_DESC, req.getResourceType());
+ ASSERT_EQ(&t.pModule, req.getParser());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}),
+ req.getParserTypes());
+}
+
+TEST(ResourceRequest, deductionWithMimetype)
+{
+ TestSetup t;
+
+ ResourceRequest req("test.domain", "application/typesystem", "",
+ {&RttiTypes::Typesystem});
+
+ ASSERT_TRUE(req.deduce(t.registry, logger));
+
+ ASSERT_EQ("test.domain", req.getPath());
+ ASSERT_EQ("application/typesystem", req.getMimetype());
+ ASSERT_EQ(RttiSet({&RttiTypes::Typesystem}), req.getSupportedTypes());
+ ASSERT_EQ(ResourceType::TYPESYSTEM, req.getResourceType());
+ ASSERT_EQ(&t.pModule, req.getParser());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}),
+ req.getParserTypes());
+}
+
+TEST(ResourceRequest, deductionWithUnknownResourceType)
+{
+ TestSetup t;
+
+ ResourceRequest req("test.domain", "", "",
+ {&RttiTypes::Domain, &RttiTypes::Typesystem});
+
+ ASSERT_TRUE(req.deduce(t.registry, logger));
+
+ ASSERT_EQ("test.domain", req.getPath());
+ ASSERT_EQ("application/domain", req.getMimetype());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}),
+ req.getSupportedTypes());
+ ASSERT_EQ(ResourceType::UNKNOWN, req.getResourceType());
+ ASSERT_EQ(&t.pModule, req.getParser());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}),
+ req.getParserTypes());
+}
+
+TEST(ResourceRequest, deductionWithRel)
+{
+ TestSetup t;
+
+ ResourceRequest req("test.domain", "", "domain",
+ {&RttiTypes::Domain, &RttiTypes::Typesystem});
+
+ ASSERT_TRUE(req.deduce(t.registry, logger));
+
+ ASSERT_EQ("test.domain", req.getPath());
+ ASSERT_EQ("application/domain", req.getMimetype());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain}), req.getSupportedTypes());
+ ASSERT_EQ(ResourceType::DOMAIN_DESC, req.getResourceType());
+ ASSERT_EQ(&t.pModule, req.getParser());
+ ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}),
+ req.getParserTypes());
+}
+}
+