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 class RootSceneTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 };
42
SetUpTestCase()43 void RootSceneTest::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void RootSceneTest::TearDownTestCase()
48 {
49 }
50
SetUp()51 void RootSceneTest::SetUp()
52 {
53 }
54
TearDown()55 void RootSceneTest::TearDown()
56 {
57 }
58
59 namespace {
60 /**
61 * @tc.name: LoadContent01
62 * @tc.desc: context is nullptr
63 * @tc.type: FUNC
64 */
65 HWTEST_F(RootSceneTest, LoadContent01, Function | SmallTest | Level3)
66 {
67 RootScene rootScene;
68 rootScene.LoadContent("a", nullptr, nullptr, nullptr);
69 ASSERT_EQ(1, rootScene.GetWindowId());
70 }
71
72 /**
73 * @tc.name: UpdateViewportConfig01
74 * @tc.desc: UpdateViewportConfig Test
75 * @tc.type: FUNC
76 */
77 HWTEST_F(RootSceneTest, UpdateViewportConfig01, Function | SmallTest | Level3)
78 {
79 RootScene rootScene;
80 Rect rect;
81 rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
82 ASSERT_EQ(1, rootScene.GetWindowId());
83 }
84
85 /**
86 * @tc.name: UpdateConfiguration
87 * @tc.desc: UpdateConfiguration Test
88 * @tc.type: FUNC
89 */
90 HWTEST_F(RootSceneTest, UpdateConfiguration, Function | SmallTest | Level3)
91 {
92 RootScene rootScene;
93 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
94 rootScene.UpdateConfiguration(configuration);
95 ASSERT_EQ(1, rootScene.GetWindowId());
96 }
97
98 /**
99 * @tc.name: UpdateConfigurationForAll
100 * @tc.desc: UpdateConfigurationForAll Test
101 * @tc.type: FUNC
102 */
103 HWTEST_F(RootSceneTest, UpdateConfigurationForAll, Function | SmallTest | Level3)
104 {
105 RootScene rootScene;
106 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
107 rootScene.UpdateConfigurationForAll(configuration);
108 ASSERT_EQ(1, rootScene.GetWindowId());
109 }
110
111 /**
112 * @tc.name: RegisterInputEventListener01
113 * @tc.desc: RegisterInputEventListener Test
114 * @tc.type: FUNC
115 */
116 HWTEST_F(RootSceneTest, RegisterInputEventListener01, Function | SmallTest | Level3)
117 {
118 RootScene rootScene;
119 rootScene.RegisterInputEventListener();
120 ASSERT_EQ(1, rootScene.GetWindowId());
121 }
122
123 /**
124 * @tc.name: RequestVsync
125 * @tc.desc: RequestVsync Test
126 * @tc.type: FUNC
127 */
128 HWTEST_F(RootSceneTest, RequestVsync, Function | SmallTest | Level3)
129 {
130 RootScene rootScene;
131 std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
132 rootScene.RequestVsync(vsyncCallback);
133 ASSERT_EQ(1, rootScene.GetWindowId());
134 }
135
136 /**
137 * @tc.name: GetVSyncPeriod
138 * @tc.desc: GetVSyncPeriod Test
139 * @tc.type: FUNC
140 */
141 HWTEST_F(RootSceneTest, GetVSyncPeriod, Function | SmallTest | Level3)
142 {
143 RootScene rootScene;
144 rootScene.GetVSyncPeriod();
145 ASSERT_EQ(1, rootScene.GetWindowId());
146 }
147
148 /**
149 * @tc.name: FlushFrameRate
150 * @tc.desc: FlushFrameRate Test
151 * @tc.type: FUNC
152 */
153 HWTEST_F(RootSceneTest, FlushFrameRate, Function | SmallTest | Level3)
154 {
155 RootScene rootScene;
156 uint32_t rate = 120;
157 rootScene.FlushFrameRate(rate);
158 ASSERT_EQ(1, rootScene.GetWindowId());
159 }
160 }
161 } // namespace Rosen
162 } // namespace OHOS