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 "session_manager/include/hidump_controller.h"
18 #include "session/host/include/scene_session.h"
19 #include "window_manager_hilog.h"
20 #include "wm_single_instance.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 class HidumpControllerTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33
34 sptr<SceneSession> GetSceneSession(std::string name);
35 };
36
SetUpTestCase()37 void HidumpControllerTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void HidumpControllerTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void HidumpControllerTest::SetUp()
46 {
47 }
48
TearDown()49 void HidumpControllerTest::TearDown()
50 {
51 }
52
GetSceneSession(std::string name)53 sptr<SceneSession> HidumpControllerTest::GetSceneSession(std::string name)
54 {
55 SessionInfo info;
56 info.abilityName_ = name;
57 info.bundleName_ = name;
58 auto result = new (std::nothrow) SceneSession(info, nullptr);
59 if (result != nullptr) {
60 result->property_ = new (std::nothrow) WindowSessionProperty();
61 if (result->property_ == nullptr) {
62 return nullptr;
63 }
64 }
65
66 return result;
67 }
68
69 namespace {
70 /**
71 * @tc.name: GetAllSessionDumpDetailedInfo
72 * @tc.desc: GetAllSessionDumpDetailedInfo Test
73 * @tc.type: FUNC
74 */
HWTEST_F(HidumpControllerTest, GetAllSessionDumpDetailedInfo01, Function | MediumTest | Level2)75 HWTEST_F(HidumpControllerTest, GetAllSessionDumpDetailedInfo01, Function | MediumTest | Level2)
76 {
77 std::vector<sptr<SceneSession>> allSession;
78 std::vector<sptr<SceneSession>> backgroundSession;
79 auto sceneSession = GetSceneSession("GetAllSessionDumpDetailedInfo01");
80 ASSERT_NE(sceneSession, nullptr);
81 backgroundSession.push_back(sceneSession);
82
83 std::ostringstream oss;
84 HidumpController::GetInstance().GetAllSessionDumpDetailedInfo(oss, allSession, backgroundSession);
85 std::string result = oss.str();
86 ASSERT_NE(result.size(), 0);
87 }
88
89 /**
90 * @tc.name: GetAllSessionDumpDetailedInfo
91 * @tc.desc: GetAllSessionDumpDetailedInfo Test
92 * @tc.type: FUNC
93 */
HWTEST_F(HidumpControllerTest, GetAllSessionDumpDetailedInfo02, Function | MediumTest | Level2)94 HWTEST_F(HidumpControllerTest, GetAllSessionDumpDetailedInfo02, Function | MediumTest | Level2)
95 {
96 std::vector<sptr<SceneSession>> allSession;
97 std::vector<sptr<SceneSession>> backgroundSession;
98 auto sceneSession = GetSceneSession("GetAllSessionDumpDetailedInfo02");
99 ASSERT_NE(sceneSession, nullptr);
100 allSession.push_back(sceneSession);
101
102 std::ostringstream oss;
103 HidumpController::GetInstance().GetAllSessionDumpDetailedInfo(oss, allSession, backgroundSession);
104 std::string result = oss.str();
105 ASSERT_NE(result.size(), 0);
106 }
107
108 /**
109 * @tc.name: DumpSceneSessionParamList
110 * @tc.desc: DumpSceneSessionParamList Test
111 * @tc.type: FUNC
112 */
HWTEST_F(HidumpControllerTest, DumpSceneSessionParamList, Function | MediumTest | Level2)113 HWTEST_F(HidumpControllerTest, DumpSceneSessionParamList, Function | MediumTest | Level2)
114 {
115 std::ostringstream oss;
116 HidumpController::GetInstance().DumpSceneSessionParamList(oss);
117 std::string result = oss.str();
118 ASSERT_NE(result.size(), 0);
119 }
120
121 /**
122 * @tc.name: DumpSceneSessionParam
123 * @tc.desc: DumpSceneSessionParam Test
124 * @tc.type: FUNC
125 */
HWTEST_F(HidumpControllerTest, DumpSceneSessionParam01, Function | MediumTest | Level2)126 HWTEST_F(HidumpControllerTest, DumpSceneSessionParam01, Function | MediumTest | Level2)
127 {
128 auto sceneSession = GetSceneSession("DumpSceneSessionParam01");
129 ASSERT_NE(sceneSession, nullptr);
130 sceneSession->property_ = nullptr;
131 std::ostringstream oss;
132 HidumpController::GetInstance().DumpSceneSessionParam(oss, sceneSession);
133
134 std::string result = oss.str();
135 ASSERT_NE(result.size(), 0);
136 }
137
138 /**
139 * @tc.name: DumpSceneSessionParam
140 * @tc.desc: DumpSceneSessionParam Test
141 * @tc.type: FUNC
142 */
HWTEST_F(HidumpControllerTest, DumpSceneSessionParam02, Function | MediumTest | Level2)143 HWTEST_F(HidumpControllerTest, DumpSceneSessionParam02, Function | MediumTest | Level2)
144 {
145 auto sceneSession = GetSceneSession("DumpSceneSessionParam02");
146 ASSERT_NE(sceneSession, nullptr);
147 std::ostringstream oss;
148 HidumpController::GetInstance().DumpSceneSessionParam(oss, sceneSession);
149
150 std::string result = oss.str();
151 ASSERT_NE(result.size(), 0);
152 }
153
154 /**
155 * @tc.name: DumpSessionParamList
156 * @tc.desc: DumpSessionParamList Test
157 * @tc.type: FUNC
158 */
HWTEST_F(HidumpControllerTest, DumpSessionParamList, Function | MediumTest | Level2)159 HWTEST_F(HidumpControllerTest, DumpSessionParamList, Function | MediumTest | Level2)
160 {
161 std::ostringstream oss;
162 HidumpController::GetInstance().DumpSessionParamList(oss);
163 std::string result = oss.str();
164 ASSERT_NE(result.size(), 0);
165 }
166
167 /**
168 * @tc.name: DumpSessionParam
169 * @tc.desc: DumpSessionParam Test
170 * @tc.type: FUNC
171 */
HWTEST_F(HidumpControllerTest, DumpSessionParam, Function | MediumTest | Level2)172 HWTEST_F(HidumpControllerTest, DumpSessionParam, Function | MediumTest | Level2)
173 {
174 auto sceneSession = GetSceneSession("DumpLayoutRectParam");
175 ASSERT_NE(sceneSession, nullptr);
176
177 std::ostringstream oss;
178 HidumpController::GetInstance().DumpSessionParam(oss, sceneSession, sceneSession->property_);
179 std::string result = oss.str();
180 ASSERT_NE(result.size(), 0);
181 }
182
183 /**
184 * @tc.name: DumpLayoutRectParamList
185 * @tc.desc: DumpLayoutRectParamList Test
186 * @tc.type: FUNC
187 */
HWTEST_F(HidumpControllerTest, DumpLayoutRectParamList, Function | MediumTest | Level2)188 HWTEST_F(HidumpControllerTest, DumpLayoutRectParamList, Function | MediumTest | Level2)
189 {
190 std::ostringstream oss;
191 HidumpController::GetInstance().DumpLayoutRectParamList(oss);
192 std::string result = oss.str();
193 ASSERT_NE(result.size(), 0);
194 }
195
196 /**
197 * @tc.name: DumpLayoutRectParam
198 * @tc.desc: DumpLayoutRectParam Test
199 * @tc.type: FUNC
200 */
HWTEST_F(HidumpControllerTest, DumpLayoutRectParam, Function | MediumTest | Level2)201 HWTEST_F(HidumpControllerTest, DumpLayoutRectParam, Function | MediumTest | Level2)
202 {
203 auto sceneSession = GetSceneSession("DumpLayoutRectParam");
204 ASSERT_NE(sceneSession, nullptr);
205
206 std::ostringstream oss;
207 HidumpController::GetInstance().DumpLayoutRectParam(oss, sceneSession, sceneSession->property_);
208 std::string result = oss.str();
209 ASSERT_NE(result.size(), 0);
210 }
211
212 /**
213 * @tc.name: DumpLayoutParamList
214 * @tc.desc: DumpLayoutParamList Test
215 * @tc.type: FUNC
216 */
HWTEST_F(HidumpControllerTest, DumpLayoutParamList, Function | MediumTest | Level2)217 HWTEST_F(HidumpControllerTest, DumpLayoutParamList, Function | MediumTest | Level2)
218 {
219 std::ostringstream oss;
220 HidumpController::GetInstance().DumpLayoutParamList(oss);
221 std::string result = oss.str();
222 ASSERT_NE(result.size(), 0);
223 }
224
225 /**
226 * @tc.name: DumpLayoutParam
227 * @tc.desc: DumpLayoutParam Test
228 * @tc.type: FUNC
229 */
HWTEST_F(HidumpControllerTest, DumpLayoutParam, Function | MediumTest | Level2)230 HWTEST_F(HidumpControllerTest, DumpLayoutParam, Function | MediumTest | Level2)
231 {
232 auto sceneSession = GetSceneSession("DumpLayoutParam");
233 ASSERT_NE(sceneSession, nullptr);
234
235 std::ostringstream oss;
236 HidumpController::GetInstance().DumpLayoutParam(oss, sceneSession, sceneSession->property_);
237 std::string result = oss.str();
238 ASSERT_NE(result.size(), 0);
239 }
240
241 /**
242 * @tc.name: DumpAbilityParamList
243 * @tc.desc: DumpAbilityParamList Test
244 * @tc.type: FUNC
245 */
HWTEST_F(HidumpControllerTest, DumpAbilityParamList, Function | MediumTest | Level2)246 HWTEST_F(HidumpControllerTest, DumpAbilityParamList, Function | MediumTest | Level2)
247 {
248 std::ostringstream oss;
249 HidumpController::GetInstance().DumpAbilityParamList(oss);
250 std::string result = oss.str();
251 ASSERT_NE(result.size(), 0);
252 }
253
254 /**
255 * @tc.name: DumpAbilityParam
256 * @tc.desc: DumpAbilityParam Test
257 * @tc.type: FUNC
258 */
HWTEST_F(HidumpControllerTest, DumpAbilityParam, Function | MediumTest | Level2)259 HWTEST_F(HidumpControllerTest, DumpAbilityParam, Function | MediumTest | Level2)
260 {
261 auto sceneSession = GetSceneSession("DumpLayoutParam");
262 ASSERT_NE(sceneSession, nullptr);
263
264 std::ostringstream oss;
265 HidumpController::GetInstance().DumpAbilityParam(oss, sceneSession, sceneSession->property_);
266 std::string result = oss.str();
267 ASSERT_NE(result.size(), 0);
268 }
269
270 /**
271 * @tc.name: DumpKeyboardParamList
272 * @tc.desc: DumpKeyboardParamList Test
273 * @tc.type: FUNC
274 */
HWTEST_F(HidumpControllerTest, DumpKeyboardParamList, Function | MediumTest | Level2)275 HWTEST_F(HidumpControllerTest, DumpKeyboardParamList, Function | MediumTest | Level2)
276 {
277 std::ostringstream oss;
278 HidumpController::GetInstance().DumpKeyboardParamList(oss);
279 std::string result = oss.str();
280 ASSERT_NE(result.size(), 0);
281 }
282
283 /**
284 * @tc.name: DumpKeyboardParam
285 * @tc.desc: DumpKeyboardParam Test
286 * @tc.type: FUNC
287 */
HWTEST_F(HidumpControllerTest, DumpKeyboardParam, Function | MediumTest | Level2)288 HWTEST_F(HidumpControllerTest, DumpKeyboardParam, Function | MediumTest | Level2)
289 {
290 auto sceneSession = GetSceneSession("DumpKeyboardParam");
291 ASSERT_NE(sceneSession, nullptr);
292
293 std::ostringstream oss;
294 HidumpController::GetInstance().DumpKeyboardParam(oss, sceneSession, sceneSession->property_);
295 std::string result = oss.str();
296 ASSERT_NE(result.size(), 0);
297 }
298
299 /**
300 * @tc.name: DumpSysconfigParamList
301 * @tc.desc: DumpSysconfigParamList Test
302 * @tc.type: FUNC
303 */
HWTEST_F(HidumpControllerTest, DumpSysconfigParamList, Function | MediumTest | Level2)304 HWTEST_F(HidumpControllerTest, DumpSysconfigParamList, Function | MediumTest | Level2)
305 {
306 std::ostringstream oss;
307 HidumpController::GetInstance().DumpSysconfigParamList(oss);
308 std::string result = oss.str();
309 ASSERT_NE(result.size(), 0);
310 }
311
312 /**
313 * @tc.name: DumpSysconfigParam
314 * @tc.desc: DumpSysconfigParam Test
315 * @tc.type: FUNC
316 */
HWTEST_F(HidumpControllerTest, DumpSysconfigParam, Function | MediumTest | Level2)317 HWTEST_F(HidumpControllerTest, DumpSysconfigParam, Function | MediumTest | Level2)
318 {
319 auto sceneSession = GetSceneSession("DumpSysconfigParam");
320 ASSERT_NE(sceneSession, nullptr);
321
322 std::ostringstream oss;
323 HidumpController::GetInstance().DumpSysconfigParam(oss, sceneSession);
324 std::string result = oss.str();
325 ASSERT_NE(result.size(), 0);
326 }
327
328 /**
329 * @tc.name: DumpLifeParamList
330 * @tc.desc: DumpLifeParamList Test
331 * @tc.type: FUNC
332 */
HWTEST_F(HidumpControllerTest, DumpLifeParamList, Function | MediumTest | Level2)333 HWTEST_F(HidumpControllerTest, DumpLifeParamList, Function | MediumTest | Level2)
334 {
335 std::ostringstream oss;
336 HidumpController::GetInstance().DumpLifeParamList(oss);
337 std::string result = oss.str();
338 ASSERT_NE(result.size(), 0);
339 }
340
341 /**
342 * @tc.name: DumpLifeParam
343 * @tc.desc: DumpLifeParam Test
344 * @tc.type: FUNC
345 */
HWTEST_F(HidumpControllerTest, DumpLifeParam, Function | MediumTest | Level2)346 HWTEST_F(HidumpControllerTest, DumpLifeParam, Function | MediumTest | Level2)
347 {
348 auto sceneSession = GetSceneSession("DumpLifeParam");
349 ASSERT_NE(sceneSession, nullptr);
350
351 std::ostringstream oss;
352 HidumpController::GetInstance().DumpLifeParam(oss, sceneSession);
353 std::string result = oss.str();
354 ASSERT_NE(result.size(), 0);
355 }
356
357 /**
358 * @tc.name: DumpDisplayParamList
359 * @tc.desc: DumpDisplayParamList Test
360 * @tc.type: FUNC
361 */
HWTEST_F(HidumpControllerTest, DumpDisplayParamList, Function | MediumTest | Level2)362 HWTEST_F(HidumpControllerTest, DumpDisplayParamList, Function | MediumTest | Level2)
363 {
364 std::ostringstream oss;
365 HidumpController::GetInstance().DumpDisplayParamList(oss);
366 std::string result = oss.str();
367 ASSERT_NE(result.size(), 0);
368 }
369
370 /**
371 * @tc.name: DumpDisplayParam
372 * @tc.desc: DumpDisplayParam Test
373 * @tc.type: FUNC
374 */
HWTEST_F(HidumpControllerTest, DumpDisplayParam, Function | MediumTest | Level2)375 HWTEST_F(HidumpControllerTest, DumpDisplayParam, Function | MediumTest | Level2)
376 {
377 auto sceneSession = GetSceneSession("DumpDisplayParam");
378 ASSERT_NE(sceneSession, nullptr);
379
380 std::ostringstream oss;
381 HidumpController::GetInstance().DumpDisplayParam(oss, sceneSession, sceneSession->property_);
382 std::string result = oss.str();
383 ASSERT_NE(result.size(), 0);
384 }
385
386 /**
387 * @tc.name: DumpFocusParamList
388 * @tc.desc: DumpFocusParamList Test
389 * @tc.type: FUNC
390 */
HWTEST_F(HidumpControllerTest, DumpFocusParamList, Function | MediumTest | Level2)391 HWTEST_F(HidumpControllerTest, DumpFocusParamList, Function | MediumTest | Level2)
392 {
393 std::ostringstream oss;
394 HidumpController::GetInstance().DumpFocusParamList(oss);
395 std::string result = oss.str();
396 ASSERT_NE(result.size(), 0);
397 }
398
399 /**
400 * @tc.name: DumpFocusParam
401 * @tc.desc: DumpFocusParam Test
402 * @tc.type: FUNC
403 */
HWTEST_F(HidumpControllerTest, DumpFocusParam, Function | MediumTest | Level2)404 HWTEST_F(HidumpControllerTest, DumpFocusParam, Function | MediumTest | Level2)
405 {
406 auto sceneSession = GetSceneSession("DumpFocusParam");
407 ASSERT_NE(sceneSession, nullptr);
408
409 std::ostringstream oss;
410 HidumpController::GetInstance().DumpFocusParam(oss, sceneSession, sceneSession->property_);
411 std::string result = oss.str();
412 ASSERT_NE(result.size(), 0);
413 }
414
415 /**
416 * @tc.name: DumpInputParamList
417 * @tc.desc: DumpInputParamList Test
418 * @tc.type: FUNC
419 */
HWTEST_F(HidumpControllerTest, DumpInputParamList, Function | MediumTest | Level2)420 HWTEST_F(HidumpControllerTest, DumpInputParamList, Function | MediumTest | Level2)
421 {
422 std::ostringstream oss;
423 HidumpController::GetInstance().DumpInputParamList(oss);
424 std::string result = oss.str();
425 ASSERT_NE(result.size(), 0);
426 }
427
428 /**
429 * @tc.name: DumpInputParam
430 * @tc.desc: DumpInputParam Test
431 * @tc.type: FUNC
432 */
HWTEST_F(HidumpControllerTest, DumpInputParam, Function | MediumTest | Level2)433 HWTEST_F(HidumpControllerTest, DumpInputParam, Function | MediumTest | Level2)
434 {
435 auto sceneSession = GetSceneSession("DumpInputParam");
436 ASSERT_NE(sceneSession, nullptr);
437
438 std::ostringstream oss;
439 HidumpController::GetInstance().DumpInputParam(oss, sceneSession, sceneSession->property_);
440 std::string result = oss.str();
441 ASSERT_NE(result.size(), 0);
442 }
443
444 /**
445 * @tc.name: DumpLakeParamList
446 * @tc.desc: DumpLakeParamList Test
447 * @tc.type: FUNC
448 */
HWTEST_F(HidumpControllerTest, DumpLakeParamList, Function | MediumTest | Level2)449 HWTEST_F(HidumpControllerTest, DumpLakeParamList, Function | MediumTest | Level2)
450 {
451 std::ostringstream oss;
452 HidumpController::GetInstance().DumpLakeParamList(oss);
453 std::string result = oss.str();
454 ASSERT_NE(result.size(), 0);
455 }
456
457 /**
458 * @tc.name: DumpLakeParam
459 * @tc.desc: DumpLakeParam Test
460 * @tc.type: FUNC
461 */
HWTEST_F(HidumpControllerTest, DumpLakeParam, Function | MediumTest | Level2)462 HWTEST_F(HidumpControllerTest, DumpLakeParam, Function | MediumTest | Level2)
463 {
464 auto sceneSession = GetSceneSession("DumpLakeParam");
465 ASSERT_NE(sceneSession, nullptr);
466
467 std::ostringstream oss;
468 HidumpController::GetInstance().DumpLakeParam(oss, sceneSession);
469 std::string result = oss.str();
470 ASSERT_NE(result.size(), 0);
471 }
472
473 /**
474 * @tc.name: DumpCOMParamList
475 * @tc.desc: DumpCOMParamList Test
476 * @tc.type: FUNC
477 */
HWTEST_F(HidumpControllerTest, DumpCOMParamList, Function | MediumTest | Level2)478 HWTEST_F(HidumpControllerTest, DumpCOMParamList, Function | MediumTest | Level2)
479 {
480 std::ostringstream oss;
481 HidumpController::GetInstance().DumpCOMParamList(oss);
482 std::string result = oss.str();
483 ASSERT_NE(result.size(), 0);
484 }
485
486 /**
487 * @tc.name: DumpCOMParam
488 * @tc.desc: DumpCOMParam Test
489 * @tc.type: FUNC
490 */
HWTEST_F(HidumpControllerTest, DumpCOMParam, Function | MediumTest | Level2)491 HWTEST_F(HidumpControllerTest, DumpCOMParam, Function | MediumTest | Level2)
492 {
493 auto sceneSession = GetSceneSession("DumpCOMParam");
494 ASSERT_NE(sceneSession, nullptr);
495
496 std::ostringstream oss;
497 HidumpController::GetInstance().DumpCOMParam(oss, sceneSession);
498 std::string result = oss.str();
499 ASSERT_NE(result.size(), 0);
500 }
501
502 /**
503 * @tc.name: DumpVisibleParamList
504 * @tc.desc: DumpVisibleParamList Test
505 * @tc.type: FUNC
506 */
HWTEST_F(HidumpControllerTest, DumpVisibleParamList, Function | MediumTest | Level2)507 HWTEST_F(HidumpControllerTest, DumpVisibleParamList, Function | MediumTest | Level2)
508 {
509 std::ostringstream oss;
510 HidumpController::GetInstance().DumpVisibleParamList(oss);
511 std::string result = oss.str();
512 ASSERT_NE(result.size(), 0);
513 }
514
515 /**
516 * @tc.name: DumpVisibleParam
517 * @tc.desc: DumpVisibleParam Test
518 * @tc.type: FUNC
519 */
HWTEST_F(HidumpControllerTest, DumpVisibleParam, Function | MediumTest | Level2)520 HWTEST_F(HidumpControllerTest, DumpVisibleParam, Function | MediumTest | Level2)
521 {
522 auto sceneSession = GetSceneSession("DumpVisibleParam");
523 ASSERT_NE(sceneSession, nullptr);
524
525 std::ostringstream oss;
526 HidumpController::GetInstance().DumpVisibleParam(oss, sceneSession);
527 std::string result = oss.str();
528 ASSERT_NE(result.size(), 0);
529 }
530 } // namespace
531 } // namespace Rosen
532 } // namespace OHOS