diff --git a/test/XPath/match_test.hpp b/test/XPath/match_test.hpp new file mode 100644 index 00000000..09981edf --- /dev/null +++ b/test/XPath/match_test.hpp @@ -0,0 +1,113 @@ +#ifndef XPATHIC_MATCH_TEST_HPP +#define XPATHIC_MATCH_TEST_HPP + +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include +#include + + +template +class MatchTest : public TestCase +{ + Arabica::XPath::XPath parser; + typedef string_adaptor SA; + +public: + MatchTest(std::string name) : TestCase(name) + { + } // MatchTest + + void setUp() + { + } // setUp + + void testParse() + { + using namespace Arabica::XPath; + assertTrue(compileThis("/")); + assertTrue(compileThis("/element")); + assertTrue(compileThis("//element")); + assertTrue(compileThis("node()")); + assertTrue(compileThis("text()")); + assertTrue(compileThis("element")); + assertTrue(compileThis("element/child")); + assertTrue(compileThis("/element/child")); + assertTrue(compileThis("//element/child")); + assertTrue(compileThis("/element//child")); + assertTrue(compileThis("//element//child")); + assertTrue(compileThis("element/child/child")); + assertTrue(compileThis("/element/child/child")); + assertTrue(compileThis("//element/child/child")); + assertTrue(compileThis("/element//child/child")); + assertTrue(compileThis("//element//child/child")); + assertTrue(compileThis("//element//child//child")); + assertTrue(compileThis("element[@ref]")); + assertTrue(compileThis("element[@type]|element[complexType]|attribute")); + assertTrue(compileThis("node()|@*")); + assertTrue(compileThis("hello")); + assertTrue(compileThis("@hello")); + assertTrue(compileThis("child::hello")); + assertTrue(compileThis("attribute::hello")); + assertTrue(compileThis("node()|attribute::*")); + } // testParse + + void testParseFails() + { + std::cerr << "\n\n\ntestParseFails"; + using namespace Arabica::XPath; + assertTrue(dontCompileThis("boolean(../hello)")); + assertTrue(dontCompileThis("../hello")); + assertTrue(dontCompileThis("following-sibling::hello")); + assertTrue(dontCompileThis("descendant::hello")); + assertTrue(dontCompileThis("ancestor-or-self::hello")); + assertTrue(dontCompileThis("///")); + assertTrue(dontCompileThis("test///test")); + assertTrue(dontCompileThis("descendant-or-self::element")); + assertTrue(dontCompileThis("//element/following-sibling::trousers")); + } // testParseFails + + bool dontCompileThis(const char* path) + { + try { + parser.compile_match(SA::construct_from_utf8(path)); + return false; + } + catch(const Arabica::XPath::SyntaxException& ex) { + std::cerr << ex.what() << std::endl; + } + return true; + } // dontCompileThis + + bool compileThis(const char* path) + { + try { + parser.compile_match(SA::construct_from_utf8(path)); + return true; + } + catch(const Arabica::XPath::UnsupportedException&) { + return true; + } + catch(const Arabica::XPath::SyntaxException& ex) { + std::cerr << ex.what() << std::endl; + } + return false; + } // compileThis + +}; // class MatchTest + +template +TestSuite* MatchTest_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller >("testParse", &MatchTest::testParse)); + suiteOfTests->addTest(new TestCaller >("testParseFail", &MatchTest::testParseFails)); + + return suiteOfTests; +} // MatchTest_suite + +#endif + diff --git a/test/XPath/xpath_test_suite.hpp b/test/XPath/xpath_test_suite.hpp index dc7f843a..5d625617 100644 --- a/test/XPath/xpath_test_suite.hpp +++ b/test/XPath/xpath_test_suite.hpp @@ -15,6 +15,7 @@ #include "step_test.hpp" #include "execute_test.hpp" #include "expression_test.hpp" +#include "match_test.hpp" template @@ -32,6 +33,7 @@ void XPath_test_suite(int argc, const char** argv) runner.addTest("ParseTest", ParseTest_suite()); runner.addTest("ExecuteTest", ExecuteTest_suite()); runner.addTest("ExpressionTest", ExpressionTest_suite()); + runner.addTest("MatchTest", MatchTest_suite()); runner.run(argc, argv); } // XPath_test_suite diff --git a/test/XPath/xpathic.vcproj b/test/XPath/xpathic.vcproj index cab2dd71..e043ab78 100644 --- a/test/XPath/xpathic.vcproj +++ b/test/XPath/xpathic.vcproj @@ -133,6 +133,39 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + + + + + + + + + + + + + + + + + + + + + +