blob: ba1c7c92849370f347b377e3e57f09e48bd7be16 [file] [log] [blame]
Siarhei Vishniakoua47a4d42019-05-06 17:14:11 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "../InputClassifierConverter.h"
18
19#include <gtest/gtest.h>
20#include <utils/BitSet.h>
21
22
23using namespace android::hardware::input;
24
25namespace android {
26
27// --- InputClassifierConverterTest ---
28
29static NotifyMotionArgs generateBasicMotionArgs() {
30 // Create a basic motion event for testing
31 PointerProperties properties;
32 properties.id = 0;
33 properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
34
35 PointerCoords coords;
36 coords.clear();
37 coords.setAxisValue(AMOTION_EVENT_AXIS_X, 1);
38 coords.setAxisValue(AMOTION_EVENT_AXIS_Y, 2);
39 coords.setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.5);
40 static constexpr nsecs_t downTime = 2;
Garfield Tan00f511d2019-06-12 16:55:40 -070041 NotifyMotionArgs motionArgs(1 /*sequenceNum*/, downTime /*eventTime*/, 3 /*deviceId*/,
42 AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, 4 /*policyFlags*/,
43 AMOTION_EVENT_ACTION_DOWN, 0 /*actionButton*/, 0 /*flags*/,
44 AMETA_NONE, 0 /*buttonState*/, MotionClassification::NONE,
45 AMOTION_EVENT_EDGE_FLAG_NONE, 5 /*deviceTimestamp*/,
46 1 /*pointerCount*/, &properties, &coords, 0 /*xPrecision*/,
47 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION,
48 AMOTION_EVENT_INVALID_CURSOR_POSITION, downTime,
49 {} /*videoFrames*/);
Siarhei Vishniakoua47a4d42019-05-06 17:14:11 -070050 return motionArgs;
51}
52
53static float getMotionEventAxis(common::V1_0::PointerCoords coords,
54 common::V1_0::Axis axis) {
55 uint32_t index = BitSet64::getIndexOfBit(static_cast<uint64_t>(coords.bits),
56 static_cast<uint64_t>(axis));
57 return coords.values[index];
58}
59
60/**
61 * Check that coordinates get converted properly from the framework's PointerCoords
62 * to the hidl PointerCoords in input::common.
63 */
64TEST(InputClassifierConverterTest, PointerCoordsAxes) {
65 const NotifyMotionArgs motionArgs = generateBasicMotionArgs();
66 ASSERT_EQ(1, motionArgs.pointerCoords[0].getX());
67 ASSERT_EQ(2, motionArgs.pointerCoords[0].getY());
68 ASSERT_EQ(0.5, motionArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_SIZE));
69 ASSERT_EQ(3U, BitSet64::count(motionArgs.pointerCoords[0].bits));
70
71 common::V1_0::MotionEvent motionEvent = notifyMotionArgsToHalMotionEvent(motionArgs);
72
73 ASSERT_EQ(getMotionEventAxis(motionEvent.pointerCoords[0], common::V1_0::Axis::X),
74 motionArgs.pointerCoords[0].getX());
75 ASSERT_EQ(getMotionEventAxis(motionEvent.pointerCoords[0], common::V1_0::Axis::Y),
76 motionArgs.pointerCoords[0].getY());
77 ASSERT_EQ(getMotionEventAxis(motionEvent.pointerCoords[0], common::V1_0::Axis::SIZE),
78 motionArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_SIZE));
79 ASSERT_EQ(BitSet64::count(motionArgs.pointerCoords[0].bits),
80 BitSet64::count(motionEvent.pointerCoords[0].bits));
81}
82
83} // namespace android