//+------------------------------------------------------------------------ // // Microsoft Windows // Copyright (C) Microsoft Corporation, 1993. // // File: bm_piact.cxx // // Contents: Persistant instance activation test // // Classes: COlePersistActivationTest // // History: 29-July-93 t-martig Created // //-------------------------------------------------------------------------- #include #pragma hdrstop #include WCHAR *COlePersistActivationTest::Name () { return L"PersistActivation"; } SCODE COlePersistActivationTest::Setup (CTestInput *pInput) { IPersistFile *pIPF = NULL; IClassFactory *pICF = NULL; SCODE sc = S_OK, scRet = S_OK; CTestBase::Setup (pInput); // Get number of iterations m_ulIterations = pInput->GetIterations(Name()); // for each class ctx, get the classid, and init internal state for (ULONG iCtx=0; iCtxGetGUID(&m_ClsID[iCtx], Name(), apwszClsIDName[iCtx]); if (FAILED(sc)) { Log (L"Setup - GetGUID failed", sc); return sc; } INIT_RESULTS (m_ulNewTime[iCtx]); INIT_RESULTS (m_ulGetTime[iCtx]); } sc = InitCOM(); if (FAILED(sc)) { Log (TEXT("Setup - CoInitialize failed."), sc); return sc; } // for each class ctx, create a persistent instance on disk for (iCtx=0; iCtxCreateInstance(NULL, IID_IPersistFile, (void **)&pIPF); pICF->Release(); if (SUCCEEDED(sc)) { // save the instance in a file sc = pIPF->Save (apwszPerstName[iCtx], TRUE); pIPF->Release(); if (FAILED(sc)) { Log (L"Setup - IPersistFile::Save failed", sc); scRet = sc; } } else { Log (L"Setup - CreateInstance failed", sc); scRet = sc; } } else { Log (L"Setup - CoGetClassObject failed", sc); scRet = sc; } } // _pInput = pInput; return scRet; } SCODE COlePersistActivationTest::Cleanup () { UninitCOM(); CHAR szPerstName[80]; // delete the persistent instances for (ULONG iCtx=0; iCtxRelease(); m_ulGetReleaseTime[iCtx][iIter] = sw.Read(); } else { m_ulGetTime[iCtx][iIter] = NOTAVAIL; } // _pInput->Pause(IP_ITERPAUSE); sw.Reset(); sc = CoNewPersistentInstance(m_ClsID[iCtx], IID_IUnknown, dwaClsCtx[iCtx], STGM_READWRITE | STGM_SHARE_EXCLUSIVE, apwszPerstName[iCtx], NULL, apwszPerstNameNew[iCtx], (void**)&punk); m_ulNewTime[iCtx][iIter] = sw.Read(); Log (L"CoNewPersistentInstance", sc); if (SUCCEEDED(sc)) { sw.Reset(); punk->Release(); m_ulNewReleaseTime[iCtx][iIter] = sw.Read(); } else { m_ulNewTime[iCtx][iIter] = NOTAVAIL; } CHAR szPerstName[80]; wcstombs(szPerstName, apwszPerstNameNew[iCtx], wcslen(apwszPerstNameNew[iCtx])+1); _unlink(szPerstName); // _pInput->Pause(IP_ITERPAUSE); } } return S_OK; } SCODE COlePersistActivationTest::Report (CTestOutput &output) { output.WriteSectionHeader (Name(), L"CoGetPersistentInstance / CoNewPersistentInstance", *m_pInput); // for each clsctx, write the results for (ULONG iCtx=0; iCtx