• 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 <ipc_types.h>
18 #include <pointer_event.h>
19 
20 #include "ability_start_setting.h"
21 #include "iremote_object_mocker.h"
22 #include "mock/mock_session_stub.h"
23 #include "parcel/accessibility_event_info_parcel.h"
24 #include "session/host/include/zidl/session_ipc_interface_code.h"
25 #include "session/host/include/zidl/session_stub.h"
26 #include "want.h"
27 #include "ws_common.h"
28 
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace OHOS {
33 namespace Rosen {
34 namespace {
35 const std::string UNDEFINED = "undefined";
36 }
37 
38 namespace OHOS::Accessibility {
39 class AccessibilityEventInfo;
40 }
41 class SessionStubLayoutTest : public testing::Test {
42 public:
43     static void SetUpTestCase();
44     static void TearDownTestCase();
45     void SetUp() override;
46     void TearDown() override;
47 
48 private:
49     sptr<SessionStub> session_ = nullptr;
50 };
51 
SetUpTestCase()52 void SessionStubLayoutTest::SetUpTestCase() {}
53 
TearDownTestCase()54 void SessionStubLayoutTest::TearDownTestCase() {}
55 
SetUp()56 void SessionStubLayoutTest::SetUp()
57 {
58     session_ = sptr<SessionStubMocker>::MakeSptr();
59 }
60 
TearDown()61 void SessionStubLayoutTest::TearDown()
62 {
63     session_ = nullptr;
64 }
65 
66 namespace {
67 /**
68  * @tc.name: HandleUpdateRectChangeListenerRegistered008
69  * @tc.desc: sessionStub sessionStubTest
70  * @tc.type: FUNC
71  * @tc.require: #I6JLSI
72  */
73 HWTEST_F(SessionStubLayoutTest, HandleUpdateRectChangeListenerRegistered008, TestSize.Level1)
74 {
75     MessageParcel data;
76     MessageParcel reply;
77     data.WriteBool(true);
78     sptr<IRemoteObjectMocker> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
79     auto res = session_->HandleUpdateRectChangeListenerRegistered(data, reply);
80     ASSERT_EQ(ERR_NONE, res);
81 }
82 
83 /**
84  * @tc.name: HandleUpdateSessionRect
85  * @tc.desc: test for HandleUpdateSessionRect
86  * @tc.type: FUNC
87  * @tc.require: #I6JLSI
88  */
89 HWTEST_F(SessionStubLayoutTest, HandleUpdateSessionRect, TestSize.Level1)
90 {
91     MessageParcel data;
92     MessageParcel reply;
93     data.WriteUint32(10);
94     data.WriteUint32(20);
95     data.WriteUint32(30);
96     data.WriteUint32(40);
97     data.WriteUint32(0);
98     data.WriteBool(true);
99     data.WriteBool(true);
100     auto res = session_->HandleUpdateSessionRect(data, reply);
101     ASSERT_EQ(ERR_NONE, res);
102 }
103 
104 /**
105  * @tc.name: HandleUpdateClientRect01
106  * @tc.desc: sessionStub sessionStubTest
107  * @tc.type: FUNC
108  */
109 HWTEST_F(SessionStubLayoutTest, HandleUpdateClientRect01, TestSize.Level1)
110 {
111     MessageParcel data;
112     MessageParcel reply;
113     auto res = session_->HandleUpdateClientRect(data, reply);
114     ASSERT_EQ(ERR_INVALID_DATA, res);
115     data.WriteInt32(100);
116     data.WriteInt32(100);
117     data.WriteInt32(800);
118     data.WriteInt32(800);
119     res = session_->HandleUpdateClientRect(data, reply);
120     ASSERT_EQ(ERR_NONE, res);
121 }
122 
123 /**
124  * @tc.name: HandleSetSystemEnableDrag_TestReadBool
125  * @tc.desc: Check whether the enableDrag is read successfully.
126  * @tc.type: FUNC
127  */
128 HWTEST_F(SessionStubLayoutTest, HandleSetSystemEnableDrag_TestReadBool, TestSize.Level1)
129 {
130     MessageParcel data;
131     MessageParcel reply;
132     auto res = session_->HandleSetSystemEnableDrag(data, reply);
133     ASSERT_EQ(ERR_INVALID_DATA, res);
134 
135     data.WriteBool(true);
136     res = session_->HandleSetSystemEnableDrag(data, reply);
137     ASSERT_EQ(ERR_NONE, res);
138 }
139 
140 /**
141  * @tc.name: HandleGetAppHookWindowInfoFromServer
142  * @tc.desc: HandleGetAppHookWindowInfoFromServer01
143  * @tc.type: FUNC
144  */
145 HWTEST_F(SessionStubLayoutTest, HandleGetAppHookWindowInfoFromServer01, TestSize.Level1)
146 {
147     ASSERT_TRUE(session_ != nullptr);
148     MessageParcel data;
149     MessageParcel reply;
150     MessageOption option = { MessageOption::TF_SYNC };
151     uint32_t code = static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_HOOK_WINDOW_INFO);
152     auto res = session_->ProcessRemoteRequest(code, data, reply, option);
153     EXPECT_EQ(ERR_NONE, res);
154 }
155 
156 /**
157  * @tc.name: HandleGetAppHookWindowInfoFromServer
158  * @tc.desc: HandleGetAppHookWindowInfoFromServer02
159  * @tc.type: FUNC
160  */
161 HWTEST_F(SessionStubLayoutTest, HandleGetAppHookWindowInfoFromServer02, TestSize.Level1)
162 {
163     ASSERT_TRUE(session_ != nullptr);
164     MessageParcel data;
165     MessageParcel reply;
166     auto res = session_->HandleGetAppHookWindowInfoFromServer(data, reply);
167     EXPECT_EQ(res, ERR_NONE);
168 }
169 } // namespace
170 } // namespace Rosen
171 } // namespace OHOS