• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_iterator.h"
19 #include "skia_adapter/skia_path_iterator.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaPathIteratorTest : 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 SkiaPathIteratorTest::SetUpTestCase() {}
TearDownTestCase()36 void SkiaPathIteratorTest::TearDownTestCase() {}
SetUp()37 void SkiaPathIteratorTest::SetUp() {}
TearDown()38 void SkiaPathIteratorTest::TearDown() {}
39 
40 /**
41  * @tc.name: SkiaPathIterNext001
42  * @tc.desc: Test Next
43  * @tc.type: FUNC
44  * @tc.require: ICAWXU
45  */
46 HWTEST_F(SkiaPathIteratorTest, SkiaPathIterNext001, TestSize.Level1)
47 {
48     Path path;
49     path.MoveTo(0, 0);
50     path.LineTo(10, 10); // 10: x, y
51     SkiaPathIter skiaPathIter(path, false);
52     Point points[4] = {}; // 4 is the max points count
53     PathVerb verb = skiaPathIter.Next(points);
54     EXPECT_EQ(verb, PathVerb::MOVE);
55     verb = skiaPathIter.Next(points);
56     EXPECT_EQ(verb, PathVerb::LINE);
57     verb = skiaPathIter.Next(points);
58     EXPECT_EQ(verb, PathVerb::DONE);
59     verb = skiaPathIter.Next(nullptr);
60     EXPECT_EQ(verb, PathVerb::DONE);
61 }
62 
63 /**
64  * @tc.name: SkiaPathIteratorNext001
65  * @tc.desc: Test Next
66  * @tc.type: FUNC
67  * @tc.require: ICDWVQ
68  */
69 HWTEST_F(SkiaPathIteratorTest, SkiaPathIteratorNext001, TestSize.Level1)
70 {
71     Path path;
72     path.MoveTo(0, 0);
73     path.LineTo(10, 10); // 10: x, y
74     SkiaPathIterator skiaPathIterator(path);
75     Point points[4] = {}; // 4 is the max points count
76     PathVerb verb = skiaPathIterator.Next(points);
77     EXPECT_EQ(verb, PathVerb::MOVE);
78     verb = skiaPathIterator.Next(points);
79     EXPECT_EQ(verb, PathVerb::LINE);
80     verb = skiaPathIterator.Next(points);
81     EXPECT_EQ(verb, PathVerb::DONE);
82     verb = skiaPathIterator.Next(nullptr);
83     EXPECT_EQ(verb, PathVerb::DONE);
84 }
85 
86 /**
87  * @tc.name: SkiaPathIterConicWeight001
88  * @tc.desc: Test ConicWeight
89  * @tc.type: FUNC
90  * @tc.require: ICAWXU
91  */
92 HWTEST_F(SkiaPathIteratorTest, SkiaPathIterConicWeight001, TestSize.Level1)
93 {
94     Path path;
95     path.MoveTo(0, 0);
96     path.ConicTo(5, 10, 10, 0, 0.5f); // 5, 0 is control, 10, 0 is end, 0.5f is weight
97     SkiaPathIter skiaPathIter(path, false);
98     PathVerb verb;
99     do {
100         Point points[4] = {}; // 4 is the max points count
101         verb = skiaPathIter.Next(points);
102     } while (verb != PathVerb::CONIC && verb != PathVerb::DONE);
103     EXPECT_EQ(verb, PathVerb::CONIC);
104     EXPECT_EQ(skiaPathIter.ConicWeight(), 0.5f); // 0.5f is the weight value
105 }
106 
107 } // namespace Drawing
108 } // namespace Rosen
109 } // namespace OHOS