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 {
43 }
44 
TearDownTestCase()45 void ScreenSceneTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void ScreenSceneTest::SetUp()
50 {
51 }
52 
TearDown()53 void ScreenSceneTest::TearDown()
54 {
55 }
56 
57 namespace {
58 /**
59  * @tc.name: LoadContent01
60  * @tc.desc: context is nullptr
61  * @tc.type: FUNC
62  */
63 HWTEST_F(ScreenSceneTest, LoadContent01, Function | SmallTest | Level3)
64 {
65     ScreenScene screenScene("UNKNOWN");
66     screenScene.LoadContent("a", nullptr, nullptr, nullptr);
67     ASSERT_EQ(1, screenScene.GetWindowId());
68 }
69 
70 /**
71  * @tc.name: Destroy01
72  * @tc.desc: context is nullptr
73  * @tc.type: FUNC
74  */
75 HWTEST_F(ScreenSceneTest, Destroy01, Function | SmallTest | Level3)
76 {
77     ScreenScene screenScene("UNKNOWN");
78     screenScene.LoadContent("a", nullptr, nullptr, nullptr);
79     screenScene.Destroy();
80     ASSERT_EQ(1, screenScene.GetWindowId());
81 }
82 
83 
84 /**
85  * @tc.name: UpdateViewportConfig01
86  * @tc.desc: UpdateViewportConfig Test
87  * @tc.type: FUNC
88  */
89 HWTEST_F(ScreenSceneTest, UpdateViewportConfig01, Function | SmallTest | Level3)
90 {
91     ScreenScene screenScene("UNKNOWN");
92     Rect rect;
93     screenScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
94     ASSERT_EQ(1, screenScene.GetWindowId());
95 }
96 
97 /**
98  * @tc.name: UpdateConfiguration
99  * @tc.desc: UpdateConfiguration Test
100  * @tc.type: FUNC
101  */
102 HWTEST_F(ScreenSceneTest, UpdateConfiguration, Function | SmallTest | Level3)
103 {
104     ScreenScene screenScene("UNKNOWN");
105     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
106     screenScene.UpdateConfiguration(configuration);
107     ASSERT_EQ(1, screenScene.GetWindowId());
108 }
109 
110 /**
111  * @tc.name: RequestVsync
112  * @tc.desc: RequestVsync Test
113  * @tc.type: FUNC
114  */
115 HWTEST_F(ScreenSceneTest, RequestVsync, Function | SmallTest | Level3)
116 {
117     ScreenScene screenScene("UNKNOWN");
118     std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
119     screenScene.RequestVsync(vsyncCallback);
120     ASSERT_EQ(1, screenScene.GetWindowId());
121 }
122 
123 /**
124  * @tc.name: GetVSyncPeriod
125  * @tc.desc: GetVSyncPeriod Test
126  * @tc.type: FUNC
127  */
128 HWTEST_F(ScreenSceneTest, GetVSyncPeriod, Function | SmallTest | Level3)
129 {
130     ScreenScene screenScene("UNKNOWN");
131     screenScene.GetVSyncPeriod();
132     ASSERT_EQ(1, screenScene.GetWindowId());
133 }
134 
135 /**
136  * @tc.name: FlushFrameRate
137  * @tc.desc: FlushFrameRate Test
138  * @tc.type: FUNC
139  */
140 HWTEST_F(ScreenSceneTest, FlushFrameRate, Function | SmallTest | Level3)
141 {
142     ScreenScene screenScene("UNKNOWN");
143     uint32_t rate = 120;
144     int32_t animatorExpectedFrameRate = -1;
145     screenScene.FlushFrameRate(rate, animatorExpectedFrameRate);
146     ASSERT_EQ(1, screenScene.GetWindowId());
147 }
148 
149 /**
150  * @tc.name: SetFrameLayoutFinishCallback
151  * @tc.desc: SetFrameLayoutFinishCallback Test
152  * @tc.type: FUNC
153  */
154 HWTEST_F(ScreenSceneTest, SetFrameLayoutFinishCallback, Function | SmallTest | Level3)
155 {
156     ScreenScene screenScene("UNKNOWN");;
__anona4f454fd0202()157     screenScene.SetFrameLayoutFinishCallback([](){});
158     ASSERT_EQ(1, screenScene.GetWindowId());
159 }
160 
161 /**
162  * @tc.name: SetDisplayDensity
163  * @tc.desc: SetDisplayDensity Test
164  * @tc.type: FUNC
165  */
166 HWTEST_F(ScreenSceneTest, SetDisplayDensity, Function | SmallTest | Level3)
167 {
168     ScreenScene screenScene("UNKNOWN");
169     float density = 2.0f;
170     screenScene.SetDisplayDensity(density);
171     ASSERT_EQ(1, screenScene.GetWindowId());
172 }
173 } // namespace
174 } // namespace Rosen
175 } // namespace OHOS