Reactos

[ATL][ATL_APITEST] Test + implement CHeapPtrList

+340 -1
+1
modules/rostests/apitests/atl/CComVariant.cpp
··· 6 6 */ 7 7 8 8 /* In case we are building against the MS headers, we need to disable assertions. */ 9 + #undef ATLASSERT 9 10 #define ATLASSERT(x) 10 11 #define _ATL_NO_VARIANT_THROW 11 12
+117
modules/rostests/apitests/atl/CHeapPtrList.cpp
··· 1 + /* 2 + * PROJECT: ReactOS api tests 3 + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4 + * PURPOSE: Test for CHeapPtrList 5 + * COPYRIGHT: Copyright 2020 Mark Jansen (mark.jansen@reactos.org) 6 + */ 7 + 8 + #ifdef HAVE_APITEST 9 + #include <apitest.h> 10 + #else 11 + #include "atltest.h" 12 + #endif 13 + #include <atlcoll.h> 14 + 15 + static PDWORD 16 + test_Alloc(DWORD value) 17 + { 18 + PDWORD ptr = (PDWORD)::CoTaskMemAlloc(sizeof(DWORD)); 19 + *ptr = value; 20 + return ptr; 21 + } 22 + 23 + // We use the CComAllocator, so we can easily spy on it 24 + template <typename T> 25 + class CComHeapPtrList : 26 + public CHeapPtrList<T, CComAllocator> 27 + { 28 + public: 29 + CComHeapPtrList(_In_ UINT nBlockSize = 10) throw() 30 + :CHeapPtrList<T, CComAllocator>(nBlockSize) 31 + { 32 + } 33 + }; 34 + 35 + 36 + 37 + static LONG g_OpenAllocations = 0; 38 + static LONG g_Reallocations = 0; 39 + 40 + struct CHeapPtrListMallocSpy : public IMallocSpy 41 + { 42 + STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject) 43 + { 44 + if (IsEqualGUID(riid, IID_IMallocSpy)) 45 + { 46 + *ppvObject = this; 47 + } 48 + return S_OK; 49 + } 50 + 51 + virtual ULONG STDMETHODCALLTYPE AddRef() { return 1; } 52 + virtual ULONG STDMETHODCALLTYPE Release() { return 1; } 53 + virtual SIZE_T STDMETHODCALLTYPE PreAlloc(SIZE_T cbRequest) { return cbRequest; } 54 + virtual LPVOID STDMETHODCALLTYPE PostAlloc(LPVOID pActual) 55 + { 56 + InterlockedIncrement(&g_OpenAllocations); 57 + return pActual; 58 + } 59 + virtual LPVOID STDMETHODCALLTYPE PreFree(LPVOID pRequest, BOOL) { return pRequest; } 60 + virtual void STDMETHODCALLTYPE PostFree(BOOL fSpyed) 61 + { 62 + if (fSpyed) 63 + InterlockedDecrement(&g_OpenAllocations); 64 + } 65 + virtual SIZE_T STDMETHODCALLTYPE PreRealloc(LPVOID pRequest, SIZE_T cbRequest, LPVOID *ppNewRequest, BOOL) 66 + { 67 + *ppNewRequest = pRequest; 68 + return cbRequest; 69 + } 70 + virtual LPVOID STDMETHODCALLTYPE PostRealloc(LPVOID pActual, BOOL fSpyed) 71 + { 72 + if (fSpyed) 73 + InterlockedIncrement(&g_Reallocations); 74 + return pActual; 75 + } 76 + virtual LPVOID STDMETHODCALLTYPE PreGetSize(LPVOID pRequest, BOOL) { return pRequest; } 77 + virtual SIZE_T STDMETHODCALLTYPE PostGetSize(SIZE_T cbActual, BOOL) { return cbActual; } 78 + virtual LPVOID STDMETHODCALLTYPE PreDidAlloc(LPVOID pRequest, BOOL) { return pRequest; } 79 + virtual int STDMETHODCALLTYPE PostDidAlloc(LPVOID, BOOL, int fActual) { return fActual; } 80 + virtual void STDMETHODCALLTYPE PreHeapMinimize() {} 81 + virtual void STDMETHODCALLTYPE PostHeapMinimize() {} 82 + }; 83 + 84 + static CHeapPtrListMallocSpy g_Spy; 85 + 86 + 87 + START_TEST(CHeapPtrList) 88 + { 89 + HRESULT hr = CoRegisterMallocSpy(&g_Spy); 90 + ok(SUCCEEDED(hr), "Expected CoRegisterMallocSpy to succeed, but it failed: 0x%lx\n", hr); 91 + 92 + { 93 + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); 94 + CComHeapPtrList<DWORD> heapPtr1; 95 + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); 96 + PDWORD Ptr = test_Alloc(0x11111111); 97 + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); 98 + CComHeapPtr<DWORD> tmp(Ptr); 99 + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); 100 + heapPtr1.AddTail(tmp); 101 + ok(tmp.m_pData == NULL, "Expected m_pData to be transfered\n"); 102 + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); 103 + Ptr = test_Alloc(0x22222222); 104 + ok(g_OpenAllocations == 2, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); 105 + #ifdef _MSC_VER 106 + heapPtr1.AddTail(CComHeapPtr<DWORD>(Ptr)); 107 + #else 108 + CComHeapPtr<DWORD> xxx(Ptr); 109 + heapPtr1.AddTail(xxx); 110 + #endif 111 + ok(g_OpenAllocations == 2, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); 112 + } 113 + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); 114 + 115 + hr = CoRevokeMallocSpy(); 116 + ok(SUCCEEDED(hr), "Expected CoRevokeMallocSpy to succeed, but it failed: 0x%lx\n", hr); 117 + }
+2 -1
modules/rostests/apitests/atl/CMakeLists.txt
··· 13 13 CComHeapPtr.cpp 14 14 CComObject.cpp 15 15 CComQIPtr.cpp 16 + CComVariant.cpp 17 + CHeapPtrList.cpp 16 18 CImage.cpp 17 19 CRegKey.cpp 18 20 CSimpleArray.cpp ··· 22 24 23 25 add_executable(atl_apitest 24 26 ${SOURCE} 25 - CComVariant.cpp 26 27 testlist.c 27 28 atl_apitest.rc) 28 29
+10
modules/rostests/apitests/atl/devenv/ATLTest.sln
··· 21 21 EndProject 22 22 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CAtlList", "CAtlList.vcxproj", "{00C3325D-0E3D-43F1-92C8-F7D5C32F70C6}" 23 23 EndProject 24 + Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CHeapPtrList", "CHeapPtrList.vcxproj", "{83D1D036-02AC-4DC5-B061-1F47F7065661}" 25 + EndProject 24 26 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CComHeapPtr", "CComHeapPtr.vcxproj", "{F10E34E3-FB53-4650-985A-28BD1905D65C}" 25 27 EndProject 26 28 Global ··· 103 105 {00C3325D-0E3D-43F1-92C8-F7D5C32F70C6}.Release|x64.Build.0 = Release|x64 104 106 {00C3325D-0E3D-43F1-92C8-F7D5C32F70C6}.Release|x86.ActiveCfg = Release|Win32 105 107 {00C3325D-0E3D-43F1-92C8-F7D5C32F70C6}.Release|x86.Build.0 = Release|Win32 108 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Debug|x64.ActiveCfg = Debug|x64 109 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Debug|x64.Build.0 = Debug|x64 110 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Debug|x86.ActiveCfg = Debug|Win32 111 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Debug|x86.Build.0 = Debug|Win32 112 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Release|x64.ActiveCfg = Release|x64 113 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Release|x64.Build.0 = Release|x64 114 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Release|x86.ActiveCfg = Release|Win32 115 + {83D1D036-02AC-4DC5-B061-1F47F7065661}.Release|x86.Build.0 = Release|Win32 106 116 {F10E34E3-FB53-4650-985A-28BD1905D65C}.Debug|x64.ActiveCfg = Debug|x64 107 117 {F10E34E3-FB53-4650-985A-28BD1905D65C}.Debug|x64.Build.0 = Debug|x64 108 118 {F10E34E3-FB53-4650-985A-28BD1905D65C}.Debug|x86.ActiveCfg = Debug|Win32
+180
modules/rostests/apitests/atl/devenv/CHeapPtrList.vcxproj
··· 1 + <?xml version="1.0" encoding="utf-8"?> 2 + <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Win32"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Win32</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Release|Win32"> 9 + <Configuration>Release</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="Release|x64"> 17 + <Configuration>Release</Configuration> 18 + <Platform>x64</Platform> 19 + </ProjectConfiguration> 20 + </ItemGroup> 21 + <PropertyGroup Label="Globals"> 22 + <ProjectGuid>{83D1D036-02AC-4DC5-B061-1F47F7065661}</ProjectGuid> 23 + <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> 24 + <Keyword>AtlProj</Keyword> 25 + </PropertyGroup> 26 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 27 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 28 + <ConfigurationType>Application</ConfigurationType> 29 + <UseDebugLibraries>true</UseDebugLibraries> 30 + <PlatformToolset>v140_xp</PlatformToolset> 31 + <CharacterSet>Unicode</CharacterSet> 32 + </PropertyGroup> 33 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 34 + <ConfigurationType>Application</ConfigurationType> 35 + <UseDebugLibraries>false</UseDebugLibraries> 36 + <PlatformToolset>v140_xp</PlatformToolset> 37 + <CharacterSet>Unicode</CharacterSet> 38 + </PropertyGroup> 39 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 40 + <ConfigurationType>Application</ConfigurationType> 41 + <UseDebugLibraries>true</UseDebugLibraries> 42 + <CharacterSet>Unicode</CharacterSet> 43 + <PlatformToolset>v140_xp</PlatformToolset> 44 + </PropertyGroup> 45 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 46 + <ConfigurationType>Application</ConfigurationType> 47 + <UseDebugLibraries>false</UseDebugLibraries> 48 + <PlatformToolset>v140_xp</PlatformToolset> 49 + <CharacterSet>Unicode</CharacterSet> 50 + </PropertyGroup> 51 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 52 + <ImportGroup Label="ExtensionSettings"> 53 + </ImportGroup> 54 + <ImportGroup Label="Shared"> 55 + </ImportGroup> 56 + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 57 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 58 + </ImportGroup> 59 + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 60 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 61 + </ImportGroup> 62 + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 63 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 64 + </ImportGroup> 65 + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 66 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 67 + </ImportGroup> 68 + <PropertyGroup Label="UserMacros" /> 69 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 70 + <IgnoreImportLibrary>true</IgnoreImportLibrary> 71 + <LinkIncremental>true</LinkIncremental> 72 + <IntDir>$(ProjectName)\$(Configuration)\</IntDir> 73 + </PropertyGroup> 74 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 75 + <IgnoreImportLibrary>true</IgnoreImportLibrary> 76 + <LinkIncremental>true</LinkIncremental> 77 + <IntDir>$(ProjectName)\$(Platform)\$(Configuration)\</IntDir> 78 + </PropertyGroup> 79 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 80 + <IgnoreImportLibrary>true</IgnoreImportLibrary> 81 + <LinkIncremental>false</LinkIncremental> 82 + <IntDir>$(ProjectName)\$(Configuration)\</IntDir> 83 + </PropertyGroup> 84 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 85 + <IgnoreImportLibrary>true</IgnoreImportLibrary> 86 + <LinkIncremental>false</LinkIncremental> 87 + <IntDir>$(ProjectName)\$(Platform)\$(Configuration)\</IntDir> 88 + </PropertyGroup> 89 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 90 + <ClCompile> 91 + <PrecompiledHeader>NotUsing</PrecompiledHeader> 92 + <WarningLevel>Level3</WarningLevel> 93 + <Optimization>Disabled</Optimization> 94 + <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 95 + <SDLCheck>true</SDLCheck> 96 + </ClCompile> 97 + <ResourceCompile> 98 + <Culture>0x0409</Culture> 99 + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 100 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 101 + </ResourceCompile> 102 + <Link> 103 + <SubSystem>Console</SubSystem> 104 + <GenerateDebugInformation>true</GenerateDebugInformation> 105 + </Link> 106 + </ItemDefinitionGroup> 107 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 108 + <ClCompile> 109 + <PrecompiledHeader>NotUsing</PrecompiledHeader> 110 + <WarningLevel>Level3</WarningLevel> 111 + <Optimization>Disabled</Optimization> 112 + <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 113 + <SDLCheck>true</SDLCheck> 114 + </ClCompile> 115 + <ResourceCompile> 116 + <Culture>0x0409</Culture> 117 + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 118 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 119 + </ResourceCompile> 120 + <Link> 121 + <SubSystem>Console</SubSystem> 122 + <GenerateDebugInformation>true</GenerateDebugInformation> 123 + </Link> 124 + </ItemDefinitionGroup> 125 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 126 + <ClCompile> 127 + <PrecompiledHeader>NotUsing</PrecompiledHeader> 128 + <WarningLevel>Level3</WarningLevel> 129 + <Optimization>MaxSpeed</Optimization> 130 + <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 131 + <SDLCheck>true</SDLCheck> 132 + </ClCompile> 133 + <ResourceCompile> 134 + <Culture>0x0409</Culture> 135 + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 136 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 137 + </ResourceCompile> 138 + <Link> 139 + <SubSystem>Console</SubSystem> 140 + <GenerateDebugInformation>true</GenerateDebugInformation> 141 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 142 + <OptimizeReferences>true</OptimizeReferences> 143 + </Link> 144 + </ItemDefinitionGroup> 145 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 146 + <ClCompile> 147 + <PrecompiledHeader>NotUsing</PrecompiledHeader> 148 + <WarningLevel>Level3</WarningLevel> 149 + <Optimization>MaxSpeed</Optimization> 150 + <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 151 + <SDLCheck>true</SDLCheck> 152 + </ClCompile> 153 + <ResourceCompile> 154 + <Culture>0x0409</Culture> 155 + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 156 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 157 + </ResourceCompile> 158 + <Link> 159 + <SubSystem>Console</SubSystem> 160 + <GenerateDebugInformation>true</GenerateDebugInformation> 161 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 162 + <OptimizeReferences>true</OptimizeReferences> 163 + </Link> 164 + </ItemDefinitionGroup> 165 + <ItemGroup> 166 + <ClCompile Include="../CHeapPtrList.cpp"> 167 + <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MultiThreaded</RuntimeLibrary> 168 + <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MultiThreaded</RuntimeLibrary> 169 + <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MultiThreadedDebug</RuntimeLibrary> 170 + <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MultiThreadedDebug</RuntimeLibrary> 171 + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader> 172 + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader> 173 + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader> 174 + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader> 175 + </ClCompile> 176 + </ItemGroup> 177 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 178 + <ImportGroup Label="ExtensionTargets"> 179 + </ImportGroup> 180 + </Project>
+2
modules/rostests/apitests/atl/testlist.c
··· 10 10 extern void func_CComObject(void); 11 11 extern void func_CComQIPtr(void); 12 12 extern void func_CComVariant(void); 13 + extern void func_CHeapPtrList(void); 13 14 extern void func_CImage(void); 14 15 extern void func_CRegKey(void); 15 16 extern void func_CSimpleArray(void); ··· 27 28 { "CComObject", func_CComObject }, 28 29 { "CComQIPtr", func_CComQIPtr }, 29 30 { "CComVariant", func_CComVariant }, 31 + { "CHeapPtrList", func_CHeapPtrList }, 30 32 { "CImage", func_CImage }, 31 33 { "CRegKey", func_CRegKey }, 32 34 { "CSimpleArray", func_CSimpleArray },
+28
sdk/lib/atl/atlcoll.h
··· 157 157 }; 158 158 159 159 160 + template<typename T, class Allocator = CCRTAllocator> 161 + class CHeapPtrElementTraits : 162 + public CDefaultElementTraits< CHeapPtr<T, Allocator> > 163 + { 164 + public: 165 + typedef CHeapPtr<T, Allocator>& INARGTYPE; 166 + typedef T*& OUTARGTYPE; 167 + }; 168 + 169 + 170 + 160 171 template<typename E, class ETraits = CElementTraits<E> > 161 172 class CAtlArray 162 173 { ··· 851 862 852 863 return m_FreeNode; 853 864 } 865 + 866 + 867 + template<typename E, class Allocator = CCRTAllocator > 868 + class CHeapPtrList : 869 + public CAtlList<CHeapPtr<E, Allocator>, CHeapPtrElementTraits<E, Allocator> > 870 + { 871 + public: 872 + CHeapPtrList(_In_ UINT nBlockSize = 10) : 873 + CAtlList<CHeapPtr<E, Allocator>, CHeapPtrElementTraits<E, Allocator> >(nBlockSize) 874 + { 875 + } 876 + 877 + private: 878 + CHeapPtrList(const CHeapPtrList&); 879 + CHeapPtrList& operator=(const CHeapPtrList*); 880 + }; 881 + 854 882 855 883 } 856 884