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: test4.c
8**
9** Purpose: Call HeapReAlloc with a NULL pointer to memory. It should
10** return NULL.
11**
12**
13**============================================================*/
14
15/* Note: When attempted with a NULL Handle, this test crashes under win32.
16 As such, the behaviour isn't tested here.
17*/
18
19#include <palsuite.h>
20
21int __cdecl main(int argc, char *argv[])
22{
23
24 HANDLE TheHeap;
25 LPVOID TheMemory = NULL;
26
27 if(PAL_Initialize(argc, argv) != 0)
28 {
29 return FAIL;
30 }
31
32 TheHeap = GetProcessHeap();
33
34 if(TheHeap == NULL)
35 {
36 Fail("ERROR: GetProcessHeap() returned NULL when it was called. "
37 "GetLastError() returned %d.",GetLastError());
38 }
39
40 /* Allocate 100 bytes on the heap */
41 if(HeapAlloc(TheHeap, 0, 100) == NULL)
42 {
43 Fail("ERROR: HeapAlloc returned NULL when it was called. "
44 "GetLastError() returned %d.",GetLastError());
45 }
46
47 /* Call HeapReAlloc with a NULL memory pointer. It should fail */
48
49 if(HeapReAlloc(TheHeap, 0, TheMemory, 100) != NULL)
50 {
51 Fail("ERROR: HeapReAlloc was passed an invalid memory pointer. "
52 "It should have failed and returned NULL upon failure.");
53 }
54
55 if(GetLastError() != 0)
56 {
57 Fail("ERROR: GetLastError should be zero after passing a NULL "
58 "memory pointer to HeapReAlloc.\n");
59 }
60
61 /* Call HeapReAlloc with a size of 0 bytes on a NULL memory pointer.
62 It should still fail.
63 */
64
65 if(HeapReAlloc(TheHeap, 0, TheMemory, 0) != NULL)
66 {
67 Fail("ERROR: HeapReAlloc was passed an invalid memory pointer and "
68 "the amount of memory to reallocate was 0. "
69 "It should have failed and returned NULL upon failure.");
70 }
71
72 if(GetLastError() != 0)
73 {
74 Fail("ERROR: GetLastError should be zero after passing a NULL "
75 "memory pointer to HeapReAlloc.\n");
76 }
77
78 PAL_Terminate();
79 return PASS;
80}
81