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.

175 lines
3.8 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_regis.cxx
  7. //
  8. // Contents: Ole object registration test
  9. //
  10. // Classes: COleRegistrationTest
  11. //
  12. // History: 12-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_regis.hxx>
  18. #include <oletest.hxx>
  19. extern COleTestClassFactory theFactory;
  20. const CLSID *apClsid[] = {&CLSID_COleTestClass1,
  21. &CLSID_COleTestClass2,
  22. &CLSID_COleTestClass3,
  23. &CLSID_COleTestClass4,
  24. &CLSID_COleTestClass5,
  25. &CLSID_COleTestClass6,
  26. &CLSID_COleTestClass7,
  27. &CLSID_COleTestClass8};
  28. TCHAR *COleRegistrationTest::Name ()
  29. {
  30. return TEXT("ObjRegistration");
  31. }
  32. SCODE COleRegistrationTest::Setup (CTestInput *pInput)
  33. {
  34. HRESULT sc;
  35. CTestBase::Setup(pInput);
  36. // get the iteration count
  37. m_ulIterations = pInput->GetIterations(Name());
  38. // for the inproc case. load a class factory object to register.
  39. // this is temporary to fix a problem (ambiguity) in inproc
  40. // registration.
  41. sc = pInput->GetGUID(&m_Clsid[0], Name(), apszClsIDName[0]);
  42. if (FAILED(sc))
  43. {
  44. Log (TEXT("Setup - GetClassID failed."), sc);
  45. return sc;
  46. }
  47. sc = pInput->GetGUID(&m_Clsid[1], Name(), apszClsIDName[1]);
  48. if (FAILED(sc))
  49. {
  50. Log (TEXT("Setup - GetClassID failed."), sc);
  51. return sc;
  52. }
  53. sc = InitCOM();
  54. if (FAILED(sc))
  55. {
  56. Log (TEXT("Setup - CoInitialize failed."), sc);
  57. return sc;
  58. }
  59. // get the class factory
  60. sc = CoGetClassObject(m_Clsid[0], dwaClsCtx[0], NULL,
  61. IID_IClassFactory, (void **)&m_apICF[0]);
  62. if (FAILED(sc))
  63. {
  64. Log (TEXT("Setup - CoGetClassObject failed."), sc);
  65. return sc;
  66. }
  67. // for local server, register an internal class.
  68. m_apICF[1] = (IClassFactory *)&theFactory;
  69. // init internal state
  70. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  71. {
  72. INIT_RESULTS(m_ulRegisterCtx[iCtx]);
  73. INIT_RESULTS(m_ulRevokeCtx[iCtx]);
  74. }
  75. // _pInput = pInput;
  76. return S_OK;
  77. }
  78. SCODE COleRegistrationTest::Cleanup ()
  79. {
  80. m_apICF[0]->Release();
  81. UninitCOM();
  82. return S_OK;
  83. }
  84. SCODE COleRegistrationTest::Run ()
  85. {
  86. CStopWatch sw;
  87. DWORD dwReg;
  88. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  89. {
  90. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  91. {
  92. sw.Reset ();
  93. SCODE sc = CoRegisterClassObject(m_Clsid[iCtx],
  94. m_apICF[iCtx],
  95. dwaClsCtx[iCtx],
  96. REGCLS_MULTIPLEUSE, &dwReg);
  97. m_ulRegisterCtx[iCtx][iIter] = sw.Read ();
  98. Log (TEXT("CoRegisterClassObject"),sc);
  99. // NOTE: Revoke has different behaviour depending on
  100. // whether single use or multiuse is specified in the
  101. // registration.
  102. if (SUCCEEDED(sc))
  103. {
  104. // Revoke
  105. sw.Reset ();
  106. sc = CoRevokeClassObject(dwReg);
  107. m_ulRevokeCtx[iCtx][iIter] = sw.Read();
  108. if (Log (TEXT("CoRevokeClassObject"), sc))
  109. m_ulRevokeCtx[iCtx][iIter] = NOTAVAIL;
  110. }
  111. else
  112. {
  113. m_ulRegisterCtx[iCtx][iIter] = NOTAVAIL;
  114. }
  115. // _pInput->Pause(IP_ITERPAUSE);
  116. }
  117. }
  118. return S_OK;
  119. }
  120. SCODE COleRegistrationTest::Report (CTestOutput &output)
  121. {
  122. output.WriteSectionHeader (Name(),
  123. TEXT("CoRegisterClassObject / CoRevokeClassObject"), *m_pInput);
  124. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  125. {
  126. output.WriteString (TEXT("\n"));
  127. output.WriteClassID(&m_Clsid[iCtx]);
  128. output.WriteString (apszClsCtx[iCtx]);
  129. output.WriteString (TEXT("\n"));
  130. output.WriteResults (TEXT("Register"), m_ulIterations,
  131. m_ulRegisterCtx[iCtx]);
  132. output.WriteResults (TEXT("Revoke "), m_ulIterations,
  133. m_ulRevokeCtx[iCtx]);
  134. }
  135. return S_OK;
  136. }