ReactOS  0.4.12-dev-409-g9f418243
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
37 } TEST_STATUS;
enum TestStatus TEST_STATUS

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_Result(TEST_STATUS status)
Definition: global_mem.c:128
#define GPTR
Definition: winbase.h:293
enum TestStatus TEST_STATUS
TEST_STATUS TestGlobalLockNUnlock(UINT allocFlags)
Definition: global_mem.c:267
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
TEST_STATUS TestGlobalFlags()
Definition: global_mem.c:775
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
#define GHND
Definition: winbase.h:294
TEST_STATUS TestGlobalDiscard()
Definition: global_mem.c:976
TEST_STATUS TestGlobalReAlloc()
Definition: global_mem.c:605
TEST_STATUS TestGlobalAllocNFree(UINT allocFlags)
Definition: global_mem.c:238
#define GMEM_FIXED
Definition: winbase.h:290
void test_set()
Definition: test_set.cpp:75
TEST_STATUS TestGlobalHandle()
Definition: global_mem.c:790
#define GMEM_MOVEABLE
Definition: winbase.h:291
TEST_STATUS TestGlobalSize()
Definition: global_mem.c:876

◆ OUTPUT_Banner()

void OUTPUT_Banner ( const char szBanner)

Definition at line 118 of file global_mem.c.

119 {
121  OUTPUT_Line(szBanner);
123 }
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
void OUTPUT_BannerLine()
Definition: global_mem.c:63

Referenced by main(), TestGlobalAllocNFree(), TestGlobalDiscard(), TestGlobalFlags(), TestGlobalHandle(), TestGlobalLockNUnlock(), TestGlobalReAlloc(), and TestGlobalSize().

◆ 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 DISPLAY_COLUMNS
Definition: global_mem.c:17
const GLubyte * c
Definition: glext.h:8905
#define printf
Definition: config.h:203

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
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
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 }
GLuint buffer
Definition: glext.h:5915
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define sprintf(buf, format,...)
Definition: sprintf.c:55
REFIID LPVOID DWORD 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;
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 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define DISPLAY_COLUMNS
Definition: global_mem.c:17
static const WCHAR szLine[]
Definition: dialog.c:141
#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
#define printf
Definition: config.h:203

