• 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: InitWithColor001
44  * @tc.desc: Test InitWithColor
45  * @tc.type: FUNC
46  * @tc.require: I91EH1
47  */
48 HWTEST_F(SkiaShaderEffectTest, InitWithColor001, TestSize.Level1)
49 {
50     ColorQuad colorQuad = 0xFF000000;
51     SkiaShaderEffect skiaShaderEffect;
52     skiaShaderEffect.InitWithColor(colorQuad);
53 }
54 
55 /**
56  * @tc.name: InitWithBlend001
57  * @tc.desc: Test InitWithBlend
58  * @tc.type: FUNC
59  * @tc.require: I91EH1
60  */
61 HWTEST_F(SkiaShaderEffectTest, InitWithBlend001, TestSize.Level1)
62 {
63     ShaderEffect shaderEffect1{ShaderEffect::ShaderEffectType::BLEND, 0xFF000000};
64     ShaderEffect shaderEffect2{ShaderEffect::ShaderEffectType::LINEAR_GRADIENT, 0xFF000000};
65     SkiaShaderEffect skiaShaderEffect;
66     skiaShaderEffect.InitWithBlend(shaderEffect1, shaderEffect2, BlendMode::CLEAR);
67 }
68 
69 /**
70  * @tc.name: InitWithImage001
71  * @tc.desc:
72  * @tc.type: FUNC
73  * @tc.author:
74  */
75 HWTEST_F(SkiaShaderEffectTest, InitWithImage001, TestSize.Level1)
76 {
77     Image image;
78     Matrix matrix;
79     SamplingOptions samplingOptions;
80     SkiaShaderEffect skiaShaderEffect;
81     skiaShaderEffect.InitWithImage(image, TileMode::MIRROR, TileMode::REPEAT, samplingOptions, matrix);
82 }
83 
84 /**
85  * @tc.name: InitWithPicture001
86  * @tc.desc:
87  * @tc.type: FUNC
88  * @tc.author:
89  */
90 HWTEST_F(SkiaShaderEffectTest, InitWithPicture001, TestSize.Level1)
91 {
92     Picture picture;
93     Matrix matrix;
94     Rect rect;
95     SkiaShaderEffect skiaShaderEffect;
96     skiaShaderEffect.InitWithPicture(picture, TileMode::MIRROR, TileMode::CLAMP, FilterMode::LINEAR, matrix, rect);
97 }
98 
99 /**
100  * @tc.name: InitWithLinearGradient001
101  * @tc.desc:
102  * @tc.type: FUNC
103  * @tc.author:
104  */
105 HWTEST_F(SkiaShaderEffectTest, InitWithLinearGradient001, TestSize.Level1)
106 {
107     Point startPt;
108     Point endPt;
109     ColorQuad colorQuad = 20;
110     std::vector<ColorQuad> color { colorQuad };
111     std::vector<scalar> pos { 30.0f };
112     SkiaShaderEffect skiaShaderEffect;
113     skiaShaderEffect.InitWithLinearGradient(startPt, endPt, color, pos, TileMode::MIRROR, nullptr);
114 }
115 
116 /**
117  * @tc.name: InitWithRadialGradient001
118  * @tc.desc:
119  * @tc.type: FUNC
120  * @tc.author:
121  */
122 HWTEST_F(SkiaShaderEffectTest, InitWithRadialGradient001, TestSize.Level1)
123 {
124     Point centerPt;
125     scalar radius = 15.0f;
126     ColorQuad colorQuad = 30;
127     std::vector<ColorQuad> color { colorQuad };
128     std::vector<scalar> pos { 16.0f };
129     SkiaShaderEffect skiaShaderEffect;
130     skiaShaderEffect.InitWithRadialGradient(centerPt, radius, color, pos, TileMode::REPEAT, nullptr);
131 }
132 
133 /**
134  * @tc.name: InitWithTwoPointConical001
135  * @tc.desc:
136  * @tc.type: FUNC
137  * @tc.author:
138  */
139 HWTEST_F(SkiaShaderEffectTest, InitWithTwoPointConical001, TestSize.Level1)
140 {
141     Point startPt;
142     scalar startRadius = 10.0f;
143     Point endPt;
144     scalar endRadius = 25.0f;
145     ColorQuad colorQuad = 15;
146     std::vector<ColorQuad> color { colorQuad };
147     std::vector<scalar> pos { 30.0f };
148     SkiaShaderEffect skiaShaderEffect;
149     Matrix matrix;
150     skiaShaderEffect.InitWithTwoPointConical(startPt, startRadius, endPt, endRadius, color, pos, TileMode::CLAMP,
151         &matrix);
152 }
153 
154 /**
155  * @tc.name: InitWithSweepGradient001
156  * @tc.desc:
157  * @tc.type: FUNC
158  * @tc.author:
159  */
160 HWTEST_F(SkiaShaderEffectTest, InitWithSweepGradient001, TestSize.Level1)
161 {
162     Point centerPt;
163     ColorQuad colorQuad = 10;
164     std::vector<ColorQuad> color { colorQuad };
165     std::vector<scalar> pos { 30.0f };
166     scalar startAngle = 45.0f;
167     scalar endAngle = 60.0f;
168     SkiaShaderEffect skiaShaderEffect;
169     skiaShaderEffect.InitWithSweepGradient(centerPt, color, pos, TileMode::MIRROR, startAngle, endAngle, nullptr);
170 }
171 
172 /**
173  * @tc.name: Serialize001
174  * @tc.desc: Test Serialize
175  * @tc.type: FUNC
176  * @tc.require: I91EH1
177  */
178 HWTEST_F(SkiaShaderEffectTest, Serialize001, TestSize.Level1)
179 {
180     SkiaShaderEffect skiaShaderEffect;
181     auto shader1 = skiaShaderEffect.GetShader();
182     EXPECT_TRUE(shader1 == nullptr);
183     skiaShaderEffect.Serialize();
184     auto shader2 = skiaShaderEffect.GetShader();
185     EXPECT_TRUE(shader2 == nullptr);
186 }
187 
188 } // namespace Drawing
189 } // namespace Rosen
190 } // namespace OHOS