• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include <gtest/gtest.h>
17 #include "iremote_object_mocker.h"
18 #include "mock/mock_session_stub.h"
19 #include "mock/mock_message_parcel.h"
20 #include "session/host/include/zidl/session_stub.h"
21 #include "parcel/accessibility_event_info_parcel.h"
22 #include "window_manager_hilog.h"
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStubMockTest"};
30 }
31 
32 namespace OHOS::Accessibility {
33 class AccessibilityEventInfo;
34 }
35 class SessionStubMockTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp() override;
40     void TearDown() override;
41 
42 private:
43     sptr<SessionStub> session_ = nullptr;
44 };
45 
SetUpTestCase()46 void SessionStubMockTest::SetUpTestCase()
47 {
48 }
49 
TearDownTestCase()50 void SessionStubMockTest::TearDownTestCase()
51 {
52 }
53 
SetUp()54 void SessionStubMockTest::SetUp()
55 {
56     session_ = sptr<SessionStubMocker>::MakeSptr();
57     EXPECT_NE(nullptr, session_);
58 }
59 
TearDown()60 void SessionStubMockTest::TearDown()
61 {
62     session_ = nullptr;
63 }
64 
65 namespace {
66 /**
67  * @tc.name: HandleTransferAccessibilityEvent
68  * @tc.desc: sessionStub HandleTransferAccessibilityEvent
69  * @tc.type: FUNC
70  * @tc.require: #I6JLSI
71  */
72 HWTEST_F(SessionStubMockTest, HandleTransferAccessibilityEvent, Function | SmallTest | Level2)
73 {
74     WLOGI("HandleTransferAccessibilityEvent begin");
75     MessageParcel data;
76     MessageParcel reply;
77     MessageOption option(MessageOption::TF_ASYNC);
78     Accessibility::AccessibilityEventInfo info;
79     Accessibility::AccessibilityEventInfoParcel infoParcel(info);
80     data.WriteParcelable(&infoParcel);
81     int64_t uiExtensionIdLevel = 0;
82     data.WriteInt64(uiExtensionIdLevel);
83     MockMessageParcel::SetReadInt64ErrorFlag(true);
84     ASSERT_EQ(ERR_INVALID_DATA, session_->HandleTransferAccessibilityEvent(data, reply));
85     MockMessageParcel::ClearAllErrorFlag();
86     WLOGI("HandleTransferAccessibilityEvent end");
87 }
88 
89 /**
90  * @tc.name: HandleTransferAccessibilityEvent
91  * @tc.desc: sessionStub HandleTransferAccessibilityEvent
92  * @tc.type: FUNC
93  * @tc.require: #I6JLSI
94  */
95 HWTEST_F(SessionStubMockTest, HandleTransferAccessibilityEvent01, Function | SmallTest | Level2)
96 {
97     WLOGI("HandleTransferAccessibilityEvent01 begin");
98     MessageParcel data;
99     MessageParcel reply;
100     MessageOption option(MessageOption::TF_ASYNC);
101 
102     Accessibility::AccessibilityEventInfo info;
103     Accessibility::AccessibilityEventInfoParcel infoParcel(info);
104     data.WriteParcelable(&infoParcel);
105 
106     int64_t uiExtensionIdLevel = 0;
107     data.WriteInt64(uiExtensionIdLevel);
108     ASSERT_EQ(ERR_INVALID_DATA, session_->HandleTransferAccessibilityEvent(data, reply));
109     WLOGI("HandleTransferAccessibilityEvent01 end");
110 }
111 }
112 } // namespace Rosen
113 } // namespace OHOS