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)
17 int g_tests_executed
= 0;
18 int g_tests_failed
= 0;
19 void ok_func(const char *file
, int line
, BOOL value
, const char *fmt
, ...)
25 printf("%s (%d): ", file
, line
);
33 #define ok(value, ...) ok_func(__FILE__, __LINE__, value, __VA_ARGS__)
34 #define START_TEST(x) int main(void)
42 public IStdMarshalInfo
55 STDMETHOD_(ULONG
, AddRef
)()
57 InterlockedIncrement(&m_dwRef
);
61 STDMETHOD_(ULONG
, Release
)()
63 InterlockedDecrement(&m_dwRef
);
67 STDMETHOD(QueryInterface
)(REFIID iid
, void **ppvObject
)
69 InterlockedIncrement(&g_QI
);
70 if (iid
== IID_IUnknown
|| iid
== IID_IPersist
)
73 *ppvObject
= static_cast<IPersist
*>(this);
76 else if (iid
== IID_IStdMarshalInfo
)
79 *ppvObject
= static_cast<IStdMarshalInfo
*>(this);
85 // *** IPersist methods ***
86 STDMETHOD(GetClassID
)(CLSID
*pClassID
)
91 // *** IStdMarshalInfo methods ***
92 STDMETHOD(GetClassForHandler
)(DWORD dwDestContext
, void *pvDestContext
, CLSID
*pClsid
)
98 // Yes this sucks, but we have to support GCC. (CORE-12710)
100 #define DECLARE_QIPTR(type) CComQIIDPtr<I_ID(type)>
102 #define DECLARE_QIPTR(type) CComQIPtr<type>
105 START_TEST(CComQIPtr
)
107 CQITestObject testObject
;
108 IUnknown
* unk
= static_cast<IPersist
*>(&testObject
);
109 ok(testObject
.m_dwRef
== 1, "Expected m_dwRef 1, got %lu\n", testObject
.m_dwRef
);
110 ok(g_QI
== 0, "Expected g_QI 0, got %lu\n", g_QI
);
113 DECLARE_QIPTR(IPersist
) ppPersist(unk
);
114 ok(testObject
.m_dwRef
== 2, "Expected m_dwRef 2, got %lu\n", testObject
.m_dwRef
);
115 ok(g_QI
== 1, "Expected g_QI 1, got %lu\n", g_QI
);
117 DECLARE_QIPTR(IStdMarshalInfo
) ppMarshal(ppPersist
);
118 ok(testObject
.m_dwRef
== 3, "Expected m_dwRef 3, got %lu\n", testObject
.m_dwRef
);
119 ok(g_QI
== 2, "Expected g_QI 2, got %lu\n", g_QI
);
121 ok(testObject
.m_dwRef
== 1, "Expected m_dwRef 1, got %lu\n", testObject
.m_dwRef
);
123 DECLARE_QIPTR(IStdMarshalInfo
) ppMarshal
;
124 ok(testObject
.m_dwRef
== 1, "Expected m_dwRef 1, got %lu\n", testObject
.m_dwRef
);
125 ok(g_QI
== 2, "Expected g_QI 2, got %lu\n", g_QI
);
128 ok(testObject
.m_dwRef
== 2, "Expected m_dwRef 2, got %lu\n", testObject
.m_dwRef
);
129 ok(g_QI
== 3, "Expected g_QI 3, got %lu\n", g_QI
);
131 ppMarshal
= static_cast<IUnknown
*>(NULL
);
132 ok(testObject
.m_dwRef
== 1, "Expected m_dwRef 1, got %lu\n", testObject
.m_dwRef
);
133 ok(g_QI
== 3, "Expected g_QI 3, got %lu\n", g_QI
);
135 CComPtr
<IUnknown
> spUnk(unk
);
136 ok(testObject
.m_dwRef
== 2, "Expected m_dwRef 2, got %lu\n", testObject
.m_dwRef
);
137 ok(g_QI
== 3, "Expected g_QI 3, got %lu\n", g_QI
);
140 ok(testObject
.m_dwRef
== 3, "Expected m_dwRef 3, got %lu\n", testObject
.m_dwRef
);
141 ok(g_QI
== 4, "Expected g_QI 4, got %lu\n", g_QI
);
144 ok(testObject
.m_dwRef
== 2, "Expected m_dwRef 2, got %lu\n", testObject
.m_dwRef
);
145 ok(g_QI
== 4, "Expected g_QI 4, got %lu\n", g_QI
);
148 ok(testObject
.m_dwRef
== 3, "Expected m_dwRef 3, got %lu\n", testObject
.m_dwRef
);
153 ok(g_QI
== 5, "Expected g_QI 5, got %lu\n", g_QI
);
157 printf("CComQIPtr: %i tests executed (0 marked as todo, %i failures), 0 skipped.\n", g_tests_executed
, g_tests_failed
);
158 return g_tests_failed
;