From 3b2aea864c4e47bdcfc4bca167d754aa0ef51248 Mon Sep 17 00:00:00 2001 From: jez_higgins <> Date: Thu, 4 Aug 2005 21:23:48 +0000 Subject: [PATCH] moved here from xpath-dev-sandbox --- test/CppUnit/framework/CppUnitException.h | 92 + test/CppUnit/framework/Guards.h | 12 + test/CppUnit/framework/Test.h | 50 + test/CppUnit/framework/TestCaller.h | 75 + test/CppUnit/framework/TestCase.cpp | 129 + test/CppUnit/framework/TestCase.h | 225 ++ test/CppUnit/framework/TestFailure.cpp | 9 + test/CppUnit/framework/TestFailure.h | 72 + test/CppUnit/framework/TestResult.cpp | 17 + test/CppUnit/framework/TestResult.h | 175 ++ test/CppUnit/framework/TestSuite.cpp | 48 + test/CppUnit/framework/TestSuite.h | 77 + test/CppUnit/framework/estring.h | 32 + test/CppUnit/framework/extensions/Orthodox.h | 93 + .../framework/extensions/RepeatedTest.h | 62 + .../framework/extensions/TestDecorator.h | 63 + test/CppUnit/framework/extensions/TestSetup.h | 36 + test/CppUnit/textui/TestRunner.cpp | 146 + test/CppUnit/textui/TextTestResult.cpp | 110 + test/CppUnit/textui/TextTestResult.h | 30 + test/XPath/.cvsignore | 6 + test/XPath/arithmetic_test.cpp | 188 ++ test/XPath/arithmetic_test.hpp | 7 + test/XPath/axis_enumerator_test.cpp | 947 +++++++ test/XPath/axis_enumerator_test.hpp | 7 + test/XPath/execute_test.cpp | 2374 +++++++++++++++++ test/XPath/execute_test.hpp | 7 + test/XPath/logical_test.cpp | 89 + test/XPath/logical_test.hpp | 6 + test/XPath/main.cpp | 167 ++ test/XPath/node_test_test.cpp | 263 ++ test/XPath/node_test_test.hpp | 6 + test/XPath/parse_test.cpp | 394 +++ test/XPath/parse_test.hpp | 7 + test/XPath/relational_test.cpp | 189 ++ test/XPath/relational_test.hpp | 6 + test/XPath/step_test.cpp | 109 + test/XPath/step_test.hpp | 6 + test/XPath/value_test.cpp | 146 + test/XPath/value_test.hpp | 7 + test/XPath/xpathic.vcproj | 246 ++ 41 files changed, 6730 insertions(+) create mode 100644 test/CppUnit/framework/CppUnitException.h create mode 100644 test/CppUnit/framework/Guards.h create mode 100644 test/CppUnit/framework/Test.h create mode 100644 test/CppUnit/framework/TestCaller.h create mode 100644 test/CppUnit/framework/TestCase.cpp create mode 100644 test/CppUnit/framework/TestCase.h create mode 100644 test/CppUnit/framework/TestFailure.cpp create mode 100644 test/CppUnit/framework/TestFailure.h create mode 100644 test/CppUnit/framework/TestResult.cpp create mode 100644 test/CppUnit/framework/TestResult.h create mode 100644 test/CppUnit/framework/TestSuite.cpp create mode 100644 test/CppUnit/framework/TestSuite.h create mode 100644 test/CppUnit/framework/estring.h create mode 100644 test/CppUnit/framework/extensions/Orthodox.h create mode 100644 test/CppUnit/framework/extensions/RepeatedTest.h create mode 100644 test/CppUnit/framework/extensions/TestDecorator.h create mode 100644 test/CppUnit/framework/extensions/TestSetup.h create mode 100644 test/CppUnit/textui/TestRunner.cpp create mode 100644 test/CppUnit/textui/TextTestResult.cpp create mode 100644 test/CppUnit/textui/TextTestResult.h create mode 100644 test/XPath/.cvsignore create mode 100644 test/XPath/arithmetic_test.cpp create mode 100644 test/XPath/arithmetic_test.hpp create mode 100644 test/XPath/axis_enumerator_test.cpp create mode 100644 test/XPath/axis_enumerator_test.hpp create mode 100644 test/XPath/execute_test.cpp create mode 100644 test/XPath/execute_test.hpp create mode 100644 test/XPath/logical_test.cpp create mode 100644 test/XPath/logical_test.hpp create mode 100644 test/XPath/main.cpp create mode 100644 test/XPath/node_test_test.cpp create mode 100644 test/XPath/node_test_test.hpp create mode 100644 test/XPath/parse_test.cpp create mode 100644 test/XPath/parse_test.hpp create mode 100644 test/XPath/relational_test.cpp create mode 100644 test/XPath/relational_test.hpp create mode 100644 test/XPath/step_test.cpp create mode 100644 test/XPath/step_test.hpp create mode 100644 test/XPath/value_test.cpp create mode 100644 test/XPath/value_test.hpp create mode 100644 test/XPath/xpathic.vcproj diff --git a/test/CppUnit/framework/CppUnitException.h b/test/CppUnit/framework/CppUnitException.h new file mode 100644 index 00000000..c572fc3c --- /dev/null +++ b/test/CppUnit/framework/CppUnitException.h @@ -0,0 +1,92 @@ + +#ifndef CPPUNIT_CPPUNITEXCEPTION_H +#define CPPUNIT_CPPUNITEXCEPTION_H + + +/* + * CppUnitException is an exception that serves + * descriptive strings through its what () method + * + */ + +#include +#include + +#define CPPUNIT_UNKNOWNFILENAME "" +#define CPPUNIT_UNKNOWNLINENUMBER (-1) + +class CppUnitException : public std::exception +{ +public: + CppUnitException (std::string message = "", + long lineNumber = CPPUNIT_UNKNOWNLINENUMBER, + std::string fileName = CPPUNIT_UNKNOWNFILENAME); + CppUnitException (const CppUnitException& other); + + virtual ~CppUnitException () throw(); + + CppUnitException& operator= (const CppUnitException& other); + + const char *what() const throw (); + + long lineNumber (); + std::string fileName (); + +private: + std::string m_message; + long m_lineNumber; + std::string m_fileName; + +}; + + +// Construct the exception +inline CppUnitException::CppUnitException (const CppUnitException& other) +: std::exception (other) +{ + m_message = other.m_message; + m_lineNumber = other.m_lineNumber; + m_fileName = other.m_fileName; +} + +inline CppUnitException::CppUnitException (std::string message, long lineNumber, std::string fileName) +: m_message (message), m_lineNumber (lineNumber), m_fileName (fileName) +{} + + +// Destruct the exception +inline CppUnitException::~CppUnitException () throw () +{} + + +// Perform an assignment +inline CppUnitException& CppUnitException::operator= (const CppUnitException& other) +{ + exception::operator=(other); + + if (&other != this) { + m_message = other.m_message; + m_lineNumber = other.m_lineNumber; + m_fileName = other.m_fileName; + } + + return *this; +} + + +// Return descriptive message +inline const char *CppUnitException::what() const throw () +{ return m_message.c_str (); } + +// The line on which the error occurred +inline long CppUnitException::lineNumber () +{ return m_lineNumber; } + + +// The file in which the error occurred +inline std::string CppUnitException::fileName () +{ return m_fileName; } + + +#endif + diff --git a/test/CppUnit/framework/Guards.h b/test/CppUnit/framework/Guards.h new file mode 100644 index 00000000..5307fe29 --- /dev/null +++ b/test/CppUnit/framework/Guards.h @@ -0,0 +1,12 @@ + + +#ifndef CPPUNIT_GUARDS_H +#define CPPUNIT_GUARDS_H + +// Prevent copy construction and assignment for a class +#define REFERENCEOBJECT(className) \ +private: \ + className (const className& other); \ + className& operator= (const className& other); + +#endif diff --git a/test/CppUnit/framework/Test.h b/test/CppUnit/framework/Test.h new file mode 100644 index 00000000..b513103d --- /dev/null +++ b/test/CppUnit/framework/Test.h @@ -0,0 +1,50 @@ + + +#ifndef CPPUNIT_TEST_H +#define CPPUNIT_TEST_H + +#include + +class TestResult; + +/* + * A Test can be run and collect its results. + * See TestResult. + * + */ + + +class Test +{ +public: + virtual ~Test () = 0; + + virtual void run (TestResult *result) = 0; + virtual int countTestCases () = 0; + virtual std::string toString () = 0; + + +}; + +inline Test::~Test () +{} + + + +// Runs a test and collects its result in a TestResult instance. +inline void Test::run (TestResult *result) +{} + + +// Counts the number of test cases that will be run by this test. +inline int Test::countTestCases () +{ return 0; } + + +// Returns the name of the test instance. +inline std::string Test::toString () +{ return ""; } + + +#endif + diff --git a/test/CppUnit/framework/TestCaller.h b/test/CppUnit/framework/TestCaller.h new file mode 100644 index 00000000..da9effbe --- /dev/null +++ b/test/CppUnit/framework/TestCaller.h @@ -0,0 +1,75 @@ + +#ifndef CPPUNIT_TESTCALLER_H +#define CPPUNIT_TESTCALLER_H + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TESTCASE_H +#include "TestCase.h" +#endif + +/* + * A test caller provides access to a test case method + * on a test case class. Test callers are useful when + * you want to run an individual test or add it to a + * suite. + * + * Here is an example: + * + * class MathTest : public TestCase { + * ... + * public: + * void setUp (); + * void tearDown (); + * + * void testAdd (); + * void testSubtract (); + * }; + * + * Test *MathTest::suite () { + * TestSuite *suite = new TestSuite; + * + * suite->addTest (new TestCaller ("testAdd", testAdd)); + * return suite; + * } + * + * You can use a TestCaller to bind any test method on a TestCase + * class, as long as it returns accepts void and returns void. + * + * See TestCase + */ + + +template class TestCaller : public TestCase +{ + REFERENCEOBJECT (TestCaller) + + typedef void (Fixture::*TestMethod)(); + +public: + TestCaller (std::string name, TestMethod test) + : TestCase (name), m_fixture (new Fixture (name)), m_test (test) + {} + +protected: + void runTest () + { (m_fixture.get ()->*m_test)(); } + + void setUp () + { m_fixture.get ()->setUp (); } + + void tearDown () + { m_fixture.get ()->tearDown (); } + +private: + std::auto_ptr m_fixture; + TestMethod m_test; + +}; + + + +#endif + diff --git a/test/CppUnit/framework/TestCase.cpp b/test/CppUnit/framework/TestCase.cpp new file mode 100644 index 00000000..0c12571c --- /dev/null +++ b/test/CppUnit/framework/TestCase.cpp @@ -0,0 +1,129 @@ + +#include +#include +#include + +#include "TestCase.h" +#include "TestResult.h" +#include "estring.h" + + + +// Create a default TestResult +TestResult *TestCase::defaultResult () +{ return new TestResult; } + + +// Check for a failed general assertion +void TestCase::assertImplementation (bool condition, + std::string conditionExpression, + long lineNumber, + std::string fileName) +{ + if (!condition) + throw CppUnitException (conditionExpression, lineNumber, fileName); +} + +// Check for a failed equality assertion +void TestCase::assertEquals (std::string expected, + std::string actual, + long lineNumber, + std::string fileName) +{ + if (expected != actual) + assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); +} + + +// Check for a failed equality assertion +void TestCase::assertEquals (long expected, + long actual, + long lineNumber, + std::string fileName) +{ + if (expected != actual) + assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); +} + + +// Check for a failed equality assertion +void TestCase::assertEquals (double expected, + double actual, + double delta, + long lineNumber, + std::string fileName) +{ + if (fabs (expected - actual) > delta) + assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); + +} + + +// Run the test and catch any exceptions that are triggered by it +void TestCase::run (TestResult *result) +{ + result->startTest (this); + + setUp (); + + try { + runTest (); + + } + catch (const CppUnitException& e) { + CppUnitException *copy = new CppUnitException (e); + result->addFailure (this, copy); + + } + catch (const std::exception& e) { + result->addError (this, new CppUnitException (e.what ())); + + } + catch (...) { + CppUnitException *e = new CppUnitException ("unknown exception"); + result->addError (this, e); + + } + + tearDown (); + + result->endTest (this); + +} + + +// A default run method +TestResult *TestCase::run () +{ + TestResult *result = defaultResult (); + + run (result); + return result; + +} + + +// All the work for runTest is deferred to subclasses +void TestCase::runTest () +{ +} + + +// Build a message about a failed equality check +std::string TestCase::notEqualsMessage (long expected, long actual) +{ + return "expected: " + estring (expected) + " but was: " + estring (actual); +} + + +// Build a message about a failed equality check +std::string TestCase::notEqualsMessage (double expected, double actual) +{ + return "expected: " + estring (expected) + " but was: " + estring (actual); +} + +std::string TestCase::notEqualsMessage (std::string expected, std::string actual) +{ + return "expected: " + expected + " but was: " + actual; +} + diff --git a/test/CppUnit/framework/TestCase.h b/test/CppUnit/framework/TestCase.h new file mode 100644 index 00000000..34b78e11 --- /dev/null +++ b/test/CppUnit/framework/TestCase.h @@ -0,0 +1,225 @@ + +#ifndef CPPUNIT_TESTCASE_H +#define CPPUNIT_TESTCASE_H + +#include +#include + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TEST_H +#include "Test.h" +#endif + +#ifndef CPPUNIT_CPPUNITEXCEPTION_H +#include "CppUnitException.h" +#endif + +class TestResult; + + + +/* + * A test case defines the fixture to run multiple tests. To define a test case + * 1) implement a subclass of TestCase + * 2) define instance variables that store the state of the fixture + * 3) initialize the fixture state by overriding setUp + * 4) clean-up after a test by overriding tearDown. + * + * Each test runs in its own fixture so there + * can be no side effects among test runs. + * Here is an example: + * + * class MathTest : public TestCase { + * protected: int m_value1; + * protected: int m_value2; + * + * public: MathTest (string name) + * : TestCase (name) { + * } + * + * protected: void setUp () { + * m_value1 = 2; + * m_value2 = 3; + * } + * } + * + * + * For each test implement a method which interacts + * with the fixture. Verify the expected results with assertions specified + * by calling assert on the expression you want to test: + * + * protected: void testAdd () { + * int result = value1 + value2; + * assert (result == 5); + * } + * + * Once the methods are defined you can run them. To do this, use + * a TestCaller. + * + * Test *test = new TestCaller("testAdd", MathTest::testAdd); + * test->run (); + * + * + * The tests to be run can be collected into a TestSuite. CppUnit provides + * different test runners which can run a test suite and collect the results. + * The test runners expect a static method suite as the entry + * point to get a test to run. + * + * public: static MathTest::suite () { + * TestSuite *suiteOfTests = new TestSuite; + * suiteOfTests->addTest(new TestCaller("testAdd", testAdd)); + * suiteOfTests->addTest(new TestCaller("testDivideByZero", testDivideByZero)); + * return suiteOfTests; + * } + * + * Note that the caller of suite assumes lifetime control + * for the returned suite. + * + * see TestResult, TestSuite and TestCaller + * + */ + + +class TestCase : public Test +{ + REFERENCEOBJECT (TestCase) + +public: + TestCase (std::string Name); + ~TestCase (); + + virtual void run (TestResult *result); + virtual TestResult *run (); + virtual int countTestCases (); + std::string name (); + std::string toString (); + + virtual void setUp (); + virtual void tearDown (); + +protected: + virtual void runTest (); + + TestResult *defaultResult (); + void assertImplementation + (bool condition, + std::string conditionExpression = "", + long lineNumber = CPPUNIT_UNKNOWNLINENUMBER, + std::string fileName = CPPUNIT_UNKNOWNFILENAME); + + void assertEquals (long expected, + long actual, + long lineNumber = CPPUNIT_UNKNOWNLINENUMBER, + std::string fileName = CPPUNIT_UNKNOWNFILENAME); + + void assertEquals (double expected, + double actual, + double delta, + long lineNumber = CPPUNIT_UNKNOWNLINENUMBER, + std::string fileName = CPPUNIT_UNKNOWNFILENAME); + + void assertEquals (std::string expected, + std::string actual, + long lineNumber = CPPUNIT_UNKNOWNLINENUMBER, + std::string fileName = CPPUNIT_UNKNOWNFILENAME); + + std::string notEqualsMessage (long expected, + long actual); + + std::string notEqualsMessage (double expected, + double actual); + + std::string notEqualsMessage (std::string expected, + std::string actual); + +private: + const std::string m_name; + + + +}; + + +// Constructs a test case +inline TestCase::TestCase (std::string name) +: m_name (name) +{} + + +// Destructs a test case +inline TestCase::~TestCase () +{} + + +// Returns a count of all the tests executed +inline int TestCase::countTestCases () +{ return 1; } + + +// Returns the name of the test case +inline std::string TestCase::name () +{ return m_name; } + + +// A hook for fixture set up +inline void TestCase::setUp () +{} + + +// A hook for fixture tear down +inline void TestCase::tearDown () +{} + + +// Returns the name of the test case instance +inline std::string TestCase::toString () +{ const std::type_info& thisClass = typeid (*this); return std::string (thisClass.name ()) + "." + name (); } + + + +// A set of macros which allow us to get the line number +// and file name at the point of an error. +// Just goes to show that preprocessors do have some +// redeeming qualities. + +#define CPPUNIT_SOURCEANNOTATION + +#ifdef CPPUNIT_SOURCEANNOTATION + +#undef assert + #define assert(condition)\ + (this->assertImplementation ((condition),(#condition),\ + __LINE__, __FILE__)) + #define assertTrue(condition)\ + (this->assertImplementation ((condition),(#condition),\ + __LINE__, __FILE__)) + +#else + + #undef assert + #define assert(condition)\ + (this->assertImplementation ((condition),"",\ + __LINE__, __FILE__)) + +#endif + + +// Macros for primitive value comparison +#define assertDoublesEqual(expected,actual,delta)\ +(this->assertEquals ((expected),\ + (actual),(delta),__LINE__,__FILE__)) + +#define assertLongsEqual(expected,actual)\ +(this->assertEquals ((expected),\ + (actual),__LINE__,__FILE__)) + +#define assertValuesEqual(expected,actual)\ +(this->assertEquals ((expected),\ + (actual),__LINE__,__FILE__)) + + +#endif + diff --git a/test/CppUnit/framework/TestFailure.cpp b/test/CppUnit/framework/TestFailure.cpp new file mode 100644 index 00000000..848df468 --- /dev/null +++ b/test/CppUnit/framework/TestFailure.cpp @@ -0,0 +1,9 @@ + +#include "TestFailure.h" +#include "Test.h" + +// Returns a short description of the failure. +std::string TestFailure::toString () +{ + return m_failedTest->toString () + ": " + m_thrownException->what (); +} diff --git a/test/CppUnit/framework/TestFailure.h b/test/CppUnit/framework/TestFailure.h new file mode 100644 index 00000000..8f3939a4 --- /dev/null +++ b/test/CppUnit/framework/TestFailure.h @@ -0,0 +1,72 @@ + + +#ifndef CPPUNIT_TESTFAILURE_H +#define CPPUNIT_TESTFAILURE_H + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_EXCEPTION_H +#include "CppUnitException.h" +#endif + +class Test; + + +/* + * A TestFailure collects a failed test together with + * the caught exception. + * + * TestFailure assumes lifetime control for any exception + * passed to it. The lifetime of tests is handled by + * their TestSuite (if they have been added to one) or + * whomever creates them. + * + * see TestResult + * see TestSuite + * + */ + +class TestFailure +{ + REFERENCEOBJECT (TestFailure) + +public: + TestFailure (Test *failedTest, CppUnitException *thrownException); + ~TestFailure (); + + Test *failedTest (); + CppUnitException *thrownException (); + std::string toString (); + +protected: + Test *m_failedTest; + CppUnitException *m_thrownException; + +}; + + +// Constructs a TestFailure with the given test and exception. +inline TestFailure::TestFailure (Test *failedTest, CppUnitException *thrownException) + : m_failedTest (failedTest), m_thrownException (thrownException) +{} + + +// Deletes the owned exception. +inline TestFailure::~TestFailure () +{ delete m_thrownException; } + + +// Gets the failed test. +inline Test *TestFailure::failedTest () +{ return m_failedTest; } + + +// Gets the thrown exception. +inline CppUnitException *TestFailure::thrownException () +{ return m_thrownException; } + + +#endif + diff --git a/test/CppUnit/framework/TestResult.cpp b/test/CppUnit/framework/TestResult.cpp new file mode 100644 index 00000000..32839e93 --- /dev/null +++ b/test/CppUnit/framework/TestResult.cpp @@ -0,0 +1,17 @@ + + +#include "TestResult.h" + +// Destroys a test result +TestResult::~TestResult () +{ + std::vector::iterator it; + + for (it = m_errors.begin (); it != m_errors.end (); ++it) + delete *it; + + for (it = m_failures.begin (); it != m_failures.end (); ++it) + delete *it; + + delete m_syncObject; +} diff --git a/test/CppUnit/framework/TestResult.h b/test/CppUnit/framework/TestResult.h new file mode 100644 index 00000000..72a1ff9f --- /dev/null +++ b/test/CppUnit/framework/TestResult.h @@ -0,0 +1,175 @@ + +#ifndef CPPUNIT_TESTRESULT_H +#define CPPUNIT_TESTRESULT_H + +#include + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TESTFAILURE_H +#include "TestFailure.h" +#endif + + +class CppUnitException; +class Test; + + +/* + * A TestResult collects the results of executing a test case. It is an + * instance of the Collecting Parameter pattern. + * + * The test framework distinguishes between failures and errors. + * A failure is anticipated and checked for with assertions. Errors are + * unanticipated problems signified by exceptions that are not generated + * by the framework. + * + * TestResult supplies a template method 'setSynchronizationObject ()' + * so that subclasses can provide mutual exclusion in the face of multiple + * threads. This can be useful when tests execute in one thread and + * they fill a subclass of TestResult which effects change in another + * thread. To have mutual exclusion, override setSynchronizationObject () + * and make sure that you create an instance of ExclusiveZone at the + * beginning of each method. + * + * see Test + */ + +class TestResult +{ + REFERENCEOBJECT (TestResult) + +public: + TestResult (); + virtual ~TestResult (); + + virtual void addError (Test *test, CppUnitException *e); + virtual void addFailure (Test *test, CppUnitException *e); + virtual void startTest (Test *test); + virtual void endTest (Test *test); + virtual int runTests (); + virtual int testErrors (); + virtual int testFailures (); + virtual bool wasSuccessful (); + virtual bool shouldStop (); + virtual void stop (); + + virtual std::vector& errors (); + virtual std::vector& failures (); + + + class SynchronizationObject + { + public: + SynchronizationObject () {} + virtual ~SynchronizationObject () {} + + virtual void lock () {} + virtual void unlock () {} + }; + + class ExclusiveZone + { + SynchronizationObject *m_syncObject; + + public: + ExclusiveZone (SynchronizationObject *syncObject) + : m_syncObject (syncObject) + { m_syncObject->lock (); } + + ~ExclusiveZone () + { m_syncObject->unlock (); } + }; + +protected: + virtual void setSynchronizationObject (SynchronizationObject *syncObject); + + std::vector m_errors; + std::vector m_failures; + int m_runTests; + bool m_stop; + SynchronizationObject *m_syncObject; + +}; + + + +// Construct a TestResult +inline TestResult::TestResult () +: m_syncObject (new SynchronizationObject ()) +{ m_runTests = 0; m_stop = false; } + + +// Adds an error to the list of errors. The passed in exception +// caused the error +inline void TestResult::addError (Test *test, CppUnitException *e) +{ ExclusiveZone zone (m_syncObject); m_errors.push_back (new TestFailure (test, e)); } + + +// Adds a failure to the list of failures. The passed in exception +// caused the failure. +inline void TestResult::addFailure (Test *test, CppUnitException *e) +{ ExclusiveZone zone (m_syncObject); m_failures.push_back (new TestFailure (test, e)); } + + +// Informs the result that a test will be started. +inline void TestResult::startTest (Test *test) +{ ExclusiveZone zone (m_syncObject); m_runTests++; } + + +// Informs the result that a test was completed. +inline void TestResult::endTest (Test *test) +{ ExclusiveZone zone (m_syncObject); } + + +// Gets the number of run tests. +inline int TestResult::runTests () +{ ExclusiveZone zone (m_syncObject); return m_runTests; } + + +// Gets the number of detected errors. +inline int TestResult::testErrors () +{ ExclusiveZone zone (m_syncObject); return static_cast(m_errors.size()); } + + +// Gets the number of detected failures. +inline int TestResult::testFailures () +{ ExclusiveZone zone (m_syncObject); return static_cast(m_failures.size()); } + + +// Returns whether the entire test was successful or not. +inline bool TestResult::wasSuccessful () +{ ExclusiveZone zone (m_syncObject); return m_failures.size () == 0 && m_errors.size () == 0; } + + +// Returns a vector of the errors. +inline std::vector& TestResult::errors () +{ ExclusiveZone zone (m_syncObject); return m_errors; } + + +// Returns a vector of the failures. +inline std::vector& TestResult::failures () +{ ExclusiveZone zone (m_syncObject); return m_failures; } + + +// Returns whether testing should be stopped +inline bool TestResult::shouldStop () +{ ExclusiveZone zone (m_syncObject); return m_stop; } + + +// Stop testing +inline void TestResult::stop () +{ ExclusiveZone zone (m_syncObject); m_stop = true; } + + +// Accept a new synchronization object for protection of this instance +// TestResult assumes ownership of the object +inline void TestResult::setSynchronizationObject (SynchronizationObject *syncObject) +{ delete m_syncObject; m_syncObject = syncObject; } + + +#endif + + diff --git a/test/CppUnit/framework/TestSuite.cpp b/test/CppUnit/framework/TestSuite.cpp new file mode 100644 index 00000000..294c5701 --- /dev/null +++ b/test/CppUnit/framework/TestSuite.cpp @@ -0,0 +1,48 @@ + + +#include "TestSuite.h" +#include "TestResult.h" + + +// Deletes all tests in the suite. +void TestSuite::deleteContents () +{ + for (std::vector::iterator it = m_tests.begin (); + it != m_tests.end (); + ++it) + delete *it; + +} + + +// Runs the tests and collects their result in a TestResult. +void TestSuite::run (TestResult *result) +{ + for (std::vector::iterator it = m_tests.begin (); + it != m_tests.end (); + ++it) { + if (result->shouldStop ()) + break; + + Test *test = *it; + test->run (result); + } + +} + + +// Counts the number of test cases that will be run by this test. +int TestSuite::countTestCases () +{ + int count = 0; + + for (std::vector::iterator it = m_tests.begin (); + it != m_tests.end (); + ++it) + count += (*it)->countTestCases (); + + return count; + +} + + diff --git a/test/CppUnit/framework/TestSuite.h b/test/CppUnit/framework/TestSuite.h new file mode 100644 index 00000000..2d959e51 --- /dev/null +++ b/test/CppUnit/framework/TestSuite.h @@ -0,0 +1,77 @@ + +#ifndef CPPUNIT_TESTSUITE_H +#define CPPUNIT_TESTSUITE_H + +#include +#include + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TEST_H +#include "Test.h" +#endif + +class TestResult; + +/* + * A TestSuite is a Composite of Tests. + * It runs a collection of test cases. Here is an example. + * + * TestSuite *suite= new TestSuite(); + * suite->addTest(new TestCaller ("testAdd", testAdd)); + * suite->addTest(new TestCaller ("testDivideByZero", testDivideByZero)); + * + * Note that TestSuites assume lifetime + * control for any tests added to them. + * + * see Test and TestCaller + */ + + +class TestSuite : public Test +{ + REFERENCEOBJECT (TestSuite) + +public: + TestSuite (std::string name = ""); + ~TestSuite (); + + void run (TestResult *result); + int countTestCases (); + void addTest (Test *test); + std::string toString (); + + virtual void deleteContents (); + +private: + std::vector m_tests; + const std::string m_name; + + +}; + + +// Default constructor +inline TestSuite::TestSuite (std::string name) +: m_name (name) +{} + + +// Destructor +inline TestSuite::~TestSuite () +{ deleteContents (); } + + +// Adds a test to the suite. +inline void TestSuite::addTest (Test *test) +{ m_tests.push_back (test); } + + +// Returns a string representation of the test suite. +inline std::string TestSuite::toString () +{ return "suite " + m_name; } + + +#endif diff --git a/test/CppUnit/framework/estring.h b/test/CppUnit/framework/estring.h new file mode 100644 index 00000000..0f33fe67 --- /dev/null +++ b/test/CppUnit/framework/estring.h @@ -0,0 +1,32 @@ + + + +#ifndef CPPUNIT_ESTRING_H +#define CPPUNIT_ESTRING_H + +#include + + +// Create a string from a const char pointer +inline std::string estring (const char *cstring) +{ return std::string (cstring); } + +// Create a string from a string (for uniformities' sake) +inline std::string estring (std::string& expandedString) +{ return expandedString; } + +// Create a string from an int +inline std::string estring (int number) +{ char buffer [50]; sprintf (buffer, "%d", number); return std::string (buffer); } + +// Create a string from a long +inline std::string estring (long number) +{ char buffer [50]; sprintf (buffer, "%ld", number); return std::string (buffer); } + +// Create a string from a double +inline std::string estring (double number) +{ char buffer [50]; sprintf (buffer, "%lf", number); return std::string (buffer); } + + +#endif + diff --git a/test/CppUnit/framework/extensions/Orthodox.h b/test/CppUnit/framework/extensions/Orthodox.h new file mode 100644 index 00000000..25c3a4de --- /dev/null +++ b/test/CppUnit/framework/extensions/Orthodox.h @@ -0,0 +1,93 @@ + +#ifndef CPPUNIT_ORTHODOX_H +#define CPPUNIT_ORTHODOX_H + +#ifndef CPPUNIT_TESTCASE_H +#include "TestCase.h" +#endif + +/* + * Orthodox performs a simple set of tests on an arbitary + * class to make sure that it supports at least the + * following operations: + * + * default construction - constructor + * equality/inequality - operator== && operator!= + * assignment - operator= + * negation - operator! + * safe passage - copy construction + * + * If operations for each of these are not declared + * the template will not instantiate. If it does + * instantiate, tests are performed to make sure + * that the operations have correct semantics. + * + * Adding an orthodox test to a suite is very + * easy: + * + * public: Test *suite () { + * TestSuite *suiteOfTests = new TestSuite; + * suiteOfTests->addTest (new ComplexNumberTest ("testAdd"); + * suiteOfTests->addTest (new TestCaller > ()); + * return suiteOfTests; + * } + * + * Templated test cases be very useful when you are want to + * make sure that a group of classes have the same form. + * + * see TestSuite + */ + + +template class Orthodox : public TestCase +{ +public: + Orthodox () : TestCase ("Orthodox") {} + +protected: + ClassUnderTest call (ClassUnderTest object); + void runTest (); + + +}; + + +// Run an orthodoxy test +template void Orthodox::runTest () +{ + // make sure we have a default constructor + ClassUnderTest a, b, c; + + // make sure we have an equality operator + assert (a == b); + + // check the inverse + b.operator= (a.operator! ()); + assert (a != b); + + // double inversion + b = !!a; + assert (a == b); + + // invert again + b = !a; + + // check calls + c = a; + assert (c == call (a)); + + c = b; + assert (c == call (b)); + +} + + +// Exercise a call +template ClassUnderTest Orthodox::call (ClassUnderTest object) +{ + return object; +} + + + +#endif \ No newline at end of file diff --git a/test/CppUnit/framework/extensions/RepeatedTest.h b/test/CppUnit/framework/extensions/RepeatedTest.h new file mode 100644 index 00000000..4571d16f --- /dev/null +++ b/test/CppUnit/framework/extensions/RepeatedTest.h @@ -0,0 +1,62 @@ + +#ifndef CPPUNIT_REPEATEDTEST_H +#define CPPUNIT_REPEATEDTEST_H + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TESTDECORATOR_H +#include "TestDecorator.h" +#endif + +class Test; +class TestResult; + + +/* + * A decorator that runs a test repeatedly. + * Does not assume ownership of the test it decorates + * + */ + +class RepeatedTest : public TestDecorator +{ + REFERENCEOBJECT (RepeatedTest) + +public: + RepeatedTest (Test *test, int timesRepeat) + : TestDecorator (test), m_timesRepeat (timesRepeat) {} + + int countTestCases (); + std::string toString (); + void run (TestResult *result); + +private: + const int m_timesRepeat; + + +}; + + +// Counts the number of test cases that will be run by this test. +inline RepeatedTest::countTestCases () +{ return TestDecorator::countTestCases () * m_timesRepeat; } + +// Returns the name of the test instance. +inline std::string RepeatedTest::toString () +{ return TestDecorator::toString () + " (repeated)"; } + +// Runs a repeated test +inline void RepeatedTest::run (TestResult *result) +{ + for (int n = 0; n < m_timesRepeat; n++) { + if (result->shouldStop ()) + break; + + TestDecorator::run (result); + } +} + + +#endif \ No newline at end of file diff --git a/test/CppUnit/framework/extensions/TestDecorator.h b/test/CppUnit/framework/extensions/TestDecorator.h new file mode 100644 index 00000000..0bf3382e --- /dev/null +++ b/test/CppUnit/framework/extensions/TestDecorator.h @@ -0,0 +1,63 @@ + + +#ifndef CPPUNIT_TESTDECORATOR_H +#define CPPUNIT_TESTDECORATOR_H + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TEST_H +#include "Test.h" +#endif + +class TestResult; + +/* + * A Decorator for Tests + * + * Does not assume ownership of the test it decorates + * + */ + +class TestDecorator : public Test +{ + REFERENCEOBJECT (TestDecorator) + +public: + TestDecorator (Test *test); + ~TestDecorator (); + + int countTestCases (); + void run (TestResult *result); + std::string toString (); + +protected: + Test *m_test; + + +}; + + +inline TestDecorator::TestDecorator (Test *test) +{ m_test = test; } + + +inline TestDecorator::~TestDecorator () +{} + + +inline TestDecorator::countTestCases () +{ return m_test->countTestCases (); } + + +inline void TestDecorator::run (TestResult *result) +{ m_test->run (result); } + + +inline std::string TestDecorator::toString () +{ return m_test->toString (); } + + +#endif + diff --git a/test/CppUnit/framework/extensions/TestSetup.h b/test/CppUnit/framework/extensions/TestSetup.h new file mode 100644 index 00000000..bf1e9753 --- /dev/null +++ b/test/CppUnit/framework/extensions/TestSetup.h @@ -0,0 +1,36 @@ + +#ifndef CPP_UINT_TESTSETUP_H +#define CPP_UINT_TESTSETUP_H + +#ifndef CPPUNIT_GUARDS_H +#include "Guards.h" +#endif + +#ifndef CPPUNIT_TESTDECORATOR_H +#include "TestDecorator.h" +#endif + +class Test; +class TestResult; + + +class TestSetup : public TestDecorator +{ + REFERENCEOBJECT (TestSetup) + +public: + TestSetup (Test *test) : TestDecorator (test) {} + run (TestResult *result); + +protected: + void setUp () {} + void tearDown () {} + +}; + + +inline TestSetup::run (TestResult *result) +{ setUp (); TestDecorator::run (result); tearDown (); } + +#endif + diff --git a/test/CppUnit/textui/TestRunner.cpp b/test/CppUnit/textui/TestRunner.cpp new file mode 100644 index 00000000..3d863e68 --- /dev/null +++ b/test/CppUnit/textui/TestRunner.cpp @@ -0,0 +1,146 @@ + + +/* + * A command line based tool to run tests. + * TestRunner expects as its only argument the name of a TestCase class. + * TestRunner prints out a trace as the tests are executed followed by a + * summary at the end. + * + * You can add to the tests that the TestRunner knows about by + * making additional calls to "addTest (...)" in main. + * + * Here is the synopsis: + * + * TestRunner [-wait] ExampleTestCase + * + */ + +#include +#include + +#include "TextTestResult.h" +#include "../framework/Test.h" +//#include "ExampleTestCase.h" + + +using namespace std; + +typedef pair mapping; +typedef vector > mappings; + +class TestRunner +{ +protected: + bool m_wait; + vector > m_mappings; + +public: + TestRunner () : m_wait (false) {} + ~TestRunner (); + + void run (int ac, char **av); + void addTest (string name, Test *test) + { m_mappings.push_back (mapping (name, test)); } + +protected: + void run (Test *test); + void printBanner (); + +}; + + + +void TestRunner::printBanner () +{ + cout << "Usage: driver [ -wait ] testName, where name is the name of a test case class" << endl; +} + + +void TestRunner::run (int ac, char **av) +{ + string testCase; + int numberOfTests = 0; + + for (int i = 1; i < ac; i++) { + + if (string (av [i]) == "-wait") { + m_wait = true; + continue; + } + + testCase = av [i]; + + if (testCase == "") { + printBanner (); + return; + } + + Test *testToRun = NULL; + + for (mappings::iterator it = m_mappings.begin (); + it != m_mappings.end (); + ++it) { + if ((*it).first == testCase) { + testToRun = (*it).second; + run (testToRun); + + } + } + + numberOfTests++; + + if (!testToRun) { + cout << "Test " << testCase << " not found." << endl; + return; + + } + + + } + + if (numberOfTests == 0) { + printBanner (); + return; + } + + if (m_wait) { + cout << " to continue" << endl; + cin.get (); + + } + + +} + + +TestRunner::~TestRunner () +{ + for (mappings::iterator it = m_mappings.begin (); + it != m_mappings.end (); + ++it) + delete it->second; + +} + + +void TestRunner::run (Test *test) +{ + TextTestResult result; + + test->run (&result); + + cout << result << endl; +} + +/* +int main (int ac, char **av) +{ + TestRunner runner; + + runner.addTest ("ExampleTestCase", ExampleTestCase::suite ()); + runner.run (ac, av); + + return 0; +} + +*/ diff --git a/test/CppUnit/textui/TextTestResult.cpp b/test/CppUnit/textui/TextTestResult.cpp new file mode 100644 index 00000000..5a327990 --- /dev/null +++ b/test/CppUnit/textui/TextTestResult.cpp @@ -0,0 +1,110 @@ + + +#include "TextTestResult.h" +#include "../framework/CppUnitException.h" +#include "../framework/estring.h" + +using namespace std; + +void TextTestResult::addError (Test *test, CppUnitException *e) +{ + TestResult::addError (test, e); + cerr << "E" << endl; + +} + +void TextTestResult::addFailure (Test *test, CppUnitException *e) +{ + TestResult::addFailure (test, e); + cerr << "F" << endl; + +} + +void TextTestResult::startTest (Test *test) +{ + TestResult::startTest (test); + cerr << "."; + +} + + +void TextTestResult::printErrors (ostream& stream) +{ + if (testErrors () != 0) { + + if (testErrors () == 1) + stream << "There was " << testErrors () << " error: " << endl; + else + stream << "There were " << testErrors () << " errors: " << endl; + + int i = 1; + + for (vector::iterator it = errors ().begin (); it != errors ().end (); ++it) { + TestFailure *failure = *it; + CppUnitException *e = failure->thrownException (); + + stream << i + << ") " + << "line: " << (e ? estring (e->lineNumber ()) : "") << " " + << (e ? e->fileName () : "") << " " + << "\"" << failure->thrownException ()->what () << "\"" + << endl; + i++; + } + } + +} + +void TextTestResult::printFailures (ostream& stream) +{ + if (testFailures () != 0) { + if (testFailures () == 1) + stream << "There was " << testFailures () << " failure: " << endl; + else + stream << "There were " << testFailures () << " failures: " << endl; + + int i = 1; + + for (vector::iterator it = failures ().begin (); it != failures ().end (); ++it) { + TestFailure *failure = *it; + CppUnitException *e = failure->thrownException (); + + stream << i + << ") " + << "line: " << (e ? estring (e->lineNumber ()) : "") << " " + << (e ? e->fileName () : "") << " " + << "\"" << failure->thrownException ()->what () << "\"" + << endl; + i++; + } + } + +} + + +void TextTestResult::print (ostream& stream) +{ + printHeader (stream); + printErrors (stream); + printFailures (stream); + +} + + +void TextTestResult::printHeader (ostream& stream) +{ + if (wasSuccessful ()) + cout << endl << "OK (" << runTests () << " tests)" << endl; + else + cout << endl + << "!!!FAILURES!!!" << endl + << "Test Results:" << endl + << "Run: " + << runTests () + << " Failures: " + << testFailures () + << " Errors: " + << testErrors () + << endl; + +} diff --git a/test/CppUnit/textui/TextTestResult.h b/test/CppUnit/textui/TextTestResult.h new file mode 100644 index 00000000..be99170d --- /dev/null +++ b/test/CppUnit/textui/TextTestResult.h @@ -0,0 +1,30 @@ + +#ifndef CPPUNIT_TEXTTESTRESULT_H +#define CPPUNIT_TEXTTESTRESULT_H + +#include +#include "../framework/TestResult.h" + + +class TextTestResult : public TestResult +{ +public: + virtual void addError (Test *test, CppUnitException *e); + virtual void addFailure (Test *test, CppUnitException *e); + virtual void startTest (Test *test); + virtual void print (std::ostream& stream); + virtual void printErrors (std::ostream& stream); + virtual void printFailures (std::ostream& stream); + virtual void printHeader (std::ostream& stream); + +}; + + +/* insertion operator for easy output */ +inline std::ostream& operator<< (std::ostream& stream, TextTestResult& result) +{ result.print (stream); return stream; } + + +#endif + + diff --git a/test/XPath/.cvsignore b/test/XPath/.cvsignore new file mode 100644 index 00000000..76fd713a --- /dev/null +++ b/test/XPath/.cvsignore @@ -0,0 +1,6 @@ +Debug +*.ncb +*.suo +xml_grammar.hpp +Release + diff --git a/test/XPath/arithmetic_test.cpp b/test/XPath/arithmetic_test.cpp new file mode 100644 index 00000000..03f68d76 --- /dev/null +++ b/test/XPath/arithmetic_test.cpp @@ -0,0 +1,188 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include + +using namespace Arabica::XPath; + +class ArithmeticTest : public TestCase +{ +public: + ArithmeticTest(const std::string& name) : TestCase(name) + { + } // ArithmeticTest + + void setUp() + { + } // setUp + + void test1() + { + XPathExpression* p1 = new NumericValue(1); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr add(new PlusOperator(p1, p2)); + assertEquals(1, add.use_count()); + + add->evaluate(dummy_); + + assertEquals(3.0, add->evaluateAsNumber(dummy_), 0.0); + + assertEquals(1, add.use_count()); + } // test1 + + void test2() + { + XPathExpression* p1 = new NumericValue(1); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr minus(new MinusOperator(p1, p2)); + + assertEquals(-1.0, minus->evaluateAsNumber(dummy_), 0.0); + } // test2 + + void test3() + { + XPathExpression* p1 = new NumericValue(3); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr mult(new MultiplyOperator(p1, p2)); + + assertEquals(6, mult->evaluateAsNumber(dummy_), 0.0); + } // test3 + + void test4() + { + XPathExpression* mult = new MultiplyOperator(new NumericValue(4), new NumericValue(2)); + + XPathExpressionPtr minus(new MinusOperator(mult, new NumericValue(2))); + + assertEquals(8, mult->evaluateAsNumber(dummy_), 0.0); + assertEquals(6, minus->evaluateAsNumber(dummy_), 0.0); + } // test4 + + void test5() + { + XPathExpression* p1 = new NumericValue(12); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr div(new DivideOperator(p1, p2)); + + assertEquals(6, div->evaluateAsNumber(dummy_), 0.0); + } // test5 + + void test6() + { + XPathExpression* p1 = new NumericValue(12); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr mod(new ModOperator(p1, p2)); + + assertEquals(0, mod->evaluateAsNumber(dummy_), 0.0); + } // test6 + + void test7() + { + XPathExpression* p1 = new NumericValue(11); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr div(new DivideOperator(p1, p2)); + + assertEquals(5.5, div->evaluateAsNumber(dummy_), 0.0); + } // test7 + + void test8() + { + XPathExpression* p1 = new NumericValue(11); + XPathExpression* p2 = new NumericValue(4); + + XPathExpressionPtr mod(new ModOperator(p1, p2)); + + assertEquals(3, mod->evaluateAsNumber(dummy_), 0.0); + } // test8 + + void test9() + { + XPathExpression* p1 = new NumericValue(5); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr mod(new ModOperator(p1, p2)); + + assertEquals(1.0, mod->evaluateAsNumber(dummy_), 0.0); + } // test9 + + void test10() + { + XPathExpression* p1 = new NumericValue(5); + XPathExpression* p2 = new NumericValue(-2); + + XPathExpressionPtr mod(new ModOperator(p1, p2)); + + assertEquals(1.00, mod->evaluateAsNumber(dummy_), 0.0); + } // test10 + + void test11() + { + XPathExpression* p1 = new NumericValue(-5); + XPathExpression* p2 = new NumericValue(2); + + XPathExpressionPtr mod(new ModOperator(p1, p2)); + + assertEquals(-1.0, mod->evaluateAsNumber(dummy_), 0.0); + } // test11 + + void test12() + { + XPathExpression* p1 = new NumericValue(-5); + XPathExpression* p2 = new NumericValue(-2); + + XPathExpressionPtr mod(new ModOperator(p1, p2)); + + assertEquals(-1.0, mod->evaluateAsNumber(dummy_), 0.0); + } // test12 + + void test13() + { + XPathExpression* p1 = new NumericValue(5); + XPathExpressionPtr p2(new UnaryNegative(p1)); + + assertEquals(-5.0, p2->evaluateAsNumber(dummy_), 0.0); + } // test13 + + void test14() + { + XPathExpression* p1 = new NumericValue(-5); + XPathExpressionPtr p2(new UnaryNegative(p1)); + + assertEquals(5.0, p2->evaluateAsNumber(dummy_), 0.0); + } // test14 + +private: + DOM::Node dummy_; +}; // ArithmeticTest + +TestSuite* ArithmeticTest_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("test1", &ArithmeticTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &ArithmeticTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &ArithmeticTest::test3)); + suiteOfTests->addTest(new TestCaller("test4", &ArithmeticTest::test4)); + suiteOfTests->addTest(new TestCaller("test5", &ArithmeticTest::test5)); + suiteOfTests->addTest(new TestCaller("test6", &ArithmeticTest::test6)); + suiteOfTests->addTest(new TestCaller("test7", &ArithmeticTest::test7)); + suiteOfTests->addTest(new TestCaller("test8", &ArithmeticTest::test8)); + suiteOfTests->addTest(new TestCaller("test9", &ArithmeticTest::test9)); + suiteOfTests->addTest(new TestCaller("test10", &ArithmeticTest::test10)); + suiteOfTests->addTest(new TestCaller("test11", &ArithmeticTest::test11)); + suiteOfTests->addTest(new TestCaller("test12", &ArithmeticTest::test12)); + suiteOfTests->addTest(new TestCaller("test13", &ArithmeticTest::test13)); + suiteOfTests->addTest(new TestCaller("test14", &ArithmeticTest::test14)); + + return suiteOfTests; +} // ArithmeticTest_suite diff --git a/test/XPath/arithmetic_test.hpp b/test/XPath/arithmetic_test.hpp new file mode 100644 index 00000000..21f1a27a --- /dev/null +++ b/test/XPath/arithmetic_test.hpp @@ -0,0 +1,7 @@ +#ifndef XPATHIC_ARITHMETIC_TEST_H +#define XPATHIC_ARITHMETIC_TEST_H + +TestSuite* ArithmeticTest_suite(); + +#endif + diff --git a/test/XPath/axis_enumerator_test.cpp b/test/XPath/axis_enumerator_test.cpp new file mode 100644 index 00000000..7639e27c --- /dev/null +++ b/test/XPath/axis_enumerator_test.cpp @@ -0,0 +1,947 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include +#include + +using namespace Arabica::XPath; + +class AxisEnumeratorTest : public TestCase +{ + DOM::DOMImplementation factory_; + DOM::Document document_; + + DOM::Element root_; + + DOM::Element element1_; + DOM::Element element2_; + DOM::Element element3_; + + DOM::Attr attr_; + + DOM::Text text_; + + DOM::Comment comment_; + + DOM::ProcessingInstruction processingInstruction_; + +public: + AxisEnumeratorTest(const std::string& name) : TestCase(name) + { + } // AxisEnumeratorTest + + void setUp() + { + factory_ = SimpleDOM::DOMImplementation::getDOMImplementation(); + document_ = factory_.createDocument("", "root", 0); + root_ = document_.getDocumentElement(); + + element1_ = document_.createElement("child1"); + element2_ = document_.createElement("child2"); + element3_ = document_.createElement("child3"); + + element1_.setAttribute("one", "1"); + + element2_.setAttribute("one", "1"); + element2_.setAttribute("two", "1"); + element2_.setAttribute("three", "1"); + element2_.setAttribute("four", "1"); + + text_ = document_.createTextNode("data"); + comment_ = document_.createComment("comment"); + processingInstruction_ = document_.createProcessingInstruction("target", "data"); + element2_.appendChild(text_); + element2_.appendChild(document_.createElement("spinkle")); + element2_.appendChild(comment_); + element2_.appendChild(processingInstruction_); + + attr_ = element1_.getAttributeNode("one"); + + root_.appendChild(element1_); + root_.appendChild(element2_); + root_.appendChild(element3_); + } // setup + + void childTest1() + { + DOM::DocumentFragment node; + + AxisEnumerator e(node, CHILD); + assertTrue(*e == 0); + assertTrue(e.forward()); + } // test1 + + void childTest2() + { + DOM::Node node; + + AxisEnumerator e(node, CHILD); + assertTrue(*e == 0); + } // test2 + + void childTest3() + { + AxisEnumerator e(root_, CHILD); + + assertTrue(element1_ == *e); + assertEquals("child1", e->getNodeName()); + ++e; + assertTrue(element2_ == *e); + assertEquals("child2", e->getNodeName()); + ++e; + assertTrue(element3_ == *e); + assertEquals("child3", e->getNodeName()); + ++e; + assertTrue(DOM::Node() == *e); + assertTrue(*e == 0); + } // test3 + + void childTest4() + { + AxisEnumerator e(document_, CHILD); + + assertTrue(root_ == *e); + ++e; + assertTrue(*e == 0); + } // childTest4 + + void attributeTest1() + { + DOM::DocumentFragment node; + + AxisEnumerator e(node, ATTRIBUTE); + assertTrue(*e == 0); + assertTrue(e.forward()); + } // attributeTest1 + + void attributeTest2() + { + DOM::Node node; + + AxisEnumerator e(node, ATTRIBUTE); + assertTrue(*e == 0); + } // attributeTest2 + + void attributeTest3() + { + AxisEnumerator e(element1_, ATTRIBUTE); + assertEquals("one", e->getNodeName()); + assertEquals("1", e->getNodeValue()); + ++e; + assertTrue(*e == 0); + } // attributeTest3 + + void attributeTest4() + { + int count = 0; + AxisEnumerator e(element2_, ATTRIBUTE); + while(*e++ != 0) + ++count; + assertEquals(4, count); + } // attributeTest4 + + void attributeTest5() + { + element2_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:poop", "poop-uri"); + + int count = 0; + AxisEnumerator e(element2_, ATTRIBUTE); + while(*e++ != 0) + ++count; + assertEquals(4, count); + } // attributeTest5 + + void attributeTest6() + { + element2_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:poop", "poop-uri"); + element2_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:qooq", "qooq-uri"); + + int count = 0; + AxisEnumerator e(element2_, ATTRIBUTE); + while(*e++ != 0) + ++count; + assertEquals(4, count); + } // attributeTest6 + + void followingSiblingTest1() + { + DOM::Node node; + AxisEnumerator e(node, FOLLOWING_SIBLING); + assertTrue(*e == 0); + assertTrue(e.forward()); + } // followingSiblingTest1 + + void followingSiblingTest2() + { + AxisEnumerator e(document_, FOLLOWING_SIBLING); + assertTrue(*e == 0); + } // followingSiblingTest2 + + void followingSiblingTest3() + { + AxisEnumerator e(element1_, FOLLOWING_SIBLING); + assertTrue(*e == element2_); + ++e; + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingSiblingTest3 + + void followingSiblingTest4() + { + AxisEnumerator e(element2_, FOLLOWING_SIBLING); + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingSiblingTest4 + + void followingSiblingTest5() + { + AxisEnumerator e(element3_, FOLLOWING_SIBLING); + assertTrue(*e == 0); + } // followingSiblingTest5 + + void followingSiblingTest6() + { + AxisEnumerator e(attr_, FOLLOWING_SIBLING); + assertTrue(*e == 0); + } // followingSiblingTest6 + + void precedingSiblingTest1() + { + DOM::Node node; + AxisEnumerator e(node, PRECEDING_SIBLING); + assertTrue(*e == 0); + assertTrue(e.reverse()); + } // precedingSiblingTest1 + + void precedingSiblingTest2() + { + AxisEnumerator e(document_, PRECEDING_SIBLING); + assertTrue(*e == 0); + } // precedingSiblingTest2 + + void precedingSiblingTest3() + { + AxisEnumerator e(element3_, PRECEDING_SIBLING); + assertTrue(*e == element2_); + ++e; + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingSiblingTest3 + + void precedingSiblingTest4() + { + AxisEnumerator e(element2_, PRECEDING_SIBLING); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingSiblingTest4 + + void precedingSiblingTest5() + { + AxisEnumerator e(element1_, PRECEDING_SIBLING); + assertTrue(*e == 0); + } // precedingSiblingTest5 + + void precedingSiblingTest6() + { + AxisEnumerator e(attr_, PRECEDING_SIBLING); + assertTrue(*e == 0); + } // precedingSiblingTest6 + + void selfTest1() + { + AxisEnumerator e(document_, SELF); + assertTrue(document_ == *e); + ++e; + assertTrue(*e == 0); + assertTrue(e.forward()); + } // selfTest1 + + void selfTest2() + { + AxisEnumerator e(root_, SELF); + assertTrue(root_ == *e); + ++e; + assertTrue(*e == 0); + } // selfTest2 + + void selfTest3() + { + DOM::Node node; + AxisEnumerator e(node, SELF); + assertTrue(*e == 0); + } // selfTest3 + + void parentTest1() + { + AxisEnumerator e(document_, PARENT); + assertTrue(*e == 0); + assertTrue(e.reverse()); + } // parentTest1 + + void parentTest2() + { + AxisEnumerator e(root_, PARENT); + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // parentTest2 + + void parentTest3() + { + AxisEnumerator e(element2_, PARENT); + assertTrue(*e == root_); + ++e; + assertTrue(*e == 0); + } // parentTest3 + + void parentTest4() + { + AxisEnumerator e(attr_, PARENT); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // parentTest4 + + void ancestorTest1() + { + AxisEnumerator e(document_, ANCESTOR); + assertTrue(*e == 0); + assertTrue(e.reverse()); + } // ancestorTest1 + + void ancestorTest2() + { + AxisEnumerator e(root_, ANCESTOR); + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // ancestorTest2 + + void ancestorTest3() + { + AxisEnumerator e(element2_, ANCESTOR); + assertTrue(*e == root_); + ++e; + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // ancestorTest3 + + void ancestorTest4() + { + AxisEnumerator e(attr_, ANCESTOR); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == root_); + ++e; + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // ancestorTest4 + + void ancestorOrSelfTest1() + { + AxisEnumerator e(document_, ANCESTOR_OR_SELF); + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + assertTrue(e.reverse()); + } // ancestorOrSelfTest1 + + void ancestorOrSelfTest2() + { + AxisEnumerator e(root_, ANCESTOR_OR_SELF); + assertTrue(*e == root_); + ++e; + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // ancestorOrSelfTest2 + + void ancestorOrSelfTest3() + { + AxisEnumerator e(element2_, ANCESTOR_OR_SELF); + assertTrue(*e == element2_); + ++e; + assertTrue(*e == root_); + ++e; + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // ancestorOrSelfTest3 + + void ancestorOrSelfTest4() + { + AxisEnumerator e(attr_, ANCESTOR_OR_SELF); + assertTrue(*e == attr_); + ++e; + assertTrue(*e == element1_); + ++e; + assertTrue(*e == root_); + ++e; + assertTrue(*e == document_); + ++e; + assertTrue(*e == 0); + } // ancestorOrSelfTest4 + + void descendantTest1() + { + AxisEnumerator e(root_, DESCENDANT); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == element2_); + ++e; + assertTrue(*e == text_); + ++e; + ++e; // spinkle + assertTrue(*e == comment_); + ++e; + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + assertTrue(e.forward()); + } // descendantTest1 + + void descendantTest2() + { + AxisEnumerator e(element1_, DESCENDANT); + assertTrue(*e == 0); + } // descendantTest2 + + void descendantTest3() + { + AxisEnumerator e(element2_, DESCENDANT); + assertTrue(*e == text_); + ++e; + ++e; // spinkle + assertTrue(*e == comment_); + ++e; + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == 0); + } // descendantTest3 + + void descendantTest4() + { + AxisEnumerator e(comment_, DESCENDANT); + assertTrue(*e == 0); + } // descendantTest4 + + void descendantTest5() + { + AxisEnumerator e(processingInstruction_, DESCENDANT); + assertTrue(*e == 0); + } // descendantTest5 + + void descendantTest6() + { + AxisEnumerator e(text_, DESCENDANT); + assertTrue(*e == 0); + } // descendantTest6 + + void descendantTest7() + { + AxisEnumerator e(attr_, DESCENDANT); + assertTrue(*e == 0); + } // descendantTest7 + + void descendantOrSelfTest1() + { + AxisEnumerator e(root_, DESCENDANT_OR_SELF); + assertTrue(e.forward()); + assertTrue(*e == root_); + ++e; + assertTrue(*e == element1_); + ++e; + assertTrue(*e == element2_); + ++e; + assertTrue(*e == text_); + ++e; + ++e; // spinkle + assertTrue(*e == comment_); + ++e; + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest1 + + void descendantOrSelfTest2() + { + AxisEnumerator e(element1_, DESCENDANT_OR_SELF); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest2 + + void descendantOrSelfTest3() + { + AxisEnumerator e(element2_, DESCENDANT_OR_SELF); + assertTrue(*e == element2_); + ++e; + assertTrue(*e == text_); + ++e; + ++e; // spinkle + assertTrue(*e == comment_); + ++e; + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest3 + + void descendantOrSelfTest4() + { + AxisEnumerator e(comment_, DESCENDANT_OR_SELF); + assertTrue(*e == comment_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest4 + + void descendantOrSelfTest5() + { + AxisEnumerator e(processingInstruction_, DESCENDANT_OR_SELF); + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest5 + + void descendantOrSelfTest6() + { + AxisEnumerator e(text_, DESCENDANT_OR_SELF); + assertTrue(*e == text_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest6 + + void descendantOrSelfTest7() + { + AxisEnumerator e(attr_, DESCENDANT_OR_SELF); + assertTrue(*e == attr_); + ++e; + assertTrue(*e == 0); + } // descendantOrSelfTest7 + + void followingTest1() + { + AxisEnumerator e(root_, FOLLOWING); + assertTrue(*e == 0); + assertTrue(e.forward()); + } // followingTest1 + + void followingTest2() + { + AxisEnumerator e(element1_, FOLLOWING); + assertTrue(*e == element2_); + ++e; + assertTrue(*e == text_); + ++e; + ++e; // spinkle + assertTrue(*e == comment_); + ++e; + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingTest2 + + void followingTest3() + { + AxisEnumerator e(element2_, FOLLOWING); + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingTest3 + + void followingTest4() + { + AxisEnumerator e(comment_, FOLLOWING); + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingTest4 + + void followingTest5() + { + AxisEnumerator e(processingInstruction_, FOLLOWING); + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingTest5 + + void followingTest6() + { + AxisEnumerator e(text_, FOLLOWING); + ++e; // spinkle + assertTrue(*e == comment_); + ++e; + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == element3_); + ++e; + assertTrue(*e == 0); + } // followingTest6 + + void followingTest7() + { + AxisEnumerator e(attr_, FOLLOWING); + assertTrue(*e == 0); + } // followingTest7 + + void precedingTest1() + { + AxisEnumerator e(root_, PRECEDING); + assertTrue(*e == 0); + } // precedingTest1 + + void precedingTest2() + { + AxisEnumerator e(element1_, PRECEDING); + assertTrue(*e == 0); + } // precedingTest2 + + void precedingTest3() + { + AxisEnumerator e(element2_, PRECEDING); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingTest3 + + void precedingTest4() + { + AxisEnumerator e(comment_, PRECEDING); + assertTrue(e.reverse()); + ++e; // spinkle + assertTrue(*e == text_); + ++e; + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingTest4(); + + void precedingTest5() + { + AxisEnumerator e(processingInstruction_, PRECEDING); + assertTrue(*e == comment_); + ++e; + ++e; // spinkle + assertTrue(*e == text_); + ++e; + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingTest5 + + void precedingTest6() + { + AxisEnumerator e(text_, PRECEDING); + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingTest6 + + void precedingTest7() + { + AxisEnumerator e(element3_, PRECEDING); + assertTrue(*e == processingInstruction_); + ++e; + assertTrue(*e == comment_); + ++e; + ++e; // spinkle; + assertTrue(*e == text_); + ++e; + assertTrue(*e == element2_); + ++e; + assertTrue(*e == element1_); + ++e; + assertTrue(*e == 0); + } // precedingTest7 + + void namespaceNodeTest1() + { + DOM::Node node(new NamespaceNodeImpl("p", "test-uri")); + DOM::Node node2; + + node2 = node; + } // namespaceNodeTest1 + + void namespaceNodeTest2() + { + DOM::Node node; + { + DOM::Node node2(new NamespaceNodeImpl("p", "test-uri")); + node = node2; + } + } // namespaceNodeTest2 + + void namespaceNodeTest3() + { + DOM::Node node; + { + DOM::Node node2(new NamespaceNodeImpl("p", "test-uri")); + node = node2; + } + node = 0; + } // namespaceNodeTest3 + + void namespaceNodeTest4() + { + DOM::Node node(new NamespaceNodeImpl("p", "test-uri")); + assertValuesEqual("p", node.getLocalName()); + assertValuesEqual("test-uri", node.getNodeValue()); + assertValuesEqual("", node.getNamespaceURI()); + assertValuesEqual("p", node.getNodeName()); + } // namespaceNodeTest4 + + void namespaceAxisTest1() + { + AxisEnumerator e(root_, NAMESPACE); + assertTrue(*e == 0); + } // namespaceAxisTest1() + + void namespaceAxisTest2() + { + root_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:poop", "urn:test"); + AxisEnumerator e(root_, NAMESPACE); + assertTrue(*e != 0); + DOM::Node ns = *e; + assertValuesEqual("poop", ns.getLocalName()); + assertValuesEqual("urn:test", ns.getNodeValue()); + ++e; + assertTrue(*e == 0); + } // namespaceAxisTest2 + + void namespaceAxisTest3() + { + root_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:poop", "urn:test"); + element2_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:test", "urn:another-test"); + AxisEnumerator e(element2_, NAMESPACE); + assertTrue(*e != 0); + ++e; + assertTrue(*e != 0); + ++e; + assertTrue(*e == 0); + } // namespaceAxisTest3 + +}; // AxisEnumeratorTest + +TestSuite* AncestorTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("ancestorTest1", &AxisEnumeratorTest::ancestorTest1)); + suiteOfTests->addTest(new TestCaller("ancestorTest2", &AxisEnumeratorTest::ancestorTest2)); + suiteOfTests->addTest(new TestCaller("ancestorTest3", &AxisEnumeratorTest::ancestorTest3)); + suiteOfTests->addTest(new TestCaller("ancestorTest4", &AxisEnumeratorTest::ancestorTest4)); + + return suiteOfTests; +} // AncestorTest_suite + +TestSuite* AncestorOrSelfTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("ancestorOrSelfTest1", &AxisEnumeratorTest::ancestorOrSelfTest1)); + suiteOfTests->addTest(new TestCaller("ancestorOrSelfTest2", &AxisEnumeratorTest::ancestorOrSelfTest2)); + suiteOfTests->addTest(new TestCaller("ancestorOrSelfTest3", &AxisEnumeratorTest::ancestorOrSelfTest3)); + suiteOfTests->addTest(new TestCaller("ancestorOrSelfTest4", &AxisEnumeratorTest::ancestorOrSelfTest4)); + + return suiteOfTests; +} // AncestorOrSelfTest_suite + +TestSuite* ChildTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("childTest1", &AxisEnumeratorTest::childTest1)); + suiteOfTests->addTest(new TestCaller("childTest2", &AxisEnumeratorTest::childTest2)); + suiteOfTests->addTest(new TestCaller("childTest3", &AxisEnumeratorTest::childTest3)); + suiteOfTests->addTest(new TestCaller("childTest4", &AxisEnumeratorTest::childTest4)); + + return suiteOfTests; +} // ChildTest_suite + +TestSuite* AttributeTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("attributeTest1", &AxisEnumeratorTest::attributeTest1)); + suiteOfTests->addTest(new TestCaller("attributeTest2", &AxisEnumeratorTest::attributeTest2)); + suiteOfTests->addTest(new TestCaller("attributeTest3", &AxisEnumeratorTest::attributeTest3)); + suiteOfTests->addTest(new TestCaller("attributeTest4", &AxisEnumeratorTest::attributeTest4)); + suiteOfTests->addTest(new TestCaller("attributeTest5", &AxisEnumeratorTest::attributeTest5)); + suiteOfTests->addTest(new TestCaller("attributeTest6", &AxisEnumeratorTest::attributeTest6)); + + return suiteOfTests; +} // AttributeTest_suite + +TestSuite* FollowingSibling_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("followingSiblingTest1", &AxisEnumeratorTest::followingSiblingTest1)); + suite->addTest(new TestCaller("followingSiblingTest2", &AxisEnumeratorTest::followingSiblingTest2)); + suite->addTest(new TestCaller("followingSiblingTest3", &AxisEnumeratorTest::followingSiblingTest3)); + suite->addTest(new TestCaller("followingSiblingTest4", &AxisEnumeratorTest::followingSiblingTest4)); + suite->addTest(new TestCaller("followingSiblingTest5", &AxisEnumeratorTest::followingSiblingTest5)); + suite->addTest(new TestCaller("followingSiblingTest6", &AxisEnumeratorTest::followingSiblingTest6)); + + return suite; +} // FollowingSibling_suite + +TestSuite* PrecedingSibling_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("precedingSiblingTest1", &AxisEnumeratorTest::precedingSiblingTest1)); + suite->addTest(new TestCaller("precedingSiblingTest2", &AxisEnumeratorTest::precedingSiblingTest2)); + suite->addTest(new TestCaller("precedingSiblingTest3", &AxisEnumeratorTest::precedingSiblingTest3)); + suite->addTest(new TestCaller("precedingSiblingTest4", &AxisEnumeratorTest::precedingSiblingTest4)); + suite->addTest(new TestCaller("precedingSiblingTest5", &AxisEnumeratorTest::precedingSiblingTest5)); + suite->addTest(new TestCaller("precedingSiblingTest6", &AxisEnumeratorTest::precedingSiblingTest6)); + + return suite; +} // PrecedingSibling_suite + +TestSuite* SelfTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("selfTest1", &AxisEnumeratorTest::selfTest1)); + suiteOfTests->addTest(new TestCaller("selfTest2", &AxisEnumeratorTest::selfTest2)); + suiteOfTests->addTest(new TestCaller("selfTest3", &AxisEnumeratorTest::selfTest3)); + + return suiteOfTests; +} // SelfTest_suite + +TestSuite* ParentTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("parentTest1", &AxisEnumeratorTest::parentTest1)); + suiteOfTests->addTest(new TestCaller("parentTest2", &AxisEnumeratorTest::parentTest2)); + suiteOfTests->addTest(new TestCaller("parentTest3", &AxisEnumeratorTest::parentTest3)); + suiteOfTests->addTest(new TestCaller("parentTest4", &AxisEnumeratorTest::parentTest4)); + + return suiteOfTests; +} // ParentTest_suite + +TestSuite* DescendantTest_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("descendantTest1", &AxisEnumeratorTest::descendantTest1)); + suite->addTest(new TestCaller("descendantTest2", &AxisEnumeratorTest::descendantTest2)); + suite->addTest(new TestCaller("descendantTest3", &AxisEnumeratorTest::descendantTest3)); + suite->addTest(new TestCaller("descendantTest4", &AxisEnumeratorTest::descendantTest4)); + suite->addTest(new TestCaller("descendantTest5", &AxisEnumeratorTest::descendantTest5)); + suite->addTest(new TestCaller("descendantTest6", &AxisEnumeratorTest::descendantTest6)); + suite->addTest(new TestCaller("descendantTest7", &AxisEnumeratorTest::descendantTest7)); + + return suite; +} // DescendantTest_suite + +TestSuite* DescendantOrSelfTest_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("descendantOrSelfTest1", &AxisEnumeratorTest::descendantOrSelfTest1)); + suite->addTest(new TestCaller("descendantOrSelfTest2", &AxisEnumeratorTest::descendantOrSelfTest2)); + suite->addTest(new TestCaller("descendantOrSelfTest3", &AxisEnumeratorTest::descendantOrSelfTest3)); + suite->addTest(new TestCaller("descendantOrSelfTest4", &AxisEnumeratorTest::descendantOrSelfTest4)); + suite->addTest(new TestCaller("descendantOrSelfTest5", &AxisEnumeratorTest::descendantOrSelfTest5)); + suite->addTest(new TestCaller("descendantOrSelfTest6", &AxisEnumeratorTest::descendantOrSelfTest6)); + suite->addTest(new TestCaller("descendantOrSelfTest7", &AxisEnumeratorTest::descendantOrSelfTest7)); + + return suite; +} // DescendantOrSelfTest_suite + +TestSuite* FollowingTest_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("followingTest1", &AxisEnumeratorTest::followingTest1)); + suite->addTest(new TestCaller("followingTest2", &AxisEnumeratorTest::followingTest2)); + suite->addTest(new TestCaller("followingTest3", &AxisEnumeratorTest::followingTest3)); + suite->addTest(new TestCaller("followingTest4", &AxisEnumeratorTest::followingTest4)); + suite->addTest(new TestCaller("followingTest5", &AxisEnumeratorTest::followingTest5)); + suite->addTest(new TestCaller("followingTest6", &AxisEnumeratorTest::followingTest6)); + suite->addTest(new TestCaller("followingTest7", &AxisEnumeratorTest::followingTest7)); + + return suite; +} // FollowingTest_suite + +TestSuite* PrecedingTest_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("precedingTest1", &AxisEnumeratorTest::precedingTest1)); + suite->addTest(new TestCaller("precedingTest2", &AxisEnumeratorTest::precedingTest2)); + suite->addTest(new TestCaller("precedingTest3", &AxisEnumeratorTest::precedingTest3)); + suite->addTest(new TestCaller("precedingTest4", &AxisEnumeratorTest::precedingTest4)); + suite->addTest(new TestCaller("precedingTest5", &AxisEnumeratorTest::precedingTest5)); + suite->addTest(new TestCaller("precedingTest6", &AxisEnumeratorTest::precedingTest6)); + suite->addTest(new TestCaller("precedingTest7", &AxisEnumeratorTest::precedingTest7)); + + return suite; +} // PrecedingTest_suite + +TestSuite* NamespaceNodeTest_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("namespaceNodeTest1", &AxisEnumeratorTest::namespaceNodeTest1)); + suite->addTest(new TestCaller("namespaceNodeTest2", &AxisEnumeratorTest::namespaceNodeTest2)); + suite->addTest(new TestCaller("namespaceNodeTest3", &AxisEnumeratorTest::namespaceNodeTest3)); + suite->addTest(new TestCaller("namespaceNodeTest4", &AxisEnumeratorTest::namespaceNodeTest4)); + + return suite; +} // NamespaceNodeTest_suite + +TestSuite* NamespaceAxisTest_suite() +{ + TestSuite* suite = new TestSuite; + + suite->addTest(new TestCaller("namespaceAxisTest1", &AxisEnumeratorTest::namespaceAxisTest1)); + suite->addTest(new TestCaller("namespaceAxisTest2", &AxisEnumeratorTest::namespaceAxisTest2)); + suite->addTest(new TestCaller("namespaceAxisTest3", &AxisEnumeratorTest::namespaceAxisTest3)); + + return suite; +} // NamespaceAxisTest_suite + +TestSuite* AxisEnumeratorTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(AncestorTest_suite()); + suiteOfTests->addTest(AncestorOrSelfTest_suite()); + suiteOfTests->addTest(AttributeTest_suite()); + suiteOfTests->addTest(ChildTest_suite()); + suiteOfTests->addTest(FollowingSibling_suite()); + suiteOfTests->addTest(PrecedingSibling_suite()); + suiteOfTests->addTest(SelfTest_suite()); + suiteOfTests->addTest(ParentTest_suite()); + suiteOfTests->addTest(DescendantTest_suite()); + suiteOfTests->addTest(DescendantOrSelfTest_suite()); + suiteOfTests->addTest(FollowingTest_suite()); + suiteOfTests->addTest(PrecedingTest_suite()); + suiteOfTests->addTest(NamespaceNodeTest_suite()); + suiteOfTests->addTest(NamespaceAxisTest_suite()); + + return suiteOfTests; +} // AxisEnumeratorTest_suite + diff --git a/test/XPath/axis_enumerator_test.hpp b/test/XPath/axis_enumerator_test.hpp new file mode 100644 index 00000000..2b7da54a --- /dev/null +++ b/test/XPath/axis_enumerator_test.hpp @@ -0,0 +1,7 @@ +#ifndef AXIS_ENUMERATOR_TEST_H +#define AXIS_ENUMERATOR_TEST_H + +TestSuite* AxisEnumeratorTest_suite(); + +#endif + diff --git a/test/XPath/execute_test.cpp b/test/XPath/execute_test.cpp new file mode 100644 index 00000000..3653a2c4 --- /dev/null +++ b/test/XPath/execute_test.cpp @@ -0,0 +1,2374 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224 4267) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include +#include + +using namespace Arabica::XPath; + +class StringVariableResolver : public VariableResolver +{ +public: + virtual XPathValuePtr resolveVariable(const std::string& name) const + { + VarMap::const_iterator n = map_.find(name); + if(n == map_.end()) + throw UnboundVariableException(name); + return XPathValuePtr(new StringValue((*n).second)); + } // resolveVariable + + void setVariable(const std::string& name, const std::string& value) + { + map_[name] = value; + } // setVariable + +private: + typedef std::map VarMap; + VarMap map_; +}; // StringVariableResolver + +class NodeSetVariableResolver : public VariableResolver +{ +public: + virtual XPathValuePtr resolveVariable(const std::string& name) const + { + VarMap::const_iterator n = map_.find(name); + if(n == map_.end()) + throw UnboundVariableException(name); + return XPathValuePtr(new NodeSetValue((*n).second)); + } // resolveVariable + + void setVariable(const std::string& name, const NodeSet& value) + { + map_[name] = value; + } // setVariable + +private: + typedef std::map VarMap; + VarMap map_; +}; // class NodeSetVariableResolver + +class TestFunction : public XPathFunction +{ +public: + TestFunction(const std::vector& args) : + XPathFunction(0, 0, args) { } + + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const + { + return new StringValue("test-" + context.getLocalName()); + } // evaluate +}; // TestFunction + +class TestFunctionResolver : public FunctionResolver +{ +public: + virtual XPathFunction* resolveFunction(const std::string& name, + const std::vector& argExprs) const + { + if(name == "test-function") + return new TestFunction(argExprs); + return 0; + } // resolveFunction +}; // class TestFunctionResolver + +class ExecuteTest : public TestCase +{ + Arabica::XPath::XPath parser; + DOM::DOMImplementation factory_; + DOM::Document document_; + + DOM::Element root_; + + DOM::Element element1_; + DOM::Element element2_; + DOM::Element element3_; + DOM::Element spinkle_; + + DOM::Attr attr_; + + DOM::Text text_; + + DOM::Comment comment_; + + DOM::ProcessingInstruction processingInstruction_; + + DOM::Document chapters_; + + DOM::Document numbers_; + +public: + ExecuteTest(std::string name) : TestCase(name) + { + } // ExecuteTest + + void setUp() + { + factory_ = SimpleDOM::DOMImplementation::getDOMImplementation(); + document_ = factory_.createDocument("", "root", 0); + root_ = document_.getDocumentElement(); + + element1_ = document_.createElement("child1"); + element2_ = document_.createElement("child2"); + element3_ = document_.createElement("child3"); + + element1_.setAttribute("one", "1"); + + element2_.setAttribute("one", "1"); + element2_.setAttribute("two", "1"); + element2_.setAttribute("three", "1"); + element2_.setAttribute("four", "1"); + + text_ = document_.createTextNode("data"); + comment_ = document_.createComment("comment"); + processingInstruction_ = document_.createProcessingInstruction("target", "data"); + element2_.appendChild(text_); + spinkle_ = document_.createElement("spinkle"); + element2_.appendChild(spinkle_); + element2_.appendChild(comment_); + element2_.appendChild(processingInstruction_); + + attr_ = element1_.getAttributeNode("one"); + + root_.appendChild(element1_); + root_.appendChild(element2_); + root_.appendChild(element3_); + + chapters_ = factory_.createDocument("", "document", 0); + chapters_.getFirstChild().appendChild(chapters_.createElement("chapter")).appendChild(chapters_.createTextNode("one")); + chapters_.getFirstChild().appendChild(chapters_.createElement("chapter")).appendChild(chapters_.createTextNode("two")); + chapters_.getFirstChild().appendChild(chapters_.createElement("chapter")).appendChild(chapters_.createTextNode("three")); + chapters_.getFirstChild().appendChild(chapters_.createElement("chapter")).appendChild(chapters_.createTextNode("four")); + chapters_.getFirstChild().appendChild(chapters_.createElement("chapter")).appendChild(chapters_.createTextNode("five")); + + numbers_ = factory_.createDocument("", "doc", 0); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("1")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("2")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("3")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("4")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("5")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("6")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("7")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("8")); + numbers_.getFirstChild().appendChild(numbers_.createElement("number")).appendChild(numbers_.createTextNode("9")); + } // setUp + + void test1() + { + XPathExpressionPtr xpath = parser.compile("root"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + DOM::Node n = result->asNodeSet()[0]; + assertTrue(root_ == n); + } // test1 + + void test2() + { + XPathExpressionPtr xpath = parser.compile("root/child2"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + DOM::Node n = result->asNodeSet()[0]; + assertTrue(element2_ == n); + } // test2 + + void test3() + { + XPathExpressionPtr xpath = parser.compile("root/*"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + } // test4 + + void test4() + { + XPathExpressionPtr xpath = parser.compile("root/*/text()"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(text_ == result->asNodeSet()[0]); + assertValuesEqual(text_.getNodeValue(), result->asString()); + } // test4 + + void test5() + { + XPathExpressionPtr xpath = parser.compile("root/*/text()"); + assertValuesEqual(text_.getNodeValue(), xpath->evaluateAsString(document_)); + } // test5 + + void test6() + { + XPathExpressionPtr xpath = parser.compile("*"); + + XPathValuePtr result = xpath->evaluate(document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(root_ == result->asNodeSet()[0]); + + result = xpath->evaluate(root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + + result = xpath->evaluate(element1_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + + result = xpath->evaluate(element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + + result = xpath->evaluate(element3_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // test6 + + void test7() + { + XPathExpressionPtr xpath = parser.compile("/root"); + + XPathValuePtr result = xpath->evaluate(document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(root_ == result->asNodeSet()[0]); + + result = xpath->evaluate(text_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(root_ == result->asNodeSet()[0]); + } // test7 + + void test8() + { + StandardNamespaceContext nsContext; + nsContext.addNamespaceDeclaration("urn:something:or:other", "ns"); + parser.setNamespaceContext(nsContext); + XPathExpressionPtr xpath = parser.compile("/ns:root"); + parser.resetNamespaceContext(); + + XPathValuePtr result = xpath->evaluate(document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + + result = xpath->evaluate(text_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // test8 + + void test9() + { + XPathExpressionPtr xpath = parser.compile("child2"); + + XPathValuePtr result = xpath->evaluate(root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + + xpath = parser.compile("./child2"); + result = xpath->evaluate(root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // test9 + + void test10() + { + assertTrue(root_ == parser.evaluate(".", root_)->asNodeSet()[0]); + } // test10 + + void test11() + { + XPathExpressionPtr xpath = parser.compile(".."); + + XPathValuePtr result = xpath->evaluate(element3_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(root_ == result->asNodeSet()[0]); + } // test11 + + void test12() + { + XPathExpressionPtr xpath = parser.compile("root/*[2]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + DOM::Node n = result->asNodeSet()[0]; + assertTrue(element2_ == n); + } // test12 + + void test13() + { + XPathValuePtr result = parser.evaluate("/root/*[2]/comment()", document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(comment_ == result->asNodeSet()[0]); + } // test13 + + void test14() + { + XPathValuePtr result = parser.evaluate("/root/*[2]/node()[3]", document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(comment_ == result->asNodeSet()[0]); + } // test14 + + void test15() + { + XPathValuePtr result = parser.evaluate("root/*[spinkle]", document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // test15 + + void test16() + { + XPathValuePtr result = parser.evaluate("root/*[doesnotmatch]", document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // test16 + + void test17() + { + XPathValuePtr result = parser.evaluate("/root/*[@two = '1']", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // test17 + + void test18() + { + StringVariableResolver svr; + svr.setVariable("index", "1"); + + parser.setVariableResolver(svr); + XPathValuePtr result = parser.evaluate("/root/*[@two = $index]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + + parser.resetVariableResolver(); + } // test18 + + void test19() + { + XPathExpressionPtr xpath = parser.compile("root/*[position() = 2]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + DOM::Node n = result->asNodeSet()[0]; + assertTrue(element2_ == n); + } // test19 + + void test20() + { + XPathExpressionPtr xpath = parser.compile("root/*[last()]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element3_ == result->asNodeSet()[0]); + } // test20 + + void test21() + { + XPathExpressionPtr xpath = parser.compile("root/*[position() != last()]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // test21 + + void test22() + { + XPathExpressionPtr xpath = parser.compile("root/*[position() = 2 or position() = 1]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // test22 + + void test23() + { + XPathExpressionPtr xpath = parser.compile("root/*[position() = 2 and @two = '1']"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // test23 + + void test24() + { + XPathExpressionPtr xpath = parser.compile("root/*[last()][1]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element3_ == result->asNodeSet()[0]); + } // test24 + + void test25() + { + XPathExpressionPtr xpath = parser.compile("root/*[last()][2]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // test25 + + void test26() + { + XPathExpressionPtr xpath = parser.compile("/root/child2/spinkle/ancestor::node()[2]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(result->asNodeSet()[0] == root_); + assertTrue(result->asNodeSet().forward() == false); + } // test26 + + void test27() + { + XPathExpressionPtr xpath = parser.compile("/root/child2/spinkle/ancestor-or-self::node()[2]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(result->asNodeSet()[0] == element2_); + assertTrue(result->asNodeSet().forward() == false); + } // test27 + + void test28() + { + XPathExpressionPtr xpath = parser.compile("/root/child2/spinkle/ancestor-or-self::node()[3]"); + XPathValuePtr result = xpath->evaluate(document_); + + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(result->asNodeSet()[0] == root_); + } // test28 + + void test29() + { + XPathValuePtr result = parser.evaluate("/child::root/child::*[attribute::two = '1']", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // test29 + + void test30() + { + XPathValuePtr result = parser.evaluate("/", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(document_ == result->asNodeSet()[0]); + } // test30 + + void test31() + { + XPathValuePtr result = parser.evaluate("/", element1_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(document_ == result->asNodeSet()[0]); + } // test31 + + void test32() + { + XPathValuePtr result = parser.evaluate("//comment()", root_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(comment_ == result->asNodeSet()[0]); + } // test32 + + void test33() + { + XPathValuePtr result = parser.evaluate("//comment()", root_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(comment_ == result->asNodeSet()[0]); + assertTrue(result->asNodeSet().forward() == true); + } // test33 + + void test34() + { + XPathValuePtr result = parser.evaluate("//*", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(5, result->asNodeSet().size()); + assertTrue(root_ == result->asNodeSet()[0]); + assertTrue(element1_ == result->asNodeSet()[1]); + assertTrue(element2_ == result->asNodeSet()[2]); + assertTrue(element3_ == result->asNodeSet()[3]); + assertTrue(spinkle_ == result->asNodeSet()[4]); + } // test34 + + void test35() + { + XPathValuePtr result = parser.evaluate("//*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(5, result->asNodeSet().size()); + assertTrue(root_ == result->asNodeSet()[0]); + assertTrue(element1_ == result->asNodeSet()[1]); + assertTrue(element2_ == result->asNodeSet()[2]); + assertTrue(element3_ == result->asNodeSet()[3]); + assertTrue(spinkle_ == result->asNodeSet()[4]); + } // test35 + + void test36() + { + XPathValuePtr result = parser.evaluate("//*/*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(4, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + assertTrue(spinkle_ == result->asNodeSet()[3]); + } // test36 + + void test37() + { + XPathValuePtr result = parser.evaluate("//*/*/*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(spinkle_ == result->asNodeSet()[0]); + } // test37 + + void test38() + { + XPathValuePtr result = parser.evaluate("//*/*/*/*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // test38 + + void test39() + { + XPathValuePtr result = parser.evaluate("/*/*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + } // test39 + + void test40() + { + XPathValuePtr result = parser.evaluate("/root//*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(4, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + assertTrue(spinkle_ == result->asNodeSet()[3]); + } // test40 + + // see http://jira.codehaus.org/browse/JAXEN-94 + void test41() + { + XPathValuePtr result = parser.evaluate_expr("2+1-1+1", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(3.0, result->asNumber(), 0.0); + } // test41 + + void testUnion1() + { + XPathValuePtr result = parser.evaluate("/root/*[@one|data]", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // testUnion1 + + void testUnion2() + { + XPathValuePtr result = parser.evaluate("/root/*[buttle|tuttle]", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + assertTrue(result->asNodeSet().forward() == true); + } // testUnion2 + + void testUnion3() + { + XPathValuePtr result = parser.evaluate("/root/*[preceding-sibling::child2|@two]", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + assertTrue(element3_ == result->asNodeSet()[1]); + } // testUnion3 + + void testUnion4() + { + try { + XPathValuePtr result = parser.evaluate("/root/*[@two|4]", root_); + } // try + catch(RuntimeException re) { + // yay! + } // catch + } // testUnion4 + + void testUnion5() + { + XPathValuePtr result = parser.evaluate("/root/*[preceding-sibling::child2|@two|following-sibling::child2]", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + } // testUnion5 + + void testUnion6() + { + XPathValuePtr result = parser.evaluate_expr("/root/child2|/root/child1", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // testUnion6 + + void testUnion7() + { + XPathValuePtr result = parser.evaluate_expr("/root/child1|/root/child2", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // testUnion7 + + void testUnion8() + { + XPathValuePtr result = parser.evaluate_expr("/root/child2/@one|/root/child2|/root/child1", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element2_.getAttributeNode("one") == result->asNodeSet()[2]); + } // testUnion8 + + void testUnion9() + { + XPathValuePtr result = parser.evaluate_expr("/root/child1/@one|/root/child2/@one|/root/child2|/root/child1", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(4, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element1_.getAttributeNode("one") == result->asNodeSet()[1]); + assertTrue(element2_ == result->asNodeSet()[2]); + assertTrue(element2_.getAttributeNode("one") == result->asNodeSet()[3]); + } // testUnion9 + + void testUnion10() + { + XPathValuePtr result = parser.evaluate_expr("/root/child3|/root/child3/preceding-sibling::*", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + } // testUnion10 + + void testUnion11() + { + DOM::DocumentFragment frag = document_.createDocumentFragment(); + frag.appendChild(document_.createElement("foo")); + + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(frag); + svr.setVariable("fruit", ns); + parser.setVariableResolver(svr); + + XPathValuePtr result = parser.evaluate_expr("$fruit/foo|/root/child3", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element3_ == result->asNodeSet()[0]); + } // testUnion11 + + void testUnion12() + { + DOM::DocumentFragment frag = document_.createDocumentFragment(); + DOM::Node n1 = document_.createElement("foo"); + DOM::Node n2 = document_.createElement("bar"); + + frag.appendChild(n1); + frag.appendChild(n2); + + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(frag); + svr.setVariable("fruit", ns); + parser.setVariableResolver(svr); + + XPathValuePtr result = parser.evaluate_expr("$fruit/bar|$fruit/foo", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(n1 == result->asNodeSet()[0]); + assertTrue(n2 == result->asNodeSet()[1]); + } // testUnion12 + + void testUnion13() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(document_.createElement("foo")); + svr.setVariable("fruit", ns); + parser.setVariableResolver(svr); + + XPathValuePtr result = parser.evaluate_expr("$fruit|/root/child3", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + assertTrue(element3_ == result->asNodeSet()[0]); + } // testUnion13 + + void testUnion14() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(document_.createElement("foo")); + ns.push_back(document_.createElement("bar")); + svr.setVariable("fruit", ns); + parser.setVariableResolver(svr); + + XPathValuePtr result = parser.evaluate_expr("$fruit|/root/child3|$fruit", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element3_ == result->asNodeSet()[0]); + } // testUnion14 + + void testPlus1() + { + XPathValuePtr result = parser.evaluate("/root/*[1+1]", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testPlus1 + + void testPlus2() + { + XPathValuePtr result = parser.evaluate("/root/*[1+1+1]", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element3_ == result->asNodeSet()[0]); + } // testPlus2 + + void testNodeSetEquality1() + { + XPathValuePtr result = parser.evaluate("/root/*[@two = 1]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetEquality1 + + void testNodeSetEquality2() + { + XPathValuePtr result = parser.evaluate("/root/*[@two = true()]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetEquality2 + + void testNodeSetEquality3() + { + XPathValuePtr result = parser.evaluate("/root/*[@two != false()]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetEquality3 + + void testNodeSetEquality4() + { + XPathValuePtr result = parser.evaluate("/root/*[@* = 1]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // testNodeSetEquality4 + + void testNodeSetEquality5() + { + XPathValuePtr result = parser.evaluate("/root/*[@* = '1']", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // testNodeSetEquality5 + + void testNodeSetEquality6() + { + XPathValuePtr result = parser.evaluate("/root/*[@* = @one]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + } // testNodeSetEquality6 + + void testNodeSetEquality7() + { + XPathValuePtr result = parser.evaluate("/root/*[@* = @two]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetEquality7 + + void testNodeSetEquality8() + { + XPathValuePtr result = parser.evaluate("/root/child2[-(@two) = -1]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetEquality8 + + void testNodeSetEquality9() + { + XPathValuePtr result = parser.evaluate("/root/child2[-(@two) - 1 = -2]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetEquality9 + + void testCountFn1() + { + XPathValuePtr result = parser.evaluate("/root/*[count(@*) = 4]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testCountFn1 + + void testCountFn2() + { + XPathValuePtr result = parser.evaluate("/root/*[count(@*) = 1]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + } // testCountFn2 + + void testCountFn3() + { + XPathValuePtr result = parser.evaluate("/root/*[count(@*) = 999]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // testCountFn3 + + void testNotFn1() + { + XPathValuePtr result = parser.evaluate("/root/*[@two != not(true())]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNotFn1 + + void testNotFn2() + { + XPathValuePtr result = parser.evaluate("/root/*[@two = not(false())]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNotFn2 + + void testBooleanFn1() + { + XPathValuePtr result = parser.evaluate("/root/*[boolean(@three)]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testBooleanFn1 + + void testBooleanFn2() + { + XPathValuePtr result = parser.evaluate("/root/*[boolean(1)]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(3, result->asNodeSet().size()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + } // testBooleanFn2 + + void testNumberFn1() + { + XPathValuePtr result = parser.evaluate_expr("number(true())", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testNumberFn1 + + void testNumberFn2() + { + XPathValuePtr result = parser.evaluate_expr("number(false())", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(0.0, result->asNumber(), 0.0); + } // testNumberFn2 + + void testNumberFn3() + { + XPathValuePtr result = parser.evaluate_expr("number(1.5)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.5, result->asNumber(), 0.0); + } // testNumberFn3 + + void testNumberFn4() + { + XPathValuePtr result = parser.evaluate_expr("number('1.5')", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.5, result->asNumber(), 0.0); + } // testNumberFn4 + + void testNumberFn5() + { + XPathValuePtr result = parser.evaluate_expr("number(\"1.5\")", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.5, result->asNumber(), 0.0); + } // testNumberFn5 + + void testNumberFn6() + { + XPathValuePtr result = parser.evaluate_expr("number(/root/child2/@one)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testNumberFn6 + + void testNumberFn7() + { + XPathValuePtr result = parser.evaluate_expr("number('trousers')", document_); + assertValuesEqual(NUMBER, result->type()); + assertTrue(isNaN(result->asNumber())); + } // testNumberFn7 + + void testFloorFn1() + { + XPathValuePtr result = parser.evaluate_expr("floor(1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testFloorFn1 + + void testFloorFn2() + { + XPathValuePtr result = parser.evaluate_expr("floor(1.0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testFloorFn2 + + void testFloorFn3() + { + XPathValuePtr result = parser.evaluate_expr("floor('1.0')", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testFloorFn3 + + void testFloorFn4() + { + XPathValuePtr result = parser.evaluate_expr("floor(1.1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testFloorFn4 + + void testFloorFn5() + { + XPathValuePtr result = parser.evaluate_expr("floor(0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(0.0, result->asNumber(), 0.0); + } // testFloorFn5 + + void testFloorFn6() + { + XPathValuePtr result = parser.evaluate_expr("floor(-1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testFloorFn6 + + void testFloorFn7() + { + XPathValuePtr result = parser.evaluate_expr("floor(-1.0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testFloorFn7 + + void testFloorFn8() + { + XPathValuePtr result = parser.evaluate_expr("floor(-1.1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-2.0, result->asNumber(), 0.0); + } // testFloorFn8 + + void testFloorFn9() + { + XPathValuePtr result = parser.evaluate_expr("floor('NaN')", document_); + assertValuesEqual(NUMBER, result->type()); + assertTrue(isNaN(result->asNumber())); + } // testFloorFn9 + + void testCeilingFn1() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testCeilingFn1 + + void testCeilingFn2() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(1.0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testCeilingFn2 + + void testCeilingFn3() + { + XPathValuePtr result = parser.evaluate_expr("ceiling('1.0')", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testCeilingFn3 + + void testCeilingFn4() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(1.1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(2.0, result->asNumber(), 0.0); + } // testCeilingFn4 + + void testCeilingFn5() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(0.0, result->asNumber(), 0.0); + } // testCeilingFn5 + + void testCeilingFn6() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(-1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testCeilingFn6 + + void testCeilingFn7() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(-1.0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testCeilingFn7 + + void testCeilingFn8() + { + XPathValuePtr result = parser.evaluate_expr("ceiling(-1.1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testCeilingFn8 + + void testCeilingFn9() + { + XPathValuePtr result = parser.evaluate_expr("ceiling('NaN')", document_); + assertValuesEqual(NUMBER, result->type()); + assertTrue(isNaN(result->asNumber())); + } // testCeilingFn9 + + void testStringFn1() + { + XPathValuePtr result = parser.evaluate_expr("string(0)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("0", result->asString()); + } // testStringFn1 + + void testStringFn2() + { + XPathValuePtr result = parser.evaluate_expr("string(true())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("true", result->asString()); + } // testStringFn2 + + void testStringFn3() + { + XPathValuePtr result = parser.evaluate_expr("string(false())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("false", result->asString()); + } // testStringFn3 + + void testStringFn4() + { + XPathValuePtr result = parser.evaluate_expr("string(number('poo'))", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("NaN", result->asString()); + } // testStringFn4 + + void testStringFn5() + { + XPathValuePtr result = parser.evaluate_expr("string('NaN')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("NaN", result->asString()); + } // testStringFn5 + + void testRoundFn1() + { + XPathValuePtr result = parser.evaluate_expr("round(1.0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testRoundFn1 + + void testRoundFn2() + { + XPathValuePtr result = parser.evaluate_expr("round(1.1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testRoundFn2 + + void testRoundFn3() + { + XPathValuePtr result = parser.evaluate_expr("round(1.5)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(2.0, result->asNumber(), 0.0); + } // testRoundFn3 + + void testRoundFn4() + { + XPathValuePtr result = parser.evaluate_expr("round(1.9)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(2.0, result->asNumber(), 0.0); + } // testRoundFn4 + + void testRoundFn5() + { + XPathValuePtr result = parser.evaluate_expr("round(-1.0)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testRoundFn5 + + void testRoundFn6() + { + XPathValuePtr result = parser.evaluate_expr("round(-1.1)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testRoundFn6 + + void testRoundFn7() + { + XPathValuePtr result = parser.evaluate_expr("round(-1.5)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-1.0, result->asNumber(), 0.0); + } // testRoundFn7 + + void testRoundFn8() + { + XPathValuePtr result = parser.evaluate_expr("round(-1.9)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-2.0, result->asNumber(), 0.0); + } // testRoundFn8 + + void testRoundFn9() + { + XPathValuePtr result = parser.evaluate_expr("round('NaN')", document_); + assertValuesEqual(NUMBER, result->type()); + assertTrue(isNaN(result->asNumber())); + } // testRoundFn9 + + void testRoundFn10() + { + XPathValuePtr result = parser.evaluate_expr("round(-0.4)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(-0.0, result->asNumber(), 0.0); + } // testRoundFn10 + + void testSumFn1() + { + XPathValuePtr result = parser.evaluate_expr("sum(/root)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(0.0, result->asNumber(), 0.0); + } // testSumFn1 + + void testSumFn2() + { + XPathValuePtr result = parser.evaluate_expr("sum(/root/child1/@one)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testSumFn2 + + void testSumFn3() + { + XPathValuePtr result = parser.evaluate_expr("sum(/root//@one)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(2.0, result->asNumber(), 0.0); + } // testSumFn3 + + void testSumFn4() + { + XPathValuePtr result = parser.evaluate_expr("sum(/root/child2/@*)", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(4.0, result->asNumber(), 0.0); + } // testSumFn4 + + void testConcatFn1() + { + XPathValuePtr result = parser.evaluate_expr("concat('a', 'b')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("ab", result->asString()); + } // testConcatFn1 + + void testConcatFn2() + { + XPathValuePtr result = parser.evaluate_expr("concat('a', 'b', 'c')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("abc", result->asString()); + } // testConcatFn2 + + void testConcatFn3() + { + XPathValuePtr result = parser.evaluate_expr("concat('a', 'b', 'c', 'd')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("abcd", result->asString()); + } // testConcatFn3 + + void testConcatFn4() + { + XPathValuePtr result = parser.evaluate_expr("concat(/root/child2/@one, /root/child2/@two, /root/child2/@three)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("111", result->asString()); + } // testConcatFn4 + + void testConcatFn5() + { + try { + parser.evaluate_expr("concat('please explode')", document_); + assertTrue(false); + } + catch(...) { } + } // testConcatFn5 + + void testStartsWithFn1() + { + XPathValuePtr result = parser.evaluate_expr("starts-with('hello', 'charlie drake')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(false, result->asBool()); + } // testStartsWithFn1 + + void testStartsWithFn2() + { + XPathValuePtr result = parser.evaluate_expr("starts-with('hello', 'hello mother')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(false, result->asBool()); + } // testStartsWithFn2 + + void testStartsWithFn3() + { + XPathValuePtr result = parser.evaluate_expr("starts-with('hello mother', 'hello')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(true, result->asBool()); + } // testStartsWithFn3 + + void testStartsWithFn4() + { + XPathValuePtr result = parser.evaluate_expr("starts-with('hello mother', 'hello mother')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(true, result->asBool()); + } // testStartsWithFn4 + + void testStringLengthFn1() + { + XPathValuePtr result = parser.evaluate_expr("string-length('')", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(0.0, result->asNumber(), 0.0); + } // testStringLengthFn1 + + void testStringLengthFn2() + { + XPathValuePtr result = parser.evaluate_expr("string-length('ab')", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(2.0, result->asNumber(), 0.0); + } // testStringLengthFn2 + + void testStringLengthFn3() + { + XPathValuePtr result = parser.evaluate_expr("string-length('abcd')", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(4.0, result->asNumber(), 0.0); + } // testStringLengthFn3 + + void testStringLengthFn4() + { + XPathValuePtr result = parser.evaluate_expr("string-length(concat('ab', 'cd'))", document_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(4.0, result->asNumber(), 0.0); + } // testStringLengthFn4 + + void testStringLengthFn5() + { + XPathValuePtr result = parser.evaluate_expr("string-length()", attr_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(1.0, result->asNumber(), 0.0); + } // testStringLengthFn5 + + void testStringLengthFn6() + { + XPathValuePtr result = parser.evaluate_expr("string-length()", element1_); + assertValuesEqual(NUMBER, result->type()); + assertDoublesEqual(0.0, result->asNumber(), 0.0); + } // testStringLengthFn6 + + void testContainsFn1() + { + XPathValuePtr result = parser.evaluate_expr("contains('hello', 'charlie drake')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(false, result->asBool()); + } // testContainsFn1 + + void testContainsFn2() + { + XPathValuePtr result = parser.evaluate_expr("contains('hello', 'hello mother')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(false, result->asBool()); + } // testContainsFn2 + + void testContainsFn3() + { + XPathValuePtr result = parser.evaluate_expr("contains('hello mother', 'hello')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(true, result->asBool()); + } // testContainsFn3 + + void testContainsFn4() + { + XPathValuePtr result = parser.evaluate_expr("contains('hello mother', 'hello mother')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(true, result->asBool()); + } // testContainsFn4 + + void testContainsFn5() + { + XPathValuePtr result = parser.evaluate_expr("contains('she heard a call hello mother somewhere in the distance', 'hello')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(true, result->asBool()); + } // testContainsFn5 + + void testContainsFn6() + { + XPathValuePtr result = parser.evaluate_expr("contains('my dogs says hello mother', 'hello mother')", document_); + assertValuesEqual(BOOL, result->type()); + assertValuesEqual(true, result->asBool()); + } // testContainsFn6 + + void testSubstringBeforeFn1() + { + XPathValuePtr result = parser.evaluate_expr("substring-before('1999/04/01', '/')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("1999", result->asString()); + } // testSubstringBeforeFn1 + + void testSubstringBeforeFn2() + { + XPathValuePtr result = parser.evaluate_expr("substring-before('1999/04/01', 'mogadon')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringBeforeFn2 + + void testSubstringBeforeFn3() + { + XPathValuePtr result = parser.evaluate_expr("substring-before('1999/04/01', '/01')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("1999/04", result->asString()); + } // testStringBeforeFn3 + + void testSubstringBeforeFn4() + { + XPathValuePtr result = parser.evaluate_expr("substring-before('1999/04/01', '1')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testStringBeforeFn4 + + void testSubstringAfterFn1() + { + XPathValuePtr result = parser.evaluate_expr("substring-after('1999/04/01', '/')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("04/01", result->asString()); + } // testSubstringAfterFn1 + + void testSubstringAfterFn2() + { + XPathValuePtr result = parser.evaluate_expr("substring-after('1999/04/01', 'mogadon')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringAfterFn2 + + void testSubstringAfterFn3() + { + XPathValuePtr result = parser.evaluate_expr("substring-after('1999/04/01', '/01')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testStringAfterFn3 + + void testSubstringAfterFn4() + { + XPathValuePtr result = parser.evaluate_expr("substring-after('1999/04/01', '19')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("99/04/01", result->asString()); + } // testStringAfterFn4 + + void testSubstringFn1() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 2, 3)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("234", result->asString()); + } // testSubstringFn1 + + void testSubstringFn2() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 2)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("2345", result->asString()); + } // testSubstringFn2 + + void testSubstringFn3() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 1.5, 2.6)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("234", result->asString()); + } // testSubstringFn3 + + void testSubstringFn4() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 0, 3)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12", result->asString()); + } // testSubstringFn4 + + void testSubstringFn5() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 0 div 0, 3)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringFn5 + + void testSubstringFn6() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 1, 0 div 0)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringFn6 + + void testSubstringFn7() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', -42, 1 div 0)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12345", result->asString()); + } // testSubstringFn7 + + void testSubstringFn8() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', -1 div 0, 1 div 0)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringFn8 + + void testSubstringFn9() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', 1, 'NaN')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringFn9 + + void testSubstringFn10() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', NaN)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringFn10 + + void testSubstringFn11() + { + XPathValuePtr result = parser.evaluate_expr("substring('12345', NaN, NaN)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testSubstringFn11 + + void testNormalizeSpaceFn1() + { + XPathValuePtr result = parser.evaluate_expr("normalize-space('12345')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12345", result->asString()); + } // testNormalizeSpaceFn1 + + void testNormalizeSpaceFn2() + { + XPathValuePtr result = parser.evaluate_expr("normalize-space(' 12345')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12345", result->asString()); + } // testNormalizeSpaceFn2 + + void testNormalizeSpaceFn3() + { + XPathValuePtr result = parser.evaluate_expr("normalize-space('12345 ')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12345", result->asString()); + } // testNormalizeSpaceFn3 + + void testNormalizeSpaceFn4() + { + XPathValuePtr result = parser.evaluate_expr("normalize-space(' 12345 ')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12345", result->asString()); + } // testNormalizeSpaceFn4 + + void testNormalizeSpaceFn5() + { + XPathValuePtr result = parser.evaluate_expr("normalize-space(' 12 3 45 ')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("12 3 45", result->asString()); + } // testNormalizeSpaceFn5 + + void testNormalizeSpaceFn6() + { + XPathValuePtr result = parser.evaluate_expr("normalize-space('1 2 3 4 5')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("1 2 3 4 5", result->asString()); + } // testNormalizeSpaceFn6 + + void testTranslateFn1() + { + XPathValuePtr result = parser.evaluate_expr("translate('bar','abc','ABC')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("BAr", result->asString()); + } // testTranslateFn1 + + void testTranslateFn2() + { + XPathValuePtr result = parser.evaluate_expr("translate('--aaa--','abc-','ABC')", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("AAA", result->asString()); + } // testTranslateFn2 + + void testLocalNameFn1() + { + XPathValuePtr result = parser.evaluate_expr("local-name(/root)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("root", result->asString()); + } // testLocalNameFn1 + + void testLocalNameFn2() + { + XPathValuePtr result = parser.evaluate_expr("local-name(/root/child2/@one)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testLocalNameFn2 + + void testLocalNameFn3() + { + XPathValuePtr result = parser.evaluate_expr("local-name(//comment())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testLocalNameFn3 + + void testLocalNameFn4() + { + XPathValuePtr result = parser.evaluate_expr("local-name(//processing-instruction())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("target", result->asString()); + } // testLocalNameFn4 + + void testLocalNameFn5() + { + XPathValuePtr result = parser.evaluate_expr("local-name()", root_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("root", result->asString()); + } // testLocalNameFn5 + + void testLocalNameFn6() + { + XPathValuePtr result = parser.evaluate_expr("local-name()", attr_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testLocalNameFn6 + + void testLocalNameFn7() + { + XPathValuePtr result = parser.evaluate_expr("local-name(//comment())", comment_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testLocalNameFn7 + + void testLocalNameFn8() + { + XPathValuePtr result = parser.evaluate_expr("local-name(//processing-instruction())", processingInstruction_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("target", result->asString()); + } // testLocalNameFn8 + + void testLocalNameFn9() + { + root_.appendChild(document_.createElementNS("test-uri", "element4")); + XPathValuePtr result = parser.evaluate_expr("local-name(/root/*[last()])", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("element4", result->asString()); + } // testLocalNameFn9 + + void testLocalNameFn10() + { + root_.setAttributeNS("test-uri", "q:woot", "hello"); + XPathValuePtr result = parser.evaluate_expr("local-name(/root/@*)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("woot", result->asString()); + } // testLocalNameFn10 + + void testLocalNameFn11() + { + root_.appendChild(document_.createElementNS("test-uri", "q:noob")); + XPathValuePtr result = parser.evaluate_expr("local-name(/root/*[last()])", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("noob", result->asString()); + } // testLocalNameFn11 + + void testNamespaceURIFn1() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri(/root)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn1 + + void testNamespaceURIFn2() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri(/root/child2/@one)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn2 + + void testNamespaceURIFn3() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri(//comment())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn3 + + void testNamespaceURIFn4() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri(//processing-instruction())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn4 + + void testNamespaceURIFn5() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri()", root_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn5 + + void testNamespaceURIFn6() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri()", attr_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn6 + + void testNamespaceURIFn7() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri(//comment())", comment_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn7 + + void testNamespaceURIFn8() + { + XPathValuePtr result = parser.evaluate_expr("namespace-uri(//processing-instruction())", processingInstruction_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNamespaceURIFn8 + + void testNamespaceURIFn9() + { + root_.appendChild(document_.createElementNS("test-uri", "element4")); + XPathValuePtr result = parser.evaluate_expr("namespace-uri(/root/*[last()])", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("test-uri", result->asString()); + } // testNamespaceURIFn9 + + void testNamespaceURIFn10() + { + root_.setAttributeNS("test-uri", "q:woot", "hello"); + XPathValuePtr result = parser.evaluate_expr("namespace-uri(/root/@*)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("test-uri", result->asString()); + } // testNamespaceURIFn10 + + void testNamespaceURIFn11() + { + root_.appendChild(document_.createElementNS("test-uri", "q:noob")); + XPathValuePtr result = parser.evaluate_expr("namespace-uri(/root/*[last()])", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("test-uri", result->asString()); + } // testNamespaceURIFn1 + + void testNameFn1() + { + XPathValuePtr result = parser.evaluate_expr("name(/root)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("root", result->asString()); + } // testNameFn1 + + void testNameFn2() + { + XPathValuePtr result = parser.evaluate_expr("name(/root/child2/@one)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testNameFn2 + + void testNameFn3() + { + XPathValuePtr result = parser.evaluate_expr("name(//comment())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNameFn3 + + void testNameFn4() + { + XPathValuePtr result = parser.evaluate_expr("name(//processing-instruction())", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("target", result->asString()); + } // testNameFn4 + + void testNameFn5() + { + XPathValuePtr result = parser.evaluate_expr("name()", root_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("root", result->asString()); + } // testNameFn5 + + void testNameFn6() + { + XPathValuePtr result = parser.evaluate_expr("name()", attr_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testNameFn6 + + void testNameFn7() + { + XPathValuePtr result = parser.evaluate_expr("name(//comment())", comment_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("", result->asString()); + } // testNameFn7 + + void testNameFn8() + { + XPathValuePtr result = parser.evaluate_expr("name(//processing-instruction())", processingInstruction_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("target", result->asString()); + } // testNameFn8 + + void testNameFn9() + { + root_.appendChild(document_.createElementNS("test-uri", "element4")); + XPathValuePtr result = parser.evaluate_expr("name(/root/*[last()])", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("element4", result->asString()); + } // testNameFn9 + + void testNameFn10() + { + root_.setAttributeNS("test-uri", "q:woot", "hello"); + XPathValuePtr result = parser.evaluate_expr("name(/root/@*)", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("q:woot", result->asString()); + } // testNameFn10 + + void testNameFn11() + { + root_.appendChild(document_.createElementNS("test-uri", "q:noob")); + XPathValuePtr result = parser.evaluate_expr("name(/root/*[last()])", document_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("q:noob", result->asString()); + } // testNameFn11 + + void testDocumentOrder1() + { + XPathValuePtr result = parser.evaluate_expr("string(/document/*)", chapters_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testDocumentOrder1 + + void testDocumentOrder2() + { + XPathValuePtr result = parser.evaluate_expr("string(/document/*[last()])", chapters_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("five", result->asString()); + } // testDocumentOrder2 + + void testDocumentOrder3() + { + XPathValuePtr result = parser.evaluate_expr("string(/document/chapter[5]/preceding-sibling::*[1])", chapters_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("four", result->asString()); + } // testDocumentOrder3 + + void testDocumentOrder4() + { + XPathValuePtr result = parser.evaluate_expr("string(/document/chapter[5]/preceding-sibling::*[last()])", chapters_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testDocumentOrder4 + + void testDocumentOrder5() + { + XPathValuePtr result = parser.evaluate_expr("string(/document/chapter[5]/preceding-sibling::*)", chapters_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("one", result->asString()); + } // testDocumentOrder5 + + void testLessThan1() + { + assertValuesEqual(false, parser.evaluate_expr("true() < true()", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("true() < false()", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("false() < false()", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("false() < true()", chapters_)->asBool()); + } // testLessThan1 + + void testLessThan2() + { + assertValuesEqual(false, parser.evaluate_expr("1 < 1", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("3.0 < 2.0", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("2.0 < 3.0", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("-1 < 1", chapters_)->asBool()); + } // testLessThan2 + + void testLessThan3() + { + assertValuesEqual(false, parser.evaluate_expr("'1' < '1'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("'3.0' < '2.0'", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("'2.0' < '3.0'", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("'-1' < '1'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("-1 < 'ooop'", chapters_)->asBool()); + } // testLessThan3 + + void testLessThan4() + { + assertValuesEqual(false, parser.evaluate_expr("/doc/number < 0", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[2] < 0", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number < 2", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number < 12", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("0 < /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("0 < /doc/number[2]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("1 < /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("7 < /doc/number", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("12 < /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()<5] < /doc/number[position()>5]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()<=5] < /doc/number[position()>4]", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[position()>5] < /doc/number[position()<5]", numbers_)->asBool()); + } // testLessThan4 + + void testLessThanEquals1() + { + assertValuesEqual(true, parser.evaluate_expr("true() <= true()", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("true() <= false()", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("false() <= false()", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("false() <= true()", chapters_)->asBool()); + } // testLessThanEquals1 + + void testLessThanEquals2() + { + assertValuesEqual(true, parser.evaluate_expr("1 <= 1", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("3.0 <= 2.0", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("2.0 <= 3.0", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("-1 <= 1", chapters_)->asBool()); + } // testLessThanEquals2 + + void testLessThanEquals3() + { + assertValuesEqual(true, parser.evaluate_expr("'1' <= '1'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("'3.0' <= '2.0'", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("'2.0' <= '3.0'", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("'-1' <= '1'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("-1 <= 'ooop'", chapters_)->asBool()); + } // testLessThanEquals3 + + void testLessThanEquals4() + { + assertValuesEqual(false, parser.evaluate_expr("/doc/number <= 0", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[2] <= 0", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number <= 2", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number <= 12", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("0 <= /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("0 <= /doc/number[2]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("1 <= /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("7 <= /doc/number", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("12 <= /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()<5] <= /doc/number[position()>5]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()<=5] <= /doc/number[position()>4]", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[position()>5] <= /doc/number[position()<5]", numbers_)->asBool()); + } // testLessThanEquals4 + + void testGreaterThan1() + { + assertValuesEqual(false, parser.evaluate_expr("true() > true()", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("true() > false()", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("false() > false()", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("false() > true()", chapters_)->asBool()); + } // testGreaterThan1 + + void testGreaterThan2() + { + assertValuesEqual(false, parser.evaluate_expr("1 > 1", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("3.0 > 2.0", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("2.0 > 3.0", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("-1 > 1", chapters_)->asBool()); + } // testGreaterThan2 + + void testGreaterThan3() + { + assertValuesEqual(false, parser.evaluate_expr("'1' > '1'", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("'3.0' > '2.0'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("'2.0' > '3.0'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("'-1' > '1'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("-1 > 'ooop'", chapters_)->asBool()); + } // testGreaterThan3 + + void testGreaterThan4() + { + assertValuesEqual(false, parser.evaluate_expr("3 > 2 > 1", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("(3>2)>1", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("3 > (2 > 1)", chapters_)->asBool()); + } // testGreaterThan4 + + void testGreaterThan5() + { + assertValuesEqual(true, parser.evaluate_expr("/doc/number > 0", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[2] > 0", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number > 1", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number > 12", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("0 > /doc/number", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("0 > /doc/number[2]", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("1 > /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("7 > /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("12 > /doc/number", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[position()<5] > /doc/number[position()>5]", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[position()<=5] > /doc/number[position()>4]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()>5] > /doc/number[position()<5]", numbers_)->asBool()); + } // testGreaterThan4 + + void testGreaterThanEquals1() + { + assertValuesEqual(true, parser.evaluate_expr("true() >= true()", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("true() >= false()", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("false() >= false()", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("false() >= true()", chapters_)->asBool()); + } // testGreaterThanEquals1 + + void testGreaterThanEquals2() + { + assertValuesEqual(true, parser.evaluate_expr("1 >= 1", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("3.0 >= 2.0", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("2.0 >= 3.0", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("-1 >= 1", chapters_)->asBool()); + } // testGreaterThanEquals2 + + void testGreaterThanEquals3() + { + assertValuesEqual(true, parser.evaluate_expr("'1' >= '1'", chapters_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("'3.0' >= '2.0'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("'2.0' >= '3.0'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("'-1' >= '1'", chapters_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("-1 >= 'ooop'", chapters_)->asBool()); + } // testGreaterThanEquals3 + + void testGreaterThanEquals4() + { + assertValuesEqual(true, parser.evaluate_expr("/doc/number >= 0", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[2] >= 0", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number >= 1", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number >= 12", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("0 >= /doc/number", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("0 >= /doc/number[2]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("1 >= /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("7 >= /doc/number", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("12 >= /doc/number", numbers_)->asBool()); + assertValuesEqual(false, parser.evaluate_expr("/doc/number[position()<5] >= /doc/number[position()>5]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()<=5] >= /doc/number[position()>4]", numbers_)->asBool()); + assertValuesEqual(true, parser.evaluate_expr("/doc/number[position()>5] >= /doc/number[position()<5]", numbers_)->asBool()); + } // testGreaterThanEquals4 + + void testNodeSetVars1() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(element1_); + ns.push_back(element2_); + ns.push_back(element3_); + svr.setVariable("fruit", ns); + + parser.setVariableResolver(svr); + XPathValuePtr result = parser.evaluate_expr("$fruit", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element1_ == result->asNodeSet()[0]); + assertTrue(element2_ == result->asNodeSet()[1]); + assertTrue(element3_ == result->asNodeSet()[2]); + } // testNodeSetVars1 + + void testNodeSetVars2() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(element1_); + ns.push_back(element2_); + ns.push_back(element3_); + svr.setVariable("fruit", ns); + + parser.setVariableResolver(svr); + XPathValuePtr result = parser.evaluate_expr("$fruit/spinkle", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(spinkle_ == result->asNodeSet()[0]); + } // testNodeSetVars2 + + void testNodeSetVars3() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(element1_); + ns.push_back(element2_); + ns.push_back(element3_); + svr.setVariable("fruit", ns); + + parser.setVariableResolver(svr); + XPathValuePtr result = parser.evaluate_expr("$fruit[2]/*", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(spinkle_ == result->asNodeSet()[0]); + } // testNodeSetVars3 + + void testNodeSetVars4() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(element1_); + ns.push_back(element2_); + ns.push_back(element3_); + svr.setVariable("fruit", ns); + + parser.setVariableResolver(svr); + XPathValuePtr result = parser.evaluate_expr("$fruit[true()][2]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetVars4 + + void testNodeSetVars5() + { + NodeSetVariableResolver svr; + NodeSet ns; + ns.push_back(element1_); + ns.push_back(element2_); + ns.push_back(element3_); + svr.setVariable("fruit", ns); + + parser.setVariableResolver(svr); + XPathValuePtr result = parser.evaluate_expr("$fruit[@two]", document_); + assertValuesEqual(NODE_SET, result->type()); + assertTrue(element2_ == result->asNodeSet()[0]); + } // testNodeSetVars5 + + void namespaceAxisTest1() + { + XPathValuePtr result = parser.evaluate_expr("namespace::*", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(0, result->asNodeSet().size()); + } // namespaceAxisTest1() + + void namespaceAxisTest2() + { + root_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:poop", "urn:test"); + XPathValuePtr result = parser.evaluate_expr("namespace::*", root_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(1, result->asNodeSet().size()); + assertValuesEqual("poop", result->asNodeSet()[0].getLocalName()); + assertValuesEqual("urn:test", result->asNodeSet()[0].getNodeValue()); + } // namespaceAxisTest2 + + void namespaceAxisTest3() + { + root_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:poop", "urn:test"); + element2_.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:test", "urn:another-test"); + XPathValuePtr result = parser.evaluate_expr("namespace::*", element2_); + assertValuesEqual(NODE_SET, result->type()); + assertValuesEqual(2, result->asNodeSet().size()); + } // namespaceAxisTest3 + + void testFunctionResolver1() + { + try { + parser.compile_expr("test-function()"); + assertTrue(false); + } + catch(...) { } + } // testFunctionResolver1 + + void testFunctionResolver2() + { + TestFunctionResolver tfr; + parser.setFunctionResolver(tfr); + + XPathValuePtr result = parser.evaluate_expr("test-function()", root_); + assertValuesEqual(STRING, result->type()); + assertValuesEqual("test-root", result->asString()); + } // testFunctionResolver2 + + void testSort1() + { + NodeSet ns; + + ns.push_back(element1_); + ns.push_back(element2_); + ns.push_back(element3_); + + ns.to_document_order(); + + assertTrue(element1_ == ns[0]); + assertTrue(element2_ == ns[1]); + assertTrue(element3_ == ns[2]); + } // testSort1 + + void testSort2() + { + NodeSet ns; + + ns.push_back(element3_); + ns.push_back(element2_); + ns.push_back(element1_); + + ns.to_document_order(); + + assertTrue(element1_ == ns[0]); + assertTrue(element2_ == ns[1]); + assertTrue(element3_ == ns[2]); + } // testSort2 +}; // class ExecuteTest + +TestSuite* ExecuteTest_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("test1", &ExecuteTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &ExecuteTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &ExecuteTest::test3)); + suiteOfTests->addTest(new TestCaller("test4", &ExecuteTest::test4)); + suiteOfTests->addTest(new TestCaller("test5", &ExecuteTest::test5)); + suiteOfTests->addTest(new TestCaller("test6", &ExecuteTest::test6)); + suiteOfTests->addTest(new TestCaller("test7", &ExecuteTest::test7)); + suiteOfTests->addTest(new TestCaller("test8", &ExecuteTest::test8)); + suiteOfTests->addTest(new TestCaller("test9", &ExecuteTest::test9)); + suiteOfTests->addTest(new TestCaller("test10", &ExecuteTest::test10)); + suiteOfTests->addTest(new TestCaller("test11", &ExecuteTest::test11)); + suiteOfTests->addTest(new TestCaller("test12", &ExecuteTest::test12)); + suiteOfTests->addTest(new TestCaller("test13", &ExecuteTest::test13)); + suiteOfTests->addTest(new TestCaller("test14", &ExecuteTest::test14)); + suiteOfTests->addTest(new TestCaller("test15", &ExecuteTest::test15)); + suiteOfTests->addTest(new TestCaller("test16", &ExecuteTest::test16)); + suiteOfTests->addTest(new TestCaller("test17", &ExecuteTest::test17)); + suiteOfTests->addTest(new TestCaller("test18", &ExecuteTest::test18)); + suiteOfTests->addTest(new TestCaller("test19", &ExecuteTest::test19)); + suiteOfTests->addTest(new TestCaller("test20", &ExecuteTest::test20)); + suiteOfTests->addTest(new TestCaller("test21", &ExecuteTest::test21)); + suiteOfTests->addTest(new TestCaller("test22", &ExecuteTest::test22)); + suiteOfTests->addTest(new TestCaller("test23", &ExecuteTest::test23)); + suiteOfTests->addTest(new TestCaller("test24", &ExecuteTest::test24)); + suiteOfTests->addTest(new TestCaller("test25", &ExecuteTest::test25)); + suiteOfTests->addTest(new TestCaller("test26", &ExecuteTest::test26)); + suiteOfTests->addTest(new TestCaller("test27", &ExecuteTest::test27)); + suiteOfTests->addTest(new TestCaller("test28", &ExecuteTest::test28)); + suiteOfTests->addTest(new TestCaller("test29", &ExecuteTest::test29)); + suiteOfTests->addTest(new TestCaller("test30", &ExecuteTest::test30)); + suiteOfTests->addTest(new TestCaller("test31", &ExecuteTest::test31)); + suiteOfTests->addTest(new TestCaller("test32", &ExecuteTest::test32)); + suiteOfTests->addTest(new TestCaller("test33", &ExecuteTest::test33)); + suiteOfTests->addTest(new TestCaller("test34", &ExecuteTest::test34)); + suiteOfTests->addTest(new TestCaller("test35", &ExecuteTest::test35)); + suiteOfTests->addTest(new TestCaller("test36", &ExecuteTest::test36)); + suiteOfTests->addTest(new TestCaller("test37", &ExecuteTest::test37)); + suiteOfTests->addTest(new TestCaller("test38", &ExecuteTest::test38)); + suiteOfTests->addTest(new TestCaller("test39", &ExecuteTest::test39)); + suiteOfTests->addTest(new TestCaller("test40", &ExecuteTest::test40)); + suiteOfTests->addTest(new TestCaller("test41", &ExecuteTest::test41)); + suiteOfTests->addTest(new TestCaller("testUnion1", &ExecuteTest::testUnion1)); + suiteOfTests->addTest(new TestCaller("testUnion2", &ExecuteTest::testUnion2)); + suiteOfTests->addTest(new TestCaller("testUnion3", &ExecuteTest::testUnion3)); + suiteOfTests->addTest(new TestCaller("testUnion4", &ExecuteTest::testUnion4)); + suiteOfTests->addTest(new TestCaller("testUnion5", &ExecuteTest::testUnion5)); + suiteOfTests->addTest(new TestCaller("testUnion6", &ExecuteTest::testUnion6)); + suiteOfTests->addTest(new TestCaller("testUnion7", &ExecuteTest::testUnion7)); + suiteOfTests->addTest(new TestCaller("testUnion8", &ExecuteTest::testUnion8)); + suiteOfTests->addTest(new TestCaller("testUnion9", &ExecuteTest::testUnion9)); + suiteOfTests->addTest(new TestCaller("testUnion10", &ExecuteTest::testUnion10)); + suiteOfTests->addTest(new TestCaller("testUnion11", &ExecuteTest::testUnion11)); + suiteOfTests->addTest(new TestCaller("testUnion12", &ExecuteTest::testUnion12)); + suiteOfTests->addTest(new TestCaller("testUnion13", &ExecuteTest::testUnion13)); + suiteOfTests->addTest(new TestCaller("testUnion14", &ExecuteTest::testUnion14)); + suiteOfTests->addTest(new TestCaller("testPlus1", &ExecuteTest::testPlus1)); + suiteOfTests->addTest(new TestCaller("testPlus2", &ExecuteTest::testPlus2)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality1", &ExecuteTest::testNodeSetEquality1)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality2", &ExecuteTest::testNodeSetEquality2)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality3", &ExecuteTest::testNodeSetEquality3)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality4", &ExecuteTest::testNodeSetEquality4)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality5", &ExecuteTest::testNodeSetEquality5)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality6", &ExecuteTest::testNodeSetEquality6)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality7", &ExecuteTest::testNodeSetEquality7)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality8", &ExecuteTest::testNodeSetEquality8)); + suiteOfTests->addTest(new TestCaller("testNodeSetEquality9", &ExecuteTest::testNodeSetEquality9)); + suiteOfTests->addTest(new TestCaller("testCountFn1", &ExecuteTest::testCountFn1)); + suiteOfTests->addTest(new TestCaller("testCountFn2", &ExecuteTest::testCountFn2)); + suiteOfTests->addTest(new TestCaller("testCountFn3", &ExecuteTest::testCountFn3)); + suiteOfTests->addTest(new TestCaller("testNotFn1", &ExecuteTest::testNotFn1)); + suiteOfTests->addTest(new TestCaller("testNotFn2", &ExecuteTest::testNotFn2)); + suiteOfTests->addTest(new TestCaller("testBooleanFn1", &ExecuteTest::testBooleanFn1)); + suiteOfTests->addTest(new TestCaller("testBooleanFn2", &ExecuteTest::testBooleanFn2)); + suiteOfTests->addTest(new TestCaller("testNumberFn1", &ExecuteTest::testNumberFn1)); + suiteOfTests->addTest(new TestCaller("testNumberFn2", &ExecuteTest::testNumberFn2)); + suiteOfTests->addTest(new TestCaller("testNumberFn3", &ExecuteTest::testNumberFn3)); + suiteOfTests->addTest(new TestCaller("testNumberFn4", &ExecuteTest::testNumberFn4)); + suiteOfTests->addTest(new TestCaller("testNumberFn5", &ExecuteTest::testNumberFn5)); + suiteOfTests->addTest(new TestCaller("testNumberFn6", &ExecuteTest::testNumberFn6)); + suiteOfTests->addTest(new TestCaller("testNumberFn7", &ExecuteTest::testNumberFn7)); + suiteOfTests->addTest(new TestCaller("testFloorFn1", &ExecuteTest::testFloorFn1)); + suiteOfTests->addTest(new TestCaller("testFloorFn2", &ExecuteTest::testFloorFn2)); + suiteOfTests->addTest(new TestCaller("testFloorFn3", &ExecuteTest::testFloorFn3)); + suiteOfTests->addTest(new TestCaller("testFloorFn4", &ExecuteTest::testFloorFn4)); + suiteOfTests->addTest(new TestCaller("testFloorFn5", &ExecuteTest::testFloorFn5)); + suiteOfTests->addTest(new TestCaller("testFloorFn6", &ExecuteTest::testFloorFn6)); + suiteOfTests->addTest(new TestCaller("testFloorFn7", &ExecuteTest::testFloorFn7)); + suiteOfTests->addTest(new TestCaller("testFloorFn8", &ExecuteTest::testFloorFn8)); + suiteOfTests->addTest(new TestCaller("testFloorFn9", &ExecuteTest::testFloorFn9)); + suiteOfTests->addTest(new TestCaller("testCeilingFn1", &ExecuteTest::testCeilingFn1)); + suiteOfTests->addTest(new TestCaller("testCeilingFn2", &ExecuteTest::testCeilingFn2)); + suiteOfTests->addTest(new TestCaller("testCeilingFn3", &ExecuteTest::testCeilingFn3)); + suiteOfTests->addTest(new TestCaller("testCeilingFn4", &ExecuteTest::testCeilingFn4)); + suiteOfTests->addTest(new TestCaller("testCeilingFn5", &ExecuteTest::testCeilingFn5)); + suiteOfTests->addTest(new TestCaller("testCeilingFn6", &ExecuteTest::testCeilingFn6)); + suiteOfTests->addTest(new TestCaller("testCeilingFn7", &ExecuteTest::testCeilingFn7)); + suiteOfTests->addTest(new TestCaller("testCeilingFn8", &ExecuteTest::testCeilingFn8)); + suiteOfTests->addTest(new TestCaller("testCeilingFn9", &ExecuteTest::testCeilingFn9)); + suiteOfTests->addTest(new TestCaller("testStringFn1", &ExecuteTest::testStringFn1)); + suiteOfTests->addTest(new TestCaller("testStringFn2", &ExecuteTest::testStringFn2)); + suiteOfTests->addTest(new TestCaller("testStringFn3", &ExecuteTest::testStringFn3)); + suiteOfTests->addTest(new TestCaller("testStringFn4", &ExecuteTest::testStringFn4)); + suiteOfTests->addTest(new TestCaller("testStringFn5", &ExecuteTest::testStringFn5)); + suiteOfTests->addTest(new TestCaller("testRoundFn1", &ExecuteTest::testRoundFn1)); + suiteOfTests->addTest(new TestCaller("testRoundFn2", &ExecuteTest::testRoundFn2)); + suiteOfTests->addTest(new TestCaller("testRoundFn3", &ExecuteTest::testRoundFn3)); + suiteOfTests->addTest(new TestCaller("testRoundFn4", &ExecuteTest::testRoundFn4)); + suiteOfTests->addTest(new TestCaller("testRoundFn5", &ExecuteTest::testRoundFn5)); + suiteOfTests->addTest(new TestCaller("testRoundFn6", &ExecuteTest::testRoundFn6)); + suiteOfTests->addTest(new TestCaller("testRoundFn7", &ExecuteTest::testRoundFn7)); + suiteOfTests->addTest(new TestCaller("testRoundFn8", &ExecuteTest::testRoundFn8)); + suiteOfTests->addTest(new TestCaller("testRoundFn9", &ExecuteTest::testRoundFn9)); + suiteOfTests->addTest(new TestCaller("testRoundFn10", &ExecuteTest::testRoundFn10)); + suiteOfTests->addTest(new TestCaller("testSumFn1", &ExecuteTest::testSumFn1)); + suiteOfTests->addTest(new TestCaller("testSumFn2", &ExecuteTest::testSumFn2)); + suiteOfTests->addTest(new TestCaller("testSumFn3", &ExecuteTest::testSumFn3)); + suiteOfTests->addTest(new TestCaller("testSumFn4", &ExecuteTest::testSumFn4)); + suiteOfTests->addTest(new TestCaller("testConcatFn1", &ExecuteTest::testConcatFn1)); + suiteOfTests->addTest(new TestCaller("testConcatFn2", &ExecuteTest::testConcatFn2)); + suiteOfTests->addTest(new TestCaller("testConcatFn3", &ExecuteTest::testConcatFn3)); + suiteOfTests->addTest(new TestCaller("testConcatFn4", &ExecuteTest::testConcatFn4)); + suiteOfTests->addTest(new TestCaller("testConcatFn5", &ExecuteTest::testConcatFn5)); + suiteOfTests->addTest(new TestCaller("testStartsWithFn1", &ExecuteTest::testStartsWithFn1)); + suiteOfTests->addTest(new TestCaller("testStartsWithFn2", &ExecuteTest::testStartsWithFn2)); + suiteOfTests->addTest(new TestCaller("testStartsWithFn3", &ExecuteTest::testStartsWithFn3)); + suiteOfTests->addTest(new TestCaller("testStartsWithFn4", &ExecuteTest::testStartsWithFn4)); + suiteOfTests->addTest(new TestCaller("testStringLengthFn1", &ExecuteTest::testStringLengthFn1)); + suiteOfTests->addTest(new TestCaller("testStringLengthFn2", &ExecuteTest::testStringLengthFn2)); + suiteOfTests->addTest(new TestCaller("testStringLengthFn3", &ExecuteTest::testStringLengthFn3)); + suiteOfTests->addTest(new TestCaller("testStringLengthFn4", &ExecuteTest::testStringLengthFn4)); + suiteOfTests->addTest(new TestCaller("testStringLengthFn5", &ExecuteTest::testStringLengthFn5)); + suiteOfTests->addTest(new TestCaller("testStringLengthFn6", &ExecuteTest::testStringLengthFn6)); + suiteOfTests->addTest(new TestCaller("testContainsFn1", &ExecuteTest::testContainsFn1)); + suiteOfTests->addTest(new TestCaller("testContainsFn2", &ExecuteTest::testContainsFn2)); + suiteOfTests->addTest(new TestCaller("testContainsFn3", &ExecuteTest::testContainsFn3)); + suiteOfTests->addTest(new TestCaller("testContainsFn4", &ExecuteTest::testContainsFn4)); + suiteOfTests->addTest(new TestCaller("testContainsFn5", &ExecuteTest::testContainsFn5)); + suiteOfTests->addTest(new TestCaller("testContainsFn6", &ExecuteTest::testContainsFn6)); + suiteOfTests->addTest(new TestCaller("testSubstringBeforeFn1", &ExecuteTest::testSubstringBeforeFn1)); + suiteOfTests->addTest(new TestCaller("testSubstringBeforeFn2", &ExecuteTest::testSubstringBeforeFn2)); + suiteOfTests->addTest(new TestCaller("testSubstringBeforeFn3", &ExecuteTest::testSubstringBeforeFn3)); + suiteOfTests->addTest(new TestCaller("testSubstringBeforeFn4", &ExecuteTest::testSubstringBeforeFn4)); + suiteOfTests->addTest(new TestCaller("testSubstringAfterFn1", &ExecuteTest::testSubstringAfterFn1)); + suiteOfTests->addTest(new TestCaller("testSubstringAfterFn2", &ExecuteTest::testSubstringAfterFn2)); + suiteOfTests->addTest(new TestCaller("testSubstringAfterFn3", &ExecuteTest::testSubstringAfterFn3)); + suiteOfTests->addTest(new TestCaller("testSubstringAfterFn4", &ExecuteTest::testSubstringAfterFn4)); + suiteOfTests->addTest(new TestCaller("testSubstringFn1", &ExecuteTest::testSubstringFn1)); + suiteOfTests->addTest(new TestCaller("testSubstringFn2", &ExecuteTest::testSubstringFn2)); + suiteOfTests->addTest(new TestCaller("testSubstringFn3", &ExecuteTest::testSubstringFn3)); + suiteOfTests->addTest(new TestCaller("testSubstringFn4", &ExecuteTest::testSubstringFn4)); + suiteOfTests->addTest(new TestCaller("testSubstringFn5", &ExecuteTest::testSubstringFn5)); + suiteOfTests->addTest(new TestCaller("testSubstringFn6", &ExecuteTest::testSubstringFn6)); + suiteOfTests->addTest(new TestCaller("testSubstringFn7", &ExecuteTest::testSubstringFn7)); + suiteOfTests->addTest(new TestCaller("testSubstringFn8", &ExecuteTest::testSubstringFn8)); + suiteOfTests->addTest(new TestCaller("testSubstringFn9", &ExecuteTest::testSubstringFn9)); + suiteOfTests->addTest(new TestCaller("testSubstringFn10", &ExecuteTest::testSubstringFn10)); + suiteOfTests->addTest(new TestCaller("testSubstringFn11", &ExecuteTest::testSubstringFn11)); + suiteOfTests->addTest(new TestCaller("testNormalizeSpaceFn1", &ExecuteTest::testNormalizeSpaceFn1)); + suiteOfTests->addTest(new TestCaller("testNormalizeSpaceFn2", &ExecuteTest::testNormalizeSpaceFn2)); + suiteOfTests->addTest(new TestCaller("testNormalizeSpaceFn3", &ExecuteTest::testNormalizeSpaceFn3)); + suiteOfTests->addTest(new TestCaller("testNormalizeSpaceFn4", &ExecuteTest::testNormalizeSpaceFn4)); + suiteOfTests->addTest(new TestCaller("testNormalizeSpaceFn5", &ExecuteTest::testNormalizeSpaceFn5)); + suiteOfTests->addTest(new TestCaller("testNormalizeSpaceFn6", &ExecuteTest::testNormalizeSpaceFn6)); + suiteOfTests->addTest(new TestCaller("testTranslateFn1", &ExecuteTest::testTranslateFn1)); + suiteOfTests->addTest(new TestCaller("testTranslateFn2", &ExecuteTest::testTranslateFn2)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn1", &ExecuteTest::testLocalNameFn1)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn2", &ExecuteTest::testLocalNameFn2)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn3", &ExecuteTest::testLocalNameFn3)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn4", &ExecuteTest::testLocalNameFn4)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn5", &ExecuteTest::testLocalNameFn5)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn6", &ExecuteTest::testLocalNameFn6)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn7", &ExecuteTest::testLocalNameFn7)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn8", &ExecuteTest::testLocalNameFn8)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn9", &ExecuteTest::testLocalNameFn9)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn10", &ExecuteTest::testLocalNameFn10)); + suiteOfTests->addTest(new TestCaller("testLocalNameFn11", &ExecuteTest::testLocalNameFn11)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn1", &ExecuteTest::testNamespaceURIFn1)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn2", &ExecuteTest::testNamespaceURIFn2)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn3", &ExecuteTest::testNamespaceURIFn3)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn4", &ExecuteTest::testNamespaceURIFn4)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn5", &ExecuteTest::testNamespaceURIFn5)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn6", &ExecuteTest::testNamespaceURIFn6)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn7", &ExecuteTest::testNamespaceURIFn7)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn8", &ExecuteTest::testNamespaceURIFn8)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn9", &ExecuteTest::testNamespaceURIFn9)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn10", &ExecuteTest::testNamespaceURIFn10)); + suiteOfTests->addTest(new TestCaller("testNamespaceURIFn11", &ExecuteTest::testNamespaceURIFn11)); + suiteOfTests->addTest(new TestCaller("testNameFn1", &ExecuteTest::testNameFn1)); + suiteOfTests->addTest(new TestCaller("testNameFn2", &ExecuteTest::testNameFn2)); + suiteOfTests->addTest(new TestCaller("testNameFn3", &ExecuteTest::testNameFn3)); + suiteOfTests->addTest(new TestCaller("testNameFn4", &ExecuteTest::testNameFn4)); + suiteOfTests->addTest(new TestCaller("testNameFn5", &ExecuteTest::testNameFn5)); + suiteOfTests->addTest(new TestCaller("testNameFn6", &ExecuteTest::testNameFn6)); + suiteOfTests->addTest(new TestCaller("testNameFn7", &ExecuteTest::testNameFn7)); + suiteOfTests->addTest(new TestCaller("testNameFn8", &ExecuteTest::testNameFn8)); + suiteOfTests->addTest(new TestCaller("testNameFn9", &ExecuteTest::testNameFn9)); + suiteOfTests->addTest(new TestCaller("testNameFn10", &ExecuteTest::testNameFn10)); + suiteOfTests->addTest(new TestCaller("testNameFn11", &ExecuteTest::testNameFn11)); + suiteOfTests->addTest(new TestCaller("testDocumentOrder1", &ExecuteTest::testDocumentOrder1)); + suiteOfTests->addTest(new TestCaller("testDocumentOrder2", &ExecuteTest::testDocumentOrder2)); + suiteOfTests->addTest(new TestCaller("testDocumentOrder3", &ExecuteTest::testDocumentOrder3)); + suiteOfTests->addTest(new TestCaller("testDocumentOrder4", &ExecuteTest::testDocumentOrder4)); + suiteOfTests->addTest(new TestCaller("testDocumentOrder5", &ExecuteTest::testDocumentOrder5)); + suiteOfTests->addTest(new TestCaller("testLessThan1", &ExecuteTest::testLessThan1)); + suiteOfTests->addTest(new TestCaller("testLessThan2", &ExecuteTest::testLessThan2)); + suiteOfTests->addTest(new TestCaller("testLessThan3", &ExecuteTest::testLessThan3)); + suiteOfTests->addTest(new TestCaller("testLessThan4", &ExecuteTest::testLessThan4)); + suiteOfTests->addTest(new TestCaller("testLessThanEquals1", &ExecuteTest::testLessThanEquals1)); + suiteOfTests->addTest(new TestCaller("testLessThanEquals2", &ExecuteTest::testLessThanEquals2)); + suiteOfTests->addTest(new TestCaller("testLessThanEquals3", &ExecuteTest::testLessThanEquals3)); + suiteOfTests->addTest(new TestCaller("testLessThanEquals4", &ExecuteTest::testLessThanEquals4)); + suiteOfTests->addTest(new TestCaller("testGreaterThan1", &ExecuteTest::testGreaterThan1)); + suiteOfTests->addTest(new TestCaller("testGreaterThan2", &ExecuteTest::testGreaterThan2)); + suiteOfTests->addTest(new TestCaller("testGreaterThan3", &ExecuteTest::testGreaterThan3)); + suiteOfTests->addTest(new TestCaller("testGreaterThan4", &ExecuteTest::testGreaterThan4)); + suiteOfTests->addTest(new TestCaller("testGreaterThan5", &ExecuteTest::testGreaterThan5)); + suiteOfTests->addTest(new TestCaller("testGreaterThanEquals1", &ExecuteTest::testGreaterThanEquals1)); + suiteOfTests->addTest(new TestCaller("testGreaterThanEquals2", &ExecuteTest::testGreaterThanEquals2)); + suiteOfTests->addTest(new TestCaller("testGreaterThanEquals3", &ExecuteTest::testGreaterThanEquals3)); + suiteOfTests->addTest(new TestCaller("testGreaterThanEquals4", &ExecuteTest::testGreaterThanEquals4)); + suiteOfTests->addTest(new TestCaller("testNodeSetVars1", &ExecuteTest::testNodeSetVars1)); + suiteOfTests->addTest(new TestCaller("testNodeSetVars2", &ExecuteTest::testNodeSetVars2)); + suiteOfTests->addTest(new TestCaller("testNodeSetVars3", &ExecuteTest::testNodeSetVars3)); + suiteOfTests->addTest(new TestCaller("testNodeSetVars4", &ExecuteTest::testNodeSetVars4)); + suiteOfTests->addTest(new TestCaller("testNodeSetVars5", &ExecuteTest::testNodeSetVars5)); + suiteOfTests->addTest(new TestCaller("namespaceAxisTest1", &ExecuteTest::namespaceAxisTest1)); + suiteOfTests->addTest(new TestCaller("namespaceAxisTest2", &ExecuteTest::namespaceAxisTest2)); + suiteOfTests->addTest(new TestCaller("namespaceAxisTest3", &ExecuteTest::namespaceAxisTest3)); + suiteOfTests->addTest(new TestCaller("testFunctionResolver1", &ExecuteTest::testFunctionResolver1)); + suiteOfTests->addTest(new TestCaller("testFunctionResolver2", &ExecuteTest::testFunctionResolver2)); + suiteOfTests->addTest(new TestCaller("testSort1", &ExecuteTest::testSort1)); + suiteOfTests->addTest(new TestCaller("testSort2", &ExecuteTest::testSort2)); + + return suiteOfTests; +} // ExecuteTest_suite diff --git a/test/XPath/execute_test.hpp b/test/XPath/execute_test.hpp new file mode 100644 index 00000000..02a7b0ff --- /dev/null +++ b/test/XPath/execute_test.hpp @@ -0,0 +1,7 @@ +#ifndef XPATHIC_EXECUTE_TEST_HPP +#define XPATHIC_EXECUTE_TEST_HPP + +TestSuite* ExecuteTest_suite(); + +#endif + diff --git a/test/XPath/logical_test.cpp b/test/XPath/logical_test.cpp new file mode 100644 index 00000000..88709225 --- /dev/null +++ b/test/XPath/logical_test.cpp @@ -0,0 +1,89 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include + +using namespace Arabica::XPath; + +class LogicalTest : public TestCase +{ +public: + LogicalTest(const std::string& name) : TestCase(name) + { + } // LogicalTest + + void setUp() + { + } // setUp + + void test1() + { + XPathExpressionPtr orTest(new OrOperator(new BoolValue(false), new BoolValue(false))); + assertEquals(false, orTest->evaluateAsBool(dummy_)); + } // test1 + + void test2() + { + XPathExpressionPtr orTest(new OrOperator(new BoolValue(false), new BoolValue(true))); + assertEquals(true, orTest->evaluateAsBool(dummy_)); + } // test2 + + void test3() + { + XPathExpressionPtr orTest(new OrOperator(new BoolValue(true), new BoolValue(false))); + assertEquals(true, orTest->evaluateAsBool(dummy_)); + } // test3 + + void test4() + { + XPathExpressionPtr orTest(new OrOperator(new BoolValue(true), new BoolValue(true))); + assertEquals(true, orTest->evaluateAsBool(dummy_)); + } // test4 + + void test5() + { + XPathExpressionPtr andTest(new AndOperator(new BoolValue(false), new BoolValue(false))); + assertEquals(false, andTest->evaluateAsBool(dummy_)); + } // test5 + + void test6() + { + XPathExpressionPtr andTest(new AndOperator(new BoolValue(false), new BoolValue(true))); + assertEquals(false, andTest->evaluateAsBool(dummy_)); + } // test6 + + void test7() + { + XPathExpressionPtr andTest(new AndOperator(new BoolValue(true), new BoolValue(false))); + assertEquals(false, andTest->evaluateAsBool(dummy_)); + } // test7 + + void test8() + { + XPathExpressionPtr andTest(new AndOperator(new BoolValue(true), new BoolValue(true))); + assertEquals(true, andTest->evaluateAsBool(dummy_)); + } // test8 + +private: + DOM::Node dummy_; +}; // class LogicalTest + +TestSuite* LogicalTest_suite() +{ + TestSuite* tests = new TestSuite; + + tests->addTest(new TestCaller("test1", &LogicalTest::test1)); + tests->addTest(new TestCaller("test2", &LogicalTest::test2)); + tests->addTest(new TestCaller("test3", &LogicalTest::test3)); + tests->addTest(new TestCaller("test4", &LogicalTest::test4)); + tests->addTest(new TestCaller("test5", &LogicalTest::test5)); + tests->addTest(new TestCaller("test6", &LogicalTest::test6)); + tests->addTest(new TestCaller("test7", &LogicalTest::test7)); + tests->addTest(new TestCaller("test8", &LogicalTest::test8)); + + return tests; +} // LogicalTest_suite diff --git a/test/XPath/logical_test.hpp b/test/XPath/logical_test.hpp new file mode 100644 index 00000000..6af23455 --- /dev/null +++ b/test/XPath/logical_test.hpp @@ -0,0 +1,6 @@ +#ifndef XPATHIC_LOGICAL_TEST_H +#define XPATHIC_LOGICAL_TEST_H + +TestSuite* LogicalTest_suite(); + +#endif diff --git a/test/XPath/main.cpp b/test/XPath/main.cpp new file mode 100644 index 00000000..bc1e2d28 --- /dev/null +++ b/test/XPath/main.cpp @@ -0,0 +1,167 @@ + +#pragma warning(disable:4224 4267) + +#include +#include "../CppUnit/textui/TextTestResult.h" +#include "../CppUnit/framework/Test.h" +#include "../CppUnit/framework/TestSuite.h" + +#include "parse_test.hpp" +#include "value_test.hpp" +#include "arithmetic_test.hpp" +#include "relational_test.hpp" +#include "logical_test.hpp" +#include "axis_enumerator_test.hpp" +#include "node_test_test.hpp" +#include "step_test.hpp" +#include "execute_test.hpp" + +class TestRunner +{ +protected: + bool m_wait; + std::vector > m_mappings; + +public: + TestRunner() : m_wait(false) {} + ~TestRunner(); + + void run(int ac, char **av); + void addTest(std::string name, Test *test) + { m_mappings.push_back(std::make_pair(name, test)); } + +protected: + void run(Test *test); + void printBanner(); +}; // TestRunner; + +///////////////////////////////////////// +int main(int argc, char** argv) +{ + std::cout << "Hello" << std::endl; + + TestRunner runner; + + runner.addTest("ValueTest", ValueTest_suite()); + runner.addTest("ArithmeticTest", ArithmeticTest_suite()); + runner.addTest("RelationalTest", RelationalTest_suite()); + runner.addTest("LogicalTest", LogicalTest_suite()); + runner.addTest("AxisEnumeratorTest", AxisEnumeratorTest_suite()); + runner.addTest("NodeTestTest", NodeTestTest_suite()); + runner.addTest("StepTest", StepTest_suite()); + runner.addTest("ParseTest", ParseTest_suite()); + runner.addTest("ExecuteTest", ExecuteTest_suite()); + + runner.run(argc, argv); +} // main + +////////////////////////////////////////// +/* + * A command line based tool to run tests. + * TestRunner expects as its only argument the name of a TestCase class. + * TestRunner prints out a trace as the tests are executed followed by a + * summary at the end. + * + * You can add to the tests that the TestRunner knows about by + * making additional calls to "addTest (...)" in main. + * + * Here is the synopsis: + * + * TestRunner [-wait] ExampleTestCase + * + */ + +using namespace std; + +typedef pair mapping; +typedef vector > mappings; + +void TestRunner::printBanner () +{ + cout << "Usage: driver [ -wait ] testName, where name is the name of a test case class" << endl; +} // printBanner + +void TestRunner::run(int ac, char **av) +{ + string testCase; + int numberOfTests = 0; + + for(int i = 1; i < ac; i++) + { + + if(string(av[i]) == "-wait") + { + m_wait = true; + continue; + } + + testCase = av[i]; + + if(testCase == "") + { + printBanner (); + return; + } + + Test *testToRun = NULL; + + for(mappings::iterator it = m_mappings.begin(); + it != m_mappings.end(); + ++it) + { + if((*it).first == testCase) + { + cout << (*it).first << std::endl; + testToRun = (*it).second; + run(testToRun); + } + } + + numberOfTests++; + + if(!testToRun) + { + cout << "Test " << testCase << " not found." << endl; + return; + } + } // for ... + + if(ac == 1) + { + // run everything + for(mappings::iterator it = m_mappings.begin(); it != m_mappings.end(); ++it) + { + cout << (*it).first << std::endl; + run((*it).second); + } + return; + } + + if(numberOfTests == 0) + { + printBanner (); + return; + } + + if(m_wait) + { + cout << " to continue" << endl; + cin.get (); + } +} // run + +TestRunner::~TestRunner () +{ + for(mappings::iterator it = m_mappings.begin (); + it != m_mappings.end (); + ++it) + delete it->second; +} // ~TestRunner + +void TestRunner::run(Test *test) +{ + TextTestResult result; + test->run (&result); + cout << result << endl; +} // run + diff --git a/test/XPath/node_test_test.cpp b/test/XPath/node_test_test.cpp new file mode 100644 index 00000000..2dee289b --- /dev/null +++ b/test/XPath/node_test_test.cpp @@ -0,0 +1,263 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include +#include + +using namespace Arabica::XPath; + +class NodeTestTest : public TestCase +{ + DOM::DOMImplementation factory_; + DOM::Document document_; + + DOM::Element root_; + + DOM::Element element1_; + DOM::Element element2_; + DOM::Element element3_; + + DOM::Attr attr_; + + DOM::Text text_; + + DOM::Comment comment_; + + DOM::ProcessingInstruction processingInstruction_; + +public: + NodeTestTest(const std::string& name) : TestCase(name) + { + } // NodeTestTest + + void setUp() + { + factory_ = SimpleDOM::DOMImplementation::getDOMImplementation(); + document_ = factory_.createDocument("", "root", 0); + root_ = document_.getDocumentElement(); + + element1_ = document_.createElement("child1"); + element2_ = document_.createElement("child2"); + element3_ = document_.createElement("child3"); + + element1_.setAttribute("one", "1"); + + element2_.setAttribute("one", "1"); + element2_.setAttribute("two", "1"); + element2_.setAttribute("three", "1"); + element2_.setAttribute("four", "1"); + + text_ = document_.createTextNode("data"); + comment_ = document_.createComment("comment"); + processingInstruction_ = document_.createProcessingInstruction("target", "data"); + element2_.appendChild(text_); + element2_.appendChild(document_.createElement("spinkle")); + element2_.appendChild(comment_); + element2_.appendChild(processingInstruction_); + + attr_ = element1_.getAttributeNode("one"); + + root_.appendChild(element1_); + root_.appendChild(element2_); + root_.appendChild(element3_); + } // setUp + + void test1() + { + AnyNodeTest test; + + assertTrue(test(element1_)); + assertTrue(test(element2_)); + assertTrue(test(root_)); + assertTrue(test(attr_)); + assertTrue(test(document_)); + assertTrue(test(text_)); + assertTrue(test(comment_)); + assertTrue(test(processingInstruction_)); + } // test1 + + void test2() + { + NameNodeTest test("child1"); + + assertTrue(test(element1_)); + assertTrue(!test(element2_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(!test(comment_)); + assertTrue(!test(processingInstruction_)); + } // test2 + + void test3() + { + NameNodeTest test("one"); + + assertTrue(!test(element1_)); + assertTrue(!test(element2_)); + assertTrue(!test(root_)); + assertTrue(test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(!test(comment_)); + assertTrue(!test(processingInstruction_)); + } // test3 + + void test4() + { + TextNodeTest test; + + assertTrue(!test(element1_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(test(text_)); + assertTrue(!test(comment_)); + assertTrue(!test(processingInstruction_)); + } // test4 + + void test5() + { + CommentNodeTest test; + + assertTrue(!test(element1_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(test(comment_)); + assertTrue(!test(processingInstruction_)); + } // test5 + + void test6() + { + ProcessingInstructionNodeTest test; + + assertTrue(!test(element1_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(!test(comment_)); + assertTrue(test(processingInstruction_)); + } // test6 + + void test7() + { + ProcessingInstructionNodeTest test("fruity"); + + assertTrue(!test(element1_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(!test(comment_)); + assertTrue(!test(processingInstruction_)); + } // test7 + + void test8() + { + ProcessingInstructionNodeTest test("target"); + + assertTrue(!test(element1_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(!test(comment_)); + assertTrue(test(processingInstruction_)); + } // test8 + + void test9() + { + StarNodeTest test; + + AxisEnumerator e(element2_, CHILD); + assertTrue(!test(*e)); + ++e; + assertTrue(test(*e)); + ++e; + assertTrue(!test(*e)); + ++e; + assertTrue(!test(*e)); + } // test9 + + void test10() + { + QNameNodeTest test("http://example.com/test", "one"); + + assertTrue(!test(element1_)); + assertTrue(!test(element2_)); + assertTrue(!test(root_)); + assertTrue(!test(attr_)); + assertTrue(!test(document_)); + assertTrue(!test(text_)); + assertTrue(!test(comment_)); + assertTrue(!test(processingInstruction_)); + } // test10 + + void test11() + { + QNameNodeTest test("http://example.com/test", "one"); + + DOM::Element e1_ = document_.createElementNS("http://example.com/test", "ns:one"); + DOM::Element e2_ = document_.createElementNS("http://example.com/test", "ttt:one"); + DOM::Element e3_ = document_.createElementNS("http://example.com/test", "ns:two"); + DOM::Element e4_ = document_.createElementNS("http://example.com/test", "ttt:two"); + DOM::Element e5_ = document_.createElementNS("http://example.com/ssss", "ns:one"); + DOM::Element e6_ = document_.createElementNS("http://example.com/eeee", "ttt:one"); + + assertTrue(test(e1_)); + assertTrue(test(e2_)); + assertTrue(!test(e3_)); + assertTrue(!test(e4_)); + assertTrue(!test(e5_)); + assertTrue(!test(e6_)); + } // test11 + + void test12() + { + QStarNodeTest test("http://example.com/test"); + + DOM::Element e1_ = document_.createElementNS("http://example.com/test", "ns:one"); + DOM::Element e2_ = document_.createElementNS("http://example.com/test", "ttt:one"); + DOM::Element e3_ = document_.createElementNS("http://example.com/test", "ns:two"); + DOM::Element e4_ = document_.createElementNS("http://example.com/test", "ttt:two"); + DOM::Element e5_ = document_.createElementNS("http://example.com/ssss", "ns:one"); + DOM::Element e6_ = document_.createElementNS("http://example.com/eeee", "ttt:one"); + + assertTrue(test(e1_)); + assertTrue(test(e2_)); + assertTrue(test(e3_)); + assertTrue(test(e4_)); + assertTrue(!test(e5_)); + assertTrue(!test(e6_)); + } // test12 +}; // class NodeTestTest + +TestSuite* NodeTestTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("test1", &NodeTestTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &NodeTestTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &NodeTestTest::test3)); + suiteOfTests->addTest(new TestCaller("test4", &NodeTestTest::test4)); + suiteOfTests->addTest(new TestCaller("test5", &NodeTestTest::test5)); + suiteOfTests->addTest(new TestCaller("test6", &NodeTestTest::test6)); + suiteOfTests->addTest(new TestCaller("test7", &NodeTestTest::test7)); + suiteOfTests->addTest(new TestCaller("test8", &NodeTestTest::test8)); + suiteOfTests->addTest(new TestCaller("test9", &NodeTestTest::test9)); + suiteOfTests->addTest(new TestCaller("test10", &NodeTestTest::test10)); + suiteOfTests->addTest(new TestCaller("test11", &NodeTestTest::test11)); + suiteOfTests->addTest(new TestCaller("test12", &NodeTestTest::test12)); + + return suiteOfTests; +} // NodeTestTest_suite + + \ No newline at end of file diff --git a/test/XPath/node_test_test.hpp b/test/XPath/node_test_test.hpp new file mode 100644 index 00000000..00efa98b --- /dev/null +++ b/test/XPath/node_test_test.hpp @@ -0,0 +1,6 @@ +#ifndef NODE_TEST_TEST_H +#define NODE_TEST_TEST_H + +TestSuite* NodeTestTest_suite(); + +#endif diff --git a/test/XPath/parse_test.cpp b/test/XPath/parse_test.cpp new file mode 100644 index 00000000..654d238c --- /dev/null +++ b/test/XPath/parse_test.cpp @@ -0,0 +1,394 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" +#include + +#include + +class ParseTest : public TestCase +{ + Arabica::XPath::XPath parser; + +public: + ParseTest(std::string name) : TestCase(name) + { + } // ParseTest + + void setUp() + { + } // setUp + + void test1() + { + assertTrue(parser.compile("text")); + assertTrue(parser.compile("comment")); + assertTrue(parser.compile("text()")); + assertTrue(parser.compile("text( )")); + assertTrue(parser.compile("text() ")); + assertTrue(parser.compile("text ( )")); + assertTrue(parser.compile("comment()")); + assertTrue(parser.compile("following-sibling::comment()")); + assertTrue(parser.compile("descendant::comment()")); + assertTrue(parser.compile("comment()[1]")); + assertTrue(parser.compile("comment()[2]")); + assertTrue(parser.compile("comment()[3]")); + assertTrue(parser.compile("/following-sibling::comment()")); + assertTrue(parser.compile("/descendant::comment()")); + assertTrue(parser.compile("/comment()[1]")); + assertTrue(parser.compile("/comment()[2]")); + assertTrue(parser.compile("/comment()[3]")); + } + + void test2() + { + Arabica::XPath::StandardNamespaceContext nsContext; + nsContext.addNamespaceDeclaration("something", "a"); + parser.setNamespaceContext(nsContext); + assertTrue(parser.compile("a:b")); + assertTrue(parser.compile(" a:b")); + assertTrue(parser.compile("a:b ")); + assertTrue(parser.compile(" a:b ")); + parser.resetNamespaceContext(); + } + + void test3() + { + assertTrue(parser.compile("processing-instruction()")); + assertTrue(parser.compile("processing-instruction( ) ")); + assertTrue(parser.compile("processing-instruction('poo')")); + assertTrue(parser.compile("processing-instruction(\"poo\")")); + assertTrue(parser.compile("processing-instruction( \"poo\")")); + assertTrue(parser.compile("processing-instruction( \"poo\" )")); + assertTrue(parser.compile("processing-instruction ( \"poo\" )")); + } + + void test4() + { + assertTrue(parser.compile("self::name")); + assertTrue(parser.compile(" self::name")); + assertTrue(parser.compile("self ::name")); + assertTrue(parser.compile("self:: name")); + assertTrue(parser.compile(" self :: name")); + } + + void test5() + { + assertTrue(parser.compile("@fruit")); + assertTrue(parser.compile(" @fruit")); + assertTrue(parser.compile("@ fruit")); + assertTrue(parser.compile(" @ fruit")); + } + + void test6() + { + assertTrue(parser.compile("one/two")); + assertTrue(parser.compile("one/@fruit")); + assertTrue(parser.compile("one/@fruit[1]")); + assertTrue(parser.compile("one/descendant-or-self::woot[1]")); + assertTrue(parser.compile("one/two/three")); + assertTrue(parser.compile("one/two/three[1]")); + assertTrue(parser.compile("one/two[1]/three")); + assertTrue(parser.compile("one/comment()")); + assertTrue(parser.compile("one/text()")); + assertTrue(parser.compile("one/processing-instruction()")); + assertTrue(parser.compile("one/node()")); + assertTrue(parser.compile("one/*")); + + Arabica::XPath::StandardNamespaceContext nsContext; + nsContext.addNamespaceDeclaration("urn:I:made:this:up", "ns"); + parser.setNamespaceContext(nsContext); + assertTrue(parser.compile("one/ns:*")); + assertTrue(parser.compile("one/ns:two")); + assertTrue(parser.compile("one/processing-instruction('parp')")); + } + + void test7() + { + assertTrue(parser.compile("/")); + assertTrue(parser.compile("/one")); + assertTrue(parser.compile("/one/two")); + assertTrue(parser.compile("/one[1]/two[2]/comment()")); + assertTrue(parser.compile("/one[1]/two[2][1]")); + } + + void test8() + { + assertTrue(parser.compile("//one")); + assertTrue(parser.compile("//one/two")); + assertTrue(parser.compile("//one/two//@id")); + assertTrue(parser.compile("//*[@id]")); + assertTrue(parser.compile("one//two")); + } + + void test9() + { + assertTrue(parser.compile(".")); + assertTrue(parser.compile("./something")); + assertTrue(parser.compile("./something/else")); + assertTrue(parser.compile("./something/./else")); + assertTrue(parser.compile("..")); + assertTrue(parser.compile("../something")); + assertTrue(parser.compile("../../something")); + assertTrue(parser.compile("../../something/../text()")); + } + + void test10() + { + assertTrue(parser.compile("/one/*")); + } + + void test11() + { + Arabica::XPath::StandardNamespaceContext nsContext; + nsContext.addNamespaceDeclaration("something", "ns"); + parser.setNamespaceContext(nsContext); + + assertTrue(parser.compile("/ns:one")); + assertTrue(parser.compile("//one/ns:two")); + assertTrue(parser.compile("//ns:one/ns:two//@id")); + assertTrue(parser.compile("//one/ns:*")); + + parser.resetNamespaceContext(); + } + + void test12() + { + assertTrue(parser.compile("one/two/three[@attr]")); + assertTrue(parser.compile("one/two/three[@attr][1]")); + assertTrue(parser.compile("one/two/three[four/@attr]")); + } + + void test13() + { + assertTrue(parser.compile("one/two/three[four|@attr]")); + } + + void test14() + { + assertTrue(parser.compile("one/two/three[-($a)]")); + assertTrue(parser.compile("one/two/three[--($a)]")); + assertTrue(parser.compile("one/two/three[-$a|$b]")); + assertTrue(parser.compile("one/two/three[2*-$a|$b]")); + assertTrue(parser.compile("one/two/three[2mod-$a|$b]")); + assertTrue(parser.compile("one/two/three[-(@two)=-1]")); + assertTrue(parser.compile("one/two/three[-(@two) =-1]")); + assertTrue(parser.compile("one/two/three[ -(@two)=-1]")); + assertTrue(parser.compile("one/two/three[-(@two) = -1]")); + } + + void test15() + { + assertTrue(parser.compile("one/two/three[four]")); + assertTrue(parser.compile("one/two/three[ four]")); + assertTrue(parser.compile("one/two/three[four ]")); + assertTrue(parser.compile("one/two/three[ four ]")); + } + + void test16() + { + assertTrue(parser.compile("one/two/three[/four]")); + assertTrue(parser.compile("one/two/three[/four/five]")); + assertTrue(parser.compile("one/two/three[/four/five[1]]")); + assertTrue(parser.compile("one/two/three[/four/five[@id][1]]")); + assertTrue(parser.compile("one/two/three[/four/five[1]/six]")); + assertTrue(parser.compile("one/two/three[/four/five[1]/six[@id][1]]")); + } + + void test17() + { + assertTrue(parser.compile("one/two/three[@attr1='nob']")); + assertTrue(parser.compile("one/two/three[$a=$b]")); + assertTrue(parser.compile("one/two/three[$a!=$b]")); + assertTrue(parser.compile("one/two/three[$a=$b=$c]")); + assertTrue(parser.compile("/root/*[child = true()]")); + assertTrue(parser.compile("/root/*[child = 1]")); + assertTrue(parser.compile("/root/*[child = '1']")); + assertTrue(parser.compile("/root/*[1]/trousers")); + assertTrue(parser.compile("/root/*[@* = @two]")); + assertTrue(parser.compile("/root/*[@*]")); + assertTrue(parser.compile("/root/*[*]")); + assertTrue(parser.compile("/root/*[charlie[one]]")); + assertTrue(parser.compile("/root/*[/one]")); + assertTrue(parser.compile("/root/*[charlie[/one]]")); + + assertTrue(parser.compile("/root/*[@* = child/@two]")); + assertTrue(parser.compile("/root/*[//root/child/@two = @*]")); + assertTrue(parser.compile("/root/*[/root/child/@two = @*]")); + assertTrue(parser.compile("/root/*[@*=//root/child/@two]")); + assertTrue(parser.compile("/root/*[@* =//root/child/@two]")); + assertTrue(parser.compile("/root/*[@* = //root/child/@two]")); + assertTrue(parser.compile("/root/*[@*= //root/child/@two]")); + assertTrue(parser.compile("/root/*[@*=/root/child/@two]")); + assertTrue(parser.compile("/root/*[@* =/root/child/@two]")); + assertTrue(parser.compile("/root/*[@* = /root/child/@two]")); + assertTrue(parser.compile("/root/*[@*= /root/child/@two]")); + assertTrue(parser.compile("root/*[@*=root/child/@two]")); + assertTrue(parser.compile("root/*[@* =root/child/@two]")); + assertTrue(parser.compile("root/*[@* = root/child/@two]")); + assertTrue(parser.compile("root/*[@*= root/child/@two]")); + + assertTrue(parser.compile("one/two/three[$a<$b]")); + assertTrue(parser.compile("one/two/three[$a <$b]")); + assertTrue(parser.compile("one/two/three[$a< $b]")); + assertTrue(parser.compile("one/two/three[$a <$b]")); + assertTrue(parser.compile("one/two/three[$a>$b]")); + assertTrue(parser.compile("one/two/three[$a >$b]")); + assertTrue(parser.compile("one/two/three[$a> $b]")); + assertTrue(parser.compile("one/two/three[$a > $b]")); + assertTrue(parser.compile("one/two/three[$a<$b]")); + assertTrue(parser.compile("one/two/three[$a>=$b]")); + assertTrue(parser.compile("one/two/three[$a<=$b]")); + assertTrue(parser.compile("one/two/three[$a>$b>$c]")); + assertTrue(parser.compile("one/two/three[$a>$b<$c]")); + assertTrue(parser.compile("one/two/three[$a=$b<$c]")); + + assertTrue(parser.compile("one/two/three[($a>$b)or($b>$c)]")); + assertTrue(parser.compile("one/two/three[($a>$b)and($b>$c)]")); + + assertTrue(parser.compile("/root/*[@* = string('woo')]")); + assertTrue(parser.compile("/root/*[@* = string(//root/child/@two)]")); + assertTrue(parser.compile_expr("$fruit/*[2]")); + assertTrue(parser.compile("/root[$fruit/root = @*]")); + assertTrue(parser.compile("/root/*[$fruit/root/child/@two = @*]")); + assertTrue(parser.compile("/root/*[$fruit/root/child/@two = $fruit/root/child/@two]")); + } + + void test18() + { + assertTrue(parser.compile("one/two/three[last()]")); + assertTrue(parser.compile("one/two/three[comment()]")); + assertTrue(parser.compile("one/two/three[string($a)]")); + + assertTrue(parser.compile("one/two/three[$var]")); + assertTrue(parser.compile("one/two/three[position()=1]")); + assertTrue(parser.compile("one/two/three[(@attr)or(@id)]")); + assertTrue(parser.compile("one/two/three[$var=1]")); + try { + parser.compile("one/two/three[string($a,$b)]"); + assert(false); + } + catch(...) { } + assertTrue(parser.compile("one/two/three[contains($a,string($b))]")); + } + + void test19() + { + assertTrue(parser.compile("one/two/three[(1+1)]")); + assertTrue(parser.compile("one/two/three[(1-1)]")); + assertTrue(parser.compile("one/two/three[(1+1-1)]")); + assertTrue(parser.compile("one/two/three[(1+1+1)]")); + assertTrue(parser.compile("one/two/three[(1+1+1+1)]")); + + assertTrue(parser.compile("one/two/three[(1*1)]")); + assertTrue(parser.compile("one/two/three[(1*1*1)]")); + assertTrue(parser.compile("one/two/three[(1*1*1*1)]")); + + assertTrue(parser.compile("one/two/three[(6div2)]")); + assertTrue(parser.compile("one/two/three[(5mod4)]")); + + assertTrue(parser.compile("one/two/three[(2*2)]")); + assertTrue(parser.compile("one[1 + 2 * 3]")); + assertTrue(parser.compile("one[3 * 2 + 1]")); + } + + void test20() + { + assertTrue(parser.compile("one/two/three[(1)]")); + assertTrue(parser.compile("one/two/three[(1.1)]")); + assertTrue(parser.compile("one/two/three[(1.)]")); + assertTrue(parser.compile("one/two/three[.1]")); + assertTrue(parser.compile("one/two/three[ .1 ]")); + assertTrue(parser.compile("one/two/three[(12)]")); + assertTrue(parser.compile("one/two/three[(123.456)]")); + assertTrue(parser.compile("one/two/three[(.123456)]")); + } + + void test21() + { + assertTrue(parser.compile("one/two/three[$var]")); + assertTrue(parser.compile("one/two/three [$var]")); + assertTrue(parser.compile("one/two/three[$var] ")); + assertTrue(parser.compile("one/two/three[$var] /four")); + assertTrue(parser.compile("one/two/three[$var ]")); + assertTrue(parser.compile("one/two/three[$var ]")); + assertTrue(parser.compile("one/two/three[ $var]")); + assertTrue(parser.compile("one/two/three[ $var]")); + assertTrue(parser.compile("one/two/three[ $var ]")); + assertTrue(parser.compile("one/two/three[$var = 1]")); + } + + void test22() + { + assertTrue(parser.compile("one/two/three[position() = 1]")); + assertTrue(parser.compile("one/two/three[position( ) = 1]")); + assertTrue(parser.compile("one/two/three[(@attr) or (@id)]")); + assertTrue(parser.compile("one/two/three[@attr or @id]")); + try { + parser.compile("one/two/three[string($a, $b)]"); + assert(false); + } + catch(...) { } + assertTrue(parser.compile("one/two/three[contains($a, string($b))]")); + assertTrue(parser.compile("one/two/three[contains( $a, string($b))]")); + assertTrue(parser.compile("one/two/three[contains ($a, string($b) )]")); + } // test22 + + void test23() + { + assertTrue(parser.compile("/root[count(something)]")); + try { + parser.compile("/root[count()]"); + assert(false); + } + catch(...) { } + try { + parser.compile("/root[count(one, two)]"); + assert(false); + } + catch(...) { } + try { + parser.compile("/root[count(one,two)]"); + assert(false); + } + catch(...) { } + try { + parser.compile("/root/count(one,two)"); + assert(false); + } + catch(...) { } + } // test23 +}; // class ParseTest + +TestSuite* ParseTest_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("test1", &ParseTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &ParseTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &ParseTest::test3)); + suiteOfTests->addTest(new TestCaller("test4", &ParseTest::test4)); + suiteOfTests->addTest(new TestCaller("test5", &ParseTest::test5)); + suiteOfTests->addTest(new TestCaller("test6", &ParseTest::test6)); + suiteOfTests->addTest(new TestCaller("test7", &ParseTest::test7)); + suiteOfTests->addTest(new TestCaller("test8", &ParseTest::test8)); + suiteOfTests->addTest(new TestCaller("test9", &ParseTest::test9)); + suiteOfTests->addTest(new TestCaller("test10", &ParseTest::test10)); + suiteOfTests->addTest(new TestCaller("test11", &ParseTest::test11)); + suiteOfTests->addTest(new TestCaller("test12", &ParseTest::test12)); + suiteOfTests->addTest(new TestCaller("test13", &ParseTest::test13)); + suiteOfTests->addTest(new TestCaller("test14", &ParseTest::test14)); + suiteOfTests->addTest(new TestCaller("test15", &ParseTest::test15)); + suiteOfTests->addTest(new TestCaller("test16", &ParseTest::test16)); + suiteOfTests->addTest(new TestCaller("test17", &ParseTest::test17)); + suiteOfTests->addTest(new TestCaller("test18", &ParseTest::test18)); + suiteOfTests->addTest(new TestCaller("test19", &ParseTest::test19)); + suiteOfTests->addTest(new TestCaller("test20", &ParseTest::test20)); + suiteOfTests->addTest(new TestCaller("test21", &ParseTest::test21)); + suiteOfTests->addTest(new TestCaller("test22", &ParseTest::test22)); + suiteOfTests->addTest(new TestCaller("test23", &ParseTest::test23)); + + return suiteOfTests; +} // ParseTest_suite diff --git a/test/XPath/parse_test.hpp b/test/XPath/parse_test.hpp new file mode 100644 index 00000000..3bf55bb2 --- /dev/null +++ b/test/XPath/parse_test.hpp @@ -0,0 +1,7 @@ +#ifndef XPATHIC_PARSE_TEST_H +#define XPATHIC_PARSE_TEST_H + +TestSuite* ParseTest_suite(); + +#endif + diff --git a/test/XPath/relational_test.cpp b/test/XPath/relational_test.cpp new file mode 100644 index 00000000..2fb9556a --- /dev/null +++ b/test/XPath/relational_test.cpp @@ -0,0 +1,189 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include + +using namespace Arabica::XPath; + +class RelationalTest : public TestCase +{ +public: + RelationalTest(const std::string& name) : TestCase(name) + { + } // RelationalTest + + void setUp() + { + } // setUp + + void test1() + { + XPathExpressionPtr equals1(new EqualsOperator(new NumericValue(1), new NumericValue(1))); + XPathExpressionPtr equals2(new EqualsOperator(new NumericValue(1), new NumericValue(1))); + + assertEquals(true, equals1->evaluateAsBool(dummy_)); + assertEquals(true, equals2->evaluateAsBool(dummy_)); + } // test1 + + void test2() + { + XPathExpressionPtr equals1(new EqualsOperator(new NumericValue(1), new NumericValue(2))); + XPathExpressionPtr equals2(new EqualsOperator(new NumericValue(2), new NumericValue(1))); + + assertEquals(false, equals1->evaluateAsBool(dummy_)); + assertEquals(false, equals2->evaluateAsBool(dummy_)); + } // test2 + + void test3() + { + XPathExpressionPtr equals1(new EqualsOperator(new NumericValue(1), new NumericValue(1))); + + assertEquals(true, equals1->evaluateAsBool(dummy_)); + } // test3 + + void test4() + { + XPathExpression* p1 = new StringValue("charlie"); + XPathExpression* p2 = new StringValue("charlie"); + + XPathExpressionPtr equals1(new EqualsOperator(p1, p2)); + + assertEquals(true, equals1->evaluateAsBool(dummy_)); + } // test4 + + void test5() + { + XPathExpression* p1 = new StringValue("trousers"); + XPathExpression* p2 = new StringValue("charlie"); + + XPathExpressionPtr equals1(new EqualsOperator(p1, p2)); + + assertEquals(false, equals1->evaluateAsBool(dummy_)); + } // test5 + + void test6() + { + XPathExpressionPtr equals1(new EqualsOperator(new BoolValue(true), new BoolValue(true))); + XPathExpressionPtr equals2(new EqualsOperator(new BoolValue(false), new BoolValue(false))); + + assertEquals(true, equals1->evaluateAsBool(dummy_)); + assertEquals(true, equals2->evaluateAsBool(dummy_)); + } // test6 + + void test7() + { + XPathExpressionPtr equals1(new EqualsOperator(new BoolValue(true), new BoolValue(false))); + XPathExpressionPtr equals2(new EqualsOperator(new BoolValue(false), new BoolValue(true))); + + assertEquals(false, equals1->evaluateAsBool(dummy_)); + assertEquals(false, equals2->evaluateAsBool(dummy_)); + } // test7 + + void testLessThan1() + { + XPathExpressionPtr lessThan1(new LessThanOperator(new BoolValue(true), new BoolValue(true))); + XPathExpressionPtr lessThan2(new LessThanOperator(new BoolValue(false), new BoolValue(false))); + XPathExpressionPtr lessThan3(new LessThanOperator(new BoolValue(true), new BoolValue(false))); + XPathExpressionPtr lessThan4(new LessThanOperator(new BoolValue(false), new BoolValue(true))); + + assertEquals(false, lessThan1->evaluateAsBool(dummy_)); + assertEquals(false, lessThan2->evaluateAsBool(dummy_)); + assertEquals(false, lessThan3->evaluateAsBool(dummy_)); + assertEquals(true, lessThan4->evaluateAsBool(dummy_)); + } // testLessThan1 + + void testLessThan2() + { + XPathExpressionPtr lessThan1(new LessThanOperator(new NumericValue(1.0), new NumericValue(1.0))); + XPathExpressionPtr lessThan2(new LessThanOperator(new NumericValue(3.0), new NumericValue(2.0))); + XPathExpressionPtr lessThan3(new LessThanOperator(new NumericValue(2.0), new NumericValue(3.0))); + XPathExpressionPtr lessThan4(new LessThanOperator(new NumericValue(-1), new NumericValue(1))); + + assertEquals(false, lessThan1->evaluateAsBool(dummy_)); + assertEquals(false, lessThan2->evaluateAsBool(dummy_)); + assertEquals(true, lessThan3->evaluateAsBool(dummy_)); + assertEquals(true, lessThan4->evaluateAsBool(dummy_)); + } // testLessThan2 + + void testLessThan3() + { + XPathExpressionPtr lessThan1(new LessThanOperator(new StringValue("1.0"), new StringValue("1.0"))); + XPathExpressionPtr lessThan2(new LessThanOperator(new StringValue("3.0"), new StringValue("2.0"))); + XPathExpressionPtr lessThan3(new LessThanOperator(new StringValue("2.0"), new StringValue("3.0"))); + XPathExpressionPtr lessThan4(new LessThanOperator(new StringValue("-1"), new StringValue("1"))); + + assertEquals(false, lessThan1->evaluateAsBool(dummy_)); + assertEquals(false, lessThan2->evaluateAsBool(dummy_)); + assertEquals(true, lessThan3->evaluateAsBool(dummy_)); + assertEquals(true, lessThan4->evaluateAsBool(dummy_)); + } // testLessThan3 + + void testLessThanEquals1() + { + XPathExpressionPtr lessThanEquals1(new LessThanEqualsOperator(new BoolValue(true), new BoolValue(true))); + XPathExpressionPtr lessThanEquals2(new LessThanEqualsOperator(new BoolValue(false), new BoolValue(false))); + XPathExpressionPtr lessThanEquals3(new LessThanEqualsOperator(new BoolValue(true), new BoolValue(false))); + XPathExpressionPtr lessThanEquals4(new LessThanEqualsOperator(new BoolValue(false), new BoolValue(true))); + + assertEquals(true, lessThanEquals1->evaluateAsBool(dummy_)); + assertEquals(true, lessThanEquals2->evaluateAsBool(dummy_)); + assertEquals(false, lessThanEquals3->evaluateAsBool(dummy_)); + assertEquals(true, lessThanEquals4->evaluateAsBool(dummy_)); + } // testLessThanEquals1 + + void testLessThanEquals2() + { + XPathExpressionPtr lessThanEquals1(new LessThanEqualsOperator(new NumericValue(1.0), new NumericValue(1.0))); + XPathExpressionPtr lessThanEquals2(new LessThanEqualsOperator(new NumericValue(3.0), new NumericValue(2.0))); + XPathExpressionPtr lessThanEquals3(new LessThanEqualsOperator(new NumericValue(2.0), new NumericValue(3.0))); + XPathExpressionPtr lessThanEquals4(new LessThanEqualsOperator(new NumericValue(-1), new NumericValue(1))); + + assertEquals(true, lessThanEquals1->evaluateAsBool(dummy_)); + assertEquals(false, lessThanEquals2->evaluateAsBool(dummy_)); + assertEquals(true, lessThanEquals3->evaluateAsBool(dummy_)); + assertEquals(true, lessThanEquals4->evaluateAsBool(dummy_)); + } // testLessThanEquals2 + + void testLessThanEquals3() + { + XPathExpressionPtr lessThanEquals1(new LessThanEqualsOperator(new StringValue("1.0"), new StringValue("1.0"))); + XPathExpressionPtr lessThanEquals2(new LessThanEqualsOperator(new StringValue("3.0"), new StringValue("2.0"))); + XPathExpressionPtr lessThanEquals3(new LessThanEqualsOperator(new StringValue("2.0"), new StringValue("3.0"))); + XPathExpressionPtr lessThanEquals4(new LessThanEqualsOperator(new StringValue("-1"), new StringValue("1"))); + + assertEquals(true, lessThanEquals1->evaluateAsBool(dummy_)); + assertEquals(false, lessThanEquals2->evaluateAsBool(dummy_)); + assertEquals(true, lessThanEquals3->evaluateAsBool(dummy_)); + assertEquals(true, lessThanEquals4->evaluateAsBool(dummy_)); + } // testLessThanEquals3 + +private: + DOM::Node dummy_; +}; // class RelationalTest + +TestSuite* RelationalTest_suite() +{ + TestSuite* tests = new TestSuite; + + tests->addTest(new TestCaller("test1", &RelationalTest::test1)); + tests->addTest(new TestCaller("test2", &RelationalTest::test2)); + tests->addTest(new TestCaller("test3", &RelationalTest::test3)); + tests->addTest(new TestCaller("test4", &RelationalTest::test4)); + tests->addTest(new TestCaller("test5", &RelationalTest::test5)); + tests->addTest(new TestCaller("test6", &RelationalTest::test6)); + tests->addTest(new TestCaller("test7", &RelationalTest::test7)); + + tests->addTest(new TestCaller("testLessThan1", &RelationalTest::testLessThan1)); + tests->addTest(new TestCaller("testLessThan2", &RelationalTest::testLessThan2)); + tests->addTest(new TestCaller("testLessThan3", &RelationalTest::testLessThan3)); + + tests->addTest(new TestCaller("testLessThanEquals1", &RelationalTest::testLessThanEquals1)); + tests->addTest(new TestCaller("testLessThanEquals2", &RelationalTest::testLessThanEquals2)); + tests->addTest(new TestCaller("testLessThanEquals3", &RelationalTest::testLessThanEquals3)); + + return tests; +} // RelationalTest_suite diff --git a/test/XPath/relational_test.hpp b/test/XPath/relational_test.hpp new file mode 100644 index 00000000..be713d60 --- /dev/null +++ b/test/XPath/relational_test.hpp @@ -0,0 +1,6 @@ +#ifndef XPATHIC_RELATIONAL_TEST_H +#define XPATHIC_RELATIONAL_TEST_H + +TestSuite* RelationalTest_suite(); + +#endif diff --git a/test/XPath/step_test.cpp b/test/XPath/step_test.cpp new file mode 100644 index 00000000..5968347d --- /dev/null +++ b/test/XPath/step_test.cpp @@ -0,0 +1,109 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224 4267) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include +#include "step_test.hpp" +#include + +using namespace Arabica::XPath; + +class StepTest : public TestCase +{ + DOM::DOMImplementation factory_; + DOM::Document document_; + + DOM::Element root_; + + DOM::Element element1_; + DOM::Element element2_; + DOM::Element element3_; + + DOM::Attr attr_; + +public: + StepTest(const std::string& name) : TestCase(name) + { + } // StepTest + + void setUp() + { + factory_ = SimpleDOM::DOMImplementation::getDOMImplementation(); + document_ = factory_.createDocument("", "root", 0); + root_ = document_.getDocumentElement(); + + element1_ = document_.createElement("child1"); + element2_ = document_.createElement("child2"); + element3_ = document_.createElement("child3"); + + element1_.setAttribute("one", "1"); + + element2_.setAttribute("one", "1"); + element2_.setAttribute("two", "1"); + element2_.setAttribute("three", "1"); + element2_.setAttribute("four", "1"); + + attr_ = element1_.getAttributeNode("one"); + + root_.appendChild(element1_); + root_.appendChild(element2_); + root_.appendChild(element3_); + } // setUp + + void test1() + { + XPathExpressionPtr step(new TestStepExpression(CHILD, new AnyNodeTest())); + + XPathValuePtr value = step->evaluate(root_); + const NodeSet& set = value->asNodeSet(); + + assertEquals(set.size(), 3); + assertTrue(set[0] == element1_); + assertTrue(set[1] == element2_); + assertTrue(set[2] == element3_); + } // test1 + + void test2() + { + XPathExpressionPtr step(new TestStepExpression(ATTRIBUTE, new AnyNodeTest())); + + NodeSet set = step->evaluateAsNodeSet(element2_); + + assertEquals(4, set.size()); + DOM::Attr attr = static_cast >(set[0]); + assertEquals(attr.getNodeName(), "one"); + attr = static_cast >(set[1]); + assertEquals(attr.getNodeName(), "two"); + attr = static_cast >(set[2]); + assertEquals(attr.getNodeName(), "three"); + attr = static_cast >(set[3]); + assertEquals(attr.getNodeName(), "four"); + } // test2 + + void test3() + { + XPathExpressionPtr step(new TestStepExpression(CHILD, new NameNodeTest("child2"))); + + XPathValuePtr value = step->evaluate(root_); + const NodeSet& set = value->asNodeSet(); + + assertEquals(1, set.size()); + assertTrue(set[0] == element2_); + } // test3 +}; // class StepTest + +TestSuite* StepTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("test1", &StepTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &StepTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &StepTest::test3)); + + return suiteOfTests; +} // StepTest_suite + + \ No newline at end of file diff --git a/test/XPath/step_test.hpp b/test/XPath/step_test.hpp new file mode 100644 index 00000000..38067fcd --- /dev/null +++ b/test/XPath/step_test.hpp @@ -0,0 +1,6 @@ +#ifndef STEP_TEST_H +#define STEP_TEST_H + +TestSuite* StepTest_suite(); + +#endif diff --git a/test/XPath/value_test.cpp b/test/XPath/value_test.cpp new file mode 100644 index 00000000..90e3e109 --- /dev/null +++ b/test/XPath/value_test.cpp @@ -0,0 +1,146 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503 4224) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include + +using namespace Arabica::XPath; + +class ValueTest : public TestCase +{ +private: + DOM::Node dummy_; + +public: + ValueTest(std::string name) : TestCase(name) + { + } // ValueTest + + void setUp() + { + } // setUp + + void test1() + { + XPathExpressionPtr b(new BoolValue(true)); + assertEquals(true, b->evaluateAsBool(dummy_)); + assertEquals(1.0, b->evaluateAsNumber(dummy_), 0.0); + assertEquals("true", b->evaluateAsString(dummy_)); + } + + void test2() + { + XPathExpressionPtr b2(new BoolValue(false)); + assertEquals(false, b2->evaluateAsBool(dummy_)); + assertEquals(0.0, b2->evaluateAsNumber(dummy_), 0.0); + assertEquals("false", b2->evaluateAsString(dummy_)); + } // test2 + + void test3() + { + XPathExpressionPtr n(new NumericValue(99.5)); + assertEquals(true, n->evaluateAsBool(dummy_)); + assertEquals(99.5, n->evaluateAsNumber(dummy_), 0.0); + assertEquals("99.5", n->evaluateAsString(dummy_)); + } + + void test4() + { + XPathExpressionPtr n(new NumericValue(0.0)); + assertEquals(false, n->evaluateAsBool(dummy_)); + assertEquals(0, n->evaluateAsNumber(dummy_), 0); + assertEquals("0", n->evaluateAsString(dummy_)); + } + + void test5() + { + XPathExpressionPtr s(new StringValue("hello")); + assertEquals(true, s->evaluateAsBool(dummy_)); + assertEquals("hello", s->evaluateAsString(dummy_)); + } // test5 + + void test6() + { + XPathExpressionPtr s(new StringValue("")); + assertEquals(false, s->evaluateAsBool(dummy_)); + } + + void test7() + { + XPathExpressionPtr s(new StringValue("100")); + assertEquals(true, s->evaluateAsBool(dummy_)); + assertEquals(100.0, s->evaluateAsNumber(dummy_), 0.0); + assertEquals("100", s->evaluateAsString(dummy_)); + } // test7 + + void test8() + { + XPathExpressionPtr s(new StringValue("0")); + assertEquals(true, s->evaluateAsBool(dummy_)); + assertEquals(0.0, s->evaluateAsNumber(dummy_), 0.0); + assertEquals("0", s->evaluateAsString(dummy_)); + } // test8 + + void test9() + { + XPathExpressionPtr bt(new BoolValue(true)); + XPathExpressionPtr st(new StringValue("true")); + XPathExpressionPtr bf(new BoolValue(false)); + XPathExpressionPtr sf(new StringValue("")); + + assertTrue(areEqual(bt->evaluate(dummy_), (st->evaluate(dummy_)))); + assertTrue(areEqual(st->evaluate(dummy_), (bt->evaluate(dummy_)))); + + assertTrue(areEqual(sf->evaluate(dummy_), (bf->evaluate(dummy_)))); + assertTrue(areEqual(bf->evaluate(dummy_), (sf->evaluate(dummy_)))); + + assertTrue(areEqual(bt->evaluate(dummy_), (bt->evaluate(dummy_)))); + assertTrue(areEqual(bf->evaluate(dummy_), (bf->evaluate(dummy_)))); + assertTrue(areEqual(st->evaluate(dummy_), (st->evaluate(dummy_)))); + assertTrue(areEqual(sf->evaluate(dummy_), (sf->evaluate(dummy_)))); + } // test9 + + void test10() + { + XPathExpressionPtr bt(new BoolValue(true)); + XPathExpressionPtr nt(new NumericValue(1.0)); + XPathExpressionPtr bf(new BoolValue(false)); + XPathExpressionPtr nf(new NumericValue(0.0)); + + assertTrue(areEqual(bt->evaluate(dummy_), (nt->evaluate(dummy_)))); + assertTrue(areEqual(nt->evaluate(dummy_), (bt->evaluate(dummy_)))); + + assertTrue(areEqual(bf->evaluate(dummy_), (nf->evaluate(dummy_)))); + assertTrue(areEqual(nf->evaluate(dummy_), (bf->evaluate(dummy_)))); + } // test10 + + void test11() + { + XPathExpressionPtr nt(new NumericValue(1.0)); + XPathValuePtr ns = nt->evaluate(dummy_); + + assertTrue(areEqual(ns, (nt->evaluate(dummy_)))); + } // test11 +}; // ValueTest + +TestSuite* ValueTest_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller("test1", &ValueTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &ValueTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &ValueTest::test3)); + suiteOfTests->addTest(new TestCaller("test4", &ValueTest::test4)); + suiteOfTests->addTest(new TestCaller("test5", &ValueTest::test5)); + suiteOfTests->addTest(new TestCaller("test6", &ValueTest::test6)); + suiteOfTests->addTest(new TestCaller("test7", &ValueTest::test7)); + suiteOfTests->addTest(new TestCaller("test8", &ValueTest::test8)); + suiteOfTests->addTest(new TestCaller("test9", &ValueTest::test9)); + suiteOfTests->addTest(new TestCaller("test10", &ValueTest::test10)); + suiteOfTests->addTest(new TestCaller("test11", &ValueTest::test11)); + + return suiteOfTests; +} // ValueTest_suite diff --git a/test/XPath/value_test.hpp b/test/XPath/value_test.hpp new file mode 100644 index 00000000..1a132a82 --- /dev/null +++ b/test/XPath/value_test.hpp @@ -0,0 +1,7 @@ +#ifndef XPATHIC_VALUE_TEST_H +#define XPATHIC_VALUE_TEST_H + +TestSuite* ValueTest_suite(); + +#endif + diff --git a/test/XPath/xpathic.vcproj b/test/XPath/xpathic.vcproj new file mode 100644 index 00000000..7a260990 --- /dev/null +++ b/test/XPath/xpathic.vcproj @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +