* 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:
parent
df96d14d39
commit
4f422578c0
@ -16,7 +16,7 @@
|
|||||||
#define TEST_AND_RETURN(condition, message, result) \
|
#define TEST_AND_RETURN(condition, message, result) \
|
||||||
{ \
|
{ \
|
||||||
if (condition) { \
|
if (condition) { \
|
||||||
fErrorMessage = message; \
|
SetErrorMessage(message); \
|
||||||
return result; \
|
return result; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
@ -173,6 +173,13 @@ PictureTest::CleanUp()
|
|||||||
fErrorMessage = "";
|
fErrorMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PictureTest::SetErrorMessage(const char *message)
|
||||||
|
{
|
||||||
|
if (fErrorMessage.Length() == 0)
|
||||||
|
fErrorMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PictureTest::Test(draw_func* func, BRect frame)
|
PictureTest::Test(draw_func* func, BRect frame)
|
||||||
{
|
{
|
||||||
@ -205,8 +212,7 @@ BBitmap *
|
|||||||
PictureTest::CreateBitmap(draw_func* func, BRect frame)
|
PictureTest::CreateBitmap(draw_func* func, BRect frame)
|
||||||
{
|
{
|
||||||
OffscreenBitmap bitmap(frame, fColorSpace);
|
OffscreenBitmap bitmap(frame, fColorSpace);
|
||||||
if (bitmap.InitCheck() != B_OK)
|
TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for direct drawing could not be created!" , NULL);
|
||||||
return NULL;
|
|
||||||
func(bitmap.View(), frame);
|
func(bitmap.View(), frame);
|
||||||
return bitmap.Copy();
|
return bitmap.Copy();
|
||||||
}
|
}
|
||||||
@ -215,8 +221,7 @@ BPicture *
|
|||||||
PictureTest::RecordPicture(draw_func* func, BRect frame)
|
PictureTest::RecordPicture(draw_func* func, BRect frame)
|
||||||
{
|
{
|
||||||
OffscreenBitmap bitmap(frame, fColorSpace);
|
OffscreenBitmap bitmap(frame, fColorSpace);
|
||||||
if (bitmap.InitCheck() != B_OK)
|
TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for picture recording could not be created!" , NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
BView *view = bitmap.View();
|
BView *view = bitmap.View();
|
||||||
// record
|
// record
|
||||||
@ -232,8 +237,7 @@ BBitmap *
|
|||||||
PictureTest::CreateBitmap(BPicture *picture, BRect frame)
|
PictureTest::CreateBitmap(BPicture *picture, BRect frame)
|
||||||
{
|
{
|
||||||
OffscreenBitmap bitmap(frame, fColorSpace);
|
OffscreenBitmap bitmap(frame, fColorSpace);
|
||||||
if (bitmap.InitCheck() != B_OK)
|
TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for picture drawing could not be created!" , NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
BView *view = bitmap.View();
|
BView *view = bitmap.View();
|
||||||
view->DrawPicture(picture);
|
view->DrawPicture(picture);
|
||||||
@ -265,15 +269,13 @@ FlattenPictureTest::SaveAndRestore(BPicture *picture)
|
|||||||
{
|
{
|
||||||
BMallocIO *data = new BMallocIO();
|
BMallocIO *data = new BMallocIO();
|
||||||
AutoDelete<BMallocIO> _data(data);
|
AutoDelete<BMallocIO> _data(data);
|
||||||
if (data == NULL)
|
TEST_AND_RETURN(data == NULL, "BMallocIO could not be allocated for flattening the picture!" , NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
picture->Flatten(data);
|
picture->Flatten(data);
|
||||||
|
|
||||||
data->Seek(0, SEEK_SET);
|
data->Seek(0, SEEK_SET);
|
||||||
BPicture *archivedPicture = new BPicture();
|
BPicture *archivedPicture = new BPicture();
|
||||||
if (archivedPicture == NULL)
|
TEST_AND_RETURN(archivedPicture == NULL, "BPicture could not be allocated for unflattening the picture!" , NULL);
|
||||||
return NULL;
|
|
||||||
archivedPicture->Unflatten(data);
|
archivedPicture->Unflatten(data);
|
||||||
|
|
||||||
return archivedPicture;
|
return archivedPicture;
|
||||||
@ -287,13 +289,16 @@ BPicture *
|
|||||||
ArchivePictureTest::SaveAndRestore(BPicture *picture)
|
ArchivePictureTest::SaveAndRestore(BPicture *picture)
|
||||||
{
|
{
|
||||||
BMessage archive;
|
BMessage archive;
|
||||||
if (picture->Archive(&archive) != B_OK)
|
TEST_AND_RETURN(picture->Archive(&archive) != B_OK, "Picture could not be archived to BMessage", NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
BPicture *archivedPicture = new BPicture(&archive);
|
BArchivable *archivable = BPicture::Instantiate(&archive);
|
||||||
if (archivedPicture == NULL)
|
AutoDelete<BArchivable> _archivable(archivable);
|
||||||
return NULL;
|
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;
|
return archivedPicture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BPicture *SaveAndRestore(BPicture *picture) = 0;
|
virtual BPicture *SaveAndRestore(BPicture *picture) = 0;
|
||||||
|
void SetErrorMessage(const char* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -315,22 +315,72 @@ static void testInvertRect(BView *view, BRect frame)
|
|||||||
view->InvertRect(frame);
|
view->InvertRect(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testBitmap(BView *view, BRect frame) {
|
static bool isBorder(int32 x, int32 y, int32 width, int32 height) {
|
||||||
BBitmap bitmap(frame, B_RGBA32);
|
return x == 0 || y == 0 || x == width - 1 || y == height - 1;
|
||||||
for (int32 y = 0; y < bitmap.Bounds().IntegerHeight(); y ++) {
|
}
|
||||||
for (int32 x = 0; x < bitmap.Bounds().IntegerWidth(); x ++) {
|
|
||||||
|
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();
|
char *pixel = (char*)bitmap.Bits();
|
||||||
pixel += bitmap.BytesPerRow() * y + 4 * x;
|
pixel += bitmap.BytesPerRow() * y + 4 * x;
|
||||||
// fill with blue
|
if (isBorder(x, y, width, height)) {
|
||||||
pixel[0] = 255;
|
// fill with green
|
||||||
pixel[1] = 0;
|
pixel[0] = 255;
|
||||||
pixel[2] = 0;
|
pixel[1] = 0;
|
||||||
pixel[3] = 255;
|
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));
|
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)
|
static void testConstrainClippingRegion(BView *view, BRect frame)
|
||||||
{
|
{
|
||||||
frame.InsetBy(2, 2);
|
frame.InsetBy(2, 2);
|
||||||
@ -672,7 +722,10 @@ TestCase gTestCases[] = {
|
|||||||
{ "Test AppendToPicture", testAppendToPicture },
|
{ "Test AppendToPicture", testAppendToPicture },
|
||||||
{ "Test LineArray", testLineArray },
|
{ "Test LineArray", testLineArray },
|
||||||
{ "Test InvertRect", testInvertRect },
|
{ "Test InvertRect", testInvertRect },
|
||||||
{ "Test Bitmap", testBitmap },
|
{ "Test DrawBitmap", testDrawBitmap },
|
||||||
|
{ "Test DrawBitmapAtPoint", testDrawBitmapAtPoint },
|
||||||
|
{ "Test DrawBitmapAtRect", testDrawBitmapAtRect },
|
||||||
|
{ "Test DrawDrawLargeBitmap", testDrawLargeBitmap },
|
||||||
{ "Test ConstrainClippingRegion", testConstrainClippingRegion },
|
{ "Test ConstrainClippingRegion", testConstrainClippingRegion },
|
||||||
{ "Test ClipToPicture", testClipToPicture },
|
{ "Test ClipToPicture", testClipToPicture },
|
||||||
{ "Test ClipToInversePicture", testClipToInversePicture },
|
{ "Test ClipToInversePicture", testClipToInversePicture },
|
||||||
|
Loading…
Reference in New Issue
Block a user