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.

217 lines
5.4 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: drt.cxx
  7. //
  8. // Contents: DRT main routine
  9. //
  10. //---------------------------------------------------------------
  11. #include "headers.cxx"
  12. #include "../../h/dbg.hxx"
  13. #include "tests.hxx"
  14. #include "illeg.hxx"
  15. // Test flags and type
  16. typedef ULONG FLAGS;
  17. #define TF_NONE 0x00000000
  18. // Suppression flags
  19. #define TF_SUPPRESS 0x0000FFFF
  20. #define TFS_ILLEGITIMATE 0x00000001
  21. #define TFS_16BIT 0x00000002
  22. // Enabling flags
  23. #define TF_ENABLE 0xFFFF0000
  24. #define TFE_DIRECT 0x00010000
  25. #define TFE_ANY (TFE_DIRECT)
  26. // Pointer to a test function
  27. typedef void (*TestFn)(void);
  28. static struct
  29. {
  30. char *pszName;
  31. char *pszDesc;
  32. TestFn tfn;
  33. FLAGS flags;
  34. } tests[] =
  35. {
  36. "Create", "Creation",
  37. t_create, TFE_ANY,
  38. "Open", "Opening",
  39. t_open, TFE_ANY,
  40. "AddRef", "AddRef/Release",
  41. t_addref, TFE_ANY,
  42. "DModify", "Direct modifications",
  43. t_dmodify, TFE_DIRECT,
  44. "Stat", "Stat",
  45. t_stat, TFE_ANY,
  46. "Stream", "Stream operations",
  47. t_stream, TFE_ANY,
  48. "Enum", "Enumerator operations",
  49. t_enum, TFE_ANY,
  50. "StgCopyTo", "IStorage::CopyTo",
  51. t_stgcopyto, TFE_ANY,
  52. "MoveCopy", "IStorage::MoveElementTo",
  53. t_movecopy, TFE_ANY,
  54. "ILockBytes", "ILockBytes usage",
  55. t_ilb, TFE_ANY,
  56. "StgMisc", "Miscellaneous Stg functions",
  57. t_stgmisc, TFE_ANY,
  58. "IllStg", "Illegitimate IStorage calls",
  59. i_storage, TFE_ANY | TFS_ILLEGITIMATE,
  60. "IllStm", "Illegitimate IStream calls",
  61. i_stream, TFE_ANY | TFS_ILLEGITIMATE,
  62. "IllEnum", "Illegitimate enumerator calls",
  63. i_enum, TFE_ANY | TFS_ILLEGITIMATE
  64. };
  65. #define NTESTS (sizeof(tests)/sizeof(tests[0]))
  66. DWORD dwRootDenyWrite = STGM_SHARE_DENY_WRITE;
  67. BOOL fVerbose = FALSE;
  68. OLECHAR atcDrtDocfile[_MAX_PATH];
  69. static BOOL fRun[NTESTS];
  70. #ifdef FLAT
  71. static FLAGS flTests = TF_NONE;
  72. #else
  73. static FLAGS flTests = TF_NONE | TFS_16BIT;
  74. #endif
  75. static void Initialize(void)
  76. {
  77. SetData();
  78. }
  79. static void Uninitialize(void)
  80. {
  81. UnsetData();
  82. }
  83. static int FindTest(char *pszName)
  84. {
  85. int i, cchName;
  86. cchName = strlen(pszName);
  87. for (i = 0; i<NTESTS; i++)
  88. if (!_strnicmp(pszName, tests[i].pszName, cchName))
  89. return i;
  90. return -1;
  91. }
  92. static void RunTests(void)
  93. {
  94. int i;
  95. for (i = 0; i<NTESTS; i++)
  96. // For a test to run:
  97. // 1) fRun[test] must be TRUE
  98. // 2) No suppression flags can be set that are not set in flTests
  99. // 3) At least one enabling flag must be set that is set in flTests
  100. if (fRun[i] &&
  101. (tests[i].flags & ~flTests & TF_SUPPRESS) == 0 &&
  102. (tests[i].flags & flTests & TF_ENABLE) != 0)
  103. {
  104. out("\n----- Test #%2d - %s -----\n", i+1, tests[i].pszDesc);
  105. tests[i].tfn();
  106. CleanData();
  107. }
  108. }
  109. static void Usage(void)
  110. {
  111. int i;
  112. printf("Usage: drt [options]\n");
  113. printf("Options are:\n");
  114. printf(" -h - This message\n");
  115. printf(" -d - Suppress direct tests\n");
  116. printf(" -i - Enable illegitimate tests\n");
  117. printf(" -v - Display test output\n");
  118. printf(" -#[+|-]<number> - Turn test <number> on (+) or off (-)\n");
  119. printf(" No number means all\n");
  120. printf(" -n[+|-]<prefix> - Turn test <prefix> on or off\n");
  121. printf(" -N<file> - Set file to use for tests\n");
  122. printf("Prefix can be any prefix of:\n");
  123. printf("HR=%lx\n", E_INVALIDARG);
  124. for (i = 0; i<NTESTS; i++)
  125. printf(" %s\n", tests[i].pszName);
  126. exit(1);
  127. }
  128. int __cdecl main(int argc, char **argv)
  129. {
  130. int i, iTest;
  131. BOOL fDirect = TRUE;
  132. // change the following line to set mem check breakpoints
  133. // on win32, using debug CRT.
  134. //_CrtSetBreakAlloc();
  135. for (i = 0; i<NTESTS; i++)
  136. fRun[i] = TRUE;
  137. ATOOLE(pszDRTDF, atcDrtDocfile, _MAX_PATH);
  138. while (--argc>0)
  139. {
  140. if (**++argv == '-')
  141. {
  142. switch(argv[0][1])
  143. {
  144. case '#':
  145. if (sscanf(argv[0]+3, "%d", &iTest) != 1)
  146. iTest = -1;
  147. else
  148. iTest--;
  149. for (i = 0; i<NTESTS; i++)
  150. if (iTest == -1 || iTest == i)
  151. fRun[i] = argv[0][2] == '+';
  152. break;
  153. case 'd':
  154. fDirect = FALSE;
  155. break;
  156. case 'i':
  157. flTests |= TFS_ILLEGITIMATE;
  158. break;
  159. case 'n':
  160. iTest = FindTest(argv[0]+3);
  161. if (iTest >= 0)
  162. fRun[iTest] = argv[0][2] == '+';
  163. break;
  164. case 'N':
  165. ATOOLE(argv[0]+2, atcDrtDocfile, _MAX_PATH);
  166. break;
  167. case 'v':
  168. fVerbose = TRUE;
  169. break;
  170. case 'h':
  171. default:
  172. Usage();
  173. }
  174. }
  175. else
  176. Usage();
  177. }
  178. Initialize();
  179. if (fDirect)
  180. {
  181. out("\n---------- Direct ----------\n");
  182. dwRootDenyWrite = STGM_SHARE_EXCLUSIVE;
  183. flTests |= TFE_DIRECT;
  184. RunTests();
  185. flTests &= ~TFE_DIRECT;
  186. }
  187. printf("Storage DRT - PASSED\n");
  188. Uninitialize();
  189. return(0);
  190. }