Add:DeviceManager key test case.
This commit is contained in:
parent
5989d9df2d
commit
73236bba8f
|
@ -36,6 +36,7 @@ void KeyManager::Init(void)
|
||||||
void KeyManager::UnInit(void)
|
void KeyManager::UnInit(void)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
StopTimer();
|
||||||
mAllKeyHal.clear();
|
mAllKeyHal.clear();
|
||||||
}
|
}
|
||||||
void KeyManager::StartTimer(void)
|
void KeyManager::StartTimer(void)
|
||||||
|
|
|
@ -121,6 +121,8 @@ private:
|
||||||
void HalMockInit(std::shared_ptr<HalCppMock> &mock);
|
void HalMockInit(std::shared_ptr<HalCppMock> &mock);
|
||||||
void SetAllKeysResult(std::shared_ptr<HalCppMock> &mock, std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
void SetAllKeysResult(std::shared_ptr<HalCppMock> &mock, std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||||
std::shared_ptr<KeyControlMock> SearchKey(const std::string &keyName);
|
std::shared_ptr<KeyControlMock> SearchKey(const std::string &keyName);
|
||||||
|
void InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||||
|
void InitKeysMock(std::shared_ptr<KeyControlMock> &mock);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<HalCppMock> mHalMock;
|
std::shared_ptr<HalCppMock> mHalMock;
|
||||||
|
|
|
@ -151,6 +151,7 @@ void HalTestTool::SetAllKeysResult(std::shared_ptr<HalCppMock> &mock,
|
||||||
{
|
{
|
||||||
EXPECT_CALL(*mock.get(), GetAllKeysTrace(_))
|
EXPECT_CALL(*mock.get(), GetAllKeysTrace(_))
|
||||||
.WillRepeatedly(DoAll(SetArgReferee<0>(allKeys), Return(CreateStatusCode(STATUS_CODE_OK))));
|
.WillRepeatedly(DoAll(SetArgReferee<0>(allKeys), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||||
|
InitAllKeysMock(allKeys);
|
||||||
}
|
}
|
||||||
std::shared_ptr<KeyControlMock> HalTestTool::SearchKey(const std::string &keyName)
|
std::shared_ptr<KeyControlMock> HalTestTool::SearchKey(const std::string &keyName)
|
||||||
{
|
{
|
||||||
|
@ -165,6 +166,25 @@ std::shared_ptr<KeyControlMock> HalTestTool::SearchKey(const std::string &keyNam
|
||||||
}
|
}
|
||||||
return mock;
|
return mock;
|
||||||
}
|
}
|
||||||
|
void HalTestTool::InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||||
|
{
|
||||||
|
std::map<std::string, std::shared_ptr<VKeyHal>>::iterator iter;
|
||||||
|
for (iter = allKeys.begin(); iter != allKeys.end(); ++iter) {
|
||||||
|
std::shared_ptr<VKeyHal> keyHal = iter->second;
|
||||||
|
std::shared_ptr<KeyControlMock> mock = std::dynamic_pointer_cast<KeyControlMock>(keyHal);
|
||||||
|
if (mock) {
|
||||||
|
InitKeysMock(mock);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("Invalid key mock.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void HalTestTool::InitKeysMock(std::shared_ptr<KeyControlMock> &mock)
|
||||||
|
{
|
||||||
|
EXPECT_CALL(*mock.get(), KeyEventTriggerTrace(_, _, _))
|
||||||
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
}
|
||||||
void HalTestTool::HalMockInit(std::shared_ptr<HalCppMock> &mock)
|
void HalTestTool::HalMockInit(std::shared_ptr<HalCppMock> &mock)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(*mock.get(), GetLedHalsTrace(_))
|
EXPECT_CALL(*mock.get(), GetLedHalsTrace(_))
|
||||||
|
|
|
@ -64,15 +64,34 @@ public:
|
||||||
protected:
|
protected:
|
||||||
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeysMock;
|
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeysMock;
|
||||||
};
|
};
|
||||||
// ../output_files/test/bin/DeviceManagerTest --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_Demo
|
// ../output_files/test/bin/DeviceManagerTest
|
||||||
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_Demo)
|
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyShortPress
|
||||||
|
/**
|
||||||
|
* @brief Construct a new test f object
|
||||||
|
* This test case demonstrates whether DeviceManager can reprocess key events and report them to the application when
|
||||||
|
* they are triggered.
|
||||||
|
*/
|
||||||
|
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyShortPress)
|
||||||
{
|
{
|
||||||
SetAllKeysResult(mAllKeysMock);
|
SetAllKeysResult(mAllKeysMock);
|
||||||
IDeviceManager::GetInstance()->Init();
|
IDeviceManager::GetInstance()->Init();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
SetKeyClick(KEY_TEST); // Simulate pressing a button.
|
||||||
// SetKeyEvent(KEY_TEST, KeyHalEvent::PRESSING);
|
|
||||||
SetKeyClick(KEY_TEST);
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
IDeviceManager::GetInstance()->UnInit();
|
IDeviceManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
|
// ../output_files/test/bin/DeviceManagerTest
|
||||||
|
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyLongPress
|
||||||
|
/**
|
||||||
|
* @brief Construct a new test f object
|
||||||
|
* This test case demonstrates whether DeviceManager can reprocess key events and report them to the application when
|
||||||
|
* they are triggered.
|
||||||
|
*/
|
||||||
|
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyLongPress)
|
||||||
|
{
|
||||||
|
SetAllKeysResult(mAllKeysMock);
|
||||||
|
IDeviceManager::GetInstance()->Init();
|
||||||
|
SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
|
IDeviceManager::GetInstance()->UnInit();
|
||||||
|
}
|
||||||
} // namespace DeviceManagerTest
|
} // namespace DeviceManagerTest
|
Loading…
Reference in New Issue
Block a user