gdiplus: Add some tests for GdipGetPropertySize and GdipGetAllPropertyItems.

This commit is contained in:
Dmitry Timoshkov 2012-07-02 13:00:20 +09:00 committed by Alexandre Julliard
parent 3c9805d471
commit b61a1ba322
1 changed files with 169 additions and 0 deletions

View File

@ -3127,6 +3127,174 @@ static void test_tiff_properties(void)
GdipDisposeImage(image);
}
static void test_GdipGetAllPropertyItems(void)
{
static const struct test_data
{
ULONG type, id, length;
BYTE value[32];
} td[16] =
{
{ PropertyTagTypeLong, 0xfe, 4, { 0 } },
{ PropertyTagTypeShort, 0x100, 2, { 1 } },
{ PropertyTagTypeShort, 0x101, 2, { 1 } },
{ PropertyTagTypeShort, 0x102, 6, { 8,0,8,0,8,0 } },
{ PropertyTagTypeShort, 0x103, 2, { 1 } },
{ PropertyTagTypeShort, 0x106, 2, { 2,0 } },
{ PropertyTagTypeASCII, 0x10d, 27, "/home/meh/Desktop/test.tif" },
{ PropertyTagTypeLong, 0x111, 4, { 8,0,0,0 } },
{ PropertyTagTypeShort, 0x112, 2, { 1 } },
{ PropertyTagTypeShort, 0x115, 2, { 3,0 } },
{ PropertyTagTypeShort, 0x116, 2, { 0x40,0 } },
{ PropertyTagTypeLong, 0x117, 4, { 3,0,0,0 } },
{ PropertyTagTypeRational, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
{ PropertyTagTypeRational, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
{ PropertyTagTypeShort, 0x11c, 2, { 1 } },
{ PropertyTagTypeShort, 0x128, 2, { 2 } }
};
GpStatus status;
GpImage *image;
GUID guid;
UINT dim_count, frame_count, prop_count, prop_size, i;
UINT total_size, total_count;
PROPID *prop_id;
PropertyItem *prop_item;
const char *item_data;
image = load_image(tiffimage, sizeof(tiffimage));
ok(image != 0, "Failed to load TIFF image data\n");
if (!image) return;
dim_count = 0xdeadbeef;
status = GdipImageGetFrameDimensionsCount(image, &dim_count);
expect(Ok, status);
expect(1, dim_count);
status = GdipImageGetFrameDimensionsList(image, &guid, 1);
expect(Ok, status);
expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
frame_count = 0xdeadbeef;
status = GdipImageGetFrameCount(image, &guid, &frame_count);
expect(Ok, status);
expect(1, frame_count);
prop_count = 0xdeadbeef;
status = GdipGetPropertyCount(image, &prop_count);
expect(Ok, status);
ok(prop_count == sizeof(td)/sizeof(td[0]),
"expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
status = GdipGetPropertyIdList(image, prop_count, prop_id);
expect(Ok, status);
prop_size = 0;
for (i = 0; i < prop_count; i++)
{
UINT size;
status = GdipGetPropertyItemSize(image, prop_id[i], &size);
expect(Ok, status);
if (status != Ok) break;
ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
prop_size += size;
prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
expect(Ok, status);
ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
ok(td[i].type == prop_item->type,
"%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
size -= sizeof(*prop_item);
ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
if (td[i].length == prop_item->length)
{
int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
ok(match, "%u: data mismatch\n", i);
if (!match)
{
UINT j;
BYTE *data = prop_item->value;
printf("id %#x:", prop_item->id);
for (j = 0; j < prop_item->length; j++)
printf(" %02x", data[j]);
printf("\n");
}
}
HeapFree(GetProcessHeap(), 0, prop_item);
}
HeapFree(GetProcessHeap(), 0, prop_id);
status = GdipGetPropertySize(NULL, &total_size, &total_count);
expect(InvalidParameter, status);
status = GdipGetPropertySize(image, &total_size, NULL);
expect(InvalidParameter, status);
status = GdipGetPropertySize(image, NULL, &total_count);
expect(InvalidParameter, status);
status = GdipGetPropertySize(image, NULL, NULL);
expect(InvalidParameter, status);
total_size = 0xdeadbeef;
total_count = 0xdeadbeef;
status = GdipGetPropertySize(image, &total_size, &total_count);
expect(Ok, status);
ok(prop_count == total_count,
"expected total property count %u, got %u\n", prop_count, total_count);
ok(prop_size == total_size,
"expected total property size %u, got %u\n", prop_size, total_size);
prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
expect(InvalidParameter, status);
status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
expect(InvalidParameter, status);
status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
expect(InvalidParameter, status);
status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
expect(InvalidParameter, status);
status = GdipGetAllPropertyItems(image, 0, 0, NULL);
expect(InvalidParameter, status);
status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
expect(InvalidParameter, status);
status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
expect(Ok, status);
item_data = (const char *)(prop_item + prop_count);
for (i = 0; i < prop_count; i++)
{
ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
i, item_data, prop_item[i].value);
ok(td[i].type == prop_item[i].type,
"%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
if (td[i].length == prop_item[i].length)
{
int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
ok(match, "%u: data mismatch\n", i);
if (!match)
{
UINT j;
BYTE *data = prop_item[i].value;
printf("id %#x:", prop_item[i].id);
for (j = 0; j < prop_item[i].length; j++)
printf(" %02x", data[j]);
printf("\n");
}
}
item_data += prop_item[i].length;
}
HeapFree(GetProcessHeap(), 0, prop_item);
GdipDisposeImage(image);
}
START_TEST(image)
{
struct GdiplusStartupInput gdiplusStartupInput;
@ -3139,6 +3307,7 @@ START_TEST(image)
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
test_GdipGetAllPropertyItems();
test_tiff_properties();
test_image_properties();
test_Scan0();