3 ** This program is a test application used for testing correctness of the
4 ** GlobalXXX memory API implementation.
6 ** Programmer: Mark Tempel
13 ** All output is line wrapped to fit a 80 column screen.
14 ** these defines control that formatting. To shrink the
15 ** screen columns, just change the DISPLAY_COMUMNS macro.
17 #define DISPLAY_COLUMNS 78
18 #define LINE_BUFFER_SIZE DISPLAY_COLUMNS + 2
21 ** This define controls the size of a memory allocation request.
22 ** For this test suite to really be comprehensive, we should
23 ** probably be testing many different block sizes.
25 #define MEM_BLOCK_SIZE 0x80000
28 ** This enumeration is really the return value for the program.
29 ** All test return a TestStatus and test statuses can be combined
30 ** with the relation TEST_CombineStatus.
32 typedef enum TestStatus
39 /*---------------------------------------------------------------------------
40 ** This is a relation used to combine two test statuses.
41 ** The combine rules are as follows:
42 ** FAIL & Anything == FAIL
43 ** SKIPPED & Anything == Anything
46 TEST_STATUS
TEST_CombineStatus(TEST_STATUS a
, TEST_STATUS b
)
48 TEST_STATUS result
= a
;
52 case PASSED
: result
= (PASSED
== b
|| SKIPPED
== b
) ? (PASSED
) : (FAILED
); break;
53 case FAILED
: result
= FAILED
; break;
54 case SKIPPED
: result
= b
; break;
60 /*---------------------------------------------------------------------------
61 ** This outputs the banner border lines.
63 void OUTPUT_BannerLine()
67 for (c
= 1; c
< DISPLAY_COLUMNS
; c
++)
75 /*---------------------------------------------------------------------------
76 ** This method prints a line that has a | on the left, and is line wrapped
77 ** to be no more that DISPLAY_COLUMNS +2 wide.
79 void OUTPUT_Line(const char *szLine
)
82 char output
[LINE_BUFFER_SIZE
];
84 memset(output
, 0, DISPLAY_COLUMNS
+ 2);
86 /*If this line is longer than DISPLAY_COLUMNS,
87 * break it at the first space.
89 if (DISPLAY_COLUMNS
- 2 < strlen(szLine
))
91 for (spaceIndex
= DISPLAY_COLUMNS
/ 2; spaceIndex
< DISPLAY_COLUMNS
- 2; spaceIndex
++)
93 if (' ' == szLine
[spaceIndex
])
99 memcpy(output
+ 2, szLine
, spaceIndex
+ 1);
102 output
[strlen(output
)] = '\n';
105 OUTPUT_Line(szLine
+ spaceIndex
+ 1);
109 sprintf(output
,"| %s\n", szLine
);
115 /*---------------------------------------------------------------------------
118 void OUTPUT_Banner(const char *szBanner
)
121 OUTPUT_Line(szBanner
);
125 /*---------------------------------------------------------------------------
128 void OUTPUT_Result(TEST_STATUS status
)
132 case PASSED
: OUTPUT_Line("==> PASSED"); break;
133 case FAILED
: OUTPUT_Line("*** FAILED"); break;
134 case SKIPPED
: OUTPUT_Line("==> SKIPPED"); break;
139 /*---------------------------------------------------------------------------
142 void OUTPUT_HexDword(DWORD dw
)
145 sprintf(buffer
, "0x%lX",dw
);
149 void OUTPUT_Handle(HANDLE h
)
152 sprintf(buffer
, "0x%p", h
);
156 /*---------------------------------------------------------------------------
159 void OutputAllocFlags(UINT pFlags
)
161 if (pFlags
& GMEM_MOVEABLE
)
163 OUTPUT_Line("Movable Memory");
167 OUTPUT_Line("Fixed Memory");
170 if (pFlags
& GMEM_ZEROINIT
)
172 OUTPUT_Line("Zero Initialized Memory");
176 /*---------------------------------------------------------------------------
179 void OutputErrorCode()
183 sprintf(buffer
,"GetLastError() returned %lu", GetLastError());
187 /*---------------------------------------------------------------------------
190 TEST_STATUS
TEST_MemoryWrite(LPVOID mem
, DWORD cbSize
)
192 TEST_STATUS result
= FAILED
;
194 if (0 == IsBadWritePtr(mem
, cbSize
))
201 /*---------------------------------------------------------------------------
204 TEST_STATUS
TEST_MemoryRead(LPVOID mem
, DWORD cbSize
)
206 TEST_STATUS result
= FAILED
;
208 if (0 == IsBadReadPtr(mem
, cbSize
))
215 /*---------------------------------------------------------------------------
216 ** This method tests to see if a block of global memory is movable
217 ** by seeing if the value returned from GlobalLock is different from
218 ** the passed in value.
220 int IsMovable(HGLOBAL hMem
)
225 pMem
= GlobalLock(hMem
);
235 /*---------------------------------------------------------------------------
238 TEST_STATUS
TestGlobalAllocNFree(UINT allocFlags
)
240 TEST_STATUS status
= SKIPPED
;
242 OUTPUT_Banner("Testing the GlobalAlloc and GlobalFree calls");
243 OUTPUT_Line("Allocate a buffer");
245 OutputAllocFlags(allocFlags
);
248 hTest
= GlobalAlloc(allocFlags
, MEM_BLOCK_SIZE
);
251 if (0 == GlobalFree(hTest
));
257 OUTPUT_Line("Result for this run:");
258 OUTPUT_Result(status
);
264 /*---------------------------------------------------------------------------
267 TEST_STATUS
TestGlobalLockNUnlock(UINT allocFlags
)
271 TEST_STATUS subtest
= SKIPPED
;
272 TEST_STATUS result
= FAILED
;
274 OUTPUT_Banner("Testing the GlobalLock/Unlock functions.");
275 OutputAllocFlags(allocFlags
);
278 hMem
= GlobalAlloc(allocFlags
, MEM_BLOCK_SIZE
);
281 OUTPUT_Line("Allocated a memory block");
283 OUTPUT_Line("Testing Lock");
284 pMem
= GlobalLock(hMem
);
287 OUTPUT_Result(PASSED
);
289 OUTPUT_Line("Testing memory for read.");
290 subtest
= TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
);
291 OUTPUT_Result(subtest
);
292 result
= TEST_CombineStatus(PASSED
, subtest
);
295 OUTPUT_Line("Testing memory for write.");
296 subtest
= TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
);
297 OUTPUT_Result(subtest
);
298 result
= TEST_CombineStatus(result
, subtest
);
301 OUTPUT_Line("Unlocking memory");
302 if (GlobalUnlock(hMem
))
304 OUTPUT_Result(PASSED
);
305 result
= TEST_CombineStatus(result
, PASSED
);
309 if (NO_ERROR
== GetLastError())
311 OUTPUT_Result(PASSED
);
312 result
= TEST_CombineStatus(result
, PASSED
);
317 OUTPUT_Result(FAILED
);
318 result
= TEST_CombineStatus(result
, FAILED
);
323 OUTPUT_Line("Freeing memory");
324 if (0 == GlobalFree(hMem
))
326 OUTPUT_Result(PASSED
);
327 result
= TEST_CombineStatus(result
, PASSED
);
332 OUTPUT_Result(FAILED
);
333 result
= TEST_CombineStatus(result
, FAILED
);
339 /*---------------------------------------------------------------------------
342 TEST_STATUS
TestGlobalReAllocFixed()
345 HGLOBAL hReAlloced
= 0;
347 TEST_STATUS subtest
= SKIPPED
;
348 TEST_STATUS result
= SKIPPED
;
350 OUTPUT_Line("Testing GlobalReAlloc() on memory allocated as GMEM_FIXED");
352 /* Case 1: convert a fixed block to a movable block. */
353 OUTPUT_Line("Allocating buffer");
354 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
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
);
361 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
362 subtest
= TEST_CombineStatus(subtest
, FAILED
);
363 OUTPUT_Result(subtest
);
368 if (0 == IsMovable(hMem
))
370 OUTPUT_Line("GlobalReAlloc returned a fixed pointer.");
371 subtest
= TEST_CombineStatus(subtest
, FAILED
);
372 OUTPUT_Result(subtest
);
376 pMem
= GlobalLock(hMem
);
377 subtest
= TEST_CombineStatus(subtest
, PASSED
);
378 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
+ 100));
379 if (FAILED
== subtest
)
381 OUTPUT_Line("Memory Read failed.");
383 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite(pMem
, MEM_BLOCK_SIZE
+ 100));
384 if (FAILED
== subtest
)
386 OUTPUT_Line("Memory Write failed.");
396 OUTPUT_Line("Global Alloc Failed.");
397 subtest
= TEST_CombineStatus(subtest
, FAILED
);
399 OUTPUT_Line("Subtest result:");
400 OUTPUT_Result(subtest
);
403 result
= TEST_CombineStatus(result
, subtest
);
406 /* case 2 only move a fixed block */
407 OUTPUT_Line("Allocating buffer");
408 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
411 OUTPUT_Line("Testing to see if a new fixed block is returned.");
412 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, GMEM_MOVEABLE
);
415 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
416 subtest
= TEST_CombineStatus(subtest
, FAILED
);
417 OUTPUT_Result(subtest
);
421 OUTPUT_Line("Alloced Handle: ");
423 OUTPUT_Line("ReAlloced Handle: ");
424 OUTPUT_Handle(hReAlloced
);
425 if (hMem
== hReAlloced
)
427 OUTPUT_Line("GlobalReAlloc returned the same pointer. The documentation states that this is wrong, but Windows NT works this way.");
431 subtest
= TEST_CombineStatus(subtest
, PASSED
);
432 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
433 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
440 subtest
= TEST_CombineStatus(subtest
, FAILED
);
442 OUTPUT_Line("Subtest result:");
443 OUTPUT_Result(subtest
);
446 result
= TEST_CombineStatus(result
, subtest
);
449 /* Case 3: re-allocate a fixed block in place */
450 OUTPUT_Line("Allocating buffer");
451 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
454 OUTPUT_Line("Testing to see if a fixed pointer is reallocated in place.");
455 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, 0);
458 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
459 subtest
= TEST_CombineStatus(subtest
, FAILED
);
460 OUTPUT_Result(subtest
);
464 OUTPUT_Line("Alloced Handle: ");
466 OUTPUT_Line("ReAlloced Handle: ");
467 OUTPUT_Handle(hReAlloced
);
468 if (hMem
!= hReAlloced
)
470 OUTPUT_Line("GlobalReAlloc returned a different.");
471 subtest
= TEST_CombineStatus(subtest
, FAILED
);
472 OUTPUT_Result(subtest
);
476 subtest
= TEST_CombineStatus(subtest
, PASSED
);
477 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
478 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
486 subtest
= TEST_CombineStatus(subtest
, FAILED
);
488 OUTPUT_Line("Subtest result:");
489 OUTPUT_Result(subtest
);
492 result
= TEST_CombineStatus(result
, subtest
);
497 /*---------------------------------------------------------------------------
500 TEST_STATUS
TestGlobalReAllocMovable()
503 HGLOBAL hReAlloced
= 0;
505 TEST_STATUS subtest
= SKIPPED
;
506 TEST_STATUS result
= SKIPPED
;
508 OUTPUT_Line("Testing GlobalReAlloc() on memory allocated as GMGM_MOVEABLE");
510 /* case 1 test reallocing a movable block that is unlocked. */
511 OUTPUT_Line("Allocating buffer");
512 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
515 OUTPUT_Line("Testing GlobalReAlloc on a unlocked block.");
516 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, 0);
519 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
520 subtest
= TEST_CombineStatus(subtest
, FAILED
);
521 OUTPUT_Result(subtest
);
525 OUTPUT_Line("Alloced Handle: ");
527 OUTPUT_Line("ReAlloced Handle: ");
528 OUTPUT_Handle(hReAlloced
);
530 pMem
= GlobalLock(hReAlloced
);
532 subtest
= TEST_CombineStatus(subtest
, PASSED
);
533 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
- 100));
534 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite(pMem
, MEM_BLOCK_SIZE
- 100));
535 GlobalUnlock(hReAlloced
);
542 subtest
= TEST_CombineStatus(subtest
, FAILED
);
544 OUTPUT_Line("Subtest result:");
545 OUTPUT_Result(subtest
);
548 result
= TEST_CombineStatus(result
, subtest
);
551 /* Case 2: re-allocate a moveable block that is locked */
552 OUTPUT_Line("Allocating buffer");
553 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
557 OUTPUT_Line("Testing GlobalReAlloc on a locked block.");
558 pMem
= GlobalLock(hMem
);
559 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, 0);
562 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
563 subtest
= TEST_CombineStatus(subtest
, FAILED
);
564 OUTPUT_Result(subtest
);
568 OUTPUT_Line("Alloced Handle: ");
570 OUTPUT_Line("ReAlloced Handle: ");
571 OUTPUT_Handle(hReAlloced
);
572 if (hMem
!= hReAlloced
)
574 OUTPUT_Line("GlobalReAlloc returned a different block.");
576 pMem
= GlobalLock(hReAlloced
);
577 subtest
= TEST_CombineStatus(subtest
, PASSED
);
578 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
- 100));
579 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite(pMem
, MEM_BLOCK_SIZE
- 100));
580 GlobalUnlock(hReAlloced
);
590 subtest
= TEST_CombineStatus(subtest
, FAILED
);
592 OUTPUT_Line("Subtest result:");
593 OUTPUT_Result(subtest
);
596 result
= TEST_CombineStatus(result
, subtest
);
602 /*---------------------------------------------------------------------------
605 TEST_STATUS
TestGlobalReAlloc()
607 TEST_STATUS result
= SKIPPED
;
608 OUTPUT_Banner("Testing GlobalReAlloc()");
610 result
= TEST_CombineStatus(result
, TestGlobalReAllocFixed());
611 result
= TEST_CombineStatus(result
, TestGlobalReAllocMovable());
613 OUTPUT_Line("GlobalReAlloc test result:");
614 OUTPUT_Result(result
);
618 /*---------------------------------------------------------------------------
621 TEST_STATUS
TestGlobalFlagsMoveable()
625 TEST_STATUS result
= SKIPPED
;
627 OUTPUT_Line("Test for the proper lock count");
629 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
633 OUTPUT_Line("Testing initial allocation");
635 OUTPUT_Line("Testing for a lock of 0");
636 uFlags
= GlobalFlags(hMem
);
637 if (((GMEM_LOCKCOUNT
& uFlags
) == 0)) /*no locks*/
639 result
= TEST_CombineStatus(result
, PASSED
);
643 result
= TEST_CombineStatus(result
, FAILED
);
645 OUTPUT_Result(result
);
647 OUTPUT_Line("Pointer from handle: ");
648 OUTPUT_Handle(GlobalLock(hMem
));
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*/
655 result
= TEST_CombineStatus(result
, PASSED
);
659 result
= TEST_CombineStatus(result
, FAILED
);
661 OUTPUT_Result(result
);
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*/
669 result
= TEST_CombineStatus(result
, PASSED
);
673 result
= TEST_CombineStatus(result
, FAILED
);
675 OUTPUT_Result(result
);
679 OUTPUT_Line("GlobalAlloc failed!");
680 result
= TEST_CombineStatus(result
, FAILED
);
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*/
688 OUTPUT_Line("Allocation handle: ");
690 OUTPUT_Line("Testing for a discarded flag");
691 uFlags
= GlobalFlags(hMem
);
692 if (0 != (uFlags
& GMEM_DISCARDED
)) /*discarded*/
694 result
= TEST_CombineStatus(result
, PASSED
);
698 result
= TEST_CombineStatus(result
, FAILED
);
700 OUTPUT_Line("Flags:");
701 OUTPUT_HexDword(uFlags
);
702 OUTPUT_Result(result
);
708 OUTPUT_Line("GlobalAlloc failed!");
709 result
= TEST_CombineStatus(result
, FAILED
);
715 /*---------------------------------------------------------------------------
718 TEST_STATUS
TestGlobalFlagsFixed()
722 TEST_STATUS result
= SKIPPED
;
724 OUTPUT_Line("Testing for correct handling of GMEM_FIXED memory");
725 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
729 OUTPUT_Line("Allocation handle: ");
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*/
738 result
= TEST_CombineStatus(result
, PASSED
);
742 result
= TEST_CombineStatus(result
, FAILED
);
744 OUTPUT_Result(result
);
746 OUTPUT_Line("Pointer from handle: ");
747 OUTPUT_Handle(GlobalLock(hMem
));
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*/
754 result
= TEST_CombineStatus(result
, PASSED
);
758 result
= TEST_CombineStatus(result
, FAILED
);
760 OUTPUT_Result(result
);
766 OUTPUT_Line("GlobalAlloc failed!");
767 result
= TEST_CombineStatus(result
, FAILED
);
772 /*---------------------------------------------------------------------------
775 TEST_STATUS
TestGlobalFlags()
777 TEST_STATUS result
= SKIPPED
;
778 OUTPUT_Banner("Testing GlobalFlags()");
780 result
= TEST_CombineStatus(result
, TestGlobalFlagsFixed());
781 result
= TEST_CombineStatus(result
, TestGlobalFlagsMoveable());
783 OUTPUT_Line("GlobalFlags result:");
784 OUTPUT_Result(result
);
787 /*---------------------------------------------------------------------------
790 TEST_STATUS
TestGlobalHandle()
795 TEST_STATUS subtest
= SKIPPED
;
796 TEST_STATUS result
= SKIPPED
;
798 OUTPUT_Banner("Testing GlobalHandle()");
800 OUTPUT_Line("Testing GlobalHandle with a block of GMEM_FIXED memory");
801 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
805 OUTPUT_Line("Allocation handle: ");
808 hTest
= GlobalHandle(hMem
);
811 subtest
= TEST_CombineStatus(subtest
, PASSED
);
815 OUTPUT_Line("GlobalHandle returned:");
816 OUTPUT_Handle(hTest
);
817 subtest
= TEST_CombineStatus(subtest
, FAILED
);
824 OUTPUT_Line("GlobalAlloc failed!");
825 subtest
= TEST_CombineStatus(subtest
, FAILED
);
828 OUTPUT_Line("Result from subtest:");
829 OUTPUT_Result(subtest
);
830 result
= TEST_CombineStatus(result
, subtest
);
834 OUTPUT_Line("Testing GlobalHandle with a block of GMEM_MOVEABLE memory");
835 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
839 OUTPUT_Line("Allocation handle: ");
841 pMem
= GlobalLock(hMem
);
842 hTest
= GlobalHandle(pMem
);
845 subtest
= TEST_CombineStatus(subtest
, PASSED
);
849 OUTPUT_Line("GlobalHandle returned:");
850 OUTPUT_Handle(hTest
);
851 subtest
= TEST_CombineStatus(subtest
, FAILED
);
859 OUTPUT_Line("GlobalAlloc failed!");
860 subtest
= TEST_CombineStatus(subtest
, FAILED
);
863 OUTPUT_Line("Result from subtest:");
864 OUTPUT_Result(subtest
);
865 result
= TEST_CombineStatus(result
, subtest
);
868 OUTPUT_Line("Global Handle test results:");
869 OUTPUT_Result(result
);
873 /*---------------------------------------------------------------------------
876 TEST_STATUS
TestGlobalSize()
880 TEST_STATUS subtest
= SKIPPED
;
881 TEST_STATUS result
= SKIPPED
;
882 OUTPUT_Banner("Testing GlobalSize()");
884 OUTPUT_Line("Testing GlobalSize with a block of GMEM_FIXED memory");
885 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
888 size
= GlobalSize(hMem
);
889 if (MEM_BLOCK_SIZE
<= size
)
891 subtest
= TEST_CombineStatus(subtest
, PASSED
);
895 OUTPUT_Line("GlobalSize returned:");
896 OUTPUT_HexDword(size
);
897 subtest
= TEST_CombineStatus(subtest
, FAILED
);
904 OUTPUT_Line("GlobalAlloc failed!");
905 subtest
= TEST_CombineStatus(subtest
, FAILED
);
908 OUTPUT_Line("Result from subtest:");
909 OUTPUT_Result(subtest
);
910 result
= TEST_CombineStatus(result
, subtest
);
912 OUTPUT_Line("Testing GlobalSize with a block of GMEM_MOVEABLE memory");
913 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
916 size
= GlobalSize(hMem
);
917 if (MEM_BLOCK_SIZE
<= size
)
919 subtest
= TEST_CombineStatus(subtest
, PASSED
);
923 OUTPUT_Line("GlobalSize returned:");
924 OUTPUT_HexDword(size
);
925 subtest
= TEST_CombineStatus(subtest
, FAILED
);
932 OUTPUT_Line("GlobalAlloc failed!");
933 subtest
= TEST_CombineStatus(subtest
, FAILED
);
936 OUTPUT_Line("Result from subtest:");
937 OUTPUT_Result(subtest
);
938 result
= TEST_CombineStatus(result
, subtest
);
940 OUTPUT_Line("Testing GlobalSize with discarded memory");
941 hMem
= GlobalAlloc(GMEM_MOVEABLE
, 0);
944 size
= GlobalSize(hMem
);
947 subtest
= TEST_CombineStatus(subtest
, PASSED
);
951 OUTPUT_Line("GlobalSize returned:");
952 OUTPUT_HexDword(size
);
953 subtest
= TEST_CombineStatus(subtest
, FAILED
);
960 OUTPUT_Line("GlobalAlloc failed!");
961 subtest
= TEST_CombineStatus(subtest
, FAILED
);
964 OUTPUT_Line("Result from subtest:");
965 OUTPUT_Result(subtest
);
966 result
= TEST_CombineStatus(result
, subtest
);
968 OUTPUT_Line("Test result:");
969 OUTPUT_Result(result
);
973 /*---------------------------------------------------------------------------
976 TEST_STATUS
TestGlobalDiscard()
981 TEST_STATUS subtest
= SKIPPED
;
982 TEST_STATUS result
= SKIPPED
;
984 OUTPUT_Banner("Testing GlobalDiscard()");
985 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
988 OUTPUT_Line("Allocation handle: ");
991 hTest
= GlobalDiscard(hMem
);
994 OUTPUT_Line("GlobalDiscard returned NULL");
995 subtest
= TEST_CombineStatus(subtest
, FAILED
);
999 uFlags
= GlobalFlags(hTest
);
1000 OUTPUT_Line("Flags from the new memory block.");
1001 OUTPUT_HexDword(uFlags
);
1002 if (0 != (uFlags
& GMEM_DISCARDED
))
1004 subtest
= TEST_CombineStatus(subtest
, PASSED
);
1008 OUTPUT_Line("Block is not marked as discardable.");
1009 subtest
= TEST_CombineStatus(subtest
, FAILED
);
1017 OUTPUT_Line("GlobalAlloc failed!");
1018 subtest
= TEST_CombineStatus(subtest
, FAILED
);
1021 OUTPUT_Line("Result from subtest:");
1022 OUTPUT_Result(subtest
);
1024 result
= TEST_CombineStatus(result
, subtest
);
1026 OUTPUT_Result(result
);
1030 /*---------------------------------------------------------------------------
1033 int main(int argc
, char ** argv
)
1035 TEST_STATUS test_set
= SKIPPED
;
1036 OUTPUT_Banner("Testing GlobalXXX memory management functions.");
1038 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GPTR
));
1039 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GHND
));
1040 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GMEM_FIXED
));
1041 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GMEM_MOVEABLE
));
1043 if (FAILED
== test_set
)
1045 OUTPUT_Line("Skipping any further tests. GlobalAlloc/Free fails.");
1046 OUTPUT_Result(test_set
);
1050 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GPTR
));
1051 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GHND
));
1052 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GMEM_FIXED
));
1053 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GMEM_MOVEABLE
));
1055 test_set
= TEST_CombineStatus(test_set
, TestGlobalReAlloc());
1057 test_set
= TEST_CombineStatus(test_set
, TestGlobalFlags());
1059 test_set
= TEST_CombineStatus(test_set
, TestGlobalHandle());
1061 test_set
= TEST_CombineStatus(test_set
, TestGlobalSize());
1063 test_set
= TEST_CombineStatus(test_set
, TestGlobalDiscard());
1065 /* output the result for the entire set of tests*/
1066 OUTPUT_Banner("Test suite result");
1067 OUTPUT_Result(test_set
);