gmock and C++11

121 views
Skip to first unread message

Avi Drissman

unread,
Oct 9, 2016, 10:54:05 PM10/9/16
to cxx
I'm working on moving autofill to use containers with owned pointers, but autofill heavily uses gmock, which seems to be rather unhappy about mocking out methods that have move-only types as parameters.

https://github.com/google/googlemock/blob/master/googlemock/docs/DesignDoc.md talks about the far-off world of C++0x, and there's an open issue https://github.com/google/googletest/issues/395 about exactly this.

Is there a new gmock we can bring in? The right way to proceed isn't obvious here to me.

Avi

Avi Drissman

unread,
Oct 9, 2016, 11:31:28 PM10/9/16
to cxx
OK, I may have found a way around the issue by using lambdas and captured references, which is too clever for my own good but might actually work... :(

Daniel Cheng

unread,
Oct 9, 2016, 11:41:06 PM10/9/16
to Avi Drissman, cxx
The usual idiom I see in Chromium code is to define a forwarding method which delegates to Gmock [1][2]:

class MockFoo : public Foo {
 public:
  void Method(std::unique_ptr<Bar>);
  MOCK_METHOD1(Method, Bar*);
};

Daniel


--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACWgwAYyPDXHPzkbbjkWCZ0fW-b43OfQQweU1E%3DpsLXP%3DdnW6g%40mail.gmail.com.

dan...@chromium.org

unread,
Oct 10, 2016, 4:34:08 PM10/10/16
to Daniel Cheng, Avi Drissman, cxx
On Sun, Oct 9, 2016 at 8:40 PM, Daniel Cheng <dch...@chromium.org> wrote:
The usual idiom I see in Chromium code is to define a forwarding method which delegates to Gmock [1][2]:

class MockFoo : public Foo {
 public:
  void Method(std::unique_ptr<Bar>);
  MOCK_METHOD1(Method, Bar*);
};

Daniel




But I think maybe gmock hasn't been rolled since that or something.. I'm not entirely sure where we're at.
 

On Sun, Oct 9, 2016 at 8:31 PM 'Avi Drissman' via cxx <c...@chromium.org> wrote:
OK, I may have found a way around the issue by using lambdas and captured references, which is too clever for my own good but might actually work... :(

On Sun, Oct 9, 2016 at 10:53 PM, Avi Drissman <a...@google.com> wrote:
I'm working on moving autofill to use containers with owned pointers, but autofill heavily uses gmock, which seems to be rather unhappy about mocking out methods that have move-only types as parameters.

https://github.com/google/googlemock/blob/master/googlemock/docs/DesignDoc.md talks about the far-off world of C++0x, and there's an open issue https://github.com/google/googletest/issues/395 about exactly this.

Is there a new gmock we can bring in? The right way to proceed isn't obvious here to me.

Avi

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACWgwAYyPDXHPzkbbjkWCZ0fW-b43OfQQweU1E%3DpsLXP%3DdnW6g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.

Xiaohan Wang (王消寒)

unread,
Aug 2, 2017, 4:49:57 PM8/2/17
to Dana Jansens, Daniel Cheng, Avi Drissman, cxx
I am also hitting this issue, for mock methods involving base::OnceCallback. Given we'll use base::OnceCallback more and more, it seems to me we should fix this gmock limitation instead of encouraging people to use the workaround.

There's actually a proposed patch in the github issue, and it seems to be working for somebody else. What's the proper way to get this fixed in gmock and roll gmock in chromium?

Xiaohan Wang (王消寒)

unread,
Aug 2, 2017, 4:50:21 PM8/2/17
to Dana Jansens, Taiju Tsuiki, Daniel Cheng, Avi Drissman, cxx
+tzik
Reply all
Reply to author
Forward
Message has been deleted
0 new messages