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 */
HWTEST_F(MatrixTest, MatrixTest001, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest002, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest003, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest004, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest005, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest006, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest007, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest008, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest009, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0010, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0011, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0012, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0013, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0014, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0015, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0016, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0017, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0018, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0019, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0020, TestSize.Level3)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 */
HWTEST_F(MatrixTest, MatrixTest0021, TestSize.Level3)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 = 1;
404 pt.y = 1;
405 matrix_.RotXY(m, rx, ry, pt);
406 ASSERT_EQ(pt.x, rx);
407 ASSERT_EQ(pt.y, ry);
408 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0021 end";
409 }
410
411 /**
412 * @tc.name: MatrixTest0022
413 * @tc.desc: Print
414 * @tc.type: FUNC
415 */
HWTEST_F(MatrixTest, MatrixTest0022, TestSize.Level3)416 HWTEST_F(MatrixTest, MatrixTest0022, TestSize.Level3)
417 {
418 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0022 start";
419 Matrix matrix_;
420 matrix_.Print();
421 ASSERT_NE(&matrix_, nullptr);
422 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0022 end";
423 }
424
425 /**
426 * @tc.name: MatrixTest0023
427 * @tc.desc: IdentityXY OperType is not 0
428 * @tc.type: FUNC
429 */
HWTEST_F(MatrixTest, MatrixTest0023, TestSize.Level3)430 HWTEST_F(MatrixTest, MatrixTest0023, TestSize.Level3)
431 {
432 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0023 start";
433 Matrix matrix_;
434 Matrix m;
435 float tx = 1;
436 float ty = 1;
437 m.SetTranslate(tx, ty);
438 ASSERT_NE(m.GetOperType(), 0);
439
440 float sx = 1;
441 float sy = 1;
442 Point pt;
443 pt.x = 1;
444 pt.y = 1;
445 matrix_.IdentityXY(m, sx, sy, pt);
446 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0023 end";
447 }
448
449 /**
450 * @tc.name: MatrixTest0024
451 * @tc.desc: Invert sx is 1e-7
452 * @tc.type: FUNC
453 */
HWTEST_F(MatrixTest, MatrixTest0024, TestSize.Level3)454 HWTEST_F(MatrixTest, MatrixTest0024, TestSize.Level3)
455 {
456 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0024 start";
457 Matrix matrix_;
458 Matrix m;
459 float tx = 0;
460 float ty = 0;
461 float sx = 1e-7;
462 float sy = 1;
463 matrix_.SetTranslateAndScale(tx, ty, sx, sy);
464 bool ret = m.Invert(matrix_);
465 ASSERT_EQ(ret, true);
466 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0024 end";
467 }
468
469 /**
470 * @tc.name: MatrixTest0025
471 * @tc.desc: Invert sy is 1e-7
472 * @tc.type: FUNC
473 */
HWTEST_F(MatrixTest, MatrixTest0025, TestSize.Level3)474 HWTEST_F(MatrixTest, MatrixTest0025, TestSize.Level3)
475 {
476 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0025 start";
477 Matrix matrix_;
478 Matrix m;
479 float tx = 0;
480 float ty = 0;
481 float sx = 1;
482 float sy = 1e-7;
483 matrix_.SetTranslateAndScale(tx, ty, sx, sy);
484 bool ret = m.Invert(matrix_);
485 ASSERT_EQ(ret, true);
486 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0025 end";
487 }
488
489 /**
490 * @tc.name: MatrixTest0026
491 * @tc.desc: InvertForRotate invDet is 0
492 * @tc.type: FUNC
493 */
HWTEST_F(MatrixTest, MatrixTest0026, TestSize.Level3)494 HWTEST_F(MatrixTest, MatrixTest0026, TestSize.Level3)
495 {
496 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0026 start";
497 Matrix matrix_;
498 Matrix m;
499 float tx = 0;
500 float ty = 0;
501 float sx = -1;
502 float sy = 1;
503 matrix_.SetTranslateAndScale(tx, ty, sx, sy);
504 bool ret = m.InvertForRotate(matrix_);
505 ASSERT_EQ(ret, true);
506 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0026 end";
507 }
508
509 /**
510 * @tc.name: MatrixTest0027
511 * @tc.desc: SetConcat
512 * @tc.type: FUNC
513 */
HWTEST_F(MatrixTest, MatrixTest0027, TestSize.Level3)514 HWTEST_F(MatrixTest, MatrixTest0027, TestSize.Level3)
515 {
516 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0027 start";
517 Matrix matrix_;
518 float tx = 1;
519 float ty = 1;
520 matrix_.SetTranslate(tx, ty);
521 ASSERT_EQ(matrix_.GetOperType(), Matrix::OperType::TRANSLATE);
522 Matrix m;
523 matrix_.SetConcat(m);
524 GTEST_LOG_(INFO) << "MatrixTest: MatrixTest0027 end";
525 }
526
527 /**
528 * @tc.name: SetConcatTest003
529 * @tc.desc: SetConcat
530 * @tc.type: FUNC
531 */
HWTEST_F(MatrixTest, SetConcatTest003, TestSize.Level3)532 HWTEST_F(MatrixTest, SetConcatTest003, TestSize.Level3)
533 {
534 GTEST_LOG_(INFO) << "MatrixTest: SetConcatTest003 start";
535 Matrix matrix_;
536 Matrix m;
537 matrix_.operType_ = 0xF;
538 matrix_.SetConcat(m);
539 ASSERT_EQ(matrix_.operType_, Matrix::OperType::ROTATEORSKEW);
540 GTEST_LOG_(INFO) << "MatrixTest: SetConcatTest003 end";
541 }
542 }
543 }