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 #include "screen_session.h"
16 #include <gtest/gtest.h>
17 #include "screen_session_manager/include/screen_session_manager.h"
18 #include "scene_board_judgement.h"
19 
20 // using namespace FRAME_TRACE;
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace Rosen {
25 class MockScreenChangeListener : public IScreenChangeListener {
26 public:
27     void OnConnect(ScreenId screenId) override {}
28     void OnDisconnect(ScreenId screenId) override {}
29     void OnPropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason,
30         ScreenId screenId) override {}
31     void OnPowerStatusChange(DisplayPowerEvent event, EventStatus status,
32         PowerStateChangeReason reason) override {}
33     void OnSensorRotationChange(float sensorRotation, ScreenId screenId) override {}
34     void OnScreenOrientationChange(float screenOrientation, ScreenId screenId) override {}
35     void OnScreenRotationLockedChange(bool isLocked, ScreenId screenId) override {}
36     void OnScreenExtendChange(ScreenId mainScreenId, ScreenId extendScreenId) override {}
37     void OnHoverStatusChange(int32_t hoverStatus, ScreenId screenId) override {}
38 };
39 class ScreenSessionTest : public testing::Test {
40   public:
ScreenSessionTest()41     ScreenSessionTest() {}
~ScreenSessionTest()42     ~ScreenSessionTest() {}
43 };
44 
45 namespace {
46 
47 /**
48  * @tc.name: create ScreenSession
49  * @tc.desc: normal function
50  * @tc.type: FUNC
51  */
HWTEST_F(ScreenSessionTest, ScreenSession, Function | SmallTest | Level2)52 HWTEST_F(ScreenSessionTest, ScreenSession, Function | SmallTest | Level2)
53 {
54     ScreenSessionConfig config = {
55         .screenId = 0,
56         .rsId = 0,
57         .name = "OpenHarmony",
58     };
59     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
60     EXPECT_NE(nullptr, screenSession);
61 }
62 
63 /**
64  * @tc.name: create ScreenSession02
65  * @tc.desc: normal function
66  * @tc.type: FUNC
67  */
HWTEST_F(ScreenSessionTest, ScreenSession02, Function | SmallTest | Level2)68 HWTEST_F(ScreenSessionTest, ScreenSession02, Function | SmallTest | Level2)
69 {
70     ScreenSessionConfig config = {
71         .screenId = 0,
72         .rsId = 0,
73         .name = "OpenHarmony",
74     };
75     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
76     EXPECT_NE(nullptr, screenSession);
77 }
78 
79 /**
80  * @tc.name: create ScreenSession03
81  * @tc.desc: normal function
82  * @tc.type: FUNC
83  */
HWTEST_F(ScreenSessionTest, ScreenSession03, Function | SmallTest | Level2)84 HWTEST_F(ScreenSessionTest, ScreenSession03, Function | SmallTest | Level2)
85 {
86     ScreenSessionConfig config = {
87         .screenId = 0,
88         .rsId = 0,
89         .name = "OpenHarmony",
90     };
91     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_MIRROR);
92     EXPECT_NE(nullptr, screenSession);
93 }
94 
95 /**
96  * @tc.name: create ScreenSession03
97  * @tc.desc: normal function
98  * @tc.type: FUNC
99  */
HWTEST_F(ScreenSessionTest, ScreenSession04, Function | SmallTest | Level2)100 HWTEST_F(ScreenSessionTest, ScreenSession04, Function | SmallTest | Level2)
101 {
102     ScreenSessionConfig config = {
103         .screenId = 0,
104         .rsId = 0,
105         .name = "OpenHarmony",
106     };
107     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_REAL);
108     EXPECT_NE(nullptr, screenSession);
109 }
110 
111 /**
112  * @tc.name: create ScreenSession05
113  * @tc.desc: normal function
114  * @tc.type: FUNC
115  */
HWTEST_F(ScreenSessionTest, ScreenSession05, Function | SmallTest | Level2)116 HWTEST_F(ScreenSessionTest, ScreenSession05, Function | SmallTest | Level2)
117 {
118     ScreenSessionConfig config = {
119         .screenId = 0,
120         .rsId = 0,
121         .name = "OpenHarmony",
122     };
123     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::INVALID);
124     EXPECT_NE(nullptr, screenSession);
125 }
126 
127 /**
128  * @tc.name: CreateDisplayNode
129  * @tc.desc: normal function
130  * @tc.type: FUNC
131  */
HWTEST_F(ScreenSessionTest, CreateDisplayNode, Function | SmallTest | Level2)132 HWTEST_F(ScreenSessionTest, CreateDisplayNode, Function | SmallTest | Level2)
133 {
134     GTEST_LOG_(INFO) << "ScreenSessionTest: CreateDisplayNode start";
135     Rosen::RSDisplayNodeConfig rsConfig;
136     ScreenSessionConfig config = {
137         .screenId = 100,
138         .rsId = 101,
139         .name = "OpenHarmony",
140     };
141     rsConfig.isMirrored = true;
142     rsConfig.screenId = 101;
143     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
144     EXPECT_NE(nullptr, screenSession);
145     screenSession->CreateDisplayNode(rsConfig);
146     GTEST_LOG_(INFO) << "ScreenSessionTest: CreateDisplayNode end";
147 }
148 
149 /**
150  * @tc.name: SetMirrorScreenType
151  * @tc.desc: normal function
152  * @tc.type: FUNC
153  */
HWTEST_F(ScreenSessionTest, SetMirrorScreenType, Function | SmallTest | Level2)154 HWTEST_F(ScreenSessionTest, SetMirrorScreenType, Function | SmallTest | Level2)
155 {
156     GTEST_LOG_(INFO) << "SetMirrorScreenType start";
157     ScreenSessionConfig config = {
158         .screenId = 100,
159         .rsId = 101,
160         .name = "OpenHarmony",
161     };
162     Rosen::RSDisplayNodeConfig rsConfig;
163     rsConfig.isMirrored = true;
164     rsConfig.screenId = 101;
165     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
166     EXPECT_NE(nullptr, screenSession);
167     MirrorScreenType mirrorType = MirrorScreenType::VIRTUAL_MIRROR;
168     screenSession->SetMirrorScreenType(mirrorType);
169     GTEST_LOG_(INFO) << "SetMirrorScreenType end";
170 }
171 
172 /**
173  * @tc.name: GetMirrorScreenType
174  * @tc.desc: normal function
175  * @tc.type: FUNC
176  */
HWTEST_F(ScreenSessionTest, GetMirrorScreenType, Function | SmallTest | Level2)177 HWTEST_F(ScreenSessionTest, GetMirrorScreenType, Function | SmallTest | Level2)
178 {
179     GTEST_LOG_(INFO) << "GetMirrorScreenType start";
180     ScreenSessionConfig config = {
181         .screenId = 100,
182         .rsId = 101,
183         .name = "OpenHarmony",
184     };
185     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
186     EXPECT_NE(nullptr, screenSession);
187     MirrorScreenType mirrorType = MirrorScreenType::VIRTUAL_MIRROR;
188     screenSession->SetMirrorScreenType(mirrorType);
189     MirrorScreenType res = screenSession->GetMirrorScreenType();
190     ASSERT_EQ(mirrorType, res);
191     GTEST_LOG_(INFO) << "GetMirrorScreenType end";
192 }
193 
194 /**
195  * @tc.name: SetDefaultDeviceRotationOffset
196  * @tc.desc: normal function
197  * @tc.type: FUNC
198  */
HWTEST_F(ScreenSessionTest, SetDefaultDeviceRotationOffset, Function | SmallTest | Level2)199 HWTEST_F(ScreenSessionTest, SetDefaultDeviceRotationOffset, Function | SmallTest | Level2)
200 {
201     GTEST_LOG_(INFO) << "SetDefaultDeviceRotationOffset start";
202     ScreenSessionConfig config = {
203         .screenId = 100,
204         .rsId = 101,
205         .name = "OpenHarmony",
206     };
207     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
208     EXPECT_NE(nullptr, screenSession);
209     uint32_t defaultRotationOffset = 0;
210     screenSession->SetDefaultDeviceRotationOffset(defaultRotationOffset);
211     GTEST_LOG_(INFO) << "SetDefaultDeviceRotationOffset end";
212 }
213 
214 /**
215  * @tc.name: UpdateDisplayState
216  * @tc.desc: normal function
217  * @tc.type: FUNC
218  */
HWTEST_F(ScreenSessionTest, UpdateDisplayState, Function | SmallTest | Level2)219 HWTEST_F(ScreenSessionTest, UpdateDisplayState, Function | SmallTest | Level2)
220 {
221     GTEST_LOG_(INFO) << "UpdateDisplayState start";
222     ScreenSessionConfig config = {
223         .screenId = 100,
224         .rsId = 101,
225         .name = "OpenHarmony",
226     };
227     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
228     EXPECT_NE(nullptr, screenSession);
229     DisplayState displayState = DisplayState::OFF;
230     screenSession->UpdateDisplayState(displayState);
231     GTEST_LOG_(INFO) << "UpdateDisplayState end";
232 }
233 
234 /**
235  * @tc.name: UpdateRefreshRate
236  * @tc.desc: normal function
237  * @tc.type: FUNC
238  */
HWTEST_F(ScreenSessionTest, UpdateRefreshRate, Function | SmallTest | Level2)239 HWTEST_F(ScreenSessionTest, UpdateRefreshRate, Function | SmallTest | Level2)
240 {
241     GTEST_LOG_(INFO) << "UpdateRefreshRate start";
242     ScreenSessionConfig config = {
243         .screenId = 100,
244         .rsId = 101,
245         .name = "OpenHarmony",
246     };
247     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
248     EXPECT_NE(nullptr, screenSession);
249     uint32_t refreshRate = 2;
250     screenSession->UpdateRefreshRate(refreshRate);
251     GTEST_LOG_(INFO) << "UpdateRefreshRate end";
252 }
253 
254 /**
255  * @tc.name: GetRefreshRate
256  * @tc.desc: normal function
257  * @tc.type: FUNC
258  */
HWTEST_F(ScreenSessionTest, GetRefreshRate, Function | SmallTest | Level2)259 HWTEST_F(ScreenSessionTest, GetRefreshRate, Function | SmallTest | Level2)
260 {
261     GTEST_LOG_(INFO) << "GetRefreshRate start";
262     ScreenSessionConfig config = {
263         .screenId = 100,
264         .rsId = 101,
265         .name = "OpenHarmony",
266     };
267     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
268     EXPECT_NE(nullptr, screenSession);
269     uint32_t refreshRate = 2;
270     screenSession->UpdateRefreshRate(refreshRate);
271     auto res = screenSession->GetRefreshRate();
272     ASSERT_EQ(refreshRate, res);
273     GTEST_LOG_(INFO) << "GetRefreshRate end";
274 }
275 
276 /**
277  * @tc.name: UpdatePropertyByResolution
278  * @tc.desc: normal function
279  * @tc.type: FUNC
280  */
HWTEST_F(ScreenSessionTest, UpdatePropertyByResolution, Function | SmallTest | Level2)281 HWTEST_F(ScreenSessionTest, UpdatePropertyByResolution, Function | SmallTest | Level2)
282 {
283     GTEST_LOG_(INFO) << "UpdatePropertyByResolution start";
284     ScreenSessionConfig config = {
285         .screenId = 100,
286         .rsId = 101,
287         .name = "OpenHarmony",
288     };
289     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
290     EXPECT_NE(nullptr, screenSession);
291     uint32_t width = 1000;
292     uint32_t height = 1500;
293     screenSession->UpdatePropertyByResolution(width, height);
294     GTEST_LOG_(INFO) << "UpdatePropertyByResolution end";
295 }
296 
297 /**
298  * @tc.name: HandleSensorRotation
299  * @tc.desc: normal function
300  * @tc.type: FUNC
301  */
HWTEST_F(ScreenSessionTest, HandleSensorRotation, Function | SmallTest | Level2)302 HWTEST_F(ScreenSessionTest, HandleSensorRotation, Function | SmallTest | Level2)
303 {
304     GTEST_LOG_(INFO) << "HandleSensorRotation start";
305     ScreenSessionConfig config = {
306         .screenId = 100,
307         .rsId = 101,
308         .name = "OpenHarmony",
309     };
310     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
311     EXPECT_NE(nullptr, screenSession);
312     float sensorRotation = 0.0f;
313     screenSession->HandleSensorRotation(sensorRotation);
314     GTEST_LOG_(INFO) << "HandleSensorRotation end";
315 }
316 
317 /**
318  * @tc.name: ConvertIntToRotation
319  * @tc.desc: normal function
320  * @tc.type: FUNC
321  */
HWTEST_F(ScreenSessionTest, ConvertIntToRotation, Function | SmallTest | Level2)322 HWTEST_F(ScreenSessionTest, ConvertIntToRotation, Function | SmallTest | Level2)
323 {
324     GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertIntToRotation start";
325     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
326     int rotation = 0;
327     auto res = session->ConvertIntToRotation(rotation);
328     ASSERT_EQ(res, Rotation::ROTATION_0);
329     rotation = 90;
330     res = session->ConvertIntToRotation(rotation);
331     ASSERT_EQ(res, Rotation::ROTATION_90);
332     rotation = 180;
333     res = session->ConvertIntToRotation(rotation);
334     ASSERT_EQ(res, Rotation::ROTATION_180);
335     rotation = 270;
336     res = session->ConvertIntToRotation(rotation);
337     ASSERT_EQ(res, Rotation::ROTATION_270);
338     GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertIntToRotation end";
339 }
340 
341 /**
342  * @tc.name: SetVirtualScreenFlag
343  * @tc.desc: normal function
344  * @tc.type: FUNC
345  */
HWTEST_F(ScreenSessionTest, SetVirtualScreenFlag, Function | SmallTest | Level2)346 HWTEST_F(ScreenSessionTest, SetVirtualScreenFlag, Function | SmallTest | Level2)
347 {
348     GTEST_LOG_(INFO) << "SetVirtualScreenFlag start";
349     ScreenSessionConfig config = {
350         .screenId = 100,
351         .rsId = 101,
352         .name = "OpenHarmony",
353     };
354     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
355     EXPECT_NE(nullptr, screenSession);
356     VirtualScreenFlag screenFlag = VirtualScreenFlag::CAST;
357     screenSession->SetVirtualScreenFlag(screenFlag);
358     GTEST_LOG_(INFO) << "SetVirtualScreenFlag end";
359 }
360 
361 /**
362  * @tc.name: GetVirtualScreenFlag
363  * @tc.desc: normal function
364  * @tc.type: FUNC
365  */
HWTEST_F(ScreenSessionTest, GetVirtualScreenFlag, Function | SmallTest | Level2)366 HWTEST_F(ScreenSessionTest, GetVirtualScreenFlag, Function | SmallTest | Level2)
367 {
368     GTEST_LOG_(INFO) << "GetVirtualScreenFlag start";
369     ScreenSessionConfig config = {
370         .screenId = 100,
371         .rsId = 101,
372         .name = "OpenHarmony",
373     };
374     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
375     EXPECT_NE(nullptr, screenSession);
376     VirtualScreenFlag screenFlag = VirtualScreenFlag::CAST;
377     screenSession->SetVirtualScreenFlag(screenFlag);
378     auto res = screenSession->GetVirtualScreenFlag();
379     ASSERT_EQ(screenFlag, res);
380     GTEST_LOG_(INFO) << "GetVirtualScreenFlag end";
381 }
382 
383 /**
384  * @tc.name: UpdateToInputManager
385  * @tc.desc: normal function
386  * @tc.type: FUNC
387  */
HWTEST_F(ScreenSessionTest, UpdateToInputManager, Function | SmallTest | Level2)388 HWTEST_F(ScreenSessionTest, UpdateToInputManager, Function | SmallTest | Level2)
389 {
390     GTEST_LOG_(INFO) << "UpdateToInputManager start";
391     ScreenSessionConfig config = {
392         .screenId = 100,
393         .rsId = 101,
394         .name = "OpenHarmony",
395     };
396     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
397     EXPECT_NE(nullptr, screenSession);
398     RRect bounds;
399     int rotation = 90;
400     FoldDisplayMode foldDisplayMode = FoldDisplayMode::FULL;
401     screenSession->UpdateToInputManager(bounds, rotation, foldDisplayMode);
402     bounds.rect_.width_ = 1344;
403     bounds.rect_.height_ = 2772;
404     rotation = 0;
405     foldDisplayMode = FoldDisplayMode::MAIN;
406     screenSession->UpdateToInputManager(bounds, rotation, foldDisplayMode);
407     GTEST_LOG_(INFO) << "UpdateToInputManager end";
408 }
409 
410 /**
411  * @tc.name: UpdatePropertyAfterRotation
412  * @tc.desc: normal function
413  * @tc.type: FUNC
414  */
HWTEST_F(ScreenSessionTest, UpdatePropertyAfterRotation, Function | SmallTest | Level2)415 HWTEST_F(ScreenSessionTest, UpdatePropertyAfterRotation, Function | SmallTest | Level2)
416 {
417     GTEST_LOG_(INFO) << "UpdatePropertyAfterRotation start";
418     ScreenSessionConfig config = {
419         .screenId = 100,
420         .rsId = 101,
421         .name = "OpenHarmony",
422     };
423     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
424     EXPECT_NE(nullptr, screenSession);
425     RRect bounds;
426     bounds.rect_.width_ = 1344;
427     bounds.rect_.height_ = 2772;
428     int rotation = 90;
429     FoldDisplayMode foldDisplayMode = FoldDisplayMode::MAIN;
430     screenSession->UpdatePropertyAfterRotation(bounds, rotation, foldDisplayMode);
431     GTEST_LOG_(INFO) << "UpdatePropertyAfterRotation end";
432 }
433 
434 /**
435  * @tc.name: ReportNotifyModeChange
436  * @tc.desc: normal function
437  * @tc.type: FUNC
438  */
HWTEST_F(ScreenSessionTest, ReportNotifyModeChange, Function | SmallTest | Level2)439 HWTEST_F(ScreenSessionTest, ReportNotifyModeChange, Function | SmallTest | Level2)
440 {
441     GTEST_LOG_(INFO) << "ReportNotifyModeChange start";
442     ScreenSessionConfig config = {
443         .screenId = 100,
444         .rsId = 101,
445         .name = "OpenHarmony",
446     };
447     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
448     EXPECT_NE(nullptr, screenSession);
449     DisplayOrientation displayOrientation = DisplayOrientation::LANDSCAPE;
450     screenSession->ReportNotifyModeChange(displayOrientation);
451     displayOrientation = DisplayOrientation::PORTRAIT;
452     screenSession->ReportNotifyModeChange(displayOrientation);
453     displayOrientation = DisplayOrientation::PORTRAIT_INVERTED;
454     screenSession->ReportNotifyModeChange(displayOrientation);
455     GTEST_LOG_(INFO) << "ReportNotifyModeChange end";
456 }
457 
458 /**
459  * @tc.name: UpdateRotationAfterBoot01
460  * @tc.desc: normal function
461  * @tc.type: FUNC
462  */
HWTEST_F(ScreenSessionTest, UpdateRotationAfterBoot01, Function | SmallTest | Level2)463 HWTEST_F(ScreenSessionTest, UpdateRotationAfterBoot01, Function | SmallTest | Level2)
464 {
465     GTEST_LOG_(INFO) << "UpdateRotationAfterBoot start";
466     ScreenSessionConfig config = {
467         .screenId = 100,
468         .rsId = 101,
469         .name = "OpenHarmony",
470     };
471     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
472     EXPECT_NE(nullptr, screenSession);
473     bool foldToExpand = true;
474     screenSession->UpdateRotationAfterBoot(foldToExpand);
475     GTEST_LOG_(INFO) << "UpdateRotationAfterBoot end";
476 }
477 
478 /**
479  * @tc.name: UpdateRotationAfterBoot02
480  * @tc.desc: normal function
481  * @tc.type: FUNC
482  */
HWTEST_F(ScreenSessionTest, UpdateRotationAfterBoot02, Function | SmallTest | Level2)483 HWTEST_F(ScreenSessionTest, UpdateRotationAfterBoot02, Function | SmallTest | Level2)
484 {
485     GTEST_LOG_(INFO) << "UpdateRotationAfterBoot start";
486     ScreenSessionConfig config = {
487         .screenId = 100,
488         .rsId = 101,
489         .name = "OpenHarmony",
490     };
491     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
492     EXPECT_NE(nullptr, screenSession);
493     bool foldToExpand = false;
494     screenSession->UpdateRotationAfterBoot(foldToExpand);
495     GTEST_LOG_(INFO) << "UpdateRotationAfterBoot end";
496 }
497 
498 /**
499  * @tc.name: SetScreenSceneDpiChangeListener
500  * @tc.desc: normal function
501  * @tc.type: FUNC
502  */
HWTEST_F(ScreenSessionTest, SetScreenSceneDpiChangeListener, Function | SmallTest | Level2)503 HWTEST_F(ScreenSessionTest, SetScreenSceneDpiChangeListener, Function | SmallTest | Level2)
504 {
505     GTEST_LOG_(INFO) << "SetScreenSceneDpiChangeListener start";
506     ScreenSessionConfig config = {
507         .screenId = 100,
508         .rsId = 101,
509         .name = "OpenHarmony",
510     };
511     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
512     EXPECT_NE(nullptr, screenSession);
513     SetScreenSceneDpiFunc func = nullptr;
514     screenSession->SetScreenSceneDpiChangeListener(func);
515     GTEST_LOG_(INFO) << "SetScreenSceneDpiChangeListener end";
516 }
517 
518 /**
519  * @tc.name: SetScreenSceneDestroyListener
520  * @tc.desc: normal function
521  * @tc.type: FUNC
522  */
HWTEST_F(ScreenSessionTest, SetScreenSceneDestroyListener, Function | SmallTest | Level2)523 HWTEST_F(ScreenSessionTest, SetScreenSceneDestroyListener, Function | SmallTest | Level2)
524 {
525     GTEST_LOG_(INFO) << "SetScreenSceneDestroyListener start";
526     ScreenSessionConfig config = {
527         .screenId = 100,
528         .rsId = 101,
529         .name = "OpenHarmony",
530     };
531     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
532     EXPECT_NE(nullptr, screenSession);
533     DestroyScreenSceneFunc func = nullptr;
534     screenSession->SetScreenSceneDestroyListener(func);
535     GTEST_LOG_(INFO) << "SetScreenSceneDestroyListener end";
536 }
537 
538 /**
539  * @tc.name: SetScreenSceneDpi
540  * @tc.desc: normal function
541  * @tc.type: FUNC
542  */
HWTEST_F(ScreenSessionTest, SetScreenSceneDpi, Function | SmallTest | Level2)543 HWTEST_F(ScreenSessionTest, SetScreenSceneDpi, Function | SmallTest | Level2)
544 {
545     GTEST_LOG_(INFO) << "SetScreenSceneDpi start";
546     ScreenSessionConfig config = {
547         .screenId = 100,
548         .rsId = 101,
549         .name = "OpenHarmony",
550     };
551     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
552     EXPECT_NE(nullptr, screenSession);
553     float density = 1.5f;
554     SetScreenSceneDpiFunc func = nullptr;
555     screenSession->SetScreenSceneDpiChangeListener(func);
556     screenSession->SetScreenSceneDpi(density);
557     SetScreenSceneDpiFunc func2 = [](float density) {
558             EXPECT_TRUE(true);
559         };
560     screenSession->SetScreenSceneDpiChangeListener(func2);
561     screenSession->SetScreenSceneDpi(density);
562     GTEST_LOG_(INFO) << "SetScreenSceneDpi end";
563 }
564 
565 /**
566  * @tc.name: DestroyScreenScene
567  * @tc.desc: normal function
568  * @tc.type: FUNC
569  */
HWTEST_F(ScreenSessionTest, DestroyScreenScene, Function | SmallTest | Level2)570 HWTEST_F(ScreenSessionTest, DestroyScreenScene, Function | SmallTest | Level2)
571 {
572     GTEST_LOG_(INFO) << "DestroyScreenScene start";
573     ScreenSessionConfig config = {
574         .screenId = 100,
575         .rsId = 101,
576         .name = "OpenHarmony",
577     };
578     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
579     EXPECT_NE(nullptr, screenSession);
580     DestroyScreenSceneFunc func = nullptr;
581     screenSession->SetScreenSceneDestroyListener(func);
582     screenSession->DestroyScreenScene();
583     DestroyScreenSceneFunc func2 = []() {
584             EXPECT_TRUE(true);
585         };
586     screenSession->SetScreenSceneDestroyListener(func2);
587     screenSession->DestroyScreenScene();
588     GTEST_LOG_(INFO) << "DestroyScreenScene end";
589 }
590 
591 /**
592  * @tc.name: SetDensityInCurResolution
593  * @tc.desc: normal function
594  * @tc.type: FUNC
595  */
HWTEST_F(ScreenSessionTest, SetDensityInCurResolution, Function | SmallTest | Level2)596 HWTEST_F(ScreenSessionTest, SetDensityInCurResolution, Function | SmallTest | Level2)
597 {
598     GTEST_LOG_(INFO) << "SetDensityInCurResolution start";
599     ScreenSessionConfig config = {
600         .screenId = 100,
601         .rsId = 101,
602         .name = "OpenHarmony",
603     };
604     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
605     EXPECT_NE(nullptr, screenSession);
606     float densityInCurResolution = 1.5f;
607     screenSession->SetDensityInCurResolution(densityInCurResolution);
608     GTEST_LOG_(INFO) << "SetDensityInCurResolution end";
609 }
610 
611 /**
612  * @tc.name: GetSourceMode
613  * @tc.desc: normal function
614  * @tc.type: FUNC
615  */
HWTEST_F(ScreenSessionTest, GetSourceMode, Function | SmallTest | Level2)616 HWTEST_F(ScreenSessionTest, GetSourceMode, Function | SmallTest | Level2)
617 {
618     GTEST_LOG_(INFO) << "ScreenSessionTest: GetSourceMode start";
619     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
620     session->screenId_ = session->defaultScreenId_;
621     ScreenSourceMode mode = session->GetSourceMode();
622     ASSERT_EQ(mode, ScreenSourceMode::SCREEN_MAIN);
623     ScreenSessionConfig config = {
624         .screenId = 100,
625         .rsId = 101,
626         .name = "OpenHarmony",
627     };
628     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
629     mode = screenSession->GetSourceMode();
630     ASSERT_EQ(mode, ScreenSourceMode::SCREEN_ALONE);
631     screenSession->SetScreenCombination(ScreenCombination::SCREEN_EXPAND);
632     mode = screenSession->GetSourceMode();
633     ASSERT_EQ(mode, ScreenSourceMode::SCREEN_EXTEND);
634     screenSession->SetScreenCombination(ScreenCombination::SCREEN_MIRROR);
635     mode = screenSession->GetSourceMode();
636     ASSERT_EQ(mode, ScreenSourceMode::SCREEN_MIRROR);
637     screenSession->SetScreenCombination(ScreenCombination::SCREEN_UNIQUE);
638     mode = screenSession->GetSourceMode();
639     ASSERT_EQ(mode, ScreenSourceMode::SCREEN_UNIQUE);
640     GTEST_LOG_(INFO) << "ScreenSessionTest: GetSourceMode end";
641 }
642 
643 /**
644  * @tc.name: GetPixelFormat
645  * @tc.desc: normal function
646  * @tc.type: FUNC
647  */
HWTEST_F(ScreenSessionTest, GetPixelFormat, Function | SmallTest | Level2)648 HWTEST_F(ScreenSessionTest, GetPixelFormat, Function | SmallTest | Level2)
649 {
650     GTEST_LOG_(INFO) << "GetPixelFormat start";
651     ScreenSessionConfig config = {
652         .screenId = 100,
653         .rsId = 0,
654         .name = "OpenHarmony",
655     };
656     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
657     EXPECT_NE(nullptr, screenSession);
658     GraphicPixelFormat pixelFormat;
659     auto res = screenSession->GetPixelFormat(pixelFormat);
660     ASSERT_EQ(res, DMError::DM_OK);
661     GTEST_LOG_(INFO) << "GetPixelFormat end";
662 }
663 
664 /**
665  * @tc.name: SetPixelFormat
666  * @tc.desc: normal function
667  * @tc.type: FUNC
668  */
HWTEST_F(ScreenSessionTest, SetPixelFormat, Function | SmallTest | Level2)669 HWTEST_F(ScreenSessionTest, SetPixelFormat, Function | SmallTest | Level2)
670 {
671     GTEST_LOG_(INFO) << "SetPixelFormat start";
672     ScreenSessionConfig config = {
673         .screenId = 100,
674         .rsId = 0,
675         .name = "OpenHarmony",
676     };
677     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
678     EXPECT_NE(nullptr, screenSession);
679     GraphicPixelFormat pixelFormat = GraphicPixelFormat{GRAPHIC_PIXEL_FMT_CLUT8};
680     auto res = screenSession->SetPixelFormat(pixelFormat);
681     ASSERT_EQ(res, DMError::DM_OK);
682     GTEST_LOG_(INFO) << "SetPixelFormat end";
683 }
684 
685 /**
686  * @tc.name: GetSupportedHDRFormats
687  * @tc.desc: normal function
688  * @tc.type: FUNC
689  */
HWTEST_F(ScreenSessionTest, GetSupportedHDRFormats, Function | SmallTest | Level2)690 HWTEST_F(ScreenSessionTest, GetSupportedHDRFormats, Function | SmallTest | Level2)
691 {
692     GTEST_LOG_(INFO) << "GetSupportedHDRFormats start";
693     ScreenSessionConfig config = {
694         .screenId = 100,
695         .rsId = 0,
696         .name = "OpenHarmony",
697     };
698     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
699     EXPECT_NE(nullptr, screenSession);
700     std::vector<ScreenHDRFormat> hdrFormats;
701     auto res = screenSession->GetSupportedHDRFormats(hdrFormats);
702     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
703         ASSERT_EQ(res, DMError::DM_OK);
704     } else {
705         ASSERT_NE(res, DMError::DM_OK);
706     }
707     GTEST_LOG_(INFO) << "GetSupportedHDRFormats end";
708 }
709 
710 /**
711  * @tc.name: GetScreenHDRFormat
712  * @tc.desc: normal function
713  * @tc.type: FUNC
714  */
HWTEST_F(ScreenSessionTest, GetScreenHDRFormat, Function | SmallTest | Level2)715 HWTEST_F(ScreenSessionTest, GetScreenHDRFormat, Function | SmallTest | Level2)
716 {
717     GTEST_LOG_(INFO) << "GetScreenHDRFormat start";
718     ScreenSessionConfig config = {
719         .screenId = 100,
720         .rsId = 0,
721         .name = "OpenHarmony",
722     };
723     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
724     EXPECT_NE(nullptr, screenSession);
725     ScreenHDRFormat hdrFormat;
726     auto res = screenSession->GetScreenHDRFormat(hdrFormat);
727     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
728         ASSERT_EQ(res, DMError::DM_OK);
729     } else {
730         ASSERT_NE(res, DMError::DM_OK);
731     }
732     GTEST_LOG_(INFO) << "GetScreenHDRFormat end";
733 }
734 
735 /**
736  * @tc.name: SetScreenHDRFormat
737  * @tc.desc: normal function
738  * @tc.type: FUNC
739  */
HWTEST_F(ScreenSessionTest, SetScreenHDRFormat, Function | SmallTest | Level2)740 HWTEST_F(ScreenSessionTest, SetScreenHDRFormat, Function | SmallTest | Level2)
741 {
742     GTEST_LOG_(INFO) << "SetScreenHDRFormat start";
743     ScreenSessionConfig config = {
744         .screenId = 100,
745         .rsId = 0,
746         .name = "OpenHarmony",
747     };
748     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
749     EXPECT_NE(nullptr, screenSession);
750     int32_t modeIdx = 0;
751     auto res = screenSession->SetScreenHDRFormat(modeIdx);
752     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
753         ASSERT_EQ(res, DMError::DM_OK);
754         modeIdx = -1;
755         res = screenSession->SetScreenHDRFormat(modeIdx);
756         ASSERT_EQ(res, DMError::DM_ERROR_INVALID_PARAM);
757     } else {
758         ASSERT_NE(res, DMError::DM_OK);
759     }
760     GTEST_LOG_(INFO) << "SetScreenHDRFormat end";
761 }
762 
763 /**
764  * @tc.name: GetSupportedColorSpaces
765  * @tc.desc: normal function
766  * @tc.type: FUNC
767  */
HWTEST_F(ScreenSessionTest, GetSupportedColorSpaces, Function | SmallTest | Level2)768 HWTEST_F(ScreenSessionTest, GetSupportedColorSpaces, Function | SmallTest | Level2)
769 {
770     GTEST_LOG_(INFO) << "GetSupportedColorSpaces start";
771     ScreenSessionConfig config = {
772         .screenId = 100,
773         .rsId = 0,
774         .name = "OpenHarmony",
775     };
776     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
777     EXPECT_NE(nullptr, screenSession);
778     std::vector<GraphicCM_ColorSpaceType> colorSpaces;
779     auto res = screenSession->GetSupportedColorSpaces(colorSpaces);
780     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
781         ASSERT_EQ(res, DMError::DM_OK);
782     } else {
783         ASSERT_NE(res, DMError::DM_OK);
784     }
785     GTEST_LOG_(INFO) << "GetSupportedColorSpaces end";
786 }
787 
788 /**
789  * @tc.name: GetScreenColorSpace
790  * @tc.desc: normal function
791  * @tc.type: FUNC
792  */
HWTEST_F(ScreenSessionTest, GetScreenColorSpace, Function | SmallTest | Level2)793 HWTEST_F(ScreenSessionTest, GetScreenColorSpace, Function | SmallTest | Level2)
794 {
795     GTEST_LOG_(INFO) << "GetScreenColorSpace start";
796     ScreenSessionConfig config = {
797         .screenId = 100,
798         .rsId = 0,
799         .name = "OpenHarmony",
800     };
801     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
802     EXPECT_NE(nullptr, screenSession);
803     GraphicCM_ColorSpaceType colorSpace;
804     auto res = screenSession->GetScreenColorSpace(colorSpace);
805     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
806         ASSERT_EQ(res, DMError::DM_OK);
807     } else {
808         ASSERT_NE(res, DMError::DM_OK);
809     }
810     GTEST_LOG_(INFO) << "GetScreenColorSpace end";
811 }
812 
813 /**
814  * @tc.name: SetScreenColorSpace
815  * @tc.desc: normal function
816  * @tc.type: FUNC
817  */
HWTEST_F(ScreenSessionTest, SetScreenColorSpace, Function | SmallTest | Level2)818 HWTEST_F(ScreenSessionTest, SetScreenColorSpace, Function | SmallTest | Level2)
819 {
820     GTEST_LOG_(INFO) << "SetScreenColorSpace start";
821     ScreenSessionConfig config = {
822         .screenId = 100,
823         .rsId = 101,
824         .name = "OpenHarmony",
825     };
826     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
827     EXPECT_NE(nullptr, screenSession);
828     GraphicCM_ColorSpaceType colorSpace = GraphicCM_ColorSpaceType{GRAPHIC_CM_COLORSPACE_NONE};
829     screenSession->SetScreenColorSpace(colorSpace);
830     EXPECT_TRUE(true);
831     GTEST_LOG_(INFO) << "SetScreenColorSpace end";
832 }
833 
834 /**
835  * @tc.name: SetPrivateSessionForeground
836  * @tc.desc: normal function
837  * @tc.type: FUNC
838  */
HWTEST_F(ScreenSessionTest, SetPrivateSessionForeground, Function | SmallTest | Level2)839 HWTEST_F(ScreenSessionTest, SetPrivateSessionForeground, Function | SmallTest | Level2)
840 {
841     GTEST_LOG_(INFO) << "SetPrivateSessionForeground start";
842     ScreenSessionConfig config = {
843         .screenId = 100,
844         .rsId = 101,
845         .name = "OpenHarmony",
846     };
847     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
848     EXPECT_NE(nullptr, screenSession);
849     bool hasPrivate = true;
850     screenSession->SetPrivateSessionForeground(hasPrivate);
851     auto res = screenSession->HasPrivateSessionForeground();
852     ASSERT_EQ(res, hasPrivate);
853     GTEST_LOG_(INFO) << "SetPrivateSessionForeground end";
854 }
855 
856 /**
857  * @tc.name: GetScreenCombination
858  * @tc.desc: normal function
859  * @tc.type: FUNC
860  */
HWTEST_F(ScreenSessionTest, GetScreenCombination, Function | SmallTest | Level2)861 HWTEST_F(ScreenSessionTest, GetScreenCombination, Function | SmallTest | Level2)
862 {
863     GTEST_LOG_(INFO) << "GetScreenCombination start";
864     ScreenSessionConfig config = {
865         .screenId = 100,
866         .rsId = 101,
867         .name = "OpenHarmony",
868     };
869     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
870     EXPECT_NE(nullptr, screenSession);
871     ScreenCombination combination { ScreenCombination::SCREEN_ALONE };
872     screenSession->SetScreenCombination(combination);
873     auto res = screenSession->GetScreenCombination();
874     ASSERT_EQ(res, combination);
875     GTEST_LOG_(INFO) << "GetScreenCombination end";
876 }
877 
878 /**
879  * @tc.name: Resize
880  * @tc.desc: normal function
881  * @tc.type: FUNC
882  */
HWTEST_F(ScreenSessionTest, Resize, Function | SmallTest | Level2)883 HWTEST_F(ScreenSessionTest, Resize, Function | SmallTest | Level2)
884 {
885     GTEST_LOG_(INFO) << "Resize start";
886     ScreenSessionConfig config = {
887         .screenId = 100,
888         .rsId = 101,
889         .name = "OpenHarmony",
890     };
891     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
892     EXPECT_NE(nullptr, screenSession);
893     uint32_t width = 1000;
894     uint32_t height = 1000;
895     screenSession->Resize(width, height);
896     GTEST_LOG_(INFO) << "Resize end";
897 }
898 
899 /**
900  * @tc.name: UpdateAvailableArea
901  * @tc.desc: normal function
902  * @tc.type: FUNC
903  */
HWTEST_F(ScreenSessionTest, UpdateAvailableArea, Function | SmallTest | Level2)904 HWTEST_F(ScreenSessionTest, UpdateAvailableArea, Function | SmallTest | Level2)
905 {
906     GTEST_LOG_(INFO) << "UpdateAvailableArea start";
907     ScreenSessionConfig config = {
908         .screenId = 100,
909         .rsId = 101,
910         .name = "OpenHarmony",
911     };
912     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
913     EXPECT_NE(nullptr, screenSession);
914     DMRect area = screenSession->GetAvailableArea();
915     auto res = screenSession->UpdateAvailableArea(area);
916     ASSERT_EQ(res, false);
917     area = {2, 2, 2, 2};
918     res = screenSession->UpdateAvailableArea(area);
919     ASSERT_EQ(res, true);
920     GTEST_LOG_(INFO) << "UpdateAvailableArea end";
921 }
922 
923 /**
924  * @tc.name: SetAvailableArea
925  * @tc.desc: normal function
926  * @tc.type: FUNC
927  */
HWTEST_F(ScreenSessionTest, SetAvailableArea, Function | SmallTest | Level2)928 HWTEST_F(ScreenSessionTest, SetAvailableArea, Function | SmallTest | Level2)
929 {
930     GTEST_LOG_(INFO) << "SetAvailableArea start";
931     ScreenSessionConfig config = {
932         .screenId = 100,
933         .rsId = 101,
934         .name = "OpenHarmony",
935     };
936     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
937     EXPECT_NE(nullptr, screenSession);
938     DMRect area = {2, 2, 2, 2};
939     screenSession->SetAvailableArea(area);
940     GTEST_LOG_(INFO) << "SetAvailableArea end";
941 }
942 
943 /**
944  * @tc.name: GetAvailableArea
945  * @tc.desc: normal function
946  * @tc.type: FUNC
947  */
HWTEST_F(ScreenSessionTest, GetAvailableArea, Function | SmallTest | Level2)948 HWTEST_F(ScreenSessionTest, GetAvailableArea, Function | SmallTest | Level2)
949 {
950     GTEST_LOG_(INFO) << "GetAvailableArea start";
951     ScreenSessionConfig config = {
952         .screenId = 100,
953         .rsId = 101,
954         .name = "OpenHarmony",
955     };
956     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
957     EXPECT_NE(nullptr, screenSession);
958     DMRect area = {2, 2, 2, 2};
959     screenSession->SetAvailableArea(area);
960     auto res = screenSession->GetAvailableArea();
961     ASSERT_EQ(res, area);
962     GTEST_LOG_(INFO) << "GetAvailableArea end";
963 }
964 
965 /**
966  * @tc.name: SetFoldScreen
967  * @tc.desc: normal function
968  * @tc.type: FUNC
969  */
HWTEST_F(ScreenSessionTest, SetFoldScreen, Function | SmallTest | Level2)970 HWTEST_F(ScreenSessionTest, SetFoldScreen, Function | SmallTest | Level2)
971 {
972     GTEST_LOG_(INFO) << "SetFoldScreen start";
973     ScreenSessionConfig config = {
974         .screenId = 100,
975         .rsId = 101,
976         .name = "OpenHarmony",
977     };
978     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
979     EXPECT_NE(nullptr, screenSession);
980     bool isFold = false;
981     screenSession->SetFoldScreen(isFold);
982     GTEST_LOG_(INFO) << "SetFoldScreen end";
983 }
984 
985 /**
986  * @tc.name: SetHdrFormats
987  * @tc.desc: normal function
988  * @tc.type: FUNC
989  */
HWTEST_F(ScreenSessionTest, SetHdrFormats, Function | SmallTest | Level2)990 HWTEST_F(ScreenSessionTest, SetHdrFormats, Function | SmallTest | Level2)
991 {
992     GTEST_LOG_(INFO) << "SetHdrFormats start";
993     ScreenSessionConfig config = {
994         .screenId = 100,
995         .rsId = 101,
996         .name = "OpenHarmony",
997     };
998     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
999     EXPECT_NE(nullptr, screenSession);
1000     std::vector<uint32_t> hdrFormats = { 0, 0, 0, 0 };
1001     screenSession->SetHdrFormats(std::move(hdrFormats));
1002     GTEST_LOG_(INFO) << "SetHdrFormats end";
1003 }
1004 
1005 /**
1006  * @tc.name: SetColorSpaces
1007  * @tc.desc: normal function
1008  * @tc.type: FUNC
1009  */
HWTEST_F(ScreenSessionTest, SetColorSpaces, Function | SmallTest | Level2)1010 HWTEST_F(ScreenSessionTest, SetColorSpaces, Function | SmallTest | Level2)
1011 {
1012     GTEST_LOG_(INFO) << "SetColorSpaces start";
1013     ScreenSessionConfig config = {
1014         .screenId = 100,
1015         .rsId = 101,
1016         .name = "OpenHarmony",
1017     };
1018     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
1019     EXPECT_NE(nullptr, screenSession);
1020     std::vector<uint32_t> colorSpaces = { 0, 0, 0, 0 };
1021     screenSession->SetColorSpaces(std::move(colorSpaces));
1022     GTEST_LOG_(INFO) << "SetColorSpaces end";
1023 }
1024 
1025 /**
1026  * @tc.name: SetDisplayNodeScreenId
1027  * @tc.desc: normal function
1028  * @tc.type: FUNC
1029  */
HWTEST_F(ScreenSessionTest, SetDisplayNodeScreenId, Function | SmallTest | Level2)1030 HWTEST_F(ScreenSessionTest, SetDisplayNodeScreenId, Function | SmallTest | Level2)
1031 {
1032     GTEST_LOG_(INFO) << "ScreenSessionTest: SetDisplayNodeScreenId start";
1033     ScreenId screenId = 0;
1034     ScreenId rsId = 1;
1035     std::string name = "OpenHarmony";
1036     ScreenProperty property;
1037     RSDisplayNodeConfig displayNodeConfig;
1038     std::shared_ptr<RSDisplayNode> displayNode = RSDisplayNode::Create(displayNodeConfig);
1039     EXPECT_NE(nullptr, displayNode);
1040     sptr<ScreenSession> session = new(std::nothrow) ScreenSession(screenId, rsId, name, property, displayNode);
1041     session->SetDisplayNodeScreenId(screenId);
1042     GTEST_LOG_(INFO) << "ScreenSessionTest: SetDisplayNodeScreenId end";
1043 }
1044 
1045 /**
1046  * @tc.name: UnregisterScreenChangeListener
1047  * @tc.desc: normal function
1048  * @tc.type: FUNC
1049  */
HWTEST_F(ScreenSessionTest, UnregisterScreenChangeListener, Function | SmallTest | Level2)1050 HWTEST_F(ScreenSessionTest, UnregisterScreenChangeListener, Function | SmallTest | Level2)
1051 {
1052     GTEST_LOG_(INFO) << "ScreenSessionTest: UnregisterScreenChangeListener start";
1053     IScreenChangeListener* screenChangeListener = nullptr;
1054     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1055     int64_t ret = 0;
1056     session->UnregisterScreenChangeListener(screenChangeListener);
1057     ASSERT_EQ(ret, 0);
1058     GTEST_LOG_(INFO) << "ScreenSessionTest: UnregisterScreenChangeListener end";
1059 }
1060 
1061 /**
1062  * @tc.name: UnregisterScreenChangeListener02
1063  * @tc.desc: normal function
1064  * @tc.type: FUNC
1065  */
HWTEST_F(ScreenSessionTest, UnregisterScreenChangeListener02, Function | SmallTest | Level2)1066 HWTEST_F(ScreenSessionTest, UnregisterScreenChangeListener02, Function | SmallTest | Level2)
1067 {
1068     GTEST_LOG_(INFO) << "ScreenSessionTest: UnregisterScreenChangeListener02 start";
1069     IScreenChangeListener* screenChangeListener = new ScreenSessionManager();
1070     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1071     int64_t ret = 0;
1072     session->UnregisterScreenChangeListener(screenChangeListener);
1073     ASSERT_EQ(ret, 0);
1074     GTEST_LOG_(INFO) << "ScreenSessionTest: UnregisterScreenChangeListener02 end";
1075 }
1076 
1077 /**
1078  * @tc.name: ConvertToDisplayInfo
1079  * @tc.desc: normal function
1080  * @tc.type: FUNC
1081  */
HWTEST_F(ScreenSessionTest, ConvertToDisplayInfo, Function | SmallTest | Level2)1082 HWTEST_F(ScreenSessionTest, ConvertToDisplayInfo, Function | SmallTest | Level2)
1083 {
1084     GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertToDisplayInfo start";
1085     sptr<DisplayInfo> displayInfo = new(std::nothrow) DisplayInfo();
1086     EXPECT_NE(displayInfo, nullptr);
1087     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1088     EXPECT_NE(nullptr, session->ConvertToDisplayInfo());
1089 
1090     sptr<ScreenInfo> info = new(std::nothrow) ScreenInfo();
1091     EXPECT_NE(info, nullptr);
1092     EXPECT_NE(nullptr, session->ConvertToScreenInfo());
1093     GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertToDisplayInfo end";
1094 }
1095 
1096 /**
1097  * @tc.name: GetScreenSupportedColorGamuts
1098  * @tc.desc: normal function
1099  * @tc.type: FUNC
1100  */
HWTEST_F(ScreenSessionTest, GetScreenSupportedColorGamuts, Function | SmallTest | Level2)1101 HWTEST_F(ScreenSessionTest, GetScreenSupportedColorGamuts, Function | SmallTest | Level2)
1102 {
1103     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenSupportedColorGamuts start";
1104     std::vector<ScreenColorGamut> colorGamuts;
1105     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1106     DMError ret = session->GetScreenSupportedColorGamuts(colorGamuts);
1107     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
1108         ASSERT_EQ(ret, DMError::DM_OK);
1109     } else {
1110         ASSERT_NE(ret, DMError::DM_OK);
1111     }
1112     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenSupportedColorGamuts end";
1113 }
1114 
1115 /**
1116  * @tc.name: GetActiveScreenMode
1117  * @tc.desc: normal function
1118  * @tc.type: FUNC
1119  */
HWTEST_F(ScreenSessionTest, GetActiveScreenMode, Function | SmallTest | Level2)1120 HWTEST_F(ScreenSessionTest, GetActiveScreenMode, Function | SmallTest | Level2)
1121 {
1122     GTEST_LOG_(INFO) << "ScreenSessionTest: GetActiveScreenMode start";
1123     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1124     session->activeIdx_ = -1;
1125     sptr<SupportedScreenModes> mode1 = session->GetActiveScreenMode();
1126     session->GetActiveScreenMode();
1127     ASSERT_EQ(mode1, nullptr);
1128 
1129     session->activeIdx_ = 100;
1130     sptr<SupportedScreenModes> mode2 = session->GetActiveScreenMode();
1131     session->GetActiveScreenMode();
1132     ASSERT_EQ(mode2, nullptr);
1133 
1134     GTEST_LOG_(INFO) << "ScreenSessionTest: GetActiveScreenMode end";
1135 }
1136 
1137 /**
1138  * @tc.name: SetScreenCombination
1139  * @tc.desc: normal function
1140  * @tc.type: FUNC
1141  */
HWTEST_F(ScreenSessionTest, SetScreenCombination, Function | SmallTest | Level2)1142 HWTEST_F(ScreenSessionTest, SetScreenCombination, Function | SmallTest | Level2)
1143 {
1144     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenCombination start";
1145     ScreenId screenId = 2024;
1146     ScreenProperty property;
1147     NodeId nodeId = 0;
1148     ScreenId defaultScreenId = 0;
1149     ScreenCombination combination { ScreenCombination::SCREEN_ALONE };
1150     sptr<ScreenSession> session = new(std::nothrow) ScreenSession(screenId, property, nodeId, defaultScreenId);
1151     session->SetScreenCombination(combination);
1152     EXPECT_NE(session, nullptr);
1153     EXPECT_EQ(combination, session->GetScreenCombination());
1154     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenCombination end";
1155 }
1156 
1157 /**
1158  * @tc.name: GetScreenColorGamut
1159  * @tc.desc: normal function
1160  * @tc.type: FUNC
1161  */
HWTEST_F(ScreenSessionTest, GetScreenColorGamut, Function | SmallTest | Level2)1162 HWTEST_F(ScreenSessionTest, GetScreenColorGamut, Function | SmallTest | Level2)
1163 {
1164     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenColorGamut start";
1165     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1166     ASSERT_NE(session, nullptr);
1167 
1168     ScreenColorGamut colorGamut;
1169     DMError res = session->GetScreenColorGamut(colorGamut);
1170     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
1171         ASSERT_EQ(res, DMError::DM_OK);
1172     } else {
1173         ASSERT_NE(res, DMError::DM_OK);
1174     }
1175     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenColorGamut end";
1176 }
1177 
1178 /**
1179  * @tc.name: SetScreenColorGamut01
1180  * @tc.desc: normal function
1181  * @tc.type: FUNC
1182  */
HWTEST_F(ScreenSessionTest, SetScreenColorGamut01, Function | SmallTest | Level2)1183 HWTEST_F(ScreenSessionTest, SetScreenColorGamut01, Function | SmallTest | Level2)
1184 {
1185     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenColorGamut start";
1186     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1187     ASSERT_NE(session, nullptr);
1188 
1189     int32_t colorGamut = 1;
1190     DMError res = session->SetScreenColorGamut(colorGamut);
1191     ASSERT_EQ(res, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
1192     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenColorGamut end";
1193 }
1194 
1195 /**
1196  * @tc.name: SetScreenColorGamut02
1197  * @tc.desc: normal function
1198  * @tc.type: FUNC
1199  */
HWTEST_F(ScreenSessionTest, SetScreenColorGamut02, Function | SmallTest | Level2)1200 HWTEST_F(ScreenSessionTest, SetScreenColorGamut02, Function | SmallTest | Level2)
1201 {
1202     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenColorGamut start";
1203     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1204     ASSERT_NE(session, nullptr);
1205 
1206     int32_t colorGamut = -1;
1207     DMError res = session->SetScreenColorGamut(colorGamut);
1208     ASSERT_EQ(res, DMError::DM_ERROR_INVALID_PARAM);
1209     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenColorGamut end";
1210 }
1211 
1212 /**
1213  * @tc.name: GetScreenGamutMap
1214  * @tc.desc: normal function
1215  * @tc.type: FUNC
1216  */
HWTEST_F(ScreenSessionTest, GetScreenGamutMap, Function | SmallTest | Level2)1217 HWTEST_F(ScreenSessionTest, GetScreenGamutMap, Function | SmallTest | Level2)
1218 {
1219     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenGamutMap start";
1220     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1221     ASSERT_NE(session, nullptr);
1222 
1223     ScreenGamutMap gamutMap;
1224     DMError res = session->GetScreenGamutMap(gamutMap);
1225     ASSERT_EQ(res, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
1226     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenGamutMap end";
1227 }
1228 
1229 /**
1230  * @tc.name: SetScreenGamutMap
1231  * @tc.desc: normal function
1232  * @tc.type: FUNC
1233  */
HWTEST_F(ScreenSessionTest, SetScreenGamutMap, Function | SmallTest | Level2)1234 HWTEST_F(ScreenSessionTest, SetScreenGamutMap, Function | SmallTest | Level2)
1235 {
1236     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenGamutMap start";
1237     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1238     ASSERT_NE(session, nullptr);
1239     ScreenGamutMap gamutMap = GAMUT_MAP_CONSTANT;
1240     DMError res = session->SetScreenGamutMap(gamutMap);
1241     ASSERT_EQ(res, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
1242 
1243     gamutMap = GAMUT_MAP_HDR_EXTENSION;
1244     res = session->SetScreenGamutMap(gamutMap);
1245     ASSERT_EQ(res, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
1246     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenGamutMap end";
1247 }
1248 
1249 /**
1250  * @tc.name: InitRSDisplayNode
1251  * @tc.desc: normal function
1252  * @tc.type: FUNC
1253  */
HWTEST_F(ScreenSessionTest, InitRSDisplayNode, Function | SmallTest | Level2)1254 HWTEST_F(ScreenSessionTest, InitRSDisplayNode, Function | SmallTest | Level2)
1255 {
1256     GTEST_LOG_(INFO) << "ScreenSessionTest: InitRSDisplayNode start";
1257     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1258     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1259     ASSERT_NE(session, nullptr);
1260     RSDisplayNodeConfig config;
1261     Point startPoint;
1262     int res = 0;
1263     sessionGroup.InitRSDisplayNode(config, startPoint);
1264     ASSERT_EQ(res, 0);
1265     GTEST_LOG_(INFO) << "ScreenSessionTest: InitRSDisplayNode end";
1266 }
1267 
1268 /**
1269  * @tc.name: GetRSDisplayNodeConfig
1270  * @tc.desc: normal function
1271  * @tc.type: FUNC
1272  */
HWTEST_F(ScreenSessionTest, GetRSDisplayNodeConfig, Function | SmallTest | Level2)1273 HWTEST_F(ScreenSessionTest, GetRSDisplayNodeConfig, Function | SmallTest | Level2)
1274 {
1275     GTEST_LOG_(INFO) << "ScreenSessionTest: GetRSDisplayNodeConfig start";
1276     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1277     sptr<ScreenSession> session0 = nullptr;
1278     RSDisplayNodeConfig config = {1};
1279     sptr<ScreenSession> defaultScreenSession;
1280     bool res = sessionGroup.GetRSDisplayNodeConfig(session0, config, defaultScreenSession);
1281     ASSERT_EQ(res, false);
1282 
1283     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1284     sessionGroup.combination_ = ScreenCombination::SCREEN_ALONE;
1285     res = sessionGroup.GetRSDisplayNodeConfig(session, config, defaultScreenSession);
1286     ASSERT_EQ(res, true);
1287 
1288     sessionGroup.combination_ = ScreenCombination::SCREEN_EXPAND;
1289     res = sessionGroup.GetRSDisplayNodeConfig(session, config, defaultScreenSession);
1290     ASSERT_EQ(res, true);
1291 
1292     sessionGroup.combination_ = ScreenCombination::SCREEN_MIRROR;
1293     res = sessionGroup.GetRSDisplayNodeConfig(session, config, defaultScreenSession);
1294     ASSERT_EQ(res, true);
1295     GTEST_LOG_(INFO) << "ScreenSessionTest: GetRSDisplayNodeConfig end";
1296 }
1297 
1298 /**
1299  * @tc.name: AddChild
1300  * @tc.desc: normal function
1301  * @tc.type: FUNC
1302  */
HWTEST_F(ScreenSessionTest, AddChild, Function | SmallTest | Level2)1303 HWTEST_F(ScreenSessionTest, AddChild, Function | SmallTest | Level2)
1304 {
1305     GTEST_LOG_(INFO) << "ScreenSessionTest: AddChild start";
1306     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1307     sptr<ScreenSession> session0 = nullptr;
1308     Point startPoint(0, 0);
1309     sptr<ScreenSession> defaultScreenSession;
1310     bool res = sessionGroup.AddChild(session0, startPoint, defaultScreenSession);
1311     ASSERT_EQ(res, false);
1312 
1313     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1314     res = sessionGroup.AddChild(session, startPoint, defaultScreenSession);
1315     ASSERT_EQ(res, true);
1316     GTEST_LOG_(INFO) << "ScreenSessionTest: AddChild end";
1317 }
1318 
1319 /**
1320  * @tc.name: AddChildren01
1321  * @tc.desc: normal function
1322  * @tc.type: FUNC
1323  */
HWTEST_F(ScreenSessionTest, AddChildren01, Function | SmallTest | Level2)1324 HWTEST_F(ScreenSessionTest, AddChildren01, Function | SmallTest | Level2)
1325 {
1326     GTEST_LOG_(INFO) << "ScreenSessionTest: AddChildren start";
1327     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1328     std::vector<sptr<ScreenSession>> smsScreens;
1329     std::vector<Point> startPoints;
1330     bool res = sessionGroup.AddChildren(smsScreens, startPoints);
1331     ASSERT_EQ(res, true);
1332     GTEST_LOG_(INFO) << "ScreenSessionTest: AddChildren end";
1333 }
1334 
1335 /**
1336  * @tc.name: AddChildren02
1337  * @tc.desc: normal function
1338  * @tc.type: FUNC
1339  */
HWTEST_F(ScreenSessionTest, AddChildren02, Function | SmallTest | Level2)1340 HWTEST_F(ScreenSessionTest, AddChildren02, Function | SmallTest | Level2)
1341 {
1342     GTEST_LOG_(INFO) << "ScreenSessionTest: AddChildren start";
1343     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1344     std::vector<sptr<ScreenSession>> smsScreens(2);
1345     std::vector<Point> startPoints(1);
1346     bool res = sessionGroup.AddChildren(smsScreens, startPoints);
1347     ASSERT_EQ(res, false);
1348     GTEST_LOG_(INFO) << "ScreenSessionTest: AddChildren end";
1349 }
1350 
1351 /**
1352  * @tc.name: RemoveChild
1353  * @tc.desc: normal function
1354  * @tc.type: FUNC
1355  */
HWTEST_F(ScreenSessionTest, RemoveChild, Function | SmallTest | Level2)1356 HWTEST_F(ScreenSessionTest, RemoveChild, Function | SmallTest | Level2)
1357 {
1358     GTEST_LOG_(INFO) << "ScreenSessionTest: RemoveChild start";
1359     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1360     sptr<ScreenSession> session0 = nullptr;
1361     bool res = sessionGroup.RemoveChild(session0);
1362     ASSERT_EQ(res, false);
1363 
1364     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1365     res = sessionGroup.RemoveChild(session);
1366     ASSERT_EQ(res, false);
1367     GTEST_LOG_(INFO) << "ScreenSessionTest: GetRSDisplayNodeConfig end";
1368 }
1369 
1370 /**
1371  * @tc.name: GetChildPosition
1372  * @tc.desc: normal function
1373  * @tc.type: FUNC
1374  */
HWTEST_F(ScreenSessionTest, GetChildPosition, Function | SmallTest | Level2)1375 HWTEST_F(ScreenSessionTest, GetChildPosition, Function | SmallTest | Level2)
1376 {
1377     GTEST_LOG_(INFO) << "ScreenSessionTest: GetChildPosition start";
1378     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1379     ScreenId screenId = 1;
1380     Point res = sessionGroup.GetChildPosition(screenId);
1381     ASSERT_EQ(res.posX_, 0);
1382     GTEST_LOG_(INFO) << "ScreenSessionTest: GetChildPosition end";
1383 }
1384 
1385 /**
1386  * @tc.name: ConvertToScreenGroupInfo
1387  * @tc.desc: normal function
1388  * @tc.type: FUNC
1389  */
HWTEST_F(ScreenSessionTest, ConvertToScreenGroupInfo, Function | SmallTest | Level2)1390 HWTEST_F(ScreenSessionTest, ConvertToScreenGroupInfo, Function | SmallTest | Level2)
1391 {
1392     GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertToScreenGroupInfo start";
1393     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1394     sptr<ScreenGroupInfo> res = sessionGroup.ConvertToScreenGroupInfo();
1395     ASSERT_NE(res, nullptr);
1396     GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertToScreenGroupInfo end";
1397 }
1398 
1399 /**
1400  * @tc.name: RegisterScreenChangeListener
1401  * @tc.desc: normal function
1402  * @tc.type: FUNC
1403  */
HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener01, Function | SmallTest | Level2)1404 HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener01, Function | SmallTest | Level2)
1405 {
1406     GTEST_LOG_(INFO) << "ScreenSessionTest: RegisterScreenChangeListener start";
1407     int res = 0;
1408     IScreenChangeListener* screenChangeListener = nullptr;
1409     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1410     session->RegisterScreenChangeListener(screenChangeListener);
1411     ASSERT_EQ(res, 0);
1412     GTEST_LOG_(INFO) << "ScreenSessionTest: RegisterScreenChangeListener end";
1413 }
1414 
1415 /**
1416  * @tc.name: RegisterScreenChangeListener
1417  * @tc.desc: Repeat to register
1418  * @tc.type: FUNC
1419  */
HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener02, Function | SmallTest | Level2)1420 HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener02, Function | SmallTest | Level2)
1421 {
1422     GTEST_LOG_(INFO) << "ScreenSessionTest: RegisterScreenChangeListener start";
1423     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
1424     IScreenChangeListener* screenChangeListener1 = new MockScreenChangeListener();
1425     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1426     session->RegisterScreenChangeListener(screenChangeListener);
1427     session->RegisterScreenChangeListener(screenChangeListener1);
1428     ASSERT_FALSE(session->isFold_);
1429 }
1430 
1431 /**
1432  * @tc.name: RegisterScreenChangeListener
1433  * @tc.desc: screenState_ == ScreenState::CONNECTION
1434  * @tc.type: FUNC
1435  */
HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener03, Function | SmallTest | Level2)1436 HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener03, Function | SmallTest | Level2)
1437 {
1438     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1439     ASSERT_EQ(session->screenState_, ScreenState::INIT);
1440     session->screenState_ = ScreenState::CONNECTION;
1441     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
1442     session->RegisterScreenChangeListener(screenChangeListener);
1443     ASSERT_FALSE(session->isFold_);
1444     session->screenState_ = ScreenState::INIT;
1445 }
1446 
1447 /**
1448  * @tc.name: Connect
1449  * @tc.desc: Connect
1450  * @tc.type: FUNC
1451  */
HWTEST_F(ScreenSessionTest, Connect, Function | SmallTest | Level2)1452 HWTEST_F(ScreenSessionTest, Connect, Function | SmallTest | Level2)
1453 {
1454     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
1455     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1456     session->RegisterScreenChangeListener(screenChangeListener);
1457     session->Connect();
1458     ASSERT_FALSE(session->isFold_);
1459 }
1460 
1461 /**
1462  * @tc.name: UpdatePropertyByActiveMode
1463  * @tc.desc: normal function
1464  * @tc.type: FUNC
1465  */
HWTEST_F(ScreenSessionTest, UpdatePropertyByActiveMode, Function | SmallTest | Level2)1466 HWTEST_F(ScreenSessionTest, UpdatePropertyByActiveMode, Function | SmallTest | Level2)
1467 {
1468     GTEST_LOG_(INFO) << "ScreenSessionTest: UpdatePropertyByActiveMode start";
1469     int res = 0;
1470     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1471     session->UpdatePropertyByActiveMode();
1472     ASSERT_EQ(res, 0);
1473     GTEST_LOG_(INFO) << "ScreenSessionTest: UpdatePropertyByActiveMode end";
1474 }
1475 
1476 /**
1477  * @tc.name: Disconnect
1478  * @tc.desc: normal function
1479  * @tc.type: FUNC
1480  */
HWTEST_F(ScreenSessionTest, Disconnect, Function | SmallTest | Level2)1481 HWTEST_F(ScreenSessionTest, Disconnect, Function | SmallTest | Level2)
1482 {
1483     GTEST_LOG_(INFO) << "ScreenSessionTest: Disconnect start";
1484     int res = 0;
1485     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1486     session->Disconnect();
1487     ASSERT_EQ(res, 0);
1488     GTEST_LOG_(INFO) << "ScreenSessionTest: Disconnect end";
1489 }
1490 
1491 /**
1492  * @tc.name: Disconnect
1493  * @tc.desc: !listener
1494  * @tc.type: FUNC
1495  */
HWTEST_F(ScreenSessionTest, Disconnect02, Function | SmallTest | Level2)1496 HWTEST_F(ScreenSessionTest, Disconnect02, Function | SmallTest | Level2)
1497 {
1498     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
1499     IScreenChangeListener* screenChangeListener1 = new MockScreenChangeListener();
1500     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1501     sptr<ScreenSession> session1 = new(std::nothrow) ScreenSession();
1502     session->RegisterScreenChangeListener(screenChangeListener);
1503     session1->RegisterScreenChangeListener(screenChangeListener1);
1504     session1->Connect();
1505     session1->Disconnect();
1506     ASSERT_FALSE(session->isFold_);
1507 }
1508 
1509 /**
1510  * @tc.name: SensorRotationChange
1511  * @tc.desc: normal function
1512  * @tc.type: FUNC
1513  */
HWTEST_F(ScreenSessionTest, SensorRotationChange01, Function | SmallTest | Level2)1514 HWTEST_F(ScreenSessionTest, SensorRotationChange01, Function | SmallTest | Level2)
1515 {
1516     GTEST_LOG_(INFO) << "ScreenSessionTest: SensorRotationChange start";
1517     int res = 0;
1518     Rotation sensorRotation = Rotation::ROTATION_0;
1519     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1520     session->SensorRotationChange(sensorRotation);
1521     ASSERT_EQ(res, 0);
1522     GTEST_LOG_(INFO) << "ScreenSessionTest: SensorRotationChange end";
1523 }
1524 
1525 /**
1526  * @tc.name: SensorRotationChange
1527  * @tc.desc: run in for
1528  * @tc.type: FUNC
1529  */
HWTEST_F(ScreenSessionTest, SensorRotationChange02, Function | SmallTest | Level2)1530 HWTEST_F(ScreenSessionTest, SensorRotationChange02, Function | SmallTest | Level2)
1531 {
1532     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
1533     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1534     session->RegisterScreenChangeListener(screenChangeListener);
1535     Rotation sensorRotation = Rotation::ROTATION_90;
1536     session->SensorRotationChange(sensorRotation);
1537     ASSERT_FALSE(session->isFold_);
1538 }
1539 
1540 /**
1541  * @tc.name: SetOrientation
1542  * @tc.desc: normal function
1543  * @tc.type: FUNC
1544  */
HWTEST_F(ScreenSessionTest, SetOrientation, Function | SmallTest | Level2)1545 HWTEST_F(ScreenSessionTest, SetOrientation, Function | SmallTest | Level2)
1546 {
1547     GTEST_LOG_(INFO) << "ScreenSessionTest: SetOrientation start";
1548     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1549     Orientation orientation = Orientation::UNSPECIFIED;
1550     session->SetOrientation(orientation);
1551     Orientation res = session->GetOrientation();
1552     ASSERT_EQ(res, orientation);
1553     GTEST_LOG_(INFO) << "ScreenSessionTest: SetOrientation end";
1554 }
1555 
1556 /**
1557  * @tc.name: SetScreenRequestedOrientation
1558  * @tc.desc: normal function
1559  * @tc.type: FUNC
1560  */
HWTEST_F(ScreenSessionTest, SetScreenRequestedOrientation, Function | SmallTest | Level2)1561 HWTEST_F(ScreenSessionTest, SetScreenRequestedOrientation, Function | SmallTest | Level2)
1562 {
1563     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation start";
1564     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1565     Orientation orientation = Orientation::UNSPECIFIED;
1566     session->SetScreenRequestedOrientation(orientation);
1567     Orientation res = session->GetScreenRequestedOrientation();
1568     ASSERT_EQ(res, orientation);
1569     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation end";
1570 }
1571 
1572 /**
1573  * @tc.name: SetUpdateToInputManagerCallback
1574  * @tc.desc: normal function
1575  * @tc.type: FUNC
1576  */
HWTEST_F(ScreenSessionTest, SetUpdateToInputManagerCallback, Function | SmallTest | Level2)1577 HWTEST_F(ScreenSessionTest, SetUpdateToInputManagerCallback, Function | SmallTest | Level2)
1578 {
1579     GTEST_LOG_(INFO) << "ScreenSessionTest: SetUpdateToInputManagerCallback start";
1580     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1581     auto func = [session](float x) {
1582         session->SetVirtualPixelRatio(x);
1583     };
1584     session->SetUpdateToInputManagerCallback(func);
1585     EXPECT_NE(nullptr, &func);
1586 
1587     ScreenProperty screenPropert = session->GetScreenProperty();
1588     EXPECT_NE(nullptr, &screenPropert);
1589     session->SetVirtualPixelRatio(3.14);
1590 
1591     ScreenType screenType { ScreenType::REAL };
1592     session->SetScreenType(screenType);
1593 
1594     GTEST_LOG_(INFO) << "ScreenSessionTest: SetUpdateToInputManagerCallbackend";
1595 }
1596 /**
1597  * @tc.name: SetScreenRotationLocked
1598  * @tc.desc: normal function
1599  * @tc.type: FUNC
1600  */
HWTEST_F(ScreenSessionTest, SetScreenRotationLocked, Function | SmallTest | Level2)1601 HWTEST_F(ScreenSessionTest, SetScreenRotationLocked, Function | SmallTest | Level2)
1602 {
1603     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLocked start";
1604     bool isLocked = true;
1605     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1606     session->SetScreenRotationLocked(isLocked);
1607     bool res = session->IsScreenRotationLocked();
1608     ASSERT_EQ(res, isLocked);
1609     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLocked end";
1610 }
1611 
1612 /**
1613  * @tc.name: SetScreenRotationLockedFromJs
1614  * @tc.desc: normal function
1615  * @tc.type: FUNC
1616  */
HWTEST_F(ScreenSessionTest, SetScreenRotationLockedFromJs, Function | SmallTest | Level2)1617 HWTEST_F(ScreenSessionTest, SetScreenRotationLockedFromJs, Function | SmallTest | Level2)
1618 {
1619     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLockedFromJs start";
1620     bool isLocked = true;
1621     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1622     session->SetScreenRotationLockedFromJs(isLocked);
1623     bool res = session->IsScreenRotationLocked();
1624     ASSERT_EQ(res, isLocked);
1625     GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLockedFromJs end";
1626 }
1627 
1628 /**
1629  * @tc.name: IsScreenRotationLocked
1630  * @tc.desc: normal function
1631  * @tc.type: FUNC
1632  */
HWTEST_F(ScreenSessionTest, IsScreenRotationLocked, Function | SmallTest | Level2)1633 HWTEST_F(ScreenSessionTest, IsScreenRotationLocked, Function | SmallTest | Level2)
1634 {
1635     GTEST_LOG_(INFO) << "ScreenSessionTest: IsScreenRotationLocked start";
1636     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1637     bool res = session->IsScreenRotationLocked();
1638     ASSERT_EQ(res, session->isScreenLocked_);
1639     GTEST_LOG_(INFO) << "ScreenSessionTest: IsScreenRotationLocked end";
1640 }
1641 
1642 /**
1643  * @tc.name: GetScreenRequestedOrientation
1644  * @tc.desc: normal function
1645  * @tc.type: FUNC
1646  */
HWTEST_F(ScreenSessionTest, GetScreenRequestedOrientation, Function | SmallTest | Level2)1647 HWTEST_F(ScreenSessionTest, GetScreenRequestedOrientation, Function | SmallTest | Level2)
1648 {
1649     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenRequestedOrientation start";
1650     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1651     Orientation res = session->GetScreenRequestedOrientation();
1652     ASSERT_EQ(res, session->property_.GetScreenRequestedOrientation());
1653     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenRequestedOrientation end";
1654 }
1655 
1656 /**
1657  * @tc.name: SetVirtualPixelRatio
1658  * @tc.desc: normal function
1659  * @tc.type: FUNC
1660  */
HWTEST_F(ScreenSessionTest, SetVirtualPixelRatio, Function | SmallTest | Level2)1661 HWTEST_F(ScreenSessionTest, SetVirtualPixelRatio, Function | SmallTest | Level2)
1662 {
1663     GTEST_LOG_(INFO) << "ScreenSessionTest: SetVirtualPixelRatio start";
1664     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1665     float virtualPixelRatio = 1;
1666     session->SetVirtualPixelRatio(virtualPixelRatio);
1667     float res = session->property_.GetVirtualPixelRatio();
1668     ASSERT_EQ(res, virtualPixelRatio);
1669     GTEST_LOG_(INFO) << "ScreenSessionTest: SetVirtualPixelRatio end";
1670 }
1671 
1672 /**
1673  * @tc.name: screen_session_test001
1674  * @tc.desc: normal function
1675  * @tc.type: FUNC
1676  */
HWTEST_F(ScreenSessionTest, screen_session_test001, Function | SmallTest | Level2)1677 HWTEST_F(ScreenSessionTest, screen_session_test001, Function | SmallTest | Level2)
1678 {
1679     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test001 start";
1680     IScreenChangeListener* screenChangeListener = nullptr;
1681     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1682     session->screenState_ = ScreenState::CONNECTION;
1683     int res = 0;
1684     session->RegisterScreenChangeListener(screenChangeListener);
1685     ASSERT_EQ(res, 0);
1686     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test001 end";
1687 }
1688 
1689 /**
1690  * @tc.name: screen_session_test002
1691  * @tc.desc: normal function
1692  * @tc.type: FUNC
1693  */
HWTEST_F(ScreenSessionTest, screen_session_test002, Function | SmallTest | Level2)1694 HWTEST_F(ScreenSessionTest, screen_session_test002, Function | SmallTest | Level2)
1695 {
1696     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test002 start";
1697     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1698     ScreenId res = session->GetScreenId();
1699     ASSERT_EQ(res, session->screenId_);
1700     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test002 end";
1701 }
1702 
1703 /**
1704  * @tc.name: screen_session_test003
1705  * @tc.desc: normal function
1706  * @tc.type: FUNC
1707  */
HWTEST_F(ScreenSessionTest, screen_session_test003, Function | SmallTest | Level2)1708 HWTEST_F(ScreenSessionTest, screen_session_test003, Function | SmallTest | Level2)
1709 {
1710     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test003 start";
1711     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1712     DMError res = session->SetScreenColorTransform();
1713     ASSERT_EQ(res, DMError::DM_OK);
1714     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test003 end";
1715 }
1716 
1717 /**
1718  * @tc.name: screen_session_test004
1719  * @tc.desc: normal function
1720  * @tc.type: FUNC
1721  */
HWTEST_F(ScreenSessionTest, screen_session_test004, Function | SmallTest | Level2)1722 HWTEST_F(ScreenSessionTest, screen_session_test004, Function | SmallTest | Level2)
1723 {
1724     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test004 start";
1725     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1726     ScreenProperty newProperty;
1727     int res = 0;
1728     session->UpdatePropertyByFoldControl(newProperty);
1729     ASSERT_EQ(res, 0);
1730     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test004 end";
1731 }
1732 
1733 /**
1734  * @tc.name: screen_session_test005
1735  * @tc.desc: normal function
1736  * @tc.type: FUNC
1737  */
HWTEST_F(ScreenSessionTest, screen_session_test005, Function | SmallTest | Level2)1738 HWTEST_F(ScreenSessionTest, screen_session_test005, Function | SmallTest | Level2)
1739 {
1740     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test005 start";
1741     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1742     ScreenProperty newProperty;
1743     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::CHANGE_MODE;
1744     int res = 0;
1745     session->PropertyChange(newProperty, reason);
1746     ASSERT_EQ(res, 0);
1747     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test005 end";
1748 }
1749 
1750 /**
1751  * @tc.name: screen_session_test006
1752  * @tc.desc: normal function
1753  * @tc.type: FUNC
1754  */
HWTEST_F(ScreenSessionTest, screen_session_test006, Function | SmallTest | Level2)1755 HWTEST_F(ScreenSessionTest, screen_session_test006, Function | SmallTest | Level2)
1756 {
1757     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test006 start";
1758     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1759     Rotation sensorRotation = Rotation::ROTATION_90;
1760     float res = session->ConvertRotationToFloat(sensorRotation);
1761     ASSERT_EQ(res, 90.f);
1762     sensorRotation = Rotation::ROTATION_180;
1763     res = session->ConvertRotationToFloat(sensorRotation);
1764     ASSERT_EQ(res, 180.f);
1765     sensorRotation = Rotation::ROTATION_270;
1766     res = session->ConvertRotationToFloat(sensorRotation);
1767     ASSERT_EQ(res, 270.f);
1768     sensorRotation = Rotation::ROTATION_0;
1769     res = session->ConvertRotationToFloat(sensorRotation);
1770     ASSERT_EQ(res, 0.f);
1771     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test006 end";
1772 }
1773 
1774 /**
1775  * @tc.name: screen_session_test007
1776  * @tc.desc: normal function
1777  * @tc.type: FUNC
1778  */
HWTEST_F(ScreenSessionTest, screen_session_test007, Function | SmallTest | Level2)1779 HWTEST_F(ScreenSessionTest, screen_session_test007, Function | SmallTest | Level2)
1780 {
1781     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test007 start";
1782     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1783     Orientation orientation = Orientation::UNSPECIFIED;
1784     int res = 0;
1785     session->ScreenOrientationChange(orientation, FoldDisplayMode::UNKNOWN);
1786     ASSERT_EQ(res, 0);
1787     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test007 end";
1788 }
1789 
1790 /**
1791  * @tc.name: screen_session_test008
1792  * @tc.desc: normal function
1793  * @tc.type: FUNC
1794  */
HWTEST_F(ScreenSessionTest, screen_session_test008, Function | SmallTest | Level2)1795 HWTEST_F(ScreenSessionTest, screen_session_test008, Function | SmallTest | Level2)
1796 {
1797     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test008 start";
1798     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1799     bool res = session->HasPrivateSessionForeground();
1800     ASSERT_EQ(res, false);
1801     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test008 end";
1802 }
1803 
1804 /**
1805  * @tc.name: screen_session_test009
1806  * @tc.desc: normal function
1807  * @tc.type: FUNC
1808  */
HWTEST_F(ScreenSessionTest, screen_session_test009, Function | SmallTest | Level2)1809 HWTEST_F(ScreenSessionTest, screen_session_test009, Function | SmallTest | Level2)
1810 {
1811     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test009 start";
1812     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1813     Rotation rotation = Rotation::ROTATION_90;
1814     session->SetRotation(rotation);
1815     Rotation res = session->GetRotation();
1816     ASSERT_EQ(res, rotation);
1817     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test009 end";
1818 }
1819 
1820 /**
1821  * @tc.name: screen_session_test010
1822  * @tc.desc: normal function
1823  * @tc.type: FUNC
1824  */
HWTEST_F(ScreenSessionTest, screen_session_test010, Function | SmallTest | Level2)1825 HWTEST_F(ScreenSessionTest, screen_session_test010, Function | SmallTest | Level2)
1826 {
1827     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test010 start";
1828     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1829     ScreenId childScreen = 1;
1830     bool res = sessionGroup.HasChild(childScreen);
1831     ASSERT_EQ(res, false);
1832     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test010 end";
1833 }
1834 
1835 /**
1836  * @tc.name: screen_session_test011
1837  * @tc.desc: normal function
1838  * @tc.type: FUNC
1839  */
HWTEST_F(ScreenSessionTest, screen_session_test011, Function | SmallTest | Level2)1840 HWTEST_F(ScreenSessionTest, screen_session_test011, Function | SmallTest | Level2)
1841 {
1842     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test011 start";
1843     ScreenSessionGroup sessionGroup(1, 1, "create", ScreenCombination::SCREEN_ALONE);
1844     std::vector<sptr<ScreenSession>> res = sessionGroup.GetChildren();
1845     ASSERT_EQ(res.empty(), true);
1846     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test011 end";
1847 }
1848 
1849 /**
1850  * @tc.name: screen_session_test012
1851  * @tc.desc: normal function
1852  * @tc.type: FUNC
1853  */
HWTEST_F(ScreenSessionTest, screen_session_test012, Function | SmallTest | Level2)1854 HWTEST_F(ScreenSessionTest, screen_session_test012, Function | SmallTest | Level2)
1855 {
1856     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test012 start";
1857     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1858     int res = 0;
1859     RectF rect = RectF(0, 0, 0, 0);
1860     uint32_t offsetY = 0;
1861     session->SetDisplayBoundary(rect, offsetY);
1862     ASSERT_EQ(res, 0);
1863     GTEST_LOG_(INFO) << "ScreenSessionTest: screen_session_test012 end";
1864 }
1865 
1866 /**
1867  * @tc.name: GetName
1868  * @tc.desc: normal function
1869  * @tc.type: FUNC
1870  */
HWTEST_F(ScreenSessionTest, GetName, Function | SmallTest | Level2)1871 HWTEST_F(ScreenSessionTest, GetName, Function | SmallTest | Level2)
1872 {
1873     GTEST_LOG_(INFO) << "ScreenSessionTest: GetName start";
1874     std::string name { "UNKNOW" };
1875     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1876     ASSERT_EQ(name, session->GetName());
1877     GTEST_LOG_(INFO) << "ScreenSessionTest: GetName end";
1878 }
1879 
1880 /**
1881  * @tc.name: SetName
1882  * @tc.desc: normal function
1883  * @tc.type: FUNC
1884  */
HWTEST_F(ScreenSessionTest, SetName, Function | SmallTest | Level2)1885 HWTEST_F(ScreenSessionTest, SetName, Function | SmallTest | Level2)
1886 {
1887     GTEST_LOG_(INFO) << "ScreenSessionTest: SetName start";
1888     std::string name { "UNKNOWN" };
1889     int ret = 0;
1890     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1891     session->SetName(name);
1892     ASSERT_EQ(ret, 0);
1893     GTEST_LOG_(INFO) << "ScreenSessionTest: SetName end";
1894 }
1895 
1896 /**
1897  * @tc.name: GetScreenSnapshot
1898  * @tc.desc: normal function
1899  * @tc.type: FUNC
1900  */
HWTEST_F(ScreenSessionTest, GetScreenSnapshot, Function | SmallTest | Level2)1901 HWTEST_F(ScreenSessionTest, GetScreenSnapshot, Function | SmallTest | Level2)
1902 {
1903     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenSnapshot start";
1904     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1905     session->displayNode_ = nullptr;
1906     auto pixelmap = session->GetScreenSnapshot(1.0, 1.0);
1907     EXPECT_EQ(pixelmap, nullptr);
1908 
1909     ScreenProperty newScreenProperty;
1910     session = new(std::nothrow) ScreenSession(0, newScreenProperty, 0);
1911     pixelmap = session->GetScreenSnapshot(1.0, 1.0);
1912     int ret = 0;
1913     ASSERT_EQ(ret, 0);
1914     GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenSnapshot end";
1915 }
1916 
1917 /**
1918  * @tc.name: GetRSScreenId
1919  * @tc.desc: normal function
1920  * @tc.type: FUNC
1921  */
HWTEST_F(ScreenSessionTest, GetRSScreenId, Function | SmallTest | Level2)1922 HWTEST_F(ScreenSessionTest, GetRSScreenId, Function | SmallTest | Level2)
1923 {
1924     GTEST_LOG_(INFO) << "ScreenSessionTest: GetRSScreenId start";
1925     ScreenProperty property;
1926     sptr<ScreenSession> session = new(std::nothrow)
1927         ScreenSession("OpenHarmony", 1, 100, 0);
1928     EXPECT_EQ(100, session->GetRSScreenId());
1929 
1930     RSDisplayNodeConfig displayNodeConfig;
1931     std::shared_ptr<RSDisplayNode> displayNode = RSDisplayNode::Create(displayNodeConfig);
1932     session = new ScreenSession(1, 100, "OpenHarmony",
1933         property, displayNode);
1934     EXPECT_NE(nullptr, session->GetDisplayNode());
1935     session->ReleaseDisplayNode();
1936     EXPECT_EQ(nullptr, session->GetDisplayNode());
1937     GTEST_LOG_(INFO) << "ScreenSessionTest: GetRSScreenId end";
1938 }
1939 
1940 /**
1941  * @tc.name: CalcRotation01
1942  * @tc.desc: normal function
1943  * @tc.type: FUNC
1944  */
HWTEST_F(ScreenSessionTest, CalcRotation01, Function | SmallTest | Level2)1945 HWTEST_F(ScreenSessionTest, CalcRotation01, Function | SmallTest | Level2)
1946 {
1947     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start";
1948     Orientation orientation { Orientation::BEGIN };
1949     FoldDisplayMode foldDisplayMode { FoldDisplayMode::COORDINATION };
1950     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
1951     session->activeIdx_ = -1;
1952     auto res = session->CalcRotation(orientation, foldDisplayMode);
1953     EXPECT_EQ(Rotation::ROTATION_0, res);
1954 
1955     sptr<SupportedScreenModes> supportedScreenModes = new SupportedScreenModes;
1956     supportedScreenModes->width_ = 40;
1957     supportedScreenModes->height_ = 20;
1958     session->modes_ = { supportedScreenModes };
1959     session->activeIdx_ = 0;
1960 
1961     orientation = Orientation::UNSPECIFIED;
1962     res = session->CalcRotation(orientation, foldDisplayMode);
1963     EXPECT_EQ(Rotation::ROTATION_0, res);
1964 
1965     orientation = Orientation::VERTICAL;
1966     res = session->CalcRotation(orientation, foldDisplayMode);
1967     if (ScreenSessionManager::GetInstance().IsFoldable()) {
1968         EXPECT_EQ(Rotation::ROTATION_0, res);
1969     } else {
1970         EXPECT_EQ(Rotation::ROTATION_90, res);
1971     }
1972 
1973     orientation = Orientation::HORIZONTAL;
1974     res = session->CalcRotation(orientation, foldDisplayMode);
1975     if (ScreenSessionManager::GetInstance().IsFoldable()) {
1976         EXPECT_EQ(Rotation::ROTATION_90, res);
1977     } else {
1978         EXPECT_EQ(Rotation::ROTATION_0, res);
1979     }
1980 
1981     orientation = Orientation::REVERSE_VERTICAL;
1982     res = session->CalcRotation(orientation, foldDisplayMode);
1983     if (ScreenSessionManager::GetInstance().IsFoldable()) {
1984         EXPECT_EQ(Rotation::ROTATION_180, res);
1985     } else {
1986         EXPECT_EQ(Rotation::ROTATION_270, res);
1987     }
1988 
1989     orientation = Orientation::REVERSE_HORIZONTAL;
1990     res = session->CalcRotation(orientation, foldDisplayMode);
1991     if (ScreenSessionManager::GetInstance().IsFoldable()) {
1992         EXPECT_EQ(Rotation::ROTATION_270, res);
1993     } else {
1994         EXPECT_EQ(Rotation::ROTATION_180, res);
1995     }
1996 
1997     orientation = Orientation::LOCKED;
1998     res = session->CalcRotation(orientation, foldDisplayMode);
1999     EXPECT_EQ(Rotation::ROTATION_0, res);
2000 
2001     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end";
2002 }
2003 
2004 /**
2005  * @tc.name: CalcRotation02
2006  * @tc.desc: normal function
2007  * @tc.type: FUNC
2008  */
HWTEST_F(ScreenSessionTest, CalcRotation02, Function | SmallTest | Level2)2009 HWTEST_F(ScreenSessionTest, CalcRotation02, Function | SmallTest | Level2)
2010 {
2011     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start";
2012     Orientation orientation { Orientation::BEGIN };
2013     FoldDisplayMode foldDisplayMode { FoldDisplayMode::UNKNOWN };
2014     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2015     session->activeIdx_ = -1;
2016     auto res = session->CalcRotation(orientation, foldDisplayMode);
2017     EXPECT_EQ(Rotation::ROTATION_0, res);
2018 
2019     sptr<SupportedScreenModes> supportedScreenModes = new SupportedScreenModes;
2020     supportedScreenModes->width_ = 40;
2021     supportedScreenModes->height_ = 20;
2022     session->modes_ = { supportedScreenModes };
2023     session->activeIdx_ = 0;
2024 
2025     orientation = Orientation::UNSPECIFIED;
2026     res = session->CalcRotation(orientation, foldDisplayMode);
2027     EXPECT_EQ(Rotation::ROTATION_0, res);
2028 
2029     orientation = Orientation::VERTICAL;
2030     res = session->CalcRotation(orientation, foldDisplayMode);
2031     EXPECT_EQ(Rotation::ROTATION_90, res);
2032 
2033     orientation = Orientation::HORIZONTAL;
2034     res = session->CalcRotation(orientation, foldDisplayMode);
2035     EXPECT_EQ(Rotation::ROTATION_0, res);
2036 
2037     orientation = Orientation::REVERSE_VERTICAL;
2038     res = session->CalcRotation(orientation, foldDisplayMode);
2039     EXPECT_EQ(Rotation::ROTATION_270, res);
2040 
2041     orientation = Orientation::REVERSE_HORIZONTAL;
2042     res = session->CalcRotation(orientation, foldDisplayMode);
2043     EXPECT_EQ(Rotation::ROTATION_180, res);
2044 
2045     orientation = Orientation::LOCKED;
2046     res = session->CalcRotation(orientation, foldDisplayMode);
2047     EXPECT_EQ(Rotation::ROTATION_0, res);
2048 
2049     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end";
2050 }
2051 
2052 /**
2053  * @tc.name: CalcDisplayOrientation01
2054  * @tc.desc: normal function
2055  * @tc.type: FUNC
2056  */
HWTEST_F(ScreenSessionTest, CalcDisplayOrientation01, Function | SmallTest | Level2)2057 HWTEST_F(ScreenSessionTest, CalcDisplayOrientation01, Function | SmallTest | Level2)
2058 {
2059     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcDisplayOrientation start";
2060     Rotation rotation { Rotation::ROTATION_0 };
2061     FoldDisplayMode foldDisplayMode { FoldDisplayMode::COORDINATION };
2062     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2063     session->activeIdx_ = -1;
2064     auto res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2065     EXPECT_EQ(DisplayOrientation::LANDSCAPE, res);
2066 
2067     sptr<SupportedScreenModes> supportedScreenModes = new SupportedScreenModes;
2068     supportedScreenModes->width_ = 40;
2069     supportedScreenModes->height_ = 20;
2070     session->modes_ = { supportedScreenModes };
2071     session->activeIdx_ = 0;
2072 
2073     rotation = Rotation::ROTATION_0;
2074     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2075     EXPECT_EQ(DisplayOrientation::LANDSCAPE, res);
2076 
2077     rotation = Rotation::ROTATION_90;
2078     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2079     EXPECT_EQ(DisplayOrientation::PORTRAIT, res);
2080 
2081     rotation = Rotation::ROTATION_180;
2082     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2083     EXPECT_EQ(DisplayOrientation::LANDSCAPE_INVERTED, res);
2084 
2085     rotation = Rotation::ROTATION_270;
2086     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2087     EXPECT_EQ(DisplayOrientation::PORTRAIT_INVERTED, res);
2088 
2089     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcDisplayOrientation end";
2090 }
2091 
2092 /**
2093  * @tc.name: CalcDisplayOrientation02
2094  * @tc.desc: normal function
2095  * @tc.type: FUNC
2096  */
HWTEST_F(ScreenSessionTest, CalcDisplayOrientation02, Function | SmallTest | Level2)2097 HWTEST_F(ScreenSessionTest, CalcDisplayOrientation02, Function | SmallTest | Level2)
2098 {
2099     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcDisplayOrientation start";
2100     Rotation rotation { Rotation::ROTATION_0 };
2101     FoldDisplayMode foldDisplayMode { FoldDisplayMode::UNKNOWN };
2102     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2103     session->activeIdx_ = -1;
2104     auto res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2105     EXPECT_EQ(DisplayOrientation::LANDSCAPE, res);
2106 
2107     sptr<SupportedScreenModes> supportedScreenModes = new SupportedScreenModes;
2108     supportedScreenModes->width_ = 40;
2109     supportedScreenModes->height_ = 20;
2110     session->modes_ = { supportedScreenModes };
2111     session->activeIdx_ = 0;
2112 
2113     rotation = Rotation::ROTATION_0;
2114     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2115     EXPECT_EQ(DisplayOrientation::LANDSCAPE, res);
2116 
2117     rotation = Rotation::ROTATION_90;
2118     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2119     EXPECT_EQ(DisplayOrientation::PORTRAIT, res);
2120 
2121     rotation = Rotation::ROTATION_180;
2122     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2123     EXPECT_EQ(DisplayOrientation::LANDSCAPE_INVERTED, res);
2124 
2125     rotation = Rotation::ROTATION_270;
2126     res = session->CalcDisplayOrientation(rotation, foldDisplayMode);
2127     EXPECT_EQ(DisplayOrientation::PORTRAIT_INVERTED, res);
2128 
2129     GTEST_LOG_(INFO) << "ScreenSessionTest: CalcDisplayOrientation end";
2130 }
2131 
2132 /**
2133  * @tc.name: FillScreenInfo
2134  * @tc.desc: normal function
2135  * @tc.type: FUNC
2136  */
HWTEST_F(ScreenSessionTest, FillScreenInfo, Function | SmallTest | Level2)2137 HWTEST_F(ScreenSessionTest, FillScreenInfo, Function | SmallTest | Level2)
2138 {
2139     GTEST_LOG_(INFO) << "ScreenSessionTest: FillScreenInfo start";
2140     ScreenProperty property;
2141     property.SetVirtualPixelRatio(3.1415927);
2142     sptr<ScreenSession> session = new(std::nothrow) ScreenSession(2024, property, 0);
2143     sptr<ScreenInfo> info = nullptr;
2144     session->FillScreenInfo(info);
2145 
2146     sptr<SupportedScreenModes> supportedScreenModes = new SupportedScreenModes;
2147     session->modes_ = { supportedScreenModes };
2148     supportedScreenModes->width_ = 40;
2149     supportedScreenModes->height_ = 20;
2150     info = new ScreenInfo;
2151     session->FillScreenInfo(info);
2152     EXPECT_NE(nullptr, info);
2153     GTEST_LOG_(INFO) << "ScreenSessionTest: FillScreenInfo end";
2154 }
2155 
2156 /**
2157  * @tc.name: PropertyChange
2158  * @tc.desc: normal function
2159  * @tc.type: FUNC
2160  */
HWTEST_F(ScreenSessionTest, PropertyChange, Function | SmallTest | Level2)2161 HWTEST_F(ScreenSessionTest, PropertyChange, Function | SmallTest | Level2)
2162 {
2163     GTEST_LOG_(INFO) << "ScreenSessionTest: PropertyChange start";
2164     int res = 0;
2165     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2166     ScreenProperty newProperty;
2167     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::CHANGE_MODE;
2168     session->PropertyChange(newProperty, reason);
2169     ASSERT_EQ(res, 0);
2170     GTEST_LOG_(INFO) << "ScreenSessionTest: PropertyChange end";
2171 }
2172 
2173 /**
2174  * @tc.name: PowerStatusChange
2175  * @tc.desc: normal function
2176  * @tc.type: FUNC
2177  */
HWTEST_F(ScreenSessionTest, PowerStatusChange, Function | SmallTest | Level2)2178 HWTEST_F(ScreenSessionTest, PowerStatusChange, Function | SmallTest | Level2)
2179 {
2180     GTEST_LOG_(INFO) << "ScreenSessionTest: PowerStatusChange start";
2181     int res = 0;
2182     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2183     DisplayPowerEvent event = DisplayPowerEvent::DISPLAY_ON;
2184     EventStatus status = EventStatus::BEGIN;
2185     PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
2186     session->PowerStatusChange(event, status, reason);
2187     ASSERT_EQ(res, 0);
2188     GTEST_LOG_(INFO) << "ScreenSessionTest: PowerStatusChange end";
2189 }
2190 
2191 /**
2192  * @tc.name: SetScreenScale
2193  * @tc.desc: SetScreenScale test
2194  * @tc.type: FUNC
2195 */
HWTEST_F(ScreenSessionTest, SetScreenScale, Function | SmallTest | Level2)2196 HWTEST_F(ScreenSessionTest, SetScreenScale, Function | SmallTest | Level2)
2197 {
2198     ScreenSession session;
2199     float scaleX = 1.0f;
2200     float scaleY = 1.0f;
2201     float pivotX = 0.5f;
2202     float pivotY = 0.5f;
2203     float translateX = 0.0f;
2204     float translateY = 0.0f;
2205     session.SetScreenScale(scaleX, scaleY, pivotX, pivotY, translateX, translateY);
2206     EXPECT_EQ(session.property_.GetScaleX(), scaleX);
2207     EXPECT_EQ(session.property_.GetScaleY(), scaleY);
2208     EXPECT_EQ(session.property_.GetPivotX(), pivotX);
2209     EXPECT_EQ(session.property_.GetPivotY(), pivotY);
2210     EXPECT_EQ(session.property_.GetTranslateX(), translateX);
2211     EXPECT_EQ(session.property_.GetTranslateY(), translateY);
2212 }
2213 
2214 /**
2215  * @tc.name: HoverStatusChange01
2216  * @tc.desc: normal function
2217  * @tc.type: FUNC
2218  */
HWTEST_F(ScreenSessionTest, HoverStatusChange01, Function | SmallTest | Level2)2219 HWTEST_F(ScreenSessionTest, HoverStatusChange01, Function | SmallTest | Level2)
2220 {
2221     GTEST_LOG_(INFO) << "HoverStatusChange start";
2222     ScreenSessionConfig config = {
2223         .screenId = 100,
2224         .rsId = 101,
2225         .name = "OpenHarmony",
2226     };
2227     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
2228     EXPECT_NE(nullptr, screenSession);
2229     int32_t HoverStatus = 0;
2230     screenSession->HoverStatusChange(HoverStatus);
2231     GTEST_LOG_(INFO) << "HoverStatusChange end";
2232 }
2233 
2234 /**
2235  * @tc.name: HoverStatusChange02
2236  * @tc.desc: run in for
2237  * @tc.type: FUNC
2238  */
HWTEST_F(ScreenSessionTest, HoverStatusChange02, Function | SmallTest | Level2)2239 HWTEST_F(ScreenSessionTest, HoverStatusChange02, Function | SmallTest | Level2)
2240 {
2241     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
2242     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2243     EXPECT_NE(nullptr, session);
2244     session->RegisterScreenChangeListener(screenChangeListener);
2245     int32_t hoverStatus = 0;
2246     session->HoverStatusChange(hoverStatus);
2247 }
2248 
2249 /**
2250  * @tc.name: HandleHoverStatusChange01
2251  * @tc.desc: run in for
2252  * @tc.type: FUNC
2253  */
HWTEST_F(ScreenSessionTest, HandleHoverStatusChange01, Function | SmallTest | Level2)2254 HWTEST_F(ScreenSessionTest, HandleHoverStatusChange01, Function | SmallTest | Level2)
2255 {
2256     IScreenChangeListener* screenChangeListener = new MockScreenChangeListener();
2257     sptr<ScreenSession> session = new(std::nothrow) ScreenSession();
2258     EXPECT_NE(nullptr, session);
2259     session->RegisterScreenChangeListener(screenChangeListener);
2260     int32_t hoverStatus = 0;
2261     session->HandleHoverStatusChange(hoverStatus);
2262 }
2263 } // namespace
2264 } // namespace Rosen
2265 } // namespace OHOS
2266