Harry Cutts | e6512e1 | 2022-11-28 18:44:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <list> |
| 20 | #include <memory> |
| 21 | |
| 22 | #include <InputDevice.h> |
| 23 | #include <InputMapper.h> |
| 24 | #include <NotifyArgs.h> |
| 25 | #include <ftl/flags.h> |
| 26 | #include <utils/StrongPointer.h> |
| 27 | |
| 28 | #include "FakeEventHub.h" |
| 29 | #include "FakeInputReaderPolicy.h" |
| 30 | #include "InstrumentedInputReader.h" |
| 31 | #include "TestConstants.h" |
| 32 | #include "TestInputListener.h" |
| 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | class InputMapperTest : public testing::Test { |
| 37 | protected: |
| 38 | static const char* DEVICE_NAME; |
| 39 | static const char* DEVICE_LOCATION; |
| 40 | static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; |
| 41 | static constexpr int32_t DEVICE_GENERATION = 2; |
| 42 | static constexpr int32_t DEVICE_CONTROLLER_NUMBER = 0; |
| 43 | static const ftl::Flags<InputDeviceClass> DEVICE_CLASSES; |
| 44 | static constexpr int32_t EVENTHUB_ID = 1; |
| 45 | |
| 46 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 47 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 48 | std::unique_ptr<TestInputListener> mFakeListener; |
| 49 | std::unique_ptr<InstrumentedInputReader> mReader; |
| 50 | std::shared_ptr<InputDevice> mDevice; |
| 51 | |
| 52 | virtual void SetUp(ftl::Flags<InputDeviceClass> classes, int bus = 0); |
| 53 | void SetUp() override; |
| 54 | void TearDown() override; |
| 55 | |
| 56 | void addConfigurationProperty(const char* key, const char* value); |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame^] | 57 | std::list<NotifyArgs> configureDevice(ConfigurationChanges changes); |
Harry Cutts | e6512e1 | 2022-11-28 18:44:01 +0000 | [diff] [blame] | 58 | std::shared_ptr<InputDevice> newDevice(int32_t deviceId, const std::string& name, |
| 59 | const std::string& location, int32_t eventHubId, |
| 60 | ftl::Flags<InputDeviceClass> classes, int bus = 0); |
| 61 | template <class T, typename... Args> |
| 62 | T& addMapperAndConfigure(Args... args) { |
Arpit Singh | 8e6fb25 | 2023-04-06 11:49:17 +0000 | [diff] [blame] | 63 | T& mapper = |
| 64 | mDevice->addMapper<T>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(), args...); |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame^] | 65 | configureDevice(/*changes=*/{}); |
Harry Cutts | e6512e1 | 2022-11-28 18:44:01 +0000 | [diff] [blame] | 66 | std::list<NotifyArgs> resetArgList = mDevice->reset(ARBITRARY_TIME); |
| 67 | resetArgList += mapper.reset(ARBITRARY_TIME); |
| 68 | // Loop the reader to flush the input listener queue. |
| 69 | for (const NotifyArgs& loopArgs : resetArgList) { |
| 70 | mFakeListener->notify(loopArgs); |
| 71 | } |
| 72 | mReader->loopOnce(); |
| 73 | return mapper; |
| 74 | } |
| 75 | |
| 76 | void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, |
| 77 | ui::Rotation orientation, const std::string& uniqueId, |
| 78 | std::optional<uint8_t> physicalPort, |
| 79 | ViewportType viewportType); |
| 80 | void clearViewports(); |
| 81 | std::list<NotifyArgs> process(InputMapper& mapper, nsecs_t when, nsecs_t readTime, int32_t type, |
| 82 | int32_t code, int32_t value); |
| 83 | void resetMapper(InputMapper& mapper, nsecs_t when); |
| 84 | |
| 85 | std::list<NotifyArgs> handleTimeout(InputMapper& mapper, nsecs_t when); |
| 86 | |
| 87 | static void assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source, |
| 88 | float min, float max, float flat, float fuzz); |
| 89 | static void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure, |
| 90 | float size, float touchMajor, float touchMinor, float toolMajor, |
| 91 | float toolMinor, float orientation, float distance, |
| 92 | float scaledAxisEpsilon = 1.f); |
Harry Cutts | e6512e1 | 2022-11-28 18:44:01 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace android |