Initial checking of unified unit testing app and example test.

+ Currently, only statically linked tests are supported.
+ None of the existing tests have been integrated into it yet; that will come after I add dynamic linking.
+ The example test has multithreaded and singlethreaded examples
+ The name of the unit testing app is open for negotiation if UnitTester is unacceptable for some reason. :-)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@78 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-07-11 03:34:41 +00:00
parent 03aa30ce94
commit bc85a65ae3
4 changed files with 160 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
#include <ExampleTest.h>
#include <ThreadedTestCaller.h>
#include <cppunit/Test.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <stdio.h>
#include <iostream>
#include <kernel/OS.h>
ExampleTest::ExampleTest(std::string name)
: BThreadedTestCase(name)
, fLocker(new BLocker())
{
}
CppUnit::Test*
ExampleTest::Suite() {
CppUnit::TestSuite *suite = new CppUnit::TestSuite("Yo");
BThreadedTestCaller<ExampleTest> *caller;
// Add a multithreaded test
ExampleTest *test = new ExampleTest("This name is never used, just so you know :-)");
caller = new BThreadedTestCaller<ExampleTest>("MultiThreaded Test #1", test);
caller->addThread("A", &ExampleTest::TestFunc1);
caller->addThread("B", &ExampleTest::TestFunc2);
caller->addThread("C", &ExampleTest::TestFunc3);
suite->addTest(caller);
// And another
caller = new BThreadedTestCaller<ExampleTest>("MultiThreaded Test #2");
caller->addThread("Thread1", &ExampleTest::TestFunc1);
caller->addThread("Thread2", &ExampleTest::TestFunc1);
caller->addThread("Thread3", &ExampleTest::TestFunc1);
suite->addTest(caller);
// And some single threaded ones
suite->addTest(new CppUnit::TestCaller<ExampleTest>("SingleThreaded Test #1", &ExampleTest::TestFunc1));
suite->addTest(new CppUnit::TestCaller<ExampleTest>("SingleThreaded Test #2", &ExampleTest::TestFunc2));
return suite;
}
const int sleeptime = 10000;
void
ExampleTest::TestFunc1() {
for (int i = 0; i < 10; i++) {
// Get the lock and do our business
NextSubTest();
fLocker->Lock();
// printf("TestFunc1() -- %d + 10 = %d\n", fNum, fNum+10);
fNum += 10;
fLocker->Unlock();
snooze(sleeptime);
}
}
void
ExampleTest::TestFunc2() {
for (int i = 0; i < 13; i++) {
// Get the lock and do our business
NextSubTest();
fLocker->Lock();
// printf("TestFunc2() -- %d * 2 = %d\n", fNum, fNum*2);
fNum *= 2;
fLocker->Unlock();
snooze(sleeptime);
}
}
void
ExampleTest::TestFunc3() {
for (int i = 0; i < 15; i++) {
// Get the lock and do our business
NextSubTest();
fLocker->Lock();
// printf("TestFunc3() -- %d - 5 = %d\n", fNum, fNum-5);
fNum += 10;
fLocker->Unlock();
snooze(sleeptime);
}
}