Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
v2: Add the broken results to the right patches.
dlls/kernel32/tests/heap.c | 110 ++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 55 deletions(-)
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index 6efe4da4634..a95e863486d 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -30,8 +30,6 @@ #include "winternl.h" #include "wine/test.h"
-#define MAGIC_DEAD 0xdeadbeef - /* some undocumented flags (names are made up) */ #define HEAP_PAGE_ALLOCS 0x01000000 #define HEAP_VALIDATE 0x10000000 @@ -160,83 +158,84 @@ static void test_heap(void) /* GlobalLock / GlobalUnlock with a valid handle */ gbl = GlobalAlloc(GMEM_MOVEABLE, 256);
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); mem = GlobalLock(gbl); /* #1 */ ok(mem != NULL, "returned %p with %ld (expected '!= NULL')\n", mem, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = GlobalFlags(gbl); ok( flags == 1, "returned 0x%04x with %ld (expected '0x0001')\n", flags, GetLastError());
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); msecond = GlobalLock(gbl); /* #2 */ ok( msecond == mem, "returned %p with %ld (expected '%p')\n", msecond, GetLastError(), mem); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = GlobalFlags(gbl); ok( flags == 2, "returned 0x%04x with %ld (expected '0x0002')\n", flags, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef );
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = GlobalUnlock(gbl); /* #1 */ ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = GlobalFlags(gbl); ok( flags , "returned 0x%04x with %ld (expected '!= 0')\n", flags, GetLastError());
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = GlobalUnlock(gbl); /* #0 */ /* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */ - ok(!res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == MAGIC_DEAD)), + ok( !res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == 0xdeadbeef)), "returned %ld with %ld (expected '0' with: ERROR_SUCCESS or " - "MAGIC_DEAD)\n", res, GetLastError()); - SetLastError(MAGIC_DEAD); + "0xdeadbeef)\n", + res, GetLastError() ); + SetLastError( 0xdeadbeef ); flags = GlobalFlags(gbl); ok( !flags , "returned 0x%04x with %ld (expected '0')\n", flags, GetLastError());
/* Unlock an already unlocked Handle */ - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = GlobalUnlock(gbl); /* NT: ERROR_NOT_LOCKED, 9x: untouched */ - ok( !res && - ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)), + ok( !res && ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == 0xdeadbeef)), "returned %ld with %ld (expected '0' with: ERROR_NOT_LOCKED or " - "MAGIC_DEAD)\n", res, GetLastError()); + "0xdeadbeef)\n", + res, GetLastError() );
GlobalFree(gbl); /* invalid handles are caught in windows: */ - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = GlobalFree(gbl); /* invalid handle: free memory twice */ ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", hsecond, GetLastError(), gbl); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = GlobalFree(LongToHandle(0xdeadbeef)); /* bogus handle */ ok( (hsecond == LongToHandle(0xdeadbeef)) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", hsecond, GetLastError(), LongToHandle(0xdeadbeef)); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = GlobalFree(LongToHandle(0xdeadbee0)); /* bogus pointer */ ok( (hsecond == LongToHandle(0xdeadbee0)) && ((GetLastError() == ERROR_INVALID_HANDLE) || broken(GetLastError() == ERROR_NOACCESS) /* wvista+ */), "returned %p with 0x%08lx (expected %p with ERROR_NOACCESS)\n", hsecond, GetLastError(), LongToHandle(0xdeadbee0));
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = GlobalFlags(gbl); ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE), "returned 0x%04x with 0x%08lx (expected GMEM_INVALID_HANDLE with " "ERROR_INVALID_HANDLE)\n", flags, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); size = GlobalSize(gbl); ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %Id with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n", size, GetLastError());
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); mem = GlobalLock(gbl); ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %p with 0x%08lx (expected NULL with ERROR_INVALID_HANDLE)\n", @@ -246,7 +245,7 @@ static void test_heap(void) 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); + SetLastError( 0xdeadbeef ); res = GlobalUnlock(gbl); ok(GetLastError() == ERROR_INVALID_HANDLE, "returned %ld with %ld (expected ERROR_INVALID_HANDLE)\n", @@ -261,7 +260,7 @@ static void test_heap(void) /* invalid free */ if (sizeof(void *) != 8) /* crashes on 64-bit */ { - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); mem = GlobalFree(gbl); ok(mem == gbl || broken(mem == NULL) /* nt4 */, "Expected gbl, got %p\n", mem); if (mem == gbl) @@ -273,7 +272,7 @@ static void test_heap(void) /* GMEM_FIXED block expands in place only without flags */ for (size = 1; size <= max_size; size <<= 1) { gbl = GlobalAlloc(GMEM_FIXED, init_size); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = GlobalReAlloc(gbl, size + init_size, 0); ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY), "got %p with %lx (expected %p or NULL) @%Id\n", hsecond, GetLastError(), gbl, size); @@ -283,7 +282,7 @@ static void test_heap(void) /* GMEM_FIXED block can be relocated with GMEM_MOVEABLE */ for (size = 1; size <= max_size; size <<= 1) { gbl = GlobalAlloc(GMEM_FIXED, init_size); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = GlobalReAlloc(gbl, size + init_size, GMEM_MOVEABLE); ok(hsecond != NULL, "got %p with %lx (expected non-NULL) @%Id\n", hsecond, GetLastError(), size); @@ -320,7 +319,7 @@ static void test_heap(void) /* GlobalSize on an invalid handle */ if (sizeof(void *) != 8) /* crashes on 64-bit Vista */ { - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); size = GlobalSize((HGLOBAL)0xc042); ok(size == 0, "Expected 0, got %Id\n", size); ok(GetLastError() == ERROR_INVALID_HANDLE || @@ -358,78 +357,79 @@ static void test_heap(void)
/* LocalLock / LocalUnlock with a valid handle */ gbl = LocalAlloc(LMEM_MOVEABLE, 256); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); mem = LocalLock(gbl); /* #1 */ ok(mem != NULL, "returned %p with %ld (expected '!= NULL')\n", mem, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = LocalFlags(gbl); ok( flags == 1, "returned 0x%04x with %ld (expected '0x0001')\n", flags, GetLastError());
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); msecond = LocalLock(gbl); /* #2 */ ok( msecond == mem, "returned %p with %ld (expected '%p')\n", msecond, GetLastError(), mem); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = LocalFlags(gbl); ok( flags == 2, "returned 0x%04x with %ld (expected '0x0002')\n", flags, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef );
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = LocalUnlock(gbl); /* #1 */ ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = LocalFlags(gbl); ok( flags , "returned 0x%04x with %ld (expected '!= 0')\n", flags, GetLastError());
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = LocalUnlock(gbl); /* #0 */ /* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */ - ok(!res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == MAGIC_DEAD)), + ok( !res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == 0xdeadbeef)), "returned %ld with %ld (expected '0' with: ERROR_SUCCESS or " - "MAGIC_DEAD)\n", res, GetLastError()); - SetLastError(MAGIC_DEAD); + "0xdeadbeef)\n", + res, GetLastError() ); + SetLastError( 0xdeadbeef ); flags = LocalFlags(gbl); ok( !flags , "returned 0x%04x with %ld (expected '0')\n", flags, GetLastError());
/* Unlock an already unlocked Handle */ - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = LocalUnlock(gbl); /* NT: ERROR_NOT_LOCKED, 9x: untouched */ - ok( !res && - ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)), + ok( !res && ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == 0xdeadbeef)), "returned %ld with %ld (expected '0' with: ERROR_NOT_LOCKED or " - "MAGIC_DEAD)\n", res, GetLastError()); + "0xdeadbeef)\n", + res, GetLastError() );
LocalFree(gbl); /* invalid handles are caught in windows: */ - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = LocalFree(gbl); /* invalid handle: free memory twice */ ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", hsecond, GetLastError(), gbl); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); flags = LocalFlags(gbl); ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE), "returned 0x%04x with 0x%08lx (expected LMEM_INVALID_HANDLE with " "ERROR_INVALID_HANDLE)\n", flags, GetLastError()); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); size = LocalSize(gbl); ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %Id with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n", size, GetLastError());
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); mem = LocalLock(gbl); ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE), "returned %p with 0x%08lx (expected NULL with ERROR_INVALID_HANDLE)\n", mem, GetLastError());
/* This Test works the same on all Systems (GlobalUnlock() is different) */ - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); res = LocalUnlock(gbl); ok(!res && (GetLastError() == ERROR_INVALID_HANDLE), "returned %ld with %ld (expected '0' with ERROR_INVALID_HANDLE)\n", @@ -438,7 +438,7 @@ static void test_heap(void) /* LMEM_FIXED block expands in place only without flags */ for (size = 1; size <= max_size; size <<= 1) { gbl = LocalAlloc(LMEM_FIXED, init_size); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = LocalReAlloc(gbl, size + init_size, 0); ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY), "got %p with %lx (expected %p or NULL) @%Id\n", hsecond, GetLastError(), gbl, size); @@ -448,7 +448,7 @@ static void test_heap(void) /* LMEM_FIXED memory can be relocated with LMEM_MOVEABLE */ for (size = 1; size <= max_size; size <<= 1) { gbl = LocalAlloc(LMEM_FIXED, init_size); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); hsecond = LocalReAlloc(gbl, size + init_size, LMEM_MOVEABLE); ok(hsecond != NULL, "got %p with %lx (expected non-NULL) @%Id\n", hsecond, GetLastError(), size); @@ -476,13 +476,13 @@ static void test_heap(void) /* trying to lock empty memory should give an error */ gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0); ok(gbl != NULL, "returned NULL\n"); - SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); mem = GlobalLock(gbl); /* NT: ERROR_DISCARDED, 9x: untouched */ - ok( (mem == NULL) && - ((GetLastError() == ERROR_DISCARDED) || (GetLastError() == MAGIC_DEAD)), + ok( (mem == NULL) && ((GetLastError() == ERROR_DISCARDED) || (GetLastError() == 0xdeadbeef)), "returned %p with 0x%lx/%ld (expected 'NULL' with: ERROR_DISCARDED or " - "MAGIC_DEAD)\n", mem, GetLastError(), GetLastError()); + "0xdeadbeef)\n", + mem, GetLastError(), GetLastError() );
GlobalFree(gbl);
@@ -825,7 +825,7 @@ static void test_obsolete_flags(void) gbl = GlobalAlloc(test_global_flags[i].flags, 4); ok(gbl != NULL, "GlobalAlloc failed\n");
- SetLastError(MAGIC_DEAD); + SetLastError( 0xdeadbeef ); resultflags = pGlobalFlags(gbl);
ok( resultflags == test_global_flags[i].globalflags ||
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernel32/tests/heap.c | 690 ++++++++++++++++++------------------- 1 file changed, 328 insertions(+), 362 deletions(-)
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index a95e863486d..8ed48994e14 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -88,7 +88,7 @@ static void test_heap(void) UINT flags; HGLOBAL gbl; HGLOBAL hsecond; - SIZE_T size, size2; + SIZE_T size; const SIZE_T max_size = 1024, init_size = 10;
/* Heap*() functions */ @@ -134,205 +134,6 @@ static void test_heap(void) "512K block not 16-byte aligned\n" ); HeapFree(GetProcessHeap(), 0, mem);
- /* Global*() functions */ - gbl = GlobalAlloc(GMEM_MOVEABLE, 0); - ok(gbl != NULL, "global memory not allocated for size 0\n"); - - gbl = GlobalReAlloc(gbl, 10, GMEM_MOVEABLE); - ok(gbl != NULL, "Can't realloc global memory\n"); - size = GlobalSize(gbl); - ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%Id\n", size); - - gbl = GlobalReAlloc(gbl, 0, GMEM_MOVEABLE); - ok(gbl != NULL, "GlobalReAlloc should not fail on size 0\n"); - - size = GlobalSize(gbl); - ok(size == 0, "Memory not resized to size 0, instead size=%Id\n", size); - ok(GlobalFree(gbl) == NULL, "Memory not freed\n"); - size = GlobalSize(gbl); - ok(size == 0, "Memory should have been freed, size=%Id\n", size); - - gbl = GlobalReAlloc(0, 10, GMEM_MOVEABLE); - ok(gbl == NULL, "global realloc allocated memory\n"); - - /* GlobalLock / GlobalUnlock with a valid handle */ - gbl = GlobalAlloc(GMEM_MOVEABLE, 256); - - SetLastError( 0xdeadbeef ); - mem = GlobalLock(gbl); /* #1 */ - ok(mem != NULL, "returned %p with %ld (expected '!= NULL')\n", mem, GetLastError()); - SetLastError( 0xdeadbeef ); - flags = GlobalFlags(gbl); - ok( flags == 1, "returned 0x%04x with %ld (expected '0x0001')\n", - flags, GetLastError()); - - SetLastError( 0xdeadbeef ); - msecond = GlobalLock(gbl); /* #2 */ - ok( msecond == mem, "returned %p with %ld (expected '%p')\n", - msecond, GetLastError(), mem); - SetLastError( 0xdeadbeef ); - flags = GlobalFlags(gbl); - ok( flags == 2, "returned 0x%04x with %ld (expected '0x0002')\n", - flags, GetLastError()); - SetLastError( 0xdeadbeef ); - - SetLastError( 0xdeadbeef ); - res = GlobalUnlock(gbl); /* #1 */ - ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError()); - SetLastError( 0xdeadbeef ); - flags = GlobalFlags(gbl); - ok( flags , "returned 0x%04x with %ld (expected '!= 0')\n", - flags, GetLastError()); - - SetLastError( 0xdeadbeef ); - res = GlobalUnlock(gbl); /* #0 */ - /* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */ - ok( !res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == 0xdeadbeef)), - "returned %ld with %ld (expected '0' with: ERROR_SUCCESS or " - "0xdeadbeef)\n", - res, GetLastError() ); - SetLastError( 0xdeadbeef ); - flags = GlobalFlags(gbl); - ok( !flags , "returned 0x%04x with %ld (expected '0')\n", - flags, GetLastError()); - - /* Unlock an already unlocked Handle */ - SetLastError( 0xdeadbeef ); - res = GlobalUnlock(gbl); - /* NT: ERROR_NOT_LOCKED, 9x: untouched */ - ok( !res && ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == 0xdeadbeef)), - "returned %ld with %ld (expected '0' with: ERROR_NOT_LOCKED or " - "0xdeadbeef)\n", - res, GetLastError() ); - - GlobalFree(gbl); - /* invalid handles are caught in windows: */ - SetLastError( 0xdeadbeef ); - hsecond = GlobalFree(gbl); /* invalid handle: free memory twice */ - ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", - hsecond, GetLastError(), gbl); - SetLastError( 0xdeadbeef ); - hsecond = GlobalFree(LongToHandle(0xdeadbeef)); /* bogus handle */ - ok( (hsecond == LongToHandle(0xdeadbeef)) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", - hsecond, GetLastError(), LongToHandle(0xdeadbeef)); - SetLastError( 0xdeadbeef ); - hsecond = GlobalFree(LongToHandle(0xdeadbee0)); /* bogus pointer */ - ok( (hsecond == LongToHandle(0xdeadbee0)) && - ((GetLastError() == ERROR_INVALID_HANDLE) || broken(GetLastError() == ERROR_NOACCESS) /* wvista+ */), - "returned %p with 0x%08lx (expected %p with ERROR_NOACCESS)\n", - hsecond, GetLastError(), LongToHandle(0xdeadbee0)); - - SetLastError( 0xdeadbeef ); - flags = GlobalFlags(gbl); - ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned 0x%04x with 0x%08lx (expected GMEM_INVALID_HANDLE with " - "ERROR_INVALID_HANDLE)\n", flags, GetLastError()); - SetLastError( 0xdeadbeef ); - size = GlobalSize(gbl); - ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %Id with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n", - size, GetLastError()); - - SetLastError( 0xdeadbeef ); - mem = GlobalLock(gbl); - ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %p with 0x%08lx (expected NULL with ERROR_INVALID_HANDLE)\n", - 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( 0xdeadbeef ); - res = GlobalUnlock(gbl); - ok(GetLastError() == ERROR_INVALID_HANDLE, - "returned %ld with %ld (expected ERROR_INVALID_HANDLE)\n", - res, GetLastError()); - - gbl = GlobalAlloc(GMEM_DDESHARE, 100); - - /* first free */ - mem = GlobalFree(gbl); - ok(mem == NULL, "Expected NULL, got %p\n", mem); - - /* invalid free */ - if (sizeof(void *) != 8) /* crashes on 64-bit */ - { - SetLastError( 0xdeadbeef ); - mem = GlobalFree(gbl); - ok(mem == gbl || broken(mem == NULL) /* nt4 */, "Expected gbl, got %p\n", mem); - if (mem == gbl) - ok(GetLastError() == ERROR_INVALID_HANDLE || - GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */ - "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError()); - } - - /* GMEM_FIXED block expands in place only without flags */ - for (size = 1; size <= max_size; size <<= 1) { - gbl = GlobalAlloc(GMEM_FIXED, init_size); - SetLastError( 0xdeadbeef ); - hsecond = GlobalReAlloc(gbl, size + init_size, 0); - ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY), - "got %p with %lx (expected %p or NULL) @%Id\n", hsecond, GetLastError(), gbl, size); - GlobalFree(gbl); - } - - /* GMEM_FIXED block can be relocated with GMEM_MOVEABLE */ - for (size = 1; size <= max_size; size <<= 1) { - gbl = GlobalAlloc(GMEM_FIXED, init_size); - SetLastError( 0xdeadbeef ); - hsecond = GlobalReAlloc(gbl, size + init_size, GMEM_MOVEABLE); - ok(hsecond != NULL, - "got %p with %lx (expected non-NULL) @%Id\n", hsecond, GetLastError(), size); - mem = GlobalLock(hsecond); - ok(mem == hsecond, "got %p (expected %p) @%Id\n", mem, hsecond, size); - GlobalFree(hsecond); - } - - gbl = GlobalAlloc(GMEM_DDESHARE, 100); - - res = GlobalUnlock(gbl); - ok(res == 1 || - broken(res == 0), /* win9x */ - "Expected 1 or 0, got %ld\n", res); - - res = GlobalUnlock(gbl); - ok(res == 1 || - broken(res == 0), /* win9x */ - "Expected 1 or 0, got %ld\n", res); - - GlobalFree(gbl); - - gbl = GlobalAlloc(GMEM_FIXED, 100); - - SetLastError(0xdeadbeef); - res = GlobalUnlock(gbl); - ok(res == 1 || - broken(res == 0), /* win9x */ - "Expected 1 or 0, got %ld\n", res); - ok(GetLastError() == 0xdeadbeef, "got %ld\n", GetLastError()); - - GlobalFree(gbl); - - /* GlobalSize on an invalid handle */ - if (sizeof(void *) != 8) /* crashes on 64-bit Vista */ - { - SetLastError( 0xdeadbeef ); - size = GlobalSize((HGLOBAL)0xc042); - ok(size == 0, "Expected 0, got %Id\n", size); - ok(GetLastError() == ERROR_INVALID_HANDLE || - GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */ - "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError()); - } - - gbl = GlobalAlloc( GMEM_FIXED, 0 ); - SetLastError(0xdeadbeef); - size = GlobalSize( gbl ); - ok( size == 1, "wrong size %Iu\n", size ); - GlobalFree( gbl ); - /* ####################################### */ /* Local*() functions */ gbl = LocalAlloc(LMEM_MOVEABLE, 0); @@ -472,49 +273,6 @@ static void test_heap(void) ok( !size || broken(size == 1), /* vistau64 */ "wrong size %Iu\n", size ); LocalFree( gbl ); - - /* trying to lock empty memory should give an error */ - gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0); - ok(gbl != NULL, "returned NULL\n"); - SetLastError( 0xdeadbeef ); - mem = GlobalLock(gbl); - /* NT: ERROR_DISCARDED, 9x: untouched */ - ok( (mem == NULL) && ((GetLastError() == ERROR_DISCARDED) || (GetLastError() == 0xdeadbeef)), - "returned %p with 0x%lx/%ld (expected 'NULL' with: ERROR_DISCARDED or " - "0xdeadbeef)\n", - mem, GetLastError(), GetLastError() ); - - GlobalFree(gbl); - - /* trying to get size from data pointer (GMEM_MOVEABLE) */ - gbl = GlobalAlloc(GMEM_MOVEABLE, 0x123); - ok(gbl != NULL, "returned NULL\n"); - mem = GlobalLock(gbl); - ok(mem != NULL, "returned NULL.\n"); - ok(gbl != mem, "unexpectedly equal.\n"); - - size = GlobalSize(gbl); - size2 = GlobalSize(mem); - ok(size == 0x123, "got %Iu\n", size); - ok(size2 == 0x123, "got %Iu\n", size2); - - GlobalFree(gbl); - - /* trying to get size from data pointer (GMEM_FIXED) */ - gbl = GlobalAlloc(GMEM_FIXED, 0x123); - ok(gbl != NULL, "returned NULL\n"); - mem = GlobalLock(gbl); - ok(mem != NULL, "returned NULL.\n"); - ok(gbl == mem, "got %p, %p.\n", gbl, mem); - - size = GlobalSize(gbl); - ok(size == 0x123, "got %Iu\n", size); - - GlobalFree(gbl); - - size = GlobalSize((void *)0xdeadbee0); - ok(size == 0, "got %Iu\n", size); - }
@@ -629,82 +387,339 @@ static void test_HeapCreate(void)
static void test_GlobalAlloc(void) { - ULONG memchunk; - HGLOBAL mem1,mem2,mem2a,mem2b; - UCHAR *mem2ptr; - UINT i; - BOOL error; - memchunk=100000; + static const UINT flags_tests[] = + { + GMEM_FIXED | GMEM_NOTIFY, + GMEM_FIXED | GMEM_DISCARDABLE, + GMEM_MOVEABLE | GMEM_NOTIFY, + GMEM_MOVEABLE | GMEM_DDESHARE, + GMEM_MOVEABLE | GMEM_NOT_BANKED, + GMEM_MOVEABLE | GMEM_NODISCARD, + GMEM_MOVEABLE | GMEM_DISCARDABLE, + GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_DISCARDABLE | GMEM_LOWER | GMEM_NOCOMPACT | GMEM_NODISCARD | GMEM_NOT_BANKED | GMEM_NOTIFY, + }; + static const char zero_buffer[100000] = {0}; + static const SIZE_T buffer_size = ARRAY_SIZE(zero_buffer); + const HGLOBAL invalid_mem = LongToHandle( 0xdeadbee0 + sizeof(void *) ); + void *const invalid_ptr = LongToHandle( 0xdeadbee0 ); + HGLOBAL mem, tmp_mem; + BYTE *ptr, *tmp_ptr; + UINT i, flags; + SIZE_T size; + BOOL ret;
- SetLastError(NO_ERROR); - /* Check that a normal alloc works */ - mem1=GlobalAlloc(0,memchunk); - ok(mem1!=NULL,"GlobalAlloc failed\n"); - if(mem1) { - ok(GlobalSize(mem1)>=memchunk, "GlobalAlloc should return a big enough memory block\n"); + mem = GlobalFree( 0 ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + mem = GlobalReAlloc( 0, 10, GMEM_MOVEABLE ); + ok( !mem, "GlobalReAlloc succeeded\n" ); + + mem = GlobalAlloc( GMEM_MOVEABLE, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + mem = GlobalReAlloc( mem, 10, GMEM_MOVEABLE ); + ok( !!mem, "GlobalReAlloc failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size >= 10 && size <= 16, "GlobalSize returned %Iu\n", size ); + mem = GlobalReAlloc( mem, 0, GMEM_MOVEABLE ); + ok( !!mem, "GlobalReAlloc failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size == 0, "GlobalSize returned %Iu\n", size ); + mem = GlobalReAlloc( mem, 10, GMEM_MOVEABLE ); + ok( !!mem, "GlobalReAlloc failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size >= 10 && size <= 16, "GlobalSize returned %Iu\n", size ); + tmp_mem = GlobalFree( mem ); + ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size == 0, "GlobalSize returned %Iu\n", size ); + + mem = GlobalAlloc( GMEM_MOVEABLE, 256 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + flags = GlobalFlags( mem ); + ok( flags == 1, "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + tmp_ptr = GlobalLock( mem ); + ok( !!tmp_ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( tmp_ptr == ptr, "got ptr %p, expected %p\n", tmp_ptr, ptr ); + flags = GlobalFlags( mem ); + ok( flags == 2, "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + ret = GlobalUnlock( mem ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + flags = GlobalFlags( mem ); + ok( flags == 1, "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = GlobalUnlock( mem ); + ok( !ret, "GlobalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_SUCCESS, "got error %lu\n", GetLastError() ); + flags = GlobalFlags( mem ); + ok( !flags, "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = GlobalUnlock( mem ); + ok( !ret, "GlobalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + tmp_mem = GlobalFree( mem ); + ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_DDESHARE, 100 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = GlobalFree( mem ); + ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); + if (sizeof(void *) != 8) /* crashes on 64-bit */ + { + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalFree( mem ); + ok( tmp_mem == mem, "GlobalFree succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + size = GlobalSize( (HGLOBAL)0xc042 ); + ok( size == 0, "GlobalSize succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); }
- /* Check that a 'zeroing' alloc works */ - mem2=GlobalAlloc(GMEM_ZEROINIT,memchunk); - ok(mem2!=NULL,"GlobalAlloc failed: error=%ld\n",GetLastError()); - if(mem2) { - ok(GlobalSize(mem2)>=memchunk,"GlobalAlloc should return a big enough memory block\n"); - mem2ptr=GlobalLock(mem2); - ok(mem2ptr==mem2,"GlobalLock should have returned the same memory as was allocated\n"); - if(mem2ptr) { - error=FALSE; - for(i=0;i<memchunk;i++) { - if(mem2ptr[i]!=0) { - error=TRUE; - } - } - ok(!error,"GlobalAlloc should have zeroed out its allocated memory\n"); - } - } - /* Check that GlobalReAlloc works */ + /* freed handles are caught */ + mem = GlobalAlloc( GMEM_MOVEABLE, 256 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = GlobalFree( mem ); + ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalFree( mem ); + ok( tmp_mem == mem, "GlobalFree succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + flags = GlobalFlags( mem ); + ok( flags == GMEM_INVALID_HANDLE, "GlobalFlags succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = GlobalSize( mem ); + ok( size == 0, "GlobalSize succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = GlobalLock( mem ); + ok( !ptr, "GlobalLock succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = GlobalUnlock( mem ); + todo_wine + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); +#if 0 /* corrupts Wine heap */ + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalReAlloc( mem, 0, GMEM_MOVEABLE ); + todo_wine + ok( !tmp_mem, "GlobalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); +#endif + + /* invalid handles are caught */ + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalFree( invalid_mem ); + ok( tmp_mem == invalid_mem, "GlobalFree succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + flags = GlobalFlags( invalid_mem ); + todo_wine + ok( flags == GMEM_INVALID_HANDLE, "GlobalFlags succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = GlobalSize( invalid_mem ); + ok( size == 0, "GlobalSize succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = GlobalLock( invalid_mem ); + ok( !ptr, "GlobalLock succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = GlobalUnlock( invalid_mem ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalReAlloc( invalid_mem, 0, GMEM_MOVEABLE ); + ok( !tmp_mem, "GlobalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + + /* invalid pointers are caught */ + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalFree( invalid_ptr ); + ok( tmp_mem == invalid_ptr, "GlobalFree succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + flags = GlobalFlags( invalid_ptr ); + todo_wine + ok( flags == GMEM_INVALID_HANDLE, "GlobalFlags succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = GlobalSize( invalid_ptr ); + ok( size == 0, "GlobalSize succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = GlobalLock( invalid_ptr ); + ok( !ptr, "GlobalLock succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = GlobalUnlock( invalid_ptr ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + ok( GetLastError() == 0xdeadbeef, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalReAlloc( invalid_ptr, 0, GMEM_MOVEABLE ); + ok( !tmp_mem, "GlobalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); + + /* GMEM_FIXED block doesn't allow resize, though it succeeds with GMEM_MODIFY */ + mem = GlobalAlloc( GMEM_FIXED, 10 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = GlobalReAlloc( mem, 9, GMEM_MODIFY ); + todo_wine + ok( !!tmp_mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem == mem, "got ptr %p, expected %p\n", tmp_mem, mem ); + size = GlobalSize( mem ); + ok( size == 10, "GlobalSize returned %Iu\n", size ); + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalReAlloc( mem, 10, 0 ); + todo_wine + ok( !tmp_mem || broken( tmp_mem == mem ) /* w1064v1507 / w1064v1607 */, + "GlobalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY || broken( GetLastError() == 0xdeadbeef ) /* w1064v1507 / w1064v1607 */, + "got error %lu\n", GetLastError() ); + if (tmp_mem) mem = tmp_mem; + tmp_mem = GlobalReAlloc( mem, 1024 * 1024, GMEM_MODIFY ); + todo_wine + ok( !!tmp_mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem == mem, "got ptr %p, expected %p\n", tmp_mem, mem ); + size = GlobalSize( mem ); + ok( size == 10, "GlobalSize returned %Iu\n", size ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + /* GMEM_FIXED block can be relocated with GMEM_MOVEABLE */ + mem = GlobalAlloc( GMEM_FIXED, 10 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = GlobalReAlloc( mem, 11, GMEM_MOVEABLE ); + ok( !!tmp_mem, "GlobalReAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem != mem || broken( tmp_mem == mem ) /* w1064v1507 / w1064v1607 */, + "GlobalReAlloc didn't relocate memory\n" ); + ptr = GlobalLock( tmp_mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( ptr == tmp_mem, "got ptr %p, expected %p\n", ptr, tmp_mem ); + GlobalFree( tmp_mem ); + + mem = GlobalAlloc( GMEM_DDESHARE, 100 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + ret = GlobalUnlock( mem ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + ret = GlobalUnlock( mem ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_FIXED, 100 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + ret = GlobalUnlock( mem ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_FIXED, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size == 1, "GlobalSize returned %Iu\n", size ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + /* trying to lock empty memory should give an error */ + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = GlobalLock( mem ); + ok( !ptr, "GlobalLock succeeded\n" ); + ok( GetLastError() == ERROR_DISCARDED, "got error %lu\n", GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( 0, buffer_size ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size >= buffer_size, "GlobalSize returned %Iu, error %lu\n", size, GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_ZEROINIT, buffer_size ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + size = GlobalSize( mem ); + ok( size >= buffer_size, "GlobalSize returned %Iu, error %lu\n", size, GetLastError() ); + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( ptr == mem, "got ptr %p, expected %p\n", ptr, mem ); + ok( !memcmp( ptr, zero_buffer, buffer_size ), "GlobalAlloc didn't clear memory\n" ); + /* Check that we can change GMEM_FIXED to GMEM_MOVEABLE */ - mem2a=GlobalReAlloc(mem2,0,GMEM_MODIFY | GMEM_MOVEABLE); - if(mem2a!=NULL) { - mem2=mem2a; - mem2ptr=GlobalLock(mem2a); - ok(mem2ptr!=NULL && !GlobalUnlock(mem2a)&&GetLastError()==NO_ERROR, - "Converting from FIXED to MOVEABLE didn't REALLY work\n"); - } + mem = GlobalReAlloc( mem, 0, GMEM_MODIFY | GMEM_MOVEABLE ); + ok( !!mem, "GlobalReAlloc failed, error %lu\n", GetLastError() ); + ok( mem != ptr, "GlobalReAlloc returned unexpected handle\n" ); + size = GlobalSize( mem ); + ok( size == buffer_size, "GlobalSize returned %Iu, error %lu\n", size, GetLastError() );
- /* Check that ReAllocing memory works as expected */ - mem2a=GlobalReAlloc(mem2,2*memchunk,GMEM_MOVEABLE | GMEM_ZEROINIT); - ok(mem2a!=NULL,"GlobalReAlloc failed\n"); - if(mem2a) { - ok(GlobalSize(mem2a)>=2*memchunk,"GlobalReAlloc failed\n"); - mem2ptr=GlobalLock(mem2a); - ok(mem2ptr!=NULL,"GlobalLock Failed\n"); - if(mem2ptr) { - error=FALSE; - for(i=0;i<memchunk;i++) { - if(mem2ptr[memchunk+i]!=0) { - error=TRUE; - } - } - ok(!error,"GlobalReAlloc should have zeroed out its allocated memory\n"); + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + ret = GlobalUnlock( mem ); + ok( !ret, "GlobalUnlock succeeded, error %lu\n", GetLastError() ); + ok( GetLastError() == NO_ERROR, "got error %lu\n", GetLastError() );
- /* Check that GlobalHandle works */ - mem2b=GlobalHandle(mem2ptr); - ok(mem2b==mem2a,"GlobalHandle didn't return the correct memory handle %p/%p for %p\n", - mem2a, mem2b, mem2ptr); - /* Check that we can't discard locked memory */ - mem2b=GlobalDiscard(mem2a); - if(mem2b==NULL) { - ok(!GlobalUnlock(mem2a) && GetLastError()==NO_ERROR,"GlobalUnlock Failed\n"); - } - } - } - if(mem1) { - ok(GlobalFree(mem1)==NULL,"GlobalFree failed\n"); - } - if(mem2a) { - ok(GlobalFree(mem2a)==NULL,"GlobalFree failed\n"); - } else { - ok(GlobalFree(mem2)==NULL,"GlobalFree failed\n"); + tmp_mem = GlobalReAlloc( mem, 2 * buffer_size, GMEM_MOVEABLE | GMEM_ZEROINIT ); + ok( !!tmp_mem, "GlobalReAlloc failed\n" ); + ok( tmp_mem == mem || broken( tmp_mem != mem ) /* happens sometimes?? */, + "GlobalReAlloc returned unexpected handle\n" ); + mem = tmp_mem; + + size = GlobalSize( mem ); + ok( size >= 2 * buffer_size, "GlobalSize returned %Iu, error %lu\n", size, GetLastError() ); + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + ok( !memcmp( ptr, zero_buffer, buffer_size ), "GlobalReAlloc didn't clear memory\n" ); + ok( !memcmp( ptr + buffer_size, zero_buffer, buffer_size ), + "GlobalReAlloc didn't clear memory\n" ); + + tmp_mem = GlobalHandle( ptr ); + ok( tmp_mem == mem, "GlobalHandle returned unexpected handle\n" ); + /* Check that we can't discard locked memory */ + SetLastError( 0xdeadbeef ); + tmp_mem = GlobalDiscard( mem ); + ok( !tmp_mem, "GlobalDiscard succeeded\n" ); + ret = GlobalUnlock( mem ); + ok( !ret, "GlobalUnlock succeeded, error %lu\n", GetLastError() ); + ok( GetLastError() == NO_ERROR, "got error %lu\n", GetLastError() ); + + tmp_mem = GlobalDiscard( mem ); + ok( tmp_mem == mem, "GlobalDiscard failed, error %lu\n", GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + for (i = 0; i < ARRAY_SIZE(flags_tests); i++) + { + mem = GlobalAlloc( flags_tests[i], 4 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + flags = GlobalFlags( mem ); + ok( !(flags & ~(GMEM_DDESHARE | GMEM_DISCARDABLE)), "got flags %#x, error %lu\n", flags, GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); } }
@@ -789,54 +804,6 @@ static void test_LocalAlloc(void) } }
-static void test_obsolete_flags(void) -{ - static struct { - UINT flags; - UINT globalflags; - } test_global_flags[] = { - {GMEM_FIXED | GMEM_NOTIFY, 0}, - {GMEM_FIXED | GMEM_DISCARDABLE, 0}, - {GMEM_MOVEABLE | GMEM_NOTIFY, 0}, - {GMEM_MOVEABLE | GMEM_DDESHARE, GMEM_DDESHARE}, - {GMEM_MOVEABLE | GMEM_NOT_BANKED, 0}, - {GMEM_MOVEABLE | GMEM_NODISCARD, 0}, - {GMEM_MOVEABLE | GMEM_DISCARDABLE, GMEM_DISCARDABLE}, - {GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_DISCARDABLE | GMEM_LOWER | GMEM_NOCOMPACT | GMEM_NODISCARD | - GMEM_NOT_BANKED | GMEM_NOTIFY, GMEM_DDESHARE | GMEM_DISCARDABLE}, - }; - - unsigned int i; - HGLOBAL gbl; - UINT resultflags; - - UINT (WINAPI *pGlobalFlags)(HGLOBAL); - - pGlobalFlags = (void *) GetProcAddress(GetModuleHandleA("kernel32"), "GlobalFlags"); - - if (!pGlobalFlags) - { - win_skip("GlobalFlags is not available\n"); - return; - } - - for (i = 0; i < ARRAY_SIZE(test_global_flags); i++) - { - gbl = GlobalAlloc(test_global_flags[i].flags, 4); - ok(gbl != NULL, "GlobalAlloc failed\n"); - - SetLastError( 0xdeadbeef ); - resultflags = pGlobalFlags(gbl); - - ok( resultflags == test_global_flags[i].globalflags || - broken(resultflags == (test_global_flags[i].globalflags & ~GMEM_DDESHARE)), /* win9x */ - "%u: expected 0x%08x, but returned 0x%08x with %ld\n", - i, test_global_flags[i].globalflags, resultflags, GetLastError() ); - - GlobalFree(gbl); - } -} - static void test_HeapQueryInformation(void) { ULONG info; @@ -1306,7 +1273,6 @@ START_TEST(heap) }
test_heap(); - test_obsolete_flags(); test_HeapCreate(); test_GlobalAlloc(); test_LocalAlloc();
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernel32/tests/heap.c | 525 ++++++++++++++++++++++--------------- 1 file changed, 308 insertions(+), 217 deletions(-)
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index 8ed48994e14..b859cf8f214 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -84,12 +84,7 @@ static void test_heap(void) { LPVOID mem; LPVOID msecond; - DWORD res; - UINT flags; - HGLOBAL gbl; - HGLOBAL hsecond; SIZE_T size; - const SIZE_T max_size = 1024, init_size = 10;
/* Heap*() functions */ mem = HeapAlloc(GetProcessHeap(), 0, 0); @@ -133,146 +128,6 @@ static void test_heap(void) ok( (ULONG_PTR)mem % 16 == 0 || broken((ULONG_PTR)mem % 16) /* win9x */, "512K block not 16-byte aligned\n" ); HeapFree(GetProcessHeap(), 0, mem); - - /* ####################################### */ - /* Local*() functions */ - gbl = LocalAlloc(LMEM_MOVEABLE, 0); - ok(gbl != NULL, "local memory not allocated for size 0\n"); - - gbl = LocalReAlloc(gbl, 10, LMEM_MOVEABLE); - ok(gbl != NULL, "Can't realloc local memory\n"); - size = LocalSize(gbl); - ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%Id\n", size); - - gbl = LocalReAlloc(gbl, 0, LMEM_MOVEABLE); - ok(gbl != NULL, "LocalReAlloc should not fail on size 0\n"); - - size = LocalSize(gbl); - ok(size == 0, "Memory not resized to size 0, instead size=%Id\n", size); - ok(LocalFree(gbl) == NULL, "Memory not freed\n"); - size = LocalSize(gbl); - ok(size == 0, "Memory should have been freed, size=%Id\n", size); - - gbl = LocalReAlloc(0, 10, LMEM_MOVEABLE); - ok(gbl == NULL, "local realloc allocated memory\n"); - - /* LocalLock / LocalUnlock with a valid handle */ - gbl = LocalAlloc(LMEM_MOVEABLE, 256); - SetLastError( 0xdeadbeef ); - mem = LocalLock(gbl); /* #1 */ - ok(mem != NULL, "returned %p with %ld (expected '!= NULL')\n", mem, GetLastError()); - SetLastError( 0xdeadbeef ); - flags = LocalFlags(gbl); - ok( flags == 1, "returned 0x%04x with %ld (expected '0x0001')\n", - flags, GetLastError()); - - SetLastError( 0xdeadbeef ); - msecond = LocalLock(gbl); /* #2 */ - ok( msecond == mem, "returned %p with %ld (expected '%p')\n", - msecond, GetLastError(), mem); - SetLastError( 0xdeadbeef ); - flags = LocalFlags(gbl); - ok( flags == 2, "returned 0x%04x with %ld (expected '0x0002')\n", - flags, GetLastError()); - SetLastError( 0xdeadbeef ); - - SetLastError( 0xdeadbeef ); - res = LocalUnlock(gbl); /* #1 */ - ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError()); - SetLastError( 0xdeadbeef ); - flags = LocalFlags(gbl); - ok( flags , "returned 0x%04x with %ld (expected '!= 0')\n", - flags, GetLastError()); - - SetLastError( 0xdeadbeef ); - res = LocalUnlock(gbl); /* #0 */ - /* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */ - ok( !res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == 0xdeadbeef)), - "returned %ld with %ld (expected '0' with: ERROR_SUCCESS or " - "0xdeadbeef)\n", - res, GetLastError() ); - SetLastError( 0xdeadbeef ); - flags = LocalFlags(gbl); - ok( !flags , "returned 0x%04x with %ld (expected '0')\n", - flags, GetLastError()); - - /* Unlock an already unlocked Handle */ - SetLastError( 0xdeadbeef ); - res = LocalUnlock(gbl); - /* NT: ERROR_NOT_LOCKED, 9x: untouched */ - ok( !res && ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == 0xdeadbeef)), - "returned %ld with %ld (expected '0' with: ERROR_NOT_LOCKED or " - "0xdeadbeef)\n", - res, GetLastError() ); - - LocalFree(gbl); - /* invalid handles are caught in windows: */ - SetLastError( 0xdeadbeef ); - hsecond = LocalFree(gbl); /* invalid handle: free memory twice */ - ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %p with 0x%08lx (expected %p with ERROR_INVALID_HANDLE)\n", - hsecond, GetLastError(), gbl); - SetLastError( 0xdeadbeef ); - flags = LocalFlags(gbl); - ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned 0x%04x with 0x%08lx (expected LMEM_INVALID_HANDLE with " - "ERROR_INVALID_HANDLE)\n", flags, GetLastError()); - SetLastError( 0xdeadbeef ); - size = LocalSize(gbl); - ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %Id with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n", - size, GetLastError()); - - SetLastError( 0xdeadbeef ); - mem = LocalLock(gbl); - ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %p with 0x%08lx (expected NULL with ERROR_INVALID_HANDLE)\n", - mem, GetLastError()); - - /* This Test works the same on all Systems (GlobalUnlock() is different) */ - SetLastError( 0xdeadbeef ); - res = LocalUnlock(gbl); - ok(!res && (GetLastError() == ERROR_INVALID_HANDLE), - "returned %ld with %ld (expected '0' with ERROR_INVALID_HANDLE)\n", - res, GetLastError()); - - /* LMEM_FIXED block expands in place only without flags */ - for (size = 1; size <= max_size; size <<= 1) { - gbl = LocalAlloc(LMEM_FIXED, init_size); - SetLastError( 0xdeadbeef ); - hsecond = LocalReAlloc(gbl, size + init_size, 0); - ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY), - "got %p with %lx (expected %p or NULL) @%Id\n", hsecond, GetLastError(), gbl, size); - LocalFree(gbl); - } - - /* LMEM_FIXED memory can be relocated with LMEM_MOVEABLE */ - for (size = 1; size <= max_size; size <<= 1) { - gbl = LocalAlloc(LMEM_FIXED, init_size); - SetLastError( 0xdeadbeef ); - hsecond = LocalReAlloc(gbl, size + init_size, LMEM_MOVEABLE); - ok(hsecond != NULL, - "got %p with %lx (expected non-NULL) @%Id\n", hsecond, GetLastError(), size); - mem = LocalLock(hsecond); - ok(mem == hsecond, "got %p (expected %p) @%Id\n", mem, hsecond, size); - LocalFree(hsecond); - } - - /* trying to unlock pointer from LocalAlloc */ - gbl = LocalAlloc(LMEM_FIXED, 100); - SetLastError(0xdeadbeef); - res = LocalUnlock(gbl); - ok(res == 0, "Expected 0, got %ld\n", res); - ok(GetLastError() == ERROR_NOT_LOCKED || - broken(GetLastError() == 0xdeadbeef) /* win9x */, "got %ld\n", GetLastError()); - LocalFree(gbl); - - gbl = LocalAlloc( LMEM_FIXED, 0 ); - SetLastError(0xdeadbeef); - size = LocalSize( gbl ); - ok( !size || broken(size == 1), /* vistau64 */ - "wrong size %Iu\n", size ); - LocalFree( gbl ); }
@@ -723,84 +578,320 @@ static void test_GlobalAlloc(void) } }
- static void test_LocalAlloc(void) { - ULONG memchunk; - HLOCAL mem1,mem2,mem2a,mem2b; - UCHAR *mem2ptr; - UINT i; - BOOL error; - memchunk=100000; + static const UINT flags_tests[] = + { + LMEM_FIXED, + LMEM_FIXED | LMEM_DISCARDABLE, + LMEM_MOVEABLE, + LMEM_MOVEABLE | LMEM_NODISCARD, + LMEM_MOVEABLE | LMEM_DISCARDABLE, + LMEM_MOVEABLE | LMEM_DISCARDABLE | LMEM_NOCOMPACT | LMEM_NODISCARD, + }; + static const char zero_buffer[100000] = {0}; + static const SIZE_T buffer_size = ARRAY_SIZE(zero_buffer); + const HLOCAL invalid_mem = LongToHandle( 0xdeadbee0 + sizeof(void *) ); + void *const invalid_ptr = LongToHandle( 0xdeadbee0 ); + HLOCAL mem, tmp_mem; + BYTE *ptr, *tmp_ptr; + UINT i, flags; + SIZE_T size; + BOOL ret;
- /* Check that a normal alloc works */ - mem1=LocalAlloc(0,memchunk); - ok(mem1!=NULL,"LocalAlloc failed: error=%ld\n",GetLastError()); - if(mem1) { - ok(LocalSize(mem1)>=memchunk, "LocalAlloc should return a big enough memory block\n"); - } + mem = LocalFree( 0 ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + mem = LocalReAlloc( 0, 10, LMEM_MOVEABLE ); + ok( !mem, "LocalReAlloc succeeded\n" );
- /* Check that a 'zeroing' and lock alloc works */ - mem2=LocalAlloc(LMEM_ZEROINIT|LMEM_MOVEABLE,memchunk); - ok(mem2!=NULL,"LocalAlloc failed: error=%ld\n",GetLastError()); - if(mem2) { - ok(LocalSize(mem2)>=memchunk,"LocalAlloc should return a big enough memory block\n"); - mem2ptr=LocalLock(mem2); - ok(mem2ptr!=NULL,"LocalLock: error=%ld\n",GetLastError()); - if(mem2ptr) { - error=FALSE; - for(i=0;i<memchunk;i++) { - if(mem2ptr[i]!=0) { - error=TRUE; - } - } - ok(!error,"LocalAlloc should have zeroed out its allocated memory\n"); - SetLastError(0); - error=LocalUnlock(mem2); - ok(!error && GetLastError()==NO_ERROR, - "LocalUnlock Failed: rc=%d err=%ld\n",error,GetLastError()); - } - } - mem2a=LocalFree(mem2); - ok(mem2a==NULL, "LocalFree failed: %p\n",mem2a); + mem = LocalAlloc( LMEM_MOVEABLE, 0 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + mem = LocalReAlloc( mem, 10, LMEM_MOVEABLE ); + ok( !!mem, "LocalReAlloc failed, error %lu\n", GetLastError() ); + size = LocalSize( mem ); + ok( size >= 10 && size <= 16, "LocalSize returned %Iu\n", size ); + mem = LocalReAlloc( mem, 0, LMEM_MOVEABLE ); + ok( !!mem, "LocalReAlloc failed, error %lu\n", GetLastError() ); + size = LocalSize( mem ); + ok( size == 0, "LocalSize returned %Iu\n", size ); + mem = LocalReAlloc( mem, 10, LMEM_MOVEABLE ); + ok( !!mem, "LocalReAlloc failed, error %lu\n", GetLastError() ); + size = LocalSize( mem ); + ok( size >= 10 && size <= 16, "LocalSize returned %Iu\n", size ); + tmp_mem = LocalFree( mem ); + ok( !tmp_mem, "LocalFree failed, error %lu\n", GetLastError() ); + size = LocalSize( mem ); + ok( size == 0, "LocalSize returned %Iu\n", size );
- /* Reallocate mem2 as moveable memory */ - mem2=LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,memchunk); - ok(mem2!=NULL, "LocalAlloc failed to create moveable memory, error=%ld\n",GetLastError()); + mem = LocalAlloc( LMEM_MOVEABLE, 256 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + ptr = LocalLock( mem ); + ok( !!ptr, "LocalLock failed, error %lu\n", GetLastError() ); + ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + flags = LocalFlags( mem ); + ok( flags == 1, "LocalFlags returned %#x, error %lu\n", flags, GetLastError() ); + tmp_ptr = LocalLock( mem ); + ok( !!tmp_ptr, "LocalLock failed, error %lu\n", GetLastError() ); + ok( tmp_ptr == ptr, "got ptr %p, expected %p\n", tmp_ptr, ptr ); + flags = LocalFlags( mem ); + ok( flags == 2, "LocalFlags returned %#x, error %lu\n", flags, GetLastError() ); + ret = LocalUnlock( mem ); + ok( ret, "LocalUnlock failed, error %lu\n", GetLastError() ); + flags = LocalFlags( mem ); + ok( flags == 1, "LocalFlags returned %#x, error %lu\n", flags, GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = LocalUnlock( mem ); + ok( !ret, "LocalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_SUCCESS, "got error %lu\n", GetLastError() ); + flags = LocalFlags( mem ); + ok( !flags, "LocalFlags returned %#x, error %lu\n", flags, GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = LocalUnlock( mem ); + ok( !ret, "LocalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + tmp_mem = LocalFree( mem ); + ok( !tmp_mem, "LocalFree failed, error %lu\n", GetLastError() );
- /* Check that ReAllocing memory works as expected */ - mem2a=LocalReAlloc(mem2,2*memchunk,LMEM_MOVEABLE | LMEM_ZEROINIT); - ok(mem2a!=NULL,"LocalReAlloc failed, error=%ld\n",GetLastError()); - if(mem2a) { - ok(LocalSize(mem2a)>=2*memchunk,"LocalReAlloc failed\n"); - mem2ptr=LocalLock(mem2a); - ok(mem2ptr!=NULL,"LocalLock Failed\n"); - if(mem2ptr) { - error=FALSE; - for(i=0;i<memchunk;i++) { - if(mem2ptr[memchunk+i]!=0) { - error=TRUE; - } - } - ok(!error,"LocalReAlloc should have zeroed out its allocated memory\n"); - /* Check that LocalHandle works */ - mem2b=LocalHandle(mem2ptr); - ok(mem2b==mem2a,"LocalHandle didn't return the correct memory handle %p/%p for %p\n", - mem2a, mem2b, mem2ptr); - /* Check that we can't discard locked memory */ - mem2b=LocalDiscard(mem2a); - ok(mem2b==NULL,"Discarded memory we shouldn't have\n"); - SetLastError(NO_ERROR); - ok(!LocalUnlock(mem2a) && GetLastError()==NO_ERROR, "LocalUnlock Failed\n"); - } - } - if(mem1) { - ok(LocalFree(mem1)==NULL,"LocalFree failed\n"); - } - if(mem2a) { - ok(LocalFree(mem2a)==NULL,"LocalFree failed\n"); - } else { - ok(LocalFree(mem2)==NULL,"LocalFree failed\n"); + /* freed handles are caught */ + mem = LocalAlloc( LMEM_MOVEABLE, 256 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = LocalFree( mem ); + ok( !tmp_mem, "LocalFree failed, error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + tmp_mem = LocalFree( mem ); + ok( tmp_mem == mem, "LocalFree succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + flags = LocalFlags( mem ); + ok( flags == LMEM_INVALID_HANDLE, "LocalFlags succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = LocalSize( mem ); + ok( size == 0, "LocalSize succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = LocalLock( mem ); + ok( !ptr, "LocalLock succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = LocalUnlock( mem ); + ok( !ret, "LocalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); +#if 0 /* corrupts Wine heap */ + SetLastError( 0xdeadbeef ); + tmp_mem = LocalReAlloc( mem, 0, LMEM_MOVEABLE ); + todo_wine + ok( !tmp_mem, "LocalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); +#endif + + /* invalid handles are caught */ + SetLastError( 0xdeadbeef ); + tmp_mem = LocalFree( invalid_mem ); + ok( tmp_mem == invalid_mem, "LocalFree succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + flags = LocalFlags( invalid_mem ); + todo_wine + ok( flags == LMEM_INVALID_HANDLE, "LocalFlags succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = LocalSize( invalid_mem ); + ok( size == 0, "LocalSize succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = LocalLock( invalid_mem ); + ok( !ptr, "LocalLock succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = LocalUnlock( invalid_mem ); + ok( !ret, "LocalUnlock succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + tmp_mem = LocalReAlloc( invalid_mem, 0, LMEM_MOVEABLE ); + ok( !tmp_mem, "LocalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + + /* invalid pointers are caught */ + SetLastError( 0xdeadbeef ); + tmp_mem = LocalFree( invalid_ptr ); + ok( tmp_mem == invalid_ptr, "LocalFree succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + flags = LocalFlags( invalid_ptr ); + todo_wine + ok( flags == LMEM_INVALID_HANDLE, "LocalFlags succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = LocalSize( invalid_ptr ); + ok( size == 0, "LocalSize succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = LocalLock( invalid_ptr ); + ok( !ptr, "LocalLock succeeded\n" ); + ok( GetLastError() == 0xdeadbeef, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = LocalUnlock( invalid_ptr ); + ok( !ret, "LocalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + tmp_mem = LocalReAlloc( invalid_ptr, 0, LMEM_MOVEABLE ); + ok( !tmp_mem, "LocalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); + + /* LMEM_FIXED block doesn't allow resize, though it succeeds with LMEM_MODIFY */ + mem = LocalAlloc( LMEM_FIXED, 10 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = LocalReAlloc( mem, 9, LMEM_MODIFY ); + todo_wine + ok( !!tmp_mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem == mem, "got ptr %p, expected %p\n", tmp_mem, mem ); + size = LocalSize( mem ); + ok( size == 10, "LocalSize returned %Iu\n", size ); + SetLastError( 0xdeadbeef ); + tmp_mem = LocalReAlloc( mem, 10, 0 ); + todo_wine + ok( !tmp_mem || broken( tmp_mem == mem ) /* w1064v1507 / w1064v1607 */, + "LocalReAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY || broken( GetLastError() == 0xdeadbeef ) /* w1064v1507 / w1064v1607 */, + "got error %lu\n", GetLastError() ); + if (tmp_mem) mem = tmp_mem; + tmp_mem = LocalReAlloc( mem, 1024 * 1024, LMEM_MODIFY ); + todo_wine + ok( !!tmp_mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem == mem, "got ptr %p, expected %p\n", tmp_mem, mem ); + size = LocalSize( mem ); + ok( size == 10, "LocalSize returned %Iu\n", size ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + /* LMEM_FIXED block can be relocated with LMEM_MOVEABLE */ + mem = LocalAlloc( LMEM_FIXED, 10 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + tmp_mem = LocalReAlloc( mem, 11, LMEM_MOVEABLE ); + ok( !!tmp_mem, "LocalReAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem != mem || broken( tmp_mem == mem ) /* w1064v1507 / w1064v1607 */, + "LocalReAlloc didn't relocate memory\n" ); + ptr = LocalLock( tmp_mem ); + ok( !!ptr, "LocalLock failed, error %lu\n", GetLastError() ); + ok( ptr == tmp_mem, "got ptr %p, expected %p\n", ptr, tmp_mem ); + LocalFree( tmp_mem ); + + mem = LocalAlloc( LMEM_FIXED, 100 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = LocalUnlock( mem ); + ok( !ret, "LocalUnlock succeeded\n" ); + ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + mem = LocalAlloc( LMEM_FIXED, 0 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + size = LocalSize( mem ); + ok( size == 0, "LocalSize returned %Iu\n", size ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + /* trying to lock empty memory should give an error */ + mem = LocalAlloc( LMEM_MOVEABLE | LMEM_ZEROINIT, 0 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ptr = LocalLock( mem ); + ok( !ptr, "LocalLock succeeded\n" ); + ok( GetLastError() == ERROR_DISCARDED, "got error %lu\n", GetLastError() ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + mem = LocalAlloc( 0, buffer_size ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + size = LocalSize( mem ); + ok( size >= buffer_size, "LocalSize returned %Iu, error %lu\n", size, GetLastError() ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + mem = LocalAlloc( LMEM_ZEROINIT, buffer_size ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + size = LocalSize( mem ); + ok( size >= buffer_size, "LocalSize returned %Iu, error %lu\n", size, GetLastError() ); + ptr = LocalLock( mem ); + ok( !!ptr, "LocalLock failed, error %lu\n", GetLastError() ); + ok( ptr == mem, "got ptr %p, expected %p\n", ptr, mem ); + ok( !memcmp( ptr, zero_buffer, buffer_size ), "LocalAlloc didn't clear memory\n" ); + + /* Check that we cannot change LMEM_FIXED to LMEM_MOVEABLE */ + mem = LocalReAlloc( mem, 0, LMEM_MODIFY | LMEM_MOVEABLE ); + ok( !!mem, "LocalReAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( mem == ptr, "LocalReAlloc returned unexpected handle\n" ); + size = LocalSize( mem ); + ok( size == buffer_size, "LocalSize returned %Iu, error %lu\n", size, GetLastError() ); + + ptr = LocalLock( mem ); + ok( !!ptr, "LocalLock failed, error %lu\n", GetLastError() ); + todo_wine + ok( ptr == mem, "got unexpected ptr %p\n", ptr ); + ret = LocalUnlock( mem ); + ok( !ret, "LocalUnlock succeeded, error %lu\n", GetLastError() ); + todo_wine + ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + + tmp_mem = LocalReAlloc( mem, 2 * buffer_size, LMEM_MOVEABLE | LMEM_ZEROINIT ); + ok( !!tmp_mem, "LocalReAlloc failed\n" ); + ok( tmp_mem == mem || broken( tmp_mem != mem ) /* happens sometimes?? */, + "LocalReAlloc returned unexpected handle\n" ); + mem = tmp_mem; + + size = LocalSize( mem ); + ok( size >= 2 * buffer_size, "LocalSize returned %Iu, error %lu\n", size, GetLastError() ); + ptr = LocalLock( mem ); + ok( !!ptr, "LocalLock failed, error %lu\n", GetLastError() ); + todo_wine + ok( ptr == mem, "got unexpected ptr %p\n", ptr ); + ok( !memcmp( ptr, zero_buffer, buffer_size ), "LocalReAlloc didn't clear memory\n" ); + ok( !memcmp( ptr + buffer_size, zero_buffer, buffer_size ), + "LocalReAlloc didn't clear memory\n" ); + + tmp_mem = LocalHandle( ptr ); + ok( tmp_mem == mem, "LocalHandle returned unexpected handle\n" ); + tmp_mem = LocalDiscard( mem ); + todo_wine + ok( !!tmp_mem, "LocalDiscard failed, error %lu\n", GetLastError() ); + todo_wine + ok( tmp_mem == mem, "LocalDiscard returned unexpected handle\n" ); + ret = LocalUnlock( mem ); + ok( !ret, "LocalUnlock succeeded, error %lu\n", GetLastError() ); + todo_wine + ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + + tmp_mem = LocalDiscard( mem ); + ok( tmp_mem == mem, "LocalDiscard failed, error %lu\n", GetLastError() ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + for (i = 0; i < ARRAY_SIZE(flags_tests); i++) + { + mem = LocalAlloc( flags_tests[i], 4 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + flags = LocalFlags( mem ); + ok( !(flags & ~LMEM_DISCARDABLE), "got flags %#x, error %lu\n", flags, GetLastError() ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); } }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=111381
Your paranoid android.
=== w10pro64_zh_CN (64 bit report) ===
kernel32: heap.c:1331: Test failed: got ullAvailPageFile 0x496ca000
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernel32/tests/heap.c | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index b859cf8f214..39cec2ac994 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -257,6 +257,7 @@ static void test_GlobalAlloc(void) static const SIZE_T buffer_size = ARRAY_SIZE(zero_buffer); const HGLOBAL invalid_mem = LongToHandle( 0xdeadbee0 + sizeof(void *) ); void *const invalid_ptr = LongToHandle( 0xdeadbee0 ); + HGLOBAL globals[0x10000]; HGLOBAL mem, tmp_mem; BYTE *ptr, *tmp_ptr; UINT i, flags; @@ -268,6 +269,37 @@ static void test_GlobalAlloc(void) mem = GlobalReAlloc( 0, 10, GMEM_MOVEABLE ); ok( !mem, "GlobalReAlloc succeeded\n" );
+ for (i = 0; i < ARRAY_SIZE(globals); ++i) + { + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + globals[i] = mem; + } + + SetLastError( 0xdeadbeef ); + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + todo_wine + ok( !mem, "GlobalAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + mem = LocalAlloc( LMEM_MOVEABLE | LMEM_DISCARDABLE, 0 ); + todo_wine + ok( !mem, "LocalAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_DISCARDABLE, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + for (i = 0; i < ARRAY_SIZE(globals); ++i) + { + mem = GlobalFree( globals[i] ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + } + mem = GlobalAlloc( GMEM_MOVEABLE, 0 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); mem = GlobalReAlloc( mem, 10, GMEM_MOVEABLE ); @@ -593,6 +625,7 @@ static void test_LocalAlloc(void) static const SIZE_T buffer_size = ARRAY_SIZE(zero_buffer); const HLOCAL invalid_mem = LongToHandle( 0xdeadbee0 + sizeof(void *) ); void *const invalid_ptr = LongToHandle( 0xdeadbee0 ); + HLOCAL locals[0x10000]; HLOCAL mem, tmp_mem; BYTE *ptr, *tmp_ptr; UINT i, flags; @@ -604,6 +637,37 @@ static void test_LocalAlloc(void) mem = LocalReAlloc( 0, 10, LMEM_MOVEABLE ); ok( !mem, "LocalReAlloc succeeded\n" );
+ for (i = 0; i < ARRAY_SIZE(locals); ++i) + { + mem = LocalAlloc( LMEM_MOVEABLE | LMEM_DISCARDABLE, 0 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + locals[i] = mem; + } + + SetLastError( 0xdeadbeef ); + mem = LocalAlloc( LMEM_MOVEABLE | LMEM_DISCARDABLE, 0 ); + todo_wine + ok( !mem, "LocalAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + todo_wine + ok( !mem, "GlobalAlloc succeeded\n" ); + todo_wine + ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() ); + + mem = LocalAlloc( LMEM_DISCARDABLE, 0 ); + ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); + mem = LocalFree( mem ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + + for (i = 0; i < ARRAY_SIZE(locals); ++i) + { + mem = LocalFree( locals[i] ); + ok( !mem, "LocalFree failed, error %lu\n", GetLastError() ); + } + mem = LocalAlloc( LMEM_MOVEABLE, 0 ); ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); mem = LocalReAlloc( mem, 10, LMEM_MOVEABLE );
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=111382
Your paranoid android.
=== w7u_adm (32 bit report) ===
kernel32: heap.c:1408: Test failed: got dwAvailPageFile 0x69e9e000
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernel32/tests/heap.c | 143 ++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index 39cec2ac994..f3a64dbab0b 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -240,6 +240,17 @@ static void test_HeapCreate(void) }
+struct mem_entry +{ + UINT_PTR flags; + void *ptr; +}; + +static struct mem_entry *mem_entry_from_HANDLE( HLOCAL handle ) +{ + return CONTAINING_RECORD( handle, struct mem_entry, ptr ); +} + static void test_GlobalAlloc(void) { static const UINT flags_tests[] = @@ -257,11 +268,12 @@ static void test_GlobalAlloc(void) static const SIZE_T buffer_size = ARRAY_SIZE(zero_buffer); const HGLOBAL invalid_mem = LongToHandle( 0xdeadbee0 + sizeof(void *) ); void *const invalid_ptr = LongToHandle( 0xdeadbee0 ); + struct mem_entry *entry; HGLOBAL globals[0x10000]; + SIZE_T size, alloc_size; HGLOBAL mem, tmp_mem; BYTE *ptr, *tmp_ptr; UINT i, flags; - SIZE_T size; BOOL ret;
mem = GlobalFree( 0 ); @@ -319,6 +331,135 @@ static void test_GlobalAlloc(void) size = GlobalSize( mem ); ok( size == 0, "GlobalSize returned %Iu\n", size );
+ mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + entry = mem_entry_from_HANDLE( mem ); + size = GlobalSize( mem ); + ok( size == 0, "GlobalSize returned %Iu\n", size ); + ret = HeapValidate( GetProcessHeap(), 0, entry ); + ok( !ret, "HeapValidate succeeded\n" ); + todo_wine + ok( entry->flags == 0xf, "got unexpected flags %#Ix\n", entry->flags ); + ok( !entry->ptr, "got unexpected ptr %p\n", entry->ptr ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_MOVEABLE, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + entry = mem_entry_from_HANDLE( mem ); + size = GlobalSize( mem ); + ok( size == 0, "GlobalSize returned %Iu\n", size ); + ret = HeapValidate( GetProcessHeap(), 0, entry ); + ok( !ret, "HeapValidate succeeded\n" ); + todo_wine + ok( entry->flags == 0xb, "got unexpected flags %#Ix\n", entry->flags ); + ok( !entry->ptr, "got unexpected ptr %p\n", entry->ptr ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + for (alloc_size = 1; alloc_size < 0x10000000; alloc_size <<= 1) + { + winetest_push_context( "size %#Ix", alloc_size ); + + mem = GlobalAlloc( GMEM_FIXED, alloc_size ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + ok( !((UINT_PTR)mem & sizeof(void *)), "got unexpected ptr align\n" ); + ok( !((UINT_PTR)mem & (sizeof(void *) - 1)), "got unexpected ptr align\n" ); + ret = HeapValidate( GetProcessHeap(), 0, mem ); + ok( ret, "HeapValidate failed, error %lu\n", GetLastError() ); + tmp_mem = GlobalFree( mem ); + ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_MOVEABLE, alloc_size ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + todo_wine + ok( ((UINT_PTR)mem & sizeof(void *)), "got unexpected entry align\n" ); + todo_wine + ok( !((UINT_PTR)mem & (sizeof(void *) - 1)), "got unexpected entry align\n" ); + + entry = mem_entry_from_HANDLE( mem ); + ret = HeapValidate( GetProcessHeap(), 0, entry ); + ok( !ret, "HeapValidate succeeded\n" ); + ret = HeapValidate( GetProcessHeap(), 0, entry->ptr ); + todo_wine + ok( ret, "HeapValidate failed, error %lu\n", GetLastError() ); + size = HeapSize( GetProcessHeap(), 0, entry->ptr ); + todo_wine + ok( size == alloc_size, "HeapSize returned %Iu\n", size ); + + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + ok( ptr == entry->ptr, "got unexpected ptr %p\n", ptr ); + ok( !((UINT_PTR)ptr & sizeof(void *)), "got unexpected ptr align\n" ); + ok( !((UINT_PTR)ptr & (sizeof(void *) - 1)), "got unexpected ptr align\n" ); + for (i = 1; i < 0xff; ++i) + { + todo_wine + ok( entry->flags == ((i<<16)|3), "got unexpected flags %#Ix\n", entry->flags ); + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + } + ptr = GlobalLock( mem ); + ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); + todo_wine + ok( entry->flags == 0xff0003, "got unexpected flags %#Ix\n", entry->flags ); + for (i = 1; i < 0xff; ++i) + { + ret = GlobalUnlock( mem ); + ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + } + ret = GlobalUnlock( mem ); + ok( !ret, "GlobalUnlock succeeded, error %lu\n", GetLastError() ); + todo_wine + ok( entry->flags == 0x3, "got unexpected flags %#Ix\n", entry->flags ); + + tmp_mem = GlobalFree( mem ); + ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); + ok( !!entry->flags, "got unexpected flags %#Ix\n", entry->flags ); + todo_wine_if(sizeof(void *) == 4) + ok( !((UINT_PTR)entry->flags & sizeof(void *)), "got unexpected ptr align\n" ); + todo_wine_if(sizeof(void *) == 4) + ok( !((UINT_PTR)entry->flags & (sizeof(void *) - 1)), "got unexpected ptr align\n" ); + todo_wine + ok( !entry->ptr, "got unexpected ptr %p\n", entry->ptr ); + + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + entry = mem_entry_from_HANDLE( mem ); + todo_wine + ok( entry->flags == 0xf, "got unexpected flags %#Ix\n", entry->flags ); + ok( !entry->ptr, "got unexpected ptr %p\n", entry->ptr ); + flags = GlobalFlags( mem ); + ok( flags == (GMEM_DISCARDED | GMEM_DISCARDABLE), "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 1 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + entry = mem_entry_from_HANDLE( mem ); + todo_wine + ok( entry->flags == 0x7, "got unexpected flags %#Ix\n", entry->flags ); + ok( !!entry->ptr, "got unexpected ptr %p\n", entry->ptr ); + flags = GlobalFlags( mem ); + ok( flags == GMEM_DISCARDABLE, "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_DDESHARE, 1 ); + ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); + entry = mem_entry_from_HANDLE( mem ); + todo_wine + ok( entry->flags == 0x8007, "got unexpected flags %#Ix\n", entry->flags ); + ok( !!entry->ptr, "got unexpected ptr %p\n", entry->ptr ); + flags = GlobalFlags( mem ); + ok( flags == (GMEM_DISCARDABLE | GMEM_DDESHARE), "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); + mem = GlobalFree( mem ); + ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() ); + + winetest_pop_context(); + } + mem = GlobalAlloc( GMEM_MOVEABLE, 256 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); ptr = GlobalLock( mem );
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=111383
Your paranoid android.
=== w7u_adm (32 bit report) ===
kernel32: heap.c:1549: Test failed: got dwAvailPageFile 0x69f4a000