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.

222 lines
5.1 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_sbind.cxx
  7. //
  8. // Contents: Ole moniker binding test (BindToObject)
  9. //
  10. // Classes: CFileMonikerStorageBindTest
  11. //
  12. // History: 9-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_sbind.hxx>
  18. TCHAR *CFileMonikerStorageBindTest::Name ()
  19. {
  20. return TEXT("BindToStorage");
  21. }
  22. SCODE CFileMonikerStorageBindTest::Setup (CTestInput *pInput)
  23. {
  24. IClassFactory *pICF = NULL;
  25. IStorage *pStg = NULL;
  26. IPersistStorage *pIPS = NULL;
  27. SCODE sc;
  28. CTestBase::Setup(pInput);
  29. // get the iteration count from the ini file
  30. m_ulIterations = pInput->GetIterations(Name());
  31. // for each class ctx, get the classid, and init internal state
  32. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  33. {
  34. // Get ClsID for this Ctx from the .ini file
  35. sc = pInput->GetGUID(&m_ClsID[iCtx], Name(), apszClsIDName[iCtx]);
  36. if (FAILED(sc))
  37. {
  38. Log (TEXT("Setup - GetClassID failed."), sc);
  39. return sc;
  40. }
  41. INIT_RESULTS(m_ulCreateMkrTime[iCtx]);
  42. INIT_RESULTS(m_ulCreateBndCtxTime[iCtx]);
  43. INIT_RESULTS(m_ulBindTime[iCtx]);
  44. }
  45. sc = InitCOM();
  46. if (FAILED(sc))
  47. {
  48. Log (TEXT("Setup - CoInitialize failed."), sc);
  49. return sc;
  50. }
  51. // for each class ctx, create a persistent instance on disk
  52. for (iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  53. {
  54. // Create an instance
  55. sc = CoGetClassObject(m_ClsID[iCtx], dwaClsCtx[iCtx], NULL,
  56. IID_IClassFactory, (void **)&pICF);
  57. if (SUCCEEDED(sc))
  58. {
  59. sc = pICF->CreateInstance(NULL, IID_IPersistStorage,
  60. (void **)&pIPS);
  61. pICF->Release();
  62. if (SUCCEEDED(sc))
  63. {
  64. // create instance of the storage
  65. sc = StgCreateDocfile(apszPerstName[iCtx],
  66. STGM_READWRITE | STGM_CREATE |
  67. STGM_SHARE_EXCLUSIVE,
  68. 0, &pStg);
  69. if (SUCCEEDED(sc))
  70. {
  71. // save the class instance in the storage
  72. sc = pIPS->Save(pStg, FALSE);
  73. pStg->Release();
  74. if (FAILED(sc))
  75. {
  76. Log (TEXT("Setup - pIPS->Save failed."), sc);
  77. }
  78. }
  79. else
  80. {
  81. Log (TEXT("Setup - StgCreateDocfile failed."), sc);
  82. }
  83. pIPS->Release();
  84. }
  85. else
  86. {
  87. Log (TEXT("Setup - CreateInstance failed"), sc);
  88. }
  89. }
  90. else
  91. {
  92. Log (TEXT("Setup - CoGetClassObject failed"), sc);
  93. }
  94. }
  95. return S_OK;
  96. }
  97. SCODE CFileMonikerStorageBindTest::Cleanup ()
  98. {
  99. UninitCOM();
  100. CHAR szPerstName[80];
  101. // delete the persistent instances
  102. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  103. {
  104. // delete original
  105. wcstombs(szPerstName, apszPerstName[iCtx],
  106. wcslen(apszPerstName[iCtx])+1);
  107. _unlink(szPerstName);
  108. }
  109. return S_OK;
  110. }
  111. SCODE CFileMonikerStorageBindTest::Run ()
  112. {
  113. CStopWatch sw;
  114. IMoniker *pmk = NULL;
  115. IBindCtx *pbc = NULL;
  116. IStorage *pStg = NULL;
  117. SCODE sc;
  118. // for each class context
  119. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  120. {
  121. // for each iteration
  122. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  123. {
  124. sw.Reset();
  125. sc = CreateFileMoniker (apszPerstName[iCtx], &pmk);
  126. m_ulCreateMkrTime[iCtx][iIter] = sw.Read();
  127. if (!Log (TEXT("CreateFileMoniker"), sc))
  128. {
  129. BIND_OPTS bindopts;
  130. bindopts.cbStruct = sizeof(BIND_OPTS);
  131. sw.Reset();
  132. sc = CreateBindCtx(0, &pbc);
  133. if (SUCCEEDED(sc))
  134. {
  135. sc = pbc->GetBindOptions(&bindopts);
  136. bindopts.grfMode |= STGM_SHARE_EXCLUSIVE | STGM_DIRECT;
  137. sc = pbc->SetBindOptions(&bindopts);
  138. }
  139. m_ulCreateBndCtxTime[iCtx][iIter] = sw.Read();
  140. if (!Log (TEXT("CreateBindCtx"), sc))
  141. {
  142. sw.Reset();
  143. sc = pmk->BindToStorage(pbc, NULL, IID_IStorage, (void**)&pStg);
  144. m_ulBindTime[iCtx][iIter]=sw.Read();
  145. if (!Log (TEXT("BindToStorage"), sc))
  146. {
  147. sw.Reset();
  148. pStg->Release();
  149. m_ulReleaseTime[iCtx][iIter]=sw.Read();
  150. }
  151. else
  152. {
  153. m_ulBindTime[iCtx][iIter] = NOTAVAIL;
  154. }
  155. pbc->Release();
  156. }
  157. else
  158. {
  159. m_ulCreateBndCtxTime[iCtx][iIter] = NOTAVAIL;
  160. }
  161. pmk->Release();
  162. }
  163. else
  164. {
  165. m_ulCreateMkrTime[iCtx][iIter] = NOTAVAIL;
  166. }
  167. }
  168. }
  169. return S_OK;
  170. }
  171. SCODE CFileMonikerStorageBindTest::Report (CTestOutput &output)
  172. {
  173. output.WriteSectionHeader (Name(), TEXT("BindToStorage via FileMoniker"), *m_pInput);
  174. // for each clsctx, write the results
  175. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  176. {
  177. output.WriteString(TEXT("\n"));
  178. output.WriteClassID(&m_ClsID[iCtx]);
  179. output.WriteString(apszClsCtx[iCtx]);
  180. output.WriteString(TEXT("\n"));
  181. output.WriteResults(TEXT("CreateMoniker"), m_ulIterations, m_ulCreateMkrTime[iCtx]);
  182. output.WriteResults(TEXT("CreateBindCtx"), m_ulIterations, m_ulCreateBndCtxTime[iCtx]);
  183. output.WriteResults(TEXT("Bind "), m_ulIterations, m_ulBindTime[iCtx]);
  184. output.WriteResults(TEXT("Release "), m_ulIterations, m_ulReleaseTime[iCtx]);
  185. }
  186. return S_OK;
  187. }
  188.