1 //------------------------------------------------------------------------------
2 // LockLooperWithTimeoutTest.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 "LockLooperWithTimeoutTest.h"
15 #include "LockLooperTestCommon.h"
16
17 // Local Defines ---------------------------------------------------------------
18
19 // Globals ---------------------------------------------------------------------
20
21 //------------------------------------------------------------------------------
22 /**
23 LockLooperWithTimeout(bigtime_t timeout)
24 @case handler has no looper
25 @param timeout 10000 microseconds (not relevant)
26 @results Returns B_BAD_VALUE
27 */
LockLooperWithTimeout1()28 void TLockLooperWithTimeoutTest::LockLooperWithTimeout1()
29 {
30 BHandler Handler;
31 CPPUNIT_ASSERT(Handler.LockLooperWithTimeout(10000) == B_BAD_VALUE);
32 }
33 //------------------------------------------------------------------------------
34 /**
35 LockLooperWithTimeout(bigtime_t timeout)
36 @case handler has a looper which is initially unlocked
37 @param timeout 10000 microseconds (not relevant)
38 @results Returns B_OK
39 */
LockLooperWithTimeout2()40 void TLockLooperWithTimeoutTest::LockLooperWithTimeout2()
41 {
42 BLooper Looper;
43 BHandler Handler;
44 Looper.AddHandler(&Handler);
45 if (Looper.IsLocked())
46 {
47 // Make sure the looper is unlocked
48 Looper.Unlock();
49 }
50 CPPUNIT_ASSERT(Handler.LockLooperWithTimeout(10000) == B_OK);
51 }
52 //------------------------------------------------------------------------------
53 /**
54 LockLooperWithTimeout(bigtime_t timeout)
55 @case handler has a looper which is initially locked
56 @param timeout 10000 microseconds (not relevant)
57 @results Returns B_OK
58 */
LockLooperWithTimeout3()59 void TLockLooperWithTimeoutTest::LockLooperWithTimeout3()
60 {
61 BLooper Looper;
62 BHandler Handler;
63 Looper.AddHandler(&Handler);
64 Looper.Lock();
65 CPPUNIT_ASSERT(Handler.LockLooperWithTimeout(10000) == B_OK);
66 }
67 //------------------------------------------------------------------------------
68 /**
69 LockLooperWithTimeout(bigtime_t timeout)
70 @case handler has a looper which is locked in another thread
71 @param timeout 10000 microseconds (not relevant)
72 @results Returns B_TIMED_OUT
73 */
LockLooperWithTimeout4()74 void TLockLooperWithTimeoutTest::LockLooperWithTimeout4()
75 {
76 BLooper Looper;
77 BHandler Handler;
78 Looper.AddHandler(&Handler);
79 if (Looper.IsLocked())
80 {
81 Looper.Unlock();
82 }
83
84 TLockLooperInfo info(&Looper);
85 thread_id tid = spawn_thread(LockLooperThreadFunc, "LockLooperHelperThread",
86 B_NORMAL_PRIORITY, (void*)&info);
87 resume_thread(tid);
88 info.LockTest();
89
90 CPPUNIT_ASSERT(Handler.LockLooperWithTimeout(10000) == B_TIMED_OUT);
91 info.UnlockThread();
92 }
93 //------------------------------------------------------------------------------
Suite()94 Test* TLockLooperWithTimeoutTest::Suite()
95 {
96 TestSuite* SuiteOfTests = new TestSuite("BHandler::LockLooperWithTimeout");
97
98 ADD_TEST4(BHandler, SuiteOfTests, TLockLooperWithTimeoutTest, LockLooperWithTimeout1);
99 ADD_TEST4(BHandler, SuiteOfTests, TLockLooperWithTimeoutTest, LockLooperWithTimeout2);
100 ADD_TEST4(BHandler, SuiteOfTests, TLockLooperWithTimeoutTest, LockLooperWithTimeout3);
101 // ADD_TEST4(BHandler, SuiteOfTests, TLockLooperWithTimeoutTest, LockLooperWithTimeout4);
102
103 return SuiteOfTests;
104 }
105 //------------------------------------------------------------------------------
106
107 /*
108 * $Log $
109 *
110 * $Id $
111 *
112 */
113
114
115