c - Specifying output string argument with GoogleMock -
i'm evaluating google test/mock framework unit tests of c code.
how can specify output string argument function mock?
here have int get_int_param(const char *)
function test , uses int _get_text_file_content(const char *fn, char *content)
function want mock.
how specify char *content
going result of execution of mocking function?
i'm struggling code:
test(getparametertest,positiv){ const static int strlen=29; char *text=(char *)calloc(strlen,1); strcpy(text, "param1=1\nparam2=42\nparam3=3"); mokedfunctions mokedfunctions; expect_call(mokedfunctions, _get_text_file_content("process.conf",_)).times(atleast(1)).willonce(setargreferee<1>(text)); expect_eq(1, get_int_param("param1")); }
and got compile error:
/usr/include/gmock/gmock-more-actions.h: in instantiation of ‘typename testing::internal::function<f>::result testing::setargrefereeactionp<k, value_type>::gmock_impl<f>::gmock_performimpl(const args_type&, arg0_type, arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, arg6_type, arg7_type, arg8_type, arg9_type) const [with arg0_type = const char*; arg1_type = char*; arg2_type = testing::internal::excessivearg; arg3_type = testing::internal::excessivearg; arg4_type = testing::internal::excessivearg; arg5_type = testing::internal::excessivearg; arg6_type = testing::internal::excessivearg; arg7_type = testing::internal::excessivearg; arg8_type = testing::internal::excessivearg; arg9_type = testing::internal::excessivearg; f = int(const char*, char*); int k = 1; value_type = char*; typename testing::internal::function<f>::result = int; testing::setargrefereeactionp<k, value_type>::gmock_impl<f>::args_type = std::tuple<const char*, char*>]’: /usr/include/gmock/gmock-generated-actions.h:664:23: required ‘static result testing::internal::actionhelper<result, impl>::perform(impl*, const std::tuple<_u1, _u2>&) [with a0 = const char*; a1 = char*; result = int; impl = testing::setargrefereeactionp<1, char*>::gmock_impl<int(const char*, char*)>]’ /usr/include/gmock/gmock-more-actions.h:168:1: required ‘testing::setargrefereeactionp<k, value_type>::gmock_impl<f>::return_type testing::setargrefereeactionp<k, value_type>::gmock_impl<f>::perform(const args_type&) [with f = int(const char*, char*); int k = 1; value_type = char*; testing::setargrefereeactionp<k, value_type>::gmock_impl<f>::return_type = int; testing::setargrefereeactionp<k, value_type>::gmock_impl<f>::args_type = std::tuple<const char*, char*>]’ test_param.cpp:68:1: required here /usr/include/gmock/gmock-more-actions.h:175:3: error: size of array negative gtest_compile_assert_(internal::is_reference<argk_type>::value, ^ in file included /usr/include/gmock/gmock.h:65:0, test_param.cpp:2: /usr/include/gmock/gmock-more-actions.h:177:28: error: assignment of read-only location ‘std::get<1u, {const char*, char*}>((* & args))’ ::std::tr1::get<k>(args) = value; ^ make[1]: *** [test_param.o] error 1
what i'm doing wrong?
setargreferee
expects argument c++ reference, it's not case.
in general, in order better understand these actions helps think of them operations on argument arg
:
setargpointee(value)
*arg = value
(arg
must pointer)setargreferee(value)
arg = value
(arg
must reference)setarrayargument(first, last)
memcpy(arg, first, last - first)
(arg
must pointer)savearg(ptr)
*ptr = arg
saveargpointee(ptr)
*ptr = *arg
(arg
must pointer)
given that, becomes obvious action need setarrayargument<1>(text, text + strlen(text) + 1)
.
Comments
Post a Comment