| 1 | // Licensed to the .NET Foundation under one or more agreements. | 
|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. | 
|---|
| 3 | // See the LICENSE file in the project root for more information. | 
|---|
| 4 |  | 
|---|
| 5 | /*============================================================= | 
|---|
| 6 | ** | 
|---|
| 7 | ** Source: test1.c | 
|---|
| 8 | ** | 
|---|
| 9 | ** Purpose: Allocate some memory. Then reallocate that memory.  Ensure the | 
|---|
| 10 | ** return values are correct, and also that data placed in the allocated | 
|---|
| 11 | ** memory carries over to the reallocated block. | 
|---|
| 12 | ** | 
|---|
| 13 | ** | 
|---|
| 14 | **============================================================*/ | 
|---|
| 15 |  | 
|---|
| 16 | #include <palsuite.h> | 
|---|
| 17 |  | 
|---|
| 18 | int __cdecl main(int argc, char *argv[]) | 
|---|
| 19 | { | 
|---|
| 20 |  | 
|---|
| 21 | HANDLE TheHeap; | 
|---|
| 22 | char* TheMemory; | 
|---|
| 23 | char* ReAllocMemory; | 
|---|
| 24 | int i; | 
|---|
| 25 |  | 
|---|
| 26 | if(PAL_Initialize(argc, argv) != 0) | 
|---|
| 27 | { | 
|---|
| 28 | return FAIL; | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | TheHeap = GetProcessHeap(); | 
|---|
| 32 |  | 
|---|
| 33 | if(TheHeap == NULL) | 
|---|
| 34 | { | 
|---|
| 35 | Fail( "ERROR: GetProcessHeap() returned NULL when it was called. " | 
|---|
| 36 | "GetLastError() returned %d.",GetLastError()); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | /* Allocate 100 bytes on the heap */ | 
|---|
| 40 | if((TheMemory = (char*)HeapAlloc(TheHeap, 0, 100)) == NULL) | 
|---|
| 41 | { | 
|---|
| 42 | Fail( "ERROR: HeapAlloc returned NULL when it was called.  " | 
|---|
| 43 | "GetLastError() returned %d.",GetLastError()); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | /* Set each byte of that memory block to 'x' */ | 
|---|
| 47 | memset(TheMemory, 'X', 100); | 
|---|
| 48 |  | 
|---|
| 49 | /* Reallocate the memory */ | 
|---|
| 50 | ReAllocMemory = (char*)HeapReAlloc(TheHeap, 0, TheMemory, 100); | 
|---|
| 51 |  | 
|---|
| 52 | if(ReAllocMemory == NULL) | 
|---|
| 53 | { | 
|---|
| 54 | Fail( "ERROR: HeapReAlloc failed to reallocate the 100 bytes of " | 
|---|
| 55 | "heap memory. GetLastError returns %d.",GetLastError()); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | /* Check that each byte of the memory Reallocated is 'x' */ | 
|---|
| 59 |  | 
|---|
| 60 | for(i=0; i<100; ++i) | 
|---|
| 61 | { | 
|---|
| 62 | if(ReAllocMemory[i] != 'X') | 
|---|
| 63 | { | 
|---|
| 64 | Fail( "ERROR: Byte number %d of the reallocated memory block " | 
|---|
| 65 | "is not set to 'X' as it should be.",i); | 
|---|
| 66 | } | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 |  | 
|---|
| 70 | PAL_Terminate(); | 
|---|
| 71 | return PASS; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|