Parameterized-Tests and Variadic Templates

803 views
Skip to first unread message

Robotic Brain

unread,
May 21, 2014, 9:14:25 AM5/21/14
to googl...@googlegroups.com
Hi,

I have this code: http://pastebin.com/LGK1F5La

For some reason I cannot Instantiate MockObserver<std::string, LogLevel> because it is abstract?
Error: cannot declare variable 'logOut' to be of abstract type '::utility::mock::MockObserver<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, ::utility::log::LogLevel>'

because the following virtual functions are pure within '::utility::mock::MockObserver<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, ::utility::log::LogLevel>':


Instantiating MockObserver<std::string> however works.
I have the suspicion that there is something wrong with my variadic templates or worse, my compiler is bugged (MacPorts gcc 4.8.20)

Does someone know what is going wrong?

Tanks in advance

Billy Donahue

unread,
May 21, 2014, 9:24:25 AM5/21/14
to Robotic Brain, googl...@googlegroups.com
To help troubleshoot this, try using a typedef inside MockObserver:

using TypedSubject = SubjectInterface<ArgTypes...>;



--

---
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/93b7f5ed-eb87-4926-a68c-af6c55d510ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robotic Brain

unread,
May 21, 2014, 10:21:51 AM5/21/14
to googl...@googlegroups.com, Robotic Brain
Do you mean like that?:

using TypedSubject = SubjectInterface<ArgTypes...>;

  MOCK_METHOD1_T(onAdd, void(TypedSubject &subject));

  MOCK_METHOD2_T(onNotify, void(TypedSubject &subject, ArgTypes... args));

  MOCK_METHOD1_T(onRemove, void(TypedSubject &subject));


unfortunately that didn't change anything either :(

Billy Donahue

unread,
May 21, 2014, 11:39:04 AM5/21/14
to Robotic Brain, googl...@googlegroups.com
On Wed, May 21, 2014 at 10:21 AM, Robotic Brain <roboti...@googlemail.com> wrote:
Do you mean like that?:

using TypedSubject = SubjectInterface<ArgTypes...>;

  MOCK_METHOD1_T(onAdd, void(TypedSubject &subject));

  MOCK_METHOD2_T(onNotify, void(TypedSubject &subject, ArgTypes... args));

  MOCK_METHOD1_T(onRemove, void(TypedSubject &subject));


unfortunately that didn't change anything either :(


I would expect this would help with onAdd and onRemove, but not with onNotify,
which still has an argument pack in its signature. 


 
Am Mittwoch, 21. Mai 2014 15:24:25 UTC+2 schrieb Billy Donahue:
To help troubleshoot this, try using a typedef inside MockObserver:

using TypedSubject = SubjectInterface<ArgTypes...>;



On Wed, May 21, 2014 at 9:14 AM, Robotic Brain <roboti...@googlemail.com> wrote:
Hi,

I have this code: http://pastebin.com/LGK1F5La

For some reason I cannot Instantiate MockObserver<std::string, LogLevel> because it is abstract?
Error: cannot declare variable 'logOut' to be of abstract type '::utility::mock::MockObserver<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, ::utility::log::LogLevel>'

because the following virtual functions are pure within '::utility::mock::MockObserver<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, ::utility::log::LogLevel>':


Instantiating MockObserver<std::string> however works.
I have the suspicion that there is something wrong with my variadic templates or worse, my compiler is bugged (MacPorts gcc 4.8.20)

Does someone know what is going wrong?

Tanks in advance

--

---
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.

--

---
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.

Robotic Brain

unread,
May 22, 2014, 5:27:27 AM5/22/14
to googl...@googlegroups.com

I got it working!

gmock doesn't seem to like variadic templates at all :(

The first use works fine since it just expands to a normal type, but the 2nd use expands to multiple arguments as if you had copy&past-ed them in there...

is there a way to prameterize the argument number of MOCK_METHOD ?

if that's not possible i would have to define the mock class everywhere i want to use it and can't extract it into a header


namespace {

template<typename... ArgTypes>

class MockObserver : public ObserverInterface<ArgTypes...> {

 public:

  MOCK_METHOD1_T(onAdd, void(SubjectInterface<ArgTypes...> &subject));

  MOCK_METHOD3_T(onNotify, void(SubjectInterface<ArgTypes...> &subject, ArgTypes... args));

                             ^ --- changed 2 to 3 here

  MOCK_METHOD1_T(onRemove, void(SubjectInterface<ArgTypes...> &subject));

};

Reply all
Reply to author
Forward
0 new messages