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