2004-11-30 18:38:52 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for MAPI IMalloc functions
|
|
|
|
*
|
|
|
|
* Copyright 2004 Jon Griffiths
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-11-30 18:38:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "mapiutil.h"
|
2001-09-17 00:00:00 +02:00
|
|
|
#include "mapi32_test.h"
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
static HMODULE hMapi32 = 0;
|
|
|
|
|
|
|
|
static SCODE (WINAPI *pScInitMapiUtil)(ULONG);
|
|
|
|
static LPMALLOC (WINAPI *pMAPIGetDefaultMalloc)(void);
|
|
|
|
|
|
|
|
static void test_IMalloc(void)
|
|
|
|
{
|
|
|
|
LPVOID lpMem;
|
|
|
|
ULONG ulRef;
|
|
|
|
int iRet;
|
|
|
|
HRESULT hRet;
|
|
|
|
LPMALLOC lpMalloc;
|
|
|
|
LPVOID lpVoid;
|
|
|
|
|
|
|
|
pMAPIGetDefaultMalloc = (void*)GetProcAddress(hMapi32,
|
|
|
|
"MAPIGetDefaultMalloc@0");
|
|
|
|
if (!pMAPIGetDefaultMalloc)
|
2010-01-18 13:59:54 +01:00
|
|
|
{
|
|
|
|
win_skip("MAPIGetDefaultMalloc is not available\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2010-01-18 13:59:54 +01:00
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
lpMalloc = pMAPIGetDefaultMalloc();
|
2010-01-18 13:59:54 +01:00
|
|
|
ok(lpMalloc != NULL, "Expected MAPIGetDefaultMalloc to return non-NULL\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
if (!lpMalloc)
|
2010-01-18 13:59:54 +01:00
|
|
|
{
|
|
|
|
skip("MAPIGetDefaultMalloc failed\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2010-01-18 13:59:54 +01:00
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
lpVoid = NULL;
|
|
|
|
hRet = IMalloc_QueryInterface(lpMalloc, &IID_IUnknown, &lpVoid);
|
|
|
|
ok (hRet == S_OK && lpVoid != NULL,
|
2007-02-14 16:22:07 +01:00
|
|
|
"IID_IUnknown: expected S_OK, non-null, got 0x%08x, %p\n",
|
2004-11-30 18:38:52 +01:00
|
|
|
hRet, lpVoid);
|
|
|
|
|
|
|
|
lpVoid = NULL;
|
|
|
|
hRet = IMalloc_QueryInterface(lpMalloc, &IID_IMalloc, &lpVoid);
|
|
|
|
ok (hRet == S_OK && lpVoid != NULL,
|
2007-02-14 16:22:07 +01:00
|
|
|
"IID_IIMalloc: expected S_OK, non-null, got 0x%08x, %p\n",
|
2004-11-30 18:38:52 +01:00
|
|
|
hRet, lpVoid);
|
|
|
|
|
|
|
|
/* Prove that native mapi uses LocalAlloc/LocalFree */
|
|
|
|
lpMem = IMalloc_Alloc(lpMalloc, 61);
|
2009-01-08 00:36:51 +01:00
|
|
|
ok (lpMem && IMalloc_GetSize(lpMalloc, lpMem) == LocalSize(lpMem),
|
2004-11-30 18:38:52 +01:00
|
|
|
"Expected non-null, same size, got %p, %s size\n", lpMem,
|
|
|
|
lpMem ? "different" : "same");
|
|
|
|
|
|
|
|
iRet = IMalloc_DidAlloc(lpMalloc, lpMem);
|
|
|
|
ok (iRet == -1, "DidAlloc, expected -1. got %d\n", iRet);
|
|
|
|
|
|
|
|
IMalloc_HeapMinimize(lpMalloc);
|
|
|
|
|
|
|
|
LocalFree(lpMem);
|
|
|
|
|
|
|
|
ulRef = IMalloc_AddRef(lpMalloc);
|
2006-10-12 20:56:25 +02:00
|
|
|
ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef);
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
ulRef = IMalloc_Release(lpMalloc);
|
2006-10-12 20:56:25 +02:00
|
|
|
ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef);
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
IMalloc_Release(lpMalloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(imalloc)
|
|
|
|
{
|
2007-03-04 11:44:34 +01:00
|
|
|
SCODE ret;
|
|
|
|
|
2001-09-17 00:00:00 +02:00
|
|
|
if (!HaveDefaultMailClient())
|
|
|
|
{
|
|
|
|
win_skip("No default mail client installed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-30 18:38:52 +01:00
|
|
|
hMapi32 = LoadLibraryA("mapi32.dll");
|
|
|
|
|
|
|
|
pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
|
|
|
|
if (!pScInitMapiUtil)
|
2007-03-04 11:44:34 +01:00
|
|
|
{
|
2009-02-23 10:40:40 +01:00
|
|
|
win_skip("ScInitMapiUtil is not available\n");
|
2007-03-04 11:44:34 +01:00
|
|
|
FreeLibrary(hMapi32);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pScInitMapiUtil(0);
|
|
|
|
if ((ret != S_OK) && (GetLastError() == ERROR_PROC_NOT_FOUND))
|
|
|
|
{
|
2009-02-23 10:40:40 +01:00
|
|
|
win_skip("ScInitMapiUtil is not implemented\n");
|
2007-03-04 11:44:34 +01:00
|
|
|
FreeLibrary(hMapi32);
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2007-03-04 11:44:34 +01:00
|
|
|
}
|
2009-06-19 12:30:40 +02:00
|
|
|
else if ((ret == E_FAIL) && (GetLastError() == ERROR_INVALID_HANDLE))
|
|
|
|
{
|
|
|
|
win_skip("ScInitMapiUtil doesn't work on some Win98 and WinME systems\n");
|
|
|
|
FreeLibrary(hMapi32);
|
|
|
|
return;
|
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
test_IMalloc();
|
2007-03-04 11:44:34 +01:00
|
|
|
|
|
|
|
FreeLibrary(hMapi32);
|
2004-11-30 18:38:52 +01:00
|
|
|
}
|