ReactOS 0.4.15-dev-7654-g6bc40d3
global_mem.c File Reference
#include <windows.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for global_mem.c:

Go to the source code of this file.

Macros

#define DISPLAY_COLUMNS   78
 
#define LINE_BUFFER_SIZE   DISPLAY_COLUMNS + 2
 
#define MEM_BLOCK_SIZE   0x80000
 

Typedefs

typedef enum TestStatus TEST_STATUS
 

Enumerations

enum  TestStatus { FAILED = 0 , PASSED = 1 , SKIPPED = -1 }
 

Functions

TEST_STATUS TEST_CombineStatus (TEST_STATUS a, TEST_STATUS b)
 
void OUTPUT_BannerLine ()
 
void OUTPUT_Line (const char *szLine)
 
void OUTPUT_Banner (const char *szBanner)
 
void OUTPUT_Result (TEST_STATUS status)
 
void OUTPUT_HexDword (DWORD dw)
 
void OUTPUT_Handle (HANDLE h)
 
void OutputAllocFlags (UINT pFlags)
 
void OutputErrorCode ()
 
TEST_STATUS TEST_MemoryWrite (LPVOID mem, DWORD cbSize)
 
TEST_STATUS TEST_MemoryRead (LPVOID mem, DWORD cbSize)
 
int IsMovable (HGLOBAL hMem)
 
TEST_STATUS TestGlobalAllocNFree (UINT allocFlags)
 
TEST_STATUS TestGlobalLockNUnlock (UINT allocFlags)
 
TEST_STATUS TestGlobalReAllocFixed ()
 
TEST_STATUS TestGlobalReAllocMovable ()
 
TEST_STATUS TestGlobalReAlloc ()
 
TEST_STATUS TestGlobalFlagsMoveable ()
 
TEST_STATUS TestGlobalFlagsFixed ()
 
TEST_STATUS TestGlobalFlags ()
 
TEST_STATUS TestGlobalHandle ()
 
TEST_STATUS TestGlobalSize ()
 
TEST_STATUS TestGlobalDiscard ()
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ DISPLAY_COLUMNS

#define DISPLAY_COLUMNS   78

Definition at line 17 of file global_mem.c.

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   DISPLAY_COLUMNS + 2

Definition at line 18 of file global_mem.c.

◆ MEM_BLOCK_SIZE

#define MEM_BLOCK_SIZE   0x80000

Definition at line 25 of file global_mem.c.

Typedef Documentation

◆ TEST_STATUS

Enumeration Type Documentation

◆ TestStatus

Enumerator
FAILED 
PASSED 
SKIPPED 

Definition at line 32 of file global_mem.c.

