1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstddef>
17 #include "gtest/gtest.h"
18 #include "skia_adapter/skia_matrix.h"
19 #include "utils/matrix.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaMatrixTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void SkiaMatrixTest::SetUpTestCase() {}
TearDownTestCase()36 void SkiaMatrixTest::TearDownTestCase() {}
SetUp()37 void SkiaMatrixTest::SetUp() {}
TearDown()38 void SkiaMatrixTest::TearDown() {}
39
40 /**
41 * @tc.name: Multiply001
42 * @tc.desc:
43 * @tc.type: FUNC
44 * @tc.author:
45 */
46 HWTEST_F(SkiaMatrixTest, Multiply001, TestSize.Level1)
47 {
48 Matrix matrix1;
49 Matrix matrix2;
50 SkiaMatrix skiaMatrix;
51 skiaMatrix.Multiply(matrix1, matrix2);
52 EXPECT_EQ(skiaMatrix.Get(0), 1);
53 }
54
55 /**
56 * @tc.name: MapPoints001
57 * @tc.desc:
58 * @tc.type: FUNC
59 * @tc.author:
60 */
61 HWTEST_F(SkiaMatrixTest, MapPoints001, TestSize.Level1)
62 {
63 PointF point1;
64 PointF point2;
65 std::vector<Point> dst { point1 };
66 std::vector<Point> src { point2 };
67 SkiaMatrix skiaMatrix;
68 skiaMatrix.MapPoints(dst, src, 0);
69 skiaMatrix.MapPoints(dst, src, 1);
70 EXPECT_EQ(skiaMatrix.Get(0), 1);
71 }
72
73 /**
74 * @tc.name: Equals001
75 * @tc.desc:
76 * @tc.type: FUNC
77 * @tc.author:
78 */
79 HWTEST_F(SkiaMatrixTest, Equals001, TestSize.Level1)
80 {
81 Matrix matrix1;
82 Matrix matrix2;
83 SkiaMatrix skiaMatrix;
84 EXPECT_EQ(skiaMatrix.Equals(matrix1, matrix2), true);
85 }
86
87 /**
88 * @tc.name: Scale001
89 * @tc.desc: Test Scale
90 * @tc.type: FUNC
91 * @tc.require: I91EH1
92 */
93 HWTEST_F(SkiaMatrixTest, Scale001, TestSize.Level1)
94 {
95 SkiaMatrix skiaMatrix;
96 skiaMatrix.Scale(2, 2, 2, 2); // 2: sx, sy, px, py
97 }
98
99 /**
100 * @tc.name: PreRotate001
101 * @tc.desc: Test PreRotate
102 * @tc.type: FUNC
103 * @tc.require: I91EH1
104 */
105 HWTEST_F(SkiaMatrixTest, PreRotate001, TestSize.Level1)
106 {
107 SkiaMatrix skiaMatrix;
108 skiaMatrix.PreRotate(90); // 90: degree
109 }
110
111 /**
112 * @tc.name: PreRotate002
113 * @tc.desc: Test PreRotate
114 * @tc.type: FUNC
115 * @tc.require: I91EH1
116 */
117 HWTEST_F(SkiaMatrixTest, PreRotate002, TestSize.Level1)
118 {
119 SkiaMatrix skiaMatrix;
120 skiaMatrix.PreRotate(90, 0, 0); // 90: degree
121 }
122
123 /**
124 * @tc.name: PostRotate001
125 * @tc.desc: Test PostRotate
126 * @tc.type: FUNC
127 * @tc.require: I91EH1
128 */
129 HWTEST_F(SkiaMatrixTest, PostRotate001, TestSize.Level1)
130 {
131 SkiaMatrix skiaMatrix;
132 skiaMatrix.PostRotate(90); // 90: degree
133 }
134
135 /**
136 * @tc.name: PostTranslate001
137 * @tc.desc: Test PostTranslate
138 * @tc.type: FUNC
139 * @tc.require: I91EH1
140 */
141 HWTEST_F(SkiaMatrixTest, PostTranslate001, TestSize.Level1)
142 {
143 SkiaMatrix skiaMatrix;
144 skiaMatrix.PostTranslate(100, 100); // 100: dx, dy
145 }
146
147 /**
148 * @tc.name: PreScale001
149 * @tc.desc: Test PreScale
150 * @tc.type: FUNC
151 * @tc.require: I91EH1
152 */
153 HWTEST_F(SkiaMatrixTest, PreScale001, TestSize.Level1)
154 {
155 SkiaMatrix skiaMatrix;
156 skiaMatrix.PreScale(2, 2); // 2: sx, sy
157 }
158
159 /**
160 * @tc.name: PostScale001
161 * @tc.desc: Test PostScale
162 * @tc.type: FUNC
163 * @tc.require: I91EH1
164 */
165 HWTEST_F(SkiaMatrixTest, PostScale001, TestSize.Level1)
166 {
167 SkiaMatrix skiaMatrix;
168 skiaMatrix.PostScale(2, 2); // 2: sx, sy
169 }
170
171 /**
172 * @tc.name: PreConcat001
173 * @tc.desc: Test PreConcat
174 * @tc.type: FUNC
175 * @tc.require: I91EH1
176 */
177 HWTEST_F(SkiaMatrixTest, PreConcat001, TestSize.Level1)
178 {
179 SkiaMatrix skiaMatrix;
180 Matrix44 matrix44;
181 skiaMatrix.PreConcat(matrix44);
182 }
183
184 /**
185 * @tc.name: PostConcat001
186 * @tc.desc: Test PostConcat
187 * @tc.type: FUNC
188 * @tc.require: I91EH1
189 */
190 HWTEST_F(SkiaMatrixTest, PostConcat001, TestSize.Level1)
191 {
192 SkiaMatrix skiaMatrix;
193 Matrix matrix;
194 skiaMatrix.PostConcat(matrix);
195 }
196
197 /**
198 * @tc.name: PostConcat002
199 * @tc.desc: Test PostConcat
200 * @tc.type: FUNC
201 * @tc.require: I91EH1
202 */
203 HWTEST_F(SkiaMatrixTest, PostConcat002, TestSize.Level1)
204 {
205 SkiaMatrix skiaMatrix;
206 Matrix44 matrix44;
207 skiaMatrix.PostConcat(matrix44);
208 }
209
210 } // namespace Drawing
211 } // namespace Rosen
212 } // namespace OHOS