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.

305 lines
8.0 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. "ILockBytes", "ILockBytes usage",
  63. t_ilb, TFE_ANY,
  64. "StgMisc", "Miscellaneous Stg functions",
  65. t_stgmisc, TFE_ANY,
  66. "IllStg", "Illegitimate IStorage calls",
  67. i_storage, TFE_ANY | TFS_ILLEGITIMATE,
  68. "IllStm", "Illegitimate IStream calls",
  69. i_stream, TFE_ANY | TFS_ILLEGITIMATE,
  70. "IllEnum", "Illegitimate enumerator calls",
  71. i_enum, TFE_ANY | TFS_ILLEGITIMATE
  72. };
  73. #define NTESTS (sizeof(tests)/sizeof(tests[0]))
  74. DWORD dwTransacted = 0;
  75. DWORD dwRootDenyWrite = STGM_SHARE_DENY_WRITE;
  76. BOOL fVerbose = FALSE;
  77. BOOL fOfs = FALSE;
  78. OLECHAR atcDrtDocfile[_MAX_PATH];
  79. static BOOL fRun[NTESTS];
  80. #ifdef FLAT
  81. static FLAGS flTests = TF_NONE;
  82. #else
  83. static FLAGS flTests = TF_NONE | TFS_16BIT;
  84. #endif
  85. static void Initialize(void)
  86. {
  87. SCODE sc;
  88. SetData();
  89. #if WIN32 == 300
  90. if (FAILED(sc = DfGetScode(CoInitializeEx(NULL, COINIT_MULTITHREADED))))
  91. error(EXIT_UNKNOWN,
  92. "CoInitializeEx failed with sc = 0x%lX\n", sc);
  93. #else
  94. if (FAILED(sc = DfGetScode(CoInitialize(NULL))))
  95. error(EXIT_UNKNOWN,
  96. "CoInitialize failed with sc = 0x%lX\n", sc);
  97. #endif
  98. }
  99. static void Uninitialize(void)
  100. {
  101. UnsetData();
  102. CoUninitialize();
  103. }
  104. static int FindTest(char *pszName)
  105. {
  106. int i, cchName;
  107. cchName = strlen(pszName);
  108. for (i = 0; i<NTESTS; i++)
  109. if (!_strnicmp(pszName, tests[i].pszName, cchName))
  110. return i;
  111. return -1;
  112. }
  113. static void RunTests(void)
  114. {
  115. int i;
  116. for (i = 0; i<NTESTS; i++)
  117. // For a test to run:
  118. // 1) fRun[test] must be TRUE
  119. // 2) No suppression flags can be set that are not set in flTests
  120. // 3) At least one enabling flag must be set that is set in flTests
  121. if (fRun[i] &&
  122. (tests[i].flags & ~flTests & TF_SUPPRESS) == 0 &&
  123. (tests[i].flags & flTests & TF_ENABLE) != 0)
  124. {
  125. out("\n----- Test #%2d - %s -----\n", i+1, tests[i].pszDesc);
  126. tests[i].tfn();
  127. CheckMemory();
  128. CleanData();
  129. }
  130. }
  131. static void Usage(void)
  132. {
  133. int i;
  134. printf("Usage: drt [options]\n");
  135. printf("Options are:\n");
  136. printf(" -h - This message\n");
  137. printf(" -d - Suppress direct tests\n");
  138. printf(" -t - Suppress transacted tests\n");
  139. printf(" -w - Suppress independent tests\n");
  140. printf(" -i - Enable illegitimate tests\n");
  141. printf(" -v - Display test output\n");
  142. #if WIN32 == 300
  143. printf(" -o - Enable tests to run on OFS\n");
  144. #endif
  145. printf(" -y<kind> - Control debug output (a, d, m, i, M, L)\n");
  146. printf(" -#[+|-]<number> - Turn test <number> on (+) or off (-)\n");
  147. printf(" No number means all\n");
  148. printf(" -n[+|-]<prefix> - Turn test <prefix> on or off\n");
  149. printf(" -N<file> - Set file to use for tests\n");
  150. printf("Prefix can be any prefix of:\n");
  151. for (i = 0; i<NTESTS; i++)
  152. printf(" %s\n", tests[i].pszName);
  153. exit(1);
  154. }
  155. int __cdecl main(int argc, char **argv)
  156. {
  157. int i, iTest;
  158. BOOL fDirect = TRUE, fTrans = TRUE, fIndep = TRUE;
  159. SetDebug(0x101, 0x101);
  160. for (i = 0; i<NTESTS; i++)
  161. fRun[i] = TRUE;
  162. ATOOLE("drt.dfl", atcDrtDocfile, _MAX_PATH);
  163. while (--argc>0)
  164. {
  165. if (**++argv == '-')
  166. {
  167. switch(argv[0][1])
  168. {
  169. case '#':
  170. if (sscanf(argv[0]+3, "%d", &iTest) != 1)
  171. iTest = -1;
  172. else
  173. iTest--;
  174. for (i = 0; i<NTESTS; i++)
  175. if (iTest == -1 || iTest == i)
  176. fRun[i] = argv[0][2] == '+';
  177. break;
  178. case 'd':
  179. fDirect = FALSE;
  180. break;
  181. case 'i':
  182. flTests |= TFS_ILLEGITIMATE;
  183. break;
  184. case 'n':
  185. iTest = FindTest(argv[0]+3);
  186. if (iTest >= 0)
  187. fRun[iTest] = argv[0][2] == '+';
  188. break;
  189. case 'N':
  190. ATOOLE(argv[0]+2, atcDrtDocfile, _MAX_PATH);
  191. break;
  192. case 't':
  193. fTrans = FALSE;
  194. break;
  195. case 'v':
  196. fVerbose = TRUE;
  197. break;
  198. case 'w':
  199. fIndep = FALSE;
  200. break;
  201. case 'y':
  202. switch(argv[0][2])
  203. {
  204. case 'a':
  205. SetDebug(0xffffffff, 0xffffffff);
  206. break;
  207. case 'd':
  208. SetDebug(0xffffffff, 0x101);
  209. break;
  210. case 'm':
  211. SetDebug(0x101, 0xffffffff);
  212. break;
  213. case 'i':
  214. SetDebug(0x101, 0x101);
  215. break;
  216. case 'M':
  217. SetDebug(0x01100000, 0);
  218. break;
  219. case 'L':
  220. SetDebug(0x00100000, 0);
  221. break;
  222. }
  223. break;
  224. #if WIN32 == 300
  225. case 'o':
  226. fOfs = TRUE;
  227. break;
  228. #endif
  229. case 'h':
  230. default:
  231. Usage();
  232. }
  233. }
  234. else
  235. Usage();
  236. }
  237. Initialize();
  238. if (fDirect)
  239. {
  240. out("\n---------- Direct ----------\n");
  241. dwTransacted = 0;
  242. dwRootDenyWrite = STGM_SHARE_EXCLUSIVE;
  243. flTests |= TFE_DIRECT;
  244. RunTests();
  245. flTests &= ~TFE_DIRECT;
  246. }
  247. #if WIN32 == 300
  248. if (fTrans && !fOfs) // turn off transacted tests for OFS
  249. #else
  250. if (fTrans)
  251. #endif
  252. {
  253. out("\n---------- Transacted ----------\n");
  254. dwTransacted = STGM_TRANSACTED;
  255. dwRootDenyWrite = STGM_SHARE_DENY_WRITE;
  256. flTests |= TFE_TRANSACTED;
  257. RunTests();
  258. flTests &= ~TFE_TRANSACTED;
  259. }
  260. #if WIN32 == 300
  261. if (fIndep && !fOfs) // turn off transacted tests for OFS
  262. #else
  263. if (fIndep)
  264. #endif
  265. {
  266. out("\n---------- Independent ----------\n");
  267. dwTransacted = STGM_TRANSACTED;
  268. dwRootDenyWrite = STGM_SHARE_DENY_NONE;
  269. flTests |= TFE_INDEPENDENT;
  270. RunTests();
  271. flTests &= ~TFE_INDEPENDENT;
  272. }
  273. printf("Storage DRT - PASSED\n");
  274. Uninitialize();
  275. return(0);
  276. }