1 /*
2 * Copyright (C) 2022 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 <cstdint>
17 #include <gtest/gtest.h>
18 #include "accessible_ability_client_proxy.h"
19 #include "accessibility_account_data.h"
20 #include "accessibility_errorcode.h"
21 #include "accessibility_event_info.h"
22 #include "accessible_ability_channel_stub.h"
23 #include "accessible_ability_connection.h"
24 #include "accessible_ability_manager_service.h"
25 #include "parcel.h"
26
27 namespace OHOS {
28 namespace Accessibility {
29 int g_testChannalId = -1;
30 int g_testEventType = -1;
31 int g_testWindowChangeTypes = -1;
32 int g_testWindowId = -1;
33 int g_testGesture = -1;
34 int g_testKeyPressEvent = -1;
35 int g_testDisplayId = -1;
36 int g_testGestureSimulateResult = -1;
37 OHOS::sptr<OHOS::Accessibility::IAccessibleAbilityChannel> g_testStub = nullptr;
38 int g_testGestureSimulate = -1;
39
40 std::vector<EventType> g_mTeventType;
41 int g_mTgestureId = -1;
42
AccessibleAbilityClientProxy(const sptr<IRemoteObject> & object)43 AccessibleAbilityClientProxy::AccessibleAbilityClientProxy(const sptr<IRemoteObject> &object)
44 : IRemoteProxy<IAccessibleAbilityClient>(object)
45 {
46 }
47
WriteInterfaceToken(MessageParcel & data)48 bool AccessibleAbilityClientProxy::WriteInterfaceToken(MessageParcel &data)
49 {
50 return true;
51 }
52
Init(const sptr<IAccessibleAbilityChannel> & channel,const int channelId)53 void AccessibleAbilityClientProxy::Init(const sptr<IAccessibleAbilityChannel> &channel, const int channelId)
54 {
55 g_testStub = channel;
56 g_testChannalId = channelId;
57 }
58
Disconnect(const int channelId)59 void AccessibleAbilityClientProxy::Disconnect(const int channelId)
60 {
61 }
62
OnAccessibilityEvent(const AccessibilityEventInfo & eventInfo)63 void AccessibleAbilityClientProxy::OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo)
64 {
65 GTEST_LOG_(INFO) << "TouchGuider_Unittest_OnTouchEvent OnAccessibilityEvent";
66 g_testWindowId = eventInfo.GetWindowId();
67 g_testWindowChangeTypes = eventInfo.GetWindowChangeTypes();
68 g_testEventType = int(eventInfo.GetEventType());
69 g_mTgestureId = int(eventInfo.GetGestureType());
70
71 switch (eventInfo.GetEventType()) {
72 case TYPE_TOUCH_GUIDE_GESTURE_BEGIN:
73 case TYPE_TOUCH_GUIDE_GESTURE_END:
74 case TYPE_TOUCH_GUIDE_BEGIN:
75 case TYPE_TOUCH_GUIDE_END:
76 case TYPE_TOUCH_BEGIN:
77 case TYPE_TOUCH_END:
78 break;
79 default:
80 return;
81 }
82 g_mTeventType.push_back(eventInfo.GetEventType());
83 }
84
OnKeyPressEvent(const MMI::KeyEvent & keyEvent,const int sequence)85 void AccessibleAbilityClientProxy::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence)
86 {
87 MessageParcel data;
88 MessageParcel reply;
89 HILOG_DEBUG();
90 HILOG_DEBUG("start.----------sequence--%{public}d ----------mock Proxy Start ", sequence);
91 g_testKeyPressEvent = sequence;
92 HILOG_DEBUG("start.-----------------------------mock Proxy end ");
93 }
94
OnDisplayResized(const int displayId,const Rect & rect,const float scale,const float centerX,const float centerY)95 void AccessibleAbilityClientProxy::OnDisplayResized(const int displayId, const Rect &rect, const float scale,
96 const float centerX, const float centerY)
97 {
98 g_testDisplayId = 1;
99 }
100
OnGestureSimulateResult(const int sequence,const bool completedSuccessfully)101 void AccessibleAbilityClientProxy::OnGestureSimulateResult(const int sequence, const bool completedSuccessfully)
102 {
103 g_testGestureSimulateResult = 1;
104 g_testGestureSimulate = sequence;
105 }
106 } // namespace Accessibility
107 } // namespace OHOS