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