ReactOS  0.4.13-dev-482-ge57f103
CComHeapPtr.cpp File Reference
#include <apitest.h>
#include <atlbase.h>
Include dependency graph for CComHeapPtr.cpp:

Go to the source code of this file.

Classes

struct  CMallocSpy
 

Functions

static PDWORD test_Alloc (DWORD value)
 
 START_TEST (CComHeapPtr)
 

Variables

static LONG g_OpenAllocations = 0
 
static LONG g_Reallocations = 0
 
static CMallocSpy g_Spy
 

Function Documentation

◆ START_TEST()

START_TEST ( CComHeapPtr  )

Definition at line 69 of file CComHeapPtr.cpp.

70 {
72  ok(SUCCEEDED(hr), "Expected CoRegisterMallocSpy to succeed, but it failed: 0x%lx\n", hr);
73 
74  {
75  ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations);
76  CComHeapPtr<DWORD> heapPtr1;
77  ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations);
78  CComHeapPtr<DWORD> heapPtr2(test_Alloc(0x11111111));
79  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
80 
81  ok((PDWORD)heapPtr1 == NULL, "Expected heapPtr1 to be NULL, was: 0x%p\n", (PDWORD)heapPtr1);
82  ok((PDWORD)heapPtr2 != NULL, "Expected heapPtr2 to not be NULL\n");
83  ok(*heapPtr2 == 0x11111111, "Expected *heapPtr2 to be 0x11111111, but was: 0x%lx\n", *heapPtr2);
84 
85  {
86  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
87  CComHeapPtr<DWORD> heapPtrSteal1(heapPtr1);
88  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
89  ok((PDWORD)heapPtr1 == NULL, "Expected heapPtr1 to be NULL, was: 0x%p\n", (PDWORD)heapPtr1);
90  ok((PDWORD)heapPtrSteal1 == NULL, "Expected heapPtrSteal1 to be NULL, was: 0x%p\n", (PDWORD)heapPtrSteal1);
91  CComHeapPtr<DWORD> heapPtrSteal2(heapPtr2);
92  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
93  ok((PDWORD)heapPtr2 == NULL, "Expected heapPtr2 to be NULL, was: 0x%p\n", (PDWORD)heapPtr2);
94  ok((PDWORD)heapPtrSteal2 != NULL, "Expected heapPtrSteal2 to not be NULL\n");
95  ok(*heapPtrSteal2 == 0x11111111, "Expected *heapPtrSteal2 to be 0x11111111, but was: 0x%lx\n", *heapPtrSteal2);
96  }
97  ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations);
98 
99  ok(heapPtr1.Allocate(1), "Expected Allocate to succeed\n");
100  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
101  ok(g_Reallocations == 0, "Expected there to be 0 reallocations, was: %ld\n", g_Reallocations);
102 
103  *heapPtr1 = 0x22222222;
104  ok(*heapPtr1 == 0x22222222, "Expected *heapPtr1 to be 0x22222222, but was: 0x%lx\n", *heapPtr1);
105 
106  ok(heapPtr1.Reallocate(2), "Expected Reallocate to succeed\n");
107  heapPtr1[1] = 0x33333333;
108  ok(*heapPtr1 == 0x22222222, "Expected *heapPtr1 to be 0x22222222, but was: 0x%lx\n", *heapPtr1);
109  ok(g_Reallocations == 1, "Expected there to be 1 reallocations, was: %ld\n", g_Reallocations);
110  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
111 
112  heapPtr2 = heapPtr1;
113  ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations);
114  ok(*heapPtr2 == 0x22222222, "Expected *heapPtr2 to be 0x33333333, but was: 0x%lx\n", *heapPtr2);
115  ok(heapPtr2[1] == 0x33333333, "Expected heapPtr2[1] to be 0x33333333, but was: 0x%lx\n", heapPtr2[1]);
116  ok((PDWORD)heapPtr1 == NULL, "Expected heapPtr1 to be NULL, was: 0x%p\n", (PDWORD)heapPtr1);
117  }
118  ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations);
119 
120  hr = CoRevokeMallocSpy();
121  ok(SUCCEEDED(hr), "Expected CoRevokeMallocSpy to succeed, but it failed: 0x%lx\n", hr);
122 }
static LONG g_OpenAllocations
Definition: CComHeapPtr.cpp:19
HRESULT hr
Definition: shlfolder.c:183
HRESULT WINAPI CoRevokeMallocSpy(void)
Definition: ifs.c:502
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static CMallocSpy g_Spy
Definition: CComHeapPtr.cpp:66
static LONG g_Reallocations
Definition: CComHeapPtr.cpp:20
LONG HRESULT
Definition: typedefs.h:77
static PDWORD test_Alloc(DWORD value)
Definition: CComHeapPtr.cpp:11
HRESULT WINAPI CoRegisterMallocSpy(LPMALLOCSPY pMallocSpy)
Definition: ifs.c:462
DWORD * PDWORD
Definition: pedump.c:68
#define SUCCEEDED(hr)
Definition: intsafe.h:57

◆ test_Alloc()

static PDWORD test_Alloc ( DWORD  value)
static

Definition at line 11 of file CComHeapPtr.cpp.

12 {
13  PDWORD ptr = (PDWORD)::CoTaskMemAlloc(sizeof(DWORD));
14  *ptr = value;
15  return ptr;
16 }
static PVOID ptr
Definition: dispmode.c:27
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei const GLfloat * value
Definition: glext.h:6069
DWORD * PDWORD
Definition: pedump.c:68
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:406

Referenced by START_TEST().

Variable Documentation

◆ g_OpenAllocations

LONG g_OpenAllocations = 0
static

Definition at line 19 of file CComHeapPtr.cpp.

Referenced by CMallocSpy::PostAlloc(), CMallocSpy::PostFree(), and START_TEST().

◆ g_Reallocations

LONG g_Reallocations = 0
static

Definition at line 20 of file CComHeapPtr.cpp.

Referenced by CMallocSpy::PostRealloc(), and START_TEST().

◆ g_Spy

CMallocSpy g_Spy
static

Definition at line 66 of file CComHeapPtr.cpp.

Referenced by START_TEST().