2011-02-20 14 views
5

recibo un error de compilación, mientras que utilizando la siguiente declaración Google Mock:Google Mock - usando la prueba :: :: An()

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

El error es:

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 

¿Qué estoy haciendo mal ?


ACTUALIZACIONES:

estoy usando VS2010.

La declaración de algunaFuncion es:

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

An() es un Google Mock wildcard matcher con la siguiente definición:

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

Una versión aún representativa simplificada de la estructura es:

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 
+0

¿Puede proporcionar las definiciones de AStructIDefined y An? –

+0

¿Qué compilador estás usando? –

Respuesta

4

La solución fue cambiar la declaración de:

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

a

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

C++ implícitamente arroja const y referencia & en los parámetros de función, pero la declaración de Google maqueta parece requerir el tipo que aparece en la firma de la función y no el tipo presentado como un parámetro para el función.