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: CanvasClipRectTest001
484 * @tc.desc: Test replacing the clipping area with the intersection or difference between clipping area and Rect.
485 * @tc.type: FUNC
486 * @tc.require: I719R9
487 */
488 HWTEST_F(CanvasTest, CanvasClipRectTest001, TestSize.Level1)
489 {
490 auto canvas = std::make_unique<Canvas>();
491 ASSERT_TRUE(canvas != nullptr);
492 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
493 canvas->ClipRect(rect, ClipOp::DIFFERENCE, true);
494 }
495
496 /**
497 * @tc.name: CanvasClipRoundRectTest001
498 * @tc.desc: Test replacing the clipping area with the intersection or difference of clipping area and Rect.
499 * @tc.type: FUNC
500 * @tc.require: I719R9
501 */
502 HWTEST_F(CanvasTest, CanvasClipRoundRectTest001, TestSize.Level1)
503 {
504 auto canvas = std::make_unique<Canvas>();
505 ASSERT_TRUE(canvas != nullptr);
506 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
507 RoundRect roundRect(rect, 1.0f, 1.0f);
508 canvas->ClipRoundRect(roundRect, ClipOp::DIFFERENCE, true);
509 }
510
511 /**
512 * @tc.name: CanvasClipPathTest001
513 * @tc.desc: Test replacing the clipping area with the intersection or difference between clipping area and path.
514 * @tc.type: FUNC
515 * @tc.require: I719R9
516 */
517 HWTEST_F(CanvasTest, CanvasClipPathTest001, TestSize.Level1)
518 {
519 auto canvas = std::make_unique<Canvas>();
520 ASSERT_TRUE(canvas != nullptr);
521 Path path;
522 canvas->ClipPath(path, ClipOp::DIFFERENCE, true);
523 }
524
525 /**
526 * @tc.name: CanvasSetMatrixTest001
527 * @tc.desc: Test for SetMatrix function.
528 * @tc.type: FUNC
529 * @tc.require: I719R9
530 */
531 HWTEST_F(CanvasTest, CanvasSetMatrixTest001, TestSize.Level1)
532 {
533 auto canvas = std::make_unique<Canvas>();
534 ASSERT_TRUE(canvas != nullptr);
535 Matrix matrix;
536 canvas->SetMatrix(matrix);
537 }
538
539 /**
540 * @tc.name: CanvasResetMatrixTest001
541 * @tc.desc: Test for ResetMatrix function.
542 * @tc.type: FUNC
543 * @tc.require: I719R9
544 */
545 HWTEST_F(CanvasTest, CanvasResetMatrixTest001, TestSize.Level1)
546 {
547 auto canvas = std::make_unique<Canvas>();
548 ASSERT_TRUE(canvas != nullptr);
549 Matrix matrix;
550 canvas->SetMatrix(matrix);
551 canvas->ResetMatrix();
552 }
553
554 /**
555 * @tc.name: CanvasConcatMatrixTest001
556 * @tc.desc: Test for ConcatMatrix function.
557 * @tc.type: FUNC
558 * @tc.require: I719R9
559 */
560 HWTEST_F(CanvasTest, CanvasConcatMatrixTest001, TestSize.Level1)
561 {
562 auto canvas = std::make_unique<Canvas>();
563 ASSERT_TRUE(canvas != nullptr);
564 Matrix matrix;
565 canvas->ConcatMatrix(matrix);
566 }
567
568 /**
569 * @tc.name: CanvasTranslateTest001
570 * @tc.desc: Test for Translate function.
571 * @tc.type: FUNC
572 * @tc.require: I719R9
573 */
574 HWTEST_F(CanvasTest, CanvasTranslateTest001, TestSize.Level1)
575 {
576 auto canvas = std::make_unique<Canvas>();
577 ASSERT_TRUE(canvas != nullptr);
578 canvas->Translate(1.0f, 1.0f);
579 }
580
581 /**
582 * @tc.name: CanvasScaleTest001
583 * @tc.desc: Test for Scale function.
584 * @tc.type: FUNC
585 * @tc.require: I719R9
586 */
587 HWTEST_F(CanvasTest, CanvasScaleTest001, TestSize.Level1)
588 {
589 auto canvas = std::make_unique<Canvas>();
590 ASSERT_TRUE(canvas != nullptr);
591 canvas->Scale(1.0f, 1.0f);
592 }
593
594 /**
595 * @tc.name: CanvasRotateTest001
596 * @tc.desc: Test for Rotating Matrix by degrees.
597 * @tc.type: FUNC
598 * @tc.require: I719R9
599 */
600 HWTEST_F(CanvasTest, CanvasRotateTest001, TestSize.Level1)
601 {
602 auto canvas = std::make_unique<Canvas>();
603 ASSERT_TRUE(canvas != nullptr);
604 canvas->Rotate(60.0f);
605 }
606
607 /**
608 * @tc.name: CanvasRotateTest002
609 * @tc.desc: Test for Rotating Matrix by degrees.
610 * @tc.type: FUNC
611 * @tc.require: I719R9
612 */
613 HWTEST_F(CanvasTest, CanvasRotateTest002, TestSize.Level1)
614 {
615 auto canvas = std::make_unique<Canvas>();
616 ASSERT_TRUE(canvas != nullptr);
617 canvas->Rotate(60.0f, 10.0f, 10.0f);
618 }
619
620 /**
621 * @tc.name: CanvasShearTest001
622 * @tc.desc: Test for Shear function.
623 * @tc.type: FUNC
624 * @tc.require: I719R9
625 */
626 HWTEST_F(CanvasTest, CanvasShearTest001, TestSize.Level1)
627 {
628 auto canvas = std::make_unique<Canvas>();
629 ASSERT_TRUE(canvas != nullptr);
630 canvas->Shear(10.0f, 10.0f);
631 }
632
633 /**
634 * @tc.name: CanvasFlushTest001
635 * @tc.desc: Test for Flush function.
636 * @tc.type: FUNC
637 * @tc.require: I719R9
638 */
639 HWTEST_F(CanvasTest, CanvasFlushTest001, TestSize.Level1)
640 {
641 auto canvas = std::make_unique<Canvas>();
642 ASSERT_TRUE(canvas != nullptr);
643 canvas->Flush();
644 }
645
646 /**
647 * @tc.name: CanvasClearTest001
648 * @tc.desc: Test for Clear function.
649 * @tc.type: FUNC
650 * @tc.require: I719R9
651 */
652 HWTEST_F(CanvasTest, CanvasClearTest001, TestSize.Level1)
653 {
654 auto canvas = std::make_unique<Canvas>();
655 ASSERT_TRUE(canvas != nullptr);
656 canvas->Clear(Color::COLOR_BLUE);
657 }
658
659 /**
660 * @tc.name: CanvasSaveTest001
661 * @tc.desc: Test for Save function.
662 * @tc.type: FUNC
663 * @tc.require: I719R9
664 */
665 HWTEST_F(CanvasTest, CanvasSaveTest001, TestSize.Level1)
666 {
667 auto canvas = std::make_unique<Canvas>();
668 ASSERT_TRUE(canvas != nullptr);
669 canvas->Save();
670 }
671
672 /**
673 * @tc.name: CanvasSaveLayerTest001
674 * @tc.desc: Test for saving Matrix and clipping area, and allocates Surface for subsequent drawing.
675 * @tc.type: FUNC
676 * @tc.require: I719U5
677 */
678 HWTEST_F(CanvasTest, CanvasSaveLayerTest001, TestSize.Level1)
679 {
680 auto canvas = std::make_unique<Canvas>();
681 ASSERT_TRUE(canvas != nullptr);
682 SaveLayerOps saveLayerOps;
683 canvas->SaveLayer(saveLayerOps);
684 }
685
686 /**
687 * @tc.name: CanvasSaveLayerTest002
688 * @tc.desc: Test for saving Matrix and clipping area, and allocates Surface for subsequent drawing.
689 * @tc.type: FUNC
690 * @tc.require: I719U5
691 */
692 HWTEST_F(CanvasTest, CanvasSaveLayerTest002, TestSize.Level1)
693 {
694 auto canvas = std::make_unique<Canvas>();
695 ASSERT_TRUE(canvas != nullptr);
696 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
697 Brush brush;
698 uint32_t saveLayerFlags = 0;
699 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
700 canvas->SaveLayer(saveLayerRec);
701 }
702
703 /**
704 * @tc.name: CanvasRestoreTest001
705 * @tc.desc: Test for Restore function.
706 * @tc.type: FUNC
707 * @tc.require: I719U5
708 */
709 HWTEST_F(CanvasTest, CanvasRestoreTest001, TestSize.Level1)
710 {
711 auto canvas = std::make_unique<Canvas>();
712 ASSERT_TRUE(canvas != nullptr);
713 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
714 Brush brush;
715 uint32_t saveLayerFlags = 0;
716 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
717 canvas->SaveLayer(saveLayerRec);
718 canvas->Restore();
719 }
720
721 /**
722 * @tc.name: CanvasGetSaveCountTest001
723 * @tc.desc: Test for geting the number of saved states.
724 * @tc.type: FUNC
725 * @tc.require: I719U5
726 */
727 HWTEST_F(CanvasTest, CanvasGetSaveCountTest001, TestSize.Level1)
728 {
729 auto canvas = std::make_unique<Canvas>();
730 ASSERT_TRUE(canvas != nullptr);
731 canvas->Save();
732 EXPECT_TRUE(2 == canvas->GetSaveCount());
733 }
734
735 /**
736 * @tc.name: CanvasRestoreToCountTest001
737 * @tc.desc: Test for restoring Canvas Matrix and clip value state to count.
738 * @tc.type: FUNC
739 * @tc.require: I719U5
740 */
741 HWTEST_F(CanvasTest, CanvasRestoreToCountTest001, TestSize.Level1)
742 {
743 auto canvas = std::make_unique<Canvas>();
744 ASSERT_TRUE(canvas != nullptr);
745 canvas->RestoreToCount(2);
746 }
747
748 /**
749 * @tc.name: CanvasAttachAndDetachPenTest001
750 * @tc.desc: Test for AttachPen and DetachPen functions.
751 * @tc.type: FUNC
752 * @tc.require: I719U5
753 */
754 HWTEST_F(CanvasTest, CanvasAttachAndDetachPenTest001, TestSize.Level1)
755 {
756 auto canvas = std::make_unique<Canvas>();
757 ASSERT_TRUE(canvas != nullptr);
758 Pen pen(Color::COLOR_GREEN);
759 canvas->AttachPen(pen);
760 canvas->DetachPen();
761 }
762
763 /**
764 * @tc.name: CanvasAttachAndDetachBrushTest001
765 * @tc.desc: Test for AttachBrush and DetachBrush functions.
766 * @tc.type: FUNC
767 * @tc.require: I719U5
768 */
769 HWTEST_F(CanvasTest, CanvasAttachAndDetachBrushTest001, TestSize.Level1)
770 {
771 auto canvas = std::make_unique<Canvas>();
772 ASSERT_TRUE(canvas != nullptr);
773 Brush brush(Color::COLOR_GREEN);
774 canvas->AttachBrush(brush);
775 canvas->DetachBrush();
776 }
777
778 /**
779 * @tc.name: SetOffscreenTest001
780 * @tc.desc: Test for SetOffscreen functions.
781 * @tc.type: FUNC
782 * @tc.require:
783 */
784 HWTEST_F(CanvasTest, SetOffscreenTest001, TestSize.Level1)
785 {
786 auto canvas = std::make_unique<Canvas>();
787 ASSERT_TRUE(canvas != nullptr);
788 canvas->SetOffscreen(true);
789 bool state = canvas->GetOffscreen();
790 ASSERT_TRUE(state);
791 }
792
793 /**
794 * @tc.name: SetUICaptureTest001
795 * @tc.desc: Test for SetUICapture functions.
796 * @tc.type: FUNC
797 * @tc.require:
798 */
799 HWTEST_F(CanvasTest, SetUICaptureTest001, TestSize.Level1)
800 {
801 auto canvas = std::make_unique<Canvas>();
802 ASSERT_TRUE(canvas != nullptr);
803 canvas->SetUICapture(true);
804 bool state = canvas->GetUICapture();
805 ASSERT_TRUE(state);
806 }
807
808 /**
809 * @tc.name: GetRecordingStateTest001
810 * @tc.desc: Test for GetRecordingState functions.
811 * @tc.type: FUNC
812 * @tc.require: I719U5
813 */
814 HWTEST_F(CanvasTest, GetRecordingStateTest001, TestSize.Level1)
815 {
816 auto canvas = std::make_unique<Canvas>();
817 ASSERT_TRUE(canvas != nullptr);
818 canvas->SetRecordingState(true);
819 bool state = canvas->GetRecordingState();
820 ASSERT_TRUE(state);
821 }
822
823 /**
824 * @tc.name: SetRecordingStateTest001
825 * @tc.desc: Test for SetRecordingState functions.
826 * @tc.type: FUNC
827 * @tc.require: I719U5
828 */
829 HWTEST_F(CanvasTest, SetRecordingStateTest001, TestSize.Level1)
830 {
831 auto canvas = std::make_unique<Canvas>();
832 ASSERT_TRUE(canvas != nullptr);
833 canvas->SetRecordingState(false);
834 bool state = canvas->GetRecordingState();
835 ASSERT_TRUE(!state);
836 }
837
838 /**
839 * @tc.name: GetDrawingTypeTest001
840 * @tc.desc: Test for GetDrawingType functions.
841 * @tc.type: FUNC
842 * @tc.require: I719U5
843 */
844 HWTEST_F(CanvasTest, GetDrawingTypeTest001, TestSize.Level1)
845 {
846 std::shared_ptr<Drawing::OverDrawCanvas> overDrawCanvas;
847 DrawingType type = overDrawCanvas->GetDrawingType();
848 ASSERT_TRUE(type == DrawingType::OVER_DRAW);
849 }
850
851 /**
852 * @tc.name: GetDrawingTypeTest002
853 * @tc.desc: Test for GetDrawingType NoDrawCanvas functions.
854 * @tc.type: FUNC
855 * @tc.require: I719U5
856 */
857 HWTEST_F(CanvasTest, GetDrawingTypeTest002, TestSize.Level1)
858 {
859 std::shared_ptr<Drawing::NoDrawCanvas> noDrawCanvas;
860 DrawingType type = noDrawCanvas->GetDrawingType();
861 ASSERT_TRUE(type == DrawingType::NO_DRAW);
862 }
863
864 /**
865 * @tc.name: GetBounds001
866 * @tc.desc: Test for geting the bounds of layer.
867 * @tc.type: FUNC
868 * @tc.require: I719U5
869 */
870 HWTEST_F(CanvasTest, GetBounds001, TestSize.Level1)
871 {
872 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
873 Brush brush;
874 uint32_t saveLayerFlags = 0;
875 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
876 auto ret = saveLayerRec.GetBounds();
877 EXPECT_EQ(ret->GetLeft(), 0.0f);
878 EXPECT_EQ(ret->GetBottom(), 20.0f);
879 }
880
881 /**
882 * @tc.name: GetBrush001
883 * @tc.desc: Test for geting the brush of layer.
884 * @tc.type: FUNC
885 * @tc.require: I719U5
886 */
887 HWTEST_F(CanvasTest, GetBrush001, TestSize.Level1)
888 {
889 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
890 Brush brush;
891 uint32_t saveLayerFlags = 0;
892 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
893 auto ret = saveLayerRec.GetBrush();
894 EXPECT_TRUE(ret != nullptr);
895 }
896
897 /**
898 * @tc.name: GetSaveLayerFlags001
899 * @tc.desc: Test for geting the options to modify layer.
900 * @tc.type: FUNC
901 * @tc.require: I719U5
902 */
903 HWTEST_F(CanvasTest, GetSaveLayerFlags001, TestSize.Level1)
904 {
905 Rect rect(0.0f, 0.0f, 10.0f, 20.0f);
906 Brush brush;
907 uint32_t saveLayerFlags = 0;
908 SaveLayerOps saveLayerRec(&rect, &brush, saveLayerFlags);
909 auto ret = saveLayerRec.GetSaveLayerFlags();
910 EXPECT_EQ(ret, 0);
911 }
912
913 /**
914 * @tc.name: AutoCanvasRestoreTest001
915 * @tc.desc: Test for Creating AutoCanvasRestore;
916 * @tc.type: FUNC
917 * @tc.require: I719U5
918 */
919 HWTEST_F(CanvasTest, AutoCanvasRestoreTest001, TestSize.Level1)
920 {
921 Canvas canvas;
922 bool doSave = true;
923 auto autoCanvasRestore = std::make_unique<AutoCanvasRestore>(canvas, doSave);
924 ASSERT_TRUE(autoCanvasRestore != nullptr);
925 }
926 } // namespace Drawing
927 } // namespace Rosen
928 } // namespace OHOS
929