need to mock methods with usual access modifiers (volatile and const volatile) and exception specs (throw ...)
Opened this issue · 8 comments
GoogleCodeExporter commented
Currently gmock don't have macros for mocking volatile and const volatile
methods. There are several options to solve this:
1. provide
MOCK_VOLATILE_METHOD0
MOCK_VOLATILE_METHOD0_T
MOCK_VOLATILE_METHOD0_WITH_CALLTYPE
MOCK_VOLATILE_METHOD0_T_WITH_CALLTYPE
and friends as needed.
2. expose a variation of GMOCK_METHOD0_ to let the user write
GMOCK_METHOD0(volatile, , Foo, int());
GMOCK_METHOD0_T(const volatile, , Bar, int());
and so on.
#1 means adding 40 more macros and doesn't scale well. I like #2 better. Its
syntax isn't as nice as #1, but good enough for occasional use.
If we go with #2, we should consider supporting exception specs at the same
time.
Original issue reported on code.google.com by w...@google.com
on 8 Sep 2010 at 8:55
GoogleCodeExporter commented
Correction: #1 means 80 more macros when we consider 'const volatile', and 160
when we add exception spec into the picture. Definitely not the way to go.
Original comment by w...@google.com
on 8 Sep 2010 at 8:56
GoogleCodeExporter commented
I've took a look into updating my partial implementation of #1 into something
more like #2.
One issue is generating the identifier for the FunctionMocker member, which
needs to include qualifiers.
Currently I supply volatile as another parameter to GMOCK_METHOD0_. Adding
exception specs we end up with 6 parameters. This seems a bit much:
GMOCK_METHOD0(const, volatile, exception-spec, call-type, name, signature);
The first 3 parameters are only separate arguments so that the FunctionMocker
member identifier can be generated. With an alternate way to generate the
identifier I think we could merge those 3 into a single param:
GMOCK_METHOD0(qualifiers, call-type, name, signature);
Some options for generating the identifier:
- Rely on the __LINE__ or __COUNTER__ (non standard, in gcc-4.3 and msvc)
macros.
- Might be possible to use some other macro hackery.
Any thoughts?
- Edgar
Original comment by edgar.el...@caris.com
on 15 Sep 2010 at 8:11
GoogleCodeExporter commented
My suggestion is (for your new macros) to forget about using the CV qualifiers
as part of the identifier name. That is only useful in very rare cases.
I agree on merging the CV qualifiers and the exception spec into one parameter.
That will give us:
GMOCK_METHOD1(STDMETHODCALLTYPE, MethodName, int(bool),
const volatile throw(Foo));
(I'm putting the call type first to be consistent with
MOCK_METHOD0_WITH_CALLTYPE.)
Original comment by w...@google.com
on 15 Sep 2010 at 8:28
GoogleCodeExporter commented
Original comment by w...@google.com
on 27 Sep 2010 at 9:39
GoogleCodeExporter commented
Original comment by w...@google.com
on 24 Feb 2011 at 8:08
- Changed title: need to mock methods with usual access modifiers (volatile and const volatile) and exception specs (throw ...)
GoogleCodeExporter commented
Hi, is there any chance this will be added soon?
Original comment by lukasz.c...@gmail.com
on 27 May 2014 at 12:03
GoogleCodeExporter commented
Sorry I never did get around to incorporating the suggestions. I'll take a stab
this week.
Original comment by edgar.el...@caris.com
on 27 May 2014 at 11:19
GoogleCodeExporter commented
Patch submitted: https://codereview.appspot.com/103030043
Notes:
- Mocking overloaded methods on the same line will not longer works (mentioned
above).
- Add macros: GMOCK_QUALIFIED_METHOD*(..., method, qualifiers, signature)
- Having the qualifiers as the last parameter was not possible, due to the use
of __VA_ARGS__ for the signature. So I put them after the method name.
Original comment by oat...@gmail.com
on 3 Jun 2014 at 4:54