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 #ifdef ACE_ENABLE_GPU
109 /**
110 * @tc.name: CanvasGetGPUContextTest001
111 * @tc.desc: Test for geting gpu context.
112 * @tc.type: FUNC
113 * @tc.require: I782P9
114 */
115 HWTEST_F(CanvasTest, CanvasGetGPUContextTest001, TestSize.Level1)
116 {
117 auto canvas = std::make_unique<Canvas>();
118 ASSERT_TRUE(canvas != nullptr);
119 auto gpuContetxt = canvas->GetGPUContext();
120 EXPECT_TRUE(gpuContetxt == nullptr);
121 }
122 #endif
123
124 /**
125 * @tc.name: CanvasGetWidthTest001
126 * @tc.desc: Test for geting width of Canvas.
127 * @tc.type: FUNC
128 * @tc.require: I719NQ
129 */
130 HWTEST_F(CanvasTest, CanvasGetWidthTest001, TestSize.Level1)
131 {
132 auto canvas = std::make_unique<Canvas>();
133 ASSERT_TRUE(canvas != nullptr);
134 auto rect = canvas->GetWidth();
135 EXPECT_EQ(rect, 0);
136 }
137
138 /**
139 * @tc.name: CanvasGetHeightTest001
140 * @tc.desc: Test for geting height of Canvas.
141 * @tc.type: FUNC
142 * @tc.require: I719NQ
143 */
144 HWTEST_F(CanvasTest, CanvasGetHeightTest001, TestSize.Level1)
145 {
146 auto canvas = std::make_unique<Canvas>();
147 ASSERT_TRUE(canvas != nullptr);
148 auto rect = canvas->GetHeight();
149 EXPECT_EQ(rect, 0);
150 }
151
152 /**
153 * @tc.name: CanvasDrawPointTest001
154 * @tc.desc: Test for DrawPoint function.
155 * @tc.type: FUNC
156 * @tc.require: I719NQ
157 */
158 HWTEST_F(CanvasTest, CanvasDrawPointTest001, TestSize.Level1)
159 {
160 auto canvas = std::make_unique<Canvas>();
161 ASSERT_TRUE(canvas != nullptr);
162 Point point(10.0f, 20.0f);
163 canvas->DrawPoint(point);
164 }
165
166 /**
167 * @tc.name: CanvasDrawLineTest001
168 * @tc.desc: Test for DrawLine function.
169 * @tc.type: FUNC
170 * @tc.require: I719NQ
171 */
172 HWTEST_F(CanvasTest, CanvasDrawLineTest001, TestSize.Level1)
173 {
174 auto canvas = std::make_unique<Canvas>();
175 ASSERT_TRUE(canvas != nullptr);
176 Point startPoint(10.0f, 20.0f);
177 Point endPoint(30.0f, 20.0f);
178 canvas->DrawLine(startPoint, endPoint);
179 }
180
181 /**
182 * @tc.name: CanvasDrawRectTest001
183 * @tc.desc: Test for DrawRect function.
184 * @tc.type: FUNC
185 * @tc.require: I719NQ
186 */
187 HWTEST_F(CanvasTest, CanvasDrawRectTest001, TestSize.Level1)
188 {
189 auto canvas = std::make_unique<Canvas>();
190 ASSERT_TRUE(canvas != nullptr);
191 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
192 canvas->DrawRect(rect);
193 }
194
195 /**
196 * @tc.name: CanvasDrawRoundRectTest001
197 * @tc.desc: Test for DrawRoundRect function.
198 * @tc.type: FUNC
199 * @tc.require: I719NQ
200 */
201 HWTEST_F(CanvasTest, CanvasDrawRoundRectTest001, 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 RoundRect roundRect(rect, 1.0f, 1.0f);
207 canvas->DrawRoundRect(roundRect);
208 }
209
210 /**
211 * @tc.name: CanvasDrawNestedRoundRectTest001
212 * @tc.desc: Test for DrawNestedRoundRect function.
213 * @tc.type: FUNC
214 * @tc.require: I719NQ
215 */
216 HWTEST_F(CanvasTest, CanvasDrawNestedRoundRectTest001, TestSize.Level1)
217 {
218 auto canvas = std::make_unique<Canvas>();
219 ASSERT_TRUE(canvas != nullptr);
220 Rect rect1(0.0f, 0.0f, 10.0f, 20.0f);
221 RoundRect roundRect1(rect1, 1.0f, 1.0f);
222 Rect rect2(0.0f, 0.0f, 5.0f, 10.0f);
223 RoundRect roundRect2(rect2, 1.0f, 1.0f);
224 canvas->DrawNestedRoundRect(roundRect1, roundRect2);
225 }
226
227 /**
228 * @tc.name: CanvasDrawArcTest001
229 * @tc.desc: Test for DrawArc function.
230 * @tc.type: FUNC
231 * @tc.require: I719NQ
232 */
233 HWTEST_F(CanvasTest, CanvasDrawArcTest001, TestSize.Level1)
234 {
235 auto canvas = std::make_unique<Canvas>();
236 ASSERT_TRUE(canvas != nullptr);
237 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
238 canvas->DrawArc(rect, 0.0f, 90.0f);
239 }
240
241 /**
242 * @tc.name: CanvasDrawPieTest001
243 * @tc.desc: Test for DrawPie function.
244 * @tc.type: FUNC
245 * @tc.require: I719NQ
246 */
247 HWTEST_F(CanvasTest, CanvasDrawPieTest001, 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->DrawPie(rect, 0.0f, 90.0f);
253 }
254
255 /**
256 * @tc.name: CanvasDrawOvalTest001
257 * @tc.desc: Test for DrawOval function.
258 * @tc.type: FUNC
259 * @tc.require: I719NQ
260 */
261 HWTEST_F(CanvasTest, CanvasDrawOvalTest001, 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->DrawOval(rect);
267 }
268
269 /**
270 * @tc.name: CanvasDrawCircleTest001
271 * @tc.desc: Test for DrawOval function.
272 * @tc.type: FUNC
273 * @tc.require: I719NQ
274 */
275 HWTEST_F(CanvasTest, CanvasDrawCircleTest001, TestSize.Level1)
276 {
277 auto canvas = std::make_unique<Canvas>();
278 ASSERT_TRUE(canvas != nullptr);
279 Point centerpoint(10.0f, 20.0f);
280 canvas->DrawCircle(centerpoint, 10.0f);
281 }
282
283 /**
284 * @tc.name: CanvasDrawPathTest001
285 * @tc.desc: Test for DrawPath function.
286 * @tc.type: FUNC
287 * @tc.require: I719NQ
288 */
289 HWTEST_F(CanvasTest, CanvasDrawPathTest001, TestSize.Level1)
290 {
291 auto canvas = std::make_unique<Canvas>();
292 ASSERT_TRUE(canvas != nullptr);
293 Path path;
294 canvas->DrawPath(path);
295 }
296
297 /**
298 * @tc.name: CanvasDrawBackgroundTest001
299 * @tc.desc: Test for DrawBackground function.
300 * @tc.type: FUNC
301 * @tc.require: I719NQ
302 */
303 HWTEST_F(CanvasTest, CanvasDrawBackgroundTest001, TestSize.Level1)
304 {
305 auto canvas = std::make_unique<Canvas>();
306 ASSERT_TRUE(canvas != nullptr);
307 Brush brush(Color::COLOR_RED);
308 canvas->DrawBackground(brush);
309 }
310
311 /**
312 * @tc.name: CanvasDrawShadowTest001
313 * @tc.desc: Test for DrawShadow function.
314 * @tc.type: FUNC
315 * @tc.require: I719NQ
316 */
317 HWTEST_F(CanvasTest, CanvasDrawShadowTest001, TestSize.Level1)
318 {
319 auto canvas = std::make_unique<Canvas>();
320 ASSERT_TRUE(canvas != nullptr);
321 Path path;
322 Point3 planeParams(1.0f, 0.0f, 0.0f);
323 Point3 devLightPos(1.0f, 1.0f, 1.0f);
324 canvas->DrawShadow(path, planeParams, devLightPos, 1.0f, Color::COLOR_BLACK, Color::COLOR_BLUE, ShadowFlags::NONE);
325 }
326
327 /**
328 * @tc.name: CanvasDrawRegionTest001
329 * @tc.desc: Test for drawing Region on the Canvas.
330 * @tc.type: FUNC
331 * @tc.require: I719R9
332 */
333 HWTEST_F(CanvasTest, CanvasDrawRegionTest001, TestSize.Level1)
334 {
335 auto canvas = std::make_unique<Canvas>();
336 ASSERT_TRUE(canvas != nullptr);
337 Region region;
338 canvas->DrawRegion(region);
339 }
340
341 /**
342 * @tc.name: CanvasDrawBitmapTest001
343 * @tc.desc: Test for drawing Bitmap on the Canvas.
344 * @tc.type: FUNC
345 * @tc.require: I719R9
346 */
347 HWTEST_F(CanvasTest, CanvasDrawBitmapTest001, TestSize.Level1)
348 {
349 auto canvas = std::make_unique<Canvas>();
350 ASSERT_TRUE(canvas != nullptr);
351 Bitmap bitmap;
352 canvas->DrawBitmap(bitmap, 10.0f, 10.0f);
353 }
354
355 /**
356 * @tc.name: CanvasDrawImageTest001
357 * @tc.desc: Test for drawing image on the Canvas.
358 * @tc.type: FUNC
359 * @tc.require: I719R9
360 */
361 HWTEST_F(CanvasTest, CanvasDrawImageTest001, TestSize.Level1)
362 {
363 auto canvas = std::make_unique<Canvas>();
364 ASSERT_TRUE(canvas != nullptr);
365 Image image;
366 SamplingOptions samplingOptions;
367 canvas->DrawImage(image, 10.0f, 10.0f, samplingOptions);
368 }
369
370 /**
371 * @tc.name: CanvasDrawImageRectTest001
372 * @tc.desc: Test for DrawImageRect function.
373 * @tc.type: FUNC
374 * @tc.require: I719R9
375 */
376 HWTEST_F(CanvasTest, CanvasDrawImageRectTest001, TestSize.Level1)
377 {
378 auto canvas = std::make_unique<Canvas>();
379 ASSERT_TRUE(canvas != nullptr);
380 Image image;
381 Rect srcRect(0.0f, 0.0f, 10.0f, 20.0f);
382 Rect dstRect(0.0f, 0.0f, 10.0f, 20.0f);
383 SamplingOptions samplingOptions;
384 canvas->DrawImageRect(image, srcRect, dstRect, samplingOptions);
385 }
386
387 /**
388 * @tc.name: CanvasDrawImageRectTest002
389 * @tc.desc: Test for DrawImageRect function.
390 * @tc.type: FUNC
391 * @tc.require: I719R9
392 */
393 HWTEST_F(CanvasTest, CanvasDrawImageRectTest002, TestSize.Level1)
394 {
395 auto canvas = std::make_unique<Canvas>();
396 ASSERT_TRUE(canvas != nullptr);
397 Image image;
398 Rect dstRect(0.0f, 0.0f, 10.0f, 20.0f);
399 SamplingOptions samplingOptions;
400 canvas->DrawImageRect(image, dstRect, samplingOptions);
401 }
402
403 /**
404 * @tc.name: CanvasDrawPictureTest001
405 * @tc.desc: Test for DrawPicture function.
406 * @tc.type: FUNC
407 * @tc.require: I719R9
408 */
409 HWTEST_F(CanvasTest, CanvasDrawPictureTest001, TestSize.Level1)
410 {
411 auto canvas = std::make_unique<Canvas>();
412 ASSERT_TRUE(canvas != nullptr);
413 Picture pic;
414 canvas->DrawPicture(pic);
415 }
416
417 /**
418 * @tc.name: CanvasClipRectTest001
419 * @tc.desc: Test replacing the clipping area with the intersection or difference between clipping area and Rect.
420 * @tc.type: FUNC
421 * @tc.require: I719R9
422 */
423 HWTEST_F(CanvasTest, CanvasClipRectTest001, TestSize.Level1)
424 {
425 auto canvas = std::make_unique<Canvas>();
426 ASSERT_TRUE(canvas != nullptr);
427 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
428 canvas->ClipRect(rect, ClipOp::DIFFERENCE, true);
429 }
430
431 /**
432 * @tc.name: CanvasClipRoundRectTest001
433 * @tc.desc: Test replacing the clipping area with the intersection or difference of clipping area and Rect.
434 * @tc.type: FUNC
435 * @tc.require: I719R9
436 */
437 HWTEST_F(CanvasTest, CanvasClipRoundRectTest001, TestSize.Level1)
438 {
439 auto canvas = std::make_unique<Canvas>();
440 ASSERT_TRUE(canvas != nullptr);
441 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
442 RoundRect roundRect(rect, 1.0f, 1.0f);
443 canvas->ClipRoundRect(roundRect, ClipOp::DIFFERENCE, true);
444 }
445
446 /**
447 * @tc.name: CanvasClipPathTest001
448 * @tc.desc: Test replacing the clipping area with the intersection or difference between clipping area and path.
449 * @tc.type: FUNC
450 * @tc.require: I719R9
451 */
452 HWTEST_F(CanvasTest, CanvasClipPathTest001, TestSize.Level1)
453 {
454 auto canvas = std::make_unique<Canvas>();
455 ASSERT_TRUE(canvas != nullptr);
456 Path path;
457 canvas->ClipPath(path, ClipOp::DIFFERENCE, true);
458 }
459
460 /**
461 * @tc.name: CanvasSetMatrixTest001
462 * @tc.desc: Test for SetMatrix function.
463 * @tc.type: FUNC
464 * @tc.require: I719R9
465 */
466 HWTEST_F(CanvasTest, CanvasSetMatrixTest001, TestSize.Level1)
467 {
468 auto canvas = std::make_unique<Canvas>();
469 ASSERT_TRUE(canvas != nullptr);
470 Matrix matrix;
471 canvas->SetMatrix(matrix);
472 }
473
474 /**
475 * @tc.name: CanvasResetMatrixTest001
476 * @tc.desc: Test for ResetMatrix function.
477 * @tc.type: FUNC
478 * @tc.require: I719R9
479 */
480 HWTEST_F(CanvasTest, CanvasResetMatrixTest001, TestSize.Level1)
481 {
482 auto canvas = std::make_unique<Canvas>();
483 ASSERT_TRUE(canvas != nullptr);
484 Matrix matrix;
485 canvas->SetMatrix(matrix);
486 canvas->ResetMatrix();
487 }
488
489 /**
490 * @tc.name: CanvasConcatMatrixTest001
491 * @tc.desc: Test for ConcatMatrix function.
492 * @tc.type: FUNC
493 * @tc.require: I719R9
494 */
495 HWTEST_F(CanvasTest, CanvasConcatMatrixTest001, TestSize.Level1)
496 {
497 auto canvas = std::make_unique<Canvas>();
498 ASSERT_TRUE(canvas != nullptr);
499 Matrix matrix;
500 canvas->ConcatMatrix(matrix);
501 }
502
503 /**
504 * @tc.name: CanvasTranslateTest001
505 * @tc.desc: Test for Translate function.
506 * @tc.type: FUNC
507 * @tc.require: I719R9
508 */
509 HWTEST_F(CanvasTest, CanvasTranslateTest001, TestSize.Level1)
510 {
511 auto canvas = std::make_unique<Canvas>();
512 ASSERT_TRUE(canvas != nullptr);
513 canvas->Translate(1.0f, 1.0f);
514 }
515
516 /**
517 * @tc.name: CanvasScaleTest001
518 * @tc.desc: Test for Scale function.
519 * @tc.type: FUNC
520 * @tc.require: I719R9
521 */
522 HWTEST_F(CanvasTest, CanvasScaleTest001, TestSize.Level1)
523 {
524 auto canvas = std::make_unique<Canvas>();
525 ASSERT_TRUE(canvas != nullptr);
526 canvas->Scale(1.0f, 1.0f);
527 }
528
529 /**
530 * @tc.name: CanvasRotateTest001
531 * @tc.desc: Test for Rotating Matrix by degrees.
532 * @tc.type: FUNC
533 * @tc.require: I719R9
534 */
535 HWTEST_F(CanvasTest, CanvasRotateTest001, TestSize.Level1)
536 {
537 auto canvas = std::make_unique<Canvas>();
538 ASSERT_TRUE(canvas != nullptr);
539 canvas->Rotate(60.0f);
540 }
541
542 /**
543 * @tc.name: CanvasRotateTest002
544 * @tc.desc: Test for Rotating Matrix by degrees.
545 * @tc.type: FUNC
546 * @tc.require: I719R9
547 */
548 HWTEST_F(CanvasTest, CanvasRotateTest002, TestSize.Level1)
549 {
550 auto canvas = std::make_unique<Canvas>();
551 ASSERT_TRUE(canvas != nullptr);
552 canvas->Rotate(60.0f, 10.0f, 10.0f);
553 }
554
555 /**
556 * @tc.name: CanvasShearTest001
557 * @tc.desc: Test for Shear function.
558 * @tc.type: FUNC
559 * @tc.require: I719R9
560 */
561 HWTEST_F(CanvasTest, CanvasShearTest001, TestSize.Level1)
562 {
563 auto canvas = std::make_unique<Canvas>();
564 ASSERT_TRUE(canvas != nullptr);
565 canvas->Shear(10.0f, 10.0f);
566 }
567
568 /**
569 * @tc.name: CanvasFlushTest001
570 * @tc.desc: Test for Flush function.
571 * @tc.type: FUNC
572 * @tc.require: I719R9
573 */
574 HWTEST_F(CanvasTest, CanvasFlushTest001, TestSize.Level1)
575 {
576 auto canvas = std::make_unique<Canvas>();
577 ASSERT_TRUE(canvas != nullptr);
578 canvas->Flush();
579 }
580
581 /**
582 * @tc.name: CanvasClearTest001
583 * @tc.desc: Test for Clear function.
584 * @tc.type: FUNC
585 * @tc.require: I719R9
586 */
587 HWTEST_F(CanvasTest, CanvasClearTest001, TestSize.Level1)
588 {
589 auto canvas = std::make_unique<Canvas>();
590 ASSERT_TRUE(canvas != nullptr);
591 canvas->Clear(Color::COLOR_BLUE);
592 }
593
594 /**
595 * @tc.name: CanvasSaveTest001
596 * @tc.desc: Test for Save function.
597 * @tc.type: FUNC
598 * @tc.require: I719R9
599 */
600 HWTEST_F(CanvasTest, CanvasSaveTest001, TestSize.Level1)
601 {
602 auto canvas = std::make_unique<Canvas>();
603 ASSERT_TRUE(canvas != nullptr);
604 canvas->Save();
605 }
606
607 /**
608 * @tc.name: CanvasSaveLayerTest001
609 * @tc.desc: Test for saving Matrix and clipping area, and allocates Surface for subsequent drawing.
610 * @tc.type: FUNC
611 * @tc.require: I719U5
612 */
613 HWTEST_F(CanvasTest, CanvasSaveLayerTest001, TestSize.Level1)
614 {
615 auto canvas = std::make_unique<Canvas>();
616 ASSERT_TRUE(canvas != nullptr);
617 SaveLayerOps saveLayerOps;
618 canvas->SaveLayer(saveLayerOps);
619 }
620
621 /**
622 * @tc.name: CanvasSaveLayerTest002
623 * @tc.desc: Test for saving Matrix and clipping area, and allocates Surface for subsequent drawing.
624 * @tc.type: FUNC
625 * @tc.require: I719U5
626 */
627 HWTEST_F(CanvasTest, CanvasSaveLayerTest002, TestSize.Level1)
628 {
629 auto canvas = std::make_unique<Canvas>();
630 ASSERT_TRUE(canvas != nullptr);
631 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
632 Brush brush;
633 uint32_t saveLayerFlags = 0;
634 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
635 canvas->SaveLayer(saveLayerRec);
636 }
637
638 /**
639 * @tc.name: CanvasRestoreTest001
640 * @tc.desc: Test for Restore function.
641 * @tc.type: FUNC
642 * @tc.require: I719U5
643 */
644 HWTEST_F(CanvasTest, CanvasRestoreTest001, TestSize.Level1)
645 {
646 auto canvas = std::make_unique<Canvas>();
647 ASSERT_TRUE(canvas != nullptr);
648 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
649 Brush brush;
650 uint32_t saveLayerFlags = 0;
651 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
652 canvas->SaveLayer(saveLayerRec);
653 canvas->Restore();
654 }
655
656 /**
657 * @tc.name: CanvasGetSaveCountTest001
658 * @tc.desc: Test for geting the number of saved states.
659 * @tc.type: FUNC
660 * @tc.require: I719U5
661 */
662 HWTEST_F(CanvasTest, CanvasGetSaveCountTest001, TestSize.Level1)
663 {
664 auto canvas = std::make_unique<Canvas>();
665 ASSERT_TRUE(canvas != nullptr);
666 canvas->Save();
667 EXPECT_TRUE(2 == canvas->GetSaveCount());
668 }
669
670 /**
671 * @tc.name: CanvasRestoreToCountTest001
672 * @tc.desc: Test for restoring Canvas Matrix and clip value state to count.
673 * @tc.type: FUNC
674 * @tc.require: I719U5
675 */
676 HWTEST_F(CanvasTest, CanvasRestoreToCountTest001, TestSize.Level1)
677 {
678 auto canvas = std::make_unique<Canvas>();
679 ASSERT_TRUE(canvas != nullptr);
680 canvas->RestoreToCount(2);
681 }
682
683 /**
684 * @tc.name: CanvasAttachAndDetachPenTest001
685 * @tc.desc: Test for AttachPen and DetachPen functions.
686 * @tc.type: FUNC
687 * @tc.require: I719U5
688 */
689 HWTEST_F(CanvasTest, CanvasAttachAndDetachPenTest001, TestSize.Level1)
690 {
691 auto canvas = std::make_unique<Canvas>();
692 ASSERT_TRUE(canvas != nullptr);
693 Pen pen(Color::COLOR_GREEN);
694 canvas->AttachPen(pen);
695 canvas->DetachPen();
696 }
697
698 /**
699 * @tc.name: CanvasAttachAndDetachBrushTest001
700 * @tc.desc: Test for AttachBrush and DetachBrush functions.
701 * @tc.type: FUNC
702 * @tc.require: I719U5
703 */
704 HWTEST_F(CanvasTest, CanvasAttachAndDetachBrushTest001, TestSize.Level1)
705 {
706 auto canvas = std::make_unique<Canvas>();
707 ASSERT_TRUE(canvas != nullptr);
708 Brush brush(Color::COLOR_GREEN);
709 canvas->AttachBrush(brush);
710 canvas->DetachBrush();
711 }
712
713 /**
714 * @tc.name: GetBounds001
715 * @tc.desc: Test for geting the bounds of layer.
716 * @tc.type: FUNC
717 * @tc.require: I719U5
718 */
719 HWTEST_F(CanvasTest, GetBounds001, TestSize.Level1)
720 {
721 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
722 Brush brush;
723 uint32_t saveLayerFlags = 0;
724 ImageFilter imageFilter(ImageFilter::FilterType::BLUR, 10.0f, 10.0f, nullptr);
725 SaveLayerOps saveLayerRec(&rect, &brush, &imageFilter, saveLayerFlags);
726 auto ret = saveLayerRec.GetBounds();
727 EXPECT_EQ(ret->GetLeft(), 0.0f);
728 EXPECT_EQ(ret->GetBottom(), 20.0f);
729 }
730
731 /**
732 * @tc.name: GetBrush001
733 * @tc.desc: Test for geting the brush of layer.
734 * @tc.type: FUNC
735 * @tc.require: I719U5
736 */
737 HWTEST_F(CanvasTest, GetBrush001, TestSize.Level1)
738 {
739 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
740 Brush brush;
741 uint32_t saveLayerFlags = 0;
742 ImageFilter imageFilter(ImageFilter::FilterType::BLUR, 10.0f, 10.0f, nullptr);
743 SaveLayerOps saveLayerRec(&rect, &brush, &imageFilter, saveLayerFlags);
744 auto ret = saveLayerRec.GetBrush();
745 EXPECT_TRUE(ret != nullptr);
746 }
747
748 /**
749 * @tc.name: GetImageFilter001
750 * @tc.desc: Test for geting the image filter of layer.
751 * @tc.type: FUNC
752 * @tc.require: I719U5
753 */
754 HWTEST_F(CanvasTest, GetImageFilter001, TestSize.Level1)
755 {
756 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
757 Brush brush;
758 uint32_t saveLayerFlags = 0;
759 ImageFilter imageFilter(ImageFilter::FilterType::BLUR, 10.0f, 10.0f, nullptr);
760 SaveLayerOps saveLayerRec(&rect, &brush, &imageFilter, saveLayerFlags);
761 auto ret = saveLayerRec.GetImageFilter();
762 EXPECT_TRUE(ret != nullptr);
763 }
764
765 /**
766 * @tc.name: GetSaveLayerFlags001
767 * @tc.desc: Test for geting the options to modify layer.
768 * @tc.type: FUNC
769 * @tc.require: I719U5
770 */
771 HWTEST_F(CanvasTest, GetSaveLayerFlags001, TestSize.Level1)
772 {
773 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
774 Brush brush;
775 uint32_t saveLayerFlags = 0;
776 ImageFilter imageFilter(ImageFilter::FilterType::BLUR, 10.0f, 10.0f, nullptr);
777 SaveLayerOps saveLayerRec(&rect, &brush, &imageFilter, saveLayerFlags);
778 auto ret = saveLayerRec.GetSaveLayerFlags();
779 EXPECT_EQ(ret, 0);
780 }
781
782 /**
783 * @tc.name: AutoCanvasRestoreTest001
784 * @tc.desc: Test for Creating AutoCanvasRestore;
785 * @tc.type: FUNC
786 * @tc.require: I719U5
787 */
788 HWTEST_F(CanvasTest, AutoCanvasRestoreTest001, TestSize.Level1)
789 {
790 Canvas canvas;
791 bool doSave = true;
792 auto autoCanvasRestore = std::make_unique<AutoCanvasRestore>(canvas, doSave);
793 ASSERT_TRUE(autoCanvasRestore != nullptr);
794 }
795 } // namespace Drawing
796 } // namespace Rosen
797 } // namespace OHOS
798