• 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 {
54 }
55 
TearDownTestCase()56 void SessionStubLayoutTest::TearDownTestCase()
57 {
58 }
59 
SetUp()60 void SessionStubLayoutTest::SetUp()
61 {
62     session_ = sptr<SessionStubMocker>::MakeSptr();
63 }
64 
TearDown()65 void SessionStubLayoutTest::TearDown()
66 {
67     session_ = nullptr;
68 }
69 
70 namespace {
71 /**
72  * @tc.name: HandleUpdateRectChangeListenerRegistered008
73  * @tc.desc: sessionStub sessionStubTest
74  * @tc.type: FUNC
75  * @tc.require: #I6JLSI
76  */
77 HWTEST_F(SessionStubLayoutTest, HandleUpdateRectChangeListenerRegistered008, Function | SmallTest | Level2)
78 {
79     MessageParcel data;
80     MessageParcel reply;
81     data.WriteBool(true);
82     sptr<IRemoteObjectMocker> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
83     auto res = session_->HandleUpdateRectChangeListenerRegistered(data, reply);
84     ASSERT_EQ(ERR_NONE, res);
85 }
86 
87 /**
88  * @tc.name: HandleUpdateSessionRect
89  * @tc.desc: test for HandleUpdateSessionRect
90  * @tc.type: FUNC
91  * @tc.require: #I6JLSI
92  */
93 HWTEST_F(SessionStubLayoutTest, HandleUpdateSessionRect, Function | SmallTest | Level2)
94 {
95     MessageParcel data;
96     MessageParcel reply;
97     data.WriteUint32(10);
98     data.WriteUint32(20);
99     data.WriteUint32(30);
100     data.WriteUint32(40);
101     data.WriteUint32(0);
102     data.WriteBool(true);
103     data.WriteBool(true);
104     auto res = session_->HandleUpdateSessionRect(data, reply);
105     ASSERT_EQ(ERR_INVALID_DATA, res);
106 }
107 
108 /**
109  * @tc.name: HandleUpdateClientRect01
110  * @tc.desc: sessionStub sessionStubTest
111  * @tc.type: FUNC
112  */
113 HWTEST_F(SessionStubLayoutTest, HandleUpdateClientRect01, Function | SmallTest | Level2)
114 {
115     MessageParcel data;
116     MessageParcel reply;
117     auto res = session_->HandleUpdateClientRect(data, reply);
118     ASSERT_EQ(ERR_INVALID_DATA, res);
119     data.WriteInt32(100);
120     data.WriteInt32(100);
121     data.WriteInt32(800);
122     data.WriteInt32(800);
123     res = session_->HandleUpdateClientRect(data, reply);
124     ASSERT_EQ(ERR_NONE, res);
125 }
126 
127 /**
128  * @tc.name: HandleSetSystemEnableDrag_TestReadBool
129  * @tc.desc: Check whether the enableDrag is read successfully.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(SessionStubLayoutTest, HandleSetSystemEnableDrag_TestReadBool, Function | SmallTest | Level2)
133 {
134     MessageParcel data;
135     MessageParcel reply;
136     auto res = session_->HandleSetSystemEnableDrag(data, reply);
137     ASSERT_EQ(ERR_INVALID_DATA, res);
138 
139     data.WriteBool(true);
140     res = session_->HandleSetSystemEnableDrag(data, reply);
141     ASSERT_EQ(ERR_NONE, res);
142 }
143 }
144 } // namespace Rosen
145 } // namespace OHOS