d3drm: Handle texture associated with the material when loading a mesh.
[wine] / dlls / windowscodecs / tests / info.c
1 /*
2  * Copyright 2009 Vincent Povirk for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20 #include <math.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "objbase.h"
26 #include "wincodec.h"
27 #include "wincodecsdk.h"
28 #include "wine/test.h"
29
30 static void test_decoder_info(void)
31 {
32     IWICImagingFactory *factory;
33     IWICComponentInfo *info;
34     IWICBitmapDecoderInfo *decoder_info;
35     HRESULT hr;
36     ULONG len;
37     WCHAR value[256];
38     const WCHAR expected_mimetype[] = {'i','m','a','g','e','/','b','m','p',0};
39     CLSID clsid;
40
41     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
42         &IID_IWICImagingFactory, (void**)&factory);
43     ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
44     if (FAILED(hr)) return;
45
46     hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
47     ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
48
49     hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoder_info);
50     ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
51
52     hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, NULL);
53     ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
54
55     hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, &clsid);
56     ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
57     ok(IsEqualGUID(&CLSID_WICBmpDecoder, &clsid), "GetCLSID returned wrong result\n");
58
59     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, NULL);
60     ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
61
62     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, NULL, &len);
63     ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
64     ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
65
66     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, NULL);
67     ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
68
69     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, &len);
70     ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
71     ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
72
73     value[0] = 0;
74     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, &len);
75     ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
76     ok(lstrcmpW(value, expected_mimetype) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
77     ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
78
79     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, value, &len);
80     ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetMimeType failed, hr=%x\n", hr);
81     ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
82
83     hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 256, value, &len);
84     ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
85     ok(lstrcmpW(value, expected_mimetype) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
86     ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
87
88     IWICBitmapDecoderInfo_Release(decoder_info);
89
90     IWICComponentInfo_Release(info);
91
92     IWICImagingFactory_Release(factory);
93 }
94
95 static void test_reader_info(void)
96 {
97     IWICImagingFactory *factory;
98     IWICComponentInfo *info;
99     IWICMetadataReaderInfo *reader_info;
100     HRESULT hr;
101     CLSID clsid;
102     GUID container_formats[10];
103     UINT count, size;
104     WICMetadataPattern *patterns;
105
106     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
107         &IID_IWICImagingFactory, (void**)&factory);
108     ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
109     if (FAILED(hr)) return;
110
111     hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICUnknownMetadataReader, &info);
112     todo_wine ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
113
114     if (FAILED(hr))
115     {
116         IWICImagingFactory_Release(factory);
117         return;
118     }
119
120     hr = IWICComponentInfo_QueryInterface(info, &IID_IWICMetadataReaderInfo, (void**)&reader_info);
121     ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
122
123     hr = IWICMetadataReaderInfo_GetCLSID(reader_info, NULL);
124     ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
125
126     hr = IWICMetadataReaderInfo_GetCLSID(reader_info, &clsid);
127     ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
128     ok(IsEqualGUID(&CLSID_WICUnknownMetadataReader, &clsid), "GetCLSID returned wrong result\n");
129
130     hr = IWICMetadataReaderInfo_GetMetadataFormat(reader_info, &clsid);
131     ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
132     ok(IsEqualGUID(&GUID_MetadataFormatUnknown, &clsid), "GetMetadataFormat returned wrong result\n");
133
134     hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, NULL);
135     ok(hr == E_INVALIDARG, "GetContainerFormats failed, hr=%x\n", hr);
136
137     count = 0xdeadbeef;
138     hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, &count);
139     ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
140     ok(count == 0, "unexpected count %d\n", count);
141
142     hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_ContainerFormatPng,
143         0, NULL, NULL, NULL);
144     ok(hr == E_INVALIDARG, "GetPatterns failed, hr=%x\n", hr);
145
146     count = size = 0xdeadbeef;
147     hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_ContainerFormatPng,
148         0, NULL, &count, &size);
149     ok(hr == WINCODEC_ERR_COMPONENTNOTFOUND || broken(hr == S_OK) /* Windows XP */,
150         "GetPatterns failed, hr=%x\n", hr);
151     ok(count == 0xdeadbeef, "unexpected count %d\n", count);
152     ok(size == 0xdeadbeef, "unexpected size %d\n", size);
153
154     IWICMetadataReaderInfo_Release(reader_info);
155
156     IWICComponentInfo_Release(info);
157
158     hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICXMBStructMetadataReader, &info);
159     ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
160
161     hr = IWICComponentInfo_QueryInterface(info, &IID_IWICMetadataReaderInfo, (void**)&reader_info);
162     ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
163
164     hr = IWICMetadataReaderInfo_GetCLSID(reader_info, NULL);
165     ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
166
167     hr = IWICMetadataReaderInfo_GetCLSID(reader_info, &clsid);
168     ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
169     ok(IsEqualGUID(&CLSID_WICXMBStructMetadataReader, &clsid), "GetCLSID returned wrong result\n");
170
171     hr = IWICMetadataReaderInfo_GetMetadataFormat(reader_info, &clsid);
172     ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
173     ok(IsEqualGUID(&GUID_MetadataFormatXMPStruct, &clsid), "GetMetadataFormat returned wrong result\n");
174
175     hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, NULL);
176     ok(hr == E_INVALIDARG, "GetContainerFormats failed, hr=%x\n", hr);
177
178     count = 0xdeadbeef;
179     hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 0, NULL, &count);
180     ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
181     ok(count >= 2, "unexpected count %d\n", count);
182
183     count = 0xdeadbeef;
184     hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 1, container_formats, &count);
185     ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
186     ok(count == 1, "unexpected count %d\n", count);
187
188     count = 0xdeadbeef;
189     hr = IWICMetadataReaderInfo_GetContainerFormats(reader_info, 10, container_formats, &count);
190     ok(hr == S_OK, "GetContainerFormats failed, hr=%x\n", hr);
191     ok(count == min(count, 10), "unexpected count %d\n", count);
192
193     count = size = 0xdeadbeef;
194     hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_ContainerFormatPng,
195         0, NULL, &count, &size);
196     ok(hr == WINCODEC_ERR_COMPONENTNOTFOUND || broken(hr == S_OK) /* Windows XP */,
197         "GetPatterns failed, hr=%x\n", hr);
198     ok(count == 0xdeadbeef, "unexpected count %d\n", count);
199     ok(size == 0xdeadbeef, "unexpected size %d\n", size);
200
201     count = size = 0xdeadbeef;
202     hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_MetadataFormatXMP,
203         0, NULL, &count, &size);
204     ok(hr == S_OK, "GetPatterns failed, hr=%x\n", hr);
205     ok(count == 1, "unexpected count %d\n", count);
206     ok(size > sizeof(WICMetadataPattern), "unexpected size %d\n", size);
207
208     if (hr == S_OK)
209     {
210         patterns = HeapAlloc(GetProcessHeap(), 0, size);
211
212         count = size = 0xdeadbeef;
213         hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_MetadataFormatXMP,
214             size-1, patterns, &count, &size);
215         ok(hr == S_OK, "GetPatterns failed, hr=%x\n", hr);
216         ok(count == 1, "unexpected count %d\n", count);
217         ok(size > sizeof(WICMetadataPattern), "unexpected size %d\n", size);
218
219         count = size = 0xdeadbeef;
220         hr = IWICMetadataReaderInfo_GetPatterns(reader_info, &GUID_MetadataFormatXMP,
221             size, patterns, &count, &size);
222         ok(hr == S_OK, "GetPatterns failed, hr=%x\n", hr);
223         ok(count == 1, "unexpected count %d\n", count);
224         ok(size == sizeof(WICMetadataPattern) + patterns->Length * 2, "unexpected size %d\n", size);
225
226         HeapFree(GetProcessHeap(), 0, patterns);
227     }
228
229     IWICMetadataReaderInfo_Release(reader_info);
230
231     IWICComponentInfo_Release(info);
232
233     IWICImagingFactory_Release(factory);
234 }
235
236 START_TEST(info)
237 {
238     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
239
240     test_decoder_info();
241     test_reader_info();
242
243     CoUninitialize();
244 }