Google Mock, argument matcher using another argument

5.7k views Asked by At

Is there any convenient way to match one argument against another one (which is a wildcard)? For example:

ON_CALL(calculator_mock, division(_, SameAsArgument<0>).WillByDefault(Return(1.0))

Is there such matcher like SameAsArgument ?

UPDATE: maybe SameAsArgument<N> is not very good. What I need is a matcher Argument<N>, which will get the value of N-th argument.

Thanks!

1

There are 1 answers

1
BЈовић On BEST ANSWER

Yes, that can be done like explained in the "Matching Multiple Arguments as a Whole" chapter of their cookbook.

In your case, should be :

EXPECT_CALL(calculator_mock, division(_,_))
      .With(AllOf(Args<0, 1>(Eq())));