• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "skia_adapter/skia_shader_effect.h"
19 #include "draw/color.h"
20 #include "effect/shader_effect.h"
21 #include "image/image.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class SkiaShaderEffectTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 };
36 
SetUpTestCase()37 void SkiaShaderEffectTest::SetUpTestCase() {}
TearDownTestCase()38 void SkiaShaderEffectTest::TearDownTestCase() {}
SetUp()39 void SkiaShaderEffectTest::SetUp() {}
TearDown()40 void SkiaShaderEffectTest::TearDown() {}
41 
42 /**
43  * @tc.name: InitWithImage001
44  * @tc.desc:
45  * @tc.type: FUNC
46  * @tc.author:
47  */
48 HWTEST_F(SkiaShaderEffectTest, InitWithImage001, TestSize.Level1)
49 {
50     Image image;
51     Matrix matrix;
52     SamplingOptions samplingOptions;
53     SkiaShaderEffect skiaShaderEffect;
54     skiaShaderEffect.InitWithImage(image, TileMode::MIRROR, TileMode::REPEAT, samplingOptions, matrix);
55 }
56 
57 /**
58  * @tc.name: InitWithPicture001
59  * @tc.desc:
60  * @tc.type: FUNC
61  * @tc.author:
62  */
63 HWTEST_F(SkiaShaderEffectTest, InitWithPicture001, TestSize.Level1)
64 {
65     Picture picture;
66     Matrix matrix;
67     Rect rect;
68     SkiaShaderEffect skiaShaderEffect;
69     skiaShaderEffect.InitWithPicture(picture, TileMode::MIRROR, TileMode::CLAMP, FilterMode::LINEAR, matrix, rect);
70 }
71 
72 /**
73  * @tc.name: InitWithLinearGradient001
74  * @tc.desc:
75  * @tc.type: FUNC
76  * @tc.author:
77  */
78 HWTEST_F(SkiaShaderEffectTest, InitWithLinearGradient001, TestSize.Level1)
79 {
80     Point startPt;
81     Point endPt;
82     ColorQuad colorQuad = 20;
83     std::vector<ColorQuad> color { colorQuad };
84     std::vector<scalar> pos { 30.0f };
85     SkiaShaderEffect skiaShaderEffect;
86     skiaShaderEffect.InitWithLinearGradient(startPt, endPt, color, pos, TileMode::MIRROR);
87 }
88 
89 /**
90  * @tc.name: InitWithRadialGradient001
91  * @tc.desc:
92  * @tc.type: FUNC
93  * @tc.author:
94  */
95 HWTEST_F(SkiaShaderEffectTest, InitWithRadialGradient001, TestSize.Level1)
96 {
97     Point centerPt;
98     scalar radius = 15.0f;
99     ColorQuad colorQuad = 30;
100     std::vector<ColorQuad> color { colorQuad };
101     std::vector<scalar> pos { 16.0f };
102     SkiaShaderEffect skiaShaderEffect;
103     skiaShaderEffect.InitWithRadialGradient(centerPt, radius, color, pos, TileMode::REPEAT);
104 }
105 
106 /**
107  * @tc.name: InitWithTwoPointConical001
108  * @tc.desc:
109  * @tc.type: FUNC
110  * @tc.author:
111  */
112 HWTEST_F(SkiaShaderEffectTest, InitWithTwoPointConical001, TestSize.Level1)
113 {
114     Point startPt;
115     scalar startRadius = 10.0f;
116     Point endPt;
117     scalar endRadius = 25.0f;
118     ColorQuad colorQuad = 15;
119     std::vector<ColorQuad> color { colorQuad };
120     std::vector<scalar> pos { 30.0f };
121     SkiaShaderEffect skiaShaderEffect;
122     skiaShaderEffect.InitWithTwoPointConical(startPt, startRadius, endPt, endRadius, color, pos, TileMode::CLAMP);
123 }
124 
125 /**
126  * @tc.name: InitWithSweepGradient001
127  * @tc.desc:
128  * @tc.type: FUNC
129  * @tc.author:
130  */
131 HWTEST_F(SkiaShaderEffectTest, InitWithSweepGradient001, TestSize.Level1)
132 {
133     Point centerPt;
134     ColorQuad colorQuad = 10;
135     std::vector<ColorQuad> color { colorQuad };
136     std::vector<scalar> pos { 30.0f };
137     scalar startAngle = 45.0f;
138     scalar endAngle = 60.0f;
139     SkiaShaderEffect skiaShaderEffect;
140     skiaShaderEffect.InitWithSweepGradient(centerPt, color, pos, TileMode::MIRROR, startAngle, endAngle);
141 }
142 
143 } // namespace Drawing
144 } // namespace Rosen
145 } // namespace OHOS