wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / windowscodecs / tests / info.c
blobbb8d3310bc9e297c6ead6faaa11e7a1bf0ef7059
1 /*
2 * Copyright 2009 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <math.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "objbase.h"
27 #include "wincodec.h"
28 #include "wincodecsdk.h"
29 #include "wine/test.h"
31 static HRESULT get_component_info(const GUID *clsid, IWICComponentInfo **result)
33 IWICImagingFactory *factory;
34 HRESULT hr;
36 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
37 &IID_IWICImagingFactory, (void**)&factory);
38 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
39 if (FAILED(hr)) return hr;
41 hr = IWICImagingFactory_CreateComponentInfo(factory, clsid, result);
43 IWICImagingFactory_Release(factory);
45 return hr;
48 static BOOL is_pixelformat(GUID *format)
50 IWICComponentInfo *info;
51 HRESULT hr;
52 WICComponentType componenttype;
54 hr = get_component_info(format, &info);
55 if (FAILED(hr))
56 return FALSE;
58 hr = IWICComponentInfo_GetComponentType(info, &componenttype);
60 IWICComponentInfo_Release(info);
62 return SUCCEEDED(hr) && componenttype == WICPixelFormat;
65 static void test_decoder_info(void)
67 struct decoder_info_test
69 const CLSID *clsid;
70 const char *mimetype;
71 const char *extensions;
72 unsigned int todo;
73 } decoder_info_tests[] =
76 &CLSID_WICBmpDecoder,
77 "image/bmp",
78 ".bmp,.dib,.rle"
81 &CLSID_WICGifDecoder,
82 "image/gif",
83 ".gif"
86 &CLSID_WICIcoDecoder,
87 "image/ico,image/x-icon",
88 ".ico,.icon",
92 &CLSID_WICJpegDecoder,
93 "image/jpeg,image/jpe,image/jpg",
94 ".jpeg,.jpe,.jpg,.jfif,.exif",
98 &CLSID_WICPngDecoder,
99 "image/png",
100 ".png"
103 &CLSID_WICTiffDecoder,
104 "image/tiff,image/tif",
105 ".tiff,.tif",
109 &CLSID_WICDdsDecoder,
110 "image/vnd.ms-dds",
111 ".dds",
114 IWICBitmapDecoderInfo *decoder_info, *decoder_info2;
115 IWICComponentInfo *info;
116 HRESULT hr;
117 ULONG len;
118 WCHAR value[256];
119 CLSID clsid;
120 GUID pixelformats[32];
121 UINT num_formats, count;
122 int i, j;
124 for (i = 0; i < ARRAY_SIZE(decoder_info_tests); i++)
126 struct decoder_info_test *test = &decoder_info_tests[i];
127 IWICBitmapDecoder *decoder, *decoder2;
128 WCHAR extensionsW[64];
129 WCHAR mimetypeW[64];
131 hr = CoCreateInstance(test->clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IWICBitmapDecoder, (void **)&decoder);
132 if (test->clsid == &CLSID_WICDdsDecoder && hr != S_OK) {
133 win_skip("DDS decoder is not supported\n");
134 continue;
136 ok(SUCCEEDED(hr), "Failed to create decoder, hr %#x.\n", hr);
138 decoder_info = NULL;
139 hr = IWICBitmapDecoder_GetDecoderInfo(decoder, &decoder_info);
140 ok(hr == S_OK || broken(IsEqualCLSID(&CLSID_WICBmpDecoder, test->clsid) && FAILED(hr)) /* Fails on Windows */,
141 "%u: failed to get decoder info, hr %#x.\n", i, hr);
143 if (hr == S_OK)
145 decoder_info2 = NULL;
146 hr = IWICBitmapDecoder_GetDecoderInfo(decoder, &decoder_info2);
147 ok(hr == S_OK, "Failed to get decoder info, hr %#x.\n", hr);
148 ok(decoder_info == decoder_info2, "Unexpected decoder info instance.\n");
150 hr = IWICBitmapDecoderInfo_QueryInterface(decoder_info, &IID_IWICBitmapDecoder, (void **)&decoder2);
151 ok(hr == E_NOINTERFACE, "Unexpected hr %#x.\n", hr);
153 IWICBitmapDecoderInfo_Release(decoder_info);
154 IWICBitmapDecoderInfo_Release(decoder_info2);
156 IWICBitmapDecoder_Release(decoder);
158 MultiByteToWideChar(CP_ACP, 0, test->mimetype, -1, mimetypeW, ARRAY_SIZE(mimetypeW));
159 MultiByteToWideChar(CP_ACP, 0, test->extensions, -1, extensionsW, ARRAY_SIZE(extensionsW));
161 hr = get_component_info(test->clsid, &info);
162 ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
164 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void **)&decoder_info);
165 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
167 hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, NULL);
168 ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
170 hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, &clsid);
171 ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
172 ok(IsEqualGUID(test->clsid, &clsid), "GetCLSID returned wrong result\n");
174 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, NULL);
175 ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
177 len = 0;
178 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, NULL, &len);
179 ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
180 todo_wine_if(test->todo)
181 ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
183 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, NULL);
184 ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
186 len = 0;
187 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, &len);
188 ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
189 todo_wine_if(test->todo)
190 ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
192 value[0] = 0;
193 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, &len);
194 ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
195 todo_wine_if(test->todo) {
196 ok(lstrcmpW(value, mimetypeW) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
197 ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
199 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, value, &len);
200 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetMimeType failed, hr=%x\n", hr);
201 todo_wine_if(test->todo)
202 ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
204 hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 256, value, &len);
205 ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
206 todo_wine_if(test->todo) {
207 ok(lstrcmpW(value, mimetypeW) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
208 ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
210 num_formats = 0xdeadbeef;
211 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, &num_formats);
212 ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
213 ok((num_formats <= 21 && num_formats >= 1) ||
214 broken(IsEqualCLSID(test->clsid, &CLSID_WICIcoDecoder) && num_formats == 0) /* WinXP */,
215 "%u: got %d formats\n", i, num_formats);
217 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, NULL);
218 ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr);
220 count = 0xdeadbeef;
221 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, pixelformats, &count);
222 ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
223 ok(count == 0, "got %d formats\n", count);
225 count = 0xdeadbeef;
226 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 1, pixelformats, &count);
227 ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
228 ok((count == 1) || broken(IsEqualCLSID(test->clsid, &CLSID_WICIcoDecoder) && count == 0) /* WinXP */,
229 "%u: got %d formats\n", i, num_formats);
230 ok(is_pixelformat(&pixelformats[0]), "got invalid pixel format\n");
232 count = 0xdeadbeef;
233 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, &count);
234 ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
235 ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats);
236 for (j = 0; j < num_formats; j++)
237 ok(is_pixelformat(&pixelformats[j]), "got invalid pixel format\n");
239 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, NULL);
240 ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr);
242 count = 0xdeadbeef;
243 hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, ARRAY_SIZE(pixelformats),
244 pixelformats, &count);
245 ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
246 ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats);
248 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 0, NULL, NULL);
249 ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
251 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 1, NULL, &len);
252 ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
253 todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
254 ok(len == lstrlenW(extensionsW) + 1, "%u: GetFileExtensions returned wrong len %i\n", i, len);
256 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, len, value, NULL);
257 ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
259 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 0, NULL, &len);
260 ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
261 todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
262 ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
264 value[0] = 0;
265 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, len, value, &len);
266 ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
267 todo_wine_if(test->todo)
268 ok(lstrcmpW(value, extensionsW) == 0, "GetFileExtensions returned wrong value %s\n", wine_dbgstr_w(value));
269 todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
270 ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
272 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 1, value, &len);
273 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetFileExtensions failed, hr=%x\n", hr);
274 todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
275 ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
277 hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 256, value, &len);
278 ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
279 todo_wine_if(test->todo)
280 ok(lstrcmpW(value, extensionsW) == 0, "GetFileExtensions returned wrong value %s\n", wine_dbgstr_w(value));
281 todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
282 ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
284 IWICBitmapDecoderInfo_Release(decoder_info);
285 IWICComponentInfo_Release(info);
289 static void test_pixelformat_info(void)
291 IWICComponentInfo *info;
292 IWICPixelFormatInfo *pixelformat_info;
293 IWICPixelFormatInfo2 *pixelformat_info2;
294 HRESULT hr;
295 ULONG len, known_len;
296 WCHAR value[256];
297 GUID guid;
298 WICComponentType componenttype;
299 WICPixelFormatNumericRepresentation numericrepresentation;
300 DWORD signing;
301 UINT uiresult;
302 BYTE abbuffer[256];
303 BOOL supportstransparency;
305 hr = get_component_info(&GUID_WICPixelFormat32bppBGRA, &info);
306 ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
308 if (FAILED(hr))
309 return;
311 hr = IWICComponentInfo_GetAuthor(info, 0, NULL, 0);
312 ok(hr == E_INVALIDARG, "GetAuthor failed, hr=%x\n", hr);
314 len = 0xdeadbeef;
315 hr = IWICComponentInfo_GetAuthor(info, 0, NULL, &len);
316 ok(hr == S_OK, "GetAuthor failed, hr=%x\n", hr);
317 ok(len < 255 && len > 0, "invalid length 0x%x\n", len);
318 known_len = len;
320 memset(value, 0xaa, 256 * sizeof(WCHAR));
321 hr = IWICComponentInfo_GetAuthor(info, len-1, value, NULL);
322 ok(hr == E_INVALIDARG, "GetAuthor failed, hr=%x\n", hr);
323 ok(value[0] == 0xaaaa, "string modified\n");
325 len = 0xdeadbeef;
326 memset(value, 0xaa, 256 * sizeof(WCHAR));
327 hr = IWICComponentInfo_GetAuthor(info, known_len-1, value, &len);
328 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetAuthor failed, hr=%x\n", hr);
329 ok(len == known_len, "got length of 0x%x, expected 0x%x\n", len, known_len);
330 ok(value[known_len-1] == 0xaaaa, "string modified past given length\n");
331 ok(value[0] == 0xaaaa, "string modified\n");
333 len = 0xdeadbeef;
334 memset(value, 0xaa, 256 * sizeof(WCHAR));
335 hr = IWICComponentInfo_GetAuthor(info, known_len, value, &len);
336 ok(hr == S_OK, "GetAuthor failed, hr=%x\n", hr);
337 ok(len == known_len, "got length of 0x%x, expected 0x%x\n", len, known_len);
338 ok(value[known_len-1] == 0, "string not terminated at expected length\n");
339 ok(value[known_len-2] != 0xaaaa, "string not modified at given length\n");
341 len = 0xdeadbeef;
342 memset(value, 0xaa, 256 * sizeof(WCHAR));
343 hr = IWICComponentInfo_GetAuthor(info, known_len+1, value, &len);
344 ok(hr == S_OK, "GetAuthor failed, hr=%x\n", hr);
345 ok(len == known_len, "got length of 0x%x, expected 0x%x\n", len, known_len);
346 ok(value[known_len] == 0xaaaa, "string modified past end\n");
347 ok(value[known_len-1] == 0, "string not terminated at expected length\n");
348 ok(value[known_len-2] != 0xaaaa, "string not modified at given length\n");
350 hr = IWICComponentInfo_GetCLSID(info, NULL);
351 ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
353 memset(&guid, 0xaa, sizeof(guid));
354 hr = IWICComponentInfo_GetCLSID(info, &guid);
355 ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
356 ok(IsEqualGUID(&guid, &GUID_WICPixelFormat32bppBGRA), "unexpected CLSID %s\n", wine_dbgstr_guid(&guid));
358 hr = IWICComponentInfo_GetComponentType(info, NULL);
359 ok(hr == E_INVALIDARG, "GetComponentType failed, hr=%x\n", hr);
361 hr = IWICComponentInfo_GetComponentType(info, &componenttype);
362 ok(hr == S_OK, "GetComponentType failed, hr=%x\n", hr);
363 ok(componenttype == WICPixelFormat, "unexpected component type 0x%x\n", componenttype);
365 len = 0xdeadbeef;
366 hr = IWICComponentInfo_GetFriendlyName(info, 0, NULL, &len);
367 ok(hr == S_OK, "GetFriendlyName failed, hr=%x\n", hr);
368 ok(len < 255 && len > 0, "invalid length 0x%x\n", len);
370 hr = IWICComponentInfo_GetSigningStatus(info, NULL);
371 ok(hr == E_INVALIDARG, "GetSigningStatus failed, hr=%x\n", hr);
373 hr = IWICComponentInfo_GetSigningStatus(info, &signing);
374 ok(hr == S_OK, "GetSigningStatus failed, hr=%x\n", hr);
375 ok(signing == WICComponentSigned, "unexpected signing status 0x%x\n", signing);
377 len = 0xdeadbeef;
378 hr = IWICComponentInfo_GetSpecVersion(info, 0, NULL, &len);
379 ok(hr == S_OK, "GetSpecVersion failed, hr=%x\n", hr);
380 ok(len == 0, "invalid length 0x%x\n", len); /* spec version does not apply to pixel formats */
382 memset(&guid, 0xaa, sizeof(guid));
383 hr = IWICComponentInfo_GetVendorGUID(info, &guid);
384 ok(hr == S_OK, "GetVendorGUID failed, hr=%x\n", hr);
385 ok(IsEqualGUID(&guid, &GUID_VendorMicrosoft) ||
386 broken(IsEqualGUID(&guid, &GUID_NULL)) /* XP */, "unexpected GUID %s\n", wine_dbgstr_guid(&guid));
388 len = 0xdeadbeef;
389 hr = IWICComponentInfo_GetVersion(info, 0, NULL, &len);
390 ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
391 ok(len == 0, "invalid length 0x%x\n", len); /* version does not apply to pixel formats */
393 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo, (void**)&pixelformat_info);
394 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
396 if (SUCCEEDED(hr))
398 hr = IWICPixelFormatInfo_GetBitsPerPixel(pixelformat_info, NULL);
399 ok(hr == E_INVALIDARG, "GetBitsPerPixel failed, hr=%x\n", hr);
401 hr = IWICPixelFormatInfo_GetBitsPerPixel(pixelformat_info, &uiresult);
402 ok(hr == S_OK, "GetBitsPerPixel failed, hr=%x\n", hr);
403 ok(uiresult == 32, "unexpected bpp %i\n", uiresult);
405 hr = IWICPixelFormatInfo_GetChannelCount(pixelformat_info, &uiresult);
406 ok(hr == S_OK, "GetChannelCount failed, hr=%x\n", hr);
407 ok(uiresult == 4, "unexpected channel count %i\n", uiresult);
409 hr = IWICPixelFormatInfo_GetChannelMask(pixelformat_info, 0, 0, NULL, NULL);
410 ok(hr == E_INVALIDARG, "GetChannelMask failed, hr=%x\n", hr);
412 uiresult = 0xdeadbeef;
413 hr = IWICPixelFormatInfo_GetChannelMask(pixelformat_info, 0, 0, NULL, &uiresult);
414 ok(hr == S_OK, "GetChannelMask failed, hr=%x\n", hr);
415 ok(uiresult == 4, "unexpected length %i\n", uiresult);
417 memset(abbuffer, 0xaa, sizeof(abbuffer));
418 hr = IWICPixelFormatInfo_GetChannelMask(pixelformat_info, 0, known_len, abbuffer, NULL);
419 ok(hr == E_INVALIDARG, "GetChannelMask failed, hr=%x\n", hr);
420 ok(abbuffer[0] == 0xaa, "buffer modified\n");
422 uiresult = 0xdeadbeef;
423 memset(abbuffer, 0xaa, sizeof(abbuffer));
424 hr = IWICPixelFormatInfo_GetChannelMask(pixelformat_info, 0, 3, abbuffer, &uiresult);
425 ok(hr == E_INVALIDARG, "GetChannelMask failed, hr=%x\n", hr);
426 ok(abbuffer[0] == 0xaa, "buffer modified\n");
427 ok(uiresult == 4, "unexpected length %i\n", uiresult);
429 memset(abbuffer, 0xaa, sizeof(abbuffer));
430 hr = IWICPixelFormatInfo_GetChannelMask(pixelformat_info, 0, 4, abbuffer, &uiresult);
431 ok(hr == S_OK, "GetChannelMask failed, hr=%x\n", hr);
432 ok(*((ULONG*)abbuffer) == 0xff, "unexpected mask 0x%x\n", *((ULONG*)abbuffer));
433 ok(uiresult == 4, "unexpected length %i\n", uiresult);
435 memset(abbuffer, 0xaa, sizeof(abbuffer));
436 hr = IWICPixelFormatInfo_GetChannelMask(pixelformat_info, 0, 5, abbuffer, &uiresult);
437 ok(hr == S_OK, "GetChannelMask failed, hr=%x\n", hr);
438 ok(*((ULONG*)abbuffer) == 0xff, "unexpected mask 0x%x\n", *((ULONG*)abbuffer));
439 ok(abbuffer[4] == 0xaa, "buffer modified past actual length\n");
440 ok(uiresult == 4, "unexpected length %i\n", uiresult);
442 memset(&guid, 0xaa, sizeof(guid));
443 hr = IWICPixelFormatInfo_GetFormatGUID(pixelformat_info, &guid);
444 ok(hr == S_OK, "GetFormatGUID failed, hr=%x\n", hr);
445 ok(IsEqualGUID(&guid, &GUID_WICPixelFormat32bppBGRA), "unexpected GUID %s\n", wine_dbgstr_guid(&guid));
447 IWICPixelFormatInfo_Release(pixelformat_info);
450 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo2, (void**)&pixelformat_info2);
452 if (FAILED(hr))
453 win_skip("IWICPixelFormatInfo2 not supported\n");
454 else
456 hr = IWICPixelFormatInfo2_GetNumericRepresentation(pixelformat_info2, NULL);
457 ok(hr == E_INVALIDARG, "GetNumericRepresentation failed, hr=%x\n", hr);
459 numericrepresentation = 0xdeadbeef;
460 hr = IWICPixelFormatInfo2_GetNumericRepresentation(pixelformat_info2, &numericrepresentation);
461 ok(hr == S_OK, "GetNumericRepresentation failed, hr=%x\n", hr);
462 ok(numericrepresentation == WICPixelFormatNumericRepresentationUnsignedInteger, "unexpected numeric representation %i\n", numericrepresentation);
464 hr = IWICPixelFormatInfo2_SupportsTransparency(pixelformat_info2, NULL);
465 ok(hr == E_INVALIDARG, "SupportsTransparency failed, hr=%x\n", hr);
467 supportstransparency = 0xdeadbeef;
468 hr = IWICPixelFormatInfo2_SupportsTransparency(pixelformat_info2, &supportstransparency);
469 ok(hr == S_OK, "SupportsTransparency failed, hr=%x\n", hr);
470 ok(supportstransparency == 1, "unexpected value %i\n", supportstransparency);
472 IWICPixelFormatInfo2_Release(pixelformat_info2);
475 IWICComponentInfo_Release(info);
478 static DWORD WINAPI cache_across_threads_test(void *arg)
480 IWICComponentInfo *info;
481 HRESULT hr;
483 CoInitialize(NULL);
485 hr = get_component_info(&CLSID_WICUnknownMetadataReader, &info);
486 ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
487 ok(info == arg, "unexpected info pointer %p\n", info);
488 IWICComponentInfo_Release(info);
490 CoUninitialize();
491 return 0;
494 static void test_reader_info(void)
496 IWICImagingFactory *factory;
497 IWICComponentInfo *info, *info2;
498 IWICMetadataReaderInfo *reader_info;
499 HRESULT hr;
500 CLSID clsid;
501 GUID container_formats[10];
502 UINT count, size, tid;
503 HANDLE thread;
504 WICMetadataPattern *patterns;
506 hr = get_component_info(&CLSID_WICUnknownMetadataReader, &info2);
507 ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
508 IWICComponentInfo_Release(info2);
510 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
511 &IID_IWICImagingFactory, (void**)&factory);
512 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
513 if (FAILED(hr)) return;
515 hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICUnknownMetadataReader, &info);
516 ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
517 ok(info == info2, "info != info2\n");
519 thread = CreateThread(NULL, 0, cache_across_threads_test, info, 0, &tid);
520 WaitForSingleObject(thread, INFINITE);
521 CloseHandle(thread);
523 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICMetadataReaderInfo, (void**)&reader_info);
524 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
526 hr = IWICMetadataReaderInfo_GetCLSID(reader_info, NULL);
527 ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
529 hr = IWICMetadataReaderInfo_GetCLSID(reader_info, &clsid);
530 ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
531 ok(IsEqualGUID(&CLSID_WICUnknownMetadataReader, &clsid), "GetCLSID returned wrong result\n");
533 hr = IWICMetadataReaderInfo_GetMetadataFormat(reader_info, &clsid);
534 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
535 ok(IsEqualGUID(&GUID_MetadataFormatUnknown, &clsid), "GetMetadataFormat returned wrong result\n");
537 hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, NULL);
538 ok(hr == E_INVALIDARG, "GetContainerFormats failed, hr=%x\n", hr);
540 count = 0xdeadbeef;
541 hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, &count);
542 ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
543 ok(count == 0, "unexpected count %d\n", count);
545 hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_ContainerFormatPng,
546 0, NULL, NULL, NULL);
547 ok(hr == E_INVALIDARG, "GetPatterns failed, hr=%x\n", hr);
549 count = size = 0xdeadbeef;
550 hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_ContainerFormatPng,
551 0, NULL, &count, &size);
552 ok(hr == WINCODEC_ERR_COMPONENTNOTFOUND || broken(hr == S_OK) /* Windows XP */,
553 "GetPatterns failed, hr=%x\n", hr);
554 ok(count == 0xdeadbeef, "unexpected count %d\n", count);
555 ok(size == 0xdeadbeef, "unexpected size %d\n", size);
557 IWICMetadataReaderInfo_Release(reader_info);
559 IWICComponentInfo_Release(info);
561 hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICXMPStructMetadataReader, &info);
562 todo_wine
563 ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
565 if (FAILED(hr))
567 IWICImagingFactory_Release(factory);
568 return;
571 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICMetadataReaderInfo, (void**)&reader_info);
572 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
574 hr = IWICMetadataReaderInfo_GetCLSID(reader_info, NULL);
575 ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
577 hr = IWICMetadataReaderInfo_GetCLSID(reader_info, &clsid);
578 ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
579 ok(IsEqualGUID(&CLSID_WICXMPStructMetadataReader, &clsid), "GetCLSID returned wrong result\n");
581 hr = IWICMetadataReaderInfo_GetMetadataFormat(reader_info, &clsid);
582 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
583 ok(IsEqualGUID(&GUID_MetadataFormatXMPStruct, &clsid), "GetMetadataFormat returned wrong result\n");
585 hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, NULL);
586 ok(hr == E_INVALIDARG, "GetContainerFormats failed, hr=%x\n", hr);
588 count = 0xdeadbeef;
589 hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, &count);
590 ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
591 ok(count >= 2, "unexpected count %d\n", count);
593 count = 0xdeadbeef;
594 hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 1, container_formats, &count);
595 ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
596 ok(count == 1, "unexpected count %d\n", count);
598 count = 0xdeadbeef;
599 hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 10, container_formats, &count);
600 ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
601 ok(count == min(count, 10), "unexpected count %d\n", count);
603 count = size = 0xdeadbeef;
604 hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_ContainerFormatPng,
605 0, NULL, &count, &size);
606 ok(hr == WINCODEC_ERR_COMPONENTNOTFOUND || broken(hr == S_OK) /* Windows XP */,
607 "GetPatterns failed, hr=%x\n", hr);
608 ok(count == 0xdeadbeef, "unexpected count %d\n", count);
609 ok(size == 0xdeadbeef, "unexpected size %d\n", size);
611 count = size = 0xdeadbeef;
612 hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_MetadataFormatXMP,
613 0, NULL, &count, &size);
614 ok(hr == S_OK, "GetPatterns failed, hr=%x\n", hr);
615 ok(count == 1, "unexpected count %d\n", count);
616 ok(size > sizeof(WICMetadataPattern), "unexpected size %d\n", size);
618 if (hr == S_OK)
620 patterns = HeapAlloc(GetProcessHeap(), 0, size);
622 count = size = 0xdeadbeef;
623 hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_MetadataFormatXMP,
624 size-1, patterns, &count, &size);
625 ok(hr == S_OK, "GetPatterns failed, hr=%x\n", hr);
626 ok(count == 1, "unexpected count %d\n", count);
627 ok(size > sizeof(WICMetadataPattern), "unexpected size %d\n", size);
629 count = size = 0xdeadbeef;
630 hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_MetadataFormatXMP,
631 size, patterns, &count, &size);
632 ok(hr == S_OK, "GetPatterns failed, hr=%x\n", hr);
633 ok(count == 1, "unexpected count %d\n", count);
634 ok(size == sizeof(WICMetadataPattern) + patterns->Length * 2, "unexpected size %d\n", size);
636 HeapFree(GetProcessHeap(), 0, patterns);
639 IWICMetadataReaderInfo_Release(reader_info);
641 IWICComponentInfo_Release(info);
643 IWICImagingFactory_Release(factory);
646 static void test_imagingfactory_interfaces(void)
648 IWICComponentFactory *component_factory;
649 IWICImagingFactory2 *factory2;
650 IWICImagingFactory *factory;
651 HRESULT hr;
653 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
654 &IID_IWICImagingFactory2, (void **)&factory2);
655 if (FAILED(hr))
657 win_skip("IWICImagingFactory2 is not supported.\n");
658 return;
661 hr = IWICImagingFactory2_QueryInterface(factory2, &IID_IWICComponentFactory, (void **)&component_factory);
662 ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
664 hr = IWICComponentFactory_QueryInterface(component_factory, &IID_IWICImagingFactory, (void **)&factory);
665 ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
666 ok(factory == (IWICImagingFactory *)component_factory, "Unexpected factory pointer.\n");
667 IWICImagingFactory_Release(factory);
669 hr = IWICImagingFactory2_QueryInterface(factory2, &IID_IWICImagingFactory, (void **)&factory);
670 ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
671 ok(factory == (IWICImagingFactory *)component_factory, "Unexpected factory pointer.\n");
673 IWICComponentFactory_Release(component_factory);
674 IWICImagingFactory2_Release(factory2);
675 IWICImagingFactory_Release(factory);
678 START_TEST(info)
680 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
682 test_decoder_info();
683 test_reader_info();
684 test_pixelformat_info();
685 test_imagingfactory_interfaces();
687 CoUninitialize();