1/*
2 * Copyright (C) 2016 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 "Matrix.h"
20#include "Rect.h"
21
22using namespace android::uirenderer;
23
24TEST(Matrix, mapRect_emptyScaleSkew) {
25    // Skew, so we don't hit identity/translate/simple fast paths
26    Matrix4 scaleMatrix;
27    scaleMatrix.loadScale(10, 10, 1);
28    scaleMatrix.skew(0.1f, 0.1f);
29
30    // non-zero empty rect, so sorting x/y would make rect non-empty
31    Rect empty(15, 20, 15, 100);
32    ASSERT_TRUE(empty.isEmpty());
33    scaleMatrix.mapRect(empty);
34    EXPECT_EQ(Rect(170, 215, 250, 1015), empty);
35    EXPECT_FALSE(empty.isEmpty())
36        << "Empty 'line' rect doesn't remain empty when skewed.";
37}
38
39TEST(Matrix, mapRect_emptyRotate) {
40    // Skew, so we don't hit identity/translate/simple fast paths
41    Matrix4 skewMatrix;
42    skewMatrix.loadRotate(45);
43
44    // non-zero empty rect, so sorting x/y would make rect non-empty
45    Rect lineRect(0, 100);
46    ASSERT_TRUE(lineRect.isEmpty());
47    skewMatrix.mapRect(lineRect);
48    EXPECT_FALSE(lineRect.isEmpty())
49        << "Empty 'line' rect doesn't remain empty when rotated.";
50}
51