msxml3: Properly escape character data in text nodes.
[wine/multimedia.git] / dlls / qedit / tests / mediadet.c
blob1d9a2f108ef0d7c9964acf9ca817cdf078dad0e2
1 /*
2 * Unit tests for Media Detector
4 * Copyright (C) 2008 Google (Lei Zhang, Dan Hipschman)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include "initguid.h"
25 #include "ole2.h"
26 #include "vfwmsgs.h"
27 #include "uuids.h"
28 #include "wine/test.h"
29 #include "qedit.h"
30 #include "rc.h"
32 /* Outer IUnknown for COM aggregation tests */
33 struct unk_impl {
34 IUnknown IUnknown_iface;
35 LONG ref;
36 IUnknown *inner_unk;
39 static inline struct unk_impl *impl_from_IUnknown(IUnknown *iface)
41 return CONTAINING_RECORD(iface, struct unk_impl, IUnknown_iface);
44 static HRESULT WINAPI unk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
46 struct unk_impl *This = impl_from_IUnknown(iface);
48 return IUnknown_QueryInterface(This->inner_unk, riid, ppv);
51 static ULONG WINAPI unk_AddRef(IUnknown *iface)
53 struct unk_impl *This = impl_from_IUnknown(iface);
55 return InterlockedIncrement(&This->ref);
58 static ULONG WINAPI unk_Release(IUnknown *iface)
60 struct unk_impl *This = impl_from_IUnknown(iface);
62 return InterlockedDecrement(&This->ref);
65 static const IUnknownVtbl unk_vtbl =
67 unk_QueryInterface,
68 unk_AddRef,
69 unk_Release
73 static WCHAR test_avi_filename[MAX_PATH];
74 static WCHAR test_sound_avi_filename[MAX_PATH];
76 static BOOL unpack_avi_file(int id, WCHAR name[MAX_PATH])
78 static WCHAR temp_path[MAX_PATH];
79 static WCHAR prefix[] = {'D','E','S',0};
80 static WCHAR avi[] = {'a','v','i',0};
81 HRSRC res;
82 HGLOBAL data;
83 char *mem;
84 DWORD size, written;
85 HANDLE fh;
87 res = FindResource(NULL, MAKEINTRESOURCE(id), MAKEINTRESOURCE(AVI_RES_TYPE));
88 if (!res)
89 return FALSE;
91 data = LoadResource(NULL, res);
92 if (!data)
93 return FALSE;
95 mem = LockResource(data);
96 if (!mem)
97 return FALSE;
99 size = SizeofResource(NULL, res);
100 if (size == 0)
101 return FALSE;
103 if (!GetTempPathW(MAX_PATH, temp_path))
104 return FALSE;
106 /* We might end up relying on the extension here, so .TMP is no good. */
107 if (!GetTempFileNameW(temp_path, prefix, 0, name))
108 return FALSE;
110 DeleteFileW(name);
111 lstrcpyW(name + lstrlenW(name) - 3, avi);
113 fh = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_NEW,
114 FILE_ATTRIBUTE_NORMAL, NULL);
115 if (fh == INVALID_HANDLE_VALUE)
116 return FALSE;
118 if (!WriteFile(fh, mem, size, &written, NULL) || written != size)
119 return FALSE;
121 CloseHandle(fh);
123 return TRUE;
126 static BOOL init_tests(void)
128 return unpack_avi_file(TEST_AVI_RES, test_avi_filename)
129 && unpack_avi_file(TEST_SOUND_AVI_RES, test_sound_avi_filename);
132 static void test_mediadet(void)
134 HRESULT hr;
135 IMediaDet *pM = NULL;
136 BSTR filename = NULL;
137 LONG nstrms = 0;
138 LONG strm;
139 AM_MEDIA_TYPE mt;
140 double fps;
141 int flags;
142 int i;
144 /* test.avi has one video stream. */
145 hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
146 &IID_IMediaDet, (LPVOID*)&pM);
147 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
148 ok(pM != NULL, "pM is NULL\n");
150 filename = NULL;
151 hr = IMediaDet_get_Filename(pM, &filename);
152 /* Despite what MSDN claims, this returns S_OK. */
153 ok(hr == S_OK, "IMediaDet_get_Filename\n");
154 ok(filename == NULL, "IMediaDet_get_Filename\n");
156 filename = (BSTR) -1;
157 hr = IMediaDet_get_Filename(pM, &filename);
158 /* Despite what MSDN claims, this returns S_OK. */
159 ok(hr == S_OK, "IMediaDet_get_Filename\n");
160 ok(filename == NULL, "IMediaDet_get_Filename\n");
162 nstrms = -1;
163 hr = IMediaDet_get_OutputStreams(pM, &nstrms);
164 ok(hr == E_INVALIDARG, "IMediaDet_get_OutputStreams\n");
165 ok(nstrms == -1, "IMediaDet_get_OutputStreams\n");
167 strm = -1;
168 /* The stream defaults to 0, even without a file! */
169 hr = IMediaDet_get_CurrentStream(pM, &strm);
170 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
171 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
173 hr = IMediaDet_get_CurrentStream(pM, NULL);
174 ok(hr == E_POINTER, "IMediaDet_get_CurrentStream\n");
176 /* But put_CurrentStream doesn't. */
177 hr = IMediaDet_put_CurrentStream(pM, 0);
178 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
180 hr = IMediaDet_put_CurrentStream(pM, -1);
181 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
183 hr = IMediaDet_get_StreamMediaType(pM, &mt);
184 ok(hr == E_INVALIDARG, "IMediaDet_get_StreamMediaType\n");
186 hr = IMediaDet_get_StreamMediaType(pM, NULL);
187 ok(hr == E_POINTER, "IMediaDet_get_StreamMediaType\n");
189 filename = SysAllocString(test_avi_filename);
190 hr = IMediaDet_put_Filename(pM, filename);
191 ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
192 SysFreeString(filename);
194 strm = -1;
195 /* The stream defaults to 0. */
196 hr = IMediaDet_get_CurrentStream(pM, &strm);
197 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
198 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
200 ZeroMemory(&mt, sizeof mt);
201 hr = IMediaDet_get_StreamMediaType(pM, &mt);
202 ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
203 CoTaskMemFree(mt.pbFormat);
205 /* Even before get_OutputStreams. */
206 hr = IMediaDet_put_CurrentStream(pM, 1);
207 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
209 hr = IMediaDet_get_OutputStreams(pM, &nstrms);
210 ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
211 ok(nstrms == 1, "IMediaDet_get_OutputStreams\n");
213 filename = NULL;
214 hr = IMediaDet_get_Filename(pM, &filename);
215 ok(hr == S_OK, "IMediaDet_get_Filename\n");
216 ok(lstrcmpW(filename, test_avi_filename) == 0,
217 "IMediaDet_get_Filename\n");
218 SysFreeString(filename);
220 hr = IMediaDet_get_Filename(pM, NULL);
221 ok(hr == E_POINTER, "IMediaDet_get_Filename\n");
223 strm = -1;
224 hr = IMediaDet_get_CurrentStream(pM, &strm);
225 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
226 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
228 hr = IMediaDet_get_CurrentStream(pM, NULL);
229 ok(hr == E_POINTER, "IMediaDet_get_CurrentStream\n");
231 hr = IMediaDet_put_CurrentStream(pM, -1);
232 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
234 hr = IMediaDet_put_CurrentStream(pM, 1);
235 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
237 /* Try again. */
238 strm = -1;
239 hr = IMediaDet_get_CurrentStream(pM, &strm);
240 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
241 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
243 hr = IMediaDet_put_CurrentStream(pM, 0);
244 ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
246 strm = -1;
247 hr = IMediaDet_get_CurrentStream(pM, &strm);
248 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
249 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
251 ZeroMemory(&mt, sizeof mt);
252 hr = IMediaDet_get_StreamMediaType(pM, &mt);
253 ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
254 ok(IsEqualGUID(&mt.majortype, &MEDIATYPE_Video),
255 "IMediaDet_get_StreamMediaType\n");
256 CoTaskMemFree(mt.pbFormat);
258 hr = IMediaDet_get_FrameRate(pM, NULL);
259 ok(hr == E_POINTER, "IMediaDet_get_FrameRate\n");
261 hr = IMediaDet_get_FrameRate(pM, &fps);
262 ok(hr == S_OK, "IMediaDet_get_FrameRate\n");
263 ok(fps == 10.0, "IMediaDet_get_FrameRate\n");
265 hr = IMediaDet_Release(pM);
266 ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
268 DeleteFileW(test_avi_filename);
270 /* test_sound.avi has one video stream and one audio stream. */
271 hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
272 &IID_IMediaDet, (LPVOID*)&pM);
273 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
274 ok(pM != NULL, "pM is NULL\n");
276 filename = SysAllocString(test_sound_avi_filename);
277 hr = IMediaDet_put_Filename(pM, filename);
278 ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
279 SysFreeString(filename);
281 hr = IMediaDet_get_OutputStreams(pM, &nstrms);
282 ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
283 ok(nstrms == 2, "IMediaDet_get_OutputStreams\n");
285 filename = NULL;
286 hr = IMediaDet_get_Filename(pM, &filename);
287 ok(hr == S_OK, "IMediaDet_get_Filename\n");
288 ok(lstrcmpW(filename, test_sound_avi_filename) == 0,
289 "IMediaDet_get_Filename\n");
290 SysFreeString(filename);
292 /* I don't know if the stream order is deterministic. Just check
293 for both an audio and video stream. */
294 flags = 0;
296 for (i = 0; i < 2; ++i)
298 hr = IMediaDet_put_CurrentStream(pM, i);
299 ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
301 strm = -1;
302 hr = IMediaDet_get_CurrentStream(pM, &strm);
303 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
304 ok(strm == i, "IMediaDet_get_CurrentStream\n");
306 ZeroMemory(&mt, sizeof mt);
307 hr = IMediaDet_get_StreamMediaType(pM, &mt);
308 ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
309 flags += (IsEqualGUID(&mt.majortype, &MEDIATYPE_Video)
311 : (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio)
313 : 0));
315 if (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio))
317 hr = IMediaDet_get_FrameRate(pM, &fps);
318 ok(hr == VFW_E_INVALIDMEDIATYPE, "IMediaDet_get_FrameRate\n");
321 CoTaskMemFree(mt.pbFormat);
323 ok(flags == 3, "IMediaDet_get_StreamMediaType\n");
325 hr = IMediaDet_put_CurrentStream(pM, 2);
326 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
328 strm = -1;
329 hr = IMediaDet_get_CurrentStream(pM, &strm);
330 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
331 ok(strm == 1, "IMediaDet_get_CurrentStream\n");
333 hr = IMediaDet_Release(pM);
334 ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
336 DeleteFileW(test_sound_avi_filename);
339 static void test_samplegrabber(void)
341 struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
342 ISampleGrabber *sg;
343 ULONG refcount;
344 HRESULT hr;
346 /* COM aggregation */
347 hr = CoCreateInstance(&CLSID_SampleGrabber, &unk_obj.IUnknown_iface, CLSCTX_INPROC_SERVER,
348 &IID_IUnknown, (void**)&unk_obj.inner_unk);
349 todo_wine ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
350 if (hr != S_OK) return;
352 hr = IUnknown_QueryInterface(unk_obj.inner_unk, &IID_ISampleGrabber, (void**)&sg);
353 ok(hr == S_OK, "QueryInterface for IID_ISampleGrabber failed: %08x\n", hr);
354 refcount = ISampleGrabber_AddRef(sg);
355 ok(refcount == unk_obj.ref, "SampleGrabber just pretends to support COM aggregation\n");
356 refcount = ISampleGrabber_Release(sg);
357 ok(refcount == unk_obj.ref, "SampleGrabber just pretends to support COM aggregation\n");
358 refcount = ISampleGrabber_Release(sg);
359 ok(refcount == 19, "Refcount should be back at 19 but is %u\n", refcount);
361 IUnknown_Release(unk_obj.inner_unk);
364 START_TEST(mediadet)
366 if (!init_tests())
368 skip("Couldn't initialize tests!\n");
369 return;
372 CoInitialize(NULL);
373 test_mediadet();
374 test_samplegrabber();
375 CoUninitialize();