diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index e11c70997bc5af57d2e25450f0294fe0a7f449a2..91ab8d95e0f4a8d5031010d72d8a164788b05b16 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -858,12 +858,12 @@ void PowerKeySuspendMonitor::EndPowerkeyScreenOff() const void PowerKeySuspendMonitor::Cancel() { +#ifdef HAS_MULTIMODALINPUT_INPUT_PART auto inputManager = InputManager::GetInstance(); if (!inputManager) { POWER_HILOGE(FEATURE_SUSPEND, "PowerKeySuspendMonitorCancel inputManager is null"); return; } -#ifdef HAS_MULTIMODALINPUT_INPUT_PART if (powerkeyReleaseId_ >= 0) { POWER_HILOGI(FEATURE_SUSPEND, "UnsubscribeKeyEvent: PowerKeySuspendMonitor"); inputManager->UnsubscribeKeyEvent(powerkeyReleaseId_); diff --git a/services/native/src/wakeup/wakeup_controller.cpp b/services/native/src/wakeup/wakeup_controller.cpp index 948a064ee9f4447ac6a83bc21f23bd8dbf4301a6..c3b499f313b6ef30a854d2048a9cf8aca31abb2a 100644 --- a/services/native/src/wakeup/wakeup_controller.cpp +++ b/services/native/src/wakeup/wakeup_controller.cpp @@ -24,7 +24,9 @@ #include #endif #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include #include "permission.h" @@ -939,6 +941,7 @@ std::shared_ptr WakeupMonitor::CreateMonitor(WakeupSource& source /** PowerkeyWakeupMonitor Implement */ bool PowerkeyWakeupMonitor::Init() { +#ifdef HAS_MULTIMODALINPUT_INPUT_PART if (powerkeyShortPressId_ >= 0) { return true; } @@ -969,6 +972,9 @@ bool PowerkeyWakeupMonitor::Init() POWER_HILOGI(FEATURE_WAKEUP, "powerkey register powerkeyShortPressId_=%{public}d", powerkeyShortPressId_); return powerkeyShortPressId_ >= 0 ? true : false; +#else + return false; +#endif } void PowerkeyWakeupMonitor::ReceivePowerkeyCallback(std::shared_ptr keyEvent) @@ -1023,6 +1029,7 @@ void PowerkeyWakeupMonitor::ReceivePowerkeyCallback(std::shared_ptrUnsubscribeKeyEvent(powerkeyShortPressId_); } +#endif } /** Keyboard Implement */ diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 399d57e1656582713861af8e802cd95e1937455f..ec8a69ae92520ad0c484b46dd61c2c29679c9235 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -70,7 +70,6 @@ deps_ex = [ "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", - "input:libmmi-client", "ipc:ipc_core", "libxml2:libxml2", "power_manager:power_ffrt", @@ -80,6 +79,9 @@ deps_ex = [ "window_manager:libwm_lite", ] +if (has_multimodalinput_input_part) { + deps_ex += [ "input:libmmi-client" ] +} if (has_sensors_sensor_part) { deps_ex += [ "sensor:sensor_interface_native" ] } @@ -1132,6 +1134,32 @@ ohos_unittest("test_power_suspend_controller") { } } +ohos_unittest("test_power_suspend_controller_option") { + module_out_path = module_output_path + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + + sources = [ "src/interface_test/power_suspend_controller_option_test.cpp" ] + + configs = [ + "${powermgr_utils_path}:utils_config", + ":module_private_config", + ":module_mock_private_config", + "${powermgr_utils_path}:coverage_flags", + ] + + defines += [ "POWERMGR_GTEST" ] + + deps = [ "${powermgr_service_path}:powermgrservice" ] + + external_deps = deps_ex +} + ohos_unittest("test_power_suspend") { module_out_path = module_output_path @@ -1729,6 +1757,7 @@ group("unittest") { ":test_power_state_machine", ":test_power_suspend", ":test_power_suspend_controller", + ":test_power_suspend_controller_option", ":test_power_suspend_parse", ":test_power_wakeup", ":test_power_wakeup_controller", diff --git a/test/unittest/include/interface_test/power_suspend_controller_option_test.h b/test/unittest/include/interface_test/power_suspend_controller_option_test.h new file mode 100644 index 0000000000000000000000000000000000000000..4f205fe5ac56f03dc4c182580440c330b48682a4 --- /dev/null +++ b/test/unittest/include/interface_test/power_suspend_controller_option_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 POWER_SUSPEND_CONTROLLER_OPTION_TEST_H +#define POWER_SUSPEND_CONTROLLER_OPTION_TEST_H + +#include + +#ifdef POWERMGR_GTEST +#define private public +#define protected public +#endif + +namespace OHOS { +namespace PowerMgr { +class PowerSuspendControllerOptionTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWER_SUSPEND_CONTROLLER_OPTION_TEST_H \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_suspend_controller_option_test.cpp b/test/unittest/src/interface_test/power_suspend_controller_option_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ad5f16d5d7aed0b418f9dc407e025a6c71ed1f9 --- /dev/null +++ b/test/unittest/src/interface_test/power_suspend_controller_option_test.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 "power_suspend_controller_option_test.h" +#ifdef HAS_MULTIMODALINPUT_INPUT_PART +#include +#endif +#include "power_mgr_service.h" + +using namespace testing::ext; +using namespace OHOS::MMI; +using namespace OHOS::PowerMgr; +using namespace OHOS; +using namespace std; +static sptr g_service; +static constexpr int SLEEP_WAIT_TIME_S = 2; + +void PowerSuspendControllerOptionTest::SetUpTestCase(void) +{ + g_service = DelayedSpSingleton::GetInstance(); + g_service->OnStart(); +} + +void PowerSuspendControllerOptionTest::TearDownTestCase(void) +{ + g_service->OnStop(); + DelayedSpSingleton::DestroyInstance(); +} + +#ifdef HAS_MULTIMODALINPUT_INPUT_PART +std::function)> callbackPower_; +std::function)> callbackTp_; + +int32_t MMI::InputManager::SubscribeKeyEvent(std::shared_ptr keyOption, + std::function)> callback) +{ + if (keyOption->GetFinalKey() == MMI::KeyEvent::KEYCODE_POWER) { + callbackPower_ = callback; + } else if (keyOption->GetFinalKey() == MMI::KeyEvent::KEYCODE_SLEEP) { + callbackTp_ = callback; + } + return 0; +} +#endif + +namespace { +/** + * @tc.name: PowerSuspendControllerOptionTest001 + * @tc.desc: test simulate powerkey event when screenon + * @tc.type: FUNC + */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART +HWTEST_F(PowerSuspendControllerOptionTest, PowerSuspendControllerOptionTest001, TestSize.Level0) +{ + POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerOptionTest001 function start!"); + GTEST_LOG_(INFO) << "PowerSuspendControllerOptionTest001: start"; + + g_service->WakeupControllerInit(); + g_service->SuspendControllerInit(); + g_service->WakeupDevice( + static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_PLUG_CHANGE, "plug change"); + EXPECT_TRUE(g_service->IsScreenOn()); + std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); + keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); + keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); + std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); + keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); + keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); + + callbackPower_(keyEventPowerkeyDown); + callbackPower_(keyEventPowerkeyUp); + sleep(SLEEP_WAIT_TIME_S); + EXPECT_FALSE(g_service->IsScreenOn()); + + std::shared_ptr suspendController = g_service->GetSuspendController(); + suspendController->monitorMap_.clear(); + callbackPower_(keyEventPowerkeyDown); + callbackPower_(keyEventPowerkeyUp); + + GTEST_LOG_(INFO) << "PowerSuspendControllerOptionTest001: end"; + POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerOptionTest001 function end!"); +} +#endif + +/** + * @tc.name: PowerSuspendControllerOptionTest002 + * @tc.desc: test simulate tpcover event when screenon + * @tc.type: FUNC + */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART +HWTEST_F(PowerSuspendControllerOptionTest, PowerSuspendControllerOptionTest002, TestSize.Level0) +{ + POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerOptionTest002 function start!"); + GTEST_LOG_(INFO) << "PowerSuspendControllerOptionTest002: start"; + + g_service->WakeupControllerInit(); + g_service->SuspendControllerInit(); + g_service->WakeupDevice( + static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_PLUG_CHANGE, "plug change"); + EXPECT_TRUE(g_service->IsScreenOn()); + std::shared_ptr keyEventTPCover = MMI::KeyEvent::Create(); + keyEventTPCover->SetKeyCode(MMI::KeyEvent::KEYCODE_SLEEP); + + callbackTp_(keyEventTPCover); + sleep(SLEEP_WAIT_TIME_S); + EXPECT_FALSE(g_service->IsScreenOn()); + + std::shared_ptr suspendController = g_service->GetSuspendController(); + suspendController->monitorMap_.clear(); + callbackTp_(keyEventTPCover); + + GTEST_LOG_(INFO) << "PowerSuspendControllerOptionTest002: end"; + POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerOptionTest002 function end!"); +} +#endif +} // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_suspend_controller_test.cpp b/test/unittest/src/interface_test/power_suspend_controller_test.cpp index b55ed9a62c8545b927c285af47f785487d79c53c..4e5be1e1eb0fe0f4a2ac9fb0fe5b5c02e0903fb8 100644 --- a/test/unittest/src/interface_test/power_suspend_controller_test.cpp +++ b/test/unittest/src/interface_test/power_suspend_controller_test.cpp @@ -23,7 +23,9 @@ #endif #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "power_mgr_service.h" @@ -100,6 +102,7 @@ HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest001, TestSize.Lev * @tc.type: FUNC * @tc.require: issueI7COGR */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest002, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest002 function start!"); @@ -112,6 +115,7 @@ HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest002, TestSize.Lev GTEST_LOG_(INFO) << "PowerSuspendControllerTest002: end"; POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest002 function end!"); } +#endif /** * @tc.name: PowerSuspendControllerTest003 @@ -411,39 +415,4 @@ HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest016, TestSize.Lev GTEST_LOG_(INFO) << "PowerSuspendControllerTest016: end"; POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest016 function end!"); } - -/** - * @tc.name: PowerSuspendControllerTest017 - * @tc.desc: test simulate powerkey event when screenon - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest017, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest017 function start!"); - GTEST_LOG_(INFO) << "PowerSuspendControllerTest017: start"; - - g_service->WakeupControllerInit(); - g_service->SuspendControllerInit(); - g_service->WakeupDevice( - static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_PLUG_CHANGE, "plug change"); - EXPECT_TRUE(g_service->IsScreenOn()); - std::shared_ptr suspendController = g_service->GetSuspendController(); - suspendController->monitorMap_.clear(); - - auto inputManager = MMI::InputManager::GetInstance(); - std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); - keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); - keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); - keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); - keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - - inputManager->SimulateInputEvent(keyEventPowerkeyDown); - inputManager->SimulateInputEvent(keyEventPowerkeyUp); - sleep(2); - EXPECT_FALSE(g_service->IsScreenOn()); - - GTEST_LOG_(INFO) << "PowerSuspendControllerTest017: end"; - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest017 function end!"); -} } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_suspend_parse_test.cpp b/test/unittest/src/interface_test/power_suspend_parse_test.cpp index af749d9deb4e677ac67c4308aea3ca0cde68ef14..b69e1c3136d587c0ad1ab36c4b1b59f186a50433 100644 --- a/test/unittest/src/interface_test/power_suspend_parse_test.cpp +++ b/test/unittest/src/interface_test/power_suspend_parse_test.cpp @@ -23,7 +23,9 @@ #endif #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "power_log.h" diff --git a/test/unittest/src/interface_test/power_wakeup_controller_oninput_test.cpp b/test/unittest/src/interface_test/power_wakeup_controller_oninput_test.cpp index 660a20db8df796821ff07a6cc5c1c79e64d98043..9ffa8ca4ee90aec786f8ed3254b75144cad318bb 100644 --- a/test/unittest/src/interface_test/power_wakeup_controller_oninput_test.cpp +++ b/test/unittest/src/interface_test/power_wakeup_controller_oninput_test.cpp @@ -13,7 +13,9 @@ * limitations under the License. */ #include "power_wakeup_controller_oninput_test.h" +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include "power_mgr_service.h" #include "power_state_machine.h" #include "wakeup_controller.h" @@ -40,10 +42,12 @@ void PowerWakeupControllerOninputTest::TearDownTestCase(void) DelayedSpSingleton::DestroyInstance(); } +#ifdef HAS_MULTIMODALINPUT_INPUT_PART MMI::InputManager *InputManager::GetInstance() { return nullptr; } +#endif namespace { /** @@ -52,6 +56,7 @@ namespace { * @tc.type: FUNC * @tc.require: issueI7COGR */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerWakeupControllerOninputTest, PowerWakeupControllerOninputTest001, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerOninputTest001: start"); @@ -80,4 +85,5 @@ HWTEST_F(PowerWakeupControllerOninputTest, PowerWakeupControllerOninputTest001, GTEST_LOG_(INFO) << "PowerWakeupControllerOninputTest001: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerOninputTest001: end"); } +#endif } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_wakeup_controller_test.cpp b/test/unittest/src/interface_test/power_wakeup_controller_test.cpp index 1645ff5ebde5abf07fbebd725ebe8f468983ac13..f0bea27274870815804e63b0b5e078bdd0b07a21 100644 --- a/test/unittest/src/interface_test/power_wakeup_controller_test.cpp +++ b/test/unittest/src/interface_test/power_wakeup_controller_test.cpp @@ -17,11 +17,13 @@ #include #include #include +#include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART +#include #include "axis_event.h" #include "input_device.h" #include "pointer_event.h" -#include -#include +#endif #include #include "power_mgr_client.h" @@ -41,12 +43,14 @@ static constexpr int32_t RECOVER_DISPLAY_OFF_TIME_S = 30 * 1000; static constexpr int32_t DISPLAY_POWER_MANAGER_ID = 3308; static const std::string TEST_DEVICE_ID = "test_device_id"; +#ifdef HAS_MULTIMODALINPUT_INPUT_PART class InputCallbackMock : public IInputEventConsumer { public: virtual void OnInputEvent(std::shared_ptr keyEvent) const; virtual void OnInputEvent(std::shared_ptr pointerEvent) const; virtual void OnInputEvent(std::shared_ptr axisEvent) const; }; +#endif void PowerWakeupControllerTest::SetUpTestCase(void) { @@ -64,6 +68,7 @@ void PowerWakeupControllerTest::TearDownTestCase(void) } namespace { +#ifdef HAS_MULTIMODALINPUT_INPUT_PART MMI::PointerEvent::PointerItem CreatePointerItem( int32_t pointerId, int32_t deviceId, const std::pair& displayLocation, bool isPressed) { @@ -75,6 +80,7 @@ MMI::PointerEvent::PointerItem CreatePointerItem( item.SetPressed(isPressed); return item; } +#endif /** * @tc.name: PowerWakeupControllerTest001 @@ -82,6 +88,7 @@ MMI::PointerEvent::PointerItem CreatePointerItem( * @tc.type: FUNC * @tc.require: issueI7COGR */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest001, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest001 function start!"); @@ -94,6 +101,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest001, TestSize.Level GTEST_LOG_(INFO) << "PowerWakeupControllerTest001: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest001 function end!"); } +#endif /** * @tc.name: PowerWakeupControllerTest002 @@ -229,6 +237,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest007, TestSize.Level POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest007 function start!"); GTEST_LOG_(INFO) << "PowerWakeupControllerTest007: start"; g_service->WakeupControllerInit(); +#ifdef HAS_MULTIMODALINPUT_INPUT_PART InputCallback* callback = new InputCallback(); InputCallbackMock* callback_mock = reinterpret_cast(callback); std::shared_ptr keyEvent = OHOS::MMI::KeyEvent::Create(); @@ -242,6 +251,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest007, TestSize.Level callback_mock->OnInputEvent(keyEvent); delete callback; EXPECT_TRUE(g_service->wakeupController_ != nullptr); +#endif GTEST_LOG_(INFO) << "PowerWakeupControllerTest007: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest007 function end!"); } @@ -263,6 +273,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest008, TestSize.Level constexpr int32_t DRAG_DST_Y {500}; int32_t deviceMouseId {0}; +#ifdef HAS_MULTIMODALINPUT_INPUT_PART InputCallback* callback = new InputCallback(); InputCallbackMock* callback_mock = reinterpret_cast(callback); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); @@ -286,6 +297,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest008, TestSize.Level callback_mock->OnInputEvent(pointerEvent); EXPECT_TRUE(g_service->wakeupController_ != nullptr); delete callback; +#endif GTEST_LOG_(INFO) << "PowerWakeupControllerTest008: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest008 function end!"); } @@ -307,6 +319,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest009, TestSize.Level constexpr int32_t DRAG_DST_Y {500}; int32_t deviceMouseId {0}; +#ifdef HAS_MULTIMODALINPUT_INPUT_PART InputCallback* callback = new InputCallback(); InputCallbackMock* callback_mock = reinterpret_cast(callback); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); @@ -338,6 +351,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest009, TestSize.Level callback_mock->OnInputEvent(pointerEvent2); delete callback; +#endif EXPECT_TRUE(g_service->wakeupController_ != nullptr); GTEST_LOG_(INFO) << "PowerWakeupControllerTest009: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest009 function end!"); @@ -422,12 +436,14 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest012, TestSize.Level g_service->WakeupDevice(static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON, "PowerWakeupControllerTest012"); EXPECT_TRUE(g_service->IsScreenOn()); +#ifdef HAS_MULTIMODALINPUT_INPUT_PART usleep(SLEEP_WAIT_TIME_MS * 1000); std::shared_ptr keyEvent = OHOS::MMI::KeyEvent::Create(); InputCallback callback; callback.OnInputEvent(keyEvent); usleep(SLEEP_WAIT_TIME_MS * 1000); EXPECT_TRUE(g_service->IsScreenOn()); +#endif g_service->SetDisplayOffTime(RECOVER_DISPLAY_OFF_TIME_S); GTEST_LOG_(INFO) << "PowerWakeupControllerTest012: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest012 function end!"); @@ -447,12 +463,14 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest013, TestSize.Level g_service->WakeupDevice(static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, "PowerWakeupControllerTest013"); EXPECT_TRUE(g_service->IsScreenOn()); +#ifdef HAS_MULTIMODALINPUT_INPUT_PART usleep(SLEEP_WAIT_TIME_MS * 1000); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); InputCallback callback; callback.OnInputEvent(pointerEvent); usleep(SLEEP_WAIT_TIME_MS * 1000); EXPECT_TRUE(g_service->IsScreenOn()); +#endif g_service->SetDisplayOffTime(RECOVER_DISPLAY_OFF_TIME_S); GTEST_LOG_(INFO) << "PowerWakeupControllerTest013: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest013 function end!"); @@ -472,12 +490,14 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest014, TestSize.Level g_service->WakeupDevice(static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, "PowerWakeupControllerTest014"); EXPECT_TRUE(g_service->IsScreenOn()); +#ifdef HAS_MULTIMODALINPUT_INPUT_PART usleep(SLEEP_WAIT_TIME_MS * 1000); std::shared_ptr axisEvent = MMI::AxisEvent::Create(); InputCallback callback; callback.OnInputEvent(axisEvent); usleep(SLEEP_WAIT_TIME_MS * 1000); EXPECT_TRUE(g_service->IsScreenOn()); +#endif g_service->SetDisplayOffTime(RECOVER_DISPLAY_OFF_TIME_S); GTEST_LOG_(INFO) << "PowerWakeupControllerTest014: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest014 function end!"); @@ -576,6 +596,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest019, TestSize.Level g_service->SuspendDevice( static_cast(time(nullptr)), SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, false); EXPECT_FALSE(g_service->IsScreenOn()); +#ifdef HAS_MULTIMODALINPUT_INPUT_PART std::shared_ptr wakeupController = g_service->GetWakeupController(); wakeupController->monitorMap_.clear(); @@ -591,13 +612,13 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest019, TestSize.Level inputManager->SimulateInputEvent(keyEventPowerkeyUp); inputManager->SimulateInputEvent(keyEventPowerkeyDown); inputManager->SimulateInputEvent(keyEventPowerkeyUp); - sleep(2); + sleep(SLEEP_WAIT_TIME_S); //wake it up when the screen goes off after timeout g_service->RefreshActivity( static_cast(std::chrono::system_clock::now().time_since_epoch().count()), UserActivityType::USER_ACTIVITY_TYPE_TOUCH, true); EXPECT_TRUE(g_service->IsScreenOn()); - +#endif GTEST_LOG_(INFO) << "PowerWakeupControllerTest019: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest019 function end!"); } @@ -644,6 +665,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest020, TestSize.Level * @tc.type: FUNC * @tc.require: issueI7COGR */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest021, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest021 function start!"); @@ -695,6 +717,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest021, TestSize.Level delete callbackThird; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest021 function end!"); } +#endif /** * @tc.name: PowerWakeupControllerTest022 @@ -702,6 +725,7 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest021, TestSize.Level * @tc.type: FUNC * @tc.require: issueI7COGR */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest022, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest022 function start!"); @@ -721,4 +745,5 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest022, TestSize.Level GTEST_LOG_(INFO) << "PowerWakeupControllerTest022: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest022 function end!"); } +#endif } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_wakeup_parse_test.cpp b/test/unittest/src/interface_test/power_wakeup_parse_test.cpp index 65e04b8cbe0cf2acb2b03fadf88dba85b1b1229d..2be56a1e98e85539c2998572e75c87e628100ab8 100644 --- a/test/unittest/src/interface_test/power_wakeup_parse_test.cpp +++ b/test/unittest/src/interface_test/power_wakeup_parse_test.cpp @@ -23,7 +23,9 @@ #endif #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "power_mgr_service.h" diff --git a/test/unittest/src/power_getcontroller_mock_test.cpp b/test/unittest/src/power_getcontroller_mock_test.cpp index 57f3d26d9dc0599f1dc01ebffba99a0d41adac3d..a61b64bcd70baef2aadb1dd0d166e585fe4161fa 100644 --- a/test/unittest/src/power_getcontroller_mock_test.cpp +++ b/test/unittest/src/power_getcontroller_mock_test.cpp @@ -58,7 +58,7 @@ HWTEST_F(PowerGetControllerMockTest, PowerGetControllerMockTest001, TestSize.Lev std::shared_ptr wakeupController_ = std::make_shared(stateMachine); EXPECT_TRUE(wakeupController_ != nullptr); wakeupController_->Wakeup(); - +#ifdef HAS_MULTIMODALINPUT_INPUT_PART InputCallback* callback = new InputCallback(); std::shared_ptr keyEvent = OHOS::MMI::KeyEvent::Create(); keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); @@ -66,6 +66,7 @@ HWTEST_F(PowerGetControllerMockTest, PowerGetControllerMockTest001, TestSize.Lev callback->OnInputEvent(keyEvent); EXPECT_TRUE(callback != nullptr); delete callback; +#endif POWER_HILOGI(LABEL_TEST, "PowerGetControllerMockTest001 function end!"); GTEST_LOG_(INFO) << "PowerGetControllerMockTest001: end"; } diff --git a/test/unittest/src/power_mgr_dump_test.cpp b/test/unittest/src/power_mgr_dump_test.cpp index 84b3d3dd84c697f15b5f3d7888cdc21e6781ff5f..95222be15982e97a52d883c84515c5f03e849214 100644 --- a/test/unittest/src/power_mgr_dump_test.cpp +++ b/test/unittest/src/power_mgr_dump_test.cpp @@ -24,8 +24,10 @@ #undef private #undef protected #include "power_mgr_dumper.h" +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include "key_event.h" #include "pointer_event.h" +#endif #include "power_log.h" using namespace testing::ext; diff --git a/test/unittest/src/power_mgr_service_native_test.cpp b/test/unittest/src/power_mgr_service_native_test.cpp index c6c6d3316602ec4f423a8413c633d71e8e20fb3f..e3900f74fdab3295e1a7bb2a7692134881bb46ab 100644 --- a/test/unittest/src/power_mgr_service_native_test.cpp +++ b/test/unittest/src/power_mgr_service_native_test.cpp @@ -23,8 +23,10 @@ #include #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include "key_event.h" #include "pointer_event.h" +#endif #include "power_common.h" #include "power_mgr_service.h" #include "setting_helper.h" @@ -88,7 +90,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative001, TestSize.Level1) POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative001 function start!"); g_pmsTest->HallSensorSubscriberInit(); g_pmsTest->HallSensorSubscriberCancel(); - +#ifdef HAS_MULTIMODALINPUT_INPUT_PART int32_t keyCode = OHOS::MMI::KeyEvent::KEYCODE_F1; g_pmsTest->HandleKeyEvent(keyCode); int32_t type = OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE; @@ -99,6 +101,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative001, TestSize.Level1) g_pmsTest->doubleClickId_ = UNCANCELID; g_pmsTest->monitorId_ = UNCANCELID; +#endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative001 function end!"); GTEST_LOG_(INFO) << "PowerMgrServiceNative001 end."; } @@ -108,6 +111,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative001, TestSize.Level1) * @tc.desc: test handleKeyEvent in powerMgrService * @tc.type: FUNC */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative002, TestSize.Level1) { GTEST_LOG_(INFO) << "PowerMgrServiceNative002 start."; @@ -131,6 +135,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative002, TestSize.Level1) POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative002 function end!"); GTEST_LOG_(INFO) << "PowerMgrServiceNative002 end."; } +#endif /** * @tc.name: PowerMgrServiceNative003 diff --git a/test/unittest/src/power_parsesources_mock_test.cpp b/test/unittest/src/power_parsesources_mock_test.cpp index 9aad63d6c55b9475c2aad51fa28d1bf8aaf0f491..c604a92fcd0ab5739a2234026a911e5de05ecb98 100644 --- a/test/unittest/src/power_parsesources_mock_test.cpp +++ b/test/unittest/src/power_parsesources_mock_test.cpp @@ -18,7 +18,9 @@ #include #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "power_mgr_service.h" diff --git a/test/unittest/src/power_screenon_mock_test.cpp b/test/unittest/src/power_screenon_mock_test.cpp index 65951f796883f1a321fb61e459754efc7b0ea1a3..b67c1071e5be753896e86d252b67ab1303297329 100644 --- a/test/unittest/src/power_screenon_mock_test.cpp +++ b/test/unittest/src/power_screenon_mock_test.cpp @@ -23,7 +23,9 @@ #endif #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "permission.h" diff --git a/test/unittest/src/running_lock_hub_native_test.cpp b/test/unittest/src/running_lock_hub_native_test.cpp index 10b48c8ad782d9bedd44b71a98725c6e9cc4ec4f..28b99fe208e7fcc5544fbd3da42f1113eabb4b75 100644 --- a/test/unittest/src/running_lock_hub_native_test.cpp +++ b/test/unittest/src/running_lock_hub_native_test.cpp @@ -19,7 +19,9 @@ #include #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "actions/irunning_lock_action.h" diff --git a/test/unittest/src/scenario_test/proximity_controller/BUILD.gn b/test/unittest/src/scenario_test/proximity_controller/BUILD.gn index 0ac7f7a48e0649148f8bd58c92059c7591254c76..f9fe7622f5685a5bed7e33cc78a8844d63f5a9b6 100644 --- a/test/unittest/src/scenario_test/proximity_controller/BUILD.gn +++ b/test/unittest/src/scenario_test/proximity_controller/BUILD.gn @@ -49,7 +49,6 @@ deps_ex = [ "hdf_core:libhdi", "hdf_core:libpub_utils", "hilog:libhilog", - "input:libmmi-client", "ipc:ipc_core", "libxml2:libxml2", "power_manager:power_ffrt", @@ -59,6 +58,10 @@ deps_ex = [ "window_manager:libwm_lite", ] +if (has_multimodalinput_input_part) { + deps_ex += [ "input:libmmi-client" ] +} + if (has_sensors_sensor_part) { deps_ex += [ "sensor:sensor_interface_native" ] } diff --git a/test/unittest/src/scenario_test/wakeup_suspend/power_suspend_test.cpp b/test/unittest/src/scenario_test/wakeup_suspend/power_suspend_test.cpp index 98a1d25de5f15b66900a7c63f71bab2bfed53c3d..cf654dcff231113747c984d528f7203dd56d4892 100644 --- a/test/unittest/src/scenario_test/wakeup_suspend/power_suspend_test.cpp +++ b/test/unittest/src/scenario_test/wakeup_suspend/power_suspend_test.cpp @@ -23,7 +23,9 @@ #endif #include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART #include +#endif #include #include "power_mgr_client.h" @@ -45,6 +47,7 @@ namespace { * @tc.desc: test simulate powerkey event when screenon * @tc.type: FUNC */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerSuspendTest, PowerSuspendTest001, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "PowerSuspendTest001 function start!"); @@ -66,11 +69,14 @@ HWTEST_F(PowerSuspendTest, PowerSuspendTest001, TestSize.Level1) EXPECT_FALSE(powerMgrClient.IsScreenOn()); POWER_HILOGI(LABEL_TEST, "PowerSuspendTest001 function end!"); } +#endif + /** * @tc.name: PowerSuspendTest002 * @tc.desc: test simulate powerkey event once when screenon * @tc.type: FUNC */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerSuspendTest, PowerSuspendTest002, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "PowerSuspendTest002 function start!"); @@ -97,6 +103,7 @@ HWTEST_F(PowerSuspendTest, PowerSuspendTest002, TestSize.Level1) POWER_HILOGI(LABEL_TEST, "PowerSuspendTest002 function end!"); } +#endif /** * @tc.name: PowerSuspendTest003 diff --git a/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp b/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp index 97f7a7737a0ccee9e1ca5dc2f1ae48a867cf78be..8662533d83b19ff379125b89c2de84e69ad1c3de 100644 --- a/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp +++ b/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp @@ -17,11 +17,13 @@ #include #include #include +#include +#ifdef HAS_MULTIMODALINPUT_INPUT_PART +#include #include "axis_event.h" #include "input_device.h" #include "pointer_event.h" -#include -#include +#endif #include #include "power_mgr_client.h" @@ -42,6 +44,7 @@ static constexpr int32_t SCREEN_OFF_TIME_MS = 5000; static const std::string TEST_DEVICE_ID = "test_device_id"; namespace { +#ifdef HAS_MULTIMODALINPUT_INPUT_PART MMI::PointerEvent::PointerItem CreatePointerItem( int32_t pointerId, int32_t deviceId, const std::pair& displayLocation, bool isPressed) { @@ -53,12 +56,14 @@ MMI::PointerEvent::PointerItem CreatePointerItem( item.SetPressed(isPressed); return item; } +#endif /** * @tc.name: PowerWakeupTest001 * @tc.desc: test keyboard wakeup and powerkey pressed at the same time * @tc.type: FUNC */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerWakeupTest, PowerWakeupTest001, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "PowerWakeupTest001 function start!"); @@ -90,12 +95,14 @@ HWTEST_F(PowerWakeupTest, PowerWakeupTest001, TestSize.Level1) powerMgrClient.RestoreScreenOffTime(); POWER_HILOGI(LABEL_TEST, "PowerWakeupTest001 function end!"); } +#endif /** * @tc.name: PowerWakeupTest002 * @tc.desc: test simulate normal key event when screenoff * @tc.type: FUNC */ +#ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerWakeupTest, PowerWakeupTest002, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "PowerWakeupTest002 function start!"); @@ -118,4 +125,5 @@ HWTEST_F(PowerWakeupTest, PowerWakeupTest002, TestSize.Level1) POWER_HILOGI(LABEL_TEST, "PowerWakeupTest002 function end!"); } +#endif } // namespace diff --git a/test/unittest/src/servicetest/BUILD.gn b/test/unittest/src/servicetest/BUILD.gn index 9156d44df5a1a46218c3eee98afcfb7ad20d64e6..e2de28d58683b36dc60fc35a60cf96f03eda3f67 100644 --- a/test/unittest/src/servicetest/BUILD.gn +++ b/test/unittest/src/servicetest/BUILD.gn @@ -57,7 +57,6 @@ deps_ex = [ "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", - "input:libmmi-client", "ipc:ipc_core", "libxml2:libxml2", "power_manager:power_ffrt", @@ -67,6 +66,10 @@ deps_ex = [ "window_manager:libwm_lite", ] +if (has_multimodalinput_input_part) { + deps_ex += [ "input:libmmi-client" ] +} + if (has_sensors_sensor_part) { deps_ex += [ "sensor:sensor_interface_native" ] }