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