2015-11-17 1 views
0

Pour la maquette suivante:Méthode prévue appel avec tableau comme argument

class MockUI8CBuff : public UI8CBuff_I { 
public: 
    MOCK_METHOD2(put, unsigned(const uint8_t* start, unsigned n)); 
}; 

Et le test suivant Snippet

MockUI8CBuff BFO; 

uint8_t arr[] = {1, 2, 3}; 

EXPECT_CALL(BFO, put(ElementsAreArray(arr, 3), 2)) 
    .WillOnce(Return(1)); 

Je l'erreur suivante

/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h|3114 col 20| error: type 'StlContainer' (aka 'const unsigned char *') cannot be used prior to '::' because it has no members 
|| typedef typename StlContainer::value_type Element; 
||     ^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h|3532 col 28| note: in instantiation of template class 'testing::internal::ElementsAreMatcherImpl<const unsigned char *>' requested here 
||  return MakeMatcher(new ElementsAreMatcherImpl<Container>(
||       ^
miwt-os/coap/unittest/cbor_encoder_test.cpp|126 col 26| note: in instantiation of function template specialization 'testing::internal::ElementsAreArrayMatcher<unsigned char>::operator Matcher<const unsigned char *>' requested here 
||  EXPECT_CALL(BFO, put(::testing::ElementsAreArray(arr, 3), 2)) 
||      ^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-spec-builders.h|1845 col 61| note: expanded from macro 'EXPECT_CALL' 
|| #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) 
||               ^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-spec-builders.h|1844 col 20| note: expanded from macro 'GMOCK_EXPECT_CALL_IMPL_' 
||  ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) 
||     ^
|| 1 error generated. 
miwt-os/coap/unittest/cbor_encoder.makefile|109| recipe for target 'cbor_encoder_test.o' failed 
|| make: *** [cbor_encoder_test.o] Error 1 

Pourquoi dois-je obtenir cette erreur? Les travaux suivants:

EXPECT_CALL(BFO, put(Pointee(1), 2)) 
    .WillOnce(Return(1)); 
+1

Les pointeurs ne peuvent pas être comparés aux tableaux. Vous devriez utiliser la syntaxe comme suit: EXPECT_CALL (BFO, put (_, _) .With (Args <0,1> (ElementsAre (1, 2, 3))); –

+0

Je n'ai pas gmock sur mon PC, seulement au travail , et je ne pouvais pas vérifier si c'était la réponse, je vais poster la réponse maintenant si: P –

Répondre

1

Les pointeurs ne peuvent pas être comparés aux matrices. Vous devez utiliser la syntaxe comme suit:

EXPECT_CALL(BFO, put(_, _)) 
    .With(Args<0,1>(ElementsAre(1, 2, 3))); // ElementsAreArray can also be used