ReactOS  0.4.15-dev-313-g8fde48b
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 
18 static LONG g_QI = 0;
19 
21  public IPersist,
22  public IStdMarshalInfo
23 {
24 public:
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 #else
84 #define DECLARE_QIPTR(type) CComQIPtr<type>
85 #endif
86 
87 START_TEST(CComQIPtr)
88 {
89  CQITestObject testObject;
90  IUnknown* unk = static_cast<IPersist*>(&testObject);
91  ok_long(testObject.m_dwRef, 1);
92  ok_long(g_QI, 0);
93 
94  {
95  DECLARE_QIPTR(IPersist) ppPersist(unk);
96  ok_long(testObject.m_dwRef, 2);
97  ok_long(g_QI, 1);
98 
99  DECLARE_QIPTR(IStdMarshalInfo) ppMarshal(ppPersist);
100  ok_long(testObject.m_dwRef, 3);
101  ok_long(g_QI, 2);
102  }
103  ok_long(testObject.m_dwRef, 1);
104  {
105  DECLARE_QIPTR(IStdMarshalInfo) ppMarshal;
106  ok_long(testObject.m_dwRef, 1);
107  ok_long(g_QI, 2);
108 
109  ppMarshal = unk;
110  ok_long(testObject.m_dwRef, 2);
111  ok_long(g_QI, 3);
112 
113  ppMarshal = static_cast<IUnknown*>(NULL);
114  ok_long(testObject.m_dwRef, 1);
115  ok_long(g_QI, 3);
116 
117  CComPtr<IUnknown> spUnk(unk);
118  ok_long(testObject.m_dwRef, 2);
119  ok_long(g_QI, 3);
120 
121  ppMarshal = spUnk;
122  ok_long(testObject.m_dwRef, 3);
123  ok_long(g_QI, 4);
124 
125  spUnk.Release();
126  ok_long(testObject.m_dwRef, 2);
127  ok_long(g_QI, 4);
128 
129  spUnk = ppMarshal;
130  ok_long(testObject.m_dwRef, 3);
131 #ifdef __REACTOS__
132  // CORE-12710
133  todo_if(1)
134 #endif
135  ok_long(g_QI, 5);
136  }
137 }
STDMETHOD() GetClassID(CLSID *pClassID)
Definition: CComQIPtr.cpp:66
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
const GUID IID_IPersist
Definition: proxy.cpp:14
STDMETHOD_(ULONG, Release)()
Definition: CComQIPtr.cpp:41
START_TEST(CComQIPtr)
Definition: CComQIPtr.cpp:87
#define ok_long(expression, result)
Definition: atltest.h:133
STDMETHOD_(ULONG, AddRef)()
Definition: CComQIPtr.cpp:35
#define STDMETHOD(m)
Definition: basetyps.h:62
long LONG
Definition: pedump.c:60
ULONG Release()
smooth NULL
Definition: ftsmooth.c:416
#define DECLARE_QIPTR(type)
Definition: CComQIPtr.cpp:84
static LONG g_QI
Definition: CComQIPtr.cpp:18
const GUID IID_IUnknown
#define todo_if(is_todo)
Definition: test.h:152
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG AddRef()
#define InterlockedDecrement
Definition: armddk.h:52
REFIID LPVOID * ppvObject
Definition: precomp.h:44
STDMETHOD() GetClassForHandler(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid)
Definition: CComQIPtr.cpp:72
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int ULONG
Definition: retypes.h:1
STDMETHOD() QueryInterface(REFIID iid, void **ppvObject)
Definition: CComQIPtr.cpp:47