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 "drawing_color.h" 17 #include "drawing_error_code.h" 18 #include "drawing_filter.h" 19 #include "drawing_mask_filter.h" 20 #include "drawing_rect.h" 21 #include "drawing_round_rect.h" 22 #include "gtest/gtest.h" 23 #include "DrawingNativeScalarCommon.h" 24 25 using namespace testing; 26 using namespace testing::ext; 27 28 namespace OHOS { 29 namespace Rosen { 30 namespace Drawing { 31 class DrawingNativeRectTest : public testing::Test { 32 protected: 33 // 在每个测试用例执行前调用 SetUp()34 void SetUp() override 35 { 36 // 设置代码 37 std::cout << "DrawingNativeRectTest Setup code called before each test case." << std::endl; 38 OH_Drawing_ErrorCodeReset(); 39 std::cout << "DrawingNativeRectTest errorCodeReset before each test case." << std::endl; 40 } TearDown()41 void TearDown() override 42 { 43 std::cout << "DrawingNativeRectTest Setup code called after each test case." << std::endl; 44 OH_Drawing_ErrorCodeReset(); 45 std::cout << "DrawingNativeRectTest errorCodeReset after each test case." << std::endl; 46 } 47 }; 48 49 /* 50 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0100 51 * @tc.name: testRectCreateNormal 52 * @tc.desc: Test for creating and destroying a rectangle object with normal parameters. 53 * @tc.size : SmallTest 54 * @tc.type : Function 55 * @tc.level : Level 0 56 */ 57 HWTEST_F(DrawingNativeRectTest, testRectCreateNormal, Function | SmallTest | Level0) { 58 // 1. Call OH_Drawing_RectCreate to create a rectangle object 59 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 600); 60 // add assert 61 EXPECT_NE(rect, nullptr); 62 // 2. Free memory 63 OH_Drawing_RectDestroy(rect); 64 } 65 66 /* 67 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0200 68 * @tc.name: testRectIntersectNormal 69 * @tc.desc: Test for intersecting two rectangles with normal parameters. 70 * @tc.size : SmallTest 71 * @tc.type : Function 72 * @tc.level : Level 0 73 */ 74 HWTEST_F(DrawingNativeRectTest, testRectIntersectNormal, Function | SmallTest | Level0) { 75 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 76 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 600); 77 // add assert 78 EXPECT_NE(rect, nullptr); 79 // 2. Call OH_Drawing_RectCreate to create another rectangle object other 80 OH_Drawing_Rect *other = OH_Drawing_RectCreate(300, 400, 700, 800); 81 // add assert 82 EXPECT_NE(other, nullptr); 83 // 3. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect 84 OH_Drawing_RectSetLeft(rect, 0); 85 // add assert 86 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 87 // 4. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 88 OH_Drawing_RectSetTop(rect, 0); 89 // add assert 90 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 91 // 5. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 92 OH_Drawing_RectSetRight(rect, 200); 93 // add assert 94 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 95 // 6. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect 96 OH_Drawing_RectSetBottom(rect, 200); 97 // add assert 98 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 99 // 7. Repeat steps 3-6 to set the coordinates of the other rectangle object 100 OH_Drawing_RectSetLeft(other, 100); 101 // add assert 102 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 103 OH_Drawing_RectSetTop(other, 100); 104 // add assert 105 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 106 OH_Drawing_RectSetRight(other, 300); 107 // add assert 108 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 109 OH_Drawing_RectSetBottom(other, 300); 110 // add assert 111 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 112 // 8. Call OH_Drawing_RectIntersect to check if the two rectangles intersect, Returns true if they intersect, 113 // false otherwise 114 bool ret = OH_Drawing_RectIntersect(rect, other); 115 EXPECT_EQ(ret, true); 116 // 9. Free memory 117 OH_Drawing_RectDestroy(rect); 118 OH_Drawing_RectDestroy(other); 119 } 120 121 /* 122 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0201 123 * @tc.name: testRectIntersectNull 124 * @tc.desc: Test for intersecting rectangles with NULL parameters. 125 * @tc.size : SmallTest 126 * @tc.type : Function 127 * @tc.level : Level 3 128 */ 129 HWTEST_F(DrawingNativeRectTest, testRectIntersectNull, Function | SmallTest | Level3) { 130 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 131 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 600); 132 // add assert 133 EXPECT_NE(rect, nullptr); 134 // 2. Call OH_Drawing_RectCreate to create another rectangle object other 135 OH_Drawing_Rect *other = OH_Drawing_RectCreate(300, 400, 700, 800); 136 // add assert 137 EXPECT_NE(other, nullptr); 138 // 3. Call OH_Drawing_RectIntersect with the first parameter as nullptr, Returns error code 139 // OH_DRAWING_ERROR_INVALID_PARAMETER 140 OH_Drawing_RectIntersect(nullptr, other); 141 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 142 OH_Drawing_ErrorCodeReset(); 143 // 4. Call OH_Drawing_RectIntersect with the second parameter as nullptr, Returns error code 144 // OH_DRAWING_ERROR_INVALID_PARAMETER 145 OH_Drawing_RectIntersect(rect, nullptr); 146 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 147 // 5. Free memory 148 OH_Drawing_RectDestroy(rect); 149 OH_Drawing_RectDestroy(other); 150 } 151 152 /* 153 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0300 154 * @tc.name: testRectJoinNormal 155 * @tc.desc: Test for joining two rectangles with normal parameters. 156 * @tc.size : SmallTest 157 * @tc.type : Function 158 * @tc.level : Level 0 159 */ 160 HWTEST_F(DrawingNativeRectTest, testRectJoinNormal, Function | SmallTest | Level0) { 161 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 162 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 163 // add assert 164 EXPECT_NE(rect, nullptr); 165 // 2. Call OH_Drawing_RectCreate to create another rectangle object other 166 OH_Drawing_Rect *other = OH_Drawing_RectCreate(100, 100, 300, 300); 167 // add assert 168 EXPECT_NE(other, nullptr); 169 // 3. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect 170 OH_Drawing_RectSetLeft(rect, 0); 171 // add assert 172 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 173 // 4. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 174 OH_Drawing_RectSetTop(rect, 0); 175 // add assert 176 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 177 // 5. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 178 OH_Drawing_RectSetRight(rect, 200); 179 // add assert 180 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 181 // 6. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect 182 OH_Drawing_RectSetBottom(rect, 200); 183 // add assert 184 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 185 // 7. Repeat steps 3-6 to set the coordinates of the other rectangle object 186 OH_Drawing_RectSetLeft(other, 100); 187 // add assert 188 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 189 OH_Drawing_RectSetTop(other, 100); 190 // add assert 191 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 192 OH_Drawing_RectSetRight(other, 300); 193 // add assert 194 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 195 OH_Drawing_RectSetBottom(other, 300); 196 // add assert 197 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 198 // 8. Call OH_Drawing_RectJoin to take the union of the two rectangles 199 bool ret = OH_Drawing_RectJoin(rect, other); 200 EXPECT_TRUE(ret); 201 // add assert 202 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 203 // 9. Free memory 204 OH_Drawing_RectDestroy(rect); 205 OH_Drawing_RectDestroy(other); 206 } 207 208 /* 209 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0301 210 * @tc.name: testRectJoinNull 211 * @tc.desc: Test for joining rectangles with NULL parameters. 212 * @tc.size : SmallTest 213 * @tc.type : Function 214 * @tc.level : Level 3 215 */ 216 HWTEST_F(DrawingNativeRectTest, testRectJoinNull, Function | SmallTest | Level3) { 217 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 218 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 219 // add assert 220 EXPECT_NE(rect, nullptr); 221 // 2. Call OH_Drawing_RectCreate to create another rectangle object other 222 OH_Drawing_Rect *other = OH_Drawing_RectCreate(100, 100, 300, 300); 223 // add assert 224 EXPECT_NE(other, nullptr); 225 // 3. Call OH_Drawing_RectJoin with the first parameter as nullptr, Returns error code 226 // OH_DRAWING_ERROR_INVALID_PARAMETER 227 OH_Drawing_RectJoin(nullptr, other); 228 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 229 OH_Drawing_ErrorCodeReset(); 230 // 4. Call OH_Drawing_RectJoin with the second parameter as nullptr, Returns error code 231 // OH_DRAWING_ERROR_INVALID_PARAMETER 232 OH_Drawing_RectJoin(rect, nullptr); 233 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 234 // 5. Free memory 235 OH_Drawing_RectDestroy(rect); 236 OH_Drawing_RectDestroy(other); 237 } 238 239 /* 240 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0400 241 * @tc.name: testRectSetLeftNormal 242 * @tc.desc: Test for setting and getting the left coordinate of a rectangle with normal parameters. 243 * @tc.size : SmallTest 244 * @tc.type : Function 245 * @tc.level : Level 0 246 */ 247 HWTEST_F(DrawingNativeRectTest, testRectSetLeftNormal, Function | SmallTest | Level0) { 248 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 249 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 250 // add assert 251 EXPECT_NE(rect, nullptr); 252 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect 253 OH_Drawing_RectSetLeft(rect, 100); 254 // add assert 255 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 256 // 3. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of rect, Returns the value set 257 // in step 2 258 float left = OH_Drawing_RectGetLeft(rect); 259 EXPECT_TRUE(IsScalarAlmostEqual(left, 100)); 260 // 4. Free memory 261 OH_Drawing_RectDestroy(rect); 262 } 263 264 /* 265 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0401 266 * @tc.name: testRectSetLeftNull 267 * @tc.desc: Test for setting the left coordinate of a rectangle with NULL parameters. 268 * @tc.size : SmallTest 269 * @tc.type : Function 270 * @tc.level : Level 3 271 */ 272 HWTEST_F(DrawingNativeRectTest, testRectSetLeftNull, Function | SmallTest | Level3) { 273 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 274 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 275 // add assert 276 EXPECT_NE(rect, nullptr); 277 // 2. Call OH_Drawing_RectSetLeft with the first parameter as nullptr, Returns error code 278 // OH_DRAWING_ERROR_INVALID_PARAMETER 279 OH_Drawing_RectSetLeft(nullptr, 0.00); 280 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 281 // 3. Call OH_Drawing_RectSetLeft with the second parameter as 0.00, Call fails without crashing 282 OH_Drawing_RectSetLeft(rect, 0.00); 283 // 4. Free memory 284 OH_Drawing_RectDestroy(rect); 285 } 286 287 /* 288 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0402 289 * @tc.name: testRectSetLeftAbnormal 290 * @tc.desc: Test for setting the left coordinate of a rectangle with abnormal parameters. 291 * @tc.size : SmallTest 292 * @tc.type : Function 293 * @tc.level : Level 3 294 */ 295 HWTEST_F(DrawingNativeRectTest, testRectSetLeftAbnormal, Function | SmallTest | Level3) { 296 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 297 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 298 // add assert 299 EXPECT_NE(rect, nullptr); 300 // 2. Call OH_Drawing_RectSetLeft with the second parameter as an integer or character data 301 OH_Drawing_RectSetLeft(rect, 100); 302 // add assert 303 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 304 // 3. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of rect, Returns the value set 305 // in step 2 (the passed parameter is forcibly converted) 306 float left = OH_Drawing_RectGetLeft(rect); 307 EXPECT_TRUE(IsScalarAlmostEqual(left, 100)); 308 // 4. Free memory 309 OH_Drawing_RectDestroy(rect); 310 } 311 312 /* 313 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0403 314 * @tc.name: testRectSetLeftMultipleCalls 315 * @tc.desc: Test for repeatedly setting and getting the left coordinate of a rectangle. 316 * @tc.size : SmallTest 317 * @tc.type : Function 318 * @tc.level : Level 3 319 */ 320 HWTEST_F(DrawingNativeRectTest, testRectSetLeftMultipleCalls, Function | SmallTest | Level3) { 321 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 322 // add assert 323 EXPECT_NE(rect, nullptr); 324 for (int i = 0; i < 10; i++) { 325 OH_Drawing_RectSetLeft(rect, i * 10); 326 float left = OH_Drawing_RectGetLeft(rect); 327 EXPECT_TRUE(IsScalarAlmostEqual(left, i * 10)); 328 } 329 OH_Drawing_RectDestroy(rect); 330 } 331 332 /* 333 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0500 334 * @tc.name: testRectSetTopNormal 335 * @tc.desc: Test for setting and getting the top coordinate of a rectangle with normal parameters. 336 * @tc.size : SmallTest 337 * @tc.type : Function 338 * @tc.level : Level 0 339 */ 340 HWTEST_F(DrawingNativeRectTest, testRectSetTopNormal, Function | SmallTest | Level0) { 341 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 342 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 343 // add assert 344 EXPECT_NE(rect, nullptr); 345 // 2. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 346 OH_Drawing_RectSetTop(rect, 100); 347 // add assert 348 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 349 // 3. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect, Returns the value set in 350 // step 2 351 float top = OH_Drawing_RectGetTop(rect); 352 EXPECT_TRUE(IsScalarAlmostEqual(top, 100)); 353 // 4. Free memory 354 OH_Drawing_RectDestroy(rect); 355 } 356 357 /* 358 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0501 359 * @tc.name: testRectSetTopNull 360 * @tc.desc: Test for setting the top coordinate of a rectangle with NULL parameters. 361 * @tc.size : SmallTest 362 * @tc.type : Function 363 * @tc.level : Level 3 364 */ 365 HWTEST_F(DrawingNativeRectTest, testRectSetTopNull, Function | SmallTest | Level3) { 366 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 367 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 368 // add assert 369 EXPECT_NE(rect, nullptr); 370 // 2. Call OH_Drawing_RectSetTop with the first parameter as nullptr, Returns error code 371 // OH_DRAWING_ERROR_INVALID_PARAMETER 372 OH_Drawing_RectSetTop(nullptr, 0.00); 373 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 374 // 3. Call OH_Drawing_RectSetTop with the second parameter as 0.00, Call fails without crashing 375 OH_Drawing_RectSetTop(rect, 0.00); 376 // 4. Free memory 377 OH_Drawing_RectDestroy(rect); 378 } 379 380 /* 381 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0502 382 * @tc.name: testRectSetTopAbnormal 383 * @tc.desc: Test for setting the top coordinate of a rectangle with abnormal parameters. 384 * @tc.size : SmallTest 385 * @tc.type : Function 386 * @tc.level : Level 3 387 */ 388 HWTEST_F(DrawingNativeRectTest, testRectSetTopAbnormal, Function | SmallTest | Level3) { 389 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 390 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 391 // add assert 392 EXPECT_NE(rect, nullptr); 393 // 2. Call OH_Drawing_RectSetTop with the second parameter as an integer or character data 394 OH_Drawing_RectSetTop(rect, 100); 395 // add assert 396 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 397 // 3. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect, Returns the value set in 398 // step 2 (the passed parameter is forcibly converted) 399 float top = OH_Drawing_RectGetTop(rect); 400 EXPECT_TRUE(IsScalarAlmostEqual(top, 100)); 401 // 4. Free memory 402 OH_Drawing_RectDestroy(rect); 403 } 404 405 /* 406 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0503 407 * @tc.name: testRectSetTopMultipleCalls 408 * @tc.desc: Test for repeatedly setting and getting the top coordinate of a rectangle. 409 * @tc.size : SmallTest 410 * @tc.type : Function 411 * @tc.level : Level 3 412 */ 413 HWTEST_F(DrawingNativeRectTest, testRectSetTopMultipleCalls, Function | SmallTest | Level3) { 414 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 415 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 416 // add assert 417 EXPECT_NE(rect, nullptr); 418 // 2. Loop to call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 10 times (each time 419 // with a different value) 420 for (int i = 0; i < 10; i++) { 421 OH_Drawing_RectSetTop(rect, i * 10); 422 // add assert 423 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 424 // 3. Loop to call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 10 times, Each 425 // time the returned value is consistent with the set value 426 float top = OH_Drawing_RectGetTop(rect); 427 EXPECT_TRUE(IsScalarAlmostEqual(top, i * 10)); 428 } 429 // 3. Loop to call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 10 times, Each time 430 // the returned value is consistent with the set value 431 for (int i = 0; i < 10; i++) { 432 OH_Drawing_RectSetTop(rect, 10); 433 // add assert 434 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 435 // 3. Loop to call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 10 times, Each 436 // time the returned value is consistent with the set value 437 float top = OH_Drawing_RectGetTop(rect); 438 EXPECT_TRUE(IsScalarAlmostEqual(top, 10)); 439 } 440 // 4. Free memory 441 OH_Drawing_RectDestroy(rect); 442 } 443 444 /* 445 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0600 446 * @tc.name: testRectSetRightNormal 447 * @tc.desc: Test for setting and getting the right coordinate of a rectangle with normal parameters. 448 * @tc.size : SmallTest 449 * @tc.type : Function 450 * @tc.level : Level 0 451 */ 452 HWTEST_F(DrawingNativeRectTest, testRectSetRightNormal, Function | SmallTest | Level0) { 453 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 454 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 455 // add assert 456 EXPECT_NE(rect, nullptr); 457 // 2. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 458 OH_Drawing_RectSetRight(rect, 300); 459 // add assert 460 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 461 // 3. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect, Returns the value set 462 // in step 2 463 float right = OH_Drawing_RectGetRight(rect); 464 EXPECT_TRUE(IsScalarAlmostEqual(right, 300)); 465 // 4. Free memory 466 OH_Drawing_RectDestroy(rect); 467 } 468 469 /* 470 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0601 471 * @tc.name: testRectSetRightNull 472 * @tc.desc: Test for setting the right coordinate of a rectangle with NULL parameters. 473 * @tc.size : SmallTest 474 * @tc.type : Function 475 * @tc.level : Level 3 476 */ 477 HWTEST_F(DrawingNativeRectTest, testRectSetRightNull, Function | SmallTest | Level3) { 478 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 479 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 480 // add assert 481 EXPECT_NE(rect, nullptr); 482 // 2. Call OH_Drawing_RectSetRight with the first parameter as nullptr, Returns error code 483 // OH_DRAWING_ERROR_INVALID_PARAMETER 484 OH_Drawing_RectSetRight(nullptr, 0.00); 485 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 486 // 3. Call OH_Drawing_RectSetRight with the second parameter as 0.00, 3. Call fails without crashing 487 OH_Drawing_RectSetRight(rect, 0.00); 488 // 4. Free memory 489 OH_Drawing_RectDestroy(rect); 490 } 491 492 /* 493 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0602 494 * @tc.name: testRectSetRightAbnormal 495 * @tc.desc: Test for setting the right coordinate of a rectangle with abnormal parameters. 496 * @tc.size : SmallTest 497 * @tc.type : Function 498 * @tc.level : Level 3 499 */ 500 HWTEST_F(DrawingNativeRectTest, testRectSetRightAbnormal, Function | SmallTest | Level3) { 501 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 502 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 503 // add assert 504 EXPECT_NE(rect, nullptr); 505 // 2. Call OH_Drawing_RectSetRight with the second parameter as an integer or character data 506 OH_Drawing_RectSetRight(rect, 100); 507 // add assert 508 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 509 // 3. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect, Returns the value set 510 // in step 2 (the passed parameter is forcibly converted) 511 float right = OH_Drawing_RectGetRight(rect); 512 EXPECT_TRUE(IsScalarAlmostEqual(right, 100)); 513 // 4. Free memory 514 OH_Drawing_RectDestroy(rect); 515 } 516 517 /* 518 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0603 519 * @tc.name: testRectSetRightMultipleCalls 520 * @tc.desc: Test for repeatedly setting and getting the right coordinate of a rectangle. 521 * @tc.size : SmallTest 522 * @tc.type : Function 523 * @tc.level : Level 3 524 */ 525 HWTEST_F(DrawingNativeRectTest, testRectSetRightMultipleCalls, Function | SmallTest | Level3) { 526 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 527 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 528 // add assert 529 EXPECT_NE(rect, nullptr); 530 // 2. Loop to call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 10 times (each 531 // time with a different value) 532 for (int i = 0; i < 10; i++) { 533 OH_Drawing_RectSetRight(rect, i * 10); 534 // add assert 535 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 536 // 3. Loop to call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 10 times, 537 // Each time the returned value is consistent with the set value 538 float right = OH_Drawing_RectGetRight(rect); 539 EXPECT_TRUE(IsScalarAlmostEqual(right, i * 10)); 540 } 541 // 3. Loop to call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 10 times, Each 542 // time the returned value is consistent with the set value 543 for (int i = 0; i < 10; i++) { 544 OH_Drawing_RectSetRight(rect, 10); 545 // add assert 546 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 547 // 3. Loop to call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 10 times, 548 // Each time the returned value is consistent with the set value 549 float right = OH_Drawing_RectGetRight(rect); 550 EXPECT_TRUE(IsScalarAlmostEqual(right, 10)); 551 } 552 // 4. Free memory 553 OH_Drawing_RectDestroy(rect); 554 } 555 556 /* 557 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0700 558 * @tc.name: testRectSetBottomNormal 559 * @tc.desc: Test for setting and getting the bottom coordinate of a rectangle with normal parameters. 560 * @tc.size : SmallTest 561 * @tc.type : Function 562 * @tc.level : Level 0 563 */ 564 HWTEST_F(DrawingNativeRectTest, testRectSetBottomNormal, Function | SmallTest | Level0) { 565 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 566 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 567 // add assert 568 EXPECT_NE(rect, nullptr); 569 // 2. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect 570 OH_Drawing_RectSetBottom(rect, 300); 571 // add assert 572 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 573 // 3. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of rect, 3. Returns the value 574 // set in step 2 575 float bottom = OH_Drawing_RectGetBottom(rect); 576 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 300)); 577 // 4. Free memory 578 OH_Drawing_RectDestroy(rect); 579 } 580 581 /* 582 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0701 583 * @tc.name: testRectSetBottomNull 584 * @tc.desc: Test for setting the bottom coordinate of a rectangle with NULL parameters. 585 * @tc.size : SmallTest 586 * @tc.type : Function 587 * @tc.level : Level 3 588 */ 589 HWTEST_F(DrawingNativeRectTest, testRectSetBottomNull, Function | SmallTest | Level3) { 590 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 591 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 592 // add assert 593 EXPECT_NE(rect, nullptr); 594 // 2. Call OH_Drawing_RectSetBottom with the first parameter as nullptr, returns error code 595 // OH_DRAWING_ERROR_INVALID_PARAMETER 596 OH_Drawing_RectSetBottom(nullptr, 0.00); 597 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 598 // 3. Call OH_Drawing_RectSetBottom with the second parameter as 0.00, the call fails without crashing 599 OH_Drawing_RectSetBottom(rect, 0.00); 600 // 4. Free memory 601 OH_Drawing_RectDestroy(rect); 602 } 603 604 /* 605 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0702 606 * @tc.name: testRectSetBottomAbnormal 607 * @tc.desc: Test for setting the bottom coordinate of a rectangle with abnormal parameters. 608 * @tc.size : SmallTest 609 * @tc.type : Function 610 * @tc.level : Level 3 611 */ 612 HWTEST_F(DrawingNativeRectTest, testRectSetBottomAbnormal, Function | SmallTest | Level3) { 613 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 614 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 615 // add assert 616 EXPECT_NE(rect, nullptr); 617 // 2. Call OH_Drawing_RectSetBottom with the second parameter as an integer or character data 618 OH_Drawing_RectSetBottom(rect, 100); 619 // add assert 620 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 621 // 3. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of rect 622 float bottom = OH_Drawing_RectGetBottom(rect); 623 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 100)); 624 // 4. Free memory 625 OH_Drawing_RectDestroy(rect); 626 } 627 628 /* 629 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0703 630 * @tc.name: testRectSetBottomMultipleCalls 631 * @tc.desc: Test for repeatedly setting and getting the bottom coordinate of a rectangle. 632 * @tc.size : SmallTest 633 * @tc.type : Function 634 * @tc.level : Level 3 635 */ 636 HWTEST_F(DrawingNativeRectTest, testRectSetBottomMultipleCalls, Function | SmallTest | Level3) { 637 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 638 // add assert 639 EXPECT_NE(rect, nullptr); 640 641 for (int i = 0; i < 10; i++) { 642 OH_Drawing_RectSetBottom(rect, i * 10); 643 float bottom = OH_Drawing_RectGetBottom(rect); 644 EXPECT_TRUE(IsScalarAlmostEqual(bottom, i * 10)); 645 } 646 647 OH_Drawing_RectDestroy(rect); 648 } 649 650 /* 651 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0800 652 * @tc.name: testRectGetLeftNormal 653 * @tc.desc: Test for setting and getting the left coordinate of a rectangle with normal parameters. 654 * @tc.size : SmallTest 655 * @tc.type : Function 656 * @tc.level : Level 0 657 */ 658 HWTEST_F(DrawingNativeRectTest, testRectGetLeftNormal, Function | SmallTest | Level0) { 659 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 660 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 661 // add assert 662 EXPECT_NE(rect, nullptr); 663 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect 664 OH_Drawing_RectSetLeft(rect, 100); 665 // 3. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of rect 666 float left = OH_Drawing_RectGetLeft(rect); 667 EXPECT_TRUE(IsScalarAlmostEqual(left, 100)); 668 // 4. Free memory 669 OH_Drawing_RectDestroy(rect); 670 } 671 672 /* 673 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0801 674 * @tc.name: testRectGetLeftNull 675 * @tc.desc: Test for getting the left coordinate of a rectangle with NULL parameters. 676 * @tc.size : SmallTest 677 * @tc.type : Function 678 * @tc.level : Level 3 679 */ 680 HWTEST_F(DrawingNativeRectTest, testRectGetLeftNull, Function | SmallTest | Level3) { 681 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 682 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 683 // add assert 684 EXPECT_NE(rect, nullptr); 685 // 2. Call OH_Drawing_RectGetLeft with nullptr as the parameter 686 OH_Drawing_RectGetLeft(nullptr); 687 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 688 // 3. Free memory 689 OH_Drawing_RectDestroy(rect); 690 } 691 692 /* 693 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0900 694 * @tc.name: testRectGetTopNormal 695 * @tc.desc: Test for setting and getting the top coordinate of a rectangle with normal parameters. 696 * @tc.size : SmallTest 697 * @tc.type : Function 698 * @tc.level : Level 0 699 */ 700 HWTEST_F(DrawingNativeRectTest, testRectGetTopNormal, Function | SmallTest | Level0) { 701 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 702 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 703 // add assert 704 EXPECT_NE(rect, nullptr); 705 // 2. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 706 OH_Drawing_RectSetTop(rect, 100); 707 // 3. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 708 float top = OH_Drawing_RectGetTop(rect); 709 EXPECT_TRUE(IsScalarAlmostEqual(top, 100)); 710 // 4. Free memory 711 OH_Drawing_RectDestroy(rect); 712 } 713 714 /* 715 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0901 716 * @tc.name: testRectGetTopNull 717 * @tc.desc: Test for getting the top coordinate of a rectangle with NULL parameters. 718 * @tc.size : SmallTest 719 * @tc.type : Function 720 * @tc.level : Level 3 721 */ 722 HWTEST_F(DrawingNativeRectTest, testRectGetTopNull, Function | SmallTest | Level3) { 723 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 724 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 725 // add assert 726 EXPECT_NE(rect, nullptr); 727 // 2. Call OH_Drawing_RectGetTop with nullptr as the parameter 728 OH_Drawing_RectGetTop(nullptr); 729 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 730 // 3. Free memory 731 OH_Drawing_RectDestroy(rect); 732 } 733 734 /* 735 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1000 736 * @tc.name: testRectGetRightNormal 737 * @tc.desc: Test for setting and getting the right coordinate of a rectangle with normal parameters. 738 * @tc.size : SmallTest 739 * @tc.type : Function 740 * @tc.level : Level 0 741 */ 742 HWTEST_F(DrawingNativeRectTest, testRectGetRightNormal, Function | SmallTest | Level0) { 743 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 744 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 745 // add assert 746 EXPECT_NE(rect, nullptr); 747 // 2. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 748 OH_Drawing_RectSetRight(rect, 300); 749 // 3. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 750 float right = OH_Drawing_RectGetRight(rect); 751 EXPECT_TRUE(IsScalarAlmostEqual(right, 300)); 752 // 4. Free memory 753 OH_Drawing_RectDestroy(rect); 754 } 755 756 /* 757 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1001 758 * @tc.name: testRectGetRightNull 759 * @tc.desc: Test for getting the right coordinate of a rectangle with NULL parameters. 760 * @tc.size : SmallTest 761 * @tc.type : Function 762 * @tc.level : Level 3 763 */ 764 HWTEST_F(DrawingNativeRectTest, testRectGetRightNull, Function | SmallTest | Level3) { 765 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 766 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 767 // add assert 768 EXPECT_NE(rect, nullptr); 769 // 2. Call OH_Drawing_RectGetRight with nullptr as the parameter, returns error code 770 // OH_DRAWING_ERROR_INVALID_PARAMETER 771 OH_Drawing_RectGetRight(nullptr); 772 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 773 // 3. Free memory 774 OH_Drawing_RectDestroy(rect); 775 } 776 777 /* 778 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1100 779 * @tc.name: testRectGetBottomNormal 780 * @tc.desc: Test for setting and getting the bottom coordinate of a rectangle with normal parameters. 781 * @tc.size : SmallTest 782 * @tc.type : Function 783 * @tc.level : Level 0 784 */ 785 HWTEST_F(DrawingNativeRectTest, testRectGetBottomNormal, Function | SmallTest | Level0) { 786 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 787 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 788 // add assert 789 EXPECT_NE(rect, nullptr); 790 // 2. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect 791 OH_Drawing_RectSetBottom(rect, 300); 792 // 3. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of rect, the return value 793 // should be the same as the set value 794 float bottom = OH_Drawing_RectGetBottom(rect); 795 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 300)); 796 // 4. Free memory 797 OH_Drawing_RectDestroy(rect); 798 } 799 800 /* 801 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1101 802 * @tc.name: testRectGetBottomNull 803 * @tc.desc: Test for getting the bottom coordinate of a rectangle with NULL parameters. 804 * @tc.size : SmallTest 805 * @tc.type : Function 806 * @tc.level : Level 3 807 */ 808 HWTEST_F(DrawingNativeRectTest, testRectGetBottomNull, Function | SmallTest | Level3) { 809 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 810 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 811 // add assert 812 EXPECT_NE(rect, nullptr); 813 // 2. Call OH_Drawing_RectGetBottom with nullptr as the parameter, returns error code 814 // OH_DRAWING_ERROR_INVALID_PARAMETER 815 OH_Drawing_RectGetBottom(nullptr); 816 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 817 // 3. Free memory 818 OH_Drawing_RectDestroy(rect); 819 } 820 821 /* 822 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1200 823 * @tc.name: testRectGetHeightNormal 824 * @tc.desc: Test for setting coordinates and getting the height of a rectangle with normal parameters. 825 * @tc.size : SmallTest 826 * @tc.type : Function 827 * @tc.level : Level 0 828 */ 829 HWTEST_F(DrawingNativeRectTest, testRectGetHeightNormal, Function | SmallTest | Level0) { 830 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 831 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 832 // add assert 833 EXPECT_NE(rect, nullptr); 834 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect 835 OH_Drawing_RectSetLeft(rect, 0); 836 // 3. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 837 OH_Drawing_RectSetTop(rect, 0); 838 // 4. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 839 OH_Drawing_RectSetRight(rect, 200); 840 // 5. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect 841 OH_Drawing_RectSetBottom(rect, 200); 842 // 6. Call OH_Drawing_RectGetHeight to get the height of the rectangle, which is the difference between the 843 // y-coordinate of the bottom-right corner and the y-coordinate of the top-left corner 844 float height = OH_Drawing_RectGetHeight(rect); 845 EXPECT_TRUE(IsScalarAlmostEqual(height, 200 - 0)); 846 // 7. Free memory 847 OH_Drawing_RectDestroy(rect); 848 } 849 850 /* 851 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1201 852 * @tc.name: testRectGetHeightNull 853 * @tc.desc: Test for getting the height of a rectangle with NULL parameters. 854 * @tc.size : SmallTest 855 * @tc.type : Function 856 * @tc.level : Level 3 857 */ 858 HWTEST_F(DrawingNativeRectTest, testRectGetHeightNull, Function | SmallTest | Level3) { 859 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 860 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 861 // add assert 862 EXPECT_NE(rect, nullptr); 863 // 2. Call OH_Drawing_RectGetHeight with nullptr as the parameter, returns error code 864 // OH_DRAWING_ERROR_INVALID_PARAMETER 865 OH_Drawing_RectGetHeight(nullptr); 866 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 867 // 3. Free memory 868 OH_Drawing_RectDestroy(rect); 869 } 870 871 /* 872 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1300 873 * @tc.name: testRectGetWidthNormal 874 * @tc.desc: Test for setting coordinates and getting the width of a rectangle with normal parameters. 875 * @tc.size : SmallTest 876 * @tc.type : Function 877 * @tc.level : Level 0 878 */ 879 HWTEST_F(DrawingNativeRectTest, testRectGetWidthNormal, Function | SmallTest | Level0) { 880 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 881 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 882 // add assert 883 EXPECT_NE(rect, nullptr); 884 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner 885 OH_Drawing_RectSetLeft(rect, 0); 886 // 3. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner 887 OH_Drawing_RectSetTop(rect, 0); 888 // 4. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner 889 OH_Drawing_RectSetRight(rect, 200); 890 // 5. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner 891 OH_Drawing_RectSetBottom(rect, 200); 892 // 6. Call OH_Drawing_RectGetWidth to get the width of the rectangle, which is the difference between the 893 // x-coordinate of the bottom-right corner and the x-coordinate of the top-left corner 894 float width = OH_Drawing_RectGetWidth(rect); 895 EXPECT_TRUE(IsScalarAlmostEqual(width, 200 - 0)); 896 // 7. Free memory 897 OH_Drawing_RectDestroy(rect); 898 } 899 900 /* 901 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1301 902 * @tc.name: testRectGetWidthNull 903 * @tc.desc: Test for getting the width of a rectangle with NULL parameters. 904 * @tc.size : SmallTest 905 * @tc.type : Function 906 * @tc.level : Level 3 907 */ 908 HWTEST_F(DrawingNativeRectTest, testRectGetWidthNull, Function | SmallTest | Level3) { 909 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 910 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 911 // add assert 912 EXPECT_NE(rect, nullptr); 913 // 2. Call OH_Drawing_RectGetWidth with nullptr as the parameter, returns error code 914 // OH_DRAWING_ERROR_INVALID_PARAMETER 915 OH_Drawing_RectGetWidth(nullptr); 916 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 917 // 3. Free memory 918 OH_Drawing_RectDestroy(rect); 919 } 920 921 /* 922 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1302 923 * @tc.name: testRectGetWidthBoundary 924 * @tc.desc: Test for setting coordinates and getting the width of a rectangle with normal parameters. 925 * @tc.size : SmallTest 926 * @tc.type : Function 927 * @tc.level : Level 0 928 */ 929 HWTEST_F(DrawingNativeRectTest, testRectGetWidthBoundary, Function | SmallTest | Level0) { 930 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect 931 uint32_t width = 4096; 932 uint32_t height = 2160; 933 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, width, height); 934 // add assert 935 EXPECT_NE(rect, nullptr); 936 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner 937 OH_Drawing_RectSetLeft(rect, 0); 938 // 3. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner 939 OH_Drawing_RectSetTop(rect, 0); 940 // 4. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner 941 OH_Drawing_RectSetRight(rect, width); 942 // 5. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner 943 OH_Drawing_RectSetBottom(rect, height); 944 // 6. Call OH_Drawing_RectGetWidth to get the width of the rectangle, which is the difference between the 945 // x-coordinate of the bottom-right corner and the x-coordinate of the top-left corner 946 float getWidth = OH_Drawing_RectGetWidth(rect); 947 EXPECT_TRUE(IsScalarAlmostEqual(getWidth, width - 0)); 948 // 7. Free memory 949 OH_Drawing_RectDestroy(rect); 950 } 951 952 /* 953 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1400 954 * @tc.name: testRectCopyNormal 955 * @tc.desc: Test for copying a rectangle with normal parameters and checking the copied values. 956 * @tc.size : SmallTest 957 * @tc.type : Function 958 * @tc.level : Level 0 959 */ 960 HWTEST_F(DrawingNativeRectTest, testRectCopyNormal, Function | SmallTest | Level0) { 961 // 1. Call OH_Drawing_RectCreate to create a rectangle object src 962 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, 200, 200); 963 // add assert 964 EXPECT_NE(src, nullptr); 965 // 2. Call OH_Drawing_RectCreate to create a rectangle object dst 966 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, 0, 0); 967 // add assert 968 EXPECT_NE(dst, nullptr); 969 // 3. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of src 970 OH_Drawing_RectSetLeft(src, 100); 971 // 4. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of src 972 OH_Drawing_RectSetTop(src, 100); 973 // 5. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of src 974 OH_Drawing_RectSetRight(src, 300); 975 // 6. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of src 976 OH_Drawing_RectSetBottom(src, 300); 977 // 7. Call OH_Drawing_RectCopy to copy the source rectangle object src to the destination rectangle object dst 978 OH_Drawing_RectCopy(src, dst); 979 // add assert 980 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 981 // 8. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of dst, which should be the same as 982 // the value set in src 983 float left = OH_Drawing_RectGetLeft(dst); 984 EXPECT_TRUE(IsScalarAlmostEqual(left, 100)); 985 // 9. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of dst, which should be the same as 986 // the value set in src 987 float top = OH_Drawing_RectGetTop(dst); 988 EXPECT_TRUE(IsScalarAlmostEqual(top, 100)); 989 // 10. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of dst, which should be the 990 // same as the value set in src 991 float right = OH_Drawing_RectGetRight(dst); 992 EXPECT_TRUE(IsScalarAlmostEqual(right, 300)); 993 // 11. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of dst, which should be the 994 // same as the value set in src 995 float bottom = OH_Drawing_RectGetBottom(dst); 996 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 300)); 997 // 12. Call OH_Drawing_RectSetLeft to modify the x-coordinate of the top-left corner of src 998 OH_Drawing_RectSetLeft(src, 200); 999 // 13. Call OH_Drawing_RectSetTop to modify the y-coordinate of the top-left corner of src 1000 OH_Drawing_RectSetTop(src, 200); 1001 // 14. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of dst, which should be the same 1002 // as the previous value (indicating that the modification in src does not affect the result in dst) 1003 left = OH_Drawing_RectGetLeft(dst); 1004 EXPECT_TRUE(IsScalarAlmostEqual(left, 100)); 1005 // 15. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of dst, which should be the same as 1006 // the previous value (indicating that the modification in src does not affect the result in dst) 1007 top = OH_Drawing_RectGetTop(dst); 1008 EXPECT_TRUE(IsScalarAlmostEqual(top, 100)); 1009 // 16. Free memory 1010 OH_Drawing_RectDestroy(src); 1011 OH_Drawing_RectDestroy(dst); 1012 } 1013 1014 /* 1015 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1401 1016 * @tc.name: testRectCopyNull 1017 * @tc.desc: Test for copying a rectangle with NULL parameters. 1018 * @tc.size : SmallTest 1019 * @tc.type : Function 1020 * @tc.level : Level 3 1021 */ 1022 HWTEST_F(DrawingNativeRectTest, testRectCopyNull, Function | SmallTest | Level3) { 1023 // 1. Call OH_Drawing_RectCreate to create a rectangle object src 1024 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, 200, 200); 1025 // add assert 1026 EXPECT_NE(src, nullptr); 1027 // 2. Call OH_Drawing_RectCreate to create a rectangle object dst 1028 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, 0, 0); 1029 // add assert 1030 EXPECT_NE(dst, nullptr); 1031 // 3. Call OH_Drawing_RectCopy with nullptr as the first parameter, returns error code 1032 // OH_DRAWING_ERROR_INVALID_PARAMETER 1033 OH_Drawing_RectCopy(nullptr, dst); 1034 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 1035 OH_Drawing_ErrorCodeReset(); 1036 // 4. Call OH_Drawing_RectCopy with nullptr as the second parameter, returns error code 1037 // OH_DRAWING_ERROR_INVALID_PARAMETER 1038 OH_Drawing_RectCopy(src, nullptr); 1039 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 1040 // 5. Free memory 1041 OH_Drawing_RectDestroy(src); 1042 OH_Drawing_RectDestroy(dst); 1043 } 1044 1045 /* 1046 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1500 1047 * @tc.name: testRectDestroyNormal 1048 * @tc.desc: Test for creating and destroying a rectangle object with normal parameters. 1049 * @tc.size : SmallTest 1050 * @tc.type : Function 1051 * @tc.level : Level 0 1052 */ 1053 HWTEST_F(DrawingNativeRectTest, testRectDestroyNormal, Function | SmallTest | Level0) { 1054 // 1. Call OH_Drawing_RectCreate to create a rectangle object 1055 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 1056 // add assert 1057 EXPECT_NE(rect, nullptr); 1058 // 2. Call OH_Drawing_RectDestroy to destroy the rectangle object 1059 OH_Drawing_RectDestroy(rect); 1060 } 1061 1062 /* 1063 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1501 1064 * @tc.name: testRectDestroyNull 1065 * @tc.desc: Test for destroying a rectangle object with NULL parameters. 1066 * @tc.size : SmallTest 1067 * @tc.type : Function 1068 * @tc.level : Level 3 1069 */ 1070 HWTEST_F(DrawingNativeRectTest, testRectDestroyNull, Function | SmallTest | Level3) { 1071 // 1. Call OH_Drawing_RectCreate to create a rectangle object 1072 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200); 1073 // add assert 1074 EXPECT_NE(rect, nullptr); 1075 // 2. Call OH_Drawing_RectDestroy with nullptr as the parameter, returns error code 1076 // OH_DRAWING_ERROR_INVALID_PARAMETER 1077 OH_Drawing_RectDestroy(nullptr); 1078 // 3. Call OH_Drawing_RectDestroy to destroy the rectangle object 1079 OH_Drawing_RectDestroy(rect); 1080 } 1081 1082 } // namespace Drawing 1083 } // namespace Rosen 1084 } // namespace OHOS