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.

198 lines
4.7 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_qi.cxx
  7. //
  8. // Contents: Ole QueryInterface test
  9. //
  10. // Classes: CQueryInterfaceTest
  11. //
  12. // History: 1-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_qi.hxx>
  18. // this is just an array of random interface iids. The qi server object
  19. // answers YES to any QI, although the only valid methods on each interface
  20. // are the methods of IUnknown.
  21. //
  22. // the code will answer NO to the following IIDs in order to prevent
  23. // custom marshalling problems...
  24. //
  25. // IID_IMarshal, IID_IStdMarshalInfo, IID_IStdIdentity,
  26. // IID_IPersist, IID_IProxyManager
  27. const IID *iid[] = {&IID_IAdviseSink, &IID_IDataObject,
  28. &IID_IOleObject, &IID_IOleClientSite,
  29. &IID_IParseDisplayName, &IID_IPersistStorage,
  30. &IID_IPersistFile, &IID_IStorage,
  31. &IID_IOleContainer, &IID_IOleItemContainer,
  32. &IID_IOleInPlaceSite, &IID_IOleInPlaceActiveObject,
  33. &IID_IOleInPlaceObject, &IID_IOleInPlaceUIWindow,
  34. &IID_IOleInPlaceFrame, &IID_IOleWindow};
  35. TCHAR *CQueryInterfaceTest::Name ()
  36. {
  37. return TEXT("QueryInterface");
  38. }
  39. SCODE CQueryInterfaceTest::Setup (CTestInput *pInput)
  40. {
  41. SCODE sc;
  42. CTestBase::Setup(pInput);
  43. // get iteration count
  44. m_ulIterations = pInput->GetIterations(Name());
  45. // initialize state
  46. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  47. {
  48. sc = pInput->GetGUID(&m_ClsID[iCtx], Name(), apszClsIDName[iCtx]);
  49. if (FAILED(sc))
  50. {
  51. Log (TEXT("Setup - GetClassID failed."), sc);
  52. return sc;
  53. }
  54. INIT_RESULTS(m_ulQueryInterfaceSameTime[iCtx]);
  55. INIT_RESULTS(m_ulPunkReleaseSameTime[iCtx]);
  56. INIT_RESULTS(m_ulQueryInterfaceNewTime[iCtx]);
  57. INIT_RESULTS(m_ulPunkReleaseNewTime[iCtx]);
  58. _pUnk[iCtx] = NULL;
  59. }
  60. sc = InitCOM();
  61. if (FAILED(sc))
  62. {
  63. Log (TEXT("Setup - CoInitialize failed."), sc);
  64. return sc;
  65. }
  66. // create an instance of each qi server object
  67. for (iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  68. {
  69. sc = CoCreateInstance(m_ClsID[iCtx], NULL, dwaClsCtx[iCtx],
  70. IID_IUnknown, (void **)&_pUnk[iCtx]);
  71. if (FAILED(sc))
  72. {
  73. Log (TEXT("Setup - CoCreateInstance failed"), sc);
  74. }
  75. }
  76. return S_OK;
  77. }
  78. SCODE CQueryInterfaceTest::Cleanup ()
  79. {
  80. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  81. {
  82. if (_pUnk[iCtx])
  83. {
  84. _pUnk[iCtx]->Release();
  85. }
  86. }
  87. UninitCOM();
  88. return S_OK;
  89. }
  90. SCODE CQueryInterfaceTest::Run ()
  91. {
  92. CStopWatch sw;
  93. IUnknown *pUnk = NULL;
  94. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  95. {
  96. if (!_pUnk[iCtx])
  97. continue;
  98. // same interface each time, releasing after each query
  99. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  100. {
  101. sw.Reset ();
  102. SCODE sc = _pUnk[iCtx]->QueryInterface(IID_IStorage, (void **)&pUnk);
  103. m_ulQueryInterfaceSameTime[iCtx][iIter] = sw.Read ();
  104. Log (TEXT("QueryInterface"), sc);
  105. if (SUCCEEDED(sc))
  106. {
  107. sw.Reset();
  108. pUnk->Release ();
  109. m_ulPunkReleaseSameTime[iCtx][iIter] = sw.Read();
  110. }
  111. else
  112. {
  113. m_ulPunkReleaseSameTime[iCtx][iIter] = NOTAVAIL;
  114. }
  115. }
  116. // different interface each time, releasing after each query
  117. for (iIter=0; iIter<m_ulIterations; iIter++)
  118. {
  119. sw.Reset ();
  120. SCODE sc = _pUnk[iCtx]->QueryInterface(*(iid[iIter]), (void **)&pUnk);
  121. m_ulQueryInterfaceNewTime[iCtx][iIter] = sw.Read ();
  122. Log (TEXT("QueryInterface"), sc);
  123. if (SUCCEEDED(sc))
  124. {
  125. sw.Reset();
  126. pUnk->Release ();
  127. m_ulPunkReleaseNewTime[iCtx][iIter] = sw.Read();
  128. }
  129. else
  130. {
  131. m_ulPunkReleaseNewTime[iCtx][iIter] = NOTAVAIL;
  132. }
  133. }
  134. }
  135. return S_OK;
  136. }
  137. SCODE CQueryInterfaceTest::Report (CTestOutput &output)
  138. {
  139. output.WriteSectionHeader (Name(), TEXT("QueryInterface"), *m_pInput);
  140. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  141. {
  142. output.WriteString(TEXT("\n"));
  143. output.WriteClassID (&m_ClsID[iCtx]);
  144. output.WriteString(apszClsCtx[iCtx]);
  145. output.WriteString(TEXT("\n"));
  146. output.WriteResults (TEXT("QuerySameInterface"), m_ulIterations,
  147. m_ulQueryInterfaceSameTime[iCtx]);
  148. output.WriteResults (TEXT("Release "), m_ulIterations,
  149. m_ulPunkReleaseSameTime[iCtx]);
  150. output.WriteResults (TEXT("QueryNewInterface "), m_ulIterations,
  151. m_ulQueryInterfaceNewTime[iCtx]);
  152. output.WriteResults (TEXT("Release "), m_ulIterations,
  153. m_ulPunkReleaseNewTime[iCtx]);
  154. }
  155. return S_OK;
  156. }