mardi 7 juillet 2020

use of variable in EXPECT_CALL

I have a simple mock class for a serial interface:

class MockSerialPort : public drivers::SerialPort
{
  public:
    MockSerialPort() : SerialPort(){};

    MOCK_METHOD((Result<size_t>), Read, (uint8_t *, size_t, (const duration<int64_t, std::micro> &)), (override));
    MOCK_METHOD((Result<size_t>), Write, (const uint8_t *, size_t), (override));
};

During the expected Read call I'd like to know what the buffer length that the calling code is expecting so that I can copy the data to the buffer properly. For example:

EXPECT_CALL(port_, Read(NotNull(),length,_))
                .WillOnce(DoAll(SetArrayArgument<0>(&data[0], &data[length]), Return(length)));

What is the correct syntax to do it? If I specify the variable as above then the value in it is what we expect. But how do I not fail the expect call and actually store the value that the caller of Read specified?

Aucun commentaire:

Enregistrer un commentaire