ReactOS 0.4.15-dev-7942-gd23573b
CComQIPtr.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for CComQIPtr
5 * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include <atlbase.h>
9#include <atlcom.h>
10
11#ifdef HAVE_APITEST
12 #include <apitest.h>
13#else
14 #include "atltest.h"
15#endif
16
17
18static LONG g_QI = 0;
19
21 public IPersist,
22 public IStdMarshalInfo
23{
24public:
26
28 :m_dwRef(1)
29 {
30 }
32 {
33 }
34
36 {
38 return 2;
39 }
40
42 {
44 return 1;
45 }
46
48 {
50 if (iid == IID_IUnknown || iid == IID_IPersist)
51 {
52 AddRef();
53 *ppvObject = static_cast<IPersist*>(this);
54 return S_OK;
55 }
56 else if (iid == IID_IStdMarshalInfo)
57 {
58 AddRef();
59 *ppvObject = static_cast<IStdMarshalInfo*>(this);
60 return S_OK;
61 }
62 return E_NOINTERFACE;
63 }
64
65 // *** IPersist methods ***
67 {
68 return E_NOTIMPL;
69 }
70
71 // *** IStdMarshalInfo methods ***
72 STDMETHOD(GetClassForHandler)(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid)
73 {
74 return E_NOTIMPL;
75 }
76};
77
78// Yes this sucks, but we have to support GCC. (CORE-12710)
79#ifdef __REACTOS__
80#define DECLARE_QIPTR(type) CComQIIDPtr<I_ID(type)>
81#elif defined(__GNUC__)
82#define DECLARE_QIPTR(type) CComQIIDPtr<I_ID(type)>
83#elif defined(__RATL__)
84#define DECLARE_QIPTR(type) CComQIIDPtr<I_ID(type)>
85#else
86#define DECLARE_QIPTR(type) CComQIPtr<type>
87#endif
88
89START_TEST(CComQIPtr)
90{
91 CQITestObject testObject;
92 IUnknown* unk = static_cast<IPersist*>(&testObject);
93 ok_long(testObject.m_dwRef, 1);
94 ok_long(g_QI, 0);
95
96 {
97 DECLARE_QIPTR(IPersist) ppPersist(unk);
98 ok_long(testObject.m_dwRef, 2);
99 ok_long(g_QI, 1);
100
101 DECLARE_QIPTR(IStdMarshalInfo) ppMarshal(ppPersist);
102 ok_long(testObject.m_dwRef, 3);
103 ok_long(g_QI, 2);
104 }
105 ok_long(testObject.m_dwRef, 1);
106 {
108 ok_long(testObject.m_dwRef, 1);
109 ok_long(g_QI, 2);
110
111 ppMarshal = unk;
112 ok_long(testObject.m_dwRef, 2);
113 ok_long(g_QI, 3);
114
115 ppMarshal = static_cast<IUnknown*>(NULL);
116 ok_long(testObject.m_dwRef, 1);
117 ok_long(g_QI, 3);
118
119 CComPtr<IUnknown> spUnk(unk);
120 ok_long(testObject.m_dwRef, 2);
121 ok_long(g_QI, 3);
122
123 ppMarshal = spUnk;
124 ok_long(testObject.m_dwRef, 3);
125 ok_long(g_QI, 4);
126
127 spUnk.Release();
128 ok_long(testObject.m_dwRef, 2);
129 ok_long(g_QI, 4);
130
131 spUnk = ppMarshal;
132 ok_long(testObject.m_dwRef, 3);
133#ifdef __REACTOS__
134 // CORE-12710
135 todo_if(1)
136#endif
137 ok_long(g_QI, 5);
138 }
139}
#define DECLARE_QIPTR(type)
Definition: CComQIPtr.cpp:86
static LONG g_QI
Definition: CComQIPtr.cpp:18
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define ok_long(expression, result)
Definition: atltest.h:133
#define START_TEST(x)
Definition: atltest.h:75
#define STDMETHOD(m)
Definition: basetyps.h:62
const GUID IID_IUnknown
STDMETHOD() QueryInterface(REFIID iid, void **ppvObject)
Definition: CComQIPtr.cpp:47
STDMETHOD_(ULONG, AddRef)()
Definition: CComQIPtr.cpp:35
STDMETHOD() GetClassID(CLSID *pClassID)
Definition: CComQIPtr.cpp:66
STDMETHOD_(ULONG, Release)()
Definition: CComQIPtr.cpp:41
STDMETHOD() GetClassForHandler(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid)
Definition: CComQIPtr.cpp:72
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG AddRef()
ULONG Release()
#define S_OK
Definition: intsafe.h:52
long LONG
Definition: pedump.c:60
const GUID IID_IPersist
Definition: proxy.cpp:14
#define REFIID
Definition: guiddef.h:118
#define todo_if(is_todo)
Definition: test.h:163
uint32_t ULONG
Definition: typedefs.h:59
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define E_NOINTERFACE
Definition: winerror.h:2364