diff --git a/tests/SAX/Makefile.am b/tests/SAX/Makefile.am index 966faa37..b9ba0a5d 100755 --- a/tests/SAX/Makefile.am +++ b/tests/SAX/Makefile.am @@ -7,27 +7,27 @@ AM_CPPFLAGS = -I$(top_srcdir)/include @PARSER_HEADERS@ $(BOOST_CPPFLAGS) LIBARABICA = $(top_builddir)/src/libarabica.la cppunit_sources = ../CppUnit/framework/CppUnitException.h \ - ../CppUnit/framework/estring.h \ - ../CppUnit/framework/Guards.h \ - ../CppUnit/framework/Test.h \ - ../CppUnit/framework/TestCaller.h \ - ../CppUnit/framework/TestCase.cpp \ - ../CppUnit/framework/TestCase.h \ - ../CppUnit/framework/TestFailure.cpp \ - ../CppUnit/framework/TestFailure.h \ - ../CppUnit/framework/TestResult.cpp \ - ../CppUnit/framework/TestResult.h \ - ../CppUnit/framework/TestSuite.cpp \ - ../CppUnit/framework/TestSuite.h \ - ../CppUnit/TestRunner.cpp \ - ../CppUnit/TestRunner.hpp \ - ../CppUnit/textui/TextTestResult.cpp \ - ../CppUnit/textui/TextTestResult.h - + ../CppUnit/framework/estring.h \ + ../CppUnit/framework/Guards.h \ + ../CppUnit/framework/Test.h \ + ../CppUnit/framework/TestCaller.h \ + ../CppUnit/framework/TestCase.cpp \ + ../CppUnit/framework/TestCase.h \ + ../CppUnit/framework/TestFailure.cpp \ + ../CppUnit/framework/TestFailure.h \ + ../CppUnit/framework/TestResult.cpp \ + ../CppUnit/framework/TestResult.h \ + ../CppUnit/framework/TestSuite.cpp \ + ../CppUnit/framework/TestSuite.h \ + ../CppUnit/TestRunner.cpp \ + ../CppUnit/TestRunner.hpp \ + ../CppUnit/textui/TextTestResult.cpp \ + ../CppUnit/textui/TextTestResult.h test_sources = filter_test_SOURCES = filter_test.cpp \ + test_WhitespaceStripper \ $(cppunit_sources) \ $(test_sources) filter_test_LDADD = $(LIBARABICA) diff --git a/tests/SAX/filter_test.cpp b/tests/SAX/filter_test.cpp index f4f01e0e..92f8f283 100644 --- a/tests/SAX/filter_test.cpp +++ b/tests/SAX/filter_test.cpp @@ -1,66 +1,23 @@ #ifdef _MSC_VER -#pragma warning(disable : 4786) +#pragma warning(disable: 4786 4250 4503) #endif -#include -#include -#include -#include -#include -#include +#include "../CppUnit/TestRunner.hpp" +#include "../CppUnit/framework/Test.h" +#include "../CppUnit/framework/TestSuite.h" +#include +#include "test_WhitespaceStripper.hpp" -#include - -template > -class basic_WhitespaceStripper : public SAX::basic_XMLFilterImpl +//////////////////////////////////////////////// +int main(int argc, const char* argv[]) { - public: - typedef string_type stringT; - typedef SAX::basic_XMLFilterImpl baseT; + TestRunner runner; - basic_WhitespaceStripper() { } + runner.addTest("WhitespaceStripperTest", WhitespaceStripper_test_suite >()); - virtual void characters(const stringT& ch) - { - baseT::characters(Arabica::string::normalize_whitespace(ch)); - } // characters + runner.run(argc, argv); - virtual void ignorableWhitespace(const stringT& ch) - { - } // ignorableWhitespace -}; // class basic_WhitespaceStripper - - -int main(int argc, char* argv[]) -{ - std::cout << "tests go here" << std::endl; - - std::ostringstream output; - std::ostringstream output2; - SAX::Writer writer2(output2, 0); - basic_WhitespaceStripper stripper; - SAX::Writer writer(output, 2); - - SAX::XMLReader parser; - SAX::CatchErrorHandler eh; - writer.setParent(parser); - writer.setErrorHandler(eh); - stripper.setParent(writer); - writer2.setParent(stripper); - writer2.setErrorHandler(eh); - - std::stringstream ss; - ss << "

Woo baby hooray

