* More error checking.

* Added more bitmap test cases. Reveals a interface kit bug: the
  1024x768 bitmap is not drawn at all!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22192 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2007-09-06 16:00:20 +00:00
parent df96d14d39
commit 4f422578c0
3 changed files with 85 additions and 26 deletions

View File

@ -16,7 +16,7 @@
#define TEST_AND_RETURN(condition, message, result) \
{ \
if (condition) { \
fErrorMessage = message; \
SetErrorMessage(message); \
return result; \
} \
}
@ -173,6 +173,13 @@ PictureTest::CleanUp()
fErrorMessage = "";
}
void
PictureTest::SetErrorMessage(const char *message)
{
if (fErrorMessage.Length() == 0)
fErrorMessage = message;
}
bool
PictureTest::Test(draw_func* func, BRect frame)
{
@ -205,8 +212,7 @@ BBitmap *
PictureTest::CreateBitmap(draw_func* func, BRect frame)
{
OffscreenBitmap bitmap(frame, fColorSpace);
if (bitmap.InitCheck() != B_OK)
return NULL;
TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for direct drawing could not be created!" , NULL);
func(bitmap.View(), frame);
return bitmap.Copy();
}
@ -215,8 +221,7 @@ BPicture *
PictureTest::RecordPicture(draw_func* func, BRect frame)
{
OffscreenBitmap bitmap(frame, fColorSpace);
if (bitmap.InitCheck() != B_OK)
return NULL;
TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for picture recording could not be created!" , NULL);
BView *view = bitmap.View();
// record
@ -232,8 +237,7 @@ BBitmap *
PictureTest::CreateBitmap(BPicture *picture, BRect frame)
{
OffscreenBitmap bitmap(frame, fColorSpace);
if (bitmap.InitCheck() != B_OK)
return NULL;
TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for picture drawing could not be created!" , NULL);
BView *view = bitmap.View();
view->DrawPicture(picture);
@ -265,15 +269,13 @@ FlattenPictureTest::SaveAndRestore(BPicture *picture)
{
BMallocIO *data = new BMallocIO();
AutoDelete<BMallocIO> _data(data);
if (data == NULL)
return NULL;
TEST_AND_RETURN(data == NULL, "BMallocIO could not be allocated for flattening the picture!" , NULL);
picture->Flatten(data);
data->Seek(0, SEEK_SET);
BPicture *archivedPicture = new BPicture();
if (archivedPicture == NULL)
return NULL;
TEST_AND_RETURN(archivedPicture == NULL, "BPicture could not be allocated for unflattening the picture!" , NULL);
archivedPicture->Unflatten(data);
return archivedPicture;
@ -287,13 +289,16 @@ BPicture *
ArchivePictureTest::SaveAndRestore(BPicture *picture)
{
BMessage archive;
if (picture->Archive(&archive) != B_OK)
return NULL;
TEST_AND_RETURN(picture->Archive(&archive) != B_OK, "Picture could not be archived to BMessage", NULL);
BPicture *archivedPicture = new BPicture(&archive);
if (archivedPicture == NULL)
return NULL;
BArchivable *archivable = BPicture::Instantiate(&archive);
AutoDelete<BArchivable> _archivable(archivable);
TEST_AND_RETURN(archivable == NULL, "Picture could not be instantiated from BMessage", NULL);
BPicture *archivedPicture = dynamic_cast<BPicture*>(archivable);
TEST_AND_RETURN(archivedPicture == NULL, "Picture could not be restored from BMessage", NULL);
_archivable.Release();
return archivedPicture;
}

View File

@ -32,6 +32,7 @@ public:
protected:
virtual BPicture *SaveAndRestore(BPicture *picture) = 0;
void SetErrorMessage(const char* message);
private:

View File

@ -315,22 +315,72 @@ static void testInvertRect(BView *view, BRect frame)
view->InvertRect(frame);
}
static void testBitmap(BView *view, BRect frame) {
BBitmap bitmap(frame, B_RGBA32);
for (int32 y = 0; y < bitmap.Bounds().IntegerHeight(); y ++) {
for (int32 x = 0; x < bitmap.Bounds().IntegerWidth(); x ++) {
static bool isBorder(int32 x, int32 y, int32 width, int32 height) {
return x == 0 || y == 0 || x == width - 1 || y == height - 1;
}
static void fillBitmap(BBitmap &bitmap) {
int32 height = bitmap.Bounds().IntegerHeight()+1;
int32 width = bitmap.Bounds().IntegerWidth()+1;
for (int32 y = 0; y < height; y ++) {
for (int32 x = 0; x < width; x ++) {
char *pixel = (char*)bitmap.Bits();
pixel += bitmap.BytesPerRow() * y + 4 * x;
// fill with blue
pixel[0] = 255;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 255;
if (isBorder(x, y, width, height)) {
// fill with green
pixel[0] = 255;
pixel[1] = 0;
pixel[2] = 255;
pixel[3] = 0;
} else {
// fill with blue
pixel[0] = 255;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 255;
}
}
}
}
static void testDrawBitmap(BView *view, BRect frame) {
BBitmap bitmap(frame, B_RGBA32);
fillBitmap(bitmap);
view->DrawBitmap(&bitmap, BPoint(0, 0));
}
static void testDrawBitmapAtPoint(BView *view, BRect frame) {
frame.InsetBy(2, 2);
BRect bounds(frame);
bounds.OffsetTo(0, 0);
bounds.right /= 2;
bounds.bottom /= 2;
BBitmap bitmap(bounds, B_RGBA32);
fillBitmap(bitmap);
view->DrawBitmap(&bitmap, centerPoint(frame));
}
static void testDrawBitmapAtRect(BView *view, BRect frame) {
BRect bounds(frame);
BBitmap bitmap(bounds, B_RGBA32);
fillBitmap(bitmap);
frame.InsetBy(2, 2);
view->DrawBitmap(&bitmap, frame);
}
static void testDrawLargeBitmap(BView *view, BRect frame) {
BRect bounds(frame);
bounds.OffsetTo(0, 0);
bounds.left = 1024;
bounds.bottom = 767;
BBitmap bitmap(bounds, B_RGBA32);
fillBitmap(bitmap);
frame.InsetBy(2, 2);
view->DrawBitmap(&bitmap, frame);
}
static void testConstrainClippingRegion(BView *view, BRect frame)
{
frame.InsetBy(2, 2);
@ -672,7 +722,10 @@ TestCase gTestCases[] = {
{ "Test AppendToPicture", testAppendToPicture },
{ "Test LineArray", testLineArray },
{ "Test InvertRect", testInvertRect },
{ "Test Bitmap", testBitmap },
{ "Test DrawBitmap", testDrawBitmap },
{ "Test DrawBitmapAtPoint", testDrawBitmapAtPoint },
{ "Test DrawBitmapAtRect", testDrawBitmapAtRect },
{ "Test DrawDrawLargeBitmap", testDrawLargeBitmap },
{ "Test ConstrainClippingRegion", testConstrainClippingRegion },
{ "Test ClipToPicture", testClipToPicture },
{ "Test ClipToInversePicture", testClipToInversePicture },