mardi 14 juillet 2020

GMock casting to base looses mock behaviour

Using a library and I'm trying to mock it in my gtests.

class MockScanOutcome : public Aws::DynamoDB::Model::ScanOutcome {
    public:
        MockScanOutcome() : Aws::DynamoDB::Model::ScanOutcome() {};
        MOCK_METHOD(bool, IsSuccess, (), (const));
};

Where the base has the following method definition:

template<typename R, typename E> // Result, Error
class Outcome
{
    public:

        ...

        inline bool IsSuccess() const
        {
            return this->success;
        }
}

I'm running the following in a test but it's coming out unequal

Aws::DynamoDB::Model::ScanOutcome *so = dynamic_cast<Aws::DynamoDB::Model::ScanOutcome *>(m_outcome);
    
EXPECT_CALL(*m_outcome, IsSuccess).WillOnce(Return(true));

EXPECT_EQ(m_outcome, so); //fine
EXPECT_EQ(m_outcome -> IsSuccess(), true); //fine
EXPECT_EQ(so -> IsSuccess(), true); //error

How do you override the const method in the base class?

Aucun commentaire:

Enregistrer un commentaire