summaryrefslogtreecommitdiff
path: root/src/msvc6
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-04-12 18:28:48 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-04-12 18:28:48 +0000
commited406a2966e62072fa6afaca8abc578db7c0c9fb (patch)
treeab8d2ffb462c3c955b2e339e8cc19f1a6be8bd0f /src/msvc6
parentfc9c76622b19adfcdebce682d9d49db8fb9336ef (diff)
downloadcppunit-ed406a2966e62072fa6afaca8abc578db7c0c9fb.tar.gz
Makefile.
Makefile.am: added examples/qt to tar ball release. * TODO: heavily updated. * contrib/msvc/CppUnit*.wwtpl: changed base class for unit test to TestFixture. * include/cppunit/Test.h: removed toString() method. Not used by the framework and source of confusions with getName(). Added getChildTestCount() and getChildTestAt(), introducing the composite pattern at top level. Added utility methods findTest() and findTestPath(). * src/cppunit/Test.cpp: added. Implementation of new utility methods. * include/cppunit/TestCase.h: * src/cppunit/TestCase.cpp: inherits TestLeaf. Removed toString(), run(void) and defaultResult(). Removed default constructor. * src/cppunit/TestCase.cpp: * src/cppunit/TestSuite.cpp: fixed some includes that used "" instead of <>. * include/cppunit/TestComposite.h: * src/cppunit/TestComposite.cpp: added. Common implementation of Test for composite tests (TestSuite). * include/cppunit/TestFailure.h: * src/cppunit/TestFailure.cpp: removed toString(). * include/cppunit/TestLeaf.h: * src/cppunit/TestLeaf.cpp: added. Common implementation of Test for single test (TestCase). * include/cppunit/TestListener.h: added TimingListener example to documentation. * include/cppunit/TestPath.h: * src/cppunit/TestPath.cpp: added. List of test traversed to access a test in the test hierarchy. * include/cppunit/TestRunner.h: added. Generic TestRunner. * src/cppunit/TestRunner.cpp: moved to TextTestRunner.cpp. Added new implementation of includecppunit/TestRunner.h. * include/cppunit/TestSuite.h: * src/cppunit/TestSuite.cpp: inherits TestComposite and implements new Test interface. Removed toString(). * src/cppunit/TextTestRunner.cpp: moved from TestRunner.cpp. Implementation of include/cppunit/ui/text/TestRunner.h. * include/cppunit/extensions/RepeatedTest.h: * src/cppunit/RepeatedTest.cpp: removed toString(). * include/cppunit/extensions/TestDecorator.h: inherits TestLeaf. Removed toString() * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: * examples/cppunittest/XmlOutputterTest.cpp: * examples/cppunittest/XmlOutputterTest.h: XML outputter now escape node content. Add unit test for that bug (#540944). Added style sheet support. Modified XML structure: failure message as its own element. * src/msvc/testrunner/TestRunnerModel.h: * src/msvc/testrunner/TestRunnerModel.cpp: used Test::findTest() to find a test by name instead of using RTTI. Added toAnsiString() for convertion when compiling as UNICODE. * src/msvc/testrunner/TreeHierarchyDlg.h: * src/msvc/testrunner/TreeHierarchyDlg.cpp: used new composite interface of Test to explorer the test hierarchy instead of RTTI. * examples/cppunittest/TestPathTest.h: * examples/cppunittest/TestPathTest.cpp: added, unit tests for TestPath. * examples/cppunittest/TestCaseTest.h: * examples/cppunittest/TestCaseTest.cpp: added test for TestLeaf. * examples/cppunittest/TestSuiteTest.h: * examples/cppunittest/TestSuiteTest.cpp: added test for TestComposite and new Test interface.
Diffstat (limited to 'src/msvc6')
-rw-r--r--src/msvc6/testrunner/TestRunnerModel.cpp36
-rw-r--r--src/msvc6/testrunner/TestRunnerModel.h2
-rw-r--r--src/msvc6/testrunner/TreeHierarchyDlg.cpp34
-rw-r--r--src/msvc6/testrunner/TreeHierarchyDlg.h6
4 files changed, 55 insertions, 23 deletions
diff --git a/src/msvc6/testrunner/TestRunnerModel.cpp b/src/msvc6/testrunner/TestRunnerModel.cpp
index c47c2a7..57e8d1f 100644
--- a/src/msvc6/testrunner/TestRunnerModel.cpp
+++ b/src/msvc6/testrunner/TestRunnerModel.cpp
@@ -7,6 +7,7 @@
#include "StdAfx.h"
#include "TestRunnerModel.h"
#include <algorithm>
+#include <stdexcept>
#include <cppunit/testsuite.h>
@@ -84,9 +85,13 @@ TestRunnerModel::loadHistory()
if ( testName.IsEmpty() )
break;
- CppUnit::Test *test = findTestByName( testName );
- if ( test != NULL )
- m_history.push_back( test );
+ try
+ {
+ m_history.push_back( m_rootTest->findTest( toAnsiString(testName ) ) );
+ }
+ catch ( std::invalid_argument &)
+ {
+ }
}
while ( true );
}
@@ -197,3 +202,28 @@ TestRunnerModel::findTestByNameFor( const CString &name,
}
return NULL;
}
+
+
+// Utility method, should be moved somewhere else...
+std::string
+TestRunnerModel::toAnsiString( const CString &text )
+{
+#ifdef _UNICODE
+ int bufferLength = ::WideCharToMultiByte( CP_THREAD_ACP, 0,
+ text, text.GetLength(),
+ NULL, 0, NULL, NULL ) +1;
+ char *ansiString = new char[bufferLength];
+ ::WideCharToMultiByte( CP_THREAD_ACP, 0,
+ text, text.GetLength(),
+ ansiString, bufferLength,
+ NULL,
+ NULL );
+
+ std::string str( ansiString, bufferLength-1 );
+ delete[] ansiString;
+
+ return str;
+#else
+ return std::string( (LPCTSTR)text );
+#endif
+}
diff --git a/src/msvc6/testrunner/TestRunnerModel.h b/src/msvc6/testrunner/TestRunnerModel.h
index 7f6cada..b036911 100644
--- a/src/msvc6/testrunner/TestRunnerModel.h
+++ b/src/msvc6/testrunner/TestRunnerModel.h
@@ -59,6 +59,8 @@ protected:
CString getHistoryEntryName( int idx ) const;
+ static std::string toAnsiString( const CString &text );
+
private:
/// Prevents the use of the copy constructor.
TestRunnerModel( const TestRunnerModel &copy );
diff --git a/src/msvc6/testrunner/TreeHierarchyDlg.cpp b/src/msvc6/testrunner/TreeHierarchyDlg.cpp
index 8d00389..0ad1c6c 100644
--- a/src/msvc6/testrunner/TreeHierarchyDlg.cpp
+++ b/src/msvc6/testrunner/TreeHierarchyDlg.cpp
@@ -54,11 +54,11 @@ TreeHierarchyDlg::setRootTest( CppUnit::Test *test )
BOOL
TreeHierarchyDlg::OnInitDialog()
{
- CDialog::OnInitDialog();
+ CDialog::OnInitDialog();
fillTree();
- return TRUE;
+ return TRUE;
}
@@ -78,7 +78,7 @@ HTREEITEM
TreeHierarchyDlg::addTest( CppUnit::Test *test,
HTREEITEM hParent )
{
- int testType = isTestSuite( test ) ? imgSuite : imgUnitTest;
+ int testType = isSuite( test ) ? imgSuite : imgUnitTest;
HTREEITEM hItem = m_treeTests.InsertItem( CString(test->getName().c_str()),
testType,
testType,
@@ -86,33 +86,33 @@ TreeHierarchyDlg::addTest( CppUnit::Test *test,
if ( hItem != NULL )
{
VERIFY( m_treeTests.SetItemData( hItem, (DWORD)test ) );
- if ( isTestSuite( test ) )
- addTestSuiteChildrenTo( static_cast<CppUnit::TestSuite *>(test),
- hItem );
+ if ( isSuite( test ) )
+ addTestSuiteChildrenTo( test, hItem );
}
return hItem;
}
void
-TreeHierarchyDlg::addTestSuiteChildrenTo( CppUnit::TestSuite *suite,
+TreeHierarchyDlg::addTestSuiteChildrenTo( CppUnit::Test *suite,
HTREEITEM hItemSuite )
{
- Tests tests( suite->getTests() );
+ Tests tests;
+ int childIndex = 0;
+ for ( ; childIndex < suite->getChildTestCount(); ++childIndex )
+ tests.push_back( suite->getChildTestAt( childIndex ) );
sortByName( tests );
- for ( Tests::const_iterator it = tests.begin(); it != tests.end(); ++it )
- {
- addTest( *it, hItemSuite );
- }
+ for ( childIndex = 0; childIndex < suite->getChildTestCount(); ++childIndex )
+ addTest( suite->getChildTestAt( childIndex ), hItemSuite );
}
bool
-TreeHierarchyDlg::isTestSuite( CppUnit::Test *test )
+TreeHierarchyDlg::isSuite( CppUnit::Test *test )
{
- CppUnit::TestSuite *suite = dynamic_cast<CppUnit::TestSuite *>(test);
- return suite != NULL;
+ return ( test->getChildTestCount() > 0 || // suite with test
+ test->countTestCases() == 0 ); // empty suite
}
@@ -120,8 +120,8 @@ struct PredSortTest
{
bool operator()( CppUnit::Test *test1, CppUnit::Test *test2 ) const
{
- bool isTest1Suite = TreeHierarchyDlg::isTestSuite( test1 );
- bool isTest2Suite = TreeHierarchyDlg::isTestSuite( test2 );
+ bool isTest1Suite = TreeHierarchyDlg::isSuite( test1 );
+ bool isTest2Suite = TreeHierarchyDlg::isSuite( test2 );
if ( isTest1Suite && !isTest2Suite )
return true;
if ( isTest1Suite && isTest2Suite )
diff --git a/src/msvc6/testrunner/TreeHierarchyDlg.h b/src/msvc6/testrunner/TreeHierarchyDlg.h
index f3ae5d5..33ac714 100644
--- a/src/msvc6/testrunner/TreeHierarchyDlg.h
+++ b/src/msvc6/testrunner/TreeHierarchyDlg.h
@@ -7,7 +7,7 @@
// TreeHierarchyDlg.h : header file
//
-#include <cppunit/TestSuite.h>
+#include <cppunit/Test.h>
#include <vector>
@@ -23,7 +23,7 @@ public:
void setRootTest( CppUnit::Test *test );
CppUnit::Test *getSelectedTest() const;
- static bool isTestSuite( CppUnit::Test *test );
+ static bool isSuite( CppUnit::Test *test );
// Dialog Data
//{{AFX_DATA(TreeHierarchyDlg)
@@ -55,7 +55,7 @@ private:
void fillTree();
HTREEITEM addTest( CppUnit::Test *test,
HTREEITEM hParent );
- void addTestSuiteChildrenTo( CppUnit::TestSuite *suite,
+ void addTestSuiteChildrenTo( CppUnit::Test *suite,
HTREEITEM hItemSuite );
void sortByName( Tests &tests ) const;