I am trying to mock Cdatabase method "Open". bellow are the files where I do mock class configurations.
afxdb.h
...
virtual BOOL Open(LPCTSTR lpszDSN, BOOL bExclusive = FALSE,
BOOL bReadonly = FALSE, LPCTSTR lpszConnect = _T("ODBC;"),
BOOL bUseCursorLib = TRUE);
...
mock_myCDatabase.h
...<linkers>
class mock_my_CDatabase :public CDatabase
{
public:
mock_my_CDatabase()
{}
~mock_my_CDatabase()
{}
**MOCK_METHOD5(Open, BOOL(LPCTSTR lpszDSN, BOOL bExclusive,BOOL bReadonly, LPCTSTR lpszConnect,BOOL bUseCursorLib));**
};
DemoClassB.cpp
...<linkers>
...
CDemoClassB::CDemoClassB(CDatabase &p_db)
{
m_db = &p_db;
}
...
...
**BOOL CDemoClassB::fun2()
{
m_db->Open((LPCTSTR)NULL, FALSE, FALSE, (LPCTSTR)"ODBC;DRIVER={MICROSOFT ACCESS DRIVER (*.mdb, *.accdb)};DSN='';DBQ=C:\\Karthik\\GMockDemo\\GMockDemo\\RepolyticsDB.accdb", CDatabase::noOdbcDialog);
return TRUE;
}**
GMockDemo.cpp
// GMockDemo.cpp : Defines the entry point for the console application.
//
...<linkers>
using namespace testing;
using ::testing::Return;
**TEST(mock, mockCDatabase)
{
mock_my_CDatabase mockDb;
EXPECT_CALL(mockDb, OpenEx((LPCTSTR)"ODBC;DRIVER={MICROSOFT ACCESS DRIVER (*.mdb, *.accdb)};DSN='';DBQ=C:\\Karthik\\GMockDemo\\GMockDemo\\RepolyticsDB.accdb", CDatabase::noOdbcDialog)).Times(8).WillRepeatedly(Return(TRUE));
CDemoClassB m_Bt(mockDb);
ASSERT_EQ(m_Bt.fun2(), TRUE);
}**
...
...
int _tmain(int argc, _TCHAR* argv[])
{
::testing::InitGoogleMock(&argc, argv);
RUN_ALL_TESTS();
std::getchar(); // keep console window open until Return keystroke
return 0;
}
I am not able to mock the CDatabase method: Open . When I run the code I get
Expected: to be called once Actual: never called - unsatisfied and active
Can anyone please help me in mocking a CDatabase method
Aucun commentaire:
Enregistrer un commentaire