-2

Please help me with this question.. I'm beginner with gtest. I have a mocked function

DoSomething(const char* par0, const char* par2)

I want to save its second argument into

    std::string `savedPar_`;

EXPECT_CALL(mockd_, DoSomething(_, _,))
        .WillOnce(DoAll(SaveArg<1>(savedPar_), (Return(Ok))));

And got this error:

error: no match for ‘operator*’ (operand type is ‘const std::__cxx11::basic_string<char>’)
   *pointer = ::testing::get<k>(args);

Than you so much in advance!

273K
  • 29,503
  • 10
  • 41
  • 64
John Kan
  • 25
  • 6

1 Answers1

2

According to the doc

SaveArg<N>(pointer) Save the N-th (0-based) argument to *pointer.

It should be:

std::string savedPar_;

EXPECT_CALL(mockd_, DoSomething(_, _,))
        .WillOnce(DoAll(SaveArg<1>(&savedPar_), (Return(Ok))));
//                                 ^
Jarod42
  • 203,559
  • 14
  • 181
  • 302