Release 0.9.61.
[wine/gsoc-2012-control.git] / dlls / quartz / tests / filtergraph.c
blobf1728f785fb9282a675bdbe56055d42e5fdde25b
1 /*
2 * Unit tests for Direct Show functions
4 * Copyright (C) 2004 Christian Costa
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 #include <assert.h>
23 #define COBJMACROS
25 #include "wine/test.h"
26 #include "uuids.h"
27 #include "dshow.h"
28 #include "control.h"
30 static const WCHAR file[] = {'t','e','s','t','.','a','v','i',0};
32 IGraphBuilder* pgraph;
34 static int createfiltergraph(void)
36 return S_OK == CoCreateInstance(
37 &CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&pgraph);
40 static void renderfile(void)
42 HRESULT hr;
44 hr = IGraphBuilder_RenderFile(pgraph, file, NULL);
45 ok(hr==S_OK, "RenderFile returned: %x\n", hr);
48 static void rungraph(void)
50 HRESULT hr;
51 IMediaControl* pmc;
52 IMediaEvent* pme;
53 IMediaFilter* pmf;
54 HANDLE hEvent;
56 hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaControl, (LPVOID*)&pmc);
57 ok(hr==S_OK, "Cannot get IMediaControl interface returned: %x\n", hr);
59 hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaFilter, (LPVOID*)&pmf);
60 ok(hr==S_OK, "Cannot get IMediaFilter interface returned: %x\n", hr);
62 IMediaControl_Stop(pmc);
64 IMediaFilter_SetSyncSource(pmf, NULL);
66 IMediaFilter_Release(pmf);
68 hr = IMediaControl_Run(pmc);
69 ok(hr==S_FALSE, "Cannot run the graph returned: %x\n", hr);
71 Sleep(10);
72 /* Crash fun */
73 trace("run -> stop\n");
74 hr = IMediaControl_Stop(pmc);
75 ok(hr==S_OK || hr == S_FALSE, "Cannot stop the graph returned: %x\n", hr);
77 IGraphBuilder_SetDefaultSyncSource(pgraph);
79 Sleep(10);
80 trace("stop -> pause\n");
81 hr = IMediaControl_Pause(pmc);
82 ok(hr==S_OK || hr == S_FALSE, "Cannot pause the graph returned: %x\n", hr);
84 Sleep(10);
85 trace("pause -> run\n");
86 hr = IMediaControl_Run(pmc);
87 ok(hr==S_OK || hr == S_FALSE, "Cannot start the graph returned: %x\n", hr);
89 Sleep(10);
90 trace("run -> pause\n");
91 hr = IMediaControl_Pause(pmc);
92 ok(hr==S_OK || hr == S_FALSE, "Cannot pause the graph returned: %x\n", hr);
94 Sleep(10);
95 trace("pause -> stop\n");
96 hr = IMediaControl_Stop(pmc);
97 ok(hr==S_OK || hr == S_FALSE, "Cannot stop the graph returned: %x\n", hr);
99 Sleep(10);
100 trace("pause -> run\n");
101 hr = IMediaControl_Run(pmc);
102 ok(hr==S_OK || hr == S_FALSE, "Cannot start the graph returned: %x\n", hr);
104 trace("run -> stop\n");
105 hr = IMediaControl_Stop(pmc);
106 ok(hr==S_OK || hr == S_FALSE, "Cannot stop the graph returned: %x\n", hr);
108 trace("stop -> run\n");
109 hr = IMediaControl_Run(pmc);
110 ok(hr==S_OK || hr == S_FALSE, "Cannot start the graph returned: %x\n", hr);
112 hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaEvent, (LPVOID*)&pme);
113 ok(hr==S_OK, "Cannot get IMediaEvent interface returned: %x\n", hr);
115 hr = IMediaEvent_GetEventHandle(pme, (OAEVENT*)&hEvent);
116 ok(hr==S_OK, "Cannot get event handle returned: %x\n", hr);
118 /* WaitForSingleObject(hEvent, INFINITE); */
119 Sleep(20000);
121 hr = IMediaEvent_Release(pme);
122 ok(hr==2, "Releasing mediaevent returned: %x\n", hr);
124 hr = IMediaControl_Stop(pmc);
125 ok(hr==S_OK, "Cannot stop the graph returned: %x\n", hr);
127 hr = IMediaControl_Release(pmc);
128 ok(hr==1, "Releasing mediacontrol returned: %x\n", hr);
131 static void releasefiltergraph(void)
133 HRESULT hr;
135 hr = IGraphBuilder_Release(pgraph);
136 ok(hr==0, "Releasing filtergraph returned: %x\n", hr);
139 static void test_render_run(void)
141 HANDLE h;
143 if (!createfiltergraph())
144 return;
146 h = CreateFileW(file, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
147 if (h != INVALID_HANDLE_VALUE) {
148 CloseHandle(h);
149 renderfile();
150 rungraph();
153 releasefiltergraph();
156 static void test_graph_builder(void)
158 HRESULT hr;
159 IBaseFilter *pF = NULL;
160 IBaseFilter *pF2 = NULL;
161 IPin *pIn = NULL;
162 IEnumPins *pEnum = NULL;
163 PIN_DIRECTION dir;
164 static const WCHAR testFilterW[] = {'t','e','s','t','F','i','l','t','e','r',0};
165 static const WCHAR fooBarW[] = {'f','o','o','B','a','r',0};
167 if (!createfiltergraph())
168 return;
170 /* create video filter */
171 hr = CoCreateInstance(&CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER,
172 &IID_IBaseFilter, (LPVOID*)&pF);
173 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
174 ok(pF != NULL, "pF is NULL\n");
176 /* add the two filters to the graph */
177 hr = IGraphBuilder_AddFilter(pgraph, pF, testFilterW);
178 ok(hr == S_OK, "failed to add pF to the graph: %x\n", hr);
180 /* find the pins */
181 hr = IBaseFilter_EnumPins(pF, &pEnum);
182 ok(hr == S_OK, "IBaseFilter_EnumPins failed for pF: %x\n", hr);
183 ok(pEnum != NULL, "pEnum is NULL\n");
184 hr = IEnumPins_Next(pEnum, 1, &pIn, NULL);
185 ok(hr == S_OK, "IEnumPins_Next failed for pF: %x\n", hr);
186 ok(pIn != NULL, "pIn is NULL\n");
187 hr = IPin_QueryDirection(pIn, &dir);
188 ok(hr == S_OK, "IPin_QueryDirection failed: %x\n", hr);
189 ok(dir == PINDIR_INPUT, "pin has wrong direction\n");
191 hr = IGraphBuilder_FindFilterByName(pgraph, fooBarW, &pF2);
192 ok(hr == VFW_E_NOT_FOUND, "IGraphBuilder_FindFilterByName returned %x\n", hr);
193 ok(pF2 == NULL, "IGraphBuilder_FindFilterByName returned %p\n", pF2);
194 hr = IGraphBuilder_FindFilterByName(pgraph, testFilterW, &pF2);
195 ok(hr == S_OK, "IGraphBuilder_FindFilterByName returned %x\n", hr);
196 ok(pF2 != NULL, "IGraphBuilder_FindFilterByName returned NULL\n");
197 hr = IGraphBuilder_FindFilterByName(pgraph, testFilterW, NULL);
198 ok(hr == E_POINTER, "IGraphBuilder_FindFilterByName returned %x\n", hr);
199 releasefiltergraph();
202 static void test_graph_builder_addfilter(void)
204 HRESULT hr;
205 IBaseFilter *pF = NULL;
206 static const WCHAR testFilterW[] = {'t','e','s','t','F','i','l','t','e','r',0};
208 if (!createfiltergraph())
209 return;
211 hr = IGraphBuilder_AddFilter(pgraph, NULL, testFilterW);
212 ok(hr == E_POINTER, "IGraphBuilder_AddFilter returned: %x\n", hr);
214 /* create video filter */
215 hr = CoCreateInstance(&CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER,
216 &IID_IBaseFilter, (LPVOID*)&pF);
217 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
218 ok(pF != NULL, "pF is NULL\n");
219 if (!pF) {
220 skip("failed to created filter, skipping\n");
221 return;
224 hr = IGraphBuilder_AddFilter(pgraph, pF, NULL);
225 ok(hr == S_OK, "IGraphBuilder_AddFilter returned: %x\n", hr);
226 IMediaFilter_Release(pF);
229 static void test_mediacontrol(void)
231 HRESULT hr;
232 LONGLONG pos = 0xdeadbeef;
233 IMediaSeeking *seeking = NULL;
234 IMediaFilter *filter = NULL;
236 IFilterGraph2_SetDefaultSyncSource(pgraph);
237 hr = IFilterGraph2_QueryInterface(pgraph, &IID_IMediaSeeking, (void**) &seeking);
238 ok(hr == S_OK, "QueryInterface IMediaControl failed: %08x\n", hr);
239 if (FAILED(hr))
240 return;
242 hr = IFilterGraph2_QueryInterface(pgraph, &IID_IMediaFilter, (void**) &filter);
243 ok(hr == S_OK, "QueryInterface IMediaFilter failed: %08x\n", hr);
244 if (FAILED(hr))
246 IUnknown_Release(seeking);
247 return;
250 hr = IMediaSeeking_GetCurrentPosition(seeking, &pos);
251 ok(hr == S_OK, "GetCurrentPosition failed: %08x\n", hr);
252 ok(pos == 0, "Position != 0 (%x%08x)\n", (DWORD)(pos >> 32), (DWORD)pos);
254 IMediaFilter_SetSyncSource(filter, NULL);
255 pos = 0xdeadbeef;
256 hr = IMediaSeeking_GetCurrentPosition(seeking, &pos);
257 ok(hr == S_OK, "GetCurrentPosition failed: %08x\n", hr);
258 ok(pos == 0, "Position != 0 (%x%08x)\n", (DWORD)(pos >> 32), (DWORD)pos);
260 IUnknown_Release(seeking);
261 IUnknown_Release(filter);
262 releasefiltergraph();
265 static void test_filter_graph2(void)
267 HRESULT hr;
268 IFilterGraph2 *pF = NULL;
270 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
271 &IID_IFilterGraph2, (LPVOID*)&pF);
272 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
273 ok(pF != NULL, "pF is NULL\n");
275 hr = IFilterGraph2_Release(pF);
276 ok(hr == 0, "IFilterGraph2_Release returned: %x\n", hr);
279 START_TEST(filtergraph)
281 CoInitialize(NULL);
282 test_render_run();
283 test_graph_builder();
284 test_graph_builder_addfilter();
285 test_mediacontrol();
286 test_filter_graph2();