Home > front end >  Save a char* parameter intro a string
Save a char* parameter intro a string

Time:10-13

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 foroperator*’ (operand type is ‘const std::__cxx11::basic_string<char>’)
   *pointer = ::testing::get<k>(args);

Than you so much in advance!

CodePudding user response:

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))));
//                                 ^
  • Related