#ifndef XPATHIC_RELATIONAL_TEST_H #define XPATHIC_RELATIONAL_TEST_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class RelationalTest : public TestCase { public: RelationalTest(const std::string& name) : TestCase(name) { } // RelationalTest void setUp() { } // setUp void test1() { using namespace Arabica::XPath; XPathExpression equals1(new impl::EqualsOperator(new NumericValue(1), new NumericValue(1))); XPathExpression equals2(new impl::EqualsOperator(new NumericValue(1), new NumericValue(1))); assertEquals(true, equals1.evaluateAsBool(dummy_)); assertEquals(true, equals2.evaluateAsBool(dummy_)); } // test1 void test2() { using namespace Arabica::XPath; XPathExpression equals1(new impl::EqualsOperator(new NumericValue(1), new NumericValue(2))); XPathExpression equals2(new impl::EqualsOperator(new NumericValue(2), new NumericValue(1))); assertEquals(false, equals1.evaluateAsBool(dummy_)); assertEquals(false, equals2.evaluateAsBool(dummy_)); } // test2 void test3() { using namespace Arabica::XPath; XPathExpression equals1(new impl::EqualsOperator(new NumericValue(1), new NumericValue(1))); assertEquals(true, equals1.evaluateAsBool(dummy_)); } // test3 void test4() { using namespace Arabica::XPath; XPathExpression_impl* p1 = new StringValue("charlie"); XPathExpression_impl* p2 = new StringValue("charlie"); XPathExpression equals1(new impl::EqualsOperator(p1, p2)); assertEquals(true, equals1.evaluateAsBool(dummy_)); } // test4 void test5() { using namespace Arabica::XPath; XPathExpression_impl* p1 = new StringValue("trousers"); XPathExpression_impl* p2 = new StringValue("charlie"); XPathExpression equals1(new impl::EqualsOperator(p1, p2)); assertEquals(false, equals1.evaluateAsBool(dummy_)); } // test5 void test6() { using namespace Arabica::XPath; XPathExpression equals1(new impl::EqualsOperator(new BoolValue(true), new BoolValue(true))); XPathExpression equals2(new impl::EqualsOperator(new BoolValue(false), new BoolValue(false))); assertEquals(true, equals1.evaluateAsBool(dummy_)); assertEquals(true, equals2.evaluateAsBool(dummy_)); } // test6 void test7() { using namespace Arabica::XPath; XPathExpression equals1(new impl::EqualsOperator(new BoolValue(true), new BoolValue(false))); XPathExpression equals2(new impl::EqualsOperator(new BoolValue(false), new BoolValue(true))); assertEquals(false, equals1.evaluateAsBool(dummy_)); assertEquals(false, equals2.evaluateAsBool(dummy_)); } // test7 void testLessThan1() { using namespace Arabica::XPath; XPathExpression lessThan1(new impl::LessThanOperator(new BoolValue(true), new BoolValue(true))); XPathExpression lessThan2(new impl::LessThanOperator(new BoolValue(false), new BoolValue(false))); XPathExpression lessThan3(new impl::LessThanOperator(new BoolValue(true), new BoolValue(false))); XPathExpression lessThan4(new impl::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() { using namespace Arabica::XPath; XPathExpression lessThan1(new impl::LessThanOperator(new NumericValue(1.0), new NumericValue(1.0))); XPathExpression lessThan2(new impl::LessThanOperator(new NumericValue(3.0), new NumericValue(2.0))); XPathExpression lessThan3(new impl::LessThanOperator(new NumericValue(2.0), new NumericValue(3.0))); XPathExpression lessThan4(new impl::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() { using namespace Arabica::XPath; XPathExpression lessThan1(new impl::LessThanOperator(new StringValue("1.0"), new StringValue("1.0"))); XPathExpression lessThan2(new impl::LessThanOperator(new StringValue("3.0"), new StringValue("2.0"))); XPathExpression lessThan3(new impl::LessThanOperator(new StringValue("2.0"), new StringValue("3.0"))); XPathExpression lessThan4(new impl::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() { using namespace Arabica::XPath; XPathExpression lessThanEquals1(new impl::LessThanEqualsOperator(new BoolValue(true), new BoolValue(true))); XPathExpression lessThanEquals2(new impl::LessThanEqualsOperator(new BoolValue(false), new BoolValue(false))); XPathExpression lessThanEquals3(new impl::LessThanEqualsOperator(new BoolValue(true), new BoolValue(false))); XPathExpression lessThanEquals4(new impl::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() { using namespace Arabica::XPath; XPathExpression lessThanEquals1(new impl::LessThanEqualsOperator(new NumericValue(1.0), new NumericValue(1.0))); XPathExpression lessThanEquals2(new impl::LessThanEqualsOperator(new NumericValue(3.0), new NumericValue(2.0))); XPathExpression lessThanEquals3(new impl::LessThanEqualsOperator(new NumericValue(2.0), new NumericValue(3.0))); XPathExpression lessThanEquals4(new impl::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() { using namespace Arabica::XPath; XPathExpression lessThanEquals1(new impl::LessThanEqualsOperator(new StringValue("1.0"), new StringValue("1.0"))); XPathExpression lessThanEquals2(new impl::LessThanEqualsOperator(new StringValue("3.0"), new StringValue("2.0"))); XPathExpression lessThanEquals3(new impl::LessThanEqualsOperator(new StringValue("2.0"), new StringValue("3.0"))); XPathExpression lessThanEquals4(new impl::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: Arabica::DOM::Node dummy_; }; // class RelationalTest template 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 #endif