Search code examples
c++googletestgooglemock

Not able to Mock CDatabase Open function using google Mock


I am trying to mock an Open function present as part of the CDatabase Class by using Google Mock. Visual studio version: 2010 Below is the code snippet:

class TestRLanguage: public RLanguage, public ::testing::Test
{
};

class FakeDatabase : public CDatabase
{
public:
    MOCK_METHOD5(Open_impl, BOOL(LPCTSTR lpszDSN, BOOL bExclusive,BOOL bReadonly, LPCTSTR lpszConnect,BOOL bUseCursorLib));

    BOOL Open(LPCTSTR lpszDSN, BOOL bExclusive = FALSE,
        BOOL bReadonly = FALSE, LPCTSTR lpszConnect = _T("ODBC;"),
        BOOL bUseCursorLib = TRUE) override
    {
        Open_impl( lpszDSN, bExclusive, bReadonly, lpszConnect, bUseCursorLib);
    }
};

// Test case for testing initialize function
TEST_F(TestRLanguage, initializeSuccess)
{
    FakeDatabase database;
    EXPECT_CALL(database, Open(NULL, FALSE, FALSE, "ODBC;DSN=", FALSE)).Times(testing::Exactly(1));
}

I get the below error:

error C2770: invalid explicit template argument(s) for 'AddReference<const ::std::tr1::tuple_element<I,std::tr1::tuple<_Arg0,_Arg1,_Arg2,_Arg3,_Arg4>>::type>::type testing::internal::TuplePolicy<TupleT>::get(const std::tr1::tuple<_Arg0,_Arg1,_Arg2,_Arg3,_Arg4> &)'    c:\src\googlemockandtest\aqtsw\util\googletest\googletest-release-1.8.1\googletest\include\gtest\gtest-printers.h

Can anyone help me in solving this problem?


Solution

  • I had the same issue. In my case it was related to the version of Google Test. I had the issue with version 1.8.1 -- "the last release supporting pre-C++11 compilers" (as stated here). The issue was fixed with pull request #1817. I am using HEAD of branch 1.8.x now (commit dea0216) and the issue is gone.