1 //------------------------------------------------------------------------------
2 // LockLooper.cpp
3 //
4 //------------------------------------------------------------------------------
5
6 // Standard Includes -----------------------------------------------------------
7
8 // System Includes -------------------------------------------------------------
9 #include <Looper.h>
10
11 // Project Includes ------------------------------------------------------------
12
13 // Local Includes --------------------------------------------------------------
14 #include "LockLooperTest.h"
15 #include "LockLooperTestCommon.h"
16
17 // Local Defines ---------------------------------------------------------------
18
19 // Globals ---------------------------------------------------------------------
20
21 //------------------------------------------------------------------------------
22 /**
23 LockLooper();
24 @case handler has no looper
25 @results Returns false
26 */
LockLooper1()27 void TLockLooperTest::LockLooper1()
28 {
29 BHandler Handler;
30 CPPUNIT_ASSERT(!Handler.LockLooper());
31 }
32 //------------------------------------------------------------------------------
33 /**
34 LockLooper();
35 @case handler has a looper which is initially unlocked
36 @results Returns true
37 */
LockLooper2()38 void TLockLooperTest::LockLooper2()
39 {
40 BLooper Looper;
41 BHandler Handler;
42 Looper.AddHandler(&Handler);
43 if (Looper.IsLocked())
44 {
45 // Make sure the looper is unlocked
46 Looper.Unlock();
47 }
48 CPPUNIT_ASSERT(Handler.LockLooper());
49 }
50 //------------------------------------------------------------------------------
51 /**
52 LockLooper();
53 @case handler has a looper which is initially locked
54 @results Returns true
55 */
LockLooper3()56 void TLockLooperTest::LockLooper3()
57 {
58 BLooper Looper;
59 BHandler Handler;
60 Looper.AddHandler(&Handler);
61 Looper.Lock();
62 CPPUNIT_ASSERT(Handler.LockLooper());
63 }
64 //------------------------------------------------------------------------------
65 /**
66 LockLooper();
67 @case handler has a looper which is locked in another thread
68 @results Returns false
69 */
LockLooper4()70 void TLockLooperTest::LockLooper4()
71 {
72 BLooper Looper;
73 BHandler Handler;
74 Looper.AddHandler(&Handler);
75 if (Looper.IsLocked())
76 {
77 Looper.Unlock();
78 }
79
80 TLockLooperInfo info(&Looper);
81 thread_id tid = spawn_thread(LockLooperThreadFunc, "LockLooperHelperThread",
82 B_NORMAL_PRIORITY, (void*)&info);
83 resume_thread(tid);
84 info.LockTest();
85
86 CPPUNIT_ASSERT(!Handler.LockLooper());
87 info.UnlockThread();
88 }
89 //------------------------------------------------------------------------------
Suite()90 Test* TLockLooperTest::Suite()
91 {
92 TestSuite* SuiteOfTests = new TestSuite("BHandler::LockLooper");
93
94 ADD_TEST4(BHandler, SuiteOfTests, TLockLooperTest, LockLooper1);
95 ADD_TEST4(BHandler, SuiteOfTests, TLockLooperTest, LockLooper2);
96 ADD_TEST4(BHandler, SuiteOfTests, TLockLooperTest, LockLooper3);
97 // ADD_TEST4(BHandler, SuiteOfTests, TLockLooperTest, LockLooper4);
98
99 return SuiteOfTests;
100 }
101 //------------------------------------------------------------------------------
102
103 /*
104 * $Log $
105 *
106 * $Id $
107 *
108 */
109
110
111