• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "device_state_action_native_test.h"
17 
18 #include <ipc_skeleton.h>
19 
20 #include "actions/irunning_lock_action.h"
21 #include "display_power_mgr_client.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::PowerMgr;
25 using namespace OHOS;
26 using namespace std;
27 
SetUpTestCase()28 void DeviceStateActionNativeTest::SetUpTestCase() {}
29 
30 namespace {
31 using SuspendCallback1 = std::function<void(uint32_t)>;
32 
DeviceStateActionCallback(uint32_t trigger)33 void DeviceStateActionCallback(uint32_t trigger) {}
34 
35 /**
36  * @tc.name: DeviceStateActionNative001
37  * @tc.desc: test init in deviceStateAction
38  * @tc.type: FUNC
39  */
40 HWTEST_F(DeviceStateActionNativeTest, DeviceStateActionNative001, TestSize.Level0)
41 {
42     POWER_HILOGI(LABEL_TEST, "DeviceStateActionNative001::fun is start!");
43     auto deviceStateAction = std::make_shared<DeviceStateAction>();
44     SuspendCallback1 sd = DeviceStateActionCallback;
45     deviceStateAction->RegisterCallback(sd);
46 
47     DisplayPowerMgr::DisplayState stateType = DisplayPowerMgr::DisplayState::DISPLAY_ON;
48     deviceStateAction->dispCallback_->OnDisplayStateChanged(
49         DISPLAYID, stateType, static_cast<uint32_t>(StateChangeReason::STATE_CHANGE_REASON_APPLICATION));
50     deviceStateAction->dispCallback_->OnDisplayStateChanged(
51         DISPLAYID_A, stateType, static_cast<uint32_t>(StateChangeReason::STATE_CHANGE_REASON_APPLICATION));
52     stateType = DisplayPowerMgr::DisplayState::DISPLAY_OFF;
53     deviceStateAction->dispCallback_->OnDisplayStateChanged(
54         DISPLAYID_A, stateType, static_cast<uint32_t>(StateChangeReason::STATE_CHANGE_REASON_APPLICATION));
55     stateType = DisplayPowerMgr::DisplayState::DISPLAY_UNKNOWN;
56     deviceStateAction->dispCallback_->OnDisplayStateChanged(
57         DISPLAYID_A, stateType, static_cast<uint32_t>(StateChangeReason::STATE_CHANGE_REASON_APPLICATION));
58     deviceStateAction->dispCallback_->notify_ = nullptr;
59     deviceStateAction->dispCallback_->NotifyDisplayActionDone(DISPLAYID);
60 
61     DisplayState state = DisplayState::DISPLAY_OFF;
62     StateChangeReason reason = StateChangeReason::STATE_CHANGE_REASON_INIT;
63     EXPECT_TRUE(deviceStateAction->SetDisplayState(state, reason) == ActionResult::SUCCESS);
64     EXPECT_TRUE(deviceStateAction->GetDisplayState() == DisplayState::DISPLAY_OFF);
65     state = DisplayState::DISPLAY_ON;
66     EXPECT_TRUE(deviceStateAction->SetDisplayState(state, reason) == ActionResult::SUCCESS);
67     EXPECT_TRUE(deviceStateAction->GetDisplayState() == DisplayState::DISPLAY_ON);
68     state = DisplayState::DISPLAY_DIM;
69     EXPECT_TRUE(deviceStateAction->SetDisplayState(state, reason) == ActionResult::SUCCESS);
70     EXPECT_TRUE(deviceStateAction->GetDisplayState() == DisplayState::DISPLAY_DIM);
71     state = DisplayState::DISPLAY_SUSPEND;
72     EXPECT_TRUE(deviceStateAction->SetDisplayState(state, reason) == ActionResult::SUCCESS);
73     EXPECT_TRUE(deviceStateAction->GetDisplayState() == DisplayState::DISPLAY_SUSPEND);
74     state = DisplayState::DISPLAY_UNKNOWN;
75     EXPECT_TRUE(deviceStateAction->SetDisplayState(state, reason) == ActionResult::FAILED);
76     EXPECT_FALSE(deviceStateAction->GetDisplayState() == DisplayState::DISPLAY_UNKNOWN);
77     deviceStateAction->SetDisplayState(DisplayState::DISPLAY_OFF, reason);
78     deviceStateAction->SetDisplayState(DisplayState::DISPLAY_ON, reason);
79     POWER_HILOGI(LABEL_TEST, "DeviceStateActionNative001::fun is end!");
80 }
81 } // namespace
82