summaryrefslogtreecommitdiff
path: root/test/plugins/xml/XmlParserTest.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-25 23:16:54 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-25 23:16:54 +0100
commit2629c62e415e9c02fe73f61c92d8148b8dad5bf9 (patch)
tree2585582a39a70610318810578b69ce9368372ef5 /test/plugins/xml/XmlParserTest.cpp
parente86c292967d85b571344b74fb5eeedf5ebf95aa8 (diff)
Adapted tests to StandaloneEnvironment, using complete pipeline in XmlParserTest
Diffstat (limited to 'test/plugins/xml/XmlParserTest.cpp')
-rw-r--r--test/plugins/xml/XmlParserTest.cpp91
1 files changed, 35 insertions, 56 deletions
diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp
index 3ed7417..3660c35 100644
--- a/test/plugins/xml/XmlParserTest.cpp
+++ b/test/plugins/xml/XmlParserTest.cpp
@@ -21,75 +21,54 @@
#include <gtest/gtest.h>
#include <core/common/CharReader.hpp>
-#include <core/common/Logger.hpp>
#include <core/common/SourceContextReader.hpp>
+#include <core/model/Project.hpp>
#include <core/frontend/TerminalLogger.hpp>
-#include <core/parser/StandaloneParserContext.hpp>
+#include <core/StandaloneEnvironment.hpp>
+#include <plugins/filesystem/FileLocator.hpp>
#include <plugins/xml/XmlParser.hpp>
namespace ousia {
-static TerminalLogger logger(std::cerr, true);
+namespace RttiTypes {
+extern const Rtti Document;
+extern const Rtti Typesystem;
+}
-TEST(XmlParser, mismatchedTagException)
-{
- StandaloneParserContext ctx;
- XmlParser p;
+struct XmlStandaloneEnvironment : public StandaloneEnvironment {
+ XmlParser xmlParser;
+ FileLocator fileLocator;
- bool hadException = false;
- try {
- p.parse("<document>\n</document2>", ctx.context);
- }
- catch (LoggableException ex) {
- hadException = true;
+ XmlStandaloneEnvironment(ConcreteLogger &logger)
+ : StandaloneEnvironment(logger)
+ {
+ fileLocator.addUnittestSearchPath("xmlparser");
+
+ registry.registerDefaultExtensions();
+ registry.registerParser({"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"},
+ {&RttiTypes::Document, &RttiTypes::Typesystem},
+ &xmlParser);
+ registry.registerResourceLocator(&fileLocator);
}
- ASSERT_TRUE(hadException);
+};
+
+static TerminalLogger logger(std::cerr, true);
+
+TEST(XmlParser, mismatchedTag)
+{
+ XmlStandaloneEnvironment env(logger);
+ env.project->parse("mismatchedTag.oxm", "", "",
+ RttiSet{&RttiTypes::Document}, logger);
+ ASSERT_TRUE(logger.hasError());
}
-const char *TEST_DATA =
- "<?xml version=\"1.0\" standalone=\"yes\"?>\n"
- "<document a:bc=\"b\">\n"
- " <head>\n"
- " <typesystem name=\"color\">\n"
- " <types>\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=\"rgba\" parent=\"rgb\">\n"
- " <field name=\"a\" type=\"double\" default=\"0xf3\"/>\n"
- " </struct>\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"
- " </body>\n"
- "</document>\n";
-
-TEST(XmlParser, namespaces)
+TEST(XmlParser, generic)
{
- StandaloneParserContext ctx(logger);
- XmlParser p;
- CharReader reader(TEST_DATA);
- {
- try {
- p.parse(TEST_DATA, ctx.context);
- }
- catch (LoggableException ex) {
- logger.log(ex);
- }
- ctx.manager.exportGraphviz("xmlDocument.dot");
- }
+ XmlStandaloneEnvironment env(logger);
+ env.project->parse("generic.oxm", "", "", RttiSet{&RttiTypes::Document},
+ logger);
+ env.manager.exportGraphviz("xmlDocument.dot");
}
}