blob: ebbf10b8dbaaabc5470c7699b54fee40bdae53d0 [file] [log] [blame]
Harry Cutts518695c2024-07-12 17:26:56 +00001/*
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 Cuttsaa931df2024-07-15 14:54:36 +000028#include "TestConstants.h"
Harry Cutts518695c2024-07-12 17:26:56 +000029
30namespace android {
31
Harry Cuttsaa931df2024-07-15 14:54:36 +000032class SwitchInputMapperTest : public InputMapperUnitTest {
Harry Cutts518695c2024-07-12 17:26:56 +000033protected:
Harry Cuttsaa931df2024-07-15 14:54:36 +000034 void SetUp() override {
35 InputMapperUnitTest::SetUp();
Harry Cuttsaa931df2024-07-15 14:54:36 +000036 mMapper = createInputMapper<SwitchInputMapper>(*mDeviceContext,
37 mFakePolicy->getReaderConfiguration());
38 }
Harry Cutts518695c2024-07-12 17:26:56 +000039};
40
41TEST_F(SwitchInputMapperTest, GetSources) {
Harry Cuttsaa931df2024-07-15 14:54:36 +000042 ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mMapper->getSources());
Harry Cutts518695c2024-07-12 17:26:56 +000043}
44
45TEST_F(SwitchInputMapperTest, GetSwitchState) {
Harry Cuttsaa931df2024-07-15 14:54:36 +000046 setSwitchState(1, {SW_LID});
47 ASSERT_EQ(1, mMapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
Harry Cutts518695c2024-07-12 17:26:56 +000048
Harry Cuttsaa931df2024-07-15 14:54:36 +000049 setSwitchState(0, {SW_LID});
50 ASSERT_EQ(0, mMapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
Harry Cutts518695c2024-07-12 17:26:56 +000051}
52
53TEST_F(SwitchInputMapperTest, Process) {
Harry Cutts518695c2024-07-12 17:26:56 +000054 std::list<NotifyArgs> out;
Harry Cuttsaa931df2024-07-15 14:54:36 +000055 out = process(ARBITRARY_TIME, EV_SW, SW_LID, 1);
Harry Cutts518695c2024-07-12 17:26:56 +000056 ASSERT_TRUE(out.empty());
Harry Cuttsaa931df2024-07-15 14:54:36 +000057 out = process(ARBITRARY_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
Harry Cutts518695c2024-07-12 17:26:56 +000058 ASSERT_TRUE(out.empty());
Harry Cuttsaa931df2024-07-15 14:54:36 +000059 out = process(ARBITRARY_TIME, EV_SW, SW_HEADPHONE_INSERT, 0);
Harry Cutts518695c2024-07-12 17:26:56 +000060 ASSERT_TRUE(out.empty());
Harry Cuttsaa931df2024-07-15 14:54:36 +000061 out = process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
Harry Cutts518695c2024-07-12 17:26:56 +000062
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