• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 <gtest/gtest.h>
17 #include "image_type.h"
18 #include "matrix.h"
19 
20 using namespace testing::ext;
21 using namespace OHOS::Media;
22 namespace OHOS {
23 namespace Multimedia {
24 class MatrixTest : public testing::Test {
25 public:
MatrixTest()26     MatrixTest() {}
~MatrixTest()27     ~MatrixTest() {}
28 };
29 
30 /**
31  * @tc.name: MatrixTest001
32  * @tc.desc: SetTranslate
33  * @tc.type: FUNC
34  */
35 HWTEST_F(MatrixTest, MatrixTest001, TestSize.Level3)
36 {
37     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest001 start";
38     Matrix matrix_;
39     float tx = 1;
40     float ty = 1;
41     matrix_.SetTranslate(tx, ty);
42     ASSERT_EQ(matrix_.GetTransX(), tx);
43     ASSERT_EQ(matrix_.GetTranY(), ty);
44     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest001 end";
45 }
46 
47 /**
48  * @tc.name: MatrixTest002
49  * @tc.desc: SetTranslate
50  * @tc.type: FUNC
51  */
52 HWTEST_F(MatrixTest, MatrixTest002, TestSize.Level3)
53 {
54     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest002 start";
55     Matrix matrix_;
56     float tx = 0;
57     float ty = 1;
58     matrix_.SetTranslate(tx, ty);
59     ASSERT_EQ(matrix_.GetTransX(), tx);
60     ASSERT_EQ(matrix_.GetTranY(), ty);
61     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest002 end";
62 }
63 
64 /**
65  * @tc.name: MatrixTest003
66  * @tc.desc: SetTranslate
67  * @tc.type: FUNC
68  */
69 HWTEST_F(MatrixTest, MatrixTest003, TestSize.Level3)
70 {
71     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest003 start";
72     Matrix matrix_;
73     float tx = 1;
74     float ty = 0;
75     matrix_.SetTranslate(tx, ty);
76     ASSERT_EQ(matrix_.GetTransX(), tx);
77     ASSERT_EQ(matrix_.GetTranY(), ty);
78     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest003 end";
79 }
80 
81 /**
82  * @tc.name: MatrixTest004
83  * @tc.desc: SetScale
84  * @tc.type: FUNC
85  */
86 HWTEST_F(MatrixTest, MatrixTest004, TestSize.Level3)
87 {
88     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest004 start";
89     Matrix matrix_;
90     float tx = 1;
91     float ty = 1;
92     matrix_.SetScale(tx, ty);
93     ASSERT_EQ(matrix_.GetScaleX(), tx);
94     ASSERT_EQ(matrix_.GetScaleY(), ty);
95     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest004 end";
96 }
97 
98 /**
99  * @tc.name: MatrixTest005
100  * @tc.desc: SetScale
101  * @tc.type: FUNC
102  */
103 HWTEST_F(MatrixTest, MatrixTest005, TestSize.Level3)
104 {
105     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest005 start";
106     Matrix matrix_;
107     float tx = 0;
108     float ty = 1;
109     matrix_.SetScale(tx, ty);
110     ASSERT_EQ(matrix_.GetScaleX(), tx);
111     ASSERT_EQ(matrix_.GetScaleY(), ty);
112     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest005 end";
113 }
114 
115 /**
116  * @tc.name: MatrixTest006
117  * @tc.desc: SetScale
118  * @tc.type: FUNC
119  */
120 HWTEST_F(MatrixTest, MatrixTest006, TestSize.Level3)
121 {
122     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest006 start";
123     Matrix matrix_;
124     float tx = 1;
125     float ty = 0;
126     matrix_.SetScale(tx, ty);
127     ASSERT_EQ(matrix_.GetScaleX(), tx);
128     ASSERT_EQ(matrix_.GetScaleY(), ty);
129     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest006 end";
130 }
131 
132 /**
133  * @tc.name: MatrixTest007
134  * @tc.desc: SetScale
135  * @tc.type: FUNC
136  */
137 HWTEST_F(MatrixTest, MatrixTest007, TestSize.Level3)
138 {
139     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest007 start";
140     Matrix matrix_;
141     float tx = 0.5;
142     float ty = 1;
143     matrix_.SetScale(tx, ty);
144     ASSERT_EQ(matrix_.GetScaleX(), tx);
145     ASSERT_EQ(matrix_.GetScaleY(), ty);
146     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest007 end";
147 }
148 
149 /**
150  * @tc.name: MatrixTest008
151  * @tc.desc: SetRotate
152  * @tc.type: FUNC
153  */
154 HWTEST_F(MatrixTest, MatrixTest008, TestSize.Level3)
155 {
156     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest007 start";
157     Matrix matrix_;
158     float tx = 1;
159     float ty = 1;
160     float degrees = 90;
161     matrix_.SetRotate(degrees, tx, ty);
162     ASSERT_NE(matrix_.GetTransX(), tx);
163     ASSERT_NE(matrix_.GetTranY(), ty);
164     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest008 end";
165 }
166 
167 /**
168  * @tc.name: MatrixTest009
169  * @tc.desc: SetRotate
170  * @tc.type: FUNC
171  */
172 HWTEST_F(MatrixTest, MatrixTest009, TestSize.Level3)
173 {
174     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest009 start";
175     Matrix matrix_;
176     float tx = 1;
177     float ty = 1;
178     float degrees = 180;
179     matrix_.SetRotate(degrees, tx, ty);
180     ASSERT_NE(matrix_.GetTransX(), tx);
181     ASSERT_NE(matrix_.GetTranY(), ty);
182     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest009 end";
183 }
184 
185 /**
186  * @tc.name: MatrixTest0010
187  * @tc.desc: SetSinCos
188  * @tc.type: FUNC
189  */
190 HWTEST_F(MatrixTest, MatrixTest0010, TestSize.Level3)
191 {
192     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0010 start";
193     Matrix matrix_;
194     float px = 1;
195     float py = 1;
196     float sinValue = 1;
197     float cosValue = 0;
198     matrix_.SetSinCos(sinValue, cosValue, px, py);
199     ASSERT_NE(matrix_.GetTransX(), px);
200     ASSERT_NE(matrix_.GetTranY(), py);
201     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0010 end";
202 }
203 
204 /**
205  * @tc.name: MatrixTest0011
206  * @tc.desc: SetConcat
207  * @tc.type: FUNC
208  */
209 HWTEST_F(MatrixTest, MatrixTest0011, TestSize.Level3)
210 {
211     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0011 start";
212     Matrix matrix_;
213     Matrix m;
214     matrix_.SetConcat(m);
215     ASSERT_EQ(matrix_.GetTransX(), m.GetTransX());
216     ASSERT_EQ(matrix_.GetTranY(), m.GetTranY());
217     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0011 end";
218 }
219 
220 /**
221  * @tc.name: MatrixTest0012
222  * @tc.desc: SetTranslateAndScale
223  * @tc.type: FUNC
224  */
225 HWTEST_F(MatrixTest, MatrixTest0012, TestSize.Level3)
226 {
227     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0012 start";
228     Matrix matrix_;
229     float tx = 0;
230     float ty = 0;
231     float sx = 1;
232     float sy = 1;
233     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
234     ASSERT_NE(matrix_.GetScaleX(), tx);
235     ASSERT_NE(matrix_.GetScaleY(), ty);
236     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0012 end";
237 }
238 
239 /**
240  * @tc.name: MatrixTest0013
241  * @tc.desc: SetTranslateAndScale
242  * @tc.type: FUNC
243  */
244 HWTEST_F(MatrixTest, MatrixTest0013, TestSize.Level3)
245 {
246     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0013 start";
247     Matrix matrix_;
248     float tx = 1;
249     float ty = 0;
250     float sx = 1;
251     float sy = 1;
252     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
253     ASSERT_EQ(matrix_.GetScaleX(), tx);
254     ASSERT_NE(matrix_.GetScaleY(), ty);
255     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0013 end";
256 }
257 
258 /**
259  * @tc.name: MatrixTest0014
260  * @tc.desc: SetTranslateAndScale
261  * @tc.type: FUNC
262  */
263 HWTEST_F(MatrixTest, MatrixTest0014, TestSize.Level3)
264 {
265     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0014 start";
266     Matrix matrix_;
267     float tx = 0;
268     float ty = 0;
269     float sx = 0;
270     float sy = 1;
271     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
272     ASSERT_EQ(matrix_.GetScaleX(), tx);
273     ASSERT_NE(matrix_.GetScaleY(), ty);
274     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0014 end";
275 }
276 
277 /**
278  * @tc.name: MatrixTest0015
279  * @tc.desc: SetTranslateAndScale
280  * @tc.type: FUNC
281  */
282 HWTEST_F(MatrixTest, MatrixTest0015, TestSize.Level3)
283 {
284     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0015 start";
285     Matrix matrix_;
286     float tx = 1;
287     float ty = 1;
288     float sx = 0;
289     float sy = 0;
290     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
291     ASSERT_NE(matrix_.GetScaleX(), tx);
292     ASSERT_NE(matrix_.GetScaleY(), ty);
293     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0015 end";
294 }
295 
296 /**
297  * @tc.name: MatrixTest0016
298  * @tc.desc: Invert
299  * @tc.type: FUNC
300  */
301 HWTEST_F(MatrixTest, MatrixTest0016, TestSize.Level3)
302 {
303     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0016 start";
304     Matrix matrix_;
305     Matrix m;
306     bool ret = matrix_.Invert(m);
307     ASSERT_EQ(ret, true);
308     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0016 end";
309 }
310 
311 /**
312  * @tc.name: MatrixTest0017
313  * @tc.desc: InvertForRotate
314  * @tc.type: FUNC
315  */
316 HWTEST_F(MatrixTest, MatrixTest0017, TestSize.Level3)
317 {
318     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0017 start";
319     Matrix matrix_;
320     Matrix m;
321     bool ret = matrix_.InvertForRotate(m);
322     ASSERT_EQ(ret, true);
323     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0017 end";
324 }
325 
326 /**
327  * @tc.name: MatrixTest0018
328  * @tc.desc: IdentityXY
329  * @tc.type: FUNC
330  */
331 HWTEST_F(MatrixTest, MatrixTest0018, TestSize.Level3)
332 {
333     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0018 start";
334     Matrix matrix_;
335     Matrix m;
336     float sx = 1;
337     float sy = 1;
338     Point pt;
339     pt.x = 1;
340     pt.y = 1;
341     matrix_.IdentityXY(m, sx, sy, pt);
342     ASSERT_EQ(matrix_.GetTransX(), m.GetTransX());
343     ASSERT_EQ(matrix_.GetTranY(), m.GetTranY());
344     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0018 end";
345 }
346 
347 /**
348  * @tc.name: MatrixTest0019
349  * @tc.desc: ScaleXY
350  * @tc.type: FUNC
351  */
352 HWTEST_F(MatrixTest, MatrixTest0019, TestSize.Level3)
353 {
354     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0019 start";
355     Matrix matrix_;
356     Matrix m;
357     float sx = 1;
358     float sy = 1;
359     Point pt;
360     pt.x = 1;
361     pt.y = 1;
362     matrix_.ScaleXY(m, sx, sy, pt);
363     ASSERT_EQ(matrix_.GetScaleX(), m.GetScaleX());
364     ASSERT_EQ(matrix_.GetScaleY(), m.GetScaleY());
365     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0019 end";
366 }
367 
368 /**
369  * @tc.name: MatrixTest0020
370  * @tc.desc: TransXY
371  * @tc.type: FUNC
372  */
373 HWTEST_F(MatrixTest, MatrixTest0020, TestSize.Level3)
374 {
375     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0020 start";
376     Matrix matrix_;
377     Matrix m;
378     float tx = 1;
379     float ty = 1;
380     Point pt;
381     pt.x = 1;
382     pt.y = 1;
383     matrix_.TransXY(m, tx, ty, pt);
384     ASSERT_EQ(matrix_.GetTransX(), m.GetTransX());
385     ASSERT_EQ(matrix_.GetTranY(), m.GetTranY());
386     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0020 end";
387 }
388 
389 /**
390  * @tc.name: MatrixTest0021
391  * @tc.desc: RotXY
392  * @tc.type: FUNC
393  */
394 HWTEST_F(MatrixTest, MatrixTest0021, TestSize.Level3)
395 {
396     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0021 start";
397     Matrix matrix_;
398     Matrix m;
399     float rx = 1;
400     float ry = 1;
401     Point pt;
402     pt.x = 1;
403     pt.y = 1;
404     matrix_.RotXY(m, rx, ry, pt);
405     ASSERT_EQ(pt.x, rx);
406     ASSERT_EQ(pt.y, ry);
407     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0021 end";
408 }
409 
410 /**
411  * @tc.name: MatrixTest0022
412  * @tc.desc: Print
413  * @tc.type: FUNC
414  */
415 HWTEST_F(MatrixTest, MatrixTest0022, TestSize.Level3)
416 {
417     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0022 start";
418     Matrix matrix_;
419     matrix_.Print();
420     ASSERT_NE(&matrix_, nullptr);
421     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0022 end";
422 }
423 
424 /**
425  * @tc.name: MatrixTest0023
426  * @tc.desc: IdentityXY OperType is not 0
427  * @tc.type: FUNC
428  */
429 HWTEST_F(MatrixTest, MatrixTest0023, TestSize.Level3)
430 {
431     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0023 start";
432     Matrix matrix_;
433     Matrix m;
434     float tx = 1;
435     float ty = 1;
436     m.SetTranslate(tx, ty);
437     ASSERT_NE(m.GetOperType(), 0);
438 
439     float sx = 1;
440     float sy = 1;
441     Point pt;
442     pt.x = 1;
443     pt.y = 1;
444     matrix_.IdentityXY(m, sx, sy, pt);
445     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0023 end";
446 }
447 
448 /**
449  * @tc.name: MatrixTest0024
450  * @tc.desc: Invert sx is 1e-7
451  * @tc.type: FUNC
452  */
453 HWTEST_F(MatrixTest, MatrixTest0024, TestSize.Level3)
454 {
455     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0024 start";
456     Matrix matrix_;
457     Matrix m;
458     float tx = 0;
459     float ty = 0;
460     float sx = 1e-7;
461     float sy = 1;
462     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
463     bool ret = m.Invert(matrix_);
464     ASSERT_EQ(ret, true);
465     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0024 end";
466 }
467 
468 /**
469  * @tc.name: MatrixTest0025
470  * @tc.desc: Invert sy is 1e-7
471  * @tc.type: FUNC
472  */
473 HWTEST_F(MatrixTest, MatrixTest0025, TestSize.Level3)
474 {
475     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0025 start";
476     Matrix matrix_;
477     Matrix m;
478     float tx = 0;
479     float ty = 0;
480     float sx = 1;
481     float sy = 1e-7;
482     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
483     bool ret = m.Invert(matrix_);
484     ASSERT_EQ(ret, true);
485     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0025 end";
486 }
487 
488 /**
489  * @tc.name: MatrixTest0026
490  * @tc.desc: InvertForRotate invDet is 0
491  * @tc.type: FUNC
492  */
493 HWTEST_F(MatrixTest, MatrixTest0026, TestSize.Level3)
494 {
495     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0026 start";
496     Matrix matrix_;
497     Matrix m;
498     float tx = 0;
499     float ty = 0;
500     float sx = -1;
501     float sy = 1;
502     matrix_.SetTranslateAndScale(tx, ty, sx, sy);
503     bool ret = m.InvertForRotate(matrix_);
504     ASSERT_EQ(ret, true);
505     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0026 end";
506 }
507 
508 /**
509  * @tc.name: MatrixTest0027
510  * @tc.desc: SetConcat
511  * @tc.type: FUNC
512  */
513 HWTEST_F(MatrixTest, MatrixTest0027, TestSize.Level3)
514 {
515     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0027 start";
516     Matrix matrix_;
517     float tx = 1;
518     float ty = 1;
519     matrix_.SetTranslate(tx, ty);
520     ASSERT_EQ(matrix_.GetOperType(), Matrix::OperType::TRANSLATE);
521     Matrix m;
522     matrix_.SetConcat(m);
523     GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0027 end";
524 }
525 }
526 }