Clipboard and Cursor tests checked in for Gabe Yoder
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1828 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,6 +4,8 @@ UsePrivateHeaders app ;
|
|||||||
|
|
||||||
# Let Jam know where to find some of our source files
|
# Let Jam know where to find some of our source files
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bapplication ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bapplication ] ;
|
||||||
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bclipboard ] ;
|
||||||
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bcursor ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bhandler ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bhandler ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) blooper ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) blooper ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bmessagequeue ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bmessagequeue ] ;
|
||||||
@@ -24,6 +26,17 @@ CommonTestLib libapptest.so
|
|||||||
AppRunTester.cpp
|
AppRunTester.cpp
|
||||||
BApplicationTester.cpp
|
BApplicationTester.cpp
|
||||||
|
|
||||||
|
# BClipboard
|
||||||
|
BClipboardTester.cpp
|
||||||
|
ClipboardTest.cpp
|
||||||
|
CountTester.cpp
|
||||||
|
LockTester.cpp
|
||||||
|
ReadWriteTester.cpp
|
||||||
|
|
||||||
|
# BCursor
|
||||||
|
BCursorTester.cpp
|
||||||
|
CursorTest.cpp
|
||||||
|
|
||||||
# BHandler
|
# BHandler
|
||||||
HandlerTest.cpp
|
HandlerTest.cpp
|
||||||
AddFilterTest.cpp
|
AddFilterTest.cpp
|
||||||
@@ -123,6 +136,8 @@ CommonTestLib libapptest.so
|
|||||||
;
|
;
|
||||||
|
|
||||||
SubInclude OBOS_TOP src tests kits app bapplication ;
|
SubInclude OBOS_TOP src tests kits app bapplication ;
|
||||||
|
SubInclude OBOS_TOP src tests kits app bclipboard ;
|
||||||
|
SubInclude OBOS_TOP src tests kits app bcursor ;
|
||||||
#SubInclude OBOS_TOP src tests kits app bhandler ;
|
#SubInclude OBOS_TOP src tests kits app bhandler ;
|
||||||
#SubInclude OBOS_TOP src tests kits app blooper ;
|
#SubInclude OBOS_TOP src tests kits app blooper ;
|
||||||
#SubInclude OBOS_TOP src tests kits app bmessageQueue ;
|
#SubInclude OBOS_TOP src tests kits app bmessageQueue ;
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
BClipboard(const char *name, bool transient = false)
|
||||||
|
case 1: name is NULL =>
|
||||||
|
(Note: R5 segfaults)
|
||||||
|
create system clipboard
|
||||||
|
Name() returns "system"
|
||||||
|
case 2: name points to valid string =>
|
||||||
|
Name() returns a copy of name
|
||||||
|
|
||||||
|
status_t Clear(void)
|
||||||
|
case 1: BClipboard not locked =>
|
||||||
|
return B_ERROR
|
||||||
|
case 2: BClipboard is locked =>
|
||||||
|
return B_OK
|
||||||
|
Data() returns an empty message
|
||||||
|
|
||||||
|
status_t Commit(void)
|
||||||
|
case 1: BClipboard not locked =>
|
||||||
|
return B_ERROR
|
||||||
|
case 2: BClipboard is locked =>
|
||||||
|
return B_OK
|
||||||
|
data is uploaded to system
|
||||||
|
|
||||||
|
status_t Revert(void)
|
||||||
|
case 1: BClipboard not locked =>
|
||||||
|
return B_ERROR
|
||||||
|
case 2: BClipboard is locked =>
|
||||||
|
return B_OK
|
||||||
|
message returned by Data() is reset to value acquired on Lock()
|
||||||
|
|
||||||
|
BMessage *Data(void) const
|
||||||
|
case 1: BClipboard not locked =>
|
||||||
|
return NULL
|
||||||
|
case 2: BClipboard is locked =>
|
||||||
|
returns a BMessage containing correct data
|
||||||
|
|
||||||
|
BMessenger DataSource(void) const
|
||||||
|
case 1: clipboard has never been written =>
|
||||||
|
returns an invalid BMessenger
|
||||||
|
case 2: BClipboard has never been locked =>
|
||||||
|
returns an invalid BMessenger
|
||||||
|
case 3: BClipboard has been locked at some point =>
|
||||||
|
returns BMessenger that wrote the data acquired in the last Lock()
|
||||||
|
|
||||||
|
uint32 LocalCount(void) const
|
||||||
|
case 1: BClipboard has not been read or written =>
|
||||||
|
return 0
|
||||||
|
case 2: BClipboard "A" writes once, no other BClipboards write =>
|
||||||
|
return 1
|
||||||
|
case 3: BClipboard "B" writes once, BClipboard "A" reads =>
|
||||||
|
return 1 for both BClipboards
|
||||||
|
case 4: BClipboard "B" writes, BClipboard "A" reads, BClipboard "B" writes =>
|
||||||
|
return 1 for BClipboard "A", return 2 for BClipboard "B"
|
||||||
|
case 5: BClipboard "A" writes, BClipboard "B" writes =>
|
||||||
|
return 1 for BClipboard "A", return 2 for BClipboard "B"
|
||||||
|
case 6: BClipboard "A" writes to system clipboard "A", BClipboard "B" reads from system clipboard "B" =>
|
||||||
|
return 1 for BClipboard "A", return 0 for BClipboard "B"
|
||||||
|
|
||||||
|
uint32 SystemCount(void) const
|
||||||
|
case 1: clipboard has never been written by any BClipboards =>
|
||||||
|
return 0
|
||||||
|
case 2: BClipboard "A" writes, BClipboard "B" neither reads nor writes =>
|
||||||
|
return 1 for both
|
||||||
|
case 3: BClipboard "A" writes to system clipboard "A", BClipboard "B" is attached to system clipboard "B" =>
|
||||||
|
return 1 for BClipboard "A", return 0 for BClipboard "B"
|
||||||
|
|
||||||
|
bool Lock(void)
|
||||||
|
case 1: BClipboard is not locked by any threads =>
|
||||||
|
return true
|
||||||
|
data is downloaded from system
|
||||||
|
case 2: BClipboard is deleted while Lock() is blocked =>
|
||||||
|
return false
|
||||||
|
|
||||||
|
bool IsLocked(void)
|
||||||
|
case 1: BClipboard is not locked =>
|
||||||
|
return false
|
||||||
|
case 2: BClipboard is locked =>
|
||||||
|
return true
|
||||||
|
|
||||||
|
void Lock(void)
|
||||||
|
case 1: BClipboard is locked =>
|
||||||
|
unlocks clipboard (IsLocked returns false)
|
||||||
|
|
||||||
|
const char *Name(void) const
|
||||||
|
covered by constructor test cases
|
||||||
|
|
||||||
|
status_t StartWatching(BMessenger target)
|
||||||
|
case 1: =>
|
||||||
|
return B_OK, target is notified when clipboard is written
|
||||||
|
|
||||||
|
status_t StopWatching(BMessenger target)
|
||||||
|
case 1: target is watching the BClipboard =>
|
||||||
|
return B_OK
|
||||||
|
case 2: target is not watching the BClipboard =>
|
||||||
|
return B_BAD_VALUE
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// BClipboardTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <Clipboard.h>
|
||||||
|
|
||||||
|
#define CHK CPPUNIT_ASSERT
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "BClipboardTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
BClipboard(const char *name, bool transient = false)
|
||||||
|
@case 1
|
||||||
|
@results clipboard defaults to system clipboard
|
||||||
|
*/
|
||||||
|
void BClipboardTester::BClipboard1()
|
||||||
|
{
|
||||||
|
BClipboard clip(NULL);
|
||||||
|
CHK(strcmp(clip.Name(),"system") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BClipboard(const char *name, bool transient = false)
|
||||||
|
@case 2
|
||||||
|
@results return string from Name() should match *name
|
||||||
|
*/
|
||||||
|
void BClipboardTester::BClipboard2()
|
||||||
|
{
|
||||||
|
char name[18] = "BClipboard Case 2";
|
||||||
|
BClipboard clip(name);
|
||||||
|
|
||||||
|
CHK(strcmp(clip.Name(),name) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test* BClipboardTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, BClipboardTester, BClipboard1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, BClipboardTester, BClipboard2);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// BClipboardTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef B_CLIPBOARD_TESTER_H
|
||||||
|
#define B_CLIPBOARD_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class BClipboardTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BClipboardTester() {;}
|
||||||
|
BClipboardTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void BClipboard1();
|
||||||
|
void BClipboard2();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // B_CLIPBOARD_TESTER_H
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
#include "BClipboardTester.h"
|
||||||
|
#include "CountTester.h"
|
||||||
|
#include "LockTester.h"
|
||||||
|
#include "ReadWriteTester.h"
|
||||||
|
|
||||||
|
CppUnit::Test* ClipboardTestSuite()
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
||||||
|
|
||||||
|
testSuite->addTest(BClipboardTester::Suite());
|
||||||
|
testSuite->addTest(CountTester::Suite());
|
||||||
|
testSuite->addTest(LockTester::Suite());
|
||||||
|
testSuite->addTest(ReadWriteTester::Suite());
|
||||||
|
|
||||||
|
return testSuite;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef _clipboard_test_h_
|
||||||
|
#define _clipboard_test_h_
|
||||||
|
|
||||||
|
class CppUnit::Test;
|
||||||
|
|
||||||
|
CppUnit::Test* ClipboardTestSuite();
|
||||||
|
|
||||||
|
#endif // _clipboard_test_h_
|
||||||
|
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// CountTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <Clipboard.h>
|
||||||
|
|
||||||
|
#define CHK CPPUNIT_ASSERT
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "CountTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
LocalCount()
|
||||||
|
@case 1
|
||||||
|
@results count == 0
|
||||||
|
*/
|
||||||
|
void CountTester::LocalCount1()
|
||||||
|
{
|
||||||
|
BClipboard clip("LocalCount1");
|
||||||
|
|
||||||
|
CHK(clip.LocalCount() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LocalCount()
|
||||||
|
@case 2
|
||||||
|
@results count == 1
|
||||||
|
*/
|
||||||
|
void CountTester::LocalCount2()
|
||||||
|
{
|
||||||
|
BClipboard clip("LocalCount2");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
clip.Clear();
|
||||||
|
if ( (data = clip.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount2",12);
|
||||||
|
clip.Commit();
|
||||||
|
}
|
||||||
|
clip.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clip.LocalCount() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LocalCount()
|
||||||
|
@case 3
|
||||||
|
@results both counts == 1
|
||||||
|
*/
|
||||||
|
void CountTester::LocalCount3()
|
||||||
|
{
|
||||||
|
BClipboard clipA("LocalCount3");
|
||||||
|
BClipboard clipB("LocalCount3");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
clipB.Clear();
|
||||||
|
if ( (data = clipB.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount3",12);
|
||||||
|
clipB.Commit();
|
||||||
|
}
|
||||||
|
clipB.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clipA.LocalCount() == 1);
|
||||||
|
CHK(clipB.LocalCount() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LocalCount()
|
||||||
|
@case 4
|
||||||
|
@results clipA.LocalCount() == 1
|
||||||
|
clipB.LocalCount() == 2
|
||||||
|
*/
|
||||||
|
void CountTester::LocalCount4()
|
||||||
|
{
|
||||||
|
BClipboard clipA("LocalCount4");
|
||||||
|
BClipboard clipB("LocalCount4");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
clipB.Clear();
|
||||||
|
if ( (data = clipB.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount4",12);
|
||||||
|
clipB.Commit();
|
||||||
|
}
|
||||||
|
clipB.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
clipB.Clear();
|
||||||
|
if ( (data = clipB.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount4",12);
|
||||||
|
clipB.Commit();
|
||||||
|
}
|
||||||
|
clipB.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clipA.LocalCount() == 1);
|
||||||
|
CHK(clipB.LocalCount() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LocalCount()
|
||||||
|
@case 5
|
||||||
|
@results clipA.LocalCount() == 1
|
||||||
|
clipB.LocalCount() == 2
|
||||||
|
*/
|
||||||
|
void CountTester::LocalCount5()
|
||||||
|
{
|
||||||
|
BClipboard clipA("LocalCount5");
|
||||||
|
BClipboard clipB("LocalCount5");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount5",12);
|
||||||
|
clipA.Commit();
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
clipB.Clear();
|
||||||
|
if ( (data = clipB.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount5",12);
|
||||||
|
clipB.Commit();
|
||||||
|
}
|
||||||
|
clipB.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clipA.LocalCount() == 1);
|
||||||
|
CHK(clipB.LocalCount() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LocalCount()
|
||||||
|
@case 6
|
||||||
|
@results clipA.LocalCount() == 1
|
||||||
|
clipB.LocalCount() == 0
|
||||||
|
*/
|
||||||
|
void CountTester::LocalCount6()
|
||||||
|
{
|
||||||
|
BClipboard clipA("LocalCount6A");
|
||||||
|
BClipboard clipB("LocalCount6B");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"LocalCount6",12);
|
||||||
|
clipA.Commit();
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
clipB.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clipA.LocalCount() == 1);
|
||||||
|
CHK(clipB.LocalCount() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
SystemCount()
|
||||||
|
@case 1
|
||||||
|
@results count == 0
|
||||||
|
*/
|
||||||
|
void CountTester::SystemCount1()
|
||||||
|
{
|
||||||
|
BClipboard clip("SystemCount1");
|
||||||
|
|
||||||
|
CHK(clip.SystemCount() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
SystemCount()
|
||||||
|
@case 2
|
||||||
|
@results clipA.SystemCount() == 1
|
||||||
|
clipB.SystemCount() == 1
|
||||||
|
*/
|
||||||
|
void CountTester::SystemCount2()
|
||||||
|
{
|
||||||
|
BClipboard clipA("SystemCount2");
|
||||||
|
BClipboard clipB("SystemCount2");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"SystemCount2",12);
|
||||||
|
clipA.Commit();
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clipA.SystemCount() == 1);
|
||||||
|
CHK(clipB.SystemCount() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
SystemCount()
|
||||||
|
@case 3
|
||||||
|
@results clipA.SystemCount() == 1
|
||||||
|
clipB.SystemCount() == 0
|
||||||
|
*/
|
||||||
|
void CountTester::SystemCount3()
|
||||||
|
{
|
||||||
|
BClipboard clipA("SystemCount3A");
|
||||||
|
BClipboard clipB("SystemCount3B");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE,"SystemCount3",12);
|
||||||
|
clipA.Commit();
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
CHK(clipA.SystemCount() == 1);
|
||||||
|
CHK(clipB.SystemCount() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test* CountTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount3);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount4);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount5);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount6);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount3);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// CountTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef COUNT_TESTER_H
|
||||||
|
#define COUNT_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class CountTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CountTester() {;}
|
||||||
|
CountTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void LocalCount1();
|
||||||
|
void LocalCount2();
|
||||||
|
void LocalCount3();
|
||||||
|
void LocalCount4();
|
||||||
|
void LocalCount5();
|
||||||
|
void LocalCount6();
|
||||||
|
void SystemCount1();
|
||||||
|
void SystemCount2();
|
||||||
|
void SystemCount3();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COUNT_TESTER_H
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
SubDir OBOS_TOP src tests kits app bclipboard ;
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// LockTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <Clipboard.h>
|
||||||
|
|
||||||
|
#define CHK CPPUNIT_ASSERT
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "LockTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool Lock()
|
||||||
|
@case 1
|
||||||
|
@results Lock() returns true
|
||||||
|
*/
|
||||||
|
void LockTester::Lock1()
|
||||||
|
{
|
||||||
|
BClipboard clip("Lock1");
|
||||||
|
|
||||||
|
CHK(clip.Lock());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32 LockTest2(void *data)
|
||||||
|
{
|
||||||
|
BClipboard *clip = (BClipboard *)data;
|
||||||
|
clip->Lock();
|
||||||
|
snooze(3000000); //Should be 3 seconds
|
||||||
|
delete clip;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
bool Lock()
|
||||||
|
@case 2
|
||||||
|
@results Lock() returns false
|
||||||
|
*/
|
||||||
|
void LockTester::Lock2()
|
||||||
|
{
|
||||||
|
BClipboard *clip = new BClipboard("Lock2");
|
||||||
|
|
||||||
|
/* This method isn't guaranteed to work, but *should* work.
|
||||||
|
Spawn a thread which locks the clipboard, waits several seconds
|
||||||
|
and then deletes the locked clipboard. After spawning
|
||||||
|
the thread, the main thread should keep checking if the clipboard
|
||||||
|
is locked. Once it is locked, the thread tries to lock it and gets
|
||||||
|
blocked. Once the clipboard is deleted, it should return false.
|
||||||
|
*/
|
||||||
|
thread_id thread = spawn_thread(LockTest2,"locktest",B_NORMAL_PRIORITY,clip);
|
||||||
|
|
||||||
|
while(!clip->IsLocked());
|
||||||
|
CHK(clip->Lock() == false);
|
||||||
|
kill_thread(thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool IsLocked()
|
||||||
|
@case 1
|
||||||
|
@results IsLocked() returns true
|
||||||
|
*/
|
||||||
|
void LockTester::IsLocked1()
|
||||||
|
{
|
||||||
|
BClipboard clip("IsLocked1");
|
||||||
|
|
||||||
|
clip.Lock();
|
||||||
|
CHK(clip.IsLocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool IsLocked()
|
||||||
|
@case 2
|
||||||
|
@results IsLocked() returns false
|
||||||
|
*/
|
||||||
|
void LockTester::IsLocked2()
|
||||||
|
{
|
||||||
|
BClipboard clip("IsLocked2");
|
||||||
|
|
||||||
|
CHK(!clip.IsLocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void Unlock()
|
||||||
|
@case 1
|
||||||
|
@results IsLocked() returns false
|
||||||
|
*/
|
||||||
|
void LockTester::Unlock1()
|
||||||
|
{
|
||||||
|
BClipboard clip("Unlock1");
|
||||||
|
|
||||||
|
clip.Lock();
|
||||||
|
CHK(clip.IsLocked());
|
||||||
|
clip.Unlock();
|
||||||
|
CHK(!clip.IsLocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
Test* LockTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, LockTester, Lock1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, LockTester, Lock2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, LockTester, IsLocked1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, LockTester, IsLocked2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, LockTester, Unlock1);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// LockTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef LOCK_TESTER_H
|
||||||
|
#define LOCK_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class LockTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LockTester() {;}
|
||||||
|
LockTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void Lock1();
|
||||||
|
void Lock2();
|
||||||
|
void IsLocked1();
|
||||||
|
void IsLocked2();
|
||||||
|
void Unlock1();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOCK_TESTER_H
|
||||||
|
|
||||||
@@ -0,0 +1,361 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// ReadWriteTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <Application.h>
|
||||||
|
#include <Clipboard.h>
|
||||||
|
|
||||||
|
#define CHK CPPUNIT_ASSERT
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "ReadWriteTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Clear()
|
||||||
|
@case 1
|
||||||
|
@results Clear() returns B_ERROR
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Clear1()
|
||||||
|
{
|
||||||
|
BClipboard clip("Clear1");
|
||||||
|
|
||||||
|
CHK(clip.Clear() == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Clear()
|
||||||
|
@case 1
|
||||||
|
@results Clear() returns B_OK
|
||||||
|
data message is empty
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Clear2()
|
||||||
|
{
|
||||||
|
BClipboard clip("Clear2");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
CHK(clip.Clear() == B_OK);
|
||||||
|
if ( (data = clip.Data()) )
|
||||||
|
CHK(data->IsEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Revert()
|
||||||
|
@case 1
|
||||||
|
@results Revert() returns B_ERROR
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Revert1()
|
||||||
|
{
|
||||||
|
BClipboard clip("Revert1");
|
||||||
|
|
||||||
|
CHK(clip.Revert() == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Revert()
|
||||||
|
@case 2
|
||||||
|
@results Revert() returns B_OK
|
||||||
|
data message is reset
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Revert2()
|
||||||
|
{
|
||||||
|
BClipboard clip("Revert2");
|
||||||
|
BMessage *data;
|
||||||
|
char *str;
|
||||||
|
ssize_t size;
|
||||||
|
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
clip.Clear();
|
||||||
|
if ( (data = clip.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "Revert2", 8);
|
||||||
|
clip.Commit();
|
||||||
|
}
|
||||||
|
clip.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
clip.Clear();
|
||||||
|
if ( (data = clip.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "Foo", 4);
|
||||||
|
}
|
||||||
|
CHK(clip.Revert() == B_OK);
|
||||||
|
if ( (data = clip.Data()) )
|
||||||
|
{
|
||||||
|
data->FindData("text/plain",B_MIME_TYPE, (const void **)&str, &size);
|
||||||
|
CHK(strcmp(str,"Revert2") == 0);
|
||||||
|
}
|
||||||
|
clip.Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Commit()
|
||||||
|
@case 1
|
||||||
|
@results Commit() returns B_ERROR
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Commit1()
|
||||||
|
{
|
||||||
|
BClipboard clip("Commit1");
|
||||||
|
|
||||||
|
CHK(clip.Commit() == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Commit()
|
||||||
|
@case 2
|
||||||
|
@results Commit() returns B_OK
|
||||||
|
data is uploaded from system
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Commit2()
|
||||||
|
{
|
||||||
|
BClipboard clipA("Commit2");
|
||||||
|
BClipboard clipB("Commit2");
|
||||||
|
BMessage *data;
|
||||||
|
char *str;
|
||||||
|
ssize_t size;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "Commit2", 8);
|
||||||
|
CHK(clipA.Commit() == B_OK);
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
if ( (data = clipB.Data()) )
|
||||||
|
{
|
||||||
|
data->FindData("text/plain",B_MIME_TYPE, (const void **)&str, &size);
|
||||||
|
CHK(strcmp(str,"Commit2") == 0);
|
||||||
|
}
|
||||||
|
clipB.Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BMessage *Data()
|
||||||
|
@case 1
|
||||||
|
@results Data() returns NULL
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Data1()
|
||||||
|
{
|
||||||
|
BClipboard clip("Data1");
|
||||||
|
|
||||||
|
CHK(!clip.Data());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BMessage *Data()
|
||||||
|
@case 2
|
||||||
|
@results Data() returns a message with correct data
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::Data2()
|
||||||
|
{
|
||||||
|
BClipboard clip("Data2");
|
||||||
|
BMessage *data;
|
||||||
|
char *str;
|
||||||
|
ssize_t size;
|
||||||
|
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
clip.Clear();
|
||||||
|
data = clip.Data();
|
||||||
|
CHK(data);
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "Data2", 6);
|
||||||
|
clip.Commit();
|
||||||
|
clip.Unlock();
|
||||||
|
}
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
data = clip.Data();
|
||||||
|
CHK(data);
|
||||||
|
data->FindData("text/plain",B_MIME_TYPE, (const void **)&str, &size);
|
||||||
|
CHK(strcmp(str,"Data2") == 0);
|
||||||
|
clip.Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BMessenger DataSource()
|
||||||
|
@case 1
|
||||||
|
@results DataSource returns and invalid BMessenger
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::DataSource1()
|
||||||
|
{
|
||||||
|
BClipboard clip("DataSource1");
|
||||||
|
|
||||||
|
CHK(!clip.DataSource().IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BMessenger DataSource()
|
||||||
|
@case 2
|
||||||
|
@results DataSource returns an invalid BMessenger
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::DataSource2()
|
||||||
|
{
|
||||||
|
BClipboard clipA("DataSource2");
|
||||||
|
BClipboard clipB("DataSource2");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "DataSource2", 12);
|
||||||
|
clipA.Commit();
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
CHK(!clipB.DataSource().IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BMessenger DataSource()
|
||||||
|
@case 3
|
||||||
|
@results DataSource returns a valid BMessenger
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::DataSource3()
|
||||||
|
{
|
||||||
|
BClipboard clipA("DataSource3");
|
||||||
|
BClipboard clipB("DataSource3");
|
||||||
|
BMessage *data;
|
||||||
|
|
||||||
|
if ( clipA.Lock() )
|
||||||
|
{
|
||||||
|
clipA.Clear();
|
||||||
|
if ( (data = clipA.Data()) )
|
||||||
|
{
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "DataSource3", 12);
|
||||||
|
clipA.Commit();
|
||||||
|
}
|
||||||
|
clipA.Unlock();
|
||||||
|
}
|
||||||
|
if ( clipB.Lock() )
|
||||||
|
{
|
||||||
|
CHK(clipB.DataSource().IsValid());
|
||||||
|
CHK(clipB.DataSource() == be_app_messenger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t StartWatching(BMessenger target)
|
||||||
|
@case 1
|
||||||
|
@results return B_OK, target is notified when clipboard is written
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::StartWatching1()
|
||||||
|
{
|
||||||
|
BClipboard clip("StartWatching1");
|
||||||
|
BMessage *data;
|
||||||
|
char *str;
|
||||||
|
ssize_t size;
|
||||||
|
|
||||||
|
RWHandler handler;
|
||||||
|
BMessenger target(&handler);
|
||||||
|
CHK(clip.StartWatching(target) == B_OK);
|
||||||
|
if ( clip.Lock() )
|
||||||
|
{
|
||||||
|
clip.Clear();
|
||||||
|
data = clip.Data();
|
||||||
|
data->AddData("text/plain",B_MIME_TYPE, "StartWatching1", 15);
|
||||||
|
clip.Commit();
|
||||||
|
clip.Unlock();
|
||||||
|
}
|
||||||
|
CHK(handler.ClipboardModified());
|
||||||
|
clip.StopWatching(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t StopWatching(BMessenger target)
|
||||||
|
@case 1
|
||||||
|
@results return B_OK
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::StopWatching1()
|
||||||
|
{
|
||||||
|
BClipboard clip("StopWatching1");
|
||||||
|
if ( clip.StartWatching(be_app_messenger) == B_OK )
|
||||||
|
{
|
||||||
|
CHK(clip.StopWatching(be_app_messenger) == B_OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t StopWatching(BMessenger target)
|
||||||
|
@case 2
|
||||||
|
@results return B_BAD_VALUE
|
||||||
|
*/
|
||||||
|
void ReadWriteTester::StopWatching2()
|
||||||
|
{
|
||||||
|
BClipboard clip("StopWatching2");
|
||||||
|
CHK(clip.StopWatching(be_app_messenger) == B_BAD_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test* ReadWriteTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Clear1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Clear2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Revert1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Revert2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Commit1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Commit2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Data1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, Data2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, DataSource1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, DataSource2);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, DataSource3);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, StartWatching1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, StopWatching1);
|
||||||
|
ADD_TEST4(BClipboard, SuiteOfTests, ReadWriteTester, StopWatching2);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RWHandler
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
RWHandler::RWHandler()
|
||||||
|
: BHandler()
|
||||||
|
{
|
||||||
|
fClipboardModified = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MessageReceived
|
||||||
|
void
|
||||||
|
RWHandler::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case B_CLIPBOARD_CHANGED:
|
||||||
|
fClipboardModified = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BHandler::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// ReadWriteTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef READ_WRITE_TESTER_H
|
||||||
|
#define READ_WRITE_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <Handler.h>
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class ReadWriteTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReadWriteTester() {;}
|
||||||
|
ReadWriteTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void Clear1();
|
||||||
|
void Clear2();
|
||||||
|
void Revert1();
|
||||||
|
void Revert2();
|
||||||
|
void Commit1();
|
||||||
|
void Commit2();
|
||||||
|
void Data1();
|
||||||
|
void Data2();
|
||||||
|
void DataSource1();
|
||||||
|
void DataSource2();
|
||||||
|
void DataSource3();
|
||||||
|
void StartWatching1();
|
||||||
|
void StopWatching1();
|
||||||
|
void StopWatching2();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
class RWHandler : public BHandler {
|
||||||
|
public:
|
||||||
|
RWHandler();
|
||||||
|
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
bool ClipboardModified();
|
||||||
|
private:
|
||||||
|
bool fClipboardModified;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // READ_WRITE_TESTER_H
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
BCursor(const void *cursorData)
|
||||||
|
case 1: cursorData is NULL =>
|
||||||
|
empty cursor object (useless)
|
||||||
|
case 2: cursorData points to valid data =>
|
||||||
|
valid cursor object
|
||||||
|
case 3: cursorData points to invalid data =>
|
||||||
|
empty cursor object (useless)
|
||||||
|
|
||||||
|
BCursor(BMessage *archive)
|
||||||
|
case 1: archive is NULL =>
|
||||||
|
empty cursor object (useless)
|
||||||
|
case 2: archive points to a valid archive =>
|
||||||
|
empty cursor object (useless, R5 does not support archiving)
|
||||||
|
|
||||||
|
static BArchivable *Instantiate(BMessage *archive)
|
||||||
|
case 1: archive is NULL =>
|
||||||
|
returns NULL
|
||||||
|
case 2: archive points to a valid archive =>
|
||||||
|
returns NULL (R5 does not support archiving)
|
||||||
|
|
||||||
|
status_t Archive(BMessage* into, bool deep = true)
|
||||||
|
case 1: into is NULL =>
|
||||||
|
returns B_OK
|
||||||
|
case 2: into is a valid message =>
|
||||||
|
returns B_OK (archiving not implemented in R5)
|
||||||
|
|
||||||
|
status_t Perform(perform_code d, void* arg)
|
||||||
|
case 1: arg is NULL =>
|
||||||
|
returns B_OK
|
||||||
|
case 2: arg points to something =>
|
||||||
|
returns B_OK
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// BCursorTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <Cursor.h>
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
#define CHK CPPUNIT_ASSERT
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "BCursorTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
BCursor(const void *cursorData)
|
||||||
|
@case 1
|
||||||
|
@results nothing apparent (no segfault)
|
||||||
|
*/
|
||||||
|
void BCursorTester::BCursor1()
|
||||||
|
{
|
||||||
|
BCursor cur((void *)NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BCursor(const void *cursorData)
|
||||||
|
@case 2
|
||||||
|
@results nothing apparent
|
||||||
|
*/
|
||||||
|
void BCursorTester::BCursor2()
|
||||||
|
{
|
||||||
|
char data[68];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
data[0] = 16;
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 0;
|
||||||
|
data[3] = 0;
|
||||||
|
for (i=4; i<68; i++)
|
||||||
|
data[i] = 1;
|
||||||
|
|
||||||
|
BCursor cur(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BCursor(const void *cursorData)
|
||||||
|
@case 3
|
||||||
|
@results nothing apparent (no segfaults)
|
||||||
|
*/
|
||||||
|
void BCursorTester::BCursor3()
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
BCursor cur1(&x);
|
||||||
|
char data[68];
|
||||||
|
data[0] = 32;
|
||||||
|
BCursor cur2(data);
|
||||||
|
data[0] = 16;
|
||||||
|
data[1] = 8;
|
||||||
|
BCursor cur3(data);
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 16;
|
||||||
|
data[3] = 16;
|
||||||
|
BCursor cur4(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BCursor(BMessage *archive)
|
||||||
|
@case 1
|
||||||
|
@results nothing apparent (no segfault)
|
||||||
|
*/
|
||||||
|
void BCursorTester::BCursor4()
|
||||||
|
{
|
||||||
|
BCursor cur((BMessage *)NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BCursor(BMessage *archive)
|
||||||
|
@case 2
|
||||||
|
@results nothing apparent (empty cursor)
|
||||||
|
*/
|
||||||
|
void BCursorTester::BCursor5()
|
||||||
|
{
|
||||||
|
/* The message really should contain a valid archive, but Cursor doesn't
|
||||||
|
support archiving anyway, so until R2, this is a moot point.
|
||||||
|
*/
|
||||||
|
BMessage msg;
|
||||||
|
BCursor cur(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
static BArchivable *Instantiate(BMessage *archive)
|
||||||
|
@case 1
|
||||||
|
@results return NULL
|
||||||
|
*/
|
||||||
|
void BCursorTester::Instantiate1()
|
||||||
|
{
|
||||||
|
CHK(BCursor::Instantiate(NULL) == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
static BArchivable *Instantiate(BMessage *archive)
|
||||||
|
@case 2
|
||||||
|
@results return NULL
|
||||||
|
*/
|
||||||
|
void BCursorTester::Instantiate2()
|
||||||
|
{
|
||||||
|
/* The message really should contain a valid archive, but Cursor doesn't
|
||||||
|
support archiving anyway, so until R2, this is a moot point.
|
||||||
|
*/
|
||||||
|
BMessage msg;
|
||||||
|
CHK(BCursor::Instantiate(&msg) == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Archive(BMessage* into, bool deep = true)
|
||||||
|
@case 1
|
||||||
|
@results return B_OK
|
||||||
|
*/
|
||||||
|
void BCursorTester::Archive1()
|
||||||
|
{
|
||||||
|
char data[68];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
data[0] = 16;
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 0;
|
||||||
|
data[3] = 0;
|
||||||
|
for (i=4; i<68; i++)
|
||||||
|
data[i] = 1;
|
||||||
|
|
||||||
|
BCursor cur(data);
|
||||||
|
CHK(cur.Archive(NULL) == B_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Archive(BMessage* into, bool deep = true)
|
||||||
|
@case 2
|
||||||
|
@results return B_OK
|
||||||
|
*/
|
||||||
|
void BCursorTester::Archive2()
|
||||||
|
{
|
||||||
|
char data[68];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
data[0] = 16;
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 0;
|
||||||
|
data[3] = 0;
|
||||||
|
for (i=4; i<68; i++)
|
||||||
|
data[i] = 1;
|
||||||
|
|
||||||
|
BCursor cur(data);
|
||||||
|
BMessage msg;
|
||||||
|
CHK(cur.Archive(&msg) == B_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Perform(perform_code d, void* arg)
|
||||||
|
@case 1
|
||||||
|
@results return B_OK
|
||||||
|
*/
|
||||||
|
void BCursorTester::Perform1()
|
||||||
|
{
|
||||||
|
char data[68];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
data[0] = 16;
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 0;
|
||||||
|
data[3] = 0;
|
||||||
|
for (i=4; i<68; i++)
|
||||||
|
data[i] = 1;
|
||||||
|
|
||||||
|
BCursor cur(data);
|
||||||
|
CHK(cur.Perform(0,NULL) == B_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t Perform(perform_code d, void* arg)
|
||||||
|
@case 2
|
||||||
|
@results return B_OK
|
||||||
|
*/
|
||||||
|
void BCursorTester::Perform2()
|
||||||
|
{
|
||||||
|
char data[68];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
data[0] = 16;
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 0;
|
||||||
|
data[3] = 0;
|
||||||
|
for (i=4; i<68; i++)
|
||||||
|
data[i] = 1;
|
||||||
|
|
||||||
|
BCursor cur(data);
|
||||||
|
CHK(cur.Perform(0,&i) == B_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test* BCursorTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor1);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor2);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor3);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor4);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor5);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Instantiate1);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Instantiate2);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Archive1);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Archive2);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Perform1);
|
||||||
|
ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Perform2);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// BCursorTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef B_CURSOR_TESTER_H
|
||||||
|
#define B_CURSOR_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class BCursorTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BCursorTester() {;}
|
||||||
|
BCursorTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void BCursor1();
|
||||||
|
void BCursor2();
|
||||||
|
void BCursor3();
|
||||||
|
void BCursor4();
|
||||||
|
void BCursor5();
|
||||||
|
void Instantiate1();
|
||||||
|
void Instantiate2();
|
||||||
|
void Archive1();
|
||||||
|
void Archive2();
|
||||||
|
void Perform1();
|
||||||
|
void Perform2();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // B_CURSOR_TESTER_H
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
#include "BCursorTester.h"
|
||||||
|
|
||||||
|
CppUnit::Test* CursorTestSuite()
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
||||||
|
|
||||||
|
testSuite->addTest(BCursorTester::Suite());
|
||||||
|
|
||||||
|
return testSuite;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef _cursor_test_h_
|
||||||
|
#define _cursor_test_h_
|
||||||
|
|
||||||
|
class CppUnit::Test;
|
||||||
|
|
||||||
|
CppUnit::Test* CursorTestSuite();
|
||||||
|
|
||||||
|
#endif // _cursor_test_h_
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
SubDir OBOS_TOP src tests kits app bcursor ;
|
||||||
Reference in New Issue
Block a user