2 * Copyright 2011 Vincent Povirk for CodeWeavers
3 * Copyright 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wincodecsdk.h"
31 #include "wine/test.h"
33 #define expect_blob(propvar, data, length) do { \
34 ok((propvar).vt == VT_BLOB, "unexpected vt: %i\n", (propvar).vt); \
35 if ((propvar).vt == VT_BLOB) { \
36 ok(U(propvar).blob.cbSize == (length), "expected size %u, got %u\n", (ULONG)(length), U(propvar).blob.cbSize); \
37 if (U(propvar).blob.cbSize == (length)) { \
38 ok(!memcmp(U(propvar).blob.pBlobData, (data), (length)), "unexpected data\n"); \
47 #define IFD_RATIONAL 5
49 #define IFD_UNDEFINED 7
52 #define IFD_SRATIONAL 10
72 static const struct ifd_data
74 USHORT number_of_entries;
75 struct IFD_entry entry[40];
77 struct IFD_rational xres;
79 struct IFD_rational srational_val;
84 struct IFD_rational rational[3];
89 { 0xfe, IFD_SHORT, 1, 1 }, /* NEWSUBFILETYPE */
90 { 0x100, IFD_LONG, 1, 222 }, /* IMAGEWIDTH */
91 { 0x101, IFD_LONG, 1, 333 }, /* IMAGELENGTH */
92 { 0x102, IFD_SHORT, 1, 24 }, /* BITSPERSAMPLE */
93 { 0x103, IFD_LONG, 1, 32773 }, /* COMPRESSION: packbits */
94 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct ifd_data, xres) },
95 { 0xf001, IFD_BYTE, 1, 0x11223344 },
96 { 0xf002, IFD_BYTE, 4, 0x11223344 },
97 { 0xf003, IFD_SBYTE, 1, 0x11223344 },
98 { 0xf004, IFD_SSHORT, 1, 0x11223344 },
99 { 0xf005, IFD_SSHORT, 2, 0x11223344 },
100 { 0xf006, IFD_SLONG, 1, 0x11223344 },
101 { 0xf007, IFD_FLOAT, 1, 0x11223344 },
102 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct ifd_data, double_val) },
103 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct ifd_data, srational_val) },
104 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct ifd_data, string) },
105 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct ifd_data, short_val) },
106 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct ifd_data, long_val) },
107 { 0xf00d, IFD_FLOAT, 2, FIELD_OFFSET(struct ifd_data, float_val) },
108 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct ifd_data, string) },
109 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
110 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct ifd_data, string) },
111 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
112 { 0xf012, IFD_BYTE, 0, 0x11223344 },
113 { 0xf013, IFD_SHORT, 0, 0x11223344 },
114 { 0xf014, IFD_LONG, 0, 0x11223344 },
115 { 0xf015, IFD_FLOAT, 0, 0x11223344 },
116 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct ifd_data, rational) },
120 1234567890.0987654321,
121 { 0x1a2b3c4d, 0x5a6b7c8d },
123 { 0x0101, 0x0202, 0x0303, 0x0404 },
124 { 0x11223344, 0x55667788 },
125 { (FLOAT)1234.5678, (FLOAT)8765.4321 },
126 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
130 static const char metadata_unknown[] = "lalala";
132 static const char metadata_tEXt[] = {
133 0,0,0,14, /* chunk length */
134 't','E','X','t', /* chunk type */
135 'w','i','n','e','t','e','s','t',0, /* keyword */
136 'v','a','l','u','e', /* text */
137 0x3f,0x64,0x19,0xf3 /* chunk CRC */
140 static const char pngimage[285] = {
141 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
142 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
143 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
144 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
145 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
146 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
147 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
150 static const char *debugstr_guid(REFIID riid)
157 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
158 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
159 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
160 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
165 static IStream *create_stream(const char *data, int data_size)
172 hdata = GlobalAlloc(GMEM_MOVEABLE, data_size);
173 ok(hdata != 0, "GlobalAlloc failed\n");
174 if (!hdata) return NULL;
176 locked_data = GlobalLock(hdata);
177 memcpy(locked_data, data, data_size);
180 hr = CreateStreamOnHGlobal(hdata, TRUE, &stream);
181 ok(hr == S_OK, "CreateStreamOnHGlobal failed, hr=%x\n", hr);
186 static void load_stream(IUnknown *reader, const char *data, int data_size, DWORD persist_options)
189 IWICPersistStream *persist;
192 ULARGE_INTEGER cur_pos;
194 stream = create_stream(data, data_size);
198 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void**)&persist);
199 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
203 hr = IWICPersistStream_LoadEx(persist, stream, NULL, persist_options);
204 ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr);
206 IWICPersistStream_Release(persist);
210 hr = IStream_Seek(stream, pos, SEEK_CUR, &cur_pos);
211 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
212 /* IFD metadata reader doesn't rewind the stream to the start */
213 ok(cur_pos.QuadPart == 0 || cur_pos.QuadPart <= data_size,
214 "current stream pos is at %x/%x, data size %x\n", cur_pos.u.LowPart, cur_pos.u.HighPart, data_size);
216 IStream_Release(stream);
219 static void test_metadata_unknown(void)
222 IWICMetadataReader *reader;
223 IWICEnumMetadataItem *enumerator;
224 IWICMetadataBlockReader *blockreader;
225 PROPVARIANT schema, id, value;
226 ULONG items_returned;
228 hr = CoCreateInstance(&CLSID_WICUnknownMetadataReader, NULL, CLSCTX_INPROC_SERVER,
229 &IID_IWICMetadataReader, (void**)&reader);
230 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
231 if (FAILED(hr)) return;
233 load_stream((IUnknown*)reader, metadata_unknown, sizeof(metadata_unknown), WICPersistOptionsDefault);
235 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
236 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr);
240 PropVariantInit(&schema);
241 PropVariantInit(&id);
242 PropVariantInit(&value);
244 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
245 ok(hr == S_OK, "Next failed, hr=%x\n", hr);
246 ok(items_returned == 1, "unexpected item count %i\n", items_returned);
248 if (hr == S_OK && items_returned == 1)
250 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
251 ok(id.vt == VT_EMPTY, "unexpected vt: %i\n", id.vt);
252 expect_blob(value, metadata_unknown, sizeof(metadata_unknown));
254 PropVariantClear(&schema);
255 PropVariantClear(&id);
256 PropVariantClear(&value);
259 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
260 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr);
261 ok(items_returned == 0, "unexpected item count %i\n", items_returned);
263 IWICEnumMetadataItem_Release(enumerator);
266 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
267 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
270 IWICMetadataBlockReader_Release(blockreader);
272 IWICMetadataReader_Release(reader);
275 static void test_metadata_tEXt(void)
278 IWICMetadataReader *reader;
279 IWICEnumMetadataItem *enumerator;
280 PROPVARIANT schema, id, value;
281 ULONG items_returned, count;
284 PropVariantInit(&schema);
285 PropVariantInit(&id);
286 PropVariantInit(&value);
288 hr = CoCreateInstance(&CLSID_WICPngTextMetadataReader, NULL, CLSCTX_INPROC_SERVER,
289 &IID_IWICMetadataReader, (void**)&reader);
290 todo_wine ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
291 if (FAILED(hr)) return;
293 hr = IWICMetadataReader_GetCount(reader, NULL);
294 ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr);
296 hr = IWICMetadataReader_GetCount(reader, &count);
297 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
298 ok(count == 0, "unexpected count %i\n", count);
300 load_stream((IUnknown*)reader, metadata_tEXt, sizeof(metadata_tEXt), WICPersistOptionsDefault);
302 hr = IWICMetadataReader_GetCount(reader, &count);
303 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
304 ok(count == 1, "unexpected count %i\n", count);
306 hr = IWICMetadataReader_GetEnumerator(reader, NULL);
307 ok(hr == E_INVALIDARG, "GetEnumerator failed, hr=%x\n", hr);
309 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
310 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr);
314 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
315 ok(hr == S_OK, "Next failed, hr=%x\n", hr);
316 ok(items_returned == 1, "unexpected item count %i\n", items_returned);
318 if (hr == S_OK && items_returned == 1)
320 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
321 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
322 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal);
323 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt);
324 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
326 PropVariantClear(&schema);
327 PropVariantClear(&id);
328 PropVariantClear(&value);
331 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
332 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr);
333 ok(items_returned == 0, "unexpected item count %i\n", items_returned);
335 IWICEnumMetadataItem_Release(enumerator);
338 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
339 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
340 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", debugstr_guid(&format));
342 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL);
343 ok(hr == E_INVALIDARG, "GetMetadataFormat failed, hr=%x\n", hr);
346 U(id).pszVal = CoTaskMemAlloc(strlen("winetest") + 1);
347 strcpy(U(id).pszVal, "winetest");
349 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
350 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
352 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value);
353 ok(hr == E_INVALIDARG, "GetValue failed, hr=%x\n", hr);
355 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
356 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
357 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
358 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
359 PropVariantClear(&value);
361 strcpy(U(id).pszVal, "test");
363 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
364 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "GetValue failed, hr=%x\n", hr);
366 PropVariantClear(&id);
368 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL);
369 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
371 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL);
372 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
373 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
375 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL);
376 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
377 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
378 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal);
379 PropVariantClear(&id);
381 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value);
382 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
383 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt);
384 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
385 PropVariantClear(&value);
387 hr = IWICMetadataReader_GetValueByIndex(reader, 1, NULL, NULL, NULL);
388 ok(hr == E_INVALIDARG, "GetValueByIndex failed, hr=%x\n", hr);
390 IWICMetadataReader_Release(reader);
393 static inline USHORT ushort_bswap(USHORT s)
395 return (s >> 8) | (s << 8);
398 static inline ULONG ulong_bswap(ULONG l)
400 return ((ULONG)ushort_bswap((USHORT)l) << 16) | ushort_bswap((USHORT)(l >> 16));
403 static inline ULONGLONG ulonglong_bswap(ULONGLONG ll)
405 return ((ULONGLONG)ulong_bswap((ULONG)ll) << 32) | ulong_bswap((ULONG)(ll >> 32));
408 static void byte_swap_ifd_data(char *data)
410 USHORT number_of_entries, i;
411 struct IFD_entry *entry;
412 char *data_start = data;
414 number_of_entries = *(USHORT *)data;
415 *(USHORT *)data = ushort_bswap(*(USHORT *)data);
416 data += sizeof(USHORT);
418 for (i = 0; i < number_of_entries; i++)
420 entry = (struct IFD_entry *)data;
428 if (entry->count > 4)
429 entry->value = ulong_bswap(entry->value);
434 if (entry->count > 2)
436 ULONG j, count = entry->count;
437 USHORT *us = (USHORT *)(data_start + entry->value);
438 if (!count) count = 1;
439 for (j = 0; j < count; j++)
440 us[j] = ushort_bswap(us[j]);
442 entry->value = ulong_bswap(entry->value);
446 ULONG j, count = entry->count;
447 USHORT *us = (USHORT *)&entry->value;
448 if (!count) count = 1;
449 for (j = 0; j < count; j++)
450 us[j] = ushort_bswap(us[j]);
457 if (entry->count > 1)
459 ULONG j, count = entry->count;
460 ULONG *ul = (ULONG *)(data_start + entry->value);
461 if (!count) count = 1;
462 for (j = 0; j < count; j++)
463 ul[j] = ulong_bswap(ul[j]);
465 entry->value = ulong_bswap(entry->value);
472 ULONG *ul = (ULONG *)(data_start + entry->value);
473 for (j = 0; j < entry->count * 2; j++)
474 ul[j] = ulong_bswap(ul[j]);
476 entry->value = ulong_bswap(entry->value);
482 ULONGLONG *ull = (ULONGLONG *)(data_start + entry->value);
483 for (j = 0; j < entry->count; j++)
484 ull[j] = ulonglong_bswap(ull[j]);
486 entry->value = ulong_bswap(entry->value);
494 entry->id = ushort_bswap(entry->id);
495 entry->type = ushort_bswap(entry->type);
496 entry->count = ulong_bswap(entry->count);
497 data += sizeof(*entry);
504 int count; /* if VT_VECTOR */
509 static void compare_ifd_metadata(IWICMetadataReader *reader, const struct test_data *td, ULONG count)
512 IWICEnumMetadataItem *enumerator;
513 PROPVARIANT schema, id, value;
514 ULONG items_returned, i;
516 hr = IWICMetadataReader_GetEnumerator(reader, NULL);
517 ok(hr == E_INVALIDARG, "GetEnumerator error %#x\n", hr);
519 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
520 ok(hr == S_OK, "GetEnumerator error %#x\n", hr);
522 PropVariantInit(&schema);
523 PropVariantInit(&id);
524 PropVariantInit(&value);
526 for (i = 0; i < count; i++)
528 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
529 ok(hr == S_OK, "Next error %#x\n", hr);
530 ok(items_returned == 1, "unexpected item count %u\n", items_returned);
532 ok(schema.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, schema.vt);
533 ok(id.vt == VT_UI2, "%u: unexpected vt: %u\n", i, id.vt);
534 ok(U(id).uiVal == td[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, U(id).uiVal);
535 ok(value.vt == td[i].type, "%u: expected vt %#x, got %#x\n", i, td[i].type, value.vt);
536 if (value.vt & VT_VECTOR)
539 switch (value.vt & ~VT_VECTOR)
543 ok(td[i].count == U(value).caub.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems);
544 for (j = 0; j < U(value).caub.cElems; j++)
545 ok(td[i].value[j] == U(value).caub.pElems[j], "%u: expected value[%d] %#x/%#x, got %#x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).caub.pElems[j]);
549 ok(td[i].count == U(value).caui.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caui.cElems);
550 for (j = 0; j < U(value).caui.cElems; j++)
551 ok(td[i].value[j] == U(value).caui.pElems[j], "%u: expected value[%d] %#x/%#x, got %#x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).caui.pElems[j]);
556 ok(td[i].count == U(value).caul.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caul.cElems);
557 for (j = 0; j < U(value).caul.cElems; j++)
558 ok(td[i].value[j] == U(value).caul.pElems[j], "%u: expected value[%d] %#x/%#x, got %#x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).caul.pElems[j]);
563 ok(td[i].count == U(value).cauh.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).cauh.cElems);
564 for (j = 0; j < U(value).cauh.cElems; j++)
565 ok(td[i].value[j] == U(value).cauh.pElems[j].QuadPart, "%u: expected value[%d] %08x/%08x, got %08x/%08x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).cauh.pElems[j].u.LowPart, U(value).cauh.pElems[j].u.HighPart);
568 ok(td[i].count == U(value).calpstr.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems);
569 for (j = 0; j < U(value).calpstr.cElems; j++)
570 trace("%u: %s\n", j, U(value).calpstr.pElems[j]);
571 /* fall through to not handled message */
573 ok(0, "%u: array of type %d is not handled\n", i, value.vt & ~VT_VECTOR);
577 else if (value.vt == VT_LPSTR)
579 ok(td[i].count == strlen(U(value).pszVal) ||
580 broken(td[i].count == strlen(U(value).pszVal) + 1), /* before Win7 */
581 "%u: expected count %d, got %d\n", i, td[i].count, lstrlenA(U(value).pszVal));
582 if (td[i].count == strlen(U(value).pszVal))
583 ok(!strcmp(td[i].string, U(value).pszVal),
584 "%u: expected %s, got %s\n", i, td[i].string, U(value).pszVal);
586 else if (value.vt == VT_BLOB)
588 ok(td[i].count == U(value).blob.cbSize, "%u: expected count %d, got %d\n", i, td[i].count, U(value).blob.cbSize);
589 ok(!memcmp(td[i].string, U(value).blob.pBlobData, td[i].count), "%u: expected %s, got %s\n", i, td[i].string, U(value).blob.pBlobData);
592 ok(U(value).uhVal.QuadPart == td[i].value[0], "%u: expected value %#x/%#x got %#x/%#x\n",
593 i, (UINT)td[i].value[0], (UINT)(td[i].value[0] >> 32), U(value).uhVal.u.LowPart, U(value).uhVal.u.HighPart);
595 PropVariantClear(&schema);
596 PropVariantClear(&id);
597 PropVariantClear(&value);
600 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
601 ok(hr == S_FALSE, "Next should fail\n");
602 ok(items_returned == 0, "unexpected item count %u\n", items_returned);
604 IWICEnumMetadataItem_Release(enumerator);
607 static void test_metadata_IFD(void)
609 static const struct test_data td[28] =
611 { VT_UI2, 0xfe, 0, { 1 } },
612 { VT_UI4, 0x100, 0, { 222 } },
613 { VT_UI4, 0x101, 0, { 333 } },
614 { VT_UI2, 0x102, 0, { 24 } },
615 { VT_UI4, 0x103, 0, { 32773 } },
616 { VT_UI8, 0x11a, 0, { ((LONGLONG)3 << 32) | 900 } },
617 { VT_UI1, 0xf001, 0, { 0x44 } },
618 { VT_UI1|VT_VECTOR, 0xf002, 4, { 0x44, 0x33, 0x22, 0x11 } },
619 { VT_I1, 0xf003, 0, { 0x44 } },
620 { VT_I2, 0xf004, 0, { 0x3344 } },
621 { VT_I2|VT_VECTOR, 0xf005, 2, { 0x3344, 0x1122 } },
622 { VT_I4, 0xf006, 0, { 0x11223344 } },
623 { VT_R4, 0xf007, 0, { 0x11223344 } },
624 { VT_R8, 0xf008, 0, { ((LONGLONG)0x41d26580 << 32) | 0xb486522c } },
625 { VT_I8, 0xf009, 0, { ((LONGLONG)0x5a6b7c8d << 32) | 0x1a2b3c4d } },
626 { VT_UI1|VT_VECTOR, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
627 { VT_I2|VT_VECTOR, 0xf00b, 4, { 0x0101, 0x0202, 0x0303, 0x0404 } },
628 { VT_I4|VT_VECTOR, 0xf00c, 2, { 0x11223344, 0x55667788 } },
629 { VT_R4|VT_VECTOR, 0xf00d, 2, { 0x449a522b, 0x4608f5ba } },
630 { VT_LPSTR, 0xf00e, 12, { 0 }, "Hello World!" },
631 { VT_LPSTR, 0xf00f, 4, { 0 }, "abcd" },
632 { VT_BLOB, 0xf010, 13, { 0 }, "Hello World!" },
633 { VT_BLOB, 0xf011, 4, { 0 }, "abcd" },
634 { VT_UI1, 0xf012, 0, { 0x44 } },
635 { VT_UI2, 0xf013, 0, { 0x3344 } },
636 { VT_UI4, 0xf014, 0, { 0x11223344 } },
637 { VT_R4, 0xf015, 0, { 0x11223344 } },
638 { VT_I8|VT_VECTOR, 0xf016, 3,
639 { ((LONGLONG)0x05060708 << 32) | 0x01020304,
640 ((LONGLONG)0x50607080 << 32) | 0x10203040,
641 ((LONGLONG)0x55667788 << 32) | 0x11223344 } },
644 IWICMetadataReader *reader;
645 IWICMetadataBlockReader *blockreader;
646 PROPVARIANT schema, id, value;
649 char *IFD_data_swapped;
650 #ifdef WORDS_BIGENDIAN
651 DWORD persist_options = WICPersistOptionsBigEndian;
653 DWORD persist_options = WICPersistOptionsLittleEndian;
656 hr = CoCreateInstance(&CLSID_WICIfdMetadataReader, NULL, CLSCTX_INPROC_SERVER,
657 &IID_IWICMetadataReader, (void**)&reader);
658 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
660 hr = IWICMetadataReader_GetCount(reader, NULL);
661 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr);
663 hr = IWICMetadataReader_GetCount(reader, &count);
664 ok(hr == S_OK, "GetCount error %#x\n", hr);
665 ok(count == 0, "unexpected count %u\n", count);
667 load_stream((IUnknown*)reader, (const char *)&IFD_data, sizeof(IFD_data), persist_options);
669 hr = IWICMetadataReader_GetCount(reader, &count);
670 ok(hr == S_OK, "GetCount error %#x\n", hr);
671 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
673 compare_ifd_metadata(reader, td, count);
675 /* test IFD data with different endianness */
676 if (persist_options == WICPersistOptionsLittleEndian)
677 persist_options = WICPersistOptionsBigEndian;
679 persist_options = WICPersistOptionsLittleEndian;
681 IFD_data_swapped = HeapAlloc(GetProcessHeap(), 0, sizeof(IFD_data));
682 memcpy(IFD_data_swapped, &IFD_data, sizeof(IFD_data));
683 byte_swap_ifd_data(IFD_data_swapped);
684 load_stream((IUnknown *)reader, IFD_data_swapped, sizeof(IFD_data), persist_options);
685 hr = IWICMetadataReader_GetCount(reader, &count);
686 ok(hr == S_OK, "GetCount error %#x\n", hr);
687 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
688 compare_ifd_metadata(reader, td, count);
689 HeapFree(GetProcessHeap(), 0, IFD_data_swapped);
691 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
692 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
693 ok(IsEqualGUID(&format, &GUID_MetadataFormatIfd), "unexpected format %s\n", debugstr_guid(&format));
695 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL);
696 ok(hr == E_INVALIDARG, "GetMetadataFormat should fail\n");
698 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL);
699 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
701 PropVariantInit(&schema);
702 PropVariantInit(&id);
703 PropVariantInit(&value);
705 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, NULL, NULL, NULL);
706 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
708 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL);
709 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
710 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt);
712 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, &schema, NULL, NULL);
713 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
714 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt);
716 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL);
717 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
718 ok(id.vt == VT_UI2, "unexpected vt: %u\n", id.vt);
719 ok(U(id).uiVal == 0xfe, "unexpected id: %#x\n", U(id).uiVal);
720 PropVariantClear(&id);
722 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value);
723 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
724 ok(value.vt == VT_UI2, "unexpected vt: %u\n", value.vt);
725 ok(U(value).uiVal == 1, "unexpected id: %#x\n", U(value).uiVal);
726 PropVariantClear(&value);
728 hr = IWICMetadataReader_GetValueByIndex(reader, count, &schema, NULL, NULL);
729 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
731 PropVariantInit(&schema);
732 PropVariantInit(&id);
733 PropVariantInit(&value);
735 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
736 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
738 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
739 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
741 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, NULL);
742 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
744 hr = IWICMetadataReader_GetValue(reader, &schema, &id, NULL);
745 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
747 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value);
748 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
751 U(id).uiVal = 0xf00e;
752 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
753 ok(hr == S_OK, "GetValue error %#x\n", hr);
755 /* schema is ignored by Ifd metadata reader */
757 U(schema).ulVal = 0xdeadbeef;
758 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
759 ok(hr == S_OK, "GetValue error %#x\n", hr);
760 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
761 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
762 PropVariantClear(&value);
764 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
765 ok(hr == S_OK, "GetValue error %#x\n", hr);
766 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
767 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
768 PropVariantClear(&value);
770 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
771 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
774 IWICMetadataBlockReader_Release(blockreader);
776 IWICMetadataReader_Release(reader);
779 static void test_metadata_Exif(void)
782 IWICMetadataReader *reader;
783 IWICMetadataBlockReader *blockreader;
786 hr = CoCreateInstance(&CLSID_WICExifMetadataReader, NULL, CLSCTX_INPROC_SERVER,
787 &IID_IWICMetadataReader, (void**)&reader);
788 todo_wine ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
789 if (FAILED(hr)) return;
791 hr = IWICMetadataReader_GetCount(reader, NULL);
792 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr);
794 hr = IWICMetadataReader_GetCount(reader, &count);
795 ok(hr == S_OK, "GetCount error %#x\n", hr);
796 ok(count == 0, "unexpected count %u\n", count);
798 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
799 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
802 IWICMetadataBlockReader_Release(blockreader);
804 IWICMetadataReader_Release(reader);
807 static void test_create_reader(void)
810 IWICComponentFactory *factory;
812 IWICMetadataReader *reader;
816 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
817 &IID_IWICComponentFactory, (void**)&factory);
818 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
820 stream = create_stream(metadata_tEXt, sizeof(metadata_tEXt));
822 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
823 &GUID_ContainerFormatPng, NULL, WICPersistOptionsDefault,
826 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
827 if (FAILED(hr)) return;
831 hr = IWICMetadataReader_GetCount(reader, &count);
832 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
833 ok(count == 1, "unexpected count %i\n", count);
835 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
836 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
837 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", debugstr_guid(&format));
839 IWICMetadataReader_Release(reader);
842 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
843 &GUID_ContainerFormatWmp, NULL, WICPersistOptionsDefault,
845 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
849 hr = IWICMetadataReader_GetCount(reader, &count);
850 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
851 ok(count == 1, "unexpected count %i\n", count);
853 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
854 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
855 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), "unexpected format %s\n", debugstr_guid(&format));
857 IWICMetadataReader_Release(reader);
860 IStream_Release(stream);
862 IWICComponentFactory_Release(factory);
865 static void test_metadata_png(void)
868 IWICBitmapDecoder *decoder;
869 IWICBitmapFrameDecode *frame;
870 IWICMetadataBlockReader *blockreader;
871 IWICMetadataReader *reader;
872 GUID containerformat;
876 hr = CoCreateInstance(&CLSID_WICPngDecoder, NULL, CLSCTX_INPROC_SERVER,
877 &IID_IWICBitmapDecoder, (void**)&decoder);
878 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
880 if (FAILED(hr)) return;
882 stream = create_stream(pngimage, sizeof(pngimage));
884 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
885 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
887 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void**)&blockreader);
888 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
890 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
891 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
893 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void**)&blockreader);
894 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
898 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL);
899 ok(hr == E_INVALIDARG, "GetContainerFormat failed, hr=%x\n", hr);
901 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &containerformat);
902 ok(hr == S_OK, "GetContainerFormat failed, hr=%x\n", hr);
903 ok(IsEqualGUID(&containerformat, &GUID_ContainerFormatPng), "unexpected container format\n");
905 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL);
906 todo_wine ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr);
908 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
909 todo_wine ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
910 todo_wine ok(count == 1, "unexpected count %d\n", count);
914 /* Crashes on Windows XP */
915 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, NULL);
916 ok(hr == E_INVALIDARG, "GetReaderByIndex failed, hr=%x\n", hr);
919 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
920 todo_wine ok(hr == S_OK, "GetReaderByIndex failed, hr=%x\n", hr);
924 hr = IWICMetadataReader_GetMetadataFormat(reader, &containerformat);
925 ok(IsEqualGUID(&containerformat, &GUID_MetadataFormatChunktIME) ||
926 broken(IsEqualGUID(&containerformat, &GUID_MetadataFormatUnknown)) /* Windows XP */,
927 "unexpected container format\n");
929 IWICMetadataReader_Release(reader);
932 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
933 todo_wine ok(hr == WINCODEC_ERR_VALUEOUTOFRANGE, "GetReaderByIndex failed, hr=%x\n", hr);
935 IWICMetadataBlockReader_Release(blockreader);
938 IWICBitmapFrameDecode_Release(frame);
940 IWICBitmapDecoder_Release(decoder);
942 IWICStream_Release(stream);
947 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
949 test_metadata_unknown();
950 test_metadata_tEXt();
952 test_metadata_Exif();
953 test_create_reader();