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.

178 lines
4.4 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // File: tmain.cxx
  4. //
  5. // Contents: entry point common for all test drivers.
  6. //
  7. //--------------------------------------------------------------------
  8. #include <pch.cxx>
  9. #include <tstmain.hxx>
  10. #include <regmain.hxx>
  11. BOOL fQuiet = 0; // turn tracing on/off
  12. DWORD gInitFlag; // current COINT flag used on main thread.
  13. DWORD dwInitFlag[2] = {COINIT_APARTMENTTHREADED,
  14. COINIT_MULTITHREADED};
  15. LPSTR pszInitFlag[2] = {"ApartmentThreaded",
  16. "MultiThreaded"};
  17. // global statistics counters
  18. LONG gCountAttempts = 0; // # of tests attempted
  19. LONG gCountPassed = 0; // # of tests passed
  20. LONG gCountFailed = 0; // # of tests failed
  21. void InitStatistics();
  22. void PrintStatistics();
  23. //+-------------------------------------------------------------------
  24. //
  25. // Function: DriverMain
  26. //
  27. // Synopsis: Entry point to EXE
  28. //
  29. // Returns: TRUE
  30. //
  31. // History: 21-Nov-92 Rickhi Created
  32. //
  33. // Parses parameters, sets the threading model, initializes OLE,
  34. // runs the test, Uninitializes OLE, reports PASSED/FAILED.
  35. //
  36. //--------------------------------------------------------------------
  37. int _cdecl DriverMain(int argc, char **argv, char *pszTestName, LPFNTEST pfnTest)
  38. {
  39. char *pszAppName = *argv;
  40. // default to running both single-thread and multi-thread
  41. int iStart = 0;
  42. int iEnd = 2;
  43. // process the command line args
  44. if (argc > 1)
  45. {
  46. for (int i=argc; i>0; i--, argv++)
  47. {
  48. if (!_strnicmp(*argv, "-r", 2))
  49. {
  50. // register class information
  51. RegistrySetup(pszAppName);
  52. return 0;
  53. }
  54. else if (!_strnicmp(*argv, "-q", 2))
  55. {
  56. // quiet output
  57. fQuiet = TRUE;
  58. }
  59. else if (!_strnicmp(*argv, "-s", 2))
  60. {
  61. // just run single-threaded
  62. iStart = 0;
  63. iEnd = 1;
  64. }
  65. else if (!_strnicmp(*argv, "-m", 2))
  66. {
  67. // just run multi-threaded
  68. iStart = 1;
  69. iEnd = 2;
  70. }
  71. }
  72. }
  73. // run the tests.
  74. for (int i=iStart; i<iEnd; i++)
  75. {
  76. InitStatistics();
  77. WriteProfileStringA("OleSrv",
  78. "ThreadMode",
  79. pszInitFlag[i]);
  80. printf ("Starting %s Test with %s threading model\n",
  81. pszTestName, pszInitFlag[i]);
  82. gInitFlag = dwInitFlag[i];
  83. SCODE sc = CoInitializeEx(NULL, gInitFlag);
  84. if (sc != S_OK)
  85. {
  86. printf("CoInitializeEx Failed with %lx\n", sc);
  87. DebugBreak();
  88. return 1;
  89. }
  90. BOOL fRslt = (pfnTest)();
  91. PrintStatistics();
  92. if (fRslt)
  93. printf("%s Tests PASSED\n", pszTestName);
  94. else
  95. printf("%s Tests FAILED\n", pszTestName);
  96. CoUninitialize();
  97. }
  98. return 0;
  99. }
  100. //+-------------------------------------------------------------------
  101. //
  102. // Function: TestResult
  103. //
  104. // Synopsis: prints test results
  105. //
  106. // History: 21-Nov-92 Rickhi Created
  107. //
  108. //--------------------------------------------------------------------
  109. BOOL TestResult(BOOL RetVal, LPSTR pszTestName)
  110. {
  111. gCountAttempts++;
  112. if (RetVal == TRUE)
  113. {
  114. printf ("PASSED: %s\n", pszTestName);
  115. gCountPassed++;
  116. }
  117. else
  118. {
  119. printf ("FAILED: %s\n", pszTestName);
  120. gCountFailed++;
  121. }
  122. return RetVal;
  123. }
  124. //+-------------------------------------------------------------------
  125. //
  126. // Function: InitStatistics
  127. //
  128. // Synopsis: Initializes run statistics
  129. //
  130. // History: 21-Nov-92 Rickhi Created
  131. //
  132. //--------------------------------------------------------------------
  133. void InitStatistics()
  134. {
  135. gCountAttempts = 0;
  136. gCountPassed = 0;
  137. gCountFailed = 0;
  138. }
  139. //+-------------------------------------------------------------------
  140. //
  141. // Function: PrintStatistics
  142. //
  143. // Synopsis: Prints run statistics
  144. //
  145. // History: 21-Nov-92 Rickhi Created
  146. //
  147. //--------------------------------------------------------------------
  148. void PrintStatistics()
  149. {
  150. printf("\nTEST STATISTICS -- Attempted:%d Passed:%d Failed:%d\n\n",
  151. gCountAttempts, gCountPassed, gCountFailed);
  152. }
  153.