[QUARTZ]
[reactos.git] / rostests / winetests / quartz / filtergraph.c
index 50ab5cf..39d6e88 100644 (file)
@@ -180,6 +180,9 @@ static void test_graph_builder(void)
     ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
     ok(pF != NULL, "pF is NULL\n");
 
+    hr = IGraphBuilder_AddFilter(pgraph, NULL, testFilterW);
+    ok(hr == E_POINTER, "IGraphBuilder_AddFilter returned %x\n", hr);
+
     /* add the two filters to the graph */
     hr = IGraphBuilder_AddFilter(pgraph, pF, testFilterW);
     ok(hr == S_OK, "failed to add pF to the graph: %x\n", hr);
@@ -204,6 +207,15 @@ static void test_graph_builder(void)
     hr = IGraphBuilder_FindFilterByName(pgraph, testFilterW, NULL);
     ok(hr == E_POINTER, "IGraphBuilder_FindFilterByName returned %x\n", hr);
 
+    hr = IGraphBuilder_Connect(pgraph, NULL, pIn);
+    ok(hr == E_POINTER, "IGraphBuilder_Connect returned %x\n", hr);
+
+    hr = IGraphBuilder_Connect(pgraph, pIn, NULL);
+    ok(hr == E_POINTER, "IGraphBuilder_Connect returned %x\n", hr);
+
+    hr = IGraphBuilder_Connect(pgraph, pIn, pIn);
+    ok(hr == VFW_E_CANNOT_CONNECT, "IGraphBuilder_Connect returned %x\n", hr);
+
     if (pIn) IPin_Release(pIn);
     if (pEnum) IEnumPins_Release(pEnum);
     if (pF) IBaseFilter_Release(pF);
@@ -1094,7 +1106,6 @@ static HRESULT createtestfilter(const CLSID* pClsid, const TestFilterPinData *pi
     pTestFilter->IBaseFilter_iface.lpVtbl = &TestFilter_Vtbl;
     pTestFilter->refCount = 1;
     InitializeCriticalSection(&pTestFilter->csFilter);
-    pTestFilter->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": TestFilterImpl.csFilter");
     pTestFilter->state = State_Stopped;
 
     ZeroMemory(&pTestFilter->filterInfo, sizeof(FILTER_INFO));
@@ -1149,7 +1160,6 @@ static HRESULT createtestfilter(const CLSID* pClsid, const TestFilterPinData *pi
         }
     }
     CoTaskMemFree(pTestFilter->ppPins);
-    pTestFilter->csFilter.DebugInfo->Spare[0] = 0;
     DeleteCriticalSection(&pTestFilter->csFilter);
     CoTaskMemFree(pTestFilter);
 
@@ -1213,7 +1223,6 @@ static ULONG WINAPI TestFilter_Release(IBaseFilter * iface)
 
         CoTaskMemFree(This->ppPins);
 
-        This->csFilter.DebugInfo->Spare[0] = 0;
         DeleteCriticalSection(&This->csFilter);
 
         CoTaskMemFree(This);
@@ -1559,9 +1568,10 @@ static void test_render_filter_priority(void)
     static const WCHAR wszFilterInstanceName4[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 'I',
                                                         'n', 's', 't', 'a', 'n', 'c', 'e', '4', 0 };
 
-    /* Test which renderer of two already added to the graph will be chosen (one is "exact" match, other is
-       "wildcard" match. Seems to very by order in which filters are added to the graph, thus indicating
-       no preference given to exact match. */
+    /* Test which renderer of two already added to the graph will be chosen
+     * (one is "exact" match, other is "wildcard" match. Seems to depend
+     * on the order in which filters are added to the graph, thus indicating
+     * no preference given to exact match. */
     hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterGraph2, (LPVOID*)&pgraph2);
     ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
     if (!pgraph2) return;
@@ -1643,7 +1653,7 @@ static void test_render_filter_priority(void)
     ok(hr == E_POINTER, "IFilterGraph2_Disconnect failed. Expected E_POINTER, received %08x\n", hr);
 
     get_connected_filter_name(ptestfilter, ConnectedFilterName2);
