diff options
author | 2024-07-12 17:26:56 +0000 | |
---|---|---|
committer | 2024-07-15 14:54:22 +0000 | |
commit | 518695c3d4c081a8ad15dcab78ebca8e162db7c0 (patch) | |
tree | c7e56a86865877163e19d98518334dff0caece84 | |
parent | fe41386f9f3645a2c032dff9b5a152db80777412 (diff) |
Extract SwitchInputMapperTest to its own file
Bug: 245989146
Test: atest frameworks/native/services/inputflinger/tests/SwitchInputMapper_test.cpp
Flag: TEST_ONLY
Change-Id: I7d6eaa72bcee96cf1bf5bce0e4cfdc04c7d0991d
-rw-r--r-- | services/inputflinger/tests/Android.bp | 1 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 43 | ||||
-rw-r--r-- | services/inputflinger/tests/SwitchInputMapper_test.cpp | 71 |
3 files changed, 72 insertions, 43 deletions
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index 65e04291a1..b2fd391218 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -78,6 +78,7 @@ cc_test { "PropertyProvider_test.cpp", "RotaryEncoderInputMapper_test.cpp", "SlopController_test.cpp", + "SwitchInputMapper_test.cpp", "SyncQueue_test.cpp", "TimerProvider_test.cpp", "TestInputListener.cpp", diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 1ba79a9c71..0b780bef88 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -31,7 +31,6 @@ #include <PeripheralController.h> #include <SensorInputMapper.h> #include <SingleTouchInputMapper.h> -#include <SwitchInputMapper.h> #include <TestEventMatchers.h> #include <TestInputListener.h> #include <TouchInputMapper.h> @@ -3063,48 +3062,6 @@ TEST_F(InputDeviceTest, KernelBufferOverflowResetsMappers) { mapper.assertProcessWasCalled(); } -// --- SwitchInputMapperTest --- - -class SwitchInputMapperTest : public InputMapperTest { -protected: -}; - -TEST_F(SwitchInputMapperTest, GetSources) { - SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>(); - - ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper.getSources()); -} - -TEST_F(SwitchInputMapperTest, GetSwitchState) { - SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>(); - - mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 1); - ASSERT_EQ(1, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); - - mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 0); - ASSERT_EQ(0, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); -} - -TEST_F(SwitchInputMapperTest, Process) { - SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>(); - std::list<NotifyArgs> out; - out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_LID, 1); - ASSERT_TRUE(out.empty()); - out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1); - ASSERT_TRUE(out.empty()); - out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_HEADPHONE_INSERT, 0); - ASSERT_TRUE(out.empty()); - out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0); - - ASSERT_EQ(1u, out.size()); - const NotifySwitchArgs& args = std::get<NotifySwitchArgs>(*out.begin()); - ASSERT_EQ(ARBITRARY_TIME, args.eventTime); - ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT), args.switchValues); - ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT), - args.switchMask); - ASSERT_EQ(uint32_t(0), args.policyFlags); -} - // --- VibratorInputMapperTest --- class VibratorInputMapperTest : public InputMapperTest { protected: diff --git a/services/inputflinger/tests/SwitchInputMapper_test.cpp b/services/inputflinger/tests/SwitchInputMapper_test.cpp new file mode 100644 index 0000000000..7b67c01a0e --- /dev/null +++ b/services/inputflinger/tests/SwitchInputMapper_test.cpp @@ -0,0 +1,71 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SwitchInputMapper.h" + +#include <list> +#include <variant> + +#include <NotifyArgs.h> +#include <gtest/gtest.h> +#include <input/Input.h> +#include <linux/input-event-codes.h> + +#include "InputMapperTest.h" + +namespace android { + +class SwitchInputMapperTest : public InputMapperTest { +protected: +}; + +TEST_F(SwitchInputMapperTest, GetSources) { + SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>(); + + ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper.getSources()); +} + +TEST_F(SwitchInputMapperTest, GetSwitchState) { + SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>(); + + mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 1); + ASSERT_EQ(1, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); + + mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 0); + ASSERT_EQ(0, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); +} + +TEST_F(SwitchInputMapperTest, Process) { + SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>(); + std::list<NotifyArgs> out; + out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_LID, 1); + ASSERT_TRUE(out.empty()); + out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1); + ASSERT_TRUE(out.empty()); + out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_HEADPHONE_INSERT, 0); + ASSERT_TRUE(out.empty()); + out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0); + + ASSERT_EQ(1u, out.size()); + const NotifySwitchArgs& args = std::get<NotifySwitchArgs>(*out.begin()); + ASSERT_EQ(ARBITRARY_TIME, args.eventTime); + ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT), args.switchValues); + ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT), + args.switchMask); + ASSERT_EQ(uint32_t(0), args.policyFlags); +} + +} // namespace android
\ No newline at end of file |