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 | |
Siarhei Vishniakou | 8154bbd | 2019-02-15 17:21:03 -0600 | [diff] [blame^] | 70 | // --- Rotate 90 degrees --- |
| 71 | |
| 72 | TEST(TouchVideoFrame, Rotate90_0x0) { |
| 73 | TouchVideoFrame frame(0, 0, {}, TIMESTAMP); |
| 74 | TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP); |
| 75 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 76 | ASSERT_EQ(frame, frameRotated); |
| 77 | } |
| 78 | |
| 79 | TEST(TouchVideoFrame, Rotate90_1x1) { |
| 80 | TouchVideoFrame frame(1, 1, {1}, TIMESTAMP); |
| 81 | TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP); |
| 82 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 83 | ASSERT_EQ(frame, frameRotated); |
| 84 | } |
| 85 | |
| 86 | TEST(TouchVideoFrame, Rotate90_2x2) { |
| 87 | TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP); |
| 88 | TouchVideoFrame frameRotated(2, 2, {3, 1, 4, 2}, TIMESTAMP); |
| 89 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 90 | ASSERT_EQ(frame, frameRotated); |
| 91 | } |
| 92 | |
| 93 | TEST(TouchVideoFrame, Rotate90_3x2) { |
| 94 | TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 95 | TouchVideoFrame frameRotated(2, 3, {5, 3, 1, 6, 4, 2}, TIMESTAMP); |
| 96 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 97 | ASSERT_EQ(frame, frameRotated); |
| 98 | } |
| 99 | |
| 100 | TEST(TouchVideoFrame, Rotate90_3x2_4times) { |
| 101 | TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 102 | TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 103 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 104 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 105 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 106 | frame.rotate(DISPLAY_ORIENTATION_90); |
| 107 | ASSERT_EQ(frame, frameOriginal); |
| 108 | } |
| 109 | |
| 110 | // --- Rotate 180 degrees --- |
| 111 | |
| 112 | TEST(TouchVideoFrame, Rotate180_0x0) { |
| 113 | TouchVideoFrame frame(0, 0, {}, TIMESTAMP); |
| 114 | TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP); |
| 115 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 116 | ASSERT_EQ(frame, frameRotated); |
| 117 | } |
| 118 | |
| 119 | TEST(TouchVideoFrame, Rotate180_1x1) { |
| 120 | TouchVideoFrame frame(1, 1, {1}, TIMESTAMP); |
| 121 | TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP); |
| 122 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 123 | ASSERT_EQ(frame, frameRotated); |
| 124 | } |
| 125 | |
| 126 | TEST(TouchVideoFrame, Rotate180_2x2) { |
| 127 | TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP); |
| 128 | TouchVideoFrame frameRotated(2, 2, {4, 3, 2, 1}, TIMESTAMP); |
| 129 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 130 | ASSERT_EQ(frame, frameRotated); |
| 131 | } |
| 132 | |
| 133 | TEST(TouchVideoFrame, Rotate180_3x2) { |
| 134 | TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 135 | TouchVideoFrame frameRotated(3, 2, {6, 5, 4, 3, 2, 1}, TIMESTAMP); |
| 136 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 137 | ASSERT_EQ(frame, frameRotated); |
| 138 | } |
| 139 | |
| 140 | TEST(TouchVideoFrame, Rotate180_3x2_2times) { |
| 141 | TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 142 | TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 143 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 144 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 145 | ASSERT_EQ(frame, frameOriginal); |
| 146 | } |
| 147 | |
| 148 | TEST(TouchVideoFrame, Rotate180_3x3) { |
| 149 | TouchVideoFrame frame(3, 3, {1, 2, 3, 4, 5, 6, 7, 8, 9}, TIMESTAMP); |
| 150 | TouchVideoFrame frameRotated(3, 3, {9, 8, 7, 6, 5, 4, 3, 2, 1}, TIMESTAMP); |
| 151 | frame.rotate(DISPLAY_ORIENTATION_180); |
| 152 | ASSERT_EQ(frame, frameRotated); |
| 153 | } |
| 154 | |
| 155 | // --- Rotate 270 degrees --- |
| 156 | |
| 157 | TEST(TouchVideoFrame, Rotate270_0x0) { |
| 158 | TouchVideoFrame frame(0, 0, {}, TIMESTAMP); |
| 159 | TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP); |
| 160 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 161 | ASSERT_EQ(frame, frameRotated); |
| 162 | } |
| 163 | |
| 164 | TEST(TouchVideoFrame, Rotate270_1x1) { |
| 165 | TouchVideoFrame frame(1, 1, {1}, TIMESTAMP); |
| 166 | TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP); |
| 167 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 168 | ASSERT_EQ(frame, frameRotated); |
| 169 | } |
| 170 | |
| 171 | TEST(TouchVideoFrame, Rotate270_2x2) { |
| 172 | TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP); |
| 173 | TouchVideoFrame frameRotated(2, 2, {2, 4, 1, 3}, TIMESTAMP); |
| 174 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 175 | ASSERT_EQ(frame, frameRotated); |
| 176 | } |
| 177 | |
| 178 | TEST(TouchVideoFrame, Rotate270_3x2) { |
| 179 | TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 180 | TouchVideoFrame frameRotated(2, 3, {2, 4, 6, 1, 3, 5}, TIMESTAMP); |
| 181 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 182 | ASSERT_EQ(frame, frameRotated); |
| 183 | } |
| 184 | |
| 185 | TEST(TouchVideoFrame, Rotate270_3x2_4times) { |
| 186 | TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 187 | TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); |
| 188 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 189 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 190 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 191 | frame.rotate(DISPLAY_ORIENTATION_270); |
| 192 | ASSERT_EQ(frame, frameOriginal); |
| 193 | } |
| 194 | |
Siarhei Vishniakou | 5ac663d | 2019-02-15 17:15:56 -0600 | [diff] [blame] | 195 | } // namespace test |
| 196 | } // namespace android |