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

Commit c1072d30 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add tests for TouchVideoFrame"

parents 74309c60 5ac663d1
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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: [
+2 −1
Original line number Diff line number Diff line
@@ -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",
+71 −0
Original line number Diff line number Diff line
/*
 * 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