* fix gcc4 build of cppunit library by explicitly spelling out std:: in
the headers and importing the required classes in the implementation files * automatic whitespace cleanup git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30586 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,23 +14,23 @@
|
||||
class TestResult;
|
||||
|
||||
template <class TestClass, class ExpectedException = CppUnit::NoExceptionExpected>
|
||||
class CPPUNIT_API BThreadedTestCaller : public CppUnit::TestCase {
|
||||
class CPPUNIT_API BThreadedTestCaller : public CppUnit::TestCase {
|
||||
public:
|
||||
/*! \brief Pointer to a test function in the given class.
|
||||
Each ThreadMethod added with addThread() is run in its own thread.
|
||||
*/
|
||||
typedef void (TestClass::*ThreadMethod)();
|
||||
|
||||
BThreadedTestCaller(std::string name);
|
||||
BThreadedTestCaller(std::string name, TestClass &object);
|
||||
BThreadedTestCaller(std::string name, TestClass *object);
|
||||
BThreadedTestCaller(std::string name);
|
||||
BThreadedTestCaller(std::string name, TestClass &object);
|
||||
BThreadedTestCaller(std::string name, TestClass *object);
|
||||
virtual ~BThreadedTestCaller();
|
||||
|
||||
|
||||
virtual CppUnit::TestResult *run();
|
||||
virtual void run(CppUnit::TestResult *result);
|
||||
|
||||
//! Adds a thread to the test. \c threadName must be unique to this BThreadedTestCaller.
|
||||
void addThread(std::string threadName, ThreadMethod method);
|
||||
void addThread(std::string threadName, ThreadMethod method);
|
||||
|
||||
protected:
|
||||
virtual void setUp();
|
||||
@@ -42,9 +42,9 @@ protected:
|
||||
bool fOwnObject;
|
||||
TestClass *fObject;
|
||||
ThreadManagerMap fThreads;
|
||||
|
||||
|
||||
sem_id fThreadSem;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -78,19 +78,19 @@ BThreadedTestCaller<TestClass, ExpectedException>::BThreadedTestCaller(std::stri
|
||||
template <class TestClass, class ExpectedException>
|
||||
BThreadedTestCaller<TestClass, ExpectedException>::~BThreadedTestCaller() {
|
||||
if (fOwnObject)
|
||||
delete fObject;
|
||||
for (ThreadManagerMap::iterator it = fThreads.begin(); it != fThreads.end (); ++it) {
|
||||
delete fObject;
|
||||
for (typename ThreadManagerMap::iterator it = fThreads.begin(); it != fThreads.end (); ++it) {
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class TestClass, class ExpectedException>
|
||||
void
|
||||
BThreadedTestCaller<TestClass, ExpectedException>::addThread(std::string threadName, ThreadMethod method) {
|
||||
if (fThreads.find(threadName) == fThreads.end()) {
|
||||
// Unused name, go ahead and add
|
||||
fThreads[threadName] = new BThreadManager<TestClass, ExpectedException>(threadName, fObject, method, fThreadSem);
|
||||
fThreads[threadName] = new BThreadManager<TestClass, ExpectedException>(threadName, fObject, method, fThreadSem);
|
||||
} else {
|
||||
// Duplicate name, throw an exception
|
||||
throw CppUnit::Exception("BThreadedTestCaller::addThread() - Attempt to add thread under duplicated name ('"
|
||||
@@ -110,11 +110,11 @@ template <class TestClass, class ExpectedException>
|
||||
void
|
||||
BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *result) {
|
||||
result->startTest(this);
|
||||
|
||||
|
||||
if (fThreads.size() <= 0)
|
||||
throw CppUnit::Exception("BThreadedTestCaller::run() -- No threads added to BThreadedTestCaller()");
|
||||
|
||||
try {
|
||||
try {
|
||||
setUp();
|
||||
|
||||
// This try/catch block should never actually have to catch
|
||||
@@ -131,13 +131,13 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
// blocked; their output appears later...).
|
||||
//
|
||||
// Each thread will acquire the semaphore once when launched,
|
||||
// thus the initial thread count is equal the number of threads.
|
||||
// thus the initial thread count is equal the number of threads.
|
||||
fThreadSem = create_sem(fThreads.size(), "ThreadSem");
|
||||
if (fThreadSem < B_OK)
|
||||
throw CppUnit::Exception("BThreadedTestCaller::run() -- Error creating fThreadSem");
|
||||
throw CppUnit::Exception("BThreadedTestCaller::run() -- Error creating fThreadSem");
|
||||
|
||||
// Launch all the threads.
|
||||
for (ThreadManagerMap::iterator i = fThreads.begin();
|
||||
for (typename ThreadManagerMap::iterator i = fThreads.begin();
|
||||
i != fThreads.end ();
|
||||
++i)
|
||||
{
|
||||
@@ -146,7 +146,7 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
result->addError(this, new CppUnit::Exception("Error launching thread '" + i->second->getName() + "'"));
|
||||
// printf("Launch(%s)\n", i->second->getName().c_str());
|
||||
}
|
||||
|
||||
|
||||
// Now we loop. Before you faint, there is a reason for this:
|
||||
// Calls to NextSubTest() from other threads don't actually
|
||||
// print anything while the main thread is blocked waiting
|
||||
@@ -158,13 +158,13 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
// any pending updates, and tries to acquire the semaphore
|
||||
// again. When it finally manages to acquire it, all the
|
||||
// test threads have terminated, and it's safe to clean up.
|
||||
|
||||
|
||||
status_t err;
|
||||
do {
|
||||
// Try to acquire the semaphore
|
||||
err = acquire_sem_etc(fThreadSem, fThreads.size(), B_RELATIVE_TIMEOUT, 500000);
|
||||
|
||||
// Empty the UpdateList
|
||||
|
||||
// Empty the UpdateList
|
||||
std::vector<std::string> &list = fObject->AcquireUpdateList();
|
||||
for (std::vector<std::string>::iterator i = list.begin();
|
||||
i != list.end();
|
||||
@@ -172,16 +172,16 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
{
|
||||
// Only print to standard out if the current global shell
|
||||
// lets us (or if no global shell is designated).
|
||||
if (BTestShell::GlobalBeVerbose()) {
|
||||
if (BTestShell::GlobalBeVerbose()) {
|
||||
printf("%s", (*i).c_str());
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
list.clear();
|
||||
fObject->ReleaseUpdateList();
|
||||
|
||||
fObject->ReleaseUpdateList();
|
||||
|
||||
} while (err != B_OK);
|
||||
|
||||
|
||||
// If we get this far, we actually managed to acquire the semaphore,
|
||||
// so we should release it now.
|
||||
release_sem_etc(fThreadSem, fThreads.size(), 0);
|
||||
@@ -189,9 +189,9 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
// Print out a newline for asthetics :-)
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
// Wait for them all to finish, then clean up
|
||||
for (ThreadManagerMap::iterator i = fThreads.begin();
|
||||
i != fThreads.end ();
|
||||
@@ -206,21 +206,21 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
*/
|
||||
|
||||
fThreads.clear();
|
||||
|
||||
|
||||
} catch ( CppUnit::Exception &e ) {
|
||||
// Add on the a note that this exception was caught by the
|
||||
// thread caller (which is a bad thing), then note the exception
|
||||
CppUnit::Exception *threadException = new CppUnit::Exception(
|
||||
std::string(e.what()) + " (NOTE: caught by BThreadedTestCaller)",
|
||||
e.sourceLine()
|
||||
);
|
||||
);
|
||||
result->addFailure( fObject, threadException );
|
||||
}
|
||||
catch ( std::exception &e ) {
|
||||
// Add on the thread name, then note the exception
|
||||
CppUnit::Exception *threadException = new CppUnit::Exception(
|
||||
std::string(e.what()) + " (NOTE: caught by BThreadedTestCaller)"
|
||||
);
|
||||
);
|
||||
result->addError( fObject, threadException );
|
||||
}
|
||||
catch (...) {
|
||||
@@ -237,7 +237,7 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
tearDown();
|
||||
} catch (...) {
|
||||
result->addError(this, new CppUnit::Exception("tearDown() failed"));
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
result->addError(this, new CppUnit::Exception("setUp() failed"));
|
||||
} // setUp() try/catch block
|
||||
@@ -253,7 +253,7 @@ BThreadedTestCaller<TestClass, ExpectedException>::setUp() {
|
||||
throw CppUnit::Exception("BThreadedTestCaller::runTest() -- NULL fObject pointer");
|
||||
if (!fObject->RegisterForUse())
|
||||
throw CppUnit::Exception("BThreadedTestCaller::runTest() -- Attempt to reuse ThreadedTestCase object already in use");
|
||||
|
||||
|
||||
fObject->setUp();
|
||||
}
|
||||
|
||||
@@ -265,8 +265,8 @@ BThreadedTestCaller<TestClass, ExpectedException>::tearDown() {
|
||||
|
||||
template <class TestClass, class ExpectedException>
|
||||
std::string
|
||||
BThreadedTestCaller<TestClass, ExpectedException>::toString() const {
|
||||
return std::string("BThreadedTestCaller for ") + getName();
|
||||
BThreadedTestCaller<TestClass, ExpectedException>::toString() const {
|
||||
return std::string("BThreadedTestCaller for ") + getName();
|
||||
}
|
||||
|
||||
#endif // _beos_threaded_test_caller_h_
|
||||
|
||||
Reference in New Issue
Block a user