1 /* 2 * Copyright 2011 Vincent Povirk for CodeWeavers 3 * Copyright 2012,2017 Dmitry Timoshkov 4 * 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. 9 * 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. 14 * 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 18 */ 19 20 #include <stdio.h> 21 #include <stdarg.h> 22 #include <math.h> 23 #include <assert.h> 24 25 #define COBJMACROS 26 27 #include "windef.h" 28 #include "objbase.h" 29 #include "wincodec.h" 30 #include "wincodecsdk.h" 31 #include "propvarutil.h" 32 #include "wine/test.h" 33 34 #include "initguid.h" 35 DEFINE_GUID(IID_MdbrUnknown, 0x00240e6f,0x3f23,0x4432,0xb0,0xcc,0x48,0xd5,0xbb,0xff,0x6c,0x36); 36 37 #define expect_blob(propvar, data, length) do { \ 38 ok((propvar).vt == VT_BLOB, "unexpected vt: %i\n", (propvar).vt); \ 39 if ((propvar).vt == VT_BLOB) { \ 40 ok(U(propvar).blob.cbSize == (length), "expected size %u, got %u\n", (ULONG)(length), U(propvar).blob.cbSize); \ 41 if (U(propvar).blob.cbSize == (length)) { \ 42 ok(!memcmp(U(propvar).blob.pBlobData, (data), (length)), "unexpected data\n"); \ 43 } \ 44 } \ 45 } while (0) 46 47 #define IFD_BYTE 1 48 #define IFD_ASCII 2 49 #define IFD_SHORT 3 50 #define IFD_LONG 4 51 #define IFD_RATIONAL 5 52 #define IFD_SBYTE 6 53 #define IFD_UNDEFINED 7 54 #define IFD_SSHORT 8 55 #define IFD_SLONG 9 56 #define IFD_SRATIONAL 10 57 #define IFD_FLOAT 11 58 #define IFD_DOUBLE 12 59 #define IFD_IFD 13 60 61 #include "pshpack2.h" 62 struct IFD_entry 63 { 64 SHORT id; 65 SHORT type; 66 ULONG count; 67 LONG value; 68 }; 69 70 struct IFD_rational 71 { 72 LONG numerator; 73 LONG denominator; 74 }; 75 76 static const struct ifd_data 77 { 78 USHORT number_of_entries; 79 struct IFD_entry entry[40]; 80 ULONG next_IFD; 81 struct IFD_rational xres; 82 DOUBLE double_val; 83 struct IFD_rational srational_val; 84 char string[14]; 85 SHORT short_val[4]; 86 LONG long_val[2]; 87 FLOAT float_val[2]; 88 struct IFD_rational rational[3]; 89 } IFD_data = 90 { 91 28, 92 { 93 { 0xfe, IFD_SHORT, 1, 1 }, /* NEWSUBFILETYPE */ 94 { 0x100, IFD_LONG, 1, 222 }, /* IMAGEWIDTH */ 95 { 0x101, IFD_LONG, 1, 333 }, /* IMAGELENGTH */ 96 { 0x102, IFD_SHORT, 1, 24 }, /* BITSPERSAMPLE */ 97 { 0x103, IFD_LONG, 1, 32773 }, /* COMPRESSION: packbits */ 98 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct ifd_data, xres) }, 99 { 0xf001, IFD_BYTE, 1, 0x11223344 }, 100 { 0xf002, IFD_BYTE, 4, 0x11223344 }, 101 { 0xf003, IFD_SBYTE, 1, 0x11223344 }, 102 { 0xf004, IFD_SSHORT, 1, 0x11223344 }, 103 { 0xf005, IFD_SSHORT, 2, 0x11223344 }, 104 { 0xf006, IFD_SLONG, 1, 0x11223344 }, 105 { 0xf007, IFD_FLOAT, 1, 0x11223344 }, 106 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct ifd_data, double_val) }, 107 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct ifd_data, srational_val) }, 108 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct ifd_data, string) }, 109 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct ifd_data, short_val) }, 110 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct ifd_data, long_val) }, 111 { 0xf00d, IFD_FLOAT, 2, FIELD_OFFSET(struct ifd_data, float_val) }, 112 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct ifd_data, string) }, 113 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 }, 114 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct ifd_data, string) }, 115 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 }, 116 { 0xf012, IFD_BYTE, 0, 0x11223344 }, 117 { 0xf013, IFD_SHORT, 0, 0x11223344 }, 118 { 0xf014, IFD_LONG, 0, 0x11223344 }, 119 { 0xf015, IFD_FLOAT, 0, 0x11223344 }, 120 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct ifd_data, rational) }, 121 }, 122 0, 123 { 900, 3 }, 124 1234567890.0987654321, 125 { 0x1a2b3c4d, 0x5a6b7c8d }, 126 "Hello World!", 127 { 0x0101, 0x0202, 0x0303, 0x0404 }, 128 { 0x11223344, 0x55667788 }, 129 { (FLOAT)1234.5678, (FLOAT)8765.4321 }, 130 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } }, 131 }; 132 #include "poppack.h" 133 134 static const char metadata_unknown[] = "lalala"; 135 136 static const char metadata_tEXt[] = { 137 0,0,0,14, /* chunk length */ 138 't','E','X','t', /* chunk type */ 139 'w','i','n','e','t','e','s','t',0, /* keyword */ 140 'v','a','l','u','e', /* text */ 141 0x3f,0x64,0x19,0xf3 /* chunk CRC */ 142 }; 143 144 static const char metadata_gAMA[] = { 145 0,0,0,4, /* chunk length */ 146 'g','A','M','A', /* chunk type */ 147 0,0,130,53, /* gamma */ 148 0xff,0xff,0xff,0xff /* chunk CRC */ 149 }; 150 151 static const char metadata_cHRM[] = { 152 0,0,0,32, /* chunk length */ 153 'c','H','R','M', /* chunk type */ 154 0,0,122,38, 0,0,128,132, /* white point */ 155 0,0,250,0, 0,0,128,232, /* red */ 156 0,0,117,48, 0,0,234,96, /* green */ 157 0,0,58,152, 0,0,23,112, /* blue */ 158 0xff,0xff,0xff,0xff /* chunk CRC */ 159 }; 160 161 static const char pngimage[285] = { 162 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, 163 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53, 164 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b, 165 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5, 166 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41, 167 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59, 168 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 169 }; 170 171 /* 1x1 pixel gif */ 172 static const char gifimage[35] = { 173 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff, 174 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44, 175 0x01,0x00,0x3b 176 }; 177 178 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */ 179 static const char animatedgif[] = { 180 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x00,0x00, 181 0x6F,0x6F,0x6F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 182 /*0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',*/ 183 0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0', 184 0x03,0x01,0x05,0x00,0x00, 185 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00, 186 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00, 187 0x21,0xF9,0x04,0x00,0x0A,0x00,0xFF,0x00,0x2C, 188 0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81, 189 0xDE,0xDE,0xDE,0x00,0x00,0x00, 190 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x4C,0x01,0x00, 191 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00, 192 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00, 193 0x21,0xF9,0x04,0x01,0x0A,0x00,0x01,0x00,0x2C, 194 0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81, 195 0x4D,0x4D,0x4D,0x00,0x00,0x00, 196 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x44,0x01,0x00, 197 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00, 198 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B 199 }; 200 201 static IStream *create_stream(const char *data, int data_size) 202 { 203 HRESULT hr; 204 IStream *stream; 205 HGLOBAL hdata; 206 void *locked_data; 207 208 hdata = GlobalAlloc(GMEM_MOVEABLE, data_size); 209 ok(hdata != 0, "GlobalAlloc failed\n"); 210 if (!hdata) return NULL; 211 212 locked_data = GlobalLock(hdata); 213 memcpy(locked_data, data, data_size); 214 GlobalUnlock(hdata); 215 216 hr = CreateStreamOnHGlobal(hdata, TRUE, &stream); 217 ok(hr == S_OK, "CreateStreamOnHGlobal failed, hr=%x\n", hr); 218 219 return stream; 220 } 221 222 static void load_stream(IUnknown *reader, const char *data, int data_size, DWORD persist_options) 223 { 224 HRESULT hr; 225 IWICPersistStream *persist; 226 IStream *stream; 227 LARGE_INTEGER pos; 228 ULARGE_INTEGER cur_pos; 229 230 stream = create_stream(data, data_size); 231 if (!stream) 232 return; 233 234 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void**)&persist); 235 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr); 236 237 if (SUCCEEDED(hr)) 238 { 239 hr = IWICPersistStream_LoadEx(persist, stream, NULL, persist_options); 240 ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr); 241 242 IWICPersistStream_Release(persist); 243 } 244 245 pos.QuadPart = 0; 246 hr = IStream_Seek(stream, pos, SEEK_CUR, &cur_pos); 247 ok(hr == S_OK, "IStream_Seek error %#x\n", hr); 248 /* IFD metadata reader doesn't rewind the stream to the start */ 249 ok(cur_pos.QuadPart == 0 || cur_pos.QuadPart <= data_size, 250 "current stream pos is at %x/%x, data size %x\n", cur_pos.u.LowPart, cur_pos.u.HighPart, data_size); 251 252 IStream_Release(stream); 253 } 254 255 static void test_metadata_unknown(void) 256 { 257 HRESULT hr; 258 IWICMetadataReader *reader; 259 IWICEnumMetadataItem *enumerator; 260 IWICMetadataBlockReader *blockreader; 261 PROPVARIANT schema, id, value; 262 ULONG items_returned; 263 264 hr = CoCreateInstance(&CLSID_WICUnknownMetadataReader, NULL, CLSCTX_INPROC_SERVER, 265 &IID_IWICMetadataReader, (void**)&reader); 266 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); 267 if (FAILED(hr)) return; 268 269 load_stream((IUnknown*)reader, metadata_unknown, sizeof(metadata_unknown), WICPersistOptionDefault); 270 271 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator); 272 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr); 273 274 if (SUCCEEDED(hr)) 275 { 276 PropVariantInit(&schema); 277 PropVariantInit(&id); 278 PropVariantInit(&value); 279 280 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); 281 ok(hr == S_OK, "Next failed, hr=%x\n", hr); 282 ok(items_returned == 1, "unexpected item count %i\n", items_returned); 283 284 if (hr == S_OK && items_returned == 1) 285 { 286 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); 287 ok(id.vt == VT_EMPTY, "unexpected vt: %i\n", id.vt); 288 expect_blob(value, metadata_unknown, sizeof(metadata_unknown)); 289 290 PropVariantClear(&schema); 291 PropVariantClear(&id); 292 PropVariantClear(&value); 293 } 294 295 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); 296 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr); 297 ok(items_returned == 0, "unexpected item count %i\n", items_returned); 298 299 IWICEnumMetadataItem_Release(enumerator); 300 } 301 302 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader); 303 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr); 304 305 if (SUCCEEDED(hr)) 306 IWICMetadataBlockReader_Release(blockreader); 307 308 IWICMetadataReader_Release(reader); 309 } 310 311 static void test_metadata_tEXt(void) 312 { 313 HRESULT hr; 314 IWICMetadataReader *reader; 315 IWICEnumMetadataItem *enumerator; 316 PROPVARIANT schema, id, value; 317 ULONG items_returned, count; 318 GUID format; 319 320 PropVariantInit(&schema); 321 PropVariantInit(&id); 322 PropVariantInit(&value); 323 324 hr = CoCreateInstance(&CLSID_WICPngTextMetadataReader, NULL, CLSCTX_INPROC_SERVER, 325 &IID_IWICMetadataReader, (void**)&reader); 326 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); 327 if (FAILED(hr)) return; 328 329 hr = IWICMetadataReader_GetCount(reader, NULL); 330 ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr); 331 332 hr = IWICMetadataReader_GetCount(reader, &count); 333 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 334 ok(count == 0, "unexpected count %i\n", count); 335 336 load_stream((IUnknown*)reader, metadata_tEXt, sizeof(metadata_tEXt), WICPersistOptionDefault); 337 338 hr = IWICMetadataReader_GetCount(reader, &count); 339 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 340 ok(count == 1, "unexpected count %i\n", count); 341 342 hr = IWICMetadataReader_GetEnumerator(reader, NULL); 343 ok(hr == E_INVALIDARG, "GetEnumerator failed, hr=%x\n", hr); 344 345 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator); 346 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr); 347 348 if (SUCCEEDED(hr)) 349 { 350 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); 351 ok(hr == S_OK, "Next failed, hr=%x\n", hr); 352 ok(items_returned == 1, "unexpected item count %i\n", items_returned); 353 354 if (hr == S_OK && items_returned == 1) 355 { 356 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); 357 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); 358 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal); 359 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt); 360 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal); 361 362 PropVariantClear(&schema); 363 PropVariantClear(&id); 364 PropVariantClear(&value); 365 } 366 367 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); 368 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr); 369 ok(items_returned == 0, "unexpected item count %i\n", items_returned); 370 371 IWICEnumMetadataItem_Release(enumerator); 372 } 373 374 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 375 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); 376 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", wine_dbgstr_guid(&format)); 377 378 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL); 379 ok(hr == E_INVALIDARG, "GetMetadataFormat failed, hr=%x\n", hr); 380 381 id.vt = VT_LPSTR; 382 U(id).pszVal = CoTaskMemAlloc(strlen("winetest") + 1); 383 strcpy(U(id).pszVal, "winetest"); 384 385 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL); 386 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); 387 388 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value); 389 ok(hr == E_INVALIDARG, "GetValue failed, hr=%x\n", hr); 390 391 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value); 392 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); 393 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); 394 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal); 395 PropVariantClear(&value); 396 397 strcpy(U(id).pszVal, "test"); 398 399 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value); 400 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "GetValue failed, hr=%x\n", hr); 401 402 PropVariantClear(&id); 403 404 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL); 405 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); 406 407 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL); 408 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); 409 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); 410 411 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL); 412 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); 413 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); 414 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal); 415 PropVariantClear(&id); 416 417 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value); 418 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr); 419 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt); 420 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal); 421 PropVariantClear(&value); 422 423 hr = IWICMetadataReader_GetValueByIndex(reader, 1, NULL, NULL, NULL); 424 ok(hr == E_INVALIDARG, "GetValueByIndex failed, hr=%x\n", hr); 425 426 IWICMetadataReader_Release(reader); 427 } 428 429 static void test_metadata_gAMA(void) 430 { 431 HRESULT hr; 432 IWICMetadataReader *reader; 433 PROPVARIANT schema, id, value; 434 ULONG count; 435 GUID format; 436 static const WCHAR ImageGamma[] = {'I','m','a','g','e','G','a','m','m','a',0}; 437 438 PropVariantInit(&schema); 439 PropVariantInit(&id); 440 PropVariantInit(&value); 441 442 hr = CoCreateInstance(&CLSID_WICPngGamaMetadataReader, NULL, CLSCTX_INPROC_SERVER, 443 &IID_IWICMetadataReader, (void**)&reader); 444 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG) /*winxp*/, "CoCreateInstance failed, hr=%x\n", hr); 445 if (FAILED(hr)) return; 446 447 load_stream((IUnknown*)reader, metadata_gAMA, sizeof(metadata_gAMA), WICPersistOptionDefault); 448 449 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 450 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); 451 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunkgAMA), "unexpected format %s\n", wine_dbgstr_guid(&format)); 452 453 hr = IWICMetadataReader_GetCount(reader, &count); 454 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 455 ok(count == 1, "unexpected count %i\n", count); 456 457 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, &id, &value); 458 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); 459 460 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); 461 PropVariantClear(&schema); 462 463 ok(id.vt == VT_LPWSTR, "unexpected vt: %i\n", id.vt); 464 ok(!lstrcmpW(U(id).pwszVal, ImageGamma), "unexpected value: %s\n", wine_dbgstr_w(U(id).pwszVal)); 465 PropVariantClear(&id); 466 467 ok(value.vt == VT_UI4, "unexpected vt: %i\n", value.vt); 468 ok(U(value).ulVal == 33333, "unexpected value: %u\n", U(value).ulVal); 469 PropVariantClear(&value); 470 471 IWICMetadataReader_Release(reader); 472 } 473 474 static void test_metadata_cHRM(void) 475 { 476 HRESULT hr; 477 IWICMetadataReader *reader; 478 PROPVARIANT schema, id, value; 479 ULONG count; 480 GUID format; 481 int i; 482 static const WCHAR expected_names[8][12] = { 483 {'W','h','i','t','e','P','o','i','n','t','X',0}, 484 {'W','h','i','t','e','P','o','i','n','t','Y',0}, 485 {'R','e','d','X',0}, 486 {'R','e','d','Y',0}, 487 {'G','r','e','e','n','X',0}, 488 {'G','r','e','e','n','Y',0}, 489 {'B','l','u','e','X',0}, 490 {'B','l','u','e','Y',0}, 491 }; 492 static const ULONG expected_vals[8] = { 493 31270,32900, 64000,33000, 30000,60000, 15000,6000 494 }; 495 496 PropVariantInit(&schema); 497 PropVariantInit(&id); 498 PropVariantInit(&value); 499 500 hr = CoCreateInstance(&CLSID_WICPngChrmMetadataReader, NULL, CLSCTX_INPROC_SERVER, 501 &IID_IWICMetadataReader, (void**)&reader); 502 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG) /*winxp*/, "CoCreateInstance failed, hr=%x\n", hr); 503 if (FAILED(hr)) return; 504 505 load_stream((IUnknown*)reader, metadata_cHRM, sizeof(metadata_cHRM), WICPersistOptionDefault); 506 507 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 508 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); 509 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunkcHRM), "unexpected format %s\n", wine_dbgstr_guid(&format)); 510 511 hr = IWICMetadataReader_GetCount(reader, &count); 512 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 513 ok(count == 8, "unexpected count %i\n", count); 514 515 for (i=0; i<8; i++) 516 { 517 hr = IWICMetadataReader_GetValueByIndex(reader, i, &schema, &id, &value); 518 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); 519 520 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); 521 PropVariantClear(&schema); 522 523 ok(id.vt == VT_LPWSTR, "unexpected vt: %i\n", id.vt); 524 ok(!lstrcmpW(U(id).pwszVal, expected_names[i]), "got %s, expected %s\n", wine_dbgstr_w(U(id).pwszVal), wine_dbgstr_w(expected_names[i])); 525 PropVariantClear(&id); 526 527 ok(value.vt == VT_UI4, "unexpected vt: %i\n", value.vt); 528 ok(U(value).ulVal == expected_vals[i], "got %u, expected %u\n", U(value).ulVal, expected_vals[i]); 529 PropVariantClear(&value); 530 } 531 532 IWICMetadataReader_Release(reader); 533 } 534 535 static inline USHORT ushort_bswap(USHORT s) 536 { 537 return (s >> 8) | (s << 8); 538 } 539 540 static inline ULONG ulong_bswap(ULONG l) 541 { 542 return ((ULONG)ushort_bswap((USHORT)l) << 16) | ushort_bswap((USHORT)(l >> 16)); 543 } 544 545 static inline ULONGLONG ulonglong_bswap(ULONGLONG ll) 546 { 547 return ((ULONGLONG)ulong_bswap((ULONG)ll) << 32) | ulong_bswap((ULONG)(ll >> 32)); 548 } 549 550 static void byte_swap_ifd_data(char *data) 551 { 552 USHORT number_of_entries, i; 553 struct IFD_entry *entry; 554 char *data_start = data; 555 556 number_of_entries = *(USHORT *)data; 557 *(USHORT *)data = ushort_bswap(*(USHORT *)data); 558 data += sizeof(USHORT); 559 560 for (i = 0; i < number_of_entries; i++) 561 { 562 entry = (struct IFD_entry *)data; 563 564 switch (entry->type) 565 { 566 case IFD_BYTE: 567 case IFD_SBYTE: 568 case IFD_ASCII: 569 case IFD_UNDEFINED: 570 if (entry->count > 4) 571 entry->value = ulong_bswap(entry->value); 572 break; 573 574 case IFD_SHORT: 575 case IFD_SSHORT: 576 if (entry->count > 2) 577 { 578 ULONG j, count = entry->count; 579 USHORT *us = (USHORT *)(data_start + entry->value); 580 if (!count) count = 1; 581 for (j = 0; j < count; j++) 582 us[j] = ushort_bswap(us[j]); 583 584 entry->value = ulong_bswap(entry->value); 585 } 586 else 587 { 588 ULONG j, count = entry->count; 589 USHORT *us = (USHORT *)&entry->value; 590 if (!count) count = 1; 591 for (j = 0; j < count; j++) 592 us[j] = ushort_bswap(us[j]); 593 } 594 break; 595 596 case IFD_LONG: 597 case IFD_SLONG: 598 case IFD_FLOAT: 599 if (entry->count > 1) 600 { 601 ULONG j, count = entry->count; 602 ULONG *ul = (ULONG *)(data_start + entry->value); 603 if (!count) count = 1; 604 for (j = 0; j < count; j++) 605 ul[j] = ulong_bswap(ul[j]); 606 } 607 entry->value = ulong_bswap(entry->value); 608 break; 609 610 case IFD_RATIONAL: 611 case IFD_SRATIONAL: 612 { 613 ULONG j; 614 ULONG *ul = (ULONG *)(data_start + entry->value); 615 for (j = 0; j < entry->count * 2; j++) 616 ul[j] = ulong_bswap(ul[j]); 617 } 618 entry->value = ulong_bswap(entry->value); 619 break; 620 621 case IFD_DOUBLE: 622 { 623 ULONG j; 624 ULONGLONG *ull = (ULONGLONG *)(data_start + entry->value); 625 for (j = 0; j < entry->count; j++) 626 ull[j] = ulonglong_bswap(ull[j]); 627 } 628 entry->value = ulong_bswap(entry->value); 629 break; 630 631 default: 632 assert(0); 633 break; 634 } 635 636 entry->id = ushort_bswap(entry->id); 637 entry->type = ushort_bswap(entry->type); 638 entry->count = ulong_bswap(entry->count); 639 data += sizeof(*entry); 640 } 641 } 642 643 struct test_data 644 { 645 ULONG type, id; 646 int count; /* if VT_VECTOR */ 647 LONGLONG value[13]; 648 const char *string; 649 const WCHAR id_string[32]; 650 }; 651 652 static void compare_metadata(IWICMetadataReader *reader, const struct test_data *td, ULONG count) 653 { 654 HRESULT hr; 655 IWICEnumMetadataItem *enumerator; 656 PROPVARIANT schema, id, value; 657 ULONG items_returned, i; 658 659 hr = IWICMetadataReader_GetEnumerator(reader, NULL); 660 ok(hr == E_INVALIDARG, "GetEnumerator error %#x\n", hr); 661 662 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator); 663 ok(hr == S_OK, "GetEnumerator error %#x\n", hr); 664 665 PropVariantInit(&schema); 666 PropVariantInit(&id); 667 PropVariantInit(&value); 668 669 for (i = 0; i < count; i++) 670 { 671 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); 672 ok(hr == S_OK, "Next error %#x\n", hr); 673 ok(items_returned == 1, "unexpected item count %u\n", items_returned); 674 675 ok(schema.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, schema.vt); 676 ok(id.vt == VT_UI2 || id.vt == VT_LPWSTR || id.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, id.vt); 677 if (id.vt == VT_UI2) 678 ok(U(id).uiVal == td[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, U(id).uiVal); 679 else if (id.vt == VT_LPWSTR) 680 ok(!lstrcmpW(td[i].id_string, U(id).pwszVal), 681 "%u: expected %s, got %s\n", i, wine_dbgstr_w(td[i].id_string), wine_dbgstr_w(U(id).pwszVal)); 682 683 ok(value.vt == td[i].type, "%u: expected vt %#x, got %#x\n", i, td[i].type, value.vt); 684 if (value.vt & VT_VECTOR) 685 { 686 ULONG j; 687 switch (value.vt & ~VT_VECTOR) 688 { 689 case VT_I1: 690 case VT_UI1: 691 ok(td[i].count == U(value).caub.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems); 692 for (j = 0; j < U(value).caub.cElems; j++) 693 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]); 694 break; 695 case VT_I2: 696 case VT_UI2: 697 ok(td[i].count == U(value).caui.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caui.cElems); 698 for (j = 0; j < U(value).caui.cElems; j++) 699 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]); 700 break; 701 case VT_I4: 702 case VT_UI4: 703 case VT_R4: 704 ok(td[i].count == U(value).caul.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caul.cElems); 705 for (j = 0; j < U(value).caul.cElems; j++) 706 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]); 707 break; 708 case VT_I8: 709 case VT_UI8: 710 case VT_R8: 711 ok(td[i].count == U(value).cauh.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).cauh.cElems); 712 for (j = 0; j < U(value).cauh.cElems; j++) 713 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); 714 break; 715 case VT_LPSTR: 716 ok(td[i].count == U(value).calpstr.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems); 717 for (j = 0; j < U(value).calpstr.cElems; j++) 718 trace("%u: %s\n", j, U(value).calpstr.pElems[j]); 719 /* fall through to not handled message */ 720 default: 721 ok(0, "%u: array of type %d is not handled\n", i, value.vt & ~VT_VECTOR); 722 break; 723 } 724 } 725 else if (value.vt == VT_LPSTR) 726 { 727 ok(td[i].count == strlen(U(value).pszVal) || 728 broken(td[i].count == strlen(U(value).pszVal) + 1), /* before Win7 */ 729 "%u: expected count %d, got %d\n", i, td[i].count, lstrlenA(U(value).pszVal)); 730 if (td[i].count == strlen(U(value).pszVal)) 731 ok(!strcmp(td[i].string, U(value).pszVal), 732 "%u: expected %s, got %s\n", i, td[i].string, U(value).pszVal); 733 } 734 else if (value.vt == VT_BLOB) 735 { 736 ok(td[i].count == U(value).blob.cbSize, "%u: expected count %d, got %d\n", i, td[i].count, U(value).blob.cbSize); 737 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); 738 } 739 else 740 ok(U(value).uhVal.QuadPart == td[i].value[0], "%u: expected value %#x/%#x got %#x/%#x\n", 741 i, (UINT)td[i].value[0], (UINT)(td[i].value[0] >> 32), U(value).uhVal.u.LowPart, U(value).uhVal.u.HighPart); 742 743 PropVariantClear(&schema); 744 PropVariantClear(&id); 745 PropVariantClear(&value); 746 } 747 748 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); 749 ok(hr == S_FALSE, "Next should fail\n"); 750 ok(items_returned == 0, "unexpected item count %u\n", items_returned); 751 752 IWICEnumMetadataItem_Release(enumerator); 753 } 754 755 static void test_metadata_IFD(void) 756 { 757 static const struct test_data td[28] = 758 { 759 { VT_UI2, 0xfe, 0, { 1 } }, 760 { VT_UI4, 0x100, 0, { 222 } }, 761 { VT_UI4, 0x101, 0, { 333 } }, 762 { VT_UI2, 0x102, 0, { 24 } }, 763 { VT_UI4, 0x103, 0, { 32773 } }, 764 { VT_UI8, 0x11a, 0, { ((LONGLONG)3 << 32) | 900 } }, 765 { VT_UI1, 0xf001, 0, { 0x44 } }, 766 { VT_UI1|VT_VECTOR, 0xf002, 4, { 0x44, 0x33, 0x22, 0x11 } }, 767 { VT_I1, 0xf003, 0, { 0x44 } }, 768 { VT_I2, 0xf004, 0, { 0x3344 } }, 769 { VT_I2|VT_VECTOR, 0xf005, 2, { 0x3344, 0x1122 } }, 770 { VT_I4, 0xf006, 0, { 0x11223344 } }, 771 { VT_R4, 0xf007, 0, { 0x11223344 } }, 772 { VT_R8, 0xf008, 0, { ((LONGLONG)0x41d26580 << 32) | 0xb486522c } }, 773 { VT_I8, 0xf009, 0, { ((LONGLONG)0x5a6b7c8d << 32) | 0x1a2b3c4d } }, 774 { VT_UI1|VT_VECTOR, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } }, 775 { VT_I2|VT_VECTOR, 0xf00b, 4, { 0x0101, 0x0202, 0x0303, 0x0404 } }, 776 { VT_I4|VT_VECTOR, 0xf00c, 2, { 0x11223344, 0x55667788 } }, 777 { VT_R4|VT_VECTOR, 0xf00d, 2, { 0x449a522b, 0x4608f5ba } }, 778 { VT_LPSTR, 0xf00e, 12, { 0 }, "Hello World!" }, 779 { VT_LPSTR, 0xf00f, 4, { 0 }, "abcd" }, 780 { VT_BLOB, 0xf010, 13, { 0 }, "Hello World!" }, 781 { VT_BLOB, 0xf011, 4, { 0 }, "abcd" }, 782 { VT_UI1, 0xf012, 0, { 0x44 } }, 783 { VT_UI2, 0xf013, 0, { 0x3344 } }, 784 { VT_UI4, 0xf014, 0, { 0x11223344 } }, 785 { VT_R4, 0xf015, 0, { 0x11223344 } }, 786 { VT_I8|VT_VECTOR, 0xf016, 3, 787 { ((LONGLONG)0x05060708 << 32) | 0x01020304, 788 ((LONGLONG)0x50607080 << 32) | 0x10203040, 789 ((LONGLONG)0x55667788 << 32) | 0x11223344 } }, 790 }; 791 HRESULT hr; 792 IWICMetadataReader *reader; 793 IWICMetadataBlockReader *blockreader; 794 PROPVARIANT schema, id, value; 795 ULONG count; 796 GUID format; 797 char *IFD_data_swapped; 798 #ifdef WORDS_BIGENDIAN 799 DWORD persist_options = WICPersistOptionBigEndian; 800 #else 801 DWORD persist_options = WICPersistOptionLittleEndian; 802 #endif 803 804 hr = CoCreateInstance(&CLSID_WICIfdMetadataReader, NULL, CLSCTX_INPROC_SERVER, 805 &IID_IWICMetadataReader, (void**)&reader); 806 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); 807 808 hr = IWICMetadataReader_GetCount(reader, NULL); 809 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr); 810 811 hr = IWICMetadataReader_GetCount(reader, &count); 812 ok(hr == S_OK, "GetCount error %#x\n", hr); 813 ok(count == 0, "unexpected count %u\n", count); 814 815 load_stream((IUnknown*)reader, (const char *)&IFD_data, sizeof(IFD_data), persist_options); 816 817 hr = IWICMetadataReader_GetCount(reader, &count); 818 ok(hr == S_OK, "GetCount error %#x\n", hr); 819 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 820 821 compare_metadata(reader, td, count); 822 823 /* test IFD data with different endianness */ 824 if (persist_options == WICPersistOptionLittleEndian) 825 persist_options = WICPersistOptionBigEndian; 826 else 827 persist_options = WICPersistOptionLittleEndian; 828 829 IFD_data_swapped = HeapAlloc(GetProcessHeap(), 0, sizeof(IFD_data)); 830 memcpy(IFD_data_swapped, &IFD_data, sizeof(IFD_data)); 831 byte_swap_ifd_data(IFD_data_swapped); 832 load_stream((IUnknown *)reader, IFD_data_swapped, sizeof(IFD_data), persist_options); 833 hr = IWICMetadataReader_GetCount(reader, &count); 834 ok(hr == S_OK, "GetCount error %#x\n", hr); 835 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 836 compare_metadata(reader, td, count); 837 HeapFree(GetProcessHeap(), 0, IFD_data_swapped); 838 839 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 840 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr); 841 ok(IsEqualGUID(&format, &GUID_MetadataFormatIfd), "unexpected format %s\n", wine_dbgstr_guid(&format)); 842 843 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL); 844 ok(hr == E_INVALIDARG, "GetMetadataFormat should fail\n"); 845 846 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL); 847 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr); 848 849 PropVariantInit(&schema); 850 PropVariantInit(&id); 851 PropVariantInit(&value); 852 853 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, NULL, NULL, NULL); 854 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr); 855 856 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL); 857 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr); 858 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt); 859 860 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, &schema, NULL, NULL); 861 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr); 862 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt); 863 864 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL); 865 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr); 866 ok(id.vt == VT_UI2, "unexpected vt: %u\n", id.vt); 867 ok(U(id).uiVal == 0xfe, "unexpected id: %#x\n", U(id).uiVal); 868 PropVariantClear(&id); 869 870 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value); 871 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr); 872 ok(value.vt == VT_UI2, "unexpected vt: %u\n", value.vt); 873 ok(U(value).uiVal == 1, "unexpected id: %#x\n", U(value).uiVal); 874 PropVariantClear(&value); 875 876 hr = IWICMetadataReader_GetValueByIndex(reader, count, &schema, NULL, NULL); 877 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 878 879 PropVariantInit(&schema); 880 PropVariantInit(&id); 881 PropVariantInit(&value); 882 883 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value); 884 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr); 885 886 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL); 887 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr); 888 889 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, NULL); 890 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 891 892 hr = IWICMetadataReader_GetValue(reader, &schema, &id, NULL); 893 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr); 894 895 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value); 896 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 897 898 id.vt = VT_UI2; 899 U(id).uiVal = 0xf00e; 900 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL); 901 ok(hr == S_OK, "GetValue error %#x\n", hr); 902 903 /* schema is ignored by Ifd metadata reader */ 904 schema.vt = VT_UI4; 905 U(schema).ulVal = 0xdeadbeef; 906 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value); 907 ok(hr == S_OK, "GetValue error %#x\n", hr); 908 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); 909 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal); 910 PropVariantClear(&value); 911 912 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value); 913 ok(hr == S_OK, "GetValue error %#x\n", hr); 914 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); 915 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal); 916 PropVariantClear(&value); 917 918 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader); 919 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr); 920 921 if (SUCCEEDED(hr)) 922 IWICMetadataBlockReader_Release(blockreader); 923 924 IWICMetadataReader_Release(reader); 925 } 926 927 static void test_metadata_Exif(void) 928 { 929 HRESULT hr; 930 IWICMetadataReader *reader; 931 IWICMetadataBlockReader *blockreader; 932 UINT count=0; 933 934 hr = CoCreateInstance(&CLSID_WICExifMetadataReader, NULL, CLSCTX_INPROC_SERVER, 935 &IID_IWICMetadataReader, (void**)&reader); 936 todo_wine ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); 937 if (FAILED(hr)) return; 938 939 hr = IWICMetadataReader_GetCount(reader, NULL); 940 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr); 941 942 hr = IWICMetadataReader_GetCount(reader, &count); 943 ok(hr == S_OK, "GetCount error %#x\n", hr); 944 ok(count == 0, "unexpected count %u\n", count); 945 946 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader); 947 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr); 948 949 if (SUCCEEDED(hr)) 950 IWICMetadataBlockReader_Release(blockreader); 951 952 IWICMetadataReader_Release(reader); 953 } 954 955 static void test_create_reader(void) 956 { 957 HRESULT hr; 958 IWICComponentFactory *factory; 959 IStream *stream; 960 IWICMetadataReader *reader; 961 UINT count=0; 962 GUID format; 963 964 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, 965 &IID_IWICComponentFactory, (void**)&factory); 966 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); 967 968 stream = create_stream(metadata_tEXt, sizeof(metadata_tEXt)); 969 970 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, 971 NULL, NULL, WICPersistOptionDefault, 972 stream, &reader); 973 ok(hr == E_INVALIDARG, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); 974 975 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, 976 &GUID_ContainerFormatPng, NULL, WICPersistOptionDefault, 977 NULL, &reader); 978 ok(hr == E_INVALIDARG, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); 979 980 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, 981 &GUID_ContainerFormatPng, NULL, WICPersistOptionDefault, 982 stream, NULL); 983 ok(hr == E_INVALIDARG, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); 984 985 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, 986 &GUID_ContainerFormatPng, NULL, WICPersistOptionDefault, 987 stream, &reader); 988 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); 989 990 if (SUCCEEDED(hr)) 991 { 992 hr = IWICMetadataReader_GetCount(reader, &count); 993 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 994 ok(count == 1, "unexpected count %i\n", count); 995 996 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 997 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); 998 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", wine_dbgstr_guid(&format)); 999 1000 IWICMetadataReader_Release(reader); 1001 } 1002 1003 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, 1004 &GUID_ContainerFormatWmp, NULL, WICPersistOptionDefault, 1005 stream, &reader); 1006 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); 1007 1008 if (SUCCEEDED(hr)) 1009 { 1010 hr = IWICMetadataReader_GetCount(reader, &count); 1011 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 1012 ok(count == 1, "unexpected count %i\n", count); 1013 1014 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1015 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); 1016 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), "unexpected format %s\n", wine_dbgstr_guid(&format)); 1017 1018 IWICMetadataReader_Release(reader); 1019 } 1020 1021 IStream_Release(stream); 1022 1023 IWICComponentFactory_Release(factory); 1024 } 1025 1026 static void test_metadata_png(void) 1027 { 1028 static const struct test_data td[6] = 1029 { 1030 { VT_UI2, 0, 0, { 2005 }, NULL, { 'Y','e','a','r',0 } }, 1031 { VT_UI1, 0, 0, { 6 }, NULL, { 'M','o','n','t','h',0 } }, 1032 { VT_UI1, 0, 0, { 3 }, NULL, { 'D','a','y',0 } }, 1033 { VT_UI1, 0, 0, { 15 }, NULL, { 'H','o','u','r',0 } }, 1034 { VT_UI1, 0, 0, { 7 }, NULL, { 'M','i','n','u','t','e',0 } }, 1035 { VT_UI1, 0, 0, { 45 }, NULL, { 'S','e','c','o','n','d',0 } } 1036 }; 1037 IStream *stream; 1038 IWICBitmapDecoder *decoder; 1039 IWICBitmapFrameDecode *frame; 1040 IWICMetadataBlockReader *blockreader; 1041 IWICMetadataReader *reader; 1042 IWICMetadataQueryReader *queryreader; 1043 IWICComponentFactory *factory; 1044 GUID containerformat; 1045 HRESULT hr; 1046 UINT count=0xdeadbeef; 1047 1048 hr = CoCreateInstance(&CLSID_WICPngDecoder, NULL, CLSCTX_INPROC_SERVER, 1049 &IID_IWICBitmapDecoder, (void**)&decoder); 1050 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); 1051 1052 if (FAILED(hr)) return; 1053 1054 stream = create_stream(pngimage, sizeof(pngimage)); 1055 1056 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad); 1057 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr); 1058 1059 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void**)&blockreader); 1060 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr); 1061 1062 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); 1063 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr); 1064 1065 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void**)&blockreader); 1066 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr); 1067 1068 if (SUCCEEDED(hr)) 1069 { 1070 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL); 1071 ok(hr == E_INVALIDARG, "GetContainerFormat failed, hr=%x\n", hr); 1072 1073 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &containerformat); 1074 ok(hr == S_OK, "GetContainerFormat failed, hr=%x\n", hr); 1075 ok(IsEqualGUID(&containerformat, &GUID_ContainerFormatPng), "unexpected container format\n"); 1076 1077 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL); 1078 ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr); 1079 1080 hr = IWICMetadataBlockReader_GetCount(blockreader, &count); 1081 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); 1082 ok(count == 1, "unexpected count %d\n", count); 1083 1084 if (0) 1085 { 1086 /* Crashes on Windows XP */ 1087 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, NULL); 1088 ok(hr == E_INVALIDARG, "GetReaderByIndex failed, hr=%x\n", hr); 1089 } 1090 1091 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader); 1092 ok(hr == S_OK, "GetReaderByIndex failed, hr=%x\n", hr); 1093 1094 if (SUCCEEDED(hr)) 1095 { 1096 hr = IWICMetadataReader_GetMetadataFormat(reader, &containerformat); 1097 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1098 todo_wine ok(IsEqualGUID(&containerformat, &GUID_MetadataFormatChunktIME) || 1099 broken(IsEqualGUID(&containerformat, &GUID_MetadataFormatUnknown)) /* Windows XP */, 1100 "unexpected container format\n"); 1101 1102 hr = IWICMetadataReader_GetCount(reader, &count); 1103 ok(hr == S_OK, "GetCount error %#x\n", hr); 1104 todo_wine ok(count == 6 || broken(count == 1) /* XP */, "expected 6, got %u\n", count); 1105 if (count == 6) 1106 compare_metadata(reader, td, count); 1107 1108 IWICMetadataReader_Release(reader); 1109 } 1110 1111 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader); 1112 todo_wine ok(hr == WINCODEC_ERR_VALUEOUTOFRANGE, "GetReaderByIndex failed, hr=%x\n", hr); 1113 1114 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, 1115 &IID_IWICComponentFactory, (void**)&factory); 1116 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); 1117 1118 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, NULL, &queryreader); 1119 ok(hr == E_INVALIDARG, "CreateQueryReaderFromBlockReader should have failed: %08x\n", hr); 1120 1121 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, blockreader, NULL); 1122 ok(hr == E_INVALIDARG, "CreateQueryReaderFromBlockReader should have failed: %08x\n", hr); 1123 1124 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, blockreader, &queryreader); 1125 ok(hr == S_OK, "CreateQueryReaderFromBlockReader failed: %08x\n", hr); 1126 1127 IWICMetadataQueryReader_Release(queryreader); 1128 1129 IWICComponentFactory_Release(factory); 1130 1131 IWICMetadataBlockReader_Release(blockreader); 1132 } 1133 1134 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(frame, &queryreader); 1135 ok(hr == S_OK, "GetMetadataQueryReader failed: %08x\n", hr); 1136 1137 if (SUCCEEDED(hr)) 1138 { 1139 IWICMetadataQueryReader_Release(queryreader); 1140 } 1141 1142 IWICBitmapFrameDecode_Release(frame); 1143 1144 IWICBitmapDecoder_Release(decoder); 1145 1146 IStream_Release(stream); 1147 } 1148 1149 static void test_metadata_gif(void) 1150 { 1151 static const struct test_data gif_LSD[9] = 1152 { 1153 { VT_UI1|VT_VECTOR, 0, 6, {'G','I','F','8','7','a'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } }, 1154 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } }, 1155 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } }, 1156 { VT_BOOL, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } }, 1157 { VT_UI1, 0, 0, { 0 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } }, 1158 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } }, 1159 { VT_UI1, 0, 0, { 0 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } }, 1160 { VT_UI1, 0, 0, { 0 }, NULL, { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 } }, 1161 { VT_UI1, 0, 0, { 0 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } } 1162 }; 1163 static const struct test_data gif_IMD[8] = 1164 { 1165 { VT_UI2, 0, 0, { 0 }, NULL, { 'L','e','f','t',0 } }, 1166 { VT_UI2, 0, 0, { 0 }, NULL, { 'T','o','p',0 } }, 1167 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } }, 1168 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } }, 1169 { VT_BOOL, 0, 0, { 0 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } }, 1170 { VT_BOOL, 0, 0, { 0 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } }, 1171 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } }, 1172 { VT_UI1, 0, 0, { 0 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } } 1173 }; 1174 static const struct test_data animated_gif_LSD[9] = 1175 { 1176 { VT_UI1|VT_VECTOR, 0, 6, {'G','I','F','8','9','a'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } }, 1177 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } }, 1178 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } }, 1179 { VT_BOOL, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } }, 1180 { VT_UI1, 0, 0, { 2 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } }, 1181 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } }, 1182 { VT_UI1, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } }, 1183 { VT_UI1, 0, 0, { 0 }, NULL, { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 } }, 1184 { VT_UI1, 0, 0, { 0 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } } 1185 }; 1186 static const struct test_data animated_gif_IMD[8] = 1187 { 1188 { VT_UI2, 0, 0, { 0 }, NULL, { 'L','e','f','t',0 } }, 1189 { VT_UI2, 0, 0, { 0 }, NULL, { 'T','o','p',0 } }, 1190 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } }, 1191 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } }, 1192 { VT_BOOL, 0, 0, { 1 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } }, 1193 { VT_BOOL, 0, 0, { 0 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } }, 1194 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } }, 1195 { VT_UI1, 0, 0, { 1 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } } 1196 }; 1197 static const struct test_data animated_gif_GCE[5] = 1198 { 1199 { VT_UI1, 0, 0, { 0 }, NULL, { 'D','i','s','p','o','s','a','l',0 } }, 1200 { VT_BOOL, 0, 0, { 0 }, NULL, { 'U','s','e','r','I','n','p','u','t','F','l','a','g',0 } }, 1201 { VT_BOOL, 0, 0, { 1 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 } }, 1202 { VT_UI2, 0, 0, { 10 }, NULL, { 'D','e','l','a','y',0 } }, 1203 { VT_UI1, 0, 0, { 1 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','t','C','o','l','o','r','I','n','d','e','x',0 } } 1204 }; 1205 static const struct test_data animated_gif_APE[2] = 1206 { 1207 { VT_UI1|VT_VECTOR, 0, 11, { 'A','N','I','M','E','X','T','S','1','.','0' }, NULL, { 'A','p','p','l','i','c','a','t','i','o','n',0 } }, 1208 { VT_UI1|VT_VECTOR, 0, 4, { 0x03,0x01,0x05,0x00 }, NULL, { 'D','a','t','a',0 } } 1209 }; 1210 static const struct test_data animated_gif_comment_1[1] = 1211 { 1212 { VT_LPSTR, 0, 12, { 0 }, "Hello World!", { 'T','e','x','t','E','n','t','r','y',0 } } 1213 }; 1214 static const struct test_data animated_gif_comment_2[1] = 1215 { 1216 { VT_LPSTR, 0, 8, { 0 }, "image #1", { 'T','e','x','t','E','n','t','r','y',0 } } 1217 }; 1218 static const struct test_data animated_gif_plain_1[1] = 1219 { 1220 { VT_BLOB, 0, 17, { 0 }, "\x21\x01\x0d\x61nimation.gif" } 1221 }; 1222 static const struct test_data animated_gif_plain_2[1] = 1223 { 1224 { VT_BLOB, 0, 16, { 0 }, "\x21\x01\x0cplaintext #1" } 1225 }; 1226 IStream *stream; 1227 IWICBitmapDecoder *decoder; 1228 IWICBitmapFrameDecode *frame; 1229 IWICMetadataBlockReader *blockreader; 1230 IWICMetadataReader *reader; 1231 IWICMetadataQueryReader *queryreader; 1232 GUID format; 1233 HRESULT hr; 1234 UINT count; 1235 1236 /* 1x1 pixel gif */ 1237 stream = create_stream(gifimage, sizeof(gifimage)); 1238 1239 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER, 1240 &IID_IWICBitmapDecoder, (void **)&decoder); 1241 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); 1242 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad); 1243 ok(hr == S_OK, "Initialize error %#x\n", hr); 1244 1245 IStream_Release(stream); 1246 1247 /* global metadata block */ 1248 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&blockreader); 1249 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr); 1250 1251 if (SUCCEEDED(hr)) 1252 { 1253 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format); 1254 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); 1255 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), 1256 "wrong container format %s\n", wine_dbgstr_guid(&format)); 1257 1258 hr = IWICMetadataBlockReader_GetCount(blockreader, &count); 1259 ok(hr == S_OK, "GetCount error %#x\n", hr); 1260 ok(count == 1, "expected 1, got %u\n", count); 1261 1262 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader); 1263 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1264 1265 if (SUCCEEDED(hr)) 1266 { 1267 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1268 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1269 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), /* Logical Screen Descriptor */ 1270 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1271 1272 hr = IWICMetadataReader_GetCount(reader, &count); 1273 ok(hr == S_OK, "GetCount error %#x\n", hr); 1274 ok(count == sizeof(gif_LSD)/sizeof(gif_LSD[0]), "unexpected count %u\n", count); 1275 1276 compare_metadata(reader, gif_LSD, count); 1277 1278 IWICMetadataReader_Release(reader); 1279 } 1280 1281 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader); 1282 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1283 1284 IWICMetadataBlockReader_Release(blockreader); 1285 } 1286 1287 /* frame metadata block */ 1288 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); 1289 ok(hr == S_OK, "GetFrame error %#x\n", hr); 1290 1291 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&blockreader); 1292 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr); 1293 1294 if (SUCCEEDED(hr)) 1295 { 1296 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL); 1297 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1298 1299 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format); 1300 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); 1301 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), 1302 "wrong container format %s\n", wine_dbgstr_guid(&format)); 1303 1304 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL); 1305 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1306 1307 hr = IWICMetadataBlockReader_GetCount(blockreader, &count); 1308 ok(hr == S_OK, "GetCount error %#x\n", hr); 1309 ok(count == 1, "expected 1, got %u\n", count); 1310 1311 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader); 1312 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1313 1314 if (SUCCEEDED(hr)) 1315 { 1316 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1317 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1318 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), /* Image Descriptor */ 1319 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1320 1321 hr = IWICMetadataReader_GetCount(reader, &count); 1322 ok(hr == S_OK, "GetCount error %#x\n", hr); 1323 ok(count == sizeof(gif_IMD)/sizeof(gif_IMD[0]), "unexpected count %u\n", count); 1324 1325 compare_metadata(reader, gif_IMD, count); 1326 1327 IWICMetadataReader_Release(reader); 1328 } 1329 1330 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader); 1331 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1332 1333 IWICMetadataBlockReader_Release(blockreader); 1334 } 1335 1336 IWICBitmapFrameDecode_Release(frame); 1337 IWICBitmapDecoder_Release(decoder); 1338 1339 /* 1x1 pixel gif, 2 frames */ 1340 stream = create_stream(animatedgif, sizeof(animatedgif)); 1341 1342 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER, 1343 &IID_IWICBitmapDecoder, (void **)&decoder); 1344 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); 1345 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad); 1346 ok(hr == S_OK, "Initialize error %#x\n", hr); 1347 1348 IStream_Release(stream); 1349 1350 /* global metadata block */ 1351 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&blockreader); 1352 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr); 1353 1354 if (SUCCEEDED(hr)) 1355 { 1356 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format); 1357 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); 1358 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), 1359 "wrong container format %s\n", wine_dbgstr_guid(&format)); 1360 1361 hr = IWICMetadataBlockReader_GetCount(blockreader, &count); 1362 ok(hr == S_OK, "GetCount error %#x\n", hr); 1363 ok(count == 4, "expected 4, got %u\n", count); 1364 1365 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader); 1366 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1367 1368 if (SUCCEEDED(hr)) 1369 { 1370 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1371 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1372 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), /* Logical Screen Descriptor */ 1373 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1374 1375 hr = IWICMetadataReader_GetCount(reader, &count); 1376 ok(hr == S_OK, "GetCount error %#x\n", hr); 1377 ok(count == sizeof(animated_gif_LSD)/sizeof(animated_gif_LSD[0]), "unexpected count %u\n", count); 1378 1379 compare_metadata(reader, animated_gif_LSD, count); 1380 1381 IWICMetadataReader_Release(reader); 1382 } 1383 1384 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader); 1385 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1386 1387 if (SUCCEEDED(hr)) 1388 { 1389 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1390 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1391 ok(IsEqualGUID(&format, &GUID_MetadataFormatAPE), /* Application Extension */ 1392 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1393 1394 hr = IWICMetadataReader_GetCount(reader, &count); 1395 ok(hr == S_OK, "GetCount error %#x\n", hr); 1396 ok(count == sizeof(animated_gif_APE)/sizeof(animated_gif_APE[0]), "unexpected count %u\n", count); 1397 1398 compare_metadata(reader, animated_gif_APE, count); 1399 1400 IWICMetadataReader_Release(reader); 1401 } 1402 1403 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 2, &reader); 1404 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1405 1406 if (SUCCEEDED(hr)) 1407 { 1408 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1409 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1410 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), /* Comment Extension */ 1411 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1412 1413 hr = IWICMetadataReader_GetCount(reader, &count); 1414 ok(hr == S_OK, "GetCount error %#x\n", hr); 1415 ok(count == sizeof(animated_gif_comment_1)/sizeof(animated_gif_comment_1[0]), "unexpected count %u\n", count); 1416 1417 compare_metadata(reader, animated_gif_comment_1, count); 1418 1419 IWICMetadataReader_Release(reader); 1420 } 1421 1422 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 3, &reader); 1423 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1424 1425 if (SUCCEEDED(hr)) 1426 { 1427 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1428 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1429 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), 1430 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1431 1432 hr = IWICMetadataReader_GetCount(reader, &count); 1433 ok(hr == S_OK, "GetCount error %#x\n", hr); 1434 ok(count == sizeof(animated_gif_plain_1)/sizeof(animated_gif_plain_1[0]), "unexpected count %u\n", count); 1435 1436 compare_metadata(reader, animated_gif_plain_1, count); 1437 1438 IWICMetadataReader_Release(reader); 1439 } 1440 1441 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 4, &reader); 1442 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1443 1444 IWICMetadataBlockReader_Release(blockreader); 1445 } 1446 1447 /* frame metadata block */ 1448 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame); 1449 ok(hr == S_OK, "GetFrame error %#x\n", hr); 1450 1451 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&blockreader); 1452 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr); 1453 1454 if (SUCCEEDED(hr)) 1455 { 1456 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL); 1457 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1458 1459 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format); 1460 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); 1461 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), 1462 "wrong container format %s\n", wine_dbgstr_guid(&format)); 1463 1464 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL); 1465 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1466 1467 hr = IWICMetadataBlockReader_GetCount(blockreader, &count); 1468 ok(hr == S_OK, "GetCount error %#x\n", hr); 1469 ok(count == 4, "expected 4, got %u\n", count); 1470 1471 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader); 1472 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1473 1474 if (SUCCEEDED(hr)) 1475 { 1476 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1477 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1478 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), /* Image Descriptor */ 1479 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1480 1481 hr = IWICMetadataReader_GetCount(reader, &count); 1482 ok(hr == S_OK, "GetCount error %#x\n", hr); 1483 ok(count == sizeof(animated_gif_IMD)/sizeof(animated_gif_IMD[0]), "unexpected count %u\n", count); 1484 1485 compare_metadata(reader, animated_gif_IMD, count); 1486 1487 IWICMetadataReader_Release(reader); 1488 } 1489 1490 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader); 1491 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1492 1493 if (SUCCEEDED(hr)) 1494 { 1495 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1496 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1497 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), /* Comment Extension */ 1498 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1499 1500 hr = IWICMetadataReader_GetCount(reader, &count); 1501 ok(hr == S_OK, "GetCount error %#x\n", hr); 1502 ok(count == sizeof(animated_gif_comment_2)/sizeof(animated_gif_comment_2[0]), "unexpected count %u\n", count); 1503 1504 if (count == 1) 1505 compare_metadata(reader, animated_gif_comment_2, count); 1506 1507 IWICMetadataReader_Release(reader); 1508 } 1509 1510 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 2, &reader); 1511 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1512 1513 if (SUCCEEDED(hr)) 1514 { 1515 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1516 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1517 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), 1518 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1519 1520 hr = IWICMetadataReader_GetCount(reader, &count); 1521 ok(hr == S_OK, "GetCount error %#x\n", hr); 1522 ok(count == sizeof(animated_gif_plain_2)/sizeof(animated_gif_plain_2[0]), "unexpected count %u\n", count); 1523 1524 compare_metadata(reader, animated_gif_plain_2, count); 1525 1526 IWICMetadataReader_Release(reader); 1527 } 1528 1529 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 3, &reader); 1530 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr); 1531 1532 if (SUCCEEDED(hr)) 1533 { 1534 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1535 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr); 1536 ok(IsEqualGUID(&format, &GUID_MetadataFormatGCE), /* Graphic Control Extension */ 1537 "wrong metadata format %s\n", wine_dbgstr_guid(&format)); 1538 1539 hr = IWICMetadataReader_GetCount(reader, &count); 1540 ok(hr == S_OK, "GetCount error %#x\n", hr); 1541 ok(count == sizeof(animated_gif_GCE)/sizeof(animated_gif_GCE[0]), "unexpected count %u\n", count); 1542 1543 compare_metadata(reader, animated_gif_GCE, count); 1544 1545 IWICMetadataReader_Release(reader); 1546 } 1547 1548 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 4, &reader); 1549 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); 1550 1551 IWICMetadataBlockReader_Release(blockreader); 1552 } 1553 1554 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &queryreader); 1555 ok(hr == S_OK || broken(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION) /* before Vista */, 1556 "GetMetadataQueryReader error %#x\n", hr); 1557 if (SUCCEEDED(hr)) 1558 { 1559 static const struct 1560 { 1561 const char *query; 1562 HRESULT hr; 1563 UINT vt; 1564 } decoder_data[] = 1565 { 1566 { "/logscrdesc/Signature", S_OK, VT_UI1 | VT_VECTOR }, 1567 { "/[0]logscrdesc/Signature", S_OK, VT_UI1 | VT_VECTOR }, 1568 { "/logscrdesc/\\Signature", S_OK, VT_UI1 | VT_VECTOR }, 1569 { "/Logscrdesc/\\signature", S_OK, VT_UI1 | VT_VECTOR }, 1570 { "/logscrdesc/{str=signature}", S_OK, VT_UI1 | VT_VECTOR }, 1571 { "/[0]logscrdesc/{str=signature}", S_OK, VT_UI1 | VT_VECTOR }, 1572 { "/logscrdesc/{wstr=signature}", S_OK, VT_UI1 | VT_VECTOR }, 1573 { "/[0]logscrdesc/{wstr=signature}", S_OK, VT_UI1 | VT_VECTOR }, 1574 { "/appext/Application", S_OK, VT_UI1 | VT_VECTOR }, 1575 { "/appext/{STR=APPlication}", S_OK, VT_UI1 | VT_VECTOR }, 1576 { "/appext/{WSTR=APPlication}", S_OK, VT_UI1 | VT_VECTOR }, 1577 { "/LogSCRdesC", S_OK, VT_UNKNOWN }, 1578 { "/[0]LogSCRdesC", S_OK, VT_UNKNOWN }, 1579 { "/appEXT", S_OK, VT_UNKNOWN }, 1580 { "/[0]appEXT", S_OK, VT_UNKNOWN }, 1581 { "grctlext", WINCODEC_ERR_PROPERTYNOTSUPPORTED, 0 }, 1582 { "/imgdesc", WINCODEC_ERR_PROPERTYNOTFOUND, 0 }, 1583 }; 1584 static const WCHAR rootW[] = {'/',0}; 1585 WCHAR name[256]; 1586 UINT len, i, j; 1587 PROPVARIANT value; 1588 IWICMetadataQueryReader *meta_reader; 1589 1590 hr = IWICMetadataQueryReader_GetContainerFormat(queryreader, &format); 1591 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); 1592 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), 1593 "wrong container format %s\n", wine_dbgstr_guid(&format)); 1594 1595 name[0] = 0; 1596 len = 0xdeadbeef; 1597 hr = IWICMetadataQueryReader_GetLocation(queryreader, 256, name, &len); 1598 ok(hr == S_OK, "GetLocation error %#x\n", hr); 1599 ok(len == 2, "expected 2, got %u\n", len); 1600 ok(!lstrcmpW(name, rootW), "expected '/', got %s\n", wine_dbgstr_w(name)); 1601 1602 for (i = 0; i < sizeof(decoder_data)/sizeof(decoder_data[0]); i++) 1603 { 1604 WCHAR queryW[256]; 1605 1606 if (winetest_debug > 1) 1607 trace("query: %s\n", decoder_data[i].query); 1608 MultiByteToWideChar(CP_ACP, 0, decoder_data[i].query, -1, queryW, 256); 1609 PropVariantInit(&value); 1610 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, &value); 1611 ok(hr == decoder_data[i].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW), hr, decoder_data[i].hr); 1612 ok(value.vt == decoder_data[i].vt, "expected %#x, got %#x\n", decoder_data[i].vt, value.vt); 1613 if (hr == S_OK && value.vt == VT_UNKNOWN) 1614 { 1615 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataQueryReader, (void **)&meta_reader); 1616 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 1617 1618 name[0] = 0; 1619 len = 0xdeadbeef; 1620 hr = IWICMetadataQueryReader_GetLocation(meta_reader, 256, name, &len); 1621 ok(hr == S_OK, "GetLocation error %#x\n", hr); 1622 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len); 1623 ok(!lstrcmpW(name, queryW), "expected %s, got %s\n", wine_dbgstr_w(queryW), wine_dbgstr_w(name)); 1624 1625 for (j = 0; j < sizeof(decoder_data)/sizeof(decoder_data[0]); j++) 1626 { 1627 MultiByteToWideChar(CP_ACP, 0, decoder_data[j].query, -1, queryW, 256); 1628 1629 if (CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, queryW, len-1, name, len-1) == CSTR_EQUAL && decoder_data[j].query[len - 1] != 0) 1630 { 1631 if (winetest_debug > 1) 1632 trace("query: %s\n", wine_dbgstr_w(queryW + len - 1)); 1633 PropVariantClear(&value); 1634 hr = IWICMetadataQueryReader_GetMetadataByName(meta_reader, queryW + len - 1, &value); 1635 ok(hr == decoder_data[j].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW + len - 1), hr, decoder_data[j].hr); 1636 ok(value.vt == decoder_data[j].vt, "expected %#x, got %#x\n", decoder_data[j].vt, value.vt); 1637 } 1638 } 1639 1640 IWICMetadataQueryReader_Release(meta_reader); 1641 } 1642 1643 PropVariantClear(&value); 1644 } 1645 1646 IWICMetadataQueryReader_Release(queryreader); 1647 } 1648 1649 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(frame, &queryreader); 1650 ok(hr == S_OK || broken(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION) /* before Vista */, 1651 "GetMetadataQueryReader error %#x\n", hr); 1652 if (SUCCEEDED(hr)) 1653 { 1654 static const struct 1655 { 1656 const char *query; 1657 HRESULT hr; 1658 UINT vt; 1659 } frame_data[] = 1660 { 1661 { "/grctlext/Delay", S_OK, VT_UI2 }, 1662 { "/[0]grctlext/Delay", S_OK, VT_UI2 }, 1663 { "/grctlext/{str=delay}", S_OK, VT_UI2 }, 1664 { "/[0]grctlext/{str=delay}", S_OK, VT_UI2 }, 1665 { "/grctlext/{wstr=delay}", S_OK, VT_UI2 }, 1666 { "/[0]grctlext/{wstr=delay}", S_OK, VT_UI2 }, 1667 { "/imgdesc/InterlaceFlag", S_OK, VT_BOOL }, 1668 { "/imgdesc/{STR=interlaceFLAG}", S_OK, VT_BOOL }, 1669 { "/imgdesc/{WSTR=interlaceFLAG}", S_OK, VT_BOOL }, 1670 { "/grctlext", S_OK, VT_UNKNOWN }, 1671 { "/[0]grctlext", S_OK, VT_UNKNOWN }, 1672 { "/imgdesc", S_OK, VT_UNKNOWN }, 1673 { "/[0]imgdesc", S_OK, VT_UNKNOWN }, 1674 { "/LogSCRdesC", WINCODEC_ERR_PROPERTYNOTFOUND, 0 }, 1675 { "/appEXT", WINCODEC_ERR_PROPERTYNOTFOUND, 0 }, 1676 { "/grctlext/{\\str=delay}", WINCODEC_ERR_WRONGSTATE, 0 }, 1677 { "/grctlext/{str=\\delay}", S_OK, VT_UI2 }, 1678 { "grctlext/Delay", WINCODEC_ERR_PROPERTYNOTSUPPORTED, 0 }, 1679 }; 1680 static const WCHAR rootW[] = {'/',0}; 1681 static const WCHAR guidW[] = {'/','{','g','u','i','d','=','\\',0}; 1682 static const WCHAR imgdescW[] = {'i','m','g','d','e','s','c',0}; 1683 static const WCHAR ImgDescW[] = {'I','m','g','D','e','s','c',0}; 1684 WCHAR name[256], queryW[256]; 1685 UINT len, i; 1686 PROPVARIANT value; 1687 IWICMetadataQueryReader *meta_reader; 1688 1689 hr = IWICMetadataQueryReader_GetContainerFormat(queryreader, &format); 1690 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); 1691 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), 1692 "wrong container format %s\n", wine_dbgstr_guid(&format)); 1693 1694 name[0] = 0; 1695 len = 0xdeadbeef; 1696 hr = IWICMetadataQueryReader_GetLocation(queryreader, 256, name, &len); 1697 ok(hr == S_OK, "GetLocation error %#x\n", hr); 1698 ok(len == 2, "expected 2, got %u\n", len); 1699 ok(!lstrcmpW(name, rootW), "expected '/', got %s\n", wine_dbgstr_w(name)); 1700 1701 for (i = 0; i < sizeof(frame_data)/sizeof(frame_data[0]); i++) 1702 { 1703 if (winetest_debug > 1) 1704 trace("query: %s\n", frame_data[i].query); 1705 MultiByteToWideChar(CP_ACP, 0, frame_data[i].query, -1, queryW, 256); 1706 PropVariantInit(&value); 1707 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, &value); 1708 ok(hr == frame_data[i].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW), hr, frame_data[i].hr); 1709 ok(value.vt == frame_data[i].vt, "expected %#x, got %#x\n", frame_data[i].vt, value.vt); 1710 if (hr == S_OK && value.vt == VT_UNKNOWN) 1711 { 1712 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataQueryReader, (void **)&meta_reader); 1713 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 1714 1715 name[0] = 0; 1716 len = 0xdeadbeef; 1717 hr = IWICMetadataQueryReader_GetLocation(meta_reader, 256, name, &len); 1718 ok(hr == S_OK, "GetLocation error %#x\n", hr); 1719 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len); 1720 ok(!lstrcmpW(name, queryW), "expected %s, got %s\n", wine_dbgstr_w(queryW), wine_dbgstr_w(name)); 1721 1722 IWICMetadataQueryReader_Release(meta_reader); 1723 } 1724 1725 PropVariantClear(&value); 1726 } 1727 1728 name[0] = 0; 1729 len = 0xdeadbeef; 1730 hr = WICMapGuidToShortName(&GUID_MetadataFormatIMD, 256, name, &len); 1731 ok(hr == S_OK, "WICMapGuidToShortName error %#x\n", hr); 1732 ok(!lstrcmpW(name, imgdescW), "wrong short name %s\n", wine_dbgstr_w(name)); 1733 1734 format = GUID_NULL; 1735 hr = WICMapShortNameToGuid(imgdescW, &format); 1736 ok(hr == S_OK, "WICMapGuidToShortName error %#x\n", hr); 1737 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong guid %s\n", wine_dbgstr_guid(&format)); 1738 1739 format = GUID_NULL; 1740 hr = WICMapShortNameToGuid(ImgDescW, &format); 1741 ok(hr == S_OK, "WICMapGuidToShortName error %#x\n", hr); 1742 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong guid %s\n", wine_dbgstr_guid(&format)); 1743 1744 lstrcpyW(queryW, guidW); 1745 StringFromGUID2(&GUID_MetadataFormatIMD, queryW + lstrlenW(queryW) - 1, 39); 1746 memcpy(queryW, guidW, sizeof(guidW) - 2); 1747 if (winetest_debug > 1) 1748 trace("query: %s\n", wine_dbgstr_w(queryW)); 1749 PropVariantInit(&value); 1750 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, &value); 1751 ok(hr == S_OK, "GetMetadataByName(%s) error %#x\n", wine_dbgstr_w(queryW), hr); 1752 ok(value.vt == VT_UNKNOWN, "expected VT_UNKNOWN, got %#x\n", value.vt); 1753 PropVariantClear(&value); 1754 1755 IWICMetadataQueryReader_Release(queryreader); 1756 } 1757 1758 IWICBitmapFrameDecode_Release(frame); 1759 IWICBitmapDecoder_Release(decoder); 1760 } 1761 1762 static void test_metadata_LSD(void) 1763 { 1764 static const WCHAR LSD_name[] = {'L','o','g','i','c','a','l',' ','S','c','r','e','e','n',' ','D','e','s','c','r','i','p','t','o','r',' ','R','e','a','d','e','r',0}; 1765 static const char LSD_data[] = "hello world!\x1\x2\x3\x4\xab\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf"; 1766 static const struct test_data td[9] = 1767 { 1768 { VT_UI1|VT_VECTOR, 0, 6, {'w','o','r','l','d','!'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } }, 1769 { VT_UI2, 0, 0, { 0x201 }, NULL, { 'W','i','d','t','h',0 } }, 1770 { VT_UI2, 0, 0, { 0x403 }, NULL, { 'H','e','i','g','h','t',0 } }, 1771 { VT_BOOL, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } }, 1772 { VT_UI1, 0, 0, { 2 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } }, 1773 { VT_BOOL, 0, 0, { 1 }, NULL, { 'S','o','r','t','F','l','a','g',0 } }, 1774 { VT_UI1, 0, 0, { 3 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } }, 1775 { VT_UI1, 0, 0, { 6 }, NULL, { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 } }, 1776 { VT_UI1, 0, 0, { 7 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } } 1777 }; 1778 LARGE_INTEGER pos; 1779 HRESULT hr; 1780 IStream *stream; 1781 IWICPersistStream *persist; 1782 IWICMetadataReader *reader; 1783 IWICMetadataHandlerInfo *info; 1784 WCHAR name[64]; 1785 UINT count, dummy; 1786 GUID format; 1787 CLSID id; 1788 1789 hr = CoCreateInstance(&CLSID_WICLSDMetadataReader, NULL, CLSCTX_INPROC_SERVER, 1790 &IID_IWICMetadataReader, (void **)&reader); 1791 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */, 1792 "CoCreateInstance error %#x\n", hr); 1793 1794 stream = create_stream(LSD_data, sizeof(LSD_data)); 1795 1796 if (SUCCEEDED(hr)) 1797 { 1798 pos.QuadPart = 6; 1799 hr = IStream_Seek(stream, pos, SEEK_SET, NULL); 1800 ok(hr == S_OK, "IStream_Seek error %#x\n", hr); 1801 1802 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); 1803 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 1804 1805 hr = IWICPersistStream_Load(persist, stream); 1806 ok(hr == S_OK, "Load error %#x\n", hr); 1807 1808 IWICPersistStream_Release(persist); 1809 } 1810 1811 if (SUCCEEDED(hr)) 1812 { 1813 hr = IWICMetadataReader_GetCount(reader, &count); 1814 ok(hr == S_OK, "GetCount error %#x\n", hr); 1815 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 1816 1817 compare_metadata(reader, td, count); 1818 1819 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1820 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr); 1821 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), "wrong format %s\n", wine_dbgstr_guid(&format)); 1822 1823 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info); 1824 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr); 1825 1826 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id); 1827 ok(hr == S_OK, "GetCLSID error %#x\n", hr); 1828 ok(IsEqualGUID(&id, &CLSID_WICLSDMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&id)); 1829 1830 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy); 1831 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr); 1832 ok(lstrcmpW(name, LSD_name) == 0, "wrong LSD reader name %s\n", wine_dbgstr_w(name)); 1833 1834 IWICMetadataHandlerInfo_Release(info); 1835 IWICMetadataReader_Release(reader); 1836 } 1837 1838 IStream_Release(stream); 1839 } 1840 1841 static void test_metadata_IMD(void) 1842 { 1843 static const WCHAR IMD_name[] = {'I','m','a','g','e',' ','D','e','s','c','r','i','p','t','o','r',' ','R','e','a','d','e','r',0}; 1844 static const char IMD_data[] = "hello world!\x1\x2\x3\x4\x5\x6\x7\x8\xed\xa\xb\xc\xd\xe\xf"; 1845 static const struct test_data td[8] = 1846 { 1847 { VT_UI2, 0, 0, { 0x201 }, NULL, { 'L','e','f','t',0 } }, 1848 { VT_UI2, 0, 0, { 0x403 }, NULL, { 'T','o','p',0 } }, 1849 { VT_UI2, 0, 0, { 0x605 }, NULL, { 'W','i','d','t','h',0 } }, 1850 { VT_UI2, 0, 0, { 0x807 }, NULL, { 'H','e','i','g','h','t',0 } }, 1851 { VT_BOOL, 0, 0, { 1 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } }, 1852 { VT_BOOL, 0, 0, { 1 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } }, 1853 { VT_BOOL, 0, 0, { 1 }, NULL, { 'S','o','r','t','F','l','a','g',0 } }, 1854 { VT_UI1, 0, 0, { 5 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } } 1855 }; 1856 LARGE_INTEGER pos; 1857 HRESULT hr; 1858 IStream *stream; 1859 IWICPersistStream *persist; 1860 IWICMetadataReader *reader; 1861 IWICMetadataHandlerInfo *info; 1862 WCHAR name[64]; 1863 UINT count, dummy; 1864 GUID format; 1865 CLSID id; 1866 1867 hr = CoCreateInstance(&CLSID_WICIMDMetadataReader, NULL, CLSCTX_INPROC_SERVER, 1868 &IID_IWICMetadataReader, (void **)&reader); 1869 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */, 1870 "CoCreateInstance error %#x\n", hr); 1871 1872 stream = create_stream(IMD_data, sizeof(IMD_data)); 1873 1874 if (SUCCEEDED(hr)) 1875 { 1876 pos.QuadPart = 12; 1877 hr = IStream_Seek(stream, pos, SEEK_SET, NULL); 1878 ok(hr == S_OK, "IStream_Seek error %#x\n", hr); 1879 1880 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); 1881 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 1882 1883 hr = IWICPersistStream_Load(persist, stream); 1884 ok(hr == S_OK, "Load error %#x\n", hr); 1885 1886 IWICPersistStream_Release(persist); 1887 } 1888 1889 if (SUCCEEDED(hr)) 1890 { 1891 hr = IWICMetadataReader_GetCount(reader, &count); 1892 ok(hr == S_OK, "GetCount error %#x\n", hr); 1893 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 1894 1895 compare_metadata(reader, td, count); 1896 1897 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1898 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr); 1899 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong format %s\n", wine_dbgstr_guid(&format)); 1900 1901 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info); 1902 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr); 1903 1904 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id); 1905 ok(hr == S_OK, "GetCLSID error %#x\n", hr); 1906 ok(IsEqualGUID(&id, &CLSID_WICIMDMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&id)); 1907 1908 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy); 1909 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr); 1910 ok(lstrcmpW(name, IMD_name) == 0, "wrong IMD reader name %s\n", wine_dbgstr_w(name)); 1911 1912 IWICMetadataHandlerInfo_Release(info); 1913 IWICMetadataReader_Release(reader); 1914 } 1915 1916 IStream_Release(stream); 1917 } 1918 1919 static void test_metadata_GCE(void) 1920 { 1921 static const WCHAR GCE_name[] = {'G','r','a','p','h','i','c',' ','C','o','n','t','r','o','l',' ','E','x','t','e','n','s','i','o','n',' ','R','e','a','d','e','r',0}; 1922 static const char GCE_data[] = "hello world!\xa\x2\x3\x4\x5\x6\x7\x8\xed\xa\xb\xc\xd\xe\xf"; 1923 static const struct test_data td[5] = 1924 { 1925 { VT_UI1, 0, 0, { 2 }, NULL, { 'D','i','s','p','o','s','a','l',0 } }, 1926 { VT_BOOL, 0, 0, { 1 }, NULL, { 'U','s','e','r','I','n','p','u','t','F','l','a','g',0 } }, 1927 { VT_BOOL, 0, 0, { 0 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 } }, 1928 { VT_UI2, 0, 0, { 0x302 }, NULL, { 'D','e','l','a','y',0 } }, 1929 { VT_UI1, 0, 0, { 4 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','t','C','o','l','o','r','I','n','d','e','x',0 } } 1930 }; 1931 LARGE_INTEGER pos; 1932 HRESULT hr; 1933 IStream *stream; 1934 IWICPersistStream *persist; 1935 IWICMetadataReader *reader; 1936 IWICMetadataHandlerInfo *info; 1937 WCHAR name[64]; 1938 UINT count, dummy; 1939 GUID format; 1940 CLSID id; 1941 1942 hr = CoCreateInstance(&CLSID_WICGCEMetadataReader, NULL, CLSCTX_INPROC_SERVER, 1943 &IID_IWICMetadataReader, (void **)&reader); 1944 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */, 1945 "CoCreateInstance error %#x\n", hr); 1946 1947 stream = create_stream(GCE_data, sizeof(GCE_data)); 1948 1949 if (SUCCEEDED(hr)) 1950 { 1951 pos.QuadPart = 12; 1952 hr = IStream_Seek(stream, pos, SEEK_SET, NULL); 1953 ok(hr == S_OK, "IStream_Seek error %#x\n", hr); 1954 1955 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); 1956 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 1957 1958 hr = IWICPersistStream_Load(persist, stream); 1959 ok(hr == S_OK, "Load error %#x\n", hr); 1960 1961 IWICPersistStream_Release(persist); 1962 } 1963 1964 if (SUCCEEDED(hr)) 1965 { 1966 hr = IWICMetadataReader_GetCount(reader, &count); 1967 ok(hr == S_OK, "GetCount error %#x\n", hr); 1968 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 1969 1970 compare_metadata(reader, td, count); 1971 1972 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 1973 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr); 1974 ok(IsEqualGUID(&format, &GUID_MetadataFormatGCE), "wrong format %s\n", wine_dbgstr_guid(&format)); 1975 1976 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info); 1977 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr); 1978 1979 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id); 1980 ok(hr == S_OK, "GetCLSID error %#x\n", hr); 1981 ok(IsEqualGUID(&id, &CLSID_WICGCEMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&id)); 1982 1983 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy); 1984 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr); 1985 ok(lstrcmpW(name, GCE_name) == 0, "wrong GCE reader name %s\n", wine_dbgstr_w(name)); 1986 1987 IWICMetadataHandlerInfo_Release(info); 1988 IWICMetadataReader_Release(reader); 1989 } 1990 1991 IStream_Release(stream); 1992 } 1993 1994 static void test_metadata_APE(void) 1995 { 1996 static const WCHAR APE_name[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','E','x','t','e','n','s','i','o','n',' ','R','e','a','d','e','r',0}; 1997 static const char APE_data[] = { 0x21,0xff,0x0b,'H','e','l','l','o',' ','W','o','r','l','d', 1998 /*sub-block*/1,0x11, 1999 /*sub-block*/2,0x22,0x33, 2000 /*sub-block*/4,0x44,0x55,0x66,0x77, 2001 /*terminator*/0 }; 2002 static const struct test_data td[2] = 2003 { 2004 { VT_UI1|VT_VECTOR, 0, 11, { 'H','e','l','l','o',' ','W','o','r','l','d' }, NULL, { 'A','p','p','l','i','c','a','t','i','o','n',0 } }, 2005 { VT_UI1|VT_VECTOR, 0, 10, { 1,0x11,2,0x22,0x33,4,0x44,0x55,0x66,0x77 }, NULL, { 'D','a','t','a',0 } } 2006 }; 2007 WCHAR dataW[] = { 'd','a','t','a',0 }; 2008 HRESULT hr; 2009 IStream *stream; 2010 IWICPersistStream *persist; 2011 IWICMetadataReader *reader; 2012 IWICMetadataHandlerInfo *info; 2013 WCHAR name[64]; 2014 UINT count, dummy, i; 2015 GUID format; 2016 CLSID clsid; 2017 PROPVARIANT id, value; 2018 2019 hr = CoCreateInstance(&CLSID_WICAPEMetadataReader, NULL, CLSCTX_INPROC_SERVER, 2020 &IID_IWICMetadataReader, (void **)&reader); 2021 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */, 2022 "CoCreateInstance error %#x\n", hr); 2023 2024 stream = create_stream(APE_data, sizeof(APE_data)); 2025 2026 if (SUCCEEDED(hr)) 2027 { 2028 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); 2029 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 2030 2031 hr = IWICPersistStream_Load(persist, stream); 2032 ok(hr == S_OK, "Load error %#x\n", hr); 2033 2034 IWICPersistStream_Release(persist); 2035 } 2036 2037 if (SUCCEEDED(hr)) 2038 { 2039 hr = IWICMetadataReader_GetCount(reader, &count); 2040 ok(hr == S_OK, "GetCount error %#x\n", hr); 2041 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 2042 2043 compare_metadata(reader, td, count); 2044 2045 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 2046 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr); 2047 ok(IsEqualGUID(&format, &GUID_MetadataFormatAPE), "wrong format %s\n", wine_dbgstr_guid(&format)); 2048 2049 PropVariantInit(&value); 2050 id.vt = VT_LPWSTR; 2051 U(id).pwszVal = dataW; 2052 2053 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value); 2054 ok(hr == S_OK, "GetValue error %#x\n", hr); 2055 ok(value.vt == (VT_UI1|VT_VECTOR), "unexpected vt: %i\n", id.vt); 2056 ok(td[1].count == U(value).caub.cElems, "expected cElems %d, got %d\n", td[1].count, U(value).caub.cElems); 2057 for (i = 0; i < U(value).caub.cElems; i++) 2058 ok(td[1].value[i] == U(value).caub.pElems[i], "%u: expected value %#x/%#x, got %#x\n", i, (ULONG)td[1].value[i], (ULONG)(td[1].value[i] >> 32), U(value).caub.pElems[i]); 2059 PropVariantClear(&value); 2060 2061 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info); 2062 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr); 2063 2064 hr = IWICMetadataHandlerInfo_GetCLSID(info, &clsid); 2065 ok(hr == S_OK, "GetCLSID error %#x\n", hr); 2066 ok(IsEqualGUID(&clsid, &CLSID_WICAPEMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&clsid)); 2067 2068 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy); 2069 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr); 2070 ok(lstrcmpW(name, APE_name) == 0, "wrong APE reader name %s\n", wine_dbgstr_w(name)); 2071 2072 IWICMetadataHandlerInfo_Release(info); 2073 IWICMetadataReader_Release(reader); 2074 } 2075 2076 IStream_Release(stream); 2077 } 2078 2079 static void test_metadata_GIF_comment(void) 2080 { 2081 static const WCHAR GIF_comment_name[] = {'C','o','m','m','e','n','t',' ','E','x','t','e','n','s','i','o','n',' ','R','e','a','d','e','r',0}; 2082 static const char GIF_comment_data[] = { 0x21,0xfe, 2083 /*sub-block*/5,'H','e','l','l','o', 2084 /*sub-block*/1,' ', 2085 /*sub-block*/6,'W','o','r','l','d','!', 2086 /*terminator*/0 }; 2087 static const struct test_data td[1] = 2088 { 2089 { VT_LPSTR, 0, 12, { 0 }, "Hello World!", { 'T','e','x','t','E','n','t','r','y',0 } } 2090 }; 2091 WCHAR text_entryW[] = { 'T','E','X','T','E','N','T','R','Y',0 }; 2092 HRESULT hr; 2093 IStream *stream; 2094 IWICPersistStream *persist; 2095 IWICMetadataReader *reader; 2096 IWICMetadataHandlerInfo *info; 2097 WCHAR name[64]; 2098 UINT count, dummy; 2099 GUID format; 2100 CLSID clsid; 2101 PROPVARIANT id, value; 2102 2103 hr = CoCreateInstance(&CLSID_WICGifCommentMetadataReader, NULL, CLSCTX_INPROC_SERVER, 2104 &IID_IWICMetadataReader, (void **)&reader); 2105 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */, 2106 "CoCreateInstance error %#x\n", hr); 2107 2108 stream = create_stream(GIF_comment_data, sizeof(GIF_comment_data)); 2109 2110 if (SUCCEEDED(hr)) 2111 { 2112 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); 2113 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 2114 2115 hr = IWICPersistStream_Load(persist, stream); 2116 ok(hr == S_OK, "Load error %#x\n", hr); 2117 2118 IWICPersistStream_Release(persist); 2119 } 2120 2121 if (SUCCEEDED(hr)) 2122 { 2123 hr = IWICMetadataReader_GetCount(reader, &count); 2124 ok(hr == S_OK, "GetCount error %#x\n", hr); 2125 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count); 2126 2127 compare_metadata(reader, td, count); 2128 2129 hr = IWICMetadataReader_GetMetadataFormat(reader, &format); 2130 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr); 2131 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), "wrong format %s\n", wine_dbgstr_guid(&format)); 2132 2133 PropVariantInit(&value); 2134 id.vt = VT_LPWSTR; 2135 U(id).pwszVal = text_entryW; 2136 2137 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value); 2138 ok(hr == S_OK, "GetValue error %#x\n", hr); 2139 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); 2140 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal); 2141 PropVariantClear(&value); 2142 2143 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info); 2144 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr); 2145 2146 hr = IWICMetadataHandlerInfo_GetCLSID(info, &clsid); 2147 ok(hr == S_OK, "GetCLSID error %#x\n", hr); 2148 ok(IsEqualGUID(&clsid, &CLSID_WICGifCommentMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&clsid)); 2149 2150 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy); 2151 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr); 2152 ok(lstrcmpW(name, GIF_comment_name) == 0, "wrong APE reader name %s\n", wine_dbgstr_w(name)); 2153 2154 IWICMetadataHandlerInfo_Release(info); 2155 IWICMetadataReader_Release(reader); 2156 } 2157 2158 IStream_Release(stream); 2159 } 2160 2161 static void test_WICMapGuidToShortName(void) 2162 { 2163 static const WCHAR unkW[] = { 'u','n','k',0 }; 2164 static const WCHAR unknownW[] = { 'u','n','k','n','o','w','n',0 }; 2165 HRESULT hr; 2166 UINT len; 2167 WCHAR name[16]; 2168 2169 name[0] = 0; 2170 len = 0xdeadbeef; 2171 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, name, &len); 2172 ok(hr == S_OK, "got %#x\n", hr); 2173 ok(len == 8, "got %u\n", len); 2174 ok(!lstrcmpW(name, unknownW), "got %s\n", wine_dbgstr_w(name)); 2175 2176 name[0] = 0; 2177 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, name, NULL); 2178 ok(hr == S_OK, "got %#x\n", hr); 2179 ok(!lstrcmpW(name, unknownW), "got %s\n", wine_dbgstr_w(name)); 2180 2181 len = 0xdeadbeef; 2182 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, NULL, &len); 2183 ok(hr == S_OK, "got %#x\n", hr); 2184 ok(len == 8, "got %u\n", len); 2185 2186 len = 0xdeadbeef; 2187 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 0, NULL, &len); 2188 ok(hr == S_OK, "got %#x\n", hr); 2189 ok(len == 8, "got %u\n", len); 2190 2191 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 0, NULL, NULL); 2192 ok(hr == S_OK, "got %#x\n", hr); 2193 2194 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, NULL, NULL); 2195 ok(hr == S_OK, "got %#x\n", hr); 2196 2197 hr = WICMapGuidToShortName(&GUID_NULL, 0, NULL, NULL); 2198 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr); 2199 2200 name[0] = 0; 2201 len = 0xdeadbeef; 2202 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 4, name, &len); 2203 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "got %#x\n", hr); 2204 ok(len == 0xdeadbeef, "got %u\n", len); 2205 ok(!lstrcmpW(name, unkW), "got %s\n", wine_dbgstr_w(name)); 2206 2207 name[0] = 0; 2208 len = 0xdeadbeef; 2209 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 0, name, &len); 2210 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2211 ok(len == 0xdeadbeef, "got %u\n", len); 2212 ok(!name[0], "got %s\n", wine_dbgstr_w(name)); 2213 2214 hr = WICMapGuidToShortName(NULL, 8, name, NULL); 2215 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2216 } 2217 2218 static void test_WICMapShortNameToGuid(void) 2219 { 2220 static const WCHAR unkW[] = { 'u','n','k',0 }; 2221 static const WCHAR xmpW[] = { 'x','m','p',0 }; 2222 static const WCHAR XmPW[] = { 'X','m','P',0 }; 2223 static const WCHAR unknownW[] = { 'u','n','k','n','o','w','n',0 }; 2224 HRESULT hr; 2225 GUID guid; 2226 2227 hr = WICMapShortNameToGuid(NULL, NULL); 2228 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2229 2230 hr = WICMapShortNameToGuid(NULL, &guid); 2231 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2232 2233 hr = WICMapShortNameToGuid(unknownW, NULL); 2234 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2235 2236 hr = WICMapShortNameToGuid(unkW, &guid); 2237 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr); 2238 2239 hr = WICMapShortNameToGuid(unknownW, &guid); 2240 ok(hr == S_OK, "got %#x\n", hr); 2241 ok(IsEqualGUID(&guid, &GUID_MetadataFormatUnknown), "got %s\n", wine_dbgstr_guid(&guid)); 2242 2243 hr = WICMapShortNameToGuid(xmpW, &guid); 2244 ok(hr == S_OK, "got %#x\n", hr); 2245 ok(IsEqualGUID(&guid, &GUID_MetadataFormatXMP), "got %s\n", wine_dbgstr_guid(&guid)); 2246 2247 guid = GUID_NULL; 2248 hr = WICMapShortNameToGuid(XmPW, &guid); 2249 ok(hr == S_OK, "got %#x\n", hr); 2250 ok(IsEqualGUID(&guid, &GUID_MetadataFormatXMP), "got %s\n", wine_dbgstr_guid(&guid)); 2251 } 2252 2253 static const GUID *guid_list[] = 2254 { 2255 &GUID_ContainerFormatBmp, 2256 &GUID_ContainerFormatPng, 2257 &GUID_ContainerFormatIco, 2258 &GUID_ContainerFormatJpeg, 2259 &GUID_ContainerFormatTiff, 2260 &GUID_ContainerFormatGif, 2261 &GUID_ContainerFormatWmp, 2262 &GUID_MetadataFormatUnknown, 2263 &GUID_MetadataFormatIfd, 2264 &GUID_MetadataFormatSubIfd, 2265 &GUID_MetadataFormatExif, 2266 &GUID_MetadataFormatGps, 2267 &GUID_MetadataFormatInterop, 2268 &GUID_MetadataFormatApp0, 2269 &GUID_MetadataFormatApp1, 2270 &GUID_MetadataFormatApp13, 2271 &GUID_MetadataFormatIPTC, 2272 &GUID_MetadataFormatIRB, 2273 &GUID_MetadataFormat8BIMIPTC, 2274 &GUID_MetadataFormat8BIMResolutionInfo, 2275 &GUID_MetadataFormat8BIMIPTCDigest, 2276 &GUID_MetadataFormatXMP, 2277 &GUID_MetadataFormatThumbnail, 2278 &GUID_MetadataFormatChunktEXt, 2279 &GUID_MetadataFormatXMPStruct, 2280 &GUID_MetadataFormatXMPBag, 2281 &GUID_MetadataFormatXMPSeq, 2282 &GUID_MetadataFormatXMPAlt, 2283 &GUID_MetadataFormatLSD, 2284 &GUID_MetadataFormatIMD, 2285 &GUID_MetadataFormatGCE, 2286 &GUID_MetadataFormatAPE, 2287 &GUID_MetadataFormatJpegChrominance, 2288 &GUID_MetadataFormatJpegLuminance, 2289 &GUID_MetadataFormatJpegComment, 2290 &GUID_MetadataFormatGifComment, 2291 &GUID_MetadataFormatChunkgAMA, 2292 &GUID_MetadataFormatChunkbKGD, 2293 &GUID_MetadataFormatChunkiTXt, 2294 &GUID_MetadataFormatChunkcHRM, 2295 &GUID_MetadataFormatChunkhIST, 2296 &GUID_MetadataFormatChunkiCCP, 2297 &GUID_MetadataFormatChunksRGB, 2298 &GUID_MetadataFormatChunktIME 2299 }; 2300 2301 static WCHAR rdf_scheme[] = { 'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g','/','1','9','9','9','/','0','2','/','2','2','-','r','d','f','-','s','y','n','t','a','x','-','n','s','#',0 }; 2302 static WCHAR dc_scheme[] = { 'h','t','t','p',':','/','/','p','u','r','l','.','o','r','g','/','d','c','/','e','l','e','m','e','n','t','s','/','1','.','1','/',0 }; 2303 static WCHAR xmp_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/',0 }; 2304 static WCHAR xmpidq_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','m','p','/','I','d','e','n','t','i','f','i','e','r','/','q','u','a','l','/','1','.','0','/',0 }; 2305 static WCHAR xmpRights_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','r','i','g','h','t','s','/',0 }; 2306 static WCHAR xmpMM_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','m','m','/',0 }; 2307 static WCHAR xmpBJ_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','b','j','/',0 }; 2308 static WCHAR xmpTPg_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','t','/','p','g','/',0 }; 2309 static WCHAR pdf_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','p','d','f','/','1','.','3','/',0 }; 2310 static WCHAR photoshop_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','p','h','o','t','o','s','h','o','p','/','1','.','0','/',0 }; 2311 static WCHAR tiff_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','t','i','f','f','/','1','.','0','/',0 }; 2312 static WCHAR exif_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','e','x','i','f','/','1','.','0','/',0 }; 2313 static WCHAR stDim_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','D','i','m','e','n','s','i','o','n','s','#',0 }; 2314 static WCHAR xapGImg_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','g','/','i','m','g','/',0 }; 2315 static WCHAR stEvt_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','R','e','s','o','u','r','c','e','E','v','e','n','t','#',0 }; 2316 static WCHAR stRef_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','R','e','s','o','u','r','c','e','R','e','f','#',0 }; 2317 static WCHAR stVer_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','V','e','r','s','i','o','n','#',0 }; 2318 static WCHAR stJob_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','J','o','b','#',0 }; 2319 static WCHAR aux_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','e','x','i','f','/','1','.','0','/','a','u','x','/',0 }; 2320 static WCHAR crs_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','c','a','m','e','r','a','-','r','a','w','-','s','e','t','t','i','n','g','s','/','1','.','0','/',0 }; 2321 static WCHAR xmpDM_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','m','p','/','1','.','0','/','D','y','n','a','m','i','c','M','e','d','i','a','/',0 }; 2322 static WCHAR Iptc4xmpCore_scheme[] = { 'h','t','t','p',':','/','/','i','p','t','c','.','o','r','g','/','s','t','d','/','I','p','t','c','4','x','m','p','C','o','r','e','/','1','.','0','/','x','m','l','n','s','/',0 }; 2323 static WCHAR MicrosoftPhoto_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','0','/',0 }; 2324 static WCHAR MP_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','2','/',0 }; 2325 static WCHAR MPRI_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','2','/','t','/','R','e','g','i','o','n','I','n','f','o','#',0 }; 2326 static WCHAR MPReg_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','2','/','t','/','R','e','g','i','o','n','#',0 }; 2327 2328 static WCHAR *schema_list[] = 2329 { 2330 aux_scheme, 2331 rdf_scheme, 2332 dc_scheme, 2333 xmp_scheme, 2334 xmpidq_scheme, 2335 xmpRights_scheme, 2336 xmpMM_scheme, 2337 xmpBJ_scheme, 2338 xmpTPg_scheme, 2339 pdf_scheme, 2340 photoshop_scheme, 2341 tiff_scheme, 2342 exif_scheme, 2343 stDim_scheme, 2344 xapGImg_scheme, 2345 stEvt_scheme, 2346 stRef_scheme, 2347 stVer_scheme, 2348 stJob_scheme, 2349 crs_scheme, 2350 xmpDM_scheme, 2351 Iptc4xmpCore_scheme, 2352 MicrosoftPhoto_scheme, 2353 MP_scheme, 2354 MPRI_scheme, 2355 MPReg_scheme 2356 }; 2357 2358 static void test_WICMapSchemaToName(void) 2359 { 2360 static const WCHAR xmW[] = { 'x','m',0 }; 2361 static const WCHAR xmpW[] = { 'x','m','p',0 }; 2362 static WCHAR schemaW[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/',0 }; 2363 static WCHAR SCHEMAW[] = { 'H','T','T','P',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/',0 }; 2364 HRESULT hr; 2365 UINT len, i, j; 2366 WCHAR name[16]; 2367 2368 hr = WICMapSchemaToName(&GUID_MetadataFormatUnknown, NULL, 0, NULL, NULL); 2369 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2370 2371 hr = WICMapSchemaToName(&GUID_MetadataFormatUnknown, schemaW, 0, NULL, NULL); 2372 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2373 2374 hr = WICMapSchemaToName(&GUID_MetadataFormatUnknown, schemaW, 0, NULL, &len); 2375 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr); 2376 2377 hr = WICMapSchemaToName(NULL, schemaW, 0, NULL, &len); 2378 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2379 2380 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 0, NULL, NULL); 2381 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2382 2383 len = 0xdeadbeef; 2384 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 0, NULL, &len); 2385 ok(hr == S_OK, "got %#x\n", hr); 2386 ok(len == 4, "got %u\n", len); 2387 2388 len = 0xdeadbeef; 2389 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 4, NULL, &len); 2390 ok(hr == S_OK, "got %#x\n", hr); 2391 ok(len == 4, "got %u\n", len); 2392 2393 len = 0xdeadbeef; 2394 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, SCHEMAW, 0, NULL, &len); 2395 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr); 2396 ok(len == 0xdeadbeef, "got %u\n", len); 2397 2398 name[0] = 0; 2399 len = 0xdeadbeef; 2400 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 4, name, &len); 2401 ok(hr == S_OK, "got %#x\n", hr); 2402 ok(len == 4, "got %u\n", len); 2403 ok(!lstrcmpW(name, xmpW), "got %s\n", wine_dbgstr_w(name)); 2404 2405 len = 0xdeadbeef; 2406 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 0, name, &len); 2407 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2408 ok(len == 0xdeadbeef, "got %u\n", len); 2409 2410 name[0] = 0; 2411 len = 0xdeadbeef; 2412 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 3, name, &len); 2413 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "got %#x\n", hr); 2414 ok(len == 0xdeadbeef, "got %u\n", len); 2415 ok(!lstrcmpW(name, xmW), "got %s\n", wine_dbgstr_w(name)); 2416 2417 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 4, name, NULL); 2418 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2419 2420 /* Check whether modern schemas are supported */ 2421 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schema_list[0], 0, NULL, &len); 2422 if (hr == WINCODEC_ERR_PROPERTYNOTFOUND) 2423 { 2424 win_skip("Modern schemas are not supported\n"); 2425 return; 2426 } 2427 2428 for (i = 0; i < sizeof(guid_list)/sizeof(guid_list[0]); i++) 2429 { 2430 for (j = 0; j < sizeof(schema_list)/sizeof(schema_list[0]); j++) 2431 { 2432 hr = WICMapSchemaToName(guid_list[i], schema_list[j], 0, NULL, &len); 2433 if (IsEqualGUID(guid_list[i], &GUID_MetadataFormatXMP) || 2434 IsEqualGUID(guid_list[i], &GUID_MetadataFormatXMPStruct)) 2435 { 2436 ok(hr == S_OK, "%u: %u: format %s does not support schema %s\n", 2437 i, j, wine_dbgstr_guid(guid_list[i]), wine_dbgstr_w(schema_list[j])); 2438 } 2439 else 2440 { 2441 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "%u: %u: format %s supports schema %s\n", 2442 i, j, wine_dbgstr_guid(guid_list[i]), wine_dbgstr_w(schema_list[j])); 2443 } 2444 } 2445 } 2446 } 2447 2448 struct metadata_item 2449 { 2450 const char *schema, *id_str; 2451 UINT id, type, value; 2452 }; 2453 2454 struct metadata_block 2455 { 2456 const GUID *metadata_format; 2457 UINT count; 2458 const struct metadata_item *item; 2459 }; 2460 2461 struct metadata 2462 { 2463 const GUID *container_format; 2464 UINT count; 2465 const struct metadata_block *block; 2466 }; 2467 2468 static const struct metadata *current_metadata; 2469 static const struct metadata_block *current_metadata_block; 2470 2471 static char the_best[] = "The Best"; 2472 static char the_worst[] = "The Worst"; 2473 2474 static HRESULT WINAPI mdr_QueryInterface(IWICMetadataReader *iface, REFIID iid, void **out) 2475 { 2476 trace("%p,%s,%p\n", iface, wine_dbgstr_guid(iid), out); 2477 2478 if (IsEqualIID(iid, &IID_IUnknown) || 2479 IsEqualIID(iid, &IID_IWICMetadataReader)) 2480 { 2481 *out = iface; 2482 return S_OK; 2483 } 2484 2485 ok(0, "unknown iid %s\n", wine_dbgstr_guid(iid)); 2486 2487 *out = NULL; 2488 return E_NOINTERFACE; 2489 } 2490 2491 static ULONG WINAPI mdr_AddRef(IWICMetadataReader *iface) 2492 { 2493 return 2; 2494 } 2495 2496 static ULONG WINAPI mdr_Release(IWICMetadataReader *iface) 2497 { 2498 return 1; 2499 } 2500 2501 static HRESULT WINAPI mdr_GetMetadataFormat(IWICMetadataReader *iface, GUID *format) 2502 { 2503 trace("%p,%p\n", iface, format); 2504 2505 ok(current_metadata_block != NULL, "current_metadata_block can't be NULL\n"); 2506 if (!current_metadata_block) return E_POINTER; 2507 2508 *format = *current_metadata_block->metadata_format; 2509 return S_OK; 2510 } 2511 2512 static HRESULT WINAPI mdr_GetMetadataHandlerInfo(IWICMetadataReader *iface, IWICMetadataHandlerInfo **handler) 2513 { 2514 ok(0, "not implemented\n"); 2515 return E_NOTIMPL; 2516 } 2517 2518 static HRESULT WINAPI mdr_GetCount(IWICMetadataReader *iface, UINT *count) 2519 { 2520 trace("%p,%p\n", iface, count); 2521 2522 ok(current_metadata_block != NULL, "current_metadata_block can't be NULL\n"); 2523 if (!current_metadata_block) return E_POINTER; 2524 2525 *count = current_metadata_block->count; 2526 return S_OK; 2527 } 2528 2529 static HRESULT WINAPI mdr_GetValueByIndex(IWICMetadataReader *iface, UINT index, PROPVARIANT *schema, PROPVARIANT *id, PROPVARIANT *value) 2530 { 2531 ok(0, "not implemented\n"); 2532 return E_NOTIMPL; 2533 } 2534 2535 static char *get_temp_buffer(int size) 2536 { 2537 static char buf[16][256]; 2538 static int idx; 2539 char *p; 2540 2541 assert(size < 256); 2542 2543 p = buf[idx & 0x0f]; 2544 idx++; 2545 return p; 2546 } 2547 2548 static const char *wine_dbgstr_propvariant(const PROPVARIANT *var) 2549 { 2550 char *ret; 2551 2552 if (!var) return "(null)"; 2553 2554 switch (var->vt) 2555 { 2556 case VT_LPWSTR: 2557 ret = get_temp_buffer(lstrlenW(U(*var).pwszVal) + 16); 2558 sprintf(ret, "(VT_LPWSTR:%s)", wine_dbgstr_w(U(*var).pwszVal)); 2559 break; 2560 2561 case VT_LPSTR: 2562 ret = get_temp_buffer(lstrlenA(U(*var).pszVal) + 16); 2563 sprintf(ret, "(VT_LPSTR:%s)", U(*var).pszVal); 2564 break; 2565 2566 default: 2567 ret = get_temp_buffer(16); 2568 sprintf(ret, "(vt:%u)", var->vt); 2569 break; 2570 } 2571 2572 return ret; 2573 } 2574 2575 static int propvar_cmp(const PROPVARIANT *v1, LONGLONG value2) 2576 { 2577 LONGLONG value1; 2578 2579 if (PropVariantToInt64(v1, &value1) != S_OK) return -1; 2580 2581 value1 -= value2; 2582 if (value1) return value1 < 0 ? -1 : 1; 2583 return 0; 2584 } 2585 2586 static HRESULT WINAPI mdr_GetValue(IWICMetadataReader *iface, const PROPVARIANT *schema, const PROPVARIANT *id, PROPVARIANT *value) 2587 { 2588 UINT i; 2589 2590 trace("%p,%s,%s,%s\n", iface, wine_dbgstr_propvariant(schema), wine_dbgstr_propvariant(id), wine_dbgstr_propvariant(value)); 2591 2592 ok(current_metadata_block != NULL, "current_metadata_block can't be NULL\n"); 2593 if (!current_metadata_block) return E_POINTER; 2594 2595 ok(schema != NULL && id != NULL && value != NULL, "%p, %p, %p should not be NULL\n", schema, id, value); 2596 2597 for (i = 0; i < current_metadata_block->count; i++) 2598 { 2599 if (schema->vt != VT_EMPTY) 2600 { 2601 if (!current_metadata_block->item[i].schema) 2602 continue; 2603 2604 switch (schema->vt) 2605 { 2606 case VT_LPSTR: 2607 if (lstrcmpA(U(*schema).pszVal, current_metadata_block->item[i].schema) != 0) 2608 continue; 2609 break; 2610 2611 case VT_LPWSTR: 2612 { 2613 char schemaA[256]; 2614 WideCharToMultiByte(CP_ACP, 0, U(*schema).pwszVal, -1, schemaA, sizeof(schemaA), NULL, NULL); 2615 if (lstrcmpA(schemaA, current_metadata_block->item[i].schema) != 0) 2616 continue; 2617 break; 2618 } 2619 2620 default: 2621 ok(0, "unsupported schema vt %u\n", schema->vt); 2622 continue; 2623 } 2624 } 2625 else if (current_metadata_block->item[i].schema) 2626 continue; 2627 2628 switch (id->vt) 2629 { 2630 case VT_LPSTR: 2631 if (current_metadata_block->item[i].id_str) 2632 { 2633 if (!lstrcmpA(U(*id).pszVal, current_metadata_block->item[i].id_str)) 2634 { 2635 value->vt = VT_LPSTR; 2636 U(*value).pszVal = the_best; 2637 return S_OK; 2638 } 2639 break; 2640 } 2641 break; 2642 2643 case VT_LPWSTR: 2644 if (current_metadata_block->item[i].id_str) 2645 { 2646 char idA[256]; 2647 WideCharToMultiByte(CP_ACP, 0, U(*id).pwszVal, -1, idA, sizeof(idA), NULL, NULL); 2648 if (!lstrcmpA(idA, current_metadata_block->item[i].id_str)) 2649 { 2650 value->vt = VT_LPSTR; 2651 U(*value).pszVal = the_worst; 2652 return S_OK; 2653 } 2654 break; 2655 } 2656 break; 2657 2658 case VT_CLSID: 2659 if (IsEqualGUID(U(*id).puuid, &GUID_MetadataFormatXMP) || 2660 IsEqualGUID(U(*id).puuid, &GUID_ContainerFormatTiff)) 2661 { 2662 value->vt = VT_UNKNOWN; 2663 value->punkVal = (IUnknown *)iface; 2664 return S_OK; 2665 } 2666 break; 2667 2668 default: 2669 if (!propvar_cmp(id, current_metadata_block->item[i].id)) 2670 { 2671 value->vt = current_metadata_block->item[i].type; 2672 U(*value).uiVal = current_metadata_block->item[i].value; 2673 return S_OK; 2674 } 2675 break; 2676 } 2677 } 2678 2679 return 0xdeadbeef; 2680 } 2681 2682 static HRESULT WINAPI mdr_GetEnumerator(IWICMetadataReader *iface, IWICEnumMetadataItem **enumerator) 2683 { 2684 ok(0, "not implemented\n"); 2685 return E_NOTIMPL; 2686 } 2687 2688 static /* const */ IWICMetadataReaderVtbl mdr_vtbl = 2689 { 2690 mdr_QueryInterface, 2691 mdr_AddRef, 2692 mdr_Release, 2693 mdr_GetMetadataFormat, 2694 mdr_GetMetadataHandlerInfo, 2695 mdr_GetCount, 2696 mdr_GetValueByIndex, 2697 mdr_GetValue, 2698 mdr_GetEnumerator 2699 }; 2700 2701 static IWICMetadataReader mdr = { &mdr_vtbl }; 2702 2703 static HRESULT WINAPI mdbr_QueryInterface(IWICMetadataBlockReader *iface, REFIID iid, void **out) 2704 { 2705 if (IsEqualIID(iid, &IID_IUnknown) || 2706 IsEqualIID(iid, &IID_IWICMetadataBlockReader)) 2707 { 2708 *out = iface; 2709 return S_OK; 2710 } 2711 2712 /* Windows 8/10 query for some undocumented IID */ 2713 if (!IsEqualIID(iid, &IID_MdbrUnknown)) 2714 ok(0, "unknown iid %s\n", wine_dbgstr_guid(iid)); 2715 2716 *out = NULL; 2717 return E_NOINTERFACE; 2718 } 2719 2720 static ULONG WINAPI mdbr_AddRef(IWICMetadataBlockReader *iface) 2721 { 2722 return 2; 2723 } 2724 2725 static ULONG WINAPI mdbr_Release(IWICMetadataBlockReader *iface) 2726 { 2727 return 1; 2728 } 2729 2730 static HRESULT WINAPI mdbr_GetContainerFormat(IWICMetadataBlockReader *iface, GUID *format) 2731 { 2732 trace("%p,%p\n", iface, format); 2733 2734 ok(current_metadata != NULL, "current_metadata can't be NULL\n"); 2735 if (!current_metadata) return E_POINTER; 2736 2737 *format = *current_metadata->container_format; 2738 return S_OK; 2739 } 2740 2741 static HRESULT WINAPI mdbr_GetCount(IWICMetadataBlockReader *iface, UINT *count) 2742 { 2743 trace("%p,%p\n", iface, count); 2744 2745 ok(current_metadata != NULL, "current_metadata can't be NULL\n"); 2746 if (!current_metadata) return E_POINTER; 2747 2748 *count = current_metadata->count; 2749 return S_OK; 2750 } 2751 2752 static HRESULT WINAPI mdbr_GetReaderByIndex(IWICMetadataBlockReader *iface, UINT index, IWICMetadataReader **out) 2753 { 2754 trace("%p,%u,%p\n", iface, index, out); 2755 2756 *out = NULL; 2757 2758 ok(current_metadata != NULL, "current_metadata can't be NULL\n"); 2759 if (!current_metadata) return E_POINTER; 2760 2761 if (index < current_metadata->count) 2762 { 2763 current_metadata_block = ¤t_metadata->block[index]; 2764 *out = &mdr; 2765 return S_OK; 2766 } 2767 2768 current_metadata_block = NULL; 2769 return E_INVALIDARG; 2770 } 2771 2772 static HRESULT WINAPI mdbr_GetEnumerator(IWICMetadataBlockReader *iface, IEnumUnknown **enumerator) 2773 { 2774 ok(0, "not implemented\n"); 2775 return E_NOTIMPL; 2776 } 2777 2778 static /* const */ IWICMetadataBlockReaderVtbl mdbr_vtbl = 2779 { 2780 mdbr_QueryInterface, 2781 mdbr_AddRef, 2782 mdbr_Release, 2783 mdbr_GetContainerFormat, 2784 mdbr_GetCount, 2785 mdbr_GetReaderByIndex, 2786 mdbr_GetEnumerator 2787 }; 2788 2789 static IWICMetadataBlockReader mdbr = { &mdbr_vtbl }; 2790 2791 static const char xmp[] = "http://ns.adobe.com/xap/1.0/"; 2792 static const char dc[] = "http://purl.org/dc/elements/1.1/"; 2793 static const char tiff[] = "http://ns.adobe.com/tiff/1.0/"; 2794 2795 static const struct metadata_item item1[] = 2796 { 2797 { NULL, NULL, 1, 2, 3 } 2798 }; 2799 2800 static const struct metadata_item item2[] = 2801 { 2802 { NULL, NULL, 1, 2, 3 }, 2803 { "xmp", "Rating", 4, 5, 6 }, 2804 { NULL, "Rating", 7, 8, 9 } 2805 }; 2806 2807 static const struct metadata_item item3[] = 2808 { 2809 { NULL, NULL, 1, 2, 3 }, 2810 { NULL, NULL, 4, 5, 6 }, 2811 { NULL, NULL, 7, 8, 9 }, 2812 { NULL, NULL, 10, 11, 12 } 2813 }; 2814 2815 static const struct metadata_item item4[] = 2816 { 2817 { NULL, NULL, 1, 2, 3 }, 2818 { xmp, "Rating", 4, 5, 6 }, 2819 { dc, NULL, 7, 8, 9 }, 2820 { tiff, NULL, 10, 11, 12 }, 2821 { NULL, "RATING", 13, 14, 15 }, 2822 { NULL, "R}ATING", 16, 17, 18 }, 2823 { NULL, "xmp", 19, 20, 21 } 2824 }; 2825 2826 static const struct metadata_block block1[] = 2827 { 2828 { &GUID_MetadataFormatIfd, 1, item1 } 2829 }; 2830 2831 static const struct metadata_block block2[] = 2832 { 2833 { &GUID_MetadataFormatXMP, 1, item1 }, 2834 { &GUID_MetadataFormatIfd, 3, item2 } 2835 }; 2836 2837 static const struct metadata_block block3[] = 2838 { 2839 { &GUID_MetadataFormatXMP, 1, item1 }, 2840 { &GUID_MetadataFormatIfd, 3, item2 }, 2841 { &GUID_MetadataFormatXMP, 4, item3 }, 2842 { &GUID_MetadataFormatXMP, 7, item4 }, 2843 { &GUID_MetadataFormatIfd, 7, item4 } 2844 }; 2845 2846 static const struct metadata data1 = 2847 { 2848 &GUID_ContainerFormatGif, 2849 1, block1 2850 }; 2851 2852 static const struct metadata data2 = 2853 { 2854 &GUID_ContainerFormatTiff, 2855 2, block2 2856 }; 2857 2858 static const struct metadata data3 = 2859 { 2860 &GUID_ContainerFormatPng, 2861 5, block3 2862 }; 2863 2864 static void test_queryreader(void) 2865 { 2866 static const char q1[] = "/ifd/{uchar=1}"; 2867 static const char q2[] = "/ifd/xmp:{long=4}"; 2868 static const char q3[] = "/ifd/{str=xmp}:{uint=4}"; 2869 static const char q4[] = "/xmp/{char=7}"; 2870 static const char q5[] = "/[1]xmp/{short=7}"; 2871 static const char q6[] = "/[1]ifd/{str=dc}:{uint=7}"; 2872 static const char q7[] = "/[1]ifd/{str=http://purl.org/dc/elements/1.1/}:{longlong=7}"; 2873 static const char q8[] = "/[1]ifd/{str=http://ns.adobe.com/tiff/1.0/}:{int=10}"; 2874 static const char q9[] = "/[2]xmp/xmp:{ulong=4}"; 2875 static const char q10[] = "/[2]xmp/{str=xmp}:{ulong=4}"; 2876 static const char q11[] = "/xmp"; 2877 static const char q12[] = "/ifd/xmp"; 2878 static const char q13[] = "/ifd/xmp/tiff"; 2879 static const char q14[] = "/[0]ifd/[0]xmp/[0]tiff"; 2880 static const char q15[] = "/[*]xmp"; 2881 2882 static const char q20[] = "/ifd/\\Rating"; 2883 static const char q21[] = "/[0]ifd/Rating"; 2884 static const char q22[] = "/[2]xmp/xmp:{str=Rating}"; 2885 static const char q23[] = "/[2]xmp/xmp:Rating"; 2886 2887 static const char q24[] = "/[1]ifd/{str=http://ns.adobe.com/xap/1.0/}:Rating"; 2888 static const char q25[] = "/[1]ifd/{str=http://ns.adobe.com/xap/1.0/}:{str=Rating}"; 2889 static const char q26[] = "/[1]ifd/{wstr=\\RATING}"; 2890 static const char q27[] = "/[1]ifd/{str=R\\ATING}"; 2891 static const char q28[] = "/[1]ifd/{str=R\\}ATING}"; 2892 2893 static const char q40[] = "[0]/ifd/Rating"; 2894 static const char q41[] = "/[+1]ifd/Rating"; 2895 static const char q42[] = "/[-1]ifd/Rating"; 2896 static const char q43[] = "/ifd/{\\str=Rating}"; 2897 static const char q44[] = "/ifd/{badtype=0}"; 2898 static const char q45[] = "/ifd/{uint=0x1234}"; 2899 static const char q46[] = "/ifd/[0]Rating"; 2900 static const char q47[] = "/ifd/[*]Rating"; 2901 static const struct 2902 { 2903 BOOL todo; 2904 const struct metadata *data; 2905 const char *query; 2906 HRESULT hr; 2907 UINT vt, value; 2908 const char *str_value; 2909 } test_data[] = 2910 { 2911 { FALSE, &data1, q1, S_OK, 2, 3, NULL }, 2912 { FALSE, &data2, q2, S_OK, 5, 6, NULL }, 2913 { FALSE, &data2, q3, S_OK, 5, 6, NULL }, 2914 { FALSE, &data3, q4, 0xdeadbeef }, 2915 { FALSE, &data3, q5, S_OK, 8, 9, NULL }, 2916 { FALSE, &data3, q6, 0xdeadbeef }, 2917 { FALSE, &data3, q7, S_OK, 8, 9, NULL }, 2918 { FALSE, &data3, q8, S_OK, 11, 12, NULL }, 2919 { FALSE, &data3, q9, S_OK, 5, 6, NULL }, 2920 { FALSE, &data3, q10, 0xdeadbeef }, 2921 2922 { FALSE, &data3, q11, S_OK, VT_UNKNOWN, 0, NULL }, 2923 { FALSE, &data3, q12, S_OK, VT_UNKNOWN, 0, NULL }, 2924 { FALSE, &data3, q13, S_OK, VT_UNKNOWN, 0, NULL }, 2925 { FALSE, &data3, q14, S_OK, VT_UNKNOWN, 0, NULL }, 2926 { TRUE, &data3, q15, S_OK, VT_LPSTR, 0, the_worst }, 2927 2928 { FALSE, &data3, q20, S_OK, VT_LPSTR, 0, the_worst }, 2929 { FALSE, &data3, q21, S_OK, VT_LPSTR, 0, the_worst }, 2930 { FALSE, &data3, q22, S_OK, VT_LPSTR, 0, the_best }, 2931 { FALSE, &data3, q23, S_OK, VT_LPSTR, 0, the_worst }, 2932 { FALSE, &data3, q24, S_OK, VT_LPSTR, 0, the_worst }, 2933 { FALSE, &data3, q25, S_OK, VT_LPSTR, 0, the_best }, 2934 { FALSE, &data3, q26, S_OK, VT_LPSTR, 0, the_worst }, 2935 { FALSE, &data3, q27, S_OK, VT_LPSTR, 0, the_best }, 2936 { FALSE, &data3, q28, S_OK, VT_LPSTR, 0, the_best }, 2937 2938 { FALSE, &data1, q40, WINCODEC_ERR_PROPERTYNOTSUPPORTED }, 2939 { TRUE, &data1, q41, WINCODEC_ERR_INVALIDQUERYCHARACTER }, 2940 { TRUE, &data1, q42, WINCODEC_ERR_INVALIDQUERYCHARACTER }, 2941 { FALSE, &data1, q43, WINCODEC_ERR_WRONGSTATE }, 2942 { FALSE, &data1, q44, WINCODEC_ERR_WRONGSTATE }, 2943 { TRUE, &data1, q45, DISP_E_TYPEMISMATCH }, 2944 { TRUE, &data1, q46, E_INVALIDARG }, 2945 { TRUE, &data1, q47, WINCODEC_ERR_REQUESTONLYVALIDATMETADATAROOT }, 2946 }; 2947 WCHAR queryW[256]; 2948 HRESULT hr; 2949 IWICComponentFactory *factory; 2950 IWICMetadataQueryReader *reader; 2951 GUID format; 2952 PROPVARIANT value; 2953 UINT i; 2954 2955 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, 2956 &IID_IWICComponentFactory, (void **)&factory); 2957 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); 2958 2959 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, &mdbr, &reader); 2960 ok(hr == S_OK, "CreateQueryReaderFromBlockReader error %#x\n", hr); 2961 2962 for (i = 0; i < sizeof(test_data)/sizeof(test_data[0]); i++) 2963 { 2964 current_metadata = test_data[i].data; 2965 2966 hr = IWICMetadataQueryReader_GetContainerFormat(reader, &format); 2967 ok(hr == S_OK, "%u: GetContainerFormat error %#x\n", i, hr); 2968 ok(IsEqualGUID(&format, test_data[i].data->container_format), "%u: expected %s, got %s\n", 2969 i, wine_dbgstr_guid(test_data[i].data->container_format), wine_dbgstr_guid(&format)); 2970 2971 MultiByteToWideChar(CP_ACP, 0, test_data[i].query, -1, queryW, 256); 2972 PropVariantInit(&value); 2973 hr = IWICMetadataQueryReader_GetMetadataByName(reader, queryW, &value); 2974 todo_wine_if(test_data[i].todo) 2975 ok(hr == test_data[i].hr, "%u: expected %#x, got %#x\n", i, test_data[i].hr, hr); 2976 if (hr == S_OK) 2977 { 2978 ok(value.vt == test_data[i].vt, "%u: expected %u, got %u\n", i, test_data[i].vt, value.vt); 2979 if (test_data[i].vt == value.vt) 2980 { 2981 if (value.vt == VT_UNKNOWN) 2982 { 2983 IWICMetadataQueryReader *new_reader; 2984 WCHAR location[256]; 2985 UINT len; 2986 2987 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataQueryReader, (void **)&new_reader); 2988 ok(hr == S_OK, "QueryInterface error %#x\n", hr); 2989 2990 location[0] = 0; 2991 len = 0xdeadbeef; 2992 hr = IWICMetadataQueryReader_GetLocation(new_reader, 256, location, &len); 2993 ok(hr == S_OK, "GetLocation error %#x\n", hr); 2994 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len); 2995 ok(!lstrcmpW(location, queryW), "expected %s, got %s\n", wine_dbgstr_w(queryW), wine_dbgstr_w(location)); 2996 2997 hr = IWICMetadataQueryReader_GetLocation(new_reader, 256, location, NULL); 2998 ok(hr == E_INVALIDARG, "got %#x\n", hr); 2999 3000 location[0] = 0; 3001 len = 0xdeadbeef; 3002 hr = IWICMetadataQueryReader_GetLocation(new_reader, 3, location, &len); 3003 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "got %#x\n", hr); 3004 ok(len == 0xdeadbeef, "got %u\n", len); 3005 ok(!location[0], "got %s\n", wine_dbgstr_w(location)); 3006 3007 location[0] = 0; 3008 len = 0xdeadbeef; 3009 hr = IWICMetadataQueryReader_GetLocation(new_reader, 0, location, &len); 3010 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "got %#x\n", hr); 3011 ok(len == 0xdeadbeef, "got %u\n", len); 3012 ok(!location[0], "got %s\n", wine_dbgstr_w(location)); 3013 3014 len = 0xdeadbeef; 3015 hr = IWICMetadataQueryReader_GetLocation(new_reader, 0, NULL, &len); 3016 ok(hr == S_OK, "GetLocation error %#x\n", hr); 3017 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len); 3018 3019 len = 0xdeadbeef; 3020 hr = IWICMetadataQueryReader_GetLocation(new_reader, 3, NULL, &len); 3021 ok(hr == S_OK, "GetLocation error %#x\n", hr); 3022 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len); 3023 3024 hr = IWICMetadataQueryReader_GetLocation(new_reader, 0, NULL, NULL); 3025 ok(hr == E_INVALIDARG, "got %#x\n", hr); 3026 3027 IWICMetadataQueryReader_Release(new_reader); 3028 } 3029 else if (value.vt == VT_LPSTR) 3030 ok(!lstrcmpA(U(value).pszVal, test_data[i].str_value), "%u: expected %s, got %s\n", 3031 i, test_data[i].str_value, U(value).pszVal); 3032 else 3033 ok(U(value).uiVal == test_data[i].value, "%u: expected %u, got %u\n", 3034 i, test_data[i].value, U(value).uiVal); 3035 } 3036 3037 /* 3038 * Do NOT call PropVariantClear(&value) for fake value types. 3039 */ 3040 } 3041 } 3042 3043 IWICMetadataQueryReader_Release(reader); 3044 IWICComponentFactory_Release(factory); 3045 } 3046 3047 START_TEST(metadata) 3048 { 3049 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 3050 3051 test_queryreader(); 3052 test_WICMapGuidToShortName(); 3053 test_WICMapShortNameToGuid(); 3054 test_WICMapSchemaToName(); 3055 test_metadata_unknown(); 3056 test_metadata_tEXt(); 3057 test_metadata_gAMA(); 3058 test_metadata_cHRM(); 3059 test_metadata_IFD(); 3060 test_metadata_Exif(); 3061 test_create_reader(); 3062 test_metadata_png(); 3063 test_metadata_gif(); 3064 test_metadata_LSD(); 3065 test_metadata_IMD(); 3066 test_metadata_GCE(); 3067 test_metadata_APE(); 3068 test_metadata_GIF_comment(); 3069 3070 CoUninitialize(); 3071 } 3072