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
28 #include "wincodecsdk.h"
29 #include "wine/test.h"
32 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
34 static const char *debugstr_guid(GUID
*guid
)
41 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
42 guid
->Data1
, guid
->Data2
, guid
->Data3
, guid
->Data4
[0],
43 guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3], guid
->Data4
[4],
44 guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
49 static HRESULT
get_component_info(const GUID
*clsid
, IWICComponentInfo
**result
)
51 IWICImagingFactory
*factory
;
54 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
55 &IID_IWICImagingFactory
, (void**)&factory
);
56 ok(hr
== S_OK
, "CoCreateInstance failed, hr=%x\n", hr
);
57 if (FAILED(hr
)) return hr
;
59 hr
= IWICImagingFactory_CreateComponentInfo(factory
, clsid
, result
);
61 IWICImagingFactory_Release(factory
);
66 static void test_decoder_info(void)
68 IWICComponentInfo
*info
;
69 IWICBitmapDecoderInfo
*decoder_info
;
73 const WCHAR expected_mimetype
[] = {'i','m','a','g','e','/','b','m','p',0};
76 hr
= get_component_info(&CLSID_WICBmpDecoder
, &info
);
78 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICBitmapDecoderInfo
, (void**)&decoder_info
);
79 ok(hr
== S_OK
, "QueryInterface failed, hr=%x\n", hr
);
81 hr
= IWICBitmapDecoderInfo_GetCLSID(decoder_info
, NULL
);
82 ok(hr
== E_INVALIDARG
, "GetCLSID failed, hr=%x\n", hr
);
84 hr
= IWICBitmapDecoderInfo_GetCLSID(decoder_info
, &clsid
);
85 ok(hr
== S_OK
, "GetCLSID failed, hr=%x\n", hr
);
86 ok(IsEqualGUID(&CLSID_WICBmpDecoder
, &clsid
), "GetCLSID returned wrong result\n");
88 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, 0, NULL
, NULL
);
89 ok(hr
== E_INVALIDARG
, "GetMimeType failed, hr=%x\n", hr
);
91 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, 1, NULL
, &len
);
92 ok(hr
== E_INVALIDARG
, "GetMimeType failed, hr=%x\n", hr
);
93 ok(len
== lstrlenW(expected_mimetype
)+1, "GetMimeType returned wrong len %i\n", len
);
95 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, len
, value
, NULL
);
96 ok(hr
== E_INVALIDARG
, "GetMimeType failed, hr=%x\n", hr
);
98 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, 0, NULL
, &len
);
99 ok(hr
== S_OK
, "GetMimeType failed, hr=%x\n", hr
);
100 ok(len
== lstrlenW(expected_mimetype
)+1, "GetMimeType returned wrong len %i\n", len
);
103 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, len
, value
, &len
);
104 ok(hr
== S_OK
, "GetMimeType failed, hr=%x\n", hr
);
105 ok(lstrcmpW(value
, expected_mimetype
) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value
));
106 ok(len
== lstrlenW(expected_mimetype
)+1, "GetMimeType returned wrong len %i\n", len
);
108 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, 1, value
, &len
);
109 ok(hr
== WINCODEC_ERR_INSUFFICIENTBUFFER
, "GetMimeType failed, hr=%x\n", hr
);
110 ok(len
== lstrlenW(expected_mimetype
)+1, "GetMimeType returned wrong len %i\n", len
);
112 hr
= IWICBitmapDecoderInfo_GetMimeTypes(decoder_info
, 256, value
, &len
);
113 ok(hr
== S_OK
, "GetMimeType failed, hr=%x\n", hr
);
114 ok(lstrcmpW(value
, expected_mimetype
) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value
));
115 ok(len
== lstrlenW(expected_mimetype
)+1, "GetMimeType returned wrong len %i\n", len
);
117 IWICBitmapDecoderInfo_Release(decoder_info
);
119 IWICComponentInfo_Release(info
);
122 static void test_pixelformat_info(void)
124 IWICComponentInfo
*info
;
126 ULONG len
, known_len
;
129 WICComponentType componenttype
;
132 hr
= get_component_info(&GUID_WICPixelFormat32bppBGRA
, &info
);
133 ok(hr
== S_OK
, "CreateComponentInfo failed, hr=%x\n", hr
);
138 hr
= IWICComponentInfo_GetAuthor(info
, 0, NULL
, 0);
139 ok(hr
== E_INVALIDARG
, "GetAuthor failed, hr=%x\n", hr
);
142 hr
= IWICComponentInfo_GetAuthor(info
, 0, NULL
, &len
);
143 ok(hr
== S_OK
, "GetAuthor failed, hr=%x\n", hr
);
144 ok(len
< 255 && len
> 0, "invalid length 0x%x\n", len
);
147 memset(value
, 0xaa, 256 * sizeof(WCHAR
));
148 hr
= IWICComponentInfo_GetAuthor(info
, len
-1, value
, NULL
);
149 ok(hr
== E_INVALIDARG
, "GetAuthor failed, hr=%x\n", hr
);
150 ok(value
[0] = 0xaaaa, "string modified\n");
153 memset(value
, 0xaa, 256 * sizeof(WCHAR
));
154 hr
= IWICComponentInfo_GetAuthor(info
, known_len
-1, value
, &len
);
155 ok(hr
== WINCODEC_ERR_INSUFFICIENTBUFFER
, "GetAuthor failed, hr=%x\n", hr
);
156 ok(len
== known_len
, "got length of 0x%x, expected 0x%x\n", len
, known_len
);
157 ok(value
[known_len
-1] == 0xaaaa, "string modified past given length\n");
158 ok(value
[0] == 0xaaaa, "string modified\n");
161 memset(value
, 0xaa, 256 * sizeof(WCHAR
));
162 hr
= IWICComponentInfo_GetAuthor(info
, known_len
, value
, &len
);
163 ok(hr
== S_OK
, "GetAuthor failed, hr=%x\n", hr
);
164 ok(len
== known_len
, "got length of 0x%x, expected 0x%x\n", len
, known_len
);
165 ok(value
[known_len
-1] == 0, "string not terminated at expected length\n");
166 ok(value
[known_len
-2] != 0xaaaa, "string not modified at given length\n");
169 memset(value
, 0xaa, 256 * sizeof(WCHAR
));
170 hr
= IWICComponentInfo_GetAuthor(info
, known_len
+1, value
, &len
);
171 ok(hr
== S_OK
, "GetAuthor failed, hr=%x\n", hr
);
172 ok(len
== known_len
, "got length of 0x%x, expected 0x%x\n", len
, known_len
);
173 ok(value
[known_len
] == 0xaaaa, "string modified past end\n");
174 ok(value
[known_len
-1] == 0, "string not terminated at expected length\n");
175 ok(value
[known_len
-2] != 0xaaaa, "string not modified at given length\n");
177 hr
= IWICComponentInfo_GetCLSID(info
, NULL
);
178 ok(hr
== E_INVALIDARG
, "GetCLSID failed, hr=%x\n", hr
);
180 memset(&guid
, 0xaa, sizeof(guid
));
181 hr
= IWICComponentInfo_GetCLSID(info
, &guid
);
182 ok(hr
== S_OK
, "GetCLSID failed, hr=%x\n", hr
);
183 ok(IsEqualGUID(&guid
, &GUID_WICPixelFormat32bppBGRA
), "unexpected CLSID %s\n", debugstr_guid(&guid
));
185 hr
= IWICComponentInfo_GetComponentType(info
, NULL
);
186 ok(hr
== E_INVALIDARG
, "GetComponentType failed, hr=%x\n", hr
);
188 hr
= IWICComponentInfo_GetComponentType(info
, &componenttype
);
189 ok(hr
== S_OK
, "GetComponentType failed, hr=%x\n", hr
);
190 ok(componenttype
== WICPixelFormat
, "unexpected component type 0x%x\n", componenttype
);
193 hr
= IWICComponentInfo_GetFriendlyName(info
, 0, NULL
, &len
);
194 ok(hr
== S_OK
, "GetFriendlyName failed, hr=%x\n", hr
);
195 ok(len
< 255 && len
> 0, "invalid length 0x%x\n", len
);
197 hr
= IWICComponentInfo_GetSigningStatus(info
, NULL
);
198 ok(hr
== E_INVALIDARG
, "GetSigningStatus failed, hr=%x\n", hr
);
200 hr
= IWICComponentInfo_GetSigningStatus(info
, &signing
);
201 ok(hr
== S_OK
, "GetSigningStatus failed, hr=%x\n", hr
);
202 ok(signing
== WICComponentSigned
, "unexpected signing status 0x%x\n", signing
);
205 hr
= IWICComponentInfo_GetSpecVersion(info
, 0, NULL
, &len
);
206 todo_wine
ok(hr
== S_OK
, "GetSpecVersion failed, hr=%x\n", hr
);
207 todo_wine
ok(len
== 0, "invalid length 0x%x\n", len
); /* spec version does not apply to pixel formats */
209 memset(&guid
, 0xaa, sizeof(guid
));
210 hr
= IWICComponentInfo_GetVendorGUID(info
, &guid
);
211 ok(hr
== S_OK
, "GetVendorGUID failed, hr=%x\n", hr
);
212 ok(IsEqualGUID(&guid
, &GUID_VendorMicrosoft
) ||
213 broken(IsEqualGUID(&guid
, &GUID_NULL
)) /* XP */, "unexpected GUID %s\n", debugstr_guid(&guid
));
216 hr
= IWICComponentInfo_GetVersion(info
, 0, NULL
, &len
);
217 ok(hr
== S_OK
, "GetVersion failed, hr=%x\n", hr
);
218 ok(len
== 0, "invalid length 0x%x\n", len
); /* version does not apply to pixel formats */
220 IWICComponentInfo_Release(info
);
223 static void test_reader_info(void)
225 IWICImagingFactory
*factory
;
226 IWICComponentInfo
*info
;
227 IWICMetadataReaderInfo
*reader_info
;
230 GUID container_formats
[10];
232 WICMetadataPattern
*patterns
;
234 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
235 &IID_IWICImagingFactory
, (void**)&factory
);
236 ok(hr
== S_OK
, "CoCreateInstance failed, hr=%x\n", hr
);
237 if (FAILED(hr
)) return;
239 hr
= IWICImagingFactory_CreateComponentInfo(factory
, &CLSID_WICUnknownMetadataReader
, &info
);
240 ok(hr
== S_OK
, "CreateComponentInfo failed, hr=%x\n", hr
);
242 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICMetadataReaderInfo
, (void**)&reader_info
);
243 ok(hr
== S_OK
, "QueryInterface failed, hr=%x\n", hr
);
245 hr
= IWICMetadataReaderInfo_GetCLSID(reader_info
, NULL
);
246 ok(hr
== E_INVALIDARG
, "GetCLSID failed, hr=%x\n", hr
);
248 hr
= IWICMetadataReaderInfo_GetCLSID(reader_info
, &clsid
);
249 ok(hr
== S_OK
, "GetCLSID failed, hr=%x\n", hr
);
250 ok(IsEqualGUID(&CLSID_WICUnknownMetadataReader
, &clsid
), "GetCLSID returned wrong result\n");
252 hr
= IWICMetadataReaderInfo_GetMetadataFormat(reader_info
, &clsid
);
253 ok(hr
== S_OK
, "GetMetadataFormat failed, hr=%x\n", hr
);
254 ok(IsEqualGUID(&GUID_MetadataFormatUnknown
, &clsid
), "GetMetadataFormat returned wrong result\n");
256 hr
= IWICMetadataReaderInfo_GetContainerFormats(reader_info
, 0, NULL
, NULL
);
257 ok(hr
== E_INVALIDARG
, "GetContainerFormats failed, hr=%x\n", hr
);
260 hr
= IWICMetadataReaderInfo_GetContainerFormats(reader_info
, 0, NULL
, &count
);
262 ok(hr
== S_OK
, "GetContainerFormats failed, hr=%x\n", hr
);
264 ok(count
== 0, "unexpected count %d\n", count
);
266 hr
= IWICMetadataReaderInfo_GetPatterns(reader_info
, &GUID_ContainerFormatPng
,
267 0, NULL
, NULL
, NULL
);
268 ok(hr
== E_INVALIDARG
, "GetPatterns failed, hr=%x\n", hr
);
270 count
= size
= 0xdeadbeef;
271 hr
= IWICMetadataReaderInfo_GetPatterns(reader_info
, &GUID_ContainerFormatPng
,
272 0, NULL
, &count
, &size
);
274 ok(hr
== WINCODEC_ERR_COMPONENTNOTFOUND
|| broken(hr
== S_OK
) /* Windows XP */,
275 "GetPatterns failed, hr=%x\n", hr
);
276 ok(count
== 0xdeadbeef, "unexpected count %d\n", count
);
277 ok(size
== 0xdeadbeef, "unexpected size %d\n", size
);
279 IWICMetadataReaderInfo_Release(reader_info
);
281 IWICComponentInfo_Release(info
);
283 hr
= IWICImagingFactory_CreateComponentInfo(factory
, &CLSID_WICXMBStructMetadataReader
, &info
);
285 ok(hr
== S_OK
, "CreateComponentInfo failed, hr=%x\n", hr
);
289 IWICImagingFactory_Release(factory
);
293 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICMetadataReaderInfo
, (void**)&reader_info
);
294 ok(hr
== S_OK
, "QueryInterface failed, hr=%x\n", hr
);
296 hr
= IWICMetadataReaderInfo_GetCLSID(reader_info
, NULL
);
297 ok(hr
== E_INVALIDARG
, "GetCLSID failed, hr=%x\n", hr
);
299 hr
= IWICMetadataReaderInfo_GetCLSID(reader_info
, &clsid
);
300 ok(hr
== S_OK
, "GetCLSID failed, hr=%x\n", hr
);
301 ok(IsEqualGUID(&CLSID_WICXMBStructMetadataReader
, &clsid
), "GetCLSID returned wrong result\n");
303 hr
= IWICMetadataReaderInfo_GetMetadataFormat(reader_info
, &clsid
);
304 ok(hr
== S_OK
, "GetMetadataFormat failed, hr=%x\n", hr
);
305 ok(IsEqualGUID(&GUID_MetadataFormatXMPStruct
, &clsid
), "GetMetadataFormat returned wrong result\n");
307 hr
= IWICMetadataReaderInfo_GetContainerFormats(reader_info
, 0, NULL
, NULL
);
308 ok(hr
== E_INVALIDARG
, "GetContainerFormats failed, hr=%x\n", hr
);
311 hr
= IWICMetadataReaderInfo_GetContainerFormats(reader_info
, 0, NULL
, &count
);
312 ok(hr
== S_OK
, "GetContainerFormats failed, hr=%x\n", hr
);
313 ok(count
>= 2, "unexpected count %d\n", count
);
316 hr
= IWICMetadataReaderInfo_GetContainerFormats(reader_info
, 1, container_formats
, &count
);
317 ok(hr
== S_OK
, "GetContainerFormats failed, hr=%x\n", hr
);
318 ok(count
== 1, "unexpected count %d\n", count
);
321 hr
= IWICMetadataReaderInfo_GetContainerFormats(reader_info
, 10, container_formats
, &count
);
322 ok(hr
== S_OK
, "GetContainerFormats failed, hr=%x\n", hr
);
323 ok(count
== min(count
, 10), "unexpected count %d\n", count
);
325 count
= size
= 0xdeadbeef;
326 hr
= IWICMetadataReaderInfo_GetPatterns(reader_info
, &GUID_ContainerFormatPng
,
327 0, NULL
, &count
, &size
);
328 ok(hr
== WINCODEC_ERR_COMPONENTNOTFOUND
|| broken(hr
== S_OK
) /* Windows XP */,
329 "GetPatterns failed, hr=%x\n", hr
);
330 ok(count
== 0xdeadbeef, "unexpected count %d\n", count
);
331 ok(size
== 0xdeadbeef, "unexpected size %d\n", size
);
333 count
= size
= 0xdeadbeef;
334 hr
= IWICMetadataReaderInfo_GetPatterns(reader_info
, &GUID_MetadataFormatXMP
,
335 0, NULL
, &count
, &size
);
336 ok(hr
== S_OK
, "GetPatterns failed, hr=%x\n", hr
);
337 ok(count
== 1, "unexpected count %d\n", count
);
338 ok(size
> sizeof(WICMetadataPattern
), "unexpected size %d\n", size
);
342 patterns
= HeapAlloc(GetProcessHeap(), 0, size
);
344 count
= size
= 0xdeadbeef;
345 hr
= IWICMetadataReaderInfo_GetPatterns(reader_info
, &GUID_MetadataFormatXMP
,
346 size
-1, patterns
, &count
, &size
);
347 ok(hr
== S_OK
, "GetPatterns failed, hr=%x\n", hr
);
348 ok(count
== 1, "unexpected count %d\n", count
);
349 ok(size
> sizeof(WICMetadataPattern
), "unexpected size %d\n", size
);
351 count
= size
= 0xdeadbeef;
352 hr
= IWICMetadataReaderInfo_GetPatterns(reader_info
, &GUID_MetadataFormatXMP
,
353 size
, patterns
, &count
, &size
);
354 ok(hr
== S_OK
, "GetPatterns failed, hr=%x\n", hr
);
355 ok(count
== 1, "unexpected count %d\n", count
);
356 ok(size
== sizeof(WICMetadataPattern
) + patterns
->Length
* 2, "unexpected size %d\n", size
);
358 HeapFree(GetProcessHeap(), 0, patterns
);
361 IWICMetadataReaderInfo_Release(reader_info
);
363 IWICComponentInfo_Release(info
);
365 IWICImagingFactory_Release(factory
);
370 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
374 test_pixelformat_info();