ReactOS 0.4.16-dev-226-g79f2289
imalloc.c File Reference
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winerror.h"
#include "winnt.h"
#include "mapiutil.h"
#include "mapi32_test.h"
Include dependency graph for imalloc.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

static SCODE (WINAPI *pScInitMapiUtil)(ULONG)
 
static LPMALLOC (WINAPI *pMAPIGetDefaultMalloc)(void)
 
static void test_IMalloc (void)
 
 START_TEST (imalloc)
 

Variables

static HMODULE hMapi32 = 0
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file imalloc.c.

Function Documentation

◆ LPMALLOC()

static LPMALLOC ( WINAPI pMAPIGetDefaultMalloc)
static

◆ SCODE()

static SCODE ( WINAPI pScInitMapiUtil)
static

◆ START_TEST()

START_TEST ( imalloc  )

Definition at line 95 of file imalloc.c.

96{
97 SCODE ret;
98
100 {
101 win_skip("No default mail client installed\n");
102 return;
103 }
104
105 hMapi32 = LoadLibraryA("mapi32.dll");
106
107 pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
108 if (!pScInitMapiUtil)
109 {
110 win_skip("ScInitMapiUtil is not available\n");
112 return;
113 }
114
115 SetLastError(0xdeadbeef);
116 ret = pScInitMapiUtil(0);
117 if ((ret != S_OK) && (GetLastError() == ERROR_PROC_NOT_FOUND))
118 {
119 win_skip("ScInitMapiUtil is not implemented\n");
121 return;
122 }
123 else if ((ret == E_FAIL) && (GetLastError() == ERROR_INVALID_HANDLE))
124 {
125 win_skip("ScInitMapiUtil doesn't work on some Win98 and WinME systems\n");
127 return;
128 }
129
130 test_IMalloc();
131
133}
#define E_FAIL
Definition: ddrawi.h:102
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
LONG SCODE
Definition: compat.h:2252
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define S_OK
Definition: intsafe.h:52
static BOOL HaveDefaultMailClient(void)
Definition: mapi32_test.h:20
static HMODULE hMapi32
Definition: imalloc.c:31
static void test_IMalloc(void)
Definition: imalloc.c:36
#define win_skip
Definition: test.h:163
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_PROC_NOT_FOUND
Definition: winerror.h:199

◆ test_IMalloc()

static void test_IMalloc ( void  )
static

Definition at line 36 of file imalloc.c.

37{
38 LPVOID lpMem;
39 ULONG ulRef;
40 int iRet;
41 HRESULT hRet;
42 LPMALLOC lpMalloc;
43 LPVOID lpVoid;
44
45 pMAPIGetDefaultMalloc = (void*)GetProcAddress(hMapi32,
46 "MAPIGetDefaultMalloc@0");
47 if (!pMAPIGetDefaultMalloc)
48 {
49 win_skip("MAPIGetDefaultMalloc is not available\n");
50 return;
51 }
52
53 lpMalloc = pMAPIGetDefaultMalloc();
54 ok(lpMalloc != NULL, "Expected MAPIGetDefaultMalloc to return non-NULL\n");
55 if (!lpMalloc)
56 {
57 skip("MAPIGetDefaultMalloc failed\n");
58 return;
59 }
60
61 lpVoid = NULL;
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",
65 hRet, lpVoid);
66
67 lpVoid = NULL;
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",
71 hRet, lpVoid);
72
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");
78
79 iRet = IMalloc_DidAlloc(lpMalloc, lpMem);
80 ok (iRet == -1, "DidAlloc, expected -1. got %d\n", iRet);
81
82 IMalloc_HeapMinimize(lpMalloc);
83
84 LocalFree(lpMem);
85
86 ulRef = IMalloc_AddRef(lpMalloc);
87 ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef);
88
89 ulRef = IMalloc_Release(lpMalloc);
90 ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef);
91
92 IMalloc_Release(lpMalloc);
93}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
const GUID IID_IUnknown
#define NULL
Definition: types.h:112
SIZE_T NTAPI LocalSize(HLOCAL hMem)
Definition: heapmem.c:1794
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
interface IMalloc * LPMALLOC
Definition: objfwd.h:12
uint32_t ULONG
Definition: typedefs.h:59

Referenced by START_TEST().

Variable Documentation

◆ hMapi32

HMODULE hMapi32 = 0
static

Definition at line 31 of file imalloc.c.

Referenced by START_TEST(), and test_IMalloc().