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
28 #include "wine/test.h"
32 /* Outer IUnknown for COM aggregation tests */
34 IUnknown IUnknown_iface
;
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
=
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};
87 res
= FindResource(NULL
, MAKEINTRESOURCE(id
), MAKEINTRESOURCE(AVI_RES_TYPE
));
91 data
= LoadResource(NULL
, res
);
95 mem
= LockResource(data
);
99 size
= SizeofResource(NULL
, res
);
103 if (!GetTempPathW(MAX_PATH
, temp_path
))
106 /* We might end up relying on the extension here, so .TMP is no good. */
107 if (!GetTempFileNameW(temp_path
, prefix
, 0, 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
)
118 if (!WriteFile(fh
, mem
, size
, &written
, NULL
) || written
!= size
)
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)
135 IMediaDet
*pM
= NULL
;
136 BSTR filename
= NULL
;
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");
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");
163 hr
= IMediaDet_get_OutputStreams(pM
, &nstrms
);
164 ok(hr
== E_INVALIDARG
, "IMediaDet_get_OutputStreams\n");
165 ok(nstrms
== -1, "IMediaDet_get_OutputStreams\n");
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
);
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");
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");
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");
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");
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");
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. */
296 for (i
= 0; i
< 2; ++i
)
298 hr
= IMediaDet_put_CurrentStream(pM
, i
);
299 ok(hr
== S_OK
, "IMediaDet_put_CurrentStream\n");
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
)
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");
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
};
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
);
368 skip("Couldn't initialize tests!\n");
374 test_samplegrabber();