mirror of
				https://github.com/pocoproject/poco.git
				synced 2025-10-23 08:31:43 +02:00 
			
		
		
		
	new trunk (base for 1.5)
windows build only
This commit is contained in:
		
							
								
								
									
										56
									
								
								CppUnit/include/CppUnit/CppUnit.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								CppUnit/include/CppUnit/CppUnit.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| // | ||||
| // CppUnit.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/CppUnit.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_CppUnit_INCLUDED | ||||
| #define CppUnit_CppUnit_INCLUDED | ||||
|  | ||||
|  | ||||
| // | ||||
| // Ensure that POCO_DLL is default unless POCO_STATIC is defined | ||||
| // | ||||
| #if defined(_WIN32) && defined(_DLL) | ||||
| 	#if !defined(POCO_DLL) && !defined(POCO_STATIC) | ||||
| 		#define POCO_DLL | ||||
| 	#endif | ||||
| #endif | ||||
|  | ||||
|  | ||||
| // | ||||
| // The following block is the standard way of creating macros which make exporting | ||||
| // from a DLL simpler. All files within this DLL are compiled with the CppUnit_EXPORTS | ||||
| // symbol defined on the command line. this symbol should not be defined on any project | ||||
| // that uses this DLL. This way any other project whose source files include this file see | ||||
| // CppUnit_API functions as being imported from a DLL, wheras this DLL sees symbols | ||||
| // defined with this macro as being exported. | ||||
| // | ||||
| #if defined(_WIN32) && defined(POCO_DLL) | ||||
| 	#if defined(CppUnit_EXPORTS) | ||||
| 		#define CppUnit_API __declspec(dllexport) | ||||
| 	#else | ||||
| 		#define CppUnit_API __declspec(dllimport) | ||||
| 	#endif | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #if !defined(CppUnit_API) | ||||
| 	#define CppUnit_API | ||||
| #endif | ||||
|  | ||||
|  | ||||
| // Turn off some annoying warnings | ||||
| #ifdef _MSC_VER | ||||
| 	#pragma warning(disable:4786)  // identifier truncation warning | ||||
| 	#pragma warning(disable:4503)  // decorated name length exceeded - mainly a problem with STLPort | ||||
| 	#pragma warning(disable:4018)  // signed/unsigned comparison | ||||
| 	#pragma warning(disable:4284)  // return type for operator -> is not UDT | ||||
| 	#pragma warning(disable:4251)  // ... needs to have dll-interface warning  | ||||
| 	#pragma warning(disable:4273)  | ||||
| 	#pragma warning(disable:4275)  // ... non dll-interface class used as base for dll-interface class | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_CppUnit_INCLUDED | ||||
							
								
								
									
										141
									
								
								CppUnit/include/CppUnit/CppUnitException.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								CppUnit/include/CppUnit/CppUnitException.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,141 @@ | ||||
