Add:DeviceManager key test case.

This commit is contained in:
Fancy code 2024-02-16 23:36:39 -08:00
parent 5989d9df2d
commit 73236bba8f
4 changed files with 47 additions and 5 deletions

View File

@ -36,6 +36,7 @@ void KeyManager::Init(void)
void KeyManager::UnInit(void)
{
//
StopTimer();
mAllKeyHal.clear();
}
void KeyManager::StartTimer(void)

View File

@ -121,6 +121,8 @@ private:
void HalMockInit(std::shared_ptr<HalCppMock> &mock);
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);
void InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
void InitKeysMock(std::shared_ptr<KeyControlMock> &mock);
private:
std::shared_ptr<HalCppMock> mHalMock;

View File

@ -151,6 +151,7 @@ void HalTestTool::SetAllKeysResult(std::shared_ptr<HalCppMock> &mock,
{
EXPECT_CALL(*mock.get(), GetAllKeysTrace(_))
.WillRepeatedly(DoAll(SetArgReferee<0>(allKeys), Return(CreateStatusCode(STATUS_CODE_OK))));
InitAllKeysMock(allKeys);
}
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;
}
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)
{
EXPECT_CALL(*mock.get(), GetLedHalsTrace(_))

View File

@ -64,15 +64,34 @@ public:
protected:
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeysMock;
};
// ../output_files/test/bin/DeviceManagerTest --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_Demo
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_Demo)
// ../output_files/test/bin/DeviceManagerTest
// --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);
IDeviceManager::GetInstance()->Init();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// SetKeyEvent(KEY_TEST, KeyHalEvent::PRESSING);
SetKeyClick(KEY_TEST);
SetKeyClick(KEY_TEST); // Simulate pressing a button.
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
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