#34 failure loading COM objects in testcases

1.9.12
open
nobody
None
5
2004-05-13
2004-05-13
Anonymous
No

Not sure this is a bug or
I am trying to test class the creates a COM object. I
use MFCTestRunner for testing.

I found that at the first the COM object wouldn't load
because CoInitialize was corrupted by the testframe work.
I had CoInitialize in the main application prior to
calling RunTests.

CTestApp::InitInstance(...
...
CoInitialize(0);
RunTests();
CoUninitialize();
...

void CTestApp::RunTests(void)
{
CPPUNIT_NS::MfcUi::TestRunner runner;
runner.addTest(
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest()
);
runner.run();
}

In that case the class under test, failed to load the
COM object. Placing the CoInitialize in the setUp
function of my test class, allowed loaded the com object.

However, the QueryInterface on the object still fails.
It seems that the test framework is disrupting some the
com loading/handling capabilities of windows.

Any suggestions?

Paul

PS: The COM object works flawlessly outside the test
framework.

Discussion

  • Logged In: YES
    user_id=196852

    The class MsDevCallerListCtrl of the MFC TestRunner does a
    CoInitialize(), which is probably the source of your problem.

    I don't have enough COM experience to know how to detect if
    it has already been initialized.

    Do you know how to do this ?

    Baptiste.

     
  • Logged In: NO

    Check for S_FALSE as the return from the call to CoInitialize
    ().