Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa931dfc authored by Harry Cutts's avatar Harry Cutts
Browse files

SwitchInputMapperTest: migrate to InputMapperUnitTest

Bug: 283812079
Test: atest frameworks/native/services/inputflinger/tests/SwitchInputMapper_test.cpp
Flag: TEST_ONLY
Change-Id: I9f7542231c09a02bf31bb59297a51f1b9e698fac
parent 518695c3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -89,6 +89,13 @@ void InputMapperUnitTest::setKeyCodeState(KeyState state, std::set<int> keyCodes
    }
}

void InputMapperUnitTest::setSwitchState(int32_t state, std::set<int32_t> switchCodes) {
    for (const auto& switchCode : switchCodes) {
        EXPECT_CALL(mMockEventHub, getSwitchState(EVENTHUB_ID, switchCode))
                .WillRepeatedly(testing::Return(static_cast<int>(state)));
    }
}

std::list<NotifyArgs> InputMapperUnitTest::process(int32_t type, int32_t code, int32_t value) {
    nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
    return process(when, type, code, value);
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ protected:

    void setKeyCodeState(KeyState state, std::set<int> keyCodes);

    void setSwitchState(int32_t state, std::set<int32_t> switchCodes);

    std::list<NotifyArgs> process(int32_t type, int32_t code, int32_t value);
    std::list<NotifyArgs> process(nsecs_t when, int32_t type, int32_t code, int32_t value);

+17 −15
Original line number Diff line number Diff line
@@ -25,39 +25,41 @@
#include <linux/input-event-codes.h>

#include "InputMapperTest.h"
#include "TestConstants.h"

namespace android {

class SwitchInputMapperTest : public InputMapperTest {
class SwitchInputMapperTest : public InputMapperUnitTest {
protected:
    void SetUp() override {
        InputMapperUnitTest::SetUp();
        createDevice();
        mMapper = createInputMapper<SwitchInputMapper>(*mDeviceContext,
                                                       mFakePolicy->getReaderConfiguration());
    }
};

TEST_F(SwitchInputMapperTest, GetSources) {
    SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();

    ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper.getSources());
    ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mMapper->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));
    setSwitchState(1, {SW_LID});
    ASSERT_EQ(1, mMapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));

    mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 0);
    ASSERT_EQ(0, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
    setSwitchState(0, {SW_LID});
    ASSERT_EQ(0, mMapper->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);
    out = process(ARBITRARY_TIME, EV_SW, SW_LID, 1);
    ASSERT_TRUE(out.empty());
    out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
    out = process(ARBITRARY_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);
    out = process(ARBITRARY_TIME, EV_SW, SW_HEADPHONE_INSERT, 0);
    ASSERT_TRUE(out.empty());
    out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
    out = process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);

    ASSERT_EQ(1u, out.size());
    const NotifySwitchArgs& args = std::get<NotifySwitchArgs>(*out.begin());