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.

197 lines
4.5 KiB

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