"; - - SAX::InputSource is(ss); - - writer2.parse(is); - - std::cout << "1: " << output.str() << std::endl; - std::cout << "2: " << output2.str() << std::endl; - - - return 5; + return 0; } // main // end of file diff --git a/tests/SAX/test_WhitespaceStripper.hpp b/tests/SAX/test_WhitespaceStripper.hpp new file mode 100644 index 00000000..198f252b --- /dev/null +++ b/tests/SAX/test_WhitespaceStripper.hpp @@ -0,0 +1,152 @@ +#ifndef ARABICA_TEST_WHITESPACE_STRIPPER_HPP +#define ARABICA_TEST_WHITESPACE_STRIPPER_HPP + +#include +#include +#include + +#include +#include +#include +#include + +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +template +class WhitespaceStripperTest : public TestCase +{ + typedef string_adaptor SA; + + public: + WhitespaceStripperTest(std::string name) : + TestCase(name) + { + } // WhitespaceStripperTest + + void setUp() + { + } // setUp + + void testNoStrip() + { + std::ostringstream o; + SAX::XMLReader parser; + SAX::PYXWriter writer(o, parser); + writer.parse(*source("

Woo baby hooray

")); + assertEquals("(test\n(p\n- Woo baby hooray \n)p\n)test\n", o.str()); + } // testNoStrip + + void testStripLeading() + { + std::ostringstream o; + SAX::XMLReader parser; + SAX::WhitespaceStripper stripper(parser); + SAX::PYXWriter writer(o, stripper); + writer.parse(*source("

Woo

")); + assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo

")); + assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo

")); + assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str()); + } // testStripLeading + + void testStripTrailing() + { + std::ostringstream o; + SAX::XMLReader parser; + SAX::WhitespaceStripper stripper(parser); + SAX::PYXWriter writer(o, stripper); + writer.parse(*source("

Woo

")); + assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo

")); + assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo

")); + assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str()); + } // testStripTrailing + + void testStripMid() + { + std::ostringstream o; + SAX::XMLReader parser; + SAX::WhitespaceStripper stripper(parser); + SAX::PYXWriter writer(o, stripper); + writer.parse(*source("

Woo yea

")); + assertEquals("(test\n(p\n-Woo yea\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo yea

")); + assertEquals("(test\n(p\n-Woo yea\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo yea

")); + assertEquals("(test\n(p\n-Woo yea\n)p\n)test\n", o.str()); + } // testStripMid + + void testStripMid2() + { + std::ostringstream o; + SAX::XMLReader parser; + SAX::WhitespaceStripper stripper(parser); + SAX::PYXWriter writer(o, stripper); + writer.parse(*source("

Woo yea man

")); + assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo yea man

")); + assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo yea man

")); + assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str()); + + o.str(""); + writer.parse(*source("

Woo yea man

")); + assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str()); + } // testStripMid2 + + void testStrip() + { + std::ostringstream o; + SAX::XMLReader parser; + SAX::WhitespaceStripper stripper(parser); + SAX::PYXWriter writer(o, stripper); + writer.parse(*source("

Woo baby hooray

")); + assertEquals("(test\n(p\n-Woo baby hooray\n)p\n)test\n", o.str()); + } // testStrip + + private: + std::auto_ptr source(const std::string& str) + { + std::auto_ptr ss(new std::stringstream()); + (*ss) << str; + return std::auto_ptr(new SAX::InputSource(ss)); + } // source +}; // WhitespaceStripperTest + +template +TestSuite* WhitespaceStripper_test_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + + suiteOfTests->addTest(new TestCaller >("testNoStrip", &WhitespaceStripperTest::testNoStrip)); + suiteOfTests->addTest(new TestCaller >("testStripLeading", &WhitespaceStripperTest::testStripLeading)); + suiteOfTests->addTest(new TestCaller >("testStripTrailing", &WhitespaceStripperTest::testStripTrailing)); + suiteOfTests->addTest(new TestCaller >("testStripMid", &WhitespaceStripperTest::testStripMid)); + suiteOfTests->addTest(new TestCaller >("testStripMid2", &WhitespaceStripperTest::testStripMid2)); + suiteOfTests->addTest(new TestCaller >("testStrip", &WhitespaceStripperTest::testStrip)); + + return suiteOfTests; +} // WhitespaceStripperTest_suite + +#endif +