mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
StepTest unification
This commit is contained in:
parent
ba55966762
commit
d58ead8ba9
9 changed files with 122 additions and 241 deletions
|
@ -10,8 +10,8 @@ DYNAMIC_LIBS += -lArabica
|
|||
|
||||
######################################
|
||||
# SOURCE FILES
|
||||
XPATH_SRCS = main.cpp arithmetic_test.cpp axis_enumerator_test.cpp execute_test.cpp logical_test.cpp node_test_test.cpp parse_test.cpp relational_test.cpp step_test.cpp value_test.cpp
|
||||
XPATH_HDRS = $(patsubst %.cpp,%.h,$(XPATH_SRCS))
|
||||
XPATH_SRCS = main.cpp
|
||||
XPATH_TESTS = arithmetic_test.hpp axis_enumerator_test.hpp execute_test.hpp logical_test.hpp node_test_test.hpp parse_test.hpp relational_test.hpp step_test.hpp value_test.hpp
|
||||
XPATH_OBJS = $(patsubst %.cpp,%.o,$(XPATH_SRCS))
|
||||
|
||||
CPPUNIT_DIR = ../CppUnit
|
||||
|
@ -24,11 +24,15 @@ CPPUNITUI_FILES = TextTestResult.cpp
|
|||
CPPUNITUI_SRCS = $(patsubst Text%,$(CPPUNIT_DIR)/textui/Text%,$(CPPUNITUI_FILES))
|
||||
CPPUNITUI_OBJS = $(patsubst %.cpp,%.o,$(CPPUNITUI_SRCS))
|
||||
|
||||
CPPUNITRUNNER_FILES = TestRunner.cpp
|
||||
CPPUNITRUNNER_SRCS = $(patsubst %.cpp,$(CPPUNIT_DIR),$CPPUNITRUNNER_FILES)
|
||||
CPPUNITRUNNER_OBJS = $(patsubst %.cpp,%.o,$(CPPUNITRUNNER_SRCS))
|
||||
|
||||
######################################
|
||||
# High level rules
|
||||
all : xpath_test
|
||||
|
||||
xpath_test : $(XPATH_OBJS) $(CPPUNITFW_OBJS) $(CPPUNITUI_OBJS)
|
||||
xpath_test : $(XPATH_OBJS) $(CPPUNITFW_OBJS) $(CPPUNITUI_OBJS) $(CPPUNITRUNNER_OBJS) $(XPATH_TESTS)
|
||||
$(LD) $(LDFLAGS) -o $@ $(XPATH_OBJS) $(CPPUNITFW_OBJS) $(CPPUNITUI_OBJS) $(LIBS_DIRS) $(STATIC_LIBS) $(DYNAMIC_LIBS)
|
||||
$(COPY) xpath_test$(EXESUFFIX) ../../bin
|
||||
|
||||
|
@ -42,8 +46,9 @@ xpath_test : $(XPATH_OBJS) $(CPPUNITFW_OBJS) $(CPPUNITUI_OBJS)
|
|||
clean :
|
||||
$(REMOVE) $(CPPUNITUI_OBJS) \
|
||||
$(CPPUNITFW_OBJS) \
|
||||
$(CPPUNITRUNNER_OBJS) \
|
||||
$(XPATH_OBJS) \
|
||||
xpath_test$(EXESUFFIX) \
|
||||
../../bin/xpath_test$(EXESUFFIX)
|
||||
|
||||
# End of File
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ int main(int argc, char** argv)
|
|||
runner.addTest("LogicalTest", LogicalTest_suite<std::string, Arabica::default_string_adaptor<std::string> >());
|
||||
runner.addTest("AxisEnumeratorTest", AxisEnumeratorTest_suite<std::string, Arabica::default_string_adaptor<std::string> >());
|
||||
runner.addTest("NodeTestTest", NodeTestTest_suite<std::string, Arabica::default_string_adaptor<std::string> >());
|
||||
runner.addTest("StepTest", StepTest_suite());
|
||||
runner.addTest("StepTest", StepTest_suite<std::string, Arabica::default_string_adaptor<std::string> >());
|
||||
runner.addTest("ParseTest", ParseTest_suite());
|
||||
runner.addTest("ExecuteTest", ExecuteTest_suite());
|
||||
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4786 4250 4503 4224 4267 4180)
|
||||
#endif
|
||||
#include "../CppUnit/framework/TestCase.h"
|
||||
#include "../CppUnit/framework/TestSuite.h"
|
||||
#include "../CppUnit/framework/TestCaller.h"
|
||||
|
||||
#include <XPath/XPath.hpp>
|
||||
#include "step_test.hpp"
|
||||
#include <DOM/Simple/DOMImplementation.h>
|
||||
|
||||
using namespace Arabica::XPath;
|
||||
|
||||
class StepTest : public TestCase
|
||||
{
|
||||
DOM::DOMImplementation<std::string> factory_;
|
||||
DOM::Document<std::string> document_;
|
||||
|
||||
DOM::Element<std::string> root_;
|
||||
|
||||
DOM::Element<std::string> element1_;
|
||||
DOM::Element<std::string> element2_;
|
||||
DOM::Element<std::string> element3_;
|
||||
|
||||
DOM::Attr<std::string> attr_;
|
||||
|
||||
public:
|
||||
StepTest(const std::string& name) : TestCase(name)
|
||||
{
|
||||
} // StepTest
|
||||
|
||||
void setUp()
|
||||
{
|
||||
factory_ = SimpleDOM::DOMImplementation<std::string>::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<std::string> step(new impl::TestStepExpression<std::string, Arabica::default_string_adaptor<std::string> >(CHILD, new impl::AnyNodeTest<std::string>()));
|
||||
|
||||
XPathValuePtr<std::string> value = step->evaluate(root_);
|
||||
const NodeSet<std::string>& set = value->asNodeSet();
|
||||
|
||||
assertEquals(set.size(), 3);
|
||||
assertTrue(set[0] == element1_);
|
||||
assertTrue(set[1] == element2_);
|
||||
assertTrue(set[2] == element3_);
|
||||
} // test1
|
||||
|
||||
void test2()
|
||||
{
|
||||
XPathExpressionPtr<std::string> step(new impl::TestStepExpression<std::string, Arabica::default_string_adaptor<std::string> >(ATTRIBUTE, new impl::AnyNodeTest<std::string>()));
|
||||
|
||||
NodeSet<std::string> set = step->evaluateAsNodeSet(element2_);
|
||||
|
||||
assertEquals(4, set.size());
|
||||
DOM::Attr<std::string> attr = static_cast<DOM::Attr<std::string> >(set[0]);
|
||||
assertEquals(attr.getNodeName(), "one");
|
||||
attr = static_cast<DOM::Attr<std::string> >(set[1]);
|
||||
assertEquals(attr.getNodeName(), "two");
|
||||
attr = static_cast<DOM::Attr<std::string> >(set[2]);
|
||||
assertEquals(attr.getNodeName(), "three");
|
||||
attr = static_cast<DOM::Attr<std::string> >(set[3]);
|
||||
assertEquals(attr.getNodeName(), "four");
|
||||
} // test2
|
||||
|
||||
void test3()
|
||||
{
|
||||
XPathExpressionPtr<std::string> step(new impl::TestStepExpression<std::string, Arabica::default_string_adaptor<std::string> >(CHILD,
|
||||
new impl::NameNodeTest<std::string, Arabica::default_string_adaptor<std::string> >("child2")));
|
||||
|
||||
XPathValuePtr<std::string> value = step->evaluate(root_);
|
||||
const NodeSet<std::string>& 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<StepTest>("test1", &StepTest::test1));
|
||||
suiteOfTests->addTest(new TestCaller<StepTest>("test2", &StepTest::test2));
|
||||
suiteOfTests->addTest(new TestCaller<StepTest>("test3", &StepTest::test3));
|
||||
|
||||
return suiteOfTests;
|
||||
} // StepTest_suite
|
|
@ -1,6 +1,114 @@
|
|||
#ifndef STEP_TEST_H
|
||||
#define STEP_TEST_H
|
||||
|
||||
TestSuite* StepTest_suite();
|
||||
#include "../CppUnit/framework/TestCase.h"
|
||||
#include "../CppUnit/framework/TestSuite.h"
|
||||
#include "../CppUnit/framework/TestCaller.h"
|
||||
|
||||
#include <XPath/XPath.hpp>
|
||||
#include <DOM/Simple/DOMImplementation.h>
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
class StepTest : public TestCase
|
||||
{
|
||||
typedef string_adaptor SA;
|
||||
|
||||
DOM::DOMImplementation<string_type> factory_;
|
||||
DOM::Document<string_type> document_;
|
||||
|
||||
DOM::Element<string_type> root_;
|
||||
|
||||
DOM::Element<string_type> element1_;
|
||||
DOM::Element<string_type> element2_;
|
||||
DOM::Element<string_type> element3_;
|
||||
|
||||
DOM::Attr<string_type> attr_;
|
||||
|
||||
public:
|
||||
StepTest(const std::string& name) : TestCase(name)
|
||||
{
|
||||
} // StepTest
|
||||
|
||||
void setUp()
|
||||
{
|
||||
factory_ = SimpleDOM::DOMImplementation<string_type>::getDOMImplementation();
|
||||
document_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8("root"), 0);
|
||||
root_ = document_.getDocumentElement();
|
||||
|
||||
element1_ = document_.createElement(SA::construct_from_utf8("child1"));
|
||||
element2_ = document_.createElement(SA::construct_from_utf8("child2"));
|
||||
element3_ = document_.createElement(SA::construct_from_utf8("child3"));
|
||||
|
||||
element1_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1"));
|
||||
|
||||
element2_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1"));
|
||||
element2_.setAttribute(SA::construct_from_utf8("two"), SA::construct_from_utf8("1"));
|
||||
element2_.setAttribute(SA::construct_from_utf8("three"), SA::construct_from_utf8("1"));
|
||||
element2_.setAttribute(SA::construct_from_utf8("four"), SA::construct_from_utf8("1"));
|
||||
|
||||
attr_ = element1_.getAttributeNode(SA::construct_from_utf8("one"));
|
||||
|
||||
root_.appendChild(element1_);
|
||||
root_.appendChild(element2_);
|
||||
root_.appendChild(element3_);
|
||||
} // setUp
|
||||
|
||||
void test1()
|
||||
{
|
||||
using namespace Arabica::XPath;
|
||||
XPathExpressionPtr<string_type> step(new impl::TestStepExpression<string_type, string_adaptor>(CHILD, new impl::AnyNodeTest<string_type>()));
|
||||
|
||||
XPathValuePtr<string_type> value = step->evaluate(root_);
|
||||
const NodeSet<string_type>& set = value->asNodeSet();
|
||||
|
||||
assertEquals(set.size(), 3);
|
||||
assertTrue(set[0] == element1_);
|
||||
assertTrue(set[1] == element2_);
|
||||
assertTrue(set[2] == element3_);
|
||||
} // test1
|
||||
|
||||
void test2()
|
||||
{
|
||||
using namespace Arabica::XPath;
|
||||
XPathExpressionPtr<string_type> step(new impl::TestStepExpression<string_type, string_adaptor>(ATTRIBUTE, new impl::AnyNodeTest<string_type>()));
|
||||
|
||||
NodeSet<string_type> set = step->evaluateAsNodeSet(element2_);
|
||||
|
||||
assertEquals(4, set.size());
|
||||
DOM::Attr<string_type> attr = static_cast<DOM::Attr<string_type> >(set[0]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("one"));
|
||||
attr = static_cast<DOM::Attr<string_type> >(set[1]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("two"));
|
||||
attr = static_cast<DOM::Attr<string_type> >(set[2]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("three"));
|
||||
attr = static_cast<DOM::Attr<string_type> >(set[3]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("four"));
|
||||
} // test2
|
||||
|
||||
void test3()
|
||||
{
|
||||
using namespace Arabica::XPath;
|
||||
XPathExpressionPtr<string_type> step(new impl::TestStepExpression<string_type,
|
||||
string_adaptor>(CHILD, new impl::NameNodeTest<string_type, string_adaptor>(SA::construct_from_utf8("child2"))));
|
||||
|
||||
XPathValuePtr<string_type> value = step->evaluate(root_);
|
||||
const NodeSet<string_type>& set = value->asNodeSet();
|
||||
|
||||
assertEquals(1, set.size());
|
||||
assertTrue(set[0] == element2_);
|
||||
} // test3
|
||||
}; // class StepTest
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
TestSuite* StepTest_suite()
|
||||
{
|
||||
TestSuite* suiteOfTests = new TestSuite;
|
||||
|
||||
suiteOfTests->addTest(new TestCaller<StepTest<string_type, string_adaptor> >("test1", &StepTest<string_type, string_adaptor>::test1));
|
||||
suiteOfTests->addTest(new TestCaller<StepTest<string_type, string_adaptor> >("test2", &StepTest<string_type, string_adaptor>::test2));
|
||||
suiteOfTests->addTest(new TestCaller<StepTest<string_type, string_adaptor> >("test3", &StepTest<string_type, string_adaptor>::test3));
|
||||
|
||||
return suiteOfTests;
|
||||
} // StepTest_suite
|
||||
|
||||
#endif
|
||||
|
|
|
@ -137,9 +137,6 @@
|
|||
<File
|
||||
RelativePath=".\relational_test.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\step_test.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "../XPath/logical_test.hpp"
|
||||
#include "../XPath/axis_enumerator_test.hpp"
|
||||
#include "../XPath/node_test_test.hpp"
|
||||
#include "step_test.hpp"
|
||||
#include "../XPath/step_test.hpp"
|
||||
#include "parse_test.hpp"
|
||||
#include "execute_test.hpp"
|
||||
|
||||
|
@ -35,7 +35,7 @@ int main(int argc, char** argv)
|
|||
runner.addTest("LogicalTest", LogicalTest_suite<silly_string, Arabica::default_string_adaptor<silly_string> >());
|
||||
runner.addTest("AxisEnumeratorTest", AxisEnumeratorTest_suite<silly_string, Arabica::default_string_adaptor<silly_string> >());
|
||||
runner.addTest("NodeTestTest", NodeTestTest_suite<silly_string, Arabica::default_string_adaptor<silly_string> >());
|
||||
runner.addTest("StepTest", StepTest_suite());
|
||||
runner.addTest("StepTest", StepTest_suite<silly_string, Arabica::default_string_adaptor<silly_string> >());
|
||||
runner.addTest("ParseTest", ParseTest_suite());
|
||||
runner.addTest("ExecuteTest", ExecuteTest_suite());
|
||||
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4786 4250 4503 4224 4267 4180)
|
||||
#endif
|
||||
#include "../CppUnit/framework/TestCase.h"
|
||||
#include "../CppUnit/framework/TestSuite.h"
|
||||
#include "../CppUnit/framework/TestCaller.h"
|
||||
|
||||
#include <XPath/XPath.hpp>
|
||||
#include "step_test.hpp"
|
||||
#include <DOM/Simple/DOMImplementation.h>
|
||||
#include "../silly_string/silly_string.hpp"
|
||||
|
||||
using namespace Arabica::XPath;
|
||||
template<> class Arabica::default_string_adaptor<silly_string> : public silly_string_adaptor { };
|
||||
|
||||
class StepTest : public TestCase
|
||||
{
|
||||
typedef silly_string_adaptor SA;
|
||||
|
||||
DOM::DOMImplementation<silly_string> factory_;
|
||||
DOM::Document<silly_string> document_;
|
||||
|
||||
DOM::Element<silly_string> root_;
|
||||
|
||||
DOM::Element<silly_string> element1_;
|
||||
DOM::Element<silly_string> element2_;
|
||||
DOM::Element<silly_string> element3_;
|
||||
|
||||
DOM::Attr<silly_string> attr_;
|
||||
|
||||
public:
|
||||
StepTest(const std::string& name) : TestCase(name)
|
||||
{
|
||||
} // StepTest
|
||||
|
||||
void setUp()
|
||||
{
|
||||
factory_ = SimpleDOM::DOMImplementation<silly_string>::getDOMImplementation();
|
||||
document_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8("root"), 0);
|
||||
root_ = document_.getDocumentElement();
|
||||
|
||||
element1_ = document_.createElement(SA::construct_from_utf8("child1"));
|
||||
element2_ = document_.createElement(SA::construct_from_utf8("child2"));
|
||||
element3_ = document_.createElement(SA::construct_from_utf8("child3"));
|
||||
|
||||
element1_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1"));
|
||||
|
||||
element2_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1"));
|
||||
element2_.setAttribute(SA::construct_from_utf8("two"), SA::construct_from_utf8("1"));
|
||||
element2_.setAttribute(SA::construct_from_utf8("three"), SA::construct_from_utf8("1"));
|
||||
element2_.setAttribute(SA::construct_from_utf8("four"), SA::construct_from_utf8("1"));
|
||||
|
||||
attr_ = element1_.getAttributeNode(SA::construct_from_utf8("one"));
|
||||
|
||||
root_.appendChild(element1_);
|
||||
root_.appendChild(element2_);
|
||||
root_.appendChild(element3_);
|
||||
} // setUp
|
||||
|
||||
void test1()
|
||||
{
|
||||
XPathExpressionPtr<silly_string> step(new impl::TestStepExpression<silly_string, Arabica::default_string_adaptor<silly_string> >(CHILD, new impl::AnyNodeTest<silly_string>()));
|
||||
|
||||
XPathValuePtr<silly_string> value = step->evaluate(root_);
|
||||
const NodeSet<silly_string>& set = value->asNodeSet();
|
||||
|
||||
assertEquals(set.size(), 3);
|
||||
assertTrue(set[0] == element1_);
|
||||
assertTrue(set[1] == element2_);
|
||||
assertTrue(set[2] == element3_);
|
||||
} // test1
|
||||
|
||||
void test2()
|
||||
{
|
||||
XPathExpressionPtr<silly_string> step(new impl::TestStepExpression<silly_string, Arabica::default_string_adaptor<silly_string> >(ATTRIBUTE, new impl::AnyNodeTest<silly_string>()));
|
||||
|
||||
NodeSet<silly_string> set = step->evaluateAsNodeSet(element2_);
|
||||
|
||||
assertEquals(4, set.size());
|
||||
DOM::Attr<silly_string> attr = static_cast<DOM::Attr<silly_string> >(set[0]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("one"));
|
||||
attr = static_cast<DOM::Attr<silly_string> >(set[1]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("two"));
|
||||
attr = static_cast<DOM::Attr<silly_string> >(set[2]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("three"));
|
||||
attr = static_cast<DOM::Attr<silly_string> >(set[3]);
|
||||
assertTrue(attr.getNodeName() == SA::construct_from_utf8("four"));
|
||||
} // test2
|
||||
|
||||
void test3()
|
||||
{
|
||||
XPathExpressionPtr<silly_string> step(new impl::TestStepExpression<silly_string,
|
||||
Arabica::default_string_adaptor<silly_string> >(CHILD, new impl::NameNodeTest<silly_string, Arabica::default_string_adaptor<silly_string> >(SA::construct_from_utf8("child2"))));
|
||||
|
||||
XPathValuePtr<silly_string> value = step->evaluate(root_);
|
||||
const NodeSet<silly_string>& 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<StepTest>("test1", &StepTest::test1));
|
||||
suiteOfTests->addTest(new TestCaller<StepTest>("test2", &StepTest::test2));
|
||||
suiteOfTests->addTest(new TestCaller<StepTest>("test3", &StepTest::test3));
|
||||
|
||||
return suiteOfTests;
|
||||
} // StepTest_suite
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef STEP_TEST_H
|
||||
#define STEP_TEST_H
|
||||
|
||||
TestSuite* StepTest_suite();
|
||||
|
||||
#endif
|
|
@ -137,9 +137,6 @@
|
|||
<File
|
||||
RelativePath="..\silly_string\silly_string.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\step_test.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
@ -170,7 +167,7 @@
|
|||
RelativePath="..\silly_string\silly_string.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\step_test.hpp">
|
||||
RelativePath="..\XPath\step_test.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\XPath\value_test.hpp">
|
||||
|
|
Loading…
Reference in a new issue