- Unknown destinations are now correctly skipped (so loading an RTF
[wine] / dlls / mapi32 / tests / imalloc.c
1 /*
2  * Unit test suite for MAPI IMalloc functions
3  *
4  * Copyright 2004 Jon Griffiths
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winerror.h"
29 #include "winnt.h"
30 #include "mapiutil.h"
31
32 static HMODULE hMapi32 = 0;
33
34 static SCODE    (WINAPI *pScInitMapiUtil)(ULONG);
35 static LPMALLOC (WINAPI *pMAPIGetDefaultMalloc)(void);
36
37 static void test_IMalloc(void)
38 {
39     LPVOID lpMem;
40     ULONG ulRef;
41     int iRet;
42     HRESULT hRet;
43     LPMALLOC lpMalloc;
44     LPVOID lpVoid;
45
46     pMAPIGetDefaultMalloc = (void*)GetProcAddress(hMapi32,
47                                                   "MAPIGetDefaultMalloc@0");
48     if (!pMAPIGetDefaultMalloc)
49         return;
50
51     lpMalloc = pMAPIGetDefaultMalloc();
52     if (!lpMalloc)
53         return;
54
55     lpVoid = NULL;
56     hRet = IMalloc_QueryInterface(lpMalloc, &IID_IUnknown, &lpVoid);
57     ok (hRet == S_OK && lpVoid != NULL,
58         "IID_IUnknown: exepected S_OK, non-null, got 0x%08lx, %p\n",
59         hRet, lpVoid);
60
61     lpVoid = NULL;
62     hRet = IMalloc_QueryInterface(lpMalloc, &IID_IMalloc, &lpVoid);
63     ok (hRet == S_OK && lpVoid != NULL,
64         "IID_IIMalloc: exepected S_OK, non-null, got 0x%08lx, %p\n",
65         hRet, lpVoid);
66
67     /* Prove that native mapi uses LocalAlloc/LocalFree */
68     lpMem = IMalloc_Alloc(lpMalloc, 61);
69     ok (lpMem && IMalloc_GetSize(lpMalloc, lpMem) ==
70         LocalSize((HANDLE)lpMem),
71         "Expected non-null, same size, got %p, %s size\n", lpMem,
72         lpMem ? "different" : "same");
73
74     iRet = IMalloc_DidAlloc(lpMalloc, lpMem);
75     ok (iRet == -1, "DidAlloc, expected -1. got %d\n", iRet);
76
77     IMalloc_HeapMinimize(lpMalloc);
78  
79     LocalFree(lpMem);
80  
81     ulRef = IMalloc_AddRef(lpMalloc);
82     ok (ulRef == 1u, "AddRef expected 1, returned %ld\n", ulRef); 
83     
84     ulRef = IMalloc_Release(lpMalloc);
85     ok (ulRef == 1u, "AddRef expected 1, returned %ld\n", ulRef);
86
87     IMalloc_Release(lpMalloc);
88 }
89
90 START_TEST(imalloc)
91 {
92     hMapi32 = LoadLibraryA("mapi32.dll");
93
94     pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
95     if (!pScInitMapiUtil)
96         return;
97     pScInitMapiUtil(0);
98
99     test_IMalloc();
100 }