ReactOS 0.4.17-dev-966-gf06eace
passthrough.c
Go to the documentation of this file.
1/*
2 * Seeking passthrough unit tests
3 *
4 * Copyright 2020 Zebediah Figura for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21#define COBJMACROS
22#include "dshow.h"
23#include "wine/test.h"
24
25static ULONG get_refcount(void *iface)
26{
27 IUnknown *unknown = iface;
28 IUnknown_AddRef(unknown);
29 return IUnknown_Release(unknown);
30}
31
32static const GUID test_iid = {0x33333333};
33static LONG outer_ref = 1;
34
36{
37 if (IsEqualGUID(iid, &IID_IUnknown)
38 || IsEqualGUID(iid, &IID_ISeekingPassThru)
39 || IsEqualGUID(iid, &test_iid))
40 {
41 *out = (IUnknown *)0xdeadbeef;
42 return S_OK;
43 }
44 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
45 return E_NOINTERFACE;
46}
47
49{
51}
52
54{
56}
57
58static const IUnknownVtbl outer_vtbl =
59{
63};
64
66
67static void test_aggregation(void)
68{
69 ISeekingPassThru *passthrough, *passthrough2;
70 IUnknown *unk, *unk2;
71 HRESULT hr;
72 ULONG ref;
73
74 passthrough = (ISeekingPassThru *)0xdeadbeef;
75 hr = CoCreateInstance(&CLSID_SeekingPassThru, &test_outer, CLSCTX_INPROC_SERVER,
76 &IID_ISeekingPassThru, (void **)&passthrough);
77 ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr);
78 ok(!passthrough, "Got interface %p.\n", passthrough);
79
80 hr = CoCreateInstance(&CLSID_SeekingPassThru, &test_outer, CLSCTX_INPROC_SERVER,
81 &IID_IUnknown, (void **)&unk);
82 ok(hr == S_OK, "Got hr %#lx.\n", hr);
83 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
84 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
85 ref = get_refcount(unk);
86 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
87
88 ref = IUnknown_AddRef(unk);
89 ok(ref == 2, "Got unexpected refcount %ld.\n", ref);
90 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
91
92 ref = IUnknown_Release(unk);
93 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
94 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
95
96 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
97 ok(hr == S_OK, "Got hr %#lx.\n", hr);
98 ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
99 IUnknown_Release(unk2);
100
101 hr = IUnknown_QueryInterface(unk, &IID_ISeekingPassThru, (void **)&passthrough);
102 ok(hr == S_OK, "Got hr %#lx.\n", hr);
103
104 hr = ISeekingPassThru_QueryInterface(passthrough, &IID_IUnknown, (void **)&unk2);
105 ok(hr == S_OK, "Got hr %#lx.\n", hr);
106 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
107
108 hr = ISeekingPassThru_QueryInterface(passthrough, &IID_ISeekingPassThru, (void **)&passthrough2);
109 ok(hr == S_OK, "Got hr %#lx.\n", hr);
110 ok(passthrough2 == (ISeekingPassThru *)0xdeadbeef, "Got unexpected ISeekingPassThru %p.\n", passthrough2);
111
112 hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
113 ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr);
114 ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
115
116 hr = ISeekingPassThru_QueryInterface(passthrough, &test_iid, (void **)&unk2);
117 ok(hr == S_OK, "Got hr %#lx.\n", hr);
118 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
119
120 ISeekingPassThru_Release(passthrough);
121 ref = IUnknown_Release(unk);
122 ok(!ref, "Got unexpected refcount %ld.\n", ref);
123 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
124}
125
126START_TEST(passthrough)
127{
129
131
133}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
const GUID IID_IUnknown
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1674
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define S_OK
Definition: intsafe.h:52
static const IUnknownVtbl outer_vtbl
Definition: passthrough.c:58
static void test_aggregation(void)
Definition: passthrough.c:67
static ULONG WINAPI outer_AddRef(IUnknown *iface)
Definition: passthrough.c:48
static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
Definition: passthrough.c:35
static ULONG get_refcount(void *iface)
Definition: passthrough.c:25
static IUnknown test_outer
Definition: passthrough.c:65
static LONG outer_ref
Definition: passthrough.c:33
static const GUID test_iid
Definition: passthrough.c:32
static ULONG WINAPI outer_Release(IUnknown *iface)
Definition: passthrough.c:53
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:181
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:3479