2003-11-25 02:02:02 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for heap functions
|
|
|
|
*
|
|
|
|
* Copyright 2003 Dimitrie O. Paun
|
2006-04-14 10:20:56 +02:00
|
|
|
* Copyright 2006 Detlef Riekenberg
|
2003-11-25 02:02:02 +01:00
|
|
|
*
|
|
|
|
* 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
|
2003-11-25 02:02:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-03-19 19:35:36 +01:00
|
|
|
#define MAGIC_DEAD 0xdeadbeef
|
|
|
|
|
2005-11-08 17:09:44 +01:00
|
|
|
static SIZE_T resize_9x(SIZE_T size)
|
|
|
|
{
|
|
|
|
DWORD dwSizeAligned = (size + 3) & ~3;
|
|
|
|
return max(dwSizeAligned, 12); /* at least 12 bytes */
|
|
|
|
}
|
|
|
|
|
2003-12-04 22:52:52 +01:00
|
|
|
START_TEST(heap)
|
2003-11-25 02:02:02 +01:00
|
|
|
{
|
2006-04-14 10:20:56 +02:00
|
|
|
LPVOID mem;
|
|
|
|
LPVOID msecond;
|
|
|
|
DWORD res;
|
2006-03-29 20:48:39 +02:00
|
|
|
UINT flags;
|
2003-12-04 22:52:52 +01:00
|
|
|
HGLOBAL gbl;
|
2006-03-19 19:35:36 +01:00
|
|
|
HGLOBAL hsecond;
|
|
|
|
SIZE_T size;
|
2003-11-25 02:02:02 +01:00
|
|
|
|
2003-12-04 22:52:52 +01:00
|
|
|
/* Heap*() functions */
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, 0);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(mem != NULL, "memory not allocated for size 0\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
|
|
|
|
mem = HeapReAlloc(GetProcessHeap(), 0, NULL, 10);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(mem == NULL, "memory allocated by HeapReAlloc\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
|
2005-07-11 15:20:40 +02:00
|
|
|
for (size = 0; size <= 256; size++)
|
|
|
|
{
|
|
|
|
SIZE_T heap_size;
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
heap_size = HeapSize(GetProcessHeap(), 0, mem);
|
2005-11-08 17:09:44 +01:00
|
|
|
ok(heap_size == size || heap_size == resize_9x(size),
|
|
|
|
"HeapSize returned %lu instead of %lu or %lu\n", heap_size, size, resize_9x(size));
|
2005-07-11 15:20:40 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
}
|
|
|
|
|
2007-05-22 11:59:18 +02:00
|
|
|
/* test some border cases of HeapAlloc and HeapReAlloc */
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, 0);
|
|
|
|
ok(mem != NULL, "memory not allocated for size 0\n");
|
|
|
|
msecond = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, ~0UL - 7);
|
|
|
|
ok(msecond == NULL, "HeapReAlloc(0xfffffff8) should have failed\n");
|
|
|
|
msecond = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, ~0UL);
|
|
|
|
ok(msecond == NULL, "HeapReAlloc(0xffffffff) should have failed\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, ~0UL);
|
|
|
|
ok(mem == NULL, "memory allocated for size ~0UL\n");
|
|
|
|
|
2003-12-04 22:52:52 +01:00
|
|
|
/* Global*() functions */
|
|
|
|
gbl = GlobalAlloc(GMEM_MOVEABLE, 0);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(gbl != NULL, "global memory not allocated for size 0\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
|
|
|
|
gbl = GlobalReAlloc(gbl, 10, GMEM_MOVEABLE);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(gbl != NULL, "Can't realloc global memory\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
size = GlobalSize(gbl);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%ld\n", size);
|
2003-12-15 20:51:17 +01:00
|
|
|
|
2006-01-12 11:55:25 +01:00
|
|
|
gbl = GlobalReAlloc(gbl, 0, GMEM_MOVEABLE);
|
|
|
|
ok(gbl != NULL, "GlobalReAlloc should not fail on size 0\n");
|
2003-12-15 20:51:17 +01:00
|
|
|
|
2003-12-04 22:52:52 +01:00
|
|
|
size = GlobalSize(gbl);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(size == 0, "Memory not resized to size 0, instead size=%ld\n", size);
|
|
|
|
ok(GlobalFree(gbl) == NULL, "Memory not freed\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
size = GlobalSize(gbl);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(size == 0, "Memory should have been freed, size=%ld\n", size);
|
2003-12-04 22:52:52 +01:00
|
|
|
|
|
|
|
gbl = GlobalReAlloc(0, 10, GMEM_MOVEABLE);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(gbl == NULL, "global realloc allocated memory\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
|
2006-04-14 10:20:56 +02:00
|
|
|
/* GlobalLock / GlobalUnlock with a valid handle */
|
2006-03-19 19:35:36 +01:00
|
|
|
gbl = GlobalAlloc(GMEM_MOVEABLE, 256);
|
2006-04-14 10:20:56 +02:00
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
mem = GlobalLock(gbl); /* #1 */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(mem != NULL, "returned %p with %d (expected '!= NULL')\n", mem, GetLastError());
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = GlobalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( flags == 1, "returned 0x%04x with %d (expected '0x0001')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
msecond = GlobalLock(gbl); /* #2 */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( msecond == mem, "returned %p with %d (expected '%p')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
msecond, GetLastError(), mem);
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = GlobalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( flags == 2, "returned 0x%04x with %d (expected '0x0002')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = GlobalUnlock(gbl); /* #1 */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = GlobalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( flags , "returned 0x%04x with %d (expected '!= 0')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = GlobalUnlock(gbl); /* #0 */
|
|
|
|
/* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */
|
|
|
|
ok(!res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == MAGIC_DEAD)),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned %d with %d (expected '0' with: ERROR_SUCCESS or "
|
2006-04-14 10:20:56 +02:00
|
|
|
"MAGIC_DEAD)\n", res, GetLastError());
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = GlobalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( !flags , "returned 0x%04x with %d (expected '0')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
|
|
|
|
/* Unlock an already unlocked Handle */
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = GlobalUnlock(gbl);
|
|
|
|
/* NT: ERROR_NOT_LOCKED, 9x: untouched */
|
|
|
|
ok( !res &&
|
|
|
|
((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned %d with %d (expected '0' with: ERROR_NOT_LOCKED or "
|
2006-04-14 10:20:56 +02:00
|
|
|
"MAGIC_DEAD)\n", res, GetLastError());
|
|
|
|
|
2006-03-19 19:35:36 +01:00
|
|
|
GlobalFree(gbl);
|
2006-12-14 17:59:46 +01:00
|
|
|
/* invalid handles are caught in windows: */
|
2006-03-19 19:35:36 +01:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
hsecond = GlobalFree(gbl); /* invalid handle: free memory twice */
|
|
|
|
ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %p with 0x%08x (expected %p with ERROR_INVALID_HANDLE)\n",
|
2006-03-19 19:35:36 +01:00
|
|
|
hsecond, GetLastError(), gbl);
|
2006-03-29 20:48:39 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = GlobalFlags(gbl);
|
|
|
|
ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned 0x%04x with 0x%08x (expected GMEM_INVALID_HANDLE with "
|
2006-03-29 20:48:39 +02:00
|
|
|
"ERROR_INVALID_HANDLE)\n", flags, GetLastError());
|
2006-03-31 12:27:30 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
size = GlobalSize(gbl);
|
|
|
|
ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %ld with 0x%08x (expected '0' with ERROR_INVALID_HANDLE)\n",
|
2006-03-31 12:27:30 +02:00
|
|
|
size, GetLastError());
|
2006-03-29 20:48:39 +02:00
|
|
|
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
mem = GlobalLock(gbl);
|
|
|
|
ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %p with 0x%08x (expected NULL with ERROR_INVALID_HANDLE)\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
mem, GetLastError());
|
|
|
|
|
|
|
|
/* documented on MSDN: GlobalUnlock() return FALSE on failure.
|
|
|
|
Win9x and wine return FALSE with ERROR_INVALID_HANDLE, but on
|
|
|
|
NT 3.51 and XPsp2, TRUE with ERROR_INVALID_HANDLE is returned.
|
|
|
|
The similar Test for LocalUnlock() works on all Systems */
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = GlobalUnlock(gbl);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %d with %d (expected ERROR_INVALID_HANDLE)\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
res, GetLastError());
|
|
|
|
|
2007-09-17 01:28:56 +02:00
|
|
|
gbl = GlobalAlloc(GMEM_DDESHARE, 100);
|
|
|
|
|
|
|
|
/* first free */
|
|
|
|
mem = GlobalFree(gbl);
|
|
|
|
ok(mem == NULL, "Expected NULL, got %p\n", mem);
|
|
|
|
|
|
|
|
/* invalid free */
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
mem = GlobalFree(gbl);
|
|
|
|
ok(mem == gbl, "Expected gbl, got %p\n", mem);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
|
|
|
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
2006-03-19 19:35:36 +01:00
|
|
|
|
2007-09-17 01:30:20 +02:00
|
|
|
gbl = GlobalAlloc(GMEM_DDESHARE, 100);
|
|
|
|
|
|
|
|
res = GlobalUnlock(gbl);
|
|
|
|
ok(res == 1, "Expected 1, got %d\n", res);
|
|
|
|
|
|
|
|
res = GlobalUnlock(gbl);
|
|
|
|
ok(res == 1, "Expected 1, got %d\n", res);
|
|
|
|
|
2007-09-20 08:49:26 +02:00
|
|
|
/* GlobalSize on an invalid handle */
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
size = GlobalSize((HGLOBAL)0xc042);
|
|
|
|
ok(size == 0, "Expected 0, got %ld\n", size);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
|
|
|
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
2006-04-14 10:20:56 +02:00
|
|
|
/* ####################################### */
|
2003-12-04 22:52:52 +01:00
|
|
|
/* Local*() functions */
|
2005-03-17 21:53:37 +01:00
|
|
|
gbl = LocalAlloc(LMEM_MOVEABLE, 0);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(gbl != NULL, "local memory not allocated for size 0\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
|
2005-03-17 21:53:37 +01:00
|
|
|
gbl = LocalReAlloc(gbl, 10, LMEM_MOVEABLE);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(gbl != NULL, "Can't realloc local memory\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
size = LocalSize(gbl);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%ld\n", size);
|
2003-12-15 20:51:17 +01:00
|
|
|
|
2006-01-12 11:55:25 +01:00
|
|
|
gbl = LocalReAlloc(gbl, 0, LMEM_MOVEABLE);
|
|
|
|
ok(gbl != NULL, "LocalReAlloc should not fail on size 0\n");
|
2003-12-15 20:51:17 +01:00
|
|
|
|
2003-12-04 22:52:52 +01:00
|
|
|
size = LocalSize(gbl);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(size == 0, "Memory not resized to size 0, instead size=%ld\n", size);
|
|
|
|
ok(LocalFree(gbl) == NULL, "Memory not freed\n");
|
2003-12-04 22:52:52 +01:00
|
|
|
size = LocalSize(gbl);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(size == 0, "Memory should have been freed, size=%ld\n", size);
|
2003-12-04 22:52:52 +01:00
|
|
|
|
2005-03-17 21:53:37 +01:00
|
|
|
gbl = LocalReAlloc(0, 10, LMEM_MOVEABLE);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(gbl == NULL, "local realloc allocated memory\n");
|
2003-11-25 02:02:02 +01:00
|
|
|
|
2006-04-14 10:20:56 +02:00
|
|
|
/* LocalLock / LocalUnlock with a valid handle */
|
2006-03-29 20:48:39 +02:00
|
|
|
gbl = LocalAlloc(LMEM_MOVEABLE, 256);
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
mem = LocalLock(gbl); /* #1 */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(mem != NULL, "returned %p with %d (expected '!= NULL')\n", mem, GetLastError());
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = LocalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( flags == 1, "returned 0x%04x with %d (expected '0x0001')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
msecond = LocalLock(gbl); /* #2 */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( msecond == mem, "returned %p with %d (expected '%p')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
msecond, GetLastError(), mem);
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = LocalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( flags == 2, "returned 0x%04x with %d (expected '0x0002')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = LocalUnlock(gbl); /* #1 */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = LocalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( flags , "returned 0x%04x with %d (expected '!= 0')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = LocalUnlock(gbl); /* #0 */
|
|
|
|
/* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */
|
|
|
|
ok(!res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == MAGIC_DEAD)),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned %d with %d (expected '0' with: ERROR_SUCCESS or "
|
2006-04-14 10:20:56 +02:00
|
|
|
"MAGIC_DEAD)\n", res, GetLastError());
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = LocalFlags(gbl);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( !flags , "returned 0x%04x with %d (expected '0')\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
flags, GetLastError());
|
|
|
|
|
|
|
|
/* Unlock an already unlocked Handle */
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = LocalUnlock(gbl);
|
|
|
|
/* NT: ERROR_NOT_LOCKED, 9x: untouched */
|
|
|
|
ok( !res &&
|
|
|
|
((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned %d with %d (expected '0' with: ERROR_NOT_LOCKED or "
|
2006-04-14 10:20:56 +02:00
|
|
|
"MAGIC_DEAD)\n", res, GetLastError());
|
|
|
|
|
2006-03-19 19:35:36 +01:00
|
|
|
LocalFree(gbl);
|
2006-12-14 17:59:46 +01:00
|
|
|
/* invalid handles are caught in windows: */
|
2006-03-19 19:35:36 +01:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
hsecond = LocalFree(gbl); /* invalid handle: free memory twice */
|
|
|
|
ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %p with 0x%08x (expected %p with ERROR_INVALID_HANDLE)\n",
|
2006-03-19 19:35:36 +01:00
|
|
|
hsecond, GetLastError(), gbl);
|
2006-03-29 20:48:39 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
flags = LocalFlags(gbl);
|
|
|
|
ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned 0x%04x with 0x%08x (expected LMEM_INVALID_HANDLE with "
|
2006-03-29 20:48:39 +02:00
|
|
|
"ERROR_INVALID_HANDLE)\n", flags, GetLastError());
|
2006-03-31 12:27:30 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
size = LocalSize(gbl);
|
|
|
|
ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %ld with 0x%08x (expected '0' with ERROR_INVALID_HANDLE)\n",
|
2006-03-31 12:27:30 +02:00
|
|
|
size, GetLastError());
|
2006-03-29 20:48:39 +02:00
|
|
|
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
mem = LocalLock(gbl);
|
|
|
|
ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %p with 0x%08x (expected NULL with ERROR_INVALID_HANDLE)\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
mem, GetLastError());
|
|
|
|
|
|
|
|
/* This Test works the same on all Systems (GlobalUnlock() is different) */
|
|
|
|
SetLastError(MAGIC_DEAD);
|
|
|
|
res = LocalUnlock(gbl);
|
|
|
|
ok(!res && (GetLastError() == ERROR_INVALID_HANDLE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"returned %d with %d (expected '0' with ERROR_INVALID_HANDLE)\n",
|
2006-04-14 10:20:56 +02:00
|
|
|
res, GetLastError());
|
2006-03-19 19:35:36 +01:00
|
|
|
|
2006-01-09 17:16:32 +01:00
|
|
|
/* trying to lock empty memory should give an error */
|
|
|
|
gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0);
|
|
|
|
ok(gbl != NULL, "returned NULL\n");
|
2006-04-14 10:20:56 +02:00
|
|
|
SetLastError(MAGIC_DEAD);
|
2006-01-09 17:16:32 +01:00
|
|
|
mem = GlobalLock(gbl);
|
2006-04-14 10:20:56 +02:00
|
|
|
/* NT: ERROR_DISCARDED, 9x: untouched */
|
|
|
|
ok( (mem == NULL) &&
|
|
|
|
((GetLastError() == ERROR_DISCARDED) || (GetLastError() == MAGIC_DEAD)),
|
2006-12-27 00:19:29 +01:00
|
|
|
"returned %p with 0x%x/%d (expected 'NULL' with: ERROR_DISCARDED or "
|
2006-04-14 10:20:56 +02:00
|
|
|
"MAGIC_DEAD)\n", mem, GetLastError(), GetLastError());
|
|
|
|
|
2006-01-09 17:16:32 +01:00
|
|
|
GlobalFree(gbl);
|
2003-11-25 02:02:02 +01:00
|
|
|
}
|