diff options
Diffstat (limited to 'libs/input/tests/InputDevice_test.cpp')
-rw-r--r-- | libs/input/tests/InputDevice_test.cpp | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/libs/input/tests/InputDevice_test.cpp b/libs/input/tests/InputDevice_test.cpp index c174ae94a6..f8f2f4e931 100644 --- a/libs/input/tests/InputDevice_test.cpp +++ b/libs/input/tests/InputDevice_test.cpp @@ -14,9 +14,12 @@ * limitations under the License. */ - +#include <binder/Binder.h> +#include <binder/Parcel.h> #include <gtest/gtest.h> #include <input/InputDevice.h> +#include <input/KeyLayoutMap.h> +#include <input/Keyboard.h> namespace android { @@ -31,4 +34,52 @@ TEST(InputDeviceIdentifierTest, getCanonicalName) { ASSERT_EQ(std::string("deviceName-123_version_C_"), identifier.getCanonicalName()); } -} // namespace android
\ No newline at end of file +class InputDeviceKeyMapTest : public testing::Test { +protected: + void loadKeyLayout(const char* name) { + std::string path = + getInputDeviceConfigurationFilePathByName(name, + InputDeviceConfigurationFileType:: + KEY_LAYOUT); + ASSERT_FALSE(path.empty()); + base::Result<std::shared_ptr<KeyLayoutMap>> ret = KeyLayoutMap::load(path); + ASSERT_TRUE(ret.ok()) << "Cannot load KeyLayout at " << path; + mKeyMap.keyLayoutMap = std::move(*ret); + mKeyMap.keyLayoutFile = path; + } + + void loadKeyCharacterMap(const char* name) { + InputDeviceIdentifier identifier; + identifier.name = name; + std::string path = + getInputDeviceConfigurationFilePathByName(identifier.getCanonicalName(), + InputDeviceConfigurationFileType:: + KEY_CHARACTER_MAP); + ASSERT_FALSE(path.empty()) << "KeyCharacterMap for " << name << " not found"; + base::Result<std::shared_ptr<KeyCharacterMap>> ret = + KeyCharacterMap::load(path, KeyCharacterMap::Format::BASE); + ASSERT_TRUE(ret.ok()) << "Cannot load KeyCharacterMap at " << path; + mKeyMap.keyCharacterMap = *ret; + mKeyMap.keyCharacterMapFile = path; + } + + virtual void SetUp() override { + loadKeyLayout("Generic"); + loadKeyCharacterMap("Generic"); + } + + virtual void TearDown() override {} + + KeyMap mKeyMap; +}; + +TEST_F(InputDeviceKeyMapTest, keyCharacterMapParcelingTest) { + Parcel parcel; + mKeyMap.keyCharacterMap->writeToParcel(&parcel); + parcel.setDataPosition(0); + std::shared_ptr<KeyCharacterMap> map = KeyCharacterMap::readFromParcel(&parcel); + // Verify the key character map is the same as original + ASSERT_EQ(*map, *mKeyMap.keyCharacterMap); +} + +} // namespace android |