[Opal-commits] opal/src/external/quicktest quicktest.h,1.3,1.4
Status: Inactive
Brought to you by:
tylerstreeter
|
From: Olex <ole...@us...> - 2005-12-01 02:05:04
|
Update of /cvsroot/opal/opal/src/external/quicktest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9152/src/external/quicktest Modified Files: quicktest.h Log Message: Implemented Solid::setMass, added unit tests to test it. Added missing Point3r implementation file. Index: quicktest.h =================================================================== RCS file: /cvsroot/opal/opal/src/external/quicktest/quicktest.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** quicktest.h 21 Nov 2005 13:59:16 -0000 1.3 --- quicktest.h 1 Dec 2005 02:04:54 -0000 1.4 *************** *** 1,26 **** /************************************************************************* ! * * ! * QuickTest * ! * Copyright (C) 2005 * ! * Tyler Streeter tyl...@gm... * ! * All rights reserved. * ! * Web: quicktest.sourceforge.net * ! * * ! * This library is free software; you can redistribute it and/or * ! * modify it under the terms of EITHER: * ! * (1) The GNU Lesser General Public License as published by the Free * ! * Software Foundation; either version 2.1 of the License, or (at * ! * your option) any later version. The text of the GNU Lesser * ! * General Public License is included with this library in the * ! * file license-LGPL.txt. * ! * (2) The BSD-style license that is included with this library in * ! * the file license-BSD.txt. * ! * * ! * This library is distributed in the hope that it will be useful, * ! * but WITHOUT ANY WARRANTY; without even the implied warranty of * ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * ! * license-LGPL.txt and license-BSD.txt for more details. * ! * * ! *************************************************************************/ // Credits: --- 1,26 ---- /************************************************************************* ! * * ! * QuickTest * ! * Copyright (C) 2005 * ! * Tyler Streeter tyl...@gm... * ! * All rights reserved. * ! * Web: quicktest.sourceforge.net * ! * * ! * This library is free software; you can redistribute it and/or * ! * modify it under the terms of EITHER: * ! * (1) The GNU Lesser General Public License as published by the Free * ! * Software Foundation; either version 2.1 of the License, or (at * ! * your option) any later version. The text of the GNU Lesser * ! * General Public License is included with this library in the * ! * file license-LGPL.txt. * ! * (2) The BSD-style license that is included with this library in * ! * the file license-BSD.txt. * ! * * ! * This library is distributed in the hope that it will be useful, * ! * but WITHOUT ANY WARRANTY; without even the implied warranty of * ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * ! * license-LGPL.txt and license-BSD.txt for more details. * ! * * ! *************************************************************************/ // Credits: *************** *** 53,233 **** namespace quicktest { ! typedef std::vector<std::string> TestResult; ! class Test ! { ! public: ! Test(const std::string& testGroup, const std::string& testName) ! { ! mTestName = testName; ! mTestGroup = testGroup; ! } ! 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; ! }; ! 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\ ! {\ ! public:\ ! testName##Test()\ ! : Test(__FILE__, #testName)\ ! {\ ! quicktest::TestManager::instance().addTest(this);\ ! }\ ! void run(quicktest::TestResult& _result);\ ! }testName##Instance;\ ! void testName##Test::run(quicktest::TestResult& _result) /// Macro that runs all tests. --- 53,234 ---- 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; ! }; ! 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\ ! {\ ! public:\ ! testName##Test()\ ! : Test(__FILE__, #testName)\ ! {\ ! quicktest::TestManager::instance().addTest(this);\ ! }\ ! void run(quicktest::TestResult& _result);\ ! }testName##Instance;\ ! void testName##Test::run(quicktest::TestResult& _result) /// Macro that runs all tests. *************** *** 236,274 **** /// 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)\ ! {\ ! if (!(condition))\ ! {\ ! recordFailure(_result, __FILE__, __LINE__, #condition);\ ! }\ ! } /// Checks whether the first parameter is equal to the second. #define QT_CHECK_EQUAL(value1, value2)\ ! {\ ! if ((value1) != (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1:" << std::endl << "(" << (value1) << ")" \ ! << std::endl << "should equal value2:" \ ! << std::endl << "(" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is not equal to the second. #define QT_CHECK_NOT_EQUAL(value1, value2)\ ! {\ ! if ((value1) == (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should not equal "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is within the given tolerance from --- 237,275 ---- /// 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)\ ! {\ ! if (!(condition))\ ! {\ ! recordFailure(_result, __FILE__, __LINE__, #condition);\ ! }\ ! } /// Checks whether the first parameter is equal to the second. #define QT_CHECK_EQUAL(value1, value2)\ ! {\ ! if ((value1) != (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1:" << std::endl << "(" << (value1) << ")" \ ! << std::endl << "should equal value2:" \ ! << std::endl << "(" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is not equal to the second. #define QT_CHECK_NOT_EQUAL(value1, value2)\ ! {\ ! if ((value1) == (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should not equal "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is within the given tolerance from *************** *** 276,350 **** /// values. #define QT_CHECK_CLOSE(value1, value2, tolerance)\ ! {\ ! if (abs((value1)-(value2)) > tolerance)\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be close to "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is less than the second. #define QT_CHECK_LESS(value1, value2)\ ! {\ ! if ((value1) >= (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be less than "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is less than or equal to the second. #define QT_CHECK_LESS_OR_EQUAL(value1, value2)\ ! {\ ! if ((value1) > (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be less than or "\ ! << "equal to " << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is greater than the second. #define QT_CHECK_GREATER(value1, value2)\ ! {\ ! if ((value1) <= (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be greater than "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is greater than or equal to the /// second. #define QT_CHECK_GREATER_OR_EQUAL(value1, value2)\ ! {\ ! if ((value1) < (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be greater than or "\ ! << "equal to " << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Fails unconditionally and prints the given message. #define QT_FAIL(message)\ ! {\ ! recordFailure(_result, __FILE__, __LINE__, (message));\ ! }\ /// Prints the given message, followed by a carriage return. #define QT_PRINT(message)\ ! {\ ! *(quicktest::TestManager::instance().getOutputStream()) << (message)\ ! << std::endl;\ ! }\ #endif --- 277,351 ---- /// values. #define QT_CHECK_CLOSE(value1, value2, tolerance)\ ! {\ ! if (abs((value1)-(value2)) > tolerance)\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be close to "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is less than the second. #define QT_CHECK_LESS(value1, value2)\ ! {\ ! if ((value1) >= (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be less than "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is less than or equal to the second. #define QT_CHECK_LESS_OR_EQUAL(value1, value2)\ ! {\ ! if ((value1) > (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be less than or "\ ! << "equal to " << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is greater than the second. #define QT_CHECK_GREATER(value1, value2)\ ! {\ ! if ((value1) <= (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be greater than "\ ! << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Checks whether the first parameter is greater than or equal to the /// second. #define QT_CHECK_GREATER_OR_EQUAL(value1, value2)\ ! {\ ! if ((value1) < (value2))\ ! {\ ! std::ostringstream oss;\ ! oss << "value1 (" << (value1) << ") should be greater than or "\ ! << "equal to " << "value2 (" << (value2) << ")";\ ! recordFailure(_result, __FILE__, __LINE__, oss.str());\ ! }\ ! } /// Fails unconditionally and prints the given message. #define QT_FAIL(message)\ ! {\ ! recordFailure(_result, __FILE__, __LINE__, (message));\ ! }\ /// Prints the given message, followed by a carriage return. #define QT_PRINT(message)\ ! {\ ! *(quicktest::TestManager::instance().getOutputStream()) << (message)\ ! << std::endl;\ ! }\ #endif |