Google Mock not able to mock LPCTSTR parameter

88 views
Skip to first unread message

Yogish Acharya

unread,
Mar 3, 2016, 1:52:28 PM3/3/16
to Google C++ Mocking Framework

Hi,

I am trying to write mock method for the method which is taking LPCTSTR as a parameter.
Example:  virtual LPCTSTR GetData(LPCTSTR key) const //declaration
//Calling function//
{
   CString str = GetData(key);
   //someother logic///
}


My mock method looks like this   MOCK_CONST_METHOD1(GetData, LPCTSTR(LPCTSTR key)); 

And expected call looks like,

LPCTSTR csPSValue;
LPCTSTR key = _T("Testing");
EXPECT_CALL(*objBasicSection, GetData(key)).WillOnce(Return(csPSValue));

GetData function call always returns empty string.
Please help me.

Thanks,
Yogisha

Keith Ray

unread,
Mar 3, 2016, 2:31:37 PM3/3/16
to Yogish Acharya, Google C++ Mocking Framework

LPCTSTR csPSValue;
LPCTSTR key = _T("Testing");
EXPECT_CALL(*objBasicSection, GetData(key)).WillOnce(Return(csPSValue));

Try

LPCTSTR csPSValue("non-empty string");


Vlad Losev

unread,
Mar 3, 2016, 9:45:35 PM3/3/16
to Google C++ Mocking Framework
LPCTSTR is just a pointer, so EXPECT_CALL(*objBasicSection, GetData(key)) ends up expecting the precise value of the pointer. In order to match string contents use EXPECT_CALL(*objBasicSection, GetData(testing::StrEq(key))).

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/35b372dd-9ff1-41e5-aaee-4b9e2381707f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages