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