1 /*
2 * Copyright (c) 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 <gtest/gtest.h>
17 #include "root_scene.h"
18 #include <event_handler.h>
19 #include <input_manager.h>
20 #include <ui_content.h>
21 #include <viewport_config.h>
22
23 #include "app_mgr_client.h"
24 #include "singleton.h"
25 #include "singleton_container.h"
26
27 #include "vsync_station.h"
28 #include "window_manager_hilog.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32
33 namespace OHOS {
34 namespace Rosen {
35 const uint32_t MOCK_LEM_SUB_WIDTH = 340;
36 const uint32_t MOCK_LEM_SUB_HEIGHT = 340;
37
38 class RootSceneTest : public testing::Test {
39 public:
40 static void SetUpTestCase();
41 static void TearDownTestCase();
42 void SetUp() override;
43 void TearDown() override;
44 private:
45 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
46 };
47
SetUpTestCase()48 void RootSceneTest::SetUpTestCase()
49 {
50 }
51
TearDownTestCase()52 void RootSceneTest::TearDownTestCase()
53 {
54 }
55
SetUp()56 void RootSceneTest::SetUp()
57 {
58 }
59
TearDown()60 void RootSceneTest::TearDown()
61 {
62 usleep(WAIT_SYNC_IN_NS);
63 }
64
65 namespace {
66 /**
67 * @tc.name: LoadContent01
68 * @tc.desc: context is nullptr
69 * @tc.type: FUNC
70 */
HWTEST_F(RootSceneTest, LoadContent01, Function | SmallTest | Level3)71 HWTEST_F(RootSceneTest, LoadContent01, Function | SmallTest | Level3)
72 {
73 RootScene rootScene;
74 rootScene.LoadContent("a", nullptr, nullptr, nullptr);
75 ASSERT_EQ(1, rootScene.GetWindowId());
76 }
77
78 /**
79 * @tc.name: UpdateViewportConfig01
80 * @tc.desc: UpdateViewportConfig Test
81 * @tc.type: FUNC
82 */
HWTEST_F(RootSceneTest, UpdateViewportConfig01, Function | SmallTest | Level3)83 HWTEST_F(RootSceneTest, UpdateViewportConfig01, Function | SmallTest | Level3)
84 {
85 RootScene rootScene;
86 Rect rect;
87
88 rootScene.uiContent_ = nullptr;
89 rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
90
91 rect.width_ = MOCK_LEM_SUB_WIDTH;
92 rect.height_ = MOCK_LEM_SUB_HEIGHT;
93 rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
94 ASSERT_EQ(1, rootScene.GetWindowId());
95 }
96
97 /**
98 * @tc.name: UpdateConfiguration
99 * @tc.desc: UpdateConfiguration Test
100 * @tc.type: FUNC
101 */
HWTEST_F(RootSceneTest, UpdateConfiguration, Function | SmallTest | Level3)102 HWTEST_F(RootSceneTest, UpdateConfiguration, Function | SmallTest | Level3)
103 {
104 RootScene rootScene;
105 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
106
107 rootScene.uiContent_ = nullptr;
108 rootScene.UpdateConfiguration(configuration);
109 ASSERT_EQ(1, rootScene.GetWindowId());
110 }
111
112 /**
113 * @tc.name: UpdateConfigurationForAll
114 * @tc.desc: UpdateConfigurationForAll Test
115 * @tc.type: FUNC
116 */
HWTEST_F(RootSceneTest, UpdateConfigurationForAll, Function | SmallTest | Level3)117 HWTEST_F(RootSceneTest, UpdateConfigurationForAll, Function | SmallTest | Level3)
118 {
119 RootScene rootScene;
120 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
121
122 auto prevStaticRootScene = RootScene::staticRootScene_;
123 rootScene.UpdateConfigurationForAll(configuration);
124
125 sptr<RootScene> staticRootScene;
126 RootScene::staticRootScene_ = staticRootScene;
127 rootScene.UpdateConfigurationForAll(configuration);
128
129 RootScene::staticRootScene_ = prevStaticRootScene;
130 ASSERT_EQ(1, rootScene.GetWindowId());
131 }
132
133 /**
134 * @tc.name: RegisterInputEventListener01
135 * @tc.desc: RegisterInputEventListener Test
136 * @tc.type: FUNC
137 */
HWTEST_F(RootSceneTest, RegisterInputEventListener01, Function | SmallTest | Level3)138 HWTEST_F(RootSceneTest, RegisterInputEventListener01, Function | SmallTest | Level3)
139 {
140 RootScene rootScene;
141 rootScene.RegisterInputEventListener();
142 ASSERT_EQ(1, rootScene.GetWindowId());
143 }
144
145 /**
146 * @tc.name: RequestVsyncErr
147 * @tc.desc: RequestVsync Test Err
148 * @tc.type: FUNC
149 */
HWTEST_F(RootSceneTest, RequestVsyncErr, Function | SmallTest | Level3)150 HWTEST_F(RootSceneTest, RequestVsyncErr, Function | SmallTest | Level3)
151 {
152 RootScene rootScene;
153 std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
154 rootScene.RequestVsync(vsyncCallback);
155 ASSERT_EQ(1, rootScene.GetWindowId());
156 }
157
158 /**
159 * @tc.name: GetVSyncPeriod
160 * @tc.desc: GetVSyncPeriod Test
161 * @tc.type: FUNC
162 */
HWTEST_F(RootSceneTest, GetVSyncPeriod, Function | SmallTest | Level3)163 HWTEST_F(RootSceneTest, GetVSyncPeriod, Function | SmallTest | Level3)
164 {
165 RootScene rootScene;
166 rootScene.GetVSyncPeriod();
167 ASSERT_EQ(1, rootScene.GetWindowId());
168 }
169
170 /**
171 * @tc.name: FlushFrameRate
172 * @tc.desc: FlushFrameRate Test
173 * @tc.type: FUNC
174 */
HWTEST_F(RootSceneTest, FlushFrameRate, Function | SmallTest | Level3)175 HWTEST_F(RootSceneTest, FlushFrameRate, Function | SmallTest | Level3)
176 {
177 RootScene rootScene;
178 uint32_t rate = 120;
179 int32_t animatorExpectedFrameRate = -1;
180 rootScene.FlushFrameRate(rate, animatorExpectedFrameRate);
181 ASSERT_EQ(1, rootScene.GetWindowId());
182 }
183
184 /**
185 * @tc.name: SetFrameLayoutFinishCallback
186 * @tc.desc: SetFrameLayoutFinishCallback Test
187 * @tc.type: FUNC
188 */
HWTEST_F(RootSceneTest, SetFrameLayoutFinishCallback, Function | SmallTest | Level3)189 HWTEST_F(RootSceneTest, SetFrameLayoutFinishCallback, Function | SmallTest | Level3)
190 {
191 RootScene rootScene;
192
193 rootScene.SetFrameLayoutFinishCallback(nullptr);
194 ASSERT_EQ(1, rootScene.GetWindowId());
195 }
196
197 /**
198 * @tc.name: SetUiDvsyncSwitch
199 * @tc.desc: SetUiDvsyncSwitch Test
200 * @tc.type: FUNC
201 */
HWTEST_F(RootSceneTest, SetUiDvsyncSwitchSucc, Function | SmallTest | Level3)202 HWTEST_F(RootSceneTest, SetUiDvsyncSwitchSucc, Function | SmallTest | Level3)
203 {
204 RootScene rootScene;
205 rootScene.SetUiDvsyncSwitch(true);
206 rootScene.SetUiDvsyncSwitch(false);
207 ASSERT_EQ(1, rootScene.GetWindowId());
208 }
209
210 /**
211 * @tc.name: SetUiDvsyncSwitch
212 * @tc.desc: SetUiDvsyncSwitch Test
213 * @tc.type: FUNC
214 */
HWTEST_F(RootSceneTest, SetUiDvsyncSwitchErr, Function | SmallTest | Level3)215 HWTEST_F(RootSceneTest, SetUiDvsyncSwitchErr, Function | SmallTest | Level3)
216 {
217 RootScene rootScene;
218 rootScene.SetUiDvsyncSwitch(true);
219 rootScene.SetUiDvsyncSwitch(false);
220 ASSERT_EQ(1, rootScene.GetWindowId());
221 }
222 }
223 } // namespace Rosen
224 } // namespace OHOS