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 "DrawingNativePathCommon.h" 17 #include "drawing_color.h" 18 #include "drawing_color_filter.h" 19 #include "drawing_filter.h" 20 #include "drawing_image.h" 21 #include "drawing_matrix.h" 22 #include "drawing_path.h" 23 #include "drawing_path_effect.h" 24 #include "drawing_pen.h" 25 #include "drawing_point.h" 26 #include "drawing_rect.h" 27 #include "drawing_region.h" 28 #include "drawing_round_rect.h" 29 #include "utils/scalar.h" 30 #include "gtest/gtest.h" 31 32 using namespace testing; 33 using namespace testing::ext; 34 35 namespace OHOS { 36 namespace Rosen { 37 namespace Drawing { 38 class DrawingNativePathPart3Test : public testing::Test { 39 protected: 40 // 在每个测试用例执行前调用 SetUp()41 void SetUp() override 42 { 43 // 设置代码 44 std::cout << "DrawingNativePathPart3Test Setup code called before each test case." << std::endl; 45 OH_Drawing_ErrorCodeReset(); 46 std::cout << "DrawingNativePathPart3Test errorCodeReset before each test case." << std::endl; 47 } TearDown()48 void TearDown() override 49 { 50 std::cout << "DrawingNativePathPart3Test Setup code called after each test case." << std::endl; 51 OH_Drawing_ErrorCodeReset(); 52 std::cout << "DrawingNativePathPart3Test errorCodeReset after each test case." << std::endl; 53 } 54 }; 55 56 /* 57 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3700 58 * @tc.name: testPathIsClosedNormal 59 * @tc.desc: Test for checking if a path is closed using normal parameters. 60 * @tc.size : SmallTest 61 * @tc.type : Function 62 * @tc.level : Level 0 63 */ 64 HWTEST_F(DrawingNativePathPart3Test, testPathIsClosedNormal, TestSize.Level0) { 65 // 1. Create a path object using OH_Drawing_PathCreate 66 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 67 // add assert 68 EXPECT_NE(path, nullptr); 69 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 70 OH_Drawing_PathMoveTo(path, 0, 0); 71 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 72 OH_Drawing_PathLineTo(path, 100, 100); 73 // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo 74 OH_Drawing_PathLineTo(path, 0, 100); 75 // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo 76 OH_Drawing_PathLineTo(path, 0, 0); 77 // 6. Close the path using OH_Drawing_PathClose 78 OH_Drawing_PathClose(path); 79 // 7. Check if the path is closed using OH_Drawing_PathIsClosed 80 bool isClosed = OH_Drawing_PathIsClosed(path, false); 81 EXPECT_EQ(isClosed, true); 82 // add assert 83 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 84 // 8. Free the memory 85 OH_Drawing_PathDestroy(path); 86 } 87 88 /* 89 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3701 90 * @tc.name: testPathIsClosedNormal2 91 * @tc.desc: Test for checking if a path is closed without closing it. 92 * @tc.size : SmallTest 93 * @tc.type : Function 94 * @tc.level : Level 0 95 */ 96 HWTEST_F(DrawingNativePathPart3Test, testPathIsClosedNormal2, TestSize.Level0) { 97 // 1. Create a path object using OH_Drawing_PathCreate 98 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 99 // add assert 100 EXPECT_NE(path, nullptr); 101 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 102 OH_Drawing_PathMoveTo(path, 0, 0); 103 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 104 OH_Drawing_PathLineTo(path, 100, 100); 105 // 4. Check if the path is closed using OH_Drawing_PathIsClosed 106 bool isClosed = OH_Drawing_PathIsClosed(path, false); 107 EXPECT_EQ(isClosed, false); 108 // add assert 109 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 110 // 5. Free the memory 111 OH_Drawing_PathDestroy(path); 112 } 113 114 /* 115 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3702 116 * @tc.name: testPathIsClosedNull 117 * @tc.desc: Test for checking if a path is closed with NULL or invalid parameters. 118 * @tc.size : SmallTest 119 * @tc.type : Function 120 * @tc.level : Level 3 121 */ 122 HWTEST_F(DrawingNativePathPart3Test, testPathIsClosedNull, TestSize.Level3) { 123 // 1. Create a path object using OH_Drawing_PathCreate 124 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 125 // add assert 126 EXPECT_NE(path, nullptr); 127 // 2. Check if the path is closed using OH_Drawing_PathIsClosed with nullptr as the parameter, should return 128 // OH_DRAWING_ERROR_INVALID_PARAMETER 129 OH_Drawing_PathIsClosed(nullptr, false); 130 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 131 // 3. Free the memory 132 OH_Drawing_PathDestroy(path); 133 } 134 135 /* 136 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3800 137 * @tc.name: testPathGetPositionTangentNormal 138 * @tc.desc: Test for getting position and tangent of a path using normal parameters with tangent flag set to true. 139 * @tc.size : SmallTest 140 * @tc.type : Function 141 * @tc.level : Level 0 142 */ 143 HWTEST_F(DrawingNativePathPart3Test, testPathGetPositionTangentNormal, TestSize.Level0) { 144 // 1. Create a path object using OH_Drawing_PathCreate 145 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 146 // add assert 147 EXPECT_NE(path, nullptr); 148 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 149 OH_Drawing_PathMoveTo(path, 0, 0); 150 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 151 OH_Drawing_PathLineTo(path, 100, 100); 152 // 4. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the 153 // second parameter to true. 154 OH_Drawing_Point2D position; 155 OH_Drawing_Point2D tangent; 156 bool isSuccess = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 157 // add assert 158 EXPECT_EQ(isSuccess, true); 159 // add assert 160 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 161 // 5. Free the memory 162 OH_Drawing_PathDestroy(path); 163 } 164 165 /* 166 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3801 167 * @tc.name: testPathGetPositionTangentNormal2 168 * @tc.desc: Test for getting position and tangent of a path using normal parameters with tangent flag set to false. 169 * @tc.size : SmallTest 170 * @tc.type : Function 171 * @tc.level : Level 0 172 */ 173 HWTEST_F(DrawingNativePathPart3Test, testPathGetPositionTangentNormal2, TestSize.Level0) { 174 // 1. Create a path object using OH_Drawing_PathCreate 175 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 176 // add assert 177 EXPECT_NE(path, nullptr); 178 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 179 OH_Drawing_PathMoveTo(path, 0, 0); 180 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 181 OH_Drawing_PathLineTo(path, 100, 100); 182 // 4. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the 183 // second parameter to false. 184 OH_Drawing_Point2D position; 185 OH_Drawing_Point2D tangent; 186 bool isSuccess = OH_Drawing_PathGetPositionTangent(path, false, 50, &position, &tangent); 187 // add assert 188 EXPECT_EQ(isSuccess, true); 189 // add assert 190 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 191 // 5. Free the memory 192 OH_Drawing_PathDestroy(path); 193 } 194 195 /* 196 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3802 197 * @tc.name: testPathGetPositionTangentNull 198 * @tc.desc: Test for getting position and tangent of a path using NULL or invalid parameters. 199 * @tc.size : SmallTest 200 * @tc.type : Function 201 * @tc.level : Level 3 202 */ 203 HWTEST_F(DrawingNativePathPart3Test, testPathGetPositionTangentNull, TestSize.Level3) { 204 // 1. Create a path object using OH_Drawing_PathCreate 205 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 206 // add assert 207 EXPECT_NE(path, nullptr); 208 // 2. Call OH_Drawing_PathGetPositionTangent with the first parameter as nullptr, expect 209 // OH_DRAWING_ERROR_INVALID_PARAMETER 210 OH_Drawing_PathGetPositionTangent(nullptr, true, 50, nullptr, nullptr); 211 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 212 OH_Drawing_ErrorCodeReset(); 213 // 3. Call OH_Drawing_PathGetPositionTangent with the third parameter as 0.00, no crash 214 OH_Drawing_Point2D position; 215 OH_Drawing_Point2D tangent; 216 bool isSuccess = OH_Drawing_PathGetPositionTangent(path, true, 0.00, &position, &tangent); 217 // add assert 218 EXPECT_EQ(isSuccess, false); 219 // 4. Call OH_Drawing_PathGetPositionTangent with the fourth parameter as nullptr, expect 220 // OH_DRAWING_ERROR_INVALID_PARAMETER 221 OH_Drawing_PathGetPositionTangent(path, true, 50, nullptr, &tangent); 222 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 223 OH_Drawing_ErrorCodeReset(); 224 // 5. Call OH_Drawing_PathGetPositionTangent with the fifth parameter as nullptr, expect 225 // OH_DRAWING_ERROR_INVALID_PARAMETER 226 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, nullptr); 227 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 228 // 6. Free the memory 229 OH_Drawing_PathDestroy(path); 230 } 231 232 /* 233 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3803 234 * @tc.name: testPathGetPositionTangentAbnormal 235 * @tc.desc: Test for getting position and tangent of a path with abnormal parameters (non-float values). 236 * @tc.size : SmallTest 237 * @tc.type : Function 238 * @tc.level : Level 3 239 */ 240 HWTEST_F(DrawingNativePathPart3Test, testPathGetPositionTangentAbnormal, TestSize.Level3) { 241 // 1. Create a path object using OH_Drawing_PathCreate 242 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 243 // add assert 244 EXPECT_NE(path, nullptr); 245 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 246 OH_Drawing_PathMoveTo(path, 0, 0); 247 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 248 OH_Drawing_PathLineTo(path, 100, 100); 249 // 4. Call OH_Drawing_PathGetPositionTangent with the third parameter as an integer or character type 250 OH_Drawing_Point2D position; 251 OH_Drawing_Point2D tangent; 252 bool isSuccess1 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 253 // add assert 254 EXPECT_EQ(isSuccess1, true); 255 // 5. Call OH_Drawing_PathGetPositionTangent with the x coordinate of the fourth parameter as an integer or 256 // character type 257 position = {10, 10.0f}; 258 bool isSuccess2 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 259 // add assert 260 EXPECT_EQ(isSuccess2, true); 261 // 6. Call OH_Drawing_PathGetPositionTangent with the y coordinate of the fourth parameter as an integer or 262 // character type 263 position = {10.0f, 10}; 264 bool isSuccess3 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 265 // add assert 266 EXPECT_EQ(isSuccess3, true); 267 // 7. Call OH_Drawing_PathGetPositionTangent with the x coordinate of the fifth parameter as an integer or character 268 // type 269 tangent = {10, 10.0f}; 270 bool isSuccess4 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 271 // add assert 272 EXPECT_EQ(isSuccess4, true); 273 // 8. Call OH_Drawing_PathGetPositionTangent with the y coordinate of the fifth parameter as an integer or character 274 // type 275 tangent = {10.0f, 10}; 276 bool isSuccess5 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 277 // add assert 278 EXPECT_EQ(isSuccess5, true); 279 // 9. Free the memory 280 OH_Drawing_PathDestroy(path); 281 } 282 283 /* 284 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3804 285 * @tc.name: testPathGetPositionTangentMaximal 286 * @tc.desc: Test for getting position and tangent of a path with maximal values. 287 * @tc.size : SmallTest 288 * @tc.type : Function 289 * @tc.level : Level 3 290 */ 291 HWTEST_F(DrawingNativePathPart3Test, testPathGetPositionTangentMaximal, TestSize.Level3) { 292 // 1. Create a path object using OH_Drawing_PathCreate 293 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 294 // add assert 295 EXPECT_NE(path, nullptr); 296 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 297 OH_Drawing_PathMoveTo(path, 0, 0); 298 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 299 OH_Drawing_PathLineTo(path, 100, 100); 300 // 4. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the 301 // third parameter to a large value FLT_MAX + 1. 302 OH_Drawing_Point2D position; 303 OH_Drawing_Point2D tangent; 304 bool isSuccess1 = OH_Drawing_PathGetPositionTangent(path, true, FLT_MAX + 1, &position, &tangent); 305 // add assert 306 EXPECT_EQ(isSuccess1, true); 307 // 5. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the x 308 // coordinate of the fourth parameter to a large value FLT_MAX + 1. 309 position = {FLT_MAX + 1, 0.0f}; 310 bool isSuccess2 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 311 // add assert 312 EXPECT_EQ(isSuccess2, true); 313 // 6. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the y 314 // coordinate of the fourth parameter to a large value FLT_MAX + 1. 315 position = {0.0f, FLT_MAX + 1}; 316 bool isSuccess3 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 317 // add assert 318 EXPECT_EQ(isSuccess3, true); 319 // 7. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the x 320 // coordinate of the fifth parameter to a large value FLT_MAX + 1. 321 tangent = {FLT_MAX + 1, 0.0f}; 322 bool isSuccess4 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 323 // add assert 324 EXPECT_EQ(isSuccess4, true); 325 // 8. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the y 326 // coordinate of the fifth parameter to a large value FLT_MAX + 1. 327 tangent = {0.0f, FLT_MAX + 1}; 328 bool isSuccess5 = OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent); 329 // add assert 330 EXPECT_EQ(isSuccess5, true); 331 // 9. Free the memory 332 OH_Drawing_PathDestroy(path); 333 } 334 335 /* 336 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3900 337 * @tc.name: testPathOpNormal 338 * @tc.desc: Test for performing path operations using normal parameters. 339 * @tc.size : SmallTest 340 * @tc.type : Function 341 * @tc.level : Level 0 342 */ 343 HWTEST_F(DrawingNativePathPart3Test, testPathOpNormal, TestSize.Level0) { 344 // 1. Create a path object using OH_Drawing_PathCreate 345 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 346 // add assert 347 EXPECT_NE(path, nullptr); 348 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 349 OH_Drawing_PathMoveTo(path, 0, 0); 350 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 351 OH_Drawing_PathLineTo(path, 100, 100); 352 // 4. Create a path object using OH_Drawing_PathCreate 353 OH_Drawing_Path *src = OH_Drawing_PathCreate(); 354 // add assert 355 EXPECT_NE(src, nullptr); 356 // 5. Set the starting point of the path using OH_Drawing_PathMoveTo 357 OH_Drawing_PathMoveTo(src, 0, 0); 358 // 6. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 359 OH_Drawing_PathLineTo(src, 100, 100); 360 // 7. Perform a path operation on the two paths according to the specified path operation mode. The third parameter 361 // enumerates the possible path operation modes. 362 bool pathOp1 = OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_INTERSECT); 363 // add assert 364 EXPECT_EQ(pathOp1, true); 365 // add assert 366 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 367 bool pathOp2 = OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_DIFFERENCE); 368 // add assert 369 EXPECT_EQ(pathOp2, true); 370 // add assert 371 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 372 bool pathOp3 = OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_UNION); 373 // add assert 374 EXPECT_EQ(pathOp3, true); 375 // add assert 376 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 377 bool pathOp4 = OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_XOR); 378 // add assert 379 EXPECT_EQ(pathOp4, true); 380 // add assert 381 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 382 bool pathOp5 = OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_REVERSE_DIFFERENCE); 383 // add assert 384 EXPECT_EQ(pathOp5, true); 385 // add assert 386 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 387 // 8. Free the memory 388 OH_Drawing_PathDestroy(path); 389 OH_Drawing_PathDestroy(src); 390 } 391 392 /* 393 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3901 394 * @tc.name: testPathOpNull 395 * @tc.desc: Test for performing path operations with NULL or invalid parameters. 396 * @tc.size : SmallTest 397 * @tc.type : Function 398 * @tc.level : Level 3 399 */ 400 HWTEST_F(DrawingNativePathPart3Test, testPathOpNull, TestSize.Level3) { 401 // 1. Create a path object using OH_Drawing_PathCreate 402 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 403 // add assert 404 EXPECT_NE(path, nullptr); 405 // 2. Create a path object using OH_Drawing_PathCreate 406 OH_Drawing_Path *src = OH_Drawing_PathCreate(); 407 // add assert 408 EXPECT_NE(src, nullptr); 409 // 3. Call OH_Drawing_PathOp with the first parameter as nullptr, expect OH_DRAWING_ERROR_INVALID_PARAMETER 410 OH_Drawing_PathOp(nullptr, src, OH_Drawing_PathOpMode::PATH_OP_MODE_INTERSECT); 411 // add assert 412 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 413 OH_Drawing_ErrorCodeReset(); 414 // 4. Call OH_Drawing_PathOp with the second parameter as nullptr, expect OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE 415 OH_Drawing_PathOp(path, nullptr, OH_Drawing_PathOpMode::PATH_OP_MODE_INTERSECT); 416 // add assert 417 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 418 // 5. Free the memory 419 OH_Drawing_PathDestroy(path); 420 OH_Drawing_PathDestroy(src); 421 } 422 423 /* 424 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4000 425 * @tc.name: testPathGetMatrixNormal 426 * @tc.desc: Test for getting transformation matrix of a path using normal parameters with matrix flag set to true. 427 * @tc.size : SmallTest 428 * @tc.type : Function 429 * @tc.level : Level 0 430 */ 431 HWTEST_F(DrawingNativePathPart3Test, testPathGetMatrixNormal, TestSize.Level0) { 432 // 1. Create a path object using OH_Drawing_PathCreate 433 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 434 // add assert 435 EXPECT_NE(path, nullptr); 436 // 2. Create a matrix object using OH_Drawing_MatrixCreate 437 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 438 // add assert 439 EXPECT_NE(matrix, nullptr); 440 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1); 441 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo 442 OH_Drawing_PathMoveTo(path, 0, 0); 443 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 444 OH_Drawing_PathLineTo(path, 100, 100); 445 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the 446 // second parameter to true. Enumerate the possible values of the fifth parameter to call the interface. 447 OH_Drawing_PathMeasureMatrixFlags flags[] = { 448 GET_POSITION_MATRIX, 449 GET_TANGENT_MATRIX, 450 GET_POSITION_AND_TANGENT_MATRIX, 451 }; 452 for (int i = 0; i < 3; i++) { 453 OH_Drawing_ErrorCodeReset(); 454 bool getMatrix = OH_Drawing_PathGetMatrix(path, true, 50, matrix, flags[i]); 455 // add assert 456 EXPECT_EQ(getMatrix, true); 457 // add assert 458 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 459 } 460 // 6. Free the memory 461 OH_Drawing_PathDestroy(path); 462 OH_Drawing_MatrixDestroy(matrix); 463 } 464 465 /* 466 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4001 467 * @tc.name: testPathGetMatrixNormal2 468 * @tc.desc: Test for getting transformation matrix of a path using normal parameters with matrix flag set to false. 469 * @tc.size : SmallTest 470 * @tc.type : Function 471 * @tc.level : Level 0 472 */ 473 HWTEST_F(DrawingNativePathPart3Test, testPathGetMatrixNormal2, TestSize.Level0) { 474 // 1. Create a path object using OH_Drawing_PathCreate 475 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 476 // add assert 477 EXPECT_NE(path, nullptr); 478 // 2. Create a matrix object using OH_Drawing_MatrixCreate 479 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 480 // add assert 481 EXPECT_NE(matrix, nullptr); 482 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1); 483 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo 484 OH_Drawing_PathMoveTo(path, 0, 0); 485 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 486 OH_Drawing_PathLineTo(path, 100, 100); 487 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the 488 // second parameter to false. Enumerate the possible values of the fifth parameter to call the interface. 489 OH_Drawing_PathMeasureMatrixFlags flags[] = { 490 GET_POSITION_MATRIX, 491 GET_TANGENT_MATRIX, 492 GET_POSITION_AND_TANGENT_MATRIX, 493 }; 494 for (int i = 0; i < 3; i++) { 495 OH_Drawing_ErrorCodeReset(); 496 bool getMatrix = OH_Drawing_PathGetMatrix(path, false, 50, matrix, flags[i]); 497 // add assert 498 EXPECT_EQ(getMatrix, true); 499 // add assert 500 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 501 } 502 // 6. Free the memory 503 OH_Drawing_PathDestroy(path); 504 OH_Drawing_MatrixDestroy(matrix); 505 } 506 507 /* 508 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4002 509 * @tc.name: testPathGetMatrixNull 510 * @tc.desc: Test for getting transformation matrix of a path using NULL or invalid parameters. 511 * @tc.size : SmallTest 512 * @tc.type : Function 513 * @tc.level : Level 3 514 */ 515 HWTEST_F(DrawingNativePathPart3Test, testPathGetMatrixNull, TestSize.Level3) { 516 // 1. Create a path object using OH_Drawing_PathCreate 517 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 518 // add assert 519 EXPECT_NE(path, nullptr); 520 // 2. Create a matrix object using OH_Drawing_MatrixCreate 521 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 522 // add assert 523 EXPECT_NE(matrix, nullptr); 524 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1); 525 // 3. Call OH_Drawing_PathGetMatrix with the first parameter as nullptr, expect OH_DRAWING_ERROR_INVALID_PARAMETER 526 OH_Drawing_PathGetMatrix(nullptr, true, 50, matrix, GET_POSITION_MATRIX); 527 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 528 OH_Drawing_ErrorCodeReset(); 529 // 4. Call OH_Drawing_PathGetMatrix with the third parameter as 0.00, the call should fail without crashing 530 bool getMatrix = OH_Drawing_PathGetMatrix(path, true, 0.00, matrix, GET_POSITION_MATRIX); 531 // add assert 532 EXPECT_EQ(getMatrix, false); 533 // 5. Call OH_Drawing_PathGetMatrix with the fourth parameter as nullptr, expect OH_DRAWING_ERROR_INVALID_PARAMETER 534 OH_Drawing_PathGetMatrix(path, true, 50, nullptr, GET_POSITION_MATRIX); 535 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 536 // 6. Free the memory 537 OH_Drawing_PathDestroy(path); 538 OH_Drawing_MatrixDestroy(matrix); 539 } 540 541 /* 542 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4003 543 * @tc.name: testPathGetMatrixAbnormal 544 * @tc.desc: Test for getting transformation matrix of a path with abnormal parameters (non-float values). 545 * @tc.size : SmallTest 546 * @tc.type : Function 547 * @tc.level : Level 3 548 */ 549 HWTEST_F(DrawingNativePathPart3Test, testPathGetMatrixAbnormal, TestSize.Level3) { 550 // 1. Create a path object using OH_Drawing_PathCreate 551 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 552 // add assert 553 EXPECT_NE(path, nullptr); 554 // 2. Create a matrix object using OH_Drawing_MatrixCreate 555 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 556 // add assert 557 EXPECT_NE(matrix, nullptr); 558 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1); 559 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo 560 OH_Drawing_PathMoveTo(path, 0, 0); 561 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 562 OH_Drawing_PathLineTo(path, 100, 100); 563 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the 564 // third parameter to an integer value. 565 bool getMatrix = OH_Drawing_PathGetMatrix(path, true, 50, matrix, GET_POSITION_MATRIX); 566 // add assert 567 EXPECT_EQ(getMatrix, true); 568 // 6. Free the memory 569 OH_Drawing_PathDestroy(path); 570 OH_Drawing_MatrixDestroy(matrix); 571 } 572 573 /* 574 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4004 575 * @tc.name: testPathGetMatrixMaximal 576 * @tc.desc: Test for getting transformation matrix of a path with maximal values. 577 * @tc.size : SmallTest 578 * @tc.type : Function 579 * @tc.level : Level 3 580 */ 581 HWTEST_F(DrawingNativePathPart3Test, testPathGetMatrixMaximal, TestSize.Level3) { 582 // 1. Create a path object using OH_Drawing_PathCreate 583 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 584 // add assert 585 EXPECT_NE(path, nullptr); 586 // 2. Create a matrix object using OH_Drawing_MatrixCreate 587 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); 588 // add assert 589 EXPECT_NE(matrix, nullptr); 590 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1); 591 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo 592 OH_Drawing_PathMoveTo(path, 0, 0); 593 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo 594 OH_Drawing_PathLineTo(path, 100, 100); 595 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the 596 // third parameter to a large value FLT_MAX + 1. 597 bool getMatrix = OH_Drawing_PathGetMatrix(path, true, FLT_MAX + 1, matrix, GET_POSITION_MATRIX); 598 // add assert 599 EXPECT_EQ(getMatrix, true); 600 // 6. Free the memory 601 OH_Drawing_PathDestroy(path); 602 OH_Drawing_MatrixDestroy(matrix); 603 } 604 605 /* 606 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4100 607 * @tc.name: testPathGetSegmentNormal 608 * @tc.desc: Testing the enumeration traversal of the interface for extracting path segments and appending them to the 609 * target path 610 * @tc.size : SmallTest 611 * @tc.type : Function 612 * @tc.level : Level 0 613 */ 614 HWTEST_F(DrawingNativePathPart3Test, testPathGetSegmentNormal, TestSize.Level0) { 615 // 1. Create a path object using OH_Drawing_PathCreate 616 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 617 EXPECT_NE(path, nullptr); 618 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 619 OH_Drawing_PathMoveTo(path, 100, 100); 620 // 3. Add two lines segment from the starting point to the target point using OH_Drawing_PathLineTo 621 OH_Drawing_PathLineTo(path, 100, 200); 622 OH_Drawing_PathLineTo(path, 200, 200); 623 // 4. Create a target path object using OH_Drawing_PathCreate 624 OH_Drawing_Path *dstPath = OH_Drawing_PathCreate(); 625 EXPECT_NE(dstPath, nullptr); 626 bool result = false; 627 OH_Drawing_ErrorCode errorCode; 628 // 5. Parameter enumeration traversal 629 errorCode = OH_Drawing_PathGetSegment(path, true, 120, 180, true, dstPath, &result); 630 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 631 EXPECT_EQ(result, true); 632 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 180, true, dstPath, &result); 633 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 634 EXPECT_EQ(result, true); 635 errorCode = OH_Drawing_PathGetSegment(path, true, 120, 180, false, dstPath, &result); 636 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 637 EXPECT_EQ(result, true); 638 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 180, false, dstPath, &result); 639 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 640 EXPECT_EQ(result, true); 641 // 6. Free the memory 642 OH_Drawing_PathDestroy(path); 643 OH_Drawing_PathDestroy(dstPath); 644 } 645 646 /* 647 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4101 648 * @tc.name: testPathGetSegmentNull 649 * @tc.desc: Tests when an interface that intercepts a path fragment and appends it to the target path passes a null 650 * pointer or invalid parameter 651 * @tc.size : SmallTest 652 * @tc.type : Function 653 * @tc.level : Level 3 654 */ 655 HWTEST_F(DrawingNativePathPart3Test, testPathGetSegmentNull, TestSize.Level3) { 656 // 1. Create a path object using OH_Drawing_PathCreate 657 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 658 EXPECT_NE(path, nullptr); 659 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 660 OH_Drawing_PathMoveTo(path, 100, 100); 661 // 3. Add two lines segment from the starting point to the target point using OH_Drawing_PathLineTo 662 OH_Drawing_PathLineTo(path, 100, 200); 663 OH_Drawing_PathLineTo(path, 200, 200); 664 // 4. Create a target path object using OH_Drawing_PathCreate 665 OH_Drawing_Path *dstPath = OH_Drawing_PathCreate(); 666 EXPECT_NE(dstPath, nullptr); 667 bool result = false; 668 OH_Drawing_ErrorCode errorCode; 669 // 5. The function OH_Drawing_PathGetSegment passes a null pointer to the first argument 670 errorCode = OH_Drawing_PathGetSegment(nullptr, false, 120, 180, true, dstPath, &result); 671 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 672 EXPECT_EQ(result, false); 673 // 6. The function OH_Drawing_PathGetSegment passes 0 to the third argument 674 errorCode = OH_Drawing_PathGetSegment(path, false, 0, 180, true, dstPath, &result); 675 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 676 EXPECT_EQ(result, true); 677 // 7. The function OH_Drawing_PathGetSegment passes 0 to the forth argument 678 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 0, true, dstPath, &result); 679 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 680 EXPECT_EQ(result, false); 681 // 8. The function OH_Drawing_PathGetSegment passes a null pointer to the fifth argument 682 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 180, true, nullptr, &result); 683 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 684 EXPECT_EQ(result, false); 685 // 9. The function OH_Drawing_PathGetSegment passes a null pointer to the sixth argument 686 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 180, true, dstPath, nullptr); 687 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 688 EXPECT_EQ(result, false); 689 // 10. Free the memory 690 OH_Drawing_PathDestroy(path); 691 OH_Drawing_PathDestroy(dstPath); 692 } 693 694 /* 695 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4102 696 * @tc.name: testPathGetSegmentAbnormal 697 * @tc.desc: Test cases where the function intercepts a path fragment and appends it to the destination path with an 698 * passed exception parameter 699 * @tc.size : SmallTest 700 * @tc.type : Function 701 * @tc.level : Level 3 702 */ 703 HWTEST_F(DrawingNativePathPart3Test, testPathGetSegmentAbnormal, TestSize.Level3) { 704 // 1. Create a path object using OH_Drawing_PathCreate 705 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 706 EXPECT_NE(path, nullptr); 707 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 708 OH_Drawing_PathMoveTo(path, 100, 100); 709 // 3. Add two lines segment from the starting point to the target point using OH_Drawing_PathLineTo 710 OH_Drawing_PathLineTo(path, 100, 200); 711 OH_Drawing_PathLineTo(path, 200, 200); 712 // 4. Create a target path object using OH_Drawing_PathCreate 713 OH_Drawing_Path *dstPath = OH_Drawing_PathCreate(); 714 EXPECT_NE(dstPath, nullptr); 715 bool result = false; 716 OH_Drawing_ErrorCode errorCode; 717 // 5. The third argument of the function OH_Drawing_PathGetSegment passes a negative number 718 errorCode = OH_Drawing_PathGetSegment(path, false, -50, 180, true, dstPath, &result); 719 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 720 EXPECT_EQ(result, true); 721 // 6. The fourth parameter of the function OH_Drawing_PathGetSegment passes a number greater than the path length 722 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 999, true, dstPath, &result); 723 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 724 EXPECT_EQ(result, true); 725 // 7. The function OH_Drawing_PathGetSegment passes in the third and fourth arguments equal in value 726 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 120, true, dstPath, &result); 727 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 728 EXPECT_EQ(result, false); 729 // 8. The third argument of the function OH_Drawing_PathGetSegment is greater than the value of the fourth argument 730 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 100, true, dstPath, &result); 731 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 732 EXPECT_EQ(result, false); 733 // 9. Free the memory 734 OH_Drawing_PathDestroy(path); 735 OH_Drawing_PathDestroy(dstPath); 736 } 737 738 /* 739 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4103 740 * @tc.name: testPathGetSegmentMultiplies 741 * @tc.desc: The test function intercepts the path fragment and appends it to the target path loop several times 742 * @tc.size : SmallTest 743 * @tc.type : Function 744 * @tc.level : Level 3 745 */ 746 HWTEST_F(DrawingNativePathPart3Test, testPathGetSegmentMultiplies, TestSize.Level3) { 747 // 1. Create a path object using OH_Drawing_PathCreate 748 OH_Drawing_Path *path = OH_Drawing_PathCreate(); 749 EXPECT_NE(path, nullptr); 750 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo 751 OH_Drawing_PathMoveTo(path, 100, 100); 752 // 3. Add two lines segment from the starting point to the target point using OH_Drawing_PathLineTo 753 OH_Drawing_PathLineTo(path, 100, 200); 754 OH_Drawing_PathLineTo(path, 200, 200); 755 // 4. Create a target path object using OH_Drawing_PathCreate 756 OH_Drawing_Path *dstPath = OH_Drawing_PathCreate(); 757 EXPECT_NE(dstPath, nullptr); 758 bool result = false; 759 OH_Drawing_ErrorCode errorCode; 760 // 5. The function OH_Drawing_PathGetSegment is called 10 times 761 for (int i = 0; i < 10; i++) { 762 errorCode = OH_Drawing_PathGetSegment(path, false, 120, 180, true, dstPath, &result); 763 } 764 EXPECT_EQ(errorCode, OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 765 EXPECT_EQ(result, true); 766 // 6. Free the memory 767 OH_Drawing_PathDestroy(path); 768 OH_Drawing_PathDestroy(dstPath); 769 } 770 } // namespace Drawing 771 } // namespace Rosen 772 } // namespace OHOS