1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "power_mgr_client_test.h" 17 18 #include <iostream> 19 20 #include <datetime_ex.h> 21 #include <gtest/gtest.h> 22 #include <if_system_ability_manager.h> 23 #include <ipc_skeleton.h> 24 #include <string_ex.h> 25 #ifdef HAS_DISPLAY_MANAGER_PART 26 #include "display_power_mgr_client.h" 27 #endif 28 #include "power_common.h" 29 #include "power_mgr_client.h" 30 #include "power_mgr_service.h" 31 #include "power_state_machine.h" 32 #include "running_lock_token_stub.h" 33 34 using namespace testing::ext; 35 using namespace OHOS::PowerMgr; 36 using namespace OHOS; 37 using namespace std; 38 39 namespace { 40 /** 41 * @tc.name: PowerMgrClient001 42 * @tc.desc: test RefreshActivity 43 * @tc.type: FUNC 44 * @tc.require: issueI5MJZJ 45 */ 46 HWTEST_F(PowerMgrClientTest, PowerMgrClient001, TestSize.Level2) 47 { 48 POWER_HILOGD(LABEL_TEST, "PowerMgrClient001::fun is start!"); 49 auto& powerMgrClient = PowerMgrClient::GetInstance(); 50 51 // Wakeup Device before test 52 powerMgrClient.WakeupDevice(); 53 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient001: Prepare Fail, Screen is OFF."; 54 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 55 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 56 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient001: Prepare Fail, Screen is OFF."; 57 powerMgrClient.RefreshActivity(); 58 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 59 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 60 61 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient001: RefreshActivity Device Fail, Screen is OFF"; 62 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 63 POWER_HILOGD(LABEL_TEST, "PowerMgrClient001::fun is end!"); 64 } 65 66 /** 67 * @tc.name: PowerMgrClient002 68 * @tc.desc: test RefreshActivity 69 * @tc.type: FUNC 70 * @tc.require: issueI5MJZJ 71 */ 72 HWTEST_F(PowerMgrClientTest, PowerMgrClient002, TestSize.Level2) 73 { 74 POWER_HILOGD(LABEL_TEST, "PowerMgrClient002::fun is start!"); 75 auto& powerMgrClient = PowerMgrClient::GetInstance(); 76 77 // Wakeup Device before test 78 powerMgrClient.WakeupDevice(); 79 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient002: Prepare Fail, Screen is OFF."; 80 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 81 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 82 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient002: Prepare Fail, Screen is OFF."; 83 powerMgrClient.RefreshActivity(UserActivityType::USER_ACTIVITY_TYPE_BUTTON); 84 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 85 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 86 87 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient002: RefreshActivity Device Fail, Screen is OFF"; 88 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 89 POWER_HILOGD(LABEL_TEST, "PowerMgrClient002::fun is end!"); 90 } 91 92 /** 93 * @tc.name: PowerMgrClient003 94 * @tc.desc: test RefreshActivity 95 * @tc.type: FUNC 96 * @tc.require: issueI5MJZJ 97 */ 98 HWTEST_F(PowerMgrClientTest, PowerMgrClient003, TestSize.Level2) 99 { 100 POWER_HILOGD(LABEL_TEST, "PowerMgrClient003::fun is start!"); 101 auto& powerMgrClient = PowerMgrClient::GetInstance(); 102 103 // Wakeup Device before test 104 powerMgrClient.WakeupDevice(); 105 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient003: Prepare Fail, Screen is OFF."; 106 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 107 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 108 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient003: Prepare Fail, Screen is OFF."; 109 powerMgrClient.RefreshActivity(UserActivityType::USER_ACTIVITY_TYPE_TOUCH); 110 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 111 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 112 113 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient003: RefreshActivity Device Fail, Screen is OFF"; 114 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 115 POWER_HILOGD(LABEL_TEST, "PowerMgrClient003::fun is end!"); 116 } 117 118 /** 119 * @tc.name: PowerMgrClient004 120 * @tc.desc: test RefreshActivity 121 * @tc.type: FUNC 122 * @tc.require: issueI5MJZJ 123 */ 124 HWTEST_F(PowerMgrClientTest, PowerMgrClient004, TestSize.Level2) 125 { 126 POWER_HILOGD(LABEL_TEST, "PowerMgrClient004::fun is start!"); 127 auto& powerMgrClient = PowerMgrClient::GetInstance(); 128 129 // Wakeup Device before test 130 powerMgrClient.WakeupDevice(); 131 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient004: Prepare Fail, Screen is OFF."; 132 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 133 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 134 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient004: Prepare Fail, Screen is OFF."; 135 powerMgrClient.RefreshActivity(UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY); 136 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 137 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 138 139 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient004: RefreshActivity Device Fail, Screen is OFF"; 140 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 141 POWER_HILOGD(LABEL_TEST, "PowerMgrClient004::fun is end!"); 142 } 143 144 /** 145 * @tc.name: PowerMgrClient005 146 * @tc.desc: test RefreshActivity 147 * @tc.type: FUNC 148 * @tc.require: issueI5MJZJ 149 */ 150 HWTEST_F(PowerMgrClientTest, PowerMgrClient005, TestSize.Level2) 151 { 152 POWER_HILOGD(LABEL_TEST, "PowerMgrClient005::fun is start!"); 153 auto& powerMgrClient = PowerMgrClient::GetInstance(); 154 155 // Wakeup Device before test 156 powerMgrClient.WakeupDevice(); 157 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient005: Prepare Fail, Screen is OFF."; 158 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 159 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 160 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient005: Prepare Fail, Screen is OFF."; 161 powerMgrClient.RefreshActivity(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); 162 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 163 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 164 165 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient005: RefreshActivity Device Fail, Screen is OFF"; 166 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 167 POWER_HILOGD(LABEL_TEST, "PowerMgrClient005::fun is end!"); 168 } 169 170 /** 171 * @tc.name: PowerMgrClient006 172 * @tc.desc: test RefreshActivity 173 * @tc.type: FUNC 174 * @tc.require: issueI5MJZJ 175 */ 176 HWTEST_F(PowerMgrClientTest, PowerMgrClient006, TestSize.Level2) 177 { 178 POWER_HILOGD(LABEL_TEST, "PowerMgrClient006::fun is start!"); 179 auto& powerMgrClient = PowerMgrClient::GetInstance(); 180 181 // Wakeup Device before test 182 powerMgrClient.WakeupDevice(); 183 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient006: Prepare Fail, Screen is OFF."; 184 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 185 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 186 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient006: Prepare Fail, Screen is OFF."; 187 powerMgrClient.RefreshActivity(UserActivityType::USER_ACTIVITY_TYPE_SOFTWARE); 188 sleep(SCREEN_OFF_WAIT_TIME_S / 2); 189 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 190 191 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient006: RefreshActivity Device Fail, Screen is OFF"; 192 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 193 POWER_HILOGD(LABEL_TEST, "PowerMgrClient006::fun is end!"); 194 } 195 196 /** 197 * @tc.name: PowerMgrClient007 198 * @tc.desc: test RefreshActivity 199 * @tc.type: FUNC 200 * @tc.require: issueI5MJZJ 201 */ 202 HWTEST_F(PowerMgrClientTest, PowerMgrClient007, TestSize.Level2) 203 { 204 POWER_HILOGD(LABEL_TEST, "PowerMgrClient007::fun is start!"); 205 auto& powerMgrClient = PowerMgrClient::GetInstance(); 206 UserActivityType abnormaltype = UserActivityType(9); 207 208 // Wakeup Device before test 209 powerMgrClient.WakeupDevice(); 210 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient007: Prepare Fail, Screen is OFF."; 211 powerMgrClient.OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); 212 usleep(SCREEN_OFF_WAIT_TIME_S * TRANSFER_NS_TO_MS / 2); 213 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient007: Prepare Fail, Screen is OFF."; 214 powerMgrClient.RefreshActivity(abnormaltype); 215 usleep(SCREEN_OFF_WAIT_TIME_S * TRANSFER_NS_TO_MS / 2 + TRANSFER_NS_TO_MS); 216 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient007: RefreshActivity Device Fail, Screen is OFF"; 217 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 218 POWER_HILOGD(LABEL_TEST, "PowerMgrClient007::fun is end!"); 219 } 220 221 #ifdef HAS_DISPLAY_MANAGER_PART 222 /** 223 * @tc.name: PowerMgrClient008 224 * @tc.desc: test DISPLAY_DIM 225 * @tc.type: FUNC 226 * @tc.require: issueI5MJZJ 227 */ 228 HWTEST_F(PowerMgrClientTest, PowerMgrClient008, TestSize.Level2) 229 { 230 POWER_HILOGD(LABEL_TEST, "PowerMgrClient008::fun is start!"); 231 int64_t time = SCREEN_OFF_WAIT_TIME_MS; 232 auto& powerMgrClient = PowerMgrClient::GetInstance(); 233 auto& displayMgrClient = OHOS::DisplayPowerMgr::DisplayPowerMgrClient::GetInstance(); 234 235 powerMgrClient.OverrideScreenOffTime(time); 236 // Wakeup Device before test 237 powerMgrClient.WakeupDevice(); 238 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient008: Prepare Fail, Screen is OFF."; 239 usleep(time * TRANSFER_MS_TO_S * DIM_RATE); 240 auto ret = displayMgrClient.GetDisplayState(); 241 EXPECT_EQ(ret, DisplayPowerMgr::DisplayState::DISPLAY_DIM); 242 243 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 244 POWER_HILOGD(LABEL_TEST, "PowerMgrClient008::fun is end!"); 245 } 246 #endif 247 248 /** 249 * @tc.name: PowerMgrClient009 250 * @tc.desc: test WakeupDevice 251 * @tc.type: FUNC 252 * @tc.require: issueI5MJZJ 253 */ 254 HWTEST_F(PowerMgrClientTest, PowerMgrClient009, TestSize.Level0) 255 { 256 POWER_HILOGD(LABEL_TEST, "PowerMgrClient009::fun is start!"); 257 int32_t wakeupReason = (static_cast<int32_t>(WakeupDeviceType::WAKEUP_DEVICE_MAX)) + 1; 258 WakeupDeviceType abnormaltype = WakeupDeviceType(wakeupReason); 259 auto& powerMgrClient = PowerMgrClient::GetInstance(); 260 261 // Suspend Device before test 262 powerMgrClient.SuspendDevice(); 263 sleep(SLEEP_WAIT_TIME_S); 264 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient009: Prepare Fail, Screen is On."; 265 powerMgrClient.WakeupDevice(abnormaltype); 266 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient009: Wakeup Device Fail, Screen is Off"; 267 268 POWER_HILOGD(LABEL_TEST, "PowerMgrClient009::fun is end!"); 269 } 270 271 /** 272 * @tc.name: PowerMgrClient010 273 * @tc.desc: test Suspend Device 274 * @tc.type: FUNC 275 * @tc.require: issueI5MJZJ 276 */ 277 HWTEST_F(PowerMgrClientTest, PowerMgrClient010, TestSize.Level0) 278 { 279 POWER_HILOGD(LABEL_TEST, "PowerMgrClient010::fun is start!"); 280 auto& powerMgrClient = PowerMgrClient::GetInstance(); 281 int32_t suspendReason = (static_cast<int32_t>(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + 1; 282 SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); 283 284 // Wakeup Device before test 285 powerMgrClient.WakeupDevice(); 286 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient010: Prepare Fail, Screen is OFF."; 287 powerMgrClient.SuspendDevice(abnormaltype, false); 288 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 289 290 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient010: Suspend Device Fail, Screen is On"; 291 POWER_HILOGD(LABEL_TEST, "PowerMgrClient010::fun is end!"); 292 } 293 294 #ifdef HAS_DISPLAY_MANAGER_PART 295 /** 296 * @tc.name: PowerMgrClient011 297 * @tc.desc: test auto suspend 298 * @tc.type: FUNC 299 * @tc.require: issueI5MJZJ 300 */ 301 HWTEST_F(PowerMgrClientTest, PowerMgrClient011, TestSize.Level2) 302 { 303 POWER_HILOGD(LABEL_TEST, "PowerMgrClient011::fun is start!"); 304 int32_t time = SET_DISPLAY_OFF_TIME_MS; 305 auto& powerMgrClient = PowerMgrClient::GetInstance(); 306 auto& displayMgrClient = OHOS::DisplayPowerMgr::DisplayPowerMgrClient::GetInstance(); 307 308 powerMgrClient.OverrideScreenOffTime(time); 309 // Wakeup Device before test 310 powerMgrClient.WakeupDevice(); 311 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient011: Prepare Fail, Screen is OFF."; 312 POWER_HILOGD(LABEL_TEST, "PowerMgrClient011::1!"); 313 usleep(time * TRANSFER_MS_TO_S * DIM_RATE); 314 auto ret = displayMgrClient.GetDisplayState(); 315 EXPECT_EQ(ret, DisplayPowerMgr::DisplayState::DISPLAY_DIM); 316 POWER_HILOGD(LABEL_TEST, "PowerMgrClient011::3!"); 317 usleep(time * TRANSFER_MS_TO_S * DIM_RATE); 318 POWER_HILOGD(LABEL_TEST, "PowerMgrClient011::8!"); 319 ret = displayMgrClient.GetDisplayState(); 320 EXPECT_EQ(ret, DisplayPowerMgr::DisplayState::DISPLAY_OFF); 321 322 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 323 POWER_HILOGD(LABEL_TEST, "PowerMgrClient011::fun is end!"); 324 } 325 #endif 326 327 /** 328 * @tc.name: PowerMgrClient012 329 * @tc.desc: test SCREEN_ON RunningLock 330 * @tc.type: FUNC 331 * @tc.require: issueI5MJZJ 332 */ 333 HWTEST_F(PowerMgrClientTest, PowerMgrClient012, TestSize.Level2) 334 { 335 POWER_HILOGD(LABEL_TEST, "PowerMgrClient012:Start."); 336 int32_t time = SET_DISPLAY_OFF_TIME_MS; 337 auto& powerMgrClient = PowerMgrClient::GetInstance(); 338 auto runningLock = powerMgrClient.CreateRunningLock("runninglock", RunningLockType::RUNNINGLOCK_SCREEN); 339 powerMgrClient.OverrideScreenOffTime(time); 340 runningLock->Lock(); 341 EXPECT_EQ(runningLock->IsUsed(), true); 342 EXPECT_EQ(powerMgrClient.IsScreenOn(), true); 343 usleep(time * TRANSFER_MS_TO_S); 344 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 345 runningLock->UnLock(); 346 EXPECT_EQ(runningLock->IsUsed(), false); 347 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 348 POWER_HILOGD(LABEL_TEST, "PowerMgrClient012:End."); 349 } 350 351 /** 352 * @tc.name: PowerMgrClient013 353 * @tc.desc: test SCREEN_ON RunningLock 354 * @tc.type: FUNC 355 * @tc.require: issueI5MJZJ 356 */ 357 HWTEST_F(PowerMgrClientTest, PowerMgrClient013, TestSize.Level2) 358 { 359 POWER_HILOGD(LABEL_TEST, "PowerMgrClient013:Start."); 360 361 int32_t time = SET_DISPLAY_OFF_TIME_MS; 362 auto& powerMgrClient = PowerMgrClient::GetInstance(); 363 auto runningLock = powerMgrClient.CreateRunningLock("runninglock", RunningLockType::RUNNINGLOCK_SCREEN); 364 powerMgrClient.OverrideScreenOffTime(time); 365 366 runningLock->Lock(); 367 EXPECT_EQ(runningLock->IsUsed(), true); 368 369 runningLock->UnLock(); 370 EXPECT_EQ(runningLock->IsUsed(), false); 371 usleep(time * TRANSFER_MS_TO_S * DOUBLE_TIMES); 372 EXPECT_EQ(powerMgrClient.IsScreenOn(), false); 373 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 374 POWER_HILOGD(LABEL_TEST, "PowerMgrClient013:End."); 375 } 376 377 /** 378 * @tc.name: PowerMgrClient014 379 * @tc.desc: test SCREEN_ON RunningLock 380 * @tc.type: FUNC 381 * @tc.require: issueI5MJZJ 382 */ 383 HWTEST_F(PowerMgrClientTest, PowerMgrClient014, TestSize.Level2) 384 { 385 POWER_HILOGD(LABEL_TEST, "PowerMgrClient014:Start."); 386 387 int32_t time = SET_DISPLAY_OFF_TIME_MS; 388 auto& powerMgrClient = PowerMgrClient::GetInstance(); 389 auto runningLock = powerMgrClient.CreateRunningLock("runninglock", RunningLockType::RUNNINGLOCK_SCREEN); 390 powerMgrClient.OverrideScreenOffTime(time); 391 392 runningLock->Lock(); 393 EXPECT_EQ(runningLock->IsUsed(), true); 394 EXPECT_EQ(powerMgrClient.IsScreenOn(), true); 395 usleep(time * TRANSFER_MS_TO_S * DOUBLE_TIMES); 396 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 397 398 runningLock->UnLock(); 399 EXPECT_EQ(runningLock->IsUsed(), false); 400 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 401 POWER_HILOGD(LABEL_TEST, "PowerMgrClient014:End."); 402 } 403 404 /** 405 * @tc.name: PowerMgrClient015 406 * @tc.desc: test SCREEN_ON RunningLock 407 * @tc.type: FUNC 408 * @tc.require: issueI5MJZJ 409 */ 410 HWTEST_F(PowerMgrClientTest, PowerMgrClient015, TestSize.Level2) 411 { 412 POWER_HILOGD(LABEL_TEST, "PowerMgrClient015:Start."); 413 414 int32_t time = SET_DISPLAY_OFF_TIME_MS; 415 auto& powerMgrClient = PowerMgrClient::GetInstance(); 416 auto runningLock = powerMgrClient.CreateRunningLock("runninglock", RunningLockType::RUNNINGLOCK_SCREEN); 417 418 powerMgrClient.OverrideScreenOffTime(time); 419 420 runningLock->Lock(); 421 EXPECT_EQ(runningLock->IsUsed(), true); 422 EXPECT_EQ(powerMgrClient.IsScreenOn(), true); 423 powerMgrClient.SuspendDevice(); 424 EXPECT_EQ(powerMgrClient.IsScreenOn(), false); 425 426 runningLock->UnLock(); 427 EXPECT_EQ(runningLock->IsUsed(), false); 428 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 429 POWER_HILOGD(LABEL_TEST, "PowerMgrClient015:End."); 430 } 431 432 /** 433 * @tc.name: PowerMgrClient016 434 * @tc.desc: test SCREEN_ON RunningLock 435 * @tc.type: FUNC 436 * @tc.require: issueI5MJZJ 437 */ 438 HWTEST_F(PowerMgrClientTest, PowerMgrClient016, TestSize.Level2) 439 { 440 POWER_HILOGD(LABEL_TEST, "PowerMgrClient016:Start."); 441 442 int32_t time = SET_DISPLAY_OFF_TIME_MS; 443 auto& powerMgrClient = PowerMgrClient::GetInstance(); 444 auto runningLock = powerMgrClient.CreateRunningLock("runninglock", RunningLockType::RUNNINGLOCK_SCREEN); 445 446 powerMgrClient.OverrideScreenOffTime(time); 447 448 powerMgrClient.SuspendDevice(); 449 EXPECT_EQ(powerMgrClient.IsScreenOn(), false); 450 runningLock->Lock(); 451 EXPECT_EQ(runningLock->IsUsed(), true); 452 EXPECT_EQ(powerMgrClient.IsScreenOn(), true); 453 usleep(time * TRANSFER_MS_TO_S); 454 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 455 456 runningLock->UnLock(); 457 EXPECT_EQ(runningLock->IsUsed(), false); 458 powerMgrClient.OverrideScreenOffTime(DEFAULT_SLEEP_TIME); 459 POWER_HILOGD(LABEL_TEST, "PowerMgrClient016:End."); 460 } 461 462 /** 463 * @tc.name: PowerMgrClient020 464 * @tc.desc: test SetDisplaySuspend 465 * @tc.type: FUNC 466 * @tc.require: issueI5MJZJ 467 */ 468 HWTEST_F(PowerMgrClientTest, PowerMgrClient020, TestSize.Level2) 469 { 470 POWER_HILOGD(LABEL_TEST, "PowerMgrClient020::fun is start!"); 471 auto& powerMgrClient = PowerMgrClient::GetInstance(); 472 473 powerMgrClient.SuspendDevice(); 474 EXPECT_EQ(powerMgrClient.IsScreenOn(), false); 475 powerMgrClient.SetDisplaySuspend(true); 476 477 EXPECT_EQ(powerMgrClient.IsScreenOn(), false); 478 powerMgrClient.SetDisplaySuspend(false); 479 POWER_HILOGD(LABEL_TEST, "PowerMgrClient020::fun is end!"); 480 } 481 482 /** 483 * @tc.name: PowerMgrClient022 484 * @tc.desc: test Suspend Device in proxy 485 * @tc.type: FUNC 486 * @tc.require: issueI5MJZJ 487 */ 488 HWTEST_F(PowerMgrClientTest, PowerMgrClient022, TestSize.Level0) 489 { 490 POWER_HILOGD(LABEL_TEST, "PowerMgrClient022::fun is start!"); 491 auto& powerMgrClient = PowerMgrClient::GetInstance(); 492 493 // Wakeup Device before test 494 powerMgrClient.WakeupDevice(); 495 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient022: Prepare Fail, Screen is OFF."; 496 497 powerMgrClient.SuspendDevice(); 498 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient022: Suspend Device Fail, Screen is On"; 499 500 POWER_HILOGD(LABEL_TEST, "PowerMgrClient022::fun is end!"); 501 } 502 503 /** 504 * @tc.name: PowerMgrClient023 505 * @tc.desc: test Suspend Device 506 * @tc.type: FUNC 507 * @tc.require: issueI5MJZJ 508 */ 509 HWTEST_F(PowerMgrClientTest, PowerMgrClient023, TestSize.Level0) 510 { 511 POWER_HILOGD(LABEL_TEST, "PowerMgrClient023::fun is start!"); 512 auto& powerMgrClient = PowerMgrClient::GetInstance(); 513 514 // Wakeup Device before test 515 powerMgrClient.WakeupDevice(); 516 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient023: Prepare Fail, Screen is OFF."; 517 518 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_DEVICE_ADMIN, false); 519 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient023: Suspend Device Fail, Screen is On"; 520 521 POWER_HILOGD(LABEL_TEST, "PowerMgrClient023::fun is end!"); 522 } 523 524 /** 525 * @tc.name: PowerMgrClient024 526 * @tc.desc: test Suspend Device 527 * @tc.type: FUNC 528 * @tc.require: issueI5MJZJ 529 */ 530 HWTEST_F(PowerMgrClientTest, PowerMgrClient024, TestSize.Level0) 531 { 532 POWER_HILOGD(LABEL_TEST, "PowerMgrClient024::fun is start!"); 533 auto& powerMgrClient = PowerMgrClient::GetInstance(); 534 535 // Wakeup Device before test 536 powerMgrClient.WakeupDevice(); 537 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient024: Prepare Fail, Screen is OFF."; 538 539 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT, false); 540 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient024: Suspend Device Fail, Screen is On"; 541 542 POWER_HILOGD(LABEL_TEST, "PowerMgrClient024::fun is end!"); 543 } 544 545 /** 546 * @tc.name: PowerMgrClient025 547 * @tc.desc: test Suspend Device 548 * @tc.type: FUNC 549 * @tc.require: issueI5MJZJ 550 */ 551 HWTEST_F(PowerMgrClientTest, PowerMgrClient025, TestSize.Level0) 552 { 553 POWER_HILOGD(LABEL_TEST, "PowerMgrClient025::fun is start!"); 554 auto& powerMgrClient = PowerMgrClient::GetInstance(); 555 556 // Wakeup Device before test 557 powerMgrClient.WakeupDevice(); 558 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient025: Prepare Fail, Screen is OFF."; 559 560 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_LID, false); 561 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient025: Suspend Device Fail, Screen is On"; 562 563 POWER_HILOGD(LABEL_TEST, "PowerMgrClient025::fun is end!"); 564 } 565 566 /** 567 * @tc.name: PowerMgrClient026 568 * @tc.desc: test Suspend Device 569 * @tc.type: FUNC 570 * @tc.require: issueI5MJZJ 571 */ 572 HWTEST_F(PowerMgrClientTest, PowerMgrClient026, TestSize.Level0) 573 { 574 POWER_HILOGD(LABEL_TEST, "PowerMgrClient026::fun is start!"); 575 auto& powerMgrClient = PowerMgrClient::GetInstance(); 576 577 // Wakeup Device before test 578 powerMgrClient.WakeupDevice(); 579 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient026: Prepare Fail, Screen is OFF."; 580 581 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY, false); 582 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient026: Suspend Device Fail, Screen is On"; 583 584 POWER_HILOGD(LABEL_TEST, "PowerMgrClient026::fun is end!"); 585 } 586 587 /** 588 * @tc.name: PowerMgrClient027 589 * @tc.desc: test Suspend Device 590 * @tc.type: FUNC 591 * @tc.require: issueI5MJZJ 592 */ 593 HWTEST_F(PowerMgrClientTest, PowerMgrClient027, TestSize.Level0) 594 { 595 POWER_HILOGD(LABEL_TEST, "PowerMgrClient027::fun is start!"); 596 auto& powerMgrClient = PowerMgrClient::GetInstance(); 597 598 // Wakeup Device before test 599 powerMgrClient.WakeupDevice(); 600 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient027: Prepare Fail, Screen is OFF."; 601 602 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_HDMI, false); 603 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient027: Suspend Device Fail, Screen is On"; 604 605 POWER_HILOGD(LABEL_TEST, "PowerMgrClient027::fun is end!"); 606 } 607 608 /** 609 * @tc.name: PowerMgrClient028 610 * @tc.desc: test Suspend Device 611 * @tc.type: FUNC 612 * @tc.require: issueI5MJZJ 613 */ 614 HWTEST_F(PowerMgrClientTest, PowerMgrClient028, TestSize.Level0) 615 { 616 POWER_HILOGD(LABEL_TEST, "PowerMgrClient028::fun is start!"); 617 auto& powerMgrClient = PowerMgrClient::GetInstance(); 618 619 // Wakeup Device before test 620 powerMgrClient.WakeupDevice(); 621 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient028: Prepare Fail, Screen is OFF."; 622 623 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_SLEEP_KEY, false); 624 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient028: Suspend Device Fail, Screen is On"; 625 626 POWER_HILOGD(LABEL_TEST, "PowerMgrClient028::fun is end!"); 627 } 628 629 /** 630 * @tc.name: PowerMgrClient029 631 * @tc.desc: test Suspend Device 632 * @tc.type: FUNC 633 * @tc.require: issueI5MJZJ 634 */ 635 HWTEST_F(PowerMgrClientTest, PowerMgrClient029, TestSize.Level0) 636 { 637 POWER_HILOGD(LABEL_TEST, "PowerMgrClient029::fun is start!"); 638 auto& powerMgrClient = PowerMgrClient::GetInstance(); 639 640 // Wakeup Device before test 641 powerMgrClient.WakeupDevice(); 642 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient029: Prepare Fail, Screen is OFF."; 643 644 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_ACCESSIBILITY, false); 645 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient029: Suspend Device Fail, Screen is On"; 646 647 POWER_HILOGD(LABEL_TEST, "PowerMgrClient029::fun is end!"); 648 } 649 650 /** 651 * @tc.name: PowerMgrClient030 652 * @tc.desc: test Suspend Device 653 * @tc.type: FUNC 654 * @tc.require: issueI5MJZJ 655 */ 656 HWTEST_F(PowerMgrClientTest, PowerMgrClient030, TestSize.Level0) 657 { 658 POWER_HILOGD(LABEL_TEST, "PowerMgrClient030::fun is start!"); 659 auto& powerMgrClient = PowerMgrClient::GetInstance(); 660 661 // Wakeup Device before test 662 powerMgrClient.WakeupDevice(); 663 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient030: Prepare Fail, Screen is OFF."; 664 665 powerMgrClient.SuspendDevice(SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND, false); 666 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient030: Suspend Device Fail, Screen is On"; 667 668 POWER_HILOGD(LABEL_TEST, "PowerMgrClient030::fun is end!"); 669 } 670 671 /** 672 * @tc.name: PowerMgrClient031 673 * @tc.desc: test WakeupDevice(int64_t timeMs) in proxy 674 * @tc.type: FUNC 675 * @tc.require: issueI5MJZJ 676 */ 677 HWTEST_F(PowerMgrClientTest, PowerMgrClient031, TestSize.Level0) 678 { 679 POWER_HILOGD(LABEL_TEST, "PowerMgrClient031::fun is start!"); 680 auto& powerMgrClient = PowerMgrClient::GetInstance(); 681 682 // Suspend Device before test 683 powerMgrClient.SuspendDevice(); 684 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient031: Prepare Fail, Screen is On."; 685 686 powerMgrClient.WakeupDevice(); 687 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 688 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient031: Wakeup Device Fail, Screen is Off"; 689 690 POWER_HILOGD(LABEL_TEST, "PowerMgrClient031::fun is end!"); 691 } 692 693 /** 694 * @tc.name: PowerMgrClient032 695 * @tc.desc: test WakeupDevice 696 * @tc.type: FUNC 697 * @tc.require: issueI5MJZJ 698 */ 699 HWTEST_F(PowerMgrClientTest, PowerMgrClient032, TestSize.Level0) 700 { 701 POWER_HILOGD(LABEL_TEST, "PowerMgrClient032::fun is start!"); 702 auto& powerMgrClient = PowerMgrClient::GetInstance(); 703 704 // Suspend Device before test 705 powerMgrClient.SuspendDevice(); 706 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient032: Prepare Fail, Screen is On."; 707 708 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN); 709 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 710 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient032: Wakeup Device Fail, Screen is Off"; 711 712 POWER_HILOGD(LABEL_TEST, "PowerMgrClient032::fun is end!"); 713 } 714 715 /** 716 * @tc.name: PowerMgrClient033 717 * @tc.desc: test WakeupDevice 718 * @tc.type: FUNC 719 * @tc.require: issueI5MJZJ 720 */ 721 HWTEST_F(PowerMgrClientTest, PowerMgrClient033, TestSize.Level0) 722 { 723 POWER_HILOGD(LABEL_TEST, "PowerMgrClient033::fun is start!"); 724 auto& powerMgrClient = PowerMgrClient::GetInstance(); 725 726 // Suspend Device before test 727 powerMgrClient.SuspendDevice(); 728 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient033: Prepare Fail, Screen is On."; 729 730 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON); 731 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 732 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient033: Wakeup Device Fail, Screen is Off"; 733 734 POWER_HILOGD(LABEL_TEST, "PowerMgrClient033::fun is end!"); 735 } 736 737 /** 738 * @tc.name: PowerMgrClient046 739 * @tc.desc: test WakeupDevice 740 * @tc.type: FUNC 741 * @tc.require: issueI5MJZJ 742 */ 743 HWTEST_F(PowerMgrClientTest, PowerMgrClient046, TestSize.Level0) 744 { 745 POWER_HILOGD(LABEL_TEST, "PowerMgrClient046::fun is start!"); 746 auto& powerMgrClient = PowerMgrClient::GetInstance(); 747 748 // Suspend Device before test 749 powerMgrClient.SuspendDevice(); 750 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient046: Prepare Fail, Screen is On."; 751 752 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION); 753 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 754 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient046: Wakeup Device Fail, Screen is Off"; 755 756 POWER_HILOGD(LABEL_TEST, "PowerMgrClient046::fun is end!"); 757 } 758 759 /** 760 * @tc.name: PowerMgrClient034 761 * @tc.desc: test WakeupDevice 762 * @tc.type: FUNC 763 * @tc.require: issueI5MJZJ 764 */ 765 HWTEST_F(PowerMgrClientTest, PowerMgrClient034, TestSize.Level0) 766 { 767 POWER_HILOGD(LABEL_TEST, "PowerMgrClient034::fun is start!"); 768 auto& powerMgrClient = PowerMgrClient::GetInstance(); 769 770 // Suspend Device before test 771 powerMgrClient.SuspendDevice(); 772 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient034: Prepare Fail, Screen is On."; 773 774 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_PLUGGED_IN); 775 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 776 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient034: Wakeup Device Fail, Screen is Off"; 777 778 POWER_HILOGD(LABEL_TEST, "PowerMgrClient034::fun is end!"); 779 } 780 781 /** 782 * @tc.name: PowerMgrClient035 783 * @tc.desc: test WakeupDevice 784 * @tc.type: FUNC 785 * @tc.require: issueI5MJZJ 786 */ 787 HWTEST_F(PowerMgrClientTest, PowerMgrClient035, TestSize.Level0) 788 { 789 POWER_HILOGD(LABEL_TEST, "PowerMgrClient035::fun is start!"); 790 auto& powerMgrClient = PowerMgrClient::GetInstance(); 791 792 // Suspend Device before test 793 powerMgrClient.SuspendDevice(); 794 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient035: Prepare Fail, Screen is On."; 795 796 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_GESTURE); 797 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 798 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient035: Wakeup Device Fail, Screen is Off"; 799 800 POWER_HILOGD(LABEL_TEST, "PowerMgrClient035::fun is end!"); 801 } 802 803 /** 804 * @tc.name: PowerMgrClient036 805 * @tc.desc: test WakeupDevice 806 * @tc.type: FUNC 807 * @tc.require: issueI5MJZJ 808 */ 809 HWTEST_F(PowerMgrClientTest, PowerMgrClient036, TestSize.Level0) 810 { 811 POWER_HILOGD(LABEL_TEST, "PowerMgrClient036::fun is start!"); 812 auto& powerMgrClient = PowerMgrClient::GetInstance(); 813 814 // Suspend Device before test 815 powerMgrClient.SuspendDevice(); 816 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient036: Prepare Fail, Screen is On."; 817 818 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_CAMERA_LAUNCH); 819 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 820 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient036: Wakeup Device Fail, Screen is Off"; 821 822 POWER_HILOGD(LABEL_TEST, "PowerMgrClient036::fun is end!"); 823 } 824 825 /** 826 * @tc.name: PowerMgrClient037 827 * @tc.desc: test WakeupDevice 828 * @tc.type: FUNC 829 * @tc.require: issueI5MJZJ 830 */ 831 HWTEST_F(PowerMgrClientTest, PowerMgrClient037, TestSize.Level0) 832 { 833 POWER_HILOGD(LABEL_TEST, "PowerMgrClient037::fun is start!"); 834 auto& powerMgrClient = PowerMgrClient::GetInstance(); 835 836 // Suspend Device before test 837 powerMgrClient.SuspendDevice(); 838 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient037: Prepare Fail, Screen is On."; 839 840 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_WAKE_KEY); 841 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 842 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient037: Wakeup Device Fail, Screen is Off"; 843 844 POWER_HILOGD(LABEL_TEST, "PowerMgrClient037::fun is end!"); 845 } 846 847 /** 848 * @tc.name: PowerMgrClient038 849 * @tc.desc: test WakeupDevice 850 * @tc.type: FUNC 851 * @tc.require: issueI5MJZJ 852 */ 853 HWTEST_F(PowerMgrClientTest, PowerMgrClient038, TestSize.Level0) 854 { 855 POWER_HILOGD(LABEL_TEST, "PowerMgrClient038::fun is start!"); 856 auto& powerMgrClient = PowerMgrClient::GetInstance(); 857 858 // Suspend Device before test 859 powerMgrClient.SuspendDevice(); 860 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient038: Prepare Fail, Screen is On."; 861 862 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_WAKE_MOTION); 863 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 864 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient038: Wakeup Device Fail, Screen is Off"; 865 866 POWER_HILOGD(LABEL_TEST, "PowerMgrClient038::fun is end!"); 867 } 868 869 /** 870 * @tc.name: PowerMgrClient039 871 * @tc.desc: test WakeupDevice 872 * @tc.type: FUNC 873 * @tc.require: issueI5MJZJ 874 */ 875 HWTEST_F(PowerMgrClientTest, PowerMgrClient039, TestSize.Level0) 876 { 877 POWER_HILOGD(LABEL_TEST, "PowerMgrClient039::fun is start!"); 878 auto& powerMgrClient = PowerMgrClient::GetInstance(); 879 880 // Suspend Device before test 881 powerMgrClient.SuspendDevice(); 882 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient039: Prepare Fail, Screen is On."; 883 884 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_HDMI); 885 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 886 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient039: Wakeup Device Fail, Screen is Off"; 887 888 POWER_HILOGD(LABEL_TEST, "PowerMgrClient039::fun is end!"); 889 } 890 891 /** 892 * @tc.name: PowerMgrClient040 893 * @tc.desc: test WakeupDevice 894 * @tc.type: FUNC 895 * @tc.require: issueI5MJZJ 896 */ 897 HWTEST_F(PowerMgrClientTest, PowerMgrClient040, TestSize.Level0) 898 { 899 POWER_HILOGD(LABEL_TEST, "PowerMgrClient040::fun is start!"); 900 auto& powerMgrClient = PowerMgrClient::GetInstance(); 901 902 // Suspend Device before test 903 powerMgrClient.SuspendDevice(); 904 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient040: Prepare Fail, Screen is On."; 905 906 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_LID); 907 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 908 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient040: Wakeup Device Fail, Screen is Off"; 909 910 POWER_HILOGD(LABEL_TEST, "PowerMgrClient040::fun is end!"); 911 } 912 913 /** 914 * @tc.name: PowerMgrClient041 915 * @tc.desc: test WakeupDevice 916 * @tc.type: FUNC 917 * @tc.require: issueI5MJZJ 918 */ 919 HWTEST_F(PowerMgrClientTest, PowerMgrClient041, TestSize.Level0) 920 { 921 POWER_HILOGD(LABEL_TEST, "PowerMgrClient041::fun is start!"); 922 auto& powerMgrClient = PowerMgrClient::GetInstance(); 923 924 // Suspend Device before test 925 powerMgrClient.SuspendDevice(); 926 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient041: Prepare Fail, Screen is On."; 927 928 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_DOUBLE_CLICK); 929 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 930 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient041: Wakeup Device Fail, Screen is Off"; 931 932 POWER_HILOGD(LABEL_TEST, "PowerMgrClient041::fun is end!"); 933 } 934 935 /** 936 * @tc.name: PowerMgrClient042 937 * @tc.desc: test WakeupDevice 938 * @tc.type: FUNC 939 * @tc.require: issueI5MJZJ 940 */ 941 HWTEST_F(PowerMgrClientTest, PowerMgrClient042, TestSize.Level0) 942 { 943 POWER_HILOGD(LABEL_TEST, "PowerMgrClient042::fun is start!"); 944 auto& powerMgrClient = PowerMgrClient::GetInstance(); 945 946 // Suspend Device before test 947 powerMgrClient.SuspendDevice(); 948 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient042: Prepare Fail, Screen is On."; 949 950 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_KEYBOARD); 951 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 952 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient042: Wakeup Device Fail, Screen is Off"; 953 954 POWER_HILOGD(LABEL_TEST, "PowerMgrClient042::fun is end!"); 955 } 956 957 /** 958 * @tc.name: PowerMgrClient043 959 * @tc.desc: test WakeupDevice 960 * @tc.type: FUNC 961 * @tc.require: issueI5MJZJ 962 */ 963 HWTEST_F(PowerMgrClientTest, PowerMgrClient043, TestSize.Level0) 964 { 965 POWER_HILOGD(LABEL_TEST, "PowerMgrClient043::fun is start!"); 966 auto& powerMgrClient = PowerMgrClient::GetInstance(); 967 968 // Suspend Device before test 969 powerMgrClient.SuspendDevice(); 970 EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient043: Prepare Fail, Screen is On."; 971 972 powerMgrClient.WakeupDevice(WakeupDeviceType::WAKEUP_DEVICE_MOUSE); 973 EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE); 974 EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient043: Wakeup Device Fail, Screen is Off"; 975 976 POWER_HILOGD(LABEL_TEST, "PowerMgrClient043::fun is end!"); 977 } 978 979 /** 980 * @tc.name: PowerMgrClient021 981 * @tc.desc: test IsRunningLockTypeSupported 982 * @tc.type: FUNC 983 * @tc.require: issueI5MJZJ 984 */ 985 HWTEST_F(PowerMgrClientTest, PowerMgrClient021, TestSize.Level0) 986 { 987 POWER_HILOGD(LABEL_TEST, "PowerMgrClient021:Start."); 988 989 auto& powerMgrClient = PowerMgrClient::GetInstance(); 990 991 auto ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT); 992 EXPECT_EQ(ret, false); 993 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_SCREEN); 994 EXPECT_EQ(ret, true); 995 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND); 996 EXPECT_EQ(ret, true); 997 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL); 998 EXPECT_EQ(ret, true); 999 powerMgrClient.WakeupDevice(); 1000 EXPECT_EQ(powerMgrClient.IsScreenOn(), true); 1001 powerMgrClient.SuspendDevice(); 1002 EXPECT_EQ(powerMgrClient.IsScreenOn(), false); 1003 1004 POWER_HILOGD(LABEL_TEST, "PowerMgrClient021:End."); 1005 } 1006 1007 /** 1008 * @tc.name: PowerMgrClient044 1009 * @tc.desc: Test GetError 1010 * @tc.type: FUNC 1011 * @tc.require: issue I5YZQR 1012 */ 1013 HWTEST_F(PowerMgrClientTest, PowerMgrClient044, TestSize.Level0) 1014 { 1015 POWER_HILOGD(LABEL_TEST, "fun is start"); 1016 PowerErrors error = PowerMgrClient::GetInstance().GetError(); 1017 POWER_HILOGD(LABEL_TEST, "get error %{public}d", static_cast<int32_t>(error)); 1018 EXPECT_TRUE(error == PowerErrors::ERR_OK); 1019 } 1020 1021 /** 1022 * @tc.name: PowerMgrClient045 1023 * @tc.desc: test IsRunningLockTypeSupported for BACKGROUND lock types 1024 * @tc.type: FUNC 1025 * @tc.require: issueI6FMHX 1026 */ 1027 HWTEST_F(PowerMgrClientTest, PowerMgrClient045, TestSize.Level0) 1028 { 1029 POWER_HILOGD(LABEL_TEST, "PowerMgrClient045:Start."); 1030 auto& powerMgrClient = PowerMgrClient::GetInstance(); 1031 auto ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND_PHONE); 1032 EXPECT_EQ(ret, true); 1033 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND_NOTIFICATION); 1034 EXPECT_EQ(ret, true); 1035 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO); 1036 EXPECT_EQ(ret, true); 1037 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND_SPORT); 1038 EXPECT_EQ(ret, true); 1039 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND_NAVIGATION); 1040 EXPECT_EQ(ret, true); 1041 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND_TASK); 1042 EXPECT_EQ(ret, true); 1043 ret = powerMgrClient.IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT); 1044 EXPECT_EQ(ret, false); 1045 POWER_HILOGD(LABEL_TEST, "PowerMgrClient045:End."); 1046 } 1047 } // namespace