diff options
author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-16 16:55:58 +0000 |
---|---|---|
committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-16 16:55:58 +0000 |
commit | 0a810d68d0550ba6f7f28f2e0dfcef691bdca7b4 (patch) | |
tree | a060d291bf0dfb6c75720ecbce7f27927b326a5b /examples/cppunittest/StringToolsTest.cpp | |
parent | 73a038f1eaa268cec330d971fb550befec6f7798 (diff) | |
download | cppunit-0a810d68d0550ba6f7f28f2e0dfcef691bdca7b4.tar.gz |
Release 1.
release 1.9.8
* include/cppunit/plugin/TestPlugIn.h: updated documentation.
* include/cppunit/tools/XmlDocument.h: updated documentation.
* include/cppunit/tools/StringTools.h:
* src/cppunit/StringTools.cpp: added split() and wrap() functions.
* include/cppunit/CompilerOutputter.h:
* src/cppunit/CompilerOutputter.cpp: extracted wrap() and
splitMessageIntoLines() to StringTools.
* include/cppunit/XmlOutputterHook.h:
* src/cppunit/XmlOutputterHook.cpp: removed rooNode parameter from
beginDocument() and endDocument(). It can be retreive from document.
Renamed 'node' occurences to 'element'.
* include/cppunit/XmlOutputter.h:
* src/cppunit/XmlOutputter.cpp: updated against
XmlOutputterHook changes. Renamed 'node' occurences to 'element'.
* examples/ClockerPlugIn/ClockerXmlHook.h:
* examples/ClockerPlugIn/ClockerXmlHook.cpp: updated against
XmlOutputterHook changes.
* examples/cppunittest/XmlElementTest.h:
* examples/cppunittest/XmlElementTest.cpp: Renamed 'node' occurences
to 'element'.
* examples/cppunittest/XmlOutputterTest.cpp: updated against
XmlOutputterHook changes.
* examples/cppunittest/StringToolsTest.h:
* examples/cppunittest/StringToolsTest.cpp: added. Unit tests for
StringTools. Turn out that VC++ dismiss empty lines in tools output,
which is the reason why empty lines where not printed in
CompilerOutputter.
Diffstat (limited to 'examples/cppunittest/StringToolsTest.cpp')
-rw-r--r-- | examples/cppunittest/StringToolsTest.cpp | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/examples/cppunittest/StringToolsTest.cpp b/examples/cppunittest/StringToolsTest.cpp new file mode 100644 index 0000000..e2c95cc --- /dev/null +++ b/examples/cppunittest/StringToolsTest.cpp @@ -0,0 +1,232 @@ +#include "StringToolsTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( StringToolsTest ); + + +StringToolsTest::StringToolsTest() +{ +} + + +StringToolsTest::~StringToolsTest() +{ +} + + +void +StringToolsTest::setUp() +{ +} + + +void +StringToolsTest::tearDown() +{ +} + + +void +StringToolsTest::testToStringInt() +{ + std::string expected = "123456789"; + std::string actual = CppUnit::StringTools::toString( 123456789 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testToStringDouble() +{ + std::string expected = "1234.56"; + std::string actual = CppUnit::StringTools::toString( 1234.56 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testSplitEmptyString() +{ + std::string text; + CppUnit::StringTools::Strings expected; + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testSplitOneItem() +{ + std::string text = "1"; + CppUnit::StringTools::Strings expected; + expected.push_back( "1" ); + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testSplitItemEmpty() +{ + std::string text = "1;"; + CppUnit::StringTools::Strings expected; + expected.push_back( "1" ); + expected.push_back( "" ); + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testSplitTwoItem() +{ + std::string text = "2;1"; + CppUnit::StringTools::Strings expected; + expected.push_back( "2" ); + expected.push_back( "1" ); + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testSplitEmptyTwoItem() +{ + std::string text = ";1;2"; + CppUnit::StringTools::Strings expected; + expected.push_back( "" ); + expected.push_back( "1" ); + expected.push_back( "2" ); + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testSplitEmptyItemEmpty() +{ + std::string text = ";1;"; + CppUnit::StringTools::Strings expected; + expected.push_back( "" ); + expected.push_back( "1" ); + expected.push_back( "" ); + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testSplitEmptyItemEmptyEmptyItem() +{ + std::string text = ";1;;;2"; + CppUnit::StringTools::Strings expected; + expected.push_back( "" ); + expected.push_back( "1" ); + expected.push_back( "" ); + expected.push_back( "" ); + expected.push_back( "2" ); + CppUnit::StringTools::Strings actual = CppUnit::StringTools::split( text, ';' ); + + CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() ); + CPPUNIT_ASSERT( expected == actual ); +} + + +void +StringToolsTest::testWrapEmpty() +{ + std::string text = ""; + std::string expected = ""; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapNotNeeded() +{ + std::string text = "abcd"; + std::string expected = text; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapLimitNotNeeded() +{ + std::string text = "abcdef"; + std::string expected = text; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapOneNeeded() +{ + std::string text = "abcdefghi"; + std::string expected = "abcdef\nghi"; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapTwoNeeded() +{ + std::string text = "abcdefghijklmnop"; + std::string expected = "abcdef\nghijkl\nmnop"; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapLimitTwoNeeded() +{ + std::string text = "abcdefghijklmnopqr"; + std::string expected = "abcdef\nghijkl\nmnopqr"; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapOneNeededTwoNeeded() +{ + std::string text = "123456789\nabcdefghijklmno"; + std::string expected = "123456\n789\nabcdef\nghijkl\nmno"; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +StringToolsTest::testWrapNotNeededEmptyLinesOneNeeded() +{ + std::string text = "12345\n\n\n\nabcdefghi"; + std::string expected = "12345\n\n\n\nabcdef\nghi"; + + std::string actual = CppUnit::StringTools::wrap( text, 6 ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + |