我有一個方法爲什麼我需要第二個參數?
class FooInterface {
bool put(uint8_t* array, unsigned array_length);
}
測試需要驗證陣列的{1, 2, 3, 4, 5}
,其具有5個元素被傳遞到put
以我TEST_F()
,我下面的代碼。
uint8_t arr[5] = {1, 2, 3, 4, 5}; // Values for 'array' the out parameter
MockFoo foo;
FooInterface* fooI = &foo;
EXPECT_CALL(foo, put(_, 5))
.With(Args<0,1>(ElementsAreArray(arr, 5)));
這似乎是工作,但它讓我瘋了,因爲它似乎像而非Args<0,1>
,我應該有Args<0>
,因爲我是第一個參數匹配陣列和陣列大小設置爲5
。更改爲:
EXPECT_CALL(BFO, put(_, 5))
.With(Args<0>(ElementsAreArray(arr, 5))); // Here is 'Args<0>'
可生產這些錯誤:
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h:3114:34: error: no type named 'value_type' in 'std::tr1::tuple<const unsigned char *>'
typedef typename StlContainer::value_type Element;
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h:3532:28: note: in instantiation of template class 'testing::internal::ElementsAreMatcherImpl<const std::tr1::tuple<const unsigned char *> &>' requested here
return MakeMatcher(new ElementsAreMatcherImpl<Container>(
^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h:555:12: note: in instantiation of function template specialization 'testing::internal::ElementsAreArrayMatcher<unsigned char>::operator Matcher<const std::tr1::tuple<const unsigned char *> &>' requested here
return polymorphic_matcher_or_value;
^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h:531:12: note: in instantiation of member function 'testing::internal::MatcherCastImpl<const std::tr1::tuple<const unsigned char *> &, testing::internal::ElementsAreArrayMatcher<unsigned char> >::CastImpl' requested here
return CastImpl(
^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h:628:45: note: in instantiation of member function 'testing::internal::MatcherCastImpl<const std::tr1::tuple<const unsigned char *> &, testing::internal::ElementsAreArrayMatcher<unsigned char> >::Cast' requested here
return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h:666:34: note: in instantiation of function template specialization 'testing::SafeMatcherCastImpl<const std::tr1::tuple<const unsigned char *> &>::Cast<testing::internal::ElementsAreArrayMatcher<unsigned char> >' requested here
return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-generated-matchers.h:221:24: note: in instantiation of function template specialization 'testing::SafeMatcherCast<const std::tr1::tuple<const unsigned char *> &, testing::internal::ElementsAreArrayMatcher<unsigned char> >' requested here
: inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-generated-matchers.h:288:28: note: in instantiation of function template specialization 'testing::internal::ArgsMatcherImpl<const std::tr1::tuple<const unsigned char *, unsigned int> &, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1>::ArgsMatcherImpl<testing::internal::ElementsAreArrayMatcher<unsigned char> >'
return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
^
/home/sporty/ws-ccs/hw_1_5/miwt-os/coap/unittest/cbor_encoder_test.cpp:176:15: note: in instantiation of function template specialization 'testing::internal::ArgsMatcher<testing::internal::ElementsAreArrayMatcher<unsigned char>, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1>::operator Matcher<const std::tr1::tuple<const unsigned char *, unsigned int> &>' requested here
.With(Args<0>(ElementsAreArray(arr, 5)));
^
第一個參數是一個指針「uint8_t *」,而不是一個數組。 – molbdnilo
@molbdnilo你是什麼意思?第一個參數是一個指向數組的指針,你可以詳細說明你的評論嗎? – user1135541
這是一個指向* one *'uint8_t'的指針,而不是數組。它指向的'uint8_t'恰好是數組的第一個元素,但編譯器完全不知道這一點。 – molbdnilo