From 0de968d42e91bcef71ec48d39f0cae764e73fd95 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Sat, 17 Feb 2024 19:44:55 -0800 Subject: [PATCH] Improve:DeviceManager test tool. --- middleware/DeviceManager/src/DeviceManager.cpp | 1 + test/middleware/DeviceManager/src/DeviceManager_Test.cpp | 6 ++++++ .../DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp | 6 ++++-- .../DeviceManager/tool/src/DeviceManagerTestTool.cpp | 6 ++++-- utils/StatusCode/src/StatusCode.c | 7 +++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/middleware/DeviceManager/src/DeviceManager.cpp b/middleware/DeviceManager/src/DeviceManager.cpp index 02c1b19f..f4193c5b 100644 --- a/middleware/DeviceManager/src/DeviceManager.cpp +++ b/middleware/DeviceManager/src/DeviceManager.cpp @@ -32,5 +32,6 @@ const StatusCode DeviceManager::UnInit(void) } const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr &monitor) { + LogInfo("DeviceManager::SetAllKeysMonitor\n"); return KeyManager::GetInstance()->SetKeyMonitor(monitor); } diff --git a/test/middleware/DeviceManager/src/DeviceManager_Test.cpp b/test/middleware/DeviceManager/src/DeviceManager_Test.cpp index 84bd1a6b..46d178d5 100644 --- a/test/middleware/DeviceManager/src/DeviceManager_Test.cpp +++ b/test/middleware/DeviceManager/src/DeviceManager_Test.cpp @@ -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 monitor = std::make_shared(); + 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 monitor = std::make_shared(); + IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor); SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button. std::this_thread::sleep_for(std::chrono::milliseconds(2000)); IDeviceManager::GetInstance()->UnInit(); diff --git a/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp b/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp index 34e71ed3..0391b04b 100644 --- a/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp +++ b/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp @@ -14,7 +14,7 @@ */ #include "DeviceManagerMakePtrTest.h" #include "ILog.h" -void OverrideHalMakePtrObject(std::shared_ptr &halMock) +void OverrideDeviceMakePtrObject(std::shared_ptr &halMock) { std::shared_ptr impl = std::make_shared(); std::shared_ptr test = std::dynamic_pointer_cast(impl); @@ -23,13 +23,15 @@ void OverrideHalMakePtrObject(std::shared_ptr &halMock) } DeviceManagerMakePtr::GetInstance(&impl); } -void CancelOverrideHalMakePtrObject(void) +void CancelOverrideDeviceMakePtrObject(void) { std::shared_ptr tmp = DeviceManagerMakePtr::GetInstance(); std::shared_ptr test = std::dynamic_pointer_cast(tmp); if (test) { test->mDeviceManagerMock.reset(); } + test.reset(); + tmp.reset(); std::shared_ptr impl = std::make_shared(); DeviceManagerMakePtr::GetInstance(&impl); } diff --git a/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp b/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp index 69894fec..e13f05d5 100644 --- a/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp +++ b/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp @@ -33,16 +33,18 @@ void DeviceManagerTestTool::Init(void) void DeviceManagerTestTool::UnInit(void) { mDeviceManagerMock.reset(); + mKeyMonitorMock.reset(); CancelOverrideDeviceMakePtrObject(); } void DeviceManagerTestTool::DeviceManagerMockInit(std::shared_ptr &mock) { auto getKeyMonitor = [=](std::shared_ptr &monitor) { + LogInfo("mKeyMonitorMock get.\n"); mKeyMonitorMock = std::dynamic_pointer_cast(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)))); } \ No newline at end of file diff --git a/utils/StatusCode/src/StatusCode.c b/utils/StatusCode/src/StatusCode.c index e9106385..fa86750d 100644 --- a/utils/StatusCode/src/StatusCode.c +++ b/utils/StatusCode/src/StatusCode.c @@ -16,8 +16,11 @@ #include "ILog.h" #include #include -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) {