2 * Unit test suite for MAPI IMalloc functions
4 * Copyright 2004 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
29 #include "mapi32_test.h"
31 static HMODULE hMapi32
= 0;
33 static SCODE (WINAPI
*pScInitMapiUtil
)(ULONG
);
34 static LPMALLOC (WINAPI
*pMAPIGetDefaultMalloc
)(void);
36 static void test_IMalloc(void)
45 pMAPIGetDefaultMalloc
= (void*)GetProcAddress(hMapi32
,
46 "MAPIGetDefaultMalloc@0");
47 if (!pMAPIGetDefaultMalloc
)
49 win_skip("MAPIGetDefaultMalloc is not available\n");
53 lpMalloc
= pMAPIGetDefaultMalloc();
54 ok(lpMalloc
!= NULL
, "Expected MAPIGetDefaultMalloc to return non-NULL\n");
57 skip("MAPIGetDefaultMalloc failed\n");
62 hRet
= IMalloc_QueryInterface(lpMalloc
, &IID_IUnknown
, &lpVoid
);
63 ok (hRet
== S_OK
&& lpVoid
!= NULL
,
64 "IID_IUnknown: expected S_OK, non-null, got 0x%08x, %p\n",
68 hRet
= IMalloc_QueryInterface(lpMalloc
, &IID_IMalloc
, &lpVoid
);
69 ok (hRet
== S_OK
&& lpVoid
!= NULL
,
70 "IID_IIMalloc: expected S_OK, non-null, got 0x%08x, %p\n",
73 /* Prove that native mapi uses LocalAlloc/LocalFree */
74 lpMem
= IMalloc_Alloc(lpMalloc
, 61);
75 ok (lpMem
&& IMalloc_GetSize(lpMalloc
, lpMem
) == LocalSize(lpMem
),
76 "Expected non-null, same size, got %p, %s size\n", lpMem
,
77 lpMem
? "different" : "same");
79 iRet
= IMalloc_DidAlloc(lpMalloc
, lpMem
);
80 ok (iRet
== -1, "DidAlloc, expected -1. got %d\n", iRet
);
82 IMalloc_HeapMinimize(lpMalloc
);
86 ulRef
= IMalloc_AddRef(lpMalloc
);
87 ok (ulRef
== 1u, "AddRef expected 1, returned %d\n", ulRef
);
89 ulRef
= IMalloc_Release(lpMalloc
);
90 ok (ulRef
== 1u, "AddRef expected 1, returned %d\n", ulRef
);
92 IMalloc_Release(lpMalloc
);
99 if (!HaveDefaultMailClient())
101 win_skip("No default mail client installed\n");
105 hMapi32
= LoadLibraryA("mapi32.dll");
107 pScInitMapiUtil
= (void*)GetProcAddress(hMapi32
, "ScInitMapiUtil@4");
108 if (!pScInitMapiUtil
)
110 win_skip("ScInitMapiUtil is not available\n");
111 FreeLibrary(hMapi32
);
115 SetLastError(0xdeadbeef);
116 ret
= pScInitMapiUtil(0);
117 if ((ret
!= S_OK
) && (GetLastError() == ERROR_PROC_NOT_FOUND
))
119 win_skip("ScInitMapiUtil is not implemented\n");
120 FreeLibrary(hMapi32
);
123 else if ((ret
== E_FAIL
) && (GetLastError() == ERROR_INVALID_HANDLE
))
125 win_skip("ScInitMapiUtil doesn't work on some Win98 and WinME systems\n");
126 FreeLibrary(hMapi32
);
132 FreeLibrary(hMapi32
);