Referenced by main(), OUTPUT_Banner(), OUTPUT_Handle(), OUTPUT_HexDword(), 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 }
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
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 }
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define GMEM_MOVEABLE
Definition: winbase.h:291
#define GMEM_ZEROINIT
Definition: winbase.h:303

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:1059
GLuint buffer
Definition: glext.h:5915
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define sprintf(buf, format,...)
Definition: sprintf.c:55

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 }
enum TestStatus TEST_STATUS
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304

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 }
enum TestStatus TEST_STATUS
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:807
Definition: mem.c:156
GLuint64EXT * result
Definition: glext.h:11304

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:885
enum TestStatus TEST_STATUS
Definition: mem.c:156
GLuint64EXT * result
Definition: glext.h:11304

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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
enum TestStatus TEST_STATUS
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
void OutputAllocFlags(UINT pFlags)
Definition: global_mem.c:159
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
void OUTPUT_HexDword(DWORD dw)
Definition: global_mem.c:142
UINT NTAPI GlobalFlags(HGLOBAL hMem)
Definition: heapmem.c:520
enum TestStatus TEST_STATUS
#define GMEM_DISCARDED
Definition: winbase.h:304
UINT uFlags
Definition: api.c:60
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
#define GlobalDiscard(m)
Definition: winbase.h:2518
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_MOVEABLE
Definition: winbase.h:291

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 TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
enum TestStatus TEST_STATUS
TEST_STATUS TestGlobalFlagsFixed()
Definition: global_mem.c:718
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
TEST_STATUS TestGlobalFlagsMoveable()
Definition: global_mem.c:621
GLuint64EXT * result
Definition: glext.h:11304

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: ");
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*/
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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
UINT NTAPI GlobalFlags(HGLOBAL hMem)
Definition: heapmem.c:520
enum TestStatus TEST_STATUS
UINT uFlags
Definition: api.c:60
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
unsigned int UINT
Definition: ndis.h:50
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define GMEM_FIXED
Definition: winbase.h:290
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_LOCKCOUNT
Definition: winbase.h:306

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: ");
648  OUTPUT_Handle(GlobalLock(hMem));
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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
void OUTPUT_HexDword(DWORD dw)
Definition: global_mem.c:142
UINT NTAPI GlobalFlags(HGLOBAL hMem)
Definition: heapmem.c:520
enum TestStatus TEST_STATUS
#define GMEM_DISCARDED
Definition: winbase.h:304
UINT uFlags
Definition: api.c:60
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
unsigned int UINT
Definition: ndis.h:50
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_LOCKCOUNT
Definition: winbase.h:306
#define GMEM_MOVEABLE
Definition: winbase.h:291

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 
833  subtest = SKIPPED;
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 GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
enum TestStatus TEST_STATUS
HGLOBAL NTAPI GlobalHandle(LPCVOID pMem)
Definition: heapmem.c:705
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define GMEM_FIXED
Definition: winbase.h:290
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_MOVEABLE
Definition: winbase.h:291

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  {
316  OutputErrorCode();
319  }
320  }
321  }
322 
323  OUTPUT_Line("Freeing memory");
324  if (0 == GlobalFree(hMem))
325  {
328  }
329  else
330  {
331  OutputErrorCode();
334  }
335  }
336  return result;
337 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
enum TestStatus TEST_STATUS
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NO_ERROR
Definition: dderror.h:5
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
void OutputErrorCode()
Definition: global_mem.c:179
void OutputAllocFlags(UINT pFlags)
Definition: global_mem.c:159
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
GLuint64EXT * result
Definition: glext.h:11304
TEST_STATUS TEST_MemoryRead(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:204

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 TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
enum TestStatus TEST_STATUS
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
TEST_STATUS TestGlobalReAllocFixed()
Definition: global_mem.c:342
TEST_STATUS TestGlobalReAllocMovable()
Definition: global_mem.c:500
GLuint64EXT * result
Definition: glext.h:11304

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 
404  subtest = SKIPPED;
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 
447  subtest = SKIPPED;
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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
HGLOBAL NTAPI GlobalReAlloc(HGLOBAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:825
int IsMovable(HGLOBAL hMem)
Definition: global_mem.c:220
enum TestStatus TEST_STATUS
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define GMEM_FIXED
Definition: winbase.h:290
#define GMEM_MODIFY
Definition: winbase.h:292
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_MOVEABLE
Definition: winbase.h:291
TEST_STATUS TEST_MemoryWrite(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:190
TEST_STATUS TEST_MemoryRead(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:204

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 
549  subtest = SKIPPED;
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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
HGLOBAL NTAPI GlobalReAlloc(HGLOBAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:825
enum TestStatus TEST_STATUS
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Handle(HANDLE h)
Definition: global_mem.c:149
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_MOVEABLE
Definition: winbase.h:291
TEST_STATUS TEST_MemoryWrite(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:190
TEST_STATUS TEST_MemoryRead(LPVOID mem, DWORD cbSize)
Definition: global_mem.c:204

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 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
TEST_STATUS TEST_CombineStatus(TEST_STATUS a, TEST_STATUS b)
Definition: global_mem.c:46
void OUTPUT_Result(TEST_STATUS status)
Definition: global_mem.c:128
void OUTPUT_HexDword(DWORD dw)
Definition: global_mem.c:142
enum TestStatus TEST_STATUS
void OUTPUT_Line(const char *szLine)
Definition: global_mem.c:79
#define MEM_BLOCK_SIZE
Definition: global_mem.c:25
void OUTPUT_Banner(const char *szBanner)
Definition: global_mem.c:118
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
GLsizeiptr size
Definition: glext.h:5919
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define GMEM_FIXED
Definition: winbase.h:290
ULONG_PTR SIZE_T
Definition: typedefs.h:78
GLuint64EXT * result
Definition: glext.h:11304
#define GMEM_MOVEABLE
Definition: winbase.h:291

Referenced by main().