I try to isolate my class, so because of the exchanging external free functions with mock implementations, because of that, I have created my mock class for free functions, which had external dependency in another class. So how will I call this mock functions in my class?
Is there any implementation you can suggest to me?
I am thinking about creating a unique pointer and calling by it, but I am not really sure about this.
Which approach should I follow for doing it?
#include "source/common/main/dpc.hpp"
#include "source/common/main/dt.hpp"
#include <gmock/gmock.h>
namespace test {
namespace {
class dpcMock
{
public:
MOCK_METHOD(bool, isVS, (const uint32_t id), ());
MOCK_METHOD(St, gpType, (const uint32_t width), ());
static dpcMock* activeMock;
};
}
}
#include "dpcMock.hpp"
#include "source/common/main/dpc.hpp"
#include <CppUTestExt/MockSupport.h>
test::dpcMock* test::dpcMock::activeMock = nullptr;
namespace common{
namespace main{
namespace {
bool isVS(const uint32_t id)
{
if (::test::dpcMock::activeMock == nullptr)
{
return true;
}
return test::dpcMock::activeMock->isVS(id);
}
inline St gpType(const uint32_t width)
{
if (::test::dpcMock::activeMock == nullptr)
{
return {};
}
return test::dpcMock::activeMock->gpType(width);
}
}
}
}
#include <memory>
#include <set>
#include "common/main/bm.hpp"
#include "common/main/ut/mocks/dpcMock.hpp"
namespace lucky{
namespace trap{
namespace main{
using namespace common::main;
class Dopy
{
public:
void cDL(const sDL& sDLp);
void cUL(const sUL& sULp);
void csDL(const sDL& sDLp);
void csUL(const sUL& sULp);
private:
std::unique_ptr<sa> sa_fr;
std::unique_ptr<bm> bm_fr;
};
}
}
}