summaryrefslogtreecommitdiff
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
parente86c292967d85b571344b74fb5eeedf5ebf95aa8 (diff)
Adapted tests to StandaloneEnvironment, using complete pipeline in XmlParserTest
-rw-r--r--CMakeLists.txt1
-rw-r--r--test/core/parser/ParserStackTest.cpp17
-rw-r--r--test/plugins/css/CSSParserTest.cpp21
-rw-r--r--test/plugins/xml/XmlParserTest.cpp91
4 files changed, 58 insertions, 72 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2c24fe..c0daa8a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -290,6 +290,7 @@ IF(TEST)
${GTEST_LIBRARIES}
ousia_core
ousia_xml
+ ousia_filesystem
)
# ADD_EXECUTABLE(ousia_test_mozjs
diff --git a/test/core/parser/ParserStackTest.cpp b/test/core/parser/ParserStackTest.cpp
index 81160da..e0c68cc 100644
--- a/test/core/parser/ParserStackTest.cpp
+++ b/test/core/parser/ParserStackTest.cpp
@@ -21,10 +21,12 @@
#include <gtest/gtest.h>
#include <core/parser/ParserStack.hpp>
-#include <core/parser/StandaloneParserContext.hpp>
+#include <core/StandaloneEnvironment.hpp>
namespace ousia {
+ConcreteLogger logger;
+
static const State STATE_DOCUMENT = 0;
static const State STATE_BODY = 1;
static const State STATE_EMPTY = 2;
@@ -67,8 +69,8 @@ static const std::multimap<std::string, HandlerDescriptor> TEST_HANDLERS{
TEST(ParserStack, simpleTest)
{
- StandaloneParserContext ctx;
- ParserStack s{ctx.context, TEST_HANDLERS};
+ StandaloneEnvironment env(logger);
+ ParserStack s{env.context, TEST_HANDLERS};
startCount = 0;
endCount = 0;
@@ -130,8 +132,8 @@ TEST(ParserStack, simpleTest)
TEST(ParserStack, errorHandling)
{
- StandaloneParserContext ctx;
- ParserStack s{ctx.context, TEST_HANDLERS};
+ StandaloneEnvironment env(logger);
+ ParserStack s{env.context, TEST_HANDLERS};
ASSERT_THROW(s.start("body", {}), OusiaException);
s.start("document", {});
@@ -149,9 +151,8 @@ TEST(ParserStack, errorHandling)
TEST(ParserStack, validation)
{
- ConcreteLogger logger;
- StandaloneParserContext ctx(logger);
- ParserStack s{ctx.context, TEST_HANDLERS};
+ StandaloneEnvironment env(logger);
+ ParserStack s{env.context, TEST_HANDLERS};
s.start("arguments", {});
ASSERT_TRUE(logger.hasError());
diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp
index 46b4ebb..33b97af 100644
--- a/test/plugins/css/CSSParserTest.cpp
+++ b/test/plugins/css/CSSParserTest.cpp
@@ -22,10 +22,14 @@
#include <sstream>
#include <core/frontend/TerminalLogger.hpp>
-#include <core/parser/StandaloneParserContext.hpp>
+#include <core/StandaloneEnvironment.hpp>
#include <plugins/css/CSSParser.hpp>
namespace ousia {
+
+static TerminalLogger logger(std::cerr, true);
+//static ConcreteLogger logger;
+
TEST(CSSParser, testParseSelectors)
{
// create a string describing a SelectorTree
@@ -39,12 +43,12 @@ TEST(CSSParser, testParseSelectors)
*/
// initialize an empty parser context.
- StandaloneParserContext ctx;
+ StandaloneEnvironment env(logger);
// parse the data.
CSSParser instance;
Rooted<SelectorNode> root =
- instance.parse(data, ctx.context).cast<SelectorNode>();
+ instance.parse(data, env.context).cast<SelectorNode>();
// we expect three children of the root node overall.
ASSERT_EQ(3U, root->getEdges().size());
@@ -149,13 +153,13 @@ TEST(CSSParser, testParseCSS)
input << "}\n";
// initialize an empty parser context.
- StandaloneParserContext ctx;
+ StandaloneEnvironment env(logger);
// parse the input.
CSSParser instance;
CharReader reader{input};
Rooted<SelectorNode> root =
- instance.parse(reader, ctx.context).cast<SelectorNode>();
+ instance.parse(reader, env.context).cast<SelectorNode>();
// we expect three children of the root node overall.
ASSERT_EQ(3U, root->getEdges().size());
@@ -264,12 +268,13 @@ TEST(CSSParser, testParseCSS)
void assertException(std::string css)
{
CharReader reader(css);
- TerminalLogger logger(std::cerr, true);
{
- StandaloneParserContext ctx(logger);
+ StandaloneEnvironment env(logger);
CSSParser instance;
+
+ logger.reset();
try {
- instance.parse(reader, ctx.context).cast<SelectorNode>();
+ instance.parse(reader, env.context).cast<SelectorNode>();
}
catch (LoggableException ex) {
logger.log(ex);
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");
}
}