• 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 "fold_screen_controller/fold_screen_policy.h"
19 #include "fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h"
20 #include "fold_screen_state_internel.h"
21 #include "screen_session_manager/include/screen_session_manager.h"
22 #include "window_manager_hilog.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace {
30 constexpr uint32_t SLEEP_TIME_US = 100000;
31 }
32 
33 class SensorFoldStateManagerTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase()41 void SensorFoldStateManagerTest::SetUpTestCase()
42 {
43 }
44 
TearDownTestCase()45 void SensorFoldStateManagerTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void SensorFoldStateManagerTest::SetUp()
50 {
51 }
52 
TearDown()53 void SensorFoldStateManagerTest::TearDown()
54 {
55     usleep(SLEEP_TIME_US);
56 }
57 
58 namespace {
59 
60 /**
61  * @tc.name: HandleSensorChange
62  * @tc.desc: HandleSensorChange
63  * @tc.type: FUNC
64  */
65 HWTEST_F(SensorFoldStateManagerTest, HandleSensorChange, Function | SmallTest | Level3)
66 {
67     SensorFoldStateManager mgr = SensorFoldStateManager();
68     FoldStatus nextState = FoldStatus::UNKNOWN;
69     float angle = 0.0f;
70     sptr<FoldScreenPolicy> foldScreenPolicy = new FoldScreenPolicy();
71     mgr.HandleSensorChange(nextState, angle, foldScreenPolicy);
72     ASSERT_EQ(mgr.mState_, FoldStatus::UNKNOWN);
73 
74     mgr.mState_ = FoldStatus::EXPAND;
75     mgr.HandleSensorChange(nextState, angle, foldScreenPolicy);
76     ASSERT_EQ(mgr.mState_, FoldStatus::EXPAND);
77 
78     nextState = FoldStatus::EXPAND;
79     mgr.HandleSensorChange(nextState, angle, foldScreenPolicy);
80     ASSERT_EQ(mgr.mState_, FoldStatus::EXPAND);
81 }
82 
83 /**
84  * @tc.name: ReportNotifyFoldStatusChange
85  * @tc.desc: ReportNotifyFoldStatusChange
86  * @tc.type: FUNC
87  */
88 HWTEST_F(SensorFoldStateManagerTest, ReportNotifyFoldStatusChange, Function | SmallTest | Level3)
89 {
90     SensorFoldStateManager mgr = SensorFoldStateManager();
91     int32_t currentStatus = 0;
92     int32_t nextStatus = 1;
93     float postureAngle = 0.0f;
94     mgr.ReportNotifyFoldStatusChange(currentStatus, nextStatus, postureAngle);
95     ASSERT_EQ(mgr.GetCurrentState(), FoldStatus::UNKNOWN);
96 }
97 
98 /**
99  * @tc.name: ClearState
100  * @tc.desc: ClearState
101  * @tc.type: FUNC
102  */
103 HWTEST_F(SensorFoldStateManagerTest, ClearState, Function | SmallTest | Level3)
104 {
105     SensorFoldStateManager mgr = SensorFoldStateManager();
106     sptr<FoldScreenPolicy> foldScreenPolicy = new FoldScreenPolicy();
107     mgr.ClearState(foldScreenPolicy);
108     ASSERT_EQ(mgr.GetCurrentState(), FoldStatus::UNKNOWN);
109 }
110 
111 /**
112  * @tc.name: NotifyReportFoldStatusToScb
113  * @tc.desc: NotifyReportFoldStatusToScb
114  * @tc.type: FUNC
115  */
116 HWTEST_F(SensorFoldStateManagerTest, NotifyReportFoldStatusToScb, Function | SmallTest | Level3)
117 {
118     SensorFoldStateManager mgr = SensorFoldStateManager();
119     FoldStatus currentStatus = FoldStatus::UNKNOWN;
120     FoldStatus nextStatus = FoldStatus::EXPAND;
121     float postureAngle = 0.0f;
122     mgr.NotifyReportFoldStatusToScb(currentStatus, nextStatus, postureAngle);
123     ASSERT_EQ(mgr.GetCurrentState(), FoldStatus::UNKNOWN);
124 }
125 
126 /**
127  * @tc.name: IsTentMode
128  * @tc.desc: IsTentMode
129  * @tc.type: FUNC
130  */
131 HWTEST_F(SensorFoldStateManagerTest, IsTentMode, Function | SmallTest | Level1)
132 {
133     SensorFoldStateManager mgr = SensorFoldStateManager();
134     mgr.tentModeType_ = 1;
135     bool ret = mgr.IsTentMode();
136     ASSERT_EQ(ret, true);
137 }
138 
139 /**
140  * @tc.name: SetTentMode
141  * @tc.desc: SetTentMode
142  * @tc.type: FUNC
143  */
144 HWTEST_F(SensorFoldStateManagerTest, SetTentMode, Function | SmallTest | Level1)
145 {
146     SensorFoldStateManager mgr = SensorFoldStateManager();
147     mgr.tentModeType_ = 0;
148     mgr.SetTentMode(0);
149     bool ret = mgr.IsTentMode();
150     ASSERT_EQ(ret, false);
151 }
152 }
153 } // namespace Rosen
154 } // namespace OHOS