James Dong | 199d1c1 | 2011-03-17 11:48:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | */ |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 16 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 17 | #include "../InputReader.h" |
| 18 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 19 | #include <utils/List.h> |
| 20 | #include <gtest/gtest.h> |
| 21 | #include <math.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | // An arbitrary time value. |
| 26 | static const nsecs_t ARBITRARY_TIME = 1234; |
| 27 | |
| 28 | // Arbitrary display properties. |
| 29 | static const int32_t DISPLAY_ID = 0; |
| 30 | static const int32_t DISPLAY_WIDTH = 480; |
| 31 | static const int32_t DISPLAY_HEIGHT = 800; |
| 32 | |
| 33 | // Error tolerance for floating point assertions. |
| 34 | static const float EPSILON = 0.001f; |
| 35 | |
| 36 | template<typename T> |
| 37 | static inline T min(T a, T b) { |
| 38 | return a < b ? a : b; |
| 39 | } |
| 40 | |
| 41 | static inline float avg(float x, float y) { |
| 42 | return (x + y) / 2; |
| 43 | } |
| 44 | |
| 45 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 46 | // --- FakePointerController --- |
| 47 | |
| 48 | class FakePointerController : public PointerControllerInterface { |
| 49 | bool mHaveBounds; |
| 50 | float mMinX, mMinY, mMaxX, mMaxY; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 51 | float mX, mY; |
| 52 | int32_t mButtonState; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 53 | |
| 54 | protected: |
| 55 | virtual ~FakePointerController() { } |
| 56 | |
| 57 | public: |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 58 | FakePointerController() : |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 59 | mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0), mX(0), mY(0), |
| 60 | mButtonState(0) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void setBounds(float minX, float minY, float maxX, float maxY) { |
| 64 | mHaveBounds = true; |
| 65 | mMinX = minX; |
| 66 | mMinY = minY; |
| 67 | mMaxX = maxX; |
| 68 | mMaxY = maxY; |
| 69 | } |
| 70 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 71 | virtual void setPosition(float x, float y) { |
| 72 | mX = x; |
| 73 | mY = y; |
| 74 | } |
| 75 | |
| 76 | virtual void setButtonState(int32_t buttonState) { |
| 77 | mButtonState = buttonState; |
| 78 | } |
| 79 | |
| 80 | virtual int32_t getButtonState() const { |
| 81 | return mButtonState; |
| 82 | } |
| 83 | |
| 84 | virtual void getPosition(float* outX, float* outY) const { |
| 85 | *outX = mX; |
| 86 | *outY = mY; |
| 87 | } |
| 88 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 89 | private: |
| 90 | virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const { |
| 91 | *outMinX = mMinX; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 92 | *outMinY = mMinY; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 93 | *outMaxX = mMaxX; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 94 | *outMaxY = mMaxY; |
| 95 | return mHaveBounds; |
| 96 | } |
| 97 | |
| 98 | virtual void move(float deltaX, float deltaY) { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 99 | mX += deltaX; |
| 100 | if (mX < mMinX) mX = mMinX; |
| 101 | if (mX > mMaxX) mX = mMaxX; |
| 102 | mY += deltaY; |
| 103 | if (mY < mMinY) mY = mMinY; |
| 104 | if (mY > mMaxY) mY = mMaxY; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 105 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 106 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 107 | virtual void fade(Transition transition) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 110 | virtual void unfade(Transition transition) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 111 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 112 | |
| 113 | virtual void setPresentation(Presentation presentation) { |
| 114 | } |
| 115 | |
Jeff Brown | 9181a5f4 | 2011-06-06 21:04:14 -0700 | [diff] [blame] | 116 | virtual void setSpots(const PointerCoords* spotCoords, |
| 117 | const uint32_t* spotIdToIndex, BitSet32 spotIdBits) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | virtual void clearSpots() { |
| 121 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 125 | // --- FakeInputReaderPolicy --- |
| 126 | |
| 127 | class FakeInputReaderPolicy : public InputReaderPolicyInterface { |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 128 | InputReaderConfiguration mConfig; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 129 | KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 130 | Vector<InputDeviceInfo> mInputDevices; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 131 | |
| 132 | protected: |
| 133 | virtual ~FakeInputReaderPolicy() { } |
| 134 | |
| 135 | public: |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 136 | FakeInputReaderPolicy() { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 139 | void setDisplayInfo(int32_t displayId, int32_t width, int32_t height, int32_t orientation) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 140 | // Set the size of both the internal and external display at the same time. |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 141 | bool isRotated = (orientation == DISPLAY_ORIENTATION_90 |
| 142 | || orientation == DISPLAY_ORIENTATION_270); |
| 143 | DisplayViewport v; |
| 144 | v.displayId = displayId; |
| 145 | v.orientation = orientation; |
| 146 | v.logicalLeft = 0; |
| 147 | v.logicalTop = 0; |
| 148 | v.logicalRight = isRotated ? height : width; |
| 149 | v.logicalBottom = isRotated ? width : height; |
| 150 | v.physicalLeft = 0; |
| 151 | v.physicalTop = 0; |
| 152 | v.physicalRight = isRotated ? height : width; |
| 153 | v.physicalBottom = isRotated ? width : height; |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 154 | v.deviceWidth = isRotated ? height : width; |
| 155 | v.deviceHeight = isRotated ? width : height; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 156 | mConfig.setDisplayInfo(false /*external*/, v); |
| 157 | mConfig.setDisplayInfo(true /*external*/, v); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 160 | void addExcludedDeviceName(const String8& deviceName) { |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 161 | mConfig.excludedDeviceNames.push(deviceName); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 164 | void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) { |
| 165 | mPointerControllers.add(deviceId, controller); |
| 166 | } |
| 167 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 168 | const InputReaderConfiguration* getReaderConfiguration() const { |
| 169 | return &mConfig; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 172 | const Vector<InputDeviceInfo>& getInputDevices() const { |
| 173 | return mInputDevices; |
| 174 | } |
| 175 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 176 | private: |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 177 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) { |
| 178 | *outConfig = mConfig; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 179 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 180 | |
| 181 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) { |
| 182 | return mPointerControllers.valueFor(deviceId); |
| 183 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 184 | |
| 185 | virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) { |
| 186 | mInputDevices = inputDevices; |
| 187 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 188 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 189 | virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 190 | return NULL; |
| 191 | } |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 192 | |
| 193 | virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) { |
| 194 | return String8::empty(); |
| 195 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 199 | // --- FakeInputListener --- |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 200 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 201 | class FakeInputListener : public InputListenerInterface { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 202 | private: |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 203 | List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgsQueue; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 204 | List<NotifyDeviceResetArgs> mNotifyDeviceResetArgsQueue; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 205 | List<NotifyKeyArgs> mNotifyKeyArgsQueue; |
| 206 | List<NotifyMotionArgs> mNotifyMotionArgsQueue; |
| 207 | List<NotifySwitchArgs> mNotifySwitchArgsQueue; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 208 | |
| 209 | protected: |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 210 | virtual ~FakeInputListener() { } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 211 | |
| 212 | public: |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 213 | FakeInputListener() { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 216 | void assertNotifyConfigurationChangedWasCalled( |
| 217 | NotifyConfigurationChangedArgs* outEventArgs = NULL) { |
| 218 | ASSERT_FALSE(mNotifyConfigurationChangedArgsQueue.empty()) |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 219 | << "Expected notifyConfigurationChanged() to have been called."; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 220 | if (outEventArgs) { |
| 221 | *outEventArgs = *mNotifyConfigurationChangedArgsQueue.begin(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 222 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 223 | mNotifyConfigurationChangedArgsQueue.erase(mNotifyConfigurationChangedArgsQueue.begin()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 226 | void assertNotifyDeviceResetWasCalled( |
| 227 | NotifyDeviceResetArgs* outEventArgs = NULL) { |
| 228 | ASSERT_FALSE(mNotifyDeviceResetArgsQueue.empty()) |
| 229 | << "Expected notifyDeviceReset() to have been called."; |
| 230 | if (outEventArgs) { |
| 231 | *outEventArgs = *mNotifyDeviceResetArgsQueue.begin(); |
| 232 | } |
| 233 | mNotifyDeviceResetArgsQueue.erase(mNotifyDeviceResetArgsQueue.begin()); |
| 234 | } |
| 235 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 236 | void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = NULL) { |
| 237 | ASSERT_FALSE(mNotifyKeyArgsQueue.empty()) |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 238 | << "Expected notifyKey() to have been called."; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 239 | if (outEventArgs) { |
| 240 | *outEventArgs = *mNotifyKeyArgsQueue.begin(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 241 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 242 | mNotifyKeyArgsQueue.erase(mNotifyKeyArgsQueue.begin()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void assertNotifyKeyWasNotCalled() { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 246 | ASSERT_TRUE(mNotifyKeyArgsQueue.empty()) |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 247 | << "Expected notifyKey() to not have been called."; |
| 248 | } |
| 249 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 250 | void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = NULL) { |
| 251 | ASSERT_FALSE(mNotifyMotionArgsQueue.empty()) |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 252 | << "Expected notifyMotion() to have been called."; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 253 | if (outEventArgs) { |
| 254 | *outEventArgs = *mNotifyMotionArgsQueue.begin(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 255 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 256 | mNotifyMotionArgsQueue.erase(mNotifyMotionArgsQueue.begin()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void assertNotifyMotionWasNotCalled() { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 260 | ASSERT_TRUE(mNotifyMotionArgsQueue.empty()) |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 261 | << "Expected notifyMotion() to not have been called."; |
| 262 | } |
| 263 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 264 | void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = NULL) { |
| 265 | ASSERT_FALSE(mNotifySwitchArgsQueue.empty()) |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 266 | << "Expected notifySwitch() to have been called."; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 267 | if (outEventArgs) { |
| 268 | *outEventArgs = *mNotifySwitchArgsQueue.begin(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 269 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 270 | mNotifySwitchArgsQueue.erase(mNotifySwitchArgsQueue.begin()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | private: |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 274 | virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { |
| 275 | mNotifyConfigurationChangedArgsQueue.push_back(*args); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 278 | virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) { |
| 279 | mNotifyDeviceResetArgsQueue.push_back(*args); |
| 280 | } |
| 281 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 282 | virtual void notifyKey(const NotifyKeyArgs* args) { |
| 283 | mNotifyKeyArgsQueue.push_back(*args); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 286 | virtual void notifyMotion(const NotifyMotionArgs* args) { |
| 287 | mNotifyMotionArgsQueue.push_back(*args); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 290 | virtual void notifySwitch(const NotifySwitchArgs* args) { |
| 291 | mNotifySwitchArgsQueue.push_back(*args); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 292 | } |
| 293 | }; |
| 294 | |
| 295 | |
| 296 | // --- FakeEventHub --- |
| 297 | |
| 298 | class FakeEventHub : public EventHubInterface { |
| 299 | struct KeyInfo { |
| 300 | int32_t keyCode; |
| 301 | uint32_t flags; |
| 302 | }; |
| 303 | |
| 304 | struct Device { |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 305 | InputDeviceIdentifier identifier; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 306 | uint32_t classes; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 307 | PropertyMap configuration; |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 308 | KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes; |
| 309 | KeyedVector<int, bool> relativeAxes; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 310 | KeyedVector<int32_t, int32_t> keyCodeStates; |
| 311 | KeyedVector<int32_t, int32_t> scanCodeStates; |
| 312 | KeyedVector<int32_t, int32_t> switchStates; |
Jeff Brown | 2717eff | 2011-06-30 23:53:07 -0700 | [diff] [blame] | 313 | KeyedVector<int32_t, int32_t> absoluteAxisValue; |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 314 | KeyedVector<int32_t, KeyInfo> keysByScanCode; |
| 315 | KeyedVector<int32_t, KeyInfo> keysByUsageCode; |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 316 | KeyedVector<int32_t, bool> leds; |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 317 | Vector<VirtualKeyDefinition> virtualKeys; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 318 | |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 319 | Device(uint32_t classes) : |
| 320 | classes(classes) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 321 | } |
| 322 | }; |
| 323 | |
| 324 | KeyedVector<int32_t, Device*> mDevices; |
| 325 | Vector<String8> mExcludedDevices; |
| 326 | List<RawEvent> mEvents; |
| 327 | |
| 328 | protected: |
| 329 | virtual ~FakeEventHub() { |
| 330 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 331 | delete mDevices.valueAt(i); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | public: |
| 336 | FakeEventHub() { } |
| 337 | |
| 338 | void addDevice(int32_t deviceId, const String8& name, uint32_t classes) { |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 339 | Device* device = new Device(classes); |
| 340 | device->identifier.name = name; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 341 | mDevices.add(deviceId, device); |
| 342 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 343 | enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void removeDevice(int32_t deviceId) { |
| 347 | delete mDevices.valueFor(deviceId); |
| 348 | mDevices.removeItem(deviceId); |
| 349 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 350 | enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void finishDeviceScan() { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 354 | enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 357 | void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) { |
| 358 | Device* device = getDevice(deviceId); |
| 359 | device->configuration.addProperty(key, value); |
| 360 | } |
| 361 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 362 | void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) { |
| 363 | Device* device = getDevice(deviceId); |
| 364 | device->configuration.addAll(configuration); |
| 365 | } |
| 366 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 367 | void addAbsoluteAxis(int32_t deviceId, int axis, |
Jeff Brown | b3a2d13 | 2011-06-12 18:14:50 -0700 | [diff] [blame] | 368 | int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 369 | Device* device = getDevice(deviceId); |
| 370 | |
| 371 | RawAbsoluteAxisInfo info; |
| 372 | info.valid = true; |
| 373 | info.minValue = minValue; |
| 374 | info.maxValue = maxValue; |
| 375 | info.flat = flat; |
| 376 | info.fuzz = fuzz; |
Jeff Brown | b3a2d13 | 2011-06-12 18:14:50 -0700 | [diff] [blame] | 377 | info.resolution = resolution; |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 378 | device->absoluteAxes.add(axis, info); |
| 379 | } |
| 380 | |
| 381 | void addRelativeAxis(int32_t deviceId, int32_t axis) { |
| 382 | Device* device = getDevice(deviceId); |
| 383 | device->relativeAxes.add(axis, true); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) { |
| 387 | Device* device = getDevice(deviceId); |
| 388 | device->keyCodeStates.replaceValueFor(keyCode, state); |
| 389 | } |
| 390 | |
| 391 | void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) { |
| 392 | Device* device = getDevice(deviceId); |
| 393 | device->scanCodeStates.replaceValueFor(scanCode, state); |
| 394 | } |
| 395 | |
| 396 | void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) { |
| 397 | Device* device = getDevice(deviceId); |
| 398 | device->switchStates.replaceValueFor(switchCode, state); |
| 399 | } |
| 400 | |
Jeff Brown | 2717eff | 2011-06-30 23:53:07 -0700 | [diff] [blame] | 401 | void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) { |
| 402 | Device* device = getDevice(deviceId); |
| 403 | device->absoluteAxisValue.replaceValueFor(axis, value); |
| 404 | } |
| 405 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 406 | void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
| 407 | int32_t keyCode, uint32_t flags) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 408 | Device* device = getDevice(deviceId); |
| 409 | KeyInfo info; |
| 410 | info.keyCode = keyCode; |
| 411 | info.flags = flags; |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 412 | if (scanCode) { |
| 413 | device->keysByScanCode.add(scanCode, info); |
| 414 | } |
| 415 | if (usageCode) { |
| 416 | device->keysByUsageCode.add(usageCode, info); |
| 417 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 420 | void addLed(int32_t deviceId, int32_t led, bool initialState) { |
| 421 | Device* device = getDevice(deviceId); |
| 422 | device->leds.add(led, initialState); |
| 423 | } |
| 424 | |
| 425 | bool getLedState(int32_t deviceId, int32_t led) { |
| 426 | Device* device = getDevice(deviceId); |
| 427 | return device->leds.valueFor(led); |
| 428 | } |
| 429 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 430 | Vector<String8>& getExcludedDevices() { |
| 431 | return mExcludedDevices; |
| 432 | } |
| 433 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 434 | void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) { |
| 435 | Device* device = getDevice(deviceId); |
| 436 | device->virtualKeys.push(definition); |
| 437 | } |
| 438 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 439 | void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 440 | int32_t code, int32_t value) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 441 | RawEvent event; |
| 442 | event.when = when; |
| 443 | event.deviceId = deviceId; |
| 444 | event.type = type; |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 445 | event.code = code; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 446 | event.value = value; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 447 | mEvents.push_back(event); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 448 | |
| 449 | if (type == EV_ABS) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 450 | setAbsoluteAxisValue(deviceId, code, value); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 451 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | void assertQueueIsEmpty() { |
| 455 | ASSERT_EQ(size_t(0), mEvents.size()) |
| 456 | << "Expected the event queue to be empty (fully consumed)."; |
| 457 | } |
| 458 | |
| 459 | private: |
| 460 | Device* getDevice(int32_t deviceId) const { |
| 461 | ssize_t index = mDevices.indexOfKey(deviceId); |
| 462 | return index >= 0 ? mDevices.valueAt(index) : NULL; |
| 463 | } |
| 464 | |
| 465 | virtual uint32_t getDeviceClasses(int32_t deviceId) const { |
| 466 | Device* device = getDevice(deviceId); |
| 467 | return device ? device->classes : 0; |
| 468 | } |
| 469 | |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 470 | virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 471 | Device* device = getDevice(deviceId); |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 472 | return device ? device->identifier : InputDeviceIdentifier(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 475 | virtual int32_t getDeviceControllerNumber(int32_t deviceId) const { |
| 476 | return 0; |
| 477 | } |
| 478 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 479 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const { |
| 480 | Device* device = getDevice(deviceId); |
| 481 | if (device) { |
| 482 | *outConfiguration = device->configuration; |
| 483 | } |
| 484 | } |
| 485 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 486 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 487 | RawAbsoluteAxisInfo* outAxisInfo) const { |
| 488 | Device* device = getDevice(deviceId); |
| 489 | if (device) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 490 | ssize_t index = device->absoluteAxes.indexOfKey(axis); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 491 | if (index >= 0) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 492 | *outAxisInfo = device->absoluteAxes.valueAt(index); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 493 | return OK; |
| 494 | } |
| 495 | } |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 496 | outAxisInfo->clear(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 497 | return -1; |
| 498 | } |
| 499 | |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 500 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 501 | Device* device = getDevice(deviceId); |
| 502 | if (device) { |
| 503 | return device->relativeAxes.indexOfKey(axis) >= 0; |
| 504 | } |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 505 | return false; |
| 506 | } |
| 507 | |
Jeff Brown | 80fd47c | 2011-05-24 01:07:44 -0700 | [diff] [blame] | 508 | virtual bool hasInputProperty(int32_t deviceId, int property) const { |
| 509 | return false; |
| 510 | } |
| 511 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 512 | virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 513 | int32_t* outKeycode, uint32_t* outFlags) const { |
| 514 | Device* device = getDevice(deviceId); |
| 515 | if (device) { |
Jeff Brown | cc11698 | 2012-04-12 10:05:41 -0700 | [diff] [blame] | 516 | const KeyInfo* key = getKey(device, scanCode, usageCode); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 517 | if (key) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 518 | if (outKeycode) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 519 | *outKeycode = key->keyCode; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 520 | } |
| 521 | if (outFlags) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 522 | *outFlags = key->flags; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 523 | } |
| 524 | return OK; |
| 525 | } |
| 526 | } |
| 527 | return NAME_NOT_FOUND; |
| 528 | } |
| 529 | |
Jeff Brown | cc11698 | 2012-04-12 10:05:41 -0700 | [diff] [blame] | 530 | const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const { |
| 531 | if (usageCode) { |
| 532 | ssize_t index = device->keysByUsageCode.indexOfKey(usageCode); |
| 533 | if (index >= 0) { |
| 534 | return &device->keysByUsageCode.valueAt(index); |
| 535 | } |
| 536 | } |
| 537 | if (scanCode) { |
| 538 | ssize_t index = device->keysByScanCode.indexOfKey(scanCode); |
| 539 | if (index >= 0) { |
| 540 | return &device->keysByScanCode.valueAt(index); |
| 541 | } |
| 542 | } |
| 543 | return NULL; |
| 544 | } |
| 545 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 546 | virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 547 | AxisInfo* outAxisInfo) const { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 548 | return NAME_NOT_FOUND; |
| 549 | } |
| 550 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 551 | virtual void setExcludedDevices(const Vector<String8>& devices) { |
| 552 | mExcludedDevices = devices; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 555 | virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 556 | if (mEvents.empty()) { |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 557 | return 0; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 560 | *buffer = *mEvents.begin(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 561 | mEvents.erase(mEvents.begin()); |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 562 | return 1; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const { |
| 566 | Device* device = getDevice(deviceId); |
| 567 | if (device) { |
| 568 | ssize_t index = device->scanCodeStates.indexOfKey(scanCode); |
| 569 | if (index >= 0) { |
| 570 | return device->scanCodeStates.valueAt(index); |
| 571 | } |
| 572 | } |
| 573 | return AKEY_STATE_UNKNOWN; |
| 574 | } |
| 575 | |
| 576 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const { |
| 577 | Device* device = getDevice(deviceId); |
| 578 | if (device) { |
| 579 | ssize_t index = device->keyCodeStates.indexOfKey(keyCode); |
| 580 | if (index >= 0) { |
| 581 | return device->keyCodeStates.valueAt(index); |
| 582 | } |
| 583 | } |
| 584 | return AKEY_STATE_UNKNOWN; |
| 585 | } |
| 586 | |
| 587 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const { |
| 588 | Device* device = getDevice(deviceId); |
| 589 | if (device) { |
| 590 | ssize_t index = device->switchStates.indexOfKey(sw); |
| 591 | if (index >= 0) { |
| 592 | return device->switchStates.valueAt(index); |
| 593 | } |
| 594 | } |
| 595 | return AKEY_STATE_UNKNOWN; |
| 596 | } |
| 597 | |
Jeff Brown | 2717eff | 2011-06-30 23:53:07 -0700 | [diff] [blame] | 598 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
| 599 | int32_t* outValue) const { |
| 600 | Device* device = getDevice(deviceId); |
| 601 | if (device) { |
| 602 | ssize_t index = device->absoluteAxisValue.indexOfKey(axis); |
| 603 | if (index >= 0) { |
| 604 | *outValue = device->absoluteAxisValue.valueAt(index); |
| 605 | return OK; |
| 606 | } |
| 607 | } |
| 608 | *outValue = 0; |
| 609 | return -1; |
| 610 | } |
| 611 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 612 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
| 613 | uint8_t* outFlags) const { |
| 614 | bool result = false; |
| 615 | Device* device = getDevice(deviceId); |
| 616 | if (device) { |
| 617 | for (size_t i = 0; i < numCodes; i++) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 618 | for (size_t j = 0; j < device->keysByScanCode.size(); j++) { |
| 619 | if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) { |
| 620 | outFlags[i] = 1; |
| 621 | result = true; |
| 622 | } |
| 623 | } |
| 624 | for (size_t j = 0; j < device->keysByUsageCode.size(); j++) { |
| 625 | if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 626 | outFlags[i] = 1; |
| 627 | result = true; |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | return result; |
| 633 | } |
| 634 | |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 635 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const { |
| 636 | Device* device = getDevice(deviceId); |
| 637 | if (device) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 638 | ssize_t index = device->keysByScanCode.indexOfKey(scanCode); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 639 | return index >= 0; |
| 640 | } |
| 641 | return false; |
| 642 | } |
| 643 | |
Jeff Brown | 7631cbb | 2010-10-24 15:22:06 -0700 | [diff] [blame] | 644 | virtual bool hasLed(int32_t deviceId, int32_t led) const { |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 645 | Device* device = getDevice(deviceId); |
| 646 | return device && device->leds.indexOfKey(led) >= 0; |
Jeff Brown | 7631cbb | 2010-10-24 15:22:06 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) { |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 650 | Device* device = getDevice(deviceId); |
| 651 | if (device) { |
| 652 | ssize_t index = device->leds.indexOfKey(led); |
| 653 | if (index >= 0) { |
| 654 | device->leds.replaceValueAt(led, on); |
| 655 | } else { |
| 656 | ADD_FAILURE() |
| 657 | << "Attempted to set the state of an LED that the EventHub declared " |
| 658 | "was not present. led=" << led; |
| 659 | } |
| 660 | } |
Jeff Brown | 7631cbb | 2010-10-24 15:22:06 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 663 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 664 | Vector<VirtualKeyDefinition>& outVirtualKeys) const { |
| 665 | outVirtualKeys.clear(); |
| 666 | |
| 667 | Device* device = getDevice(deviceId); |
| 668 | if (device) { |
| 669 | outVirtualKeys.appendVector(device->virtualKeys); |
| 670 | } |
| 671 | } |
| 672 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 673 | virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const { |
| 674 | return NULL; |
Jeff Brown | 1e08fe9 | 2011-11-15 17:48:10 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 677 | virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) { |
| 678 | return false; |
| 679 | } |
| 680 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 681 | virtual void vibrate(int32_t deviceId, nsecs_t duration) { |
| 682 | } |
| 683 | |
| 684 | virtual void cancelVibrate(int32_t deviceId) { |
| 685 | } |
| 686 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 687 | virtual bool isExternal(int32_t deviceId) const { |
| 688 | return false; |
| 689 | } |
| 690 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 691 | virtual void dump(String8& dump) { |
| 692 | } |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 693 | |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 694 | virtual void monitor() { |
| 695 | } |
| 696 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 697 | virtual void requestReopenDevices() { |
| 698 | } |
| 699 | |
| 700 | virtual void wake() { |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 701 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 702 | }; |
| 703 | |
| 704 | |
| 705 | // --- FakeInputReaderContext --- |
| 706 | |
| 707 | class FakeInputReaderContext : public InputReaderContext { |
| 708 | sp<EventHubInterface> mEventHub; |
| 709 | sp<InputReaderPolicyInterface> mPolicy; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 710 | sp<InputListenerInterface> mListener; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 711 | int32_t mGlobalMetaState; |
| 712 | bool mUpdateGlobalMetaStateWasCalled; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 713 | int32_t mGeneration; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 714 | |
| 715 | public: |
| 716 | FakeInputReaderContext(const sp<EventHubInterface>& eventHub, |
| 717 | const sp<InputReaderPolicyInterface>& policy, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 718 | const sp<InputListenerInterface>& listener) : |
| 719 | mEventHub(eventHub), mPolicy(policy), mListener(listener), |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 720 | mGlobalMetaState(0) { |
| 721 | } |
| 722 | |
| 723 | virtual ~FakeInputReaderContext() { } |
| 724 | |
| 725 | void assertUpdateGlobalMetaStateWasCalled() { |
| 726 | ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled) |
| 727 | << "Expected updateGlobalMetaState() to have been called."; |
| 728 | mUpdateGlobalMetaStateWasCalled = false; |
| 729 | } |
| 730 | |
| 731 | void setGlobalMetaState(int32_t state) { |
| 732 | mGlobalMetaState = state; |
| 733 | } |
| 734 | |
| 735 | private: |
| 736 | virtual void updateGlobalMetaState() { |
| 737 | mUpdateGlobalMetaStateWasCalled = true; |
| 738 | } |
| 739 | |
| 740 | virtual int32_t getGlobalMetaState() { |
| 741 | return mGlobalMetaState; |
| 742 | } |
| 743 | |
| 744 | virtual EventHubInterface* getEventHub() { |
| 745 | return mEventHub.get(); |
| 746 | } |
| 747 | |
| 748 | virtual InputReaderPolicyInterface* getPolicy() { |
| 749 | return mPolicy.get(); |
| 750 | } |
| 751 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 752 | virtual InputListenerInterface* getListener() { |
| 753 | return mListener.get(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 754 | } |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 755 | |
| 756 | virtual void disableVirtualKeysUntil(nsecs_t time) { |
| 757 | } |
| 758 | |
| 759 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 760 | InputDevice* device, int32_t keyCode, int32_t scanCode) { |
| 761 | return false; |
| 762 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 763 | |
| 764 | virtual void fadePointer() { |
| 765 | } |
Jeff Brown | aa3855d | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 766 | |
| 767 | virtual void requestTimeoutAtTime(nsecs_t when) { |
| 768 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 769 | |
| 770 | virtual int32_t bumpGeneration() { |
| 771 | return ++mGeneration; |
| 772 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 773 | }; |
| 774 | |
| 775 | |
| 776 | // --- FakeInputMapper --- |
| 777 | |
| 778 | class FakeInputMapper : public InputMapper { |
| 779 | uint32_t mSources; |
| 780 | int32_t mKeyboardType; |
| 781 | int32_t mMetaState; |
| 782 | KeyedVector<int32_t, int32_t> mKeyCodeStates; |
| 783 | KeyedVector<int32_t, int32_t> mScanCodeStates; |
| 784 | KeyedVector<int32_t, int32_t> mSwitchStates; |
| 785 | Vector<int32_t> mSupportedKeyCodes; |
| 786 | RawEvent mLastEvent; |
| 787 | |
| 788 | bool mConfigureWasCalled; |
| 789 | bool mResetWasCalled; |
| 790 | bool mProcessWasCalled; |
| 791 | |
| 792 | public: |
| 793 | FakeInputMapper(InputDevice* device, uint32_t sources) : |
| 794 | InputMapper(device), |
| 795 | mSources(sources), mKeyboardType(AINPUT_KEYBOARD_TYPE_NONE), |
| 796 | mMetaState(0), |
| 797 | mConfigureWasCalled(false), mResetWasCalled(false), mProcessWasCalled(false) { |
| 798 | } |
| 799 | |
| 800 | virtual ~FakeInputMapper() { } |
| 801 | |
| 802 | void setKeyboardType(int32_t keyboardType) { |
| 803 | mKeyboardType = keyboardType; |
| 804 | } |
| 805 | |
| 806 | void setMetaState(int32_t metaState) { |
| 807 | mMetaState = metaState; |
| 808 | } |
| 809 | |
| 810 | void assertConfigureWasCalled() { |
| 811 | ASSERT_TRUE(mConfigureWasCalled) |
| 812 | << "Expected configure() to have been called."; |
| 813 | mConfigureWasCalled = false; |
| 814 | } |
| 815 | |
| 816 | void assertResetWasCalled() { |
| 817 | ASSERT_TRUE(mResetWasCalled) |
| 818 | << "Expected reset() to have been called."; |
| 819 | mResetWasCalled = false; |
| 820 | } |
| 821 | |
| 822 | void assertProcessWasCalled(RawEvent* outLastEvent = NULL) { |
| 823 | ASSERT_TRUE(mProcessWasCalled) |
| 824 | << "Expected process() to have been called."; |
| 825 | if (outLastEvent) { |
| 826 | *outLastEvent = mLastEvent; |
| 827 | } |
| 828 | mProcessWasCalled = false; |
| 829 | } |
| 830 | |
| 831 | void setKeyCodeState(int32_t keyCode, int32_t state) { |
| 832 | mKeyCodeStates.replaceValueFor(keyCode, state); |
| 833 | } |
| 834 | |
| 835 | void setScanCodeState(int32_t scanCode, int32_t state) { |
| 836 | mScanCodeStates.replaceValueFor(scanCode, state); |
| 837 | } |
| 838 | |
| 839 | void setSwitchState(int32_t switchCode, int32_t state) { |
| 840 | mSwitchStates.replaceValueFor(switchCode, state); |
| 841 | } |
| 842 | |
| 843 | void addSupportedKeyCode(int32_t keyCode) { |
| 844 | mSupportedKeyCodes.add(keyCode); |
| 845 | } |
| 846 | |
| 847 | private: |
| 848 | virtual uint32_t getSources() { |
| 849 | return mSources; |
| 850 | } |
| 851 | |
| 852 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) { |
| 853 | InputMapper::populateDeviceInfo(deviceInfo); |
| 854 | |
| 855 | if (mKeyboardType != AINPUT_KEYBOARD_TYPE_NONE) { |
| 856 | deviceInfo->setKeyboardType(mKeyboardType); |
| 857 | } |
| 858 | } |
| 859 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 860 | virtual void configure(nsecs_t when, |
| 861 | const InputReaderConfiguration* config, uint32_t changes) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 862 | mConfigureWasCalled = true; |
| 863 | } |
| 864 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 865 | virtual void reset(nsecs_t when) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 866 | mResetWasCalled = true; |
| 867 | } |
| 868 | |
| 869 | virtual void process(const RawEvent* rawEvent) { |
| 870 | mLastEvent = *rawEvent; |
| 871 | mProcessWasCalled = true; |
| 872 | } |
| 873 | |
| 874 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { |
| 875 | ssize_t index = mKeyCodeStates.indexOfKey(keyCode); |
| 876 | return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN; |
| 877 | } |
| 878 | |
| 879 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) { |
| 880 | ssize_t index = mScanCodeStates.indexOfKey(scanCode); |
| 881 | return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN; |
| 882 | } |
| 883 | |
| 884 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode) { |
| 885 | ssize_t index = mSwitchStates.indexOfKey(switchCode); |
| 886 | return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN; |
| 887 | } |
| 888 | |
| 889 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 890 | const int32_t* keyCodes, uint8_t* outFlags) { |
| 891 | bool result = false; |
| 892 | for (size_t i = 0; i < numCodes; i++) { |
| 893 | for (size_t j = 0; j < mSupportedKeyCodes.size(); j++) { |
| 894 | if (keyCodes[i] == mSupportedKeyCodes[j]) { |
| 895 | outFlags[i] = 1; |
| 896 | result = true; |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | return result; |
| 901 | } |
| 902 | |
| 903 | virtual int32_t getMetaState() { |
| 904 | return mMetaState; |
| 905 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 906 | |
| 907 | virtual void fadePointer() { |
| 908 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 909 | }; |
| 910 | |
| 911 | |
| 912 | // --- InstrumentedInputReader --- |
| 913 | |
| 914 | class InstrumentedInputReader : public InputReader { |
| 915 | InputDevice* mNextDevice; |
| 916 | |
| 917 | public: |
| 918 | InstrumentedInputReader(const sp<EventHubInterface>& eventHub, |
| 919 | const sp<InputReaderPolicyInterface>& policy, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 920 | const sp<InputListenerInterface>& listener) : |
| 921 | InputReader(eventHub, policy, listener), |
Jeff Brown | 71c86ad | 2011-02-07 20:29:08 -0800 | [diff] [blame] | 922 | mNextDevice(NULL) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | virtual ~InstrumentedInputReader() { |
| 926 | if (mNextDevice) { |
| 927 | delete mNextDevice; |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | void setNextDevice(InputDevice* device) { |
| 932 | mNextDevice = device; |
| 933 | } |
| 934 | |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 935 | InputDevice* newDevice(int32_t deviceId, int32_t controllerNumber, const String8& name, |
| 936 | uint32_t classes) { |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 937 | InputDeviceIdentifier identifier; |
| 938 | identifier.name = name; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 939 | int32_t generation = deviceId + 1; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 940 | return new InputDevice(&mContext, deviceId, generation, controllerNumber, identifier, |
| 941 | classes); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 944 | protected: |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 945 | virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber, |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 946 | const InputDeviceIdentifier& identifier, uint32_t classes) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 947 | if (mNextDevice) { |
| 948 | InputDevice* device = mNextDevice; |
| 949 | mNextDevice = NULL; |
| 950 | return device; |
| 951 | } |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 952 | return InputReader::createDeviceLocked(deviceId, controllerNumber, identifier, classes); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | friend class InputReaderTest; |
| 956 | }; |
| 957 | |
| 958 | |
| 959 | // --- InputReaderTest --- |
| 960 | |
| 961 | class InputReaderTest : public testing::Test { |
| 962 | protected: |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 963 | sp<FakeInputListener> mFakeListener; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 964 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 965 | sp<FakeEventHub> mFakeEventHub; |
| 966 | sp<InstrumentedInputReader> mReader; |
| 967 | |
| 968 | virtual void SetUp() { |
| 969 | mFakeEventHub = new FakeEventHub(); |
| 970 | mFakePolicy = new FakeInputReaderPolicy(); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 971 | mFakeListener = new FakeInputListener(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 972 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 973 | mReader = new InstrumentedInputReader(mFakeEventHub, mFakePolicy, mFakeListener); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | virtual void TearDown() { |
| 977 | mReader.clear(); |
| 978 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 979 | mFakeListener.clear(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 980 | mFakePolicy.clear(); |
| 981 | mFakeEventHub.clear(); |
| 982 | } |
| 983 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 984 | void addDevice(int32_t deviceId, const String8& name, uint32_t classes, |
| 985 | const PropertyMap* configuration) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 986 | mFakeEventHub->addDevice(deviceId, name, classes); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 987 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 988 | if (configuration) { |
| 989 | mFakeEventHub->addConfigurationMap(deviceId, configuration); |
| 990 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 991 | mFakeEventHub->finishDeviceScan(); |
| 992 | mReader->loopOnce(); |
| 993 | mReader->loopOnce(); |
| 994 | mFakeEventHub->assertQueueIsEmpty(); |
| 995 | } |
| 996 | |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 997 | FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, int32_t controllerNumber, |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 998 | const String8& name, uint32_t classes, uint32_t sources, |
| 999 | const PropertyMap* configuration) { |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1000 | InputDevice* device = mReader->newDevice(deviceId, controllerNumber, name, classes); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1001 | FakeInputMapper* mapper = new FakeInputMapper(device, sources); |
| 1002 | device->addMapper(mapper); |
| 1003 | mReader->setNextDevice(device); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1004 | addDevice(deviceId, name, classes, configuration); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1005 | return mapper; |
| 1006 | } |
| 1007 | }; |
| 1008 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1009 | TEST_F(InputReaderTest, GetInputDevices) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1010 | ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1011 | INPUT_DEVICE_CLASS_KEYBOARD, NULL)); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1012 | ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("ignored"), |
| 1013 | 0, NULL)); // no classes so device will be ignored |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1014 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1015 | Vector<InputDeviceInfo> inputDevices; |
| 1016 | mReader->getInputDevices(inputDevices); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1017 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1018 | ASSERT_EQ(1U, inputDevices.size()); |
| 1019 | ASSERT_EQ(1, inputDevices[0].getId()); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1020 | ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string()); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1021 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); |
| 1022 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); |
| 1023 | ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1024 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1025 | // Should also have received a notification describing the new input devices. |
| 1026 | inputDevices = mFakePolicy->getInputDevices(); |
| 1027 | ASSERT_EQ(1U, inputDevices.size()); |
| 1028 | ASSERT_EQ(1, inputDevices[0].getId()); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1029 | ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string()); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1030 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); |
| 1031 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); |
| 1032 | ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) { |
| 1036 | FakeInputMapper* mapper = NULL; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1037 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1038 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1039 | mapper->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); |
| 1040 | |
| 1041 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(0, |
| 1042 | AINPUT_SOURCE_ANY, AKEYCODE_A)) |
| 1043 | << "Should return unknown when the device id is >= 0 but unknown."; |
| 1044 | |
| 1045 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(1, |
| 1046 | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1047 | << "Should return unknown when the device id is valid but the sources are not supported by the device."; |
| 1048 | |
| 1049 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(1, |
| 1050 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1051 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; |
| 1052 | |
| 1053 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(-1, |
| 1054 | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1055 | << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; |
| 1056 | |
| 1057 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(-1, |
| 1058 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1059 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; |
| 1060 | } |
| 1061 | |
| 1062 | TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) { |
| 1063 | FakeInputMapper* mapper = NULL; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1064 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1065 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1066 | mapper->setScanCodeState(KEY_A, AKEY_STATE_DOWN); |
| 1067 | |
| 1068 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(0, |
| 1069 | AINPUT_SOURCE_ANY, KEY_A)) |
| 1070 | << "Should return unknown when the device id is >= 0 but unknown."; |
| 1071 | |
| 1072 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(1, |
| 1073 | AINPUT_SOURCE_TRACKBALL, KEY_A)) |
| 1074 | << "Should return unknown when the device id is valid but the sources are not supported by the device."; |
| 1075 | |
| 1076 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(1, |
| 1077 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A)) |
| 1078 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; |
| 1079 | |
| 1080 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(-1, |
| 1081 | AINPUT_SOURCE_TRACKBALL, KEY_A)) |
| 1082 | << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; |
| 1083 | |
| 1084 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(-1, |
| 1085 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A)) |
| 1086 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; |
| 1087 | } |
| 1088 | |
| 1089 | TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) { |
| 1090 | FakeInputMapper* mapper = NULL; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1091 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1092 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1093 | mapper->setSwitchState(SW_LID, AKEY_STATE_DOWN); |
| 1094 | |
| 1095 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(0, |
| 1096 | AINPUT_SOURCE_ANY, SW_LID)) |
| 1097 | << "Should return unknown when the device id is >= 0 but unknown."; |
| 1098 | |
| 1099 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(1, |
| 1100 | AINPUT_SOURCE_TRACKBALL, SW_LID)) |
| 1101 | << "Should return unknown when the device id is valid but the sources are not supported by the device."; |
| 1102 | |
| 1103 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(1, |
| 1104 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID)) |
| 1105 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; |
| 1106 | |
| 1107 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(-1, |
| 1108 | AINPUT_SOURCE_TRACKBALL, SW_LID)) |
| 1109 | << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; |
| 1110 | |
| 1111 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(-1, |
| 1112 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID)) |
| 1113 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; |
| 1114 | } |
| 1115 | |
| 1116 | TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) { |
| 1117 | FakeInputMapper* mapper = NULL; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1118 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1119 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1120 | mapper->addSupportedKeyCode(AKEYCODE_A); |
| 1121 | mapper->addSupportedKeyCode(AKEYCODE_B); |
| 1122 | |
| 1123 | const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 }; |
| 1124 | uint8_t flags[4] = { 0, 0, 0, 1 }; |
| 1125 | |
| 1126 | ASSERT_FALSE(mReader->hasKeys(0, AINPUT_SOURCE_ANY, 4, keyCodes, flags)) |
| 1127 | << "Should return false when device id is >= 0 but unknown."; |
| 1128 | ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); |
| 1129 | |
| 1130 | flags[3] = 1; |
| 1131 | ASSERT_FALSE(mReader->hasKeys(1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) |
| 1132 | << "Should return false when device id is valid but the sources are not supported by the device."; |
| 1133 | ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); |
| 1134 | |
| 1135 | flags[3] = 1; |
| 1136 | ASSERT_TRUE(mReader->hasKeys(1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) |
| 1137 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; |
| 1138 | ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]); |
| 1139 | |
| 1140 | flags[3] = 1; |
| 1141 | ASSERT_FALSE(mReader->hasKeys(-1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) |
| 1142 | << "Should return false when the device id is < 0 but the sources are not supported by any device."; |
| 1143 | ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); |
| 1144 | |
| 1145 | flags[3] = 1; |
| 1146 | ASSERT_TRUE(mReader->hasKeys(-1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) |
| 1147 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; |
| 1148 | ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]); |
| 1149 | } |
| 1150 | |
| 1151 | TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1152 | addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, NULL); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1153 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1154 | NotifyConfigurationChangedArgs args; |
| 1155 | |
| 1156 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1157 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 1158 | } |
| 1159 | |
| 1160 | TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) { |
| 1161 | FakeInputMapper* mapper = NULL; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1162 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1163 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1164 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1165 | mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1166 | mReader->loopOnce(); |
| 1167 | ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty()); |
| 1168 | |
| 1169 | RawEvent event; |
| 1170 | ASSERT_NO_FATAL_FAILURE(mapper->assertProcessWasCalled(&event)); |
| 1171 | ASSERT_EQ(0, event.when); |
| 1172 | ASSERT_EQ(1, event.deviceId); |
| 1173 | ASSERT_EQ(EV_KEY, event.type); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1174 | ASSERT_EQ(KEY_A, event.code); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1175 | ASSERT_EQ(1, event.value); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | // --- InputDeviceTest --- |
| 1180 | |
| 1181 | class InputDeviceTest : public testing::Test { |
| 1182 | protected: |
| 1183 | static const char* DEVICE_NAME; |
| 1184 | static const int32_t DEVICE_ID; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1185 | static const int32_t DEVICE_GENERATION; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1186 | static const int32_t DEVICE_CONTROLLER_NUMBER; |
Jeff Brown | 9ee285a | 2011-08-31 12:56:34 -0700 | [diff] [blame] | 1187 | static const uint32_t DEVICE_CLASSES; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1188 | |
| 1189 | sp<FakeEventHub> mFakeEventHub; |
| 1190 | sp<FakeInputReaderPolicy> mFakePolicy; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1191 | sp<FakeInputListener> mFakeListener; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1192 | FakeInputReaderContext* mFakeContext; |
| 1193 | |
| 1194 | InputDevice* mDevice; |
| 1195 | |
| 1196 | virtual void SetUp() { |
| 1197 | mFakeEventHub = new FakeEventHub(); |
| 1198 | mFakePolicy = new FakeInputReaderPolicy(); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1199 | mFakeListener = new FakeInputListener(); |
| 1200 | mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1201 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1202 | mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 1203 | InputDeviceIdentifier identifier; |
| 1204 | identifier.name = DEVICE_NAME; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1205 | mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1206 | DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | virtual void TearDown() { |
| 1210 | delete mDevice; |
| 1211 | |
| 1212 | delete mFakeContext; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1213 | mFakeListener.clear(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1214 | mFakePolicy.clear(); |
| 1215 | mFakeEventHub.clear(); |
| 1216 | } |
| 1217 | }; |
| 1218 | |
| 1219 | const char* InputDeviceTest::DEVICE_NAME = "device"; |
| 1220 | const int32_t InputDeviceTest::DEVICE_ID = 1; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1221 | const int32_t InputDeviceTest::DEVICE_GENERATION = 2; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1222 | const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0; |
Jeff Brown | 9ee285a | 2011-08-31 12:56:34 -0700 | [diff] [blame] | 1223 | const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD |
| 1224 | | INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_JOYSTICK; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1225 | |
| 1226 | TEST_F(InputDeviceTest, ImmutableProperties) { |
| 1227 | ASSERT_EQ(DEVICE_ID, mDevice->getId()); |
| 1228 | ASSERT_STREQ(DEVICE_NAME, mDevice->getName()); |
Jeff Brown | 9ee285a | 2011-08-31 12:56:34 -0700 | [diff] [blame] | 1229 | ASSERT_EQ(DEVICE_CLASSES, mDevice->getClasses()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) { |
| 1233 | // Configuration. |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 1234 | InputReaderConfiguration config; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1235 | mDevice->configure(ARBITRARY_TIME, &config, 0); |
| 1236 | |
| 1237 | // Reset. |
| 1238 | mDevice->reset(ARBITRARY_TIME); |
| 1239 | |
| 1240 | NotifyDeviceResetArgs resetArgs; |
| 1241 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); |
| 1242 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); |
| 1243 | ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1244 | |
| 1245 | // Metadata. |
| 1246 | ASSERT_TRUE(mDevice->isIgnored()); |
| 1247 | ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mDevice->getSources()); |
| 1248 | |
| 1249 | InputDeviceInfo info; |
| 1250 | mDevice->getDeviceInfo(&info); |
| 1251 | ASSERT_EQ(DEVICE_ID, info.getId()); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1252 | ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1253 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType()); |
| 1254 | ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, info.getSources()); |
| 1255 | |
| 1256 | // State queries. |
| 1257 | ASSERT_EQ(0, mDevice->getMetaState()); |
| 1258 | |
| 1259 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, 0)) |
| 1260 | << "Ignored device should return unknown key code state."; |
| 1261 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 0)) |
| 1262 | << "Ignored device should return unknown scan code state."; |
| 1263 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 0)) |
| 1264 | << "Ignored device should return unknown switch state."; |
| 1265 | |
| 1266 | const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B }; |
| 1267 | uint8_t flags[2] = { 0, 1 }; |
| 1268 | ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 2, keyCodes, flags)) |
| 1269 | << "Ignored device should never mark any key codes."; |
| 1270 | ASSERT_EQ(0, flags[0]) << "Flag for unsupported key should be unchanged."; |
| 1271 | ASSERT_EQ(1, flags[1]) << "Flag for unsupported key should be unchanged."; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) { |
| 1275 | // Configuration. |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1276 | mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8("key"), String8("value")); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1277 | |
| 1278 | FakeInputMapper* mapper1 = new FakeInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD); |
| 1279 | mapper1->setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1280 | mapper1->setMetaState(AMETA_ALT_ON); |
| 1281 | mapper1->addSupportedKeyCode(AKEYCODE_A); |
| 1282 | mapper1->addSupportedKeyCode(AKEYCODE_B); |
| 1283 | mapper1->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); |
| 1284 | mapper1->setKeyCodeState(AKEYCODE_B, AKEY_STATE_UP); |
| 1285 | mapper1->setScanCodeState(2, AKEY_STATE_DOWN); |
| 1286 | mapper1->setScanCodeState(3, AKEY_STATE_UP); |
| 1287 | mapper1->setSwitchState(4, AKEY_STATE_DOWN); |
| 1288 | mDevice->addMapper(mapper1); |
| 1289 | |
| 1290 | FakeInputMapper* mapper2 = new FakeInputMapper(mDevice, AINPUT_SOURCE_TOUCHSCREEN); |
| 1291 | mapper2->setMetaState(AMETA_SHIFT_ON); |
| 1292 | mDevice->addMapper(mapper2); |
| 1293 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 1294 | InputReaderConfiguration config; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1295 | mDevice->configure(ARBITRARY_TIME, &config, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1296 | |
| 1297 | String8 propertyValue; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1298 | ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue)) |
| 1299 | << "Device should have read configuration during configuration phase."; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1300 | ASSERT_STREQ("value", propertyValue.string()); |
| 1301 | |
| 1302 | ASSERT_NO_FATAL_FAILURE(mapper1->assertConfigureWasCalled()); |
| 1303 | ASSERT_NO_FATAL_FAILURE(mapper2->assertConfigureWasCalled()); |
| 1304 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1305 | // Reset |
| 1306 | mDevice->reset(ARBITRARY_TIME); |
| 1307 | ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled()); |
| 1308 | ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled()); |
| 1309 | |
| 1310 | NotifyDeviceResetArgs resetArgs; |
| 1311 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); |
| 1312 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); |
| 1313 | ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); |
| 1314 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1315 | // Metadata. |
| 1316 | ASSERT_FALSE(mDevice->isIgnored()); |
| 1317 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources()); |
| 1318 | |
| 1319 | InputDeviceInfo info; |
| 1320 | mDevice->getDeviceInfo(&info); |
| 1321 | ASSERT_EQ(DEVICE_ID, info.getId()); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1322 | ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1323 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType()); |
| 1324 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), info.getSources()); |
| 1325 | |
| 1326 | // State queries. |
| 1327 | ASSERT_EQ(AMETA_ALT_ON | AMETA_SHIFT_ON, mDevice->getMetaState()) |
| 1328 | << "Should query mappers and combine meta states."; |
| 1329 | |
| 1330 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1331 | << "Should return unknown key code state when source not supported."; |
| 1332 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1333 | << "Should return unknown scan code state when source not supported."; |
| 1334 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) |
| 1335 | << "Should return unknown switch state when source not supported."; |
| 1336 | |
| 1337 | ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, AKEYCODE_A)) |
| 1338 | << "Should query mapper when source is supported."; |
| 1339 | ASSERT_EQ(AKEY_STATE_UP, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 3)) |
| 1340 | << "Should query mapper when source is supported."; |
| 1341 | ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 4)) |
| 1342 | << "Should query mapper when source is supported."; |
| 1343 | |
| 1344 | const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 }; |
| 1345 | uint8_t flags[4] = { 0, 0, 0, 1 }; |
| 1346 | ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) |
| 1347 | << "Should do nothing when source is unsupported."; |
| 1348 | ASSERT_EQ(0, flags[0]) << "Flag should be unchanged when source is unsupported."; |
| 1349 | ASSERT_EQ(0, flags[1]) << "Flag should be unchanged when source is unsupported."; |
| 1350 | ASSERT_EQ(0, flags[2]) << "Flag should be unchanged when source is unsupported."; |
| 1351 | ASSERT_EQ(1, flags[3]) << "Flag should be unchanged when source is unsupported."; |
| 1352 | |
| 1353 | ASSERT_TRUE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 4, keyCodes, flags)) |
| 1354 | << "Should query mapper when source is supported."; |
| 1355 | ASSERT_EQ(1, flags[0]) << "Flag for supported key should be set."; |
| 1356 | ASSERT_EQ(1, flags[1]) << "Flag for supported key should be set."; |
| 1357 | ASSERT_EQ(0, flags[2]) << "Flag for unsupported key should be unchanged."; |
| 1358 | ASSERT_EQ(1, flags[3]) << "Flag for unsupported key should be unchanged."; |
| 1359 | |
| 1360 | // Event handling. |
| 1361 | RawEvent event; |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 1362 | mDevice->process(&event, 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1363 | |
| 1364 | ASSERT_NO_FATAL_FAILURE(mapper1->assertProcessWasCalled()); |
| 1365 | ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | // --- InputMapperTest --- |
| 1370 | |
| 1371 | class InputMapperTest : public testing::Test { |
| 1372 | protected: |
| 1373 | static const char* DEVICE_NAME; |
| 1374 | static const int32_t DEVICE_ID; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1375 | static const int32_t DEVICE_GENERATION; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1376 | static const int32_t DEVICE_CONTROLLER_NUMBER; |
Jeff Brown | 9ee285a | 2011-08-31 12:56:34 -0700 | [diff] [blame] | 1377 | static const uint32_t DEVICE_CLASSES; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1378 | |
| 1379 | sp<FakeEventHub> mFakeEventHub; |
| 1380 | sp<FakeInputReaderPolicy> mFakePolicy; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1381 | sp<FakeInputListener> mFakeListener; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1382 | FakeInputReaderContext* mFakeContext; |
| 1383 | InputDevice* mDevice; |
| 1384 | |
| 1385 | virtual void SetUp() { |
| 1386 | mFakeEventHub = new FakeEventHub(); |
| 1387 | mFakePolicy = new FakeInputReaderPolicy(); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1388 | mFakeListener = new FakeInputListener(); |
| 1389 | mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener); |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 1390 | InputDeviceIdentifier identifier; |
| 1391 | identifier.name = DEVICE_NAME; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1392 | mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1393 | DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1394 | |
| 1395 | mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); |
| 1396 | } |
| 1397 | |
| 1398 | virtual void TearDown() { |
| 1399 | delete mDevice; |
| 1400 | delete mFakeContext; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1401 | mFakeListener.clear(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1402 | mFakePolicy.clear(); |
| 1403 | mFakeEventHub.clear(); |
| 1404 | } |
| 1405 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1406 | void addConfigurationProperty(const char* key, const char* value) { |
| 1407 | mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8(key), String8(value)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | void addMapperAndConfigure(InputMapper* mapper) { |
| 1411 | mDevice->addMapper(mapper); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1412 | mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0); |
| 1413 | mDevice->reset(ARBITRARY_TIME); |
| 1414 | } |
| 1415 | |
| 1416 | void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, |
| 1417 | int32_t orientation) { |
| 1418 | mFakePolicy->setDisplayInfo(displayId, width, height, orientation); |
| 1419 | mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), |
| 1420 | InputReaderConfiguration::CHANGE_DISPLAY_INFO); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1424 | int32_t code, int32_t value) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1425 | RawEvent event; |
| 1426 | event.when = when; |
| 1427 | event.deviceId = deviceId; |
| 1428 | event.type = type; |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1429 | event.code = code; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1430 | event.value = value; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1431 | mapper->process(&event); |
| 1432 | } |
| 1433 | |
| 1434 | static void assertMotionRange(const InputDeviceInfo& info, |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 1435 | int32_t axis, uint32_t source, float min, float max, float flat, float fuzz) { |
| 1436 | const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source); |
| 1437 | ASSERT_TRUE(range != NULL) << "Axis: " << axis << " Source: " << source; |
| 1438 | ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source; |
| 1439 | ASSERT_EQ(source, range->source) << "Axis: " << axis << " Source: " << source; |
| 1440 | ASSERT_NEAR(min, range->min, EPSILON) << "Axis: " << axis << " Source: " << source; |
| 1441 | ASSERT_NEAR(max, range->max, EPSILON) << "Axis: " << axis << " Source: " << source; |
| 1442 | ASSERT_NEAR(flat, range->flat, EPSILON) << "Axis: " << axis << " Source: " << source; |
| 1443 | ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | static void assertPointerCoords(const PointerCoords& coords, |
| 1447 | float x, float y, float pressure, float size, |
| 1448 | float touchMajor, float touchMinor, float toolMajor, float toolMinor, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1449 | float orientation, float distance) { |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 1450 | ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), 1); |
| 1451 | ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), 1); |
| 1452 | ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON); |
| 1453 | ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON); |
| 1454 | ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), 1); |
| 1455 | ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), 1); |
| 1456 | ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), 1); |
| 1457 | ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), 1); |
| 1458 | ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1459 | ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON); |
| 1460 | } |
| 1461 | |
| 1462 | static void assertPosition(const sp<FakePointerController>& controller, float x, float y) { |
| 1463 | float actualX, actualY; |
| 1464 | controller->getPosition(&actualX, &actualY); |
| 1465 | ASSERT_NEAR(x, actualX, 1); |
| 1466 | ASSERT_NEAR(y, actualY, 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1467 | } |
| 1468 | }; |
| 1469 | |
| 1470 | const char* InputMapperTest::DEVICE_NAME = "device"; |
| 1471 | const int32_t InputMapperTest::DEVICE_ID = 1; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1472 | const int32_t InputMapperTest::DEVICE_GENERATION = 2; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 1473 | const int32_t InputMapperTest::DEVICE_CONTROLLER_NUMBER = 0; |
Jeff Brown | 9ee285a | 2011-08-31 12:56:34 -0700 | [diff] [blame] | 1474 | const uint32_t InputMapperTest::DEVICE_CLASSES = 0; // not needed for current tests |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1475 | |
| 1476 | |
| 1477 | // --- SwitchInputMapperTest --- |
| 1478 | |
| 1479 | class SwitchInputMapperTest : public InputMapperTest { |
| 1480 | protected: |
| 1481 | }; |
| 1482 | |
| 1483 | TEST_F(SwitchInputMapperTest, GetSources) { |
| 1484 | SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); |
| 1485 | addMapperAndConfigure(mapper); |
| 1486 | |
Jeff Brown | 89de57a | 2011-01-19 18:41:38 -0800 | [diff] [blame] | 1487 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper->getSources()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | TEST_F(SwitchInputMapperTest, GetSwitchState) { |
| 1491 | SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); |
| 1492 | addMapperAndConfigure(mapper); |
| 1493 | |
| 1494 | mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 1); |
| 1495 | ASSERT_EQ(1, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); |
| 1496 | |
| 1497 | mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 0); |
| 1498 | ASSERT_EQ(0, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); |
| 1499 | } |
| 1500 | |
| 1501 | TEST_F(SwitchInputMapperTest, Process) { |
| 1502 | SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); |
| 1503 | addMapperAndConfigure(mapper); |
| 1504 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1505 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 1); |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 1506 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_JACK_PHYSICAL_INSERT, 1); |
| 1507 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_HEADPHONE_INSERT, 0); |
| 1508 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1509 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1510 | NotifySwitchArgs args; |
| 1511 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args)); |
| 1512 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 1513 | ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT), args.switchValues); |
| 1514 | ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT), |
| 1515 | args.switchMask); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1516 | ASSERT_EQ(uint32_t(0), args.policyFlags); |
| 1517 | } |
| 1518 | |
| 1519 | |
| 1520 | // --- KeyboardInputMapperTest --- |
| 1521 | |
| 1522 | class KeyboardInputMapperTest : public InputMapperTest { |
| 1523 | protected: |
| 1524 | void testDPadKeyRotation(KeyboardInputMapper* mapper, |
| 1525 | int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode); |
| 1526 | }; |
| 1527 | |
| 1528 | void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper, |
| 1529 | int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode) { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1530 | NotifyKeyArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1531 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1532 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 1); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1533 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1534 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); |
| 1535 | ASSERT_EQ(originalScanCode, args.scanCode); |
| 1536 | ASSERT_EQ(rotatedKeyCode, args.keyCode); |
| 1537 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1538 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1539 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1540 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); |
| 1541 | ASSERT_EQ(originalScanCode, args.scanCode); |
| 1542 | ASSERT_EQ(rotatedKeyCode, args.keyCode); |
| 1543 | } |
| 1544 | |
| 1545 | |
| 1546 | TEST_F(KeyboardInputMapperTest, GetSources) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1547 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1548 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1549 | addMapperAndConfigure(mapper); |
| 1550 | |
| 1551 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, mapper->getSources()); |
| 1552 | } |
| 1553 | |
| 1554 | TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1555 | const int32_t USAGE_A = 0x070004; |
| 1556 | const int32_t USAGE_UNKNOWN = 0x07ffff; |
| 1557 | mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE); |
| 1558 | mFakeEventHub->addKey(DEVICE_ID, 0, USAGE_A, AKEYCODE_A, POLICY_FLAG_WAKE); |
| 1559 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1560 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1561 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1562 | addMapperAndConfigure(mapper); |
| 1563 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1564 | // Key down by scan code. |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1565 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1566 | EV_KEY, KEY_HOME, 1); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1567 | NotifyKeyArgs args; |
| 1568 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1569 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 1570 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 1571 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 1572 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); |
| 1573 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); |
| 1574 | ASSERT_EQ(KEY_HOME, args.scanCode); |
| 1575 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1576 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); |
| 1577 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); |
| 1578 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 1579 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1580 | // Key up by scan code. |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1581 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1582 | EV_KEY, KEY_HOME, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1583 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1584 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 1585 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 1586 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); |
| 1587 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); |
| 1588 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); |
| 1589 | ASSERT_EQ(KEY_HOME, args.scanCode); |
| 1590 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1591 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); |
| 1592 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); |
| 1593 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1594 | |
| 1595 | // Key down by usage code. |
| 1596 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
| 1597 | EV_MSC, MSC_SCAN, USAGE_A); |
| 1598 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
| 1599 | EV_KEY, 0, 1); |
| 1600 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
| 1601 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 1602 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 1603 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 1604 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); |
| 1605 | ASSERT_EQ(AKEYCODE_A, args.keyCode); |
| 1606 | ASSERT_EQ(0, args.scanCode); |
| 1607 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1608 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); |
| 1609 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); |
| 1610 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 1611 | |
| 1612 | // Key up by usage code. |
| 1613 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
| 1614 | EV_MSC, MSC_SCAN, USAGE_A); |
| 1615 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, |
| 1616 | EV_KEY, 0, 0); |
| 1617 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
| 1618 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 1619 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 1620 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); |
| 1621 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); |
| 1622 | ASSERT_EQ(AKEYCODE_A, args.keyCode); |
| 1623 | ASSERT_EQ(0, args.scanCode); |
| 1624 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1625 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); |
| 1626 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); |
| 1627 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 1628 | |
| 1629 | // Key down with unknown scan code or usage code. |
| 1630 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
| 1631 | EV_MSC, MSC_SCAN, USAGE_UNKNOWN); |
| 1632 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
| 1633 | EV_KEY, KEY_UNKNOWN, 1); |
| 1634 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
| 1635 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 1636 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 1637 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 1638 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); |
| 1639 | ASSERT_EQ(0, args.keyCode); |
| 1640 | ASSERT_EQ(KEY_UNKNOWN, args.scanCode); |
| 1641 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1642 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); |
| 1643 | ASSERT_EQ(0U, args.policyFlags); |
| 1644 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 1645 | |
| 1646 | // Key up with unknown scan code or usage code. |
| 1647 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
| 1648 | EV_MSC, MSC_SCAN, USAGE_UNKNOWN); |
| 1649 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, |
| 1650 | EV_KEY, KEY_UNKNOWN, 0); |
| 1651 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
| 1652 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 1653 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 1654 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); |
| 1655 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); |
| 1656 | ASSERT_EQ(0, args.keyCode); |
| 1657 | ASSERT_EQ(KEY_UNKNOWN, args.scanCode); |
| 1658 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1659 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); |
| 1660 | ASSERT_EQ(0U, args.policyFlags); |
| 1661 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1664 | TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1665 | mFakeEventHub->addKey(DEVICE_ID, KEY_LEFTSHIFT, 0, AKEYCODE_SHIFT_LEFT, 0); |
| 1666 | mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0); |
| 1667 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1668 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1669 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1670 | addMapperAndConfigure(mapper); |
| 1671 | |
| 1672 | // Initial metastate. |
| 1673 | ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); |
| 1674 | |
| 1675 | // Metakey down. |
| 1676 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1677 | EV_KEY, KEY_LEFTSHIFT, 1); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1678 | NotifyKeyArgs args; |
| 1679 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1680 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
| 1681 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); |
| 1682 | ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled()); |
| 1683 | |
| 1684 | // Key down. |
| 1685 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1686 | EV_KEY, KEY_A, 1); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1687 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1688 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
| 1689 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); |
| 1690 | |
| 1691 | // Key up. |
| 1692 | process(mapper, ARBITRARY_TIME + 2, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1693 | EV_KEY, KEY_A, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1694 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1695 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
| 1696 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); |
| 1697 | |
| 1698 | // Metakey up. |
| 1699 | process(mapper, ARBITRARY_TIME + 3, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1700 | EV_KEY, KEY_LEFTSHIFT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1701 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1702 | ASSERT_EQ(AMETA_NONE, args.metaState); |
| 1703 | ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); |
| 1704 | ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled()); |
| 1705 | } |
| 1706 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1707 | TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateDPad) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1708 | mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0); |
| 1709 | mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0); |
| 1710 | mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0); |
| 1711 | mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0); |
| 1712 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1713 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1714 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1715 | addMapperAndConfigure(mapper); |
| 1716 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1717 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1718 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1719 | DISPLAY_ORIENTATION_90); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1720 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1721 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); |
| 1722 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1723 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT)); |
| 1724 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1725 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN)); |
| 1726 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1727 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT)); |
| 1728 | } |
| 1729 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1730 | TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1731 | mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0); |
| 1732 | mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0); |
| 1733 | mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0); |
| 1734 | mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0); |
| 1735 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1736 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1737 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1738 | addConfigurationProperty("keyboard.orientationAware", "1"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1739 | addMapperAndConfigure(mapper); |
| 1740 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1741 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1742 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1743 | DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1744 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1745 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); |
| 1746 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1747 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT)); |
| 1748 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1749 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN)); |
| 1750 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1751 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT)); |
| 1752 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1753 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1754 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1755 | DISPLAY_ORIENTATION_90); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1756 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1757 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT)); |
| 1758 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1759 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP)); |
| 1760 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1761 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT)); |
| 1762 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1763 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN)); |
| 1764 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1765 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1766 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1767 | DISPLAY_ORIENTATION_180); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1768 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1769 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN)); |
| 1770 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1771 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_LEFT)); |
| 1772 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1773 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_UP)); |
| 1774 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1775 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT)); |
| 1776 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1777 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1778 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1779 | DISPLAY_ORIENTATION_270); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1780 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1781 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT)); |
| 1782 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1783 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_DOWN)); |
| 1784 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1785 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_LEFT)); |
| 1786 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, |
| 1787 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_UP)); |
| 1788 | |
| 1789 | // Special case: if orientation changes while key is down, we still emit the same keycode |
| 1790 | // in the key up as we did in the key down. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1791 | NotifyKeyArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1792 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1793 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1794 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1795 | DISPLAY_ORIENTATION_270); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1796 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1797 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1798 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); |
| 1799 | ASSERT_EQ(KEY_UP, args.scanCode); |
| 1800 | ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); |
| 1801 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1802 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1803 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1804 | DISPLAY_ORIENTATION_180); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1805 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1806 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1807 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); |
| 1808 | ASSERT_EQ(KEY_UP, args.scanCode); |
| 1809 | ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); |
| 1810 | } |
| 1811 | |
| 1812 | TEST_F(KeyboardInputMapperTest, GetKeyCodeState) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1813 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1814 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1815 | addMapperAndConfigure(mapper); |
| 1816 | |
| 1817 | mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 1); |
| 1818 | ASSERT_EQ(1, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); |
| 1819 | |
| 1820 | mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 0); |
| 1821 | ASSERT_EQ(0, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); |
| 1822 | } |
| 1823 | |
| 1824 | TEST_F(KeyboardInputMapperTest, GetScanCodeState) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1825 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1826 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1827 | addMapperAndConfigure(mapper); |
| 1828 | |
| 1829 | mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 1); |
| 1830 | ASSERT_EQ(1, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); |
| 1831 | |
| 1832 | mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 0); |
| 1833 | ASSERT_EQ(0, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); |
| 1834 | } |
| 1835 | |
| 1836 | TEST_F(KeyboardInputMapperTest, MarkSupportedKeyCodes) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1837 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1838 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1839 | addMapperAndConfigure(mapper); |
| 1840 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1841 | mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1842 | |
| 1843 | const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B }; |
| 1844 | uint8_t flags[2] = { 0, 0 }; |
| 1845 | ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 1, keyCodes, flags)); |
| 1846 | ASSERT_TRUE(flags[0]); |
| 1847 | ASSERT_FALSE(flags[1]); |
| 1848 | } |
| 1849 | |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1850 | TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds) { |
| 1851 | mFakeEventHub->addLed(DEVICE_ID, LED_CAPSL, true /*initially on*/); |
| 1852 | mFakeEventHub->addLed(DEVICE_ID, LED_NUML, false /*initially off*/); |
| 1853 | mFakeEventHub->addLed(DEVICE_ID, LED_SCROLLL, false /*initially off*/); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1854 | mFakeEventHub->addKey(DEVICE_ID, KEY_CAPSLOCK, 0, AKEYCODE_CAPS_LOCK, 0); |
| 1855 | mFakeEventHub->addKey(DEVICE_ID, KEY_NUMLOCK, 0, AKEYCODE_NUM_LOCK, 0); |
| 1856 | mFakeEventHub->addKey(DEVICE_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1857 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1858 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1859 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); |
| 1860 | addMapperAndConfigure(mapper); |
| 1861 | |
| 1862 | // Initialization should have turned all of the lights off. |
| 1863 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1864 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1865 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1866 | |
| 1867 | // Toggle caps lock on. |
| 1868 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1869 | EV_KEY, KEY_CAPSLOCK, 1); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1870 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1871 | EV_KEY, KEY_CAPSLOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1872 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1873 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1874 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1875 | ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper->getMetaState()); |
| 1876 | |
| 1877 | // Toggle num lock on. |
| 1878 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1879 | EV_KEY, KEY_NUMLOCK, 1); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1880 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1881 | EV_KEY, KEY_NUMLOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1882 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1883 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1884 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1885 | ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper->getMetaState()); |
| 1886 | |
| 1887 | // Toggle caps lock off. |
| 1888 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1889 | EV_KEY, KEY_CAPSLOCK, 1); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1890 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1891 | EV_KEY, KEY_CAPSLOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1892 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1893 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1894 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1895 | ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper->getMetaState()); |
| 1896 | |
| 1897 | // Toggle scroll lock on. |
| 1898 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1899 | EV_KEY, KEY_SCROLLLOCK, 1); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1900 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1901 | EV_KEY, KEY_SCROLLLOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1902 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1903 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1904 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1905 | ASSERT_EQ(AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper->getMetaState()); |
| 1906 | |
| 1907 | // Toggle num lock off. |
| 1908 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1909 | EV_KEY, KEY_NUMLOCK, 1); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1910 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1911 | EV_KEY, KEY_NUMLOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1912 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1913 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1914 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1915 | ASSERT_EQ(AMETA_SCROLL_LOCK_ON, mapper->getMetaState()); |
| 1916 | |
| 1917 | // Toggle scroll lock off. |
| 1918 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1919 | EV_KEY, KEY_SCROLLLOCK, 1); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1920 | process(mapper, ARBITRARY_TIME, DEVICE_ID, |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1921 | EV_KEY, KEY_SCROLLLOCK, 0); |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1922 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); |
| 1923 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); |
| 1924 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); |
| 1925 | ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); |
| 1926 | } |
| 1927 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1928 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1929 | // --- CursorInputMapperTest --- |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1930 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1931 | class CursorInputMapperTest : public InputMapperTest { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1932 | protected: |
| 1933 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD; |
| 1934 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1935 | sp<FakePointerController> mFakePointerController; |
| 1936 | |
| 1937 | virtual void SetUp() { |
| 1938 | InputMapperTest::SetUp(); |
| 1939 | |
| 1940 | mFakePointerController = new FakePointerController(); |
| 1941 | mFakePolicy->setPointerController(DEVICE_ID, mFakePointerController); |
| 1942 | } |
| 1943 | |
| 1944 | void testMotionRotation(CursorInputMapper* mapper, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1945 | int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY); |
| 1946 | }; |
| 1947 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1948 | const int32_t CursorInputMapperTest::TRACKBALL_MOVEMENT_THRESHOLD = 6; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1949 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1950 | void CursorInputMapperTest::testMotionRotation(CursorInputMapper* mapper, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1951 | int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY) { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1952 | NotifyMotionArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1953 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 1954 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, originalX); |
| 1955 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, originalY); |
| 1956 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1957 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1958 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); |
| 1959 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
| 1960 | float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD, |
| 1961 | float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 1962 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1965 | TEST_F(CursorInputMapperTest, WhenModeIsPointer_GetSources_ReturnsMouse) { |
| 1966 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 1967 | addConfigurationProperty("cursor.mode", "pointer"); |
| 1968 | addMapperAndConfigure(mapper); |
| 1969 | |
| 1970 | ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources()); |
| 1971 | } |
| 1972 | |
| 1973 | TEST_F(CursorInputMapperTest, WhenModeIsNavigation_GetSources_ReturnsTrackball) { |
| 1974 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 1975 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 1976 | addMapperAndConfigure(mapper); |
| 1977 | |
| 1978 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, mapper->getSources()); |
| 1979 | } |
| 1980 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1981 | TEST_F(CursorInputMapperTest, WhenModeIsPointer_PopulateDeviceInfo_ReturnsRangeFromPointerController) { |
| 1982 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 1983 | addConfigurationProperty("cursor.mode", "pointer"); |
| 1984 | addMapperAndConfigure(mapper); |
| 1985 | |
| 1986 | InputDeviceInfo info; |
| 1987 | mapper->populateDeviceInfo(&info); |
| 1988 | |
| 1989 | // Initially there may not be a valid motion range. |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 1990 | ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE)); |
| 1991 | ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE)); |
| 1992 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, |
| 1993 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, 0.0f, 1.0f, 0.0f, 0.0f)); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1994 | |
| 1995 | // When the bounds are set, then there should be a valid motion range. |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 1996 | mFakePointerController->setBounds(1, 2, 800 - 1, 480 - 1); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1997 | |
| 1998 | InputDeviceInfo info2; |
| 1999 | mapper->populateDeviceInfo(&info2); |
| 2000 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2001 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, |
| 2002 | AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE, |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2003 | 1, 800 - 1, 0.0f, 0.0f)); |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2004 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, |
| 2005 | AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE, |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2006 | 2, 480 - 1, 0.0f, 0.0f)); |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2007 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, |
| 2008 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2009 | 0.0f, 1.0f, 0.0f, 0.0f)); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | TEST_F(CursorInputMapperTest, WhenModeIsNavigation_PopulateDeviceInfo_ReturnsScaledRange) { |
| 2013 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2014 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2015 | addMapperAndConfigure(mapper); |
| 2016 | |
| 2017 | InputDeviceInfo info; |
| 2018 | mapper->populateDeviceInfo(&info); |
| 2019 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2020 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, |
| 2021 | AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_TRACKBALL, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2022 | -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD)); |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2023 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, |
| 2024 | AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_TRACKBALL, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2025 | -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD)); |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2026 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, |
| 2027 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TRACKBALL, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2028 | 0.0f, 1.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2031 | TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaState) { |
| 2032 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2033 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2034 | addMapperAndConfigure(mapper); |
| 2035 | |
| 2036 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 2037 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2038 | NotifyMotionArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2039 | |
| 2040 | // Button press. |
| 2041 | // Mostly testing non x/y behavior here so we don't need to check again elsewhere. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2042 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); |
| 2043 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2044 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2045 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 2046 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 2047 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); |
| 2048 | ASSERT_EQ(uint32_t(0), args.policyFlags); |
| 2049 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); |
| 2050 | ASSERT_EQ(0, args.flags); |
| 2051 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2052 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, args.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2053 | ASSERT_EQ(0, args.edgeFlags); |
| 2054 | ASSERT_EQ(uint32_t(1), args.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2055 | ASSERT_EQ(0, args.pointerProperties[0].id); |
| 2056 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2057 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2058 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2059 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); |
| 2060 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); |
| 2061 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 2062 | |
| 2063 | // Button release. Should have same down time. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2064 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); |
| 2065 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2066 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2067 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); |
| 2068 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 2069 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); |
| 2070 | ASSERT_EQ(uint32_t(0), args.policyFlags); |
| 2071 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); |
| 2072 | ASSERT_EQ(0, args.flags); |
| 2073 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2074 | ASSERT_EQ(0, args.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2075 | ASSERT_EQ(0, args.edgeFlags); |
| 2076 | ASSERT_EQ(uint32_t(1), args.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2077 | ASSERT_EQ(0, args.pointerProperties[0].id); |
| 2078 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2079 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2080 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2081 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); |
| 2082 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); |
| 2083 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 2084 | } |
| 2085 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2086 | TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) { |
| 2087 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2088 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2089 | addMapperAndConfigure(mapper); |
| 2090 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2091 | NotifyMotionArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2092 | |
| 2093 | // Motion in X but not Y. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2094 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1); |
| 2095 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2096 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2097 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); |
| 2098 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2099 | 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2100 | |
| 2101 | // Motion in Y but not X. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2102 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2); |
| 2103 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2104 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2105 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2106 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2107 | 0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2110 | TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) { |
| 2111 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2112 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2113 | addMapperAndConfigure(mapper); |
| 2114 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2115 | NotifyMotionArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2116 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2117 | // Button press. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2118 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); |
| 2119 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2120 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2121 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); |
| 2122 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2123 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2124 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2125 | // Button release. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2126 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); |
| 2127 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2128 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2129 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); |
| 2130 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2131 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2134 | TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) { |
| 2135 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2136 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2137 | addMapperAndConfigure(mapper); |
| 2138 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2139 | NotifyMotionArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2140 | |
| 2141 | // Combined X, Y and Button. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2142 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1); |
| 2143 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2); |
| 2144 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); |
| 2145 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2146 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2147 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); |
| 2148 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
| 2149 | 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2150 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2151 | |
| 2152 | // Move X, Y a bit while pressed. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2153 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 2); |
| 2154 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 1); |
| 2155 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2156 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2157 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); |
| 2158 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
| 2159 | 2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2160 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2161 | |
| 2162 | // Release Button. |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2163 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); |
| 2164 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2165 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2166 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); |
| 2167 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2168 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2171 | TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) { |
| 2172 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2173 | addConfigurationProperty("cursor.mode", "navigation"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2174 | addMapperAndConfigure(mapper); |
| 2175 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2176 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2177 | DISPLAY_WIDTH, DISPLAY_HEIGHT, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2178 | DISPLAY_ORIENTATION_90); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2179 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1)); |
| 2180 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1)); |
| 2181 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 1, 0)); |
| 2182 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, 1, -1)); |
| 2183 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 0, -1)); |
| 2184 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1)); |
| 2185 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, -1, 0)); |
| 2186 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, 1)); |
| 2187 | } |
| 2188 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2189 | TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions) { |
| 2190 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2191 | addConfigurationProperty("cursor.mode", "navigation"); |
| 2192 | addConfigurationProperty("cursor.orientationAware", "1"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2193 | addMapperAndConfigure(mapper); |
| 2194 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2195 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2196 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2197 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1)); |
| 2198 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1)); |
| 2199 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 1, 0)); |
| 2200 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, 1, -1)); |
| 2201 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 0, -1)); |
| 2202 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1)); |
| 2203 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, -1, 0)); |
| 2204 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, 1)); |
| 2205 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2206 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2207 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_90); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2208 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 1, 0)); |
| 2209 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, -1)); |
| 2210 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 0, -1)); |
| 2211 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, -1, -1)); |
| 2212 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, -1, 0)); |
| 2213 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, 1)); |
| 2214 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 0, 1)); |
| 2215 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, 1)); |
| 2216 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2217 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2218 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_180); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2219 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, -1)); |
| 2220 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, -1)); |
| 2221 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, -1, 0)); |
| 2222 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, -1, 1)); |
| 2223 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 0, 1)); |
| 2224 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, 1, 1)); |
| 2225 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 1, 0)); |
| 2226 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, -1)); |
| 2227 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2228 | setDisplayInfoAndReconfigure(DISPLAY_ID, |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2229 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_270); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2230 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, -1, 0)); |
| 2231 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, 1)); |
| 2232 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 0, 1)); |
| 2233 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, 1, 1)); |
| 2234 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 1, 0)); |
| 2235 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, 1, -1)); |
| 2236 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 0, -1)); |
| 2237 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, -1)); |
| 2238 | } |
| 2239 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2240 | TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) { |
| 2241 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2242 | addConfigurationProperty("cursor.mode", "pointer"); |
| 2243 | addMapperAndConfigure(mapper); |
| 2244 | |
| 2245 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); |
| 2246 | mFakePointerController->setPosition(100, 200); |
| 2247 | mFakePointerController->setButtonState(0); |
| 2248 | |
| 2249 | NotifyMotionArgs motionArgs; |
| 2250 | NotifyKeyArgs keyArgs; |
| 2251 | |
| 2252 | // press BTN_LEFT, release BTN_LEFT |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2253 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 1); |
| 2254 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2255 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2256 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 2257 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); |
| 2258 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState()); |
| 2259 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2260 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2261 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2262 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 0); |
| 2263 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2264 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2265 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2266 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2267 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 2268 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2269 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2270 | |
| 2271 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2272 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2273 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2274 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2275 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2276 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2277 | |
| 2278 | // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2279 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 1); |
| 2280 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 1); |
| 2281 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2282 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2283 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 2284 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, |
| 2285 | motionArgs.buttonState); |
| 2286 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, |
| 2287 | mFakePointerController->getButtonState()); |
| 2288 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2289 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2290 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2291 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 0); |
| 2292 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2293 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2294 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); |
| 2295 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState()); |
| 2296 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 2297 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2298 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2299 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2300 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 0); |
| 2301 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2302 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2303 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2304 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2305 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 2306 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2307 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2308 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2309 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2310 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2311 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2312 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2313 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2314 | |
| 2315 | // press BTN_BACK, release BTN_BACK |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2316 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 1); |
| 2317 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2318 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2319 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 2320 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 2321 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2322 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); |
| 2323 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState()); |
| 2324 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2325 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2326 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2327 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2328 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 0); |
| 2329 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2330 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2331 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2332 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2333 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2334 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2335 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2336 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2337 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 2338 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 2339 | |
| 2340 | // press BTN_SIDE, release BTN_SIDE |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2341 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 1); |
| 2342 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2343 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2344 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 2345 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 2346 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2347 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); |
| 2348 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState()); |
| 2349 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2350 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2351 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2352 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2353 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 0); |
| 2354 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2355 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2356 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2357 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2358 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2359 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2360 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2361 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2362 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 2363 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 2364 | |
| 2365 | // press BTN_FORWARD, release BTN_FORWARD |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2366 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 1); |
| 2367 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2368 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2369 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 2370 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 2371 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2372 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); |
| 2373 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState()); |
| 2374 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2375 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2376 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2377 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2378 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 0); |
| 2379 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2380 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2381 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2382 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2383 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2384 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2385 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2386 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2387 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 2388 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 2389 | |
| 2390 | // press BTN_EXTRA, release BTN_EXTRA |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2391 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 1); |
| 2392 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2393 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2394 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 2395 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 2396 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2397 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); |
| 2398 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState()); |
| 2399 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2400 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2401 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2402 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2403 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 0); |
| 2404 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2405 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 2406 | ASSERT_EQ(0, motionArgs.buttonState); |
| 2407 | ASSERT_EQ(0, mFakePointerController->getButtonState()); |
| 2408 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 2409 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 2410 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2411 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 2412 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 2413 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 2414 | } |
| 2415 | |
| 2416 | TEST_F(CursorInputMapperTest, Process_WhenModeIsPointer_ShouldMoveThePointerAround) { |
| 2417 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); |
| 2418 | addConfigurationProperty("cursor.mode", "pointer"); |
| 2419 | addMapperAndConfigure(mapper); |
| 2420 | |
| 2421 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); |
| 2422 | mFakePointerController->setPosition(100, 200); |
| 2423 | mFakePointerController->setButtonState(0); |
| 2424 | |
| 2425 | NotifyMotionArgs args; |
| 2426 | |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2427 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 10); |
| 2428 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 20); |
| 2429 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2430 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
| 2431 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action); |
| 2432 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
| 2433 | 110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); |
| 2434 | ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f)); |
| 2435 | } |
| 2436 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2437 | |
| 2438 | // --- TouchInputMapperTest --- |
| 2439 | |
| 2440 | class TouchInputMapperTest : public InputMapperTest { |
| 2441 | protected: |
| 2442 | static const int32_t RAW_X_MIN; |
| 2443 | static const int32_t RAW_X_MAX; |
| 2444 | static const int32_t RAW_Y_MIN; |
| 2445 | static const int32_t RAW_Y_MAX; |
| 2446 | static const int32_t RAW_TOUCH_MIN; |
| 2447 | static const int32_t RAW_TOUCH_MAX; |
| 2448 | static const int32_t RAW_TOOL_MIN; |
| 2449 | static const int32_t RAW_TOOL_MAX; |
| 2450 | static const int32_t RAW_PRESSURE_MIN; |
| 2451 | static const int32_t RAW_PRESSURE_MAX; |
| 2452 | static const int32_t RAW_ORIENTATION_MIN; |
| 2453 | static const int32_t RAW_ORIENTATION_MAX; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2454 | static const int32_t RAW_DISTANCE_MIN; |
| 2455 | static const int32_t RAW_DISTANCE_MAX; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2456 | static const int32_t RAW_TILT_MIN; |
| 2457 | static const int32_t RAW_TILT_MAX; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2458 | static const int32_t RAW_ID_MIN; |
| 2459 | static const int32_t RAW_ID_MAX; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2460 | static const int32_t RAW_SLOT_MIN; |
| 2461 | static const int32_t RAW_SLOT_MAX; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2462 | static const float X_PRECISION; |
| 2463 | static const float Y_PRECISION; |
| 2464 | |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 2465 | static const float GEOMETRIC_SCALE; |
| 2466 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2467 | static const VirtualKeyDefinition VIRTUAL_KEYS[2]; |
| 2468 | |
| 2469 | enum Axes { |
| 2470 | POSITION = 1 << 0, |
| 2471 | TOUCH = 1 << 1, |
| 2472 | TOOL = 1 << 2, |
| 2473 | PRESSURE = 1 << 3, |
| 2474 | ORIENTATION = 1 << 4, |
| 2475 | MINOR = 1 << 5, |
| 2476 | ID = 1 << 6, |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2477 | DISTANCE = 1 << 7, |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2478 | TILT = 1 << 8, |
| 2479 | SLOT = 1 << 9, |
| 2480 | TOOL_TYPE = 1 << 10, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2481 | }; |
| 2482 | |
| 2483 | void prepareDisplay(int32_t orientation); |
| 2484 | void prepareVirtualKeys(); |
| 2485 | int32_t toRawX(float displayX); |
| 2486 | int32_t toRawY(float displayY); |
| 2487 | float toDisplayX(int32_t rawX); |
| 2488 | float toDisplayY(int32_t rawY); |
| 2489 | }; |
| 2490 | |
| 2491 | const int32_t TouchInputMapperTest::RAW_X_MIN = 25; |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2492 | const int32_t TouchInputMapperTest::RAW_X_MAX = 1019; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2493 | const int32_t TouchInputMapperTest::RAW_Y_MIN = 30; |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2494 | const int32_t TouchInputMapperTest::RAW_Y_MAX = 1009; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2495 | const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0; |
| 2496 | const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31; |
| 2497 | const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0; |
| 2498 | const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15; |
| 2499 | const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = RAW_TOUCH_MIN; |
| 2500 | const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = RAW_TOUCH_MAX; |
| 2501 | const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7; |
| 2502 | const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2503 | const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0; |
| 2504 | const int32_t TouchInputMapperTest::RAW_DISTANCE_MAX = 7; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2505 | const int32_t TouchInputMapperTest::RAW_TILT_MIN = 0; |
| 2506 | const int32_t TouchInputMapperTest::RAW_TILT_MAX = 150; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2507 | const int32_t TouchInputMapperTest::RAW_ID_MIN = 0; |
| 2508 | const int32_t TouchInputMapperTest::RAW_ID_MAX = 9; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2509 | const int32_t TouchInputMapperTest::RAW_SLOT_MIN = 0; |
| 2510 | const int32_t TouchInputMapperTest::RAW_SLOT_MAX = 9; |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2511 | const float TouchInputMapperTest::X_PRECISION = float(RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH; |
| 2512 | const float TouchInputMapperTest::Y_PRECISION = float(RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2513 | |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 2514 | const float TouchInputMapperTest::GEOMETRIC_SCALE = |
| 2515 | avg(float(DISPLAY_WIDTH) / (RAW_X_MAX - RAW_X_MIN + 1), |
| 2516 | float(DISPLAY_HEIGHT) / (RAW_Y_MAX - RAW_Y_MIN + 1)); |
| 2517 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2518 | const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = { |
| 2519 | { KEY_HOME, 60, DISPLAY_HEIGHT + 15, 20, 20 }, |
| 2520 | { KEY_MENU, DISPLAY_HEIGHT - 60, DISPLAY_WIDTH + 15, 20, 20 }, |
| 2521 | }; |
| 2522 | |
| 2523 | void TouchInputMapperTest::prepareDisplay(int32_t orientation) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2524 | setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | void TouchInputMapperTest::prepareVirtualKeys() { |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 2528 | mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[0]); |
| 2529 | mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[1]); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2530 | mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE); |
| 2531 | mFakeEventHub->addKey(DEVICE_ID, KEY_MENU, 0, AKEYCODE_MENU, POLICY_FLAG_WAKE); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | int32_t TouchInputMapperTest::toRawX(float displayX) { |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2535 | return int32_t(displayX * (RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH + RAW_X_MIN); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | int32_t TouchInputMapperTest::toRawY(float displayY) { |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2539 | return int32_t(displayY * (RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT + RAW_Y_MIN); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | float TouchInputMapperTest::toDisplayX(int32_t rawX) { |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2543 | return float(rawX - RAW_X_MIN) * DISPLAY_WIDTH / (RAW_X_MAX - RAW_X_MIN + 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | float TouchInputMapperTest::toDisplayY(int32_t rawY) { |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2547 | return float(rawY - RAW_Y_MIN) * DISPLAY_HEIGHT / (RAW_Y_MAX - RAW_Y_MIN + 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | |
| 2551 | // --- SingleTouchInputMapperTest --- |
| 2552 | |
| 2553 | class SingleTouchInputMapperTest : public TouchInputMapperTest { |
| 2554 | protected: |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2555 | void prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2556 | void prepareAxes(int axes); |
| 2557 | |
| 2558 | void processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y); |
| 2559 | void processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y); |
| 2560 | void processUp(SingleTouchInputMapper* mappery); |
| 2561 | void processPressure(SingleTouchInputMapper* mapper, int32_t pressure); |
| 2562 | void processToolMajor(SingleTouchInputMapper* mapper, int32_t toolMajor); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2563 | void processDistance(SingleTouchInputMapper* mapper, int32_t distance); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2564 | void processTilt(SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2565 | void processKey(SingleTouchInputMapper* mapper, int32_t code, int32_t value); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2566 | void processSync(SingleTouchInputMapper* mapper); |
| 2567 | }; |
| 2568 | |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2569 | void SingleTouchInputMapperTest::prepareButtons() { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2570 | mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2573 | void SingleTouchInputMapperTest::prepareAxes(int axes) { |
| 2574 | if (axes & POSITION) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2575 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_X, |
| 2576 | RAW_X_MIN, RAW_X_MAX, 0, 0); |
| 2577 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_Y, |
| 2578 | RAW_Y_MIN, RAW_Y_MAX, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2579 | } |
| 2580 | if (axes & PRESSURE) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2581 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_PRESSURE, |
| 2582 | RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2583 | } |
| 2584 | if (axes & TOOL) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 2585 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TOOL_WIDTH, |
| 2586 | RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2587 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2588 | if (axes & DISTANCE) { |
| 2589 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_DISTANCE, |
| 2590 | RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0); |
| 2591 | } |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2592 | if (axes & TILT) { |
| 2593 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_X, |
| 2594 | RAW_TILT_MIN, RAW_TILT_MAX, 0, 0); |
| 2595 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_Y, |
| 2596 | RAW_TILT_MIN, RAW_TILT_MAX, 0, 0); |
| 2597 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2601 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 1); |
| 2602 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x); |
| 2603 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2607 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x); |
| 2608 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper* mapper) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2612 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | void SingleTouchInputMapperTest::processPressure( |
| 2616 | SingleTouchInputMapper* mapper, int32_t pressure) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2617 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_PRESSURE, pressure); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | void SingleTouchInputMapperTest::processToolMajor( |
| 2621 | SingleTouchInputMapper* mapper, int32_t toolMajor) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2622 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TOOL_WIDTH, toolMajor); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2625 | void SingleTouchInputMapperTest::processDistance( |
| 2626 | SingleTouchInputMapper* mapper, int32_t distance) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2627 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_DISTANCE, distance); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2630 | void SingleTouchInputMapperTest::processTilt( |
| 2631 | SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2632 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_X, tiltX); |
| 2633 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_Y, tiltY); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2636 | void SingleTouchInputMapperTest::processKey( |
| 2637 | SingleTouchInputMapper* mapper, int32_t code, int32_t value) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2638 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2641 | void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper* mapper) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 2642 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | |
Jeff Brown | ace13b1 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 2646 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) { |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2647 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2648 | prepareButtons(); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2649 | prepareAxes(POSITION); |
| 2650 | addMapperAndConfigure(mapper); |
| 2651 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2652 | ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources()); |
Jeff Brown | ace13b1 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndIsACursor_ReturnsTouchPad) { |
| 2656 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
| 2657 | mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_X); |
| 2658 | mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_Y); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2659 | prepareButtons(); |
Jeff Brown | ace13b1 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 2660 | prepareAxes(POSITION); |
| 2661 | addMapperAndConfigure(mapper); |
| 2662 | |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2663 | ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); |
| 2664 | } |
| 2665 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2666 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchPad_ReturnsTouchPad) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2667 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2668 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2669 | prepareAxes(POSITION); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2670 | addConfigurationProperty("touch.deviceType", "touchPad"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2671 | addMapperAndConfigure(mapper); |
| 2672 | |
| 2673 | ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); |
| 2674 | } |
| 2675 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2676 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchScreen_ReturnsTouchScreen) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2677 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2678 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2679 | prepareAxes(POSITION); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2680 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2681 | addMapperAndConfigure(mapper); |
| 2682 | |
| 2683 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources()); |
| 2684 | } |
| 2685 | |
| 2686 | TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2687 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2688 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2689 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2690 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2691 | prepareAxes(POSITION); |
| 2692 | prepareVirtualKeys(); |
| 2693 | addMapperAndConfigure(mapper); |
| 2694 | |
| 2695 | // Unknown key. |
| 2696 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); |
| 2697 | |
| 2698 | // Virtual key is down. |
| 2699 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); |
| 2700 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); |
| 2701 | processDown(mapper, x, y); |
| 2702 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2703 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2704 | |
| 2705 | ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME)); |
| 2706 | |
| 2707 | // Virtual key is up. |
| 2708 | processUp(mapper); |
| 2709 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2710 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2711 | |
| 2712 | ASSERT_EQ(AKEY_STATE_UP, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME)); |
| 2713 | } |
| 2714 | |
| 2715 | TEST_F(SingleTouchInputMapperTest, GetScanCodeState) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2716 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2717 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2718 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2719 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2720 | prepareAxes(POSITION); |
| 2721 | prepareVirtualKeys(); |
| 2722 | addMapperAndConfigure(mapper); |
| 2723 | |
| 2724 | // Unknown key. |
| 2725 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); |
| 2726 | |
| 2727 | // Virtual key is down. |
| 2728 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); |
| 2729 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); |
| 2730 | processDown(mapper, x, y); |
| 2731 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2732 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2733 | |
| 2734 | ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME)); |
| 2735 | |
| 2736 | // Virtual key is up. |
| 2737 | processUp(mapper); |
| 2738 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2739 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2740 | |
| 2741 | ASSERT_EQ(AKEY_STATE_UP, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME)); |
| 2742 | } |
| 2743 | |
| 2744 | TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2745 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2746 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2747 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2748 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2749 | prepareAxes(POSITION); |
| 2750 | prepareVirtualKeys(); |
| 2751 | addMapperAndConfigure(mapper); |
| 2752 | |
| 2753 | const int32_t keys[2] = { AKEYCODE_HOME, AKEYCODE_A }; |
| 2754 | uint8_t flags[2] = { 0, 0 }; |
| 2755 | ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 2, keys, flags)); |
| 2756 | ASSERT_TRUE(flags[0]); |
| 2757 | ASSERT_FALSE(flags[1]); |
| 2758 | } |
| 2759 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2760 | TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2761 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2762 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2763 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2764 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2765 | prepareAxes(POSITION); |
| 2766 | prepareVirtualKeys(); |
| 2767 | addMapperAndConfigure(mapper); |
| 2768 | |
| 2769 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 2770 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2771 | NotifyKeyArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2772 | |
| 2773 | // Press virtual key. |
| 2774 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); |
| 2775 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); |
| 2776 | processDown(mapper, x, y); |
| 2777 | processSync(mapper); |
| 2778 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2779 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2780 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 2781 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 2782 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 2783 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); |
| 2784 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); |
| 2785 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); |
| 2786 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); |
| 2787 | ASSERT_EQ(KEY_HOME, args.scanCode); |
| 2788 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
| 2789 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 2790 | |
| 2791 | // Release virtual key. |
| 2792 | processUp(mapper); |
| 2793 | processSync(mapper); |
| 2794 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2795 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2796 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 2797 | ASSERT_EQ(DEVICE_ID, args.deviceId); |
| 2798 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); |
| 2799 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); |
| 2800 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); |
| 2801 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); |
| 2802 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); |
| 2803 | ASSERT_EQ(KEY_HOME, args.scanCode); |
| 2804 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); |
| 2805 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); |
| 2806 | |
| 2807 | // Should not have sent any motions. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2808 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfBounds_SendsKeyDownAndKeyCancel) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2812 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2813 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2814 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2815 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2816 | prepareAxes(POSITION); |
| 2817 | prepareVirtualKeys(); |
| 2818 | addMapperAndConfigure(mapper); |
| 2819 | |
| 2820 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 2821 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2822 | NotifyKeyArgs keyArgs; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2823 | |
| 2824 | // Press virtual key. |
| 2825 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); |
| 2826 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); |
| 2827 | processDown(mapper, x, y); |
| 2828 | processSync(mapper); |
| 2829 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2830 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2831 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime); |
| 2832 | ASSERT_EQ(DEVICE_ID, keyArgs.deviceId); |
| 2833 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source); |
| 2834 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags); |
| 2835 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 2836 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, keyArgs.flags); |
| 2837 | ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode); |
| 2838 | ASSERT_EQ(KEY_HOME, keyArgs.scanCode); |
| 2839 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState); |
| 2840 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime); |
| 2841 | |
| 2842 | // Move out of bounds. This should generate a cancel and a pointer down since we moved |
| 2843 | // into the display area. |
| 2844 | y -= 100; |
| 2845 | processMove(mapper, x, y); |
| 2846 | processSync(mapper); |
| 2847 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2848 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2849 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime); |
| 2850 | ASSERT_EQ(DEVICE_ID, keyArgs.deviceId); |
| 2851 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source); |
| 2852 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags); |
| 2853 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 2854 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY |
| 2855 | | AKEY_EVENT_FLAG_CANCELED, keyArgs.flags); |
| 2856 | ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode); |
| 2857 | ASSERT_EQ(KEY_HOME, keyArgs.scanCode); |
| 2858 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState); |
| 2859 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime); |
| 2860 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2861 | NotifyMotionArgs motionArgs; |
| 2862 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2863 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 2864 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 2865 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 2866 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 2867 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 2868 | ASSERT_EQ(0, motionArgs.flags); |
| 2869 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2870 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2871 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 2872 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2873 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 2874 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2875 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2876 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2877 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 2878 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 2879 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 2880 | |
| 2881 | // Keep moving out of bounds. Should generate a pointer move. |
| 2882 | y -= 50; |
| 2883 | processMove(mapper, x, y); |
| 2884 | processSync(mapper); |
| 2885 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2886 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2887 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 2888 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 2889 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 2890 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 2891 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 2892 | ASSERT_EQ(0, motionArgs.flags); |
| 2893 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2894 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2895 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 2896 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2897 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 2898 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2899 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2900 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2901 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 2902 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 2903 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 2904 | |
| 2905 | // Release out of bounds. Should generate a pointer up. |
| 2906 | processUp(mapper); |
| 2907 | processSync(mapper); |
| 2908 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2909 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2910 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 2911 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 2912 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 2913 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 2914 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 2915 | ASSERT_EQ(0, motionArgs.flags); |
| 2916 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2917 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2918 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 2919 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2920 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 2921 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2922 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2923 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2924 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 2925 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 2926 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 2927 | |
| 2928 | // Should not have sent any more keys or motions. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2929 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
| 2930 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMovesIn_SendsDownAsTouchEntersDisplay) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2934 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2935 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 2936 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 2937 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2938 | prepareAxes(POSITION); |
| 2939 | prepareVirtualKeys(); |
| 2940 | addMapperAndConfigure(mapper); |
| 2941 | |
| 2942 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 2943 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2944 | NotifyMotionArgs motionArgs; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2945 | |
| 2946 | // Initially go down out of bounds. |
| 2947 | int32_t x = -10; |
| 2948 | int32_t y = -10; |
| 2949 | processDown(mapper, x, y); |
| 2950 | processSync(mapper); |
| 2951 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2952 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2953 | |
| 2954 | // Move into the display area. Should generate a pointer down. |
| 2955 | x = 50; |
| 2956 | y = 75; |
| 2957 | processMove(mapper, x, y); |
| 2958 | processSync(mapper); |
| 2959 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2960 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2961 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 2962 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 2963 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 2964 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 2965 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 2966 | ASSERT_EQ(0, motionArgs.flags); |
| 2967 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2968 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2969 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 2970 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2971 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 2972 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2973 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2974 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2975 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 2976 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 2977 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 2978 | |
| 2979 | // Release. Should generate a pointer up. |
| 2980 | processUp(mapper); |
| 2981 | processSync(mapper); |
| 2982 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2983 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2984 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 2985 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 2986 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 2987 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 2988 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 2989 | ASSERT_EQ(0, motionArgs.flags); |
| 2990 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2991 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2992 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 2993 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2994 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 2995 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2996 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2997 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2998 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 2999 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3000 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3001 | |
| 3002 | // Should not have sent any more keys or motions. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3003 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
| 3004 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3008 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 3009 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3010 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 3011 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3012 | prepareAxes(POSITION); |
| 3013 | prepareVirtualKeys(); |
| 3014 | addMapperAndConfigure(mapper); |
| 3015 | |
| 3016 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 3017 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3018 | NotifyMotionArgs motionArgs; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3019 | |
| 3020 | // Down. |
| 3021 | int32_t x = 100; |
| 3022 | int32_t y = 125; |
| 3023 | processDown(mapper, x, y); |
| 3024 | processSync(mapper); |
| 3025 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3026 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3027 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3028 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3029 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3030 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3031 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 3032 | ASSERT_EQ(0, motionArgs.flags); |
| 3033 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3034 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3035 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3036 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3037 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3038 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3039 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3040 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3041 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3042 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3043 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3044 | |
| 3045 | // Move. |
| 3046 | x += 50; |
| 3047 | y += 75; |
| 3048 | processMove(mapper, x, y); |
| 3049 | processSync(mapper); |
| 3050 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3051 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3052 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3053 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3054 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3055 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3056 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3057 | ASSERT_EQ(0, motionArgs.flags); |
| 3058 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3059 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3060 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3061 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3062 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3063 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3064 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3065 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3066 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3067 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3068 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3069 | |
| 3070 | // Up. |
| 3071 | processUp(mapper); |
| 3072 | processSync(mapper); |
| 3073 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3074 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3075 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3076 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3077 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3078 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3079 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 3080 | ASSERT_EQ(0, motionArgs.flags); |
| 3081 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3082 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3083 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3084 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3085 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3086 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3087 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3088 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3089 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3090 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3091 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3092 | |
| 3093 | // Should not have sent any more keys or motions. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3094 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
| 3095 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3098 | TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotateMotions) { |
| 3099 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 3100 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 3101 | prepareButtons(); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3102 | prepareAxes(POSITION); |
| 3103 | addConfigurationProperty("touch.orientationAware", "0"); |
| 3104 | addMapperAndConfigure(mapper); |
| 3105 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3106 | NotifyMotionArgs args; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3107 | |
| 3108 | // Rotation 90. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3109 | prepareDisplay(DISPLAY_ORIENTATION_90); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3110 | processDown(mapper, toRawX(50), toRawY(75)); |
| 3111 | processSync(mapper); |
| 3112 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3113 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 3114 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); |
| 3115 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3116 | |
| 3117 | processUp(mapper); |
| 3118 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3119 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) { |
| 3123 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 3124 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 3125 | prepareButtons(); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3126 | prepareAxes(POSITION); |
| 3127 | addMapperAndConfigure(mapper); |
| 3128 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3129 | NotifyMotionArgs args; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3130 | |
| 3131 | // Rotation 0. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3132 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3133 | processDown(mapper, toRawX(50), toRawY(75)); |
| 3134 | processSync(mapper); |
| 3135 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3136 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 3137 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); |
| 3138 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3139 | |
| 3140 | processUp(mapper); |
| 3141 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3142 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3143 | |
| 3144 | // Rotation 90. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3145 | prepareDisplay(DISPLAY_ORIENTATION_90); |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 3146 | processDown(mapper, RAW_X_MAX - toRawX(75) + RAW_X_MIN, toRawY(50)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3147 | processSync(mapper); |
| 3148 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3149 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 3150 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); |
| 3151 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3152 | |
| 3153 | processUp(mapper); |
| 3154 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3155 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3156 | |
| 3157 | // Rotation 180. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3158 | prepareDisplay(DISPLAY_ORIENTATION_180); |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 3159 | processDown(mapper, RAW_X_MAX - toRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRawY(75) + RAW_Y_MIN); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3160 | processSync(mapper); |
| 3161 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3162 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 3163 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); |
| 3164 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3165 | |
| 3166 | processUp(mapper); |
| 3167 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3168 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3169 | |
| 3170 | // Rotation 270. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3171 | prepareDisplay(DISPLAY_ORIENTATION_270); |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 3172 | processDown(mapper, toRawX(75), RAW_Y_MAX - toRawY(50) + RAW_Y_MIN); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3173 | processSync(mapper); |
| 3174 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3175 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | 9626b14 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 3176 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); |
| 3177 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3178 | |
| 3179 | processUp(mapper); |
| 3180 | processSync(mapper); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3181 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3185 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 3186 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3187 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 3188 | prepareButtons(); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3189 | prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE | TILT); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3190 | addMapperAndConfigure(mapper); |
| 3191 | |
| 3192 | // These calculations are based on the input device calibration documentation. |
| 3193 | int32_t rawX = 100; |
| 3194 | int32_t rawY = 200; |
| 3195 | int32_t rawPressure = 10; |
| 3196 | int32_t rawToolMajor = 12; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3197 | int32_t rawDistance = 2; |
| 3198 | int32_t rawTiltX = 30; |
| 3199 | int32_t rawTiltY = 110; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3200 | |
| 3201 | float x = toDisplayX(rawX); |
| 3202 | float y = toDisplayY(rawY); |
| 3203 | float pressure = float(rawPressure) / RAW_PRESSURE_MAX; |
| 3204 | float size = float(rawToolMajor) / RAW_TOOL_MAX; |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 3205 | float tool = float(rawToolMajor) * GEOMETRIC_SCALE; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3206 | float distance = float(rawDistance); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3207 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3208 | float tiltCenter = (RAW_TILT_MAX + RAW_TILT_MIN) * 0.5f; |
| 3209 | float tiltScale = M_PI / 180; |
| 3210 | float tiltXAngle = (rawTiltX - tiltCenter) * tiltScale; |
| 3211 | float tiltYAngle = (rawTiltY - tiltCenter) * tiltScale; |
| 3212 | float orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle)); |
| 3213 | float tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle)); |
| 3214 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3215 | processDown(mapper, rawX, rawY); |
| 3216 | processPressure(mapper, rawPressure); |
| 3217 | processToolMajor(mapper, rawToolMajor); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3218 | processDistance(mapper, rawDistance); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3219 | processTilt(mapper, rawTiltX, rawTiltY); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3220 | processSync(mapper); |
| 3221 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3222 | NotifyMotionArgs args; |
| 3223 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3224 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3225 | x, y, pressure, size, tool, tool, tool, tool, orientation, distance)); |
| 3226 | ASSERT_EQ(tilt, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TILT)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) { |
| 3230 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
| 3231 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 3232 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 3233 | prepareButtons(); |
| 3234 | prepareAxes(POSITION); |
| 3235 | addMapperAndConfigure(mapper); |
| 3236 | |
| 3237 | NotifyMotionArgs motionArgs; |
| 3238 | NotifyKeyArgs keyArgs; |
| 3239 | |
| 3240 | processDown(mapper, 100, 200); |
| 3241 | processSync(mapper); |
| 3242 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3243 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 3244 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3245 | |
| 3246 | // press BTN_LEFT, release BTN_LEFT |
| 3247 | processKey(mapper, BTN_LEFT, 1); |
| 3248 | processSync(mapper); |
| 3249 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3250 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3251 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); |
| 3252 | |
| 3253 | processKey(mapper, BTN_LEFT, 0); |
| 3254 | processSync(mapper); |
| 3255 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3256 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3257 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3258 | |
| 3259 | // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE |
| 3260 | processKey(mapper, BTN_RIGHT, 1); |
| 3261 | processKey(mapper, BTN_MIDDLE, 1); |
| 3262 | processSync(mapper); |
| 3263 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3264 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3265 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, |
| 3266 | motionArgs.buttonState); |
| 3267 | |
| 3268 | processKey(mapper, BTN_RIGHT, 0); |
| 3269 | processSync(mapper); |
| 3270 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3271 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); |
| 3272 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3273 | |
| 3274 | processKey(mapper, BTN_MIDDLE, 0); |
| 3275 | processSync(mapper); |
| 3276 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3277 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3278 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3279 | |
| 3280 | // press BTN_BACK, release BTN_BACK |
| 3281 | processKey(mapper, BTN_BACK, 1); |
| 3282 | processSync(mapper); |
| 3283 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3284 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 3285 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 3286 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3287 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); |
| 3288 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3289 | |
| 3290 | processKey(mapper, BTN_BACK, 0); |
| 3291 | processSync(mapper); |
| 3292 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3293 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3294 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3295 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3296 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 3297 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 3298 | |
| 3299 | // press BTN_SIDE, release BTN_SIDE |
| 3300 | processKey(mapper, BTN_SIDE, 1); |
| 3301 | processSync(mapper); |
| 3302 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3303 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 3304 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 3305 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3306 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); |
| 3307 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3308 | |
| 3309 | processKey(mapper, BTN_SIDE, 0); |
| 3310 | processSync(mapper); |
| 3311 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3312 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3313 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3314 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3315 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 3316 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 3317 | |
| 3318 | // press BTN_FORWARD, release BTN_FORWARD |
| 3319 | processKey(mapper, BTN_FORWARD, 1); |
| 3320 | processSync(mapper); |
| 3321 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3322 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 3323 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 3324 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3325 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); |
| 3326 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3327 | |
| 3328 | processKey(mapper, BTN_FORWARD, 0); |
| 3329 | processSync(mapper); |
| 3330 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3331 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3332 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3333 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3334 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 3335 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 3336 | |
| 3337 | // press BTN_EXTRA, release BTN_EXTRA |
| 3338 | processKey(mapper, BTN_EXTRA, 1); |
| 3339 | processSync(mapper); |
| 3340 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3341 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 3342 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 3343 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3344 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); |
| 3345 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3346 | |
| 3347 | processKey(mapper, BTN_EXTRA, 0); |
| 3348 | processSync(mapper); |
| 3349 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3350 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3351 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3352 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 3353 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 3354 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 3355 | |
| 3356 | // press BTN_STYLUS, release BTN_STYLUS |
| 3357 | processKey(mapper, BTN_STYLUS, 1); |
| 3358 | processSync(mapper); |
| 3359 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3360 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3361 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY, motionArgs.buttonState); |
| 3362 | |
| 3363 | processKey(mapper, BTN_STYLUS, 0); |
| 3364 | processSync(mapper); |
| 3365 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3366 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3367 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3368 | |
| 3369 | // press BTN_STYLUS2, release BTN_STYLUS2 |
| 3370 | processKey(mapper, BTN_STYLUS2, 1); |
| 3371 | processSync(mapper); |
| 3372 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3373 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3374 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); |
| 3375 | |
| 3376 | processKey(mapper, BTN_STYLUS2, 0); |
| 3377 | processSync(mapper); |
| 3378 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3379 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3380 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3381 | |
| 3382 | // release touch |
| 3383 | processUp(mapper); |
| 3384 | processSync(mapper); |
| 3385 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3386 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 3387 | ASSERT_EQ(0, motionArgs.buttonState); |
| 3388 | } |
| 3389 | |
| 3390 | TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { |
| 3391 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
| 3392 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 3393 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 3394 | prepareButtons(); |
| 3395 | prepareAxes(POSITION); |
| 3396 | addMapperAndConfigure(mapper); |
| 3397 | |
| 3398 | NotifyMotionArgs motionArgs; |
| 3399 | |
| 3400 | // default tool type is finger |
| 3401 | processDown(mapper, 100, 200); |
| 3402 | processSync(mapper); |
| 3403 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3404 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 3405 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3406 | |
| 3407 | // eraser |
| 3408 | processKey(mapper, BTN_TOOL_RUBBER, 1); |
| 3409 | processSync(mapper); |
| 3410 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3411 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3412 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); |
| 3413 | |
| 3414 | // stylus |
| 3415 | processKey(mapper, BTN_TOOL_RUBBER, 0); |
| 3416 | processKey(mapper, BTN_TOOL_PEN, 1); |
| 3417 | processSync(mapper); |
| 3418 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3419 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3420 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 3421 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3422 | // brush |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3423 | processKey(mapper, BTN_TOOL_PEN, 0); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3424 | processKey(mapper, BTN_TOOL_BRUSH, 1); |
| 3425 | processSync(mapper); |
| 3426 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3427 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3428 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 3429 | |
| 3430 | // pencil |
| 3431 | processKey(mapper, BTN_TOOL_BRUSH, 0); |
| 3432 | processKey(mapper, BTN_TOOL_PENCIL, 1); |
| 3433 | processSync(mapper); |
| 3434 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3435 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3436 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 3437 | |
| 3438 | // airbrush |
| 3439 | processKey(mapper, BTN_TOOL_PENCIL, 0); |
| 3440 | processKey(mapper, BTN_TOOL_AIRBRUSH, 1); |
| 3441 | processSync(mapper); |
| 3442 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3443 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3444 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 3445 | |
| 3446 | // mouse |
| 3447 | processKey(mapper, BTN_TOOL_AIRBRUSH, 0); |
| 3448 | processKey(mapper, BTN_TOOL_MOUSE, 1); |
| 3449 | processSync(mapper); |
| 3450 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3451 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3452 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); |
| 3453 | |
| 3454 | // lens |
| 3455 | processKey(mapper, BTN_TOOL_MOUSE, 0); |
| 3456 | processKey(mapper, BTN_TOOL_LENS, 1); |
| 3457 | processSync(mapper); |
| 3458 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3459 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3460 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); |
| 3461 | |
Jeff Brown | ea6892e | 2011-08-23 17:31:25 -0700 | [diff] [blame] | 3462 | // double-tap |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3463 | processKey(mapper, BTN_TOOL_LENS, 0); |
Jeff Brown | ea6892e | 2011-08-23 17:31:25 -0700 | [diff] [blame] | 3464 | processKey(mapper, BTN_TOOL_DOUBLETAP, 1); |
| 3465 | processSync(mapper); |
| 3466 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3467 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3468 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3469 | |
| 3470 | // triple-tap |
| 3471 | processKey(mapper, BTN_TOOL_DOUBLETAP, 0); |
| 3472 | processKey(mapper, BTN_TOOL_TRIPLETAP, 1); |
| 3473 | processSync(mapper); |
| 3474 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3475 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3476 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3477 | |
| 3478 | // quad-tap |
| 3479 | processKey(mapper, BTN_TOOL_TRIPLETAP, 0); |
| 3480 | processKey(mapper, BTN_TOOL_QUADTAP, 1); |
| 3481 | processSync(mapper); |
| 3482 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3483 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3484 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3485 | |
| 3486 | // finger |
| 3487 | processKey(mapper, BTN_TOOL_QUADTAP, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3488 | processKey(mapper, BTN_TOOL_FINGER, 1); |
| 3489 | processSync(mapper); |
| 3490 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3491 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3492 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3493 | |
| 3494 | // stylus trumps finger |
| 3495 | processKey(mapper, BTN_TOOL_PEN, 1); |
| 3496 | processSync(mapper); |
| 3497 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3498 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3499 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 3500 | |
| 3501 | // eraser trumps stylus |
| 3502 | processKey(mapper, BTN_TOOL_RUBBER, 1); |
| 3503 | processSync(mapper); |
| 3504 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3505 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3506 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); |
| 3507 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3508 | // mouse trumps eraser |
| 3509 | processKey(mapper, BTN_TOOL_MOUSE, 1); |
| 3510 | processSync(mapper); |
| 3511 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3512 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3513 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); |
| 3514 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3515 | // back to default tool type |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3516 | processKey(mapper, BTN_TOOL_MOUSE, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3517 | processKey(mapper, BTN_TOOL_RUBBER, 0); |
| 3518 | processKey(mapper, BTN_TOOL_PEN, 0); |
| 3519 | processKey(mapper, BTN_TOOL_FINGER, 0); |
| 3520 | processSync(mapper); |
| 3521 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3522 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3523 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3524 | } |
| 3525 | |
| 3526 | TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { |
| 3527 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
| 3528 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 3529 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 3530 | prepareButtons(); |
| 3531 | prepareAxes(POSITION); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3532 | mFakeEventHub->addKey(DEVICE_ID, BTN_TOOL_FINGER, 0, AKEYCODE_UNKNOWN, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3533 | addMapperAndConfigure(mapper); |
| 3534 | |
| 3535 | NotifyMotionArgs motionArgs; |
| 3536 | |
| 3537 | // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0 |
| 3538 | processKey(mapper, BTN_TOOL_FINGER, 1); |
| 3539 | processMove(mapper, 100, 200); |
| 3540 | processSync(mapper); |
| 3541 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3542 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 3543 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3544 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3545 | |
| 3546 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3547 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 3548 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3549 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3550 | |
| 3551 | // move a little |
| 3552 | processMove(mapper, 150, 250); |
| 3553 | processSync(mapper); |
| 3554 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3555 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 3556 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3557 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3558 | |
| 3559 | // down when BTN_TOUCH is pressed, pressure defaults to 1 |
| 3560 | processKey(mapper, BTN_TOUCH, 1); |
| 3561 | processSync(mapper); |
| 3562 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3563 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 3564 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3565 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3566 | |
| 3567 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3568 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 3569 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3570 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 3571 | |
| 3572 | // up when BTN_TOUCH is released, hover restored |
| 3573 | processKey(mapper, BTN_TOUCH, 0); |
| 3574 | processSync(mapper); |
| 3575 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3576 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 3577 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3578 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 3579 | |
| 3580 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3581 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 3582 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3583 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3584 | |
| 3585 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3586 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 3587 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3588 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3589 | |
| 3590 | // exit hover when pointer goes away |
| 3591 | processKey(mapper, BTN_TOOL_FINGER, 0); |
| 3592 | processSync(mapper); |
| 3593 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3594 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 3595 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3596 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 3597 | } |
| 3598 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3599 | TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsValueIsZero) { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3600 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); |
| 3601 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 3602 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 3603 | prepareButtons(); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3604 | prepareAxes(POSITION | PRESSURE); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3605 | addMapperAndConfigure(mapper); |
| 3606 | |
| 3607 | NotifyMotionArgs motionArgs; |
| 3608 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3609 | // initially hovering because pressure is 0 |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3610 | processDown(mapper, 100, 200); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3611 | processPressure(mapper, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3612 | processSync(mapper); |
| 3613 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3614 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 3615 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3616 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3617 | |
| 3618 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3619 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 3620 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3621 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3622 | |
| 3623 | // move a little |
| 3624 | processMove(mapper, 150, 250); |
| 3625 | processSync(mapper); |
| 3626 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3627 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 3628 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3629 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3630 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3631 | // down when pressure is non-zero |
| 3632 | processPressure(mapper, RAW_PRESSURE_MAX); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3633 | processSync(mapper); |
| 3634 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3635 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 3636 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3637 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3638 | |
| 3639 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3640 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 3641 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3642 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 3643 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3644 | // up when pressure becomes 0, hover restored |
| 3645 | processPressure(mapper, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3646 | processSync(mapper); |
| 3647 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3648 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 3649 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 3650 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 3651 | |
| 3652 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3653 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 3654 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3655 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3656 | |
| 3657 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3658 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 3659 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3660 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3661 | |
| 3662 | // exit hover when pointer goes away |
| 3663 | processUp(mapper); |
| 3664 | processSync(mapper); |
| 3665 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 3666 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 3667 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3668 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | |
| 3672 | // --- MultiTouchInputMapperTest --- |
| 3673 | |
| 3674 | class MultiTouchInputMapperTest : public TouchInputMapperTest { |
| 3675 | protected: |
| 3676 | void prepareAxes(int axes); |
| 3677 | |
| 3678 | void processPosition(MultiTouchInputMapper* mapper, int32_t x, int32_t y); |
| 3679 | void processTouchMajor(MultiTouchInputMapper* mapper, int32_t touchMajor); |
| 3680 | void processTouchMinor(MultiTouchInputMapper* mapper, int32_t touchMinor); |
| 3681 | void processToolMajor(MultiTouchInputMapper* mapper, int32_t toolMajor); |
| 3682 | void processToolMinor(MultiTouchInputMapper* mapper, int32_t toolMinor); |
| 3683 | void processOrientation(MultiTouchInputMapper* mapper, int32_t orientation); |
| 3684 | void processPressure(MultiTouchInputMapper* mapper, int32_t pressure); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3685 | void processDistance(MultiTouchInputMapper* mapper, int32_t distance); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3686 | void processId(MultiTouchInputMapper* mapper, int32_t id); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3687 | void processSlot(MultiTouchInputMapper* mapper, int32_t slot); |
| 3688 | void processToolType(MultiTouchInputMapper* mapper, int32_t toolType); |
| 3689 | void processKey(MultiTouchInputMapper* mapper, int32_t code, int32_t value); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3690 | void processMTSync(MultiTouchInputMapper* mapper); |
| 3691 | void processSync(MultiTouchInputMapper* mapper); |
| 3692 | }; |
| 3693 | |
| 3694 | void MultiTouchInputMapperTest::prepareAxes(int axes) { |
| 3695 | if (axes & POSITION) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3696 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_X, |
| 3697 | RAW_X_MIN, RAW_X_MAX, 0, 0); |
| 3698 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_Y, |
| 3699 | RAW_Y_MIN, RAW_Y_MAX, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3700 | } |
| 3701 | if (axes & TOUCH) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3702 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MAJOR, |
| 3703 | RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3704 | if (axes & MINOR) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3705 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MINOR, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3706 | RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0); |
| 3707 | } |
| 3708 | } |
| 3709 | if (axes & TOOL) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3710 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MAJOR, |
| 3711 | RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3712 | if (axes & MINOR) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3713 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MINOR, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3714 | RAW_TOOL_MAX, RAW_TOOL_MAX, 0, 0); |
| 3715 | } |
| 3716 | } |
| 3717 | if (axes & ORIENTATION) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3718 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_ORIENTATION, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3719 | RAW_ORIENTATION_MIN, RAW_ORIENTATION_MAX, 0, 0); |
| 3720 | } |
| 3721 | if (axes & PRESSURE) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3722 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_PRESSURE, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3723 | RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0); |
| 3724 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3725 | if (axes & DISTANCE) { |
| 3726 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_DISTANCE, |
| 3727 | RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0); |
| 3728 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3729 | if (axes & ID) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 3730 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TRACKING_ID, |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3731 | RAW_ID_MIN, RAW_ID_MAX, 0, 0); |
| 3732 | } |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3733 | if (axes & SLOT) { |
| 3734 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_SLOT, |
| 3735 | RAW_SLOT_MIN, RAW_SLOT_MAX, 0, 0); |
| 3736 | mFakeEventHub->setAbsoluteAxisValue(DEVICE_ID, ABS_MT_SLOT, 0); |
| 3737 | } |
| 3738 | if (axes & TOOL_TYPE) { |
| 3739 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOOL_TYPE, |
| 3740 | 0, MT_TOOL_MAX, 0, 0); |
| 3741 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | void MultiTouchInputMapperTest::processPosition( |
| 3745 | MultiTouchInputMapper* mapper, int32_t x, int32_t y) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3746 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_X, x); |
| 3747 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_Y, y); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | void MultiTouchInputMapperTest::processTouchMajor( |
| 3751 | MultiTouchInputMapper* mapper, int32_t touchMajor) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3752 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MAJOR, touchMajor); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | void MultiTouchInputMapperTest::processTouchMinor( |
| 3756 | MultiTouchInputMapper* mapper, int32_t touchMinor) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3757 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MINOR, touchMinor); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | void MultiTouchInputMapperTest::processToolMajor( |
| 3761 | MultiTouchInputMapper* mapper, int32_t toolMajor) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3762 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MAJOR, toolMajor); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | void MultiTouchInputMapperTest::processToolMinor( |
| 3766 | MultiTouchInputMapper* mapper, int32_t toolMinor) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3767 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MINOR, toolMinor); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | void MultiTouchInputMapperTest::processOrientation( |
| 3771 | MultiTouchInputMapper* mapper, int32_t orientation) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3772 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_ORIENTATION, orientation); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | void MultiTouchInputMapperTest::processPressure( |
| 3776 | MultiTouchInputMapper* mapper, int32_t pressure) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3777 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_PRESSURE, pressure); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3780 | void MultiTouchInputMapperTest::processDistance( |
| 3781 | MultiTouchInputMapper* mapper, int32_t distance) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3782 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_DISTANCE, distance); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3783 | } |
| 3784 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3785 | void MultiTouchInputMapperTest::processId( |
| 3786 | MultiTouchInputMapper* mapper, int32_t id) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3787 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TRACKING_ID, id); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3790 | void MultiTouchInputMapperTest::processSlot( |
| 3791 | MultiTouchInputMapper* mapper, int32_t slot) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3792 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_SLOT, slot); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | void MultiTouchInputMapperTest::processToolType( |
| 3796 | MultiTouchInputMapper* mapper, int32_t toolType) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3797 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOOL_TYPE, toolType); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | void MultiTouchInputMapperTest::processKey( |
| 3801 | MultiTouchInputMapper* mapper, int32_t code, int32_t value) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3802 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3805 | void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3806 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper* mapper) { |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 3810 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | |
| 3814 | TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3815 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 3816 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 3817 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3818 | prepareAxes(POSITION); |
| 3819 | prepareVirtualKeys(); |
| 3820 | addMapperAndConfigure(mapper); |
| 3821 | |
| 3822 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 3823 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3824 | NotifyMotionArgs motionArgs; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3825 | |
| 3826 | // Two fingers down at once. |
| 3827 | int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; |
| 3828 | processPosition(mapper, x1, y1); |
| 3829 | processMTSync(mapper); |
| 3830 | processPosition(mapper, x2, y2); |
| 3831 | processMTSync(mapper); |
| 3832 | processSync(mapper); |
| 3833 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3834 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3835 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3836 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3837 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3838 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3839 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 3840 | ASSERT_EQ(0, motionArgs.flags); |
| 3841 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3842 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3843 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3844 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3845 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3846 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3847 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3848 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3849 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3850 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3851 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3852 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3853 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3854 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3855 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3856 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3857 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3858 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 3859 | motionArgs.action); |
| 3860 | ASSERT_EQ(0, motionArgs.flags); |
| 3861 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3862 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3863 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3864 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3865 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3866 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3867 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 3868 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3869 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3870 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3871 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3872 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3873 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3874 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3875 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3876 | |
| 3877 | // Move. |
| 3878 | x1 += 10; y1 += 15; x2 += 5; y2 -= 10; |
| 3879 | processPosition(mapper, x1, y1); |
| 3880 | processMTSync(mapper); |
| 3881 | processPosition(mapper, x2, y2); |
| 3882 | processMTSync(mapper); |
| 3883 | processSync(mapper); |
| 3884 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3885 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3886 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3887 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3888 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3889 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3890 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3891 | ASSERT_EQ(0, motionArgs.flags); |
| 3892 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3893 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3894 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3895 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3896 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3897 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3898 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 3899 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3900 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3901 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3902 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3903 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3904 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3905 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3906 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3907 | |
| 3908 | // First finger up. |
| 3909 | x2 += 15; y2 -= 20; |
| 3910 | processPosition(mapper, x2, y2); |
| 3911 | processMTSync(mapper); |
| 3912 | processSync(mapper); |
| 3913 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3914 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3915 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3916 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3917 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3918 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3919 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 3920 | motionArgs.action); |
| 3921 | ASSERT_EQ(0, motionArgs.flags); |
| 3922 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3923 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3924 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3925 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3926 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 3927 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 3928 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 3929 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3930 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3931 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3932 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3933 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3934 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3935 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3936 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3937 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3938 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3939 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3940 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3941 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3942 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3943 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3944 | ASSERT_EQ(0, motionArgs.flags); |
| 3945 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3946 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3947 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3948 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3949 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); |
| 3950 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3951 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3952 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3953 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3954 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3955 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3956 | |
| 3957 | // Move. |
| 3958 | x2 += 20; y2 -= 25; |
| 3959 | processPosition(mapper, x2, y2); |
| 3960 | processMTSync(mapper); |
| 3961 | processSync(mapper); |
| 3962 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3963 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3964 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3965 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3966 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3967 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3968 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 3969 | ASSERT_EQ(0, motionArgs.flags); |
| 3970 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3971 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3972 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 3973 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3974 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); |
| 3975 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3976 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3977 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3978 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 3979 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 3980 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 3981 | |
| 3982 | // New finger down. |
| 3983 | int32_t x3 = 700, y3 = 300; |
| 3984 | processPosition(mapper, x2, y2); |
| 3985 | processMTSync(mapper); |
| 3986 | processPosition(mapper, x3, y3); |
| 3987 | processMTSync(mapper); |
| 3988 | processSync(mapper); |
| 3989 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 3990 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3991 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 3992 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 3993 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 3994 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 3995 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 3996 | motionArgs.action); |
| 3997 | ASSERT_EQ(0, motionArgs.flags); |
| 3998 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3999 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4000 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 4001 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4002 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4003 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4004 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4005 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4006 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4007 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4008 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4009 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4010 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 4011 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 4012 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 4013 | |
| 4014 | // Second finger up. |
| 4015 | x3 += 30; y3 -= 20; |
| 4016 | processPosition(mapper, x3, y3); |
| 4017 | processMTSync(mapper); |
| 4018 | processSync(mapper); |
| 4019 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4020 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4021 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 4022 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 4023 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 4024 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 4025 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4026 | motionArgs.action); |
| 4027 | ASSERT_EQ(0, motionArgs.flags); |
| 4028 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4029 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4030 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 4031 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4032 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4033 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4034 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4035 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4036 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4037 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4038 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4039 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4040 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 4041 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 4042 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 4043 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4044 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4045 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 4046 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 4047 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 4048 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 4049 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4050 | ASSERT_EQ(0, motionArgs.flags); |
| 4051 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4052 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4053 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 4054 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4055 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4056 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4057 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4058 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4059 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 4060 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 4061 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 4062 | |
| 4063 | // Last finger up. |
| 4064 | processMTSync(mapper); |
| 4065 | processSync(mapper); |
| 4066 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4067 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4068 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); |
| 4069 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); |
| 4070 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); |
| 4071 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); |
| 4072 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 4073 | ASSERT_EQ(0, motionArgs.flags); |
| 4074 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4075 | ASSERT_EQ(0, motionArgs.buttonState); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4076 | ASSERT_EQ(0, motionArgs.edgeFlags); |
| 4077 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4078 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4079 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4080 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4081 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4082 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); |
| 4083 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); |
| 4084 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); |
| 4085 | |
| 4086 | // Should not have sent any more keys or motions. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4087 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
| 4088 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingIds) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 4092 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4093 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 4094 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4095 | prepareAxes(POSITION | ID); |
| 4096 | prepareVirtualKeys(); |
| 4097 | addMapperAndConfigure(mapper); |
| 4098 | |
| 4099 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 4100 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4101 | NotifyMotionArgs motionArgs; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4102 | |
| 4103 | // Two fingers down at once. |
| 4104 | int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; |
| 4105 | processPosition(mapper, x1, y1); |
| 4106 | processId(mapper, 1); |
| 4107 | processMTSync(mapper); |
| 4108 | processPosition(mapper, x2, y2); |
| 4109 | processId(mapper, 2); |
| 4110 | processMTSync(mapper); |
| 4111 | processSync(mapper); |
| 4112 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4113 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4114 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 4115 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4116 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4117 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4118 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4119 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4120 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4121 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4122 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4123 | motionArgs.action); |
| 4124 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4125 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4126 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4127 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4128 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4129 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4130 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4131 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4132 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4133 | |
| 4134 | // Move. |
| 4135 | x1 += 10; y1 += 15; x2 += 5; y2 -= 10; |
| 4136 | processPosition(mapper, x1, y1); |
| 4137 | processId(mapper, 1); |
| 4138 | processMTSync(mapper); |
| 4139 | processPosition(mapper, x2, y2); |
| 4140 | processId(mapper, 2); |
| 4141 | processMTSync(mapper); |
| 4142 | processSync(mapper); |
| 4143 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4144 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4145 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4146 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4147 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4148 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4149 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4150 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4151 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4152 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4153 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4154 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4155 | |
| 4156 | // First finger up. |
| 4157 | x2 += 15; y2 -= 20; |
| 4158 | processPosition(mapper, x2, y2); |
| 4159 | processId(mapper, 2); |
| 4160 | processMTSync(mapper); |
| 4161 | processSync(mapper); |
| 4162 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4163 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4164 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4165 | motionArgs.action); |
| 4166 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4167 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4168 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4169 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4170 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4171 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4172 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4173 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4174 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4175 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4176 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4177 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4178 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4179 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4180 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4181 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4182 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4183 | |
| 4184 | // Move. |
| 4185 | x2 += 20; y2 -= 25; |
| 4186 | processPosition(mapper, x2, y2); |
| 4187 | processId(mapper, 2); |
| 4188 | processMTSync(mapper); |
| 4189 | processSync(mapper); |
| 4190 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4191 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4192 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4193 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4194 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4195 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4196 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4197 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4198 | |
| 4199 | // New finger down. |
| 4200 | int32_t x3 = 700, y3 = 300; |
| 4201 | processPosition(mapper, x2, y2); |
| 4202 | processId(mapper, 2); |
| 4203 | processMTSync(mapper); |
| 4204 | processPosition(mapper, x3, y3); |
| 4205 | processId(mapper, 3); |
| 4206 | processMTSync(mapper); |
| 4207 | processSync(mapper); |
| 4208 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4209 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4210 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4211 | motionArgs.action); |
| 4212 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4213 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4214 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4215 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4216 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4217 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4218 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4219 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4220 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4221 | |
| 4222 | // Second finger up. |
| 4223 | x3 += 30; y3 -= 20; |
| 4224 | processPosition(mapper, x3, y3); |
| 4225 | processId(mapper, 3); |
| 4226 | processMTSync(mapper); |
| 4227 | processSync(mapper); |
| 4228 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4229 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4230 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4231 | motionArgs.action); |
| 4232 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4233 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4234 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4235 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4236 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4237 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4238 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4239 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4240 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4241 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4242 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4243 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4244 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4245 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4246 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4247 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4248 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4249 | |
| 4250 | // Last finger up. |
| 4251 | processMTSync(mapper); |
| 4252 | processSync(mapper); |
| 4253 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4254 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4255 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 4256 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4257 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4258 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4259 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4260 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4261 | |
| 4262 | // Should not have sent any more keys or motions. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4263 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
| 4264 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
| 4265 | } |
| 4266 | |
| 4267 | TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { |
| 4268 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
| 4269 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 4270 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 4271 | prepareAxes(POSITION | ID | SLOT); |
| 4272 | prepareVirtualKeys(); |
| 4273 | addMapperAndConfigure(mapper); |
| 4274 | |
| 4275 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); |
| 4276 | |
| 4277 | NotifyMotionArgs motionArgs; |
| 4278 | |
| 4279 | // Two fingers down at once. |
| 4280 | int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; |
| 4281 | processPosition(mapper, x1, y1); |
| 4282 | processId(mapper, 1); |
| 4283 | processSlot(mapper, 1); |
| 4284 | processPosition(mapper, x2, y2); |
| 4285 | processId(mapper, 2); |
| 4286 | processSync(mapper); |
| 4287 | |
| 4288 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4289 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 4290 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
| 4291 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4292 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4293 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4294 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4295 | |
| 4296 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4297 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4298 | motionArgs.action); |
| 4299 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
| 4300 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4301 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4302 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4303 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
| 4304 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4305 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4306 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
| 4307 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4308 | |
| 4309 | // Move. |
| 4310 | x1 += 10; y1 += 15; x2 += 5; y2 -= 10; |
| 4311 | processSlot(mapper, 0); |
| 4312 | processPosition(mapper, x1, y1); |
| 4313 | processSlot(mapper, 1); |
| 4314 | processPosition(mapper, x2, y2); |
| 4315 | processSync(mapper); |
| 4316 | |
| 4317 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4318 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4319 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
| 4320 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4321 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4322 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4323 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
| 4324 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4325 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4326 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
| 4327 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4328 | |
| 4329 | // First finger up. |
| 4330 | x2 += 15; y2 -= 20; |
| 4331 | processSlot(mapper, 0); |
| 4332 | processId(mapper, -1); |
| 4333 | processSlot(mapper, 1); |
| 4334 | processPosition(mapper, x2, y2); |
| 4335 | processSync(mapper); |
| 4336 | |
| 4337 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4338 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4339 | motionArgs.action); |
| 4340 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
| 4341 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4342 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4343 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4344 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
| 4345 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4346 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4347 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
| 4348 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4349 | |
| 4350 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4351 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4352 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
| 4353 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); |
| 4354 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4355 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4356 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4357 | |
| 4358 | // Move. |
| 4359 | x2 += 20; y2 -= 25; |
| 4360 | processPosition(mapper, x2, y2); |
| 4361 | processSync(mapper); |
| 4362 | |
| 4363 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4364 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4365 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
| 4366 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); |
| 4367 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4368 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4369 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4370 | |
| 4371 | // New finger down. |
| 4372 | int32_t x3 = 700, y3 = 300; |
| 4373 | processPosition(mapper, x2, y2); |
| 4374 | processSlot(mapper, 0); |
| 4375 | processId(mapper, 3); |
| 4376 | processPosition(mapper, x3, y3); |
| 4377 | processSync(mapper); |
| 4378 | |
| 4379 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4380 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4381 | motionArgs.action); |
| 4382 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
| 4383 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4384 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4385 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4386 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
| 4387 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4388 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4389 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
| 4390 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4391 | |
| 4392 | // Second finger up. |
| 4393 | x3 += 30; y3 -= 20; |
| 4394 | processSlot(mapper, 1); |
| 4395 | processId(mapper, -1); |
| 4396 | processSlot(mapper, 0); |
| 4397 | processPosition(mapper, x3, y3); |
| 4398 | processSync(mapper); |
| 4399 | |
| 4400 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4401 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4402 | motionArgs.action); |
| 4403 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); |
| 4404 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4405 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4406 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); |
| 4407 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); |
| 4408 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4409 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4410 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], |
| 4411 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4412 | |
| 4413 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4414 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4415 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
| 4416 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4417 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4418 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4419 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4420 | |
| 4421 | // Last finger up. |
| 4422 | processId(mapper, -1); |
| 4423 | processSync(mapper); |
| 4424 | |
| 4425 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4426 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 4427 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); |
| 4428 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); |
| 4429 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4430 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4431 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4432 | |
| 4433 | // Should not have sent any more keys or motions. |
| 4434 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); |
| 4435 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 4439 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4440 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 4441 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4442 | prepareAxes(POSITION | TOUCH | TOOL | PRESSURE | ORIENTATION | ID | MINOR | DISTANCE); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4443 | addMapperAndConfigure(mapper); |
| 4444 | |
| 4445 | // These calculations are based on the input device calibration documentation. |
| 4446 | int32_t rawX = 100; |
| 4447 | int32_t rawY = 200; |
| 4448 | int32_t rawTouchMajor = 7; |
| 4449 | int32_t rawTouchMinor = 6; |
| 4450 | int32_t rawToolMajor = 9; |
| 4451 | int32_t rawToolMinor = 8; |
| 4452 | int32_t rawPressure = 11; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4453 | int32_t rawDistance = 0; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4454 | int32_t rawOrientation = 3; |
| 4455 | int32_t id = 5; |
| 4456 | |
| 4457 | float x = toDisplayX(rawX); |
| 4458 | float y = toDisplayY(rawY); |
| 4459 | float pressure = float(rawPressure) / RAW_PRESSURE_MAX; |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4460 | float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX; |
| 4461 | float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE; |
| 4462 | float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE; |
| 4463 | float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE; |
| 4464 | float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4465 | float orientation = float(rawOrientation) / RAW_ORIENTATION_MAX * M_PI_2; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4466 | float distance = float(rawDistance); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4467 | |
| 4468 | processPosition(mapper, rawX, rawY); |
| 4469 | processTouchMajor(mapper, rawTouchMajor); |
| 4470 | processTouchMinor(mapper, rawTouchMinor); |
| 4471 | processToolMajor(mapper, rawToolMajor); |
| 4472 | processToolMinor(mapper, rawToolMinor); |
| 4473 | processPressure(mapper, rawPressure); |
| 4474 | processOrientation(mapper, rawOrientation); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4475 | processDistance(mapper, rawDistance); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4476 | processId(mapper, id); |
| 4477 | processMTSync(mapper); |
| 4478 | processSync(mapper); |
| 4479 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4480 | NotifyMotionArgs args; |
| 4481 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | 6894a29 | 2011-07-01 17:59:27 -0700 | [diff] [blame] | 4482 | ASSERT_EQ(0, args.pointerProperties[0].id); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4483 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4484 | x, y, pressure, size, touchMajor, touchMinor, toolMajor, toolMinor, |
| 4485 | orientation, distance)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 4489 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4490 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 4491 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4492 | prepareAxes(POSITION | TOUCH | TOOL | MINOR); |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4493 | addConfigurationProperty("touch.size.calibration", "geometric"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4494 | addMapperAndConfigure(mapper); |
| 4495 | |
| 4496 | // These calculations are based on the input device calibration documentation. |
| 4497 | int32_t rawX = 100; |
| 4498 | int32_t rawY = 200; |
| 4499 | int32_t rawTouchMajor = 140; |
| 4500 | int32_t rawTouchMinor = 120; |
| 4501 | int32_t rawToolMajor = 180; |
| 4502 | int32_t rawToolMinor = 160; |
| 4503 | |
| 4504 | float x = toDisplayX(rawX); |
| 4505 | float y = toDisplayY(rawY); |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4506 | float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX; |
| 4507 | float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE; |
| 4508 | float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE; |
| 4509 | float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE; |
| 4510 | float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4511 | |
| 4512 | processPosition(mapper, rawX, rawY); |
| 4513 | processTouchMajor(mapper, rawTouchMajor); |
| 4514 | processTouchMinor(mapper, rawTouchMinor); |
| 4515 | processToolMajor(mapper, rawToolMajor); |
| 4516 | processToolMinor(mapper, rawToolMinor); |
| 4517 | processMTSync(mapper); |
| 4518 | processSync(mapper); |
| 4519 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4520 | NotifyMotionArgs args; |
| 4521 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4522 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4523 | x, y, 1.0f, size, touchMajor, touchMinor, toolMajor, toolMinor, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4526 | TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_SummedLinearCalibration) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 4527 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4528 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 4529 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4530 | prepareAxes(POSITION | TOUCH | TOOL); |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4531 | addConfigurationProperty("touch.size.calibration", "diameter"); |
| 4532 | addConfigurationProperty("touch.size.scale", "10"); |
| 4533 | addConfigurationProperty("touch.size.bias", "160"); |
| 4534 | addConfigurationProperty("touch.size.isSummed", "1"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4535 | addMapperAndConfigure(mapper); |
| 4536 | |
| 4537 | // These calculations are based on the input device calibration documentation. |
| 4538 | // Note: We only provide a single common touch/tool value because the device is assumed |
| 4539 | // not to emit separate values for each pointer (isSummed = 1). |
| 4540 | int32_t rawX = 100; |
| 4541 | int32_t rawY = 200; |
| 4542 | int32_t rawX2 = 150; |
| 4543 | int32_t rawY2 = 250; |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4544 | int32_t rawTouchMajor = 5; |
| 4545 | int32_t rawToolMajor = 8; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4546 | |
| 4547 | float x = toDisplayX(rawX); |
| 4548 | float y = toDisplayY(rawY); |
| 4549 | float x2 = toDisplayX(rawX2); |
| 4550 | float y2 = toDisplayY(rawY2); |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4551 | float size = float(rawTouchMajor) / 2 / RAW_TOUCH_MAX; |
| 4552 | float touch = float(rawTouchMajor) / 2 * 10.0f + 160.0f; |
| 4553 | float tool = float(rawToolMajor) / 2 * 10.0f + 160.0f; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4554 | |
| 4555 | processPosition(mapper, rawX, rawY); |
| 4556 | processTouchMajor(mapper, rawTouchMajor); |
| 4557 | processToolMajor(mapper, rawToolMajor); |
| 4558 | processMTSync(mapper); |
| 4559 | processPosition(mapper, rawX2, rawY2); |
| 4560 | processTouchMajor(mapper, rawTouchMajor); |
| 4561 | processToolMajor(mapper, rawToolMajor); |
| 4562 | processMTSync(mapper); |
| 4563 | processSync(mapper); |
| 4564 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4565 | NotifyMotionArgs args; |
| 4566 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4567 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 4568 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4569 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4570 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 4571 | args.action); |
| 4572 | ASSERT_EQ(size_t(2), args.pointerCount); |
| 4573 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4574 | x, y, 1.0f, size, touch, touch, tool, tool, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4575 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[1], |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4576 | x2, y2, 1.0f, size, touch, touch, tool, tool, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4579 | TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_AreaCalibration) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 4580 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4581 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 4582 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4583 | prepareAxes(POSITION | TOUCH | TOOL); |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4584 | addConfigurationProperty("touch.size.calibration", "area"); |
| 4585 | addConfigurationProperty("touch.size.scale", "43"); |
| 4586 | addConfigurationProperty("touch.size.bias", "3"); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4587 | addMapperAndConfigure(mapper); |
| 4588 | |
| 4589 | // These calculations are based on the input device calibration documentation. |
| 4590 | int32_t rawX = 100; |
| 4591 | int32_t rawY = 200; |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4592 | int32_t rawTouchMajor = 5; |
| 4593 | int32_t rawToolMajor = 8; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4594 | |
| 4595 | float x = toDisplayX(rawX); |
| 4596 | float y = toDisplayY(rawY); |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4597 | float size = float(rawTouchMajor) / RAW_TOUCH_MAX; |
| 4598 | float touch = sqrtf(rawTouchMajor) * 43.0f + 3.0f; |
| 4599 | float tool = sqrtf(rawToolMajor) * 43.0f + 3.0f; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4600 | |
| 4601 | processPosition(mapper, rawX, rawY); |
| 4602 | processTouchMajor(mapper, rawTouchMajor); |
| 4603 | processToolMajor(mapper, rawToolMajor); |
| 4604 | processMTSync(mapper); |
| 4605 | processSync(mapper); |
| 4606 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4607 | NotifyMotionArgs args; |
| 4608 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4609 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
Jeff Brown | a1f89ce | 2011-08-11 00:05:01 -0700 | [diff] [blame] | 4610 | x, y, 1.0f, size, touch, touch, tool, tool, 0, 0)); |
| 4611 | } |
| 4612 | |
| 4613 | TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) { |
| 4614 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
| 4615 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 4616 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 4617 | prepareAxes(POSITION | PRESSURE); |
| 4618 | addConfigurationProperty("touch.pressure.calibration", "amplitude"); |
| 4619 | addConfigurationProperty("touch.pressure.scale", "0.01"); |
| 4620 | addMapperAndConfigure(mapper); |
| 4621 | |
| 4622 | // These calculations are based on the input device calibration documentation. |
| 4623 | int32_t rawX = 100; |
| 4624 | int32_t rawY = 200; |
| 4625 | int32_t rawPressure = 60; |
| 4626 | |
| 4627 | float x = toDisplayX(rawX); |
| 4628 | float y = toDisplayY(rawY); |
| 4629 | float pressure = float(rawPressure) * 0.01f; |
| 4630 | |
| 4631 | processPosition(mapper, rawX, rawY); |
| 4632 | processPressure(mapper, rawPressure); |
| 4633 | processMTSync(mapper); |
| 4634 | processSync(mapper); |
| 4635 | |
| 4636 | NotifyMotionArgs args; |
| 4637 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); |
| 4638 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], |
| 4639 | x, y, pressure, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4642 | TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllButtons) { |
| 4643 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
| 4644 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 4645 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 4646 | prepareAxes(POSITION | ID | SLOT); |
| 4647 | addMapperAndConfigure(mapper); |
| 4648 | |
| 4649 | NotifyMotionArgs motionArgs; |
| 4650 | NotifyKeyArgs keyArgs; |
| 4651 | |
| 4652 | processId(mapper, 1); |
| 4653 | processPosition(mapper, 100, 200); |
| 4654 | processSync(mapper); |
| 4655 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4656 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 4657 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4658 | |
| 4659 | // press BTN_LEFT, release BTN_LEFT |
| 4660 | processKey(mapper, BTN_LEFT, 1); |
| 4661 | processSync(mapper); |
| 4662 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4663 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4664 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); |
| 4665 | |
| 4666 | processKey(mapper, BTN_LEFT, 0); |
| 4667 | processSync(mapper); |
| 4668 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4669 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4670 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4671 | |
| 4672 | // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE |
| 4673 | processKey(mapper, BTN_RIGHT, 1); |
| 4674 | processKey(mapper, BTN_MIDDLE, 1); |
| 4675 | processSync(mapper); |
| 4676 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4677 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4678 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, |
| 4679 | motionArgs.buttonState); |
| 4680 | |
| 4681 | processKey(mapper, BTN_RIGHT, 0); |
| 4682 | processSync(mapper); |
| 4683 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4684 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); |
| 4685 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4686 | |
| 4687 | processKey(mapper, BTN_MIDDLE, 0); |
| 4688 | processSync(mapper); |
| 4689 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4690 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4691 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4692 | |
| 4693 | // press BTN_BACK, release BTN_BACK |
| 4694 | processKey(mapper, BTN_BACK, 1); |
| 4695 | processSync(mapper); |
| 4696 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4697 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 4698 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 4699 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4700 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); |
| 4701 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4702 | |
| 4703 | processKey(mapper, BTN_BACK, 0); |
| 4704 | processSync(mapper); |
| 4705 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4706 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4707 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4708 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4709 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 4710 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 4711 | |
| 4712 | // press BTN_SIDE, release BTN_SIDE |
| 4713 | processKey(mapper, BTN_SIDE, 1); |
| 4714 | processSync(mapper); |
| 4715 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4716 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 4717 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 4718 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4719 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); |
| 4720 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4721 | |
| 4722 | processKey(mapper, BTN_SIDE, 0); |
| 4723 | processSync(mapper); |
| 4724 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4725 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4726 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4727 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4728 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 4729 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); |
| 4730 | |
| 4731 | // press BTN_FORWARD, release BTN_FORWARD |
| 4732 | processKey(mapper, BTN_FORWARD, 1); |
| 4733 | processSync(mapper); |
| 4734 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4735 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 4736 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 4737 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4738 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); |
| 4739 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4740 | |
| 4741 | processKey(mapper, BTN_FORWARD, 0); |
| 4742 | processSync(mapper); |
| 4743 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4744 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4745 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4746 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4747 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 4748 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 4749 | |
| 4750 | // press BTN_EXTRA, release BTN_EXTRA |
| 4751 | processKey(mapper, BTN_EXTRA, 1); |
| 4752 | processSync(mapper); |
| 4753 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4754 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); |
| 4755 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 4756 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4757 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); |
| 4758 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4759 | |
| 4760 | processKey(mapper, BTN_EXTRA, 0); |
| 4761 | processSync(mapper); |
| 4762 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4763 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4764 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4765 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); |
| 4766 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); |
| 4767 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); |
| 4768 | |
| 4769 | // press BTN_STYLUS, release BTN_STYLUS |
| 4770 | processKey(mapper, BTN_STYLUS, 1); |
| 4771 | processSync(mapper); |
| 4772 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4773 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4774 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY, motionArgs.buttonState); |
| 4775 | |
| 4776 | processKey(mapper, BTN_STYLUS, 0); |
| 4777 | processSync(mapper); |
| 4778 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4779 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4780 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4781 | |
| 4782 | // press BTN_STYLUS2, release BTN_STYLUS2 |
| 4783 | processKey(mapper, BTN_STYLUS2, 1); |
| 4784 | processSync(mapper); |
| 4785 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4786 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4787 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); |
| 4788 | |
| 4789 | processKey(mapper, BTN_STYLUS2, 0); |
| 4790 | processSync(mapper); |
| 4791 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4792 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4793 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4794 | |
| 4795 | // release touch |
| 4796 | processId(mapper, -1); |
| 4797 | processSync(mapper); |
| 4798 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4799 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 4800 | ASSERT_EQ(0, motionArgs.buttonState); |
| 4801 | } |
| 4802 | |
| 4803 | TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { |
| 4804 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
| 4805 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 4806 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 4807 | prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); |
| 4808 | addMapperAndConfigure(mapper); |
| 4809 | |
| 4810 | NotifyMotionArgs motionArgs; |
| 4811 | |
| 4812 | // default tool type is finger |
| 4813 | processId(mapper, 1); |
| 4814 | processPosition(mapper, 100, 200); |
| 4815 | processSync(mapper); |
| 4816 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4817 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 4818 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4819 | |
| 4820 | // eraser |
| 4821 | processKey(mapper, BTN_TOOL_RUBBER, 1); |
| 4822 | processSync(mapper); |
| 4823 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4824 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4825 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); |
| 4826 | |
| 4827 | // stylus |
| 4828 | processKey(mapper, BTN_TOOL_RUBBER, 0); |
| 4829 | processKey(mapper, BTN_TOOL_PEN, 1); |
| 4830 | processSync(mapper); |
| 4831 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4832 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4833 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 4834 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 4835 | // brush |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4836 | processKey(mapper, BTN_TOOL_PEN, 0); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 4837 | processKey(mapper, BTN_TOOL_BRUSH, 1); |
| 4838 | processSync(mapper); |
| 4839 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4840 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4841 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 4842 | |
| 4843 | // pencil |
| 4844 | processKey(mapper, BTN_TOOL_BRUSH, 0); |
| 4845 | processKey(mapper, BTN_TOOL_PENCIL, 1); |
| 4846 | processSync(mapper); |
| 4847 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4848 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4849 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 4850 | |
| 4851 | // airbrush |
| 4852 | processKey(mapper, BTN_TOOL_PENCIL, 0); |
| 4853 | processKey(mapper, BTN_TOOL_AIRBRUSH, 1); |
| 4854 | processSync(mapper); |
| 4855 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4856 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4857 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 4858 | |
| 4859 | // mouse |
| 4860 | processKey(mapper, BTN_TOOL_AIRBRUSH, 0); |
| 4861 | processKey(mapper, BTN_TOOL_MOUSE, 1); |
| 4862 | processSync(mapper); |
| 4863 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4864 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4865 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); |
| 4866 | |
| 4867 | // lens |
| 4868 | processKey(mapper, BTN_TOOL_MOUSE, 0); |
| 4869 | processKey(mapper, BTN_TOOL_LENS, 1); |
| 4870 | processSync(mapper); |
| 4871 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4872 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4873 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); |
| 4874 | |
Jeff Brown | ea6892e | 2011-08-23 17:31:25 -0700 | [diff] [blame] | 4875 | // double-tap |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 4876 | processKey(mapper, BTN_TOOL_LENS, 0); |
Jeff Brown | ea6892e | 2011-08-23 17:31:25 -0700 | [diff] [blame] | 4877 | processKey(mapper, BTN_TOOL_DOUBLETAP, 1); |
| 4878 | processSync(mapper); |
| 4879 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4880 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4881 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4882 | |
| 4883 | // triple-tap |
| 4884 | processKey(mapper, BTN_TOOL_DOUBLETAP, 0); |
| 4885 | processKey(mapper, BTN_TOOL_TRIPLETAP, 1); |
| 4886 | processSync(mapper); |
| 4887 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4888 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4889 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4890 | |
| 4891 | // quad-tap |
| 4892 | processKey(mapper, BTN_TOOL_TRIPLETAP, 0); |
| 4893 | processKey(mapper, BTN_TOOL_QUADTAP, 1); |
| 4894 | processSync(mapper); |
| 4895 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4896 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4897 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4898 | |
| 4899 | // finger |
| 4900 | processKey(mapper, BTN_TOOL_QUADTAP, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4901 | processKey(mapper, BTN_TOOL_FINGER, 1); |
| 4902 | processSync(mapper); |
| 4903 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4904 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4905 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4906 | |
| 4907 | // stylus trumps finger |
| 4908 | processKey(mapper, BTN_TOOL_PEN, 1); |
| 4909 | processSync(mapper); |
| 4910 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4911 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4912 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 4913 | |
| 4914 | // eraser trumps stylus |
| 4915 | processKey(mapper, BTN_TOOL_RUBBER, 1); |
| 4916 | processSync(mapper); |
| 4917 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4918 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4919 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); |
| 4920 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 4921 | // mouse trumps eraser |
| 4922 | processKey(mapper, BTN_TOOL_MOUSE, 1); |
| 4923 | processSync(mapper); |
| 4924 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4925 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4926 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); |
| 4927 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4928 | // MT tool type trumps BTN tool types: MT_TOOL_FINGER |
| 4929 | processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE |
| 4930 | processSync(mapper); |
| 4931 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4932 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4933 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4934 | |
| 4935 | // MT tool type trumps BTN tool types: MT_TOOL_PEN |
| 4936 | processToolType(mapper, MT_TOOL_PEN); |
| 4937 | processSync(mapper); |
| 4938 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4939 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4940 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); |
| 4941 | |
| 4942 | // back to default tool type |
| 4943 | processToolType(mapper, -1); // use a deliberately undefined tool type, for testing |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 4944 | processKey(mapper, BTN_TOOL_MOUSE, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4945 | processKey(mapper, BTN_TOOL_RUBBER, 0); |
| 4946 | processKey(mapper, BTN_TOOL_PEN, 0); |
| 4947 | processKey(mapper, BTN_TOOL_FINGER, 0); |
| 4948 | processSync(mapper); |
| 4949 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4950 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); |
| 4951 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); |
| 4952 | } |
| 4953 | |
| 4954 | TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { |
| 4955 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
| 4956 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 4957 | prepareDisplay(DISPLAY_ORIENTATION_0); |
| 4958 | prepareAxes(POSITION | ID | SLOT); |
Jeff Brown | 49ccac5 | 2012-04-11 18:27:33 -0700 | [diff] [blame] | 4959 | mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 4960 | addMapperAndConfigure(mapper); |
| 4961 | |
| 4962 | NotifyMotionArgs motionArgs; |
| 4963 | |
| 4964 | // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0 |
| 4965 | processId(mapper, 1); |
| 4966 | processPosition(mapper, 100, 200); |
| 4967 | processSync(mapper); |
| 4968 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4969 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 4970 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4971 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 4972 | |
| 4973 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4974 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 4975 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4976 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 4977 | |
| 4978 | // move a little |
| 4979 | processPosition(mapper, 150, 250); |
| 4980 | processSync(mapper); |
| 4981 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4982 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 4983 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4984 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 4985 | |
| 4986 | // down when BTN_TOUCH is pressed, pressure defaults to 1 |
| 4987 | processKey(mapper, BTN_TOUCH, 1); |
| 4988 | processSync(mapper); |
| 4989 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4990 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 4991 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4992 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 4993 | |
| 4994 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 4995 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 4996 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 4997 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 4998 | |
| 4999 | // up when BTN_TOUCH is released, hover restored |
| 5000 | processKey(mapper, BTN_TOUCH, 0); |
| 5001 | processSync(mapper); |
| 5002 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5003 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 5004 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 5005 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 5006 | |
| 5007 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5008 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 5009 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 5010 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 5011 | |
| 5012 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5013 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 5014 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 5015 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 5016 | |
| 5017 | // exit hover when pointer goes away |
| 5018 | processId(mapper, -1); |
| 5019 | processSync(mapper); |
| 5020 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5021 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 5022 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 5023 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
| 5024 | } |
| 5025 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5026 | TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfItsValueIsZero) { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5027 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); |
| 5028 | addConfigurationProperty("touch.deviceType", "touchScreen"); |
| 5029 | prepareDisplay(DISPLAY_ORIENTATION_0); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5030 | prepareAxes(POSITION | ID | SLOT | PRESSURE); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5031 | addMapperAndConfigure(mapper); |
| 5032 | |
| 5033 | NotifyMotionArgs motionArgs; |
| 5034 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5035 | // initially hovering because pressure is 0 |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5036 | processId(mapper, 1); |
| 5037 | processPosition(mapper, 100, 200); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5038 | processPressure(mapper, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5039 | processSync(mapper); |
| 5040 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5041 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 5042 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5043 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5044 | |
| 5045 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5046 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 5047 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5048 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5049 | |
| 5050 | // move a little |
| 5051 | processPosition(mapper, 150, 250); |
| 5052 | processSync(mapper); |
| 5053 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5054 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 5055 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5056 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5057 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5058 | // down when pressure becomes non-zero |
| 5059 | processPressure(mapper, RAW_PRESSURE_MAX); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5060 | processSync(mapper); |
| 5061 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5062 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 5063 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5064 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5065 | |
| 5066 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5067 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); |
| 5068 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 5069 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 5070 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5071 | // up when pressure becomes 0, hover restored |
| 5072 | processPressure(mapper, 0); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5073 | processSync(mapper); |
| 5074 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5075 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); |
| 5076 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
| 5077 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); |
| 5078 | |
| 5079 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5080 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); |
| 5081 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5082 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5083 | |
| 5084 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5085 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); |
| 5086 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5087 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5088 | |
| 5089 | // exit hover when pointer goes away |
| 5090 | processId(mapper, -1); |
| 5091 | processSync(mapper); |
| 5092 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); |
| 5093 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); |
| 5094 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 5095 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 5099 | } // namespace android |