It is accomplished ...
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
//----------------------------------------------------------------------
|
||||
// CppUnitShell.h - Copyright 2002 Tyler Dauwalder
|
||||
// This software is release under the GNU Lesser GPL
|
||||
// See the accompanying CppUnitShell.LICENSE file, or wander
|
||||
// over to: http://www.gnu.org/copyleft/lesser.html
|
||||
//----------------------------------------------------------------------
|
||||
#ifndef __cppunitshell_h__
|
||||
#define __cppunitshell_h__
|
||||
|
||||
#include <LockerSyncObject.h>
|
||||
#include <cppunit/Exception.h>
|
||||
#include <cppunit/Test.h>
|
||||
#include <cppunit/TestListener.h>
|
||||
#include <TestResult.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
// Defines SuiteFunction to be a pointer to a function that
|
||||
// takes no arguments and returns a pointer to a CppUnit::Test
|
||||
typedef CppUnit::Test* (*SuiteFunction)(void);
|
||||
|
||||
// This is just absurd to have to type...
|
||||
typedef CppUnit::SynchronizedObject::SynchronizationObject SyncObject;
|
||||
|
||||
// This class provides a fully functional command-line testing interface
|
||||
// built on top of the CppUnit testing library. You add named test suites
|
||||
// via AddSuite(), and then call Run(), which does all the dirty work. The
|
||||
// user can get a list of each test installed via AddSuite(), and optionally
|
||||
// can opt to run only a specified set of them.
|
||||
class CppUnitShell {
|
||||
public:
|
||||
CppUnitShell(const std::string &description = "", SyncObject *syncObject = 0);
|
||||
|
||||
// This function is used to add test suites to the list of available
|
||||
// tests. A SuiteFunction is just a function that takes no parameters
|
||||
// and returns a pointer to a CppUnit::Test object. Return NULL at
|
||||
// your own risk :-). The name given is the name that will be presented
|
||||
// when the program is run with "--list" as an argument. Usually the
|
||||
// given suite would be a test suite for an entire class, but that's
|
||||
// not a requirement.
|
||||
void AddSuite(const std::string &name, const SuiteFunction suite);
|
||||
|
||||
// This is the function you call after you've added all your test
|
||||
// suites with calls to AddSuite(). It runs the test, or displays
|
||||
// help, or lists installed tests, or whatever, depending on the
|
||||
// command-line arguments passed in.
|
||||
int Run(int argc, char *argv[]);
|
||||
|
||||
// Verbosity Level enumeration and accessor function
|
||||
enum VerbosityLevel { v0, v1, v2, v3 };
|
||||
VerbosityLevel Verbosity() const;
|
||||
|
||||
// Returns true if verbosity is high enough that individual tests are
|
||||
// allowed to make noise.
|
||||
bool BeVerbose() const { return Verbosity() >= v2; };
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
VerbosityLevel fVerbosityLevel;
|
||||
std::set<std::string> fTestsToRun;
|
||||
std::map<std::string, SuiteFunction> fTests;
|
||||
CppUnit::TestResult fTestResults;
|
||||
CppUnit::TestResultCollector fResultsCollector;
|
||||
std::string fDescription;
|
||||
|
||||
// Prints a brief description of the program and a guess as to
|
||||
// which Storage Kit library the app was linked with based on
|
||||
// the filename of the app
|
||||
virtual void PrintDescription(int argc, char *argv[]);
|
||||
|
||||
// Prints out command line argument instructions
|
||||
void PrintHelp();
|
||||
|
||||
// Handles command line arguments; returns true if everything goes
|
||||
// okay, false if not (or if the program just needs to terminate without
|
||||
// running any tests). Modifies settings in "settings" as necessary.
|
||||
bool ProcessArguments(int argc, char *argv[]);
|
||||
|
||||
// Makes any necessary pre-test preparations
|
||||
void InitOutput();
|
||||
|
||||
// Prints out the test results in the proper format per
|
||||
// the specified verbosity level.
|
||||
void PrintResults();
|
||||
|
||||
//! Handles printing of test progress info
|
||||
/*! Receives notification of the beginning and end of each test,
|
||||
as well as all failures and errors for each test. Prints out
|
||||
said test information in a standard format to standard output.
|
||||
*/
|
||||
class TestListener : public ::CppUnit::TestListener {
|
||||
protected:
|
||||
bool ok;
|
||||
|
||||
public:
|
||||
|
||||
virtual void startTest( CppUnit::Test *test ) {
|
||||
ok = true;
|
||||
cout << test->getName() << endl;
|
||||
}
|
||||
|
||||
virtual void addError( CppUnit::Test *test, CppUnit::Exception *e ) {
|
||||
ok = false;
|
||||
cout << " - ERROR -- " << e->what() << endl;
|
||||
}
|
||||
|
||||
virtual void addFailure( CppUnit::Test *test, CppUnit::Exception *e ) {
|
||||
ok = false;
|
||||
cout << " - FAILURE -- " << e->what() << endl;
|
||||
}
|
||||
|
||||
virtual void endTest( CppUnit::Test *test ) {
|
||||
if (ok)
|
||||
cout << " + PASSED" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
}; // class CppUnitShell
|
||||
|
||||
#endif // __cppunitshell_h__
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _beos_synchronization_object_h_
|
||||
#define _beos_synchronization_object_h_
|
||||
|
||||
#include <cppunit/SynchronizedObject.h>
|
||||
#include <Locker.h>
|
||||
|
||||
/*! \brief BLocker based implementation of CppUnit::SynchronizedObject::SynchronizationObject
|
||||
*/
|
||||
class LockerSyncObject : public CppUnit::SynchronizedObject::SynchronizationObject {
|
||||
public:
|
||||
/* LockerSyncObject() : fLock(new BLocker()) {}
|
||||
virtual ~LockerSyncObject() { cout << 1 << endl; delete fLock; cout << 2 << endl; }
|
||||
|
||||
virtual void lock() { fLock->Lock(); }
|
||||
virtual void unlock() { fLock->Unlock(); }
|
||||
protected:
|
||||
BLocker *fLock;
|
||||
*/
|
||||
LockerSyncObject() {}
|
||||
virtual ~LockerSyncObject() {}
|
||||
|
||||
virtual void lock() { fLock.Lock(); }
|
||||
virtual void unlock() { fLock.Unlock(); }
|
||||
protected:
|
||||
BLocker fLock;
|
||||
};
|
||||
|
||||
#endif // _beos_synchronization_object_h_
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef _beos_test_case_h_
|
||||
#define _beos_test_case_h_
|
||||
|
||||
#include <cppunit/TestCase.h>
|
||||
#include <StorageDefs.h>
|
||||
|
||||
class TestCase : public CppUnit::TestCase {
|
||||
public:
|
||||
TestCase();
|
||||
TestCase(std::string Name);
|
||||
void SaveCWD();
|
||||
void RestoreCWD(const char *alternate = NULL);
|
||||
protected:
|
||||
bool fValidCWD;
|
||||
char fCurrentWorkingDir[B_PATH_NAME_LENGTH+1];
|
||||
};
|
||||
|
||||
#endif // _beos_test_case_h_
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef _beos_test_result_h_
|
||||
#define _beos_test_result_h_
|
||||
|
||||
#include <cppunit/TestResult.h>
|
||||
|
||||
/*! \brief CppUnit::TestResult class with BeOS synchronization implementation.
|
||||
|
||||
*/
|
||||
//template <class SynchronizationObject>
|
||||
class TestResult : public CppUnit::TestResult {
|
||||
public:
|
||||
TestResult();
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif // _beos_test_result_h_
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef _beos_test_shell_h_
|
||||
#define _beos_test_shell_h_
|
||||
|
||||
#include <CppUnitShell.h>
|
||||
|
||||
class TestShell : public CppUnitShell {
|
||||
public:
|
||||
TestShell(const std::string &description = "", SyncObject *syncObject = 0);
|
||||
~TestShell();
|
||||
int Run(int argc, char *argv[]);
|
||||
// virtual void PrintDescription(int argc, char *argv[]);
|
||||
const char* TestDir() const;
|
||||
private:
|
||||
BPath *fTestDir;
|
||||
};
|
||||
|
||||
#endif // _beos_test_shell_h_
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef _beos_test_suite_h_
|
||||
#define _beos_test_suite_h_
|
||||
|
||||
#include <cppunit/TestSuite.h>
|
||||
|
||||
class TestSuite : public CppUnit::TestSuite {
|
||||
//! Calls setUp(), runs the test suite, calls tearDown().
|
||||
virtual void run (CppUnit::TestResult *result);
|
||||
|
||||
//! This function called *once* before the entire suite of tests is run
|
||||
virtual void setUp() {}
|
||||
|
||||
//! This function called *once* after the entire suite of tests is run
|
||||
virtual void tearDown() {}
|
||||
|
||||
};
|
||||
|
||||
#endif // _beos_test_suite_h_
|
||||
@@ -0,0 +1,91 @@
|
||||
#ifndef CPPUNIT_ASSERTER_H
|
||||
#define CPPUNIT_ASSERTER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/SourceLine.h>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
/*! \brief A set of functions to help writing assertion macros.
|
||||
* \ingroup CreatingNewAssertions
|
||||
*
|
||||
* Here is an example of assertion, a simplified version of the
|
||||
* actual assertion implemented in examples/cppunittest/XmlUniformiser.h:
|
||||
* \code
|
||||
* #include <cppunit/SourceLine.h>
|
||||
* #include <cppunit/TestAssert.h>
|
||||
*
|
||||
* void
|
||||
* checkXmlEqual( std::string expectedXml,
|
||||
* std::string actualXml,
|
||||
* CppUnit::SourceLine sourceLine )
|
||||
* {
|
||||
* std::string expected = XmlUniformiser( expectedXml ).stripped();
|
||||
* std::string actual = XmlUniformiser( actualXml ).stripped();
|
||||
*
|
||||
* if ( expected == actual )
|
||||
* return;
|
||||
*
|
||||
* ::CppUnit::Asserter::failNotEqual( expected,
|
||||
* actual,
|
||||
* sourceLine );
|
||||
* }
|
||||
*
|
||||
* /// Asserts that two XML strings are equivalent.
|
||||
* #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
|
||||
* checkXmlEqual( expected, actual, \
|
||||
* CPPUNIT_SOURCELINE() )
|
||||
* \endcode
|
||||
*/
|
||||
namespace Asserter
|
||||
{
|
||||
|
||||
/*! Throws a Exception with the specified message and location.
|
||||
*/
|
||||
void CPPUNIT_API fail( std::string message,
|
||||
SourceLine sourceLine = SourceLine() );
|
||||
|
||||
/*! Throws a Exception with the specified message and location.
|
||||
* \param shouldFail if \c true then the exception is thrown. Otherwise
|
||||
* nothing happen.
|
||||
* \param message Message explaining the assertion failiure.
|
||||
* \param sourceLine Location of the assertion.
|
||||
*/
|
||||
void CPPUNIT_API failIf( bool shouldFail,
|
||||
std::string message,
|
||||
SourceLine sourceLine = SourceLine() );
|
||||
|
||||
/*! Throws a NotEqualException with the specified message and location.
|
||||
* \param expected Text describing the expected value.
|
||||
* \param actual Text describing the actual value.
|
||||
* \param additionalMessage Additional message. Usually used to report
|
||||
* where the "difference" is located.
|
||||
* \param sourceLine Location of the assertion.
|
||||
*/
|
||||
void CPPUNIT_API failNotEqual( std::string expected,
|
||||
std::string actual,
|
||||
SourceLine sourceLine = SourceLine(),
|
||||
std::string additionalMessage ="" );
|
||||
|
||||
/*! Throws a NotEqualException with the specified message and location.
|
||||
* \param shouldFail if \c true then the exception is thrown. Otherwise
|
||||
* nothing happen.
|
||||
* \param expected Text describing the expected value.
|
||||
* \param actual Text describing the actual value.
|
||||
* \param additionalMessage Additional message. Usually used to report
|
||||
* where the "difference" is located.
|
||||
* \param sourceLine Location of the assertion.
|
||||
*/
|
||||
void CPPUNIT_API failNotEqualIf( bool shouldFail,
|
||||
std::string expected,
|
||||
std::string actual,
|
||||
SourceLine sourceLine = SourceLine(),
|
||||
std::string additionalMessage ="" );
|
||||
|
||||
} // namespace Asserter
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_ASSERTER_H
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
|
||||
#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/Outputter.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
class Exception;
|
||||
class SourceLine;
|
||||
class Test;
|
||||
class TestFailure;
|
||||
class TestResultCollector;
|
||||
|
||||
/*!
|
||||
* \brief Outputs a TestResultCollector in a compiler compatible format.
|
||||
* \ingroup WritingTestResult
|
||||
*
|
||||
* Printing the test results in a compiler compatible format (assertion
|
||||
* location has the same format as compiler error), allow you to use your
|
||||
* IDE to jump to the assertion failure.
|
||||
*
|
||||
* For example, when running the test in a post-build with VC++, if an assertion
|
||||
* fails, you can jump to the assertion by pressing F4 (jump to next error).
|
||||
*
|
||||
* You should use defaultOutputter() to create an instance.
|
||||
*
|
||||
* Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp):
|
||||
* \code
|
||||
* int main( int argc, char* argv[] ) {
|
||||
* // if command line contains "-selftest" then this is the post build check
|
||||
* // => the output must be in the compiler error format.
|
||||
* bool selfTest = (argc > 1) &&
|
||||
* (std::string("-selftest") == argv[1]);
|
||||
*
|
||||
* CppUnit::TextUi::TestRunner runner;
|
||||
* runner.addTest( CppUnitTest::suite() ); // Add the top suite to the test runner
|
||||
*
|
||||
* if ( selfTest )
|
||||
* { // Change the default outputter to a compiler error format outputter
|
||||
* // The test runner owns the new outputter.
|
||||
* runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter(
|
||||
* &runner.result(),
|
||||
* std::cerr ) );
|
||||
* }
|
||||
*
|
||||
* // Run the test and don't wait a key if post build check.
|
||||
* bool wasSucessful = runner.run( "", !selfTest );
|
||||
*
|
||||
* // Return error code 1 if the one of test failed.
|
||||
* return wasSucessful ? 0 : 1;
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
class CPPUNIT_API CompilerOutputter : public Outputter
|
||||
{
|
||||
public:
|
||||
/*! Constructs a CompilerOutputter object.
|
||||
*/
|
||||
CompilerOutputter( TestResultCollector *result,
|
||||
std::ostream &stream );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~CompilerOutputter();
|
||||
|
||||
/*! Creates an instance of an outputter that matches your current compiler.
|
||||
*/
|
||||
static CompilerOutputter *defaultOutputter( TestResultCollector *result,
|
||||
std::ostream &stream );
|
||||
|
||||
void write();
|
||||
|
||||
virtual void printSucess();
|
||||
virtual void printFailureReport();
|
||||
virtual void printFailuresList();
|
||||
virtual void printStatistics();
|
||||
virtual void printFailureDetail( TestFailure *failure );
|
||||
virtual void printFailureLocation( SourceLine sourceLine );
|
||||
virtual void printFailureType( TestFailure *failure );
|
||||
virtual void printFailedTestName( TestFailure *failure );
|
||||
virtual void printFailureMessage( TestFailure *failure );
|
||||
virtual void printNotEqualMessage( Exception *thrownException );
|
||||
virtual void printDefaultMessage( Exception *thrownException );
|
||||
virtual std::string wrap( std::string message );
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
CompilerOutputter( const CompilerOutputter © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const CompilerOutputter © );
|
||||
|
||||
typedef std::vector<std::string> Lines;
|
||||
static Lines splitMessageIntoLines( std::string message );
|
||||
|
||||
private:
|
||||
TestResultCollector *m_result;
|
||||
std::ostream &m_stream;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
|
||||
#endif // CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef CPPUNIT_EXCEPTION_H
|
||||
#define CPPUNIT_EXCEPTION_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/SourceLine.h>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*! \brief Exceptions thrown by failed assertions.
|
||||
* \ingroup BrowsingCollectedTestResult
|
||||
*
|
||||
* Exception is an exception that serves
|
||||
* descriptive strings through its what() method
|
||||
*/
|
||||
class CPPUNIT_API Exception : public std::exception
|
||||
{
|
||||
public:
|
||||
|
||||
class Type
|
||||
{
|
||||
public:
|
||||
Type( std::string type ) : m_type ( type ) {}
|
||||
|
||||
bool operator ==( const Type &other ) const
|
||||
{
|
||||
return m_type == other.m_type;
|
||||
}
|
||||
private:
|
||||
const std::string m_type;
|
||||
};
|
||||
|
||||
|
||||
Exception( std::string message = "",
|
||||
SourceLine sourceLine = SourceLine() );
|
||||
|
||||
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
|
||||
Exception( std::string message,
|
||||
long lineNumber,
|
||||
std::string fileName );
|
||||
#endif
|
||||
|
||||
Exception (const Exception& other);
|
||||
|
||||
virtual ~Exception () throw();
|
||||
|
||||
Exception& operator= (const Exception& other);
|
||||
|
||||
const char *what() const throw ();
|
||||
|
||||
SourceLine sourceLine() const;
|
||||
|
||||
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
|
||||
long lineNumber() const;
|
||||
std::string fileName() const;
|
||||
|
||||
static const std::string UNKNOWNFILENAME;
|
||||
static const long UNKNOWNLINENUMBER;
|
||||
#endif
|
||||
|
||||
virtual Exception *clone() const;
|
||||
|
||||
virtual bool isInstanceOf( const Type &type ) const;
|
||||
|
||||
static Type type();
|
||||
|
||||
private:
|
||||
// VC++ does not recognize call to parent class when prefixed
|
||||
// with a namespace. This is a workaround.
|
||||
typedef std::exception SuperClass;
|
||||
|
||||
std::string m_message;
|
||||
SourceLine m_sourceLine;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_EXCEPTION_H
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef NOTEQUALEXCEPTION_H
|
||||
#define NOTEQUALEXCEPTION_H
|
||||
|
||||
#include <cppunit/Exception.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*! \brief Exception thrown by failed equality assertions.
|
||||
* \ingroup BrowsingCollectedTestResult
|
||||
*/
|
||||
class CPPUNIT_API NotEqualException : public Exception
|
||||
{
|
||||
public:
|
||||
/*! Constructs the exception.
|
||||
* \param expected Text that represents the expected value.
|
||||
* \param actual Text that represents the actual value.
|
||||
* \param sourceLine Location of the assertion.
|
||||
* \param additionalMessage Additionnal information provided to further qualify
|
||||
* the inequality.
|
||||
*/
|
||||
NotEqualException( std::string expected,
|
||||
std::string actual,
|
||||
SourceLine sourceLine = SourceLine(),
|
||||
std::string additionalMessage = "" );
|
||||
|
||||
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
|
||||
NotEqualException( std::string expected,
|
||||
std::string actual,
|
||||
long lineNumber,
|
||||
std::string fileName );
|
||||
#endif
|
||||
|
||||
NotEqualException( const NotEqualException &other );
|
||||
|
||||
|
||||
virtual ~NotEqualException() throw();
|
||||
|
||||
std::string expectedValue() const;
|
||||
|
||||
std::string actualValue() const;
|
||||
|
||||
std::string additionalMessage() const;
|
||||
|
||||
/*! Copy operator.
|
||||
* @param other Object to copy.
|
||||
* @return Reference on this object.
|
||||
*/
|
||||
NotEqualException &operator =( const NotEqualException &other );
|
||||
|
||||
Exception *clone() const;
|
||||
|
||||
bool isInstanceOf( const Type &type ) const;
|
||||
|
||||
static Type type();
|
||||
|
||||
private:
|
||||
std::string m_expected;
|
||||
std::string m_actual;
|
||||
std::string m_additionalMessage;
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // NOTEQUALEXCEPTION_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef CPPUNIT_OUTPUTTER_H
|
||||
#define CPPUNIT_OUTPUTTER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
/*! \brief Abstract outputter to print test result summary.
|
||||
* \ingroup WritingTestResult
|
||||
*/
|
||||
class CPPUNIT_API Outputter
|
||||
{
|
||||
public:
|
||||
/// Destructor.
|
||||
virtual ~Outputter() {}
|
||||
|
||||
virtual void write() =0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Inlines methods for Outputter:
|
||||
// ------------------------------
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_OUTPUTTER_H
|
||||
@@ -0,0 +1,85 @@
|
||||
#ifndef CPPUNIT_PORTABILITY_H
|
||||
#define CPPUNIT_PORTABILITY_H
|
||||
|
||||
/* include platform specific config */
|
||||
#if defined(__BORLANDC__)
|
||||
# include <cppunit/config-bcb5.h>
|
||||
#elif defined (_MSC_VER)
|
||||
# include <cppunit/config-msvc6.h>
|
||||
#else
|
||||
# include <cppunit/config-auto.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Options that the library user may switch on or off.
|
||||
* If the user has not done so, we chose default values.
|
||||
*/
|
||||
|
||||
|
||||
/* Define to 1 if you wish to have the old-style macros
|
||||
assert(), assertEqual(), assertDoublesEqual(), and assertLongsEqual() */
|
||||
#ifndef CPPUNIT_ENABLE_NAKED_ASSERT
|
||||
#define CPPUNIT_ENABLE_NAKED_ASSERT 0
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you wish to have the old-style CU_TEST family
|
||||
of macros. */
|
||||
#ifndef CPPUNIT_ENABLE_CU_TEST_MACROS
|
||||
#define CPPUNIT_ENABLE_CU_TEST_MACROS 0
|
||||
#endif
|
||||
|
||||
/* Define to 1 if the preprocessor expands (#foo) to "foo" (quotes incl.)
|
||||
I don't think there is any C preprocess that does NOT support this! */
|
||||
#ifndef CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION
|
||||
#define CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION 1
|
||||
#endif
|
||||
|
||||
// CPPUNIT_API is defined in <config_msvc6.h> if required (building or using as dll)
|
||||
#ifndef CPPUNIT_API
|
||||
#define CPPUNIT_API
|
||||
#undef CPPUNIT_NEED_DLL_DECL
|
||||
#define CPPUNIT_NEED_DLL_DECL 0
|
||||
#endif
|
||||
|
||||
|
||||
/* perform portability hacks */
|
||||
|
||||
|
||||
/* Define CPPUNIT_SSTREAM as a stream with a "std::string str()"
|
||||
* method.
|
||||
*/
|
||||
#if CPPUNIT_HAVE_SSTREAM
|
||||
# include <sstream>
|
||||
namespace CppUnit {
|
||||
class OStringStream : public std::ostringstream
|
||||
{
|
||||
};
|
||||
}
|
||||
#else
|
||||
#if CPPUNIT_HAVE_CLASS_STRSTREAM
|
||||
# include <string>
|
||||
# if CPPUNIT_HAVE_STRSTREAM
|
||||
# include <strstream>
|
||||
# else
|
||||
# include <strstream.h>
|
||||
# endif
|
||||
|
||||
namespace CppUnit {
|
||||
class OStringStream : public std::ostrstream
|
||||
{
|
||||
public:
|
||||
std::string str()
|
||||
{
|
||||
(*this) << '\0';
|
||||
std::string msg(std::ostrstream::str());
|
||||
std::ostrstream::freeze(false);
|
||||
return msg;
|
||||
}
|
||||
};
|
||||
}
|
||||
#else
|
||||
# error Cannot define CppUnit::OStringStream.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // CPPUNIT_PORTABILITY_H
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef CPPUNIT_SOURCELINE_H
|
||||
#define CPPUNIT_SOURCELINE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
/*! \brief Constructs a SourceLine object initialized with the location where the macro is expanded.
|
||||
* \ingroup CreatingNewAssertions
|
||||
* \relates CppUnit::SourceLine
|
||||
* Used to write your own assertion macros.
|
||||
* \see Asserter for example of usage.
|
||||
*/
|
||||
#define CPPUNIT_SOURCELINE() ::CppUnit::SourceLine( __FILE__, __LINE__ )
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
/*! \brief Represents a source line location.
|
||||
* \ingroup CreatingNewAssertions
|
||||
* \ingroup BrowsingCollectedTestResult
|
||||
*
|
||||
* Used to capture the failure location in assertion.
|
||||
*
|
||||
* Use the CPPUNIT_SOURCELINE() macro to construct that object. Typically used when
|
||||
* writing an assertion macro in association with Asserter.
|
||||
*
|
||||
* \see Asserter.
|
||||
*/
|
||||
class CPPUNIT_API SourceLine
|
||||
{
|
||||
public:
|
||||
SourceLine();
|
||||
|
||||
SourceLine( const std::string &fileName,
|
||||
int lineNumber );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~SourceLine();
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
int lineNumber() const;
|
||||
|
||||
std::string fileName() const;
|
||||
|
||||
bool operator ==( const SourceLine &other ) const;
|
||||
bool operator !=( const SourceLine &other ) const;
|
||||
|
||||
private:
|
||||
std::string m_fileName;
|
||||
int m_lineNumber;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
|
||||
#endif // CPPUNIT_SOURCELINE_H
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef CPPUNIT_SYNCHRONIZEDOBJECT_H
|
||||
#define CPPUNIT_SYNCHRONIZEDOBJECT_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
/*! \brief Base class for synchronized object.
|
||||
*
|
||||
* Synchronized object are object which members are used concurrently by mutiple
|
||||
* threads.
|
||||
*
|
||||
* This class define the class SynchronizationObject which must be subclassed
|
||||
* to implement an actual lock.
|
||||
*
|
||||
* Each instance of this class holds a pointer on a lock object.
|
||||
*
|
||||
* See src/msvc6/MfcSynchronizedObject.h for an example.
|
||||
*/
|
||||
class CPPUNIT_API SynchronizedObject
|
||||
{
|
||||
public:
|
||||
/*! \brief Abstract synchronization object (mutex)
|
||||
*/
|
||||
class SynchronizationObject
|
||||
{
|
||||
public:
|
||||
SynchronizationObject() {}
|
||||
virtual ~SynchronizationObject() {}
|
||||
|
||||
virtual void lock() {}
|
||||
virtual void unlock() {}
|
||||
};
|
||||
|
||||
/*! Constructs a SynchronizedObject object.
|
||||
*/
|
||||
SynchronizedObject( SynchronizationObject *syncObject =0 );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~SynchronizedObject();
|
||||
|
||||
protected:
|
||||
/*! \brief Locks a synchronization object in the current scope.
|
||||
*/
|
||||
class ExclusiveZone
|
||||
{
|
||||
SynchronizationObject *m_syncObject;
|
||||
|
||||
public:
|
||||
ExclusiveZone( SynchronizationObject *syncObject )
|
||||
: m_syncObject( syncObject )
|
||||
{
|
||||
m_syncObject->lock();
|
||||
}
|
||||
|
||||
~ExclusiveZone()
|
||||
{
|
||||
m_syncObject->unlock ();
|
||||
}
|
||||
};
|
||||
|
||||
virtual void setSynchronizationObject( SynchronizationObject *syncObject );
|
||||
|
||||
protected:
|
||||
SynchronizationObject *m_syncObject;
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
SynchronizedObject( const SynchronizedObject © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const SynchronizedObject © );
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_SYNCHRONIZEDOBJECT_H
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef CPPUNIT_TEST_H
|
||||
#define CPPUNIT_TEST_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class TestResult;
|
||||
|
||||
/*! \brief Base class for all test objects.
|
||||
* \ingroup BrowsingCollectedTestResult
|
||||
*
|
||||
* All test objects should be a subclass of Test. Some test objects,
|
||||
* TestCase for example, represent one individual test. Other test
|
||||
* objects, such as TestSuite, are comprised of several tests.
|
||||
*
|
||||
* When a Test is run, the result is collected by a TestResult object.
|
||||
*
|
||||
* \see TestCase
|
||||
* \see TestSuite
|
||||
*/
|
||||
class CPPUNIT_API Test
|
||||
{
|
||||
public:
|
||||
virtual ~Test () {};
|
||||
|
||||
/*! \brief Run the test, collecting results.
|
||||
*/
|
||||
virtual void run (TestResult *result) = 0;
|
||||
|
||||
/*! \brief Return the number of test cases invoked by run().
|
||||
*
|
||||
* The base unit of testing is the class TestCase. This
|
||||
* method returns the number of TestCase objects invoked by
|
||||
* the run() method.
|
||||
*/
|
||||
virtual int countTestCases () const = 0;
|
||||
|
||||
/*! \brief Returns the test name.
|
||||
*
|
||||
* Each test has a name. This name may be used to find the
|
||||
* test in a suite or registry of tests.
|
||||
*/
|
||||
virtual std::string getName () const = 0;
|
||||
|
||||
/*! \brief Description of the test, for diagnostic output.
|
||||
*
|
||||
* The test description will typically include the test name,
|
||||
* but may have additional description. For example, a test
|
||||
* suite named <tt>complex_add</tt> may be described as
|
||||
* <tt>suite complex_add</tt>.
|
||||
*/
|
||||
virtual std::string toString () const = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TEST_H
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
#ifndef CPPUNIT_TESTASSERT_H
|
||||
#define CPPUNIT_TESTASSERT_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/Exception.h>
|
||||
#include <cppunit/Asserter.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*! \brief Traits used by CPPUNIT_ASSERT_EQUAL().
|
||||
*
|
||||
* Here is an example of specialization of that traits:
|
||||
*
|
||||
* \code
|
||||
* template<>
|
||||
* struct assertion_traits<std::string> // specialization for the std::string type
|
||||
* {
|
||||
* static bool equal( const std::string& x, const std::string& y )
|
||||
* {
|
||||
* return x == y;
|
||||
* }
|
||||
*
|
||||
* static std::string toString( const std::string& x )
|
||||
* {
|
||||
* std::string text = '"' + x + '"'; // adds quote around the string to see whitespace
|
||||
* OStringStream ost;
|
||||
* ost << text;
|
||||
* return ost.str();
|
||||
* }
|
||||
* };
|
||||
* \endcode
|
||||
*/
|
||||
template <class T>
|
||||
struct assertion_traits
|
||||
{
|
||||
static bool equal( const T& x, const T& y )
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
static std::string toString( const T& x )
|
||||
{
|
||||
OStringStream ost;
|
||||
ost << x;
|
||||
return ost.str();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace TestAssert
|
||||
{
|
||||
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
|
||||
void CPPUNIT_API assertImplementation( bool condition,
|
||||
std::string conditionExpression = "",
|
||||
long lineNumber,
|
||||
std::string fileName );
|
||||
|
||||
void CPPUNIT_API assertNotEqualImplementation( std::string expected,
|
||||
std::string actual,
|
||||
long lineNumber,
|
||||
std::string fileName );
|
||||
|
||||
|
||||
template <class T>
|
||||
void assertEquals( const T& expected,
|
||||
const T& actual,
|
||||
long lineNumber,
|
||||
std::string fileName )
|
||||
{
|
||||
if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
|
||||
{
|
||||
assertNotEqualImplementation( assertion_traits<T>::toString(expected),
|
||||
assertion_traits<T>::toString(actual),
|
||||
lineNumber,
|
||||
fileName );
|
||||
}
|
||||
}
|
||||
|
||||
void CPPUNIT_API assertEquals( double expected,
|
||||
double actual,
|
||||
double delta,
|
||||
long lineNumber,
|
||||
std::string fileName );
|
||||
|
||||
#else // using SourceLine
|
||||
|
||||
template <class T>
|
||||
void assertEquals( const T& expected,
|
||||
const T& actual,
|
||||
SourceLine sourceLine,
|
||||
const std::string &message ="" )
|
||||
{
|
||||
if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
|
||||
{
|
||||
Asserter::failNotEqual( assertion_traits<T>::toString(expected),
|
||||
assertion_traits<T>::toString(actual),
|
||||
sourceLine,
|
||||
message );
|
||||
}
|
||||
}
|
||||
|
||||
void CPPUNIT_API assertDoubleEquals( double expected,
|
||||
double actual,
|
||||
double delta,
|
||||
SourceLine sourceLine );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* A set of macros which allow us to get the line number
|
||||
* and file name at the point of an error.
|
||||
* Just goes to show that preprocessors do have some
|
||||
* redeeming qualities.
|
||||
*/
|
||||
#if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION
|
||||
/** Assertions that a condition is \c true.
|
||||
* \ingroup Assertions
|
||||
*/
|
||||
#define CPPUNIT_ASSERT(condition) \
|
||||
( ::CppUnit::Asserter::failIf( !(condition), \
|
||||
(#condition), \
|
||||
CPPUNIT_SOURCELINE() ) )
|
||||
#else
|
||||
#define CPPUNIT_ASSERT(condition) \
|
||||
( ::CppUnit::Asserter::failIf( !(condition), \
|
||||
"", \
|
||||
CPPUNIT_SOURCELINE() ) )
|
||||
#endif
|
||||
|
||||
/** Assertion with a user specified message.
|
||||
* \ingroup Assertions
|
||||
* \param message Message reported in diagnostic if \a condition evaluates
|
||||
* to \c false.
|
||||
* \param condition If this condition evaluates to \c false then the
|
||||
* test failed.
|
||||
*/
|
||||
#define CPPUNIT_ASSERT_MESSAGE(message,condition) \
|
||||
( ::CppUnit::Asserter::failIf( !(condition), \
|
||||
(message), \
|
||||
CPPUNIT_SOURCELINE() ) )
|
||||
|
||||
/** Fails with the specified message.
|
||||
* \ingroup Assertions
|
||||
* \param message Message reported in diagnostic.
|
||||
*/
|
||||
#define CPPUNIT_FAIL( message ) \
|
||||
( ::CppUnit::Asserter::fail( message, \
|
||||
CPPUNIT_SOURCELINE() ) )
|
||||
|
||||
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
|
||||
/// Generalized macro for primitive value comparisons
|
||||
#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
|
||||
( ::CppUnit::TestAssert::assertEquals( (expected), \
|
||||
(actual), \
|
||||
__LINE__, __FILE__ ) )
|
||||
#else
|
||||
/** Asserts that two values are equals.
|
||||
* \ingroup Assertions
|
||||
*
|
||||
* Equality and string representation can be defined with
|
||||
* an appropriate CppUnit::assertion_traits class.
|
||||
*
|
||||
* A diagnostic is printed if actual and expected values disagree.
|
||||
*
|
||||
* Requirement for \a expected and \a actual parameters:
|
||||
* - They are exactly of the same type
|
||||
* - They are serializable into a std::strstream using operator <<.
|
||||
* - They can be compared using operator ==.
|
||||
*
|
||||
* The last two requirements (serialization and comparison) can be
|
||||
* removed by specializing the CppUnit::assertion_traits.
|
||||
*/
|
||||
#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
|
||||
( ::CppUnit::TestAssert::assertEquals( (expected), \
|
||||
(actual), \
|
||||
CPPUNIT_SOURCELINE() ) )
|
||||
|
||||
/** Asserts that two values are equals, provides additional messafe on failure.
|
||||
* \ingroup Assertions
|
||||
*
|
||||
* Equality and string representation can be defined with
|
||||
* an appropriate assertion_traits class.
|
||||
*
|
||||
* A diagnostic is printed if actual and expected values disagree.
|
||||
* The message is printed in addition to the expected and actual value
|
||||
* to provide additional information.
|
||||
*
|
||||
* Requirement for \a expected and \a actual parameters:
|
||||
* - They are exactly of the same type
|
||||
* - They are serializable into a std::strstream using operator <<.
|
||||
* - They can be compared using operator ==.
|
||||
*
|
||||
* The last two requirements (serialization and comparison) can be
|
||||
* removed by specializing the CppUnit::assertion_traits.
|
||||
*/
|
||||
#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \
|
||||
( ::CppUnit::TestAssert::assertEquals( (expected), \
|
||||
(actual), \
|
||||
CPPUNIT_SOURCELINE(), \
|
||||
(message) ) )
|
||||
#endif
|
||||
|
||||
/*! \brief Macro for primitive value comparisons
|
||||
* \ingroup Assertions
|
||||
*/
|
||||
#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \
|
||||
( ::CppUnit::TestAssert::assertDoubleEquals( (expected), \
|
||||
(actual), \
|
||||
(delta), \
|
||||
CPPUNIT_SOURCELINE() ) )
|
||||
|
||||
// Backwards compatibility
|
||||
|
||||
#if CPPUNIT_ENABLE_NAKED_ASSERT
|
||||
|
||||
#undef assert
|
||||
#define assert(c) CPPUNIT_ASSERT(c)
|
||||
#define assertEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a)
|
||||
#define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d)
|
||||
#define assertLongsEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TESTASSERT_H
|
||||
@@ -0,0 +1,204 @@
|
||||
#ifndef CPPUNIT_TESTCALLER_H // -*- C++ -*-
|
||||
#define CPPUNIT_TESTCALLER_H
|
||||
|
||||
#include <cppunit/Exception.h>
|
||||
#include <cppunit/TestCase.h>
|
||||
|
||||
|
||||
#if CPPUNIT_USE_TYPEINFO_NAME
|
||||
# include <cppunit/extensions/TypeInfoHelper.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*! \brief Marker class indicating that no exception is expected by TestCaller.
|
||||
* This class is an implementation detail. You should never use this class directly.
|
||||
*/
|
||||
class CPPUNIT_API NoExceptionExpected
|
||||
{
|
||||
private:
|
||||
//! Prevent class instantiation.
|
||||
NoExceptionExpected();
|
||||
};
|
||||
|
||||
|
||||
/*! \brief (Implementation) Traits used by TestCaller to expect an exception.
|
||||
*
|
||||
* This class is an implementation detail. You should never use this class directly.
|
||||
*/
|
||||
template<typename ExceptionType>
|
||||
struct ExpectedExceptionTraits
|
||||
{
|
||||
static void expectedException()
|
||||
{
|
||||
#if CPPUNIT_USE_TYPEINFO_NAME
|
||||
std::string message( "Expected exception of type " );
|
||||
message += TypeInfoHelper::getClassName( typeid( ExceptionType ) );
|
||||
message += ", but got none";
|
||||
#else
|
||||
std::string message( "Expected exception but got none" );
|
||||
#endif
|
||||
throw Exception( message );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*! \brief (Implementation) Traits specialization used by TestCaller to
|
||||
* expect no exception.
|
||||
*
|
||||
* This class is an implementation detail. You should never use this class directly.
|
||||
*/
|
||||
template<>
|
||||
struct ExpectedExceptionTraits<NoExceptionExpected>
|
||||
{
|
||||
static void expectedException()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//*** FIXME: rework this when class Fixture is implemented. ***//
|
||||
|
||||
|
||||
/*! \brief Generate a test case from a fixture method.
|
||||
* \ingroup WritingTestFixture
|
||||
*
|
||||
* A test caller provides access to a test case method
|
||||
* on a test fixture class. Test callers are useful when
|
||||
* you want to run an individual test or add it to a
|
||||
* suite.
|
||||
* Test Callers invoke only one Test (i.e. test method) on one
|
||||
* Fixture of a TestFixture.
|
||||
*
|
||||
* Here is an example:
|
||||
* \code
|
||||
* class MathTest : public CppUnit::TestFixture {
|
||||
* ...
|
||||
* public:
|
||||
* void setUp();
|
||||
* void tearDown();
|
||||
*
|
||||
* void testAdd();
|
||||
* void testSubtract();
|
||||
* };
|
||||
*
|
||||
* CppUnit::Test *MathTest::suite() {
|
||||
* CppUnit::TestSuite *suite = new CppUnit::TestSuite;
|
||||
*
|
||||
* suite->addTest( new CppUnit::TestCaller<MathTest>( "testAdd", testAdd ) );
|
||||
* return suite;
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* You can use a TestCaller to bind any test method on a TestFixture
|
||||
* class, as long as it accepts void and returns void.
|
||||
*
|
||||
* \see TestCase
|
||||
*/
|
||||
|
||||
template <typename Fixture,
|
||||
typename ExpectedException = NoExceptionExpected>
|
||||
class TestCaller : public TestCase
|
||||
{
|
||||
typedef void (Fixture::*TestMethod)();
|
||||
|
||||
public:
|
||||
/*!
|
||||
* Constructor for TestCaller. This constructor builds a new Fixture
|
||||
* instance owned by the TestCaller.
|
||||
* \param name name of this TestCaller
|
||||
* \param test the method this TestCaller calls in runTest()
|
||||
*/
|
||||
TestCaller( std::string name, TestMethod test ) :
|
||||
TestCase( name ),
|
||||
m_ownFixture( true ),
|
||||
m_fixture( new Fixture() ),
|
||||
m_test( test )
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Constructor for TestCaller.
|
||||
* This constructor does not create a new Fixture instance but accepts
|
||||
* an existing one as parameter. The TestCaller will not own the
|
||||
* Fixture object.
|
||||
* \param name name of this TestCaller
|
||||
* \param test the method this TestCaller calls in runTest()
|
||||
* \param fixture the Fixture to invoke the test method on.
|
||||
*/
|
||||
TestCaller(std::string name, TestMethod test, Fixture& fixture) :
|
||||
TestCase( name ),
|
||||
m_ownFixture( false ),
|
||||
m_fixture( &fixture ),
|
||||
m_test( test )
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Constructor for TestCaller.
|
||||
* This constructor does not create a new Fixture instance but accepts
|
||||
* an existing one as parameter. The TestCaller will own the
|
||||
* Fixture object and delete it in its destructor.
|
||||
* \param name name of this TestCaller
|
||||
* \param test the method this TestCaller calls in runTest()
|
||||
* \param fixture the Fixture to invoke the test method on.
|
||||
*/
|
||||
TestCaller(std::string name, TestMethod test, Fixture* fixture) :
|
||||
TestCase( name ),
|
||||
m_ownFixture( true ),
|
||||
m_fixture( fixture ),
|
||||
m_test( test )
|
||||
{
|
||||
}
|
||||
|
||||
~TestCaller()
|
||||
{
|
||||
if (m_ownFixture)
|
||||
delete m_fixture;
|
||||
}
|
||||
|
||||
protected:
|
||||
void runTest()
|
||||
{
|
||||
try {
|
||||
(m_fixture->*m_test)();
|
||||
}
|
||||
catch ( ExpectedException & ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ExpectedExceptionTraits<ExpectedException>::expectedException();
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
m_fixture->setUp ();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
m_fixture->tearDown ();
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return "TestCaller " + getName();
|
||||
}
|
||||
|
||||
private:
|
||||
TestCaller( const TestCaller &other );
|
||||
TestCaller &operator =( const TestCaller &other );
|
||||
|
||||
private:
|
||||
bool m_ownFixture;
|
||||
Fixture *m_fixture;
|
||||
TestMethod m_test;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TESTCALLER_H
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef CPPUNIT_TESTCASE_H
|
||||
#define CPPUNIT_TESTCASE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/Test.h>
|
||||
#include <cppunit/TestAssert.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*! \brief A single test object.
|
||||
*
|
||||
* This class is used to implement a simple test case: define a subclass
|
||||
* that overrides the runTest method.
|
||||
*
|
||||
* You don't usually need to use that class, but TestFixture and TestCaller instead.
|
||||
*
|
||||
* You are expected to subclass TestCase is you need to write a class similiar
|
||||
* to TestCaller.
|
||||
*/
|
||||
class CPPUNIT_API TestCase : public Test,
|
||||
public TestFixture
|
||||
{
|
||||
public:
|
||||
|
||||
TestCase( std::string Name );
|
||||
//! \internal
|
||||
TestCase();
|
||||
~TestCase();
|
||||
|
||||
virtual void run(TestResult *result);
|
||||
virtual int countTestCases() const;
|
||||
std::string getName() const;
|
||||
std::string toString() const;
|
||||
|
||||
//! FIXME: what is this for?
|
||||
virtual TestResult *run();
|
||||
|
||||
protected:
|
||||
//! FIXME: this should probably be pure virtual.
|
||||
virtual void runTest();
|
||||
|
||||
//! Create TestResult for the run(void) method.
|
||||
TestResult *defaultResult();
|
||||
|
||||
private:
|
||||
TestCase( const TestCase &other );
|
||||
TestCase &operator=( const TestCase &other );
|
||||
|
||||
private:
|
||||
const std::string m_name;
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TESTCASE_H
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef CPPUNIT_TESTFAILURE_H // -*- C++ -*-
|
||||
#define CPPUNIT_TESTFAILURE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Exception;
|
||||
class SourceLine;
|
||||
class Test;
|
||||
|
||||
|
||||
/*! \brief Record of a failed Test execution.
|
||||
* \ingroup BrowsingCollectedTestResult
|
||||
*
|
||||
* A TestFailure collects a failed test together with
|
||||
* the caught exception.
|
||||
*
|
||||
* TestFailure assumes lifetime control for any exception
|
||||
* passed to it.
|
||||
*/
|
||||
class CPPUNIT_API TestFailure
|
||||
{
|
||||
public:
|
||||
TestFailure( Test *failedTest,
|
||||
Exception *thrownException,
|
||||
bool isError );
|
||||
|
||||
virtual ~TestFailure ();
|
||||
|
||||
virtual Test *failedTest() const;
|
||||
|
||||
virtual Exception *thrownException() const;
|
||||
|
||||
virtual SourceLine sourceLine() const;
|
||||
|
||||
virtual bool isError() const;
|
||||
|
||||
virtual std::string failedTestName() const;
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
virtual TestFailure *clone() const;
|
||||
|
||||
protected:
|
||||
Test *m_failedTest;
|
||||
Exception *m_thrownException;
|
||||
bool m_isError;
|
||||
|
||||
private:
|
||||
TestFailure( const TestFailure &other );
|
||||
TestFailure &operator =( const TestFailure& other );
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TESTFAILURE_H
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef CPPUNIT_TESTFIXTURE_H // -*- C++ -*-
|
||||
#define CPPUNIT_TESTFIXTURE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
/*! \brief Wraps a test case with setUp and tearDown methods.
|
||||
* \ingroup WritingTestFixture
|
||||
*
|
||||
* A TestFixture is used to provide a common environment for a set
|
||||
* of test cases.
|
||||
*
|
||||
* To define a test fixture, do the following:
|
||||
* - implement a subclass of TestCase
|
||||
* - the fixture is defined by instance variables
|
||||
* - initialize the fixture state by overriding setUp
|
||||
* (i.e. construct the instance variables of the fixture)
|
||||
* - clean-up after a test by overriding tearDown.
|
||||
*
|
||||
* Each test runs in its own fixture so there
|
||||
* can be no side effects among test runs.
|
||||
* Here is an example:
|
||||
*
|
||||
* \code
|
||||
* class MathTest : public CppUnit::TestFixture {
|
||||
* protected:
|
||||
* int m_value1, m_value2;
|
||||
*
|
||||
* public:
|
||||
* MathTest() {}
|
||||
*
|
||||
* void setUp () {
|
||||
* m_value1 = 2;
|
||||
* m_value2 = 3;
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* For each test implement a method which interacts
|
||||
* with the fixture. Verify the expected results with assertions specified
|
||||
* by calling CPPUNIT_ASSERT on the expression you want to test:
|
||||
*
|
||||
* \code
|
||||
* public:
|
||||
* void testAdd () {
|
||||
* int result = m_value1 + m_value2;
|
||||
* CPPUNIT_ASSERT( result == 5 );
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* Once the methods are defined you can run them. To do this, use
|
||||
* a TestCaller.
|
||||
*
|
||||
* \code
|
||||
* CppUnit::Test *test = new CppUnit::TestCaller<MathTest>( "testAdd",
|
||||
* &MathTest::testAdd );
|
||||
* test->run();
|
||||
* \endcode
|
||||
*
|
||||
*
|
||||
* The tests to be run can be collected into a TestSuite.
|
||||
*
|
||||
* \code
|
||||
* public:
|
||||
* static CppUnit::TestSuite *MathTest::suite () {
|
||||
* CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite;
|
||||
* suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>(
|
||||
* "testAdd", &MathTest::testAdd));
|
||||
* suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>(
|
||||
* "testDivideByZero", &MathTest::testDivideByZero));
|
||||
* return suiteOfTests;
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* A set of macros have been created for convenience. They are located in HelperMacros.h.
|
||||
*
|
||||
* \see TestResult, TestSuite, TestCaller,
|
||||
* \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
|
||||
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
|
||||
*/
|
||||
class CPPUNIT_API TestFixture
|
||||
{
|
||||
public:
|
||||
virtual ~TestFixture() {};
|
||||
|
||||
//! \brief Set up context before running a test.
|
||||
virtual void setUp() {};
|
||||
|
||||
//! Clean up after the test run.
|
||||
virtual void tearDown() {};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef CPPUNIT_TESTLISTENER_H // -*- C++ -*-
|
||||
#define CPPUNIT_TESTLISTENER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Exception;
|
||||
class Test;
|
||||
class TestFailure;
|
||||
|
||||
|
||||
/*! \brief Listener for test progress and result.
|
||||
* \ingroup TrackingTestExecution
|
||||
*
|
||||
* Implementing the Observer pattern a TestListener may be registered
|
||||
* to a TestResult to obtain information on the testing progress. Use
|
||||
* specialized sub classes of TestListener for text output
|
||||
* (TextTestProgressListener). Do not use the Listener for the test
|
||||
* result output, use a subclass of Outputter instead.
|
||||
*
|
||||
* The test framework distinguishes between failures and errors.
|
||||
* A failure is anticipated and checked for with assertions. Errors are
|
||||
* unanticipated problems signified by exceptions that are not generated
|
||||
* by the framework.
|
||||
*
|
||||
* \see TestResult
|
||||
*/
|
||||
class CPPUNIT_API TestListener
|
||||
{
|
||||
public:
|
||||
virtual ~TestListener() {}
|
||||
|
||||
/// Called when just before a TestCase is run.
|
||||
virtual void startTest( Test *test ) {}
|
||||
|
||||
/*! Called when a failure occurs while running a test.
|
||||
* \see TestFailure.
|
||||
* \warning \a failure is a temporary object that is destroyed after the
|
||||
* method call. Use TestFailure::clone() to create a duplicate.
|
||||
*/
|
||||
virtual void addFailure( const TestFailure &failure ) {}
|
||||
|
||||
/// Called just after a TestCase was run (even if a failure occured).
|
||||
virtual void endTest( Test *test ) {}
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TESTLISTENER_H
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef CPPUNIT_TESTRESULT_H
|
||||
#define CPPUNIT_TESTRESULT_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
|
||||
#endif
|
||||
|
||||
#include <cppunit/SynchronizedObject.h>
|
||||
#include <deque>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Exception;
|
||||
class Test;
|
||||
class TestFailure;
|
||||
class TestListener;
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
template class CPPUNIT_API std::deque<TestListener *>;
|
||||
#endif
|
||||
|
||||
/*! \brief Manages TestListener.
|
||||
* \ingroup TrackingTestExecution
|
||||
*
|
||||
* A single instance of this class is used when running the test. It is usually
|
||||
* created by the test runner (TestRunner).
|
||||
*
|
||||
* This class shouldn't have to be inherited from. Use a TestListener
|
||||
* or one of its subclasses to be informed of the ongoing tests.
|
||||
* Use a Outputter to receive a test summary once it has finished
|
||||
*
|
||||
* TestResult supplies a template method 'setSynchronizationObject()'
|
||||
* so that subclasses can provide mutual exclusion in the face of multiple
|
||||
* threads. This can be useful when tests execute in one thread and
|
||||
* they fill a subclass of TestResult which effects change in another
|
||||
* thread. To have mutual exclusion, override setSynchronizationObject()
|
||||
* and make sure that you create an instance of ExclusiveZone at the
|
||||
* beginning of each method.
|
||||
*
|
||||
* \see Test, TestListener, TestResultCollector, Outputter.
|
||||
*/
|
||||
class CPPUNIT_API TestResult : protected SynchronizedObject
|
||||
{
|
||||
public:
|
||||
TestResult( SynchronizationObject *syncObject = 0 );
|
||||
virtual ~TestResult();
|
||||
|
||||
virtual void addListener( TestListener *listener );
|
||||
virtual void removeListener( TestListener *listener );
|
||||
|
||||
virtual void reset();
|
||||
virtual void stop();
|
||||
|
||||
virtual bool shouldStop() const;
|
||||
|
||||
virtual void startTest( Test *test );
|
||||
virtual void addError( Test *test, Exception *e );
|
||||
virtual void addFailure( Test *test, Exception *e );
|
||||
virtual void endTest( Test *test );
|
||||
|
||||
protected:
|
||||
void addFailure( const TestFailure &failure );
|
||||
|
||||
protected:
|
||||
typedef std::deque<TestListener *> TestListeners;
|
||||
TestListeners m_listeners;
|
||||
bool m_stop;
|
||||
|
||||
private:
|
||||
TestResult( const TestResult &other );
|
||||
TestResult &operator =( const TestResult &other );
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
#endif // CPPUNIT_TESTRESULT_H
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef CPPUNIT_TESTRESULTCOLLECTOR_H
|
||||
#define CPPUNIT_TESTRESULTCOLLECTOR_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
|
||||
#endif
|
||||
|
||||
#include <cppunit/TestSucessListener.h>
|
||||
#include <deque>
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
template class CPPUNIT_API std::deque<TestFailure *>;
|
||||
template class CPPUNIT_API std::deque<Test *>;
|
||||
#endif
|
||||
|
||||
|
||||
/*! \brief Collects test result.
|
||||
* \ingroup WritingTestResult
|
||||
* \ingroup BrowsingCollectedTestResult
|
||||
*
|
||||
* A TestResultCollector is a TestListener which collects the results of executing
|
||||
* a test case. It is an instance of the Collecting Parameter pattern.
|
||||
*
|
||||
* The test framework distinguishes between failures and errors.
|
||||
* A failure is anticipated and checked for with assertions. Errors are
|
||||
* unanticipated problems signified by exceptions that are not generated
|
||||
* by the framework.
|
||||
* \see TestListener, TestFailure.
|
||||
*/
|
||||
class CPPUNIT_API TestResultCollector : public TestSucessListener
|
||||
{
|
||||
public:
|
||||
typedef std::deque<TestFailure *> TestFailures;
|
||||
typedef std::deque<Test *> Tests;
|
||||
|
||||
|
||||
/*! Constructs a TestResultCollector object.
|
||||
*/
|
||||
TestResultCollector( SynchronizationObject *syncObject = 0 );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TestResultCollector();
|
||||
|
||||
void startTest( Test *test );
|
||||
void addFailure( const TestFailure &failure );
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual int runTests() const;
|
||||
virtual int testErrors() const;
|
||||
virtual int testFailures() const;
|
||||
virtual int testFailuresTotal() const;
|
||||
|
||||
virtual const TestFailures& failures() const;
|
||||
virtual const Tests &tests() const;
|
||||
|
||||
protected:
|
||||
Tests m_tests;
|
||||
TestFailures m_failures;
|
||||
int m_testErrors;
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
TestResultCollector( const TestResultCollector © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const TestResultCollector © );
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CPPUNIT_TESTRESULTCOLLECTOR_H
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef CPPUNIT_TESTSUCESSLISTENER_H
|
||||
#define CPPUNIT_TESTSUCESSLISTENER_H
|
||||
|
||||
#include <cppunit/SynchronizedObject.h>
|
||||
#include <cppunit/TestListener.h>
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
/*! \brief TestListener that checks if any test case failed.
|
||||
* \ingroup TrackingTestExecution
|
||||
*/
|
||||
class CPPUNIT_API TestSucessListener : public TestListener,
|
||||
public SynchronizedObject
|
||||
{
|
||||
public:
|
||||
/*! Constructs a TestSucessListener object.
|
||||
*/
|
||||
TestSucessListener( SynchronizationObject *syncObject = 0 );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TestSucessListener();
|
||||
|
||||
virtual void reset();
|
||||
|
||||
void addFailure( const TestFailure &failure );
|
||||
|
||||
/// Returns whether the entire test was successful or not.
|
||||
virtual bool wasSuccessful() const;
|
||||
|
||||
private:
|
||||
bool m_sucess;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_TESTSUCESSLISTENER_H
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef CPPUNIT_TESTSUITE_H // -*- C++ -*-
|
||||
#define CPPUNIT_TESTSUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
|
||||
#endif
|
||||
|
||||
#include <cppunit/Test.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class TestResult;
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
template class CPPUNIT_API std::vector<Test *>;
|
||||
#endif
|
||||
|
||||
|
||||
/*! \brief A Composite of Tests.
|
||||
* \ingroup CreatingTestSuite
|
||||
*
|
||||
* It runs a collection of test cases. Here is an example.
|
||||
* \code
|
||||
* CppUnit::TestSuite *suite= new CppUnit::TestSuite();
|
||||
* suite->addTest(new CppUnit::TestCaller<MathTest> (
|
||||
* "testAdd", testAdd));
|
||||
* suite->addTest(new CppUnit::TestCaller<MathTest> (
|
||||
* "testDivideByZero", testDivideByZero));
|
||||
* \endcode
|
||||
* Note that TestSuites assume lifetime
|
||||
* control for any tests added to them.
|
||||
*
|
||||
* TestSuites do not register themselves in the TestRegistry.
|
||||
* \see Test
|
||||
* \see TestCaller
|
||||
*/
|
||||
|
||||
|
||||
class CPPUNIT_API TestSuite : public Test
|
||||
{
|
||||
public:
|
||||
TestSuite( std::string name = "" );
|
||||
~TestSuite();
|
||||
|
||||
void run( TestResult *result );
|
||||
int countTestCases() const;
|
||||
std::string getName() const;
|
||||
std::string toString() const;
|
||||
|
||||
void addTest( Test *test );
|
||||
const std::vector<Test *> &getTests() const;
|
||||
|
||||
virtual void deleteContents();
|
||||
|
||||
private:
|
||||
TestSuite( const TestSuite &other );
|
||||
TestSuite &operator =( const TestSuite &other );
|
||||
|
||||
private:
|
||||
std::vector<Test *> m_tests;
|
||||
const std::string m_name;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
#endif // CPPUNIT_TESTSUITE_H
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef CPPUNIT_TEXTOUTPUTTER_H
|
||||
#define CPPUNIT_TEXTOUTPUTTER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/Outputter.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
class Exception;
|
||||
class SourceLine;
|
||||
class TestResultCollector;
|
||||
class TestFailure;
|
||||
|
||||
|
||||
/*! \brief Prints a TestResultCollector to a text stream.
|
||||
* \ingroup WritingTestResult
|
||||
*/
|
||||
class CPPUNIT_API TextOutputter : public Outputter
|
||||
{
|
||||
public:
|
||||
TextOutputter( TestResultCollector *result,
|
||||
std::ostream &stream );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TextOutputter();
|
||||
|
||||
void write();
|
||||
virtual void printFailures();
|
||||
virtual void printHeader();
|
||||
|
||||
virtual void printFailure( TestFailure *failure,
|
||||
int failureNumber );
|
||||
virtual void printFailureListMark( int failureNumber );
|
||||
virtual void printFailureTestName( TestFailure *failure );
|
||||
virtual void printFailureType( TestFailure *failure );
|
||||
virtual void printFailureLocation( SourceLine sourceLine );
|
||||
virtual void printFailureDetail( Exception *thrownException );
|
||||
virtual void printFailureWarning();
|
||||
virtual void printStatistics();
|
||||
|
||||
protected:
|
||||
TestResultCollector *m_result;
|
||||
std::ostream &m_stream;
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
TextOutputter( const TextOutputter © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const TextOutputter © );
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_TEXTOUTPUTTER_H
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef CPPUNIT_TEXTTESTPROGRESSLISTENER_H
|
||||
#define CPPUNIT_TEXTTESTPROGRESSLISTENER_H
|
||||
|
||||
#include <cppunit/TestListener.h>
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief TestListener that show the status of each TestCase test result.
|
||||
* \ingroup TrackingTestExecution
|
||||
*/
|
||||
class CPPUNIT_API TextTestProgressListener : public TestListener
|
||||
{
|
||||
public:
|
||||
/*! Constructs a TextTestProgressListener object.
|
||||
*/
|
||||
TextTestProgressListener();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TextTestProgressListener();
|
||||
|
||||
void startTest( Test *test );
|
||||
void addFailure( const TestFailure &failure );
|
||||
|
||||
void done();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
TextTestProgressListener( const TextTestProgressListener © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const TextTestProgressListener © );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_TEXTTESTPROGRESSLISTENER_H
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef CPPUNIT_TEXTTESTRESULT_H
|
||||
#define CPPUNIT_TEXTTESTRESULT_H
|
||||
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class SourceLine;
|
||||
class Exception;
|
||||
class Test;
|
||||
|
||||
/*! \brief Holds printable test result (DEPRECATED).
|
||||
* \ingroup TrackingTestExecution
|
||||
*
|
||||
* deprecated Use class TextTestProgressListener and TextOutputter instead.
|
||||
*/
|
||||
class CPPUNIT_API TextTestResult : public TestResult,
|
||||
public TestResultCollector
|
||||
{
|
||||
public:
|
||||
TextTestResult();
|
||||
|
||||
virtual void addFailure( const TestFailure &failure );
|
||||
virtual void startTest( Test *test );
|
||||
virtual void print( std::ostream &stream );
|
||||
virtual void printFailures( std::ostream &stream );
|
||||
virtual void printHeader( std::ostream &stream );
|
||||
|
||||
virtual void printFailure( TestFailure *failure,
|
||||
int failureNumber,
|
||||
std::ostream &stream );
|
||||
virtual void printFailureListMark( int failureNumber,
|
||||
std::ostream &stream );
|
||||
virtual void printFailureTestName( TestFailure *failure,
|
||||
std::ostream &stream );
|
||||
virtual void printFailureType( TestFailure *failure,
|
||||
std::ostream &stream );
|
||||
virtual void printFailureLocation( SourceLine sourceLine,
|
||||
std::ostream &stream );
|
||||
virtual void printFailureDetail( Exception *thrownException,
|
||||
std::ostream &stream );
|
||||
virtual void printFailureWarning( std::ostream &stream );
|
||||
virtual void printStatistics( std::ostream &stream );
|
||||
};
|
||||
|
||||
/** insertion operator for easy output */
|
||||
std::ostream &operator <<( std::ostream &stream,
|
||||
TextTestResult &result );
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TEXTTESTRESULT_H
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef CPPUNIT_TEXTTESTRUNNER_H
|
||||
#define CPPUNIT_TEXTTESTRUNNER_H
|
||||
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*!
|
||||
* \brief A text mode test runner.
|
||||
* \ingroup ExecutingTest
|
||||
* \deprecated Use CppUnit::TextUi::TestRunner instead.
|
||||
*/
|
||||
typedef CppUnit::TextUi::TestRunner TextTestRunner;
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_TEXTTESTRUNNER_H
|
||||
@@ -0,0 +1,136 @@
|
||||
#ifndef CPPUNIT_XMLTESTRESULTOUTPUTTER_H
|
||||
#define CPPUNIT_XMLTESTRESULTOUTPUTTER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
|
||||
#endif
|
||||
|
||||
#include <cppunit/Outputter.h>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
|
||||
class Test;
|
||||
class TestFailure;
|
||||
class TestResultCollector;
|
||||
|
||||
|
||||
/*! \brief Outputs a TestResultCollector in XML format.
|
||||
* \ingroup WritingTestResult
|
||||
*/
|
||||
class CPPUNIT_API XmlOutputter : public Outputter
|
||||
{
|
||||
public:
|
||||
/*! Constructs a XmlOutputter object.
|
||||
* \param result Result of the test run.
|
||||
* \param stream Stream used to output the XML output.
|
||||
* \param encoding Encoding used in the XML file (default is Latin-1).
|
||||
*/
|
||||
XmlOutputter( TestResultCollector *result,
|
||||
std::ostream &stream,
|
||||
std::string encoding = "ISO-8859-1" );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~XmlOutputter();
|
||||
|
||||
/*! Writes the specified result as an XML document to the stream.
|
||||
*
|
||||
* Refer to examples/cppunittest/XmlOutputterTest.cpp for example
|
||||
* of use and XML document structure.
|
||||
*/
|
||||
virtual void write();
|
||||
|
||||
/*! \brief An XML Element.
|
||||
* \warning This class will probably be replaced with an abstract
|
||||
* builder in future version.
|
||||
*/
|
||||
class CPPUNIT_API Node
|
||||
{
|
||||
public:
|
||||
Node( std::string elementName,
|
||||
std::string content ="" );
|
||||
Node( std::string elementName,
|
||||
int numericContent );
|
||||
virtual ~Node();
|
||||
|
||||
void addAttribute( std::string attributeName,
|
||||
std::string value );
|
||||
void addAttribute( std::string attributeName,
|
||||
int numericValue );
|
||||
void addNode( Node *node );
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
typedef std::pair<std::string,std::string> Attribute;
|
||||
|
||||
std::string attributesAsString() const;
|
||||
std::string escape( std::string value ) const;
|
||||
static std::string asString( int value );
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_content;
|
||||
typedef std::deque<Attribute> Attributes;
|
||||
Attributes m_attributes;
|
||||
typedef std::deque<Node *> Nodes;
|
||||
Nodes m_nodes;
|
||||
};
|
||||
|
||||
|
||||
virtual void writeProlog();
|
||||
virtual void writeTestsResult();
|
||||
|
||||
typedef std::map<Test *,TestFailure*> FailedTests;
|
||||
virtual Node *makeRootNode();
|
||||
virtual void addFailedTests( FailedTests &failedTests,
|
||||
Node *rootNode );
|
||||
virtual void addSucessfulTests( FailedTests &failedTests,
|
||||
Node *rootNode );
|
||||
virtual void addStatistics( Node *rootNode );
|
||||
virtual void addFailedTest( Test *test,
|
||||
TestFailure *failure,
|
||||
int testNumber,
|
||||
Node *testsNode );
|
||||
virtual void addFailureLocation( TestFailure *failure,
|
||||
Node *testNode );
|
||||
virtual void addSucessfulTest( Test *test,
|
||||
int testNumber,
|
||||
Node *testsNode );
|
||||
protected:
|
||||
virtual void fillFailedTestsMap( FailedTests &failedTests );
|
||||
|
||||
protected:
|
||||
TestResultCollector *m_result;
|
||||
std::ostream &m_stream;
|
||||
std::string m_encoding;
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
XmlOutputter( const XmlOutputter © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const XmlOutputter © );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
#endif // CPPUNIT_XMLTESTRESULTOUTPUTTER_H
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef _INCLUDE_CPPUNIT_CONFIG_AUTO_H
|
||||
#define _INCLUDE_CPPUNIT_CONFIG_AUTO_H 1
|
||||
|
||||
/* include/cppunit/config-auto.h. Generated automatically at end of configure. */
|
||||
/* config/config.h. Generated automatically by configure. */
|
||||
/* config/config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* define if library uses std::string::compare(string,pos,n) */
|
||||
#ifndef CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST
|
||||
#define CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST 1
|
||||
#endif
|
||||
|
||||
/* define if the library defines strstream */
|
||||
#ifndef CPPUNIT_HAVE_CLASS_STRSTREAM
|
||||
#define CPPUNIT_HAVE_CLASS_STRSTREAM 1
|
||||
#endif
|
||||
|
||||
/* Define if you have the <cmath> header file. */
|
||||
#ifndef CPPUNIT_HAVE_CMATH
|
||||
#define CPPUNIT_HAVE_CMATH 1
|
||||
#endif
|
||||
|
||||
/* Define if you have the <dlfcn.h> header file. */
|
||||
/* #undef CPPUNIT_HAVE_DLFCN_H */
|
||||
|
||||
/* define to 1 if the compiler implements namespaces */
|
||||
#ifndef CPPUNIT_HAVE_NAMESPACES
|
||||
#define CPPUNIT_HAVE_NAMESPACES 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports Run-Time Type Identification */
|
||||
#ifndef CPPUNIT_HAVE_RTTI
|
||||
#define CPPUNIT_HAVE_RTTI 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler has stringstream */
|
||||
/* #undef CPPUNIT_HAVE_SSTREAM */
|
||||
|
||||
/* Define if you have the <strstream> header file. */
|
||||
#ifndef CPPUNIT_HAVE_STRSTREAM
|
||||
#define CPPUNIT_HAVE_STRSTREAM 1
|
||||
#endif
|
||||
|
||||
/* Name of package */
|
||||
#ifndef CPPUNIT_PACKAGE
|
||||
#define CPPUNIT_PACKAGE "cppunit"
|
||||
#endif
|
||||
|
||||
/* Define to 1 to use type_info::name() for class names */
|
||||
#ifndef CPPUNIT_USE_TYPEINFO_NAME
|
||||
#define CPPUNIT_USE_TYPEINFO_NAME CPPUNIT_HAVE_RTTI
|
||||
#endif
|
||||
|
||||
/* Version number of package */
|
||||
#ifndef CPPUNIT_VERSION
|
||||
#define CPPUNIT_VERSION "1.8.0"
|
||||
#endif
|
||||
|
||||
/* _INCLUDE_CPPUNIT_CONFIG_AUTO_H */
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
|
||||
#define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
|
||||
|
||||
#include <string>
|
||||
#include <cppunit/extensions/TestSuiteFactory.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/** Automatically register the test suite of the specified type.
|
||||
*
|
||||
* You should not use this class directly. Instead, use the following macros:
|
||||
* - CPPUNIT_TEST_SUITE_REGISTRATION()
|
||||
* - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION()
|
||||
*
|
||||
* This object will register the test returned by TestCaseType::suite()
|
||||
* when constructed to the test registry.
|
||||
*
|
||||
* This object is intented to be used as a static variable.
|
||||
*
|
||||
*
|
||||
* \param TestCaseType Type of the test case which suite is registered.
|
||||
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
|
||||
* \see CppUnit::TestFactoryRegistry.
|
||||
*/
|
||||
template<typename TestCaseType>
|
||||
class AutoRegisterSuite
|
||||
{
|
||||
public:
|
||||
/** Auto-register the suite factory in the global registry.
|
||||
*/
|
||||
AutoRegisterSuite()
|
||||
{
|
||||
TestFactory *factory = new TestSuiteFactory<TestCaseType>();
|
||||
TestFactoryRegistry::getRegistry().registerFactory( factory );
|
||||
}
|
||||
|
||||
/** Auto-register the suite factory in the specified registry.
|
||||
* \param name Name of the registry.
|
||||
*/
|
||||
AutoRegisterSuite( const std::string &name )
|
||||
{
|
||||
TestFactory *factory = new TestSuiteFactory<TestCaseType>();
|
||||
TestFactoryRegistry::getRegistry( name ).registerFactory( factory );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
|
||||
@@ -0,0 +1,345 @@
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
// Header file HelperMacros.h
|
||||
// (c)Copyright 2000, Baptiste Lepilleur.
|
||||
// Created: 2001/04/15
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
#ifndef CPPUNIT_EXTENSIONS_HELPERMACROS_H
|
||||
#define CPPUNIT_EXTENSIONS_HELPERMACROS_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/extensions/AutoRegisterSuite.h>
|
||||
#include <cppunit/extensions/TestSuiteBuilder.h>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit
|
||||
{
|
||||
class TestFixture;
|
||||
|
||||
/*! \brief Abstract TestFixture factory.
|
||||
*/
|
||||
class TestFixtureFactory
|
||||
{
|
||||
public:
|
||||
//! Creates a new TestFixture instance.
|
||||
virtual CppUnit::TestFixture *makeFixture() =0;
|
||||
};
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
// The macro __CPPUNIT_SUITE_CTOR_ARGS expand to an expression used to construct
|
||||
// the TestSuiteBuilder with macro CPPUNIT_TEST_SUITE.
|
||||
//
|
||||
// The name of the suite is obtained using RTTI if CPPUNIT_USE_TYPEINFO_NAME
|
||||
// is defined, otherwise it is extracted from the macro parameter
|
||||
//
|
||||
// This macro is for cppunit internal and should not be use otherwise.
|
||||
#if CPPUNIT_USE_TYPEINFO_NAME
|
||||
# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType )
|
||||
#else
|
||||
# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ) (std::string(#ATestFixtureType))
|
||||
#endif
|
||||
|
||||
|
||||
/*! \addtogroup WritingTestFixture Writing test fixture
|
||||
*/
|
||||
/** @{
|
||||
*/
|
||||
|
||||
|
||||
/** \file
|
||||
* Macros intended to ease the definition of test suites.
|
||||
*
|
||||
* The macros
|
||||
* CPPUNIT_TEST_SUITE(), CPPUNIT_TEST(), and CPPUNIT_TEST_SUITE_END()
|
||||
* are designed to facilitate easy creation of a test suite.
|
||||
* For example,
|
||||
*
|
||||
* \code
|
||||
* #include <cppunit/extensions/HelperMacros.h>
|
||||
* class MyTest : public CppUnit::TestFixture {
|
||||
* CPPUNIT_TEST_SUITE( MyTest );
|
||||
* CPPUNIT_TEST( testEquality );
|
||||
* CPPUNIT_TEST( testSetName );
|
||||
* CPPUNIT_TEST_SUITE_END();
|
||||
* public:
|
||||
* void testEquality();
|
||||
* void testSetName();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* The effect of these macros is to define two methods in the
|
||||
* class MyTest. The first method is an auxiliary function
|
||||
* named registerTests that you will not need to call directly.
|
||||
* The second function
|
||||
* \code static CppUnit::TestSuite *suite()\endcode
|
||||
* returns a pointer to the suite of tests defined by the CPPUNIT_TEST()
|
||||
* macros.
|
||||
*
|
||||
* Rather than invoking suite() directly,
|
||||
* the macro CPPUNIT_TEST_SUITE_REGISTRATION() is
|
||||
* used to create a static variable that automatically
|
||||
* registers its test suite in a global registry.
|
||||
* The registry yields a Test instance containing all the
|
||||
* registered suites.
|
||||
* \code
|
||||
* CPPUNIT_TEST_SUITE_REGISTRATION( MyTest );
|
||||
* CppUnit::Test* tp =
|
||||
* CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
||||
* \endcode
|
||||
*
|
||||
* The test suite macros can even be used with templated test classes.
|
||||
* For example:
|
||||
*
|
||||
* \code
|
||||
* template<typename CharType>
|
||||
* class StringTest : public CppUnit::TestFixture {
|
||||
* CPPUNIT_TEST_SUITE( StringTest );
|
||||
* CPPUNIT_TEST( testAppend );
|
||||
* CPPUNIT_TEST_SUITE_END();
|
||||
* public:
|
||||
* ...
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* You need to add in an implementation file:
|
||||
*
|
||||
* \code
|
||||
* CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<char> );
|
||||
* CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<wchar_t> );
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
|
||||
/*! \brief Begin test suite
|
||||
*
|
||||
* This macro starts the declaration of a new test suite.
|
||||
* Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the
|
||||
* test suite of the parent class.
|
||||
*
|
||||
* \param ATestFixtureType Type of the test case class. This type \b MUST
|
||||
* be derived from TestFixture.
|
||||
* \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
|
||||
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
|
||||
*/
|
||||
#define CPPUNIT_TEST_SUITE( ATestFixtureType ) \
|
||||
private: \
|
||||
typedef ATestFixtureType __ThisTestFixtureType; \
|
||||
class ThisTestFixtureFactory : public CppUnit::TestFixtureFactory \
|
||||
{ \
|
||||
virtual CppUnit::TestFixture *makeFixture() \
|
||||
{ \
|
||||
return new ATestFixtureType(); \
|
||||
} \
|
||||
}; \
|
||||
public: \
|
||||
static void \
|
||||
registerTests( CppUnit::TestSuite *suite, \
|
||||
CppUnit::TestFixtureFactory *factory ) \
|
||||
{ \
|
||||
CppUnit::TestSuiteBuilder<__ThisTestFixtureType> builder( suite );
|
||||
|
||||
|
||||
/*! \brief Begin test suite (includes parent suite)
|
||||
*
|
||||
* This macro may only be used in a class whose parent class
|
||||
* defines a test suite using CPPUNIT_TEST_SUITE() or CPPUNIT_TEST_SUB_SUITE().
|
||||
*
|
||||
* This macro begins the declaration of a test suite, in the same
|
||||
* manner as CPPUNIT_TEST_SUITE(). In addition, the test suite of the
|
||||
* parent is automatically inserted in the test suite being
|
||||
* defined.
|
||||
*
|
||||
* Here is an example:
|
||||
*
|
||||
* \code
|
||||
* #include <cppunit/extensions/HelperMacros.h>
|
||||
* class MySubTest : public MyTest {
|
||||
* CPPUNIT_TEST_SUB_SUITE( MySubTest, MyTest );
|
||||
* CPPUNIT_TEST( testAdd );
|
||||
* CPPUNIT_TEST( testSub );
|
||||
* CPPUNIT_TEST_SUITE_END();
|
||||
* public:
|
||||
* void testAdd();
|
||||
* void testSub();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* \param ATestFixtureType Type of the test case class. This type \b MUST
|
||||
* be derived from TestFixture.
|
||||
* \param ASuperClass Type of the parent class.
|
||||
* \see CPPUNIT_TEST_SUITE.
|
||||
*/
|
||||
#define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \
|
||||
private: \
|
||||
typedef ASuperClass __ThisSuperClassType; \
|
||||
CPPUNIT_TEST_SUITE( ATestFixtureType ); \
|
||||
__ThisSuperClassType::registerTests( suite, factory )
|
||||
|
||||
|
||||
/*! \brief Add a method to the suite.
|
||||
* \param testMethod Name of the method of the test case to add to the
|
||||
* suite. The signature of the method must be of
|
||||
* type: void testMethod();
|
||||
* \see CPPUNIT_TEST_SUITE.
|
||||
*/
|
||||
#define CPPUNIT_TEST( testMethod ) \
|
||||
builder.addTestCaller( #testMethod, \
|
||||
&__ThisTestFixtureType::testMethod , \
|
||||
(__ThisTestFixtureType*)factory->makeFixture() )
|
||||
|
||||
|
||||
/*! \brief Add a test which fail if the specified exception is not caught.
|
||||
*
|
||||
* Example:
|
||||
* \code
|
||||
* #include <cppunit/extensions/HelperMacros.h>
|
||||
* #include <vector>
|
||||
* class MyTest : public CppUnit::TestFixture {
|
||||
* CPPUNIT_TEST_SUITE( MyTest );
|
||||
* CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::invalid_argument );
|
||||
* CPPUNIT_TEST_SUITE_END();
|
||||
* public:
|
||||
* void testVectorAtThrow()
|
||||
* {
|
||||
* std::vector<int> v;
|
||||
* v.at( 1 ); // must throw exception std::invalid_argument
|
||||
* }
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* \param testMethod Name of the method of the test case to add to the suite.
|
||||
* \param ExceptionType Type of the exception that must be thrown by the test
|
||||
* method.
|
||||
*/
|
||||
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
|
||||
builder.addTestCallerForException( #testMethod, \
|
||||
&__ThisTestFixtureType::testMethod , \
|
||||
(__ThisTestFixtureType*)factory->makeFixture(), \
|
||||
(ExceptionType *)NULL );
|
||||
|
||||
/*! \brief Adds a test case which is excepted to fail.
|
||||
*
|
||||
* The added test case expect an assertion to fail. You usually used that type
|
||||
* of test case when testing custom assertion macros.
|
||||
*
|
||||
* \code
|
||||
* CPPUNIT_TEST_FAIL( testAssertFalseFail );
|
||||
*
|
||||
* void testAssertFalseFail()
|
||||
* {
|
||||
* CPPUNIT_ASSERT( false );
|
||||
* }
|
||||
* \endcode
|
||||
* \see CreatingNewAssertions.
|
||||
*/
|
||||
#define CPPUNIT_TEST_FAIL( testMethod ) \
|
||||
CPPUNIT_TEST_EXCEPTION( testMethod, CppUnit::Exception )
|
||||
|
||||
/*! \brief End declaration of the test suite.
|
||||
*
|
||||
* After this macro, member access is set to "private".
|
||||
*
|
||||
* \see CPPUNIT_TEST_SUITE.
|
||||
* \see CPPUNIT_TEST_SUITE_REGISTRATION.
|
||||
*/
|
||||
#define CPPUNIT_TEST_SUITE_END() \
|
||||
builder.takeSuite(); \
|
||||
} \
|
||||
static CppUnit::TestSuite *suite() \
|
||||
{ \
|
||||
CppUnit::TestSuiteBuilder<__ThisTestFixtureType> \
|
||||
builder __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ); \
|
||||
ThisTestFixtureFactory factory; \
|
||||
__ThisTestFixtureType::registerTests( builder.suite(), &factory ); \
|
||||
return builder.takeSuite(); \
|
||||
} \
|
||||
private: /* dummy typedef so that the macro can still end with ';'*/ \
|
||||
typedef ThisTestFixtureFactory __ThisTestFixtureFactory
|
||||
|
||||
/** @}
|
||||
*/
|
||||
|
||||
#define __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) s1##s2
|
||||
#define __CPPUNIT_CONCATENATE( s1, s2 ) __CPPUNIT_CONCATENATE_DIRECT( s1, s2 )
|
||||
|
||||
/** Decorates the specified string with the line number to obtain a unique name;
|
||||
* @param str String to decorate.
|
||||
*/
|
||||
#define __CPPUNIT_MAKE_UNIQUE_NAME( str ) __CPPUNIT_CONCATENATE( str, __LINE__ )
|
||||
|
||||
|
||||
/** Adds the specified fixture suite to the unnamed registry.
|
||||
* \ingroup CreatingTestSuite
|
||||
*
|
||||
* This macro declares a static variable whose construction
|
||||
* causes a test suite factory to be inserted in a global registry
|
||||
* of such factories. The registry is available by calling
|
||||
* the static function CppUnit::TestFactoryRegistry::getRegistry().
|
||||
*
|
||||
* \param ATestFixtureType Type of the test case class.
|
||||
* \warning This macro should be used only once per line of code (the line
|
||||
* number is used to name a hidden static variable).
|
||||
* \see CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
|
||||
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
|
||||
* CppUnit::TestFactoryRegistry.
|
||||
*/
|
||||
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
|
||||
static CppUnit::AutoRegisterSuite< ATestFixtureType > \
|
||||
__CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )
|
||||
|
||||
|
||||
/** Adds the specified fixture suite to the specified registry suite.
|
||||
* \ingroup CreatingTestSuite
|
||||
*
|
||||
* This macro declares a static variable whose construction
|
||||
* causes a test suite factory to be inserted in the global registry
|
||||
* suite of the specified name. The registry is available by calling
|
||||
* the static function CppUnit::TestFactoryRegistry::getRegistry().
|
||||
*
|
||||
* For the suite name, use a string returned by a static function rather
|
||||
* than a hardcoded string. That way, you can know what are the name of
|
||||
* named registry and you don't risk mistyping the registry name.
|
||||
*
|
||||
* \code
|
||||
* // MySuites.h
|
||||
* namespace MySuites {
|
||||
* std::string math() {
|
||||
* return "Math";
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ComplexNumberTest.cpp
|
||||
* #include "MySuites.h"
|
||||
*
|
||||
* CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComplexNumberTest, MySuites::math() );
|
||||
* \endcode
|
||||
*
|
||||
* \param ATestFixtureType Type of the test case class.
|
||||
* \param suiteName Name of the global registry suite the test suite is
|
||||
* registered into.
|
||||
* \warning This macro should be used only once per line of code (the line
|
||||
* number is used to name a hidden static variable).
|
||||
* \see CPPUNIT_TEST_SUITE_REGISTRATION
|
||||
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
|
||||
* CppUnit::TestFactoryRegistry..
|
||||
*/
|
||||
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
|
||||
static CppUnit::AutoRegisterSuite< ATestFixtureType > \
|
||||
__CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )(suiteName)
|
||||
|
||||
|
||||
// Backwards compatibility
|
||||
// (Not tested!)
|
||||
|
||||
#if CPPUNIT_ENABLE_CU_TEST_MACROS
|
||||
|
||||
#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
|
||||
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
|
||||
#define CU_TEST(tm) CPPUNIT_TEST(tm)
|
||||
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
|
||||
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_ORTHODOX_H
|
||||
#define CPPUNIT_EXTENSIONS_ORTHODOX_H
|
||||
|
||||
#include <cppunit/TestCase.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*
|
||||
* Orthodox performs a simple set of tests on an arbitary
|
||||
* class to make sure that it supports at least the
|
||||
* following operations:
|
||||
*
|
||||
* default construction - constructor
|
||||
* equality/inequality - operator== && operator!=
|
||||
* assignment - operator=
|
||||
* negation - operator!
|
||||
* safe passage - copy construction
|
||||
*
|
||||
* If operations for each of these are not declared
|
||||
* the template will not instantiate. If it does
|
||||
* instantiate, tests are performed to make sure
|
||||
* that the operations have correct semantics.
|
||||
*
|
||||
* Adding an orthodox test to a suite is very
|
||||
* easy:
|
||||
*
|
||||
* public: Test *suite () {
|
||||
* TestSuite *suiteOfTests = new TestSuite;
|
||||
* suiteOfTests->addTest (new ComplexNumberTest ("testAdd");
|
||||
* suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());
|
||||
* return suiteOfTests;
|
||||
* }
|
||||
*
|
||||
* Templated test cases be very useful when you are want to
|
||||
* make sure that a group of classes have the same form.
|
||||
*
|
||||
* see TestSuite
|
||||
*/
|
||||
|
||||
|
||||
template <typename ClassUnderTest> class Orthodox : public TestCase
|
||||
{
|
||||
public:
|
||||
Orthodox () : TestCase ("Orthodox") {}
|
||||
|
||||
protected:
|
||||
ClassUnderTest call (ClassUnderTest object);
|
||||
void runTest ();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Run an orthodoxy test
|
||||
template <typename ClassUnderTest> void Orthodox<ClassUnderTest>::runTest ()
|
||||
{
|
||||
// make sure we have a default constructor
|
||||
ClassUnderTest a, b, c;
|
||||
|
||||
// make sure we have an equality operator
|
||||
CPPUNIT_ASSERT (a == b);
|
||||
|
||||
// check the inverse
|
||||
b.operator= (a.operator! ());
|
||||
CPPUNIT_ASSERT (a != b);
|
||||
|
||||
// double inversion
|
||||
b = !!a;
|
||||
CPPUNIT_ASSERT (a == b);
|
||||
|
||||
// invert again
|
||||
b = !a;
|
||||
|
||||
// check calls
|
||||
c = a;
|
||||
CPPUNIT_ASSERT (c == call (a));
|
||||
|
||||
c = b;
|
||||
CPPUNIT_ASSERT (c == call (b));
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Exercise a call
|
||||
template <typename ClassUnderTest>
|
||||
ClassUnderTest Orthodox<ClassUnderTest>::call (ClassUnderTest object)
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_REPEATEDTEST_H
|
||||
#define CPPUNIT_EXTENSIONS_REPEATEDTEST_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/extensions/TestDecorator.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Test;
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*! \brief Decorator that runs a test repeatedly.
|
||||
*
|
||||
* Does not assume ownership of the test it decorates
|
||||
*/
|
||||
class CPPUNIT_API RepeatedTest : public TestDecorator
|
||||
{
|
||||
public:
|
||||
RepeatedTest( Test *test,
|
||||
int timesRepeat ) :
|
||||
TestDecorator( test ),
|
||||
m_timesRepeat(timesRepeat) {}
|
||||
|
||||
void run( TestResult *result );
|
||||
int countTestCases() const;
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
RepeatedTest( const RepeatedTest & );
|
||||
void operator=( const RepeatedTest & );
|
||||
|
||||
const int m_timesRepeat;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_REPEATEDTEST_H
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_TESTDECORATOR_H
|
||||
#define CPPUNIT_EXTENSIONS_TESTDECORATOR_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <cppunit/Test.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*! \brief Decorator for Tests.
|
||||
*
|
||||
* TestDecorator provides an alternate means to extend functionality
|
||||
* of a test class without subclassing the test. Instead, one can
|
||||
* subclass the decorater and use it to wrap the test class.
|
||||
*
|
||||
* Does not assume ownership of the test it decorates
|
||||
*/
|
||||
class CPPUNIT_API TestDecorator : public Test
|
||||
{
|
||||
public:
|
||||
TestDecorator (Test *test);
|
||||
~TestDecorator ();
|
||||
|
||||
void run (TestResult *result);
|
||||
int countTestCases () const;
|
||||
std::string getName () const;
|
||||
std::string toString () const;
|
||||
|
||||
protected:
|
||||
Test *m_test;
|
||||
|
||||
private:
|
||||
TestDecorator( const TestDecorator &);
|
||||
void operator =( const TestDecorator & );
|
||||
};
|
||||
|
||||
|
||||
inline TestDecorator::TestDecorator (Test *test)
|
||||
{ m_test = test; }
|
||||
|
||||
|
||||
inline TestDecorator::~TestDecorator ()
|
||||
{}
|
||||
|
||||
|
||||
inline int TestDecorator::countTestCases () const
|
||||
{ return m_test->countTestCases (); }
|
||||
|
||||
|
||||
inline void TestDecorator::run (TestResult *result)
|
||||
{ m_test->run (result); }
|
||||
|
||||
|
||||
inline std::string TestDecorator::toString () const
|
||||
{ return m_test->toString (); }
|
||||
|
||||
|
||||
inline std::string TestDecorator::getName () const
|
||||
{ return m_test->getName(); }
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_TESTFACTORY_H
|
||||
#define CPPUNIT_EXTENSIONS_TESTFACTORY_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Test;
|
||||
|
||||
/*! \brief Abstract Test factory.
|
||||
*/
|
||||
class CPPUNIT_API TestFactory
|
||||
{
|
||||
public:
|
||||
virtual ~TestFactory() {}
|
||||
|
||||
/*! Makes a new test.
|
||||
* \return A new Test.
|
||||
*/
|
||||
virtual Test* makeTest() = 0;
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_TESTFACTORY_H
|
||||
@@ -0,0 +1,148 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H
|
||||
#define CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
|
||||
#endif
|
||||
|
||||
#include <cppunit/extensions/TestFactory.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class TestSuite;
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
template class CPPUNIT_API std::map<std::string, TestFactory *>;
|
||||
#endif
|
||||
|
||||
|
||||
/*! \brief Registry for TestFactory.
|
||||
* \ingroup CreatingTestSuite
|
||||
*
|
||||
* Notes that the registry assumes lifetime control for any registered test.
|
||||
*
|
||||
* To register tests, use the macros:
|
||||
* - CPPUNIT_TEST_SUITE_REGISTRATION(): to add tests in the unnamed registry.
|
||||
* - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(): to add tests in a named registry.
|
||||
*
|
||||
* Example 1: retreiving a suite that contains all the test registered with
|
||||
* CPPUNIT_TEST_SUITE_REGISTRATION().
|
||||
* \code
|
||||
* CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
* CppUnit::TestSuite *suite = registry.makeTest();
|
||||
* \endcode
|
||||
*
|
||||
* Example 2: retreiving a suite that contains all the test registered with
|
||||
* \link CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" )\endlink.
|
||||
* \code
|
||||
* CppUnit::TestFactoryRegistry &mathRegistry = CppUnit::TestFactoryRegistry::getRegistry( "Math" );
|
||||
* CppUnit::TestSuite *mathSuite = mathRegistry.makeTest();
|
||||
* \endcode
|
||||
*
|
||||
* Example 3: creating a test suite hierarchy composed of unnamed registration and
|
||||
* named registration:
|
||||
* - All Tests
|
||||
* - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Graph" )
|
||||
* - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" )
|
||||
* - tests registered with CPPUNIT_TEST_SUITE_REGISTRATION
|
||||
*
|
||||
* \code
|
||||
* CppUnit::TestSuite *rootSuite = new CppUnit::TestSuite( "All tests" );
|
||||
* rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ).makeTest() );
|
||||
* rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Math" ).makeTest() );
|
||||
* CppUnit::TestFactoryRegistry::getRegistry().addTestToSuite( rootSuite );
|
||||
* \endcode
|
||||
*
|
||||
* The same result can be obtained with:
|
||||
* \code
|
||||
* CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
* registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ) );
|
||||
* registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Math" ) );
|
||||
* CppUnit::TestSuite *suite = registry.makeTest();
|
||||
* \endcode
|
||||
*
|
||||
* Since a TestFactoryRegistry is a TestFactory, the named registries can be
|
||||
* registered in the unnamed registry, creating the hierarchy links.
|
||||
*
|
||||
* \see TestSuiteFactory, AutoRegisterSuite
|
||||
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
|
||||
*/
|
||||
class CPPUNIT_API TestFactoryRegistry : public TestFactory
|
||||
{
|
||||
public:
|
||||
/** Constructs the registry with the specified name.
|
||||
* \param name Name of the registry. It is the name of TestSuite returned by
|
||||
* makeTest().
|
||||
*/
|
||||
TestFactoryRegistry( std::string name = "All Tests" );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TestFactoryRegistry();
|
||||
|
||||
/** Returns a new TestSuite that contains the registered test.
|
||||
* \return A new TestSuite which contains all the test added using
|
||||
* registerFactory(TestFactory *).
|
||||
*/
|
||||
virtual Test *makeTest();
|
||||
|
||||
/** Returns unnamed the registry.
|
||||
* TestSuite registered using CPPUNIT_TEST_SUITE_REGISTRATION() are registered
|
||||
* in this registry.
|
||||
* \return Registry which name is "All Tests".
|
||||
*/
|
||||
static TestFactoryRegistry &getRegistry();
|
||||
|
||||
/** Returns a named registry.
|
||||
* TestSuite registered using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() are registered
|
||||
* in the registry of the same name.
|
||||
* \param name Name of the registry to return.
|
||||
* \return Registry. If the registry does not exist, it is created with the
|
||||
* specified name.
|
||||
*/
|
||||
static TestFactoryRegistry &getRegistry( const std::string &name );
|
||||
|
||||
/** Adds the registered tests to the specified suite.
|
||||
* \param suite Suite the tests are added to.
|
||||
*/
|
||||
void addTestToSuite( TestSuite *suite );
|
||||
|
||||
/** Adds the specified TestFactory with a specific name (DEPRECATED).
|
||||
* \param name Name associated to the factory.
|
||||
* \param factory Factory to register.
|
||||
* \deprecated Use registerFactory( TestFactory *) instead.
|
||||
*/
|
||||
void registerFactory( const std::string &name,
|
||||
TestFactory *factory );
|
||||
|
||||
/** Adds the specified TestFactory to the registry.
|
||||
*
|
||||
* \param factory Factory to register.
|
||||
*/
|
||||
void registerFactory( TestFactory *factory );
|
||||
|
||||
private:
|
||||
TestFactoryRegistry( const TestFactoryRegistry © );
|
||||
void operator =( const TestFactoryRegistry © );
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, TestFactory *> Factories;
|
||||
Factories m_factories;
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#if CPPUNIT_NEED_DLL_DECL
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_TESTSETUP_H
|
||||
#define CPPUNIT_EXTENSIONS_TESTSETUP_H
|
||||
|
||||
#include <cppunit/extensions/TestDecorator.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Test;
|
||||
class TestResult;
|
||||
|
||||
|
||||
class CPPUNIT_API TestSetUp : public TestDecorator
|
||||
{
|
||||
public:
|
||||
TestSetUp( Test *test );
|
||||
|
||||
void run( TestResult *result );
|
||||
|
||||
protected:
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
private:
|
||||
TestSetUp( const TestSetUp & );
|
||||
void operator =( const TestSetUp & );
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_TESTSETUP_H
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H
|
||||
#define CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <memory>
|
||||
#include <cppunit/TestSuite.h>
|
||||
#include <cppunit/TestCaller.h>
|
||||
|
||||
#if CPPUNIT_USE_TYPEINFO_NAME
|
||||
# include <cppunit/extensions/TypeInfoHelper.h>
|
||||
#endif
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/*! \brief Helper to add tests to a TestSuite.
|
||||
* \ingroup WritingTestFixture
|
||||
*
|
||||
* All tests added to the TestSuite are prefixed by TestSuite name. The resulting
|
||||
* TestCase name has the following pattern:
|
||||
*
|
||||
* MyTestSuiteName.myTestName
|
||||
*/
|
||||
template<typename Fixture>
|
||||
class TestSuiteBuilder
|
||||
{
|
||||
public:
|
||||
typedef void (Fixture::*TestMethod)();
|
||||
|
||||
#if CPPUNIT_USE_TYPEINFO_NAME
|
||||
TestSuiteBuilder() :
|
||||
m_suite( new TestSuite(
|
||||
TypeInfoHelper::getClassName( typeid(Fixture) ) ) )
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
TestSuiteBuilder( TestSuite *suite ) : m_suite( suite )
|
||||
{
|
||||
}
|
||||
|
||||
TestSuiteBuilder(std::string name) : m_suite( new TestSuite(name) )
|
||||
{
|
||||
}
|
||||
|
||||
TestSuite *suite() const
|
||||
{
|
||||
return m_suite.get();
|
||||
}
|
||||
|
||||
TestSuite *takeSuite()
|
||||
{
|
||||
return m_suite.release();
|
||||
}
|
||||
|
||||
void addTest( Test *test )
|
||||
{
|
||||
m_suite->addTest( test );
|
||||
}
|
||||
|
||||
void addTestCaller( std::string methodName,
|
||||
TestMethod testMethod )
|
||||
{
|
||||
Test *test =
|
||||
new TestCaller<Fixture>( makeTestName( methodName ),
|
||||
testMethod );
|
||||
addTest( test );
|
||||
}
|
||||
|
||||
void addTestCaller( std::string methodName,
|
||||
TestMethod testMethod,
|
||||
Fixture *fixture )
|
||||
{
|
||||
Test *test =
|
||||
new TestCaller<Fixture>( makeTestName( methodName ),
|
||||
testMethod,
|
||||
fixture);
|
||||
addTest( test );
|
||||
}
|
||||
|
||||
template<typename ExceptionType>
|
||||
void addTestCallerForException( std::string methodName,
|
||||
TestMethod testMethod,
|
||||
Fixture *fixture,
|
||||
ExceptionType *dummyPointer )
|
||||
{
|
||||
Test *test = new TestCaller<Fixture,ExceptionType>(
|
||||
makeTestName( methodName ),
|
||||
testMethod,
|
||||
fixture);
|
||||
addTest( test );
|
||||
}
|
||||
|
||||
|
||||
std::string makeTestName( const std::string &methodName )
|
||||
{
|
||||
return m_suite->getName() + "." + methodName;
|
||||
}
|
||||
|
||||
private:
|
||||
std::auto_ptr<TestSuite> m_suite;
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H
|
||||
#define CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H
|
||||
|
||||
#include <cppunit/extensions/TestFactory.h>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Test;
|
||||
|
||||
/*! \brief TestFactory for TestFixture that implements a static suite() method.
|
||||
* \see AutoRegisterSuite.
|
||||
*/
|
||||
template<typename TestCaseType>
|
||||
class TestSuiteFactory : public TestFactory
|
||||
{
|
||||
public:
|
||||
virtual Test *makeTest()
|
||||
{
|
||||
return TestCaseType::suite();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef CPPUNIT_TYPEINFOHELPER_H
|
||||
#define CPPUNIT_TYPEINFOHELPER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
|
||||
#if CPPUNIT_USE_TYPEINFO_NAME
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
/** Helper to use type_info.
|
||||
*/
|
||||
class CPPUNIT_API TypeInfoHelper
|
||||
{
|
||||
public:
|
||||
/** Get the class name of the specified type_info.
|
||||
* \param info Info which the class name is extracted from.
|
||||
* \return The string returned by type_info::name() without
|
||||
* the "class" prefix. If the name is not prefixed
|
||||
* by "class", it is returned as this.
|
||||
*/
|
||||
static std::string getClassName( const std::type_info &info );
|
||||
};
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif
|
||||
|
||||
#endif // CPPUNIT_TYPEINFOHELPER_H
|
||||
@@ -0,0 +1,103 @@
|
||||
#ifndef CPPUNITUI_TEXT_TESTRUNNER_H
|
||||
#define CPPUNITUI_TEXT_TESTRUNNER_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
class Outputter;
|
||||
class Test;
|
||||
class TestSuite;
|
||||
class TextOutputter;
|
||||
class TestResult;
|
||||
class TestResultCollector;
|
||||
|
||||
namespace TextUi
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief A text mode test runner.
|
||||
* \ingroup WritingTestResult
|
||||
* \ingroup ExecutingTest
|
||||
*
|
||||
* The test runner manage the life cycle of the added tests.
|
||||
*
|
||||
* The test runner can run only one of the added tests or all the tests.
|
||||
*
|
||||
* TestRunner prints out a trace as the tests are executed followed by a
|
||||
* summary at the end. The trace and summary print are optional.
|
||||
*
|
||||
* Here is an example of use:
|
||||
*
|
||||
* \code
|
||||
* CppUnit::TextUi::TestRunner runner;
|
||||
* runner.addTest( ExampleTestCase::suite() );
|
||||
* runner.run( "", true ); // Run all tests and wait
|
||||
* \endcode
|
||||
*
|
||||
* The trace is printed using a TextTestProgressListener. The summary is printed
|
||||
* using a TextOutputter.
|
||||
*
|
||||
* You can specify an alternate Outputter at construction
|
||||
* or later with setOutputter().
|
||||
*
|
||||
* After construction, you can register additional TestListener to eventManager(),
|
||||
* for a custom progress trace, for example.
|
||||
*
|
||||
* \code
|
||||
* CppUnit::TextUi::TestRunner runner;
|
||||
* runner.addTest( ExampleTestCase::suite() );
|
||||
* runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter(
|
||||
* &runner.result(),
|
||||
* std::cerr ) );
|
||||
* MyCustomProgressTestListener progress;
|
||||
* runner.eventManager().addListener( &progress );
|
||||
* runner.run( "", true ); // Run all tests and wait
|
||||
* \endcode
|
||||
*
|
||||
* \see CompilerOutputter, XmlOutputter, TextOutputter.
|
||||
*/
|
||||
class CPPUNIT_API TestRunner
|
||||
{
|
||||
public:
|
||||
TestRunner( Outputter *outputter =NULL );
|
||||
|
||||
virtual ~TestRunner();
|
||||
|
||||
bool run( std::string testName ="",
|
||||
bool doWait = false,
|
||||
bool doPrintResult = true,
|
||||
bool doPrintProgress = true );
|
||||
|
||||
void addTest( Test *test );
|
||||
|
||||
void setOutputter( Outputter *outputter );
|
||||
|
||||
TestResultCollector &result() const;
|
||||
|
||||
TestResult &eventManager() const;
|
||||
|
||||
protected:
|
||||
virtual bool runTest( Test *test,
|
||||
bool doPrintProgress );
|
||||
virtual bool runTestByName( std::string testName,
|
||||
bool printProgress );
|
||||
virtual void wait( bool doWait );
|
||||
virtual void printResult( bool doPrintResult );
|
||||
|
||||
virtual Test *findTestByName( std::string name ) const;
|
||||
|
||||
TestSuite *m_suite;
|
||||
TestResultCollector *m_result;
|
||||
TestResult *m_eventManager;
|
||||
Outputter *m_outputter;
|
||||
};
|
||||
|
||||
|
||||
} // namespace TextUi
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
#endif // CPPUNITUI_TEXT_TESTRUNNER_H
|
||||
Reference in New Issue
Block a user