1 #include "ExampleTest.h"
3 #include <ThreadedTestCaller.h>
4 #include <cppunit/Test.h>
5 #include <cppunit/TestCaller.h>
6 #include <cppunit/TestSuite.h>
10 #include <TestUtils.h>
12 ExampleTest::ExampleTest(std::string name
)
13 : BThreadedTestCase(name
)
14 , fLocker(new BLocker())
19 ExampleTest::Suite() {
20 CppUnit::TestSuite
*suite
= new CppUnit::TestSuite("Yo");
21 BThreadedTestCaller
<ExampleTest
> *caller
;
23 // Add a multithreaded test
24 ExampleTest
*test
= new ExampleTest("This name is never used, just so you know :-)");
25 caller
= new BThreadedTestCaller
<ExampleTest
>("ExampleTests::MultiThreaded Test #1", test
);
26 caller
->addThread("A", &ExampleTest::TestFunc1
);
27 caller
->addThread("B", &ExampleTest::TestFunc2
);
28 caller
->addThread("C", &ExampleTest::TestFunc3
);
29 suite
->addTest(caller
);
32 caller
= new BThreadedTestCaller
<ExampleTest
>("ExampleTests::MultiThreaded Test #2");
33 caller
->addThread("Thread1", &ExampleTest::TestFunc1
);
34 caller
->addThread("Thread2", &ExampleTest::TestFunc1
);
35 caller
->addThread("Thread3", &ExampleTest::TestFunc1
);
36 suite
->addTest(caller
);
38 // And one that fails, if you're so inclined
39 caller
= new BThreadedTestCaller
<ExampleTest
>("ExampleTests::MultiThreaded Failing Test");
40 caller
->addThread("GoodThread1", &ExampleTest::TestFunc1
);
41 caller
->addThread("GoodThread2", &ExampleTest::TestFunc2
);
42 caller
->addThread("BadThread", &ExampleTest::FailureFunc
);
43 suite
->addTest(caller
);
45 // And some single threaded ones
46 suite
->addTest(new CppUnit::TestCaller
<ExampleTest
>("ExampleTests::SingleThreaded Test #1", &ExampleTest::TestFunc1
));
47 suite
->addTest(new CppUnit::TestCaller
<ExampleTest
>("ExampleTests::SingleThreaded Test #2", &ExampleTest::TestFunc2
));
52 const int sleeptime
= 10000;
55 ExampleTest::TestFunc1() {
56 for (int i
= 0; i
< 10; i
++) {
57 // Get the lock and do our business
63 // Outputf("(1:%d)", i);
68 ExampleTest::TestFunc2() {
69 for (int i
= 0; i
< 13; i
++) {
70 // Get the lock and do our business
76 // Outputf("(2:%d)", i);
81 ExampleTest::TestFunc3() {
82 for (int i
= 0; i
< 15; i
++) {
83 // Get the lock and do our business
89 // Outputf("(3:%d)", i);
94 ExampleTest::FailureFunc() {