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
29 #include "wine/test.h"
33 static WCHAR test_avi_filename[MAX_PATH];
34 static WCHAR test_sound_avi_filename[MAX_PATH];
36 static BOOL unpack_avi_file(int id, WCHAR name[MAX_PATH])
38 static WCHAR temp_path[MAX_PATH];
39 static WCHAR prefix[] = {'D','E','S',0};
40 static WCHAR avi[] = {'a','v','i',0};
47 res = FindResource(NULL, MAKEINTRESOURCE(id), MAKEINTRESOURCE(AVI_RES_TYPE));
51 data = LoadResource(NULL, res);
55 mem = LockResource(data);
59 size = SizeofResource(NULL, res);
63 if (!GetTempPathW(MAX_PATH, temp_path))
66 /* We might end up relying on the extension here, so .TMP is no good. */
67 if (!GetTempFileNameW(temp_path, prefix, 0, name))
71 lstrcpyW(name + lstrlenW(name) - 3, avi);
73 fh = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_NEW,
74 FILE_ATTRIBUTE_NORMAL, NULL);
75 if (fh == INVALID_HANDLE_VALUE)
78 if (!WriteFile(fh, mem, size, &written, NULL) || written != size)
86 static BOOL init_tests(void)
88 return unpack_avi_file(TEST_AVI_RES, test_avi_filename)
89 && unpack_avi_file(TEST_SOUND_AVI_RES, test_sound_avi_filename);
92 static void test_mediadet(void)
104 /* test.avi has one video stream. */
105 hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
106 &IID_IMediaDet, (LPVOID*)&pM);
107 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
108 ok(pM != NULL, "pM is NULL\n");
111 hr = IMediaDet_get_Filename(pM, &filename);
112 /* Despite what MSDN claims, this returns S_OK. */
113 ok(hr == S_OK, "IMediaDet_get_Filename\n");
114 ok(filename == NULL, "IMediaDet_get_Filename\n");
116 filename = (BSTR) -1;
117 hr = IMediaDet_get_Filename(pM, &filename);
118 /* Despite what MSDN claims, this returns S_OK. */
119 ok(hr == S_OK, "IMediaDet_get_Filename\n");
120 ok(filename == NULL, "IMediaDet_get_Filename\n");
123 hr = IMediaDet_get_OutputStreams(pM, &nstrms);
124 ok(hr == E_INVALIDARG, "IMediaDet_get_OutputStreams\n");
125 ok(nstrms == -1, "IMediaDet_get_OutputStreams\n");
128 /* The stream defaults to 0, even without a file! */
129 hr = IMediaDet_get_CurrentStream(pM, &strm);
130 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
131 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
133 hr = IMediaDet_get_CurrentStream(pM, NULL);
134 ok(hr == E_POINTER, "IMediaDet_get_CurrentStream\n");
136 /* But put_CurrentStream doesn't. */
137 hr = IMediaDet_put_CurrentStream(pM, 0);
138 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
140 hr = IMediaDet_put_CurrentStream(pM, -1);
141 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
143 hr = IMediaDet_get_StreamMediaType(pM, &mt);
144 ok(hr == E_INVALIDARG, "IMediaDet_get_StreamMediaType\n");
146 hr = IMediaDet_get_StreamMediaType(pM, NULL);
147 ok(hr == E_POINTER, "IMediaDet_get_StreamMediaType\n");
149 filename = SysAllocString(test_avi_filename);
150 hr = IMediaDet_put_Filename(pM, filename);
151 ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
152 SysFreeString(filename);
155 /* The stream defaults to 0. */
156 hr = IMediaDet_get_CurrentStream(pM, &strm);
157 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
158 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
160 ZeroMemory(&mt, sizeof mt);
161 hr = IMediaDet_get_StreamMediaType(pM, &mt);
162 ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
163 CoTaskMemFree(mt.pbFormat);
165 /* Even before get_OutputStreams. */
166 hr = IMediaDet_put_CurrentStream(pM, 1);
167 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
169 hr = IMediaDet_get_OutputStreams(pM, &nstrms);
170 ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
171 ok(nstrms == 1, "IMediaDet_get_OutputStreams\n");
174 hr = IMediaDet_get_Filename(pM, &filename);
175 ok(hr == S_OK, "IMediaDet_get_Filename\n");
176 ok(lstrcmpW(filename, test_avi_filename) == 0,
177 "IMediaDet_get_Filename\n");
178 SysFreeString(filename);
180 hr = IMediaDet_get_Filename(pM, NULL);
181 ok(hr == E_POINTER, "IMediaDet_get_Filename\n");
184 hr = IMediaDet_get_CurrentStream(pM, &strm);
185 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
186 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
188 hr = IMediaDet_get_CurrentStream(pM, NULL);
189 ok(hr == E_POINTER, "IMediaDet_get_CurrentStream\n");
191 hr = IMediaDet_put_CurrentStream(pM, -1);
192 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
194 hr = IMediaDet_put_CurrentStream(pM, 1);
195 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
199 hr = IMediaDet_get_CurrentStream(pM, &strm);
200 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
201 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
203 hr = IMediaDet_put_CurrentStream(pM, 0);
204 ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
207 hr = IMediaDet_get_CurrentStream(pM, &strm);
208 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
209 ok(strm == 0, "IMediaDet_get_CurrentStream\n");
211 ZeroMemory(&mt, sizeof mt);
212 hr = IMediaDet_get_StreamMediaType(pM, &mt);
213 ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
214 ok(IsEqualGUID(&mt.majortype, &MEDIATYPE_Video),
215 "IMediaDet_get_StreamMediaType\n");
216 CoTaskMemFree(mt.pbFormat);
218 hr = IMediaDet_get_FrameRate(pM, NULL);
219 ok(hr == E_POINTER, "IMediaDet_get_FrameRate\n");
221 hr = IMediaDet_get_FrameRate(pM, &fps);
222 ok(hr == S_OK, "IMediaDet_get_FrameRate\n");
223 ok(fps == 10.0, "IMediaDet_get_FrameRate\n");
225 hr = IMediaDet_Release(pM);
226 ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
228 DeleteFileW(test_avi_filename);
230 /* test_sound.avi has one video stream and one audio stream. */
231 hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
232 &IID_IMediaDet, (LPVOID*)&pM);
233 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
234 ok(pM != NULL, "pM is NULL\n");
236 filename = SysAllocString(test_sound_avi_filename);
237 hr = IMediaDet_put_Filename(pM, filename);
238 ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
239 SysFreeString(filename);
241 hr = IMediaDet_get_OutputStreams(pM, &nstrms);
242 ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
243 ok(nstrms == 2, "IMediaDet_get_OutputStreams\n");
246 hr = IMediaDet_get_Filename(pM, &filename);
247 ok(hr == S_OK, "IMediaDet_get_Filename\n");
248 ok(lstrcmpW(filename, test_sound_avi_filename) == 0,
249 "IMediaDet_get_Filename\n");
250 SysFreeString(filename);
252 /* I don't know if the stream order is deterministic. Just check
253 for both an audio and video stream. */
256 for (i = 0; i < 2; ++i)
258 hr = IMediaDet_put_CurrentStream(pM, i);
259 ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
262 hr = IMediaDet_get_CurrentStream(pM, &strm);
263 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
264 ok(strm == i, "IMediaDet_get_CurrentStream\n");
266 ZeroMemory(&mt, sizeof mt);
267 hr = IMediaDet_get_StreamMediaType(pM, &mt);
268 ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
269 flags += (IsEqualGUID(&mt.majortype, &MEDIATYPE_Video)
271 : (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio)
275 if (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio))
277 hr = IMediaDet_get_FrameRate(pM, &fps);
278 ok(hr == VFW_E_INVALIDMEDIATYPE, "IMediaDet_get_FrameRate\n");
281 CoTaskMemFree(mt.pbFormat);
283 ok(flags == 3, "IMediaDet_get_StreamMediaType\n");
285 hr = IMediaDet_put_CurrentStream(pM, 2);
286 ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
289 hr = IMediaDet_get_CurrentStream(pM, &strm);
290 ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
291 ok(strm == 1, "IMediaDet_get_CurrentStream\n");
293 hr = IMediaDet_Release(pM);
294 ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
296 DeleteFileW(test_sound_avi_filename);
303 skip("Couldn't initialize tests!\n");