51 lines
2.0 KiB
C++
51 lines
2.0 KiB
C++
#include "IMcuManager.h"
|
|
#include "Log.h"
|
|
#include "IHal.h"
|
|
#include "LinuxApiTestForMcu.h"
|
|
#include "LinuxApiMock.h"
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
#include <thread>
|
|
namespace IMcuManagerTest2
|
|
{
|
|
class IHalMock : public IHal
|
|
{
|
|
public:
|
|
IHalMock() = default;
|
|
~IHalMock() = default;
|
|
MOCK_METHOD0(GetMcuDeviceInformation, const McuDeviceInformation(void));
|
|
};
|
|
// ../out/test/bin/McuManagerTest --gtest_filter=IMcuManagerTest2.Demo
|
|
TEST(IMcuManagerTest2, Demo)
|
|
{
|
|
InitLog(LOG_EASYLOGGING, nullptr);
|
|
std::shared_ptr<IHal> hal = std::make_shared<IHalMock>();
|
|
EXPECT_CALL(*(std::dynamic_pointer_cast<IHalMock>(hal)).get(), GetMcuDeviceInformation())
|
|
.Times(1)
|
|
.WillRepeatedly(::testing::DoAll(::testing::Return(gMcuInfoMock)));
|
|
IHal::GetInstance(&hal);
|
|
|
|
std::shared_ptr<LinuxApiTest> linuxApiMock;
|
|
linuxApiMock = std::make_shared<LinuxApiTest>();
|
|
std::shared_ptr<LinuxApiMock> tmp = linuxApiMock;
|
|
LinuxApiMock::GetInstance(&tmp);
|
|
LinuxApiTest::DefaultApiInit(linuxApiMock);
|
|
LinuxApiTestForMcu::LinuxApiInit(linuxApiMock);
|
|
|
|
CreateMcuManager();
|
|
IMcuManager::GetInstance()->Init();
|
|
std::shared_ptr<VMcuDevice> mcuDevice = std::make_shared<VMcuDevice>();
|
|
IMcuManager::GetInstance()->GetMcuDevice(mcuDevice);
|
|
unsigned char changedStartupMode = mcuDevice->GetStartupMode();
|
|
LogInfo("Get startup mode = %d\n", changedStartupMode);
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
LinuxApiTestForMcu::Test(linuxApiMock);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
IMcuManager::GetInstance()->UnInit();
|
|
std::shared_ptr<LinuxApiMock> tmpLinux = std::make_shared<LinuxApiMock>();
|
|
LinuxApiMock::GetInstance(&tmpLinux);
|
|
linuxApiMock.reset();
|
|
UnInitLog();
|
|
}
|
|
} |