Improve:DeviceManager test tool.
This commit is contained in:
parent
9fe836864e
commit
4efd610707
|
@ -36,7 +36,7 @@ class VKeyMonitor
|
||||||
public:
|
public:
|
||||||
VKeyMonitor() = default;
|
VKeyMonitor() = default;
|
||||||
virtual ~VKeyMonitor() = default;
|
virtual ~VKeyMonitor() = default;
|
||||||
void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) {}
|
virtual void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) {}
|
||||||
};
|
};
|
||||||
class IDeviceManager
|
class IDeviceManager
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,5 +108,6 @@ void KeyManager::KeyEventHappened(const std::string &keyName, const VirtualKeyEv
|
||||||
LogError("monitor is nullptr.\n");
|
LogError("monitor is nullptr.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
LogInfo("KeyManager::KeyEventHappened: key = %s, event = %d, time = %u\n", keyName.c_str(), event, timeMs);
|
||||||
monitor->KeyEventReport(keyName, static_cast<VirtualKeyEvent>(event), timeMs);
|
monitor->KeyEventReport(keyName, static_cast<VirtualKeyEvent>(event), timeMs);
|
||||||
}
|
}
|
|
@ -117,6 +117,9 @@ public:
|
||||||
void SetKeyEvent(const std::string keyName, const KeyHalEvent &event);
|
void SetKeyEvent(const std::string keyName, const KeyHalEvent &event);
|
||||||
void SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
|
void SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void KeyEventHappendOnce(std::shared_ptr<KeyControlMock> &mock, const unsigned int &pressingTimeMs);
|
void KeyEventHappendOnce(std::shared_ptr<KeyControlMock> &mock, const unsigned int &pressingTimeMs);
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,7 @@ void HalTestTool::SetKeyClick(const std::string &keyName, const unsigned int &pr
|
||||||
}
|
}
|
||||||
if (key->SetKeyClick(pressingTimeMs)) {
|
if (key->SetKeyClick(pressingTimeMs)) {
|
||||||
// KeyEventHappendOnce(key, pressingTimeMs);
|
// KeyEventHappendOnce(key, pressingTimeMs);
|
||||||
|
DeviceManagerNotice(keyName, pressingTimeMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HalTestTool::KeyEventHappendOnce(std::shared_ptr<KeyControlMock> &mock, const unsigned int &pressingTimeMs)
|
void HalTestTool::KeyEventHappendOnce(std::shared_ptr<KeyControlMock> &mock, const unsigned int &pressingTimeMs)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
namespace DeviceManagerTest
|
namespace DeviceManagerTest
|
||||||
{
|
{
|
||||||
const char *KEY_TEST = "TEST";
|
const char *KEY_TEST = "TEST";
|
||||||
class DeviceManagerTest : public testing::Test, public HalTestTool, public DeviceManagerTestTool
|
class DeviceManagerTest : public testing::Test, virtual public HalTestTool, public DeviceManagerTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceManagerTest() {}
|
DeviceManagerTest() {}
|
||||||
|
|
|
@ -7,7 +7,7 @@ include_directories(
|
||||||
./include
|
./include
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
${UTILS_SOURCE_PATH}/McuProtocol/include
|
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef DEVICE_MANAGER_TEST_TOOL_H
|
#ifndef DEVICE_MANAGER_TEST_TOOL_H
|
||||||
#define DEVICE_MANAGER_TEST_TOOL_H
|
#define DEVICE_MANAGER_TEST_TOOL_H
|
||||||
#include "DeviceManager.h"
|
#include "DeviceManager.h"
|
||||||
|
#include "HalTestTool.h"
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
|
@ -73,7 +74,7 @@ public:
|
||||||
virtual ~KeyMonitorMock() = default;
|
virtual ~KeyMonitorMock() = default;
|
||||||
MOCK_METHOD3(KeyEventReport, void(const std::string &, const VirtualKeyEvent &, const unsigned int &));
|
MOCK_METHOD3(KeyEventReport, void(const std::string &, const VirtualKeyEvent &, const unsigned int &));
|
||||||
};
|
};
|
||||||
class DeviceManagerTestTool
|
class DeviceManagerTestTool : virtual public HalTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceManagerTestTool() = default;
|
DeviceManagerTestTool() = default;
|
||||||
|
@ -81,8 +82,13 @@ public:
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DeviceManagerMockInit(std::shared_ptr<DeviceManagerMock> &mock);
|
void DeviceManagerMockInit(std::shared_ptr<DeviceManagerMock> &mock);
|
||||||
|
void KeyMonitorInit(std::shared_ptr<KeyMonitorMock> &mock, const std::string &keyName,
|
||||||
|
const unsigned int &pressingTimeMs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DeviceManagerMock> mDeviceManagerMock;
|
std::shared_ptr<DeviceManagerMock> mDeviceManagerMock;
|
||||||
|
|
|
@ -36,6 +36,16 @@ void DeviceManagerTestTool::UnInit(void)
|
||||||
mKeyMonitorMock.reset();
|
mKeyMonitorMock.reset();
|
||||||
CancelOverrideDeviceMakePtrObject();
|
CancelOverrideDeviceMakePtrObject();
|
||||||
}
|
}
|
||||||
|
void DeviceManagerTestTool::DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||||
|
{
|
||||||
|
LogInfo("DeviceManagerTestTool::DeviceManagerNotice\n");
|
||||||
|
if (mKeyMonitorMock) {
|
||||||
|
KeyMonitorInit(mKeyMonitorMock, keyName, pressingTimeMs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("mKeyMonitorMock is nullptr.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
void DeviceManagerTestTool::DeviceManagerMockInit(std::shared_ptr<DeviceManagerMock> &mock)
|
void DeviceManagerTestTool::DeviceManagerMockInit(std::shared_ptr<DeviceManagerMock> &mock)
|
||||||
{
|
{
|
||||||
auto getKeyMonitor = [=](std::shared_ptr<VKeyMonitor> &monitor) {
|
auto getKeyMonitor = [=](std::shared_ptr<VKeyMonitor> &monitor) {
|
||||||
|
@ -47,4 +57,25 @@ void DeviceManagerTestTool::DeviceManagerMockInit(std::shared_ptr<DeviceManagerM
|
||||||
.Times(ONLY_BE_CALLED_ONCE)
|
.Times(ONLY_BE_CALLED_ONCE)
|
||||||
.WillOnce(DoAll(WithArgs<0>(Invoke(getKeyMonitor)), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
.WillOnce(DoAll(WithArgs<0>(Invoke(getKeyMonitor)), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
// .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
// .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
}
|
||||||
|
void DeviceManagerTestTool::KeyMonitorInit(std::shared_ptr<KeyMonitorMock> &mock, const std::string &keyName,
|
||||||
|
const unsigned int &pressingTimeMs)
|
||||||
|
{
|
||||||
|
// EXPECT_CALL(*mock.get(), KeyEventReport(_, _, _)).Times(100).WillRepeatedly(DoAll(Return()));
|
||||||
|
EXPECT_CALL(*mock.get(), KeyEventReport(_, _, _)).WillRepeatedly(DoAll(Return()));
|
||||||
|
constexpr int CLICK_EVENT_HAPPENED_ONLY_ONCE = 1;
|
||||||
|
constexpr int HOLD_UP_EVENT_HAPPENED_ONLY_ONCE = 1;
|
||||||
|
if (KEY_ACTION_SHORT_CLICK <= pressingTimeMs && pressingTimeMs < KEY_ACTION_HOLD_DWON) {
|
||||||
|
EXPECT_CALL(*mock.get(), KeyEventReport(keyName, static_cast<VirtualKeyEvent>(KeyEvent::SHORT_CLICK), _))
|
||||||
|
.Times(CLICK_EVENT_HAPPENED_ONLY_ONCE)
|
||||||
|
.WillRepeatedly(DoAll(Return()));
|
||||||
|
}
|
||||||
|
if (KEY_ACTION_HOLD_DWON <= pressingTimeMs) {
|
||||||
|
EXPECT_CALL(*mock.get(), KeyEventReport(keyName, static_cast<VirtualKeyEvent>(KeyEvent::HOLD_DOWN), _))
|
||||||
|
.Times(AtLeast(1))
|
||||||
|
.WillRepeatedly(DoAll(Return()));
|
||||||
|
EXPECT_CALL(*mock.get(), KeyEventReport(keyName, static_cast<VirtualKeyEvent>(KeyEvent::HOLD_UP), _))
|
||||||
|
.Times(HOLD_UP_EVENT_HAPPENED_ONLY_ONCE)
|
||||||
|
.WillOnce(DoAll(Return()));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user