33{
34 FAILED = 0,
35 PASSED = 1,
36 SKIPPED = -1
enum TestStatus TEST_STATUS
@ SKIPPED
Definition: global_mem.c:36
@ PASSED
Definition: global_mem.c:35
@ FAILED
Definition: global_mem.c:34

Function Documentation

◆ IsMovable()

int IsMovable ( HGLOBAL  hMem)

Definition at line 220 of file global_mem.c.

221{
222 LPVOID pMem = 0;
223 int rc = 0;
224
225 pMem = GlobalLock(hMem);
226 if (pMem != hMem)
227 {
228 rc = 1;
229 }
230 GlobalUnlock(hMem);
231
232 return rc;
233}
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190

Referenced by TestGlobalReAllocFixed().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 1033 of file global_mem.c.

1034{
1036 OUTPUT_Banner("Testing GlobalXXX memory management functions.");
1037
1042
1043 if (FAILED == test_set)
1044 {
1045 OUTPUT_Line("Skipping any further tests. GlobalAlloc/Free fails.");
1047 return test_set;
1048 }
1049
1054
1056
1058
1060
1062
1064
1065 /* output the result for the entire set of tests*/
1066 OUTPUT_Banner("Test suite result");
1068 return test_set;
1069}
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
TEST_STATUS TestGlobalDiscard()
Definition: global_mem.c:976
TEST_STATUS TestGlobalLockNUnlock(UINT allocFlags)
Definition: global_mem.c:267
TEST_STATUS TestGlobalFlags()
Definition: global_mem.c:775
TEST_STATUS TestGlobalAllocNFree(UINT allocFlags)
Definition: global_mem.c:238
TEST_STATUS TestGlobalHandle()
Definition: global_mem.c:790
TEST_STATUS TestGlobalReAlloc()
Definition: global_mem.c:605
TEST_STATUS TestGlobalSize()
Definition: global_mem.c:876
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
void test_set()
Definition: test_set.cpp:75
#define GPTR
Definition: winbase.h:296
#define GMEM_FIXED
Definition: winbase.h:293
#define GHND
Definition: winbase.h:297
#define GMEM_MOVEABLE
Definition: winbase.h:294

◆ OUTPUT_Banner()

void OUTPUT_Banner ( const char szBanner)

◆ OUTPUT_BannerLine()

void OUTPUT_BannerLine ( )

Definition at line 63 of file global_mem.c.

64{
65 int c = 0;
66 printf("+");
67 for (c = 1; c < DISPLAY_COLUMNS; c++)
68 {
69 printf("-");
70 }
71 printf("\n");
72}
#define printf
Definition: freeldr.h:94
const GLubyte * c
Definition: glext.h:8905
#define DISPLAY_COLUMNS
Definition: global_mem.c:17

Referenced by OUTPUT_Banner().

◆ OUTPUT_Handle()

void OUTPUT_Handle ( HANDLE  h)

Definition at line 149 of file global_mem.c.

150{
151 char buffer[32];
152 sprintf(buffer, "0x%p", h);
154}
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define sprintf(buf, format,...)
Definition: sprintf.c:55

Referenced by TestGlobalDiscard(), TestGlobalFlagsFixed(), TestGlobalFlagsMoveable(), TestGlobalHandle(), TestGlobalReAllocFixed(), and TestGlobalReAllocMovable().

◆ OUTPUT_HexDword()

void OUTPUT_HexDword ( DWORD  dw)

Definition at line 142 of file global_mem.c.

143{
144 char buffer[32];
145 sprintf(buffer, "0x%lX",dw);
147}
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40

Referenced by TestGlobalDiscard(), TestGlobalFlagsMoveable(), and TestGlobalSize().

◆ OUTPUT_Line()

void OUTPUT_Line ( const char szLine)

Definition at line 79 of file global_mem.c.

80{
81 int spaceIndex = 0;
82 char output[LINE_BUFFER_SIZE];
83
84 memset(output, 0, DISPLAY_COLUMNS + 2);
85
86 /*If this line is longer than DISPLAY_COLUMNS,
87 * break it at the first space.
88 */
89 if (DISPLAY_COLUMNS - 2 < strlen(szLine))
90 {
91 for (spaceIndex = DISPLAY_COLUMNS / 2; spaceIndex < DISPLAY_COLUMNS - 2; spaceIndex++)
92 {
93 if (' ' == szLine[spaceIndex])
94 {
95 break;
96 }
97 }
98
99 memcpy(output + 2, szLine, spaceIndex + 1);
100 output[0] = '|';
101 output[1] = ' ';
102 output[strlen(output)] = '\n';
103 printf(output);
104
105 OUTPUT_Line(szLine + spaceIndex + 1);
106 }
107 else
108 {
109 sprintf(output,"| %s\n", szLine);
110 printf(output);
111 }
112
113}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define LINE_BUFFER_SIZE
Definition: global_mem.c:18
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memset(x, y, z)
Definition: compat.h:39

Referenced by main(), OUTPUT_Banner(), OUTPUT_Handle(), OUTPUT_HexDword(), OUTPUT_Line(), OUTPUT_Result(), OutputAllocFlags(), OutputErrorCode(), TestGlobalAllocNFree(), TestGlobalDiscard(), TestGlobalFlags(), TestGlobalFlagsFixed(), TestGlobalFlagsMoveable(), TestGlobalHandle(), TestGlobalLockNUnlock(), TestGlobalReAlloc(), TestGlobalReAllocFixed(), TestGlobalReAllocMovable(), and TestGlobalSize().

◆ OUTPUT_Result()

void OUTPUT_Result ( TEST_STATUS  status)

Definition at line 128 of file global_mem.c.

129{
130 switch (status)
131 {
132 case PASSED: OUTPUT_Line("==> PASSED"); break;
133 case FAILED: OUTPUT_Line("*** FAILED"); break;
134 case SKIPPED: OUTPUT_Line("==> SKIPPED"); break;
135 }
136 OUTPUT_Line("");
137}
Definition: ps.c:97

Referenced by main(), TestGlobalAllocNFree(), TestGlobalDiscard(), TestGlobalFlags(), TestGlobalFlagsFixed(), TestGlobalFlagsMoveable(), TestGlobalHandle(), TestGlobalLockNUnlock(), TestGlobalReAlloc(), TestGlobalReAllocFixed(), TestGlobalReAllocMovable(), and TestGlobalSize().

◆ OutputAllocFlags()

void OutputAllocFlags ( UINT  pFlags)

Definition at line 159 of file global_mem.c.

160{
161 if (pFlags & GMEM_MOVEABLE)
162 {
163 OUTPUT_Line("Movable Memory");
164 }
165 else
166 {
167 OUTPUT_Line("Fixed Memory");
168 }
169
170 if (pFlags & GMEM_ZEROINIT)
171 {
172 OUTPUT_Line("Zero Initialized Memory");
173 }
174}
#define GMEM_ZEROINIT
Definition: winbase.h:306

Referenced by TestGlobalAllocNFree(), and TestGlobalLockNUnlock().

◆ OutputErrorCode()

void OutputErrorCode ( )

Definition at line 179 of file global_mem.c.

180{
181 char buffer[256];
182
183 sprintf(buffer,"GetLastError() returned %lu", GetLastError());
184
186}
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by TestGlobalLockNUnlock().

◆ TEST_CombineStatus()

TEST_STATUS TEST_CombineStatus ( TEST_STATUS  a,
TEST_STATUS  b 
)

Definition at line 46 of file global_mem.c.

47{
49
50 switch (a)
51 {
52 case PASSED: result = (PASSED == b || SKIPPED == b) ? (PASSED) : (FAILED); break;
53 case FAILED: result = FAILED; break;
54 case SKIPPED: result = b; break;
55 }
56
57 return result;
58}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79

Referenced by main(), TestGlobalDiscard(), TestGlobalFlags(), TestGlobalFlagsFixed(), TestGlobalFlagsMoveable(), TestGlobalHandle(), TestGlobalLockNUnlock(), TestGlobalReAlloc(), TestGlobalReAllocFixed(), TestGlobalReAllocMovable(), and TestGlobalSize().

◆ TEST_MemoryRead()

TEST_STATUS TEST_MemoryRead ( LPVOID  mem,
DWORD  cbSize 
)

Definition at line 204 of file global_mem.c.

205{
207
208 if (0 == IsBadReadPtr(mem, cbSize))
209 {
210 result = PASSED;
211 }
212 return result;
213}
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:805
Definition: mem.c:156

Referenced by TestGlobalLockNUnlock(), TestGlobalReAllocFixed(), and TestGlobalReAllocMovable().

◆ TEST_MemoryWrite()

TEST_STATUS TEST_MemoryWrite ( LPVOID  mem,
DWORD  cbSize 
)

Definition at line 190 of file global_mem.c.

191{
193
194 if (0 == IsBadWritePtr(mem, cbSize))
195 {
196 result = PASSED;
197 }
198 return result;
199}
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883

Referenced by TestGlobalReAllocFixed(), and TestGlobalReAllocMovable().

◆ TestGlobalAllocNFree()

TEST_STATUS TestGlobalAllocNFree ( UINT  allocFlags)

Definition at line 238 of file global_mem.c.

239{
241 HGLOBAL hTest = 0;
242 OUTPUT_Banner("Testing the GlobalAlloc and GlobalFree calls");
243 OUTPUT_Line("Allocate a buffer");
244
245 OutputAllocFlags(allocFlags);
246
247 status = FAILED;
248 hTest = GlobalAlloc(allocFlags, MEM_BLOCK_SIZE);
249 if (0 != hTest)
250 {
251 if (0 == GlobalFree(hTest))
252 {
253 status = PASSED;
254 }
255 }
256
257 OUTPUT_Line("Result for this run:");
259 OUTPUT_Line("");
260
261 return status;
262}
void OutputAllocFlags(UINT pFlags)
Definition: global_mem.c:159
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368

Referenced by main().

◆ TestGlobalDiscard()

TEST_STATUS TestGlobalDiscard ( )

Definition at line 976 of file global_mem.c.

977{
978 HGLOBAL hMem = 0;
979 HGLOBAL hTest = 0;
980 DWORD uFlags = 0;
983
984 OUTPUT_Banner("Testing GlobalDiscard()");
986 if (0 != hMem)
987 {
988 OUTPUT_Line("Allocation handle: ");
989 OUTPUT_Handle(hMem);
990
991 hTest = GlobalDiscard(hMem);
992 if (0 == hTest)
993 {
994 OUTPUT_Line("GlobalDiscard returned NULL");
996 }
997 else
998 {
999 uFlags = GlobalFlags(hTest);
1000 OUTPUT_Line("Flags from the new memory block.");
1002 if (0 != (uFlags & GMEM_DISCARDED))
1003 {
1005 }
1006 else
1007 {
1008 OUTPUT_Line("Block is not marked as discardable.");
1010 }
1011 }
1012
1013 GlobalFree(hTest);
1014 }
1015 else
1016 {
1017 OUTPUT_Line("GlobalAlloc failed!");
1019 }
1020
1021 OUTPUT_Line("Result from subtest:");
1023
1025
1027 return result;
1028}
UINT uFlags
Definition: api.c:59
unsigned long DWORD
Definition: ntddk_ex.h:95
void OUTPUT_HexDword(DWORD dw)
Definition: global_mem.c:142
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
UINT NTAPI GlobalFlags(HGLOBAL hMem)
Definition: heapmem.c:520
Definition: pseh.c:2763
#define GMEM_DISCARDED
Definition: winbase.h:307
#define GlobalDiscard(m)
Definition: winbase.h:2578

Referenced by main().

◆ TestGlobalFlags()

TEST_STATUS TestGlobalFlags ( )

Definition at line 775 of file global_mem.c.

776{
778 OUTPUT_Banner("Testing GlobalFlags()");
779
782
783 OUTPUT_Line("GlobalFlags result:");
785 return result;
786}
TEST_STATUS TestGlobalFlagsFixed()
Definition: global_mem.c:718
TEST_STATUS TestGlobalFlagsMoveable()
Definition: global_mem.c:621

Referenced by main().

◆ TestGlobalFlagsFixed()

TEST_STATUS TestGlobalFlagsFixed ( )

Definition at line 718 of file global_mem.c.

719{
720 HGLOBAL hMem = 0;
721 UINT uFlags = 0;
723
724 OUTPUT_Line("Testing for correct handling of GMEM_FIXED memory");
726 if (0 != hMem)
727 {
728
729 OUTPUT_Line("Allocation handle: ");
730 OUTPUT_Handle(hMem);
731
732 OUTPUT_Line("Testing initial allocation");
733 OUTPUT_Line("Testing for non-discarded and lock of 0");
734 uFlags = GlobalFlags(hMem);
735 if (((GMEM_LOCKCOUNT & uFlags) == 0) && /*no locks*/
736 (((uFlags >> 8) & 0xff) == 0 )) /*not discarded*/
737 {
739 }
740 else
741 {
743 }
745
746 OUTPUT_Line("Pointer from handle: ");
748 OUTPUT_Line("Testing after a lock");
749 OUTPUT_Line("Testing for non-discarded and lock of 0");
750 uFlags = GlobalFlags(hMem);
751 if (((GMEM_LOCKCOUNT & uFlags) == 0) && /*no locks*/
752 (((uFlags >> 8) & 0xff) == 0 )) /*not discarded*/
753 {
755 }
756 else
757 {
759 }
761
762 GlobalFree(hMem);
763 }
764 else
765 {
766 OUTPUT_Line("GlobalAlloc failed!");
768 }
769
770 return result;
771}
unsigned int UINT
Definition: ndis.h:50
#define GMEM_LOCKCOUNT
Definition: winbase.h:309

Referenced by TestGlobalFlags().

◆ TestGlobalFlagsMoveable()

TEST_STATUS TestGlobalFlagsMoveable ( )

Definition at line 621 of file global_mem.c.

622{
623 HGLOBAL hMem = 0;
624 UINT uFlags = 0;
626
627 OUTPUT_Line("Test for the proper lock count");
628
630 if (0 != hMem)
631 {
632
633 OUTPUT_Line("Testing initial allocation");
634
635 OUTPUT_Line("Testing for a lock of 0");
636 uFlags = GlobalFlags(hMem);
637 if (((GMEM_LOCKCOUNT & uFlags) == 0)) /*no locks*/
638 {
640 }
641 else
642 {
644 }
646
647 OUTPUT_Line("Pointer from handle: ");
649
650 OUTPUT_Line("Testing after a lock");
651 OUTPUT_Line("Testing for a lock of 1");
652 uFlags = GlobalFlags(hMem);
653 if (((GMEM_LOCKCOUNT & uFlags) == 1)) /*no locks*/
654 {
656 }
657 else
658 {
660 }
662
663 GlobalUnlock(hMem);
664 OUTPUT_Line("Testing after an unlock");
665 OUTPUT_Line("Testing for a lock of 0");
666 uFlags = GlobalFlags(hMem);
667 if (((GMEM_LOCKCOUNT & uFlags) == 0)) /*no locks*/
668 {
670 }
671 else
672 {
674 }
676 }
677 else
678 {
679 OUTPUT_Line("GlobalAlloc failed!");
681 }
682
683 OUTPUT_Line("Test for discarded memory");
684 OUTPUT_Line("Allocating an empty moveable block---automatically marked as discarded");
685 hMem = GlobalAlloc(GMEM_MOVEABLE, 0); /*allocate a discarded block*/
686 if (0 != hMem)
687 {
688 OUTPUT_Line("Allocation handle: ");
689 OUTPUT_Handle(hMem);
690 OUTPUT_Line("Testing for a discarded flag");
691 uFlags = GlobalFlags(hMem);
692 if (0 != (uFlags & GMEM_DISCARDED)) /*discarded*/
693 {
695 }
696 else
697 {
699 }
700 OUTPUT_Line("Flags:");
703
704 GlobalFree(hMem);
705 }
706 else
707 {
708 OUTPUT_Line("GlobalAlloc failed!");
710 }
711 return result;
712}

Referenced by TestGlobalFlags().

◆ TestGlobalHandle()

TEST_STATUS TestGlobalHandle ( )

Definition at line 790 of file global_mem.c.

791{
792 HGLOBAL hMem = 0;
793 HGLOBAL hTest = 0;
794 PVOID pMem = 0;
797
798 OUTPUT_Banner("Testing GlobalHandle()");
799
800 OUTPUT_Line("Testing GlobalHandle with a block of GMEM_FIXED memory");
802 if (0 != hMem)
803 {
804
805 OUTPUT_Line("Allocation handle: ");
806 OUTPUT_Handle(hMem);
807
808 hTest = GlobalHandle(hMem);
809 if (hMem == hTest)
810 {
812 }
813 else
814 {
815 OUTPUT_Line("GlobalHandle returned:");
816 OUTPUT_Handle(hTest);
818 }
819
820 GlobalFree(hMem);
821 }
822 else
823 {
824 OUTPUT_Line("GlobalAlloc failed!");
826 }
827
828 OUTPUT_Line("Result from subtest:");
831
832
834 OUTPUT_Line("Testing GlobalHandle with a block of GMEM_MOVEABLE memory");
836 if (0 != hMem)
837 {
838
839 OUTPUT_Line("Allocation handle: ");
840 OUTPUT_Handle(hMem);
841 pMem = GlobalLock(hMem);
842 hTest = GlobalHandle(pMem);
843 if (hMem == hTest)
844 {
846 }
847 else
848 {
849 OUTPUT_Line("GlobalHandle returned:");
850 OUTPUT_Handle(hTest);
852 }
853
854 GlobalUnlock(hMem);
855 GlobalFree(hMem);
856 }
857 else
858 {
859 OUTPUT_Line("GlobalAlloc failed!");
861 }
862
863 OUTPUT_Line("Result from subtest:");
866
867
868 OUTPUT_Line("Global Handle test results:");
870 return result;
871}
HGLOBAL NTAPI GlobalHandle(LPCVOID pMem)
Definition: heapmem.c:705

Referenced by main().

◆ TestGlobalLockNUnlock()

TEST_STATUS TestGlobalLockNUnlock ( UINT  allocFlags)

Definition at line 267 of file global_mem.c.

268{
269 HGLOBAL hMem = 0;
270 LPVOID pMem = 0;
273
274 OUTPUT_Banner("Testing the GlobalLock/Unlock functions.");
275 OutputAllocFlags(allocFlags);
276 OUTPUT_Line("");
277
278 hMem = GlobalAlloc(allocFlags, MEM_BLOCK_SIZE);
279 if (0 != hMem)
280 {
281 OUTPUT_Line("Allocated a memory block");
282
283 OUTPUT_Line("Testing Lock");
284 pMem = GlobalLock(hMem);
285 if (0 != pMem)
286 {
288
289 OUTPUT_Line("Testing memory for read.");
293
294
295 OUTPUT_Line("Testing memory for write.");
299
300
301 OUTPUT_Line("Unlocking memory");
302 if (GlobalUnlock(hMem))
303 {
306 }
307 else
308 {
309 if (NO_ERROR == GetLastError())
310 {
313 }
314 else
315 {
319 }
320 }
321 }
322
323 OUTPUT_Line("Freeing memory");
324 if (0 == GlobalFree(hMem))
325 {
328 }
329 else
330 {
334 }
335 }
336 return result;
337}
#define NO_ERROR
Definition: dderror.h:5
TEST_STATUS TEST_MemoryRead(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:204
void OutputErrorCode()
Definition: global_mem.c:179

Referenced by main().

◆ TestGlobalReAlloc()

TEST_STATUS TestGlobalReAlloc ( )

Definition at line 605 of file global_mem.c.

606{
608 OUTPUT_Banner("Testing GlobalReAlloc()");
609
612
613 OUTPUT_Line("GlobalReAlloc test result:");
615 return result;
616}
TEST_STATUS TestGlobalReAllocFixed()
Definition: global_mem.c:342
TEST_STATUS TestGlobalReAllocMovable()
Definition: global_mem.c:500

Referenced by main().

◆ TestGlobalReAllocFixed()

TEST_STATUS TestGlobalReAllocFixed ( )

Definition at line 342 of file global_mem.c.

343{
344 HGLOBAL hMem = 0;
345 HGLOBAL hReAlloced = 0;
346 LPVOID pMem = 0;
349
350 OUTPUT_Line("Testing GlobalReAlloc() on memory allocated as GMEM_FIXED");
351
352 /* Case 1: convert a fixed block to a movable block. */
353 OUTPUT_Line("Allocating buffer");
355 if (0 != hMem)
356 {
357 OUTPUT_Line("Testing to see if this is converted into a movable block");
358 hReAlloced = GlobalReAlloc(hMem, MEM_BLOCK_SIZE + 100, GMEM_MOVEABLE | GMEM_MODIFY);
359 if (0 == hReAlloced)
360 {
361 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
364 }
365 else
366 {
367 hMem = hReAlloced;
368 if (0 == IsMovable(hMem))
369 {
370 OUTPUT_Line("GlobalReAlloc returned a fixed pointer.");
373 }
374 else
375 {
376 pMem = GlobalLock(hMem);
379 if (FAILED == subtest)
380 {
381 OUTPUT_Line("Memory Read failed.");
382 }
384 if (FAILED == subtest)
385 {
386 OUTPUT_Line("Memory Write failed.");
387 }
388 GlobalUnlock(hMem);
389 }
390 }
391
392 GlobalFree(hMem);
393 }
394 else
395 {
396 OUTPUT_Line("Global Alloc Failed.");
398 }
399 OUTPUT_Line("Subtest result:");
401 OUTPUT_Line("");
402
405
406 /* case 2 only move a fixed block */
407 OUTPUT_Line("Allocating buffer");
409 if (0 != hMem)
410 {
411 OUTPUT_Line("Testing to see if a new fixed block is returned.");
412 hReAlloced = GlobalReAlloc(hMem, MEM_BLOCK_SIZE - 100, GMEM_MOVEABLE);
413 if (0 == hReAlloced)
414 {
415 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
418 }
419 else
420 {
421 OUTPUT_Line("Alloced Handle: ");
422 OUTPUT_Handle(hMem);
423 OUTPUT_Line("ReAlloced Handle: ");
424 OUTPUT_Handle(hReAlloced);
425 if (hMem == hReAlloced)
426 {
427 OUTPUT_Line("GlobalReAlloc returned the same pointer. The documentation states that this is wrong, but Windows NT works this way.");
428 }
429
430 hMem = hReAlloced;
434 }
435
436 GlobalFree(hMem);
437 }
438 else
439 {
441 }
442 OUTPUT_Line("Subtest result:");
444 OUTPUT_Line("");
445
448
449 /* Case 3: re-allocate a fixed block in place */
450 OUTPUT_Line("Allocating buffer");
452 if (0 != hMem)
453 {
454 OUTPUT_Line("Testing to see if a fixed pointer is reallocated in place.");
455 hReAlloced = GlobalReAlloc(hMem, MEM_BLOCK_SIZE - 100, 0);
456 if (0 == hReAlloced)
457 {
458 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
461 }
462 else
463 {
464 OUTPUT_Line("Alloced Handle: ");
465 OUTPUT_Handle(hMem);
466 OUTPUT_Line("ReAlloced Handle: ");
467 OUTPUT_Handle(hReAlloced);
468 if (hMem != hReAlloced)
469 {
470 OUTPUT_Line("GlobalReAlloc returned a different.");
473 }
474 else
475 {
479 }
480 }
481
482 GlobalFree(hMem);
483 }
484 else
485 {
487 }
488 OUTPUT_Line("Subtest result:");
490 OUTPUT_Line("");
491
493
494 OUTPUT_Line("");
495 return result;
496}
TEST_STATUS TEST_MemoryWrite(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:190
int IsMovable(HGLOBAL hMem)
Definition: global_mem.c:220
HGLOBAL NTAPI GlobalReAlloc(HGLOBAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:825
#define GMEM_MODIFY
Definition: winbase.h:295

Referenced by TestGlobalReAlloc().

◆ TestGlobalReAllocMovable()

TEST_STATUS TestGlobalReAllocMovable ( )

Definition at line 500 of file global_mem.c.

501{
502 HGLOBAL hMem = 0;
503 HGLOBAL hReAlloced = 0;
504 LPVOID pMem = 0;
507
508 OUTPUT_Line("Testing GlobalReAlloc() on memory allocated as GMGM_MOVEABLE");
509
510 /* case 1 test reallocing a movable block that is unlocked. */
511 OUTPUT_Line("Allocating buffer");
513 if (0 != hMem)
514 {
515 OUTPUT_Line("Testing GlobalReAlloc on a unlocked block.");
516 hReAlloced = GlobalReAlloc(hMem, MEM_BLOCK_SIZE - 100, 0);
517 if (0 == hReAlloced)
518 {
519 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
522 }
523 else
524 {
525 OUTPUT_Line("Alloced Handle: ");
526 OUTPUT_Handle(hMem);
527 OUTPUT_Line("ReAlloced Handle: ");
528 OUTPUT_Handle(hReAlloced);
529
530 pMem = GlobalLock(hReAlloced);
531 hMem = hReAlloced;
535 GlobalUnlock(hReAlloced);
536 }
537
538 GlobalFree(hMem);
539 }
540 else
541 {
543 }
544 OUTPUT_Line("Subtest result:");
546 OUTPUT_Line("");
547
550
551 /* Case 2: re-allocate a moveable block that is locked */
552 OUTPUT_Line("Allocating buffer");
554 if (0 != hMem)
555 {
556
557 OUTPUT_Line("Testing GlobalReAlloc on a locked block.");
558 pMem = GlobalLock(hMem);
559 hReAlloced = GlobalReAlloc(hMem, MEM_BLOCK_SIZE - 100, 0);
560 if (0 == hReAlloced)
561 {
562 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
565 }
566 else
567 {
568 OUTPUT_Line("Alloced Handle: ");
569 OUTPUT_Handle(hMem);
570 OUTPUT_Line("ReAlloced Handle: ");
571 OUTPUT_Handle(hReAlloced);
572 if (hMem != hReAlloced)
573 {
574 OUTPUT_Line("GlobalReAlloc returned a different block.");
575 }
576 pMem = GlobalLock(hReAlloced);
580 GlobalUnlock(hReAlloced);
581
582 }
583
584 GlobalUnlock(hMem);
585
586 GlobalFree(hMem);
587 }
588 else
589 {
591 }
592 OUTPUT_Line("Subtest result:");
594 OUTPUT_Line("");
595
597
598 OUTPUT_Line("");
599 return result;
600}

Referenced by TestGlobalReAlloc().

◆ TestGlobalSize()

TEST_STATUS TestGlobalSize ( )

Definition at line 876 of file global_mem.c.

877{
878 HGLOBAL hMem = 0;
879 SIZE_T size = 0;
882 OUTPUT_Banner("Testing GlobalSize()");
883
884 OUTPUT_Line("Testing GlobalSize with a block of GMEM_FIXED memory");
886 if (0 != hMem)
887 {
888 size = GlobalSize(hMem);
889 if (MEM_BLOCK_SIZE <= size)
890 {
892 }
893 else
894 {
895 OUTPUT_Line("GlobalSize returned:");
898 }
899
900 GlobalFree(hMem);
901 }
902 else
903 {
904 OUTPUT_Line("GlobalAlloc failed!");
906 }
907
908 OUTPUT_Line("Result from subtest:");
911
912 OUTPUT_Line("Testing GlobalSize with a block of GMEM_MOVEABLE memory");
914 if (0 != hMem)
915 {
916 size = GlobalSize(hMem);
917 if (MEM_BLOCK_SIZE <= size)
918 {
920 }
921 else
922 {
923 OUTPUT_Line("GlobalSize returned:");
926 }
927
928 GlobalFree(hMem);
929 }
930 else
931 {
932 OUTPUT_Line("GlobalAlloc failed!");
934 }
935
936 OUTPUT_Line("Result from subtest:");
939
940 OUTPUT_Line("Testing GlobalSize with discarded memory");
941 hMem = GlobalAlloc(GMEM_MOVEABLE, 0);
942 if (0 != hMem)
943 {
944 size = GlobalSize(hMem);
945 if (0 == size)
946 {
948 }
949 else
950 {
951 OUTPUT_Line("GlobalSize returned:");
954 }
955
956 GlobalFree(hMem);
957 }
958 else
959 {
960 OUTPUT_Line("GlobalAlloc failed!");
962 }
963
964 OUTPUT_Line("Result from subtest:");
967
968 OUTPUT_Line("Test result:");
970 return result;
971}
GLsizeiptr size
Definition: glext.h:5919
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by main().