ReactOS 0.4.15-dev-7887-g64a59a1
CComHeapPtr.cpp File Reference
#include "atltest.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 74 of file CComHeapPtr.cpp.

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

◆ test_Alloc()

static PDWORD test_Alloc ( DWORD  value)
static

Definition at line 16 of file CComHeapPtr.cpp.

17{
19 *ptr = value;
20 return ptr;
21}
unsigned long DWORD
Definition: ntddk_ex.h:95
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
static PVOID ptr
Definition: dispmode.c:27
Definition: pdh_main.c:94

Variable Documentation

◆ g_OpenAllocations

LONG g_OpenAllocations = 0
static

Definition at line 24 of file CComHeapPtr.cpp.

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

◆ g_Reallocations

LONG g_Reallocations = 0
static

Definition at line 25 of file CComHeapPtr.cpp.

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

◆ g_Spy

CMallocSpy g_Spy
static

Definition at line 71 of file CComHeapPtr.cpp.

Referenced by START_TEST().