Thread: [Opal-commits] opal/src/external/quicktest quicktest.h,1.8,1.9
Status: Inactive
Brought to you by:
tylerstreeter
|
From: Olex <ole...@us...> - 2005-12-11 04:43:13
|
Update of /cvsroot/opal/opal/src/external/quicktest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4690/src/external/quicktest Modified Files: quicktest.h Log Message: Fixes for Windows linking. Index: quicktest.h =================================================================== RCS file: /cvsroot/opal/opal/src/external/quicktest/quicktest.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** quicktest.h 10 Dec 2005 05:18:35 -0000 1.8 --- quicktest.h 11 Dec 2005 04:43:05 -0000 1.9 *************** *** 24,29 **** *************************************************************************/ - - // Credits: // Thanks to Noel Llopis for his helpful comparison of various C++ unit --- 24,27 ---- *************** *** 45,461 **** - // ----------------------------------------------------------------------- - // Design Notes - // ----------------------------------------------------------------------- - // * Each test automatically registers itself by accessing the TestManager - // singleton. - // - // * There are no formal fixtures. Fixtures are simply user-defined - // objects. setup and teardown occur in the user-defined object's - // constructor and destructor. Tests that need fixtures should staticly - // allocate one of these objects at the beginning of the test. This method - // is flexible and conceptually simple. - - namespace quicktest - { - typedef std::vector<std::string> TestResult; - - class Test - { - public: - Test( const std::string& testGroup, const std::string& testName ) - { - mTestName = testName; - mTestGroup = testGroup; - } - - virtual ~Test() {} - - const std::string & getGroup() { return mTestGroup; } - - virtual void run( TestResult& result ) = 0; - - protected: - void recordFailure( TestResult& result, const std::string& file, - unsigned long int line, const std::string& message ) - { - // If the full filename is too long, only use the last part. - std::string fileStr = file; - size_t maxLength = 40; - size_t fileLength = file.size(); - if ( fileLength > maxLength ) - { - // Get the last maxLength characters - 3 (leave room for - // three ellipses at the beginning). - fileStr = "..."; - fileStr += file.substr( fileLength - maxLength + 3, - fileLength - 1 ); - } - - std::ostringstream oss; - oss << fileStr << "(" << line << "): '" << mTestName - << "' FAILED: " << message; - result.push_back( oss.str() ); - } - - /// The unique name of this test. - std::string mTestName; - - /// The group name of this test - std::string mTestGroup; - - /// helper method - static bool areEqual(double x, double y) - { - const double EPSILON = 0.00001; - double maxVal = 1; - - if (fabs(static_cast<double>(x)) > maxVal) - { - maxVal = fabs(x); - } - - if (fabs(static_cast<double>(y)) > maxVal) - { - maxVal = fabs(static_cast<double>(y)); - } - - if (fabs(static_cast<double>(x - y)) <= EPSILON * maxVal) - { - return true; - } - else - { - return false; - } - } - }; - - class TestManager - { - public: - static TestManager& instance() - { - static TestManager self; - return self; - } - - void addTest( Test* test ) - { - mTests.push_back( test ); - } - - void setOutputStream( std::ostream* stream ) - { - mOutputStream = stream; - } - - std::ostream* getOutputStream() - { - return mOutputStream; - } - - void runTests() - { - unsigned int numFailures = 0; - - *getOutputStream() - << "[---------------- RUNNING TESTS ----------------]" - << std::endl; - - unsigned int numLocalFailures = 0; - unsigned int numLocalSuccesses = 0; - - std::string currentGroup; - std::vector<Test*>::iterator iter; - for ( iter = mTests.begin(); iter != mTests.end(); ++iter ) - { - if ( currentGroup != ( *iter ) ->getGroup() ) - { - if ( !currentGroup.empty() ) - { - *getOutputStream() << "Group results: " - << numLocalSuccesses << " succeeded, " - << numLocalFailures << " failed" - << std::endl; - } - - currentGroup = ( *iter ) ->getGroup(); - - *getOutputStream() << - "Group: " << ( *iter ) ->getGroup() - << std::endl; - - numLocalFailures = 0; - numLocalSuccesses = 0; - } - - ( *iter ) ->run( mResult ); - - bool testFailed = false; - - size_t size = mResult.size(); - for ( size_t i = 0; i < size; ++i ) - { - *getOutputStream() << mResult.at( i ) << std::endl; - testFailed = true; - } - mResult.clear(); - - if ( testFailed ) - { - ++numFailures; - ++numLocalFailures; - } - else - { - ++numLocalSuccesses; - } - } - - if ( !currentGroup.empty() ) - { - *getOutputStream() << "Group results: " - << numLocalSuccesses << " succeeded, " - << numLocalFailures << " failed" - << std::endl; - } - - *getOutputStream() << "Overall results: " << ( unsigned int ) mTests.size() - - numFailures << " succeeded, " << numFailures << " failed" - << std::endl; - - *getOutputStream() - << "[---------------- TESTS FINISHED ---------------]" - << std::endl; - } - - private: - TestManager() - { - mOutputStream = &std::cout; - } - - ~TestManager() - {} - - /// List of pointers to Tests. All tests are staticly allocated, - /// so we don't need to destroy them manually. - std::vector<Test*> mTests; - - std::ostream* mOutputStream; - - TestResult mResult; - }; - } - - /// Macro to define a single test without using a fixture. - #define QT_TEST(testName)\ class testName##Test : public quicktest::Test\ --- 43,252 ---- *************** *** 473,477 **** /// Macro that runs all tests. - #define QT_RUN_TESTS quicktest::TestManager::instance().runTests() --- 264,267 ---- *************** *** 479,490 **** /// Macro that sets the output stream to use. - #define QT_SET_OUTPUT(stream)\ quicktest::TestManager::instance().setOutputStream(stream) - /// Checks whether the given condition is true. - #define QT_CHECK(condition)\ {\ --- 269,277 ---- *************** *** 499,503 **** /// Checks whether the first parameter is equal to the second. - #define QT_CHECK_EQUAL(value1, value2)\ {\ --- 286,289 ---- *************** *** 514,520 **** - /// Checks whether the first parameter is not equal to the second. - #define QT_CHECK_NOT_EQUAL(value1, value2)\ {\ --- 300,304 ---- *************** *** 530,540 **** - /// Checks whether the first parameter is within the given tolerance from - /// the second parameter. This is useful for comparing floating point - /// values. - #define QT_CHECK_CLOSE(value1, value2)\ {\ --- 314,320 ---- *************** *** 554,558 **** #define QT_CHECK_CLOSE_CUSTOM(value1, value2, tolerance)\ {\ ! if (abs((value1)-(value2)) > tolerance)\ {\ std::ostringstream oss;\ --- 334,338 ---- #define QT_CHECK_CLOSE_CUSTOM(value1, value2, tolerance)\ {\ ! if (fabs((value1)-(value2)) > tolerance)\ {\ std::ostringstream oss;\ *************** *** 565,569 **** /// Checks whether the first parameter is less than the second. - #define QT_CHECK_LESS(value1, value2)\ {\ --- 345,348 ---- *************** *** 579,585 **** - /// Checks whether the first parameter is less than or equal to the second. - #define QT_CHECK_LESS_OR_EQUAL(value1, value2)\ {\ --- 358,362 ---- *************** *** 594,601 **** } - - /// Checks whether the first parameter is greater than the second. - #define QT_CHECK_GREATER(value1, value2)\ {\ --- 371,375 ---- *************** *** 611,619 **** - /// Checks whether the first parameter is greater than or equal to the - /// second. - #define QT_CHECK_GREATER_OR_EQUAL(value1, value2)\ {\ --- 385,390 ---- *************** *** 628,635 **** } - - /// Fails unconditionally and prints the given message. - #define QT_FAIL(message)\ {\ --- 399,403 ---- *************** *** 638,645 **** }\ - - /// Prints the given message, followed by a carriage return. - #define QT_PRINT(message)\ {\ --- 406,410 ---- *************** *** 648,652 **** }\ - #endif - --- 413,415 ---- |