/* * 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 "HalTestTool.h" #include "IDeviceManager.h" #include "ILog.h" #include #include #include namespace DeviceManagerTest { const char *KEY_TEST = "TEST"; class DeviceManagerTest : public testing::Test, public HalTestTool, public DeviceManagerTestTool { public: DeviceManagerTest() {} virtual ~DeviceManagerTest() {} static void SetUpTestCase() { CreateLogModule(); ILogInit(LOG_INSTANCE_TYPE_END); } static void TearDownTestCase() { ILogUnInit(); } virtual void SetUp() { CreateAllKeysMcok(); HalTestTool::Init(); CreateHalCppModule(); CreateDeviceManagerModule(); // CreateMcuManager(); } virtual void TearDown() { HalTestTool::UnInit(); DestroyDeviceManagerModule(); DestroyAllKeysMock(); } private: void CreateAllKeysMcok(void) { std::shared_ptr key = std::make_shared(KEY_TEST); mAllKeysMock[KEY_TEST] = key; } void DestroyAllKeysMock(void) { // mAllKeysMock.clear(); } public: // std::shared_ptr mLinuxTest; protected: std::map> mAllKeysMock; }; // ../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(); 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(); } // ../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