diff options
author | 2019-02-15 17:15:56 -0600 | |
---|---|---|
committer | 2019-02-15 20:23:17 -0600 | |
commit | 5ac663d1fd27b42c550b660024b22524d082efd5 (patch) | |
tree | e5695a4eaa902a145588420f354c8fc547bdaacc | |
parent | fda3aee5b7b17bc64e66e1f6f7aaa7d2e3ac1419 (diff) |
Add tests for TouchVideoFrame
These tests are pretty basic for now, but will include rotation tests in
the future.
Test: atest libinput_tests
Bug: 123241238
Change-Id: Ie0c5282d25208cd91b2d0ce583516d562b8b115f
-rw-r--r-- | libs/input/Android.bp | 8 | ||||
-rw-r--r-- | libs/input/tests/Android.bp | 3 | ||||
-rw-r--r-- | libs/input/tests/TouchVideoFrame_test.cpp | 71 |
3 files changed, 77 insertions, 5 deletions
diff --git a/libs/input/Android.bp b/libs/input/Android.bp index 1172864df9..6aedb000c8 100644 --- a/libs/input/Android.bp +++ b/libs/input/Android.bp @@ -28,8 +28,8 @@ cc_library { "Keyboard.cpp", "KeyCharacterMap.cpp", "KeyLayoutMap.cpp", - "VirtualKeyMap.cpp", "TouchVideoFrame.cpp", + "VirtualKeyMap.cpp", ], clang: true, @@ -43,12 +43,12 @@ cc_library { target: { android: { srcs: [ + "IInputFlinger.cpp", + "InputApplication.cpp", "InputTransport.cpp", + "InputWindow.cpp", "VelocityControl.cpp", "VelocityTracker.cpp", - "InputApplication.cpp", - "InputWindow.cpp", - "IInputFlinger.cpp" ], shared_libs: [ diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp index fdd945e90e..57ba2a25a8 100644 --- a/libs/input/tests/Android.bp +++ b/libs/input/tests/Android.bp @@ -5,8 +5,9 @@ cc_test { "InputChannel_test.cpp", "InputEvent_test.cpp", "InputPublisherAndConsumer_test.cpp", + "InputWindow_test.cpp", + "TouchVideoFrame_test.cpp", "VelocityTracker_test.cpp", - "InputWindow_test.cpp" ], cflags: [ "-Wall", diff --git a/libs/input/tests/TouchVideoFrame_test.cpp b/libs/input/tests/TouchVideoFrame_test.cpp new file mode 100644 index 0000000000..3c1c7f3295 --- /dev/null +++ b/libs/input/tests/TouchVideoFrame_test.cpp @@ -0,0 +1,71 @@ +/* + * Copyright 2019 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 <gtest/gtest.h> + +#include <input/TouchVideoFrame.h> + +namespace android { +namespace test { + +static const struct timeval TIMESTAMP = {1, 2}; + +TEST(TouchVideoFrame, Constructor) { + const std::vector<int16_t> data = {1, 2, 3, 4, 5, 6}; + constexpr uint32_t height = 3; + constexpr uint32_t width = 2; + + TouchVideoFrame frame(height, width, data, TIMESTAMP); + + ASSERT_EQ(data, frame.getData()); + ASSERT_EQ(height, frame.getHeight()); + ASSERT_EQ(width, frame.getWidth()); + ASSERT_EQ(TIMESTAMP.tv_sec, frame.getTimestamp().tv_sec); + ASSERT_EQ(TIMESTAMP.tv_usec, frame.getTimestamp().tv_usec); +} + +TEST(TouchVideoFrame, Equality) { + const std::vector<int16_t> data = {1, 2, 3, 4, 5, 6}; + constexpr uint32_t height = 3; + constexpr uint32_t width = 2; + TouchVideoFrame frame(height, width, data, TIMESTAMP); + + TouchVideoFrame identicalFrame(height, width, data, TIMESTAMP); + ASSERT_EQ(frame, identicalFrame); + + // The two cases below create an invalid frame, but it is OK for comparison purposes. + // There aren't any checks currently enforced on the frame dimensions and data + // Change height + TouchVideoFrame changedHeightFrame(height + 1, width, data, TIMESTAMP); + ASSERT_FALSE(frame == changedHeightFrame); + + // Change width + TouchVideoFrame changedWidthFrame(height, width + 1, data, TIMESTAMP); + ASSERT_FALSE(frame == changedWidthFrame); + + // Change data + const std::vector<int16_t> differentData = {1, 2, 3, 3, 5, 6}; + TouchVideoFrame changedDataFrame(height, width, differentData, TIMESTAMP); + ASSERT_FALSE(frame == changedDataFrame); + + // Change timestamp + const struct timeval differentTimestamp = {TIMESTAMP.tv_sec + 1, TIMESTAMP.tv_usec + 1}; + TouchVideoFrame changedTimestampFrame(height, width, data, differentTimestamp); + ASSERT_FALSE(frame == changedTimestampFrame); +} + +} // namespace test +} // namespace android |