#ifndef XPATHIC_VALUE_TEST_H #define XPATHIC_VALUE_TEST_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class ValueTest : public TestCase { private: Arabica::DOM::Node dummy_; typedef string_adaptor SA; public: ValueTest(std::string name) : TestCase(name) { } // ValueTest void setUp() { } // setUp void test1() { using namespace Arabica::XPath; XPathExpression b(new BoolValue(true)); assertEquals(true, b.evaluateAsBool(dummy_)); assertEquals(1.0, b.evaluateAsNumber(dummy_), 0.0); assertTrue(SA::construct_from_utf8("true") == b.evaluateAsString(dummy_)); } void test2() { using namespace Arabica::XPath; XPathExpression b2(new BoolValue(false)); assertEquals(false, b2.evaluateAsBool(dummy_)); assertEquals(0.0, b2.evaluateAsNumber(dummy_), 0.0); assertTrue(SA::construct_from_utf8("false") == b2.evaluateAsString(dummy_)); } // test2 void test3() { using namespace Arabica::XPath; XPathExpression n(new NumericValue(99.5)); assertEquals(true, n.evaluateAsBool(dummy_)); assertEquals(99.5, n.evaluateAsNumber(dummy_), 0.0); assertTrue(SA::construct_from_utf8("99.5") == n.evaluateAsString(dummy_)); } void test4() { using namespace Arabica::XPath; XPathExpression n(new NumericValue(0.0)); assertEquals(false, n.evaluateAsBool(dummy_)); assertEquals(0, n.evaluateAsNumber(dummy_), 0); assertTrue(SA::construct_from_utf8("0") == n.evaluateAsString(dummy_)); } void test5() { using namespace Arabica::XPath; XPathExpression s(new StringValue("hello")); assertEquals(true, s.evaluateAsBool(dummy_)); assertTrue(SA::construct_from_utf8("hello") == s.evaluateAsString(dummy_)); } // test5 void test6() { using namespace Arabica::XPath; XPathExpression s(new StringValue("")); assertEquals(false, s.evaluateAsBool(dummy_)); } void test7() { using namespace Arabica::XPath; XPathExpression s(new StringValue("100")); assertEquals(true, s.evaluateAsBool(dummy_)); assertEquals(100.0, s.evaluateAsNumber(dummy_), 0.0); assertTrue(SA::construct_from_utf8("100") == s.evaluateAsString(dummy_)); } // test7 void test8() { using namespace Arabica::XPath; XPathExpression s(new StringValue("0")); assertEquals(true, s.evaluateAsBool(dummy_)); assertEquals(0.0, s.evaluateAsNumber(dummy_), 0.0); assertTrue(SA::construct_from_utf8("0") == s.evaluateAsString(dummy_)); } // test8 void test9() { using namespace Arabica::XPath; XPathExpression bt(new BoolValue(true)); XPathExpression st(new StringValue("true")); XPathExpression bf(new BoolValue(false)); XPathExpression sf(new StringValue("")); assertTrue((impl::areEqual(bt.evaluate(dummy_), (st.evaluate(dummy_))))); assertTrue((impl::areEqual(st.evaluate(dummy_), (bt.evaluate(dummy_))))); assertTrue((impl::areEqual(sf.evaluate(dummy_), (bf.evaluate(dummy_))))); assertTrue((impl::areEqual(bf.evaluate(dummy_), (sf.evaluate(dummy_))))); assertTrue((impl::areEqual(bt.evaluate(dummy_), (bt.evaluate(dummy_))))); assertTrue((impl::areEqual(bf.evaluate(dummy_), (bf.evaluate(dummy_))))); assertTrue((impl::areEqual(st.evaluate(dummy_), (st.evaluate(dummy_))))); assertTrue((impl::areEqual(sf.evaluate(dummy_), (sf.evaluate(dummy_))))); } // test9 void test10() { using namespace Arabica::XPath; XPathExpression bt(new BoolValue(true)); XPathExpression nt(new NumericValue(1.0)); XPathExpression bf(new BoolValue(false)); XPathExpression nf(new NumericValue(0.0)); assertTrue((impl::areEqual(bt.evaluate(dummy_), (nt.evaluate(dummy_))))); assertTrue((impl::areEqual(nt.evaluate(dummy_), (bt.evaluate(dummy_))))); assertTrue((impl::areEqual(bf.evaluate(dummy_), (nf.evaluate(dummy_))))); assertTrue((impl::areEqual(nf.evaluate(dummy_), (bf.evaluate(dummy_))))); } // test10 void test11() { using namespace Arabica::XPath; XPathExpression nt(new NumericValue(1.0)); XPathValue ns = nt.evaluate(dummy_); assertTrue((impl::areEqual(ns, (nt.evaluate(dummy_))))); } // test11 void test12() { using namespace Arabica::XPath; XPathExpression n(new NumericValue(NaN)); assertEquals(false, n.evaluateAsBool(dummy_)); assertTrue(isNaN(n.evaluateAsNumber(dummy_))); assertTrue(SA::construct_from_utf8("NaN") == n.evaluateAsString(dummy_)); } void test13() { using namespace Arabica::XPath; XPathExpression s(new StringValue(" 100 ")); assertEquals(true, s.evaluateAsBool(dummy_)); assertEquals(100.0, s.evaluateAsNumber(dummy_), 0.0); } // test13 void test14() { using namespace Arabica::XPath; XPathExpression s(new StringValue(" -100 ")); assertEquals(true, s.evaluateAsBool(dummy_)); assertEquals(-100.0, s.evaluateAsNumber(dummy_), 0.0); } // test14 void test15() { using namespace Arabica::XPath; XPathExpression s(new StringValue("trousers")); assertEquals(true, s.evaluateAsBool(dummy_)); assertTrue(isNaN(s.evaluateAsNumber(dummy_))); } // test15 }; // ValueTest template 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)); suiteOfTests->addTest(new TestCaller >("test12", &ValueTest::test12)); suiteOfTests->addTest(new TestCaller >("test13", &ValueTest::test13)); suiteOfTests->addTest(new TestCaller >("test14", &ValueTest::test14)); suiteOfTests->addTest(new TestCaller >("test15", &ValueTest::test15)); return suiteOfTests; } // ValueTest_suite #endif