1 //------------------------------------------------------------------------------ 2 // LockTester.cpp 3 // 4 //------------------------------------------------------------------------------ 5 6 // Standard Includes ----------------------------------------------------------- 7 8 // System Includes ------------------------------------------------------------- 9 #include <Application.h> 10 #include <Clipboard.h> 11 12 #define CHK CPPUNIT_ASSERT 13 14 // Project Includes ------------------------------------------------------------ 15 16 // Local Includes -------------------------------------------------------------- 17 #include "LockTester.h" 18 19 // Local Defines --------------------------------------------------------------- 20 21 // Globals --------------------------------------------------------------------- 22 23 //------------------------------------------------------------------------------ 24 25 /* 26 bool Lock() 27 @case 1 28 @results Lock() returns true 29 */ 30 void LockTester::Lock1() 31 { 32 BApplication app("application/x-vnd.clipboardtest"); 33 BClipboard clip("Lock1"); 34 35 CHK(clip.Lock()); 36 } 37 38 static int32 LockTest2(void *data) 39 { 40 BClipboard *clip = (BClipboard *)data; 41 clip->Lock(); 42 snooze(300000); //Should be .3 seconds 43 delete clip; 44 return 0; 45 } 46 /* 47 bool Lock() 48 @case 2 49 @results Lock() returns false 50 */ 51 void LockTester::Lock2() 52 { 53 BApplication app("application/x-vnd.clipboardtest"); 54 BClipboard *clip = new BClipboard("Lock2"); 55 56 /* This method isn't guaranteed to work, but *should* work. 57 Spawn a thread which locks the clipboard, waits .3 seconds 58 and then deletes the locked clipboard. After spawning 59 the thread, the main thread waits .1 second. It then tries to 60 lock the clipboard and gets blocked. Once the clipboard is deleted, 61 it should return false. 62 */ 63 thread_id thread = spawn_thread(LockTest2,"locktest",B_NORMAL_PRIORITY,clip); 64 CHK(thread >= B_OK); 65 resume_thread(thread); 66 snooze(100000); //Should be .1 seconds 67 CHK(clip->Lock() == false); 68 } 69 70 /* 71 bool IsLocked() 72 @case 1 73 @results IsLocked() returns true 74 */ 75 void LockTester::IsLocked1() 76 { 77 BApplication app("application/x-vnd.clipboardtest"); 78 BClipboard clip("IsLocked1"); 79 80 clip.Lock(); 81 CHK(clip.IsLocked()); 82 } 83 84 /* 85 bool IsLocked() 86 @case 2 87 @results IsLocked() returns false 88 */ 89 void LockTester::IsLocked2() 90 { 91 BApplication app("application/x-vnd.clipboardtest"); 92 BClipboard clip("IsLocked2"); 93 94 CHK(!clip.IsLocked()); 95 } 96 97 /* 98 void Unlock() 99 @case 1 100 @results IsLocked() returns false 101 */ 102 void LockTester::Unlock1() 103 { 104 BApplication app("application/x-vnd.clipboardtest"); 105 BClipboard clip("Unlock1"); 106 107 clip.Lock(); 108 CHK(clip.IsLocked()); 109 clip.Unlock(); 110 CHK(!clip.IsLocked()); 111 } 112 113 Test* LockTester::Suite() 114 { 115 TestSuite* SuiteOfTests = new TestSuite; 116 117 ADD_TEST4(BClipboard, SuiteOfTests, LockTester, Lock1); 118 ADD_TEST4(BClipboard, SuiteOfTests, LockTester, Lock2); 119 ADD_TEST4(BClipboard, SuiteOfTests, LockTester, IsLocked1); 120 ADD_TEST4(BClipboard, SuiteOfTests, LockTester, IsLocked2); 121 ADD_TEST4(BClipboard, SuiteOfTests, LockTester, Unlock1); 122 123 return SuiteOfTests; 124 } 125 126 127 128