eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.24k stars 170 forks source link

Inheritance & Dynamic Casting Quickstart example crashes #127

Open Medality opened 6 years ago

Medality commented 6 years ago

Hi,

I followed the Inheritance & Dynamic Casting Quickstart example. The upcast is working correctly but the dynamic_cast crashes: Mock<C> cMock; When(Method(cMock, foo)).AlwaysReturn(0); A& a = cMock.get(); // get instance and upcast to A& B& b = dynamic_cast<B&>(a); // downcast to B& --> Crash!

I'm using Visual Studio 2015 Update 3 on Windows 10.

Thanks.

lyn444 commented 6 years ago

i also have the same issue regarding the downcasting. it throws access violation exception.

My deduced code is:

class Base { public: virtual ~Base() {} };

class Derived : public Base
{
public:
    virtual ~Derived() {}
};

TEST(Test, TestCase)
{
    fakeit::Mock<Derived> mockDerived;
    Base* base = &mockDerived.get();
    Derived* derived = dynamic_cast<Derived*>(base); // Crash here. Access violation - no RTTI data!
}

my environment is Visual Studio 2015 Update 1 running on Windows 8.1

helmesjo commented 5 years ago

@eranpeer Any details on this? Just stumbled upon the same. Need the downcast in a special case caused by fakeit not supporting multiple inheritance.