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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 62 by schoenebeck, Sun May 2 17:45:43 2004 UTC revision 63 by schoenebeck, Tue May 4 18:52:24 2004 UTC
# Line 30  int ThreadTest::HelperThread::Main() { Line 30  int ThreadTest::HelperThread::Main() {
30  }  }
31    
32    
33    // WaitingThread
34    
35    ThreadTest::WaitingThread::WaitingThread() : Thread(false, 0, -4) {
36    }
37    
38    int ThreadTest::WaitingThread::Main() {
39        while (true) condition.WaitIf(false);
40    }
41    
42    
43  // ThreadTest  // ThreadTest
44    
45    // Check if Thread class actually deploys a thread
46  void ThreadTest::testThreadRunning() {  void ThreadTest::testThreadRunning() {
47      dummythread.StartThread();      dummythread.StartThread();
48      usleep(25000); // wait 25ms      usleep(25000); // wait 25ms
# Line 39  void ThreadTest::testThreadRunning() { Line 50  void ThreadTest::testThreadRunning() {
50      CPPUNIT_ASSERT(dummythread.IsRunning());      CPPUNIT_ASSERT(dummythread.IsRunning());
51  }  }
52    
53    // Check if SignalStopThread() method actually stops the thread
54  void ThreadTest::testSignalStopThread() {  void ThreadTest::testSignalStopThread() {
55      dummythread.SignalStopThread();      dummythread.SignalStopThread();
56      usleep(40000); // wait 40ms      usleep(40000); // wait 40ms
57      CPPUNIT_ASSERT(!dummythread.IsRunning());      CPPUNIT_ASSERT(!dummythread.IsRunning());
58  }  }
59    
60    // Check if the thread can be relaunched
61  void ThreadTest::testRelaunchThread() {  void ThreadTest::testRelaunchThread() {
62        dummythread.StartThread();
63        usleep(25000); // wait 25ms
64        CPPUNIT_ASSERT(dummythread.wasRunning);
65        CPPUNIT_ASSERT(dummythread.IsRunning());
66        dummythread.StopThread();
67        usleep(25000); // wait 25ms
68      dummythread.wasRunning = false;      dummythread.wasRunning = false;
69      dummythread.StartThread();      dummythread.StartThread();
70      usleep(25000); // wait 25ms      usleep(25000); // wait 25ms
# Line 53  void ThreadTest::testRelaunchThread() { Line 72  void ThreadTest::testRelaunchThread() {
72      CPPUNIT_ASSERT(dummythread.IsRunning());      CPPUNIT_ASSERT(dummythread.IsRunning());
73  }  }
74    
75    // Check if the StopThread() method actually stops the thread and doesn't freeze the calling thread which wants to stop it
76  void ThreadTest::testStopThread() {  void ThreadTest::testStopThread() {
77      HelperThread* phelper = new HelperThread(&dummythread);      HelperThread* phelper = new HelperThread(&dummythread);
78      phelper->StartThread(); // let the helper thread kill the dummy thread      phelper->StartThread(); // let the helper thread kill the dummy thread
# Line 61  void ThreadTest::testStopThread() { Line 81  void ThreadTest::testStopThread() {
81      CPPUNIT_ASSERT(phelper->returnedFromDummyStop);      CPPUNIT_ASSERT(phelper->returnedFromDummyStop);
82      if (phelper) delete phelper;      if (phelper) delete phelper;
83  }  }
84    
85    // Check if the thread can be stopped even when it's waiting for a condition
86    void ThreadTest::testThreadKillableWhenWaiting() {
87        WaitingThread waitingthread;
88        waitingthread.SignalStartThread();
89        usleep(50000); // wait 50ms
90        CPPUNIT_ASSERT(waitingthread.IsRunning());
91        waitingthread.SignalStopThread();
92        usleep(40000); // wait 40ms
93        CPPUNIT_ASSERT(!waitingthread.IsRunning());
94    }

Legend:
Removed from v.62  
changed lines
  Added in v.63

  ViewVC Help
Powered by ViewVC