gtest/gmock override call from base class

39 Views Asked by At

I'm trying to overide a base method but it fails. class B derives from A and I need to override the call to value. I can't change A or B. How to fix this in a proper way? Any ideas?

class A {
protected:
    virtual void print(std::string s) = 0;
    std::string value()
    {
        return "A: ";
    }
};

class B : public A {
public:
    void print(std::string s)
    {
        std::cout << value() << s << std::endl;
    }
};

class M : public B {
public:
    MOCK_METHOD(std::string, value, ());
};

TEST(Test, test)
{
    M m;

    EXPECT_CALL(m, value())
        .WillRepeatedly(::testing::Return("M: "));

    m.print("test mock");
}

The output is: A: test mock

0

There are 0 best solutions below