From 4b8f6d5eaba7d55dfd2e339d4d4564a62da1353b Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sun, 5 Aug 2018 11:50:02 +0200 Subject: [PATCH] [ATL_APITEST] Add test for CComQIPtr (or rather, our gcc hack that slightly looks like it) --- modules/rostests/apitests/atl/CComQIPtr.cpp | 160 ++++++++++++++++ modules/rostests/apitests/atl/CMakeLists.txt | 1 + .../rostests/apitests/atl/devenv/ATLTest.sln | 10 + .../apitests/atl/devenv/CComObject.vcxproj | 4 - .../apitests/atl/devenv/CComQIPtr.vcxproj | 176 ++++++++++++++++++ .../apitests/atl/devenv/CImage.vcxproj | 4 - .../apitests/atl/devenv/CSimpleArray.vcxproj | 4 - .../apitests/atl/devenv/CSimpleMap.vcxproj | 4 - .../apitests/atl/devenv/CString.vcxproj | 4 - modules/rostests/apitests/atl/testlist.c | 2 + 10 files changed, 349 insertions(+), 20 deletions(-) create mode 100644 modules/rostests/apitests/atl/CComQIPtr.cpp create mode 100644 modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj diff --git a/modules/rostests/apitests/atl/CComQIPtr.cpp b/modules/rostests/apitests/atl/CComQIPtr.cpp new file mode 100644 index 00000000000..f9fedb68986 --- /dev/null +++ b/modules/rostests/apitests/atl/CComQIPtr.cpp @@ -0,0 +1,160 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Test for CComQIPtr + * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org) + */ + +#include +#include + +#ifdef __REACTOS__ + #include +#else + #include + #include + #include + int g_tests_executed = 0; + int g_tests_failed = 0; + void ok_func(const char *file, int line, BOOL value, const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + if (!value) + { + printf("%s (%d): ", file, line); + vprintf(fmt, va); + g_tests_failed++; + } + g_tests_executed++; + va_end(va); + } + #undef ok + #define ok(value, ...) ok_func(__FILE__, __LINE__, value, __VA_ARGS__) + #define START_TEST(x) int main(void) +#endif + + +static LONG g_QI = 0; + +class CQITestObject : + public IPersist, + public IStdMarshalInfo +{ +public: + LONG m_dwRef; + + CQITestObject() + :m_dwRef(1) + { + } + ~CQITestObject() + { + } + + STDMETHOD_(ULONG, AddRef)() + { + InterlockedIncrement(&m_dwRef); + return 2; + } + + STDMETHOD_(ULONG, Release)() + { + InterlockedDecrement(&m_dwRef); + return 1; + } + + STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject) + { + InterlockedIncrement(&g_QI); + if (iid == IID_IUnknown || iid == IID_IPersist) + { + AddRef(); + *ppvObject = static_cast(this); + return S_OK; + } + else if (iid == IID_IStdMarshalInfo) + { + AddRef(); + *ppvObject = static_cast(this); + return S_OK; + } + return E_NOINTERFACE; + } + + // *** IPersist methods *** + STDMETHOD(GetClassID)(CLSID *pClassID) + { + return E_NOTIMPL; + } + + // *** IStdMarshalInfo methods *** + STDMETHOD(GetClassForHandler)(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid) + { + return E_NOTIMPL; + } +}; + +// Yes this sucks, but we have to support GCC. (CORE-12710) +#ifdef __REACTOS__ +#define DECLARE_QIPTR(type) CComQIIDPtr +#else +#define DECLARE_QIPTR(type) CComQIPtr +#endif + +START_TEST(CComQIPtr) +{ + CQITestObject testObject; + IUnknown* unk = static_cast(&testObject); + ok(testObject.m_dwRef == 1, "Expected m_dwRef 1, got %lu\n", testObject.m_dwRef); + ok(g_QI == 0, "Expected g_QI 0, got %lu\n", g_QI); + + { + DECLARE_QIPTR(IPersist) ppPersist(unk); + ok(testObject.m_dwRef == 2, "Expected m_dwRef 2, got %lu\n", testObject.m_dwRef); + ok(g_QI == 1, "Expected g_QI 1, got %lu\n", g_QI); + + DECLARE_QIPTR(IStdMarshalInfo) ppMarshal(ppPersist); + ok(testObject.m_dwRef == 3, "Expected m_dwRef 3, got %lu\n", testObject.m_dwRef); + ok(g_QI == 2, "Expected g_QI 2, got %lu\n", g_QI); + } + ok(testObject.m_dwRef == 1, "Expected m_dwRef 1, got %lu\n", testObject.m_dwRef); + { + DECLARE_QIPTR(IStdMarshalInfo) ppMarshal; + ok(testObject.m_dwRef == 1, "Expected m_dwRef 1, got %lu\n", testObject.m_dwRef); + ok(g_QI == 2, "Expected g_QI 2, got %lu\n", g_QI); + + ppMarshal = unk; + ok(testObject.m_dwRef == 2, "Expected m_dwRef 2, got %lu\n", testObject.m_dwRef); + ok(g_QI == 3, "Expected g_QI 3, got %lu\n", g_QI); + + ppMarshal = static_cast(NULL); + ok(testObject.m_dwRef == 1, "Expected m_dwRef 1, got %lu\n", testObject.m_dwRef); + ok(g_QI == 3, "Expected g_QI 3, got %lu\n", g_QI); + + CComPtr spUnk(unk); + ok(testObject.m_dwRef == 2, "Expected m_dwRef 2, got %lu\n", testObject.m_dwRef); + ok(g_QI == 3, "Expected g_QI 3, got %lu\n", g_QI); + + ppMarshal = spUnk; + ok(testObject.m_dwRef == 3, "Expected m_dwRef 3, got %lu\n", testObject.m_dwRef); + ok(g_QI == 4, "Expected g_QI 4, got %lu\n", g_QI); + + spUnk.Release(); + ok(testObject.m_dwRef == 2, "Expected m_dwRef 2, got %lu\n", testObject.m_dwRef); + ok(g_QI == 4, "Expected g_QI 4, got %lu\n", g_QI); + + spUnk = ppMarshal; + ok(testObject.m_dwRef == 3, "Expected m_dwRef 3, got %lu\n", testObject.m_dwRef); +#ifdef __REACTOS__ + // CORE-12710 + todo_if(1) +#endif + ok(g_QI == 5, "Expected g_QI 5, got %lu\n", g_QI); + } + +#ifndef __REACTOS__ + printf("CComQIPtr: %i tests executed (0 marked as todo, %i failures), 0 skipped.\n", g_tests_executed, g_tests_failed); + return g_tests_failed; +#endif +} diff --git a/modules/rostests/apitests/atl/CMakeLists.txt b/modules/rostests/apitests/atl/CMakeLists.txt index fbc1420decf..3cbf35bc09d 100644 --- a/modules/rostests/apitests/atl/CMakeLists.txt +++ b/modules/rostests/apitests/atl/CMakeLists.txt @@ -9,6 +9,7 @@ list(APPEND SOURCE CComBSTR.cpp CComHeapPtr.cpp CComObject.cpp + CComQIPtr.cpp CImage.cpp CRegKey.cpp CSimpleArray.cpp diff --git a/modules/rostests/apitests/atl/devenv/ATLTest.sln b/modules/rostests/apitests/atl/devenv/ATLTest.sln index d9d18dddb67..b36db073331 100644 --- a/modules/rostests/apitests/atl/devenv/ATLTest.sln +++ b/modules/rostests/apitests/atl/devenv/ATLTest.sln @@ -13,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CString", "CString.vcxproj" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CComObject", "CComObject.vcxproj", "{408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CComQIPtr", "CComQIPtr.vcxproj", "{907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -61,6 +63,14 @@ Global {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x64.Build.0 = Release|x64 {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x86.ActiveCfg = Release|Win32 {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x86.Build.0 = Release|Win32 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x64.ActiveCfg = Debug|x64 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x64.Build.0 = Debug|x64 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x86.ActiveCfg = Debug|Win32 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x86.Build.0 = Debug|Win32 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x64.ActiveCfg = Release|x64 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x64.Build.0 = Release|x64 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x86.ActiveCfg = Release|Win32 + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/modules/rostests/apitests/atl/devenv/CComObject.vcxproj b/modules/rostests/apitests/atl/devenv/CComObject.vcxproj index ac525e52d9d..97903a9250c 100644 --- a/modules/rostests/apitests/atl/devenv/CComObject.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CComObject.vcxproj @@ -98,7 +98,6 @@ Console true - false @@ -117,7 +116,6 @@ Console true - true @@ -138,7 +136,6 @@ true true true - true @@ -159,7 +156,6 @@ true true true - true diff --git a/modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj b/modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj new file mode 100644 index 00000000000..345f1d8ea14 --- /dev/null +++ b/modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj @@ -0,0 +1,176 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {907AEF87-D169-4A2F-A9E3-FF3DD1D59E65} + 8.1 + AtlProj + + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + Application + true + Unicode + v120_xp + + + Application + false + v120_xp + Unicode + + + + + + + + + + + + + + + + + + + + + true + true + + + true + true + + + true + false + + + true + false + + + + NotUsing + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + + + + + NotUsing + Level3 + Disabled + _WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + + + + + NotUsing + Level3 + MaxSpeed + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + MultiThreaded + MultiThreaded + MultiThreadedDebug + MultiThreadedDebug + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + \ No newline at end of file diff --git a/modules/rostests/apitests/atl/devenv/CImage.vcxproj b/modules/rostests/apitests/atl/devenv/CImage.vcxproj index 5c77112862d..80984b87c90 100644 --- a/modules/rostests/apitests/atl/devenv/CImage.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CImage.vcxproj @@ -98,7 +98,6 @@ Console true - false @@ -117,7 +116,6 @@ Console true - true @@ -138,7 +136,6 @@ true true true - true @@ -159,7 +156,6 @@ true true true - true diff --git a/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj b/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj index 8053eea2193..76b03d7598e 100644 --- a/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj @@ -98,7 +98,6 @@ Console true - false @@ -117,7 +116,6 @@ Console true - true @@ -138,7 +136,6 @@ true true true - true @@ -159,7 +156,6 @@ true true true - true diff --git a/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj b/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj index f7e75490367..03862264d7f 100644 --- a/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj @@ -98,7 +98,6 @@ Console true - false @@ -117,7 +116,6 @@ Console true - true @@ -138,7 +136,6 @@ true true true - true @@ -159,7 +156,6 @@ true true true - true diff --git a/modules/rostests/apitests/atl/devenv/CString.vcxproj b/modules/rostests/apitests/atl/devenv/CString.vcxproj index 82dfc4687b4..8772a168149 100644 --- a/modules/rostests/apitests/atl/devenv/CString.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CString.vcxproj @@ -98,7 +98,6 @@ Console true - false @@ -117,7 +116,6 @@ Console true - true @@ -138,7 +136,6 @@ true true true - true @@ -159,7 +156,6 @@ true true true - true diff --git a/modules/rostests/apitests/atl/testlist.c b/modules/rostests/apitests/atl/testlist.c index 0c40c3b140c..232785a4b86 100644 --- a/modules/rostests/apitests/atl/testlist.c +++ b/modules/rostests/apitests/atl/testlist.c @@ -5,6 +5,7 @@ extern void func_atltypes(void); extern void func_CComBSTR(void); extern void func_CComHeapPtr(void); extern void func_CComObject(void); +extern void func_CComQIPtr(void); extern void func_CComVariant(void); extern void func_CImage(void); extern void func_CRegKey(void); @@ -18,6 +19,7 @@ const struct test winetest_testlist[] = { "CComBSTR", func_CComBSTR }, { "CComHeapPtr", func_CComHeapPtr }, { "CComObject", func_CComObject }, + { "CComQIPtr", func_CComQIPtr }, { "CComVariant", func_CComVariant }, { "CImage", func_CImage }, { "CRegKey", func_CRegKey },