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