ReactOS 0.4.15-dev-8241-g63935f8
CComObject.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 CComObject
5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8
9#include <atlbase.h>
10#include <atlcom.h>
11
12#ifdef HAVE_APITEST
13 #include <apitest.h>
14#else
15 #include "atltest.h"
16#endif
17
18
19static LONG g_CTOR = 0;
20static LONG g_DTOR = 0;
21static LONG g_BLIND = 0;
22
24 public CComObjectRootEx<CComMultiThreadModelNoCS>,
25 public IPersist,
26 public IStdMarshalInfo
27{
28public:
30 {
32 }
34 {
36 }
37
38 // *** IPersist methods ***
40 {
41 return E_NOTIMPL;
42 }
43
44 // *** IStdMarshalInfo methods ***
45 virtual HRESULT STDMETHODCALLTYPE GetClassForHandler(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid)
46 {
47 return E_NOTIMPL;
48 }
49
51 {
53 return E_FAIL;
54 }
55
58
60 COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist) /* First entry has to be a simple entry, otherwise ATL asserts */
61 COM_INTERFACE_ENTRY_FUNC_BLIND(0, FuncBlind) /* Showing that even after a Blind func, entryies can be found */
62 COM_INTERFACE_ENTRY_IID(IID_IStdMarshalInfo, IStdMarshalInfo)
64};
65
66#ifndef __RATL__ // Avoid conflict (causing assertion at CAtlModule::CAtlModule)
67class CDumExe: public CAtlExeModuleT<CDumExe>
68{
69
70};
72#endif
73
74START_TEST(CComObject)
75{
76 g_CTOR = g_DTOR = g_BLIND = 0;
77
78 CComObject<CTestObject>* pTest;
79 HRESULT hr = CComObject<CTestObject>::CreateInstance(&pTest);
80
81 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
82
83 ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR);
84 ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR);
85 ok(g_BLIND == 0, "Expected 0, got %lu\n", g_BLIND);
86
87 if (hr == S_OK)
88 {
89 ULONG ref = pTest->AddRef();
90 ok(ref == 1, "Expected 1, got %lu\n", ref);
91
92 {
93 CComPtr<IUnknown> ppv;
94 hr = pTest->QueryInterface(IID_IUnknown, (void **) &ppv);
95 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
96 ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR);
97 ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR);
98 ok(g_BLIND == 0, "Expected 0, got %lu\n", g_BLIND);
99
100 CComPtr<IPersist> ppersist;
101 hr = pTest->QueryInterface(IID_IPersist, (void **)&ppersist);
102 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
103 ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR);
104 ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR);
105 ok(g_BLIND == 0, "Expected 0, got %lu\n", g_BLIND);
106
107 }
108
109 {
110 CComPtr<IStdMarshalInfo> pstd;
111 hr = pTest->QueryInterface(IID_IStdMarshalInfo, (void **)&pstd);
112 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
113 ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR);
114 ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR);
115 ok(g_BLIND == 1, "Expected 1, got %lu\n", g_BLIND);
116 }
117
118 ref = pTest->Release();
119 ok(ref == 0, "Expected 0, got %lu\n", ref);
120 ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR);
121 ok(g_DTOR == 1, "Expected 1, got %lu\n", g_DTOR);
122 ok(g_BLIND == 1, "Expected 1, got %lu\n", g_BLIND);
123 }
124}
static LONG g_CTOR
Definition: CComObject.cpp:19
static LONG g_DTOR
Definition: CComObject.cpp:20
static LONG g_BLIND
Definition: CComObject.cpp:21
CDumExe dum
Definition: CComObject.cpp:71
#define InterlockedIncrement
Definition: armddk.h:53
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID)
Definition: CComObject.cpp:39
static HRESULT WINAPI FuncBlind(void *pv, REFIID riid, LPVOID *ppv, DWORD_PTR dw)
Definition: CComObject.cpp:50
virtual HRESULT STDMETHODCALLTYPE GetClassForHandler(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid)
Definition: CComObject.cpp:45
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define COM_INTERFACE_ENTRY_FUNC_BLIND(dw, func)
Definition: atlcom.h:629
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define END_COM_MAP()
Definition: atlcom.h:592
long LONG
Definition: pedump.c:60
const GUID IID_IPersist
Definition: proxy.cpp:14
#define REFIID
Definition: guiddef.h:118
HRESULT hr
Definition: shlfolder.c:183
Definition: send.c:48
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6