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 DrawingNativeMatrixTest : public testing::Test { 32 protected: 33 // 在每个测试用例执行前调用 SetUp()34 void SetUp() override 35 { 36 // 设置代码 37 std::cout << "DrawingNativeMatrixTest Setup code called before each test case." << std::endl; 38 OH_Drawing_ErrorCodeReset(); 39 std::cout << "DrawingNativeMatrixTest errorCodeReset before each test case." << std::endl; 40 } TearDown()41 void TearDown() override 42 { 43 std::cout << "DrawingNativeMatrixTest Setup code called after each test case." << std::endl; 44 OH_Drawing_ErrorCodeReset(); 45 std::cout << "DrawingNativeMatrixTest errorCodeReset after each test case." << std::endl; 46 } 47 }; 48 /* 49 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0100 50 * @tc.name: testMatrixCreateDestroyNormal 51 * @tc.desc: Test for creating and destroying a matrix with normal parameters. 52 * @tc.size : SmallTest 53 * @tc.type : Function 54 * @tc.level : Level 0 55 */ 56 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateDestroyNormal, TestSize.Level0) { 57 // 1. OH_Drawing_MatrixCreate 58 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 59 EXPECT_NE(matrix, nullptr); 60 // 2. OH_Drawing_MatrixDestroy 61 OH_Drawing_MatrixDestroy(matrix); 62 } 63 64 /* 65 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0101 66 * @tc.name: testMatrixCreateDestroyNULL 67 * @tc.desc: Test for creating and destroying a matrix with NULL parameters. 68 * @tc.size : SmallTest 69 * @tc.type : Function 70 * @tc.level : Level 3 71 */ 72 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateDestroyNULL, TestSize.Level3) { 73 // 1. OH_Drawing_MatrixDestroy with nullptr parameter 74 OH_Drawing_MatrixDestroy(nullptr); 75 // add assert 76 EXPECT_TRUE(true); 77 } 78 79 /* 80 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0102 81 * @tc.name: testMatrixCreateDestroyMultipleCalls 82 * @tc.desc: Test for multiple calls of creating and destroying a matrix. 83 * @tc.size : SmallTest 84 * @tc.type : Function 85 * @tc.level : Level 3 86 */ 87 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateDestroyMultipleCalls, TestSize.Level3) { 88 // 1. Call OH_Drawing_MatrixCreate 10 times 89 OH_Drawing_Matrix *matrices[10]; 90 for (int i = 0; i < 10; i++) { 91 matrices[i] = OH_Drawing_MatrixCreate(); 92 EXPECT_NE(matrices[i], nullptr); 93 } 94 // 2. Call OH_Drawing_MatrixDestroy 10 times 95 for (int i = 0; i < 10; i++) { 96 OH_Drawing_MatrixDestroy(matrices[i]); 97 } 98 // 3. Call OH_Drawing_MatrixCreate and OH_Drawing_MatrixDestroy alternately 10 times 99 for (int i = 0; i < 10; i++) { 100 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 101 EXPECT_NE(matrix, nullptr); 102 OH_Drawing_MatrixDestroy(matrix); 103 } 104 } 105 106 /* 107 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0200 108 * @tc.name: testMatrixCreateRotationNormal 109 * @tc.desc: Test for creating a rotation matrix with normal parameters. 110 * @tc.size : SmallTest 111 * @tc.type : Function 112 * @tc.level : Level 0 113 */ 114 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateRotationNormal, TestSize.Level0) { 115 // 1. OH_Drawing_MatrixCreateRotation, rotate angles deg traverse 0 degrees, 180 degrees, 360 degrees, -90 degrees, 116 // -180 degrees, -360 degrees, 45.5 degrees, x\y cover decimals and integers 117 float degs[] = {0, 180, 360, -90, -180, -360, 45.5}; 118 float x[] = {0, 10, 10.0f, 20, 20.0f, 30, 30.0f}; 119 float y[] = {0, 10, 10.0f, 20, 20.0f, 30, 30.0f}; 120 for (int i = 0; i < 7; i++) { 121 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateRotation(degs[i], x[i], y[i]); 122 EXPECT_NE(matrix, nullptr); 123 OH_Drawing_MatrixDestroy(matrix); 124 } 125 } 126 127 /* 128 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0201 129 * @tc.name: testMatrixCreateRotationNull 130 * @tc.desc: Test for creating a rotation matrix with NULL parameters. 131 * @tc.size : SmallTest 132 * @tc.type : Function 133 * @tc.level : Level 3 134 */ 135 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateRotationNull, TestSize.Level3) { 136 // 1. OH_Drawing_MatrixCreateRotation with the first parameter as null 137 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateRotation(0, 10.0f, 10.0f); 138 // add assert 139 EXPECT_NE(matrix, nullptr); 140 // 2. OH_Drawing_MatrixCreateRotation with the second parameter as null 141 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateRotation(180, 0, 10.0f); 142 // add assert 143 EXPECT_NE(matrix2, nullptr); 144 // 3. OH_Drawing_MatrixCreateRotation with the third parameter as null 145 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreateRotation(360, 10.0f, 0); 146 // add assert 147 EXPECT_NE(matrix3, nullptr); 148 // 4. Free memory 149 OH_Drawing_MatrixDestroy(matrix); 150 OH_Drawing_MatrixDestroy(matrix2); 151 OH_Drawing_MatrixDestroy(matrix3); 152 } 153 154 /* 155 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0202 156 * @tc.name: testMatrixCreateRotationAbnormal 157 * @tc.desc: Test for creating a rotation matrix with abnormal parameters. 158 * @tc.size : SmallTest 159 * @tc.type : Function 160 * @tc.level : Level 3 161 */ 162 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateRotationAbnormal, TestSize.Level3) { 163 // 1. OH_Drawing_MatrixCreateRotation with an input angle greater than 360 degrees 164 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateRotation(361, 10.0f, 10.0f); 165 // add assert 166 EXPECT_NE(matrix, nullptr); 167 // 2. OH_Drawing_MatrixCreateRotation with a negative value for the x parameter 168 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateRotation(180, -10.0f, 10.0f); 169 // add assert 170 EXPECT_NE(matrix2, nullptr); 171 // 3. OH_Drawing_MatrixCreateRotation with a negative value for the y parameter 172 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreateRotation(180, 10.0f, -10.0f); 173 // add assert 174 EXPECT_NE(matrix3, nullptr); 175 // 4. Free memory 176 OH_Drawing_MatrixDestroy(matrix); 177 OH_Drawing_MatrixDestroy(matrix2); 178 OH_Drawing_MatrixDestroy(matrix3); 179 } 180 181 /* 182 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0203 183 * @tc.name: testMatrixCreateRotationMaximum 184 * @tc.desc: Test for creating a rotation matrix with maximum values. 185 * @tc.size : SmallTest 186 * @tc.type : Function 187 * @tc.level : Level 3 188 */ 189 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateRotationMaximum, TestSize.Level3) { 190 // 1. OH_Drawing_MatrixCreateRotation with the maximum value of the rotation angle parameter deg 191 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateRotation(FLT_MAX, 10.0f, 10.0f); 192 // add assert 193 EXPECT_NE(matrix, nullptr); 194 // 2. OH_Drawing_MatrixCreateRotation with the maximum value of the x parameter 195 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateRotation(180, FLT_MAX, 10.0f); 196 // add assert 197 EXPECT_NE(matrix2, nullptr); 198 // 3. OH_Drawing_MatrixCreateRotation with the maximum value of the y parameter 199 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreateRotation(180, 10.0f, FLT_MAX); 200 // add assert 201 EXPECT_NE(matrix3, nullptr); 202 // 4. Free memory 203 OH_Drawing_MatrixDestroy(matrix); 204 OH_Drawing_MatrixDestroy(matrix2); 205 OH_Drawing_MatrixDestroy(matrix3); 206 } 207 208 /* 209 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0205 210 * @tc.name: testMatrixCreateRotationMultipleCalls 211 * @tc.desc: Test for multiple calls of creating a rotation matrix. 212 * @tc.size : SmallTest 213 * @tc.type : Function 214 * @tc.level : Level 3 215 */ 216 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateRotationMultipleCalls, TestSize.Level3) { 217 // 1. Call OH_Drawing_MatrixCreateRotation 10 times, each time with different rotation angles and coordinate points 218 std::random_device rd; 219 std::mt19937 gen(rd()); 220 std::uniform_int_distribution<int> deg_dist(-360, 360); 221 std::uniform_real_distribution<float> x_dist(0.0f, 100.0f); 222 std::uniform_real_distribution<float> y_dist(0.0f, 100.0f); 223 for (int i = 0; i < 10; i++) { 224 float deg = deg_dist(gen); 225 float x = x_dist(gen); 226 float y = y_dist(gen); 227 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateRotation(deg, x, y); 228 EXPECT_NE(matrix, nullptr); 229 OH_Drawing_MatrixDestroy(matrix); 230 } 231 } 232 233 /* 234 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0300 235 * @tc.name: testMatrixCreateTranslationNormal 236 * @tc.desc: Test for creating a translation matrix with normal parameters. 237 * @tc.size : SmallTest 238 * @tc.type : Function 239 * @tc.level : Level 0 240 */ 241 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateTranslationNormal, TestSize.Level0) { 242 // 1. OH_Drawing_MatrixCreateTranslation, passing in a decimal number 243 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(10.0f, 10.0f); 244 // add assert 245 EXPECT_NE(matrix, nullptr); 246 // 2. OH_Drawing_MatrixCreateTranslation, passing in an integer 247 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateTranslation(20, 20); 248 // add assert 249 EXPECT_NE(matrix2, nullptr); 250 // 3. Free memory 251 OH_Drawing_MatrixDestroy(matrix); 252 OH_Drawing_MatrixDestroy(matrix2); 253 } 254 255 /* 256 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0301 257 * @tc.name: testMatrixCreateTranslationNull 258 * @tc.desc: Test for creating a translation matrix with NULL parameters. 259 * @tc.size : SmallTest 260 * @tc.type : Function 261 * @tc.level : Level 3 262 */ 263 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateTranslationNull, TestSize.Level3) { 264 // 1. OH_Drawing_MatrixCreateTranslation with the first parameter as null 265 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(0, 10.0f); 266 // add assert 267 EXPECT_NE(matrix, nullptr); 268 // 2. OH_Drawing_MatrixCreateTranslation with the second parameter as null 269 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateTranslation(10.0f, 0); 270 // add assert 271 EXPECT_NE(matrix2, nullptr); 272 // 3. Free memory 273 OH_Drawing_MatrixDestroy(matrix); 274 OH_Drawing_MatrixDestroy(matrix2); 275 } 276 277 /* 278 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0302 279 * @tc.name: testMatrixCreateTranslationAbnormal 280 * @tc.desc: Test for creating a translation matrix with abnormal parameters. 281 * @tc.size : SmallTest 282 * @tc.type : Function 283 * @tc.level : Level 3 284 */ 285 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateTranslationAbnormal, TestSize.Level3) { 286 // 1. OH_Drawing_MatrixCreateTranslation with the first parameter as a negative number 287 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(-10.0f, 10.0f); 288 // add assert 289 EXPECT_NE(matrix, nullptr); 290 // 2. OH_Drawing_MatrixCreateTranslation with the second parameter as a negative number 291 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateTranslation(10.0f, -10.0f); 292 // add assert 293 EXPECT_NE(matrix2, nullptr); 294 // 3. Free memory 295 OH_Drawing_MatrixDestroy(matrix); 296 OH_Drawing_MatrixDestroy(matrix2); 297 } 298 299 /* 300 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0303 301 * @tc.name: testMatrixCreateTranslationMaximum 302 * @tc.desc: Test for creating a translation matrix with maximum values. 303 * @tc.size : SmallTest 304 * @tc.type : Function 305 * @tc.level : Level 3 306 */ 307 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateTranslationMaximum, TestSize.Level3) { 308 // 1. OH_Drawing_MatrixCreateTranslation with the first parameter as the maximum value 309 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(FLT_MAX, 10.0f); 310 // add assert 311 EXPECT_NE(matrix, nullptr); 312 // 2. OH_Drawing_MatrixCreateTranslation with the second parameter as the maximum value 313 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateTranslation(10.0f, FLT_MAX); 314 // add assert 315 EXPECT_NE(matrix2, nullptr); 316 // 3. Free memory 317 OH_Drawing_MatrixDestroy(matrix); 318 OH_Drawing_MatrixDestroy(matrix2); 319 } 320 321 /* 322 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0304 323 * @tc.name: testMatrixCreateTranslationMultipleCalls 324 * @tc.desc: Test for multiple calls of creating a translation matrix. 325 * @tc.size : SmallTest 326 * @tc.type : Function 327 * @tc.level : Level 3 328 */ 329 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateTranslationMultipleCalls, TestSize.Level3) { 330 std::random_device rd; 331 std::mt19937 gen(rd()); 332 std::uniform_real_distribution<float> dis(0.0, 100.0); 333 // 1. Call OH_Drawing_MatrixCreateTranslation 10 times, each time with different random values for dx and dy 334 for (int i = 0; i < 10; i++) { 335 float dx = dis(gen); 336 float dy = dis(gen); 337 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(dx, dy); 338 EXPECT_NE(matrix, nullptr); 339 OH_Drawing_MatrixDestroy(matrix); 340 } 341 } 342 343 /* 344 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0400 345 * @tc.name: testMatrixMatrixSetGetMatrixNormal 346 * @tc.desc: Test for setting and getting matrix values with normal parameters. 347 * @tc.size : SmallTest 348 * @tc.type : Function 349 * @tc.level : Level 0 350 */ 351 HWTEST_F(DrawingNativeMatrixTest, testMatrixMatrixSetGetMatrixNormal, TestSize.Level0) { 352 // 1. OH_Drawing_MatrixCreate 353 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 354 EXPECT_NE(matrix, nullptr); 355 // 2. OH_Drawing_MatrixSetMatrix with integer parameters, calling OH_Drawing_MatrixGetAll and 356 // OH_Drawing_MatrixGetValue interfaces 357 OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 0, 0, -1, 0, 0, 0, 1); 358 // add assert 359 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 360 float value[9]; 361 OH_Drawing_ErrorCode code = OH_Drawing_MatrixGetAll(matrix, value); 362 EXPECT_EQ(code, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 363 OH_Drawing_MatrixGetValue(matrix, 0); 364 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 0), 1); 365 // 3. OH_Drawing_MatrixSetMatrix with floating-point parameters, calling OH_Drawing_MatrixGetAll and 366 // OH_Drawing_MatrixGetValue interfaces 367 OH_Drawing_MatrixSetMatrix(matrix, 1.1, 0, 0, 0, -1.1, 0, 0, 0, 1.1); 368 // add assert 369 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 370 OH_Drawing_ErrorCode code2 = OH_Drawing_MatrixGetAll(matrix, value); 371 EXPECT_EQ(code2, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 372 OH_Drawing_MatrixGetValue(matrix, 1); 373 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 1), 0); 374 // 4. Free memory 375 OH_Drawing_MatrixDestroy(matrix); 376 } 377 378 /* 379 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0401 380 * @tc.name: testMatrixMatrixSetGetMatrixNull 381 * @tc.desc: Test for setting and getting matrix values with NULL parameters. 382 * @tc.size : SmallTest 383 * @tc.type : Function 384 * @tc.level : Level 3 385 */ 386 HWTEST_F(DrawingNativeMatrixTest, testMatrixMatrixSetGetMatrixNull, TestSize.Level3) { 387 // 1. OH_Drawing_MatrixCreate 388 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 389 EXPECT_NE(matrix, nullptr); 390 // 2. OH_Drawing_MatrixSetMatrix with the first parameter as null, check the error code with OH_Drawing_ErrorCodeGet 391 OH_Drawing_MatrixSetMatrix(nullptr, 1, 0, 0, 0, -1, 0, 0, 0, 1); 392 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 393 OH_Drawing_ErrorCodeReset(); 394 // 3. OH_Drawing_MatrixSetMatrix with the second to tenth parameters as null 395 OH_Drawing_MatrixSetMatrix(matrix, 0, 1, 1, 1, 1, 1, 1, 1, 1); 396 OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 1, 1, 1, 1, 1, 1, 1); 397 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 0, 1, 1, 1, 1, 1, 1); 398 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 0, 1, 1, 1, 1, 1); 399 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 0, 1, 1, 1, 1); 400 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 0, 1, 1, 1); 401 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 0, 1, 1); 402 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 1, 0, 1); 403 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 1, 1, 0); 404 // 4. OH_Drawing_MatrixGetAll with the first parameter as null, check the error code with OH_Drawing_ErrorCodeGet 405 float value[9]; 406 OH_Drawing_ErrorCode code = OH_Drawing_MatrixGetAll(nullptr, value); 407 EXPECT_EQ(code, OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 408 // 5. OH_Drawing_MatrixGetAll with the second parameter as an empty array, check the error code with 409 // OH_Drawing_ErrorCodeGet 410 float value2[0]; 411 OH_Drawing_ErrorCode code2 = OH_Drawing_MatrixGetAll(matrix, value2); 412 EXPECT_EQ(code2, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 413 // 6. OH_Drawing_MatrixGetAll with the second parameter as null, check the error code with OH_Drawing_ErrorCodeGet 414 OH_Drawing_ErrorCode code3 = OH_Drawing_MatrixGetAll(matrix, nullptr); 415 EXPECT_EQ(code3, OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 416 // 7. OH_Drawing_MatrixGetValue with the first parameter as null, check the error code with OH_Drawing_ErrorCodeGet 417 OH_Drawing_MatrixGetValue(nullptr, 0); 418 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 419 // 8. OH_Drawing_MatrixGetValue with the second parameter as null 420 OH_Drawing_MatrixGetValue(matrix, 0); 421 // 9. Free memory 422 OH_Drawing_MatrixDestroy(matrix); 423 } 424 425 /* 426 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0402 427 * @tc.name: testMatrixMatrixSetGetMatrixAbnormal 428 * @tc.desc: Test for setting and getting matrix values with abnormal parameters. 429 * @tc.size : SmallTest 430 * @tc.type : Function 431 * @tc.level : Level 3 432 */ 433 HWTEST_F(DrawingNativeMatrixTest, testMatrixMatrixSetGetMatrixAbnormal, TestSize.Level3) { 434 // 1. OH_Drawing_MatrixCreate 435 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 436 // add assert 437 EXPECT_NE(matrix, nullptr); 438 // 2. OH_Drawing_MatrixSetMatrix with the second to tenth parameters as negative numbers 439 OH_Drawing_MatrixSetMatrix(matrix, -1, 1, 1, 1, 1, 1, 1, 1, 1); 440 OH_Drawing_MatrixSetMatrix(matrix, 1, -1, 1, 1, 1, 1, 1, 1, 1); 441 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, -1, 1, 1, 1, 1, 1, 1); 442 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, -1, 1, 1, 1, 1, 1); 443 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, -1, 1, 1, 1, 1); 444 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, -1, 1, 1, 1); 445 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, -1, 1, 1); 446 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 1, -1, 1); 447 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 1, 1, -1); 448 // 3. OH_Drawing_MatrixGetAll with an array 'value' of length less than 9 449 float value2[9]; 450 OH_Drawing_ErrorCode code2 = OH_Drawing_MatrixGetAll(matrix, value2); 451 EXPECT_EQ(code2, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 452 // 4. OH_Drawing_MatrixGetValue with the parameter 'index' as -1, check the error code with OH_Drawing_ErrorCodeGet 453 OH_Drawing_MatrixGetValue(matrix, -1); 454 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE); 455 // 5. OH_Drawing_MatrixGetValue with the parameter 'index' as 9, check the error code with OH_Drawing_ErrorCodeGet 456 OH_Drawing_MatrixGetValue(matrix, 9); 457 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE); 458 // 6. Free memory 459 OH_Drawing_MatrixDestroy(matrix); 460 } 461 462 /* 463 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0403 464 * @tc.name: testMatrixMatrixSetGetMatrixMaximum 465 * @tc.desc: Test for setting and getting matrix values with maximum values. 466 * @tc.size : SmallTest 467 * @tc.type : Function 468 * @tc.level : Level 3 469 */ 470 HWTEST_F(DrawingNativeMatrixTest, testMatrixMatrixSetGetMatrixMaximum, TestSize.Level3) { 471 // 1. OH_Drawing_MatrixSetMatrix with the second to tenth parameters as maximum values 472 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 473 // add assert 474 EXPECT_NE(matrix, nullptr); 475 OH_Drawing_MatrixSetMatrix(matrix, FLT_MAX, 1, 1, 1, 1, 1, 1, 1, 1); 476 OH_Drawing_MatrixSetMatrix(matrix, 1, FLT_MAX, 1, 1, 1, 1, 1, 1, 1); 477 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, FLT_MAX, 1, 1, 1, 1, 1, 1); 478 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, FLT_MAX, 1, 1, 1, 1, 1); 479 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, FLT_MAX, 1, 1, 1, 1); 480 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, FLT_MAX, 1, 1, 1); 481 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, FLT_MAX, 1, 1); 482 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 1, FLT_MAX, 1); 483 OH_Drawing_MatrixSetMatrix(matrix, 1, 1, 1, 1, 1, 1, 1, 1, FLT_MAX); 484 // 2. Free memory 485 OH_Drawing_MatrixDestroy(matrix); 486 } 487 488 /* 489 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0404 490 * @tc.name: testMatrixMatrixSetGetMatrixMultipleCalls 491 * @tc.desc: Test for multiple calls of setting and getting matrix values. 492 * @tc.size : SmallTest 493 * @tc.type : Function 494 * @tc.level : Level 3 495 */ 496 HWTEST_F(DrawingNativeMatrixTest, testMatrixMatrixSetGetMatrixMultipleCalls, TestSize.Level3) { 497 // 1. OH_Drawing_MatrixCreate 498 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 499 // add assert 500 EXPECT_NE(matrix, nullptr); 501 // 2. OH_Drawing_MatrixSetMatrix with random parameters, calling the interface 10 times, corresponding to calling 502 // OH_Drawing_MatrixGetAll and OH_Drawing_MatrixGetValue interfaces 503 std::random_device rd; 504 std::mt19937 gen(rd()); 505 std::uniform_real_distribution<float> dis(0.0, 100.0); 506 for (int i = 0; i < 10; i++) { 507 float value[9]; 508 float val0 = dis(gen); 509 float val1 = dis(gen); 510 float val2 = dis(gen); 511 float val3 = dis(gen); 512 float val4 = dis(gen); 513 float val5 = dis(gen); 514 float val6 = dis(gen); 515 float val7 = dis(gen); 516 float val8 = dis(gen); 517 OH_Drawing_MatrixSetMatrix(matrix, val0, val1, val2, val3, val4, val5, val6, val7, val8); 518 OH_Drawing_ErrorCode code = OH_Drawing_MatrixGetAll(matrix, value); 519 EXPECT_EQ(code, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 520 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 0), val0); 521 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 1), val1); 522 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 2), val2); 523 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 3), val3); 524 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 4), val4); 525 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 5), val5); 526 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 6), val6); 527 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 7), val7); 528 EXPECT_EQ(OH_Drawing_MatrixGetValue(matrix, 8), val8); 529 } 530 // 3. Free memory 531 OH_Drawing_MatrixDestroy(matrix); 532 } 533 534 /* 535 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0500 536 * @tc.name: testMatrixTranslateNormal 537 * @tc.desc: Test for translating a matrix with normal parameters. 538 * @tc.size : SmallTest 539 * @tc.type : Function 540 * @tc.level : Level 0 541 */ 542 HWTEST_F(DrawingNativeMatrixTest, testMatrixTranslateNormal, TestSize.Level0) { 543 // 1. OH_Drawing_MatrixCreate 544 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 545 EXPECT_NE(matrix, nullptr); 546 // 2. OH_Drawing_MatrixTranslate, passing in floating point numbers 547 OH_Drawing_MatrixTranslate(matrix, 10.0f, 10.0f); 548 // add assert 549 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 550 // 3. OH_Drawing_MatrixTranslate, passing in integers 551 OH_Drawing_MatrixTranslate(matrix, 20, 20); 552 // add assert 553 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 554 // 4. Free memory 555 OH_Drawing_MatrixDestroy(matrix); 556 } 557 558 /* 559 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0501 560 * @tc.name: testMatrixTranslateNull 561 * @tc.desc: Test for translating a matrix with NULL parameters. 562 * @tc.size : SmallTest 563 * @tc.type : Function 564 * @tc.level : Level 3 565 */ 566 HWTEST_F(DrawingNativeMatrixTest, testMatrixTranslateNull, TestSize.Level3) { 567 // 1. OH_Drawing_MatrixCreate 568 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 569 EXPECT_NE(matrix, nullptr); 570 // 2. OH_Drawing_MatrixTranslate with the first parameter as null, check the error code with OH_Drawing_ErrorCodeGet 571 OH_Drawing_MatrixTranslate(nullptr, 10.0f, 10.0f); 572 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 573 // 3. OH_Drawing_MatrixTranslate with the second parameter as null 574 OH_Drawing_MatrixTranslate(matrix, 0, 10.0f); 575 // 4. OH_Drawing_MatrixTranslate with the third parameter as null 576 OH_Drawing_MatrixTranslate(matrix, 10.0f, 0); 577 // 5. Free memory 578 OH_Drawing_MatrixDestroy(matrix); 579 } 580 581 /* 582 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0502 583 * @tc.name: testMatrixTranslateAbnormal 584 * @tc.desc: Test for translating a matrix with abnormal parameters. 585 * @tc.size : SmallTest 586 * @tc.type : Function 587 * @tc.level : Level 3 588 */ 589 HWTEST_F(DrawingNativeMatrixTest, testMatrixTranslateAbnormal, TestSize.Level3) { 590 // 1. OH_Drawing_MatrixCreate 591 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 592 EXPECT_NE(matrix, nullptr); 593 // 2. OH_Drawing_MatrixTranslate with the second parameter as a negative number 594 OH_Drawing_MatrixTranslate(matrix, -10.0f, 10.0f); 595 // 3. OH_Drawing_MatrixTranslate with the third parameter as a negative number 596 OH_Drawing_MatrixTranslate(matrix, 10.0f, -10.0f); 597 // 4. Free memory 598 OH_Drawing_MatrixDestroy(matrix); 599 } 600 601 /* 602 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0503 603 * @tc.name: testMatrixTranslateMaximum 604 * @tc.desc: Test for translating a matrix with maximum values. 605 * @tc.size : SmallTest 606 * @tc.type : Function 607 * @tc.level : Level 3 608 */ 609 HWTEST_F(DrawingNativeMatrixTest, testMatrixTranslateMaximum, TestSize.Level3) { 610 // 1. OH_Drawing_MatrixCreate 611 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 612 EXPECT_NE(matrix, nullptr); 613 // 2. OH_Drawing_MatrixTranslate with the second parameter as the maximum value 614 OH_Drawing_MatrixTranslate(matrix, FLT_MAX, 10.0f); 615 // 3. OH_Drawing_MatrixTranslate with the third parameter as the maximum value 616 OH_Drawing_MatrixTranslate(matrix, 10.0f, FLT_MAX); 617 // 4. Free memory 618 OH_Drawing_MatrixDestroy(matrix); 619 } 620 621 /* 622 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0504 623 * @tc.name: testMatrixTranslateMultipleCalls 624 * @tc.desc: Test for multiple calls of translating a matrix. 625 * @tc.size : SmallTest 626 * @tc.type : Function 627 * @tc.level : Level 3 628 */ 629 HWTEST_F(DrawingNativeMatrixTest, testMatrixTranslateMultipleCalls, TestSize.Level3) { 630 // 1. OH_Drawing_MatrixCreate 631 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 632 EXPECT_NE(matrix, nullptr); 633 // 2. OH_Drawing_MatrixTranslate, passing in random numbers for dx and dy 634 std::random_device rd; 635 std::mt19937 gen(rd()); 636 std::uniform_real_distribution<float> dis(0.0, 100.0); 637 for (int i = 0; i < 10; i++) { 638 float dx = dis(gen); 639 float dy = dis(gen); 640 OH_Drawing_MatrixTranslate(matrix, dx, dy); 641 } 642 // 3. Free memory 643 OH_Drawing_MatrixDestroy(matrix); 644 } 645 646 /* 647 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0600 648 * @tc.name: testMatrixRotateNormal 649 * @tc.desc: test for testMatrixRotateNormal. 650 * @tc.size : SmallTest 651 * @tc.type : Function 652 * @tc.level : Level 0 653 */ 654 HWTEST_F(DrawingNativeMatrixTest, testMatrixRotateNormal, TestSize.Level0) { 655 // 1. OH_Drawing_MatrixCreate 656 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 657 EXPECT_NE(matrix, nullptr); 658 // 2. OH_Drawing_MatrixRotate, rotate angles include 0 degrees, 180 degrees, 360 degrees, -90 degrees, -180 degrees, 659 // -360 degrees, and 45.5 degrees, px and py cover both decimals and integers 660 OH_Drawing_MatrixRotate(matrix, 0, 0, 0); 661 // add assert 662 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 663 OH_Drawing_MatrixRotate(matrix, 180, 10, 10); 664 // add assert 665 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 666 OH_Drawing_MatrixRotate(matrix, 360, 10.0f, 10.0f); 667 // add assert 668 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 669 OH_Drawing_MatrixRotate(matrix, -90, 20, 20); 670 // add assert 671 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 672 OH_Drawing_MatrixRotate(matrix, -180, 20.0f, 20.0f); 673 // add assert 674 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 675 OH_Drawing_MatrixRotate(matrix, -360, 30, 30); 676 // add assert 677 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 678 OH_Drawing_MatrixRotate(matrix, 45.5, 30.0f, 30.0f); 679 // add assert 680 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 681 // 3. Free memory 682 OH_Drawing_MatrixDestroy(matrix); 683 } 684 685 /* 686 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0601 687 * @tc.name: testMatrixRotateNull 688 * @tc.desc: test for testMatrixRotateNull. 689 * @tc.size : SmallTest 690 * @tc.type : Function 691 * @tc.level : Level 3 692 */ 693 HWTEST_F(DrawingNativeMatrixTest, testMatrixRotateNull, TestSize.Level3) { 694 // 1. OH_Drawing_MatrixCreate 695 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 696 EXPECT_NE(matrix, nullptr); 697 // 2. OH_Drawing_MatrixRotate with the first parameter as null, check the error code with OH_Drawing_ErrorCodeGet 698 OH_Drawing_MatrixRotate(nullptr, 180, 10, 10); 699 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 700 // 3. OH_Drawing_MatrixRotate with the second parameter as null 701 OH_Drawing_MatrixRotate(matrix, 0, 10, 10); 702 // 4. OH_Drawing_MatrixRotate with the third parameter as null 703 OH_Drawing_MatrixRotate(matrix, 180, 0, 10); 704 // 5. OH_Drawing_MatrixRotate with the fourth parameter as null 705 OH_Drawing_MatrixRotate(matrix, 180, 10, 0); 706 // 6. Free memory 707 OH_Drawing_MatrixDestroy(matrix); 708 } 709 710 /* 711 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0602 712 * @tc.name: testMatrixRotateAbnormal 713 * @tc.desc: test for testMatrixRotateAbnormal. 714 * @tc.size : SmallTest 715 * @tc.type : Function 716 * @tc.level : Level 3 717 */ 718 HWTEST_F(DrawingNativeMatrixTest, testMatrixRotateAbnormal, TestSize.Level3) { 719 // 1. OH_Drawing_MatrixCreate 720 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 721 // add assert 722 EXPECT_NE(matrix, nullptr); 723 // 2. OH_Drawing_MatrixRotate with the third parameter as a negative number 724 OH_Drawing_MatrixRotate(matrix, 180, -10, 10); 725 // 3. OH_Drawing_MatrixRotate with the fourth parameter as a negative number 726 OH_Drawing_MatrixRotate(matrix, 180, 10, -10); 727 // 4. Free memory 728 OH_Drawing_MatrixDestroy(matrix); 729 } 730 731 /* 732 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0603 733 * @tc.name: testMatrixRotateMaximum 734 * @tc.desc: test for testMatrixRotateMaximum. 735 * @tc.size : SmallTest 736 * @tc.type : Function 737 * @tc.level : Level 3 738 */ 739 HWTEST_F(DrawingNativeMatrixTest, testMatrixRotateMaximum, TestSize.Level3) { 740 // 1. OH_Drawing_MatrixCreate 741 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 742 // add assert 743 EXPECT_NE(matrix, nullptr); 744 // 2. OH_Drawing_MatrixRotate with the second parameter as the maximum value 745 OH_Drawing_MatrixRotate(matrix, FLT_MAX, 10.0f, 10.0f); 746 // 3. OH_Drawing_MatrixRotate with the third parameter as the maximum value 747 OH_Drawing_MatrixRotate(matrix, 180, FLT_MAX, 10.0f); 748 // 4. OH_Drawing_MatrixRotate with the fourth parameter as the maximum value 749 OH_Drawing_MatrixRotate(matrix, 180, 10.0f, FLT_MAX); 750 // 5. Free memory 751 OH_Drawing_MatrixDestroy(matrix); 752 } 753 754 /* 755 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0604 756 * @tc.name: testMatrixRotateMultipleCalls 757 * @tc.desc: test for testMatrixRotateMultipleCalls. 758 * @tc.size : SmallTest 759 * @tc.type : Function 760 * @tc.level : Level 3 761 */ 762 HWTEST_F(DrawingNativeMatrixTest, testMatrixRotateMultipleCalls, TestSize.Level3) { 763 // 1. OH_Drawing_MatrixCreate 764 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 765 // add assert 766 EXPECT_NE(matrix, nullptr); 767 // 2. OH_Drawing_MatrixRotate, passing in random numbers for degree, px, and py 768 std::random_device rd; 769 std::mt19937 gen(rd()); 770 std::uniform_real_distribution<float> dis(0.0, 100.0); 771 for (int i = 0; i < 10; i++) { 772 float degree = dis(gen); 773 float px = dis(gen); 774 float py = dis(gen); 775 OH_Drawing_MatrixRotate(matrix, degree, px, py); 776 } 777 // 3. Free memory 778 OH_Drawing_MatrixDestroy(matrix); 779 } 780 781 /* 782 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0700 783 * @tc.name: testMatrixCreateScaleNormal 784 * @tc.desc: test for testMatrixCreateScaleNormal. 785 * @tc.size : SmallTest 786 * @tc.type : Function 787 * @tc.level : Level 0 788 */ 789 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateScaleNormal, TestSize.Level0) { 790 // 1. OH_Drawing_MatrixCreateScale, passing in decimals 791 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, 10.0f, 10.0f); 792 EXPECT_NE(matrix, nullptr); 793 // 2. OH_Drawing_MatrixCreateScale, passing in integers 794 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateScale(20, 20, 20, 20); 795 EXPECT_NE(matrix2, nullptr); 796 // 3. Free memory 797 OH_Drawing_MatrixDestroy(matrix); 798 OH_Drawing_MatrixDestroy(matrix2); 799 } 800 801 /* 802 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0701 803 * @tc.name: testMatrixCreateScaleNull 804 * @tc.desc: test for testMatrixCreateScaleNull. 805 * @tc.size : SmallTest 806 * @tc.type : Function 807 * @tc.level : Level 3 808 */ 809 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateScaleNull, TestSize.Level3) { 810 // 1. OH_Drawing_MatrixCreateScale with the first parameter as null 811 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateScale(0, 10.0f, 10.0f, 10.0f); 812 // add assert 813 EXPECT_NE(matrix, nullptr); 814 // 2. OH_Drawing_MatrixCreateScale with the second parameter as null 815 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateScale(10.0f, 0, 10.0f, 10.0f); 816 // add assert 817 EXPECT_NE(matrix2, nullptr); 818 // 3. OH_Drawing_MatrixCreateScale with the third parameter as null 819 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, 0, 10.0f); 820 // add assert 821 EXPECT_NE(matrix3, nullptr); 822 // 4. OH_Drawing_MatrixCreateScale with the fourth parameter as null 823 OH_Drawing_Matrix *matrix4 = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, 10.0f, 0); 824 // add assert 825 EXPECT_NE(matrix4, nullptr); 826 // 5. Free memory 827 OH_Drawing_MatrixDestroy(matrix); 828 OH_Drawing_MatrixDestroy(matrix2); 829 OH_Drawing_MatrixDestroy(matrix3); 830 OH_Drawing_MatrixDestroy(matrix4); 831 } 832 833 /* 834 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0702 835 * @tc.name: testMatrixCreateScaleAbnormal 836 * @tc.desc: test for testMatrixCreateScaleAbnormal. 837 * @tc.size : SmallTest 838 * @tc.type : Function 839 * @tc.level : Level 3 840 */ 841 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateScaleAbnormal, TestSize.Level3) { 842 // 1. OH_Drawing_MatrixCreateScale with the first parameter as a negative number 843 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateScale(-10.0f, 10.0f, 10.0f, 10.0f); 844 // add assert 845 EXPECT_NE(matrix, nullptr); 846 // 2. OH_Drawing_MatrixCreateScale with the second parameter as a negative number 847 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateScale(10.0f, -10.0f, 10.0f, 10.0f); 848 // add assert 849 EXPECT_NE(matrix2, nullptr); 850 // 3. OH_Drawing_MatrixCreateScale with the third parameter as a negative number 851 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, -10.0f, 10.0f); 852 // add assert 853 EXPECT_NE(matrix3, nullptr); 854 // 4. OH_Drawing_MatrixCreateScale with the fourth parameter as a negative number 855 OH_Drawing_Matrix *matrix4 = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, 10.0f, -10.0f); 856 // add assert 857 EXPECT_NE(matrix4, nullptr); 858 // 5. Free memory 859 OH_Drawing_MatrixDestroy(matrix); 860 OH_Drawing_MatrixDestroy(matrix2); 861 OH_Drawing_MatrixDestroy(matrix3); 862 OH_Drawing_MatrixDestroy(matrix4); 863 } 864 865 /* 866 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0703 867 * @tc.name: testMatrixCreateScaleMaximum 868 * @tc.desc: test for testMatrixCreateScaleMaximum. 869 * @tc.size : SmallTest 870 * @tc.type : Function 871 * @tc.level : Level 3 872 */ 873 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateScaleMaximum, TestSize.Level3) { 874 // 1. OH_Drawing_MatrixCreateScale with the first parameter as the maximum value 875 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateScale(FLT_MAX, 10.0f, 10.0f, 10.0f); 876 // add assert 877 EXPECT_NE(matrix, nullptr); 878 // 2. OH_Drawing_MatrixCreateScale with the second parameter as the maximum value 879 OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateScale(10.0f, FLT_MAX, 10.0f, 10.0f); 880 // add assert 881 EXPECT_NE(matrix2, nullptr); 882 // 3. OH_Drawing_MatrixCreateScale with the third parameter as the maximum value 883 OH_Drawing_Matrix *matrix3 = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, FLT_MAX, 10.0f); 884 // add assert 885 EXPECT_NE(matrix3, nullptr); 886 // 4. OH_Drawing_MatrixCreateScale with the fourth parameter as the maximum value 887 OH_Drawing_Matrix *matrix4 = OH_Drawing_MatrixCreateScale(10.0f, 10.0f, 10.0f, FLT_MAX); 888 // add assert 889 EXPECT_NE(matrix4, nullptr); 890 // 5. Free memory 891 OH_Drawing_MatrixDestroy(matrix); 892 OH_Drawing_MatrixDestroy(matrix2); 893 OH_Drawing_MatrixDestroy(matrix3); 894 OH_Drawing_MatrixDestroy(matrix4); 895 } 896 897 /* 898 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0704 899 * @tc.name: testMatrixCreateScaleMultipleCalls 900 * @tc.desc: test for testMatrixCreateScaleMultipleCalls. 901 * @tc.size : SmallTest 902 * @tc.type : Function 903 * @tc.level : Level 3 904 */ 905 HWTEST_F(DrawingNativeMatrixTest, testMatrixCreateScaleMultipleCalls, TestSize.Level3) { 906 // 1. Call OH_Drawing_MatrixCreateScale 10 times with random numbers for sx, sy, px, and py, and ensure successful 907 // execution 908 std::random_device rd; 909 std::mt19937 gen(rd()); 910 std::uniform_real_distribution<float> dis(0.0, 100.0); 911 for (int i = 0; i < 10; i++) { 912 float sx = dis(gen); 913 float sy = dis(gen); 914 float px = dis(gen); 915 float py = dis(gen); 916 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateScale(sx, sy, px, py); 917 EXPECT_NE(matrix, nullptr); 918 OH_Drawing_MatrixDestroy(matrix); 919 } 920 } 921 922 /* 923 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0800 924 * @tc.name: testMatrixScaleNormal 925 * @tc.desc: test for testMatrixScaleNormal. 926 * @tc.size : SmallTest 927 * @tc.type : Function 928 * @tc.level : Level 0 929 */ 930 HWTEST_F(DrawingNativeMatrixTest, testMatrixScaleNormal, TestSize.Level0) { 931 // 1. OH_Drawing_MatrixCreate 932 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 933 // add assert 934 EXPECT_NE(matrix, nullptr); 935 // 2. OH_Drawing_MatrixScale, passing in decimals 936 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, 10.0f, 10.0f); 937 // add assert 938 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 939 // 3. OH_Drawing_MatrixScale, passing in integers 940 OH_Drawing_MatrixScale(matrix, 20, 20, 20, 20); 941 // add assert 942 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 943 // 4. Free memory 944 OH_Drawing_MatrixDestroy(matrix); 945 } 946 947 /* 948 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0801 949 * @tc.name: testMatrixScaleNull 950 * @tc.desc: test for testMatrixScaleNull. 951 * @tc.size : SmallTest 952 * @tc.type : Function 953 * @tc.level : Level 3 954 */ 955 HWTEST_F(DrawingNativeMatrixTest, testMatrixScaleNull, TestSize.Level3) { 956 // 1. OH_Drawing_MatrixCreate 957 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 958 // add assert 959 EXPECT_NE(matrix, nullptr); 960 // 2. OH_Drawing_MatrixScale with the first parameter as null, check the error code using OH_Drawing_ErrorCodeGet 961 OH_Drawing_MatrixScale(nullptr, 10.0f, 10.0f, 10.0f, 10.0f); 962 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 963 // 3. OH_Drawing_MatrixScale with the second parameter as null 964 OH_Drawing_MatrixScale(matrix, 0, 10.0f, 10.0f, 10.0f); 965 // 4. OH_Drawing_MatrixScale with the third parameter as null 966 OH_Drawing_MatrixScale(matrix, 10.0f, 0, 10.0f, 10.0f); 967 // 5. OH_Drawing_MatrixScale with the fourth parameter as null 968 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, 0, 10.0f); 969 // 6. OH_Drawing_MatrixScale with the fifth parameter as null 970 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, 10.0f, 0); 971 // 7. Free memory 972 OH_Drawing_MatrixDestroy(matrix); 973 } 974 975 /* 976 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0802 977 * @tc.name: testMatrixScaleAbnormal 978 * @tc.desc: test for testMatrixScaleAbnormal. 979 * @tc.size : SmallTest 980 * @tc.type : Function 981 * @tc.level : Level 3 982 */ 983 HWTEST_F(DrawingNativeMatrixTest, testMatrixScaleAbnormal, TestSize.Level3) { 984 // 1. OH_Drawing_MatrixCreate 985 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 986 // add assert 987 EXPECT_NE(matrix, nullptr); 988 // 2. OH_Drawing_MatrixScale with the second parameter as a negative number 989 OH_Drawing_MatrixScale(matrix, -10.0f, 10.0f, 10.0f, 10.0f); 990 // 3. OH_Drawing_MatrixScale with the third parameter as a negative number 991 OH_Drawing_MatrixScale(matrix, 10.0f, -10.0f, 10.0f, 10.0f); 992 // 4. OH_Drawing_MatrixScale with the fourth parameter as a negative number 993 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, -10.0f, 10.0f); 994 // 5. OH_Drawing_MatrixScale with the fifth parameter as a negative number 995 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, 10.0f, -10.0f); 996 // 6. Free memory 997 OH_Drawing_MatrixDestroy(matrix); 998 } 999 1000 /* 1001 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0803 1002 * @tc.name: testMatrixScaleMaximum 1003 * @tc.desc: test for testMatrixScaleMaximum. 1004 * @tc.size : SmallTest 1005 * @tc.type : Function 1006 * @tc.level : Level 3 1007 */ 1008 HWTEST_F(DrawingNativeMatrixTest, testMatrixScaleMaximum, TestSize.Level3) { 1009 // 1. OH_Drawing_MatrixCreate 1010 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1011 // add assert 1012 EXPECT_NE(matrix, nullptr); 1013 // 2. OH_Drawing_MatrixScale with the second parameter as the maximum value 1014 OH_Drawing_MatrixScale(matrix, FLT_MAX, 10.0f, 10.0f, 10.0f); 1015 // 3. OH_Drawing_MatrixScale with the third parameter as the maximum value 1016 OH_Drawing_MatrixScale(matrix, 10.0f, FLT_MAX, 10.0f, 10.0f); 1017 // 4. OH_Drawing_MatrixScale with the fourth parameter as the maximum value 1018 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, FLT_MAX, 10.0f); 1019 // 5. OH_Drawing_MatrixScale with the fifth parameter as the maximum value 1020 OH_Drawing_MatrixScale(matrix, 10.0f, 10.0f, 10.0f, FLT_MAX); 1021 // 6. Free memory 1022 OH_Drawing_MatrixDestroy(matrix); 1023 } 1024 1025 /* 1026 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0804 1027 * @tc.name: testMatrixScaleMultipleCalls 1028 * @tc.desc: test for testMatrixScaleMultipleCalls. 1029 * @tc.size : SmallTest 1030 * @tc.type : Function 1031 * @tc.level : Level 3 1032 */ 1033 HWTEST_F(DrawingNativeMatrixTest, testMatrixScaleMultipleCalls, TestSize.Level3) { 1034 // 1. OH_Drawing_MatrixCreate 1035 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1036 // add assert 1037 EXPECT_NE(matrix, nullptr); 1038 // 2. Call OH_Drawing_MatrixCreateScale 10 times with random numbers for sx, sy, px, and py 1039 std::random_device rd; 1040 std::mt19937 gen(rd()); 1041 std::uniform_real_distribution<float> dis(0.0, 100.0); 1042 for (int i = 0; i < 10; i++) { 1043 float sx = dis(gen); 1044 float sy = dis(gen); 1045 float px = dis(gen); 1046 float py = dis(gen); 1047 OH_Drawing_MatrixScale(matrix, sx, sy, px, py); 1048 } 1049 // 3. Free memory 1050 OH_Drawing_MatrixDestroy(matrix); 1051 } 1052 1053 /* 1054 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0900 1055 * @tc.name: testMatrixSetRectToRectNormal 1056 * @tc.desc: test for testMatrixSetRectToRectNormal. 1057 * @tc.size : SmallTest 1058 * @tc.type : Function 1059 * @tc.level : Level 0 1060 */ 1061 HWTEST_F(DrawingNativeMatrixTest, testMatrixSetRectToRectNormal, TestSize.Level0) { 1062 // 1. OH_Drawing_MatrixCreate 1063 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1064 // add assert 1065 EXPECT_NE(matrix, nullptr); 1066 // 2. Enumerate OH_Drawing_ScaleToFit values in OH_Drawing_MatrixSetRectToRect 1067 OH_Drawing_Rect *rectSrc = OH_Drawing_RectCreate(0, 0, 100, 100); 1068 OH_Drawing_Rect *rectDst = OH_Drawing_RectCreate(0, 0, 200, 200); 1069 OH_Drawing_ScaleToFit fitList[] = { 1070 SCALE_TO_FIT_FILL, 1071 SCALE_TO_FIT_START, 1072 SCALE_TO_FIT_CENTER, 1073 SCALE_TO_FIT_END, 1074 }; 1075 for (OH_Drawing_ScaleToFit fit : fitList) { 1076 bool isSuccess = OH_Drawing_MatrixSetRectToRect(matrix, rectSrc, rectDst, fit); 1077 EXPECT_EQ(isSuccess, true); 1078 } 1079 // 3. Free memory 1080 OH_Drawing_MatrixDestroy(matrix); 1081 OH_Drawing_RectDestroy(rectSrc); 1082 OH_Drawing_RectDestroy(rectDst); 1083 } 1084 1085 /* 1086 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0901 1087 * @tc.name: testMatrixSetRectToRectNull 1088 * @tc.desc: test for testMatrixSetRectToRectNull. 1089 * @tc.size : SmallTest 1090 * @tc.type : Function 1091 * @tc.level : Level 3 1092 */ 1093 HWTEST_F(DrawingNativeMatrixTest, testMatrixSetRectToRectNull, TestSize.Level3) { 1094 // 1. OH_Drawing_MatrixCreate 1095 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1096 // add assert 1097 EXPECT_NE(matrix, nullptr); 1098 OH_Drawing_Rect *rectSrc = OH_Drawing_RectCreate(0, 0, 0, 0); 1099 // add assert 1100 EXPECT_NE(rectSrc, nullptr); 1101 OH_Drawing_Rect *rectDst = OH_Drawing_RectCreate(0, 0, 0, 0); 1102 // add assert 1103 EXPECT_NE(rectDst, nullptr); 1104 // 2. OH_Drawing_MatrixSetRectToRect, the first parameter is null, check the error code using 1105 // OH_Drawing_ErrorCodeGet 1106 OH_Drawing_MatrixSetRectToRect(nullptr, rectSrc, rectDst, SCALE_TO_FIT_FILL); 1107 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1108 OH_Drawing_ErrorCodeReset(); 1109 // 3. OH_Drawing_MatrixSetRectToRect, the second parameter is null, check the error code using 1110 // OH_Drawing_ErrorCodeGet 1111 OH_Drawing_MatrixSetRectToRect(matrix, nullptr, rectDst, SCALE_TO_FIT_FILL); 1112 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1113 OH_Drawing_ErrorCodeReset(); 1114 // 4. OH_Drawing_MatrixSetRectToRect, the third parameter is null, check the error code using 1115 // OH_Drawing_ErrorCodeGet 1116 OH_Drawing_MatrixSetRectToRect(matrix, rectSrc, nullptr, SCALE_TO_FIT_FILL); 1117 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1118 // 5. Free memory 1119 OH_Drawing_MatrixDestroy(matrix); 1120 OH_Drawing_RectDestroy(rectSrc); 1121 OH_Drawing_RectDestroy(rectDst); 1122 } 1123 1124 /* 1125 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_0902 1126 * @tc.name: testMatrixSetRectToRectMultipleCalls 1127 * @tc.desc: test for testMatrixSetRectToRectMultipleCalls. 1128 * @tc.size : SmallTest 1129 * @tc.type : Function 1130 * @tc.level : Level 3 1131 */ 1132 HWTEST_F(DrawingNativeMatrixTest, testMatrixSetRectToRectMultipleCalls, TestSize.Level3) { 1133 // 1. OH_Drawing_MatrixCreate 1134 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1135 // add assert 1136 EXPECT_NE(matrix, nullptr); 1137 // 2. Call OH_Drawing_MatrixSetRectToRect 10 times with random enum values and different rect sizes 1138 std::random_device rd; 1139 std::mt19937 gen(rd()); 1140 std::uniform_real_distribution<float> dis(0.0, 100.0); 1141 OH_Drawing_ScaleToFit fitList[] = { 1142 SCALE_TO_FIT_FILL, 1143 SCALE_TO_FIT_START, 1144 SCALE_TO_FIT_CENTER, 1145 SCALE_TO_FIT_END, 1146 }; 1147 for (int i = 0; i < 10; i++) { 1148 OH_Drawing_Rect *rectSrc = OH_Drawing_RectCreate(dis(gen), dis(gen), dis(gen) + 100, dis(gen) + 100); 1149 OH_Drawing_Rect *rectDst = OH_Drawing_RectCreate(dis(gen), dis(gen), dis(gen) + 200, dis(gen) + 200); 1150 OH_Drawing_ScaleToFit fit = fitList[i % 4]; 1151 bool isSuccess = OH_Drawing_MatrixSetRectToRect(matrix, rectSrc, rectDst, fit); 1152 EXPECT_EQ(isSuccess, true); 1153 OH_Drawing_RectDestroy(rectSrc); 1154 OH_Drawing_RectDestroy(rectDst); 1155 } 1156 } 1157 1158 /* 1159 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1000 1160 * @tc.name: testMatrixPreRotateNormal 1161 * @tc.desc: test for testMatrixPreRotateNormal. 1162 * @tc.size : SmallTest 1163 * @tc.type : Function 1164 * @tc.level : Level 0 1165 */ 1166 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreRotateNormal, TestSize.Level0) { 1167 // 1. OH_Drawing_MatrixCreate 1168 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1169 // add assert 1170 EXPECT_NE(matrix, nullptr); 1171 // 2. OH_Drawing_MatrixPreRotate, rotate angles include 0 degrees, 180 degrees, 360 degrees, -90 degrees, -180 1172 // degrees, -360 degrees, and 45.5 degrees, px and py cover both decimals and integers 1173 OH_Drawing_MatrixPreRotate(matrix, 0, 0, 0); 1174 // add assert 1175 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1176 OH_Drawing_MatrixPreRotate(matrix, 180, 10, 10); 1177 // add assert 1178 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1179 OH_Drawing_MatrixPreRotate(matrix, 360, 10.0f, 10.0f); 1180 // add assert 1181 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1182 OH_Drawing_MatrixPreRotate(matrix, -90, 20, 20); 1183 // add assert 1184 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1185 OH_Drawing_MatrixPreRotate(matrix, -180, 20.0f, 20.0f); 1186 // add assert 1187 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1188 OH_Drawing_MatrixPreRotate(matrix, -360, 30, 30); 1189 // add assert 1190 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1191 OH_Drawing_MatrixPreRotate(matrix, 45.5, 30.0f, 30.0f); 1192 // add assert 1193 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1194 // 3. Free memory 1195 OH_Drawing_MatrixDestroy(matrix); 1196 } 1197 1198 /* 1199 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1001 1200 * @tc.name: testMatrixPreRotateNull 1201 * @tc.desc: test for testMatrixPreRotateNull. 1202 * @tc.size : SmallTest 1203 * @tc.type : Function 1204 * @tc.level : Level 3 1205 */ 1206 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreRotateNull, TestSize.Level3) { 1207 // 1. OH_Drawing_MatrixCreate 1208 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1209 // add assert 1210 EXPECT_NE(matrix, nullptr); 1211 // 2. OH_Drawing_MatrixPreRotate with the first parameter as null, check the error code using 1212 // OH_Drawing_ErrorCodeGet, no crash, error code returns OH_DRAWING_ERROR_INVALID_PARAMETER 1213 OH_Drawing_MatrixPreRotate(nullptr, 180, 10, 10); 1214 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1215 // 3. OH_Drawing_MatrixPreRotate with the second parameter as null 1216 OH_Drawing_MatrixPreRotate(matrix, 0, 10, 10); 1217 // 4. OH_Drawing_MatrixPreRotate with the third parameter as null 1218 OH_Drawing_MatrixPreRotate(matrix, 180, 0, 10); 1219 // 5. OH_Drawing_MatrixPreRotate with the fourth parameter as null 1220 OH_Drawing_MatrixPreRotate(matrix, 180, 10, 0); 1221 // 6. Free memory 1222 OH_Drawing_MatrixDestroy(matrix); 1223 } 1224 1225 /* 1226 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1002 1227 * @tc.name: testMatrixPreRotateAbnormal 1228 * @tc.desc: test for testMatrixPreRotateAbnormal. 1229 * @tc.size : SmallTest 1230 * @tc.type : Function 1231 * @tc.level : Level 3 1232 */ 1233 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreRotateAbnormal, TestSize.Level3) { 1234 // 1. OH_Drawing_MatrixCreate 1235 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1236 // add assert 1237 EXPECT_NE(matrix, nullptr); 1238 // 2. OH_Drawing_MatrixPreRotate with a negative value for the third parameter 1239 OH_Drawing_MatrixPreRotate(matrix, 180, -10, 10); 1240 // 3. OH_Drawing_MatrixPreRotate with a negative value for the fourth parameter 1241 OH_Drawing_MatrixPreRotate(matrix, 180, 10, -10); 1242 // 4. Free memory 1243 OH_Drawing_MatrixDestroy(matrix); 1244 } 1245 1246 /* 1247 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1003 1248 * @tc.name: testMatrixPreRotateMaximum 1249 * @tc.desc: test for testMatrixPreRotateMaximum. 1250 * @tc.size : SmallTest 1251 * @tc.type : Function 1252 * @tc.level : Level 3 1253 */ 1254 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreRotateMaximum, TestSize.Level3) { 1255 // 1. OH_Drawing_MatrixCreate 1256 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1257 // add assert 1258 EXPECT_NE(matrix, nullptr); 1259 // 2. OH_Drawing_MatrixPreRotate with the second parameter as the maximum value 1260 OH_Drawing_MatrixPreRotate(matrix, FLT_MAX, 10.0f, 10.0f); 1261 // 3. OH_Drawing_MatrixPreRotate with the third parameter as the maximum value 1262 OH_Drawing_MatrixPreRotate(matrix, 180, FLT_MAX, 10.0f); 1263 // 4. OH_Drawing_MatrixPreRotate with the fourth parameter as the maximum value 1264 OH_Drawing_MatrixPreRotate(matrix, 180, 10.0f, FLT_MAX); 1265 // 5. Free memory 1266 OH_Drawing_MatrixDestroy(matrix); 1267 } 1268 1269 /* 1270 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1004 1271 * @tc.name: testMatrixPreRotateMultipleCalls 1272 * @tc.desc: test for testMatrixPreRotateMultipleCalls. 1273 * @tc.size : SmallTest 1274 * @tc.type : Function 1275 * @tc.level : Level 3 1276 */ 1277 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreRotateMultipleCalls, TestSize.Level3) { 1278 // 1. OH_Drawing_MatrixCreate 1279 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1280 // add assert 1281 EXPECT_NE(matrix, nullptr); 1282 // 2. OH_Drawing_MatrixPreRotate, pass in random numbers for degree, px, and py 1283 std::random_device rd; 1284 std::mt19937 gen(rd()); 1285 std::uniform_real_distribution<float> dis(0.0, 100.0); 1286 for (int i = 0; i < 10; i++) { 1287 float degree = dis(gen); 1288 float px = dis(gen); 1289 float py = dis(gen); 1290 OH_Drawing_MatrixPreRotate(matrix, degree, px, py); 1291 } 1292 // 3. Free memory 1293 OH_Drawing_MatrixDestroy(matrix); 1294 } 1295 1296 /* 1297 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1100 1298 * @tc.name: testMatrixPreScaleNormal 1299 * @tc.desc: test for testMatrixPreScaleNormal. 1300 * @tc.size : SmallTest 1301 * @tc.type : Function 1302 * @tc.level : Level 0 1303 */ 1304 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreScaleNormal, TestSize.Level0) { 1305 // 1. OH_Drawing_MatrixCreate 1306 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1307 // add assert 1308 EXPECT_NE(matrix, nullptr); 1309 // 2. OH_Drawing_MatrixPreScale, pass in decimals 1310 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, 10.0f, 10.0f); 1311 // add assert 1312 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1313 // 3. OH_Drawing_MatrixPreScale, pass in integers 1314 OH_Drawing_MatrixPreScale(matrix, 20, 20, 20, 20); 1315 // add assert 1316 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1317 // 4. Free memory 1318 OH_Drawing_MatrixDestroy(matrix); 1319 } 1320 1321 /* 1322 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1101 1323 * @tc.name: testMatrixPreScaleNull 1324 * @tc.desc: test for testMatrixPreScaleNull. 1325 * @tc.size : SmallTest 1326 * @tc.type : Function 1327 * @tc.level : Level 3 1328 */ 1329 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreScaleNull, TestSize.Level3) { 1330 // 1. OH_Drawing_MatrixCreate 1331 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1332 // add assert 1333 EXPECT_NE(matrix, nullptr); 1334 // 2. OH_Drawing_MatrixPreScale, the first parameter is null, check the error code using OH_Drawing_ErrorCodeGet, no 1335 // crash, error code returns OH_DRAWING_ERROR_INVALID_PARAMETER 1336 OH_Drawing_MatrixPreScale(nullptr, 10.0f, 10.0f, 10.0f, 10.0f); 1337 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1338 // 3. OH_Drawing_MatrixPreScale, the second parameter is null 1339 OH_Drawing_MatrixPreScale(matrix, 0, 10.0f, 10.0f, 10.0f); 1340 // 4. OH_Drawing_MatrixPreScale, the third parameter is null 1341 OH_Drawing_MatrixPreScale(matrix, 10.0f, 0, 10.0f, 10.0f); 1342 // 5. OH_Drawing_MatrixPreScale, the fourth parameter is null 1343 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, 0, 10.0f); 1344 // 6. OH_Drawing_MatrixPreScale, the fifth parameter is null 1345 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, 10.0f, 0); 1346 // 7. Free memory 1347 OH_Drawing_MatrixDestroy(matrix); 1348 } 1349 1350 /* 1351 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1102 1352 * @tc.name: testMatrixPreScaleAbnormal 1353 * @tc.desc: test for testMatrixPreScaleAbnormal. 1354 * @tc.size : SmallTest 1355 * @tc.type : Function 1356 * @tc.level : Level 3 1357 */ 1358 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreScaleAbnormal, TestSize.Level3) { 1359 // 1. OH_Drawing_MatrixCreate 1360 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1361 // add assert 1362 EXPECT_NE(matrix, nullptr); 1363 // 2. OH_Drawing_MatrixPreScale, the second parameter is negative 1364 OH_Drawing_MatrixPreScale(matrix, -10.0f, 10.0f, 10.0f, 10.0f); 1365 // 3. OH_Drawing_MatrixPreScale, the third parameter is negative 1366 OH_Drawing_MatrixPreScale(matrix, 10.0f, -10.0f, 10.0f, 10.0f); 1367 // 4. OH_Drawing_MatrixPreScale, the fourth parameter is negative 1368 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, -10.0f, 10.0f); 1369 // 5. OH_Drawing_MatrixPreScale, the fifth parameter is negative 1370 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, 10.0f, -10.0f); 1371 // 6. Free memory 1372 OH_Drawing_MatrixDestroy(matrix); 1373 } 1374 1375 /* 1376 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1103 1377 * @tc.name: testMatrixPreScaleMaximum 1378 * @tc.desc: test for testMatrixPreScaleMaximum. 1379 * @tc.size : SmallTest 1380 * @tc.type : Function 1381 * @tc.level : Level 3 1382 */ 1383 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreScaleMaximum, TestSize.Level3) { 1384 // 1. OH_Drawing_MatrixCreate 1385 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1386 // add assert 1387 EXPECT_NE(matrix, nullptr); 1388 // 2. OH_Drawing_MatrixPreScale with the second parameter as the maximum value 1389 OH_Drawing_MatrixPreScale(matrix, FLT_MAX, 10.0f, 10.0f, 10.0f); 1390 // 3. OH_Drawing_MatrixPreScale with the third parameter as the maximum value 1391 OH_Drawing_MatrixPreScale(matrix, 10.0f, FLT_MAX, 10.0f, 10.0f); 1392 // 4. OH_Drawing_MatrixPreScale with the fourth parameter as the maximum value 1393 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, FLT_MAX, 10.0f); 1394 // 5. OH_Drawing_MatrixPreScale with the fifth parameter as the maximum value 1395 OH_Drawing_MatrixPreScale(matrix, 10.0f, 10.0f, 10.0f, FLT_MAX); 1396 // 6. Free memory 1397 OH_Drawing_MatrixDestroy(matrix); 1398 } 1399 1400 /* 1401 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1104 1402 * @tc.name: testMatrixPreScaleMultipleCalls 1403 * @tc.desc: test for testMatrixPreScaleMultipleCalls. 1404 * @tc.size : SmallTest 1405 * @tc.type : Function 1406 * @tc.level : Level 3 1407 */ 1408 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreScaleMultipleCalls, TestSize.Level3) { 1409 // 1. OH_Drawing_MatrixCreate 1410 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1411 // add assert 1412 EXPECT_NE(matrix, nullptr); 1413 // 2. Call OH_Drawing_MatrixCreateScale 10 times, passing in random numbers for sx, sy, px, and py 1414 std::random_device rd; 1415 std::mt19937 gen(rd()); 1416 std::uniform_real_distribution<float> dis(0.0, 100.0); 1417 for (int i = 0; i < 10; i++) { 1418 float sx = dis(gen); 1419 float sy = dis(gen); 1420 float px = dis(gen); 1421 float py = dis(gen); 1422 OH_Drawing_MatrixPreScale(matrix, sx, sy, px, py); 1423 } 1424 // 3. Free memory 1425 OH_Drawing_MatrixDestroy(matrix); 1426 } 1427 1428 /* 1429 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1200 1430 * @tc.name: testMatrixPreTranslateNormal 1431 * @tc.desc: test for testMatrixPreTranslateNormal. 1432 * @tc.size : SmallTest 1433 * @tc.type : Function 1434 * @tc.level : Level 0 1435 */ 1436 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreTranslateNormal, TestSize.Level0) { 1437 // 1. OH_Drawing_MatrixCreate 1438 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1439 // add assert 1440 EXPECT_NE(matrix, nullptr); 1441 // 2. OH_Drawing_MatrixPreTranslate, pass in decimals 1442 OH_Drawing_MatrixPreTranslate(matrix, 10.0f, 10.0f); 1443 // add assert 1444 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1445 // 3. OH_Drawing_MatrixPreTranslate, pass in integers 1446 OH_Drawing_MatrixPreTranslate(matrix, 20, 20); 1447 // add assert 1448 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1449 // 4. Free memory 1450 OH_Drawing_MatrixDestroy(matrix); 1451 } 1452 1453 /* 1454 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1201 1455 * @tc.name: testMatrixPreTranslateNull 1456 * @tc.desc: test for testMatrixPreTranslateNull. 1457 * @tc.size : SmallTest 1458 * @tc.type : Function 1459 * @tc.level : Level 3 1460 */ 1461 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreTranslateNull, TestSize.Level3) { 1462 // 1. OH_Drawing_MatrixCreate 1463 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1464 // add assert 1465 EXPECT_NE(matrix, nullptr); 1466 // 2. OH_Drawing_MatrixPreTranslate, the first parameter is null, check the error code using OH_Drawing_ErrorCodeGet 1467 OH_Drawing_MatrixPreTranslate(nullptr, 10.0f, 10.0f); 1468 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1469 // 3. OH_Drawing_MatrixPreTranslate, the second parameter is null 1470 OH_Drawing_MatrixPreTranslate(matrix, 0, 10.0f); 1471 // 4. OH_Drawing_MatrixPreTranslate, the third parameter is null 1472 OH_Drawing_MatrixPreTranslate(matrix, 10.0f, 0); 1473 // 5. Free memory 1474 OH_Drawing_MatrixDestroy(matrix); 1475 } 1476 1477 /* 1478 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1202 1479 * @tc.name: testMatrixPreTranslateAbnormal 1480 * @tc.desc: test for testMatrixPreTranslateAbnormal. 1481 * @tc.size : SmallTest 1482 * @tc.type : Function 1483 * @tc.level : Level 3 1484 */ 1485 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreTranslateAbnormal, TestSize.Level3) { 1486 // 1. OH_Drawing_MatrixCreate 1487 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1488 // add assert 1489 EXPECT_NE(matrix, nullptr); 1490 // 2. OH_Drawing_MatrixPreTranslate, the second parameter is negative 1491 OH_Drawing_MatrixPreTranslate(matrix, -10.0f, 10.0f); 1492 // 3. OH_Drawing_MatrixPreTranslate, the third parameter is negative 1493 OH_Drawing_MatrixPreTranslate(matrix, 10.0f, -10.0f); 1494 // 4. Free memory 1495 OH_Drawing_MatrixDestroy(matrix); 1496 } 1497 1498 /* 1499 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1203 1500 * @tc.name: testMatrixPreTranslateMaximum 1501 * @tc.desc: test for testMatrixPreTranslateMaximum. 1502 * @tc.size : SmallTest 1503 * @tc.type : Function 1504 * @tc.level : Level 3 1505 */ 1506 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreTranslateMaximum, TestSize.Level3) { 1507 // 1. OH_Drawing_MatrixCreate 1508 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1509 // add assert 1510 EXPECT_NE(matrix, nullptr); 1511 // 2. OH_Drawing_MatrixPreTranslate with the second parameter as the maximum value 1512 OH_Drawing_MatrixPreTranslate(matrix, FLT_MAX, 10.0f); 1513 // 3. OH_Drawing_MatrixPreTranslate with the third parameter as the maximum value 1514 OH_Drawing_MatrixPreTranslate(matrix, 10.0f, FLT_MAX); 1515 // 4. Free memory 1516 OH_Drawing_MatrixDestroy(matrix); 1517 } 1518 1519 /* 1520 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1204 1521 * @tc.name: testMatrixPreTranslateMultipleCalls 1522 * @tc.desc: test for testMatrixPreTranslateMultipleCalls. 1523 * @tc.size : SmallTest 1524 * @tc.type : Function 1525 * @tc.level : Level 3 1526 */ 1527 HWTEST_F(DrawingNativeMatrixTest, testMatrixPreTranslateMultipleCalls, TestSize.Level3) { 1528 // 1. OH_Drawing_MatrixCreate 1529 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1530 // add assert 1531 EXPECT_NE(matrix, nullptr); 1532 // 2. OH_Drawing_MatrixPreTranslate, pass in random numbers for dx and dy 1533 std::random_device rd; 1534 std::mt19937 gen(rd()); 1535 std::uniform_real_distribution<float> dis(0.0, 100.0); 1536 for (int i = 0; i < 10; i++) { 1537 float dx = dis(gen); 1538 float dy = dis(gen); 1539 OH_Drawing_MatrixPreTranslate(matrix, dx, dy); 1540 } 1541 // 3. Free memory 1542 OH_Drawing_MatrixDestroy(matrix); 1543 } 1544 1545 /* 1546 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1300 1547 * @tc.name: testMatrixPostRotateNormal 1548 * @tc.desc: test for testMatrixPostRotateNormal. 1549 * @tc.size : SmallTest 1550 * @tc.type : Function 1551 * @tc.level : Level 0 1552 */ 1553 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostRotateNormal, TestSize.Level0) { 1554 // 1. OH_Drawing_MatrixCreate 1555 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1556 // add assert 1557 EXPECT_NE(matrix, nullptr); 1558 // 2. OH_Drawing_MatrixPostRotate, rotate angles include 0 degrees, 180 degrees, 360 degrees, -90 degrees, -180 1559 // degrees, -360 degrees, and 45.5 degrees, px and py cover decimals and integers 1560 OH_Drawing_MatrixPostRotate(matrix, 0, 0, 0); 1561 // add assert 1562 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1563 OH_Drawing_MatrixPostRotate(matrix, 180, 10, 10); 1564 // add assert 1565 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1566 OH_Drawing_MatrixPostRotate(matrix, 360, 10.0f, 10.0f); 1567 // add assert 1568 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1569 OH_Drawing_MatrixPostRotate(matrix, -90, 20, 20); 1570 // add assert 1571 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1572 OH_Drawing_MatrixPostRotate(matrix, -180, 20.0f, 20.0f); 1573 // add assert 1574 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1575 OH_Drawing_MatrixPostRotate(matrix, -360, 30, 30); 1576 // add assert 1577 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1578 OH_Drawing_MatrixPostRotate(matrix, 45.5, 30.0f, 30.0f); 1579 // add assert 1580 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1581 // 3. Free memory 1582 OH_Drawing_MatrixDestroy(matrix); 1583 } 1584 1585 /* 1586 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1301 1587 * @tc.name: testMatrixPostRotateNull 1588 * @tc.desc: test for testMatrixPostRotateNull. 1589 * @tc.size : SmallTest 1590 * @tc.type : Function 1591 * @tc.level : Level 3 1592 */ 1593 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostRotateNull, TestSize.Level3) { 1594 // 1. OH_Drawing_MatrixCreate 1595 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1596 // add assert 1597 EXPECT_NE(matrix, nullptr); 1598 // 2. OH_Drawing_MatrixPostRotate with the first parameter as null, check the error code using 1599 // OH_Drawing_ErrorCodeGet 1600 OH_Drawing_MatrixPostRotate(nullptr, 180, 10, 10); 1601 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1602 // 3. OH_Drawing_MatrixPostRotate with the second parameter as null 1603 OH_Drawing_MatrixPostRotate(matrix, 0, 10, 10); 1604 // 4. OH_Drawing_MatrixPostRotate with the third parameter as null 1605 OH_Drawing_MatrixPostRotate(matrix, 180, 0, 10); 1606 // 5. OH_Drawing_MatrixPostRotate with the fourth parameter as null 1607 OH_Drawing_MatrixPostRotate(matrix, 180, 10, 0); 1608 // 6. Free memory 1609 OH_Drawing_MatrixDestroy(matrix); 1610 } 1611 1612 /* 1613 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1302 1614 * @tc.name: testMatrixPostRotateAbnormal 1615 * @tc.desc: test for testMatrixPostRotateAbnormal. 1616 * @tc.size : SmallTest 1617 * @tc.type : Function 1618 * @tc.level : Level 3 1619 */ 1620 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostRotateAbnormal, TestSize.Level3) { 1621 // 1. OH_Drawing_MatrixCreate 1622 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1623 // add assert 1624 EXPECT_NE(matrix, nullptr); 1625 // 2. OH_Drawing_MatrixPostRotate, the third parameter is negative 1626 OH_Drawing_MatrixPostRotate(matrix, 180, -10, 10); 1627 // 3. OH_Drawing_MatrixPostRotate, the fourth parameter is negative 1628 OH_Drawing_MatrixPostRotate(matrix, 180, 10, -10); 1629 // 4. Free memory 1630 OH_Drawing_MatrixDestroy(matrix); 1631 } 1632 1633 /* 1634 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1303 1635 * @tc.name: testMatrixPostRotateMaximum 1636 * @tc.desc: test for testMatrixPostRotateMaximum. 1637 * @tc.size : SmallTest 1638 * @tc.type : Function 1639 * @tc.level : Level 3 1640 */ 1641 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostRotateMaximum, TestSize.Level3) { 1642 // 1. OH_Drawing_MatrixCreate 1643 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1644 // add assert 1645 EXPECT_NE(matrix, nullptr); 1646 // 2. OH_Drawing_MatrixPostRotate with the second parameter as the maximum value 1647 OH_Drawing_MatrixPostRotate(matrix, FLT_MAX, 10.0f, 10.0f); 1648 // 3. OH_Drawing_MatrixPostRotate with the third parameter as the maximum value 1649 OH_Drawing_MatrixPostRotate(matrix, 180, FLT_MAX, 10.0f); 1650 // 4. OH_Drawing_MatrixPostRotate with the fourth parameter as the maximum value 1651 OH_Drawing_MatrixPostRotate(matrix, 180, 10.0f, FLT_MAX); 1652 // 5. Free memory 1653 OH_Drawing_MatrixDestroy(matrix); 1654 } 1655 1656 /* 1657 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1304 1658 * @tc.name: testMatrixPostRotateMultipleCalls 1659 * @tc.desc: test for testMatrixPostRotateMultipleCalls. 1660 * @tc.size : SmallTest 1661 * @tc.type : Function 1662 * @tc.level : Level 3 1663 */ 1664 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostRotateMultipleCalls, TestSize.Level3) { 1665 // 1. OH_Drawing_MatrixCreate 1666 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1667 // add assert 1668 EXPECT_NE(matrix, nullptr); 1669 // 2. OH_Drawing_MatrixPostRotate, pass in random numbers for degree, px, and py 1670 std::random_device rd; 1671 std::mt19937 gen(rd()); 1672 std::uniform_real_distribution<float> dis(0.0, 100.0); 1673 for (int i = 0; i < 10; i++) { 1674 float degree = dis(gen); 1675 float px = dis(gen); 1676 float py = dis(gen); 1677 OH_Drawing_MatrixPostRotate(matrix, degree, px, py); 1678 } 1679 // 3. Free memory 1680 OH_Drawing_MatrixDestroy(matrix); 1681 } 1682 1683 /* 1684 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1400 1685 * @tc.name: testMatrixPostScaleNormal 1686 * @tc.desc: test for testMatrixPostScaleNormal. 1687 * @tc.size : SmallTest 1688 * @tc.type : Function 1689 * @tc.level : Level 0 1690 */ 1691 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostScaleNormal, TestSize.Level0) { 1692 // 1. OH_Drawing_MatrixCreate 1693 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1694 // add assert 1695 EXPECT_NE(matrix, nullptr); 1696 // 2. OH_Drawing_MatrixPostScale, pass in decimals 1697 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, 10.0f, 10.0f); 1698 // add assert 1699 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1700 // 3. OH_Drawing_MatrixPostScale, pass in integers 1701 OH_Drawing_MatrixPostScale(matrix, 20, 20, 20, 20); 1702 // add assert 1703 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS); 1704 // 4. Free memory 1705 OH_Drawing_MatrixDestroy(matrix); 1706 } 1707 1708 /* 1709 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1401 1710 * @tc.name: testMatrixPostScaleNull 1711 * @tc.desc: test for testMatrixPostScaleNull. 1712 * @tc.size : SmallTest 1713 * @tc.type : Function 1714 * @tc.level : Level 3 1715 */ 1716 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostScaleNull, TestSize.Level3) { 1717 // 1. OH_Drawing_MatrixCreate 1718 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1719 // add assert 1720 EXPECT_NE(matrix, nullptr); 1721 // 2. OH_Drawing_MatrixPostScale, the first parameter is null, check the error code using OH_Drawing_ErrorCodeGet 1722 OH_Drawing_MatrixPostScale(nullptr, 10.0f, 10.0f, 10.0f, 10.0f); 1723 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1724 // 3. OH_Drawing_MatrixPostScale, the second parameter is null 1725 OH_Drawing_MatrixPostScale(matrix, 0, 10.0f, 10.0f, 10.0f); 1726 // 4. OH_Drawing_MatrixPostScale, the third parameter is null 1727 OH_Drawing_MatrixPostScale(matrix, 10.0f, 0, 10.0f, 10.0f); 1728 // 5. OH_Drawing_MatrixPostScale, the fourth parameter is null 1729 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, 0, 10.0f); 1730 // 6. OH_Drawing_MatrixPostScale, the fifth parameter is null 1731 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, 10.0f, 0); 1732 // 7. Free memory 1733 OH_Drawing_MatrixDestroy(matrix); 1734 } 1735 1736 /* 1737 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1402 1738 * @tc.name: testMatrixPostScaleAbnormal 1739 * @tc.desc: test for testMatrixPostScaleAbnormal. 1740 * @tc.size : SmallTest 1741 * @tc.type : Function 1742 * @tc.level : Level 3 1743 */ 1744 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostScaleAbnormal, TestSize.Level3) { 1745 // 1. OH_Drawing_MatrixCreate 1746 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1747 // add assert 1748 EXPECT_NE(matrix, nullptr); 1749 // 2. OH_Drawing_MatrixPostScale, the second parameter is negative 1750 OH_Drawing_MatrixPostScale(matrix, -10.0f, 10.0f, 10.0f, 10.0f); 1751 // 3. OH_Drawing_MatrixPostScale, the third parameter is negative 1752 OH_Drawing_MatrixPostScale(matrix, 10.0f, -10.0f, 10.0f, 10.0f); 1753 // 4. OH_Drawing_MatrixPostScale, the fourth parameter is negative 1754 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, -10.0f, 10.0f); 1755 // 5. OH_Drawing_MatrixPostScale, the fifth parameter is negative 1756 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, 10.0f, -10.0f); 1757 // 6. Free memory 1758 OH_Drawing_MatrixDestroy(matrix); 1759 } 1760 1761 /* 1762 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1403 1763 * @tc.name: testMatrixPostScaleMaximum 1764 * @tc.desc: test for testMatrixPostScaleMaximum. 1765 * @tc.size : SmallTest 1766 * @tc.type : Function 1767 * @tc.level : Level 3 1768 */ 1769 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostScaleMaximum, TestSize.Level3) { 1770 // 1. OH_Drawing_MatrixCreate 1771 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1772 // add assert 1773 EXPECT_NE(matrix, nullptr); 1774 // 2. OH_Drawing_MatrixPostScale, the second parameter is the maximum value 1775 OH_Drawing_MatrixPostScale(matrix, FLT_MAX, 10.0f, 10.0f, 10.0f); 1776 // 3. OH_Drawing_MatrixPostScale, the third parameter is the maximum value 1777 OH_Drawing_MatrixPostScale(matrix, 10.0f, FLT_MAX, 10.0f, 10.0f); 1778 // 4. OH_Drawing_MatrixPostScale, the fourth parameter is the maximum value 1779 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, FLT_MAX, 10.0f); 1780 // 5. OH_Drawing_MatrixPostScale, the fifth parameter is the maximum value 1781 OH_Drawing_MatrixPostScale(matrix, 10.0f, 10.0f, 10.0f, FLT_MAX); 1782 // 6. Free memory 1783 OH_Drawing_MatrixDestroy(matrix); 1784 } 1785 1786 /* 1787 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MATRIX_1404 1788 * @tc.name: testMatrixPostScaleMultipleCalls 1789 * @tc.desc: test for testMatrixPostScaleMultipleCalls. 1790 * @tc.size : SmallTest 1791 * @tc.type : Function 1792 * @tc.level : Level 3 1793 */ 1794 HWTEST_F(DrawingNativeMatrixTest, testMatrixPostScaleMultipleCalls, TestSize.Level3) { 1795 // 1. OH_Drawing_MatrixCreate 1796 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 1797 // add assert 1798 EXPECT_NE(matrix, nullptr); 1799 // 2. Call OH_Drawing_MatrixCreateScale 10 times, passing in random numbers for sx, sy, px, and py 1800 std::random_device rd; 1801 std::mt19937 gen(rd()); 1802 std::uniform_real_distribution<float> dis(0.0, 100.0); 1803 for (int i = 0; i < 10; i++) { 1804 float sx = dis(gen); 1805 float sy = dis(gen); 1806 float px = dis(gen); 1807 float py = dis(gen); 1808 OH_Drawing_MatrixPostScale(matrix, sx, sy, px, py); 1809 } 1810 // 3. Free memory 1811 OH_Drawing_MatrixDestroy(matrix); 1812 } 1813 1814 } // namespace Drawing 1815 } // namespace Rosen 1816 } // namespace OHOS