• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <cstddef>
17 #include "gtest/gtest.h"
18 #include "draw/path.h"
19 #include "skia_adapter/skia_path.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaPathTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33 };
34 
SetUpTestCase()35 void SkiaPathTest::SetUpTestCase() {}
TearDownTestCase()36 void SkiaPathTest::TearDownTestCase() {}
SetUp()37 void SkiaPathTest::SetUp() {}
TearDown()38 void SkiaPathTest::TearDown() {}
39 
40 /**
41  * @tc.name: SkiaPath001
42  * @tc.desc: Test SkiaPath's funstions
43  * @tc.type: FUNC
44  * @tc.require: I8VQSW
45  */
46 HWTEST_F(SkiaPathTest, SkiaPath001, TestSize.Level1)
47 {
48     SkiaPath skiaPath;
49     skiaPath.MoveTo(0, 0);
50     skiaPath.LineTo(100, 100); // 100: x, y
51     skiaPath.LineTo(100, 0); // 100: x
52     skiaPath.Close();
53     skiaPath.Reset();
54     skiaPath.ArcTo(0, 0, 100, 100, 90, 90); // 100: pt2X and pt2Y, 90: startAngle and sweepAngle
55     skiaPath.ArcTo(0, 0, 90, PathDirection::CW_DIRECTION, 90, 90); // 90: angle, 90: endX and endY
56     skiaPath.ArcTo(0, 0, 90, 90, 10); // 90: x2 and y2, 10: radius
57     skiaPath.CubicTo(0, 0, 100, 100, 100, 200); // 100: angle, direction and endX, 200: endY
58     skiaPath.QuadTo(0, 0, 100, 100); // 100: endX and endY
59     skiaPath.RMoveTo(100, 100); // 100: dx and dy
60     skiaPath.RLineTo(200, 200); // 200: dx and dy
61     skiaPath.RCubicTo(0, 0, 100, 100, 100, 200); // 200: dx and dy
62     skiaPath.RQuadTo(0, 0, 100, 100); // 100: dx2 and dy2
63     skiaPath.AddOval(0, 0, 100, 100, PathDirection::CW_DIRECTION); // 100: right, bottom
64     skiaPath.AddArc(0, 0, 100, 100, 90, 90); // 100: right, bottom, 90: startAngle, sweepAngle
65     skiaPath.AddCircle(0, 0, 100, PathDirection::CW_DIRECTION); // 100: radius
66     skiaPath.AddRoundRect(0, 0,
67         100, 100, 100, 100, PathDirection::CW_DIRECTION); // 100: right, bottom, xRadius, yRadius
68     Path path;
69     skiaPath.AddPath(path, 200, 200); // 200: dx and dy
70     skiaPath.AddPath(path);
71     skiaPath.ReverseAddPath(path);
72     Matrix matrix;
73     skiaPath.AddPathWithMatrix(path, matrix);
74     skiaPath.SetFillStyle(PathFillType::WINDING);
75     Path path2;
76     skiaPath.Interpolate(path, 2, path2); // 2: weight
77     skiaPath.Transform(matrix);
78     std::string svgString = skiaPath.ConvertToSVGString();
79     SkiaPath skiaPath2;
80     skiaPath2.InitWithSVGString(svgString);
81     EXPECT_TRUE(skiaPath2.GetLength(true) >= 0);
82     EXPECT_TRUE(skiaPath2.Contains(0, 0));
83     EXPECT_TRUE(!skiaPath2.Deserialize(nullptr));
84 }
85 } // namespace Drawing
86 } // namespace Rosen
87 } // namespace OHOS