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 #include "gtest/gtest.h"
16 #include "impl_interface/typeface_impl.h"
17 #include "skia_adapter/skia_typeface.h"
18
19 #include "render/rs_typeface_cache.h"
20 #include "transaction/rs_interfaces.h"
21 #include "transaction/rs_render_service_client.h"
22 #include "ui/rs_canvas_node.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS::Rosen {
28 class RSInterfacesTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase()36 void RSInterfacesTest::SetUpTestCase() {}
TearDownTestCase()37 void RSInterfacesTest::TearDownTestCase() {}
SetUp()38 void RSInterfacesTest::SetUp() {}
TearDown()39 void RSInterfacesTest::TearDown() {}
40
41 /**
42 * @tc.name: TakeSurfaceCaptureForUI001
43 * @tc.desc: test results of TakeSurfaceCaptureForUI
44 * @tc.type: FUNC
45 * @tc.require: issueI9N0I9
46 */
47 HWTEST_F(RSInterfacesTest, TakeSurfaceCaptureForUI001, TestSize.Level1)
48 {
49 class TestSurfaceCapture : public SurfaceCaptureCallback {
50 public:
TestSurfaceCapture()51 explicit TestSurfaceCapture() {}
~TestSurfaceCapture()52 ~TestSurfaceCapture() {}
OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap)53 void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) override {}
54 };
55 RSInterfaces& instance = RSInterfaces::GetInstance();
56 auto callback = std::make_shared<TestSurfaceCapture>();
57 bool res = instance.TakeSurfaceCaptureForUI(nullptr, callback, 1.f, 1.f, true);
58 EXPECT_TRUE(res == false);
59
60 auto node = std::make_shared<RSNode>(true);
61 res = instance.TakeSurfaceCaptureForUI(nullptr, callback, 1.f, 1.f, true);
62 EXPECT_TRUE(res == false);
63
64 RSUINodeType type = node->GetType();
65 type = RSUINodeType::UNKNOW;
66 res = instance.TakeSurfaceCaptureForUI(nullptr, callback, 1.f, 1.f, true);
67 EXPECT_TRUE(res == false);
68
69 RSDisplayNodeConfig config;
70 auto rsDisplayNode = RSDisplayNode::Create(config);
71 res = instance.TakeSurfaceCaptureForUI(rsDisplayNode, callback, 1.f, 1.f, true);
72 EXPECT_TRUE(res == false);
73 }
74
75 /**
76 * @tc.name: TakeSurfaceCaptureForUI002
77 * @tc.desc: test results of TakeSurfaceCaptureForUI
78 * @tc.type: FUNC
79 * @tc.require: issueIA61E9
80 */
81 HWTEST_F(RSInterfacesTest, TakeSurfaceCaptureForUI002, TestSize.Level1)
82 {
83 std::shared_ptr<RSNode> node = nullptr;
84 std::shared_ptr<SurfaceCaptureCallback> callback = nullptr;
85 RSInterfaces& instance = RSInterfaces::GetInstance();
86 bool res = instance.TakeSurfaceCaptureForUI(node, callback, 1.f, 1.f, true);
87 EXPECT_TRUE(res == false);
88
89 node = std::make_shared<RSNode>(true);
90 res = instance.TakeSurfaceCaptureForUI(node, callback, 1.f, 1.f, true);
91 EXPECT_TRUE(res == false);
92 }
93
94 /**
95 * @tc.name: RegisterTypeface001
96 * @tc.desc: test results of RegisterTypeface
97 * @tc.type: FUNC
98 * @tc.require: issueIA61E9
99 */
100 HWTEST_F(RSInterfacesTest, RegisterTypeface001, TestSize.Level1)
101 {
102 RSInterfaces& instance = RSInterfaces::GetInstance();
103 auto typefaceImpl = std::make_shared<Drawing::SkiaTypeface>();
104 EXPECT_NE(typefaceImpl, nullptr);
105 auto typeface = std::make_shared<Drawing::Typeface>(typefaceImpl);
106 EXPECT_NE(typeface, nullptr);
107 auto globalUniqueId = RSTypefaceCache::GenGlobalUniqueId(typeface->GetUniqueID());
108 RSTypefaceCache& typefaceCache = RSTypefaceCache::Instance();
109 typefaceCache.typefaceHashCode_.emplace(globalUniqueId, 0);
110 bool res = instance.RegisterTypeface(typeface);
111 typefaceCache.typefaceHashCode_.clear();
112 EXPECT_TRUE(res);
113 }
114
115 /**
116 * @tc.name: UnRegisterTypeface001
117 * @tc.desc: test results of UnRegisterTypeface
118 * @tc.type: FUNC
119 * @tc.require: issueI9N0I9
120 */
121 HWTEST_F(RSInterfacesTest, UnRegisterTypeface001, TestSize.Level1)
122 {
123 RSInterfaces& instance = RSInterfaces::GetInstance();
124 auto typefaceImpl = std::make_shared<Drawing::SkiaTypeface>();
125 auto typeface = std::make_shared<Drawing::Typeface>(typefaceImpl);
126 bool res = instance.UnRegisterTypeface(typeface);
127 EXPECT_TRUE(res);
128 }
129
130 /**
131 * @tc.name: GetTotalAppMemSize001
132 * @tc.desc: test results of GetTotalAppMemSize
133 * @tc.type: FUNC
134 * @tc.require: issueI9N0I9
135 */
136 HWTEST_F(RSInterfacesTest, GetTotalAppMemSize001, TestSize.Level1)
137 {
138 RSInterfaces& instance = RSInterfaces::GetInstance();
139 float cpuMemSize = 1.f;
140 float gpuMemSize = 1.f;
141 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
142 bool res = instance.GetTotalAppMemSize(cpuMemSize, gpuMemSize);
143 EXPECT_TRUE(res);
144 }
145
146 /**
147 * @tc.name: SetAppWindowNum001
148 * @tc.desc: test results of SetAppWindowNum
149 * @tc.type: FUNC
150 * @tc.require: issueI9N0I9
151 */
152 HWTEST_F(RSInterfacesTest, SetAppWindowNum001, TestSize.Level1)
153 {
154 RSInterfaces& instance = RSInterfaces::GetInstance();
155 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
156 instance.SetAppWindowNum(1);
157 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
158 }
159
160 /**
161 * @tc.name: ReportJankStats001
162 * @tc.desc: test results of ReportJankStats
163 * @tc.type: FUNC
164 * @tc.require: issueI9N0I9
165 */
166 HWTEST_F(RSInterfacesTest, ReportJankStats001, TestSize.Level1)
167 {
168 RSInterfaces& instance = RSInterfaces::GetInstance();
169 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
170 instance.ReportJankStats();
171 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
172 }
173
174 /**
175 * @tc.name: ReportEventResponse001
176 * @tc.desc: test results of ReportEventResponse
177 * @tc.type: FUNC
178 * @tc.require: issueI9N0I9
179 */
180 HWTEST_F(RSInterfacesTest, ReportEventResponse001, TestSize.Level1)
181 {
182 RSInterfaces& instance = RSInterfaces::GetInstance();
183 DataBaseRs info;
184 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
185 instance.ReportEventResponse(info);
186 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
187 }
188
189 /**
190 * @tc.name: ReportEventComplete001
191 * @tc.desc: test results of ReportEventComplete
192 * @tc.type: FUNC
193 * @tc.require: issueI9N0I9
194 */
195 HWTEST_F(RSInterfacesTest, ReportEventComplete001, TestSize.Level1)
196 {
197 RSInterfaces& instance = RSInterfaces::GetInstance();
198 DataBaseRs info;
199 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
200 instance.ReportEventComplete(info);
201 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
202 }
203
204 /**
205 * @tc.name: ReportEventJankFrame001
206 * @tc.desc: test results of ReportEventJankFrame
207 * @tc.type: FUNC
208 * @tc.require: issueI9N0I9
209 */
210 HWTEST_F(RSInterfacesTest, ReportEventJankFrame001, TestSize.Level1)
211 {
212 RSInterfaces& instance = RSInterfaces::GetInstance();
213 DataBaseRs info;
214 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
215 instance.ReportEventJankFrame(info);
216 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
217 }
218
219 /**
220 * @tc.name: ReportGameStateData001
221 * @tc.desc: test results of ReportGameStateData
222 * @tc.type: FUNC
223 * @tc.require: issueI9N0I9
224 */
225 HWTEST_F(RSInterfacesTest, ReportGameStateData001, TestSize.Level1)
226 {
227 RSInterfaces& instance = RSInterfaces::GetInstance();
228 GameStateData info;
229 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
230 instance.ReportGameStateData(info);
231 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
232 }
233
234 /**
235 * @tc.name: SetOnRemoteDiedCallback001
236 * @tc.desc: test results of SetOnRemoteDiedCallback
237 * @tc.type: FUNC
238 * @tc.require: issueI9N0I9
239 */
240 HWTEST_F(RSInterfacesTest, SetOnRemoteDiedCallback001, TestSize.Level1)
241 {
242 RSInterfaces& instance = RSInterfaces::GetInstance();
__anone06483d30102() 243 OnRemoteDiedCallback callback = []() {};
244 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
245 instance.SetOnRemoteDiedCallback(callback);
246 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
247 }
248
249 /**
250 * @tc.name: GetActiveDirtyRegionInfo001
251 * @tc.desc: test results of GetActiveDirtyRegionInfo
252 * @tc.type: FUNC
253 * @tc.require: issueI97N4E
254 */
255 HWTEST_F(RSInterfacesTest, GetActiveDirtyRegionInfo001, TestSize.Level1)
256 {
257 RSInterfaces& instance = RSInterfaces::GetInstance();
258 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
259 instance.GetActiveDirtyRegionInfo();
260 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
261 }
262
263 /**
264 * @tc.name: GetGlobalDirtyRegionInfo001
265 * @tc.desc: test results of GetGlobalDirtyRegionInfo
266 * @tc.type: FUNC
267 * @tc.require: issueI97N4E
268 */
269 HWTEST_F(RSInterfacesTest, GetGlobalDirtyRegionInfo001, TestSize.Level1)
270 {
271 RSInterfaces& instance = RSInterfaces::GetInstance();
272 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
273 instance.GetGlobalDirtyRegionInfo();
274 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
275 }
276
277 /**
278 * @tc.name: GetLayerComposeInfo001
279 * @tc.desc: test results of GetLayerComposeInfo
280 * @tc.type: FUNC
281 * @tc.require: issueI97N4E
282 */
283 HWTEST_F(RSInterfacesTest, GetLayerComposeInfo001, TestSize.Level1)
284 {
285 RSInterfaces& instance = RSInterfaces::GetInstance();
286 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
287 instance.GetLayerComposeInfo();
288 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
289 }
290
291 /**
292 * @tc.name: GetHardwareComposeDisabledReasonInfo001
293 * @tc.desc: test results of GetHwcDisabledReasonInfo
294 * @tc.type: FUNC
295 * @tc.require: issueI97N4E
296 */
297 HWTEST_F(RSInterfacesTest, GetHardwareComposeDisabledReasonInfo001, TestSize.Level1)
298 {
299 RSInterfaces& instance = RSInterfaces::GetInstance();
300 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
301 instance.GetHwcDisabledReasonInfo();
302 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
303 }
304
305 /**
306 * @tc.name: SetVmaCacheStatus001
307 * @tc.desc: test results of SetVmaCacheStatus
308 * @tc.type: FUNC
309 * @tc.require: issueI97N4E
310 */
311 HWTEST_F(RSInterfacesTest, SetVmaCacheStatus001, TestSize.Level1)
312 {
313 RSInterfaces& instance = RSInterfaces::GetInstance();
314 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
315 instance.SetVmaCacheStatus(true);
316 instance.SetVmaCacheStatus(false);
317 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
318 }
319
320 #ifdef TP_FEATURE_ENABLE
321 /**
322 * @tc.name: SetTpFeatureConfig001
323 * @tc.desc: test results of SetTpFeatureConfig
324 * @tc.type: FUNC
325 * @tc.require: issueI9N0I9
326 */
327 HWTEST_F(RSInterfacesTest, SetTpFeatureConfig001, TestSize.Level1)
328 {
329 RSInterfaces& instance = RSInterfaces::GetInstance();
330 int32_t feature = 1;
331 std::string config = "config";
332 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
333 instance.SetTpFeatureConfig(feature, config.c_str());
334 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
335 }
336
337 /**
338 * @tc.name: SetTpFeatureConfig002
339 * @tc.desc: test results of SetTpFeatureConfig
340 * @tc.type: FUNC
341 * @tc.require: issueIB39L8
342 */
343 HWTEST_F(RSInterfacesTest, SetTpFeatureConfig002, TestSize.Level1)
344 {
345 RSInterfaces& instance = RSInterfaces::GetInstance();
346 int32_t feature = 1;
347 std::string config = "config";
348 instance.renderServiceClient_ = std::make_unique<RSRenderServiceClient>();
349 instance.SetTpFeatureConfig(feature, config.c_str(), TpFeatureConfigType::AFT_TP_FEATURE);
350 EXPECT_TRUE(instance.renderServiceClient_ != nullptr);
351 }
352 #endif
353 } // namespace OHOS::Rosen
354