Since the MFC TestRunner runs each test on a separate
thread, the COM components that I was trying to test
were failing because CoInitialize was not called for
the thread that separate thread.
My fix was simple. Just call CoInitialize and
CoUninitialize in ActiveTest::threadFunction:
// Simple execution thread. Assuming that an
ActiveTest instance
// only creates one of these at a time.
UINT ActiveTest::threadFunction (LPVOID thisInstance)
{
ActiveTest *test = (ActiveTest *)thisInstance;
bool comInit = SUCCEEDED( CoInitialize( NULL ) );
test->run ();
test->m_runCompleted.SetEvent ();
if ( comInit )
CoUninitialize();
return 0;
}
This works for me because my components are STA but a
more general solution is needed to handle testing in
other threading models. Perhaps by passing in some
parameters to the TestRunner constructor.
Logged In: YES
user_id=196852
I aware of that problem. This will be adressed in a future
release by providing a global 'setup decorator' when
running test.
In the meantime, you can either use a common base class for
all your test that require CoInitialize, or use the text
mode test runner.
Baptiste.
Logged In: YES
user_id=196852
It is now possible to provide TestListener to do some global
set up, but the MFC TestRunner still need to be reworked to
support this feature.