/[svn]/linuxsampler/trunk/src/testcases/ThreadTest.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/testcases/ThreadTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (hide annotations) (download)
Sun May 2 17:45:43 2004 UTC (19 years, 11 months ago) by schoenebeck
File size: 1525 byte(s)
* src/common/Thread.cpp: method StartThread() now blocks until thread
  actually runs, mlockall() will only be applied for realtime threads
* libtoolized liblinuxsampler
* initiated automatic unit tests against the LinuxSampler codebase
  (see src/testcases): already added a couple of tests for the Thread and
  Mutex classes, you have to explicitly compile the unit tests by running
  'make testcases' (you need to have cppunit installed though) and then you
  can run the console version of the test runner by calling
  'src/testcases/linuxsamplertest'
* src/Sampler.h: added API documentation

1 schoenebeck 57 #include "ThreadTest.h"
2    
3     #include <iostream>
4    
5     CPPUNIT_TEST_SUITE_REGISTRATION(ThreadTest);
6    
7    
8     // DummyThread
9    
10     ThreadTest::DummyThread::DummyThread() : Thread(false, 0, -4) {
11     wasRunning = false;
12     }
13    
14     int ThreadTest::DummyThread::Main() {
15     wasRunning = true;
16     while (true) sleep (1000);
17     }
18    
19    
20     // HelperThread
21    
22     ThreadTest::HelperThread::HelperThread(DummyThread* pDummyThread) : Thread(false, 0, -4) {
23     returnedFromDummyStop = false;
24     this->pDummyThread = pDummyThread;
25     }
26    
27     int ThreadTest::HelperThread::Main() {
28     pDummyThread->StopThread();
29     returnedFromDummyStop = true;
30     }
31    
32    
33     // ThreadTest
34    
35     void ThreadTest::testThreadRunning() {
36     dummythread.StartThread();
37     usleep(25000); // wait 25ms
38     CPPUNIT_ASSERT(dummythread.wasRunning);
39     CPPUNIT_ASSERT(dummythread.IsRunning());
40     }
41    
42     void ThreadTest::testSignalStopThread() {
43     dummythread.SignalStopThread();
44     usleep(40000); // wait 40ms
45     CPPUNIT_ASSERT(!dummythread.IsRunning());
46     }
47    
48     void ThreadTest::testRelaunchThread() {
49     dummythread.wasRunning = false;
50     dummythread.StartThread();
51     usleep(25000); // wait 25ms
52     CPPUNIT_ASSERT(dummythread.wasRunning);
53     CPPUNIT_ASSERT(dummythread.IsRunning());
54     }
55    
56     void ThreadTest::testStopThread() {
57     HelperThread* phelper = new HelperThread(&dummythread);
58     phelper->StartThread(); // let the helper thread kill the dummy thread
59     usleep(25000); // wait 25ms
60     CPPUNIT_ASSERT(!dummythread.IsRunning());
61     CPPUNIT_ASSERT(phelper->returnedFromDummyStop);
62     if (phelper) delete phelper;
63     }

  ViewVC Help
Powered by ViewVC