• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
17 
18 #include "display_power_controller.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26 constexpr uint32_t SLEEP_TIME_US = 100000;
27 }
28 class DisplayPowerControllerTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 
35 private:
36     std::recursive_mutex mutex_;
37     sptr<DisplayPowerController> dpc_ = nullptr;
38 };
39 
SetUpTestCase()40 void DisplayPowerControllerTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void DisplayPowerControllerTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void DisplayPowerControllerTest::SetUp()
49 {
50 }
51 
TearDown()52 void DisplayPowerControllerTest::TearDown()
53 {
54     usleep(SLEEP_TIME_US);
55 }
56 
57 namespace {
58 /**
59  * @tc.name: SuspendBegin
60  * @tc.desc: test function : SuspendBegin
61  * @tc.type: FUNC
62  */
63 HWTEST_F(DisplayPowerControllerTest, SuspendBegin, TestSize.Level1)
64 {
65     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30302(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 66         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
67 
68     PowerStateChangeReason reason = PowerStateChangeReason{0};
69     auto ret = dpc_->SuspendBegin(reason);
70     ASSERT_EQ(true, ret);
71 }
72 
73 /**
74  * @tc.name: SetDisplayState01
75  * @tc.desc: test function : SetDisplayState
76  * @tc.type: FUNC
77  */
78 HWTEST_F(DisplayPowerControllerTest, SetDisplayState01, TestSize.Level1)
79 {
80     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30402(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 81         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
82 
83     DisplayState state = DisplayState::UNKNOWN;
84     auto ret = dpc_->SetDisplayState(state);
85     ASSERT_EQ(false, ret);
86 }
87 
88 /**
89  * @tc.name: SetDisplayState02
90  * @tc.desc: test function : SetDisplayState
91  * @tc.type: FUNC
92  */
93 HWTEST_F(DisplayPowerControllerTest, SetDisplayState02, TestSize.Level1)
94 {
95     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30502(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 96         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
97 
98     DisplayState state = DisplayState::ON;
99     auto ret = dpc_->SetDisplayState(state);
100     ASSERT_EQ(true, ret);
101 }
102 
103 /**
104  * @tc.name: SetDisplayState03
105  * @tc.desc: test function : SetDisplayState
106  * @tc.type: FUNC
107  */
108 HWTEST_F(DisplayPowerControllerTest, SetDisplayState03, TestSize.Level1)
109 {
110     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30602(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 111         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
112 
113     DisplayState state = DisplayState::OFF;
114     auto ret = dpc_->SetDisplayState(state);
115     ASSERT_EQ(true, ret);
116 }
117 
118 /**
119  * @tc.name: SetDisplayState04
120  * @tc.desc: test function : SetDisplayState
121  * @tc.type: FUNC
122  */
123 HWTEST_F(DisplayPowerControllerTest, SetDisplayState04, TestSize.Level1)
124 {
125     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30702(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 126         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
127 
128     DisplayState state = dpc_->GetDisplayState(0);
129     auto ret = dpc_->SetDisplayState(state);
130     EXPECT_EQ(false, ret);
131 }
132 
133 /**
134  * @tc.name: GetDisplayState
135  * @tc.desc: test function : GetDisplayState
136  * @tc.type: FUNC
137  */
138 HWTEST_F(DisplayPowerControllerTest, GetDisplayState, TestSize.Level1)
139 {
140     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30802(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 141         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
142 
143     DisplayId displayId = 1;
144     auto ret = dpc_->GetDisplayState(displayId);
145     ASSERT_EQ(DisplayState::UNKNOWN, ret);
146 }
147 
148 /**
149  * @tc.name: NotifyDisplayEvent01
150  * @tc.desc: test function : NotifyDisplayEvent
151  * @tc.type: FUNC
152  */
153 HWTEST_F(DisplayPowerControllerTest, NotifyDisplayEvent01, TestSize.Level1)
154 {
155     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30902(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 156         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
157 
158     DisplayEvent event = DisplayEvent::UNLOCK;
159     dpc_->NotifyDisplayEvent(event);
160     ASSERT_EQ(false, dpc_->isKeyguardDrawn_);
161 }
162 
163 /**
164  * @tc.name: NotifyDisplayEvent02
165  * @tc.desc: test function : NotifyDisplayEvent
166  * @tc.type: FUNC
167  */
168 HWTEST_F(DisplayPowerControllerTest, NotifyDisplayEvent02, TestSize.Level1)
169 {
170     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30a02(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 171         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
172 
173     DisplayEvent event = DisplayEvent::KEYGUARD_DRAWN;
174     dpc_->NotifyDisplayEvent(event);
175     ASSERT_EQ(true, dpc_->isKeyguardDrawn_);
176 }
177 
178 /**
179  * @tc.name: NotifyDisplayEvent03
180  * @tc.desc: test function : NotifyDisplayEvent
181  * @tc.type: FUNC
182  */
183 HWTEST_F(DisplayPowerControllerTest, NotifyDisplayEvent03, TestSize.Level1)
184 {
185     dpc_ = new DisplayPowerController(mutex_, [](DisplayId, sptr<DisplayInfo>,
__anone332f2e30b02(DisplayId, sptr<DisplayInfo>, const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) 186         const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType) {});
187 
188     bool isKeyguardDrawn = dpc_->isKeyguardDrawn_;
189     DisplayEvent event = DisplayEvent::SCREEN_LOCK_END_DREAM;
190     dpc_->NotifyDisplayEvent(event);
191     EXPECT_EQ(isKeyguardDrawn, dpc_->isKeyguardDrawn_);
192 }
193 }
194 }
195 }