Saturday, February 06, 2010

Using GoogleTest to Test a COM DLL

The following is a simple GoogleTest of a COM interface.  Used an example GoogleTest project, removed the example test, and added my simple test.  I abbreviate some of the names and changed some syntax to get a couple of includes to show. Each test is performed in order.

#include "iostream"

#include "gtest/gtest.h"


#import "..\..\interfaces\tlb\FAOServer.tlb" no_namespace, named_guids

int main(int argc, char **argv) {
  std::cout << "Running main() from TestFAOServer.cpp\n";

  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

#include "test/production.h"

TEST(FAOServerTest, InitializeCOMSubSystem)
{
    HRESULT hr = CoInitialize(NULL);
    ASSERT_EQ(hr,S_OK);
}

TEST(FAOServerTest, CreateInstance)
{
    IAO* pAPOL = NULL;
    bool pointerNull = false;

    ASSERT_EQ((pAPOL == NULL), true);

    HRESULT hr = CoCreateInstance
    (
        CLSID_AO,
        NULL,
        CLSCTX_ALL,
        IID_IAO,
        (void**)&pAPOL
    );

    ASSERT_EQ(hr, S_OK);

    if (hr == S_OK)
    {
        hr = pAPOL->OnDTC();

        ASSERT_EQ(hr, S_OK);
    }
}

TEST(FAOSTest, TerminateCOMSubSystem)
{
    CoUninitialize();
    ASSERT_EQ(0,0);
}

No comments: