• 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 
TearDownTestCase()48 void SessionStubMockTest::TearDownTestCase() {}
49 
SetUp()50 void SessionStubMockTest::SetUp()
51 {
52     session_ = sptr<SessionStubMocker>::MakeSptr();
53     EXPECT_NE(nullptr, session_);
54 }
55 
TearDown()56 void SessionStubMockTest::TearDown()
57 {
58     session_ = nullptr;
59 }
60 
61 namespace {
62 /**
63  * @tc.name: HandleTransferAccessibilityEvent
64  * @tc.desc: sessionStub HandleTransferAccessibilityEvent
65  * @tc.type: FUNC
66  * @tc.require: #I6JLSI
67  */
68 HWTEST_F(SessionStubMockTest, HandleTransferAccessibilityEvent, TestSize.Level1)
69 {
70     WLOGI("HandleTransferAccessibilityEvent begin");
71     MessageParcel data;
72     MessageParcel reply;
73     MessageOption option(MessageOption::TF_ASYNC);
74     Accessibility::AccessibilityEventInfo info;
75     Accessibility::AccessibilityEventInfoParcel infoParcel(info);
76     data.WriteParcelable(&infoParcel);
77     int64_t uiExtensionIdLevel = 0;
78     data.WriteInt64(uiExtensionIdLevel);
79     MockMessageParcel::SetReadInt64ErrorFlag(true);
80     ASSERT_EQ(ERR_INVALID_DATA, session_->HandleTransferAccessibilityEvent(data, reply));
81     MockMessageParcel::ClearAllErrorFlag();
82     WLOGI("HandleTransferAccessibilityEvent end");
83 }
84 
85 /**
86  * @tc.name: HandleTransferAccessibilityEvent
87  * @tc.desc: sessionStub HandleTransferAccessibilityEvent
88  * @tc.type: FUNC
89  * @tc.require: #I6JLSI
90  */
91 HWTEST_F(SessionStubMockTest, HandleTransferAccessibilityEvent01, TestSize.Level1)
92 {
93     WLOGI("HandleTransferAccessibilityEvent01 begin");
94     MessageParcel data;
95     MessageParcel reply;
96     MessageOption option(MessageOption::TF_ASYNC);
97 
98     Accessibility::AccessibilityEventInfo info;
99     Accessibility::AccessibilityEventInfoParcel infoParcel(info);
100     data.WriteParcelable(&infoParcel);
101 
102     int64_t uiExtensionIdLevel = 0;
103     data.WriteInt64(uiExtensionIdLevel);
104     ASSERT_EQ(ERR_INVALID_DATA, session_->HandleTransferAccessibilityEvent(data, reply));
105     WLOGI("HandleTransferAccessibilityEvent01 end");
106 }
107 } // namespace
108 } // namespace Rosen
109 } // namespace OHOS