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 #include <cmath> 16 17 #include "gtest/gtest.h" 18 19 #include "drawing_bitmap.h" 20 #include "drawing_brush.h" 21 #include "drawing_canvas.h" 22 #include "drawing_color.h" 23 #include "drawing_color_filter.h" 24 #include "drawing_filter.h" 25 #include "drawing_font.h" 26 #include "drawing_image.h" 27 #include "drawing_mask_filter.h" 28 #include "drawing_matrix.h" 29 #include "drawing_memory_stream.h" 30 #include "drawing_path.h" 31 #include "drawing_pen.h" 32 #include "drawing_point.h" 33 #include "drawing_rect.h" 34 #include "drawing_region.h" 35 #include "drawing_round_rect.h" 36 #include "drawing_sampling_options.h" 37 #include "drawing_shader_effect.h" 38 #include "drawing_shadow_layer.h" 39 #include "drawing_text_blob.h" 40 #include "drawing_typeface.h" 41 42 using namespace testing; 43 using namespace testing::ext; 44 45 namespace OHOS { 46 namespace Rosen { 47 namespace Drawing { 48 class DrawingNativeBrushTest : public testing::Test { 49 protected: 50 // 在每个测试用例执行前调用 SetUp()51 void SetUp() override 52 { 53 // 设置代码 54 std::cout << "DrawingNativeBrushTest Setup code called before each test case." << std::endl; 55 OH_Drawing_ErrorCodeReset(); 56 std::cout << "DrawingNativeBrushTest errorCodeReset before each test case." << std::endl; 57 } TearDown()58 void TearDown() override 59 { 60 std::cout << "DrawingNativeBrushTest Setup code called after each test case." << std::endl; 61 OH_Drawing_ErrorCodeReset(); 62 std::cout << "DrawingNativeBrushTest errorCodeReset after each test case." << std::endl; 63 } 64 }; 65 66 /* 67 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0100 68 * @tc.name: testBrushCreateNormal 69 * @tc.desc: test for testBrushCreateNormal. 70 * @tc.size : SmallTest 71 * @tc.type : Function 72 * @tc.level : Level 0 73 */ 74 HWTEST_F(DrawingNativeBrushTest, testBrushCreateNormal, TestSize.Level0) { 75 // 1. Call OH_Drawing_BrushCreate to create a brush object 76 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 77 // add assert 78 EXPECT_NE(brush, nullptr); 79 // 2. Free memory 80 OH_Drawing_BrushDestroy(brush); 81 } 82 83 /* 84 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0200 85 * @tc.name: testBrushCopyNormal 86 * @tc.desc: test for testBrushCopyNormal. 87 * @tc.size : SmallTest 88 * @tc.type : Function 89 * @tc.level : Level 0 90 */ 91 HWTEST_F(DrawingNativeBrushTest, testBrushCopyNormal, TestSize.Level0) { 92 // 1. Create a brush object 1 by calling OH_Drawing_BrushCreate 93 OH_Drawing_Brush *brush1 = OH_Drawing_BrushCreate(); 94 // add assert 95 EXPECT_NE(brush1, nullptr); 96 // 2. Set the color of brush 1 by calling OH_Drawing_BrushSetColor 97 OH_Drawing_BrushSetColor(brush1, 0x12345678); 98 // 3. Copy brush 1 to create brush object 2 by calling OH_Drawing_BrushCopy 99 OH_Drawing_Brush *brush2 = OH_Drawing_BrushCopy(brush1); 100 // add assert 101 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 102 // add assert 103 EXPECT_NE(brush2, nullptr); 104 // 4. Get the color of brush object 2 by calling OH_Drawing_BrushGetColor 105 uint32_t color = OH_Drawing_BrushGetColor(brush2); 106 EXPECT_EQ(color, 0x12345678); 107 // 5. Modify the color of brush object 1 by calling OH_Drawing_BrushSetColor 108 OH_Drawing_BrushSetColor(brush1, 0x87654321); 109 // 6. Get the color of brush object 2 again by calling OH_Drawing_BrushGetColor 110 color = OH_Drawing_BrushGetColor(brush2); 111 EXPECT_EQ(color, 0x12345678); 112 // 7. Free memory 113 OH_Drawing_BrushDestroy(brush1); 114 OH_Drawing_BrushDestroy(brush2); 115 } 116 117 /* 118 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0201 119 * @tc.name: testBrushCopyNull 120 * @tc.desc: test for testBrushCopyNull. 121 * @tc.size : SmallTest 122 * @tc.type : Function 123 * @tc.level : Level 3 124 */ 125 HWTEST_F(DrawingNativeBrushTest, testBrushCopyNull, TestSize.Level3) { 126 // 1. Create a brush object by calling OH_Drawing_BrushCreate 127 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 128 // add assert 129 EXPECT_NE(brush, nullptr); 130 // 2. Copy a brush object by calling OH_Drawing_BrushCopy with nullptr as parameter 131 OH_Drawing_Brush *brushCopy = OH_Drawing_BrushCopy(nullptr); 132 // add assert 133 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 134 // 3. Free memory 135 OH_Drawing_BrushDestroy(brush); 136 OH_Drawing_BrushDestroy(brushCopy); 137 } 138 139 /* 140 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0202 141 * @tc.name: testBrushCopyInputDestroyed 142 * @tc.desc: test for testBrushCopyInputDestroyed. 143 * @tc.size : SmallTest 144 * @tc.type : Function 145 * @tc.level : Level 3 146 */ 147 HWTEST_F(DrawingNativeBrushTest, testBrushCopyInputDestroyed, TestSize.Level3) { 148 // 1. Call OH_Drawing_BrushCreate to create a brush object 1 149 OH_Drawing_Brush *brush1 = OH_Drawing_BrushCreate(); 150 // add assert 151 EXPECT_NE(brush1, nullptr); 152 // 2. Copy brush object 1 to create brush object 2 by calling OH_Drawing_BrushCopy 153 OH_Drawing_Brush *brush2 = OH_Drawing_BrushCopy(brush1); 154 // add assert 155 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 156 // add assert 157 EXPECT_NE(brush2, nullptr); 158 // 3. Destroy brush object 1 by calling OH_Drawing_BrushDestroy 159 OH_Drawing_BrushDestroy(brush1); 160 // 4. Set the color of brush object 2 by calling OH_Drawing_BrushSetColor 161 OH_Drawing_BrushSetColor(brush2, 0x12345678); 162 // 5. Get the color of brush object 2 by calling OH_Drawing_BrushGetColor 163 uint32_t color = OH_Drawing_BrushGetColor(brush2); 164 EXPECT_EQ(color, 0x12345678); 165 // 6. Free memory 166 OH_Drawing_BrushDestroy(brush2); 167 } 168 169 /* 170 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0203 171 * @tc.name: testBrushCopyMultipleCalls 172 * @tc.desc: test for testBrushCopyMultipleCalls. 173 * @tc.size : SmallTest 174 * @tc.type : Function 175 * @tc.level : Level 3 176 */ 177 HWTEST_F(DrawingNativeBrushTest, testBrushCopyMultipleCalls, TestSize.Level3) { 178 // 1. Create a brush object by calling OH_Drawing_BrushCreate 179 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 180 // add assert 181 EXPECT_NE(brush, nullptr); 182 // 2. Call OH_Drawing_BrushCopy ten times in a loop 183 for (int i = 0; i < 10; i++) { 184 OH_Drawing_Brush *brushCopy = OH_Drawing_BrushCopy(brush); 185 // add assert 186 EXPECT_NE(brushCopy, nullptr); 187 OH_Drawing_BrushDestroy(brushCopy); 188 } 189 // 3. Free memory 190 OH_Drawing_BrushDestroy(brush); 191 } 192 193 /* 194 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0300 195 * @tc.name: testBrushDestroyNormal 196 * @tc.desc: test for testBrushDestroyNormal. 197 * @tc.size : SmallTest 198 * @tc.type : Function 199 * @tc.level : Level 0 200 */ 201 HWTEST_F(DrawingNativeBrushTest, testBrushDestroyNormal, TestSize.Level0) { 202 // 1. Call OH_Drawing_BrushCreate to create a brush object 203 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 204 // add assert 205 EXPECT_NE(brush, nullptr); 206 // 2. Call OH_Drawing_BrushDestroy to destroy the object 207 OH_Drawing_BrushDestroy(brush); 208 } 209 210 /* 211 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0301 212 * @tc.name: testBrushDestroyNull 213 * @tc.desc: test for testBrushDestroyNull. 214 * @tc.size : SmallTest 215 * @tc.type : Function 216 * @tc.level : Level 3 217 */ 218 HWTEST_F(DrawingNativeBrushTest, testBrushDestroyNull, TestSize.Level3) { 219 // 1. Create a brush object by calling OH_Drawing_BrushCreate 220 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 221 // add assert 222 EXPECT_NE(brush, nullptr); 223 // 2. Call OH_Drawing_BrushDestroy with nullptr as parameter 224 OH_Drawing_BrushDestroy(nullptr); 225 // 3. Free memory 226 OH_Drawing_BrushDestroy(brush); 227 } 228 229 /* 230 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0400 231 * @tc.name: testBrushIsAntiAliasNormal 232 * @tc.desc: test for testBrushIsAntiAliasNormal. 233 * @tc.size : SmallTest 234 * @tc.type : Function 235 * @tc.level : Level 0 236 */ 237 HWTEST_F(DrawingNativeBrushTest, testBrushIsAntiAliasNormal, TestSize.Level0) { 238 // 1. Call OH_Drawing_BrushCreate to create a brush object 239 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 240 // add assert 241 EXPECT_NE(brush, nullptr); 242 // 2. Call OH_Drawing_BrushSetAntiAlias to set the anti-aliasing property to true 243 OH_Drawing_BrushSetAntiAlias(brush, true); 244 // add assert 245 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 246 // 3. Call OH_Drawing_BrushIsAntiAlias to check the return value 247 bool isAntiAlias = OH_Drawing_BrushIsAntiAlias(brush); 248 EXPECT_EQ(isAntiAlias, true); 249 // 4. Free memory 250 OH_Drawing_BrushDestroy(brush); 251 } 252 253 /* 254 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0401 255 * @tc.name: testBrushIsAntiAliasNull 256 * @tc.desc: test for testBrushIsAntiAliasNull. 257 * @tc.size : SmallTest 258 * @tc.type : Function 259 * @tc.level : Level 3 260 */ 261 HWTEST_F(DrawingNativeBrushTest, testBrushIsAntiAliasNull, TestSize.Level3) { 262 // 1. Create a brush object by calling OH_Drawing_BrushCreate 263 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 264 // add assert 265 EXPECT_NE(brush, nullptr); 266 // 2. Call OH_Drawing_BrushIsAntiAlias with nullptr as parameter 267 OH_Drawing_BrushIsAntiAlias(nullptr); 268 // add assert 269 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 270 // 3. Free memory 271 OH_Drawing_BrushDestroy(brush); 272 } 273 274 /* 275 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0500 276 * @tc.name: testBrushSetAntiAliasNormal 277 * @tc.desc: test for testBrushSetAntiAliasNormal. 278 * @tc.size: SmallTest 279 * @tc.type: Function 280 * @tc.level: Level 0 281 */ 282 HWTEST_F(DrawingNativeBrushTest, testBrushSetAntiAliasNormal, TestSize.Level0) { 283 // 1. Call OH_Drawing_BrushCreate to create a brush object 284 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 285 // add assert 286 EXPECT_NE(brush, nullptr); 287 // 2. Call OH_Drawing_BrushSetAntiAlias to set the anti-aliasing property to true 288 OH_Drawing_BrushSetAntiAlias(brush, true); 289 // add assert 290 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 291 // 3. Call OH_Drawing_BrushIsAntiAlias to check the return value 292 bool isAntiAlias = OH_Drawing_BrushIsAntiAlias(brush); 293 EXPECT_EQ(isAntiAlias, true); 294 // 4. Free memory 295 OH_Drawing_BrushDestroy(brush); 296 } 297 298 /* 299 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0501 300 * @tc.name: testBrushSetAntiAliasNull 301 * @tc.desc: test for testBrushSetAntiAliasNull. 302 * @tc.size: SmallTest 303 * @tc.type: Function 304 * @tc.level: Level 3 305 */ 306 HWTEST_F(DrawingNativeBrushTest, testBrushSetAntiAliasNull, TestSize.Level3) { 307 // 1. Create a brush object by calling OH_Drawing_BrushCreate 308 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 309 // add assert 310 EXPECT_NE(brush, nullptr); 311 // 2. Call OH_Drawing_BrushSetAntiAlias with nullptr as the first parameter 312 OH_Drawing_BrushSetAntiAlias(nullptr, true); 313 // add assert 314 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 315 // 3. Free memory 316 OH_Drawing_BrushDestroy(brush); 317 } 318 319 /* 320 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0600 321 * @tc.name: testBrushGetColorNormal 322 * @tc.desc: Test for testBrushGetColorNormal. 323 * @tc.size: SmallTest 324 * @tc.type: Function 325 * @tc.level: Level 0 326 */ 327 HWTEST_F(DrawingNativeBrushTest, testBrushGetColorNormal, TestSize.Level0) { 328 // 1. Create a brush object by calling OH_Drawing_BrushCreate 329 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 330 // add assert 331 EXPECT_NE(brush, nullptr); 332 // 2. Set the color of the brush object by calling OH_Drawing_BrushSetColor 333 OH_Drawing_BrushSetColor(brush, 0x12345678); 334 // add assert 335 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 336 // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor 337 uint32_t color = OH_Drawing_BrushGetColor(brush); 338 EXPECT_EQ(color, 0x12345678); 339 // 4. Free memory 340 OH_Drawing_BrushDestroy(brush); 341 } 342 343 /* 344 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0601 345 * @tc.name: testBrushGetColorNull 346 * @tc.desc: Test for testBrushGetColorNull. 347 * @tc.size: SmallTest 348 * @tc.type: Function 349 * @tc.level: Level 3 350 */ 351 HWTEST_F(DrawingNativeBrushTest, testBrushGetColorNull, TestSize.Level3) { 352 // 1. Create a brush object by calling OH_Drawing_BrushCreate 353 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 354 // add assert 355 EXPECT_NE(brush, nullptr); 356 // 2. Call OH_Drawing_BrushGetColor with nullptr as parameter 357 OH_Drawing_BrushGetColor(nullptr); 358 // add assert 359 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 360 // 3. Free memory 361 OH_Drawing_BrushDestroy(brush); 362 } 363 364 /* 365 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0700 366 * @tc.name: testBrushSetColorNormal 367 * @tc.desc: Test for testBrushSetColorNormal. 368 * @tc.size: SmallTest 369 * @tc.type: Function 370 * @tc.level: Level 0 371 */ 372 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorNormal, TestSize.Level0) { 373 // 1. Create a brush object by calling OH_Drawing_BrushCreate 374 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 375 // add assert 376 EXPECT_NE(brush, nullptr); 377 // 2. Set the color of the brush object by calling OH_Drawing_BrushSetColor 378 OH_Drawing_BrushSetColor(brush, 0x12345678); 379 // add assert 380 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 381 // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor 382 uint32_t color = OH_Drawing_BrushGetColor(brush); 383 EXPECT_EQ(color, 0x12345678); 384 // 4. Free memory 385 OH_Drawing_BrushDestroy(brush); 386 } 387 388 /* 389 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0701 390 * @tc.name: testBrushSetColorNull 391 * @tc.desc: Test for testBrushSetColorNull. 392 * @tc.size: SmallTest 393 * @tc.type: Function 394 * @tc.level: Level 3 395 */ 396 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorNull, TestSize.Level3) { 397 // 1. Create a brush object by calling OH_Drawing_BrushCreate 398 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 399 // add assert 400 EXPECT_NE(brush, nullptr); 401 // 2. Call OH_Drawing_BrushSetColor with nullptr as the first parameter 402 OH_Drawing_BrushSetColor(nullptr, 0x12345678); 403 // add assert 404 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 405 // 3. Call OH_Drawing_BrushSetColor with 0 as the second parameter 406 OH_Drawing_BrushSetColor(brush, 0); 407 // 4. Call OH_Drawing_BrushGetColor to get the brush color 408 uint32_t color = OH_Drawing_BrushGetColor(brush); 409 EXPECT_EQ(color, 0); 410 // 5. Free memory 411 OH_Drawing_BrushDestroy(brush); 412 } 413 414 /* 415 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0702 416 * @tc.name: testBrushSetColorAbnormal 417 * @tc.desc: Test for testBrushSetColorAbnormal. 418 * @tc.size: SmallTest 419 * @tc.type: Function 420 * @tc.level: Level 3 421 */ 422 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorAbnormal, TestSize.Level3) { 423 // 1. Create a brush object by calling OH_Drawing_BrushCreate 424 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 425 // add assert 426 EXPECT_NE(brush, nullptr); 427 // 2. Call OH_Drawing_BrushSetColor with a negative number or a non-uint32_t type parameter as the second argument 428 OH_Drawing_BrushSetColor(brush, -1); 429 // Ignoring the test for passing a floating-point number, as it will result in an error 430 // 3. Call OH_Drawing_BrushGetColor to get the brush color 431 uint32_t color = OH_Drawing_BrushGetColor(brush); 432 EXPECT_EQ(color, std::pow(2, 32) - 1); 433 // 4. Free memory 434 OH_Drawing_BrushDestroy(brush); 435 } 436 437 /* 438 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0703 439 * @tc.name: testBrushSetColorMaximum 440 * @tc.desc: Test for testBrushSetColorMaximum. 441 * @tc.size: SmallTest 442 * @tc.type: Function 443 * @tc.level: Level 3 444 */ 445 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorMaximum, TestSize.Level3) { 446 // 1. Create a brush object by calling OH_Drawing_BrushCreate 447 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 448 // add assert 449 EXPECT_NE(brush, nullptr); 450 // 2. Set the color of the brush object by calling OH_Drawing_BrushSetColor with a value greater than the maximum 451 // value of uint32_t (0xFFFFFFFF) 452 OH_Drawing_BrushSetColor(brush, 0xFFFFFFFF + 1); 453 // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor 454 uint32_t color = OH_Drawing_BrushGetColor(brush); 455 EXPECT_EQ(color, 0); 456 // 4. Free memory 457 OH_Drawing_BrushDestroy(brush); 458 } 459 460 /* 461 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0800 462 * @tc.name: testBrushGetAlphaNormal 463 * @tc.desc: Test for testBrushGetAlphaNormal. 464 * @tc.size: SmallTest 465 * @tc.type: Function 466 * @tc.level: Level 0 467 */ 468 HWTEST_F(DrawingNativeBrushTest, testBrushGetAlphaNormal, TestSize.Level0) { 469 // 1. Create a brush object by calling OH_Drawing_BrushCreate 470 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 471 // add assert 472 EXPECT_NE(brush, nullptr); 473 // 2. Set the alpha value of the brush object by calling OH_Drawing_BrushSetAlpha 474 OH_Drawing_BrushSetAlpha(brush, 128); 475 // 3. Get the alpha value of the brush object by calling OH_Drawing_BrushGetAlpha 476 uint8_t alpha = OH_Drawing_BrushGetAlpha(brush); 477 EXPECT_EQ(alpha, 128); 478 // 4. Free memory 479 OH_Drawing_BrushDestroy(brush); 480 } 481 482 /* 483 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0801 484 * @tc.name: testBrushGetAlphaNull 485 * @tc.desc: Test for testBrushGetAlphaNull. 486 * @tc.size: SmallTest 487 * @tc.type: Function 488 * @tc.level: Level 3 489 */ 490 HWTEST_F(DrawingNativeBrushTest, testBrushGetAlphaNull, TestSize.Level3) { 491 // 1. Create a brush object by calling OH_Drawing_BrushCreate 492 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 493 // add assert 494 EXPECT_NE(brush, nullptr); 495 // 2. Call OH_Drawing_BrushGetAlpha with nullptr as parameter 496 OH_Drawing_BrushGetAlpha(nullptr); 497 // add assert 498 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 499 // 3. Free memory 500 OH_Drawing_BrushDestroy(brush); 501 } 502 503 /* 504 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0900 505 * @tc.name: testBrushSetAlphaNormal 506 * @tc.desc: Test for testBrushSetAlphaNormal. 507 * @tc.size: SmallTest 508 * @tc.type: Function 509 * @tc.level: Level 0 510 */ 511 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaNormal, TestSize.Level0) { 512 // 1. Create a brush object by calling OH_Drawing_BrushCreate 513 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 514 // add assert 515 EXPECT_NE(brush, nullptr); 516 // 2. Set the alpha value of the brush object by calling OH_Drawing_BrushSetAlpha 517 OH_Drawing_BrushSetAlpha(brush, 128); 518 // 3. Get the alpha value of the brush object by calling OH_Drawing_BrushGetAlpha 519 uint8_t alpha = OH_Drawing_BrushGetAlpha(brush); 520 EXPECT_EQ(alpha, 128); 521 // 4. Free memory 522 OH_Drawing_BrushDestroy(brush); 523 } 524 525 /* 526 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0901 527 * @tc.name: testBrushSetAlphaNull 528 * @tc.desc: Test for testBrushSetAlphaNull. 529 * @tc.size: SmallTest 530 * @tc.type: Function 531 * @tc.level: Level 3 532 */ 533 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaNull, TestSize.Level3) { 534 // 1. Create a brush object by calling OH_Drawing_BrushCreate 535 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 536 // add assert 537 EXPECT_NE(brush, nullptr); 538 // 2. Call OH_Drawing_BrushSetAlpha with nullptr as the first parameter 539 OH_Drawing_BrushSetAlpha(nullptr, 128); 540 // add assert 541 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 542 // 3. Call OH_Drawing_BrushSetAlpha with 0 as the second parameter 543 OH_Drawing_BrushSetAlpha(brush, 0); 544 // 4. Free memory 545 OH_Drawing_BrushDestroy(brush); 546 } 547 548 /* 549 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0902 550 * @tc.name: testBrushSetAlphaAbnormal 551 * @tc.desc: Test for testBrushSetAlphaAbnormal. 552 * @tc.size: SmallTest 553 * @tc.type: Function 554 * @tc.level: Level 3 555 */ 556 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaAbnormal, TestSize.Level3) { 557 // 1. Create a brush object by calling OH_Drawing_BrushCreate 558 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 559 // add assert 560 EXPECT_NE(brush, nullptr); 561 // 2. Call OH_Drawing_BrushSetAlpha with a negative number or a non-uint8_t type parameter as the second argument 562 OH_Drawing_BrushSetAlpha(brush, -1); 563 // 3. Call OH_Drawing_BrushGetAlpha to get the alpha value 564 uint8_t alpha = OH_Drawing_BrushGetAlpha(brush); 565 EXPECT_EQ(alpha, 0xff); 566 // 4. Free memory 567 OH_Drawing_BrushDestroy(brush); 568 } 569 570 /* 571 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0903 572 * @tc.name: testBrushSetAlphaMaximum 573 * @tc.desc: Test for testBrushSetAlphaMaximum. 574 * @tc.size: SmallTest 575 * @tc.type: Function 576 * @tc.level: Level 3 577 */ 578 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaMaximum, TestSize.Level3) { 579 // 1. Create a brush object by calling OH_Drawing_BrushCreate 580 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 581 // add assert 582 EXPECT_NE(brush, nullptr); 583 // 2. Set the alpha value of the brush object by calling OH_Drawing_BrushSetAlpha with a value greater than the 584 // maximum value of uint8_t (0xFFFFFFFF + 1) 585 OH_Drawing_BrushSetAlpha(brush, 0xFFFFFFFF + 1); 586 // 3. Get the alpha value of the brush object by calling OH_Drawing_BrushGetAlpha 587 uint8_t alpha = OH_Drawing_BrushGetAlpha(brush); 588 EXPECT_EQ(alpha, 0); 589 // 4. Free memory 590 OH_Drawing_BrushDestroy(brush); 591 } 592 593 /* 594 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1000 595 * @tc.name: testBrushSetShaderEffectNormal 596 * @tc.desc: Test for testBrushSetShaderEffectNormal. 597 * @tc.size: SmallTest 598 * @tc.type: Function 599 * @tc.level: Level 0 600 */ 601 HWTEST_F(DrawingNativeBrushTest, testBrushSetShaderEffectNormal, TestSize.Level0) { 602 // 1. Create a brush object by calling OH_Drawing_BrushCreate 603 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 604 // add assert 605 EXPECT_NE(brush, nullptr); 606 // 2. Create a shader object by calling OH_Drawing_ShaderEffectCreate 607 OH_Drawing_Point *startPt = OH_Drawing_PointCreate(100, 400); 608 OH_Drawing_Point *endPt = OH_Drawing_PointCreate(200, 500); 609 uint32_t color[] = {0xffff0000, 0xff00ff00}; 610 float pos[] = {0., 1.0}; 611 OH_Drawing_ShaderEffect *linearGradient = 612 OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, color, pos, 2, OH_Drawing_TileMode::CLAMP); 613 // add assert 614 EXPECT_NE(linearGradient, nullptr); 615 // 3. Set the shader effect for the brush object by calling OH_Drawing_BrushSetShaderEffect 616 OH_Drawing_BrushSetShaderEffect(brush, linearGradient); 617 // add assert 618 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 619 // 4. Free memory 620 OH_Drawing_ShaderEffectDestroy(linearGradient); 621 OH_Drawing_PointDestroy(startPt); 622 OH_Drawing_PointDestroy(endPt); 623 OH_Drawing_BrushDestroy(brush); 624 } 625 626 /* 627 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1001 628 * @tc.name: testBrushSetShaderEffectNull 629 * @tc.desc: Test for testBrushSetShaderEffectNull. 630 * @tc.size: SmallTest 631 * @tc.type: Function 632 * @tc.level: Level 3 633 */ 634 HWTEST_F(DrawingNativeBrushTest, testBrushSetShaderEffectNull, TestSize.Level3) { 635 // 1. Create a brush object by calling OH_Drawing_BrushCreate 636 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 637 // add assert 638 EXPECT_NE(brush, nullptr); 639 OH_Drawing_Point *startPt = OH_Drawing_PointCreate(100, 400); 640 OH_Drawing_Point *endPt = OH_Drawing_PointCreate(200, 500); 641 uint32_t color[] = {0xffff0000, 0xff00ff00}; 642 float pos[] = {0., 1.0}; 643 OH_Drawing_ShaderEffect *linearGradient = 644 OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, color, pos, 2, OH_Drawing_TileMode::CLAMP); 645 // add assert 646 EXPECT_NE(linearGradient, nullptr); 647 // 2. Call OH_Drawing_BrushSetShaderEffect with nullptr as the first parameter 648 OH_Drawing_BrushSetShaderEffect(nullptr, linearGradient); 649 // add assert 650 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 651 // 3. Call OH_Drawing_BrushSetShaderEffect with nullptr as the second parameter 652 OH_Drawing_BrushSetShaderEffect(brush, nullptr); 653 // 4. Free memory 654 OH_Drawing_ShaderEffectDestroy(linearGradient); 655 OH_Drawing_PointDestroy(startPt); 656 OH_Drawing_PointDestroy(endPt); 657 OH_Drawing_BrushDestroy(brush); 658 } 659 660 /* 661 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1100 662 * @tc.name: testBrushSetShadowLayerNormal 663 * @tc.desc: Test for testBrushSetShadowLayerNormal. 664 * @tc.size: SmallTest 665 * @tc.type: Function 666 * @tc.level: Level 0 667 */ 668 HWTEST_F(DrawingNativeBrushTest, testBrushSetShadowLayerNormal, TestSize.Level0) { 669 // 1. Create a brush object by calling OH_Drawing_BrushCreate 670 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 671 // add assert 672 EXPECT_NE(brush, nullptr); 673 // 2. Create a shadow layer object by calling OH_Drawing_ShadowLayerCreate 674 OH_Drawing_ShadowLayer *shadowLayer = OH_Drawing_ShadowLayerCreate(10, 10, 10, 0x12345678); 675 // add assert 676 EXPECT_NE(shadowLayer, nullptr); 677 // add assert 678 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 679 // 3. Set the shadow layer for the brush object by calling OH_Drawing_BrushSetShadowLayer 680 OH_Drawing_BrushSetShadowLayer(brush, shadowLayer); 681 // add assert 682 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 683 // 4. Free memory 684 OH_Drawing_ShadowLayerDestroy(shadowLayer); 685 } 686 687 /* 688 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1101 689 * @tc.name: testBrushSetShadowLayerNull 690 * @tc.desc: Test for testBrushSetShadowLayerNull. 691 * @tc.size: SmallTest 692 * @tc.type: Function 693 * @tc.level: Level 3 694 */ 695 HWTEST_F(DrawingNativeBrushTest, testBrushSetShadowLayerNull, TestSize.Level3) { 696 // 1. Create a brush object by calling OH_Drawing_BrushCreate 697 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 698 // add assert 699 EXPECT_NE(brush, nullptr); 700 OH_Drawing_ShadowLayer *shadowLayer = OH_Drawing_ShadowLayerCreate(10, 10, 10, 0x12345678); 701 // add assert 702 EXPECT_NE(shadowLayer, nullptr); 703 // 2. Call OH_Drawing_BrushSetShadowLayer with nullptr as the first parameter 704 OH_Drawing_BrushSetShadowLayer(nullptr, shadowLayer); 705 // add assert 706 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 707 // 3. Call OH_Drawing_BrushSetShadowLayer with nullptr as the second parameter 708 OH_Drawing_BrushSetShadowLayer(brush, nullptr); 709 // 4. Free memory 710 OH_Drawing_ShadowLayerDestroy(shadowLayer); 711 } 712 713 /* 714 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1200 715 * @tc.name: testBrushSetFilterNormal 716 * @tc.desc: Test for testBrushSetFilterNormal. 717 * @tc.size: SmallTest 718 * @tc.type: Function 719 * @tc.level: Level 0 720 */ 721 HWTEST_F(DrawingNativeBrushTest, testBrushSetFilterNormal, TestSize.Level0) { 722 // 1. Create a brush object by calling OH_Drawing_BrushCreate 723 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 724 // add assert 725 EXPECT_NE(brush, nullptr); 726 // 2. Create a filter object by calling OH_Drawing_FilterCreate 727 OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); 728 // add assert 729 EXPECT_NE(filter, nullptr); 730 // 3. Set the filter for the brush object by calling OH_Drawing_BrushSetFilter 731 OH_Drawing_BrushSetFilter(brush, filter); 732 // add assert 733 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 734 // 4. Free memory 735 OH_Drawing_FilterDestroy(filter); 736 OH_Drawing_BrushDestroy(brush); 737 } 738 739 /* 740 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1201 741 * @tc.name: testBrushSetFilterNull 742 * @tc.desc: Test for testBrushSetFilterNull. 743 * @tc.size: SmallTest 744 * @tc.type: Function 745 * @tc.level: Level 3 746 */ 747 HWTEST_F(DrawingNativeBrushTest, testBrushSetFilterNull, TestSize.Level3) { 748 // 1. Create a brush object by calling OH_Drawing_BrushCreate 749 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 750 // add assert 751 EXPECT_NE(brush, nullptr); 752 OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); 753 // add assert 754 EXPECT_NE(filter, nullptr); 755 // 2. Call OH_Drawing_BrushSetFilter with nullptr as the first parameter 756 OH_Drawing_BrushSetFilter(nullptr, filter); 757 // add assert 758 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 759 // 3. Call OH_Drawing_BrushSetFilter with nullptr as the second parameter 760 OH_Drawing_BrushSetFilter(brush, nullptr); 761 // 4. Free memory 762 OH_Drawing_FilterDestroy(filter); 763 OH_Drawing_BrushDestroy(brush); 764 } 765 766 /* 767 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1300 768 * @tc.name: testBrushGetFilterNormal 769 * @tc.desc: Test for testBrushGetFilterNormal. 770 * @tc.size: SmallTest 771 * @tc.type: Function 772 * @tc.level: Level 0 773 */ 774 HWTEST_F(DrawingNativeBrushTest, testBrushGetFilterNormal, TestSize.Level0) { 775 // 1. Create a brush object by calling OH_Drawing_BrushCreate 776 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 777 // add assert 778 EXPECT_NE(brush, nullptr); 779 // 2. Create a filter object by calling OH_Drawing_FilterCreate 780 OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); 781 // add assert 782 EXPECT_NE(filter, nullptr); 783 // 3. Set the filter for the brush object by calling OH_Drawing_BrushSetFilter 784 OH_Drawing_BrushSetFilter(brush, filter); 785 // add assert 786 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 787 // 4. Get the filter by calling OH_Drawing_BrushGetFilter 788 OH_Drawing_Filter *tmpFilter = OH_Drawing_FilterCreate(); 789 // add assert 790 EXPECT_NE(tmpFilter, nullptr); 791 OH_Drawing_BrushGetFilter(brush, tmpFilter); 792 // add assert 793 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 794 // 5. Free memory 795 OH_Drawing_FilterDestroy(filter); 796 OH_Drawing_FilterDestroy(tmpFilter); 797 OH_Drawing_BrushDestroy(brush); 798 } 799 800 /* 801 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1301 802 * @tc.name: testBrushGetFilterNull 803 * @tc.desc: Test for testBrushGetFilterNull. 804 * @tc.size: SmallTest 805 * @tc.type: Function 806 * @tc.level: Level 3 807 */ 808 HWTEST_F(DrawingNativeBrushTest, testBrushGetFilterNull, TestSize.Level3) { 809 // 1. Create a brush object by calling OH_Drawing_BrushCreate 810 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 811 // add assert 812 EXPECT_NE(brush, nullptr); 813 OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); 814 // add assert 815 EXPECT_NE(filter, nullptr); 816 // 2. Call OH_Drawing_BrushGetFilter with nullptr as the first parameter 817 OH_Drawing_BrushGetFilter(nullptr, filter); 818 // add assert 819 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 820 OH_Drawing_ErrorCodeReset(); 821 // 3. Call OH_Drawing_BrushGetFilter with nullptr as the second parameter 822 OH_Drawing_BrushGetFilter(brush, nullptr); 823 // add assert 824 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 825 // 4. Free memory 826 OH_Drawing_FilterDestroy(filter); 827 OH_Drawing_BrushDestroy(brush); 828 } 829 830 /* 831 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1400 832 * @tc.name: testBrushSetBlendModeNormal 833 * @tc.desc: Test for testBrushSetBlendModeNormal. 834 * @tc.size: SmallTest 835 * @tc.type: Function 836 * @tc.level: Level 0 837 */ 838 HWTEST_F(DrawingNativeBrushTest, testBrushSetBlendModeNormal, TestSize.Level0) { 839 // 1. Create a brush object by calling OH_Drawing_BrushCreate 840 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 841 // add assert 842 EXPECT_NE(brush, nullptr); 843 // 2. Call OH_Drawing_BrushSetBlendMode with the second parameter being an enumeration 844 OH_Drawing_BlendMode blendMode[] = { 845 BLEND_MODE_CLEAR, BLEND_MODE_SRC, BLEND_MODE_DST, BLEND_MODE_SRC_OVER, 846 BLEND_MODE_DST_OVER, BLEND_MODE_SRC_IN, BLEND_MODE_DST_IN, BLEND_MODE_SRC_OUT, 847 BLEND_MODE_DST_OUT, BLEND_MODE_SRC_ATOP, BLEND_MODE_DST_ATOP, BLEND_MODE_XOR, 848 BLEND_MODE_PLUS, BLEND_MODE_MODULATE, BLEND_MODE_SCREEN, BLEND_MODE_OVERLAY, 849 BLEND_MODE_DARKEN, BLEND_MODE_LIGHTEN, BLEND_MODE_COLOR_DODGE, BLEND_MODE_COLOR_BURN, 850 BLEND_MODE_HARD_LIGHT, BLEND_MODE_SOFT_LIGHT, BLEND_MODE_DIFFERENCE, BLEND_MODE_EXCLUSION, 851 BLEND_MODE_MULTIPLY, BLEND_MODE_HUE, BLEND_MODE_SATURATION, BLEND_MODE_COLOR, 852 BLEND_MODE_LUMINOSITY, 853 }; 854 for (int i = 0; i < sizeof(blendMode) / sizeof(OH_Drawing_BlendMode); i++) { 855 OH_Drawing_ErrorCodeReset(); 856 OH_Drawing_BrushSetBlendMode(brush, blendMode[i]); 857 // add assert 858 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 859 } 860 // 3. Free memory 861 OH_Drawing_BrushDestroy(brush); 862 } 863 864 /* 865 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1401 866 * @tc.name: testBrushSetBlendModeNull 867 * @tc.desc: Test for testBrushSetBlendModeNull. 868 * @tc.size: SmallTest 869 * @tc.type: Function 870 * @tc.level: Level 3 871 */ 872 HWTEST_F(DrawingNativeBrushTest, testBrushSetBlendModeNull, TestSize.Level3) { 873 // 1. Create a brush object by calling OH_Drawing_BrushCreate 874 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 875 // add assert 876 EXPECT_NE(brush, nullptr); 877 // 2. Call OH_Drawing_BrushSetBlendMode with nullptr as the first parameter 878 OH_Drawing_BrushSetBlendMode(nullptr, BLEND_MODE_CLEAR); 879 // add assert 880 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 881 // 3. Free memory 882 OH_Drawing_BrushDestroy(brush); 883 } 884 885 /* 886 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1500 887 * @tc.name: testBrushResetNormal 888 * @tc.desc: Test for testBrushResetNormal. 889 * @tc.size: SmallTest 890 * @tc.type: Function 891 * @tc.level: Level 0 892 */ 893 HWTEST_F(DrawingNativeBrushTest, testBrushResetNormal, TestSize.Level0) { 894 // 1. Create a brush object by calling OH_Drawing_BrushCreate 895 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 896 // add assert 897 EXPECT_NE(brush, nullptr); 898 uint32_t color1 = OH_Drawing_BrushGetColor(brush); 899 // 2. Set the color for the brush object by calling OH_Drawing_BrushSetColor 900 OH_Drawing_BrushSetColor(brush, 0x12345678); 901 // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor 902 uint32_t color2 = OH_Drawing_BrushGetColor(brush); 903 EXPECT_EQ(color2, 0x12345678); 904 // 4. Reset the state of the brush object by calling OH_Drawing_BrushReset 905 OH_Drawing_BrushReset(brush); 906 // add assert 907 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS); 908 // 5. Get the color of the brush object by calling OH_Drawing_BrushGetColor 909 uint32_t color3 = OH_Drawing_BrushGetColor(brush); 910 EXPECT_EQ(color3, color1); 911 // 6. Free memory 912 OH_Drawing_BrushDestroy(brush); 913 } 914 915 /* 916 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1501 917 * @tc.name: testBrushResetNull 918 * @tc.desc: Test for testBrushResetNull. 919 * @tc.size: SmallTest 920 * @tc.type: Function 921 * @tc.level: Level 3 922 */ 923 HWTEST_F(DrawingNativeBrushTest, testBrushResetNull, TestSize.Level3) { 924 // 1. Create a brush object by calling OH_Drawing_BrushCreate 925 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 926 // add assert 927 EXPECT_NE(brush, nullptr); 928 // 2. Call OH_Drawing_BrushReset with nullptr as the parameter 929 OH_Drawing_BrushReset(nullptr); 930 // add assert 931 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 932 // 3. Free memory 933 OH_Drawing_BrushDestroy(brush); 934 } 935 936 } // namespace Drawing 937 } // namespace Rosen 938 } // namespace OHOS