mardi 12 octobre 2021

Use a value saved with SaveArg in an expect_call

I have to following mocked functions

DoSomething(const char* par0, const char* par2)
DoSomething2(std::string);

I save the value from DoSomething into

std::string savedPar_;

I want to use it in DoSomething2. How is that possible ? PS: is there any other possibility than using action_p ?

EXPECT_CALL(mockd_, DoSomething(_, _,))
                .WillOnce(DoAll(SaveArg<1>(&savedPar_), (Return(Ok))));
       
EXPECT_CALL(mockd_, DoSomething2(savedPar_,))
                .WillOnce((Return(Ok)))); 
      // has not yet the val


sut_->work();
// savedPar_ has the value

Aucun commentaire:

Enregistrer un commentaire