From 5554f3594d00e267af447a24149f655ceff64d17 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Mon, 1 Dec 2014 21:27:08 +0100 Subject: working version of the ParserStack class plus unit tests --- src/core/parser/ParserStack.cpp | 155 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/core/parser/ParserStack.cpp (limited to 'src/core/parser/ParserStack.cpp') diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp new file mode 100644 index 0000000..01fce3f --- /dev/null +++ b/src/core/parser/ParserStack.cpp @@ -0,0 +1,155 @@ +/* + 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 . +*/ + +#include + +#include "ParserStack.hpp" + +#include + +namespace ousia { +namespace parser { + +/* Class HandlerDescriptor */ + +HandlerInstance HandlerDescriptor::create(const ParserContext &ctx, + std::string name, State parentState, + bool isChild, char **attrs) const +{ + Handler *h = ctor(ctx, name, targetState, parentState, isChild); + h->start(attrs); + return HandlerInstance(h, this); +} + +/* Class ParserStack */ + +/** + * Function used internally to turn the elements of a collection into a string + * separated by the given delimiter. + */ +template +static std::string join(T es, const std::string &delim) +{ + std::stringstream res; + bool first = true; + for (auto &e : es) { + if (!first) { + res << delim; + } + res << e; + first = false; + } + return res.str(); +} + +/** + * Returns an Exception that should be thrown when a currently invalid command + * is thrown. + */ +static LoggableException invalidCommand(const std::string &name, + const std::set &expected) +{ + if (expected.empty()) { + return LoggableException{ + std::string{"No nested elements allowed, but got \""} + name + + std::string{"\""}}; + } else { + return LoggableException{ + std::string{"Expected "} + + (expected.size() == 1 ? std::string{"\""} + : std::string{"one of \""}) + + join(expected, "\", \"") + std::string{"\", but got \""} + name + + std::string{"\""}}; + } +} + +std::set ParserStack::expectedCommands(State state) +{ + std::set res; + for (const auto &v : handlers) { + if (v.second.parentStates.count(state)) { + res.insert(v.first); + } + } + return res; +} + +void ParserStack::start(std::string name, char **attrs) +{ + // Fetch the current handler and the current state + const HandlerInstance *h = stack.empty() ? nullptr : &stack.top(); + const State curState = currentState(); + bool isChild = false; + + // Fetch the correct Handler descriptor for this + const HandlerDescriptor *descr = nullptr; + auto range = handlers.equal_range(name); + for (auto it = range.first; it != range.second; it++) { + if (it->second.parentStates.count(curState)) { + descr = &(it->second); + break; + } + } + if (!descr && currentArbitraryChildren()) { + isChild = true; + descr = h->descr; + } + + // No descriptor found, throw an exception. + if (!descr) { + throw invalidCommand(name, expectedCommands(curState)); + } + + // Instantiate the handler and call its start function + stack.emplace(descr->create(ctx, name, curState, isChild, attrs)); +} + +void ParserStack::end() +{ + // Check whether the current command could be ended + if (stack.empty()) { + throw LoggableException{"No command to end."}; + } + + // Remove the current HandlerInstance from the stack + HandlerInstance inst{stack.top()}; + stack.pop(); + + // Call the end function of the last Handler + inst.handler->end(); + + // Call the "child" function of the parent Handler in the stack + // (if one exists). + if (!stack.empty()) { + stack.top().handler->child(inst.handler); + } +} + +void ParserStack::data(const char *data, int len) +{ + // Check whether there is any command the data can be sent to + if (stack.empty()) { + throw LoggableException{"No command to receive data."}; + } + + // Pass the data to the current Handler instance + stack.top().handler->data(data, len); +} +} +} + -- cgit v1.2.3 From 35554e6d32a5e66819f8a7bf869f1853e0d6fede Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 2 Dec 2014 14:59:44 +0100 Subject: continued working on the xml parser class --- src/core/parser/ParserStack.cpp | 3 ++- src/core/parser/ParserStack.hpp | 3 ++- src/plugins/xml/XmlParser.cpp | 43 ++++++++++++++++++++++++++++++++++++ test/core/BufferedCharReaderTest.cpp | 4 ++-- test/core/parser/ParserStackTest.cpp | 9 ++++---- 5 files changed, 54 insertions(+), 8 deletions(-) (limited to 'src/core/parser/ParserStack.cpp') diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp index 01fce3f..7bc7af3 100644 --- a/src/core/parser/ParserStack.cpp +++ b/src/core/parser/ParserStack.cpp @@ -100,7 +100,8 @@ void ParserStack::start(std::string name, char **attrs) const HandlerDescriptor *descr = nullptr; auto range = handlers.equal_range(name); for (auto it = range.first; it != range.second; it++) { - if (it->second.parentStates.count(curState)) { + const std::set &parentStates = it->second.parentStates; + if (parentStates.count(curState) || parentStates.count(STATE_ALL)) { descr = &(it->second); break; } diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp index a777b1e..18fc8d9 100644 --- a/src/core/parser/ParserStack.hpp +++ b/src/core/parser/ParserStack.hpp @@ -45,7 +45,7 @@ namespace parser { /** * The State type alias is used to */ -using State = int8_t; +using State = int16_t; static const State STATE_ALL = -2; static const State STATE_NONE = -1; @@ -140,6 +140,7 @@ public: * Handler instance. * * TODO: Replace with std::string? + * TODO: Per default: Allow no data except for whitespace characters! * * @param data is a pointer at the character data that is available for the * Handler instance. diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index f6891a8..42e0dd4 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -20,12 +20,55 @@ #include +#include + #include "XmlParser.hpp" namespace ousia { namespace parser { namespace xml { +/* Document structure */ +static const State STATE_DOCUMENT = 0; +static const State STATE_HEAD = 1; +static const State STATE_BODY = 2; + +/* Special commands */ +static const State STATE_USE = 100; +static const State STATE_INCLUDE = 101; +static const State STATE_INLINE = 102; + +/* Type system definitions */ +static const State STATE_TYPES = 200; +static const State STATE_CONSTANT = 201; +static const State STATE_ENUM = 202; +static const State STATE_STRUCT = 203; + +static Handler* createTestHandler(const ParserContext &ctx, + std::string name, State state, + State parentState, bool isChild) +{ + return nullptr; +} + +static const std::multimap XML_HANDLERS{ + /* Documents */ + {"document", {{STATE_NONE}, createTestHandler, STATE_DOCUMENT}}, + {"head", {{STATE_DOCUMENT}, createTestHandler, STATE_HEAD}}, + {"body", {{STATE_DOCUMENT}, createTestHandler, STATE_BODY, true}}, + + /* Special commands */ + {"use", {{STATE_HEAD}, createTestHandler, STATE_USE}}, + {"include", {{STATE_ALL}, createTestHandler, STATE_INCLUDE}}, + {"inline", {{STATE_ALL}, createTestHandler, STATE_INLINE}}, + + /* Typesystem definitions */ + {"types", {{STATE_NONE, STATE_HEAD}, createTestHandler, STATE_TYPES}}, + {"enum", {{STATE_TYPES}, createTestHandler, STATE_ENUM}}, + {"struct", {{STATE_TYPES}, createTestHandler, STATE_STRUCT}}, + {"constant", {{STATE_TYPES}, createTestHandler, STATE_CONSTANT}} +}; + /** * Wrapper class around the XML_Parser pointer which safely frees it whenever * the scope is left (e.g. because an exception was thrown). diff --git a/test/core/BufferedCharReaderTest.cpp b/test/core/BufferedCharReaderTest.cpp index b0955c2..b3498f7 100644 --- a/test/core/BufferedCharReaderTest.cpp +++ b/test/core/BufferedCharReaderTest.cpp @@ -1,6 +1,6 @@ /* - SCAENEA IDL Compiler (scidlc) - Copyright (C) 2014 Andreas Stöckel + 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 diff --git a/test/core/parser/ParserStackTest.cpp b/test/core/parser/ParserStackTest.cpp index 92249ff..1f4a4e2 100644 --- a/test/core/parser/ParserStackTest.cpp +++ b/test/core/parser/ParserStackTest.cpp @@ -1,6 +1,6 @@ /* - SCAENEA IDL Compiler (scidlc) - Copyright (C) 2014 Andreas Stöckel + 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 @@ -72,14 +72,13 @@ static Handler* createTestHandler(const ParserContext &ctx, return new TestHandler(ctx, name, state, parentState, isChild); } -// Two nested elements used for testing static const std::multimap TEST_HANDLERS{ {"document", {{STATE_NONE}, createTestHandler, STATE_DOCUMENT}}, {"body", {{STATE_DOCUMENT}, createTestHandler, STATE_BODY, true}}, {"empty", {{STATE_DOCUMENT}, createTestHandler, STATE_EMPTY}}, + {"special", {{STATE_ALL}, createTestHandler, STATE_EMPTY}}, }; - TEST(ParserStack, simpleTest) { StandaloneParserContext ctx; @@ -153,6 +152,8 @@ TEST(ParserStack, errorHandling) ASSERT_THROW(s.start("document", nullptr), OusiaException); s.start("empty", nullptr); ASSERT_THROW(s.start("body", nullptr), OusiaException); + s.start("special", nullptr); + s.end(); s.end(); s.end(); ASSERT_EQ(STATE_NONE, s.currentState()); -- cgit v1.2.3 From 59177921e8c81c1604e4154503a63190db66989c Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 3 Dec 2014 00:04:05 +0100 Subject: continued work on XML parser and underlying ParserStack class --- src/core/parser/ParserStack.cpp | 46 +++++++--------- src/core/parser/ParserStack.hpp | 57 ++++++++++++++------ src/plugins/xml/XmlParser.cpp | 102 +++++++++++++++++++++++------------ test/core/parser/ParserStackTest.cpp | 14 ++--- test/plugins/xml/XmlParserTest.cpp | 36 ++++++------- 5 files changed, 151 insertions(+), 104 deletions(-) (limited to 'src/core/parser/ParserStack.cpp') diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp index 7bc7af3..dca7f35 100644 --- a/src/core/parser/ParserStack.cpp +++ b/src/core/parser/ParserStack.cpp @@ -20,43 +20,37 @@ #include "ParserStack.hpp" +#include #include namespace ousia { namespace parser { +/* Class Handler */ + +void Handler::data(const std::string &data, int field) +{ + for (auto &c : data) { + if (!Utils::isWhitespace(c)) { + throw LoggableException{"No data allowed here."}; + } + } +} + /* Class HandlerDescriptor */ HandlerInstance HandlerDescriptor::create(const ParserContext &ctx, std::string name, State parentState, - bool isChild, char **attrs) const + bool isChild, + const Variant &args) const { Handler *h = ctor(ctx, name, targetState, parentState, isChild); - h->start(attrs); + h->start(args); return HandlerInstance(h, this); } /* Class ParserStack */ -/** - * Function used internally to turn the elements of a collection into a string - * separated by the given delimiter. - */ -template -static std::string join(T es, const std::string &delim) -{ - std::stringstream res; - bool first = true; - for (auto &e : es) { - if (!first) { - res << delim; - } - res << e; - first = false; - } - return res.str(); -} - /** * Returns an Exception that should be thrown when a currently invalid command * is thrown. @@ -73,7 +67,7 @@ static LoggableException invalidCommand(const std::string &name, std::string{"Expected "} + (expected.size() == 1 ? std::string{"\""} : std::string{"one of \""}) + - join(expected, "\", \"") + std::string{"\", but got \""} + name + + Utils::join(expected, "\", \"") + std::string{"\", but got \""} + name + std::string{"\""}}; } } @@ -89,7 +83,7 @@ std::set ParserStack::expectedCommands(State state) return res; } -void ParserStack::start(std::string name, char **attrs) +void ParserStack::start(std::string name, const Variant &args) { // Fetch the current handler and the current state const HandlerInstance *h = stack.empty() ? nullptr : &stack.top(); @@ -117,7 +111,7 @@ void ParserStack::start(std::string name, char **attrs) } // Instantiate the handler and call its start function - stack.emplace(descr->create(ctx, name, curState, isChild, attrs)); + stack.emplace(descr->create(ctx, name, curState, isChild, args)); } void ParserStack::end() @@ -141,7 +135,7 @@ void ParserStack::end() } } -void ParserStack::data(const char *data, int len) +void ParserStack::data(const std::string &data, int field) { // Check whether there is any command the data can be sent to if (stack.empty()) { @@ -149,7 +143,7 @@ void ParserStack::data(const char *data, int len) } // Pass the data to the current Handler instance - stack.top().handler->data(data, len); + stack.top().handler->data(data, field); } } } diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp index 18fc8d9..c5ed4e4 100644 --- a/src/core/parser/ParserStack.hpp +++ b/src/core/parser/ParserStack.hpp @@ -37,6 +37,8 @@ #include #include +#include + #include "Parser.hpp" namespace ousia { @@ -125,10 +127,9 @@ public: * Called when the command that was specified in the constructor is * instanciated. * - * @param attrs contains the attributes that were specified for the command. - * TODO: Replace with StructInstance! + * @param args is a map from strings to variants (argument name and value). */ - virtual void start(char **attrs) = 0; + virtual void start(const Variant &args) = 0; /** * Called whenever the command for which this handler @@ -137,15 +138,15 @@ public: /** * Called whenever raw data (int the form of a string) is available for the - * Handler instance. - * - * TODO: Replace with std::string? - * TODO: Per default: Allow no data except for whitespace characters! + * Handler instance. In the default handler an exception is raised if the + * received data contains non-whitespace characters. * * @param data is a pointer at the character data that is available for the * Handler instance. + * @param field is the field number (the interpretation of this value + * depends on the format that is being parsed). */ - virtual void data(const char *data, int len){}; + virtual void data(const std::string &data, int field); /** * Called whenever a direct child element was created and has ended. @@ -225,7 +226,8 @@ struct HandlerDescriptor { * HandlerDescriptor and calls its start function. */ HandlerInstance create(const ParserContext &ctx, std::string name, - State parentState, bool isChild, char **attrs) const; + State parentState, bool isChild, + const Variant &args) const; }; /** @@ -239,6 +241,11 @@ private: */ const ParserContext &ctx; + /** + * User specified data that will be passed to all handlers. + */ + void *userData; + /** * Map containing all registered command names and the corresponding * handler @@ -278,7 +285,8 @@ public: * @return the state of the currently active Handler instance or STATE_NONE * if no handler is on the stack. */ - State currentState() { + State currentState() + { return stack.empty() ? STATE_NONE : stack.top().handler->state; } @@ -288,7 +296,8 @@ public: * @return the name of the command currently being handled by the active * Handler instance or an empty string if no handler is currently active. */ - std::string currentName() { + std::string currentName() + { return stack.empty() ? std::string{} : stack.top().handler->name; } @@ -297,17 +306,33 @@ public: * * @return true if the handler allows arbitrary children, false otherwise. */ - bool currentArbitraryChildren() { + bool currentArbitraryChildren() + { return stack.empty() ? false : stack.top().descr->arbitraryChildren; } - // TODO: Change signature - void start(std::string name, char **attrs); + /** + * Function that should be called whenever a new command starts. + * + * @param name is the name of the command. + * @param args is a map from strings to variants (argument name and value). + */ + void start(std::string name, const Variant &args); + /** + * Function called whenever a command ends. + */ void end(); - // TODO: Change signature - void data(const char *data, int len); + /** + * Function that should be called whenever data is available for the + * command. + * + * @param data is the data that should be passed to the handler. + * @param field is the field number (the interpretation of this value + * depends on the format that is being parsed). + */ + void data(const std::string &data, int field = 0); }; } } diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index 42e0dd4..afc7f14 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -20,6 +20,7 @@ #include +#include #include #include "XmlParser.hpp" @@ -44,30 +45,54 @@ static const State STATE_CONSTANT = 201; static const State STATE_ENUM = 202; static const State STATE_STRUCT = 203; -static Handler* createTestHandler(const ParserContext &ctx, - std::string name, State state, - State parentState, bool isChild) +class TestHandler : public Handler { +public: + using Handler::Handler; + + void start(const Variant &args) override + { + std::cout << this->name << ": start (isChild: " << (this->isChild) + << ", args: " << args << ")" << std::endl; + } + + void end() override + { + // TODO + } + + void data(const std::string &data, int field) override + { + std::cout << this->name << ": data \"" << data << "\"" << std::endl; + } + + void child(std::shared_ptr handler) override + { + // TODO + } +}; + +static Handler *createTestHandler(const ParserContext &ctx, std::string name, + State state, State parentState, bool isChild) { - return nullptr; + return new TestHandler{ctx, name, state, parentState, isChild}; } static const std::multimap XML_HANDLERS{ - /* Documents */ - {"document", {{STATE_NONE}, createTestHandler, STATE_DOCUMENT}}, - {"head", {{STATE_DOCUMENT}, createTestHandler, STATE_HEAD}}, - {"body", {{STATE_DOCUMENT}, createTestHandler, STATE_BODY, true}}, - - /* Special commands */ - {"use", {{STATE_HEAD}, createTestHandler, STATE_USE}}, - {"include", {{STATE_ALL}, createTestHandler, STATE_INCLUDE}}, - {"inline", {{STATE_ALL}, createTestHandler, STATE_INLINE}}, - - /* Typesystem definitions */ - {"types", {{STATE_NONE, STATE_HEAD}, createTestHandler, STATE_TYPES}}, - {"enum", {{STATE_TYPES}, createTestHandler, STATE_ENUM}}, - {"struct", {{STATE_TYPES}, createTestHandler, STATE_STRUCT}}, - {"constant", {{STATE_TYPES}, createTestHandler, STATE_CONSTANT}} -}; + /* Documents */ + {"document", {{STATE_NONE}, createTestHandler, STATE_DOCUMENT}}, + {"head", {{STATE_DOCUMENT}, createTestHandler, STATE_HEAD}}, + {"body", {{STATE_DOCUMENT}, createTestHandler, STATE_BODY, true}}, + + /* Special commands */ + {"use", {{STATE_HEAD}, createTestHandler, STATE_USE}}, + {"include", {{STATE_ALL}, createTestHandler, STATE_INCLUDE}}, + {"inline", {{STATE_ALL}, createTestHandler, STATE_INLINE}}, + + /* Typesystem definitions */ + {"typesystem", {{STATE_NONE, STATE_HEAD}, createTestHandler, STATE_TYPES}}, + {"enum", {{STATE_TYPES}, createTestHandler, STATE_ENUM}}, + {"struct", {{STATE_TYPES}, createTestHandler, STATE_STRUCT}}, + {"constant", {{STATE_TYPES}, createTestHandler, STATE_CONSTANT}}}; /** * Wrapper class around the XML_Parser pointer which safely frees it whenever @@ -89,8 +114,7 @@ public: * @param encoding is the protocol-defined encoding passed to expat (or * nullptr if expat should determine the encoding by itself). */ - ScopedExpatXmlParser(const XML_Char *encoding) - : parser(nullptr) + ScopedExpatXmlParser(const XML_Char *encoding) : parser(nullptr) { parser = XML_ParserCreate(encoding); if (!parser) { @@ -116,28 +140,36 @@ public: XML_Parser operator&() { return parser; } }; +/* Adapter Expat -> ParserStack */ + static void xmlStartElementHandler(void *userData, const XML_Char *name, const XML_Char **attrs) { - std::cout << "start tag: " << name << std::endl; + Variant::mapType args; const XML_Char **attr = attrs; while (*attr) { - std::cout << "\t" << *attr; - attr++; - std::cout << " -> " << *attr << std::endl; - attr++; + const std::string key{*(attr++)}; + args.emplace(std::make_pair(key, Variant{*(attr++)})); } + (static_cast(userData))->start(std::string(name), args); } -static void xmlEndElementHandler(void *userData, const XML_Char *name) { - std::cout << "end tag: " << name << std::endl; +static void xmlEndElementHandler(void *userData, const XML_Char *name) +{ + (static_cast(userData))->end(); } - -static void xmlCharacterDataHandler(void *userData, const XML_Char *s, int len) { - std::cout << "\tdata: " << std::string(s, len) << std::endl; +static void xmlCharacterDataHandler(void *userData, const XML_Char *s, int len) +{ + const std::string data = + Utils::trim(std::string{s, static_cast(len)}); + if (!data.empty()) { + (static_cast(userData))->data(data); + } } +/* Class XmlParser */ + std::set XmlParser::mimetypes() { return std::set{{"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"}}; @@ -147,7 +179,11 @@ Rooted XmlParser::parse(std::istream &is, ParserContext &ctx) { // Create the parser object ScopedExpatXmlParser p{"UTF-8"}; - XML_SetUserData(&p, &ctx); + + // Create the parser stack instance and pass the reference to the state + // machine descriptor + ParserStack stack{ctx, XML_HANDLERS}; + XML_SetUserData(&p, &stack); // Set the callback functions XML_SetStartElementHandler(&p, xmlStartElementHandler); diff --git a/test/core/parser/ParserStackTest.cpp b/test/core/parser/ParserStackTest.cpp index 1f4a4e2..5dab979 100644 --- a/test/core/parser/ParserStackTest.cpp +++ b/test/core/parser/ParserStackTest.cpp @@ -39,28 +39,24 @@ class TestHandler : public Handler { public: using Handler::Handler; - void start(char **attrs) override + void start(const Variant &args) override { startCount++; -// std::cout << this->name << ": start (isChild: " << (this->isChild) << ")" << std::endl; } void end() override { endCount++; -// std::cout << this->name << ": end " << std::endl; } - void data(const char *data, int len) override + void data(const std::string &data, int field) override { dataCount++; -// std::cout << this->name << ": data \"" << std::string{data, static_cast(len)} << "\"" << std::endl; } void child(std::shared_ptr handler) override { childCount++; -// std::cout << this->name << ": has child \"" << handler->name << "\"" << std::endl; } }; @@ -93,7 +89,7 @@ TEST(ParserStack, simpleTest) ASSERT_EQ(STATE_NONE, s.currentState()); s.start("document", nullptr); - s.data("test1", 5); + s.data("test1"); ASSERT_EQ("document", s.currentName()); ASSERT_EQ(STATE_DOCUMENT, s.currentState()); @@ -101,7 +97,7 @@ TEST(ParserStack, simpleTest) ASSERT_EQ(1, dataCount); s.start("body", nullptr); - s.data("test2", 5); + s.data("test2"); ASSERT_EQ("body", s.currentName()); ASSERT_EQ(STATE_BODY, s.currentState()); ASSERT_EQ(2, startCount); @@ -123,7 +119,7 @@ TEST(ParserStack, simpleTest) ASSERT_EQ(STATE_DOCUMENT, s.currentState()); s.start("body", nullptr); - s.data("test3", 5); + s.data("test3"); ASSERT_EQ("body", s.currentName()); ASSERT_EQ(STATE_BODY, s.currentState()); s.end(); diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index 98a5a34..ecc9438 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -26,26 +26,14 @@ namespace ousia { namespace parser { namespace xml { -struct TestParserContext : public ParserContext { - -private: - Logger log; - Registry r; - Scope s; - -public: - TestParserContext() : ParserContext(s, r, log), r(log), s(nullptr) {}; - -}; - TEST(XmlParser, mismatchedTagException) { - TestParserContext ctx; + StandaloneParserContext ctx; XmlParser p; bool hadException = false; try { - p.parse("data\n", ctx); + p.parse("\n", ctx); } catch (ParserException ex) { ASSERT_EQ(2, ex.line); @@ -55,19 +43,27 @@ TEST(XmlParser, mismatchedTagException) ASSERT_TRUE(hadException); } -const char* TEST_DATA = "\n" - "\n" - " \n" - "\n"; +const char *TEST_DATA = + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " Dies ist ein Test>\n" + " \n" + "\n"; TEST(XmlParser, namespaces) { - TestParserContext ctx; + StandaloneParserContext ctx; XmlParser p; p.parse(TEST_DATA, ctx); } - } } } -- cgit v1.2.3