hunting/test/utils/LinuxApiMock/include/LinuxApiMock.h
2024-01-25 15:38:02 -08:00

51 lines
1.5 KiB
C++

#ifndef LINUX_API_MOCK_H
#define LINUX_API_MOCK_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <memory>
constexpr int INVALID_HANDLE = -1;
class LinuxApiMock
{
public:
LinuxApiMock() = default;
virtual ~LinuxApiMock() = default;
static std::shared_ptr<LinuxApiMock> &GetInstance(std::shared_ptr<LinuxApiMock> *impl = nullptr)
{
static auto instance = std::make_shared<LinuxApiMock>();
if (impl) {
// The non-thread-safe changing is only for gtest.
instance = *impl;
}
return instance;
}
virtual void Init() {}
virtual void UnInit() {}
virtual int fx_open(const char *pathname, int flags);
virtual int fx_tcgetattr(int fd, struct termios *termios_p);
virtual int fx_tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
};
/**
* A simulation interface class used for automated testing in Ubuntu systems, implementing the function of piling on
* some Linux standard interfaces.
*/
class LinuxTest : public LinuxApiMock
{
public:
LinuxTest() = default;
virtual ~LinuxTest() = default;
MOCK_METHOD2(fx_open, int(const char *, int));
MOCK_METHOD2(fx_tcgetattr, int(int, struct termios *));
MOCK_METHOD3(fx_tcsetattr, int(int, int, const struct termios *));
public:
/**
* @brief Get the Handle For Mock object
*
* @return int
*/
virtual int GetHandleForMock(void) { return INVALID_HANDLE; }
public:
static std::shared_ptr<LinuxTest> CreateLinuxTest(void);
};
#endif