• 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 <gtest/gtest.h>
17 #include "ge_particle_circular_halo_shader.h"
18 #include "ge_external_dynamic_loader.h"
19 #include "ge_visual_effect_impl.h"
20 #include "draw/path.h"
21 #include "draw/canvas.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 
29 class GEParticleCircularHaloShaderTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35     std::shared_ptr<Drawing::Image> MakeImage(Drawing::Canvas& canvas);
36 
37     static inline Drawing::Canvas canvas_;
38     std::shared_ptr<Drawing::Image> image_ { nullptr };
39 
40     // 1.0f, 1.0f, 2.0f, 2.0f is left top right bottom
41     Drawing::Rect rect_ { 1.0f, 1.0f, 2.0f, 2.0f };
42 };
43 
SetUpTestCase(void)44 void GEParticleCircularHaloShaderTest::SetUpTestCase(void) {}
TearDownTestCase(void)45 void GEParticleCircularHaloShaderTest::TearDownTestCase(void) {}
46 
SetUp()47 void GEParticleCircularHaloShaderTest::SetUp()
48 {
49     canvas_.Restore();
50 
51     Drawing::Bitmap bmp;
52     Drawing::BitmapFormat format { Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL };
53     bmp.Build(50, 50, format); // 50, 50  bitmap size
54     bmp.ClearWithColor(Drawing::Color::COLOR_BLUE);
55     image_ = bmp.MakeImage();
56 }
57 
TearDown()58 void GEParticleCircularHaloShaderTest::TearDown() {}
59 
60 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest001, TestSize.Level1)
61 {
62     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_001 start";
63     Drawing::GEParticleCircularHaloShaderParams params;
64     params.radius_ = 0.5f;
65     params.center_ = std::make_pair(0.5f, 0.5f);
66     params.noise_ = 4.0f;
67 
68     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
69     shader->Preprocess(canvas_, rect_);
70     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
71 
72     if (shaderEffect) {
73         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (0.5, 0.5), noise = 4.0";
74     } else {
75         GTEST_LOG_(ERROR) << "Failed to create shader.";
76     }
77     EXPECT_EQ(shaderEffect, nullptr);
78 
79     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_001 end";
80 }
81 
82 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest002, TestSize.Level1)
83 {
84     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_002 start";
85     Drawing::GEParticleCircularHaloShaderParams params;
86     params.radius_ = -0.1f;
87     params.center_ = std::make_pair(0.5f, 0.5f);
88     params.noise_ = 4.0f;
89 
90     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
91     shader->Preprocess(canvas_, rect_);
92     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
93 
94     if (shaderEffect) {
95         GTEST_LOG_(INFO) << "Shader created successfully, radius = -0.5, center = (0.5, 0.5), noise = 4.0";
96     } else {
97         GTEST_LOG_(ERROR) << "Failed to create shader.";
98     }
99     EXPECT_EQ(shaderEffect, nullptr);
100 
101     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_002 end";
102 }
103 
104 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest003, TestSize.Level1)
105 {
106     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_003 start";
107     Drawing::GEParticleCircularHaloShaderParams params;
108     params.radius_ = 2.0f;
109     params.center_ = std::make_pair(0.5f, 0.5f);
110     params.noise_ = 4.0f;
111 
112     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
113     shader->Preprocess(canvas_, rect_);
114     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
115 
116     if (shaderEffect) {
117         GTEST_LOG_(INFO) << "Shader created successfully, radius = 2.0, center = (0.5, 0.5), noise = 4.0";
118     } else {
119         GTEST_LOG_(ERROR) << "Failed to create shader.";
120     }
121     EXPECT_EQ(shaderEffect, nullptr);
122 
123     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_003 end";
124 }
125 
126 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest004, TestSize.Level1)
127 {
128     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_004 start";
129     Drawing::GEParticleCircularHaloShaderParams params;
130     params.radius_ = 0.5f;
131     params.center_ = std::make_pair(-0.5f, 0.5f);
132     params.noise_ = 4.0f;
133 
134     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
135     shader->Preprocess(canvas_, rect_);
136     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
137 
138     if (shaderEffect) {
139         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (-0.5, 0.5), noise = 4.0";
140     } else {
141         GTEST_LOG_(ERROR) << "Failed to create shader.";
142     }
143     EXPECT_EQ(shaderEffect, nullptr);
144 
145     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_004 end";
146 }
147 
148 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest005, TestSize.Level1)
149 {
150     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_005 start";
151     Drawing::GEParticleCircularHaloShaderParams params;
152     params.radius_ = 0.5f;
153     params.center_ = std::make_pair(0.5f, -0.5f);
154     params.noise_ = 4.0f;
155 
156     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
157     shader->Preprocess(canvas_, rect_);
158     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
159 
160     if (shaderEffect) {
161         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (0.5, -0.5), noise = 4.0";
162     } else {
163         GTEST_LOG_(ERROR) << "Failed to create shader.";
164     }
165     EXPECT_EQ(shaderEffect, nullptr);
166 
167     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_005 end";
168 }
169 
170 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest006, TestSize.Level1)
171 {
172     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_006 start";
173     Drawing::GEParticleCircularHaloShaderParams params;
174     params.radius_ = 0.5f;
175     params.center_ = std::make_pair(1.5f, 0.5f);
176     params.noise_ = 4.0f;
177 
178     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
179     shader->Preprocess(canvas_, rect_);
180     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
181 
182     if (shaderEffect) {
183         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (1.5, 0.5), noise = 4.0";
184     } else {
185         GTEST_LOG_(ERROR) << "Failed to create shader.";
186     }
187     EXPECT_EQ(shaderEffect, nullptr);
188 
189     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_006 end";
190 }
191 
192 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest007, TestSize.Level1)
193 {
194     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_007 start";
195     Drawing::GEParticleCircularHaloShaderParams params;
196     params.radius_ = 0.5f;
197     params.center_ = std::make_pair(0.5f, 1.5f);
198     params.noise_ = 4.0f;
199 
200     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
201     shader->Preprocess(canvas_, rect_);
202     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
203 
204     if (shaderEffect) {
205         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (0.5, 1.5), noise = 4.0";
206     } else {
207         GTEST_LOG_(ERROR) << "Failed to create shader.";
208     }
209     EXPECT_EQ(shaderEffect, nullptr);
210 
211     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_007 end";
212 }
213 
214 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest008, TestSize.Level1)
215 {
216     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_008 start";
217     Drawing::GEParticleCircularHaloShaderParams params;
218     params.radius_ = 0.5f;
219     params.center_ = std::make_pair(1.5f, 0.5f);
220     params.noise_ = -2.0f;
221 
222     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
223     shader->Preprocess(canvas_, rect_);
224     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
225 
226     if (shaderEffect) {
227         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (1.5, 0.5), noise = -2.0";
228     } else {
229         GTEST_LOG_(ERROR) << "Failed to create shader.";
230     }
231     EXPECT_EQ(shaderEffect, nullptr);
232 
233     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_008 end";
234 }
235 
236 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest009, TestSize.Level1)
237 {
238     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_009 start";
239     Drawing::GEParticleCircularHaloShaderParams params;
240     params.radius_ = -0.5f;
241     params.center_ = std::make_pair(-0.5f, -0.5f);
242     params.noise_ = -2.0f;
243 
244     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
245     shader->Preprocess(canvas_, rect_);
246     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
247 
248     if (shaderEffect) {
249         GTEST_LOG_(INFO) << "Shader created successfully, radius = -0.5, center = (-0.5, -0.5), noise = -2.0";
250     } else {
251         GTEST_LOG_(ERROR) << "Failed to create shader.";
252     }
253     EXPECT_EQ(shaderEffect, nullptr);
254 
255     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_009 end";
256 }
257 
258 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest010, TestSize.Level1)
259 {
260     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_010 start";
261     Drawing::GEParticleCircularHaloShaderParams params;
262     params.center_ = std::make_pair(0.5f, 0.5f);
263     params.noise_ = 2.0f;
264 
265     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
266     shader->Preprocess(canvas_, rect_);
267     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
268 
269     if (shaderEffect) {
270         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (0.5, 0.5), noise = 2.0";
271     } else {
272         GTEST_LOG_(ERROR) << "Failed to create shader.";
273     }
274     EXPECT_EQ(shaderEffect, nullptr);
275 
276     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_010 end";
277 }
278 
279 HWTEST_F(GEParticleCircularHaloShaderTest, GEParticleCircularHaloShaderTest011, TestSize.Level1)
280 {
281     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_011 start";
282     Drawing::GEParticleCircularHaloShaderParams params;
283     params.radius_ = 1;
284     params.center_ = std::make_pair(0.5f, 0.5f);
285     params.noise_ = 2.0f;
286 
287     auto shader = GEParticleCircularHaloShader::CreateParticleCircularHaloShader(params);
288     shader->Preprocess(canvas_, rect_);
289     auto shaderEffect = shader->MakeParticleCircularHaloShader(rect_);
290 
291     if (shaderEffect) {
292         GTEST_LOG_(INFO) << "Shader created successfully, radius = 0.5, center = (0.5, 0.5), noise = 2.0";
293     } else {
294         GTEST_LOG_(ERROR) << "Failed to create shader.";
295     }
296     EXPECT_EQ(shaderEffect, nullptr);
297 
298     GTEST_LOG_(INFO) << "GEParticleCircularHaloShaderTest MakeParticleCircularHaloShader_011 end";
299 }
300 
301 }  // namespace Rosen
302 }  // namespace OHOS