Closed oriolarcas closed 4 years ago
Just found a workaround while playing with the example. If the method is overridden in the derived interface, it will compile:
struct I1 {
virtual int get() = 0;
virtual ~I1() = default;
};
struct I2 : virtual I1 {
using I1::I1;
virtual int get() override = 0;
virtual ~I2() = default;
};
TEST_CASE( "interfaces", "[ifc]" ) {
Mock<I2> i2_mock;
When(Method(i2_mock,get)).AlwaysReturn(1);
}
However, if I try to call the virtual method in the abstract interface the program will crash...
TEST_CASE( "interfaces", "[ifc]" ) {
Mock<I2> i2_mock;
When(Method(i2_mock,get)).AlwaysReturn(1);
I2& i2 = i2_mock.get();
REQUIRE(i2.get() == 1); /* works OK */
I1& i1 = static_cast<I1&>(i2);
REQUIRE(i1.get() == 1); /* causes SIGSEGV */
}
The Limitation section of https://github.com/eranpeer/FakeIt clearly states:
Can't mock classes with virtual inheritance.
My bad. Thanks!
Hi,
I have the following interfaces:
I need virtual inheritance for subclasses of I2, but the interfaces I1 and I2 themselves have no multiple inheritance. However, when I compile this code:
I get the following error:
Any ideas?