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 /*---------------------------------------------------------------------------
152 void OutputAllocFlags(UINT pFlags
)
154 if (pFlags
& GMEM_MOVEABLE
)
156 OUTPUT_Line("Movable Memory");
160 OUTPUT_Line("Fixed Memory");
163 if (pFlags
& GMEM_ZEROINIT
)
165 OUTPUT_Line("Zero Initialized Memory");
169 /*---------------------------------------------------------------------------
172 void OutputErrorCode()
176 sprintf(buffer
,"GetLastError() returned %lu", GetLastError());
180 /*---------------------------------------------------------------------------
183 TEST_STATUS
TEST_MemoryWrite(LPVOID mem
, DWORD cbSize
)
185 TEST_STATUS result
= FAILED
;
187 if (0 == IsBadWritePtr(mem
, cbSize
))
194 /*---------------------------------------------------------------------------
197 TEST_STATUS
TEST_MemoryRead(LPVOID mem
, DWORD cbSize
)
199 TEST_STATUS result
= FAILED
;
201 if (0 == IsBadReadPtr(mem
, cbSize
))
208 /*---------------------------------------------------------------------------
209 ** This method tests to see if a block of global memory is movable
210 ** by seeing if the value returned from GlobalLock is different from
211 ** the passed in value.
213 int IsMovable(HGLOBAL hMem
)
218 pMem
= GlobalLock(hMem
);
228 /*---------------------------------------------------------------------------
231 TEST_STATUS
TestGlobalAllocNFree(UINT allocFlags
)
233 TEST_STATUS status
= SKIPPED
;
235 OUTPUT_Banner("Testing the GlobalAlloc and GlobalFree calls");
236 OUTPUT_Line("Allocate a buffer");
238 OutputAllocFlags(allocFlags
);
241 hTest
= GlobalAlloc(allocFlags
, MEM_BLOCK_SIZE
);
244 if (0 == GlobalFree(hTest
));
250 OUTPUT_Line("Result for this run:");
251 OUTPUT_Result(status
);
257 /*---------------------------------------------------------------------------
260 TEST_STATUS
TestGlobalLockNUnlock(UINT allocFlags
)
264 TEST_STATUS subtest
= SKIPPED
;
265 TEST_STATUS result
= FAILED
;
267 OUTPUT_Banner("Testing the GlobalLock/Unlock functions.");
268 OutputAllocFlags(allocFlags
);
271 hMem
= GlobalAlloc(allocFlags
, MEM_BLOCK_SIZE
);
274 OUTPUT_Line("Allocated a memory block");
276 OUTPUT_Line("Testing Lock");
277 pMem
= GlobalLock(hMem
);
280 OUTPUT_Result(PASSED
);
282 OUTPUT_Line("Testing memory for read.");
283 subtest
= TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
);
284 OUTPUT_Result(subtest
);
285 result
= TEST_CombineStatus(PASSED
, subtest
);
288 OUTPUT_Line("Testing memory for write.");
289 subtest
= TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
);
290 OUTPUT_Result(subtest
);
291 result
= TEST_CombineStatus(result
, subtest
);
294 OUTPUT_Line("Unlocking memory");
295 if (GlobalUnlock(hMem
))
297 OUTPUT_Result(PASSED
);
298 result
= TEST_CombineStatus(result
, PASSED
);
302 if (NO_ERROR
== GetLastError())
304 OUTPUT_Result(PASSED
);
305 result
= TEST_CombineStatus(result
, PASSED
);
310 OUTPUT_Result(FAILED
);
311 result
= TEST_CombineStatus(result
, FAILED
);
316 OUTPUT_Line("Freeing memory");
317 if (0 == GlobalFree(hMem
))
319 OUTPUT_Result(PASSED
);
320 result
= TEST_CombineStatus(result
, PASSED
);
325 OUTPUT_Result(FAILED
);
326 result
= TEST_CombineStatus(result
, FAILED
);
332 /*---------------------------------------------------------------------------
335 TEST_STATUS
TestGlobalReAllocFixed()
338 HGLOBAL hReAlloced
= 0;
340 TEST_STATUS subtest
= SKIPPED
;
341 TEST_STATUS result
= SKIPPED
;
343 OUTPUT_Line("Testing GlobalReAlloc() on memory allocated as GMEM_FIXED");
345 /* Case 1: convert a fixed block to a movable block. */
346 OUTPUT_Line("Allocating buffer");
347 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
350 OUTPUT_Line("Testing to see if this is converted into a movable block");
351 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
+ 100, GMEM_MOVEABLE
| GMEM_MODIFY
);
354 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
355 subtest
= TEST_CombineStatus(subtest
, FAILED
);
356 OUTPUT_Result(subtest
);
361 if (0 == IsMovable(hMem
))
363 OUTPUT_Line("GlobalReAlloc returned a fixed pointer.");
364 subtest
= TEST_CombineStatus(subtest
, FAILED
);
365 OUTPUT_Result(subtest
);
369 pMem
= GlobalLock(hMem
);
370 subtest
= TEST_CombineStatus(subtest
, PASSED
);
371 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
+ 100));
372 if (FAILED
== subtest
)
374 OUTPUT_Line("Memory Read failed.");
376 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite(pMem
, MEM_BLOCK_SIZE
+ 100));
377 if (FAILED
== subtest
)
379 OUTPUT_Line("Memory Write failed.");
389 OUTPUT_Line("Global Alloc Failed.");
390 subtest
= TEST_CombineStatus(subtest
, FAILED
);
392 OUTPUT_Line("Subtest result:");
393 OUTPUT_Result(subtest
);
396 result
= TEST_CombineStatus(result
, subtest
);
399 /* case 2 only move a fixed block */
400 OUTPUT_Line("Allocating buffer");
401 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
404 OUTPUT_Line("Testing to see if a new fixed block is returned.");
405 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, GMEM_MOVEABLE
);
408 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
409 subtest
= TEST_CombineStatus(subtest
, FAILED
);
410 OUTPUT_Result(subtest
);
414 OUTPUT_Line("Alloced Handle: ");
415 OUTPUT_HexDword((DWORD
)hMem
);
416 OUTPUT_Line("ReAlloced Handle: ");
417 OUTPUT_HexDword((DWORD
)hReAlloced
);
418 if (hMem
== hReAlloced
)
420 OUTPUT_Line("GlobalReAlloc returned the same pointer. The documentation states that this is wrong, but Windows NT works this way.");
424 subtest
= TEST_CombineStatus(subtest
, PASSED
);
425 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
426 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
433 subtest
= TEST_CombineStatus(subtest
, FAILED
);
435 OUTPUT_Line("Subtest result:");
436 OUTPUT_Result(subtest
);
439 result
= TEST_CombineStatus(result
, subtest
);
442 /* Case 3: re-allocate a fixed block in place */
443 OUTPUT_Line("Allocating buffer");
444 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
447 OUTPUT_Line("Testing to see if a fixed pointer is reallocated in place.");
448 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, 0);
451 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
452 subtest
= TEST_CombineStatus(subtest
, FAILED
);
453 OUTPUT_Result(subtest
);
457 OUTPUT_Line("Alloced Handle: ");
458 OUTPUT_HexDword((DWORD
)hMem
);
459 OUTPUT_Line("ReAlloced Handle: ");
460 OUTPUT_HexDword((DWORD
)hReAlloced
);
461 if (hMem
!= hReAlloced
)
463 OUTPUT_Line("GlobalReAlloc returned a different.");
464 subtest
= TEST_CombineStatus(subtest
, FAILED
);
465 OUTPUT_Result(subtest
);
469 subtest
= TEST_CombineStatus(subtest
, PASSED
);
470 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
471 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite((LPVOID
)hMem
, MEM_BLOCK_SIZE
- 100));
479 subtest
= TEST_CombineStatus(subtest
, FAILED
);
481 OUTPUT_Line("Subtest result:");
482 OUTPUT_Result(subtest
);
485 result
= TEST_CombineStatus(result
, subtest
);
490 /*---------------------------------------------------------------------------
493 TEST_STATUS
TestGlobalReAllocMovable()
496 HGLOBAL hReAlloced
= 0;
498 TEST_STATUS subtest
= SKIPPED
;
499 TEST_STATUS result
= SKIPPED
;
501 OUTPUT_Line("Testing GlobalReAlloc() on memory allocated as GMGM_MOVEABLE");
503 /* case 1 test reallocing a movable block that is unlocked. */
504 OUTPUT_Line("Allocating buffer");
505 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
508 OUTPUT_Line("Testing GlobalReAlloc on a unlocked block.");
509 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, 0);
512 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
513 subtest
= TEST_CombineStatus(subtest
, FAILED
);
514 OUTPUT_Result(subtest
);
518 OUTPUT_Line("Alloced Handle: ");
519 OUTPUT_HexDword((DWORD
)hMem
);
520 OUTPUT_Line("ReAlloced Handle: ");
521 OUTPUT_HexDword((DWORD
)hReAlloced
);
523 pMem
= GlobalLock(hReAlloced
);
525 subtest
= TEST_CombineStatus(subtest
, PASSED
);
526 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
- 100));
527 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite(pMem
, MEM_BLOCK_SIZE
- 100));
528 GlobalUnlock(hReAlloced
);
535 subtest
= TEST_CombineStatus(subtest
, FAILED
);
537 OUTPUT_Line("Subtest result:");
538 OUTPUT_Result(subtest
);
541 result
= TEST_CombineStatus(result
, subtest
);
544 /* Case 2: re-allocate a moveable block that is locked */
545 OUTPUT_Line("Allocating buffer");
546 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
550 OUTPUT_Line("Testing GlobalReAlloc on a locked block.");
551 pMem
= GlobalLock(hMem
);
552 hReAlloced
= GlobalReAlloc(hMem
, MEM_BLOCK_SIZE
- 100, 0);
555 OUTPUT_Line("GlobalReAlloc failed-- returned NULL");
556 subtest
= TEST_CombineStatus(subtest
, FAILED
);
557 OUTPUT_Result(subtest
);
561 OUTPUT_Line("Alloced Handle: ");
562 OUTPUT_HexDword((DWORD
)hMem
);
563 OUTPUT_Line("ReAlloced Handle: ");
564 OUTPUT_HexDword((DWORD
)hReAlloced
);
565 if (hMem
!= hReAlloced
)
567 OUTPUT_Line("GlobalReAlloc returned a different block.");
569 pMem
= GlobalLock(hReAlloced
);
570 subtest
= TEST_CombineStatus(subtest
, PASSED
);
571 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryRead(pMem
, MEM_BLOCK_SIZE
- 100));
572 subtest
= TEST_CombineStatus(subtest
, TEST_MemoryWrite(pMem
, MEM_BLOCK_SIZE
- 100));
573 GlobalUnlock(hReAlloced
);
583 subtest
= TEST_CombineStatus(subtest
, FAILED
);
585 OUTPUT_Line("Subtest result:");
586 OUTPUT_Result(subtest
);
589 result
= TEST_CombineStatus(result
, subtest
);
595 /*---------------------------------------------------------------------------
598 TEST_STATUS
TestGlobalReAlloc()
600 OUTPUT_Banner("Testing GlobalReAlloc()");
601 TEST_STATUS result
= SKIPPED
;
603 result
= TEST_CombineStatus(result
, TestGlobalReAllocFixed());
604 result
= TEST_CombineStatus(result
, TestGlobalReAllocMovable());
606 OUTPUT_Line("GlobalReAlloc test result:");
607 OUTPUT_Result(result
);
611 /*---------------------------------------------------------------------------
614 TEST_STATUS
TestGlobalFlagsMoveable()
618 TEST_STATUS result
= SKIPPED
;
620 OUTPUT_Line("Test for the proper lock count");
622 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
626 OUTPUT_Line("Testing initial allocation");
628 OUTPUT_Line("Testing for a lock of 0");
629 uFlags
= GlobalFlags(hMem
);
630 if (((GMEM_LOCKCOUNT
& uFlags
) == 0)) /*no locks*/
632 result
= TEST_CombineStatus(result
, PASSED
);
636 result
= TEST_CombineStatus(result
, FAILED
);
638 OUTPUT_Result(result
);
640 OUTPUT_Line("Pointer from handle: ");
641 OUTPUT_HexDword((DWORD
)GlobalLock(hMem
));
643 OUTPUT_Line("Testing after a lock");
644 OUTPUT_Line("Testing for a lock of 1");
645 uFlags
= GlobalFlags(hMem
);
646 if (((GMEM_LOCKCOUNT
& uFlags
) == 1)) /*no locks*/
648 result
= TEST_CombineStatus(result
, PASSED
);
652 result
= TEST_CombineStatus(result
, FAILED
);
654 OUTPUT_Result(result
);
657 OUTPUT_Line("Testing after an unlock");
658 OUTPUT_Line("Testing for a lock of 0");
659 uFlags
= GlobalFlags(hMem
);
660 if (((GMEM_LOCKCOUNT
& uFlags
) == 0)) /*no locks*/
662 result
= TEST_CombineStatus(result
, PASSED
);
666 result
= TEST_CombineStatus(result
, FAILED
);
668 OUTPUT_Result(result
);
672 OUTPUT_Line("GlobalAlloc failed!");
673 result
= TEST_CombineStatus(result
, FAILED
);
676 OUTPUT_Line("Test for discarded memory");
677 OUTPUT_Line("Allocating an empty moveable block---automatically marked as discarded");
678 hMem
= GlobalAlloc(GMEM_MOVEABLE
, 0); /*allocate a discarded block*/
681 OUTPUT_Line("Allocation handle: ");
682 OUTPUT_HexDword((DWORD
)hMem
);
683 OUTPUT_Line("Testing for a discarded flag");
684 uFlags
= GlobalFlags(hMem
);
685 if (0 != (uFlags
& GMEM_DISCARDED
)) /*discarded*/
687 result
= TEST_CombineStatus(result
, PASSED
);
691 result
= TEST_CombineStatus(result
, FAILED
);
693 OUTPUT_Line("Flags:");
694 OUTPUT_HexDword(uFlags
);
695 OUTPUT_Result(result
);
701 OUTPUT_Line("GlobalAlloc failed!");
702 result
= TEST_CombineStatus(result
, FAILED
);
708 /*---------------------------------------------------------------------------
711 TEST_STATUS
TestGlobalFlagsFixed()
715 TEST_STATUS result
= SKIPPED
;
717 OUTPUT_Line("Testing for correct handling of GMEM_FIXED memory");
718 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
722 OUTPUT_Line("Allocation handle: ");
723 OUTPUT_HexDword((DWORD
)hMem
);
725 OUTPUT_Line("Testing initial allocation");
726 OUTPUT_Line("Testing for non-discarded and lock of 0");
727 uFlags
= GlobalFlags(hMem
);
728 if (((GMEM_LOCKCOUNT
& uFlags
) == 0) && /*no locks*/
729 (((uFlags
>> 8) & 0xff) == 0 )) /*not discarded*/
731 result
= TEST_CombineStatus(result
, PASSED
);
735 result
= TEST_CombineStatus(result
, FAILED
);
737 OUTPUT_Result(result
);
739 OUTPUT_Line("Pointer from handle: ");
740 OUTPUT_HexDword((DWORD
)GlobalLock(hMem
));
741 OUTPUT_Line("Testing after a lock");
742 OUTPUT_Line("Testing for non-discarded and lock of 0");
743 uFlags
= GlobalFlags(hMem
);
744 if (((GMEM_LOCKCOUNT
& uFlags
) == 0) && /*no locks*/
745 (((uFlags
>> 8) & 0xff) == 0 )) /*not discarded*/
747 result
= TEST_CombineStatus(result
, PASSED
);
751 result
= TEST_CombineStatus(result
, FAILED
);
753 OUTPUT_Result(result
);
759 OUTPUT_Line("GlobalAlloc failed!");
760 result
= TEST_CombineStatus(result
, FAILED
);
765 /*---------------------------------------------------------------------------
768 TEST_STATUS
TestGlobalFlags()
770 OUTPUT_Banner("Testing GlobalFlags()");
771 TEST_STATUS result
= SKIPPED
;
773 result
= TEST_CombineStatus(result
, TestGlobalFlagsFixed());
774 result
= TEST_CombineStatus(result
, TestGlobalFlagsMoveable());
776 OUTPUT_Line("GlobalFlags result:");
777 OUTPUT_Result(result
);
780 /*---------------------------------------------------------------------------
783 TEST_STATUS
TestGlobalHandle()
788 TEST_STATUS subtest
= SKIPPED
;
789 TEST_STATUS result
= SKIPPED
;
791 OUTPUT_Banner("Testing GlobalHandle()");
793 OUTPUT_Line("Testing GlobalHandle with a block of GMEM_FIXED memory");
794 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
798 OUTPUT_Line("Allocation handle: ");
799 OUTPUT_HexDword((DWORD
)hMem
);
801 hTest
= GlobalHandle(hMem
);
804 subtest
= TEST_CombineStatus(subtest
, PASSED
);
808 OUTPUT_Line("GlobalHandle returned:");
809 OUTPUT_HexDword((DWORD
)hTest
);
810 subtest
= TEST_CombineStatus(subtest
, FAILED
);
817 OUTPUT_Line("GlobalAlloc failed!");
818 subtest
= TEST_CombineStatus(subtest
, FAILED
);
821 OUTPUT_Line("Result from subtest:");
822 OUTPUT_Result(subtest
);
823 result
= TEST_CombineStatus(result
, subtest
);
827 OUTPUT_Line("Testing GlobalHandle with a block of GMEM_MOVEABLE memory");
828 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
832 OUTPUT_Line("Allocation handle: ");
833 OUTPUT_HexDword((DWORD
)hMem
);
834 pMem
= GlobalLock(hMem
);
835 hTest
= GlobalHandle(pMem
);
838 subtest
= TEST_CombineStatus(subtest
, PASSED
);
842 OUTPUT_Line("GlobalHandle returned:");
843 OUTPUT_HexDword((DWORD
)hTest
);
844 subtest
= TEST_CombineStatus(subtest
, FAILED
);
852 OUTPUT_Line("GlobalAlloc failed!");
853 subtest
= TEST_CombineStatus(subtest
, FAILED
);
856 OUTPUT_Line("Result from subtest:");
857 OUTPUT_Result(subtest
);
858 result
= TEST_CombineStatus(result
, subtest
);
861 OUTPUT_Line("Global Handle test results:");
862 OUTPUT_Result(result
);
866 /*---------------------------------------------------------------------------
869 TEST_STATUS
TestGlobalSize()
873 TEST_STATUS subtest
= SKIPPED
;
874 TEST_STATUS result
= SKIPPED
;
875 OUTPUT_Banner("Testing GlobalSize()");
877 OUTPUT_Line("Testing GlobalSize with a block of GMEM_FIXED memory");
878 hMem
= GlobalAlloc(GMEM_FIXED
, MEM_BLOCK_SIZE
);
881 size
= GlobalSize(hMem
);
882 if (MEM_BLOCK_SIZE
<= size
)
884 subtest
= TEST_CombineStatus(subtest
, PASSED
);
888 OUTPUT_Line("GlobalSize returned:");
889 OUTPUT_HexDword(size
);
890 subtest
= TEST_CombineStatus(subtest
, FAILED
);
897 OUTPUT_Line("GlobalAlloc failed!");
898 subtest
= TEST_CombineStatus(subtest
, FAILED
);
901 OUTPUT_Line("Result from subtest:");
902 OUTPUT_Result(subtest
);
903 result
= TEST_CombineStatus(result
, subtest
);
905 OUTPUT_Line("Testing GlobalSize with a block of GMEM_MOVEABLE memory");
906 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
909 size
= GlobalSize(hMem
);
910 if (MEM_BLOCK_SIZE
<= size
)
912 subtest
= TEST_CombineStatus(subtest
, PASSED
);
916 OUTPUT_Line("GlobalSize returned:");
917 OUTPUT_HexDword(size
);
918 subtest
= TEST_CombineStatus(subtest
, FAILED
);
925 OUTPUT_Line("GlobalAlloc failed!");
926 subtest
= TEST_CombineStatus(subtest
, FAILED
);
929 OUTPUT_Line("Result from subtest:");
930 OUTPUT_Result(subtest
);
931 result
= TEST_CombineStatus(result
, subtest
);
933 OUTPUT_Line("Testing GlobalSize with discarded memory");
934 hMem
= GlobalAlloc(GMEM_MOVEABLE
, 0);
937 size
= GlobalSize(hMem
);
940 subtest
= TEST_CombineStatus(subtest
, PASSED
);
944 OUTPUT_Line("GlobalSize returned:");
945 OUTPUT_HexDword(size
);
946 subtest
= TEST_CombineStatus(subtest
, FAILED
);
953 OUTPUT_Line("GlobalAlloc failed!");
954 subtest
= TEST_CombineStatus(subtest
, FAILED
);
957 OUTPUT_Line("Result from subtest:");
958 OUTPUT_Result(subtest
);
959 result
= TEST_CombineStatus(result
, subtest
);
961 OUTPUT_Line("Test result:");
962 OUTPUT_Result(result
);
966 /*---------------------------------------------------------------------------
969 TEST_STATUS
TestGlobalDiscard()
974 TEST_STATUS subtest
= SKIPPED
;
975 TEST_STATUS result
= SKIPPED
;
977 OUTPUT_Banner("Testing GlobalDiscard()");
978 hMem
= GlobalAlloc(GMEM_MOVEABLE
, MEM_BLOCK_SIZE
);
981 OUTPUT_Line("Allocation handle: ");
982 OUTPUT_HexDword((DWORD
)hMem
);
984 hTest
= GlobalDiscard(hMem
);
987 OUTPUT_Line("GlobalDiscard returned NULL");
988 subtest
= TEST_CombineStatus(subtest
, FAILED
);
992 uFlags
= GlobalFlags(hTest
);
993 OUTPUT_Line("Flags from the new memory block.");
994 OUTPUT_HexDword(uFlags
);
995 if (0 != (uFlags
& GMEM_DISCARDED
))
997 subtest
= TEST_CombineStatus(subtest
, PASSED
);
1001 OUTPUT_Line("Block is not marked as discardable.");
1002 subtest
= TEST_CombineStatus(subtest
, FAILED
);
1010 OUTPUT_Line("GlobalAlloc failed!");
1011 subtest
= TEST_CombineStatus(subtest
, FAILED
);
1014 OUTPUT_Line("Result from subtest:");
1015 OUTPUT_Result(subtest
);
1017 result
= TEST_CombineStatus(result
, subtest
);
1019 OUTPUT_Result(result
);
1023 /*---------------------------------------------------------------------------
1026 int main(int argc
, char ** argv
)
1028 TEST_STATUS test_set
= SKIPPED
;
1029 OUTPUT_Banner("Testing GlobalXXX memory management functions.");
1031 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GPTR
));
1032 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GHND
));
1033 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GMEM_FIXED
));
1034 test_set
= TEST_CombineStatus(test_set
, TestGlobalAllocNFree(GMEM_MOVEABLE
));
1036 if (FAILED
== test_set
)
1038 OUTPUT_Line("Skipping any further tests. GlobalAlloc/Free fails.");
1039 OUTPUT_Result(test_set
);
1043 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GPTR
));
1044 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GHND
));
1045 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GMEM_FIXED
));
1046 test_set
= TEST_CombineStatus(test_set
, TestGlobalLockNUnlock(GMEM_MOVEABLE
));
1048 test_set
= TEST_CombineStatus(test_set
, TestGlobalReAlloc());
1050 test_set
= TEST_CombineStatus(test_set
, TestGlobalFlags());
1052 test_set
= TEST_CombineStatus(test_set
, TestGlobalHandle());
1054 test_set
= TEST_CombineStatus(test_set
, TestGlobalSize());
1056 test_set
= TEST_CombineStatus(test_set
, TestGlobalDiscard());
1058 /* output the result for the entire set of tests*/
1059 OUTPUT_Banner("Test suite result");
1060 OUTPUT_Result(test_set
);