gdiplus: Add more sophisticated tests for GdipSaveImageToFile.

Add a test to make sure the saved image has the same dimensions as
original. Delete the test file when finished.
This commit is contained in:
Nathan Beckmann 2008-03-10 08:16:57 -07:00 committed by Alexandre Julliard
parent 75841d8323
commit 67e811cc3c
1 changed files with 19 additions and 2 deletions

View File

@ -128,6 +128,8 @@ static void test_SavingImages(void)
GpBitmap *bm; GpBitmap *bm;
UINT n; UINT n;
UINT s; UINT s;
const REAL WIDTH = 10.0, HEIGHT = 20.0;
REAL w, h;
ImageCodecInfo *codecs; ImageCodecInfo *codecs;
static const WCHAR filename[] = { 'a','.','b','m','p',0 }; static const WCHAR filename[] = { 'a','.','b','m','p',0 };
@ -137,7 +139,7 @@ static void test_SavingImages(void)
expect(InvalidParameter, stat); expect(InvalidParameter, stat);
bm = NULL; bm = NULL;
stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm); stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
expect(Ok, stat); expect(Ok, stat);
if (!bm) if (!bm)
return; return;
@ -149,7 +151,7 @@ static void test_SavingImages(void)
stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0); stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
expect(InvalidParameter, stat); expect(InvalidParameter, stat);
/* this should succeed */ /* encoder tests should succeed -- already tested */
stat = GdipGetImageEncodersSize(&n, &s); stat = GdipGetImageEncodersSize(&n, &s);
if (stat != Ok || n == 0) goto cleanup; if (stat != Ok || n == 0) goto cleanup;
@ -162,11 +164,26 @@ static void test_SavingImages(void)
stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0); stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
expect(stat, Ok); expect(stat, Ok);
GdipDisposeImage((GpImage*)bm);
bm = 0;
/* re-load and check image stats */
stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
expect(stat, Ok);
if (stat != Ok) goto cleanup;
stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
if (stat != Ok) goto cleanup;
ok((fabs(w - WIDTH) < 0.01) && (fabs(h - HEIGHT) < 0.01),
"Saved image dimensions are different!\n");
cleanup: cleanup:
if (codecs) if (codecs)
GdipFree(codecs); GdipFree(codecs);
if (bm) if (bm)
GdipDisposeImage((GpImage*)bm); GdipDisposeImage((GpImage*)bm);
ok(DeleteFileW(filename), "Delete failed.\n");
} }
static void test_encoders(void) static void test_encoders(void)