Improve:DeviceManager test tool.
This commit is contained in:
parent
10921b1b57
commit
0de968d42e
|
@ -32,5 +32,6 @@ const StatusCode DeviceManager::UnInit(void)
|
||||||
}
|
}
|
||||||
const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor)
|
const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor)
|
||||||
{
|
{
|
||||||
|
LogInfo("DeviceManager::SetAllKeysMonitor\n");
|
||||||
return KeyManager::GetInstance()->SetKeyMonitor(monitor);
|
return KeyManager::GetInstance()->SetKeyMonitor(monitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
{
|
{
|
||||||
CreateAllKeysMcok();
|
CreateAllKeysMcok();
|
||||||
HalTestTool::Init();
|
HalTestTool::Init();
|
||||||
|
DeviceManagerTestTool::Init();
|
||||||
CreateHalCppModule();
|
CreateHalCppModule();
|
||||||
CreateDeviceManagerModule();
|
CreateDeviceManagerModule();
|
||||||
// CreateMcuManager();
|
// CreateMcuManager();
|
||||||
|
@ -44,6 +45,7 @@ public:
|
||||||
virtual void TearDown()
|
virtual void TearDown()
|
||||||
{
|
{
|
||||||
HalTestTool::UnInit();
|
HalTestTool::UnInit();
|
||||||
|
DeviceManagerTestTool::UnInit();
|
||||||
DestroyDeviceManagerModule();
|
DestroyDeviceManagerModule();
|
||||||
DestroyAllKeysMock();
|
DestroyAllKeysMock();
|
||||||
}
|
}
|
||||||
|
@ -76,6 +78,8 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyShortPress)
|
||||||
{
|
{
|
||||||
SetAllKeysResult(mAllKeysMock);
|
SetAllKeysResult(mAllKeysMock);
|
||||||
IDeviceManager::GetInstance()->Init();
|
IDeviceManager::GetInstance()->Init();
|
||||||
|
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||||
|
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||||
SetKeyClick(KEY_TEST); // Simulate pressing a button.
|
SetKeyClick(KEY_TEST); // Simulate pressing a button.
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
IDeviceManager::GetInstance()->UnInit();
|
IDeviceManager::GetInstance()->UnInit();
|
||||||
|
@ -91,6 +95,8 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyLongPress)
|
||||||
{
|
{
|
||||||
SetAllKeysResult(mAllKeysMock);
|
SetAllKeysResult(mAllKeysMock);
|
||||||
IDeviceManager::GetInstance()->Init();
|
IDeviceManager::GetInstance()->Init();
|
||||||
|
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||||
|
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||||
SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
IDeviceManager::GetInstance()->UnInit();
|
IDeviceManager::GetInstance()->UnInit();
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#include "DeviceManagerMakePtrTest.h"
|
#include "DeviceManagerMakePtrTest.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
void OverrideHalMakePtrObject(std::shared_ptr<DeviceManagerMock> &halMock)
|
void OverrideDeviceMakePtrObject(std::shared_ptr<DeviceManagerMock> &halMock)
|
||||||
{
|
{
|
||||||
std::shared_ptr<DeviceManagerMakePtr> impl = std::make_shared<DeviceManagerMakePtrTest>();
|
std::shared_ptr<DeviceManagerMakePtr> impl = std::make_shared<DeviceManagerMakePtrTest>();
|
||||||
std::shared_ptr<DeviceManagerMakePtrTest> test = std::dynamic_pointer_cast<DeviceManagerMakePtrTest>(impl);
|
std::shared_ptr<DeviceManagerMakePtrTest> test = std::dynamic_pointer_cast<DeviceManagerMakePtrTest>(impl);
|
||||||
|
@ -23,13 +23,15 @@ void OverrideHalMakePtrObject(std::shared_ptr<DeviceManagerMock> &halMock)
|
||||||
}
|
}
|
||||||
DeviceManagerMakePtr::GetInstance(&impl);
|
DeviceManagerMakePtr::GetInstance(&impl);
|
||||||
}
|
}
|
||||||
void CancelOverrideHalMakePtrObject(void)
|
void CancelOverrideDeviceMakePtrObject(void)
|
||||||
{
|
{
|
||||||
std::shared_ptr<DeviceManagerMakePtr> tmp = DeviceManagerMakePtr::GetInstance();
|
std::shared_ptr<DeviceManagerMakePtr> tmp = DeviceManagerMakePtr::GetInstance();
|
||||||
std::shared_ptr<DeviceManagerMakePtrTest> test = std::dynamic_pointer_cast<DeviceManagerMakePtrTest>(tmp);
|
std::shared_ptr<DeviceManagerMakePtrTest> test = std::dynamic_pointer_cast<DeviceManagerMakePtrTest>(tmp);
|
||||||
if (test) {
|
if (test) {
|
||||||
test->mDeviceManagerMock.reset();
|
test->mDeviceManagerMock.reset();
|
||||||
}
|
}
|
||||||
|
test.reset();
|
||||||
|
tmp.reset();
|
||||||
std::shared_ptr<DeviceManagerMakePtr> impl = std::make_shared<DeviceManagerMakePtrTest>();
|
std::shared_ptr<DeviceManagerMakePtr> impl = std::make_shared<DeviceManagerMakePtrTest>();
|
||||||
DeviceManagerMakePtr::GetInstance(&impl);
|
DeviceManagerMakePtr::GetInstance(&impl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,18 @@ void DeviceManagerTestTool::Init(void)
|
||||||
void DeviceManagerTestTool::UnInit(void)
|
void DeviceManagerTestTool::UnInit(void)
|
||||||
{
|
{
|
||||||
mDeviceManagerMock.reset();
|
mDeviceManagerMock.reset();
|
||||||
|
mKeyMonitorMock.reset();
|
||||||
CancelOverrideDeviceMakePtrObject();
|
CancelOverrideDeviceMakePtrObject();
|
||||||
}
|
}
|
||||||
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) {
|
||||||
|
LogInfo("mKeyMonitorMock get.\n");
|
||||||
mKeyMonitorMock = std::dynamic_pointer_cast<KeyMonitorMock>(monitor);
|
mKeyMonitorMock = std::dynamic_pointer_cast<KeyMonitorMock>(monitor);
|
||||||
};
|
};
|
||||||
constexpr int ONLY_BE_CALLED_ONCE = 1;
|
constexpr int ONLY_BE_CALLED_ONCE = 1;
|
||||||
EXPECT_CALL(*mock.get(), SetAllKeysMonitorTrace(_))
|
EXPECT_CALL(*mock.get(), SetAllKeysMonitorTrace(_))
|
||||||
.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))));
|
||||||
}
|
}
|
|
@ -16,8 +16,11 @@
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
static const char *StatusCodeString[STATUS_CODE_END + 1] = {
|
static const char *StatusCodeString[STATUS_CODE_END + 1] = {"STATUS_CODE_OK",
|
||||||
"STATUS_CODE_OK", "STATUS_CODE_NOT_OK", "STATUS_CODE_INVALID_PARAMENTER", "STATUS_CODE_END"};
|
"STATUS_CODE_NOT_OK",
|
||||||
|
"STATUS_CODE_VIRTUAL_FUNCTION",
|
||||||
|
"STATUS_CODE_INVALID_PARAMENTER",
|
||||||
|
"STATUS_CODE_END"};
|
||||||
static const char *_PrintStringCode_(const StatusCode this)
|
static const char *_PrintStringCode_(const StatusCode this)
|
||||||
{
|
{
|
||||||
if (STATUS_CODE_OK <= this.mStatusCode && this.mStatusCode <= STATUS_CODE_END) {
|
if (STATUS_CODE_OK <= this.mStatusCode && this.mStatusCode <= STATUS_CODE_END) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user