1 /* 2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 "DrawingNativeMatrixCommon.h" 17 #include "drawing_error_code.h" 18 #include "drawing_matrix.h" 19 #include "drawing_rect.h" 20 #include "utils/scalar.h" 21 #include "gtest/gtest.h" 22 #include <iostream> 23 #include <random> 24 25 using namespace testing; 26 using namespace testing::ext; 27 28 namespace OHOS { 29 namespace Rosen { 30 namespace Drawing { 31 class DrawingNativeMatrixPart2Test : public testing::Test { 32 protected: 33 // 在每个测试用例执行前调用 SetUp()34 void SetUp() override 35 { 36 // 设置代码 37 std::cout << "DrawingNativeMatrixPart2Test Setup code called before each test case." << std::endl; 38 OH_Drawing_ErrorCodeReset(); 39 std::cout << "DrawingNativeMatrixPart2Test errorCodeReset before each test case." << std::endl; 40 } TearDown()41 void TearDown() override 42 { 43 std::cout << "DrawingNativeMatrixPart2Test Setup code called after each test case." << std::endl; 44 OH_Drawing_ErrorCodeReset(); 45 std::cout << "DrawingNativeMatrixPart2Test errorCodeReset after each test case." << std::endl; 46 } 47 }; 48 49 /* 50 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1500 51 * @tc.name: testMatrixPostTranslateNormal 52 * @tc.desc: test for testMatrixPostTranslateNormal. 53 * @tc.size : SmallTest 54 * @tc.type : Function 55 * @tc.level : Level 0 56 */ 57 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixPostTranslateNormal, TestSize.Level0) { 58 // 1. OH_Drawing_MatrixCreate 59 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 60 EXPECT_NE(matrix, nullptr); 61 // 2. OH_Drawing_MatrixPostTranslate, passing decimal numbers 62 OH_Drawing_MatrixPostTranslate(matrix, 1.5, 2.5); 63 // add assert 64 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 65 // 3. OH_Drawing_MatrixPostTranslate, passing integers 66 OH_Drawing_MatrixPostTranslate(matrix, 3, 4); 67 // add assert 68 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 69 // 4. Free memory 70 OH_Drawing_MatrixDestroy(matrix); 71 } 72 73 /* 74 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1501 75 * @tc.name: testMatrixPostTranslateNull 76 * @tc.desc: test for testMatrixPostTranslateNull. 77 * @tc.size : SmallTest 78 * @tc.type : Function 79 * @tc.level : Level 3 80 */ 81 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixPostTranslateNull, TestSize.Level3) { 82 // 1. OH_Drawing_MatrixCreate 83 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 84 EXPECT_NE(matrix, nullptr); 85 // 2. OH_Drawing_MatrixPostTranslate, passing nullptr as the first parameter, check the error code with 86 // OH_Drawing_ErrorCodeGet, no crash, error code returns OH_DRAWING_ERROR_INVALID_PARAMETER 87 OH_Drawing_MatrixPostTranslate(nullptr, 1.5, 2.5); 88 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 89 // 3. OH_Drawing_MatrixPostTranslate, passing 0 as the second parameter 90 OH_Drawing_MatrixPostTranslate(matrix, 0, 2.5); 91 // 4. OH_Drawing_MatrixPostTranslate, passing 0 as the third parameter 92 OH_Drawing_MatrixPostTranslate(matrix, 1.5, 0); 93 // 5. Free memory 94 OH_Drawing_MatrixDestroy(matrix); 95 } 96 97 /* 98 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1502 99 * @tc.name: testMatrixPostTranslateAbnormal 100 * @tc.desc: test for testMatrixPostTranslateAbnormal. 101 * @tc.size : SmallTest 102 * @tc.type : Function 103 * @tc.level : Level 3 104 */ 105 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixPostTranslateAbnormal, TestSize.Level3) { 106 // 1. OH_Drawing_MatrixCreate 107 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 108 EXPECT_NE(matrix, nullptr); 109 // 2. OH_Drawing_MatrixPostTranslate with a negative value as the second parameter 110 OH_Drawing_MatrixPostTranslate(matrix, -1.5, 2.5); 111 // 3. OH_Drawing_MatrixPostTranslate with a negative value as the third parameter 112 OH_Drawing_MatrixPostTranslate(matrix, 1.5, -2.5); 113 // 4. Free memory 114 OH_Drawing_MatrixDestroy(matrix); 115 } 116 117 /* 118 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1503 119 * @tc.name: testMatrixPostTranslateMaximum 120 * @tc.desc: test for testMatrixPostTranslateMaximum. 121 * @tc.size : SmallTest 122 * @tc.type : Function 123 * @tc.level : Level 3 124 */ 125 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixPostTranslateMaximum, TestSize.Level3) { 126 // 1. OH_Drawing_MatrixCreate 127 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 128 EXPECT_NE(matrix, nullptr); 129 // 2. OH_Drawing_MatrixPostTranslate with the second parameter as the maximum value 130 OH_Drawing_MatrixPostTranslate(matrix, FLT_MAX, 2.5); 131 // 3. OH_Drawing_MatrixPostTranslate with the third parameter as the maximum value 132 OH_Drawing_MatrixPostTranslate(matrix, 1.5, FLT_MAX); 133 // 4. Free memory 134 OH_Drawing_MatrixDestroy(matrix); 135 } 136 137 /* 138 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1504 139 * @tc.name: testMatrixPostTranslateMultipleCalls 140 * @tc.desc: test for testMatrixPostTranslateMultipleCalls. 141 * @tc.size : SmallTest 142 * @tc.type : Function 143 * @tc.level : Level 3 144 */ 145 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixPostTranslateMultipleCalls, TestSize.Level3) { 146 // 1. OH_Drawing_MatrixCreate 147 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 148 EXPECT_NE(matrix, nullptr); 149 // 2. Call OH_Drawing_MatrixPostTranslate 10 times, with dx and dy as random numbers 150 std::random_device rd; 151 std::mt19937 gen(rd()); 152 std::uniform_real_distribution<float> dis(-100, 100); 153 for (int i = 0; i < 10; i++) { 154 OH_Drawing_MatrixPostTranslate(matrix, dis(gen), dis(gen)); 155 } 156 // 3. Free memory 157 OH_Drawing_MatrixDestroy(matrix); 158 } 159 160 /* 161 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1600 162 * @tc.name: testMatrixResetNormal 163 * @tc.desc: test for testMatrixResetNormal. 164 * @tc.size : SmallTest 165 * @tc.type : Function 166 * @tc.level : Level 0 167 */ 168 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixResetNormal, TestSize.Level0) { 169 // 1. OH_Drawing_MatrixCreate 170 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 171 // add assert 172 EXPECT_NE(matrix, nullptr); 173 // 2. OH_Drawing_MatrixReset with the identity matrix 174 OH_Drawing_MatrixReset(matrix); 175 // add assert 176 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 177 // 3. OH_Drawing_MatrixReset with a non-identity matrix 178 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1); 179 OH_Drawing_MatrixReset(matrix); 180 // add assert 181 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 182 // 4. Free memory 183 OH_Drawing_MatrixDestroy(matrix); 184 } 185 186 /* 187 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1601 188 * @tc.name: testMatrixResetNull 189 * @tc.desc: test for testMatrixResetNull. 190 * @tc.size : SmallTest 191 * @tc.type : Function 192 * @tc.level : Level 3 193 */ 194 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixResetNull, TestSize.Level3) { 195 // 1. OH_Drawing_MatrixReset with nullptr as the parameter, check the error code with OH_Drawing_ErrorCodeGet, no 196 // crash, error code returns OH_DRAWING_ERROR_INVALID_PARAMETER 197 OH_Drawing_MatrixReset(nullptr); 198 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 199 } 200 201 /* 202 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1602 203 * @tc.name: testMatrixResetMultipleCalls 204 * @tc.desc: test for testMatrixResetMultipleCalls. 205 * @tc.size : SmallTest 206 * @tc.type : Function 207 * @tc.level : Level 3 208 */ 209 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixResetMultipleCalls, TestSize.Level3) { 210 // 1. OH_Drawing_MatrixCreate 211 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 212 // add assert 213 EXPECT_NE(matrix, nullptr); 214 // 2. Call OH_Drawing_MatrixSetMatrix 10 times 215 for (int i = 0; i < 10; i++) { 216 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1); 217 } 218 // 3. Call OH_Drawing_MatrixReset 10 times 219 for (int i = 0; i < 10; i++) { 220 OH_Drawing_MatrixReset(matrix); 221 } 222 // 4. Call OH_Drawing_MatrixSetMatrix and OH_Drawing_MatrixReset alternately 10 times 223 for (int i = 0; i < 10; i++) { 224 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1); 225 OH_Drawing_MatrixReset(matrix); 226 } 227 // 5. Free memory 228 OH_Drawing_MatrixDestroy(matrix); 229 } 230 231 /* 232 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1700 233 * @tc.name: testMatrixConcatNormal 234 * @tc.desc: test for testMatrixConcatNormal. 235 * @tc.size : SmallTest 236 * @tc.type : Function 237 * @tc.level : Level 0 238 */ 239 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixConcatNormal, TestSize.Level0) { 240 // Define matrices a and b 241 OH_Drawing_Matrix *a = OH_Drawing_MatrixCreate(); 242 // add assert 243 EXPECT_NE(a, nullptr); 244 OH_Drawing_MatrixSetMatrix(a, 1, 0, 0, 0, -1, 0, 0, 0, 1); 245 OH_Drawing_Matrix *b = OH_Drawing_MatrixCreate(); 246 // add assert 247 EXPECT_NE(b, nullptr); 248 OH_Drawing_MatrixSetMatrix(b, 1, 0, 0, 0, 1, 0, 0, 0, 1); 249 OH_Drawing_Matrix *c = OH_Drawing_MatrixCreate(); 250 // add assert 251 EXPECT_NE(c, nullptr); 252 // 1. Call OH_Drawing_MatrixConcat with matrices a and b of different sizes, 253 // and use OH_Drawing_MatrixGetAll to get the result of matrix a multiplied by matrix b 254 OH_Drawing_MatrixConcat(c, b, a); 255 // add assert 256 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 257 float values[9]; 258 OH_Drawing_MatrixGetAll(c, values); 259 EXPECT_EQ(values[0], 1); 260 // 2. Free memory 261 OH_Drawing_MatrixDestroy(a); 262 OH_Drawing_MatrixDestroy(b); 263 OH_Drawing_MatrixDestroy(c); 264 } 265 266 /* 267 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1701 268 * @tc.name: testMatrixConcatNull 269 * @tc.desc: test for testMatrixConcatNull. 270 * @tc.size : SmallTest 271 * @tc.type : Function 272 * @tc.level : Level 3 273 */ 274 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixConcatNull, TestSize.Level3) { 275 // 1. OH_Drawing_MatrixCreate 276 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 277 // add assert 278 EXPECT_NE(matrix, nullptr); 279 // 2. OH_Drawing_MatrixConcat, passing nullptr as the first parameter, check the error code with 280 // OH_Drawing_ErrorCodeGet 281 OH_Drawing_MatrixConcat(nullptr, matrix, matrix); 282 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 283 OH_Drawing_ErrorCodeReset(); 284 // 3. OH_Drawing_MatrixConcat, passing nullptr as the second parameter, check the error code with 285 // OH_Drawing_ErrorCodeGet 286 OH_Drawing_MatrixConcat(matrix, nullptr, matrix); 287 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 288 OH_Drawing_ErrorCodeReset(); 289 // 4. OH_Drawing_MatrixConcat, passing nullptr as the third parameter, check the error code with 290 // OH_Drawing_ErrorCodeGet 291 OH_Drawing_MatrixConcat(matrix, matrix, nullptr); 292 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 293 // 5. Free memory 294 OH_Drawing_MatrixDestroy(matrix); 295 } 296 297 /* 298 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1702 299 * @tc.name: testMatrixConcatMultipleCalls 300 * @tc.desc: test for testMatrixConcatMultipleCalls. 301 * @tc.size : SmallTest 302 * @tc.type : Function 303 * @tc.level : Level 3 304 */ 305 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixConcatMultipleCalls, TestSize.Level3) { 306 // 1. Call OH_Drawing_MatrixConcat 10 times with matrices a and b of different sizes, 307 // and use OH_Drawing_MatrixGetAll to get the result of matrix a multiplied by matrix b 308 OH_Drawing_Matrix *a = OH_Drawing_MatrixCreate(); 309 // add assert 310 EXPECT_NE(a, nullptr); 311 OH_Drawing_MatrixSetMatrix(a, 1, 0, 0, 0, -1, 0, 0, 0, 1); 312 OH_Drawing_Matrix *b = OH_Drawing_MatrixCreate(); 313 // add assert 314 EXPECT_NE(b, nullptr); 315 OH_Drawing_MatrixSetMatrix(b, 1, 0, 0, 0, 1, 0, 0, 0, 1); 316 OH_Drawing_Matrix *c = OH_Drawing_MatrixCreate(); 317 // add assert 318 EXPECT_NE(c, nullptr); 319 for (int i = 0; i < 10; i++) { 320 OH_Drawing_MatrixConcat(c, b, a); 321 float values[9]; 322 OH_Drawing_MatrixGetAll(c, values); 323 EXPECT_EQ(values[0], 1); 324 EXPECT_EQ(values[1], 0); 325 EXPECT_EQ(values[2], 0); 326 EXPECT_EQ(values[3], 0); 327 EXPECT_EQ(values[4], -1); 328 EXPECT_EQ(values[5], 0); 329 EXPECT_EQ(values[6], 0); 330 EXPECT_EQ(values[7], 0); 331 EXPECT_EQ(values[8], 1); 332 } 333 // 2. Free memory 334 OH_Drawing_MatrixDestroy(a); 335 OH_Drawing_MatrixDestroy(b); 336 OH_Drawing_MatrixDestroy(c); 337 } 338 339 /* 340 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1800 341 * @tc.name: testMatrixInvertNormal 342 * @tc.desc: test for testMatrixInvertNormal. 343 * @tc.size : SmallTest 344 * @tc.type : Function 345 * @tc.level : Level 0 346 */ 347 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixInvertNormal, TestSize.Level0) { 348 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 349 // add assert 350 EXPECT_NE(matrix, nullptr); 351 OH_Drawing_Matrix *inverse = OH_Drawing_MatrixCreate(); 352 // add assert 353 EXPECT_NE(inverse, nullptr); 354 OH_Drawing_MatrixInvert(matrix, inverse); 355 // add assert 356 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 357 OH_Drawing_MatrixInvert(inverse, matrix); 358 // add assert 359 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 360 OH_Drawing_MatrixDestroy(matrix); 361 OH_Drawing_MatrixDestroy(inverse); 362 } 363 364 /* 365 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1801 366 * @tc.name: testMatrixInvertNull 367 * @tc.desc: test for testMatrixInvertNull. 368 * @tc.size : SmallTest 369 * @tc.type : Function 370 * @tc.level : Level 3 371 */ 372 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixInvertNull, TestSize.Level3) { 373 // 1. OH_Drawing_MatrixCreate 374 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 375 // add assert 376 EXPECT_NE(matrix, nullptr); 377 // 2. OH_Drawing_MatrixInvert with the first parameter as nullptr, check the error code with OH_Drawing_ErrorCodeGet 378 OH_Drawing_MatrixInvert(nullptr, matrix); 379 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 380 OH_Drawing_ErrorCodeReset(); 381 // 3. OH_Drawing_MatrixInvert with the second parameter as nullptr, check the error code with 382 // OH_Drawing_ErrorCodeGet 383 OH_Drawing_MatrixInvert(matrix, nullptr); 384 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 385 // 4. Free memory 386 OH_Drawing_MatrixDestroy(matrix); 387 } 388 389 /* 390 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1802 391 * @tc.name: testMatrixInvertMultipleCalls 392 * @tc.desc: test for testMatrixInvertMultipleCalls. 393 * @tc.size : SmallTest 394 * @tc.type : Function 395 * @tc.level : Level 3 396 */ 397 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixInvertMultipleCalls, TestSize.Level3) { 398 // 1. Call OH_Drawing_MatrixInvert 10 times with matrices of different sizes 399 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 400 // add assert 401 EXPECT_NE(matrix, nullptr); 402 OH_Drawing_Matrix *inverse = OH_Drawing_MatrixCreate(); 403 // add assert 404 EXPECT_NE(inverse, nullptr); 405 OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 0, 0, -1, 0, 0, 0, 1); 406 for (int i = 0; i < 10; i++) { 407 OH_Drawing_MatrixInvert(matrix, inverse); 408 OH_Drawing_MatrixInvert(inverse, matrix); 409 float values[9]; 410 OH_Drawing_MatrixGetAll(matrix, values); 411 EXPECT_EQ(values[0], 1); 412 EXPECT_EQ(values[1], 0); 413 EXPECT_EQ(values[2], 0); 414 EXPECT_EQ(values[3], 0); 415 EXPECT_EQ(values[4], -1); 416 EXPECT_EQ(values[5], 0); 417 EXPECT_EQ(values[6], 0); 418 EXPECT_EQ(values[7], 0); 419 EXPECT_EQ(values[8], 1); 420 } 421 // 2. Free memory 422 OH_Drawing_MatrixDestroy(matrix); 423 OH_Drawing_MatrixDestroy(inverse); 424 } 425 426 /* 427 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1900 428 * @tc.name: testMatrixSetPolyToPolyNormal 429 * @tc.desc: test for testMatrixSetPolyToPolyNormal. 430 * @tc.size : SmallTest 431 * @tc.type : Function 432 * @tc.level : Level 0 433 */ 434 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixSetPolyToPolyNormal, TestSize.Level0) { 435 // 1. OH_Drawing_MatrixCreate 436 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 437 EXPECT_NE(matrix, nullptr); 438 // 2. OH_Drawing_MatrixSetPolyToPoly 439 OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 0, 0, -1, 0, 0, 0, 1); 440 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}}; 441 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}}; 442 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 1); 443 // add assert 444 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 445 // 3. OH_Drawing_MatrixSetPolyToPoly, iterate count from 0 to 4, keeping the length of the array consistent with 446 // count 447 std::random_device rd; 448 std::mt19937 gen(rd()); 449 std::uniform_real_distribution<float> dis(0, 100); 450 for (int i = 0; i < 5; i++) { 451 OH_Drawing_ErrorCodeReset(); 452 OH_Drawing_Point2D src[i]; 453 OH_Drawing_Point2D dst[i]; 454 for (int j = 0; j < i; j++) { 455 // Generate random numbers 456 src[j] = {dis(gen), dis(gen)}; 457 dst[j] = {dis(gen), dis(gen)}; 458 } 459 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, i); 460 // add assert 461 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 462 } 463 // 4. Free memory 464 OH_Drawing_MatrixDestroy(matrix); 465 } 466 467 /* 468 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1901 469 * @tc.name: testMatrixSetPolyToPolyNull 470 * @tc.desc: test for testMatrixSetPolyToPolyNull. 471 * @tc.size : SmallTest 472 * @tc.type : Function 473 * @tc.level : Level 3 474 */ 475 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixSetPolyToPolyNull, TestSize.Level3) { 476 // 1. OH_Drawing_MatrixCreate 477 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 478 // add assert 479 EXPECT_NE(matrix, nullptr); 480 // 2. OH_Drawing_MatrixSetPolyToPoly, the first parameter is nullptr, check the error code with 481 // OH_Drawing_ErrorCodeGet 482 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}}; 483 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}}; 484 OH_Drawing_MatrixSetPolyToPoly(nullptr, src, dst, 5); 485 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 486 // 3. OH_Drawing_MatrixSetPolyToPoly, the second parameter is nullptr, check the error code with 487 // OH_Drawing_ErrorCodeGet 488 OH_Drawing_MatrixSetPolyToPoly(matrix, nullptr, dst, 5); 489 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE); 490 // 4. OH_Drawing_MatrixSetPolyToPoly, the third parameter is nullptr, check the error code with 491 // OH_Drawing_ErrorCodeGet 492 OH_Drawing_MatrixSetPolyToPoly(matrix, src, nullptr, 5); 493 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE); 494 // 5. Free memory 495 OH_Drawing_MatrixDestroy(matrix); 496 } 497 498 /* 499 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1902 500 * @tc.name: testMatrixSetPolyToPolyAbnormal 501 * @tc.desc: test for testMatrixSetPolyToPolyAbnormal. 502 * @tc.size : SmallTest 503 * @tc.type : Function 504 * @tc.level : Level 3 505 */ 506 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixSetPolyToPolyAbnormal, TestSize.Level3) { 507 // 1. OH_Drawing_MatrixCreate 508 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 509 // add assert 510 EXPECT_NE(matrix, nullptr); 511 // 2. OH_Drawing_MatrixSetPolyToPoly, pass -1 as count, check the error code with OH_Drawing_ErrorCodeGet 512 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}}; 513 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}}; 514 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, -1); 515 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE); 516 // 3. OH_Drawing_MatrixSetPolyToPoly, pass 5 as count, check the error code with OH_Drawing_ErrorCodeGet 517 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 5); 518 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE); 519 // 4. Free memory 520 OH_Drawing_MatrixDestroy(matrix); 521 } 522 523 /* 524 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1904 525 * @tc.name: testMatrixSetPolyToPolyMultipleCalls 526 * @tc.desc: test for testMatrixSetPolyToPolyMultipleCalls. 527 * @tc.size : SmallTest 528 * @tc.type : Function 529 * @tc.level : Level 3 530 */ 531 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixSetPolyToPolyMultipleCalls, TestSize.Level3) { 532 // 1. OH_Drawing_MatrixCreate 533 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 534 // add assert 535 EXPECT_NE(matrix, nullptr); 536 // 2. Call OH_Drawing_MatrixSetPolyToPoly 10 times 537 std::random_device rd; 538 std::mt19937 gen(rd()); 539 std::uniform_real_distribution<float> dis(0, 100); 540 for (int i = 0; i < 10; i++) { 541 OH_Drawing_Point2D src[2] = {{dis(gen), dis(gen)}, {dis(gen), dis(gen)}}; 542 OH_Drawing_Point2D dst[2] = {{dis(gen), dis(gen)}, {dis(gen), dis(gen)}}; 543 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 2); 544 } 545 // 3. Free memory 546 OH_Drawing_MatrixDestroy(matrix); 547 } 548 549 /* 550 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2000 551 * @tc.name: testMatrixMapPointsNormal 552 * @tc.desc: test for testMatrixMapPointsNormal. 553 * @tc.size : SmallTest 554 * @tc.type : Function 555 * @tc.level : Level 0 556 */ 557 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapPointsNormal, TestSize.Level0) { 558 // 1. OH_Drawing_MatrixCreate 559 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 560 // add assert 561 EXPECT_NE(matrix, nullptr); 562 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}}; 563 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}}; 564 // 2. OH_Drawing_MatrixMapPoints, pass the float value 1.52 as count 565 double value = 1.52; 566 uint32_t count = static_cast<uint32_t>(value); 567 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, count); 568 // 3. OH_Drawing_MatrixMapPoints, pass integer 5 as count 569 OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 5); 570 // 4. Free memory 571 OH_Drawing_MatrixDestroy(matrix); 572 } 573 574 /* 575 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2001 576 * @tc.name: testMatrixMapPointsNull 577 * @tc.desc: test for testMatrixMapPointsNull. 578 * @tc.size : SmallTest 579 * @tc.type : Function 580 * @tc.level : Level 3 581 */ 582 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapPointsNull, TestSize.Level3) { 583 // 1. OH_Drawing_MatrixCreate 584 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 585 // add assert 586 EXPECT_NE(matrix, nullptr); 587 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}}; 588 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}}; 589 // 2. OH_Drawing_MatrixMapPoints, the first parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 590 OH_Drawing_MatrixMapPoints(nullptr, src, dst, 5); 591 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 592 OH_Drawing_ErrorCodeReset(); 593 // 3. OH_Drawing_MatrixMapPoints, the second parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 594 OH_Drawing_MatrixMapPoints(matrix, nullptr, dst, 5); 595 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 596 OH_Drawing_ErrorCodeReset(); 597 // 4. OH_Drawing_MatrixMapPoints, the third parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 598 OH_Drawing_MatrixMapPoints(matrix, src, nullptr, 5); 599 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 600 OH_Drawing_ErrorCodeReset(); 601 // 5. OH_Drawing_MatrixMapPoints, the fourth parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 602 OH_Drawing_MatrixMapPoints(matrix, src, dst, 0); 603 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 604 // 6. Free memory 605 OH_Drawing_MatrixDestroy(matrix); 606 } 607 608 /* 609 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2002 610 * @tc.name: testMatrixMapPointsAbnormal 611 * @tc.desc: test for testMatrixMapPointsAbnormal. 612 * @tc.size : SmallTest 613 * @tc.type : Function 614 * @tc.level : Level 3 615 */ 616 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapPointsAbnormal, TestSize.Level3) { 617 // 1. OH_Drawing_MatrixCreate 618 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 619 // add assert 620 EXPECT_NE(matrix, nullptr); 621 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}}; 622 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}}; 623 // 2. OH_Drawing_MatrixMapPoints, pass -1 as count, check the error code with OH_Drawing_ErrorCodeGet 624 OH_Drawing_MatrixMapPoints(matrix, src, dst, -1); 625 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 626 // 3. Free memory 627 OH_Drawing_MatrixDestroy(matrix); 628 } 629 630 /* 631 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2003 632 * @tc.name: testMatrixMapPointsMultipleCalls 633 * @tc.desc: test for testMatrixMapPointsMultipleCalls. 634 * @tc.size : SmallTest 635 * @tc.type : Function 636 * @tc.level : Level 3 637 */ 638 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapPointsMultipleCalls, TestSize.Level3) { 639 // 1. OH_Drawing_MatrixCreate 640 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 641 // add assert 642 EXPECT_NE(matrix, nullptr); 643 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}}; 644 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}}; 645 // 2. Call OH_Drawing_MatrixMapPoints 10 times 646 for (int i = 0; i < 10; i++) { 647 OH_Drawing_ErrorCodeReset(); 648 OH_Drawing_MatrixMapPoints(matrix, src, dst, 5); 649 // add assert 650 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 651 } 652 // 3. Free memory 653 OH_Drawing_MatrixDestroy(matrix); 654 } 655 656 /* 657 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2100 658 * @tc.name: testMatrixMapRectNormal 659 * @tc.desc: test for testMatrixMapRectNormal. 660 * @tc.size : SmallTest 661 * @tc.type : Function 662 * @tc.level : Level 0 663 */ 664 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapRectNormal, TestSize.Level0) { 665 // 1. OH_Drawing_MatrixCreate 666 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 667 // add assert 668 EXPECT_NE(matrix, nullptr); 669 // 2. OH_Drawing_MatrixMapRect, src and dst are the same 670 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, 100, 100); 671 // add assert 672 EXPECT_NE(src, nullptr); 673 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, 100, 100); 674 // add assert 675 EXPECT_NE(dst, nullptr); 676 OH_Drawing_MatrixMapRect(matrix, src, dst); 677 // add assert 678 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 679 // 3. OH_Drawing_MatrixMapRect, src and dst are different 680 OH_Drawing_Rect *src2 = OH_Drawing_RectCreate(0, 0, 100, 100); 681 // add assert 682 EXPECT_NE(src2, nullptr); 683 OH_Drawing_Rect *dst2 = OH_Drawing_RectCreate(0, 0, 200, 200); 684 // add assert 685 EXPECT_NE(dst2, nullptr); 686 OH_Drawing_MatrixMapRect(matrix, src2, dst2); 687 // add assert 688 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 689 // 4. Free memory 690 OH_Drawing_MatrixDestroy(matrix); 691 OH_Drawing_RectDestroy(src); 692 OH_Drawing_RectDestroy(dst); 693 OH_Drawing_RectDestroy(src2); 694 OH_Drawing_RectDestroy(dst2); 695 } 696 697 /* 698 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2101 699 * @tc.name: testMatrixMapRectNull 700 * @tc.desc: test for testMatrixMapRectNull. 701 * @tc.size : SmallTest 702 * @tc.type : Function 703 * @tc.level : Level 3 704 */ 705 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapRectNull, TestSize.Level3) { 706 // 1. OH_Drawing_MatrixCreate 707 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 708 // add assert 709 EXPECT_NE(matrix, nullptr); 710 // 2. OH_Drawing_MatrixMapRect, the first parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 711 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, 100, 100); 712 // add assert 713 EXPECT_NE(src, nullptr); 714 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, 100, 100); 715 // add assert 716 EXPECT_NE(dst, nullptr); 717 OH_Drawing_MatrixMapRect(nullptr, src, dst); 718 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 719 OH_Drawing_ErrorCodeReset(); 720 // 3. OH_Drawing_MatrixMapRect, the second parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 721 OH_Drawing_MatrixMapRect(matrix, nullptr, dst); 722 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 723 OH_Drawing_ErrorCodeReset(); 724 // 4. OH_Drawing_MatrixMapRect, the third parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 725 OH_Drawing_MatrixMapRect(matrix, src, nullptr); 726 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 727 // 5. Free memory 728 OH_Drawing_MatrixDestroy(matrix); 729 OH_Drawing_RectDestroy(src); 730 OH_Drawing_RectDestroy(dst); 731 } 732 733 /* 734 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2103 735 * @tc.name: testMatrixMapRectMultipleCalls 736 * @tc.desc: test for testMatrixMapRectMultipleCalls. 737 * @tc.size : SmallTest 738 * @tc.type : Function 739 * @tc.level : Level 3 740 */ 741 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixMapRectMultipleCalls, TestSize.Level3) { 742 // 1. OH_Drawing_MatrixCreate 743 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 744 // add assert 745 EXPECT_NE(matrix, nullptr); 746 // 2. Call OH_Drawing_MatrixMapRect 10 times with different src and dst 747 std::random_device rd; 748 std::mt19937 gen(rd()); 749 std::uniform_real_distribution<float> dis(100, 200); 750 for (int i = 0; i < 10; i++) { 751 OH_Drawing_ErrorCodeReset(); 752 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, dis(gen), dis(gen)); 753 // add assert 754 EXPECT_NE(src, nullptr); 755 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, dis(gen), dis(gen)); 756 // add assert 757 EXPECT_NE(dst, nullptr); 758 OH_Drawing_MatrixMapRect(matrix, src, dst); 759 // add assert 760 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 761 OH_Drawing_RectDestroy(src); 762 OH_Drawing_RectDestroy(dst); 763 } 764 // 3. Free memory 765 OH_Drawing_MatrixDestroy(matrix); 766 } 767 768 /* 769 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2200 770 * @tc.name: testMatrixIsEqualNormal 771 * @tc.desc: test for testMatrixIsEqualNormal. 772 * @tc.size : SmallTest 773 * @tc.type : Function 774 * @tc.level : Level 0 775 */ 776 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixIsEqualNormal, TestSize.Level0) { 777 // 1. OH_Drawing_MatrixIsEqual with the same matrix 778 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 779 // add assert 780 EXPECT_NE(matrix, nullptr); 781 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9); 782 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreate(); 783 // add assert 784 EXPECT_NE(matrix2, nullptr); 785 OH_Drawing_MatrixSetMatrix(matrix2, 1, 2, 3, 4, 5, 6, 7, 8, 9); 786 bool ret = OH_Drawing_MatrixIsEqual(matrix, matrix2); 787 // add assert 788 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 789 EXPECT_EQ(ret, true); 790 // 2. OH_Drawing_MatrixIsEqual with different matrices 791 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreate(); 792 // add assert 793 EXPECT_NE(matrix3, nullptr); 794 OH_Drawing_MatrixSetMatrix(matrix3, 2, 2, 3, 4, 5, 6, 7, 8, 9); 795 ret = OH_Drawing_MatrixIsEqual(matrix, matrix3); 796 // add assert 797 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 798 EXPECT_EQ(ret, false); 799 // 3. Free memory 800 OH_Drawing_MatrixDestroy(matrix); 801 OH_Drawing_MatrixDestroy(matrix2); 802 OH_Drawing_MatrixDestroy(matrix3); 803 } 804 805 /* 806 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2201 807 * @tc.name: testMatrixIsEqualNull 808 * @tc.desc: test for testMatrixIsEqualNull. 809 * @tc.size : SmallTest 810 * @tc.type : Function 811 * @tc.level : Level 3 812 */ 813 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixIsEqualNull, TestSize.Level3) { 814 // 1. OH_Drawing_MatrixCreate 815 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 816 // add assert 817 EXPECT_NE(matrix, nullptr); 818 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9); 819 // 2. OH_Drawing_MatrixIsEqual, the first parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 820 OH_Drawing_MatrixIsEqual(nullptr, matrix); 821 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 822 OH_Drawing_ErrorCodeReset(); 823 // 3. OH_Drawing_MatrixIsEqual, the second parameter is nullptr, check the error code with OH_Drawing_ErrorCodeGet 824 OH_Drawing_MatrixIsEqual(matrix, nullptr); 825 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 826 // 4. Free memory 827 OH_Drawing_MatrixDestroy(matrix); 828 } 829 830 /* 831 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2202 832 * @tc.name: testMatrixIsEqualMultipleCalls 833 * @tc.desc: test for testMatrixIsEqualMultipleCalls. 834 * @tc.size : SmallTest 835 * @tc.type : Function 836 * @tc.level : Level 3 837 */ 838 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixIsEqualMultipleCalls, TestSize.Level3) { 839 // 1. OH_Drawing_MatrixCreate 840 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 841 // add assert 842 EXPECT_NE(matrix, nullptr); 843 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreate(); 844 // add assert 845 EXPECT_NE(matrix2, nullptr); 846 // 2. Call OH_Drawing_MatrixIsEqual 10 times with alternating different or same matrices 847 for (int i = 0; i < 10; i++) { 848 if (i % 2 == 0) { 849 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9); 850 OH_Drawing_MatrixSetMatrix(matrix2, 1, 2, 3, 4, 5, 6, 7, 8, 9); 851 bool ret = OH_Drawing_MatrixIsEqual(matrix, matrix2); 852 EXPECT_EQ(ret, true); 853 } else { 854 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9); 855 OH_Drawing_MatrixSetMatrix(matrix2, 2, 2, 3, 4, 5, 6, 7, 8, 9); 856 bool ret = OH_Drawing_MatrixIsEqual(matrix, matrix2); 857 EXPECT_EQ(ret, false); 858 } 859 } 860 // 3. Free memory 861 OH_Drawing_MatrixDestroy(matrix); 862 OH_Drawing_MatrixDestroy(matrix2); 863 } 864 865 /* 866 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2300 867 * @tc.name: testMatrixIsIdentityNormal 868 * @tc.desc: test for testMatrixIsIdentityNormal. 869 * @tc.size : SmallTest 870 * @tc.type : Function 871 * @tc.level : Level 0 872 */ 873 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixIsIdentityNormal, TestSize.Level0) { 874 // 1. OH_Drawing_MatrixIsIdentity with an identity matrix 875 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 876 // add assert 877 EXPECT_NE(matrix, nullptr); 878 bool ret = OH_Drawing_MatrixIsIdentity(matrix); 879 // add assert 880 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 881 EXPECT_EQ(ret, true); 882 // 2. OH_Drawing_MatrixIsIdentity with a non-identity matrix 883 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9); 884 ret = OH_Drawing_MatrixIsIdentity(matrix); 885 // add assert 886 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 887 EXPECT_EQ(ret, false); 888 // 3. Free memory 889 OH_Drawing_MatrixDestroy(matrix); 890 } 891 892 /* 893 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2301 894 * @tc.name: testMatrixIsIdentityNull 895 * @tc.desc: test for testMatrixIsIdentityNull. 896 * @tc.size : SmallTest 897 * @tc.type : Function 898 * @tc.level : Level 3 899 */ 900 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixIsIdentityNull, TestSize.Level3) { 901 // 1. OH_Drawing_MatrixCreate 902 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 903 // add assert 904 EXPECT_NE(matrix, nullptr); 905 // 2. OH_Drawing_MatrixIsIdentity with nullptr as parameter, check the error code with OH_Drawing_ErrorCodeGet 906 OH_Drawing_MatrixIsIdentity(nullptr); 907 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 908 // 3. Free memory 909 OH_Drawing_MatrixDestroy(matrix); 910 } 911 912 /* 913 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_2302 914 * @tc.name: testMatrixIsIdentityMultipleCalls 915 * @tc.desc: test for testMatrixIsIdentityMultipleCalls. 916 * @tc.size : SmallTest 917 * @tc.type : Function 918 * @tc.level : Level 3 919 */ 920 HWTEST_F(DrawingNativeMatrixPart2Test, testMatrixIsIdentityMultipleCalls, TestSize.Level3) { 921 // Call OH_Drawing_MatrixIsIdentity 10 times with alternating identity or non-identity matrices 922 for (int i = 0; i < 10; i++) { 923 if (i % 2 == 0) { 924 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 925 // add assert 926 EXPECT_NE(matrix, nullptr); 927 bool ret = OH_Drawing_MatrixIsIdentity(matrix); 928 EXPECT_EQ(ret, true); 929 OH_Drawing_MatrixDestroy(matrix); 930 } else { 931 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 932 // add assert 933 EXPECT_NE(matrix, nullptr); 934 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9); 935 bool ret = OH_Drawing_MatrixIsIdentity(matrix); 936 EXPECT_EQ(ret, false); 937 OH_Drawing_MatrixDestroy(matrix); 938 } 939 } 940 } 941 942 } // namespace Drawing 943 } // namespace Rosen 944 } // namespace OHOS