Siarhei Vishniakou | 5ac663d | 2019-02-15 17:15:56 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include <input/TouchVideoFrame.h> |
| 20 | |
| 21 | namespace android { |
| 22 | namespace test { |
| 23 | |
| 24 | static const struct timeval TIMESTAMP = {1, 2}; |
| 25 | |
| 26 | TEST(TouchVideoFrame, Constructor) { |
| 27 | const std::vector<int16_t> data = {1, 2, 3, 4, 5, 6}; |
| 28 | constexpr uint32_t height = 3; |
| 29 | constexpr uint32_t width = 2; |
| 30 | |
| 31 | TouchVideoFrame frame(height, width, data, TIMESTAMP); |
| 32 | |
| 33 | ASSERT_EQ(data, frame.getData()); |
| 34 | ASSERT_EQ(height, frame.getHeight()); |
| 35 | ASSERT_EQ(width, frame.getWidth()); |
| 36 | ASSERT_EQ(TIMESTAMP.tv_sec, frame.getTimestamp().tv_sec); |
| 37 | ASSERT_EQ(TIMESTAMP.tv_usec, frame.getTimestamp().tv_usec); |
| 38 | } |
| 39 | |
| 40 | TEST(TouchVideoFrame, Equality) { |
| 41 | const std::vector<int16_t> data = {1, 2, 3, 4, 5, 6}; |
| 42 | constexpr uint32_t height = 3; |
| 43 | constexpr uint32_t width = 2; |
| 44 | TouchVideoFrame frame(height, width, data, TIMESTAMP); |
| 45 | |
| 46 | TouchVideoFrame identicalFrame(height, width, data, TIMESTAMP); |
| 47 | ASSERT_EQ(frame, identicalFrame); |
| 48 | |
| 49 | // The two cases below create an invalid frame, but it is OK for comparison purposes. |
| 50 | // There aren't any checks currently enforced on the frame dimensions and data |
| 51 | // Change height |
| 52 | TouchVideoFrame changedHeightFrame(height + 1, width, data, TIMESTAMP); |
| 53 | ASSERT_FALSE(frame == changedHeightFrame); |
| 54 | |
| 55 | // Change width |
| 56 | TouchVideoFrame changedWidthFrame(height, width + 1, data, TIMESTAMP); |
| 57 | ASSERT_FALSE(frame == changedWidthFrame); |
| 58 | |
| 59 | // Change data |
| 60 | const std::vector<int16_t> differentData = {1, 2, 3, 3, 5, 6}; |
| 61 | TouchVideoFrame changedDataFrame(height, width, differentData, TIMESTAMP); |
| 62 | ASSERT_FALSE(frame == changedDataFrame); |
| 63 | |
| 64 | // Change timestamp |
| 65 | const struct timeval differentTimestamp = {TIMESTAMP.tv_sec + 1, TIMESTAMP.tv_usec + 1}; |
| 66 | TouchVideoFrame changedTimestampFrame(height, width, data, differentTimestamp); |
| 67 | ASSERT_FALSE(frame == changedTimestampFrame); |
| 68 | } |
| 69 | |
| 70 | } // namespace test |
| 71 | } // namespace android |