• 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 "screen_session_manager/include/screen_session_manager_lite.h"
19 #include "window_manager_hilog.h"
20 #include "display_manager_agent_default.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28 constexpr uint32_t SLEEP_TIME_US = 100000;
29 }
30 
31 class ScreenSessionManagerLiteTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase()39 void ScreenSessionManagerLiteTest::SetUpTestCase()
40 {
41 }
42 
TearDownTestCase()43 void ScreenSessionManagerLiteTest::TearDownTestCase()
44 {
45 }
46 
SetUp()47 void ScreenSessionManagerLiteTest::SetUp()
48 {
49 }
50 
TearDown()51 void ScreenSessionManagerLiteTest::TearDown()
52 {
53     usleep(SLEEP_TIME_US);
54 }
55 
56 namespace {
57 
58 /**
59  * @tc.name: ConnectToServer
60  * @tc.desc: ConnectToServer
61  * @tc.type: FUNC
62  */
63 HWTEST_F(ScreenSessionManagerLiteTest, ConnectToServer, TestSize.Level1)
64 {
65     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
66     screenSessionManagerLite.ConnectToServer();
67     ASSERT_EQ(screenSessionManagerLite.screenSessionManager_, nullptr);
68 }
69 
70 /**
71  * @tc.name: RegisterDisplayManagerAgent
72  * @tc.desc: RegisterDisplayManagerAgent
73  * @tc.type: FUNC
74  */
75 HWTEST_F(ScreenSessionManagerLiteTest, RegisterDisplayManagerAgent, TestSize.Level1)
76 {
77     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
78     sptr<IDisplayManagerAgent> displayManagerAgent= new DisplayManagerAgentDefault();
79     DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER;
80     DMError ret = screenSessionManagerLite.RegisterDisplayManagerAgent(displayManagerAgent, type);
81     ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
82 }
83 
84 /**
85  * @tc.name: UnregisterDisplayManagerAgent
86  * @tc.desc: UnregisterDisplayManagerAgent
87  * @tc.type: FUNC
88  */
89 HWTEST_F(ScreenSessionManagerLiteTest, UnregisterDisplayManagerAgent, TestSize.Level1)
90 {
91     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
92     sptr<IDisplayManagerAgent> displayManagerAgent= new DisplayManagerAgentDefault();
93     DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER;
94     DMError ret = screenSessionManagerLite.UnregisterDisplayManagerAgent(displayManagerAgent, type);
95     ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
96 }
97 
98 /**
99  * @tc.name: GetFoldDisplayMode
100  * @tc.desc: GetFoldDisplayMode
101  * @tc.type: FUNC
102  */
103 HWTEST_F(ScreenSessionManagerLiteTest, GetFoldDisplayMode, TestSize.Level1)
104 {
105     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
106     FoldDisplayMode ret = screenSessionManagerLite.GetFoldDisplayMode();
107     ASSERT_EQ(ret, FoldDisplayMode::UNKNOWN);
108 }
109 
110 /**
111  * @tc.name: IsFoldable
112  * @tc.desc: IsFoldable
113  * @tc.type: FUNC
114  */
115 HWTEST_F(ScreenSessionManagerLiteTest, IsFoldable, TestSize.Level1)
116 {
117     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
118     bool ret = screenSessionManagerLite.IsFoldable();
119     ASSERT_FALSE(ret);
120 }
121 
122 /**
123  * @tc.name: GetFoldStatus
124  * @tc.desc: GetFoldStatus
125  * @tc.type: FUNC
126  */
127 HWTEST_F(ScreenSessionManagerLiteTest, GetFoldStatus, TestSize.Level1)
128 {
129     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
130     FoldStatus ret = screenSessionManagerLite.GetFoldStatus();
131     ASSERT_EQ(ret, FoldStatus::UNKNOWN);
132 }
133 
134 /**
135  * @tc.name: GetDefaultDisplayInfo
136  * @tc.desc: GetDefaultDisplayInfo
137  * @tc.type: FUNC
138  */
139 HWTEST_F(ScreenSessionManagerLiteTest, GetDefaultDisplayInfo, TestSize.Level1)
140 {
141     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
142     sptr<DisplayInfo> ret = screenSessionManagerLite.GetDefaultDisplayInfo();
143     ASSERT_EQ(ret, nullptr);
144 }
145 
146 /**
147  * @tc.name: GetDisplayInfoById
148  * @tc.desc: GetDisplayInfoById
149  * @tc.type: FUNC
150  */
151 HWTEST_F(ScreenSessionManagerLiteTest, GetDisplayInfoById, TestSize.Level1)
152 {
153     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
154     DisplayId displayId = 0;
155     sptr<DisplayInfo> ret = screenSessionManagerLite.GetDisplayInfoById(displayId);
156     ASSERT_EQ(ret, nullptr);
157 }
158 
159 /**
160  * @tc.name: GetCutoutInfo
161  * @tc.desc: GetCutoutInfo
162  * @tc.type: FUNC
163  */
164 HWTEST_F(ScreenSessionManagerLiteTest, GetCutoutInfo, TestSize.Level1)
165 {
166     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
167     DisplayId displayId = 0;
168     sptr<CutoutInfo> ret = screenSessionManagerLite.GetCutoutInfo(displayId);
169     ASSERT_EQ(ret, nullptr);
170 }
171 
172 /**
173  * @tc.name: Clear
174  * @tc.desc: Clear
175  * @tc.type: FUNC
176  */
177 HWTEST_F(ScreenSessionManagerLiteTest, Clear, TestSize.Level1)
178 {
179     ScreenSessionManagerLite screenSessionManagerLite = ScreenSessionManagerLite();
180     screenSessionManagerLite.Clear();
181     ASSERT_EQ(screenSessionManagerLite.screenSessionManager_, nullptr);
182 }
183 
184 /**
185  * @tc.name: GetInstance_ShouldCreateNewInstance_WhenInstanceIsNull
186  * @tc.desc: Test if GetInstance creates a new instance when instance is nullptr
187  * @tc.type: FUNC
188  */
189 HWTEST_F(ScreenSessionManagerLiteTest, GetInstance_ShouldCreateNewInstance_WhenInstanceIsNull, TestSize.Level1)
190 {
191     ScreenSessionManagerLite& instance = ScreenSessionManagerLite::GetInstance();
192 
193     EXPECT_NE(nullptr, &instance);
194 }
195 
196 /**
197  * @tc.name: GetInstance_ShouldReturnExistingInstance_WhenInstanceIsNotNull
198  * @tc.desc: Test if GetInstance returns the existing instance when it's not nullptr
199  * @tc.type: FUNC
200  */
201 HWTEST_F(ScreenSessionManagerLiteTest, GetInstance_ShouldReturnExistingInstance_WhenInstanceIsNotNull,
202     TestSize.Level1)
203 {
204     ScreenSessionManagerLite& instance1 = ScreenSessionManagerLite::GetInstance();
205 
206     ScreenSessionManagerLite& instance2 = ScreenSessionManagerLite::GetInstance();
207 
208     EXPECT_EQ(&instance1, &instance2);
209 }
210 }
211 } // namespace Rosen
212 } // namespace OHOS