In CPP, gTest, version does not matter too much, I have a class that I would like to mock in order to use gMock. I therefore defined an interface and implement it once with the Mock class and once with something like a wrapper that just forwards the mocked methods to the original.
I wonder if in the wrapper, I really have to call the underlying original function or, if there is some way to tell cpp: Use the method of your parent A to implement the interface method.
interact
class IQProcess : public QObject {
Q_OBJECT
public:
virtual ~IQProcess() = default;
virtual void start(const QString &program) = 0;
virtual bool startDetached(const QString &program) = 0;
};
#endif // IQPROCESS_H
mock
#ifndef QPROCESSMOCK_H
#define QPROCESSMOCK_H
#include <gmock/gmock.h>
#include "IQProcess.h"
#include <QObject>
class QProcessMock : public IQProcess {
Q_OBJECT
public:
MOCK_METHOD(void, start, (const QString &program), (override));
MOCK_METHOD(bool, startDetached, (const QString &program), (override));
};
#endif // QPROCESSMOCK_H
wrapper
#ifndef QPROCESSWRAPPER_H
#define QPROCESSWRAPPER_H
#include "IQProcess.h"
#include <QProcess>
class QProcessWrapper : public QProcess, public IQProcess {
public:
void start(const QString &program) override {
QProcess::start(program);
}
bool startDetached(const QString &program) override {
return QProcess::startDetached(program);
}
};
#endif // QPROCESSWRAPPER_H