Minor tweaks and finish StartWatching test

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1906 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shadow303
2002-11-12 00:45:40 +00:00
parent 18d65fb5c0
commit c399a55fcd
5 changed files with 38 additions and 14 deletions
@@ -8,28 +8,28 @@ case 2: name points to valid string =>
status_t Clear(void) status_t Clear(void)
case 1: BClipboard not locked => case 1: BClipboard not locked =>
return B_ERROR return B_ERROR (R5 segfaults)
case 2: BClipboard is locked => case 2: BClipboard is locked =>
return B_OK return B_OK
Data() returns an empty message Data() returns an empty message
status_t Commit(void) status_t Commit(void)
case 1: BClipboard not locked => case 1: BClipboard not locked =>
return B_ERROR return B_ERROR (R5 segfaults)
case 2: BClipboard is locked => case 2: BClipboard is locked =>
return B_OK return B_OK
data is uploaded to system data is uploaded to system
status_t Revert(void) status_t Revert(void)
case 1: BClipboard not locked => case 1: BClipboard not locked =>
return B_ERROR return B_ERROR (R5 segfaults)
case 2: BClipboard is locked => case 2: BClipboard is locked =>
return B_OK return B_OK
message returned by Data() is reset to value acquired on Lock() message returned by Data() is reset to value acquired on Lock()
BMessage *Data(void) const BMessage *Data(void) const
case 1: BClipboard not locked => case 1: BClipboard not locked =>
return NULL return NULL (R5 segfaults)
case 2: BClipboard is locked => case 2: BClipboard is locked =>
returns a BMessage containing correct data returns a BMessage containing correct data
@@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Application.h>
#include <Clipboard.h> #include <Clipboard.h>
#define CHK CPPUNIT_ASSERT #define CHK CPPUNIT_ASSERT
@@ -29,6 +30,7 @@
*/ */
void BClipboardTester::BClipboard1() void BClipboardTester::BClipboard1()
{ {
BApplication app("application/x-vnd.clipboardtest");
#ifdef TEST_R5 #ifdef TEST_R5
CHK(false); CHK(false);
#endif #endif
@@ -43,6 +45,7 @@ void BClipboardTester::BClipboard1()
*/ */
void BClipboardTester::BClipboard2() void BClipboardTester::BClipboard2()
{ {
BApplication app("application/x-vnd.clipboardtest");
char name[18] = "BClipboard Case 2"; char name[18] = "BClipboard Case 2";
BClipboard clip(name); BClipboard clip(name);
@@ -6,6 +6,7 @@
// Standard Includes ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Application.h>
#include <Clipboard.h> #include <Clipboard.h>
#define CHK CPPUNIT_ASSERT #define CHK CPPUNIT_ASSERT
@@ -28,6 +29,7 @@
*/ */
void CountTester::LocalCount1() void CountTester::LocalCount1()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("LocalCount1"); BClipboard clip("LocalCount1");
CHK(clip.LocalCount() == 0); CHK(clip.LocalCount() == 0);
@@ -40,6 +42,7 @@ void CountTester::LocalCount1()
*/ */
void CountTester::LocalCount2() void CountTester::LocalCount2()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("LocalCount2"); BClipboard clip("LocalCount2");
BMessage *data; BMessage *data;
@@ -64,6 +67,7 @@ void CountTester::LocalCount2()
*/ */
void CountTester::LocalCount3() void CountTester::LocalCount3()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clipA("LocalCount3"); BClipboard clipA("LocalCount3");
BClipboard clipB("LocalCount3"); BClipboard clipB("LocalCount3");
BMessage *data; BMessage *data;
@@ -95,6 +99,7 @@ void CountTester::LocalCount3()
*/ */
void CountTester::LocalCount4() void CountTester::LocalCount4()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clipA("LocalCount4"); BClipboard clipA("LocalCount4");
BClipboard clipB("LocalCount4"); BClipboard clipB("LocalCount4");
BMessage *data; BMessage *data;
@@ -136,6 +141,7 @@ void CountTester::LocalCount4()
*/ */
void CountTester::LocalCount5() void CountTester::LocalCount5()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clipA("LocalCount5"); BClipboard clipA("LocalCount5");
BClipboard clipB("LocalCount5"); BClipboard clipB("LocalCount5");
BMessage *data; BMessage *data;
@@ -173,6 +179,7 @@ void CountTester::LocalCount5()
*/ */
void CountTester::LocalCount6() void CountTester::LocalCount6()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clipA("LocalCount6A"); BClipboard clipA("LocalCount6A");
BClipboard clipB("LocalCount6B"); BClipboard clipB("LocalCount6B");
BMessage *data; BMessage *data;
@@ -203,6 +210,7 @@ void CountTester::LocalCount6()
*/ */
void CountTester::SystemCount1() void CountTester::SystemCount1()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("SystemCount1"); BClipboard clip("SystemCount1");
CHK(clip.SystemCount() == 0); CHK(clip.SystemCount() == 0);
@@ -216,6 +224,7 @@ void CountTester::SystemCount1()
*/ */
void CountTester::SystemCount2() void CountTester::SystemCount2()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clipA("SystemCount2"); BClipboard clipA("SystemCount2");
BClipboard clipB("SystemCount2"); BClipboard clipB("SystemCount2");
BMessage *data; BMessage *data;
@@ -243,6 +252,7 @@ void CountTester::SystemCount2()
*/ */
void CountTester::SystemCount3() void CountTester::SystemCount3()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clipA("SystemCount3A"); BClipboard clipA("SystemCount3A");
BClipboard clipB("SystemCount3B"); BClipboard clipB("SystemCount3B");
BMessage *data; BMessage *data;
+14 -9
View File
@@ -6,6 +6,7 @@
// Standard Includes ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Application.h>
#include <Clipboard.h> #include <Clipboard.h>
#define CHK CPPUNIT_ASSERT #define CHK CPPUNIT_ASSERT
@@ -28,6 +29,7 @@
*/ */
void LockTester::Lock1() void LockTester::Lock1()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("Lock1"); BClipboard clip("Lock1");
CHK(clip.Lock()); CHK(clip.Lock());
@@ -37,7 +39,7 @@ static int32 LockTest2(void *data)
{ {
BClipboard *clip = (BClipboard *)data; BClipboard *clip = (BClipboard *)data;
clip->Lock(); clip->Lock();
snooze(3000000); //Should be 3 seconds snooze(300000); //Should be .3 seconds
delete clip; delete clip;
return 0; return 0;
} }
@@ -48,21 +50,21 @@ static int32 LockTest2(void *data)
*/ */
void LockTester::Lock2() void LockTester::Lock2()
{ {
CHK(false); // fail until I figure out why it is hanging BApplication app("application/x-vnd.clipboardtest");
BClipboard *clip = new BClipboard("Lock2"); BClipboard *clip = new BClipboard("Lock2");
/* This method isn't guaranteed to work, but *should* work. /* This method isn't guaranteed to work, but *should* work.
Spawn a thread which locks the clipboard, waits several seconds Spawn a thread which locks the clipboard, waits .3 seconds
and then deletes the locked clipboard. After spawning and then deletes the locked clipboard. After spawning
the thread, the main thread should keep checking if the clipboard the thread, the main thread waits .1 second. It then tries to
is locked. Once it is locked, the thread tries to lock it and gets lock the clipboard and gets blocked. Once the clipboard is deleted,
blocked. Once the clipboard is deleted, it should return false. it should return false.
*/ */
thread_id thread = spawn_thread(LockTest2,"locktest",B_NORMAL_PRIORITY,clip); thread_id thread = spawn_thread(LockTest2,"locktest",B_NORMAL_PRIORITY,clip);
CHK(thread >= B_OK);
while(!clip->IsLocked()); resume_thread(thread);
snooze(100000); //Should be .1 seconds
CHK(clip->Lock() == false); CHK(clip->Lock() == false);
kill_thread(thread);
} }
/* /*
@@ -72,6 +74,7 @@ void LockTester::Lock2()
*/ */
void LockTester::IsLocked1() void LockTester::IsLocked1()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("IsLocked1"); BClipboard clip("IsLocked1");
clip.Lock(); clip.Lock();
@@ -85,6 +88,7 @@ void LockTester::IsLocked1()
*/ */
void LockTester::IsLocked2() void LockTester::IsLocked2()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("IsLocked2"); BClipboard clip("IsLocked2");
CHK(!clip.IsLocked()); CHK(!clip.IsLocked());
@@ -97,6 +101,7 @@ void LockTester::IsLocked2()
*/ */
void LockTester::Unlock1() void LockTester::Unlock1()
{ {
BApplication app("application/x-vnd.clipboardtest");
BClipboard clip("Unlock1"); BClipboard clip("Unlock1");
clip.Lock(); clip.Lock();
@@ -41,7 +41,7 @@ void ReadWriteTester::Clear1()
/* /*
status_t Clear() status_t Clear()
@case 1 @case 2
@results Clear() returns B_OK @results Clear() returns B_OK
data message is empty data message is empty
*/ */
@@ -297,7 +297,10 @@ void ReadWriteTester::StartWatching1()
char *str; char *str;
ssize_t size; ssize_t size;
BLooper *looper = new BLooper();
RWHandler handler; RWHandler handler;
looper->AddHandler(&handler);
looper->Run();
BMessenger target(&handler); BMessenger target(&handler);
CHK(clip.StartWatching(target) == B_OK); CHK(clip.StartWatching(target) == B_OK);
if ( clip.Lock() ) if ( clip.Lock() )
@@ -308,6 +311,9 @@ void ReadWriteTester::StartWatching1()
clip.Commit(); clip.Commit();
clip.Unlock(); clip.Unlock();
} }
snooze(100000);
looper->Lock();
looper->Quit();
CHK(handler.ClipboardModified()); CHK(handler.ClipboardModified());
clip.StopWatching(target); clip.StopWatching(target);
} }