vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bhandler / LockLooperTest.cpp
bloba0bcf3d5a19eab61ff25ece3a67d73dc2244eecb
1 //------------------------------------------------------------------------------
2 // LockLooper.cpp
3 //
4 //------------------------------------------------------------------------------
6 // Standard Includes -----------------------------------------------------------
8 // System Includes -------------------------------------------------------------
9 #include <Looper.h>
11 // Project Includes ------------------------------------------------------------
13 // Local Includes --------------------------------------------------------------
14 #include "LockLooperTest.h"
15 #include "LockLooperTestCommon.h"
17 // Local Defines ---------------------------------------------------------------
19 // Globals ---------------------------------------------------------------------
21 //------------------------------------------------------------------------------
22 /**
23 LockLooper();
24 @case handler has no looper
25 @results Returns false
27 void TLockLooperTest::LockLooper1()
29 BHandler Handler;
30 CPPUNIT_ASSERT(!Handler.LockLooper());
32 //------------------------------------------------------------------------------
33 /**
34 LockLooper();
35 @case handler has a looper which is initially unlocked
36 @results Returns true
38 void TLockLooperTest::LockLooper2()
40 BLooper Looper;
41 BHandler Handler;
42 Looper.AddHandler(&Handler);
43 if (Looper.IsLocked())
45 // Make sure the looper is unlocked
46 Looper.Unlock();
48 CPPUNIT_ASSERT(Handler.LockLooper());
50 //------------------------------------------------------------------------------
51 /**
52 LockLooper();
53 @case handler has a looper which is initially locked
54 @results Returns true
56 void TLockLooperTest::LockLooper3()
58 BLooper Looper;
59 BHandler Handler;
60 Looper.AddHandler(&Handler);
61 Looper.Lock();
62 CPPUNIT_ASSERT(Handler.LockLooper());
64 //------------------------------------------------------------------------------
65 /**
66 LockLooper();
67 @case handler has a looper which is locked in another thread
68 @results Returns false
70 void TLockLooperTest::LockLooper4()
72 BLooper Looper;
73 BHandler Handler;
74 Looper.AddHandler(&Handler);
75 if (Looper.IsLocked())
77 Looper.Unlock();
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();
86 CPPUNIT_ASSERT(!Handler.LockLooper());
87 info.UnlockThread();
89 //------------------------------------------------------------------------------
90 Test* TLockLooperTest::Suite()
92 TestSuite* SuiteOfTests = new TestSuite("BHandler::LockLooper");
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);
99 return SuiteOfTests;
101 //------------------------------------------------------------------------------
104 * $Log $
106 * $Id $