Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 401145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:00:26+00:00 2026-05-12T17:00:26+00:00

I asked this question on the Google Group but I think I will get

  • 0

I asked this question on the Google Group but I think I will get a faster response on here.

I’m trying to use Google’s Mocking framework to test my code. I am also utilizing their test framework as well. I’m compiling in VC9.
I’m having issues matching arguments that are MFC\ATL CStrings. GMock
says the objects are not equal and it appears it is evaluating on the
pointer addresses. The method I am attempting to mock is structured
like so:

void myMethod(const CString & key, const CString & value);

thus:

MOCK_METHOD2(myMethod, void(const CString & key , const CString &
value);

When setting up my expectations I am doing to following comparison:

CString szKey = _T("Some key");
CString szValue = _T("Some value");

EXPECT_CALL(myMock, myMethod(Eq(szKey), Eq(szValue))).WillOnce(Return
(true));

I have tried many different combinations of the matchers such as:

EXPECT_CALL(myMock, myMethod(StrCaseEq(_T("Some Key")), StrCaseEq(_T
(""Some value)))).WillOnce(Return(true));

EXPECT_CALL(myMock, myMethod(TypedEq<const CString &>(szKey),
TypedEq<const CString &>(szValue))).WillOnce(Return(true));


EXPECT_CALL(myMock, myMethod(TypedEq<const CString &>(szKey),
TypedEq<const CString &>(szValue))).WillOnce(Return(true));

Any of the above calls have produced the same result. Anyone else run
into this issue?

This is the output:

Google Mock tried the following 2 expectations, but none matched:

:80: tried expectation #0
  Expected arg #1: is equal to 006D430C pointing to "Some value"
           Actual: 4-byte object <A8EF 1102>
         Expected: to be called once
           Actual: never called - unsatisfied and active
:83: tried expectation #1
  Expected arg #1: is equal to (ignoring case) ""
           Actual: 4-byte object <A8EF 1102>
  Expected arg #2: is equal to (ignoring case) "Some value"
           Actual: 4-byte object <C0EE 1102>
         Expected: to be called once
           Actual: never called - unsatisfied and active

Adam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:00:26+00:00Added an answer on May 12, 2026 at 5:00 pm

    Since you are not making a copy of the strings when they are passed to your method, do you really need to check their values? It should suffice to write the following expectation:

    CString szKey = _T("Some key");
    CString szValue = _T("Some value");
    
    EXPECT_CALL(myMock, myMethod(szKey, szValue)).WillOnce(Return(true));
    

    … which will check that the strings given to the mock method are indeed the ones you expect (validated by address), and not a copy or other string.

    Regarding why the pre-canned matchers don’t work with CString, I suspect it is either because CString doesn’t override operator()== or the matcher implementations don’t have an explicit specialization for CString.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question before, Here however I think I presented the problem poorly,
I asked this question over in the actual tutorial, but not sure I'll get
(I asked this question in another way , and got some interesting responses but
I asked this question a while back but now I'm looking to implement an
I originally asked this question on RefactorMyCode , but got no responses there... Basically
I get asked this question a lot and I thought I'd solicit some input
I originally asked this question , but in finding an answer, discovered that my
I feel like I've seen this question asked before, but neither the SO search
I recently answered this question how-to-call-user-defined-function-in-order-to-use-with-select-group-by-order-by My answer was to use an inline view
I asked this question about a year ago on another site but never got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.