1 /*
2 * Copyright (c) 2022-2023 Huawei Device 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 "gtest/gtest.h"
17
18 #include "draw/canvas.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 namespace Drawing {
26 class CanvasTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void CanvasTest::SetUpTestCase() {}
TearDownTestCase()35 void CanvasTest::TearDownTestCase() {}
SetUp()36 void CanvasTest::SetUp() {}
TearDown()37 void CanvasTest::TearDown() {}
38
39 /**
40 * @tc.name: CreateAndDestroy001
41 * @tc.desc:
42 * @tc.type: FUNC
43 * @tc.require: AR000GGNV3
44 * @tc.author:
45 */
46 HWTEST_F(CanvasTest, CreateAndDestroy001, TestSize.Level1)
47 {
48 auto canvas = std::make_unique<Canvas>();
49 EXPECT_TRUE(canvas != nullptr);
50 }
51
52 /**
53 * @tc.name: CanvasBindTest001
54 * @tc.desc: Test for bind Bitmap function.
55 * @tc.type: FUNC
56 * @tc.require: I719NQ
57 */
58 HWTEST_F(CanvasTest, CanvasBindTest001, TestSize.Level1)
59 {
60 auto canvas = std::make_unique<Canvas>();
61 ASSERT_TRUE(canvas != nullptr);
62 Bitmap bitmap;
63 canvas->Bind(bitmap);
64 }
65
66 /**
67 * @tc.name: CanvasGetTotalMatrixTest001
68 * @tc.desc: Test for geting the total matrix of Canvas to device.
69 * @tc.type: FUNC
70 * @tc.require: I719NQ
71 */
72 HWTEST_F(CanvasTest, CanvasGetTotalMatrixTest001, TestSize.Level1)
73 {
74 auto canvas = std::make_unique<Canvas>();
75 ASSERT_TRUE(canvas != nullptr);
76 auto matrix = std::make_unique<Matrix>(canvas->GetTotalMatrix());
77 EXPECT_TRUE(matrix != nullptr);
78 }
79
80 /**
81 * @tc.name: CanvasGetLocalClipBoundsTest001
82 * @tc.desc: Test for geting bounds of clip in local coordinates.
83 * @tc.type: FUNC
84 * @tc.require: I719NQ
85 */
86 HWTEST_F(CanvasTest, CanvasGetLocalClipBoundsTest001, TestSize.Level1)
87 {
88 auto canvas = std::make_unique<Canvas>();
89 ASSERT_TRUE(canvas != nullptr);
90 auto rect = std::make_unique<Rect>(canvas->GetLocalClipBounds());
91 EXPECT_TRUE(rect != nullptr);
92 }
93
94 /**
95 * @tc.name: CanvasGetDeviceClipBoundsTest001
96 * @tc.desc: Test for geting bounds of clip in device corrdinates.
97 * @tc.type: FUNC
98 * @tc.require: I719NQ
99 */
100 HWTEST_F(CanvasTest, CanvasGetDeviceClipBoundsTest001, TestSize.Level1)
101 {
102 auto canvas = std::make_unique<Canvas>();
103 ASSERT_TRUE(canvas != nullptr);
104 auto rect = std::make_unique<RectI>(canvas->GetDeviceClipBounds());
105 EXPECT_TRUE(rect != nullptr);
106 }
107
108 /**
109 * @tc.name: CanvasGetRoundInDeviceClipBoundsTest001
110 * @tc.desc: Test for geting bounds of clip in device corrdinates.
111 * @tc.type: FUNC
112 * @tc.require: I719NQ
113 */
114 HWTEST_F(CanvasTest, CanvasGetRoundInDeviceClipBoundsTest001, TestSize.Level1)
115 {
116 auto canvas = std::make_unique<Canvas>();
117 ASSERT_TRUE(canvas != nullptr);
118 auto rect = std::make_unique<RectI>(canvas->GetRoundInDeviceClipBounds());
119 EXPECT_TRUE(rect != nullptr);
120 }
121
122 #ifdef RS_ENABLE_GPU
123 /**
124 * @tc.name: CanvasGetGPUContextTest001
125 * @tc.desc: Test for geting gpu context.
126 * @tc.type: FUNC
127 * @tc.require: I782P9
128 */
129 HWTEST_F(CanvasTest, CanvasGetGPUContextTest001, TestSize.Level1)
130 {
131 auto canvas = std::make_unique<Canvas>();
132 ASSERT_TRUE(canvas != nullptr);
133 auto gpuContetxt = canvas->GetGPUContext();
134 EXPECT_TRUE(gpuContetxt == nullptr);
135 }
136 #endif
137
138 /**
139 * @tc.name: CanvasGetWidthTest001
140 * @tc.desc: Test for geting width of Canvas.
141 * @tc.type: FUNC
142 * @tc.require: I719NQ
143 */
144 HWTEST_F(CanvasTest, CanvasGetWidthTest001, TestSize.Level1)
145 {
146 auto canvas = std::make_unique<Canvas>();
147 ASSERT_TRUE(canvas != nullptr);
148 auto rect = canvas->GetWidth();
149 EXPECT_EQ(rect, 0);
150 }
151
152 /**
153 * @tc.name: CanvasGetHeightTest001
154 * @tc.desc: Test for geting height of Canvas.
155 * @tc.type: FUNC
156 * @tc.require: I719NQ
157 */
158 HWTEST_F(CanvasTest, CanvasGetHeightTest001, TestSize.Level1)
159 {
160 auto canvas = std::make_unique<Canvas>();
161 ASSERT_TRUE(canvas != nullptr);
162 auto rect = canvas->GetHeight();
163 EXPECT_EQ(rect, 0);
164 }
165
166 /**
167 * @tc.name: CanvasDrawPointTest001
168 * @tc.desc: Test for DrawPoint function.
169 * @tc.type: FUNC
170 * @tc.require: I719NQ
171 */
172 HWTEST_F(CanvasTest, CanvasDrawPointTest001, TestSize.Level1)
173 {
174 auto canvas = std::make_unique<Canvas>();
175 ASSERT_TRUE(canvas != nullptr);
176 Point point(10.0f, 20.0f);
177 canvas->DrawPoint(point);
178 }
179
180 /**
181 * @tc.name: CanvasDrawLineTest001
182 * @tc.desc: Test for DrawLine function.
183 * @tc.type: FUNC
184 * @tc.require: I719NQ
185 */
186 HWTEST_F(CanvasTest, CanvasDrawLineTest001, TestSize.Level1)
187 {
188 auto canvas = std::make_unique<Canvas>();
189 ASSERT_TRUE(canvas != nullptr);
190 Point startPoint(10.0f, 20.0f);
191 Point endPoint(30.0f, 20.0f);
192 canvas->DrawLine(startPoint, endPoint);
193 }
194
195 /**
196 * @tc.name: CanvasDrawRectTest001
197 * @tc.desc: Test for DrawRect function.
198 * @tc.type: FUNC
199 * @tc.require: I719NQ
200 */
201 HWTEST_F(CanvasTest, CanvasDrawRectTest001, TestSize.Level1)
202 {
203 auto canvas = std::make_unique<Canvas>();
204 ASSERT_TRUE(canvas != nullptr);
205 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
206 canvas->DrawRect(rect);
207 }
208
209 /**
210 * @tc.name: CanvasDrawRoundRectTest001
211 * @tc.desc: Test for DrawRoundRect function.
212 * @tc.type: FUNC
213 * @tc.require: I719NQ
214 */
215 HWTEST_F(CanvasTest, CanvasDrawRoundRectTest001, TestSize.Level1)
216 {
217 auto canvas = std::make_unique<Canvas>();
218 ASSERT_TRUE(canvas != nullptr);
219 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
220 RoundRect roundRect(rect, 1.0f, 1.0f);
221 canvas->DrawRoundRect(roundRect);
222 }
223
224 /**
225 * @tc.name: CanvasDrawNestedRoundRectTest001
226 * @tc.desc: Test for DrawNestedRoundRect function.
227 * @tc.type: FUNC
228 * @tc.require: I719NQ
229 */
230 HWTEST_F(CanvasTest, CanvasDrawNestedRoundRectTest001, TestSize.Level1)
231 {
232 auto canvas = std::make_unique<Canvas>();
233 ASSERT_TRUE(canvas != nullptr);
234 Rect rect1(0.0f, 0.0f, 10.0f, 20.0f);
235 RoundRect roundRect1(rect1, 1.0f, 1.0f);
236 Rect rect2(0.0f, 0.0f, 5.0f, 10.0f);
237 RoundRect roundRect2(rect2, 1.0f, 1.0f);
238 canvas->DrawNestedRoundRect(roundRect1, roundRect2);
239 }
240
241 /**
242 * @tc.name: CanvasDrawArcTest001
243 * @tc.desc: Test for DrawArc function.
244 * @tc.type: FUNC
245 * @tc.require: I719NQ
246 */
247 HWTEST_F(CanvasTest, CanvasDrawArcTest001, TestSize.Level1)
248 {
249 auto canvas = std::make_unique<Canvas>();
250 ASSERT_TRUE(canvas != nullptr);
251 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
252 canvas->DrawArc(rect, 0.0f, 90.0f);
253 }
254
255 /**
256 * @tc.name: CanvasDrawPieTest001
257 * @tc.desc: Test for DrawPie function.
258 * @tc.type: FUNC
259 * @tc.require: I719NQ
260 */
261 HWTEST_F(CanvasTest, CanvasDrawPieTest001, TestSize.Level1)
262 {
263 auto canvas = std::make_unique<Canvas>();
264 ASSERT_TRUE(canvas != nullptr);
265 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
266 canvas->DrawPie(rect, 0.0f, 90.0f);
267 }
268
269 /**
270 * @tc.name: CanvasDrawOvalTest001
271 * @tc.desc: Test for DrawOval function.
272 * @tc.type: FUNC
273 * @tc.require: I719NQ
274 */
275 HWTEST_F(CanvasTest, CanvasDrawOvalTest001, TestSize.Level1)
276 {
277 auto canvas = std::make_unique<Canvas>();
278 ASSERT_TRUE(canvas != nullptr);
279 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
280 canvas->DrawOval(rect);
281 }
282
283 /**
284 * @tc.name: CanvasDrawCircleTest001
285 * @tc.desc: Test for DrawOval function.
286 * @tc.type: FUNC
287 * @tc.require: I719NQ
288 */
289 HWTEST_F(CanvasTest, CanvasDrawCircleTest001, TestSize.Level1)
290 {
291 auto canvas = std::make_unique<Canvas>();
292 ASSERT_TRUE(canvas != nullptr);
293 Point centerpoint(10.0f, 20.0f);
294 canvas->DrawCircle(centerpoint, 10.0f);
295 }
296
297 /**
298 * @tc.name: CanvasDrawPathTest001
299 * @tc.desc: Test for DrawPath function.
300 * @tc.type: FUNC
301 * @tc.require: I719NQ
302 */
303 HWTEST_F(CanvasTest, CanvasDrawPathTest001, TestSize.Level1)
304 {
305 auto canvas = std::make_unique<Canvas>();
306 ASSERT_TRUE(canvas != nullptr);
307 Path path;
308 canvas->DrawPath(path);
309 }
310
311 /**
312 * @tc.name: CanvasDrawBackgroundTest001
313 * @tc.desc: Test for DrawBackground function.
314 * @tc.type: FUNC
315 * @tc.require: I719NQ
316 */
317 HWTEST_F(CanvasTest, CanvasDrawBackgroundTest001, TestSize.Level1)
318 {
319 auto canvas = std::make_unique<Canvas>();
320 ASSERT_TRUE(canvas != nullptr);
321 Brush brush(Color::COLOR_RED);
322 canvas->DrawBackground(brush);
323 }
324
325 /**
326 * @tc.name: CanvasDrawShadowTest001
327 * @tc.desc: Test for DrawShadow function.
328 * @tc.type: FUNC
329 * @tc.require: I719NQ
330 */
331 HWTEST_F(CanvasTest, CanvasDrawShadowTest001, TestSize.Level1)
332 {
333 auto canvas = std::make_unique<Canvas>();
334 ASSERT_TRUE(canvas != nullptr);
335 Path path;
336 Point3 planeParams(1.0f, 0.0f, 0.0f);
337 Point3 devLightPos(1.0f, 1.0f, 1.0f);
338 canvas->DrawShadow(path, planeParams, devLightPos, 1.0f, Color::COLOR_BLACK, Color::COLOR_BLUE, ShadowFlags::NONE);
339 }
340
341 /**
342 * @tc.name: CanvasDrawShadowStyleTest001
343 * @tc.desc: Test for DrawShadowStyle function.
344 * @tc.type: FUNC
345 * @tc.require: I719NQ
346 */
347 HWTEST_F(CanvasTest, CanvasDrawShadowStyleTest001, TestSize.Level1)
348 {
349 auto canvas = std::make_unique<Canvas>();
350 ASSERT_TRUE(canvas != nullptr);
351 Path path;
352 Point3 planeParams(1.0f, 0.0f, 0.0f);
353 Point3 devLightPos(1.0f, 1.0f, 1.0f);
354 canvas->DrawShadowStyle(
355 path, planeParams, devLightPos, 1.0f, Color::COLOR_BLACK, Color::COLOR_BLUE, ShadowFlags::NONE, true);
356 }
357
358 /**
359 * @tc.name: CanvasDrawRegionTest001
360 * @tc.desc: Test for drawing Region on the Canvas.
361 * @tc.type: FUNC
362 * @tc.require: I719R9
363 */
364 HWTEST_F(CanvasTest, CanvasDrawRegionTest001, TestSize.Level1)
365 {
366 auto canvas = std::make_unique<Canvas>();
367 ASSERT_TRUE(canvas != nullptr);
368 Region region;
369 canvas->DrawRegion(region);
370 }
371
372 /**
373 * @tc.name: CanvasDrawAtlasTest001
374 * @tc.desc: Test for drawing Atlas on the Canvas.
375 * @tc.type: FUNC
376 * @tc.require: I719R9
377 */
378 HWTEST_F(CanvasTest, CanvasDrawAtlasTest001, TestSize.Level1)
379 {
380 auto canvas = std::make_unique<Canvas>();
381 ASSERT_TRUE(canvas != nullptr);
382 Bitmap bitmap;
383 BitmapFormat format {ColorType::COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE};
384 bitmap.Build(200, 200, format);
385 bitmap.ClearWithColor(Color::COLOR_WHITE);
386 RSXform xform[] = { {25, 36, 2, 5}, {7, 8, 9, 12} };
387 Rect rect[] = { {0, 0, 50, 50}, {50, 50, 100, 100}};
388 canvas->DrawAtlas(bitmap.MakeImage().get(), xform, rect, nullptr, 2,
389 BlendMode::SRC, SamplingOptions(), nullptr);
390 ColorQuad colors[] = {0xffffffff, 0xff000000};
391 Rect cullRect(0, 0, 100, 100);
392 canvas->DrawAtlas(bitmap.MakeImage().get(), nullptr, rect, colors, 2,
393 BlendMode::SRC, SamplingOptions(), &cullRect);
394 canvas->DrawAtlas(bitmap.MakeImage().get(), xform, nullptr, colors, 2,
395 BlendMode::SRC, SamplingOptions(), &cullRect);
396 canvas->DrawAtlas(bitmap.MakeImage().get(), xform, rect, colors, 2,
397 BlendMode::SRC, SamplingOptions(), &cullRect);
398 canvas->DrawAtlas(bitmap.MakeImage().get(), xform, rect, colors, -10,
399 BlendMode::SRC, SamplingOptions(), &cullRect);
400 canvas->DrawAtlas(bitmap.MakeImage().get(), xform, rect, colors, 5000,
401 BlendMode::SRC, SamplingOptions(), &cullRect);
402 canvas->DrawAtlas(nullptr, xform, rect, colors, 2,
403 BlendMode::SRC, SamplingOptions(), &cullRect);
404 }
405
406 /**
407 * @tc.name: CanvasDrawBitmapTest001
408 * @tc.desc: Test for drawing Bitmap on the Canvas.
409 * @tc.type: FUNC
410 * @tc.require: I719R9
411 */
412 HWTEST_F(CanvasTest, CanvasDrawBitmapTest001, TestSize.Level1)
413 {
414 auto canvas = std::make_unique<Canvas>();
415 ASSERT_TRUE(canvas != nullptr);
416 Bitmap bitmap;
417 canvas->DrawBitmap(bitmap, 10.0f, 10.0f);
418 }
419
420 /**
421 * @tc.name: CanvasDrawImageTest001
422 * @tc.desc: Test for drawing image on the Canvas.
423 * @tc.type: FUNC
424 * @tc.require: I719R9
425 */
426 HWTEST_F(CanvasTest, CanvasDrawImageTest001, TestSize.Level1)
427 {
428 auto canvas = std::make_unique<Canvas>();
429 ASSERT_TRUE(canvas != nullptr);
430 Image image;
431 SamplingOptions samplingOptions;
432 canvas->DrawImage(image, 10.0f, 10.0f, samplingOptions);
433 }
434
435 /**
436 * @tc.name: CanvasDrawImageRectTest001
437 * @tc.desc: Test for DrawImageRect function.
438 * @tc.type: FUNC
439 * @tc.require: I719R9
440 */
441 HWTEST_F(CanvasTest, CanvasDrawImageRectTest001, TestSize.Level1)
442 {
443 auto canvas = std::make_unique<Canvas>();
444 ASSERT_TRUE(canvas != nullptr);
445 Image image;
446 Rect srcRect(0.0f, 0.0f, 10.0f, 20.0f);
447 Rect dstRect(0.0f, 0.0f, 10.0f, 20.0f);
448 SamplingOptions samplingOptions;
449 canvas->DrawImageRect(image, srcRect, dstRect, samplingOptions);
450 }
451
452 /**
453 * @tc.name: CanvasDrawImageRectTest002
454 * @tc.desc: Test for DrawImageRect function.
455 * @tc.type: FUNC
456 * @tc.require: I719R9
457 */
458 HWTEST_F(CanvasTest, CanvasDrawImageRectTest002, TestSize.Level1)
459 {
460 auto canvas = std::make_unique<Canvas>();
461 ASSERT_TRUE(canvas != nullptr);
462 Image image;
463 Rect dstRect(0.0f, 0.0f, 10.0f, 20.0f);
464 SamplingOptions samplingOptions;
465 canvas->DrawImageRect(image, dstRect, samplingOptions);
466 }
467
468 /**
469 * @tc.name: CanvasDrawPictureTest001
470 * @tc.desc: Test for DrawPicture function.
471 * @tc.type: FUNC
472 * @tc.require: I719R9
473 */
474 HWTEST_F(CanvasTest, CanvasDrawPictureTest001, TestSize.Level1)
475 {
476 auto canvas = std::make_unique<Canvas>();
477 ASSERT_TRUE(canvas != nullptr);
478 Picture pic;
479 canvas->DrawPicture(pic);
480 }
481
482 /**
483 * @tc.name: DrawImageEffectHPSTest001
484 * @tc.desc: Test for DrawImageEffectHPS function.
485 * @tc.type: FUNC
486 * @tc.require: I719R9
487 */
488 HWTEST_F(CanvasTest, DrawImageEffectHPSTest001, TestSize.Level1)
489 {
490 auto canvas = std::make_unique<Canvas>();
491 ASSERT_TRUE(canvas != nullptr);
492 Drawing::Image image;
493 Drawing::Rect srcRect = { 0.0f, 0.0f, 1.0f, 1.0f };
494 Drawing::Rect dstRect = { 0.0f, 0.0f, 1.0f, 1.0f };
495 std::vector<std::shared_ptr<Drawing::HpsEffectParameter>> hpsEffectParams;
496 hpsEffectParams.push_back(std::make_shared<Drawing::HpsBlurEffectParameter>(srcRect, dstRect, 10.f, 1.f, 1.f));
497 canvas->DrawImageEffectHPS(image, hpsEffectParams);
498 }
499
500 /**
501 * @tc.name: HpsEffectParameterGetTypeTest001
502 * @tc.desc: Test for HpsEffectParameter GetEffectType function.
503 * @tc.type: FUNC
504 * @tc.require: I719R9
505 */
506 HWTEST_F(CanvasTest, HpsEffectParameterGetTypeTest001, TestSize.Level1)
507 {
508 Drawing::Image image;
509 Drawing::Rect srcRect = { 0.0f, 0.0f, 1.0f, 1.0f };
510 Drawing::Rect dstRect = { 0.0f, 0.0f, 1.0f, 1.0f };
511 // Blur
512 auto hpsBlurEffectArgs = std::make_shared<Drawing::HpsBlurEffectParameter>(srcRect, dstRect, 10.f, 1.f, 1.f);
513 EXPECT_EQ(hpsBlurEffectArgs->GetEffectType(), Drawing::HpsEffect::BLUR);
514 // GREY
515 auto hpsGreyArgs = std::make_shared<Drawing::HpsGreyParameter>(srcRect, dstRect, 1.f, 2.f);
516 EXPECT_EQ(hpsGreyArgs->GetEffectType(), Drawing::HpsEffect::GREY);
517 // AIBAR
518 auto hpsAiBarArgs = std::make_shared<Drawing::HpsAiBarParameter>(srcRect, dstRect,
519 0.5f, 0.7f, 0.5f, 0.2f, 1.f);
520 EXPECT_EQ(hpsAiBarArgs->GetEffectType(), Drawing::HpsEffect::AIBAR);
521 // STRETCH
522 auto hpsStretchArgs = std::make_shared<Drawing::HpsStretchParameter>(srcRect, dstRect,
523 11.f, 12.f, 13.f, 14.f, 1, 256.f, 256.f);
524 EXPECT_EQ(hpsStretchArgs->GetEffectType(), Drawing::HpsEffect::STRETCH);
525 // LINEAR_GRADIENT_BLUR
526 std::vector<float> fractionStopsData = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f};
527 std::shared_ptr<std::vector<float>> fractionStopsPtr = std::make_shared<std::vector<float>>(fractionStopsData);
528 uint32_t fractionStopsCount = fractionStopsData.size() / 2;
529 std::array<float, 9> mat = {1.0f, 0.0f, 56.0f, 0.0f, 1.0f, 1898.0f, 0.0f, 0.0f, 1.0f};
530 auto hpsGradientBlurArgs = std::make_shared<Drawing::HpsGradientBlurParameter>(srcRect, dstRect,
531 30.f, fractionStopsPtr, fractionStopsCount, 0, 1316.f, 364.f, mat);
532 EXPECT_EQ(hpsGradientBlurArgs->GetEffectType(), Drawing::HpsEffect::LINEAR_GRADIENT_BLUR);
533 // MESA
534 auto hpsMesaArgs = std::make_shared<Drawing::HpsMesaParameter>(srcRect, dstRect,
535 10.f, 1.f, 2.f, 11.f, 12.f, 13.f, 14.f, 1, 256.f, 256.f);
536 EXPECT_EQ(hpsMesaArgs->GetEffectType(), Drawing::HpsEffect::MESA);
537 }
538
539 /**
540 * @tc.name: CanvasClipRectTest001
541 * @tc.desc: Test replacing the clipping area with the intersection or difference between clipping area and Rect.
542 * @tc.type: FUNC
543 * @tc.require: I719R9
544 */
545 HWTEST_F(CanvasTest, CanvasClipRectTest001, TestSize.Level1)
546 {
547 auto canvas = std::make_unique<Canvas>();
548 ASSERT_TRUE(canvas != nullptr);
549 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
550 canvas->ClipRect(rect, ClipOp::DIFFERENCE, true);
551 }
552
553 /**
554 * @tc.name: CanvasClipRoundRectTest001
555 * @tc.desc: Test replacing the clipping area with the intersection or difference of clipping area and Rect.
556 * @tc.type: FUNC
557 * @tc.require: I719R9
558 */
559 HWTEST_F(CanvasTest, CanvasClipRoundRectTest001, TestSize.Level1)
560 {
561 auto canvas = std::make_unique<Canvas>();
562 ASSERT_TRUE(canvas != nullptr);
563 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
564 RoundRect roundRect(rect, 1.0f, 1.0f);
565 canvas->ClipRoundRect(roundRect, ClipOp::DIFFERENCE, true);
566 }
567
568 /**
569 * @tc.name: CanvasClipPathTest001
570 * @tc.desc: Test replacing the clipping area with the intersection or difference between clipping area and path.
571 * @tc.type: FUNC
572 * @tc.require: I719R9
573 */
574 HWTEST_F(CanvasTest, CanvasClipPathTest001, TestSize.Level1)
575 {
576 auto canvas = std::make_unique<Canvas>();
577 ASSERT_TRUE(canvas != nullptr);
578 Path path;
579 canvas->ClipPath(path, ClipOp::DIFFERENCE, true);
580 }
581
582 /**
583 * @tc.name: CanvasSetMatrixTest001
584 * @tc.desc: Test for SetMatrix function.
585 * @tc.type: FUNC
586 * @tc.require: I719R9
587 */
588 HWTEST_F(CanvasTest, CanvasSetMatrixTest001, TestSize.Level1)
589 {
590 auto canvas = std::make_unique<Canvas>();
591 ASSERT_TRUE(canvas != nullptr);
592 Matrix matrix;
593 canvas->SetMatrix(matrix);
594 }
595
596 /**
597 * @tc.name: CanvasResetMatrixTest001
598 * @tc.desc: Test for ResetMatrix function.
599 * @tc.type: FUNC
600 * @tc.require: I719R9
601 */
602 HWTEST_F(CanvasTest, CanvasResetMatrixTest001, TestSize.Level1)
603 {
604 auto canvas = std::make_unique<Canvas>();
605 ASSERT_TRUE(canvas != nullptr);
606 Matrix matrix;
607 canvas->SetMatrix(matrix);
608 canvas->ResetMatrix();
609 }
610
611 /**
612 * @tc.name: CanvasConcatMatrixTest001
613 * @tc.desc: Test for ConcatMatrix function.
614 * @tc.type: FUNC
615 * @tc.require: I719R9
616 */
617 HWTEST_F(CanvasTest, CanvasConcatMatrixTest001, TestSize.Level1)
618 {
619 auto canvas = std::make_unique<Canvas>();
620 ASSERT_TRUE(canvas != nullptr);
621 Matrix matrix;
622 canvas->ConcatMatrix(matrix);
623 }
624
625 /**
626 * @tc.name: CanvasTranslateTest001
627 * @tc.desc: Test for Translate function.
628 * @tc.type: FUNC
629 * @tc.require: I719R9
630 */
631 HWTEST_F(CanvasTest, CanvasTranslateTest001, TestSize.Level1)
632 {
633 auto canvas = std::make_unique<Canvas>();
634 ASSERT_TRUE(canvas != nullptr);
635 canvas->Translate(1.0f, 1.0f);
636 }
637
638 /**
639 * @tc.name: CanvasScaleTest001
640 * @tc.desc: Test for Scale function.
641 * @tc.type: FUNC
642 * @tc.require: I719R9
643 */
644 HWTEST_F(CanvasTest, CanvasScaleTest001, TestSize.Level1)
645 {
646 auto canvas = std::make_unique<Canvas>();
647 ASSERT_TRUE(canvas != nullptr);
648 canvas->Scale(1.0f, 1.0f);
649 }
650
651 /**
652 * @tc.name: CanvasRotateTest001
653 * @tc.desc: Test for Rotating Matrix by degrees.
654 * @tc.type: FUNC
655 * @tc.require: I719R9
656 */
657 HWTEST_F(CanvasTest, CanvasRotateTest001, TestSize.Level1)
658 {
659 auto canvas = std::make_unique<Canvas>();
660 ASSERT_TRUE(canvas != nullptr);
661 canvas->Rotate(60.0f);
662 }
663
664 /**
665 * @tc.name: CanvasRotateTest002
666 * @tc.desc: Test for Rotating Matrix by degrees.
667 * @tc.type: FUNC
668 * @tc.require: I719R9
669 */
670 HWTEST_F(CanvasTest, CanvasRotateTest002, TestSize.Level1)
671 {
672 auto canvas = std::make_unique<Canvas>();
673 ASSERT_TRUE(canvas != nullptr);
674 canvas->Rotate(60.0f, 10.0f, 10.0f);
675 }
676
677 /**
678 * @tc.name: CanvasShearTest001
679 * @tc.desc: Test for Shear function.
680 * @tc.type: FUNC
681 * @tc.require: I719R9
682 */
683 HWTEST_F(CanvasTest, CanvasShearTest001, TestSize.Level1)
684 {
685 auto canvas = std::make_unique<Canvas>();
686 ASSERT_TRUE(canvas != nullptr);
687 canvas->Shear(10.0f, 10.0f);
688 }
689
690 /**
691 * @tc.name: CanvasFlushTest001
692 * @tc.desc: Test for Flush function.
693 * @tc.type: FUNC
694 * @tc.require: I719R9
695 */
696 HWTEST_F(CanvasTest, CanvasFlushTest001, TestSize.Level1)
697 {
698 auto canvas = std::make_unique<Canvas>();
699 ASSERT_TRUE(canvas != nullptr);
700 canvas->Flush();
701 }
702
703 /**
704 * @tc.name: CanvasClearTest001
705 * @tc.desc: Test for Clear function.
706 * @tc.type: FUNC
707 * @tc.require: I719R9
708 */
709 HWTEST_F(CanvasTest, CanvasClearTest001, TestSize.Level1)
710 {
711 auto canvas = std::make_unique<Canvas>();
712 ASSERT_TRUE(canvas != nullptr);
713 canvas->Clear(Color::COLOR_BLUE);
714 }
715
716 /**
717 * @tc.name: CanvasSaveTest001
718 * @tc.desc: Test for Save function.
719 * @tc.type: FUNC
720 * @tc.require: I719R9
721 */
722 HWTEST_F(CanvasTest, CanvasSaveTest001, TestSize.Level1)
723 {
724 auto canvas = std::make_unique<Canvas>();
725 ASSERT_TRUE(canvas != nullptr);
726 canvas->Save();
727 }
728
729 /**
730 * @tc.name: CanvasSaveLayerTest001
731 * @tc.desc: Test for saving Matrix and clipping area, and allocates Surface for subsequent drawing.
732 * @tc.type: FUNC
733 * @tc.require: I719U5
734 */
735 HWTEST_F(CanvasTest, CanvasSaveLayerTest001, TestSize.Level1)
736 {
737 auto canvas = std::make_unique<Canvas>();
738 ASSERT_TRUE(canvas != nullptr);
739 SaveLayerOps saveLayerOps;
740 canvas->SaveLayer(saveLayerOps);
741 }
742
743 /**
744 * @tc.name: CanvasSaveLayerTest002
745 * @tc.desc: Test for saving Matrix and clipping area, and allocates Surface for subsequent drawing.
746 * @tc.type: FUNC
747 * @tc.require: I719U5
748 */
749 HWTEST_F(CanvasTest, CanvasSaveLayerTest002, TestSize.Level1)
750 {
751 auto canvas = std::make_unique<Canvas>();
752 ASSERT_TRUE(canvas != nullptr);
753 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
754 Brush brush;
755 uint32_t saveLayerFlags = 0;
756 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
757 canvas->SaveLayer(saveLayerRec);
758 }
759
760 /**
761 * @tc.name: CanvasRestoreTest001
762 * @tc.desc: Test for Restore function.
763 * @tc.type: FUNC
764 * @tc.require: I719U5
765 */
766 HWTEST_F(CanvasTest, CanvasRestoreTest001, TestSize.Level1)
767 {
768 auto canvas = std::make_unique<Canvas>();
769 ASSERT_TRUE(canvas != nullptr);
770 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
771 Brush brush;
772 uint32_t saveLayerFlags = 0;
773 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
774 canvas->SaveLayer(saveLayerRec);
775 canvas->Restore();
776 }
777
778 /**
779 * @tc.name: CanvasGetSaveCountTest001
780 * @tc.desc: Test for geting the number of saved states.
781 * @tc.type: FUNC
782 * @tc.require: I719U5
783 */
784 HWTEST_F(CanvasTest, CanvasGetSaveCountTest001, TestSize.Level1)
785 {
786 auto canvas = std::make_unique<Canvas>();
787 ASSERT_TRUE(canvas != nullptr);
788 canvas->Save();
789 EXPECT_TRUE(2 == canvas->GetSaveCount());
790 }
791
792 /**
793 * @tc.name: CanvasRestoreToCountTest001
794 * @tc.desc: Test for restoring Canvas Matrix and clip value state to count.
795 * @tc.type: FUNC
796 * @tc.require: I719U5
797 */
798 HWTEST_F(CanvasTest, CanvasRestoreToCountTest001, TestSize.Level1)
799 {
800 auto canvas = std::make_unique<Canvas>();
801 ASSERT_TRUE(canvas != nullptr);
802 canvas->RestoreToCount(2);
803 }
804
805 /**
806 * @tc.name: CanvasAttachAndDetachPenTest001
807 * @tc.desc: Test for AttachPen and DetachPen functions.
808 * @tc.type: FUNC
809 * @tc.require: I719U5
810 */
811 HWTEST_F(CanvasTest, CanvasAttachAndDetachPenTest001, TestSize.Level1)
812 {
813 auto canvas = std::make_unique<Canvas>();
814 ASSERT_TRUE(canvas != nullptr);
815 Pen pen(Color::COLOR_GREEN);
816 canvas->AttachPen(pen);
817 canvas->DetachPen();
818 }
819
820 /**
821 * @tc.name: CanvasAttachAndDetachBrushTest001
822 * @tc.desc: Test for AttachBrush and DetachBrush functions.
823 * @tc.type: FUNC
824 * @tc.require: I719U5
825 */
826 HWTEST_F(CanvasTest, CanvasAttachAndDetachBrushTest001, TestSize.Level1)
827 {
828 auto canvas = std::make_unique<Canvas>();
829 ASSERT_TRUE(canvas != nullptr);
830 Brush brush(Color::COLOR_GREEN);
831 canvas->AttachBrush(brush);
832 canvas->DetachBrush();
833 }
834
835 /**
836 * @tc.name: SetOffscreenTest001
837 * @tc.desc: Test for SetOffscreen functions.
838 * @tc.type: FUNC
839 * @tc.require:
840 */
841 HWTEST_F(CanvasTest, SetOffscreenTest001, TestSize.Level1)
842 {
843 auto canvas = std::make_unique<Canvas>();
844 ASSERT_TRUE(canvas != nullptr);
845 canvas->SetOffscreen(true);
846 bool state = canvas->GetOffscreen();
847 ASSERT_TRUE(state);
848 }
849
850 /**
851 * @tc.name: SetUICaptureTest001
852 * @tc.desc: Test for SetUICapture functions.
853 * @tc.type: FUNC
854 * @tc.require:
855 */
856 HWTEST_F(CanvasTest, SetUICaptureTest001, TestSize.Level1)
857 {
858 auto canvas = std::make_unique<Canvas>();
859 ASSERT_TRUE(canvas != nullptr);
860 canvas->SetUICapture(true);
861 bool state = canvas->GetUICapture();
862 ASSERT_TRUE(state);
863 }
864
865 /**
866 * @tc.name: GetRecordingStateTest001
867 * @tc.desc: Test for GetRecordingState functions.
868 * @tc.type: FUNC
869 * @tc.require: I719U5
870 */
871 HWTEST_F(CanvasTest, GetRecordingStateTest001, TestSize.Level1)
872 {
873 auto canvas = std::make_unique<Canvas>();
874 ASSERT_TRUE(canvas != nullptr);
875 canvas->SetRecordingState(true);
876 bool state = canvas->GetRecordingState();
877 ASSERT_TRUE(state);
878 }
879
880 /**
881 * @tc.name: SetRecordingStateTest001
882 * @tc.desc: Test for SetRecordingState functions.
883 * @tc.type: FUNC
884 * @tc.require: I719U5
885 */
886 HWTEST_F(CanvasTest, SetRecordingStateTest001, TestSize.Level1)
887 {
888 auto canvas = std::make_unique<Canvas>();
889 ASSERT_TRUE(canvas != nullptr);
890 canvas->SetRecordingState(false);
891 bool state = canvas->GetRecordingState();
892 ASSERT_TRUE(!state);
893 }
894
895 /**
896 * @tc.name: GetDrawingTypeTest001
897 * @tc.desc: Test for GetDrawingType functions.
898 * @tc.type: FUNC
899 * @tc.require: I719U5
900 */
901 HWTEST_F(CanvasTest, GetDrawingTypeTest001, TestSize.Level1)
902 {
903 std::shared_ptr<Drawing::OverDrawCanvas> overDrawCanvas;
904 DrawingType type = overDrawCanvas->GetDrawingType();
905 ASSERT_TRUE(type == DrawingType::OVER_DRAW);
906 overDrawCanvas->SetGrContext(nullptr);
907 EXPECT_EQ(overDrawCanvas->GetGPUContext(), nullptr);
908 }
909
910 /**
911 * @tc.name: GetDrawingTypeTest002
912 * @tc.desc: Test for GetDrawingType NoDrawCanvas functions.
913 * @tc.type: FUNC
914 * @tc.require: I719U5
915 */
916 HWTEST_F(CanvasTest, GetDrawingTypeTest002, TestSize.Level1)
917 {
918 std::shared_ptr<Drawing::NoDrawCanvas> noDrawCanvas;
919 DrawingType type = noDrawCanvas->GetDrawingType();
920 ASSERT_TRUE(type == DrawingType::NO_DRAW);
921 }
922
923 /**
924 * @tc.name: GetDrawingTypeTest003
925 * @tc.desc: Test for GetDrawingType functions.
926 * @tc.type: FUNC
927 * @tc.require: I719U5
928 */
929 HWTEST_F(CanvasTest, GetDrawingTypeTest003, TestSize.Level1)
930 {
931 std::shared_ptr<Drawing::StateInheriteCanvas> stateInheriteCanvas;
932 DrawingType type = stateInheriteCanvas->GetDrawingType();
933 ASSERT_TRUE(type == DrawingType::INHERITE_STATE);
934 }
935
936 /**
937 * @tc.name: GetBounds001
938 * @tc.desc: Test for geting the bounds of layer.
939 * @tc.type: FUNC
940 * @tc.require: I719U5
941 */
942 HWTEST_F(CanvasTest, GetBounds001, TestSize.Level1)
943 {
944 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
945 Brush brush;
946 uint32_t saveLayerFlags = 0;
947 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
948 auto ret = saveLayerRec.GetBounds();
949 EXPECT_EQ(ret->GetLeft(), 0.0f);
950 EXPECT_EQ(ret->GetBottom(), 20.0f);
951 }
952
953 /**
954 * @tc.name: GetBrush001
955 * @tc.desc: Test for geting the brush of layer.
956 * @tc.type: FUNC
957 * @tc.require: I719U5
958 */
959 HWTEST_F(CanvasTest, GetBrush001, TestSize.Level1)
960 {
961 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
962 Brush brush;
963 uint32_t saveLayerFlags = 0;
964 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
965 auto ret = saveLayerRec.GetBrush();
966 EXPECT_TRUE(ret != nullptr);
967 }
968
969 /**
970 * @tc.name: GetSaveLayerFlags001
971 * @tc.desc: Test for geting the options to modify layer.
972 * @tc.type: FUNC
973 * @tc.require: I719U5
974 */
975 HWTEST_F(CanvasTest, GetSaveLayerFlags001, TestSize.Level1)
976 {
977 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
978 Brush brush;
979 uint32_t saveLayerFlags = 0;
980 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
981 auto ret = saveLayerRec.GetSaveLayerFlags();
982 EXPECT_EQ(ret, 0);
983 }
984
985 /**
986 * @tc.name: AutoCanvasRestoreTest001
987 * @tc.desc: Test for Creating AutoCanvasRestore;
988 * @tc.type: FUNC
989 * @tc.require: I719U5
990 */
991 HWTEST_F(CanvasTest, AutoCanvasRestoreTest001, TestSize.Level1)
992 {
993 Canvas canvas;
994 bool doSave = true;
995 auto autoCanvasRestore = std::make_unique<AutoCanvasRestore>(canvas, doSave);
996 ASSERT_TRUE(autoCanvasRestore != nullptr);
997 }
998
999 /**
1000 * @tc.name: GetStencilVal001
1001 * @tc.desc: Test for GetStencilVal
1002 * @tc.type: FUNC
1003 * @tc.require: IBROZ2
1004 */
1005 HWTEST_F(CanvasTest, GetStencilVal001, TestSize.Level1)
1006 {
1007 Canvas canvas;
1008 EXPECT_EQ(canvas.GetStencilVal(), Canvas::INVALID_STENCIL_VAL);
1009
1010 constexpr int64_t testStencilVal{1};
1011 canvas.SetStencilVal(testStencilVal);
1012 EXPECT_EQ(canvas.GetStencilVal(), testStencilVal);
1013 }
1014
1015 /**
1016 * @tc.name: GetMaxStencilVal001
1017 * @tc.desc: Test for GetMaxStencilVal
1018 * @tc.type: FUNC
1019 * @tc.require: IBROZ2
1020 */
1021 HWTEST_F(CanvasTest, GetMaxStencilVal001, TestSize.Level1)
1022 {
1023 Canvas canvas;
1024 EXPECT_EQ(canvas.GetMaxStencilVal(), 0);
1025
1026 constexpr int64_t testStencilVal{1};
1027 canvas.SetMaxStencilVal(testStencilVal);
1028 EXPECT_EQ(canvas.GetMaxStencilVal(), testStencilVal);
1029 }
1030
1031 /**
1032 * @tc.name: SetGrContext001
1033 * @tc.desc: Test for SetGrContext
1034 * @tc.type: FUNC
1035 * @tc.require: IBROZ2
1036 */
1037 HWTEST_F(CanvasTest, SetGrContext001, TestSize.Level1)
1038 {
1039 std::shared_ptr<Canvas> canvas;
1040 auto overDrawCanvas = std::make_shared<OverDrawCanvas>(canvas);
1041 auto gpuContext = std::make_shared<GPUContext>();
1042 overDrawCanvas->SetGrContext(gpuContext);
1043 ASSERT_TRUE(overDrawCanvas->GetGPUContext() != nullptr);
1044 }
1045
1046 /**
1047 * @tc.name: GetGPUContext001
1048 * @tc.desc: Test for GetGPUContext
1049 * @tc.type: FUNC
1050 * @tc.require: IBROZ2
1051 */
1052 HWTEST_F(CanvasTest, GetGPUContext001, TestSize.Level1)
1053 {
1054 std::shared_ptr<Canvas> canvas;
1055 auto overDrawCanvas = std::make_shared<OverDrawCanvas>(canvas);
1056 auto gpuContext = std::make_shared<GPUContext>();
1057 ASSERT_FALSE(overDrawCanvas->GetGPUContext() == gpuContext);
1058 overDrawCanvas->SetGrContext(gpuContext);
1059 ASSERT_TRUE(overDrawCanvas->GetGPUContext() == gpuContext);
1060 }
1061
1062 /**
1063 * @tc.name: RecordStateTest
1064 * @tc.desc: Test Inherite State
1065 * @tc.type: FUNC
1066 * @tc.require: IC8TIV
1067 */
1068 HWTEST_F(CanvasTest, RecordStateTest, TestSize.Level1)
1069 {
1070 auto canvas = std::make_unique<Canvas>();
1071 ASSERT_TRUE(canvas != nullptr);
1072 canvas->RecordState(canvas.get());
1073 }
1074
1075 /**
1076 * @tc.name: SetParallelRenderTest
1077 * @tc.desc: Test Set Parallel
1078 * @tc.type: FUNC
1079 * @tc.require: IC8TIV
1080 */
1081 HWTEST_F(CanvasTest, SetParallelRenderTest, TestSize.Level1)
1082 {
1083 auto canvas = std::make_unique<Canvas>();
1084 ASSERT_TRUE(canvas != nullptr);
1085 canvas->SetParallelRender(true);
1086 }
1087 } // namespace Drawing
1088 } // namespace Rosen
1089 } // namespace OHOS
1090