From 10921b1b57be8c3faba9128dea70efbed3609667 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Sat, 17 Feb 2024 10:17:53 -0800 Subject: [PATCH] Add:DeviceManager test tool. --- .../DeviceManager/include/IDeviceManager.h | 8 ++ .../DeviceManager/src/DeviceManager.cpp | 4 + middleware/DeviceManager/src/DeviceManager.h | 1 + .../DeviceManager/src/IDeviceManager.cpp | 4 + middleware/DeviceManager/src/KeyManager.cpp | 20 +++- middleware/DeviceManager/src/KeyManager.h | 6 +- test/middleware/DeviceManager/CMakeLists.txt | 12 +-- .../DeviceManager/src/DeviceManager_Test.cpp | 15 ++- .../DeviceManager/tool/CMakeLists.txt | 52 +++++++++++ .../tool/include/DeviceManagerTestTool.h | 91 +++++++++++++++++++ .../tool/src/DeviceManagerMakePtrTest.cpp | 55 +++++++++++ .../tool/src/DeviceManagerMakePtrTest.h | 31 +++++++ .../tool/src/DeviceManagerTestTool.cpp | 48 ++++++++++ 13 files changed, 335 insertions(+), 12 deletions(-) create mode 100644 test/middleware/DeviceManager/tool/CMakeLists.txt create mode 100644 test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h create mode 100644 test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp create mode 100644 test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.h create mode 100644 test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp diff --git a/middleware/DeviceManager/include/IDeviceManager.h b/middleware/DeviceManager/include/IDeviceManager.h index 9f16d61..0690fcb 100644 --- a/middleware/DeviceManager/include/IDeviceManager.h +++ b/middleware/DeviceManager/include/IDeviceManager.h @@ -31,6 +31,13 @@ typedef struct key_status const VirtualKeyEvent mKeyEvent; const long int mHoldTimeMs; } KeyStatus; +class VKeyMonitor +{ +public: + VKeyMonitor() = default; + virtual ~VKeyMonitor() = default; + void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) {} +}; class IDeviceManager { public: @@ -41,5 +48,6 @@ public: virtual const StatusCode UnInit(void); virtual const StatusCode SetLedState(const std::string &ledName, const VirtualLedState ¤tState, const unsigned int &KeepAliveTime, const unsigned int &blinkPeriod); + virtual const StatusCode SetAllKeysMonitor(std::shared_ptr &monitor); }; #endif \ No newline at end of file diff --git a/middleware/DeviceManager/src/DeviceManager.cpp b/middleware/DeviceManager/src/DeviceManager.cpp index e38ad59..02c1b19 100644 --- a/middleware/DeviceManager/src/DeviceManager.cpp +++ b/middleware/DeviceManager/src/DeviceManager.cpp @@ -30,3 +30,7 @@ const StatusCode DeviceManager::UnInit(void) KeyManager::GetInstance()->UnInit(); return CreateStatusCode(STATUS_CODE_OK); } +const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr &monitor) +{ + return KeyManager::GetInstance()->SetKeyMonitor(monitor); +} diff --git a/middleware/DeviceManager/src/DeviceManager.h b/middleware/DeviceManager/src/DeviceManager.h index f47cc2e..b07a4dd 100644 --- a/middleware/DeviceManager/src/DeviceManager.h +++ b/middleware/DeviceManager/src/DeviceManager.h @@ -28,6 +28,7 @@ public: // const StatusCode SetLedState(const std::string &ledName, const VirtualLedState ¤tState, // const unsigned int &keepAliveTime = DEFAULT_KEEP_ALIVE_TIME, // const unsigned int &blinkPeriod = LED_NOT_BLINK) override; + const StatusCode SetAllKeysMonitor(std::shared_ptr &monitor) override; private: // std::vector> mLedManagers; diff --git a/middleware/DeviceManager/src/IDeviceManager.cpp b/middleware/DeviceManager/src/IDeviceManager.cpp index 38efd80..89dbbf0 100644 --- a/middleware/DeviceManager/src/IDeviceManager.cpp +++ b/middleware/DeviceManager/src/IDeviceManager.cpp @@ -32,6 +32,10 @@ const StatusCode IDeviceManager::Init(void) { return CreateStatusCode(STATUS_COD const StatusCode IDeviceManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } const StatusCode IDeviceManager::SetLedState(const std::string &ledName, const VirtualLedState ¤tState, const unsigned int &KeepAliveTime, const unsigned int &blinkPeriod) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +const StatusCode IDeviceManager::SetAllKeysMonitor(std::shared_ptr &monitor) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/middleware/DeviceManager/src/KeyManager.cpp b/middleware/DeviceManager/src/KeyManager.cpp index 6e3201f..d3f6b2d 100644 --- a/middleware/DeviceManager/src/KeyManager.cpp +++ b/middleware/DeviceManager/src/KeyManager.cpp @@ -28,6 +28,10 @@ std::shared_ptr &KeyManager::GetInstance(std::shared_ptr } return instance; } +KeyManager::KeyManager() +{ + // +} void KeyManager::Init(void) { // @@ -45,7 +49,7 @@ void KeyManager::StartTimer(void) LogError("StartTimer failed, no key to manager.\n"); return; } - SetAllKeysMonitor(); + SetKeyHalMonitor(); auto timerThread = [](std::shared_ptr timer) { LogInfo("Key timer started.\n"); timer->Timer(); @@ -83,7 +87,12 @@ void KeyManager::GetAllKeysState(std::map &status) status.insert(std::make_pair(iter->first, result)); } } -void KeyManager::SetAllKeysMonitor(void) +const StatusCode KeyManager::SetKeyMonitor(std::shared_ptr &monitor) +{ + mKeyMonitor = monitor; + return CreateStatusCode(STATUS_CODE_OK); +} +void KeyManager::SetKeyHalMonitor(void) { std::shared_ptr monitor = shared_from_this(); std::map>::iterator iter; @@ -94,5 +103,10 @@ void KeyManager::SetAllKeysMonitor(void) } void KeyManager::KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) { - // + auto monitor = mKeyMonitor.lock(); + if (mKeyMonitor.expired()) { + LogError("monitor is nullptr.\n"); + return; + } + monitor->KeyEventReport(keyName, static_cast(event), timeMs); } \ No newline at end of file diff --git a/middleware/DeviceManager/src/KeyManager.h b/middleware/DeviceManager/src/KeyManager.h index d394990..dea867f 100644 --- a/middleware/DeviceManager/src/KeyManager.h +++ b/middleware/DeviceManager/src/KeyManager.h @@ -23,7 +23,7 @@ class KeyManager : public VKeyHalMonitor, public std::enable_shared_from_this { public: - KeyManager() = default; + KeyManager(); ~KeyManager() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); void Init(void); @@ -32,9 +32,10 @@ public: void StopTimer(void); void Timer(void); void GetAllKeysState(std::map &status); + const StatusCode SetKeyMonitor(std::shared_ptr &monitor); private: - void SetAllKeysMonitor(void); + void SetKeyHalMonitor(void); private: void KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event, @@ -45,5 +46,6 @@ private: std::map> mAllKeyHal; bool mTimerRuning; std::thread mTimer; + std::weak_ptr mKeyMonitor; }; #endif \ No newline at end of file diff --git a/test/middleware/DeviceManager/CMakeLists.txt b/test/middleware/DeviceManager/CMakeLists.txt index c55ef3d..54a3a05 100644 --- a/test/middleware/DeviceManager/CMakeLists.txt +++ b/test/middleware/DeviceManager/CMakeLists.txt @@ -8,15 +8,15 @@ include_directories( ./tool/include ${UTILS_SOURCE_PATH}/Log/include ${UTILS_SOURCE_PATH}/StatusCode/include - ${UTILS_SOURCE_PATH}/UartDevice/include - ${UTILS_SOURCE_PATH}/McuProtocol/include + # ${UTILS_SOURCE_PATH}/UartDevice/include + # ${UTILS_SOURCE_PATH}/McuProtocol/include ${UTILS_SOURCE_PATH}/KeyControl/include ${HAL_SOURCE_PATH}/include ${HAL_SOURCE_PATH}/src ${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include ${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src - ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include - ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + # ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include + # ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include ${TEST_SOURCE_PATH}/hal/tool/include # ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include # ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include @@ -40,7 +40,7 @@ endif() set(TARGET_NAME DeviceManagerTest) add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} DeviceManager HalTestTool gtest gmock pthread) +target_link_libraries(${TARGET_NAME} DeviceManager DeviceManagerTestTool HalTestTool gtest gmock pthread) if(${TEST_COVERAGE} MATCHES "true") target_link_libraries(${TARGET_NAME} gcov) endif() @@ -85,4 +85,4 @@ endif() define_file_name(${TARGET_NAME}) -# add_subdirectory(tool) \ No newline at end of file +add_subdirectory(tool) \ No newline at end of file diff --git a/test/middleware/DeviceManager/src/DeviceManager_Test.cpp b/test/middleware/DeviceManager/src/DeviceManager_Test.cpp index 04ac955..84bd1a6 100644 --- a/test/middleware/DeviceManager/src/DeviceManager_Test.cpp +++ b/test/middleware/DeviceManager/src/DeviceManager_Test.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "DeviceManagerTestTool.h" #include "HalTestTool.h" #include "IDeviceManager.h" #include "ILog.h" @@ -21,7 +22,7 @@ namespace DeviceManagerTest { const char *KEY_TEST = "TEST"; -class DeviceManagerTest : public testing::Test, public HalTestTool +class DeviceManagerTest : public testing::Test, public HalTestTool, public DeviceManagerTestTool { public: DeviceManagerTest() {} @@ -94,4 +95,16 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyLongPress) std::this_thread::sleep_for(std::chrono::milliseconds(2000)); IDeviceManager::GetInstance()->UnInit(); } +// ../output_files/test/bin/DeviceManagerTest +// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_SetKeyMonitor +TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_SetKeyMonitor) +{ + 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(); +} } // namespace DeviceManagerTest \ No newline at end of file diff --git a/test/middleware/DeviceManager/tool/CMakeLists.txt b/test/middleware/DeviceManager/tool/CMakeLists.txt new file mode 100644 index 0000000..cab4304 --- /dev/null +++ b/test/middleware/DeviceManager/tool/CMakeLists.txt @@ -0,0 +1,52 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) +set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) + +include_directories( + ./src + ./include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/McuProtocol/include + ${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src + ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) +aux_source_directory(./src TEST_TOOL_SRC_FILES) +set(TEST_TOOL_TARGET DeviceManagerTestTool) +add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) +target_link_libraries(${TEST_TOOL_TARGET} Log) + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + DeviceManagerTestTool_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${TEST_TOOL_SRC_FILES} + ${CLANG_TIDY_CONFIG} + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/DeviceManager/tool +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + DeviceManagerTestTool_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${TEST_TOOL_SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/DeviceManager/tool +) +add_custom_command( + TARGET ${TEST_TOOL_TARGET} + PRE_BUILD + COMMAND make DeviceManagerTestTool_code_check + COMMAND make DeviceManagerTestTool_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TEST_TOOL_TARGET}) \ No newline at end of file diff --git a/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h b/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h new file mode 100644 index 0000000..912d8f9 --- /dev/null +++ b/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DEVICE_MANAGER_TEST_TOOL_H +#define DEVICE_MANAGER_TEST_TOOL_H +#include "DeviceManager.h" +#include +#include +using ::testing::_; +using ::testing::Action; +using ::testing::ActionInterface; +using ::testing::AnyNumber; +using ::testing::Assign; +using ::testing::AtLeast; +using ::testing::ByMove; +using ::testing::ByRef; +using ::testing::DefaultValue; +using ::testing::DoAll; +using ::testing::DoDefault; +using ::testing::IgnoreResult; +using ::testing::Invoke; +using ::testing::InvokeWithoutArgs; +using ::testing::MakePolymorphicAction; +using ::testing::PolymorphicAction; +using ::testing::Return; +using ::testing::ReturnNew; +using ::testing::ReturnNull; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::ReturnRefOfCopy; +using ::testing::ReturnRoundRobin; +using ::testing::SaveArg; +using ::testing::SetArgPointee; +using ::testing::SetArgumentPointee; +using ::testing::Unused; +using ::testing::WithArgs; +using ::testing::internal::BuiltInDefaultValue; +class DeviceManagerTool : public DeviceManager +{ +public: + DeviceManagerTool() = default; + virtual ~DeviceManagerTool() = default; + const StatusCode SetAllKeysMonitor(std::shared_ptr &monitor) override; + +private: + virtual const StatusCode SetAllKeysMonitorTrace(std::shared_ptr &monitor) + { + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + } +}; +class DeviceManagerMock : public DeviceManagerTool +{ +public: + DeviceManagerMock() = default; + virtual ~DeviceManagerMock() = default; + MOCK_METHOD1(SetAllKeysMonitorTrace, const StatusCode(std::shared_ptr &)); +}; +class KeyMonitorMock : public VKeyMonitor +{ +public: + KeyMonitorMock() = default; + virtual ~KeyMonitorMock() = default; + MOCK_METHOD3(KeyEventReport, void(const std::string &, const VirtualKeyEvent &, const unsigned int &)); +}; +class DeviceManagerTestTool +{ +public: + DeviceManagerTestTool() = default; + virtual ~DeviceManagerTestTool() = default; + void Init(void); + void UnInit(void); + +private: + void DeviceManagerMockInit(std::shared_ptr &mock); + +private: + std::shared_ptr mDeviceManagerMock; + std::shared_ptr mKeyMonitorMock; +}; +#endif \ No newline at end of file diff --git a/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp b/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp new file mode 100644 index 0000000..34e71ed --- /dev/null +++ b/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "DeviceManagerMakePtrTest.h" +#include "ILog.h" +void OverrideHalMakePtrObject(std::shared_ptr &halMock) +{ + std::shared_ptr impl = std::make_shared(); + std::shared_ptr test = std::dynamic_pointer_cast(impl); + if (test) { + test->mDeviceManagerMock = halMock; + } + DeviceManagerMakePtr::GetInstance(&impl); +} +void CancelOverrideHalMakePtrObject(void) +{ + std::shared_ptr tmp = DeviceManagerMakePtr::GetInstance(); + std::shared_ptr test = std::dynamic_pointer_cast(tmp); + if (test) { + test->mDeviceManagerMock.reset(); + } + std::shared_ptr impl = std::make_shared(); + DeviceManagerMakePtr::GetInstance(&impl); +} +DeviceManagerMakePtrTest::DeviceManagerMakePtrTest() +{ + // +} +DeviceManagerMakePtrTest::~DeviceManagerMakePtrTest() +{ + // + mDeviceManagerMock.reset(); +} +const StatusCode DeviceManagerMakePtrTest::CreateDeviceManager(std::shared_ptr &impl) +{ + if (mDeviceManagerMock) { + LogInfo("CreateDeviceManager mDeviceManagerMock\n"); + impl = mDeviceManagerMock; + } + else { + LogWarning("CreateMcuManager failed:mDeviceManagerMock is nullptr.\n"); + } + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.h b/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.h new file mode 100644 index 0000000..c35ccc6 --- /dev/null +++ b/test/middleware/DeviceManager/tool/src/DeviceManagerMakePtrTest.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DEVICE_MANAGER_MAKE_PTR_TEST_H +#define DEVICE_MANAGER_MAKE_PTR_TEST_H +#include "DeviceManagerMakePtr.h" +#include "DeviceManagerTestTool.h" +void OverrideDeviceMakePtrObject(std::shared_ptr &halMock); +void CancelOverrideDeviceMakePtrObject(void); +class DeviceManagerMakePtrTest : public DeviceManagerMakePtr +{ +public: + DeviceManagerMakePtrTest(); + virtual ~DeviceManagerMakePtrTest(); + const StatusCode CreateDeviceManager(std::shared_ptr &impl) override; + +public: + std::shared_ptr mDeviceManagerMock; +}; +#endif \ No newline at end of file diff --git a/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp b/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp new file mode 100644 index 0000000..69894fe --- /dev/null +++ b/test/middleware/DeviceManager/tool/src/DeviceManagerTestTool.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "DeviceManagerTestTool.h" +#include "DeviceManagerMakePtrTest.h" +#include "ILog.h" +const StatusCode DeviceManagerTool::SetAllKeysMonitor(std::shared_ptr &monitor) +{ + LogInfo("DeviceManagerTool::SetAllKeysMonitor\n"); + StatusCode code = SetAllKeysMonitorTrace(monitor); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return DeviceManager::SetAllKeysMonitor(monitor); + } + return code; +} +void DeviceManagerTestTool::Init(void) +{ + mDeviceManagerMock = std::make_shared(); + DeviceManagerMockInit(mDeviceManagerMock); + OverrideDeviceMakePtrObject(mDeviceManagerMock); +} +void DeviceManagerTestTool::UnInit(void) +{ + mDeviceManagerMock.reset(); + CancelOverrideDeviceMakePtrObject(); +} +void DeviceManagerTestTool::DeviceManagerMockInit(std::shared_ptr &mock) +{ + auto getKeyMonitor = [=](std::shared_ptr &monitor) { + 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)))); +} \ No newline at end of file