ReactOS 0.4.15-dev-8102-g108db8f
CHeapPtrList.cpp
Go to the documentation of this file.
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
15static PDWORD
17{
19 *ptr = value;
20 return ptr;
21}
22
23// We use the CComAllocator, so we can easily spy on it
24template <typename T>
26 public CHeapPtrList<T, CComAllocator>
27{
28public:
29 CComHeapPtrList(_In_ UINT nBlockSize = 10) throw()
30 :CHeapPtrList<T, CComAllocator>(nBlockSize)
31 {
32 }
33};
34
35
36
39
41{
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; }
55 {
57 return pActual;
58 }
60 virtual void STDMETHODCALLTYPE PostFree(BOOL fSpyed)
61 {
62 if (fSpyed)
64 }
65 virtual SIZE_T STDMETHODCALLTYPE PreRealloc(LPVOID pRequest, SIZE_T cbRequest, LPVOID *ppNewRequest, BOOL)
66 {
67 *ppNewRequest = pRequest;
68 return cbRequest;
69 }
71 {
72 if (fSpyed)
74 return pActual;
75 }
77 virtual SIZE_T STDMETHODCALLTYPE PostGetSize(SIZE_T cbActual, BOOL) { return cbActual; }
79 virtual int STDMETHODCALLTYPE PostDidAlloc(LPVOID, BOOL, int fActual) { return fActual; }
82};
83
85
86
88{
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);
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);
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#if defined(_MSC_VER) && !defined(__clang__)
106 heapPtr1.AddTail(CComHeapPtr<DWORD>(Ptr));
107#else
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
116 ok(SUCCEEDED(hr), "Expected CoRevokeMallocSpy to succeed, but it failed: 0x%lx\n", hr);
117}
static CHeapPtrListMallocSpy g_Spy
static LONG g_Reallocations
static LONG g_OpenAllocations
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define STDMETHODIMP
Definition: basetyps.h:43
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:626
CComHeapPtrList(_In_ UINT nBlockSize=10)
T * m_pData
Definition: atlalloc.h:192
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
FxRequest * pRequest
HRESULT WINAPI CoRevokeMallocSpy(void)
Definition: ifs.c:522
HRESULT WINAPI CoRegisterMallocSpy(LPMALLOCSPY pMallocSpy)
Definition: ifs.c:482
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static PVOID ptr
Definition: dispmode.c:27
static void test_Alloc(void)
Definition: misc.c:148
#define _In_
Definition: ms_sal.h:308
unsigned int UINT
Definition: ndis.h:50
DWORD * PDWORD
Definition: pedump.c:68
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
HRESULT hr
Definition: shlfolder.c:183
virtual LPVOID STDMETHODCALLTYPE PreDidAlloc(LPVOID pRequest, BOOL)
virtual SIZE_T STDMETHODCALLTYPE PostGetSize(SIZE_T cbActual, BOOL)
virtual ULONG STDMETHODCALLTYPE Release()
virtual void STDMETHODCALLTYPE PostHeapMinimize()
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject)
virtual ULONG STDMETHODCALLTYPE AddRef()
virtual SIZE_T STDMETHODCALLTYPE PreRealloc(LPVOID pRequest, SIZE_T cbRequest, LPVOID *ppNewRequest, BOOL)
virtual void STDMETHODCALLTYPE PostFree(BOOL fSpyed)
virtual LPVOID STDMETHODCALLTYPE PostRealloc(LPVOID pActual, BOOL fSpyed)
virtual LPVOID STDMETHODCALLTYPE PostAlloc(LPVOID pActual)
virtual SIZE_T STDMETHODCALLTYPE PreAlloc(SIZE_T cbRequest)
virtual LPVOID STDMETHODCALLTYPE PreFree(LPVOID pRequest, BOOL)
virtual void STDMETHODCALLTYPE PreHeapMinimize()
virtual int STDMETHODCALLTYPE PostDidAlloc(LPVOID, BOOL, int fActual)
virtual LPVOID STDMETHODCALLTYPE PreGetSize(LPVOID pRequest, BOOL)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:94
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082