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.

351 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1993-2000 Microsoft Corporation
  3. Module Name:
  4. dceclnt.c
  5. Abstract:
  6. This is the client side of the test program for newndr.dll.
  7. Author:
  8. Michael Montague (mikemon) 13-Apr-1993
  9. Revision History:
  10. RyszardK Nov 30, 1993 Added tests for rpc_sm* package.
  11. RyszardK Jan 3, 1993 Carved out this independent test for newndr
  12. --*/
  13. #include <sysinc.h>
  14. #include <rpc.h>
  15. #include "rpcndr.h"
  16. void
  17. ApiError (
  18. char * TestName,
  19. char * ApiName,
  20. RPC_STATUS RpcStatus
  21. )
  22. {
  23. PrintToConsole(" ApiError in %s (%s = %u [%lx])\n", TestName, ApiName,
  24. RpcStatus, RpcStatus);
  25. }
  26. unsigned int MississippiBlockCount = 0;
  27. unsigned int VistulaBlockCount = 0;
  28. void *
  29. MississippiAllocate (
  30. unsigned long Size
  31. )
  32. {
  33. MississippiBlockCount += 1;
  34. return(I_RpcAllocate((unsigned int) Size));
  35. }
  36. void
  37. MississippiFree (
  38. void * Pointer
  39. )
  40. {
  41. MississippiBlockCount -= 1;
  42. I_RpcFree(Pointer);
  43. }
  44. void *
  45. VistulaAllocate (
  46. unsigned long Size
  47. )
  48. {
  49. VistulaBlockCount += 1;
  50. return(I_RpcAllocate((unsigned int) Size));
  51. }
  52. void
  53. VistulaFree (
  54. void * Pointer
  55. )
  56. {
  57. VistulaBlockCount -= 1;
  58. I_RpcFree(Pointer);
  59. }
  60. #define MISSISSIPPI_MAXIMUM 256
  61. #define VISTULA_MAXIMUM 4
  62. void * __RPC_API
  63. MIDL_user_allocate (
  64. size_t Size
  65. );
  66. void __RPC_API
  67. MIDL_user_free (
  68. void * Buffer
  69. );
  70. void
  71. Mississippi (
  72. )
  73. /*++
  74. Routine Description:
  75. We will test the memory allocator, both client and server, in this routine.
  76. --*/
  77. {
  78. unsigned int Count, Iterations;
  79. void * Pointer;
  80. // void * AllocatedBlocks[MISSISSIPPI_MAXIMUM];
  81. unsigned int MississippiPassed = 1;
  82. PrintToConsole("Mississippi : Test Ss* Memory Allocation\n");
  83. RpcTryExcept
  84. {
  85. for (Iterations = 1; Iterations < 64; Iterations++)
  86. {
  87. PrintToConsole(".");
  88. RpcSsEnableAllocate();
  89. for (Count = 0; Count < 2048; Count++)
  90. {
  91. Pointer = RpcSsAllocate(Count);
  92. if ( Count % Iterations == 0 )
  93. {
  94. RpcSsFree(Pointer);
  95. }
  96. }
  97. RpcSsDisableAllocate();
  98. }
  99. PrintToConsole("\n");
  100. }
  101. RpcExcept(1)
  102. {
  103. PrintToConsole("Mississippi : FAIL - Exception %d (%lx)\n",
  104. RpcExceptionCode(), RpcExceptionCode());
  105. MississippiPassed = 0;
  106. }
  107. RpcEndExcept
  108. #if 0
  109. RpcTryExcept
  110. {
  111. for (Count = 0; Count < MISSISSIPPI_MAXIMUM; Count++)
  112. {
  113. AllocatedBlocks[Count] = MIDL_user_allocate(Count);
  114. }
  115. for (Count = 0; Count < MISSISSIPPI_MAXIMUM; Count++)
  116. {
  117. MIDL_user_free(AllocatedBlocks[Count]);
  118. }
  119. RpcSsSetClientAllocFree(MississippiAllocate, MississippiFree);
  120. for (Count = 0; Count < MISSISSIPPI_MAXIMUM; Count++)
  121. {
  122. AllocatedBlocks[Count] = MIDL_user_allocate(Count);
  123. }
  124. if ( MississippiBlockCount != MISSISSIPPI_MAXIMUM )
  125. {
  126. PrintToConsole("Mississippi : FAIL - ");
  127. PrintToConsole("MississippiBlockCount != MISSISSIPPI_MAXIMUM\n");
  128. MississippiPassed = 0;
  129. }
  130. for (Count = 0; Count < MISSISSIPPI_MAXIMUM; Count++)
  131. {
  132. MIDL_user_free(AllocatedBlocks[Count]);
  133. }
  134. if ( MississippiBlockCount != 0 )
  135. {
  136. PrintToConsole("Mississippi : FAIL - ");
  137. PrintToConsole("MississippiBlockCount != 0");
  138. PrintToConsole(" (%d)\n", MississippiBlockCount );
  139. MississippiPassed = 0;
  140. }
  141. }
  142. RpcExcept(1)
  143. {
  144. PrintToConsole("Mississippi : FAIL - Exception %d (%lx)\n",
  145. RpcExceptionCode(), RpcExceptionCode());
  146. MississippiPassed = 0;
  147. }
  148. RpcEndExcept
  149. #endif
  150. if ( MississippiPassed != 0 )
  151. {
  152. PrintToConsole("Mississippi : PASS\n");
  153. }
  154. }
  155. void
  156. Vistula (
  157. )
  158. /*++
  159. Routine Description:
  160. We will test the memory allocator in this routine.
  161. This is cloned from the Mississippi bvt case.
  162. --*/
  163. {
  164. unsigned int Count, Iterations;
  165. void * Pointer;
  166. // void * AllocatedBlocks[VISTULA_MAXIMUM];
  167. RPC_SS_THREAD_HANDLE ThreadHandle = 0;
  168. unsigned int VistulaPassed = 1;
  169. RPC_STATUS Status;
  170. int Result = 0;
  171. PrintToConsole("Vistula : Test Sm* Memory Allocation\n");
  172. RpcTryExcept
  173. {
  174. for (Iterations = 1; Iterations < 64; Iterations++)
  175. {
  176. PrintToConsole(".");
  177. ThreadHandle = RpcSmGetThreadHandle( &Status );
  178. if ( ThreadHandle != 0 )
  179. PrintToConsole("H");
  180. if ( RpcSmEnableAllocate() != RPC_S_OK )
  181. {
  182. Result++;
  183. PrintToConsole("!");
  184. }
  185. ThreadHandle = RpcSmGetThreadHandle( &Status );
  186. if ( ThreadHandle == 0 )
  187. PrintToConsole("h");
  188. for (Count = 0; Count < 2048; Count++)
  189. {
  190. Pointer = RpcSmAllocate( Count, &Status );
  191. if ( Status != RPC_S_OK )
  192. {
  193. Result++;
  194. PrintToConsole("a");
  195. }
  196. if ( Count % Iterations == 0 )
  197. {
  198. Status = RpcSmFree(Pointer);
  199. if ( Status != RPC_S_OK )
  200. {
  201. Result++;
  202. PrintToConsole("f");
  203. }
  204. }
  205. }
  206. if ( RpcSmDisableAllocate() != RPC_S_OK )
  207. {
  208. Result++;
  209. PrintToConsole("?");
  210. }
  211. }
  212. PrintToConsole("\n");
  213. }
  214. RpcExcept(1)
  215. {
  216. PrintToConsole("Vistula : FAIL - Exception %d (%lx)\n",
  217. RpcExceptionCode(), RpcExceptionCode());
  218. VistulaPassed = 0;
  219. }
  220. RpcEndExcept
  221. if ( Result )
  222. {
  223. PrintToConsole("Vistula : FAIL - %d\n", Result );
  224. VistulaPassed = 0;
  225. }
  226. #if 0
  227. RpcTryExcept
  228. {
  229. for (Count = 0; Count < VISTULA_MAXIMUM; Count++)
  230. {
  231. AllocatedBlocks[Count] = MIDL_user_allocate(Count);
  232. }
  233. for (Count = 0; Count < VISTULA_MAXIMUM; Count++)
  234. {
  235. MIDL_user_free(AllocatedBlocks[Count]);
  236. }
  237. Status = RpcSmSetClientAllocFree( VistulaAllocate, VistulaFree);
  238. for (Count = 0; Count < VISTULA_MAXIMUM; Count++)
  239. {
  240. AllocatedBlocks[Count] = MIDL_user_allocate(Count);
  241. }
  242. if ( Status != RPC_S_OK ||
  243. VistulaBlockCount != VISTULA_MAXIMUM )
  244. {
  245. PrintToConsole("Vistula : FAIL - ");
  246. PrintToConsole("VistulaBlockCount != VISTULA_MAXIMUM\n");
  247. VistulaPassed = 0;
  248. }
  249. for (Count = 0; Count < VISTULA_MAXIMUM; Count++)
  250. {
  251. MIDL_user_free(AllocatedBlocks[Count]);
  252. }
  253. if ( VistulaBlockCount != 0 )
  254. {
  255. PrintToConsole("Vistula : FAIL - ");
  256. PrintToConsole("VistulaBlockCount != 0\n");
  257. VistulaPassed = 0;
  258. }
  259. }
  260. RpcExcept(1)
  261. {
  262. PrintToConsole("Vistula : FAIL - Exception %d (%lx)\n",
  263. RpcExceptionCode(), RpcExceptionCode());
  264. VistulaPassed = 0;
  265. }
  266. RpcEndExcept
  267. #endif
  268. if ( VistulaPassed != 0 )
  269. {
  270. PrintToConsole("Vistula : PASS\n");
  271. }
  272. }
  273. #ifdef NTENV
  274. int __cdecl
  275. #else // NTENV
  276. int
  277. #endif // NTENV
  278. main (
  279. int argc,
  280. char * argv[]
  281. )
  282. {
  283. Mississippi();
  284. Vistula();
  285. // To keep the compiler happy. There is nothing worse than an unhappy
  286. // compiler.
  287. return(0);
  288. }