Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tbase.c
  5. Abstract:
  6. Skeleton for a Win32 Base API Test Program
  7. Author:
  8. Steve Wood (stevewo) 26-Oct-1990
  9. Revision History:
  10. --*/
  11. #include <assert.h>
  12. #include <stdio.h>
  13. #include <conio.h>
  14. #include <string.h>
  15. #include <windows.h>
  16. LPSTR Inserts[ 9 ] = {
  17. "Insert 1",
  18. "Insert 2",
  19. "Insert 3",
  20. "Insert 4",
  21. "Insert 5",
  22. "Insert 6",
  23. "Insert 7",
  24. "Insert 8",
  25. "Insert 9"
  26. };
  27. void
  28. TestEnvironment( void );
  29. DWORD
  30. main(
  31. int argc,
  32. char *argv[],
  33. char *envp[]
  34. )
  35. {
  36. int i;
  37. HANDLE hMod,x;
  38. CHAR Buff[256];
  39. PCHAR s;
  40. FARPROC f;
  41. DWORD Version;
  42. HANDLE Handle;
  43. DWORD rc;
  44. STARTUPINFO StartupInfo;
  45. GetStartupInfo(&StartupInfo);
  46. printf("Title %s\n",StartupInfo.lpTitle);
  47. printf( "TBASE: Entering Test Program\n" );
  48. assert(GetModuleFileName(0,Buff,256) < 255);
  49. printf("Image Name %s\n",Buff);
  50. #if 0
  51. printf( "argc: %ld\n", argc );
  52. for (i=0; i<argc; i++) {
  53. printf( "argv[ %3ld ]: '%s'\n", i, argv[ i ] );
  54. }
  55. for (i=0; envp[ i ]; i++) {
  56. printf( "envp[ %3ld ]: %s\n", i, envp[ i ] );
  57. }
  58. DbgBreakPoint();
  59. s = "ync ""Yes or No""";
  60. printf( "Invoking: '%s'\nResult: %d\n", s, system(s) );
  61. TestEnvironment();
  62. for (i=1; i<=256; i++) {
  63. rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  64. NULL,
  65. i, NULL, sizeof( Buff ), (va_list *)Inserts );
  66. if (rc != 0) {
  67. rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL,
  68. i, Buff, rc, (va_list *)Inserts );
  69. if (rc != 0) {
  70. cprintf( "SYS%05u: %s\r\n", i, Buff );
  71. }
  72. }
  73. }
  74. Handle = CreateFile( "\\config.sys",
  75. GENERIC_READ,
  76. FILE_SHARE_READ | FILE_SHARE_WRITE,
  77. NULL,
  78. OPEN_EXISTING,
  79. 0,
  80. NULL
  81. );
  82. if (Handle != INVALID_HANDLE_VALUE) {
  83. printf( "CreateFile successful, handle = %lX\n", Handle );
  84. }
  85. else {
  86. printf( "CreateFile failed\n" );
  87. }
  88. rc = SetFilePointer(Handle, 0, NULL, FILE_END);
  89. if (rc != -1) {
  90. printf( "File size = %ld\n", rc );
  91. }
  92. else {
  93. printf( "SetFilePointer failed\n" );
  94. }
  95. Version = GetVersion();
  96. assert( (Version & 0x0000ffff) == 4);
  97. assert( (Version >> 16) == 0);
  98. #endif
  99. hMod = LoadLibrary("dbgdll");
  100. assert(hMod);
  101. assert(hMod == GetModuleHandle("dbgdll"));
  102. hMod = LoadLibrary("c:\\nt\\dll\\csr.dll");
  103. assert(hMod);
  104. assert(GetModuleFileName(hMod,Buff,256) == strlen("c:\\nt\\dll\\csr.dll")+1);
  105. assert(_strcmpi(Buff,"c:\\nt\\dll\\csr.dll") == 0 );
  106. hMod = LoadLibrary("nt\\dll\\csrrtl.dll");
  107. assert(hMod);
  108. x = LoadLibrary("csrrtl");
  109. assert( x && x == hMod);
  110. assert(FreeLibrary(x));
  111. assert(FreeLibrary(x));
  112. hMod = GetModuleHandle("csrrtl");
  113. assert(hMod == NULL);
  114. x = LoadLibrary("csrrtl");
  115. assert( x );
  116. assert(FreeLibrary(x));
  117. hMod = LoadLibrary("kernel32");
  118. assert(hMod);
  119. f = GetProcAddress(hMod,"GetProcAddress");
  120. assert(f);
  121. assert(f == (f)(hMod,"GetProcAddress"));
  122. assert(f == MakeProcInstance(f,hMod));
  123. FreeProcInstance(f);
  124. DebugBreak();
  125. assert(FreeLibrary(hMod));
  126. // hMod = LoadLibrary("baddll");
  127. // assert(!hMod);
  128. printf( "TBASE: Exiting Test Program\n" );
  129. return 0;
  130. }
  131. VOID
  132. DumpEnvironment( VOID )
  133. {
  134. PCHAR s;
  135. s = (PCHAR)GetEnvironmentStrings();
  136. while (*s) {
  137. printf( "%s\n", s );
  138. while (*s++) {
  139. }
  140. }
  141. }
  142. VOID
  143. SetEnvironment(
  144. PCHAR Name,
  145. PCHAR Value
  146. );
  147. VOID
  148. SetEnvironment(
  149. PCHAR Name,
  150. PCHAR Value
  151. )
  152. {
  153. BOOL Success;
  154. Success = SetEnvironmentVariable( Name, Value );
  155. if (Value != NULL) {
  156. printf( "TENV: set variable %s=%s", Name, Value );
  157. }
  158. else {
  159. printf( "TENV: delete variable %Z", Name );
  160. }
  161. if (Success) {
  162. printf( "\n" );
  163. }
  164. else {
  165. printf( " - failed\n" );
  166. }
  167. DumpEnvironment();
  168. printf( "\n" );
  169. }
  170. void
  171. TestEnvironment( void )
  172. {
  173. DumpEnvironment();
  174. SetEnvironment( "aaaa", "12345" );
  175. SetEnvironment( "aaaa", "1234567890" );
  176. SetEnvironment( "aaaa", "1" );
  177. SetEnvironment( "aaaa", "" );
  178. SetEnvironment( "aaaa", NULL );
  179. SetEnvironment( "AAAA", "12345" );
  180. SetEnvironment( "AAAA", "1234567890" );
  181. SetEnvironment( "AAAA", "1" );
  182. SetEnvironment( "AAAA", "" );
  183. SetEnvironment( "AAAA", NULL );
  184. SetEnvironment( "MMMM", "12345" );
  185. SetEnvironment( "MMMM", "1234567890" );
  186. SetEnvironment( "MMMM", "1" );
  187. SetEnvironment( "MMMM", "" );
  188. SetEnvironment( "MMMM", NULL );
  189. SetEnvironment( "ZZZZ", "12345" );
  190. SetEnvironment( "ZZZZ", "1234567890" );
  191. SetEnvironment( "ZZZZ", "1" );
  192. SetEnvironment( "ZZZZ", "" );
  193. SetEnvironment( "ZZZZ", NULL );
  194. return;
  195. }