#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 expect(char const* expected, std::basic_ostringstream& result) { assertEquals( expected, string_adaptor::asStdString(string_adaptor::construct(result.str().c_str())) ); } void testNoStrip() { std::basic_ostringstream o; Arabica::SAX::XMLReader parser; Arabica::SAX::PYXWriter writer(o, parser); writer.parse(*source("

Woo baby hooray

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

Woo

")); expect("(test\n(p\n-Woo\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo

")); expect("(test\n(p\n-Woo\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo

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

Woo

")); expect("(test\n(p\n-Woo\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo

")); expect("(test\n(p\n-Woo\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo

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

Woo yea

")); expect("(test\n(p\n-Woo yea\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo yea

")); expect("(test\n(p\n-Woo yea\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo yea

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

Woo yea man

")); expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo yea man

")); expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo yea man

")); expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o); o.str(string_adaptor::empty_string()); writer.parse(*source("

Woo yea man

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

Woo baby hooray

")); expect("(test\n(p\n-Woo baby hooray\n)p\n)test\n", o); } // testStrip private: std::unique_ptr > source(const std::string& str) { std::unique_ptr ss(new std::stringstream()); (*ss) << str; return std::make_unique>(std::move(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