blob: 7b67c01a0e131fe7fc72c663b44ee9c94ee86383 [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"
28
29namespace android {
30
31class SwitchInputMapperTest : public InputMapperTest {
32protected:
33};
34
35TEST_F(SwitchInputMapperTest, GetSources) {
36 SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();
37
38 ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper.getSources());
39}
40
41TEST_F(SwitchInputMapperTest, GetSwitchState) {
42 SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();
43
44 mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 1);
45 ASSERT_EQ(1, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
46
47 mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 0);
48 ASSERT_EQ(0, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
49}
50
51TEST_F(SwitchInputMapperTest, Process) {
52 SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();
53 std::list<NotifyArgs> out;
54 out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_LID, 1);
55 ASSERT_TRUE(out.empty());
56 out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
57 ASSERT_TRUE(out.empty());
58 out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_HEADPHONE_INSERT, 0);
59 ASSERT_TRUE(out.empty());
60 out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
61
62 ASSERT_EQ(1u, out.size());
63 const NotifySwitchArgs& args = std::get<NotifySwitchArgs>(*out.begin());
64 ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
65 ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT), args.switchValues);
66 ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT),
67 args.switchMask);
68 ASSERT_EQ(uint32_t(0), args.policyFlags);
69}
70
71} // namespace android