| // | ||||
| // CppUnitException.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/CppUnitException.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_CppUnitException_INCLUDED | ||||
| #define CppUnit_CppUnitException_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include <exception> | ||||
| #include <string> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class CppUnit_API CppUnitException: public std::exception | ||||
| 	/// CppUnitException is an exception that serves | ||||
| 	/// descriptive strings through its what() method | ||||
| { | ||||
| public: | ||||
| 	CppUnitException(const std::string& message = "",  | ||||
| 	                 long lineNumber = CPPUNIT_UNKNOWNLINENUMBER,  | ||||
| 	                 const std::string& fileName = CPPUNIT_UNKNOWNFILENAME); | ||||
| 	CppUnitException(const std::string& message, | ||||
| 	                 long lineNumber, | ||||
| 	                 long data1lineNumber, | ||||
| 	                 const std::string& fileName); | ||||
| 	CppUnitException(const std::string& message, | ||||
| 	                 long lineNumber, | ||||
| 	                 long data1lineNumber, | ||||
| 	                 long data2lineNumber, | ||||
| 	                 const std::string& fileName); | ||||
| 	CppUnitException(const CppUnitException& other); | ||||
| 	virtual ~CppUnitException() throw(); | ||||
|  | ||||
| 	CppUnitException& operator = (const CppUnitException& other); | ||||
|  | ||||
| 	const char* what() const throw (); | ||||
|  | ||||
| 	long lineNumber() const; | ||||
| 	long data1LineNumber() const; | ||||
| 	long data2LineNumber() const; | ||||
| 	const std::string& fileName() const; | ||||
|  | ||||
| 	static const std::string CPPUNIT_UNKNOWNFILENAME; | ||||
| 	static const int CPPUNIT_UNKNOWNLINENUMBER; | ||||
|  | ||||
| private: | ||||
| 	std::string _message; | ||||
| 	long        _lineNumber; | ||||
| 	long        _data1lineNumber; | ||||
| 	long        _data2lineNumber; | ||||
| 	std::string _fileName; | ||||
| }; | ||||
|  | ||||
|  | ||||
| inline CppUnitException::CppUnitException(const CppUnitException& other): exception (other) | ||||
| { | ||||
|     _message         = other._message; | ||||
|     _lineNumber      = other._lineNumber; | ||||
|     _data1lineNumber = other._data1lineNumber; | ||||
|     _data2lineNumber = other._data2lineNumber; | ||||
|     _fileName        = other._fileName; | ||||
| } | ||||
|  | ||||
|  | ||||
| inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, long data2lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(data2lineNumber), _fileName(fileName) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| inline CppUnitException::~CppUnitException () throw() | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| inline CppUnitException& CppUnitException::operator = (const CppUnitException& other) | ||||
| { | ||||
| 	exception::operator= (other); | ||||
|  | ||||
|     if (&other != this) | ||||
|     { | ||||
|         _message    = other._message; | ||||
|         _lineNumber = other._lineNumber; | ||||
|         _data1lineNumber = other._data1lineNumber; | ||||
|         _data2lineNumber = other._data2lineNumber; | ||||
|         _fileName   = other._fileName; | ||||
|     } | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
|  | ||||
| inline const char* CppUnitException::what() const throw () | ||||
| { | ||||
| 	return _message.c_str(); | ||||
| } | ||||
|  | ||||
|  | ||||
| inline long CppUnitException::lineNumber() const | ||||
| { | ||||
| 	return _lineNumber;  | ||||
| } | ||||
|  | ||||
|  | ||||
| inline long CppUnitException::data1LineNumber() const | ||||
| { | ||||
| 	return _data1lineNumber;  | ||||
| } | ||||
|  | ||||
|  | ||||
| inline long CppUnitException::data2LineNumber() const | ||||
| { | ||||
| 	return _data2lineNumber;  | ||||
| } | ||||
|  | ||||
|  | ||||
| // The file in which the error occurred | ||||
| inline const std::string& CppUnitException::fileName() const | ||||
| { | ||||
| 	return _fileName;  | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_CppUnitException_INCLUDED | ||||
							
								
								
									
										19
									
								
								CppUnit/include/CppUnit/Guards.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								CppUnit/include/CppUnit/Guards.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| // | ||||
| // Guards.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/Guards.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_Guards_INCLUDED | ||||
| #define CppUnit_Guards_INCLUDED | ||||
|  | ||||
|  | ||||
| // Prevent copy construction and assignment for a class | ||||
| #define REFERENCEOBJECT(className) \ | ||||
| private: \ | ||||
| 	className(const className& other); \ | ||||
| 	className& operator = (const className& other); | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_Guards_INCLUDED | ||||
							
								
								
									
										105
									
								
								CppUnit/include/CppUnit/Orthodox.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								CppUnit/include/CppUnit/Orthodox.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| // | ||||
| // Orthodox.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/Orthodox.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_Orthodox_INCLUDED | ||||
| #define CppUnit_Orthodox_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.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 <class ClassUnderTest>  | ||||
| class Orthodox: public TestCase | ||||
| { | ||||
| public: | ||||
| 	Orthodox(): TestCase("Orthodox")  | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| protected: | ||||
|     ClassUnderTest call(ClassUnderTest object); | ||||
|     void runTest (); | ||||
| }; | ||||
|  | ||||
|  | ||||
| // Run an orthodoxy test | ||||
| template <class ClassUnderTest>  | ||||
| void Orthodox<ClassUnderTest>::runTest() | ||||
| { | ||||
|     // make sure we have a default constructor | ||||
|     ClassUnderTest   a, b, c; | ||||
|  | ||||
|     // make sure we have an equality operator | ||||
|     assert (a == b); | ||||
|  | ||||
|     // check the inverse | ||||
|     b.operator= (a.operator! ()); | ||||
|     assert (a != b); | ||||
|  | ||||
|     // double inversion | ||||
|     b = !!a; | ||||
|     assert (a == b); | ||||
|  | ||||
|     // invert again | ||||
|     b = !a; | ||||
|  | ||||
|     // check calls | ||||
|     c = a; | ||||
|     assert (c == call (a)); | ||||
|  | ||||
|     c = b; | ||||
|     assert (c == call (b)); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Exercise a call | ||||
| template <class ClassUnderTest>  | ||||
| ClassUnderTest Orthodox<ClassUnderTest>::call(ClassUnderTest object) | ||||
| { | ||||
|     return object; | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_Orthodox_INCLUDED | ||||
							
								
								
									
										77
									
								
								CppUnit/include/CppUnit/RepeatedTest.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								CppUnit/include/CppUnit/RepeatedTest.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| // | ||||
| // RepeatedTest.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/RepeatedTest.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_RepeatedTest_INCLUDED | ||||
| #define CppUnit_RepeatedTest_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/Guards.h" | ||||
| #include "CppUnit/TestDecorator.h" | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class Test; | ||||
| class TestResult; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A decorator that runs a test repeatedly. | ||||
|  * Does not assume ownership of the test it decorates | ||||
|  * | ||||
|  */ | ||||
| class CppUnit_API RepeatedTest: public TestDecorator | ||||
| { | ||||
| 	REFERENCEOBJECT (RepeatedTest) | ||||
|  | ||||
| public: | ||||
| 	RepeatedTest(Test* test, int timesRepeat): TestDecorator (test), _timesRepeat (timesRepeat)  | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	int countTestCases(); | ||||
| 	std::string toString(); | ||||
| 	void run(TestResult *result); | ||||
|  | ||||
| private: | ||||
| 	const int _timesRepeat; | ||||
| }; | ||||
|  | ||||
|  | ||||
| // Counts the number of test cases that will be run by this test. | ||||
| inline RepeatedTest::countTestCases () | ||||
| { | ||||
| 	return TestDecorator::countTestCases() * _timesRepeat; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns the name of the test instance. | ||||
| inline std::string RepeatedTest::toString() | ||||
| { | ||||
| 	return TestDecorator::toString() + " (repeated)"; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Runs a repeated test | ||||
| inline void RepeatedTest::run(TestResult *result) | ||||
| { | ||||
| 	for (int n = 0; n < _timesRepeat; n++)  | ||||
| 	{ | ||||
| 		if (result->shouldStop()) | ||||
| 			break; | ||||
|  | ||||
| 		TestDecorator::run(result); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_RepeatedTest_INCLUDED | ||||
							
								
								
									
										65
									
								
								CppUnit/include/CppUnit/Test.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								CppUnit/include/CppUnit/Test.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| // | ||||
| // Test.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/Test.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_Test_INCLUDED | ||||
| #define CppUnit_Test_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include <string> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class TestResult; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A Test can be run and collect its results. | ||||
|  * See TestResult. | ||||
|  * | ||||
|  */ | ||||
| class CppUnit_API Test | ||||
| { | ||||
| public: | ||||
| 	virtual ~Test() = 0; | ||||
| 	virtual void run(TestResult* result) = 0; | ||||
| 	virtual int countTestCases() = 0; | ||||
| 	virtual std::string toString() = 0; | ||||
| }; | ||||
|  | ||||
|  | ||||
| inline Test::~Test() | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Runs a test and collects its result in a TestResult instance. | ||||
| inline void Test::run(TestResult *result) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Counts the number of test cases that will be run by this test. | ||||
| inline int Test::countTestCases() | ||||
| { | ||||
| 	return 0;  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns the name of the test instance. | ||||
| inline std::string Test::toString() | ||||
| { | ||||
| 	return ""; | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_Test_INCLUDED | ||||
							
								
								
									
										95
									
								
								CppUnit/include/CppUnit/TestCaller.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								CppUnit/include/CppUnit/TestCaller.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,95 @@ | ||||
| // | ||||
| // TestCaller.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestCaller.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestCaller_INCLUDED | ||||
| #define CppUnit_TestCaller_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "Guards.h" | ||||
| #include "TestCase.h" | ||||
| #include <memory> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A test caller provides access to a test case method | ||||
|  * on a test case class.  Test callers are useful when | ||||
|  * you want to run an individual test or add it to a | ||||
|  * suite. | ||||
|  * | ||||
|  * Here is an example: | ||||
|  * | ||||
|  * class MathTest : public TestCase { | ||||
|  *         ... | ||||
|  *     public: | ||||
|  *         void         setUp (); | ||||
|  *         void         tearDown (); | ||||
|  * | ||||
|  *         void         testAdd (); | ||||
|  *         void         testSubtract (); | ||||
|  * }; | ||||
|  * | ||||
|  * Test *MathTest::suite () { | ||||
|  *     TestSuite *suite = new TestSuite; | ||||
|  * | ||||
|  *     suite->addTest (new TestCaller<MathTest> ("testAdd", testAdd)); | ||||
|  *     return suite; | ||||
|  * } | ||||
|  * | ||||
|  * You can use a TestCaller to bind any test method on a TestCase | ||||
|  * class, as long as it returns accepts void and returns void. | ||||
|  * | ||||
|  * See TestCase | ||||
|  */ | ||||
| template <class Fixture> | ||||
| class TestCaller: public TestCase | ||||
| { | ||||
| 	REFERENCEOBJECT (TestCaller) | ||||
|  | ||||
| 	typedef void (Fixture::*TestMethod)(); | ||||
|  | ||||
| public: | ||||
| 	TestCaller(const std::string& name, TestMethod test):  | ||||
| 		TestCase(name),  | ||||
| 		_test(test), | ||||
| 		_fixture(new Fixture(name)) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| protected: | ||||
| 	void runTest() | ||||
| 	{ | ||||
| 		(_fixture.get()->*_test)(); | ||||
| 	} | ||||
|  | ||||
| 	void setUp() | ||||
| 	{ | ||||
| 		_fixture.get()->setUp(); | ||||
| 	} | ||||
|  | ||||
| 	void tearDown() | ||||
| 	{ | ||||
| 		_fixture.get()->tearDown(); | ||||
| 	} | ||||
|  | ||||
| private: | ||||
| 	TestMethod             _test; | ||||
| 	std::auto_ptr<Fixture> _fixture; | ||||
| }; | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #define CppUnit_addTest(suite, cls, mth) \ | ||||
| 	suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth)) | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestCaller_INCLUDED | ||||
							
								
								
									
										249
									
								
								CppUnit/include/CppUnit/TestCase.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										249
									
								
								CppUnit/include/CppUnit/TestCase.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,249 @@ | ||||
| // | ||||
| // TestCase.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestCase.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestCase_INCLUDED | ||||
| #define CppUnit_TestCase_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/Guards.h" | ||||
| #include "CppUnit/Test.h" | ||||
| #include "CppUnit/CppUnitException.h" | ||||
| #include <string> | ||||
| #include <typeinfo> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class TestResult; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A test case defines the fixture to run multiple tests. To define a test case | ||||
|  * 1) implement a subclass of TestCase | ||||
|  * 2) define instance variables that store the state of the fixture | ||||
|  * 3) initialize the fixture state by overriding setUp | ||||
|  * 4) 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: | ||||
|  * | ||||
|  * class MathTest : public TestCase { | ||||
|  *     protected: int m_value1; | ||||
|  *     protected: int m_value2; | ||||
|  * | ||||
|  *     public: MathTest (std::string name) | ||||
|  *                 : TestCase (name) { | ||||
|  *     } | ||||
|  * | ||||
|  *     protected: void setUp () { | ||||
|  *         m_value1 = 2; | ||||
|  *         m_value2 = 3; | ||||
|  *     } | ||||
|  * } | ||||
|  * | ||||
|  * | ||||
|  * For each test implement a method which interacts | ||||
|  * with the fixture. Verify the expected results with assertions specified | ||||
|  * by calling assert on the expression you want to test: | ||||
|  * | ||||
|  *    protected: void testAdd () { | ||||
|  *        int result = value1 + value2; | ||||
|  *        assert (result == 5); | ||||
|  *    } | ||||
|  * | ||||
|  * Once the methods are defined you can run them. To do this, use | ||||
|  * a TestCaller. | ||||
|  * | ||||
|  * Test *test = new TestCaller<MathTest>("testAdd", MathTest::testAdd); | ||||
|  * test->run (); | ||||
|  * | ||||
|  * | ||||
|  * The tests to be run can be collected into a TestSuite. CppUnit provides | ||||
|  * different test runners which can run a test suite and collect the results. | ||||
|  * The test runners expect a static method suite as the entry | ||||
|  * point to get a test to run. | ||||
|  * | ||||
|  * public: static MathTest::suite () { | ||||
|  *      TestSuite *suiteOfTests = new TestSuite; | ||||
|  *      suiteOfTests->addTest(new TestCaller<MathTest>("testAdd", testAdd)); | ||||
|  *      suiteOfTests->addTest(new TestCaller<MathTest>("testDivideByZero", testDivideByZero)); | ||||
|  *      return suiteOfTests; | ||||
|  *  } | ||||
|  * | ||||
|  * Note that the caller of suite assumes lifetime control | ||||
|  * for the returned suite. | ||||
|  * | ||||
|  * see TestResult, TestSuite and TestCaller | ||||
|  * | ||||
|  */ | ||||
| class CppUnit_API TestCase: public Test | ||||
| { | ||||
|     REFERENCEOBJECT (TestCase) | ||||
|  | ||||
| public: | ||||
| 	TestCase(const std::string& Name); | ||||
| 	~TestCase(); | ||||
|  | ||||
| 	virtual void run(TestResult* result); | ||||
| 	virtual TestResult* run(); | ||||
| 	virtual int countTestCases(); | ||||
| 	const std::string& name() const; | ||||
| 	std::string toString(); | ||||
|  | ||||
| 	virtual void setUp(); | ||||
| 	virtual void tearDown(); | ||||
|  | ||||
| protected: | ||||
| 	virtual void runTest(); | ||||
| 	TestResult* defaultResult(); | ||||
| 	 | ||||
| 	void assertImplementation(bool condition, | ||||
| 	                          const std::string& conditionExpression = "", | ||||
| 	                          long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                          const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void loop1assertImplementation(bool condition, | ||||
| 	                               const std::string& conditionExpression = "", | ||||
| 	                               long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
|                                    long dataLineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                               const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void loop2assertImplementation(bool condition, | ||||
| 	                               const std::string& conditionExpression = "", | ||||
| 	                               long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
|                                    long data1LineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
|                                    long data2LineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                               const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void assertEquals(long expected, | ||||
| 	                  long actual, | ||||
| 	                  long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                  const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void assertEquals(double expected, | ||||
| 	                  double actual, | ||||
|                       double delta, | ||||
|                       long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
|                       const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void assertEquals(const std::string& expected,  | ||||
| 	                  const std::string& actual, | ||||
| 	                  long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                  const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void assertEquals(const void* expected, | ||||
| 	                  const void* actual, | ||||
| 	                  long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                  const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	std::string notEqualsMessage(long expected, long actual); | ||||
| 	std::string notEqualsMessage(double expected, double actual); | ||||
| 	std::string notEqualsMessage(const void* expected, const void* actual); | ||||
| 	std::string notEqualsMessage(const std::string& expected, const std::string& actual); | ||||
|  | ||||
| 	void assertNotNull(const void* pointer, | ||||
| 	                   const std::string& pointerExpression = "", | ||||
| 	                   long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                   const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void assertNull(const void* pointer,   | ||||
| 	                const std::string& pointerExpression = "", | ||||
| 	                long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	                const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| 	void fail(const std::string&message = "", | ||||
| 	          long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, | ||||
| 	          const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); | ||||
|  | ||||
| private: | ||||
| 	const std::string _name; | ||||
| }; | ||||
|  | ||||
|  | ||||
| // Constructs a test case | ||||
| inline TestCase::TestCase(const std::string& name): _name (name) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Destructs a test case | ||||
| inline TestCase::~TestCase() | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns a count of all the tests executed | ||||
| inline int TestCase::countTestCases() | ||||
| { | ||||
| 	return 1;  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns the name of the test case | ||||
| inline const std::string& TestCase::name() const | ||||
| { | ||||
| 	return _name;  | ||||
| } | ||||
|  | ||||
|  | ||||
| // A hook for fixture set up | ||||
| inline void TestCase::setUp() | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // A hook for fixture tear down | ||||
| inline void TestCase::tearDown() | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns the name of the test case instance | ||||
| inline std::string TestCase::toString() | ||||
| { | ||||
| 	const std::type_info& thisClass = typeid(*this);  | ||||
| 	return std::string(thisClass.name()) + "." + name();  | ||||
| } | ||||
|  | ||||
|  | ||||
| // 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. | ||||
| #undef assert | ||||
| #define assert(condition) \ | ||||
| 	(this->assertImplementation((condition), (#condition), __LINE__, __FILE__)) | ||||
|  | ||||
| #define loop_1_assert(data1line, condition) \ | ||||
| 	(this->loop1assertImplementation((condition), (#condition), __LINE__, data1line, __FILE__)) | ||||
|  | ||||
| #define loop_2_assert(data1line, data2line, condition) \ | ||||
| 	(this->loop2assertImplementation((condition), (#condition), __LINE__, data1line, data2line, __FILE__)) | ||||
|  | ||||
| #define assertEqualDelta(expected, actual, delta) \ | ||||
| 	(this->assertEquals((expected), (actual), (delta), __LINE__, __FILE__)) | ||||
|  | ||||
| #define assertEqual(expected, actual) \ | ||||
| 	(this->assertEquals((expected), (actual), __LINE__, __FILE__)) | ||||
|  | ||||
| #define assertNullPtr(ptr) \ | ||||
| 	(this->assertNull((ptr), #ptr, __LINE__, __FILE__)) | ||||
| 	 | ||||
| #define assertNotNullPtr(ptr) \ | ||||
| 	(this->assertNotNull((ptr), #ptr, __LINE__, __FILE__)) | ||||
|  | ||||
| #define failmsg(msg) \ | ||||
| 	(this->fail(msg, __LINE__, __FILE__)) | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestCase_INCLUDED | ||||
							
								
								
									
										52
									
								
								CppUnit/include/CppUnit/TestDecorator.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								CppUnit/include/CppUnit/TestDecorator.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| // | ||||
| // TestDecorator.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestDecorator.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestDecorator_INCLUDED | ||||
| #define CppUnit_TestDecorator_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/Guards.h" | ||||
| #include "CppUnit/Test.h" | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class TestResult; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A Decorator for Tests | ||||
|  * | ||||
|  * Does not assume ownership of the test it decorates | ||||
|  * | ||||
|  */ | ||||
| class CppUnit_API TestDecorator: public Test | ||||
| { | ||||
| 	REFERENCEOBJECT(TestDecorator) | ||||
|  | ||||
| public: | ||||
| 	TestDecorator(Test* test); | ||||
|  | ||||
| 	virtual ~TestDecorator(); | ||||
|  | ||||
| 	int countTestCases(); | ||||
|  | ||||
| 	void run(TestResult* result); | ||||
|  | ||||
| 	std::string toString(); | ||||
|  | ||||
| protected: | ||||
| 	Test* _test; | ||||
| }; | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestDecorator_INCLUDED | ||||
							
								
								
									
										86
									
								
								CppUnit/include/CppUnit/TestFailure.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								CppUnit/include/CppUnit/TestFailure.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,86 @@ | ||||
| // | ||||
| // TestFailure.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestFailure.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestFailure_INCLUDED | ||||
| #define CppUnit_TestFailure_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/CppUnitException.h" | ||||
| #include "CppUnit/Guards.h" | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class Test; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A TestFailure collects a failed test together with | ||||
|  * the caught exception. | ||||
|  * | ||||
|  * TestFailure assumes lifetime control for any exception | ||||
|  * passed to it.  The lifetime of tests is handled by | ||||
|  * their TestSuite (if they have been added to one) or | ||||
|  * whomever creates them. | ||||
|  * | ||||
|  * see TestResult | ||||
|  * see TestSuite | ||||
|  * | ||||
|  */ | ||||
| class CppUnit_API TestFailure | ||||
| { | ||||
| 	REFERENCEOBJECT (TestFailure) | ||||
|  | ||||
| public: | ||||
| 	TestFailure(Test* failedTest, CppUnitException* thrownException); | ||||
| 	~TestFailure(); | ||||
|  | ||||
| 	Test* failedTest(); | ||||
| 	CppUnitException* thrownException(); | ||||
| 	std::string toString(); | ||||
|  | ||||
| protected: | ||||
| 	Test* _failedTest; | ||||
| 	CppUnitException *_thrownException; | ||||
| }; | ||||
|  | ||||
|  | ||||
| // Constructs a TestFailure with the given test and exception. | ||||
| inline TestFailure::TestFailure(Test* failedTest, CppUnitException* thrownException): _failedTest(failedTest), _thrownException(thrownException) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Deletes the owned exception. | ||||
| inline TestFailure::~TestFailure() | ||||
| {  | ||||
| 	delete _thrownException; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Gets the failed test. | ||||
| inline Test* TestFailure::failedTest() | ||||
| { | ||||
| 	return _failedTest; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Gets the thrown exception. | ||||
| inline CppUnitException* TestFailure::thrownException() | ||||
| { | ||||
| 	return _thrownException; | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestFailure_INCLUDED | ||||
|  | ||||
|  | ||||
							
								
								
									
										231
									
								
								CppUnit/include/CppUnit/TestResult.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										231
									
								
								CppUnit/include/CppUnit/TestResult.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,231 @@ | ||||
| // | ||||
| // TestResult.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestResult.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestResult_INCLUDED | ||||
| #define CppUnit_TestResult_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/Guards.h" | ||||
| #include "CppUnit/TestFailure.h" | ||||
| #include <vector> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class CppUnitException; | ||||
| class Test; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A TestResult 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. | ||||
|  * | ||||
|  * 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 | ||||
|  */ | ||||
| class CppUnit_API TestResult | ||||
| { | ||||
| 	REFERENCEOBJECT (TestResult) | ||||
|  | ||||
| public: | ||||
| 	TestResult(); | ||||
| 	virtual ~TestResult(); | ||||
|  | ||||
| 	virtual void addError(Test* test, CppUnitException* e); | ||||
| 	virtual void addFailure(Test* test, CppUnitException* e); | ||||
| 	virtual void startTest(Test* test); | ||||
| 	virtual void endTest(Test* test); | ||||
| 	virtual int runTests(); | ||||
| 	virtual int testErrors(); | ||||
| 	virtual int testFailures(); | ||||
| 	virtual bool wasSuccessful(); | ||||
| 	virtual bool shouldStop(); | ||||
| 	virtual void stop(); | ||||
|  | ||||
| 	virtual std::vector<TestFailure*>& errors(); | ||||
| 	virtual std::vector<TestFailure*>& failures(); | ||||
|  | ||||
| 	class SynchronizationObject | ||||
| 	{ | ||||
| 	public: | ||||
| 		SynchronizationObject() | ||||
| 		{ | ||||
| 		} | ||||
| 		 | ||||
| 		virtual ~SynchronizationObject() | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		virtual void lock() | ||||
| 		{ | ||||
| 		} | ||||
| 		 | ||||
| 		virtual void unlock() | ||||
| 		{ | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	class ExclusiveZone | ||||
| 	{ | ||||
| 		SynchronizationObject* m_syncObject; | ||||
|  | ||||
| 	public: | ||||
| 		ExclusiveZone(SynchronizationObject* syncObject): m_syncObject(syncObject) | ||||
| 		{ | ||||
| 			m_syncObject->lock(); | ||||
| 		} | ||||
|  | ||||
| 		~ExclusiveZone() | ||||
| 		{ | ||||
| 			m_syncObject->unlock(); | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| protected: | ||||
| 	virtual void setSynchronizationObject(SynchronizationObject* syncObject); | ||||
|  | ||||
| 	std::vector<TestFailure*> _errors; | ||||
| 	std::vector<TestFailure*> _failures; | ||||
| 	int _runTests; | ||||
| 	bool _stop; | ||||
| 	SynchronizationObject* _syncObject; | ||||
|  | ||||
| }; | ||||
|  | ||||
|  | ||||
| // Construct a TestResult | ||||
| inline TestResult::TestResult(): _syncObject(new SynchronizationObject()) | ||||
| { | ||||
| 	_runTests = 0;  | ||||
| 	_stop = false; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Adds an error to the list of errors. The passed in exception | ||||
| // caused the error | ||||
| inline void TestResult::addError(Test* test, CppUnitException* e) | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	_errors.push_back(new TestFailure(test, e)); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Adds a failure to the list of failures. The passed in exception | ||||
| // caused the failure. | ||||
| inline void TestResult::addFailure(Test* test, CppUnitException* e) | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	_failures.push_back(new TestFailure(test, e)); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Informs the result that a test will be started. | ||||
| inline void TestResult::startTest(Test* test) | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	_runTests++; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Informs the result that a test was completed. | ||||
| inline void TestResult::endTest(Test* test) | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Gets the number of run tests. | ||||
| inline int TestResult::runTests() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return _runTests; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Gets the number of detected errors. | ||||
| inline int TestResult::testErrors() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return (int) _errors.size(); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Gets the number of detected failures. | ||||
| inline int TestResult::testFailures() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return (int) _failures.size(); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns whether the entire test was successful or not. | ||||
| inline bool TestResult::wasSuccessful() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return _failures.size() == 0 && _errors.size () == 0;  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns a std::vector of the errors. | ||||
| inline std::vector<TestFailure*>& TestResult::errors() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return _errors; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns a std::vector of the failures. | ||||
| inline std::vector<TestFailure*>& TestResult::failures() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return _failures; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns whether testing should be stopped | ||||
| inline bool TestResult::shouldStop() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	return _stop; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Stop testing | ||||
| inline void TestResult::stop() | ||||
| { | ||||
| 	ExclusiveZone zone(_syncObject);  | ||||
| 	_stop = true; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Accept a new synchronization object for protection of this instance | ||||
| // TestResult assumes ownership of the object | ||||
| inline void TestResult::setSynchronizationObject(SynchronizationObject* syncObject) | ||||
| { | ||||
| 	delete _syncObject;  | ||||
| 	_syncObject = syncObject; | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestResult_INCLUDED | ||||
							
								
								
									
										103
									
								
								CppUnit/include/CppUnit/TestRunner.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								CppUnit/include/CppUnit/TestRunner.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,103 @@ | ||||
| // | ||||
| // TestRunner.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestRunner.h#2 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestRunner_INCLUDED | ||||
| #define CppUnit_TestRunner_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include <vector> | ||||
| #include <string> | ||||
| #include <ostream> | ||||
| #if defined(POCO_VXWORKS) | ||||
| #include <cstdarg> | ||||
| #endif | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class Test; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A command line based tool to run tests. | ||||
|  * TestRunner expects as its only argument the name of a TestCase class. | ||||
|  * TestRunner prints out a trace as the tests are executed followed by a | ||||
|  * summary at the end. | ||||
|  * | ||||
|  * You can add to the tests that the TestRunner knows about by | ||||
|  * making additional calls to "addTest (...)" in main. | ||||
|  * | ||||
|  * Here is the synopsis: | ||||
|  * | ||||
|  * TestRunner [-all] [-print] [-wait] ExampleTestCase | ||||
|  * | ||||
|  */ | ||||
| class CppUnit_API TestRunner | ||||
| { | ||||
| 	typedef std::pair<std::string, Test*> Mapping; | ||||
| 	typedef std::vector<Mapping> Mappings; | ||||
|  | ||||
| public: | ||||
| 	TestRunner(); | ||||
| 	TestRunner(std::ostream& ostr); | ||||
| 	~TestRunner(); | ||||
|  | ||||
| 	bool run(const std::vector<std::string>& args); | ||||
| 	void addTest(const std::string& name, Test* test); | ||||
|  | ||||
| protected: | ||||
| 	bool run(Test* test); | ||||
| 	void printBanner(); | ||||
| 	void print(const std::string& name, Test* pTest, int indent); | ||||
| 	Test* find(const std::string& name, Test* pTest, const std::string& testName); | ||||
|  | ||||
| private: | ||||
| 	std::ostream& _ostr; | ||||
| 	Mappings _mappings; | ||||
| }; | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #if defined(POCO_VXWORKS) | ||||
| #define CppUnitMain(testCase) \ | ||||
| 	int testCase##Runner(const char* arg0, ...) \ | ||||
| 	{ \ | ||||
| 		std::vector<std::string> args; \ | ||||
| 		args.push_back(#testCase "Runner"); \ | ||||
| 		args.push_back(std::string(arg0)); \ | ||||
| 		va_list vargs; \ | ||||
| 		va_start(vargs, arg0); \ | ||||
| 		const char* arg = va_arg(vargs, const char*); \ | ||||
| 		while (arg) \ | ||||
| 		{ \ | ||||
| 			args.push_back(std::string(arg)); \ | ||||
| 			arg = va_arg(vargs, const char*); \ | ||||
| 		} \ | ||||
| 		va_end(vargs); \ | ||||
| 		CppUnit::TestRunner runner; \ | ||||
| 		runner.addTest(#testCase, testCase::suite()); \ | ||||
| 		return runner.run(args) ? 0 : 1; \ | ||||
| 	} | ||||
| #else | ||||
| #define CppUnitMain(testCase) \ | ||||
| 	int main(int ac, char **av)							\ | ||||
| 	{													\ | ||||
| 		std::vector<std::string> args;					\ | ||||
| 		for (int i = 0; i < ac; ++i)					\ | ||||
| 			args.push_back(std::string(av[i]));			\ | ||||
| 		CppUnit::TestRunner runner;						\ | ||||
| 		runner.addTest(#testCase, testCase::suite());	\ | ||||
| 		return runner.run(args) ? 0 : 1;				\ | ||||
| 	} | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestRunner_INCLUDED | ||||
							
								
								
									
										57
									
								
								CppUnit/include/CppUnit/TestSetup.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								CppUnit/include/CppUnit/TestSetup.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | ||||
| // | ||||
| // TestSetup.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestSetup.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestSetup_INCLUDED | ||||
| #define CppUnit_TestSetup_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/Guards.h" | ||||
| #include "CppUnit/TestDecorator.h" | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class Test; | ||||
| class TestResult; | ||||
|  | ||||
|  | ||||
| class CppUnit_API TestSetup: public TestDecorator | ||||
| { | ||||
| 	REFERENCEOBJECT (TestSetup) | ||||
|  | ||||
| public: | ||||
| 	TestSetup(Test* test): TestDecorator(test)  | ||||
| 	{ | ||||
| 	} | ||||
| 	 | ||||
| 	void run(TestResult* result); | ||||
|  | ||||
| protected: | ||||
| 	void setUp()  | ||||
| 	{ | ||||
| 	} | ||||
| 	 | ||||
| 	void tearDown() | ||||
| 	{ | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|  | ||||
| inline void TestSetup::run(TestResult* result) | ||||
| { | ||||
| 	setUp(); | ||||
| 	TestDecorator::run(result);  | ||||
| 	tearDown(); | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestSetup_INCLUDED | ||||
							
								
								
									
										98
									
								
								CppUnit/include/CppUnit/TestSuite.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								CppUnit/include/CppUnit/TestSuite.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | ||||
| // | ||||
| // TestSuite.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TestSuite.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TestSuite_INCLUDED | ||||
| #define CppUnit_TestSuite_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/Guards.h" | ||||
| #include "CppUnit/Test.h" | ||||
| #include <vector> | ||||
| #include <string> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class TestResult; | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * A TestSuite is a Composite of Tests. | ||||
|  * It runs a collection of test cases. Here is an example. | ||||
|  * | ||||
|  * TestSuite *suite= new TestSuite(); | ||||
|  * suite->addTest(new TestCaller<MathTest> ("testAdd", testAdd)); | ||||
|  * suite->addTest(new TestCaller<MathTest> ("testDivideByZero", testDivideByZero)); | ||||
|  * | ||||
|  * Note that TestSuites assume lifetime | ||||
|  * control for any tests added to them. | ||||
|  * | ||||
|  * see Test and TestCaller | ||||
|  */ | ||||
| class CppUnit_API TestSuite: public Test | ||||
| { | ||||
| 	REFERENCEOBJECT (TestSuite) | ||||
|  | ||||
| public: | ||||
| 	TestSuite(const std::string& name = ""); | ||||
| 	~TestSuite(); | ||||
|  | ||||
| 	void run(TestResult* result); | ||||
| 	int countTestCases(); | ||||
| 	void addTest(Test* test); | ||||
| 	std::string toString(); | ||||
|  | ||||
| 	virtual void deleteContents(); | ||||
| 	 | ||||
| 	const std::vector<Test*> tests() const; | ||||
|  | ||||
| private: | ||||
| 	std::vector<Test*> _tests; | ||||
| 	const std::string _name; | ||||
| }; | ||||
|  | ||||
|  | ||||
| // Default constructor | ||||
| inline TestSuite::TestSuite(const std::string& name): _name(name) | ||||
| { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Destructor | ||||
| inline TestSuite::~TestSuite() | ||||
| { | ||||
| 	deleteContents(); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Adds a test to the suite. | ||||
| inline void TestSuite::addTest(Test* test) | ||||
| { | ||||
| 	_tests.push_back(test); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns a std::string representation of the test suite. | ||||
| inline std::string TestSuite::toString() | ||||
| { | ||||
| 	return "suite " + _name;  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns all tests | ||||
| inline const std::vector<Test*> TestSuite::tests() const | ||||
| { | ||||
| 	return _tests; | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TestSuite_INCLUDED | ||||
							
								
								
									
										53
									
								
								CppUnit/include/CppUnit/TextTestResult.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								CppUnit/include/CppUnit/TextTestResult.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| // | ||||
| // TextTestResult.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/TextTestResult.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_TextTestResult_INCLUDED | ||||
| #define CppUnit_TextTestResult_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include "CppUnit/TestResult.h" | ||||
| #include <ostream> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| class CppUnit_API TextTestResult: public TestResult | ||||
| { | ||||
| public: | ||||
| 	TextTestResult(); | ||||
| 	TextTestResult(std::ostream& ostr); | ||||
| 	 | ||||
| 	virtual void addError(Test* test, CppUnitException* e); | ||||
| 	virtual void addFailure(Test* test, CppUnitException* e); | ||||
| 	virtual void startTest(Test* test); | ||||
| 	virtual void print(std::ostream& stream); | ||||
| 	virtual void printErrors(std::ostream& stream); | ||||
| 	virtual void printFailures(std::ostream& stream); | ||||
| 	virtual void printHeader(std::ostream& stream); | ||||
| 	 | ||||
| protected: | ||||
| 	std::string shortName(const std::string& testName); | ||||
| 	 | ||||
| private: | ||||
| 	std::ostream& _ostr; | ||||
| }; | ||||
|  | ||||
|  | ||||
| /* insertion operator for easy output */ | ||||
| inline std::ostream& operator<< (std::ostream& stream, TextTestResult& result) | ||||
| { | ||||
| 	result.print(stream); | ||||
| 	return stream; | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_TextTestResult_INCLUDED | ||||
							
								
								
									
										73
									
								
								CppUnit/include/CppUnit/estring.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								CppUnit/include/CppUnit/estring.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| // | ||||
| // estring.h | ||||
| // | ||||
| // $Id: //poco/1.4/CppUnit/include/CppUnit/estring.h#1 $ | ||||
| // | ||||
|  | ||||
|  | ||||
| #ifndef CppUnit_estring_INCLUDED | ||||
| #define CppUnit_estring_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "CppUnit/CppUnit.h" | ||||
| #include <string> | ||||
| #include <stdio.h> | ||||
|  | ||||
|  | ||||
| namespace CppUnit { | ||||
|  | ||||
|  | ||||
| // Create a std::string from a const char pointer | ||||
| inline std::string estring(const char *cstring) | ||||
| { | ||||
| 	return std::string(cstring); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Create a std::string from a std::string (for uniformities' sake) | ||||
| inline std::string estring(std::string& expandedString) | ||||
| { | ||||
| 	return expandedString; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Create a std::string from an int | ||||
| inline std::string estring(int number) | ||||
| { | ||||
| 	char buffer[50];  | ||||
| 	sprintf(buffer, "%d", number);  | ||||
| 	return std::string (buffer);  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Create a string from a long | ||||
| inline std::string estring(long number) | ||||
| { | ||||
| 	char buffer[50];  | ||||
| 	sprintf(buffer, "%ld", number);  | ||||
| 	return std::string (buffer);  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Create a std::string from a double | ||||
| inline std::string estring(double number) | ||||
| { | ||||
| 	char buffer[50];  | ||||
| 	sprintf(buffer, "%lf", number);  | ||||
| 	return std::string(buffer); | ||||
| } | ||||
|  | ||||
|  | ||||
| // Create a std::string from a double | ||||
| inline std::string estring(const void* ptr) | ||||
| { | ||||
| 	char buffer[50];  | ||||
| 	sprintf(buffer, "%p", ptr);  | ||||
| 	return std::string(buffer); | ||||
| } | ||||
|  | ||||
|  | ||||
| } // namespace CppUnit | ||||
|  | ||||
|  | ||||
| #endif // CppUnit_estring_INCLUDED | ||||
		Reference in New Issue
	
	Block a user
	 Aleksandar Fabijanic
					Aleksandar Fabijanic