Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "SwitchInputMapper.h" |
| 18 | |
| 19 | #include <list> |
| 20 | #include <variant> |
| 21 | |
| 22 | #include <NotifyArgs.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | #include <input/Input.h> |
| 25 | #include <linux/input-event-codes.h> |
| 26 | |
| 27 | #include "InputMapperTest.h" |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 28 | #include "TestConstants.h" |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 32 | class SwitchInputMapperTest : public InputMapperUnitTest { |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 33 | protected: |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 34 | void SetUp() override { |
| 35 | InputMapperUnitTest::SetUp(); |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 36 | mMapper = createInputMapper<SwitchInputMapper>(*mDeviceContext, |
| 37 | mFakePolicy->getReaderConfiguration()); |
| 38 | } |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | TEST_F(SwitchInputMapperTest, GetSources) { |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 42 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mMapper->getSources()); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | TEST_F(SwitchInputMapperTest, GetSwitchState) { |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 46 | setSwitchState(1, {SW_LID}); |
| 47 | ASSERT_EQ(1, mMapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 48 | |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 49 | setSwitchState(0, {SW_LID}); |
| 50 | ASSERT_EQ(0, mMapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | TEST_F(SwitchInputMapperTest, Process) { |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 54 | std::list<NotifyArgs> out; |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 55 | out = process(ARBITRARY_TIME, EV_SW, SW_LID, 1); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 56 | ASSERT_TRUE(out.empty()); |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 57 | out = process(ARBITRARY_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 58 | ASSERT_TRUE(out.empty()); |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 59 | out = process(ARBITRARY_TIME, EV_SW, SW_HEADPHONE_INSERT, 0); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 60 | ASSERT_TRUE(out.empty()); |
Harry Cutts | aa931df | 2024-07-15 14:54:36 +0000 | [diff] [blame] | 61 | out = process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); |
Harry Cutts | 518695c | 2024-07-12 17:26:56 +0000 | [diff] [blame] | 62 | |
| 63 | ASSERT_EQ(1u, out.size()); |
| 64 | const NotifySwitchArgs& args = std::get<NotifySwitchArgs>(*out.begin()); |
| 65 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); |
| 66 | ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT), args.switchValues); |
| 67 | ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT), |
| 68 | args.switchMask); |
| 69 | ASSERT_EQ(uint32_t(0), args.policyFlags); |
| 70 | } |
| 71 | |
| 72 | } // namespace android |