Leaked source code of windows server 2003
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.

314 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Tshutwnd.c
  5. Abstract:
  6. This module contains the function test for the System Shutdown APIs
  7. Author:
  8. Dave Chalmers (davidc) 30-Apr-1992
  9. Environment:
  10. Windows, Crt - User Mode
  11. Notes:
  12. Since this is a test program it relies on assertions for error checking
  13. rather than a more robust mechanism.
  14. --*/
  15. #define MAX_STRING_LENGTH 80
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <windows.h>
  20. #ifdef UNICODE
  21. #error This module was designed to be built as ansi only
  22. #endif
  23. VOID
  24. main(
  25. INT argc,
  26. PCHAR argv[ ]
  27. )
  28. {
  29. LPTSTR MachineName = NULL;
  30. WCHAR UnicodeMachineName[MAX_STRING_LENGTH];
  31. PWCHAR pUnicodeMachineName = NULL;
  32. BOOL Result;
  33. BOOL Failed = FALSE;
  34. DWORD Error;
  35. //
  36. // Initialize options based on the command line.
  37. //
  38. while( *++argv ) {
  39. MachineName = *argv;
  40. }
  41. //
  42. // Get the machine name in unicode
  43. //
  44. if (MachineName != NULL) {
  45. MultiByteToWideChar(0,
  46. MachineName, -1,
  47. UnicodeMachineName, sizeof(UnicodeMachineName),
  48. MB_PRECOMPOSED);
  49. pUnicodeMachineName = UnicodeMachineName;
  50. printf("Machine Name(a) = <%s>\n", MachineName);
  51. printf("Machine Name(u) = <%ws>\n", UnicodeMachineName);
  52. }
  53. //
  54. // Start the test
  55. //
  56. printf("Running test again machine <%s>\n\n", MachineName);
  57. //
  58. // InitiateSystemShutdown (Ansi)
  59. //
  60. printf("Test InitiateSystemShutdown (Ansi)...");
  61. Result = InitiateSystemShutdownA(
  62. MachineName,
  63. NULL, // No message
  64. 0, // Timeout
  65. FALSE, // Force
  66. FALSE // Reboot
  67. );
  68. if (Result == FALSE) {
  69. Error = GetLastError();
  70. if (Error != ERROR_CALL_NOT_IMPLEMENTED) {
  71. printf("Failed.\n");
  72. printf("Call failed as expected but last error is incorrect\n");
  73. printf("LastError() returned %d, expected %d\n", Error, ERROR_CALL_NOT_IMPLEMENTED);
  74. Failed = TRUE;
  75. }
  76. } else {
  77. printf("Failed.\n");
  78. printf("Call succeeded, expected it to fail.\n");
  79. Failed = TRUE;
  80. }
  81. Result = InitiateSystemShutdownA(
  82. MachineName,
  83. "A shutdown message",
  84. 0, // Timeout
  85. FALSE, // Force
  86. FALSE // Reboot
  87. );
  88. if (Result == FALSE) {
  89. Error = GetLastError();
  90. if (Error != ERROR_CALL_NOT_IMPLEMENTED) {
  91. printf("Failed.\n");
  92. printf("Call failed as expected but last error is incorrect\n");
  93. printf("LastError() returned %d, expected %d\n", Error, ERROR_CALL_NOT_IMPLEMENTED);
  94. Failed = TRUE;
  95. }
  96. } else {
  97. printf("Failed.\n");
  98. printf("Call succeeded, expected it to fail.\n");
  99. Failed = TRUE;
  100. }
  101. if (Failed) {
  102. return;
  103. }
  104. printf("Succeeded.\n");
  105. //
  106. // InitiateSystemShutdown (Unicode)
  107. //
  108. printf("Test InitiateSystemShutdown (Unicode)...");
  109. Result = InitiateSystemShutdownW(
  110. pUnicodeMachineName,
  111. NULL, // No message
  112. 0, // Timeout
  113. FALSE, // Force
  114. FALSE // Reboot
  115. );
  116. if (Result == FALSE) {
  117. Error = GetLastError();
  118. if (Error != ERROR_CALL_NOT_IMPLEMENTED) {
  119. printf("Failed.\n");
  120. printf("Call failed as expected but last error is incorrect\n");
  121. printf("LastError() returned %d, expected %d\n", Error, ERROR_CALL_NOT_IMPLEMENTED);
  122. Failed = TRUE;
  123. }
  124. } else {
  125. printf("Failed.\n");
  126. printf("Call succeeded, expected it to fail.\n");
  127. Failed = TRUE;
  128. }
  129. Result = InitiateSystemShutdownW(
  130. pUnicodeMachineName,
  131. L"A shutdown message",
  132. 0, // Timeout
  133. FALSE, // Force
  134. FALSE // Reboot
  135. );
  136. if (Result == FALSE) {
  137. Error = GetLastError();
  138. if (Error != ERROR_CALL_NOT_IMPLEMENTED) {
  139. printf("Failed.\n");
  140. printf("Call failed as expected but last error is incorrect\n");
  141. printf("LastError() returned %d, expected %d\n", Error, ERROR_CALL_NOT_IMPLEMENTED);
  142. Failed = TRUE;
  143. }
  144. } else {
  145. printf("Failed.\n");
  146. printf("Call succeeded, expected it to fail.\n");
  147. Failed = TRUE;
  148. }
  149. if (Failed) {
  150. return;
  151. }
  152. printf("Succeeded.\n");
  153. //
  154. // AbortSystemShutdown (Ansi)
  155. //
  156. printf("Test AbortSystemShutdown (Ansi)...");
  157. Result = AbortSystemShutdownA(
  158. MachineName
  159. );
  160. if (Result == FALSE) {
  161. Error = GetLastError();
  162. if (Error != ERROR_CALL_NOT_IMPLEMENTED) {
  163. printf("Failed.\n");
  164. printf("Call failed as expected but last error is incorrect\n");
  165. printf("LastError() returned %d, expected %d\n", Error, ERROR_CALL_NOT_IMPLEMENTED);
  166. Failed = TRUE;
  167. }
  168. } else {
  169. printf("Failed.\n");
  170. printf("Call succeeded, expected it to fail.\n");
  171. Failed = TRUE;
  172. }
  173. if (Failed) {
  174. return;
  175. }
  176. printf("Succeeded.\n");
  177. //
  178. // AbortSystemShutdown (Unicode)
  179. //
  180. printf("Test AbortSystemShutdown (Unicode)...");
  181. Result = AbortSystemShutdownW(
  182. pUnicodeMachineName
  183. );
  184. if (Result == FALSE) {
  185. Error = GetLastError();
  186. if (Error != ERROR_CALL_NOT_IMPLEMENTED) {
  187. printf("Failed.\n");
  188. printf("Call failed as expected but last error is incorrect\n");
  189. printf("LastError() returned %d, expected %d\n", Error, ERROR_CALL_NOT_IMPLEMENTED);
  190. Failed = TRUE;
  191. }
  192. } else {
  193. printf("Failed.\n");
  194. printf("Call succeeded, expected it to fail.\n");
  195. Failed = TRUE;
  196. }
  197. if (Failed) {
  198. return;
  199. }
  200. printf("Succeeded.\n");
  201. return;
  202. UNREFERENCED_PARAMETER(argc);
  203. }