lundi 31 août 2015

How to use the googlemock's Field matcher?

Suppose the following :

enum ElevatorDirection{UP, DOWN, NONE}

class ElevatorStatus
{
public:
    ElevatorDirection currentDirection;
}

Somewhere in my tests, I have :

using testing::Field;
using testing::Eq;

TEST(myTestCase, myTestName)
{
    EXPECT_CALL(*server, Broadcast(Field(&ElevatorStatus::currentDirection, Eq(ElevatorDirection::UP))));
    // ...
}

When I compile, I get a bunch of errors. The first one is :

../../../GoogleTest/gmock-1.7.0/include/gmock/gmock-matchers.h:437:47: required from ‘bool testing::PolymorphicMatcher::MonomorphicImpl::MatchAndExplain(T, testing::MatchResultListener*) const [with T = const std::basic_string&; Impl = testing::internal::FieldMatcher]’

tests/WebsocketInterfaceTest.cpp:48:1: required from here

../../../GoogleTest/gmock-1.7.0/include/gmock/gmock-matchers.h:2030:24: error: no matching function for call to ‘testing::internal::FieldMatcher::MatchAndExplainImpl(testing::internal::bool_constant::type, const std::basic_string&, testing::MatchResultListener*&) const’

If I comment the EXPECT_CALL(...) line, everything compiles fine. What am I doing wrong using the Fieldmatcher?

Aucun commentaire:

Enregistrer un commentaire