blob: 081a995a6f3337e9d2b2d113b5a0a6f570d2ea64 [file] [log] [blame]
Siarhei Vishniakou5ac663d2019-02-15 17:15:56 -06001/*
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
Dominik Laskowski718f9602019-11-09 20:01:35 -080019#include <input/DisplayViewport.h>
Siarhei Vishniakou5ac663d2019-02-15 17:15:56 -060020#include <input/TouchVideoFrame.h>
21
22namespace android {
23namespace test {
24
25static const struct timeval TIMESTAMP = {1, 2};
26
27TEST(TouchVideoFrame, Constructor) {
28 const std::vector<int16_t> data = {1, 2, 3, 4, 5, 6};
29 constexpr uint32_t height = 3;
30 constexpr uint32_t width = 2;
31
32 TouchVideoFrame frame(height, width, data, TIMESTAMP);
33
34 ASSERT_EQ(data, frame.getData());
35 ASSERT_EQ(height, frame.getHeight());
36 ASSERT_EQ(width, frame.getWidth());
37 ASSERT_EQ(TIMESTAMP.tv_sec, frame.getTimestamp().tv_sec);
38 ASSERT_EQ(TIMESTAMP.tv_usec, frame.getTimestamp().tv_usec);
39}
40
41TEST(TouchVideoFrame, Equality) {
42 const std::vector<int16_t> data = {1, 2, 3, 4, 5, 6};
43 constexpr uint32_t height = 3;
44 constexpr uint32_t width = 2;
45 TouchVideoFrame frame(height, width, data, TIMESTAMP);
46
47 TouchVideoFrame identicalFrame(height, width, data, TIMESTAMP);
48 ASSERT_EQ(frame, identicalFrame);
49
50 // The two cases below create an invalid frame, but it is OK for comparison purposes.
51 // There aren't any checks currently enforced on the frame dimensions and data
52 // Change height
53 TouchVideoFrame changedHeightFrame(height + 1, width, data, TIMESTAMP);
54 ASSERT_FALSE(frame == changedHeightFrame);
55
56 // Change width
57 TouchVideoFrame changedWidthFrame(height, width + 1, data, TIMESTAMP);
58 ASSERT_FALSE(frame == changedWidthFrame);
59
60 // Change data
61 const std::vector<int16_t> differentData = {1, 2, 3, 3, 5, 6};
62 TouchVideoFrame changedDataFrame(height, width, differentData, TIMESTAMP);
63 ASSERT_FALSE(frame == changedDataFrame);
64
65 // Change timestamp
66 const struct timeval differentTimestamp = {TIMESTAMP.tv_sec + 1, TIMESTAMP.tv_usec + 1};
67 TouchVideoFrame changedTimestampFrame(height, width, data, differentTimestamp);
68 ASSERT_FALSE(frame == changedTimestampFrame);
69}
70
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060071// --- Rotate 90 degrees ---
72
73TEST(TouchVideoFrame, Rotate90_0x0) {
74 TouchVideoFrame frame(0, 0, {}, TIMESTAMP);
75 TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +000076 frame.rotate(ui::ROTATION_90);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060077 ASSERT_EQ(frame, frameRotated);
78}
79
80TEST(TouchVideoFrame, Rotate90_1x1) {
81 TouchVideoFrame frame(1, 1, {1}, TIMESTAMP);
82 TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +000083 frame.rotate(ui::ROTATION_90);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060084 ASSERT_EQ(frame, frameRotated);
85}
86
87TEST(TouchVideoFrame, Rotate90_2x2) {
88 TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP);
Philip Quinn882bbf32020-02-26 18:48:28 -080089 TouchVideoFrame frameRotated(2, 2, {2, 4, 1, 3}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +000090 frame.rotate(ui::ROTATION_90);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060091 ASSERT_EQ(frame, frameRotated);
92}
93
94TEST(TouchVideoFrame, Rotate90_3x2) {
95 TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
Philip Quinn882bbf32020-02-26 18:48:28 -080096 TouchVideoFrame frameRotated(2, 3, {2, 4, 6, 1, 3, 5}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +000097 frame.rotate(ui::ROTATION_90);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060098 ASSERT_EQ(frame, frameRotated);
99}
100
101TEST(TouchVideoFrame, Rotate90_3x2_4times) {
102 TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
103 TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000104 frame.rotate(ui::ROTATION_90);
105 frame.rotate(ui::ROTATION_90);
106 frame.rotate(ui::ROTATION_90);
107 frame.rotate(ui::ROTATION_90);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600108 ASSERT_EQ(frame, frameOriginal);
109}
110
111// --- Rotate 180 degrees ---
112
113TEST(TouchVideoFrame, Rotate180_0x0) {
114 TouchVideoFrame frame(0, 0, {}, TIMESTAMP);
115 TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000116 frame.rotate(ui::ROTATION_180);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600117 ASSERT_EQ(frame, frameRotated);
118}
119
120TEST(TouchVideoFrame, Rotate180_1x1) {
121 TouchVideoFrame frame(1, 1, {1}, TIMESTAMP);
122 TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000123 frame.rotate(ui::ROTATION_180);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600124 ASSERT_EQ(frame, frameRotated);
125}
126
127TEST(TouchVideoFrame, Rotate180_2x2) {
128 TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP);
129 TouchVideoFrame frameRotated(2, 2, {4, 3, 2, 1}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000130 frame.rotate(ui::ROTATION_180);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600131 ASSERT_EQ(frame, frameRotated);
132}
133
134TEST(TouchVideoFrame, Rotate180_3x2) {
135 TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
136 TouchVideoFrame frameRotated(3, 2, {6, 5, 4, 3, 2, 1}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000137 frame.rotate(ui::ROTATION_180);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600138 ASSERT_EQ(frame, frameRotated);
139}
140
141TEST(TouchVideoFrame, Rotate180_3x2_2times) {
142 TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
143 TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000144 frame.rotate(ui::ROTATION_180);
145 frame.rotate(ui::ROTATION_180);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600146 ASSERT_EQ(frame, frameOriginal);
147}
148
149TEST(TouchVideoFrame, Rotate180_3x3) {
150 TouchVideoFrame frame(3, 3, {1, 2, 3, 4, 5, 6, 7, 8, 9}, TIMESTAMP);
151 TouchVideoFrame frameRotated(3, 3, {9, 8, 7, 6, 5, 4, 3, 2, 1}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000152 frame.rotate(ui::ROTATION_180);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600153 ASSERT_EQ(frame, frameRotated);
154}
155
156// --- Rotate 270 degrees ---
157
158TEST(TouchVideoFrame, Rotate270_0x0) {
159 TouchVideoFrame frame(0, 0, {}, TIMESTAMP);
160 TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000161 frame.rotate(ui::ROTATION_270);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600162 ASSERT_EQ(frame, frameRotated);
163}
164
165TEST(TouchVideoFrame, Rotate270_1x1) {
166 TouchVideoFrame frame(1, 1, {1}, TIMESTAMP);
167 TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000168 frame.rotate(ui::ROTATION_270);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600169 ASSERT_EQ(frame, frameRotated);
170}
171
172TEST(TouchVideoFrame, Rotate270_2x2) {
173 TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP);
Philip Quinn882bbf32020-02-26 18:48:28 -0800174 TouchVideoFrame frameRotated(2, 2, {3, 1, 4, 2}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000175 frame.rotate(ui::ROTATION_270);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600176 ASSERT_EQ(frame, frameRotated);
177}
178
179TEST(TouchVideoFrame, Rotate270_3x2) {
180 TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
Philip Quinn882bbf32020-02-26 18:48:28 -0800181 TouchVideoFrame frameRotated(2, 3, {5, 3, 1, 6, 4, 2}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000182 frame.rotate(ui::ROTATION_270);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600183 ASSERT_EQ(frame, frameRotated);
184}
185
186TEST(TouchVideoFrame, Rotate270_3x2_4times) {
187 TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
188 TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP);
Michael Wrighta9cf4192022-12-01 23:46:39 +0000189 frame.rotate(ui::ROTATION_270);
190 frame.rotate(ui::ROTATION_270);
191 frame.rotate(ui::ROTATION_270);
192 frame.rotate(ui::ROTATION_270);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -0600193 ASSERT_EQ(frame, frameOriginal);
194}
195
Siarhei Vishniakou5ac663d2019-02-15 17:15:56 -0600196} // namespace test
197} // namespace android