jagtesh / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Can I extend MOCK_METHOD* to make it support more than 10 arguments function? #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Dear Google Mock Owners,

Sorry for bothering you.
I suffer an problem when I use MOCK_METHOD* to mock my class's virtual function.

I wrote a class to wrap some Windows API, and provide some pure virtual 
functions as interfaces for these APIs.
Due to these virtual functions are dedicated call Windows API, so their 
arguments are one by one mapping to Windows API.

However, some of Windows API's argument number are more than 10, such as 
CreateService, it has 13 arguments.
So that I can not use MOCK_METHOD* to mock this virtual function, because 
MOCK_METHOD* only supports 10 arguments and I need MOCK_METHOD13.

Is it possible that I extend MOCK_METHOD* by myself?
or it has to be modified by you because some binary files also need change?

Thank you for your help in advance.
Best regards and have a nice day.
Tom.

Original issue reported on code.google.com by liucc...@gmail.com on 22 Jul 2010 at 11:51

GoogleCodeExporter commented 9 years ago
(In the future, it's best to send questions to googlemock@googlegroups.com 
instead of the issue tracker.)

MOCK_METHOD* relies on tr1::tuple for storing the arguments.  Many tr1::tuple 
implementations limit the number of fields to 10, so you'll run into problems 
if you try to extend MOCK_METHOD* to more than 10 arguments.

A function with more than 10 arguments isn't readable.  At the call site, it's 
very hard to tell which argument is for what.  Usually we suggest to limit the 
arguments to under 6.

I understand that you cannot change CreateService, but you can create a wrapper 
for it.  The wrapper can take a struct argument, which can hold the arguments 
that are less interesting.  Then you can keep the total number of arguments 
under 10, and then you can mock the wrapper.

Original comment by w...@google.com on 22 Jul 2010 at 4:47

GoogleCodeExporter commented 9 years ago
Dear Google Mock Owners,

Thank you for your explanation.
I think I can change my design for this exception.

BTW, sorry for issuing question as tracker, next time I will send to 
googlemock@googlegroups.com first.

Thank you.

Original comment by liucc...@gmail.com on 23 Jul 2010 at 6:58

GoogleCodeExporter commented 9 years ago
Is there any sample of how to write the wrapper? I have the same problem.

Original comment by hla...@gmail.com on 1 Oct 2012 at 10:08