문제

다음 Google mock 선언 : 을 사용하는 동안 편집 오류가 발생합니다.

EXPECT_CALL(some_object, someFunction(1,An<AStructIDefined>()))
    .Times(2);
.

오류는 다음과 같습니다.

1>ClCompile:
1>  TestMyClass.cpp
1>TestMyClass.cpp(189): error C2664: 'mynamespace::MockMyClassClient::gmock_someFunction' : cannot convert parameter 2 from 'testing::Matcher<T>' to 'const testing::Matcher<T> &'
1>          with
1>          [
1>              T=mynamespace::AStructIDefined
1>          ]
1>          and
1>          [
1>              T=const mynamespace::AStructIDefined &
1>          ]
1>          Reason: cannot convert from 'testing::Matcher<T>' to 'const testing::Matcher<T>'
1>          with
1>          [
1>              T=mynamespace::AStructIDefined
1>          ]
1>          and
1>          [
1>              T=const mynamespace::AStructIDefined &
1>          ]
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
.

무엇을 잘못하고 있습니까?


업데이트 :

VS2010을 사용하고 있습니다.

조치 선언은 다음과 같습니다.

virtual void someFunction( long long ll, const AStructIDefined& a_struct);
.

an ()은 Google 모의 와일드 카드 일치저 다음과 같이정의 :

// Creates a matcher that matches any value of the given type T.
template <typename T>
inline Matcher<T> An() { return A<T>(); }
.

struct의 단순화 된 아직 대표적인 버전은 다음과 같습니다.

namespace mynamespace {

class ABaseCLass
{
public:
    virtual ~ABaseCLass(){};
    virtual bool isValid() const = 0;
};

struct AStructIDefined : public ABaseCLass
{
public:
    OrderStatusReport(SomeEnum1 e_, int i_, double d_);

    SomeEnum1 e;
    int i;
    double d;

    const std::string toString() const;
    bool isSane() const;
    bool operator== (const SomeEnum1& ref_) const;
    double getD() const;
    int getI() const;
    bool isCondition() const;
};

} // namespace mynamespace
.

도움이 되었습니까?

해결책

The solution was to change the declaration from:

EXPECT_CALL(some_object, someFunction(1,An<AStructIDefined>()))
    .Times(2);

to

EXPECT_CALL(some_object, someFunction(1,An<const AStructIDefined &>()))
    .Times(2);

C++ implicitly casts const and reference & on function parameters, but google mock's declaration seems to require the type appearing in the function's signature and not the type submitted as a parameter to the function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top