2 * Unit tests for the avi splitter functions
4 * Copyright (C) 2007 Google (Lei Zhang)
5 * Copyright (C) 2008 Google (Maarten Lankhorst)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
28 static HANDLE (WINAPI *pCreateToolhelp32Snapshot)(DWORD, DWORD);
29 static BOOL (WINAPI *pThread32First)(HANDLE, LPTHREADENTRY32);
30 static BOOL (WINAPI *pThread32Next)(HANDLE, LPTHREADENTRY32);
32 static IUnknown *pAviSplitter = NULL;
34 static int count_threads(void)
40 h = pCreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
41 te.dwSize = sizeof(te);
43 if (h == INVALID_HANDLE_VALUE)
46 pThread32First(h, &te);
47 if (te.th32OwnerProcessID == GetCurrentProcessId())
52 while (pThread32Next(h, &te))
53 if (te.th32OwnerProcessID == GetCurrentProcessId())
60 static int create_avisplitter(void)
64 hr = CoCreateInstance(&CLSID_AviSplitter, NULL, CLSCTX_INPROC_SERVER,
65 &IID_IUnknown, (LPVOID*)&pAviSplitter);
66 return (hr == S_OK && pAviSplitter != NULL);
69 static void release_avisplitter(void)
74 hr = IUnknown_Release(pAviSplitter);
76 /* Looks like wine has a reference leak somewhere on test_threads tests,
77 * it passes in windows
79 ok(hr == 0, "IUnknown_Release failed with %d\n", (INT)hr);
82 hr = IUnknown_Release(pAviSplitter);
86 static void test_query_interface(void)
90 IUnknown *iface= NULL;
92 hr = IUnknown_QueryInterface(pAviSplitter, &IID_IBaseFilter,
96 "IID_IBaseFilter should exist, got %08x!\n", GetLastError());
99 ref = IUnknown_Release(iface);
101 ok(ref == 1, "Reference is %u, expected 1\n", ref);
104 hr = IUnknown_QueryInterface(pAviSplitter, &IID_IMediaSeeking,
107 ref = IUnknown_Release(iface);
109 todo_wine ok(hr == E_NOINTERFACE,
110 "Query for IMediaSeeking returned: %08x\n", hr);
112 /* These interfaces should not be present:
113 IID_IKsPropertySet, IID_IMediaPosition, IID_IQualityControl, IID_IQualProp
117 static void test_pin(IPin *pin)
119 IMemInputPin *mpin = NULL;
121 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&mpin);
123 ok(mpin == NULL, "IMemInputPin found!\n");
125 IMemInputPin_Release(mpin);
129 static void test_basefilter(void)
131 IEnumPins *pin_enum = NULL;
132 IBaseFilter *base = NULL;
137 IUnknown_QueryInterface(pAviSplitter, &IID_IBaseFilter, (void *)&base);
140 /* test_query_interface handles this case */
141 skip("No IBaseFilter\n");
145 hr = IBaseFilter_EnumPins(base, NULL);
146 ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
148 hr= IBaseFilter_EnumPins(base, &pin_enum);
149 ok(hr == S_OK, "hr = %08x and not S_OK\n", hr);
151 hr = IEnumPins_Next(pin_enum, 1, NULL, NULL);
152 ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
154 hr = IEnumPins_Next(pin_enum, 2, pins, NULL);
155 ok(hr == E_INVALIDARG, "hr = %08x and not E_INVALIDARG\n", hr);
157 pins[0] = (void *)0xdead;
158 pins[1] = (void *)0xdeed;
160 hr = IEnumPins_Next(pin_enum, 2, pins, &ref);
161 ok(hr == S_FALSE, "hr = %08x instead of S_FALSE\n", hr);
162 ok(pins[0] != (void *)0xdead && pins[0] != NULL,
163 "pins[0] = %p\n", pins[0]);
164 if (pins[0] != (void *)0xdead && pins[0] != NULL)
167 IPin_Release(pins[0]);
170 ok(pins[1] == (void *)0xdeed, "pins[1] = %p\n", pins[1]);
172 ref = IEnumPins_Release(pin_enum);
173 ok(ref == 0, "ref is %u and not 0!\n", ref);
175 IBaseFilter_Release(base);
178 static const WCHAR wfile[] = {'t','e','s','t','.','a','v','i',0};
179 static const char afile[] = "test.avi";
181 /* This test doesn't use the quartz filtergraph because it makes it impossible
182 * to be certain that a thread is really one owned by the avi splitter
183 * A lot of the decoder filters will also have their own thread, and windows'
184 * filtergraph has a separate thread for start/stop/seeking requests.
185 * By avoiding the filtergraph all together and connecting streams directly to
186 * the null renderer I am sure that this is not the case here.
188 static void test_threads()
190 IFileSourceFilter *pfile = NULL;
191 IBaseFilter *preader = NULL, *pavi = NULL;
192 IEnumPins *enumpins = NULL;
193 IPin *filepin = NULL, *avipin = NULL;
195 int baselevel, curlevel, expected;
197 PIN_DIRECTION dir = PINDIR_OUTPUT;
202 /* We need another way of counting threads on NT4. Skip these tests (for now) */
203 if (!pCreateToolhelp32Snapshot || !pThread32First || !pThread32Next)
205 win_skip("Needed thread functions are not available (NT4)\n");
209 /* Before doing anything */
210 baselevel = count_threads();
212 ok(baselevel == expected,
213 "Basic amount of threads should be %d, not %d!\n", expected, baselevel);
215 file = CreateFileW(wfile, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
216 NULL, OPEN_EXISTING, 0, NULL);
217 if (file == INVALID_HANDLE_VALUE)
219 skip("Could not read test file \"%s\", skipping test\n", afile);
223 memset(buffer, 0, 13);
225 ReadFile(file, buffer, readbytes, &readbytes, NULL);
227 if (strncmp(buffer, "RIFF", 4) || strcmp(buffer + 8, "AVI "))
229 skip("%s is not an avi riff file, not doing the avi splitter test\n",
234 hr = IUnknown_QueryInterface(pAviSplitter, &IID_IFileSourceFilter,
236 ok(hr == E_NOINTERFACE,
237 "Avi splitter returns unexpected error: %08x\n", hr);
239 IUnknown_Release(pfile);
242 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER,
243 &IID_IBaseFilter, (LPVOID*)&preader);
244 ok(hr == S_OK, "Could not create asynchronous reader: %08x\n", hr);
248 hr = IUnknown_QueryInterface(preader, &IID_IFileSourceFilter,
250 ok(hr == S_OK, "Could not get IFileSourceFilter: %08x\n", hr);
254 hr = IUnknown_QueryInterface(pAviSplitter, &IID_IBaseFilter,
256 ok(hr == S_OK, "Could not get base filter: %08x\n", hr);
260 hr = IFileSourceFilter_Load(pfile, wfile, NULL);
263 trace("Could not load file\n");
267 hr = IBaseFilter_EnumPins(preader, &enumpins);
268 ok(hr == S_OK, "No enumpins: %08x\n", hr);
272 hr = IEnumPins_Next(enumpins, 1, &filepin, NULL);
273 ok(hr == S_OK, "No pin: %08x\n", hr);
277 IUnknown_Release(enumpins);
280 hr = IBaseFilter_EnumPins(pavi, &enumpins);
281 ok(hr == S_OK, "No enumpins: %08x\n", hr);
285 hr = IEnumPins_Next(enumpins, 1, &avipin, NULL);
286 ok(hr == S_OK, "No pin: %08x\n", hr);
290 curlevel = count_threads();
291 ok(curlevel == baselevel,
292 "Amount of threads should be %d not %d\n", baselevel, curlevel);
294 hr = IPin_Connect(filepin, avipin, NULL);
295 ok(hr == S_OK, "Could not connect: %08x\n", hr);
299 expected = 1 + baselevel;
300 curlevel = count_threads();
301 ok(curlevel == expected,
302 "Amount of threads should be %d not %d\n", expected, curlevel);
304 IUnknown_Release(avipin);
307 IEnumPins_Reset(enumpins);
309 /* Windows puts the pins in the order: Outputpins - Inputpin,
310 * wine does the reverse, just don't test it for now
311 * Hate to admit it, but windows way makes more sense
313 while (IEnumPins_Next(enumpins, 1, &avipin, NULL) == S_OK)
315 ok(hr == S_OK, "hr: %08x\n", hr);
316 IPin_QueryDirection(avipin, &dir);
317 if (dir == PINDIR_OUTPUT)
319 /* Well, connect it to a null renderer! */
320 IBaseFilter *pnull = NULL;
321 IEnumPins *nullenum = NULL;
322 IPin *nullpin = NULL;
324 hr = CoCreateInstance(&CLSID_NullRenderer, NULL,
325 CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pnull);
326 ok(hr == S_OK, "Could not create null renderer: %08x\n", hr);
330 IBaseFilter_EnumPins(pnull, &nullenum);
331 IEnumPins_Next(nullenum, 1, &nullpin, NULL);
332 IEnumPins_Release(nullenum);
333 IPin_QueryDirection(nullpin, &dir);
335 hr = IPin_Connect(avipin, nullpin, NULL);
336 ok(hr == S_OK, "Failed to connect output pin: %08x\n", hr);
337 IPin_Release(nullpin);
340 IBaseFilter_Release(pnull);
343 IBaseFilter_Run(pnull, 0);
347 IUnknown_Release(avipin);
352 IUnknown_Release(avipin);
357 /* At this point there is a minimalistic connected avi splitter that can
358 * Be used for all sorts of source filter tests, however that still needs
359 * to be written at a later time.
362 * - Can you disconnect an output pin while running?
364 * - Can you disconnect the pullpin while running?
366 * - Is the reference count incremented during playback or when connected?
367 * Does this happen once for every output pin? Or is there something else
369 * Expecting: You tell me
372 IBaseFilter_Run(preader, 0);
373 IBaseFilter_Run(pavi, 0);
374 IBaseFilter_GetState(pavi, INFINITE, &state);
376 curlevel = count_threads();
377 /* On a 2 stream filter, there are 4 or 5 threads (seems to be 5)
378 * One is the thread we are in. That leaves 3 or 4 for other dark purposes
379 * Wine is 1 thread short!
381 ok(curlevel == expected || curlevel == expected + 1,
382 "Amount of threads should be %d not %d\n", expected, curlevel);
384 IBaseFilter_Pause(pavi);
385 IBaseFilter_Pause(preader);
386 IBaseFilter_Stop(pavi);
387 IBaseFilter_Stop(preader);
388 IBaseFilter_GetState(pavi, INFINITE, &state);
389 IBaseFilter_GetState(preader, INFINITE, &state);
392 IEnumPins_Reset(enumpins);
393 while (IEnumPins_Next(enumpins, 1, &avipin, NULL) == S_OK)
397 IPin_QueryDirection(avipin, &dir);
398 IPin_ConnectedTo(avipin, &to);
403 if (dir == PINDIR_OUTPUT)
406 IPin_QueryPinInfo(to, &info);
408 /* Release twice: Once normal, second from the
409 * previous while loop
411 IBaseFilter_Stop(info.pFilter);
413 IPin_Disconnect(avipin);
414 IBaseFilter_Release(info.pFilter);
415 IBaseFilter_Release(info.pFilter);
420 IPin_Disconnect(avipin);
423 IPin_Release(avipin);
429 skip("Prerequisites not matched, skipping remainder of test\n");
431 IUnknown_Release(enumpins);
434 IUnknown_Release(avipin);
439 IPin_ConnectedTo(filepin, &to);
442 IPin_Disconnect(filepin);
445 IUnknown_Release(filepin);
449 IUnknown_Release(preader);
451 IUnknown_Release(pavi);
453 IUnknown_Release(pfile);
456 "Basic amount of threads should be %d, not %d!\n", 1, baselevel);
459 START_TEST(avisplitter)
461 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
463 pCreateToolhelp32Snapshot = (void*)GetProcAddress(kernel32, "CreateToolhelp32Snapshot");
464 pThread32First = (void*)GetProcAddress(kernel32, "Thread32First");
465 pThread32Next = (void*)GetProcAddress(kernel32, "Thread32Next");
469 if (!create_avisplitter())
471 skip("Could not create avisplitter\n");
475 test_query_interface();
479 release_avisplitter();