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.

221 lines
4.9 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_piact.cxx
  7. //
  8. // Contents: Persistant instance activation test
  9. //
  10. // Classes: COlePersistActivationTest
  11. //
  12. // History: 29-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_piact.hxx>
  18. WCHAR *COlePersistActivationTest::Name ()
  19. {
  20. return L"PersistActivation";
  21. }
  22. SCODE COlePersistActivationTest::Setup (CTestInput *pInput)
  23. {
  24. IPersistFile *pIPF = NULL;
  25. IClassFactory *pICF = NULL;
  26. SCODE sc = S_OK, scRet = S_OK;
  27. CTestBase::Setup (pInput);
  28. // Get number of iterations
  29. m_ulIterations = pInput->GetIterations(Name());
  30. // for each class ctx, get the classid, and init internal state
  31. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  32. {
  33. // Get ClsID for this Ctx from the .ini file
  34. sc = pInput->GetGUID(&m_ClsID[iCtx], Name(), apwszClsIDName[iCtx]);
  35. if (FAILED(sc))
  36. {
  37. Log (L"Setup - GetGUID failed", sc);
  38. return sc;
  39. }
  40. INIT_RESULTS (m_ulNewTime[iCtx]);
  41. INIT_RESULTS (m_ulGetTime[iCtx]);
  42. }
  43. sc = InitCOM();
  44. if (FAILED(sc))
  45. {
  46. Log (TEXT("Setup - CoInitialize failed."), sc);
  47. return sc;
  48. }
  49. // for each class ctx, create a persistent instance on disk
  50. for (iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  51. {
  52. // Create an instance
  53. sc = CoGetClassObject(m_ClsID[iCtx], dwaClsCtx[iCtx], NULL,
  54. IID_IClassFactory, (void **)&pICF);
  55. if (SUCCEEDED(sc))
  56. {
  57. sc = pICF->CreateInstance(NULL, IID_IPersistFile, (void **)&pIPF);
  58. pICF->Release();
  59. if (SUCCEEDED(sc))
  60. {
  61. // save the instance in a file
  62. sc = pIPF->Save (apwszPerstName[iCtx], TRUE);
  63. pIPF->Release();
  64. if (FAILED(sc))
  65. {
  66. Log (L"Setup - IPersistFile::Save failed", sc);
  67. scRet = sc;
  68. }
  69. }
  70. else
  71. {
  72. Log (L"Setup - CreateInstance failed", sc);
  73. scRet = sc;
  74. }
  75. }
  76. else
  77. {
  78. Log (L"Setup - CoGetClassObject failed", sc);
  79. scRet = sc;
  80. }
  81. }
  82. // _pInput = pInput;
  83. return scRet;
  84. }
  85. SCODE COlePersistActivationTest::Cleanup ()
  86. {
  87. UninitCOM();
  88. CHAR szPerstName[80];
  89. // delete the persistent instances
  90. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  91. {
  92. // delete original
  93. wcstombs(szPerstName, apwszPerstName[iCtx],
  94. wcslen(apwszPerstName[iCtx])+1);
  95. _unlink (szPerstName);
  96. // delete new instance
  97. wcstombs(szPerstName, apwszPerstNameNew[iCtx],
  98. wcslen(apwszPerstNameNew[iCtx])+1);
  99. _unlink (szPerstName);
  100. }
  101. return S_OK;
  102. }
  103. SCODE COlePersistActivationTest::Run ()
  104. {
  105. CStopWatch sw;
  106. IUnknown *punk = NULL;
  107. SCODE sc;
  108. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  109. {
  110. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  111. {
  112. sw.Reset();
  113. sc = CoGetPersistentInstance(IID_IUnknown,
  114. dwaClsCtx[iCtx],
  115. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  116. apwszPerstName[iCtx],
  117. NULL,
  118. CLSID_NULL,
  119. NULL,
  120. (void**)&punk);
  121. m_ulGetTime[iCtx][iIter] = sw.Read();
  122. Log (L"CoGetPersistentInstance", sc);
  123. if (SUCCEEDED(sc))
  124. {
  125. sw.Reset();
  126. punk->Release();
  127. m_ulGetReleaseTime[iCtx][iIter] = sw.Read();
  128. }
  129. else
  130. {
  131. m_ulGetTime[iCtx][iIter] = NOTAVAIL;
  132. }
  133. // _pInput->Pause(IP_ITERPAUSE);
  134. sw.Reset();
  135. sc = CoNewPersistentInstance(m_ClsID[iCtx],
  136. IID_IUnknown,
  137. dwaClsCtx[iCtx],
  138. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  139. apwszPerstName[iCtx],
  140. NULL,
  141. apwszPerstNameNew[iCtx],
  142. (void**)&punk);
  143. m_ulNewTime[iCtx][iIter] = sw.Read();
  144. Log (L"CoNewPersistentInstance", sc);
  145. if (SUCCEEDED(sc))
  146. {
  147. sw.Reset();
  148. punk->Release();
  149. m_ulNewReleaseTime[iCtx][iIter] = sw.Read();
  150. }
  151. else
  152. {
  153. m_ulNewTime[iCtx][iIter] = NOTAVAIL;
  154. }
  155. CHAR szPerstName[80];
  156. wcstombs(szPerstName, apwszPerstNameNew[iCtx],
  157. wcslen(apwszPerstNameNew[iCtx])+1);
  158. _unlink(szPerstName);
  159. // _pInput->Pause(IP_ITERPAUSE);
  160. }
  161. }
  162. return S_OK;
  163. }
  164. SCODE COlePersistActivationTest::Report (CTestOutput &output)
  165. {
  166. output.WriteSectionHeader (Name(),
  167. L"CoGetPersistentInstance / CoNewPersistentInstance",
  168. *m_pInput);
  169. // for each clsctx, write the results
  170. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  171. {
  172. output.WriteString(L"\n");
  173. output.WriteClassID (&m_ClsID[iCtx]);
  174. output.WriteString (apwszClsCtx[iCtx]);
  175. output.WriteString(L"\n");
  176. output.WriteResults (L"CoGetPI", m_ulIterations, m_ulGetTime[iCtx]);
  177. output.WriteResults (L"Release", m_ulIterations, m_ulGetReleaseTime[iCtx]);
  178. output.WriteResults (L"CoNewPI", m_ulIterations, m_ulNewTime[iCtx]);
  179. output.WriteResults (L"Release", m_ulIterations, m_ulNewReleaseTime[iCtx]);
  180. }
  181. return S_OK;
  182. }
  183.