1 /* 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 23 using namespace android::hardware::input; 24 25 namespace android { 26 27 // --- InputClassifierConverterTest --- 28 29 static 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; 41 NotifyMotionArgs motionArgs(1/*sequenceNum*/, downTime/*eventTime*/, 3/*deviceId*/, 42 AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, 4/*policyFlags*/, AMOTION_EVENT_ACTION_DOWN, 43 0/*actionButton*/, 0/*flags*/, AMETA_NONE, 0/*buttonState*/, MotionClassification::NONE, 44 AMOTION_EVENT_EDGE_FLAG_NONE, 5/*deviceTimestamp*/, 45 1/*pointerCount*/, &properties, &coords, 0/*xPrecision*/, 0/*yPrecision*/, 46 downTime, {}/*videoFrames*/); 47 return motionArgs; 48 } 49 50 static float getMotionEventAxis(common::V1_0::PointerCoords coords, 51 common::V1_0::Axis axis) { 52 uint32_t index = BitSet64::getIndexOfBit(static_cast<uint64_t>(coords.bits), 53 static_cast<uint64_t>(axis)); 54 return coords.values[index]; 55 } 56 57 /** 58 * Check that coordinates get converted properly from the framework's PointerCoords 59 * to the hidl PointerCoords in input::common. 60 */ 61 TEST(InputClassifierConverterTest, PointerCoordsAxes) { 62 const NotifyMotionArgs motionArgs = generateBasicMotionArgs(); 63 ASSERT_EQ(1, motionArgs.pointerCoords[0].getX()); 64 ASSERT_EQ(2, motionArgs.pointerCoords[0].getY()); 65 ASSERT_EQ(0.5, motionArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_SIZE)); 66 ASSERT_EQ(3U, BitSet64::count(motionArgs.pointerCoords[0].bits)); 67 68 common::V1_0::MotionEvent motionEvent = notifyMotionArgsToHalMotionEvent(motionArgs); 69 70 ASSERT_EQ(getMotionEventAxis(motionEvent.pointerCoords[0], common::V1_0::Axis::X), 71 motionArgs.pointerCoords[0].getX()); 72 ASSERT_EQ(getMotionEventAxis(motionEvent.pointerCoords[0], common::V1_0::Axis::Y), 73 motionArgs.pointerCoords[0].getY()); 74 ASSERT_EQ(getMotionEventAxis(motionEvent.pointerCoords[0], common::V1_0::Axis::SIZE), 75 motionArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_SIZE)); 76 ASSERT_EQ(BitSet64::count(motionArgs.pointerCoords[0].bits), 77 BitSet64::count(motionEvent.pointerCoords[0].bits)); 78 } 79 80 } // namespace android 81