• 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 #include <ui_content.h>
18 #include <viewport_config.h>
19 
20 #include "app_mgr_client.h"
21 #include "singleton.h"
22 #include "singleton_container.h"
23 
24 #include "screen_scene.h"
25 #include "vsync_station.h"
26 #include "window_manager_hilog.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Rosen {
33 class ScreenSceneTest : 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 ScreenSceneTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void ScreenSceneTest::TearDownTestCase() {}
44 
SetUp()45 void ScreenSceneTest::SetUp() {}
46 
TearDown()47 void ScreenSceneTest::TearDown() {}
48 
49 namespace {
50 /**
51  * @tc.name: LoadContent01
52  * @tc.desc: context is nullptr
53  * @tc.type: FUNC
54  */
55 HWTEST_F(ScreenSceneTest, LoadContent01, TestSize.Level1)
56 {
57     ScreenScene screenScene("UNKNOWN");
58     screenScene.LoadContent("a", nullptr, nullptr, nullptr);
59     ASSERT_EQ(1, screenScene.GetWindowId());
60 }
61 
62 /**
63  * @tc.name: Destroy01
64  * @tc.desc: context is nullptr
65  * @tc.type: FUNC
66  */
67 HWTEST_F(ScreenSceneTest, Destroy01, TestSize.Level1)
68 {
69     ScreenScene screenScene("UNKNOWN");
70     screenScene.LoadContent("a", nullptr, nullptr, nullptr);
71     screenScene.Destroy();
72     ASSERT_EQ(1, screenScene.GetWindowId());
73 }
74 
75 /**
76  * @tc.name: UpdateViewportConfig01
77  * @tc.desc: UpdateViewportConfig Test
78  * @tc.type: FUNC
79  */
80 HWTEST_F(ScreenSceneTest, UpdateViewportConfig01, TestSize.Level1)
81 {
82     ScreenScene screenScene("UNKNOWN");
83     Rect rect;
84     screenScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
85     ASSERT_EQ(1, screenScene.GetWindowId());
86 }
87 
88 /**
89  * @tc.name: UpdateConfiguration
90  * @tc.desc: UpdateConfiguration Test
91  * @tc.type: FUNC
92  */
93 HWTEST_F(ScreenSceneTest, UpdateConfiguration, TestSize.Level1)
94 {
95     ScreenScene screenScene("UNKNOWN");
96     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
97     screenScene.UpdateConfiguration(configuration);
98     ASSERT_EQ(1, screenScene.GetWindowId());
99 }
100 
101 /**
102  * @tc.name: RequestVsync
103  * @tc.desc: RequestVsync Test
104  * @tc.type: FUNC
105  */
106 HWTEST_F(ScreenSceneTest, RequestVsync, TestSize.Level1)
107 {
108     ScreenScene screenScene("UNKNOWN");
109     std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
110     screenScene.RequestVsync(vsyncCallback);
111     ASSERT_EQ(1, screenScene.GetWindowId());
112 }
113 
114 /**
115  * @tc.name: GetVSyncPeriod
116  * @tc.desc: GetVSyncPeriod Test
117  * @tc.type: FUNC
118  */
119 HWTEST_F(ScreenSceneTest, GetVSyncPeriod, TestSize.Level1)
120 {
121     ScreenScene screenScene("UNKNOWN");
122     screenScene.GetVSyncPeriod();
123     ASSERT_EQ(1, screenScene.GetWindowId());
124 }
125 
126 /**
127  * @tc.name: FlushFrameRate
128  * @tc.desc: FlushFrameRate Test
129  * @tc.type: FUNC
130  */
131 HWTEST_F(ScreenSceneTest, FlushFrameRate, TestSize.Level1)
132 {
133     ScreenScene screenScene("UNKNOWN");
134     uint32_t rate = 120;
135     int32_t animatorExpectedFrameRate = -1;
136     screenScene.FlushFrameRate(rate, animatorExpectedFrameRate);
137     ASSERT_EQ(1, screenScene.GetWindowId());
138 }
139 
140 /**
141  * @tc.name: OnBundleUpdated
142  * @tc.desc: OnBundleUpdated Test
143  * @tc.type: FUNC
144  */
145 HWTEST_F(ScreenSceneTest, OnBundleUpdated, TestSize.Level1)
146 {
147     ScreenScene screenScene("UNKNOWN");
148     std::string bundleName = "test";
149     screenScene.OnBundleUpdated(bundleName);
150     ASSERT_EQ(1, screenScene.GetWindowId());
151 }
152 
153 /**
154  * @tc.name: GetDisplayId & SetDisplayId
155  * @tc.desc: GetDisplayId & SetDisplayId Test01
156  * @tc.type: FUNC
157  */
158 HWTEST_F(ScreenSceneTest, DisplayIdTest01, TestSize.Level1)
159 {
160     ScreenScene screenScene("UNKNOWN");
161     DisplayId setDisplayId = 0;
162     screenScene.SetDisplayId(setDisplayId);
163     screenScene.GetDisplayId();
164     ASSERT_EQ(1, screenScene.GetWindowId());
165 }
166 
167 /**
168  * @tc.name: GetDisplayId & SetDisplayId
169  * @tc.desc: GetDisplayId & SetDisplayId Test02
170  * @tc.type: FUNC
171  */
172 HWTEST_F(ScreenSceneTest, DisplayIdTest02, TestSize.Level1)
173 {
174     ScreenScene screenScene("UNKNOWN");
175     DisplayId setDisplayId = 100;
176     screenScene.SetDisplayId(setDisplayId);
177     screenScene.GetDisplayId();
178     ASSERT_EQ(1, screenScene.GetWindowId());
179 }
180 
181 /**
182  * @tc.name: SetDisplayOrientation
183  * @tc.desc: SetDisplayOrientation Test01
184  * @tc.type: FUNC
185  */
186 HWTEST_F(ScreenSceneTest, SetDisplayOrientation01, TestSize.Level1)
187 {
188     ScreenScene screenScene("UNKNOWN");
189     int32_t orientation = 0;
190     screenScene.SetDisplayOrientation(orientation);
191     ASSERT_EQ(1, screenScene.GetWindowId());
192 }
193 
194 /**
195  * @tc.name: SetDisplayOrientation
196  * @tc.desc: SetDisplayOrientation Test02
197  * @tc.type: FUNC
198  */
199 HWTEST_F(ScreenSceneTest, SetDisplayOrientation02, TestSize.Level1)
200 {
201     ScreenScene screenScene("UNKNOWN");
202     int32_t orientation = 100;
203     screenScene.SetDisplayOrientation(orientation);
204     ASSERT_EQ(1, screenScene.GetWindowId());
205 }
206 
207 /**
208  * @tc.name: SetFrameLayoutFinishCallback
209  * @tc.desc: SetFrameLayoutFinishCallback Test
210  * @tc.type: FUNC
211  */
212 HWTEST_F(ScreenSceneTest, SetFrameLayoutFinishCallback, TestSize.Level1)
213 {
214     ScreenScene screenScene("UNKNOWN");
__anon4181e6a70202() 215     screenScene.SetFrameLayoutFinishCallback([]() {});
216     ASSERT_EQ(1, screenScene.GetWindowId());
217 }
218 
219 /**
220  * @tc.name: SetDisplayDensity
221  * @tc.desc: SetDisplayDensity Test
222  * @tc.type: FUNC
223  */
224 HWTEST_F(ScreenSceneTest, SetDisplayDensity, TestSize.Level1)
225 {
226     ScreenScene screenScene("UNKNOWN");
227     float density = 2.0f;
228     screenScene.SetDisplayDensity(density);
229     ASSERT_EQ(1, screenScene.GetWindowId());
230 }
231 
232 /**
233  * @tc.name: IsSystemWindow
234  * @tc.desc: IsSystemWindow Test
235  * @tc.type: FUNC
236  */
237 HWTEST_F(ScreenSceneTest, IsSystemWindow, TestSize.Level1)
238 {
239     ScreenScene screenScene("UNKNOWN");
240     bool res = screenScene.IsSystemWindow();
241     ASSERT_EQ(true, res);
242 }
243 
244 /**
245  * @tc.name: IsAppWindow
246  * @tc.desc: IsAppWindow Test
247  * @tc.type: FUNC
248  */
249 HWTEST_F(ScreenSceneTest, IsAppWindow, TestSize.Level1)
250 {
251     ScreenScene screenScene("UNKNOWN");
252     bool res = screenScene.IsAppWindow();
253     ASSERT_EQ(false, res);
254 }
255 } // namespace
256 } // namespace Rosen
257 } // namespace OHOS