https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4b8f6d5eaba7d55dfd2e33...
commit 4b8f6d5eaba7d55dfd2e339d4d4564a62da1353b Author: Mark Jansen mark.jansen@reactos.org AuthorDate: Sun Aug 5 11:50:02 2018 +0200 Commit: Mark Jansen mark.jansen@reactos.org CommitDate: Sun Aug 19 17:35:18 2018 +0200
[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 + modules/rostests/apitests/atl/devenv/ATLTest.sln | 10 ++ .../apitests/atl/devenv/CComObject.vcxproj | 4 - .../{CSimpleMap.vcxproj => CComQIPtr.vcxproj} | 10 +- .../rostests/apitests/atl/devenv/CImage.vcxproj | 4 - .../apitests/atl/devenv/CSimpleArray.vcxproj | 4 - .../apitests/atl/devenv/CSimpleMap.vcxproj | 4 - .../rostests/apitests/atl/devenv/CString.vcxproj | 4 - modules/rostests/apitests/atl/testlist.c | 2 + 10 files changed, 176 insertions(+), 27 deletions(-)
diff --git a/modules/rostests/apitests/atl/CComQIPtr.cpp b/modules/rostests/apitests/atl/CComQIPtr.cpp new file mode 100644 index 0000000000..f9fedb6898 --- /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 <atlbase.h> +#include <atlcom.h> + +#ifdef __REACTOS__ + #include <apitest.h> +#else + #include <stdlib.h> + #include <stdio.h> + #include <stdarg.h> + 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<IPersist*>(this); + return S_OK; + } + else if (iid == IID_IStdMarshalInfo) + { + AddRef(); + *ppvObject = static_cast<IStdMarshalInfo*>(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<I_ID(type)> +#else +#define DECLARE_QIPTR(type) CComQIPtr<type> +#endif + +START_TEST(CComQIPtr) +{ + CQITestObject testObject; + IUnknown* unk = static_cast<IPersist*>(&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<IUnknown*>(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<IUnknown> 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 fbc1420dec..3cbf35bc09 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 d9d18dddb6..b36db07333 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 ac525e52d9..97903a9250 100644 --- a/modules/rostests/apitests/atl/devenv/CComObject.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CComObject.vcxproj @@ -98,7 +98,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>false</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -117,7 +116,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -138,7 +136,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -159,7 +156,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj b/modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj similarity index 96% copy from modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj copy to modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj index f7e7549036..345f1d8ea1 100644 --- a/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CComQIPtr.vcxproj @@ -19,7 +19,7 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{EC560DE6-6DB3-437D-85CA-582491FE6F95}</ProjectGuid> + <ProjectGuid>{907AEF87-D169-4A2F-A9E3-FF3DD1D59E65}</ProjectGuid> <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> <Keyword>AtlProj</Keyword> </PropertyGroup> @@ -39,8 +39,8 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120_xp</PlatformToolset> <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v120_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> @@ -98,7 +98,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>false</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -117,7 +116,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -138,7 +136,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -159,11 +156,10 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemGroup> - <ClCompile Include="../CSimpleMap.cpp"> + <ClCompile Include="../CComQIPtr.cpp"> <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MultiThreaded</RuntimeLibrary> <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MultiThreaded</RuntimeLibrary> <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MultiThreadedDebug</RuntimeLibrary> diff --git a/modules/rostests/apitests/atl/devenv/CImage.vcxproj b/modules/rostests/apitests/atl/devenv/CImage.vcxproj index 5c77112862..80984b87c9 100644 --- a/modules/rostests/apitests/atl/devenv/CImage.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CImage.vcxproj @@ -98,7 +98,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>false</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -117,7 +116,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -138,7 +136,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -159,7 +156,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj b/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj index 8053eea219..76b03d7598 100644 --- a/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CSimpleArray.vcxproj @@ -98,7 +98,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>false</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -117,7 +116,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -138,7 +136,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -159,7 +156,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj b/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj index f7e7549036..03862264d7 100644 --- a/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CSimpleMap.vcxproj @@ -98,7 +98,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>false</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -117,7 +116,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -138,7 +136,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -159,7 +156,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/modules/rostests/apitests/atl/devenv/CString.vcxproj b/modules/rostests/apitests/atl/devenv/CString.vcxproj index 82dfc4687b..8772a16814 100644 --- a/modules/rostests/apitests/atl/devenv/CString.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CString.vcxproj @@ -98,7 +98,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>false</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -117,7 +116,6 @@ <Link> <SubSystem>Console</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -138,7 +136,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -159,7 +156,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <RegisterOutput>true</RegisterOutput> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/modules/rostests/apitests/atl/testlist.c b/modules/rostests/apitests/atl/testlist.c index 0c40c3b140..232785a4b8 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 },