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