1 /*
2 * Copyright 2021 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 <ui/Transform.h>
18
19 #include <gtest/gtest.h>
20
21 namespace android::ui {
22
TEST(TransformTest,inverseRotation_hasCorrectType)23 TEST(TransformTest, inverseRotation_hasCorrectType) {
24 const auto testRotationFlagsForInverse = [](Transform::RotationFlags rotation,
25 Transform::RotationFlags expectedInverse,
26 bool isRotation) {
27 const Transform t(rotation, 0, 0);
28 EXPECT_EQ(t.getOrientation(), rotation);
29 const Transform inverse = t.inverse();
30 EXPECT_EQ(inverse.getOrientation(), expectedInverse);
31
32 if (isRotation) {
33 EXPECT_TRUE(t.getType() & Transform::ROTATE);
34 EXPECT_TRUE(inverse.getType() & Transform::ROTATE);
35 } else {
36 EXPECT_FALSE(t.getType() & Transform::ROTATE);
37 EXPECT_FALSE(inverse.getType() & Transform::ROTATE);
38 }
39 };
40
41 testRotationFlagsForInverse(Transform::ROT_0, Transform::ROT_0, false);
42 testRotationFlagsForInverse(Transform::ROT_90, Transform::ROT_270, true);
43 testRotationFlagsForInverse(Transform::ROT_180, Transform::ROT_180, true);
44 testRotationFlagsForInverse(Transform::ROT_270, Transform::ROT_90, true);
45 testRotationFlagsForInverse(Transform::FLIP_H, Transform::FLIP_H, false);
46 testRotationFlagsForInverse(Transform::FLIP_V, Transform::FLIP_V, false);
47 }
48
49 } // namespace android::ui
50