-    ok(lstrcmp(ConnectedFilterName1, ConnectedFilterName2),
+    ok(strcmp(ConnectedFilterName1, ConnectedFilterName2),
         "expected connected filters to be different but got %s both times\n", ConnectedFilterName1);
 
     IFilterGraph2_Release(pgraph2);
@@ -1699,7 +1709,7 @@ static void test_render_filter_priority(void)
     ok(hr == S_OK, "IFilterGraph2_Render failed with %08x\n", hr);
 
     get_connected_filter_name(ptestfilter, ConnectedFilterName1);
-    ok(!lstrcmp(ConnectedFilterName1, "TestfilterInstance3") || !lstrcmp(ConnectedFilterName1, "TestfilterInstance2"),
+    ok(!strcmp(ConnectedFilterName1, "TestfilterInstance3") || !strcmp(ConnectedFilterName1, "TestfilterInstance2"),
             "unexpected connected filter: %s\n", ConnectedFilterName1);
 
     IFilterGraph2_Release(pgraph2);
@@ -1751,9 +1761,9 @@ static void test_render_filter_priority(void)
     ok(hr == S_OK, "IFilterGraph2_Render failed with %08x\n", hr);
 
     get_connected_filter_name(ptestfilter, ConnectedFilterName2);
-    ok(!lstrcmp(ConnectedFilterName2, "TestfilterInstance3") || !lstrcmp(ConnectedFilterName2, "TestfilterInstance2"),
+    ok(!strcmp(ConnectedFilterName2, "TestfilterInstance3") || !strcmp(ConnectedFilterName2, "TestfilterInstance2"),
             "unexpected connected filter: %s\n", ConnectedFilterName2);
-    ok(lstrcmp(ConnectedFilterName1, ConnectedFilterName2),
+    ok(strcmp(ConnectedFilterName1, ConnectedFilterName2),
         "expected connected filters to be different but got %s both times\n", ConnectedFilterName1);
 
     IFilterGraph2_Release(pgraph2);
@@ -1847,19 +1857,19 @@ static void test_render_filter_priority(void)
         ok(hr == S_OK, "IFilterGraph2_Render failed with %08x\n", hr);
 
         get_connected_filter_name(ptestfilter, ConnectedFilterName1);
-        ok(!lstrcmp(ConnectedFilterName1, "TestfilterInstance3"),
+        ok(!strcmp(ConnectedFilterName1, "TestfilterInstance3"),
            "unexpected connected filter: %s\n", ConnectedFilterName1);
-    }
 
-    hr = IFilterMapper2_UnregisterFilter(pMapper2, &CLSID_LegacyAmFilterCategory, NULL,
-            &CLSID_TestFilter2);
-    ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
-    hr = IFilterMapper2_UnregisterFilter(pMapper2, &CLSID_LegacyAmFilterCategory, NULL,
-            &CLSID_TestFilter3);
-    ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
-    hr = IFilterMapper2_UnregisterFilter(pMapper2, &CLSID_LegacyAmFilterCategory, NULL,
-             &CLSID_TestFilter4);
-    ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
+        hr = IFilterMapper2_UnregisterFilter(pMapper2, &CLSID_LegacyAmFilterCategory, NULL,
+                &CLSID_TestFilter2);
+        ok(hr == S_OK, "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
+        hr = IFilterMapper2_UnregisterFilter(pMapper2, &CLSID_LegacyAmFilterCategory, NULL,
+                &CLSID_TestFilter3);
+        ok(hr == S_OK, "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
+        hr = IFilterMapper2_UnregisterFilter(pMapper2, &CLSID_LegacyAmFilterCategory, NULL,
+                 &CLSID_TestFilter4);
+        ok(hr == S_OK, "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
+    }
 
     out:
 
@@ -1876,16 +1886,101 @@ static void test_render_filter_priority(void)
     ok(hr == S_OK, "CoRevokeClassObject failed with %08x\n", hr);
 }
 
-START_TEST(filtergraph)
+typedef struct IUnknownImpl
+{
+    IUnknown IUnknown_iface;
+    int AddRef_called;
+    int Release_called;
+} IUnknownImpl;
+
+static IUnknownImpl *IUnknownImpl_from_iface(IUnknown * iface)
+{
+    return CONTAINING_RECORD(iface, IUnknownImpl, IUnknown_iface);
+}
+
+static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
+{
+    ok(0, "QueryInterface should not be called for %s\n", wine_dbgstr_guid(riid));
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI IUnknownImpl_AddRef(IUnknown * iface)
+{
+    IUnknownImpl *This = IUnknownImpl_from_iface(iface);
+    This->AddRef_called++;
+    return 2;
+}
+
+static ULONG WINAPI IUnknownImpl_Release(IUnknown * iface)
+{
+    IUnknownImpl *This = IUnknownImpl_from_iface(iface);
+    This->Release_called++;
+    return 1;
+}
+
+static CONST_VTBL IUnknownVtbl IUnknownImpl_Vtbl =
+{
+    IUnknownImpl_QueryInterface,
+    IUnknownImpl_AddRef,
+    IUnknownImpl_Release
+};
+
+static void test_aggregate_filter_graph(void)
 {
     HRESULT hr;
+    IUnknown *pgraph;
+    IUnknown *punk;
+    IUnknownImpl unk_outer = { { &IUnknownImpl_Vtbl }, 0, 0 };
 
-    if (!winetest_interactive)
-    {
-        skip("Skipping filtergraph test, see ROSTESTS-116\n");
-        return;
-    }
+    hr = CoCreateInstance(&CLSID_FilterGraph, &unk_outer.IUnknown_iface, CLSCTX_INPROC_SERVER,
+                          &IID_IUnknown, (void **)&pgraph);
+    ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
+    ok(pgraph != &unk_outer.IUnknown_iface, "pgraph = %p, expected not %p\n", pgraph, &unk_outer.IUnknown_iface);
+
+    hr = IUnknown_QueryInterface(pgraph, &IID_IUnknown, (void **)&punk);
+    ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
+    ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
+    IUnknown_Release(punk);
+
+    ok(unk_outer.AddRef_called == 0, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
+    ok(unk_outer.Release_called == 0, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
+    unk_outer.AddRef_called = 0;
+    unk_outer.Release_called = 0;
+
+    hr = IUnknown_QueryInterface(pgraph, &IID_IFilterMapper, (void **)&punk);
+    ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
+    ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
+    IUnknown_Release(punk);
 
+    ok(unk_outer.AddRef_called == 1, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
+    ok(unk_outer.Release_called == 1, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
+    unk_outer.AddRef_called = 0;
+    unk_outer.Release_called = 0;
+
+    hr = IUnknown_QueryInterface(pgraph, &IID_IFilterMapper2, (void **)&punk);
+    ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
+    ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
+    IUnknown_Release(punk);
+
+    ok(unk_outer.AddRef_called == 1, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
+    ok(unk_outer.Release_called == 1, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
+    unk_outer.AddRef_called = 0;
+    unk_outer.Release_called = 0;
+
+    hr = IUnknown_QueryInterface(pgraph, &IID_IFilterMapper3, (void **)&punk);
+    ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
+    ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
+    IUnknown_Release(punk);
+
+    ok(unk_outer.AddRef_called == 1, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
+    ok(unk_outer.Release_called == 1, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
+
+    IUnknown_Release(pgraph);
+}
+
+START_TEST(filtergraph)
+{
+    HRESULT hr;
     CoInitializeEx(NULL, COINIT_MULTITHREADED);
     hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
                           &IID_IGraphBuilder, (LPVOID*)&pgraph);
@@ -1893,6 +1988,7 @@ START_TEST(filtergraph)
         skip("Creating filtergraph returned %08x, skipping tests\n", hr);
         return;
     }
+    IGraphBuilder_Release(pgraph);
     test_render_run(avifile);
     test_render_run(mpegfile);
     test_graph_builder();
@@ -1900,5 +1996,6 @@ START_TEST(filtergraph)
     test_mediacontrol();
     test_filter_graph2();
     test_render_filter_priority();
+    test_aggregate_filter_graph();
     CoUninitialize();
 }