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.

291 lines
7.7 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: drt.cxx
  7. //
  8. // Contents: DRT main routine
  9. //
  10. // History: 22-Sep-92 DrewB Created
  11. //
  12. //---------------------------------------------------------------
  13. #include "headers.cxx"
  14. #pragma hdrstop
  15. #include "tests.hxx"
  16. #include "illeg.hxx"
  17. // Test flags and type
  18. typedef ULONG FLAGS;
  19. #define TF_NONE 0x00000000
  20. // Suppression flags
  21. #define TF_SUPPRESS 0x0000FFFF
  22. #define TFS_ILLEGITIMATE 0x00000001
  23. #define TFS_16BIT 0x00000002
  24. // Enabling flags
  25. #define TF_ENABLE 0xFFFF0000
  26. #define TFE_DIRECT 0x00010000
  27. #define TFE_TRANSACTED 0x00020000
  28. #define TFE_INDEPENDENT 0x00040000
  29. #define TFE_ANY (TFE_DIRECT | TFE_TRANSACTED | TFE_INDEPENDENT)
  30. // Pointer to a test function
  31. typedef void (*TestFn)(void);
  32. static struct
  33. {
  34. char *pszName;
  35. char *pszDesc;
  36. TestFn tfn;
  37. FLAGS flags;
  38. } tests[] =
  39. {
  40. "Create", "Creation",
  41. t_create, TFE_ANY,
  42. "Open", "Opening",
  43. t_open, TFE_ANY,
  44. "AddRef", "AddRef/Release",
  45. t_addref, TFE_ANY,
  46. "TModify", "Transacted modify/Commit/Revert",
  47. t_tmodify, TFE_TRANSACTED | TFE_INDEPENDENT,
  48. "DModify", "Direct modifications",
  49. t_dmodify, TFE_DIRECT,
  50. "Stat", "Stat",
  51. t_stat, TFE_ANY,
  52. "Stream", "Stream operations",
  53. t_stream, TFE_ANY,
  54. "Enum", "Enumerator operations",
  55. t_enum, TFE_ANY,
  56. "StgCopyTo", "IStorage::CopyTo",
  57. t_stgcopyto, TFE_ANY,
  58. "MoveCopy", "IStorage::MoveElementTo",
  59. t_movecopy, TFE_ANY,
  60. "Marshal", "IMarshal operations",
  61. t_marshal, TFE_ANY
  62. #if WIN32 == 200
  63. // No marshalling on Chicago
  64. | TFS_16BIT
  65. #endif
  66. ,
  67. "ILockBytes", "ILockBytes usage",
  68. t_ilb, TFE_ANY,
  69. "StgMisc", "Miscellaneous Stg functions",
  70. t_stgmisc, TFE_ANY,
  71. "IllStg", "Illegitimate IStorage calls",
  72. i_storage, TFE_ANY | TFS_ILLEGITIMATE,
  73. "IllStm", "Illegitimate IStream calls",
  74. i_stream, TFE_ANY | TFS_ILLEGITIMATE,
  75. "IllEnum", "Illegitimate enumerator calls",
  76. i_enum, TFE_ANY | TFS_ILLEGITIMATE
  77. };
  78. #define NTESTS (sizeof(tests)/sizeof(tests[0]))
  79. DWORD dwTransacted = 0;
  80. DWORD dwRootDenyWrite = STGM_SHARE_DENY_WRITE;
  81. BOOL fVerbose = FALSE;
  82. OLECHAR atcDrtDocfile[_MAX_PATH];
  83. static BOOL fRun[NTESTS];
  84. #ifdef FLAT
  85. static FLAGS flTests = TF_NONE;
  86. #else
  87. static FLAGS flTests = TF_NONE | TFS_16BIT;
  88. #endif
  89. static void Initialize(void)
  90. {
  91. SCODE sc;
  92. SetData();
  93. #if WIN32 == 300
  94. if (FAILED(sc = DfGetScode(CoInitializeEx(NULL, COINIT_MULTITHREADED))))
  95. error(EXIT_UNKNOWN,
  96. "CoInitializeEx failed with sc = 0x%lX\n", sc);
  97. #else
  98. if (FAILED(sc = DfGetScode(CoInitialize(NULL))))
  99. error(EXIT_UNKNOWN,
  100. "CoInitialize failed with sc = 0x%lX\n", sc);
  101. #endif
  102. }
  103. static void Uninitialize(void)
  104. {
  105. UnsetData();
  106. CoUninitialize();
  107. }
  108. static int FindTest(char *pszName)
  109. {
  110. int i, cchName;
  111. cchName = strlen(pszName);
  112. for (i = 0; i<NTESTS; i++)
  113. if (!_strnicmp(pszName, tests[i].pszName, cchName))
  114. return i;
  115. return -1;
  116. }
  117. static void RunTests(void)
  118. {
  119. int i;
  120. for (i = 0; i<NTESTS; i++)
  121. // For a test to run:
  122. // 1) fRun[test] must be TRUE
  123. // 2) No suppression flags can be set that are not set in flTests
  124. // 3) At least one enabling flag must be set that is set in flTests
  125. if (fRun[i] &&
  126. (tests[i].flags & ~flTests & TF_SUPPRESS) == 0 &&
  127. (tests[i].flags & flTests & TF_ENABLE) != 0)
  128. {
  129. out("\n----- Test #%2d - %s -----\n", i+1, tests[i].pszDesc);
  130. tests[i].tfn();
  131. CheckMemory();
  132. CleanData();
  133. }
  134. }
  135. static void Usage(void)
  136. {
  137. int i;
  138. printf("Usage: drt [options]\n");
  139. printf("Options are:\n");
  140. printf(" -h - This message\n");
  141. printf(" -d - Suppress direct tests\n");
  142. printf(" -t - Suppress transacted tests\n");
  143. printf(" -w - Suppress independent tests\n");
  144. printf(" -i - Enable illegitimate tests\n");
  145. printf(" -v - Display test output\n");
  146. printf(" -y<kind> - Control debug output (a, d, m, i, M, L)\n");
  147. printf(" -#[+|-]<number> - Turn test <number> on (+) or off (-)\n");
  148. printf(" No number means all\n");
  149. printf(" -n[+|-]<prefix> - Turn test <prefix> on or off\n");
  150. printf(" -N<file> - Set file to use for tests\n");
  151. printf("Prefix can be any prefix of:\n");
  152. for (i = 0; i<NTESTS; i++)
  153. printf(" %s\n", tests[i].pszName);
  154. exit(1);
  155. }
  156. void __cdecl main(int argc, char **argv)
  157. {
  158. int i, iTest;
  159. BOOL fDirect = TRUE, fTrans = TRUE, fIndep = TRUE;
  160. SetDebug(0x101, 0x101);
  161. for (i = 0; i<NTESTS; i++)
  162. fRun[i] = TRUE;
  163. ATOOLE("drt.dfl", atcDrtDocfile, _MAX_PATH);
  164. while (--argc>0)
  165. {
  166. if (**++argv == '-')
  167. {
  168. switch(argv[0][1])
  169. {
  170. case '#':
  171. if (sscanf(argv[0]+3, "%d", &iTest) != 1)
  172. iTest = -1;
  173. else
  174. iTest--;
  175. for (i = 0; i<NTESTS; i++)
  176. if (iTest == -1 || iTest == i)
  177. fRun[i] = argv[0][2] == '+';
  178. break;
  179. case 'd':
  180. fDirect = FALSE;
  181. break;
  182. case 'i':
  183. flTests |= TFS_ILLEGITIMATE;
  184. break;
  185. case 'n':
  186. iTest = FindTest(argv[0]+3);
  187. if (iTest >= 0)
  188. fRun[iTest] = argv[0][2] == '+';
  189. break;
  190. case 'N':
  191. ATOOLE(argv[0]+2, atcDrtDocfile, _MAX_PATH);
  192. break;
  193. case 't':
  194. fTrans = FALSE;
  195. break;
  196. case 'v':
  197. fVerbose = TRUE;
  198. break;
  199. case 'w':
  200. fIndep = FALSE;
  201. break;
  202. case 'y':
  203. switch(argv[0][2])
  204. {
  205. case 'a':
  206. SetDebug(0xffffffff, 0xffffffff);
  207. break;
  208. case 'd':
  209. SetDebug(0xffffffff, 0x101);
  210. break;
  211. case 'm':
  212. SetDebug(0x101, 0xffffffff);
  213. break;
  214. case 'i':
  215. SetDebug(0x101, 0x101);
  216. break;
  217. case 'M':
  218. SetDebug(0x01100000, 0);
  219. break;
  220. case 'L':
  221. SetDebug(0x00100000, 0);
  222. break;
  223. }
  224. break;
  225. case 'h':
  226. default:
  227. Usage();
  228. }
  229. }
  230. else
  231. Usage();
  232. }
  233. Initialize();
  234. if (fDirect)
  235. {
  236. out("\n---------- Direct ----------\n");
  237. dwTransacted = 0;
  238. dwRootDenyWrite = STGM_SHARE_EXCLUSIVE;
  239. flTests |= TFE_DIRECT;
  240. RunTests();
  241. flTests &= ~TFE_DIRECT;
  242. }
  243. if (fTrans)
  244. {
  245. out("\n---------- Transacted ----------\n");
  246. dwTransacted = STGM_TRANSACTED;
  247. dwRootDenyWrite = STGM_SHARE_DENY_WRITE;
  248. flTests |= TFE_TRANSACTED;
  249. RunTests();
  250. flTests &= ~TFE_TRANSACTED;
  251. }
  252. if (fIndep)
  253. {
  254. out("\n---------- Independent ----------\n");
  255. dwTransacted = STGM_TRANSACTED;
  256. dwRootDenyWrite = STGM_SHARE_DENY_NONE;
  257. flTests |= TFE_INDEPENDENT;
  258. RunTests();
  259. flTests &= ~TFE_INDEPENDENT;
  260. }
  261. printf("Docfile DRT - PASSED\n");
  262. Uninitialize();
  263. }