summaryrefslogtreecommitdiff
path: root/examples/cppunittest
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-06-16 16:55:58 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-06-16 16:55:58 +0000
commit0a810d68d0550ba6f7f28f2e0dfcef691bdca7b4 (patch)
treea060d291bf0dfb6c75720ecbce7f27927b326a5b /examples/cppunittest
parent73a038f1eaa268cec330d971fb550befec6f7798 (diff)
downloadcppunit-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')
-rw-r--r--examples/cppunittest/CppUnitTestMain.dsp8
-rw-r--r--examples/cppunittest/Makefile.am2
-rw-r--r--examples/cppunittest/StringToolsTest.cpp232
-rw-r--r--examples/cppunittest/StringToolsTest.h74
-rw-r--r--examples/cppunittest/XmlElementTest.cpp14
-rw-r--r--examples/cppunittest/XmlElementTest.h28
-rw-r--r--examples/cppunittest/XmlOutputterTest.cpp12
7 files changed, 342 insertions, 28 deletions
diff --git a/examples/cppunittest/CppUnitTestMain.dsp b/examples/cppunittest/CppUnitTestMain.dsp
index 6969c52..02f3792 100644
--- a/examples/cppunittest/CppUnitTestMain.dsp
+++ b/examples/cppunittest/CppUnitTestMain.dsp
@@ -346,6 +346,14 @@ SOURCE=.\XmlOutputterTest.h
# PROP Default_Filter ""
# Begin Source File
+SOURCE=.\StringToolsTest.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\StringToolsTest.h
+# End Source File
+# Begin Source File
+
SOURCE=.\XmlElementTest.cpp
# End Source File
# Begin Source File
diff --git a/examples/cppunittest/Makefile.am b/examples/cppunittest/Makefile.am
index 4dd2e69..3d46300 100644
--- a/examples/cppunittest/Makefile.am
+++ b/examples/cppunittest/Makefile.am
@@ -29,6 +29,8 @@ cppunittestmain_SOURCES = \
OutputSuite.h \
RepeatedTestTest.cpp \
RepeatedTestTest.h \
+ StringToolsTest.h \
+ StringToolsTest.cpp \
SubclassedTestCase.cpp \
SubclassedTestCase.h \
SynchronizedTestResult.h \
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 );
+}
+
diff --git a/examples/cppunittest/StringToolsTest.h b/examples/cppunittest/StringToolsTest.h
new file mode 100644
index 0000000..4a42e20
--- /dev/null
+++ b/examples/cppunittest/StringToolsTest.h
@@ -0,0 +1,74 @@
+#ifndef STRINGTOOLSTEST_H
+#define STRINGTOOLSTEST_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/tools/StringTools.h>
+
+
+/// Unit tests for StringToolsTest
+class StringToolsTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE( StringToolsTest );
+ CPPUNIT_TEST( testToStringInt );
+ CPPUNIT_TEST( testToStringDouble );
+ CPPUNIT_TEST( testSplitEmptyString );
+ CPPUNIT_TEST( testSplitOneItem );
+ CPPUNIT_TEST( testSplitItemEmpty );
+ CPPUNIT_TEST( testSplitTwoItem );
+ CPPUNIT_TEST( testSplitEmptyTwoItem );
+ CPPUNIT_TEST( testSplitEmptyItemEmpty );
+ CPPUNIT_TEST( testSplitEmptyItemEmptyEmptyItem );
+ CPPUNIT_TEST( testWrapEmpty );
+ CPPUNIT_TEST( testWrapNotNeeded );
+ CPPUNIT_TEST( testWrapLimitNotNeeded );
+ CPPUNIT_TEST( testWrapOneNeeded );
+ CPPUNIT_TEST( testWrapTwoNeeded );
+ CPPUNIT_TEST( testWrapLimitTwoNeeded );
+ CPPUNIT_TEST( testWrapOneNeededTwoNeeded );
+ CPPUNIT_TEST( testWrapNotNeededEmptyLinesOneNeeded );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ /*! Constructs a StringToolsTest object.
+ */
+ StringToolsTest();
+
+ /// Destructor.
+ virtual ~StringToolsTest();
+
+ void setUp();
+ void tearDown();
+
+ void testToStringInt();
+ void testToStringDouble();
+
+ void testSplitEmptyString();
+ void testSplitOneItem();
+ void testSplitItemEmpty();
+ void testSplitTwoItem();
+ void testSplitEmptyTwoItem();
+ void testSplitEmptyItemEmpty();
+ void testSplitEmptyItemEmptyEmptyItem();
+
+ void testWrapEmpty();
+ void testWrapNotNeeded();
+ void testWrapLimitNotNeeded();
+ void testWrapOneNeeded();
+ void testWrapTwoNeeded();
+ void testWrapLimitTwoNeeded();
+ void testWrapOneNeededTwoNeeded();
+ void testWrapNotNeededEmptyLinesOneNeeded();
+
+private:
+ /// Prevents the use of the copy constructor.
+ StringToolsTest( const StringToolsTest &other );
+
+ /// Prevents the use of the copy operator.
+ void operator =( const StringToolsTest &other );
+
+private:
+};
+
+
+
+#endif // STRINGTOOLSTEST_H
diff --git a/examples/cppunittest/XmlElementTest.cpp b/examples/cppunittest/XmlElementTest.cpp
index 26a0778..585b0ba 100644
--- a/examples/cppunittest/XmlElementTest.cpp
+++ b/examples/cppunittest/XmlElementTest.cpp
@@ -76,7 +76,7 @@ XmlElementTest::testSetNumericContent()
void
-XmlElementTest::testNodeCount()
+XmlElementTest::testElementCount()
{
CppUnit::XmlElement node( "element", "content" );
CPPUNIT_ASSERT_EQUAL( 0, node.elementCount() );
@@ -150,7 +150,7 @@ XmlElementTest::testEmptyNodeToString()
void
-XmlElementTest::testNodeWithAttributesToString()
+XmlElementTest::testElementWithAttributesToString()
{
CppUnit::XmlElement node( "element" );
node.addAttribute( "id", 17 );
@@ -175,7 +175,7 @@ XmlElementTest::testEscapedAttributeValueToString()
void
-XmlElementTest::testNodeToStringEscapeContent()
+XmlElementTest::testElementToStringEscapeContent()
{
CppUnit::XmlElement node( "element", "ChessTest<class Chess>" );
std::string expectedXml = "<element>"
@@ -186,7 +186,7 @@ XmlElementTest::testNodeToStringEscapeContent()
void
-XmlElementTest::testNodeWithChildrenToString()
+XmlElementTest::testElementWithChildrenToString()
{
CppUnit::XmlElement node( "element" );
node.addElement( new CppUnit::XmlElement( "child1" ) );
@@ -198,7 +198,7 @@ XmlElementTest::testNodeWithChildrenToString()
void
-XmlElementTest::testNodeWithContentToString()
+XmlElementTest::testElementWithContentToString()
{
CppUnit::XmlElement node( "element", "content\nline2" );
std::string expectedXml = "<element>content\nline2</element>";
@@ -207,7 +207,7 @@ XmlElementTest::testNodeWithContentToString()
void
-XmlElementTest::testNodeWithNumericContentToString()
+XmlElementTest::testElementWithNumericContentToString()
{
CppUnit::XmlElement node( "element", 123456789 );
std::string expectedXml = "<element>123456789</element>";
@@ -216,7 +216,7 @@ XmlElementTest::testNodeWithNumericContentToString()
void
-XmlElementTest::testNodeWithContentAndChildToString()
+XmlElementTest::testElementWithContentAndChildToString()
{
CppUnit::XmlElement node( "element", "content" );
node.addElement( new CppUnit::XmlElement( "child1" ) );
diff --git a/examples/cppunittest/XmlElementTest.h b/examples/cppunittest/XmlElementTest.h
index e4f4875..96f9993 100644
--- a/examples/cppunittest/XmlElementTest.h
+++ b/examples/cppunittest/XmlElementTest.h
@@ -14,7 +14,7 @@ class XmlElementTest : public CppUnit::TestFixture
CPPUNIT_TEST( testSetName );
CPPUNIT_TEST( testSetStringContent );
CPPUNIT_TEST( testSetNumericContent );
- CPPUNIT_TEST( testNodeCount );
+ CPPUNIT_TEST( testElementCount );
CPPUNIT_TEST_EXCEPTION( testElementAtNegativeIndexThrow, std::invalid_argument );
CPPUNIT_TEST_EXCEPTION( testElementAtTooLargeIndexThrow, std::invalid_argument );
CPPUNIT_TEST( testElementAt );
@@ -22,13 +22,13 @@ class XmlElementTest : public CppUnit::TestFixture
CPPUNIT_TEST( testElementFor );
CPPUNIT_TEST( testEmptyNodeToString );
- CPPUNIT_TEST( testNodeWithAttributesToString );
+ CPPUNIT_TEST( testElementWithAttributesToString );
CPPUNIT_TEST( testEscapedAttributeValueToString );
- CPPUNIT_TEST( testNodeToStringEscapeContent );
- CPPUNIT_TEST( testNodeWithChildrenToString );
- CPPUNIT_TEST( testNodeWithContentToString );
- CPPUNIT_TEST( testNodeWithNumericContentToString );
- CPPUNIT_TEST( testNodeWithContentAndChildToString );
+ CPPUNIT_TEST( testElementToStringEscapeContent );
+ CPPUNIT_TEST( testElementWithChildrenToString );
+ CPPUNIT_TEST( testElementWithContentToString );
+ CPPUNIT_TEST( testElementWithNumericContentToString );
+ CPPUNIT_TEST( testElementWithContentAndChildToString );
CPPUNIT_TEST_SUITE_END();
public:
@@ -47,7 +47,7 @@ public:
void testSetName();
void testSetStringContent();
void testSetNumericContent();
- void testNodeCount();
+ void testElementCount();
void testElementAtNegativeIndexThrow();
void testElementAtTooLargeIndexThrow();
void testElementAt();
@@ -55,13 +55,13 @@ public:
void testElementFor();
void testEmptyNodeToString();
- void testNodeWithAttributesToString();
+ void testElementWithAttributesToString();
void testEscapedAttributeValueToString();
- void testNodeToStringEscapeContent();
- void testNodeWithChildrenToString();
- void testNodeWithContentToString();
- void testNodeWithNumericContentToString();
- void testNodeWithContentAndChildToString();
+ void testElementToStringEscapeContent();
+ void testElementWithChildrenToString();
+ void testElementWithContentToString();
+ void testElementWithNumericContentToString();
+ void testElementWithContentAndChildToString();
private:
/// Prevents the use of the copy constructor.
diff --git a/examples/cppunittest/XmlOutputterTest.cpp b/examples/cppunittest/XmlOutputterTest.cpp
index 84a1719..7e85191 100644
--- a/examples/cppunittest/XmlOutputterTest.cpp
+++ b/examples/cppunittest/XmlOutputterTest.cpp
@@ -237,20 +237,18 @@ public:
{
}
- void beginDocument( CppUnit::XmlDocument *document,
- CppUnit::XmlElement *rootNode )
+ void beginDocument( CppUnit::XmlDocument *document )
{
++m_beginCalls;
}
- void endDocument( CppUnit::XmlDocument *document,
- CppUnit::XmlElement *rootNode )
+ void endDocument( CppUnit::XmlDocument *document )
{
++m_endCalls;
}
void failTestAdded( CppUnit::XmlDocument *document,
- CppUnit::XmlElement *testNode,
+ CppUnit::XmlElement *testElement,
CppUnit::Test *test,
CppUnit::TestFailure *failure )
{
@@ -258,14 +256,14 @@ public:
}
void successfulTestAdded( CppUnit::XmlDocument *document,
- CppUnit::XmlElement *testNode,
+ CppUnit::XmlElement *testElement,
CppUnit::Test *test )
{
++m_successfulTestCalls;
}
void statisticsAdded( CppUnit::XmlDocument *document,
- CppUnit::XmlElement *statisticsNode )
+ CppUnit::XmlElement *statisticsElement )
{
++m_statisticsCalls;
}