• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
211  * @tc.name: SetMatrix001
212  * @tc.desc: Test SetMatrix
213  * @tc.type: FUNC
214  * @tc.require: I91EH1
215  */
216 HWTEST_F(SkiaMatrixTest, SetMatrix001, TestSize.Level1)
217 {
218     SkiaMatrix skiaMatrix;
219     skiaMatrix.SetMatrix(5, 5, 5, 5, 5, 5, 5, 5, 5);
220     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 5);
221     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_X) == 5);
222     ASSERT_TRUE(skiaMatrix.Get(Matrix::SCALE_X) == 5);
223     ASSERT_TRUE(skiaMatrix.Get(Matrix::SCALE_Y) == 5);
224     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_X) == 5);
225     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_Y) == 5);
226 }
227 
228 /**
229  * @tc.name: SetSkew001
230  * @tc.desc: Test SetSkew
231  * @tc.type: FUNC
232  * @tc.require: I91EH1
233  */
234 HWTEST_F(SkiaMatrixTest, SetSkew001, TestSize.Level1)
235 {
236     SkiaMatrix skiaMatrix;
237     skiaMatrix.SetSkew(10.0, 10.0);
238     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 10);
239     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_Y) == 10);
240 }
241 
242 /**
243  * @tc.name: SetSkew002
244  * @tc.desc: Test SetSkew
245  * @tc.type: FUNC
246  * @tc.require: I91EH1
247  */
248 HWTEST_F(SkiaMatrixTest, SetSkew002, TestSize.Level1)
249 {
250     SkiaMatrix skiaMatrix;
251     skiaMatrix.SetSkew(10.0, 10.0, 20.0, 20);
252     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 10);
253     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_Y) == 10);
254     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_X) == -10*20);
255     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_Y) == -10*20);
256 }
257 
258 /**
259  * @tc.name: PreSkew001
260  * @tc.desc: Test PreSkew
261  * @tc.type: FUNC
262  * @tc.require: I91EH1
263  */
264 HWTEST_F(SkiaMatrixTest, PreSkew001, TestSize.Level1)
265 {
266     SkiaMatrix skiaMatrix;
267     skiaMatrix.PreSkew(5.0, 5.0);
268     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 5);
269     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_Y) == 5);
270 }
271 
272 /**
273  * @tc.name: PreSkew002
274  * @tc.desc: Test PreSkew
275  * @tc.type: FUNC
276  * @tc.require: I91EH1
277  */
278 HWTEST_F(SkiaMatrixTest, PreSkew002, TestSize.Level1)
279 {
280     SkiaMatrix skiaMatrix;
281     skiaMatrix.PreSkew(10.0, 10.0, 20.0, 20);
282     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 10);
283     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_Y) == 10);
284     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_X) == -10*20);
285     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_Y) == -10*20);
286 }
287 
288 /**
289  * @tc.name: PostSkew001
290  * @tc.desc: Test PostSkew
291  * @tc.type: FUNC
292  * @tc.require: I91EH1
293  */
294 HWTEST_F(SkiaMatrixTest, PostSkew001, TestSize.Level1)
295 {
296     SkiaMatrix skiaMatrix;
297     skiaMatrix.PostSkew(5.0, 5.0);
298     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 5);
299     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_Y) == 5);
300 }
301 
302 /**
303  * @tc.name: PostSkew002
304  * @tc.desc: Test PostSkew
305  * @tc.type: FUNC
306  * @tc.require: I91EH1
307  */
308 HWTEST_F(SkiaMatrixTest, PostSkew002, TestSize.Level1)
309 {
310     SkiaMatrix skiaMatrix;
311     skiaMatrix.PostSkew(10.0, 10.0, 20.0, 20);
312     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_X) == 10);
313     ASSERT_TRUE(skiaMatrix.Get(Matrix::SKEW_Y) == 10);
314     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_X) == -10*20);
315     ASSERT_TRUE(skiaMatrix.Get(Matrix::TRANS_Y) == -10*20);
316 }
317 
318 /**
319  * @tc.name: Invert001
320  * @tc.desc: Test Invert
321  * @tc.type: FUNC
322  * @tc.require: I91EH1
323  */
324 HWTEST_F(SkiaMatrixTest, Invert001, TestSize.Level1)
325 {
326     SkiaMatrix skiaMatrix;
327     Matrix inverse;
328     ASSERT_TRUE(skiaMatrix.Invert(inverse) == true);
329 }
330 
331 } // namespace Drawing
332 } // namespace Rosen
333 } // namespace OHOS