• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <pointer_event.h>
18 #include <ui/rs_surface_node.h>
19 
20 #include "display_manager.h"
21 #include "input_event.h"
22 #include "key_event.h"
23 #include "mock/mock_session_stage.h"
24 #include "pointer_event.h"
25 #include "session/host/include/main_session.h"
26 #include "session/host/include/scene_session.h"
27 #include "session/host/include/sub_session.h"
28 #include "session/host/include/system_session.h"
29 #include "window_helper.h"
30 #include "wm_common.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 namespace OHOS {
35 namespace Rosen {
36 class SceneSessionLayoutTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp() override;
41     void TearDown() override;
42 
43 private:
44     sptr<SessionStageMocker> mockSessionStage_ = nullptr;
45 };
46 
SetUpTestCase()47 void SceneSessionLayoutTest::SetUpTestCase()
48 {
49 }
50 
TearDownTestCase()51 void SceneSessionLayoutTest::TearDownTestCase()
52 {
53 }
54 
SetUp()55 void SceneSessionLayoutTest::SetUp()
56 {
57     mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
58 }
59 
TearDown()60 void SceneSessionLayoutTest::TearDown()
61 {
62 }
63 
64 namespace {
65 /**
66  * @tc.name: NotifySingleHandTransformChange
67  * @tc.desc: NotifySingleHandTransformChange
68  * @tc.type: FUNC
69  */
70 HWTEST_F(SceneSessionLayoutTest, NotifySingleHandTransformChange, Function | SmallTest | Level2)
71 {
72     SessionInfo info;
73     info.abilityName_ = "NotifySingleHandTransformChange";
74     info.bundleName_ = "NotifySingleHandTransformChange";
75     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
76 
77     SingleHandTransform testTransform;
78     sceneSession->state_ = SessionState::STATE_BACKGROUND;
79     sceneSession->NotifySingleHandTransformChange(testTransform);
80 
81     sceneSession->state_ = SessionState::STATE_FOREGROUND;
82     mockSessionStage_ = nullptr;
83     sceneSession->sessionStage_ = mockSessionStage_;
84     sceneSession->NotifySingleHandTransformChange(testTransform);
85 
86     mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
87     sceneSession->sessionStage_ = mockSessionStage_;
88     sceneSession->NotifySingleHandTransformChange(testTransform);
89     ASSERT_NE(100, testTransform.posX);
90 }
91 
92 /**
93  * @tc.name: GetSessionGlobalRectWithSingleHandScale
94  * @tc.desc: GetSessionGlobalRectWithSingleHandScale
95  * @tc.type: FUNC
96  */
97 HWTEST_F(SceneSessionLayoutTest, GetSessionGlobalRectWithSingleHandScale, Function | SmallTest | Level2)
98 {
99     SessionInfo info;
100     info.abilityName_ = "GetSessionGlobalRectWithSingleHandScale";
101     info.bundleName_ = "GetSessionGlobalRectWithSingleHandScale";
102     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
103 
104     SingleHandTransform testTransform;
105     WSRect globalRect = { 100, 100, 800, 800 };
106     sceneSession->SetSessionGlobalRect(globalRect);
107     sceneSession->SetSingleHandTransform(testTransform);
108     ASSERT_EQ(sceneSession->GetSessionGlobalRect().posX_,
109               sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_);
110 
111     testTransform.posX = 10;
112     testTransform.posY = 10;
113     testTransform.scaleX = 0.75f;
114     testTransform.scaleY = 0.75f;
115     sceneSession->SetSingleHandTransform(testTransform);
116     ASSERT_NE(sceneSession->GetSessionGlobalRect().posX_,
117               sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_);
118 }
119 } // namespace
120 } // Rosen
121 } // OHOS