Commit 757012cd authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

gdiplus: Test the types of records in an empty EMF+.

parent a06b4bc5
......@@ -25,6 +25,129 @@
#define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
typedef struct emfplus_record
{
ULONG todo;
ULONG record_type;
int is_emfplus;
} emfplus_record;
typedef struct emfplus_check_state
{
const char *desc;
int count;
const struct emfplus_record *expected;
} emfplus_check_state;
static void check_record(int count, const char *desc, const struct emfplus_record *expected, const struct emfplus_record *actual)
{
ok(expected->record_type == actual->record_type,
"%s.%i: Expected record type 0x%x, got 0x%x\n", desc, count,
expected->record_type, actual->record_type);
ok(expected->is_emfplus == actual->is_emfplus,
"%s.%i: Expected is_emfplus %i, got %i\n", desc, count,
expected->record_type, actual->record_type);
}
typedef struct EmfPlusRecordHeader
{
WORD Type;
WORD Flags;
DWORD Size;
DWORD DataSize;
} EmfPlusRecordHeader;
static int CALLBACK enum_emf_proc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETARECORD *lpEMFR,
int nObj, LPARAM lpData)
{
emfplus_check_state *state = (emfplus_check_state*)lpData;
emfplus_record actual;
if (lpEMFR->iType == EMR_GDICOMMENT)
{
const EMRGDICOMMENT *comment = (const EMRGDICOMMENT*)lpEMFR;
if (comment->cbData >= 4 && memcmp(comment->Data, "EMF+", 4) == 0)
{
int offset = 4;
while (offset + sizeof(EmfPlusRecordHeader) <= comment->cbData)
{
const EmfPlusRecordHeader *record = (const EmfPlusRecordHeader*)&comment->Data[offset];
ok(record->Size == record->DataSize + sizeof(EmfPlusRecordHeader),
"%s: EMF+ record datasize %u and size %u mismatch\n", state->desc, record->DataSize, record->Size);
ok(offset + record->DataSize <= comment->cbData,
"%s: EMF+ record truncated\n", state->desc);
if (offset + record->DataSize > comment->cbData)
return 0;
if (state->expected[state->count].record_type)
{
actual.todo = 0;
actual.record_type = record->Type;
actual.is_emfplus = 1;
check_record(state->count, state->desc, &state->expected[state->count], &actual);
state->count++;
}
else
{
ok(0, "%s: Unexpected EMF+ 0x%x record\n", state->desc, record->Type);
}
offset += record->Size;
}
ok(offset == comment->cbData, "%s: truncated EMF+ record data?\n", state->desc);
return 1;
}
}
if (state->expected[state->count].record_type)
{
actual.todo = 0;
actual.record_type = lpEMFR->iType;
actual.is_emfplus = 0;
check_record(state->count, state->desc, &state->expected[state->count], &actual);
state->count++;
}
else
{
ok(0, "%s: Unexpected EMF 0x%x record\n", state->desc, lpEMFR->iType);
}
return 1;
}
static void check_emfplus(HENHMETAFILE hemf, const emfplus_record *expected, const char *desc)
{
emfplus_check_state state;
state.desc = desc;
state.count = 0;
state.expected = expected;
EnumEnhMetaFile(0, hemf, enum_emf_proc, &state, NULL);
ok(expected[state.count].record_type == 0, "%s: Got %i records, expecting more\n", desc, state.count);
}
static const emfplus_record empty_records[] = {
{0, EMR_HEADER, 0},
{0, EmfPlusRecordTypeHeader, 1},
{0, EmfPlusRecordTypeEndOfFile, 1},
{0, EMR_EOF, 0},
{0}
};
static void test_empty(void)
{
GpStatus stat;
......@@ -67,6 +190,8 @@ static void test_empty(void)
stat = GdipDisposeImage((GpImage*)metafile);
expect(Ok, stat);
check_emfplus(hemf, empty_records, "empty");
ret = DeleteEnhMetaFile(hemf);
ok(ret != 0, "Failed to delete enhmetafile %p\n", hemf);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment