Index: apitests/atl/CComHeapPtr.cpp =================================================================== --- apitests/atl/CComHeapPtr.cpp (revision 0) +++ apitests/atl/CComHeapPtr.cpp (working copy) @@ -0,0 +1,129 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Test for CComHeapPtr + * PROGRAMMER: Mark Jansen + */ + +#define COM_NO_WINDOWS_H +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include +#include +#include + +PDWORD test_Alloc(DWORD value) +{ + PDWORD ptr = (PDWORD)::CoTaskMemAlloc(sizeof(DWORD)); + *ptr = value; + return ptr; +} + + +LONG g_OpenAllocations = 0; +LONG g_Reallocations = 0; + +struct CMallocSpy : public IMallocSpy +{ + STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject) + { + if (IsEqualGUID(riid, IID_IMallocSpy)) + { + *ppvObject = this; + } + return S_OK; + } + + virtual ULONG STDMETHODCALLTYPE AddRef() { return 1; } + virtual ULONG STDMETHODCALLTYPE Release() { return 1; } + virtual ULONG STDMETHODCALLTYPE PreAlloc(ULONG cbRequest) { return cbRequest; } + virtual LPVOID STDMETHODCALLTYPE PostAlloc(LPVOID pActual) + { + InterlockedIncrement(&g_OpenAllocations); + return pActual; + } + virtual LPVOID STDMETHODCALLTYPE PreFree(LPVOID pRequest, BOOL) { return pRequest; } + virtual void STDMETHODCALLTYPE PostFree(BOOL fSpyed) + { + if (fSpyed) + InterlockedDecrement(&g_OpenAllocations); + } + virtual ULONG STDMETHODCALLTYPE PreRealloc(LPVOID pRequest, ULONG cbRequest, LPVOID *ppNewRequest, BOOL) + { + *ppNewRequest = pRequest; + return cbRequest; + } + virtual LPVOID STDMETHODCALLTYPE PostRealloc(LPVOID pActual, BOOL fSpyed) + { + if (fSpyed) + InterlockedIncrement(&g_Reallocations); + return pActual; + } + virtual LPVOID STDMETHODCALLTYPE PreGetSize(LPVOID pRequest, BOOL) { return pRequest; } + virtual ULONG STDMETHODCALLTYPE PostGetSize(ULONG cbActual, BOOL) { return cbActual; } + virtual LPVOID STDMETHODCALLTYPE PreDidAlloc(LPVOID pRequest, BOOL) { return pRequest; } + virtual int STDMETHODCALLTYPE PostDidAlloc(LPVOID, BOOL, int fActual) { return fActual; } + virtual void STDMETHODCALLTYPE PreHeapMinimize() {} + virtual void STDMETHODCALLTYPE PostHeapMinimize() {} +}; + +CMallocSpy g_Spy; + + +START_TEST(CComHeapPtr) +{ + HRESULT hr = CoRegisterMallocSpy(&g_Spy); + ok(SUCCEEDED(hr), "Expected CoRegisterMallocSpy to succeed, but it failed: 0x%lx\n", hr); + + { + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); + CComHeapPtr heapPtr1; + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); + CComHeapPtr heapPtr2(test_Alloc(0x11111111)); + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + + ok((PDWORD)heapPtr1 == NULL, "Expected heapPtr1 to be NULL, was: 0x%p\n", (PDWORD)heapPtr1); + ok((PDWORD)heapPtr2 != NULL, "Expected heapPtr2 to not be NULL\n"); + ok(*heapPtr2 == 0x11111111, "Expected *heapPtr2 to be 0x11111111, but was: 0x%lx\n", *heapPtr2); + + { + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + CComHeapPtr heapPtrSteal1(heapPtr1); + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + ok((PDWORD)heapPtr1 == NULL, "Expected heapPtr1 to be NULL, was: 0x%p\n", (PDWORD)heapPtr1); + ok((PDWORD)heapPtrSteal1 == NULL, "Expected heapPtrSteal1 to be NULL, was: 0x%p\n", (PDWORD)heapPtrSteal1); + CComHeapPtr heapPtrSteal2(heapPtr2); + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + ok((PDWORD)heapPtr2 == NULL, "Expected heapPtr2 to be NULL, was: 0x%p\n", (PDWORD)heapPtr2); + ok((PDWORD)heapPtrSteal2 != NULL, "Expected heapPtrSteal2 to not be NULL\n"); + ok(*heapPtrSteal2 == 0x11111111, "Expected *heapPtrSteal2 to be 0x11111111, but was: 0x%lx\n", *heapPtrSteal2); + } + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); + + ok(heapPtr1.Allocate(1), "Expected Allocate to succeed\n"); + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + ok(g_Reallocations == 0, "Expected there to be 0 reallocations, was: %ld\n", g_Reallocations); + + *heapPtr1 = 0x22222222; + ok(*heapPtr1 == 0x22222222, "Expected *heapPtr1 to be 0x22222222, but was: 0x%lx\n", *heapPtr1); + + ok(heapPtr1.Reallocate(2), "Expected Reallocate to succeed\n"); + heapPtr1[1] = 0x33333333; + ok(*heapPtr1 == 0x22222222, "Expected *heapPtr1 to be 0x22222222, but was: 0x%lx\n", *heapPtr1); + ok(g_Reallocations == 1, "Expected there to be 1 reallocations, was: %ld\n", g_Reallocations); + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + + heapPtr2 = heapPtr1; + ok(g_OpenAllocations == 1, "Expected there to be 1 allocations, was: %ld\n", g_OpenAllocations); + ok(*heapPtr2 == 0x22222222, "Expected *heapPtr2 to be 0x33333333, but was: 0x%lx\n", *heapPtr2); + ok(heapPtr2[1] == 0x33333333, "Expected heapPtr2[1] to be 0x33333333, but was: 0x%lx\n", heapPtr2[1]); + ok((PDWORD)heapPtr1 == NULL, "Expected heapPtr1 to be NULL, was: 0x%p\n", (PDWORD)heapPtr1); + } + ok(g_OpenAllocations == 0, "Expected there to be 0 allocations, was: %ld\n", g_OpenAllocations); + + hr = CoRevokeMallocSpy(); + ok(SUCCEEDED(hr), "Expected CoRevokeMallocSpy to succeed, but it failed: 0x%lx\n", hr); +} Index: apitests/atl/CMakeLists.txt =================================================================== --- apitests/atl/CMakeLists.txt (revision 0) +++ apitests/atl/CMakeLists.txt (working copy) @@ -0,0 +1,12 @@ + +set_cpp(WITH_RUNTIME) + +include_directories(${REACTOS_SOURCE_DIR}/lib/atl) + +add_executable(atl_apitest + CComHeapPtr.cpp + testlist.c) +target_link_libraries(atl_apitest wine uuid) +set_module_type(atl_apitest win32cui) +add_importlibs(atl_apitest ole32 oleaut32 msvcrt kernel32) +add_cd_file(TARGET atl_apitest DESTINATION reactos/bin FOR all) Index: apitests/atl/testlist.c =================================================================== --- apitests/atl/testlist.c (revision 0) +++ apitests/atl/testlist.c (working copy) @@ -0,0 +1,12 @@ +#define __ROS_LONG64__ + +#define STANDALONE +#include + +extern void func_CComHeapPtr(void); + +const struct test winetest_testlist[] = +{ + { "CComHeapPtr", func_CComHeapPtr }, + { 0, 0 } +}; Index: apitests/CMakeLists.txt =================================================================== --- apitests/CMakeLists.txt (revision 69557) +++ apitests/CMakeLists.txt (working copy) @@ -4,6 +4,7 @@ add_dependencies(apitest xdk) add_subdirectory(advapi32) +add_subdirectory(atl) add_subdirectory(browseui) add_subdirectory(com) add_subdirectory(crt)