Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify a method on a parent class was called #211

Open
dolfandringa opened this issue Jun 2, 2020 · 1 comment
Open

Verify a method on a parent class was called #211

dolfandringa opened this issue Jun 2, 2020 · 1 comment

Comments

@dolfandringa
Copy link

How can I verify that a child class calls a function on the parent class. In the sample below, I have separate unittests for class A. But when testing class B I want to verify that it indeed calls its parent class' test function. Is this possible using fakeit?

#include "fakeit.hpp"
#include <iostream>

class A {
    public:
        virtual void test() {
            a = 5;
        }
        int a;
};

class B: public A {
    public:
        virtual void test() {
            A::test();
            b = 3;
        }
        int b;
};


void test_B_test() {
    B *b = new B();
    fakeit::Mock<B> spy(*b);
    b->test();
    //Verify somehow that A::test was called
    std::cout << b->a << " " << b->b << std::endl;
}

int main() {
    test_B_test();
}
@FranckRJ
Copy link
Collaborator

FranckRJ commented Nov 9, 2022

No it's not possible currently and I don't see how we can implement it. The way mocks work is by creating a sub-class that inherit from the class you want to mock, and alter the V-Table to redirect the call to the function we want to be called. When you use a fully qualified name to call your method (in the form Class::method) the call won't go through the V-Table, so we can't redirect it or do anything with it.

I'll keep it open in case anyone have an idea but I guess it will never be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants