* fix gcc4 build of cppunit library by explicitly spelling out std:: in

the headers and importing the required classes in the implementation files
* automatic whitespace cleanup

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30586 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2009-05-02 19:04:52 +00:00
parent 226136446a
commit 58481f0f6e
50 changed files with 683 additions and 605 deletions
+3 -1
View File
@@ -4,6 +4,8 @@
#include <stdio.h>
#include <stdarg.h>
using std::string;
_EXPORT
BTestCase::BTestCase(string name)
: CppUnit::TestCase(name)
@@ -31,7 +33,7 @@ BTestCase::NextSubTest() {
_EXPORT
void
BTestCase::NextSubTestBlock() {
if (BTestShell::GlobalBeVerbose())
if (BTestShell::GlobalBeVerbose())
printf("\n");
}
+17 -14
View File
@@ -2,6 +2,9 @@
#include <cppunit/Test.h>
#include <cppunit/TestResult.h>
using std::map;
using std::string;
// Default constructor
_EXPORT
BTestSuite::BTestSuite( string name )
@@ -11,14 +14,14 @@ BTestSuite::BTestSuite( string name )
// Destructor
_EXPORT
BTestSuite::~BTestSuite() {
deleteContents();
BTestSuite::~BTestSuite() {
deleteContents();
}
// Deletes all tests in the suite.
_EXPORT
void
void
BTestSuite::deleteContents() {
for ( map<string, CppUnit::Test*>::iterator it = fTests.begin();
it != fTests.end();
@@ -30,7 +33,7 @@ BTestSuite::deleteContents() {
/// Runs the tests and collects their result in a TestResult.
_EXPORT
void
void
BTestSuite::run( CppUnit::TestResult *result ) {
for ( map<string, CppUnit::Test*>::iterator it = fTests.begin();
it != fTests.end();
@@ -47,7 +50,7 @@ BTestSuite::run( CppUnit::TestResult *result ) {
// Counts the number of test cases that will be run by this test.
_EXPORT
int
int
BTestSuite::countTestCases() const {
int count = 0;
@@ -60,27 +63,27 @@ BTestSuite::countTestCases() const {
}
// Adds a test to the suite.
// Adds a test to the suite.
_EXPORT
void
BTestSuite::addTest(string name, CppUnit::Test *test) {
fTests[name] = test;
void
BTestSuite::addTest(string name, CppUnit::Test *test) {
fTests[name] = test;
}
// Returns a string representation of the test suite.
_EXPORT
string
BTestSuite::toString() const {
string
BTestSuite::toString() const {
return "suite " + getName();
}
// Returns the name of the test suite.
_EXPORT
string
BTestSuite::getName() const {
return fName;
string
BTestSuite::getName() const {
return fName;
}
+1
View File
@@ -1,6 +1,7 @@
// TestApp.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Autolock.h>
+5 -2
View File
@@ -7,6 +7,9 @@
#include <stdio.h>
#include <OS.h>
using std::cout;
using std::endl;
_EXPORT
void
BTestListener::startTest( CppUnit::Test *test ) {
@@ -25,7 +28,7 @@ BTestListener::addFailure( const CppUnit::TestFailure &failure ) {
cout << (failure.thrownException() != NULL
? failure.thrownException()->what()
: "(unknown error)");
cout << endl;
cout << endl;
}
_EXPORT
@@ -38,7 +41,7 @@ BTestListener::endTest( CppUnit::Test *test ) {
// cout << " - FAILED" << endl;
printTime(length);
cout << endl;
}
}
_EXPORT
void
+42 -38
View File
@@ -26,6 +26,10 @@
# include <ElfSymbolPatcher.h>
#endif
using std::cout;
using std::endl;
using std::set;
_EXPORT BTestShell *BTestShell::fGlobalShell = NULL;
const char BTestShell::indent[] = " ";
@@ -62,20 +66,20 @@ BTestShell::AddSuite(BTestSuite *suite) {
if (suite) {
if (Verbosity() >= v3)
cout << "Adding suite '" << suite->getName() << "'" << endl;
// Add the suite
fSuites[suite->getName()] = suite;
// Add its tests
const TestMap &map = suite->getTests();
for (TestMap::const_iterator i = map.begin();
i != map.end();
i++) {
AddTest(i->first, i->second);
if (Verbosity() >= v4 && i->second)
if (Verbosity() >= v4 && i->second)
cout << " " << i->first << endl;
}
return B_OK;
} else
return B_BAD_VALUE;
@@ -121,7 +125,7 @@ BTestShell::LoadSuitesFrom(BDirectory *libDir) {
} else {
// cout << " !!! err == " << err << endl;
}
if (!err)
if (!err)
err = AddSuite(func());
if (!err)
count++;
@@ -133,11 +137,11 @@ _EXPORT
int
BTestShell::Run(int argc, char *argv[]) {
// Make note of which directory we started in
UpdateTestDir(argv);
UpdateTestDir(argv);
// Parse the command line args
if (!ProcessArguments(argc, argv))
return 0;
return 0;
// Load any dynamically loadable tests we can find
LoadDynamicSuites();
@@ -147,24 +151,24 @@ BTestShell::Run(int argc, char *argv[]) {
if (fListTestsAndExit) {
PrintInstalledTests();
return 0;
}
}
// Add the proper tests to our suite (or exit if there
// are no tests installed).
CppUnit::TestSuite suite;
CppUnit::TestSuite suite;
if (fTests.empty()) {
// No installed tests whatsoever, so bail
cout << "ERROR: No installed tests to run!" << endl;
return 0;
} else if (fSuitesToRun.empty() && fTestsToRun.empty()) {
// None specified, so run them all
TestMap::iterator i;
for (i = fTests.begin(); i != fTests.end(); ++i)
suite.addTest( i->second );
} else {
set<string>::const_iterator i;
set<string> suitesToRemove;
@@ -187,14 +191,14 @@ BTestShell::Run(int argc, char *argv[]) {
}
}
}
// Remove the names of all of the suites we discovered from the
// list of tests to run (unless there's also an installed individual
// test of the same name).
for (i = suitesToRemove.begin(); i != suitesToRemove.end(); i++) {
fTestsToRun.erase(*i);
}
// Everything still in fTestsToRun must then be an explicit test
for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) {
// Make sure it's a valid test
@@ -206,9 +210,9 @@ BTestShell::Run(int argc, char *argv[]) {
return 0;
}
}
}
// Run all the tests
InitOutput();
InstallPatches();
@@ -223,7 +227,7 @@ _EXPORT
BTestShell::VerbosityLevel
BTestShell::Verbosity() const {
return fVerbosityLevel;
}
}
_EXPORT
const char*
@@ -276,7 +280,7 @@ BTestShell::PrintHelp() {
cout << "VALID ARGUMENTS: " << endl;
PrintValidArguments();
cout << endl;
}
_EXPORT
@@ -308,7 +312,7 @@ BTestShell::PrintInstalledTests() {
cout << "------------------------------------------------------------------------------" << endl;
cout << "Available Suites:" << endl;
cout << "------------------------------------------------------------------------------" << endl;
SuiteMap::const_iterator j;
SuiteMap::const_iterator j;
for (j = fSuites.begin(); j != fSuites.end(); ++j)
cout << j->first << endl;
cout << endl;
@@ -317,7 +321,7 @@ BTestShell::PrintInstalledTests() {
cout << "------------------------------------------------------------------------------" << endl;
cout << "Available Tests:" << endl;
cout << "------------------------------------------------------------------------------" << endl;
TestMap::const_iterator i;
TestMap::const_iterator i;
for (i = fTests.begin(); i != fTests.end(); ++i)
cout << i->first << endl;
cout << endl;
@@ -335,11 +339,11 @@ BTestShell::ProcessArguments(int argc, char *argv[]) {
// which is just the app name)
for (int i = 1; i < argc; i++) {
string str(argv[i]);
if (!ProcessArgument(str, argc, argv))
return false;
return false;
}
return true;
}
@@ -363,12 +367,12 @@ BTestShell::ProcessArgument(string arg, int argc, char *argv[]) {
} else if (arg == "-v4") {
fVerbosityLevel = v4;
} else if (arg.length() >= 2 && arg[0] == '-' && arg[1] == 'l') {
fLibDirs.insert(arg.substr(2, arg.size()-2));
fLibDirs.insert(arg.substr(2, arg.size()-2));
} else {
fTestsToRun.insert(arg);
}
return true;
}
}
_EXPORT
void
@@ -404,7 +408,7 @@ BTestShell::PrintResults() {
iFailure != fResultsCollector.failures().end();
++iFailure)
{
if (!(*iFailure)->isError())
if (!(*iFailure)->isError())
cout << " " << (*iFailure)->toString() << endl;
}
}
@@ -414,17 +418,17 @@ BTestShell::PrintResults() {
iFailure != fResultsCollector.failures().end();
++iFailure)
{
if ((*iFailure)->isError())
if ((*iFailure)->isError())
cout << " " << (*iFailure)->toString() << endl;
}
}
}
else
cout << "+ PASSED" << endl;
cout << endl;
}
else {
// Print out concise results for verbosity level == 0
@@ -433,7 +437,7 @@ BTestShell::PrintResults() {
else
cout << "+ PASSED" << endl;
}
}
_EXPORT
@@ -448,15 +452,15 @@ BTestShell::LoadDynamicSuites() {
set<string>::iterator i;
for (i = fLibDirs.begin(); i != fLibDirs.end(); i++) {
BDirectory libDir((*i).c_str());
if (Verbosity() >= v3)
if (Verbosity() >= v3)
cout << "Checking " << *i << endl;
/* int count =*/ LoadSuitesFrom(&libDir);
if (Verbosity() >= v3) {
if (Verbosity() >= v3) {
// cout << "Loaded " << count << " suite" << (count == 1 ? "" : "s");
// cout << " from " << *i << endl;
}
}
if (Verbosity() >= v3)
cout << endl;
@@ -466,11 +470,11 @@ BTestShell::LoadDynamicSuites() {
if (fTests.find(i->first) != fTests.end() && Verbosity() > v0) {
cout << "WARNING: '" << i->first << "' refers to both a test suite *and* an individual" <<
endl << " test. Both will be executed, but it is reccommended you rename" <<
endl << " one of them to resolve the conflict." <<
endl << " one of them to resolve the conflict." <<
endl << endl;
}
}
}
}
_EXPORT
+44 -36
View File
@@ -3,8 +3,16 @@
#include <TestUtils.h>
#include <TestShell.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using std::cout;
using std::dec;
using std::endl;
using std::hex;
using std::string;
_EXPORT
status_t DecodeResult(status_t result) {
if (!BTestShell::GlobalBeVerbose())
@@ -20,134 +28,134 @@ status_t DecodeResult(status_t result) {
case B_ERROR:
str = "B_ERROR";
break;
// Storage Kit Errors
case B_FILE_ERROR:
str = "B_FILE_ERROR";
break;
case B_FILE_NOT_FOUND:
str = "B_FILE_NOT_FOUND";
break;
case B_FILE_EXISTS:
str = "B_FILE_EXISTS";
break;
case B_ENTRY_NOT_FOUND:
str = "B_ENTRY_NOT_FOUND";
break;
case B_NAME_TOO_LONG:
str = "B_NAME_TOO_LONG";
break;
case B_DIRECTORY_NOT_EMPTY:
str = "B_DIRECTORY_NOT_EMPTY";
break;
case B_DEVICE_FULL:
str = "B_DEVICE_FULL";
break;
case B_READ_ONLY_DEVICE:
str = "B_READ_ONLY_DEVICE";
break;
case B_IS_A_DIRECTORY:
str = "B_IS_A_DIRECTORY";
break;
case B_NO_MORE_FDS:
str = "B_NO_MORE_FDS";
break;
case B_CROSS_DEVICE_LINK:
str = "B_CROSS_DEVICE_LINK";
break;
case B_LINK_LIMIT:
str = "B_LINK_LIMIT";
break;
case B_BUSTED_PIPE:
str = "B_BUSTED_PIPE";
break;
case B_UNSUPPORTED:
str = "B_UNSUPPORTED";
break;
case B_PARTITION_TOO_SMALL:
str = "B_PARTITION_TOO_SMALL";
break;
case B_BAD_MIME_SNIFFER_RULE:
str = "B_BAD_MIME_SNIFFER_RULE";
break;
break;
// General Errors
case B_NO_MEMORY:
str = "B_NO_MEMORY";
break;
case B_IO_ERROR:
str = "B_IO_ERROR";
break;
case B_PERMISSION_DENIED:
str = "B_PERMISSION_DENIED";
break;
case B_BAD_INDEX:
str = "B_BAD_INDEX";
break;
case B_BAD_TYPE:
str = "B_BAD_TYPE";
break;
case B_BAD_VALUE:
str = "B_BAD_VALUE";
break;
case B_MISMATCHED_VALUES:
str = "B_MISMATCHED_VALUES";
break;
case B_NAME_NOT_FOUND:
str = "B_NAME_NOT_FOUND";
break;
case B_NAME_IN_USE:
str = "B_NAME_IN_USE";
break;
case B_TIMED_OUT:
str = "B_TIMED_OUT";
break;
case B_INTERRUPTED:
str = "B_INTERRUPTED";
break;
case B_WOULD_BLOCK:
str = "B_WOULD_BLOCK";
break;
case B_CANCELED:
str = "B_CANCELED";
break;
case B_NO_INIT:
str = "B_NO_INIT";
break;
case B_BUSY:
str = "B_BUSY";
break;
case B_NOT_ALLOWED:
str = "B_NOT_ALLOWED";
break;
@@ -171,11 +179,11 @@ status_t DecodeResult(status_t result) {
default:
str = "??????????";
break;
}
cout << endl << "DecodeResult() -- " "0x" << hex << result << " (" << dec << result << ") == " << str << endl;
return result;
}
+8 -4
View File
@@ -4,6 +4,10 @@
#include <stdio.h>
#include <stdarg.h>
using std::map;
using std::string;
using std::vector;
_EXPORT
BThreadedTestCase::BThreadedTestCase(string name, string progressSeparator)
: BTestCase(name)
@@ -24,7 +28,7 @@ BThreadedTestCase::~BThreadedTestCase() {
i++)
{
delete i->second;
}
}
}
_EXPORT
@@ -47,9 +51,9 @@ BThreadedTestCase::NextSubTest() {
return;
}
}
// Handle single-threaded case
BTestCase::NextSubTest();
BTestCase::NextSubTest();
}
_EXPORT
@@ -62,7 +66,7 @@ BThreadedTestCase::Outputf(const char *str, ...) {
{
BAutolock lock(fUpdateLock);
isSingleThreaded = fNumberMap.find(id) == fNumberMap.end();
}
}
if (isSingleThreaded) {
va_list args;
va_start(args, str);
+16 -14
View File
@@ -2,6 +2,8 @@
#include <cppunit/NotEqualException.h>
using std::string;
namespace CppUnit
{
@@ -10,17 +12,17 @@ namespace Asserter
{
void
fail( string message,
void
fail( string message,
SourceLine sourceLine )
{
throw Exception( message, sourceLine );
}
void
failIf( bool shouldFail,
string message,
void
failIf( bool shouldFail,
string message,
SourceLine location )
{
if ( shouldFail )
@@ -28,23 +30,23 @@ failIf( bool shouldFail,
}
void
failNotEqual( string expected,
string actual,
void
failNotEqual( string expected,
string actual,
SourceLine sourceLine,
string additionalMessage )
{
throw NotEqualException( expected,
actual,
sourceLine,
throw NotEqualException( expected,
actual,
sourceLine,
additionalMessage );
}
void
void
failNotEqualIf( bool shouldFail,
string expected,
string actual,
string expected,
string actual,
SourceLine sourceLine,
string additionalMessage )
{
+22 -18
View File
@@ -6,6 +6,10 @@
#include <cppunit/CompilerOutputter.h>
using std::endl;
using std::ostream;
using std::string;
namespace CppUnit
{
@@ -32,7 +36,7 @@ CompilerOutputter::defaultOutputter( TestResultCollector *result,
}
void
void
CompilerOutputter::write()
{
if ( m_result->wasSuccessful() )
@@ -42,15 +46,15 @@ CompilerOutputter::write()
}
void
void
CompilerOutputter::printSucess()
{
m_stream << "OK (" << m_result->runTests() << ")"
m_stream << "OK (" << m_result->runTests() << ")"
<< endl;
}
void
void
CompilerOutputter::printFailureReport()
{
printFailuresList();
@@ -58,7 +62,7 @@ CompilerOutputter::printFailureReport()
}
void
void
CompilerOutputter::printFailuresList()
{
for ( int index =0; index < m_result->testFailuresTotal(); ++index)
@@ -68,7 +72,7 @@ CompilerOutputter::printFailuresList()
}
void
void
CompilerOutputter::printFailureDetail( TestFailure *failure )
{
printFailureLocation( failure->sourceLine() );
@@ -77,26 +81,26 @@ CompilerOutputter::printFailureDetail( TestFailure *failure )
printFailureMessage( failure );
}
void
void
CompilerOutputter::printFailureLocation( SourceLine sourceLine )
{
if ( sourceLine.isValid() )
m_stream << sourceLine.fileName()
m_stream << sourceLine.fileName()
<< "(" << sourceLine.lineNumber() << ") : ";
else
m_stream << "##Failure Location unknown## : ";
}
void
void
CompilerOutputter::printFailureType( TestFailure *failure )
{
m_stream << (failure->isError() ? "Error" : "Assertion");
}
void
void
CompilerOutputter::printFailedTestName( TestFailure *failure )
{
m_stream << endl;
@@ -104,7 +108,7 @@ CompilerOutputter::printFailedTestName( TestFailure *failure )
}
void
void
CompilerOutputter::printFailureMessage( TestFailure *failure )
{
m_stream << endl;
@@ -117,7 +121,7 @@ CompilerOutputter::printFailureMessage( TestFailure *failure )
}
void
void
CompilerOutputter::printNotEqualMessage( Exception *thrownException )
{
NotEqualException *e = (NotEqualException *)thrownException;
@@ -133,7 +137,7 @@ CompilerOutputter::printNotEqualMessage( Exception *thrownException )
}
void
void
CompilerOutputter::printDefaultMessage( Exception *thrownException )
{
string wrappedMessage = wrap( thrownException->what() );
@@ -141,7 +145,7 @@ CompilerOutputter::printDefaultMessage( Exception *thrownException )
}
void
void
CompilerOutputter::printStatistics()
{
m_stream << "Failures !!!" << endl;
@@ -177,7 +181,7 @@ CompilerOutputter::wrap( string message )
}
CompilerOutputter::Lines
CompilerOutputter::Lines
CompilerOutputter::splitMessageIntoLines( string message )
{
Lines lines;
@@ -185,8 +189,8 @@ CompilerOutputter::splitMessageIntoLines( string message )
string::iterator itStart = message.begin();
while ( true )
{
string::iterator itEol = find( itStart,
message.end(),
string::iterator itEol = find( itStart,
message.end(),
'\n' );
lines.push_back( message.substr( itStart - message.begin(),
itEol - itStart ) );
+27 -27
View File
@@ -18,20 +18,20 @@ const long Exception::UNKNOWNLINENUMBER = -1;
/// Construct the exception
Exception::Exception( const Exception &other ) :
Exception::Exception( const Exception &other ) :
exception( other )
{
m_message = other.m_message;
{
m_message = other.m_message;
m_sourceLine = other.m_sourceLine;
}
}
/*!
* \deprecated Use other constructor instead.
*/
Exception::Exception( string message,
SourceLine sourceLine ) :
m_message( message ),
Exception::Exception( std::string message,
SourceLine sourceLine ) :
m_message( message ),
m_sourceLine( sourceLine )
{
}
@@ -41,10 +41,10 @@ Exception::Exception( string message,
/*!
* \deprecated Use other constructor instead.
*/
Exception::Exception( string message,
long lineNumber,
string fileName ) :
m_message( message ),
Exception::Exception( std::string message,
long lineNumber,
std::string fileName ) :
m_message( message ),
m_sourceLine( fileName, lineNumber )
{
}
@@ -58,33 +58,33 @@ Exception::~Exception () throw()
/// Perform an assignment
Exception&
Exception&
Exception::operator =( const Exception& other )
{
{
// Don't call superclass operator =(). VC++ STL implementation
// has a bug. It calls the destructor and copy constructor of
// has a bug. It calls the destructor and copy constructor of
// exception() which reset the virtual table to exception.
// SuperClass::operator =(other);
if ( &other != this )
{
m_message = other.m_message;
m_message = other.m_message;
m_sourceLine = other.m_sourceLine;
}
return *this;
return *this;
}
/// Return descriptive message
const char*
Exception::what() const throw()
{
return m_message.c_str ();
{
return m_message.c_str ();
}
/// Location where the error occured
SourceLine
SourceLine
Exception::sourceLine() const
{
return m_sourceLine;
@@ -93,19 +93,19 @@ Exception::sourceLine() const
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
/// The line on which the error occurred
long
long
Exception::lineNumber() const
{
return m_sourceLine.isValid() ? m_sourceLine.lineNumber() :
UNKNOWNLINENUMBER;
{
return m_sourceLine.isValid() ? m_sourceLine.lineNumber() :
UNKNOWNLINENUMBER;
}
/// The file in which the error occurred
string
string
Exception::fileName() const
{
return m_sourceLine.isValid() ? m_sourceLine.fileName() :
{
return m_sourceLine.isValid() ? m_sourceLine.fileName() :
UNKNOWNFILENAME;
}
#endif
@@ -118,7 +118,7 @@ Exception::clone() const
}
bool
bool
Exception::isInstanceOf( const Type &exceptionType ) const
{
return exceptionType == type();
+12 -10
View File
@@ -3,12 +3,14 @@
namespace CppUnit {
using std::string;
NotEqualException::NotEqualException( string expected,
string actual,
string actual,
SourceLine sourceLine ,
string additionalMessage ) :
Exception( "Expected: " + expected +
", but was: " + actual +
Exception( "Expected: " + expected +
", but was: " + actual +
"." + additionalMessage ,
sourceLine),
m_expected( expected ),
@@ -24,8 +26,8 @@ NotEqualException::NotEqualException( string expected,
*/
NotEqualException::NotEqualException( string expected,
string actual,
long lineNumber,
string fileName ) :
long lineNumber,
string fileName ) :
Exception( "Expected: " + expected + ", but was: " + actual,
lineNumber,
fileName ),
@@ -36,7 +38,7 @@ NotEqualException::NotEqualException( string expected,
#endif
NotEqualException::NotEqualException( const NotEqualException &other ) :
NotEqualException::NotEqualException( const NotEqualException &other ) :
Exception( other ),
m_expected( other.m_expected ),
m_actual( other.m_actual ),
@@ -72,7 +74,7 @@ NotEqualException::clone() const
}
bool
bool
NotEqualException::isInstanceOf( const Type &exceptionType ) const
{
return exceptionType == type() ||
@@ -87,21 +89,21 @@ NotEqualException::type()
}
string
string
NotEqualException::expectedValue() const
{
return m_expected;
}
string
string
NotEqualException::actualValue() const
{
return m_actual;
}
string
string
NotEqualException::additionalMessage() const
{
return m_additionalMessage;
+9 -8
View File
@@ -4,27 +4,28 @@
namespace CppUnit {
using std::string;
// Counts the number of test cases that will be run by this test.
int
RepeatedTest::countTestCases() const
{
return TestDecorator::countTestCases () * m_timesRepeat;
{
return TestDecorator::countTestCases () * m_timesRepeat;
}
// Returns the name of the test instance.
string
// Returns the name of the test instance.
string
RepeatedTest::toString() const
{
return TestDecorator::toString () + " (repeated)";
{
return TestDecorator::toString () + " (repeated)";
}
// Runs a repeated test
void
void
RepeatedTest::run( TestResult *result )
{
for ( int n = 0; n < m_timesRepeat; n++ )
for ( int n = 0; n < m_timesRepeat; n++ )
{
if ( result->shouldStop() )
break;
+7 -5
View File
@@ -1,6 +1,8 @@
#include <cppunit/SourceLine.h>
using std::string;
namespace CppUnit
{
@@ -23,28 +25,28 @@ SourceLine::~SourceLine()
}
bool
bool
SourceLine::isValid() const
{
return !m_fileName.empty();
}
int
int
SourceLine::lineNumber() const
{
return m_lineNumber;
}
string
string
SourceLine::fileName() const
{
return m_fileName;
}
bool
bool
SourceLine::operator ==( const SourceLine &other ) const
{
return m_fileName == other.m_fileName &&
@@ -52,7 +54,7 @@ SourceLine::operator ==( const SourceLine &other ) const
}
bool
bool
SourceLine::operator !=( const SourceLine &other ) const
{
return !( *this == other );
+24 -21
View File
@@ -7,18 +7,21 @@
#include "cppunit/TestResult.h"
using std::exception;
using std::string;
namespace CppUnit {
/// Create a default TestResult
CppUnit::TestResult*
CppUnit::TestResult*
TestCase::defaultResult()
{
return new TestResult;
}
{
return new TestResult;
}
/// Run the test and catch any exceptions that are triggered by it
void
/// Run the test and catch any exceptions that are triggered by it
void
TestCase::run( TestResult *result )
{
result->startTest(this);
@@ -51,12 +54,12 @@ TestCase::run( TestResult *result )
catch (...) {
result->addError( this, new Exception( "setUp() failed" ) );
}
result->endTest( this );
}
/// A default run method
/// A default run method
TestResult *
TestCase::run()
{
@@ -67,8 +70,8 @@ TestCase::run()
}
/// All the work for runTest is deferred to subclasses
void
/// All the work for runTest is deferred to subclasses
void
TestCase::runTest()
{
}
@@ -100,36 +103,36 @@ TestCase::~TestCase()
/// Returns a count of all the tests executed
int
int
TestCase::countTestCases() const
{
return 1;
{
return 1;
}
/// Returns the name of the test case
string
string
TestCase::getName() const
{
return m_name;
{
return m_name;
}
/// Returns the name of the test case instance
string
string
TestCase::toString() const
{
{
string className;
#if CPPUNIT_USE_TYPEINFO_NAME
const type_info& thisClass = typeid( *this );
const std::type_info& thisClass = typeid( *this );
className = thisClass.name();
#else
className = "TestCase";
#endif
return className + "." + getName();
return className + "." + getName();
}
} // namespace CppUnit
@@ -9,12 +9,16 @@
#endif
using std::map;
using std::set;
using std::string;
namespace CppUnit {
/** (Implementation) This class manages all the TestFactoryRegistry.
*
* Responsible for the life-cycle of the TestFactoryRegistry.
*
*
* TestFactory registry must call wasDestroyed() to indicate that
* a given TestRegistry was destroyed, and needDestroy() to
* know if a given TestFactory need to be destroyed (was not already
@@ -71,13 +75,13 @@ NamedRegistries::getRegistry( string name )
{
TestFactoryRegistry *factory = new TestFactoryRegistry( name );
#if defined(__POWERPC__) && (defined(__BEOS__) || defined(__HAIKU__))
m_registries.insert(
m_registries.insert(
pair<
const basic_string< char, char_traits< char>, allocator<char> >,
const basic_string< char, char_traits< char>, allocator<char> >,
CppUnit::TestFactoryRegistry*
>(
name, factory
)
name, factory
)
);
#else
m_registries.insert( std::make_pair( name, factory ) );
@@ -89,7 +93,7 @@ NamedRegistries::getRegistry( string name )
}
void
void
NamedRegistries::wasDestroyed( TestFactory *factory )
{
m_factoriesToDestroy.erase( factory );
@@ -97,7 +101,7 @@ NamedRegistries::wasDestroyed( TestFactory *factory )
}
bool
bool
NamedRegistries::needDestroy( TestFactory *factory )
{
return m_destroyedFactories.count( factory ) == 0;
@@ -143,7 +147,7 @@ TestFactoryRegistry::getRegistry( const string &name )
}
void
void
TestFactoryRegistry::registerFactory( const string &name,
TestFactory *factory )
{
@@ -151,7 +155,7 @@ TestFactoryRegistry::registerFactory( const string &name,
}
void
void
TestFactoryRegistry::registerFactory( TestFactory *factory )
{
static int serialNumber = 1;
@@ -172,11 +176,11 @@ TestFactoryRegistry::makeTest()
}
void
void
TestFactoryRegistry::addTestToSuite( TestSuite *suite )
{
for ( Factories::iterator it = m_factories.begin();
it != m_factories.end();
for ( Factories::iterator it = m_factories.begin();
it != m_factories.end();
++it )
{
TestFactory *factory = (*it).second;
+16 -14
View File
@@ -2,13 +2,15 @@
#include "cppunit/Test.h"
#include "cppunit/TestFailure.h"
using std::string;
namespace CppUnit {
/// Constructs a TestFailure with the given test and exception.
TestFailure::TestFailure( Test *failedTest,
TestFailure::TestFailure( Test *failedTest,
Exception *thrownException,
bool isError ) :
m_failedTest( failedTest ),
m_failedTest( failedTest ),
m_thrownException( thrownException ),
m_isError( isError )
{
@@ -16,28 +18,28 @@ TestFailure::TestFailure( Test *failedTest,
/// Deletes the owned exception.
TestFailure::~TestFailure()
{
delete m_thrownException;
{
delete m_thrownException;
}
/// Gets the failed test.
Test *
TestFailure::failedTest() const
{
return m_failedTest;
{
return m_failedTest;
}
/// Gets the thrown exception. Never \c NULL.
Exception *
TestFailure::thrownException() const
{
return m_thrownException;
{
return m_thrownException;
}
/// Gets the failure location.
SourceLine
SourceLine
TestFailure::sourceLine() const
{
return m_thrownException->sourceLine();
@@ -45,7 +47,7 @@ TestFailure::sourceLine() const
/// Indicates if the failure is a failed assertion or an error.
bool
bool
TestFailure::isError() const
{
return m_isError;
@@ -53,7 +55,7 @@ TestFailure::isError() const
/// Gets the name of the failed test.
string
string
TestFailure::failedTestName() const
{
return m_failedTest->getName();
@@ -61,9 +63,9 @@ TestFailure::failedTestName() const
/// Returns a short description of the failure.
string
TestFailure::toString() const
{
string
TestFailure::toString() const
{
return m_failedTest->toString() + ": " + m_thrownException->what();
}
+13 -10
View File
@@ -6,6 +6,9 @@
#include <cppunit/ui/text/TestRunner.h>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
namespace CppUnit {
namespace TextUi {
@@ -13,7 +16,7 @@ namespace TextUi {
/*! Constructs a new text runner.
* \param outputter used to print text result. Owned by the runner.
*/
TestRunner::TestRunner( Outputter *outputter )
TestRunner::TestRunner( Outputter *outputter )
: m_suite( new TestSuite( "All Tests" ) )
, m_result( new TestResultCollector() )
, m_eventManager( new TestResult() )
@@ -38,7 +41,7 @@ TestRunner::~TestRunner()
*
* \param test Test to add.
*/
void
void
TestRunner::addTest( Test *test )
{
if ( test != NULL )
@@ -51,7 +54,7 @@ TestRunner::addTest( Test *test )
* \param testName Name of the test case to run. If an empty is given, then
* all added test are run. The name must be the name of
* of an added test.
* \param doWait if \c true then the user must press the RETURN key
* \param doWait if \c true then the user must press the RETURN key
* before the run() method exit.
* \param doPrintResult if \c true (default) then the test result are printed
* on the standard output.
@@ -89,10 +92,10 @@ TestRunner::runTestByName( string testName,
}
void
void
TestRunner::wait( bool doWait )
{
if ( doWait )
if ( doWait )
{
cout << "<RETURN> to continue" << endl;
cin.get ();
@@ -100,7 +103,7 @@ TestRunner::wait( bool doWait )
}
void
void
TestRunner::printResult( bool doPrintResult )
{
cout << endl;
@@ -109,11 +112,11 @@ TestRunner::printResult( bool doPrintResult )
}
Test *
Test *
TestRunner::findTestByName( string name ) const
{
for ( vector<Test *>::const_iterator it = m_suite->getTests().begin();
it != m_suite->getTests().end();
for ( vector<Test *>::const_iterator it = m_suite->getTests().begin();
it != m_suite->getTests().end();
++it )
{
Test *test = *it;
@@ -167,7 +170,7 @@ TestRunner::eventManager() const
* \c true.
* \see CompilerOutputter, XmlOutputter, TextOutputter.
*/
void
void
TestRunner::setOutputter( Outputter *outputter )
{
delete m_outputter;
+17 -14
View File
@@ -5,6 +5,9 @@
#include <cppunit/TextOutputter.h>
using std::endl;
using std::ostream;
namespace CppUnit
{
@@ -22,8 +25,8 @@ TextOutputter::~TextOutputter()
}
void
TextOutputter::write()
void
TextOutputter::write()
{
printHeader();
m_stream << endl;
@@ -32,12 +35,12 @@ TextOutputter::write()
}
void
void
TextOutputter::printFailures()
{
TestResultCollector::TestFailures::const_iterator itFailure = m_result->failures().begin();
int failureNumber = 1;
while ( itFailure != m_result->failures().end() )
while ( itFailure != m_result->failures().end() )
{
m_stream << endl;
printFailure( *itFailure++, failureNumber++ );
@@ -45,7 +48,7 @@ TextOutputter::printFailures()
}
void
void
TextOutputter::printFailure( TestFailure *failure,
int failureNumber )
{
@@ -62,21 +65,21 @@ TextOutputter::printFailure( TestFailure *failure,
}
void
void
TextOutputter::printFailureListMark( int failureNumber )
{
m_stream << failureNumber << ")";
}
void
void
TextOutputter::printFailureTestName( TestFailure *failure )
{
m_stream << "test: " << failure->failedTestName();
}
void
void
TextOutputter::printFailureType( TestFailure *failure )
{
m_stream << "("
@@ -85,7 +88,7 @@ TextOutputter::printFailureType( TestFailure *failure )
}
void
void
TextOutputter::printFailureLocation( SourceLine sourceLine )
{
if ( !sourceLine.isValid() )
@@ -96,7 +99,7 @@ TextOutputter::printFailureLocation( SourceLine sourceLine )
}
void
void
TextOutputter::printFailureDetail( Exception *thrownException )
{
if ( thrownException->isInstanceOf( NotEqualException::type() ) )
@@ -118,11 +121,11 @@ TextOutputter::printFailureDetail( Exception *thrownException )
}
void
void
TextOutputter::printHeader()
{
if ( m_result->wasSuccessful() )
m_stream << endl << "OK (" << m_result->runTests () << " tests)"
m_stream << endl << "OK (" << m_result->runTests () << " tests)"
<< endl;
else
{
@@ -133,14 +136,14 @@ TextOutputter::printHeader()
}
void
void
TextOutputter::printFailureWarning()
{
m_stream << "!!!FAILURES!!!" << endl;
}
void
void
TextOutputter::printStatistics()
{
m_stream << "Test Results:" << endl;
@@ -3,6 +3,9 @@
#include <iostream>
using std::cerr;
using std::endl;
namespace CppUnit
{
@@ -17,7 +20,7 @@ TextTestProgressListener::~TextTestProgressListener()
}
void
void
TextTestProgressListener::startTest( Test *test )
{
cerr << ".";
@@ -25,7 +28,7 @@ TextTestProgressListener::startTest( Test *test )
}
void
void
TextTestProgressListener::addFailure( const TestFailure &failure )
{
cerr << ( failure.isError() ? "E" : "F" );
@@ -33,7 +36,7 @@ TextTestProgressListener::addFailure( const TestFailure &failure )
}
void
void
TextTestProgressListener::done()
{
cerr << endl;
+24 -20
View File
@@ -6,6 +6,10 @@
#include <iostream>
using std::cerr;
using std::endl;
using std::ostream;
namespace CppUnit {
@@ -15,14 +19,14 @@ TextTestResult::TextTestResult()
}
void
void
TextTestResult::addFailure( Test *test, Exception *e )
{
TestResult::addFailure( test, e );
}
void
void
TextTestResult::addFailure( const TestFailure &failure )
{
TestResultCollector::addFailure( failure );
@@ -30,7 +34,7 @@ TextTestResult::addFailure( const TestFailure &failure )
}
void
void
TextTestResult::startTest( Test *test )
{
TestResultCollector::startTest (test);
@@ -38,12 +42,12 @@ TextTestResult::startTest( Test *test )
}
void
void
TextTestResult::printFailures( ostream &stream )
{
TestFailures::const_iterator itFailure = failures().begin();
int failureNumber = 1;
while ( itFailure != failures().end() )
while ( itFailure != failures().end() )
{
stream << endl;
printFailure( *itFailure++, failureNumber++, stream );
@@ -51,7 +55,7 @@ TextTestResult::printFailures( ostream &stream )
}
void
void
TextTestResult::printFailure( TestFailure *failure,
int failureNumber,
ostream &stream )
@@ -69,7 +73,7 @@ TextTestResult::printFailure( TestFailure *failure,
}
void
void
TextTestResult::printFailureListMark( int failureNumber,
ostream &stream )
{
@@ -77,7 +81,7 @@ TextTestResult::printFailureListMark( int failureNumber,
}
void
void
TextTestResult::printFailureTestName( TestFailure *failure,
ostream &stream )
{
@@ -85,7 +89,7 @@ TextTestResult::printFailureTestName( TestFailure *failure,
}
void
void
TextTestResult::printFailureType( TestFailure *failure,
ostream &stream )
{
@@ -95,7 +99,7 @@ TextTestResult::printFailureType( TestFailure *failure,
}
void
void
TextTestResult::printFailureLocation( SourceLine sourceLine,
ostream &stream )
{
@@ -107,7 +111,7 @@ TextTestResult::printFailureLocation( SourceLine sourceLine,
}
void
void
TextTestResult::printFailureDetail( Exception *thrownException,
ostream &stream )
{
@@ -130,8 +134,8 @@ TextTestResult::printFailureDetail( Exception *thrownException,
}
void
TextTestResult::print( ostream& stream )
void
TextTestResult::print( ostream& stream )
{
printHeader( stream );
stream << endl;
@@ -139,11 +143,11 @@ TextTestResult::print( ostream& stream )
}
void
void
TextTestResult::printHeader( ostream &stream )
{
if (wasSuccessful ())
stream << endl << "OK (" << runTests () << " tests)"
stream << endl << "OK (" << runTests () << " tests)"
<< endl;
else
{
@@ -154,14 +158,14 @@ TextTestResult::printHeader( ostream &stream )
}
void
void
TextTestResult::printFailureWarning( ostream &stream )
{
stream << "!!!FAILURES!!!" << endl;
}
void
void
TextTestResult::printStatistics( ostream &stream )
{
stream << "Test Results:" << endl;
@@ -174,10 +178,10 @@ TextTestResult::printStatistics( ostream &stream )
ostream &
operator <<( ostream &stream,
operator <<( ostream &stream,
TextTestResult &result )
{
result.print (stream); return stream;
{
result.print (stream); return stream;
}
+6 -3
View File
@@ -6,9 +6,12 @@
#include <cppunit/extensions/TypeInfoHelper.h>
using std::string;
using std::type_info;
namespace CppUnit {
string
string
TypeInfoHelper::getClassName( const type_info &info )
{
static const string classPrefix( "class " );
@@ -18,7 +21,7 @@ TypeInfoHelper::getClassName( const type_info &info )
#if CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST
name.compare( classPrefix, 0, classPrefix.length() );
#else
name.compare( 0, classPrefix.length(), classPrefix );
name.compare( 0, classPrefix.length(), classPrefix );
#endif
return has_class_prefix ? name.substr( classPrefix.length() ) : name;
@@ -27,4 +30,4 @@ TypeInfoHelper::getClassName( const type_info &info )
} // namespace CppUnit
#endif
#endif
+32 -26
View File
@@ -7,6 +7,12 @@
#include <stdlib.h>
using std::endl;
using std::ostream;
using std::pair;
using std::string;
namespace CppUnit
{
@@ -21,7 +27,7 @@ XmlOutputter::Node::Node( string elementName,
{
}
XmlOutputter::Node::Node( string elementName,
int numericContent ) :
m_name( elementName )
@@ -38,7 +44,7 @@ XmlOutputter::Node::~Node()
}
void
void
XmlOutputter::Node::addAttribute( string attributeName,
string value )
{
@@ -46,7 +52,7 @@ XmlOutputter::Node::addAttribute( string attributeName,
}
void
void
XmlOutputter::Node::addAttribute( string attributeName,
int numericValue )
{
@@ -54,14 +60,14 @@ XmlOutputter::Node::addAttribute( string attributeName,
}
void
void
XmlOutputter::Node::addNode( Node *node )
{
m_nodes.push_back( node );
}
string
string
XmlOutputter::Node::toString() const
{
string element = "<";
@@ -87,7 +93,7 @@ XmlOutputter::Node::toString() const
}
string
string
XmlOutputter::Node::attributesAsString() const
{
string attributes;
@@ -104,7 +110,7 @@ XmlOutputter::Node::attributesAsString() const
}
string
string
XmlOutputter::Node::escape( string value ) const
{
string escaped;
@@ -113,31 +119,31 @@ XmlOutputter::Node::escape( string value ) const
char c = value[index ];
switch ( c ) // escape all predefined XML entity (safe?)
{
case '<':
case '<':
escaped += "&lt;";
break;
case '>':
case '>':
escaped += "&gt;";
break;
case '&':
case '&':
escaped += "&amp;";
break;
case '\'':
case '\'':
escaped += "&apos;";
break;
case '"':
case '"':
escaped += "&quot;";
break;
default:
escaped += c;
}
}
return escaped;
}
// should be somewhere else... Future CppUnit::String ?
string
// should be somewhere else... Future CppUnit::String ?
string
XmlOutputter::Node::asString( int value )
{
OStringStream stream;
@@ -166,7 +172,7 @@ XmlOutputter::~XmlOutputter()
}
void
void
XmlOutputter::write()
{
writeProlog();
@@ -174,7 +180,7 @@ XmlOutputter::write()
}
void
void
XmlOutputter::writeProlog()
{
m_stream << "<?xml version=\"1.0\" "
@@ -183,7 +189,7 @@ XmlOutputter::writeProlog()
}
void
void
XmlOutputter::writeTestsResult()
{
Node *rootNode = makeRootNode();
@@ -208,7 +214,7 @@ XmlOutputter::makeRootNode()
}
void
void
XmlOutputter::fillFailedTestsMap( FailedTests &failedTests )
{
const TestResultCollector::TestFailures &failures = m_result->failures();
@@ -216,11 +222,11 @@ XmlOutputter::fillFailedTestsMap( FailedTests &failedTests )
while ( itFailure != failures.end() )
{
TestFailure *failure = *itFailure++;
failedTests.insert(
failedTests.insert(
pair< CppUnit::Test* const, CppUnit::TestFailure*
>(
failure->failedTest(), failure
)
failure->failedTest(), failure
)
);
}
}
@@ -266,7 +272,7 @@ XmlOutputter::addStatistics( Node *rootNode )
Node *statisticsNode = new Node( "Statistics" );
rootNode->addNode( statisticsNode );
statisticsNode->addNode( new Node( "Tests", m_result->runTests() ) );
statisticsNode->addNode( new Node( "FailuresTotal",
statisticsNode->addNode( new Node( "FailuresTotal",
m_result->testFailuresTotal() ) );
statisticsNode->addNode( new Node( "Errors", m_result->testErrors() ) );
statisticsNode->addNode( new Node( "Failures", m_result->testFailures() ) );
@@ -280,12 +286,12 @@ XmlOutputter::addFailedTest( Test *test,
Node *testsNode )
{
Exception *thrownException = failure->thrownException();
Node *testNode = new Node( "FailedTest", thrownException->what() );
testsNode->addNode( testNode );
testNode->addAttribute( "id", testNumber );
testNode->addNode( new Node( "Name", test->getName() ) );
testNode->addNode( new Node( "FailureType",
testNode->addNode( new Node( "FailureType",
failure->isError() ? "Error" : "Assertion" ) );
if ( failure->sourceLine().isValid() )
@@ -306,7 +312,7 @@ XmlOutputter::addFailureLocation( TestFailure *failure,
void
XmlOutputter::addSucessfulTest( Test *test,
XmlOutputter::addSucessfulTest( Test *test,
int testNumber,
Node *testsNode )
{