• 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 "gtest/gtest.h"
17 
18 #include "effect/shader_effect.h"
19 #include "effect/shader_effect_lazy.h"
20 #include "draw/blend_mode.h"
21 #ifdef RS_ENABLE_GPU
22 #include "image/gpu_context.h"
23 #endif
24 #include "image/image.h"
25 #include "utils/object_helper.h"
26 #ifdef ROSEN_OHOS
27 #include <parcel.h>
28 #include <message_parcel.h>
29 #endif
30 #include "transaction/rs_marshalling_helper.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 
35 namespace OHOS {
36 namespace Rosen {
37 namespace Drawing {
38 class ShaderEffectTest : public testing::Test {
39 public:
40     static void SetUpTestCase();
41     static void TearDownTestCase();
42     void SetUp() override;
43     void TearDown() override;
44 
45 private:
46 #ifdef ROSEN_OHOS
47     static std::function<bool(Parcel&, std::shared_ptr<Data>)> originalMarshallingCallback_;
48     static std::function<std::shared_ptr<Data>(Parcel&)> originalUnmarshallingCallback_;
49 #endif
50 };
51 
52 #ifdef ROSEN_OHOS
53 std::function<bool(Parcel&, std::shared_ptr<Data>)> ShaderEffectTest::originalMarshallingCallback_;
54 std::function<std::shared_ptr<Data>(Parcel&)> ShaderEffectTest::originalUnmarshallingCallback_;
55 #endif
56 
SetUpTestCase()57 void ShaderEffectTest::SetUpTestCase()
58 {
59 #ifdef ROSEN_OHOS
60     // Save original callbacks
61     originalMarshallingCallback_ = ObjectHelper::Instance().GetDataMarshallingCallback();
62     originalUnmarshallingCallback_ = ObjectHelper::Instance().GetDataUnmarshallingCallback();
63 
64     // Register Data marshalling/unmarshalling callbacks
65     ObjectHelper::Instance().SetDataMarshallingCallback(
66         [](Parcel& parcel, std::shared_ptr<Data> data) -> bool {
67             return OHOS::Rosen::RSMarshallingHelper::Marshalling(parcel, data);
68         }
69     );
70     ObjectHelper::Instance().SetDataUnmarshallingCallback(
71         [](Parcel& parcel) -> std::shared_ptr<Data> {
72             std::shared_ptr<Data> data;
73             return OHOS::Rosen::RSMarshallingHelper::Unmarshalling(parcel, data) ? data : nullptr;
74         }
75     );
76 #endif
77 }
78 
TearDownTestCase()79 void ShaderEffectTest::TearDownTestCase()
80 {
81 #ifdef ROSEN_OHOS
82     // Restore original callbacks
83     ObjectHelper::Instance().SetDataMarshallingCallback(originalMarshallingCallback_);
84     ObjectHelper::Instance().SetDataUnmarshallingCallback(originalUnmarshallingCallback_);
85 #endif
86 }
SetUp()87 void ShaderEffectTest::SetUp() {}
TearDown()88 void ShaderEffectTest::TearDown() {}
89 
90 // Create a mock shader that will return null from Serialize
91 class MockShaderEffect : public ShaderEffect {
92 public:
MockShaderEffect()93     MockShaderEffect() : ShaderEffect(ShaderEffectType::COLOR_SHADER) {}
94 
Serialize() const95     std::shared_ptr<Data> Serialize() const override
96     {
97         return nullptr;
98     }
99 };
100 
101 /*
102  * @tc.name: CreateColorShader001
103  * @tc.desc:
104  * @tc.type: FUNC
105  * @tc.require: AR000GGNV3
106  * @tc.author:
107  */
108 HWTEST_F(ShaderEffectTest, CreateColorShader001, TestSize.Level1)
109 {
110     ColorQuad color = 13;
111     auto newShaderEffect = ShaderEffect::CreateColorShader(color);
112     EXPECT_TRUE(newShaderEffect != nullptr);
113 }
114 
115 /*
116  * @tc.name: CreateColorShader002
117  * @tc.desc:
118  * @tc.type: FUNC
119  * @tc.require: AR000GGNV3
120  * @tc.author:
121  */
122 HWTEST_F(ShaderEffectTest, CreateColorShader002, TestSize.Level1)
123 {
124     ColorQuad color = 24;
125     auto newShaderEffect = ShaderEffect::CreateColorShader(color);
126     EXPECT_TRUE(newShaderEffect != nullptr);
127 }
128 
129 /*
130  * @tc.name: CreateBlendShader001
131  * @tc.desc:
132  * @tc.type: FUNC
133  * @tc.require: AR000GGNV3
134  * @tc.author:
135  */
136 HWTEST_F(ShaderEffectTest, CreateBlendShader001, TestSize.Level1)
137 {
138     ShaderEffect shaderEffect1(ShaderEffect::ShaderEffectType::BLEND, 20);
139     ShaderEffect shaderEffect2(ShaderEffect::ShaderEffectType::LINEAR_GRADIENT, 10);
140     auto newShaderEffect = ShaderEffect::CreateBlendShader(shaderEffect1, shaderEffect2, BlendMode::CLEAR);
141     EXPECT_TRUE(newShaderEffect != nullptr);
142 }
143 
144 /*
145  * @tc.name: CreateBlendShader003
146  * @tc.desc:
147  * @tc.type: FUNC
148  * @tc.require: AR000GGNV3
149  * @tc.author:
150  */
151 HWTEST_F(ShaderEffectTest, CreateBlendShader003, TestSize.Level1)
152 {
153     ShaderEffect shaderEffect3(ShaderEffect::ShaderEffectType::LINEAR_GRADIENT, 60);
154     ShaderEffect shaderEffect4(ShaderEffect::ShaderEffectType::CONICAL_GRADIENT, 4);
155     auto newShaderEffect = ShaderEffect::CreateBlendShader(shaderEffect3, shaderEffect4, BlendMode::DST);
156     EXPECT_TRUE(newShaderEffect != nullptr);
157     EXPECT_FALSE(newShaderEffect->IsLazy());
158 }
159 
160 /*
161  * @tc.name: CreateImageShader001
162  * @tc.desc:
163  * @tc.type: FUNC
164  * @tc.require: AR000GGNV3
165  * @tc.author:
166  */
167 HWTEST_F(ShaderEffectTest, CreateImageShader001, TestSize.Level1)
168 {
169     Image image;
170     SamplingOptions sampling;
171     Matrix matrix;
172     auto newShaderEffect = ShaderEffect::CreateImageShader(image, TileMode::CLAMP, TileMode::REPEAT, sampling, matrix);
173     EXPECT_TRUE(newShaderEffect != nullptr);
174 }
175 
176 /*
177  * @tc.name: CreateImageShader002
178  * @tc.desc:
179  * @tc.type: FUNC
180  * @tc.require: AR000GGNV3
181  * @tc.author:
182  */
183 HWTEST_F(ShaderEffectTest, CreateImageShader002, TestSize.Level1)
184 {
185     Image image;
186     SamplingOptions sampling;
187     Matrix matrix;
188     auto newShaderEffect = ShaderEffect::CreateImageShader(image, TileMode::REPEAT, TileMode::MIRROR, sampling, matrix);
189     EXPECT_TRUE(newShaderEffect != nullptr);
190 }
191 
192 /*
193  * @tc.name: CreatePictureShader001
194  * @tc.desc:
195  * @tc.type: FUNC
196  * @tc.require: AR000GGNV3
197  * @tc.author:
198  */
199 HWTEST_F(ShaderEffectTest, CreatePictureShader001, TestSize.Level1)
200 {
201     Picture picture;
202     Matrix matrix;
203     Rect rect;
204     auto newShaderEffect = ShaderEffect::CreatePictureShader(
205         picture, TileMode::MIRROR, TileMode::REPEAT, FilterMode::LINEAR, matrix, rect);
206     EXPECT_TRUE(newShaderEffect != nullptr);
207 }
208 
209 /*
210  * @tc.name: CreatePictureShader002
211  * @tc.desc:
212  * @tc.type: FUNC
213  * @tc.require: AR000GGNV3
214  * @tc.author:
215  */
216 HWTEST_F(ShaderEffectTest, CreatePictureShader002, TestSize.Level1)
217 {
218     Picture picture;
219     Matrix matrix;
220     Rect rect;
221     auto newShaderEffect =
222         ShaderEffect::CreatePictureShader(picture, TileMode::CLAMP, TileMode::REPEAT, FilterMode::LINEAR, matrix, rect);
223     EXPECT_TRUE(newShaderEffect != nullptr);
224 }
225 
226 /*
227  * @tc.name: CreateLinearGradient001
228  * @tc.desc:
229  * @tc.type: FUNC
230  * @tc.require: AR000GGNV3
231  * @tc.author:
232  */
233 HWTEST_F(ShaderEffectTest, CreateLinearGradient001, TestSize.Level1)
234 {
235     Point startPoint;
236     Point endPoint;
237     std::vector<ColorQuad> colors;
238     std::vector<scalar> position;
239     auto newShaderEffect = ShaderEffect::CreateLinearGradient(startPoint, endPoint, colors, position, TileMode::CLAMP);
240     EXPECT_TRUE(newShaderEffect != nullptr);
241 }
242 
243 /*
244  * @tc.name: CreateLinearGradient002
245  * @tc.desc:
246  * @tc.type: FUNC
247  * @tc.require: AR000GGNV3
248  * @tc.author:
249  */
250 HWTEST_F(ShaderEffectTest, CreateLinearGradient002, TestSize.Level1)
251 {
252     Point startPoint;
253     Point endPoint;
254     std::vector<ColorQuad> colors;
255     std::vector<scalar> position;
256     auto newShaderEffect = ShaderEffect::CreateLinearGradient(startPoint, endPoint, colors, position, TileMode::REPEAT);
257     EXPECT_TRUE(newShaderEffect != nullptr);
258 }
259 
260 /*
261  * @tc.name: CreateLinearGradient003
262  * @tc.desc:
263  * @tc.type: FUNC
264  * @tc.require: AR000GGNV3
265  * @tc.author:
266  */
267 HWTEST_F(ShaderEffectTest, CreateLinearGradient003, TestSize.Level1)
268 {
269     Point startPoint;
270     Point endPoint;
271     std::vector<Color4f> colors;
272     colors.push_back({0.1, 0.1, 0.1, 1.0f});
273     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
274     std::vector<scalar> position;
275     auto newShaderEffect = ShaderEffect::CreateLinearGradient(startPoint, endPoint, colors, colorSpace,
276         position,TileMode::REPEAT);
277     EXPECT_TRUE(newShaderEffect != nullptr);
278     colors.clear();
279     auto newShaderEffect2 = ShaderEffect::CreateLinearGradient(startPoint, endPoint, colors, colorSpace,
280         position,TileMode::REPEAT);
281     EXPECT_TRUE(newShaderEffect2 != nullptr);
282 }
283 
284 /*
285  * @tc.name: CreateRadialGradient001
286  * @tc.desc:
287  * @tc.type: FUNC
288  * @tc.require: AR000GGNV3
289  * @tc.author:
290  */
291 HWTEST_F(ShaderEffectTest, CreateRadialGradient001, TestSize.Level1)
292 {
293     Point centerPoint;
294     scalar radius = 0.5f;
295     std::vector<ColorQuad> colors;
296     std::vector<scalar> position;
297     TileMode tileMode = TileMode::MIRROR;
298     auto newShaderEffect = ShaderEffect::CreateRadialGradient(centerPoint, radius, colors, position, tileMode);
299     EXPECT_TRUE(newShaderEffect != nullptr);
300 }
301 
302 /*
303  * @tc.name: CreateRadialGradient002
304  * @tc.desc:
305  * @tc.type: FUNC
306  * @tc.require: AR000GGNV3
307  * @tc.author:
308  */
309 HWTEST_F(ShaderEffectTest, CreateRadialGradient002, TestSize.Level1)
310 {
311     Point centerPoint;
312     scalar radius = 2.5f;
313     std::vector<ColorQuad> colors;
314     std::vector<scalar> position;
315     TileMode tileMode = TileMode::REPEAT;
316     auto newShaderEffect = ShaderEffect::CreateRadialGradient(centerPoint, radius, colors, position, tileMode);
317     EXPECT_TRUE(newShaderEffect != nullptr);
318 }
319 
320 /*
321  * @tc.name: CreateRadialGradient003
322  * @tc.desc:
323  * @tc.type: FUNC
324  * @tc.require: AR000GGNV3
325  * @tc.author:
326  */
327 HWTEST_F(ShaderEffectTest, CreateRadialGradient003, TestSize.Level1)
328 {
329     Point centerPoint;
330     scalar radius = 2.5f;
331     std::vector<Color4f> colors;
332     colors.push_back({0.1, 0.1, 0.1, 1.0f});
333     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
334     std::vector<scalar> position;
335     TileMode tileMode = TileMode::REPEAT;
336     Matrix matrix;
337     auto newShaderEffect = ShaderEffect::CreateRadialGradient(centerPoint, radius, colors, colorSpace, position,
338         tileMode, &matrix);
339     EXPECT_TRUE(newShaderEffect != nullptr);
340     colors.clear();
341     auto newShaderEffect2 = ShaderEffect::CreateRadialGradient(centerPoint, radius, colors, colorSpace, position,
342         tileMode, &matrix);
343     EXPECT_TRUE(newShaderEffect2 != nullptr);
344 }
345 
346 /*
347  * @tc.name: CreateTwoPointConical001
348  * @tc.desc:
349  * @tc.type: FUNC
350  * @tc.require: AR000GGNV3
351  * @tc.author:
352  */
353 HWTEST_F(ShaderEffectTest, CreateTwoPointConical001, TestSize.Level1)
354 {
355     Point startPoint;
356     scalar startRadius = 0.2f;
357     Point endPoint;
358     scalar endRadius = 0.5f;
359     std::vector<ColorQuad> colors;
360     std::vector<scalar> position;
361     TileMode tileMode = TileMode::MIRROR;
362     Matrix matrix;
363     auto newShaderEffect = ShaderEffect::CreateTwoPointConical(startPoint, startRadius, endPoint, endRadius, colors,
364         position, tileMode, &matrix);
365     EXPECT_TRUE(newShaderEffect != nullptr);
366 }
367 
368 /*
369  * @tc.name: CreateTwoPointConical002
370  * @tc.desc:
371  * @tc.type: FUNC
372  * @tc.require: AR000GGNV3
373  * @tc.author:
374  */
375 HWTEST_F(ShaderEffectTest, CreateTwoPointConical002, TestSize.Level1)
376 {
377     Point startPoint;
378     scalar startRadius = 0.1f;
379     Point endPoint;
380     scalar endRadius = 0.7f;
381     std::vector<ColorQuad> colors;
382     std::vector<scalar> position;
383     TileMode tileMode = TileMode::REPEAT;
384     Matrix matrix;
385     auto newShaderEffect = ShaderEffect::CreateTwoPointConical(startPoint, startRadius, endPoint, endRadius, colors,
386         position, tileMode, &matrix);
387     EXPECT_TRUE(newShaderEffect != nullptr);
388 }
389 
390 /*
391  * @tc.name: CreateTwoPointConical003
392  * @tc.desc:
393  * @tc.type: FUNC
394  * @tc.require: AR000GGNV3
395  * @tc.author:
396  */
397 HWTEST_F(ShaderEffectTest, CreateTwoPointConical003, TestSize.Level1)
398 {
399     Point startPoint;
400     scalar startRadius = 0.1f;
401     Point endPoint;
402     scalar endRadius = 0.7f;
403     std::vector<Color4f> colors;
404     colors.push_back({0.1, 0.1, 0.1, 1.0f});
405     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
406     std::vector<scalar> position;
407     TileMode tileMode = TileMode::REPEAT;
408     Matrix matrix;
409     auto newShaderEffect = ShaderEffect::CreateTwoPointConical(startPoint, startRadius, endPoint, endRadius, colors,
410         colorSpace, position, tileMode, &matrix);
411     EXPECT_TRUE(newShaderEffect != nullptr);
412     colors.clear();
413     auto newShaderEffect2 = ShaderEffect::CreateTwoPointConical(startPoint, startRadius, endPoint, endRadius, colors,
414         colorSpace, position, tileMode, &matrix);
415     EXPECT_TRUE(newShaderEffect2 != nullptr);
416 }
417 
418 /*
419  * @tc.name: CreateSweepGradient001
420  * @tc.desc:
421  * @tc.type: FUNC
422  * @tc.require: AR000GGNV3
423  * @tc.author:
424  */
425 HWTEST_F(ShaderEffectTest, CreateSweepGradient001, TestSize.Level1)
426 {
427     Point centerPoint;
428     std::vector<ColorQuad> colors;
429     std::vector<scalar> position;
430     TileMode tileMode = TileMode::MIRROR;
431     scalar startAngle = 0.2f;
432     scalar endAngle = 0.5f;
433     auto newShaderEffect =
434         ShaderEffect::CreateSweepGradient(centerPoint, colors, position, tileMode, startAngle, endAngle, nullptr);
435     EXPECT_TRUE(newShaderEffect != nullptr);
436 }
437 
438 /*
439  * @tc.name: CreateSweepGradient002
440  * @tc.desc:
441  * @tc.type: FUNC
442  * @tc.require: AR000GGNV3
443  * @tc.author:
444  */
445 HWTEST_F(ShaderEffectTest, CreateSweepGradient002, TestSize.Level1)
446 {
447     Point centerPoint;
448     std::vector<ColorQuad> colors;
449     std::vector<scalar> position;
450     TileMode tileMode = TileMode::REPEAT;
451     scalar startAngle = 10.2f;
452     scalar endAngle = 10.5f;
453     auto newShaderEffect =
454         ShaderEffect::CreateSweepGradient(centerPoint, colors, position, tileMode, startAngle, endAngle, nullptr);
455     EXPECT_TRUE(newShaderEffect != nullptr);
456 }
457 
458 /*
459  * @tc.name: CreateSweepGradient003
460  * @tc.desc:
461  * @tc.type: FUNC
462  * @tc.require: AR000GGNV3
463  * @tc.author:
464  */
465 HWTEST_F(ShaderEffectTest, CreateSweepGradient003, TestSize.Level1)
466 {
467     Point centerPoint;
468     std::vector<Color4f> colors;
469     colors.push_back({0.1, 0.1, 0.1, 1.0f});
470     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
471     std::vector<scalar> position;
472     TileMode tileMode = TileMode::REPEAT;
473     scalar startAngle = 10.2f;
474     scalar endAngle = 10.5f;
475     auto newShaderEffect =
476         ShaderEffect::CreateSweepGradient(centerPoint, colors, colorSpace, position, tileMode, startAngle,
477         endAngle, nullptr);
478     EXPECT_TRUE(newShaderEffect != nullptr);
479     colors.clear();
480     auto newShaderEffect2 =
481         ShaderEffect::CreateSweepGradient(centerPoint, colors, colorSpace, position, tileMode, startAngle,
482         endAngle, nullptr);
483     EXPECT_TRUE(newShaderEffect2 != nullptr);
484 }
485 
486 /*
487  * @tc.name: ArgsContructor001
488  * @tc.desc:
489  * @tc.type: FUNC
490  * @tc.require: AR000GGNV3
491  * @tc.author:
492  */
493 HWTEST_F(ShaderEffectTest, ArgsContructor001, TestSize.Level1)
494 {
495     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::COLOR_SHADER, 230);
496     ASSERT_TRUE(newShaderEffect != nullptr);
497 }
498 
499 /*
500  * @tc.name: ArgsContructor002
501  * @tc.desc:
502  * @tc.type: FUNC
503  * @tc.require: AR000GGNV3
504  * @tc.author:
505  */
506 HWTEST_F(ShaderEffectTest, ArgsContructor002, TestSize.Level1)
507 {
508     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::PICTURE, 100);
509     ASSERT_TRUE(newShaderEffect != nullptr);
510 }
511 
512 /*
513  * @tc.name: ArgsContructor003
514  * @tc.desc:
515  * @tc.type: FUNC
516  * @tc.require: AR000GGNV3
517  * @tc.author:
518  */
519 HWTEST_F(ShaderEffectTest, ArgsContructor003, TestSize.Level1)
520 {
521     ShaderEffect shaderEffect3(ShaderEffect::ShaderEffectType::IMAGE, 55);
522     ShaderEffect shaderEffect4(ShaderEffect::ShaderEffectType::IMAGE, 100);
523     auto newShaderEffect = std::make_unique<ShaderEffect>(
524         ShaderEffect::ShaderEffectType::RADIAL_GRADIENT, shaderEffect3, shaderEffect4, BlendMode::SRC);
525     ASSERT_TRUE(newShaderEffect != nullptr);
526 }
527 
528 /*
529  * @tc.name: ArgsContructor004
530  * @tc.desc:
531  * @tc.type: FUNC
532  * @tc.require: AR000GGNV3
533  * @tc.author:
534  */
535 HWTEST_F(ShaderEffectTest, ArgsContructor004, TestSize.Level1)
536 {
537     ShaderEffect shaderEffect3(ShaderEffect::ShaderEffectType::SWEEP_GRADIENT, 60);
538     ShaderEffect shaderEffect4(ShaderEffect::ShaderEffectType::IMAGE, 10);
539     auto newShaderEffect = std::make_unique<ShaderEffect>(
540         ShaderEffect::ShaderEffectType::SWEEP_GRADIENT, shaderEffect3, shaderEffect4, BlendMode::SRC);
541     ASSERT_TRUE(newShaderEffect != nullptr);
542 }
543 
544 /*
545  * @tc.name: ArgsContructor005
546  * @tc.desc:
547  * @tc.type: FUNC
548  * @tc.require: AR000GGNV3
549  * @tc.author:
550  */
551 HWTEST_F(ShaderEffectTest, ArgsContructor005, TestSize.Level1)
552 {
553     Image image;
554     TileMode tileX = TileMode::REPEAT;
555     TileMode tileY = TileMode::MIRROR;
556     SamplingOptions sampling;
557     Matrix matrix;
558     auto newShaderEffect = std::make_unique<ShaderEffect>(
559         ShaderEffect::ShaderEffectType::CONICAL_GRADIENT, image, tileX, tileY, sampling, matrix);
560     ASSERT_TRUE(newShaderEffect != nullptr);
561 }
562 
563 /*
564  * @tc.name: ArgsContructor006
565  * @tc.desc:
566  * @tc.type: FUNC
567  * @tc.require: AR000GGNV3
568  * @tc.author:
569  */
570 HWTEST_F(ShaderEffectTest, ArgsContructor006, TestSize.Level1)
571 {
572     Image image;
573     TileMode tileX = TileMode::REPEAT;
574     TileMode tileY = TileMode::CLAMP;
575     SamplingOptions sampling;
576     Matrix matrix;
577     auto newShaderEffect =
578         std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::PICTURE, image, tileX, tileY, sampling, matrix);
579     ASSERT_TRUE(newShaderEffect != nullptr);
580 }
581 
582 /*
583  * @tc.name: ArgsContructor007
584  * @tc.desc:
585  * @tc.type: FUNC
586  * @tc.require: AR000GGNV3
587  * @tc.author:
588  */
589 HWTEST_F(ShaderEffectTest, ArgsContructor007, TestSize.Level1)
590 {
591     Image image;
592     SamplingOptions sampling;
593     Matrix matrix;
594     auto newShaderEffect = std::make_unique<ShaderEffect>(
595         ShaderEffect::ShaderEffectType::NO_TYPE, image, TileMode::CLAMP, TileMode::REPEAT, sampling, matrix);
596     ASSERT_TRUE(newShaderEffect != nullptr);
597 }
598 
599 /*
600  * @tc.name: ArgsContructor008
601  * @tc.desc:
602  * @tc.type: FUNC
603  * @tc.require: AR000GGNV3
604  * @tc.author:
605  */
606 HWTEST_F(ShaderEffectTest, ArgsContructor008, TestSize.Level1)
607 {
608     Image image;
609     SamplingOptions sampling;
610     Matrix matrix;
611     auto newShaderEffect = std::make_unique<ShaderEffect>(
612         ShaderEffect::ShaderEffectType::CONICAL_GRADIENT, image, TileMode::REPEAT, TileMode::CLAMP, sampling, matrix);
613     ASSERT_TRUE(newShaderEffect != nullptr);
614 }
615 
616 /*
617  * @tc.name: ArgsContructor009
618  * @tc.desc:
619  * @tc.type: FUNC
620  * @tc.require: AR000GGNV3
621  * @tc.author:
622  */
623 HWTEST_F(ShaderEffectTest, ArgsContructor009, TestSize.Level1)
624 {
625     Picture picture;
626     Rect rect;
627     Matrix matrix;
628     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::PICTURE, picture,
629         TileMode::REPEAT, TileMode::MIRROR, FilterMode::LINEAR, matrix, rect);
630     ASSERT_TRUE(newShaderEffect != nullptr);
631 }
632 
633 /*
634  * @tc.name: ArgsContructor010
635  * @tc.desc:
636  * @tc.type: FUNC
637  * @tc.require: AR000GGNV3
638  * @tc.author:
639  */
640 HWTEST_F(ShaderEffectTest, ArgsContructor010, TestSize.Level1)
641 {
642     Picture picture;
643     Rect rect;
644     Matrix matrix;
645     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::CONICAL_GRADIENT, picture,
646         TileMode::MIRROR, TileMode::REPEAT, FilterMode::LINEAR, matrix, rect);
647     ASSERT_TRUE(newShaderEffect != nullptr);
648 }
649 
650 /*
651  * @tc.name: ArgsContructor011
652  * @tc.desc:
653  * @tc.type: FUNC
654  * @tc.require: AR000GGNV3
655  * @tc.author:
656  */
657 HWTEST_F(ShaderEffectTest, ArgsContructor011, TestSize.Level1)
658 {
659     Point startPoint;
660     Point endPoint;
661     std::vector<ColorQuad> colors;
662     std::vector<scalar> position;
663     auto newShaderEffect = std::make_unique<ShaderEffect>(
664         ShaderEffect::ShaderEffectType::NO_TYPE, startPoint, endPoint, colors, position, TileMode::REPEAT);
665     ASSERT_TRUE(newShaderEffect != nullptr);
666 }
667 
668 /*
669  * @tc.name: ArgsContructor012
670  * @tc.desc:
671  * @tc.type: FUNC
672  * @tc.require: AR000GGNV3
673  * @tc.author:
674  */
675 HWTEST_F(ShaderEffectTest, ArgsContructor012, TestSize.Level1)
676 {
677     Point startPoint;
678     Point endPoint;
679     std::vector<ColorQuad> colors;
680     std::vector<scalar> position;
681     auto newShaderEffect = std::make_unique<ShaderEffect>(
682         ShaderEffect::ShaderEffectType::COLOR_SHADER, startPoint, endPoint, colors, position, TileMode::REPEAT);
683     ASSERT_TRUE(newShaderEffect != nullptr);
684     auto type = newShaderEffect->GetType();
685     EXPECT_EQ(type, ShaderEffect::ShaderEffectType::COLOR_SHADER);
686 }
687 
688 /*
689  * @tc.name: ArgsContructor013
690  * @tc.desc:
691  * @tc.type: FUNC
692  * @tc.require: AR000GGNV3
693  * @tc.author:
694  */
695 HWTEST_F(ShaderEffectTest, ArgsContructor013, TestSize.Level1)
696 {
697     Point centerPoint;
698     scalar radius = 0.5f;
699     std::vector<ColorQuad> colors;
700     std::vector<scalar> position;
701     auto newShaderEffect = std::make_unique<ShaderEffect>(
702         ShaderEffect::ShaderEffectType::SWEEP_GRADIENT, centerPoint, radius, colors, position, TileMode::REPEAT);
703     ASSERT_TRUE(newShaderEffect != nullptr);
704     auto type = newShaderEffect->GetType();
705     EXPECT_EQ(type, ShaderEffect::ShaderEffectType::SWEEP_GRADIENT);
706 }
707 
708 /*
709  * @tc.name: ArgsContructor014
710  * @tc.desc:
711  * @tc.type: FUNC
712  * @tc.require: AR000GGNV3
713  * @tc.author:
714  */
715 HWTEST_F(ShaderEffectTest, ArgsContructor014, TestSize.Level1)
716 {
717     Point centerPoint;
718     scalar radius = 0.5f;
719     std::vector<ColorQuad> colors;
720     std::vector<scalar> position;
721     auto newShaderEffect = std::make_unique<ShaderEffect>(
722         ShaderEffect::ShaderEffectType::IMAGE, centerPoint, radius, colors, position, TileMode::REPEAT);
723     ASSERT_TRUE(newShaderEffect != nullptr);
724 }
725 
726 /*
727  * @tc.name: ArgsContructor015
728  * @tc.desc:
729  * @tc.type: FUNC
730  * @tc.require: AR000GGNV3
731  * @tc.author:
732  */
733 HWTEST_F(ShaderEffectTest, ArgsContructor015, TestSize.Level1)
734 {
735     Point startPoint;
736     scalar startRadius = 0.1f;
737     Point endPoint;
738     scalar endRadius = 0.7f;
739     std::vector<ColorQuad> colors;
740     std::vector<scalar> position;
741     Matrix matrix;
742     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::COLOR_SHADER, startPoint,
743         startRadius, endPoint, endRadius, colors, position, TileMode::REPEAT, &matrix);
744     ASSERT_TRUE(newShaderEffect != nullptr);
745 }
746 
747 /*
748  * @tc.name: ArgsContructor016
749  * @tc.desc:
750  * @tc.type: FUNC
751  * @tc.require: AR000GGNV3
752  * @tc.author:
753  */
754 HWTEST_F(ShaderEffectTest, ArgsContructor016, TestSize.Level1)
755 {
756     Point startPoint;
757     scalar startRadius = 55.1f;
758     Point endPoint;
759     scalar endRadius = 10.7f;
760     std::vector<ColorQuad> colors;
761     std::vector<scalar> position;
762     Matrix matrix;
763     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::LINEAR_GRADIENT, startPoint,
764         startRadius, endPoint, endRadius, colors, position, TileMode::REPEAT, &matrix);
765     ASSERT_TRUE(newShaderEffect != nullptr);
766 }
767 
768 /*
769  * @tc.name: ArgsContructor017
770  * @tc.desc:
771  * @tc.type: FUNC
772  * @tc.require: AR000GGNV3
773  * @tc.author:
774  */
775 HWTEST_F(ShaderEffectTest, ArgsContructor017, TestSize.Level1)
776 {
777     Point centerPoint;
778     scalar startAngle = 42.2f;
779     scalar endAngle = 55.7f;
780     std::vector<ColorQuad> colors;
781     std::vector<scalar> position;
782     auto newShaderEffect = std::make_unique<ShaderEffect>(
783         ShaderEffect::ShaderEffectType::BLEND, centerPoint, colors, position, TileMode::REPEAT, startAngle, endAngle,
784         nullptr);
785     ASSERT_TRUE(newShaderEffect != nullptr);
786 }
787 
788 /*
789  * @tc.name: ArgsContructor017
790  * @tc.desc:
791  * @tc.type: FUNC
792  * @tc.require: AR000GGNV3
793  * @tc.author:
794  */
795 HWTEST_F(ShaderEffectTest, ArgsContructor018, TestSize.Level1)
796 {
797     Point centerPoint;
798     scalar startAngle = 3.55f;
799     scalar endAngle = 4.65f;
800     std::vector<ColorQuad> colors;
801     std::vector<scalar> position;
802     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::COLOR_SHADER, centerPoint,
803         colors, position, TileMode::REPEAT, startAngle, endAngle, nullptr);
804     ASSERT_TRUE(newShaderEffect != nullptr);
805 }
806 
807 /*
808  * @tc.name: ArgsContructor018
809  * @tc.desc:
810  * @tc.type: FUNC
811  * @tc.require: AR000GGNV3
812  * @tc.author:
813  */
814 HWTEST_F(ShaderEffectTest, ArgsContructor019, TestSize.Level1)
815 {
816     Point startPoint;
817     Point endPoint;
818     std::vector<Color4f> colors;
819     colors.push_back({0.1, 0.1, 0.1, 1.0f});
820     std::vector<scalar> position;
821     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
822     Matrix matrix;
823     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::LINEAR_GRADIENT, startPoint,
824         endPoint, colors, colorSpace, position, TileMode::REPEAT, &matrix);
825     ASSERT_TRUE(newShaderEffect != nullptr);
826 }
827 
828 /*
829  * @tc.name: ArgsContructor019
830  * @tc.desc:
831  * @tc.type: FUNC
832  * @tc.require: AR000GGNV3
833  * @tc.author:
834  */
835 HWTEST_F(ShaderEffectTest, ArgsContructor020, TestSize.Level1)
836 {
837     Point centerPoint;
838     scalar radius = 55.1f;
839     std::vector<Color4f> colors;
840     colors.push_back({0.1, 0.1, 0.1, 1.0f});
841     std::vector<scalar> position;
842     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
843     TileMode mode = TileMode::REPEAT;
844     Matrix matrix;
845     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::RADIAL_GRADIENT, centerPoint,
846         radius, colors, colorSpace, position, mode, &matrix);
847     ASSERT_TRUE(newShaderEffect != nullptr);
848 }
849 
850 /*
851  * @tc.name: ArgsContructor020
852  * @tc.desc:
853  * @tc.type: FUNC
854  * @tc.require: AR000GGNV3
855  * @tc.author:
856  */
857 HWTEST_F(ShaderEffectTest, ArgsContructor021, TestSize.Level1)
858 {
859     Point startPoint;
860     scalar startRadius = 55.1f;
861     Point endPoint;
862     scalar endRadius = 10.7f;
863     std::vector<Color4f> colors;
864     colors.push_back({0.1, 0.1, 0.1, 1.0f});
865     std::vector<scalar> position;
866     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
867     Matrix matrix;
868     auto newShaderEffect = std::make_unique<ShaderEffect>(ShaderEffect::ShaderEffectType::CONICAL_GRADIENT, startPoint,
869         startRadius, endPoint, endRadius, colors, colorSpace, position, TileMode::REPEAT, &matrix);
870     ASSERT_TRUE(newShaderEffect != nullptr);
871 }
872 
873 /*
874  * @tc.name: ArgsContructor021
875  * @tc.desc:
876  * @tc.type: FUNC
877  * @tc.require: AR000GGNV3
878  * @tc.author:
879  */
880 HWTEST_F(ShaderEffectTest, ArgsContructor022, TestSize.Level1)
881 {
882     Point centerPoint;
883     scalar startAngle = 0.0f;
884     scalar endAngle = 180.0f;
885     std::vector<Color4f> colors;
886     colors.push_back({0.1, 0.1, 0.1, 1.0f});
887     std::vector<scalar> position;
888     std::shared_ptr<ColorSpace> colorSpace = std::make_shared<ColorSpace>();
889     Matrix matrix;
890     auto newShaderEffect = std::make_unique<ShaderEffect>(
891         ShaderEffect::ShaderEffectType::SWEEP_GRADIENT, centerPoint, colors, colorSpace, position, TileMode::REPEAT,
892         startAngle, endAngle, &matrix);
893     ASSERT_TRUE(newShaderEffect != nullptr);
894     auto type = newShaderEffect->GetType();
895     EXPECT_EQ(type, ShaderEffect::ShaderEffectType::SWEEP_GRADIENT);
896 }
897 
898 /*
899  * @tc.name: SetGPUContext001
900  * @tc.desc: test ShaderEffect
901  * @tc.type: FUNC
902  * @tc.require: issue#ICHPKE
903  * @tc.author:
904  */
905 HWTEST_F(ShaderEffectTest, SetGPUContext001, TestSize.Level1)
906 {
907     auto shaderEffect = ShaderEffect::CreateColorShader(Color::COLOR_TRANSPARENT);
908     ASSERT_TRUE(shaderEffect != nullptr);
909 #ifdef RS_ENABLE_GPU
910     auto gpuContext = std::make_shared<GPUContext>();
911     shaderEffect->SetGPUContext(gpuContext);
912 #endif
913 }
914 
915 /*
916  * @tc.name: CreateBlendShader004
917  * @tc.desc: Test CreateBlendShader with Lazy dst shader (should fail)
918  * @tc.type: FUNC
919  * @tc.require: AR000GGNV3
920  * @tc.author:
921  */
922 HWTEST_F(ShaderEffectTest, CreateBlendShader004, TestSize.Level1)
923 {
924     auto baseShader = ShaderEffect::CreateColorShader(0xFF0000FF);
925     auto lazyDstShader = ShaderEffectLazy::CreateBlendShader(baseShader, baseShader, BlendMode::SRC_OVER);
926     auto srcShader = ShaderEffect::CreateColorShader(0xFF00FF00);
927     ASSERT_TRUE(lazyDstShader != nullptr);
928     ASSERT_TRUE(srcShader != nullptr);
929     // Check shader types
930     EXPECT_TRUE(lazyDstShader->IsLazy());
931     EXPECT_FALSE(srcShader->IsLazy());
932 
933     // CreateBlendShader should fail with Lazy dst shader
934     auto blendShader = ShaderEffect::CreateBlendShader(*lazyDstShader, *srcShader, BlendMode::MULTIPLY);
935     EXPECT_TRUE(blendShader == nullptr); // Should return nullptr due to Lazy dst shader
936 }
937 
938 /*
939  * @tc.name: CreateBlendShader005
940  * @tc.desc: Test CreateBlendShader with Lazy src shader (should fail)
941  * @tc.type: FUNC
942  * @tc.require: AR000GGNV3
943  * @tc.author:
944  */
945 HWTEST_F(ShaderEffectTest, CreateBlendShader005, TestSize.Level1)
946 {
947     auto dstShader = ShaderEffect::CreateColorShader(0xFF0000FF);
948     auto baseShader = ShaderEffect::CreateColorShader(0xFF00FF00);
949     auto lazySrcShader = ShaderEffectLazy::CreateBlendShader(baseShader, baseShader, BlendMode::SRC_OVER);
950     ASSERT_TRUE(dstShader != nullptr);
951     ASSERT_TRUE(lazySrcShader != nullptr);
952     // Check shader types
953     EXPECT_FALSE(dstShader->IsLazy());
954     EXPECT_TRUE(lazySrcShader->IsLazy());
955 
956     // CreateBlendShader should fail with Lazy src shader
957     auto blendShader = ShaderEffect::CreateBlendShader(*dstShader, *lazySrcShader, BlendMode::SCREEN);
958     EXPECT_TRUE(blendShader == nullptr); // Should return nullptr due to Lazy src shader
959 }
960 
961 #ifdef ROSEN_OHOS
962 /*
963  * @tc.name: UnmarshallingCompleteRoundTrip001
964  * @tc.desc: Test complete round-trip marshalling and serialization data consistency
965  * @tc.type: FUNC
966  * @tc.require: AR000GGNV3
967  * @tc.author:
968  */
969 HWTEST_F(ShaderEffectTest, UnmarshallingCompleteRoundTrip001, TestSize.Level1)
970 {
971     // Test 1: Complete round-trip with multiple shader types
972     std::vector<std::shared_ptr<ShaderEffect>> testShaders;
973     // ColorShader
974     testShaders.push_back(ShaderEffect::CreateColorShader(Color::COLOR_BLUE));
975 
976     // LinearGradient
977     Point startPt(0, 0);
978     Point endPt(100, 100);
979     std::vector<ColorQuad> colors = {Color::COLOR_RED, Color::COLOR_GREEN, Color::COLOR_BLUE};
980     std::vector<scalar> pos = {0.0f, 0.5f, 1.0f};
981     testShaders.push_back(ShaderEffect::CreateLinearGradient(startPt, endPt, colors, pos, TileMode::CLAMP));
982 
983     // RadialGradient
984     Point center(50, 50);
985     scalar radius = 25.0f;
986     std::vector<ColorQuad> radialColors = {Color::COLOR_BLACK, Color::COLOR_WHITE};
987     std::vector<scalar> radialPos = {0.0f, 1.0f};
988     testShaders.push_back(ShaderEffect::CreateRadialGradient(center,
989         radius, radialColors, radialPos, TileMode::REPEAT));
990 
991     for (auto& originalShader : testShaders) {
992         ASSERT_NE(originalShader, nullptr);
993         auto originalType = originalShader->GetType();
994 
995         // Marshal and unmarshal
996         Parcel parcel;
997         bool marshalResult = originalShader->Marshalling(parcel);
998         EXPECT_TRUE(marshalResult);
999 
1000         bool isValid = true;
1001         auto unmarshaledShader = ShaderEffect::Unmarshalling(parcel, isValid);
1002         EXPECT_NE(unmarshaledShader, nullptr);
1003         EXPECT_TRUE(isValid);
1004         EXPECT_EQ(unmarshaledShader->GetType(), originalType);
1005 
1006         // Verify data serialization consistency
1007         auto originalData = originalShader->Serialize();
1008         auto unmarshaledData = unmarshaledShader->Serialize();
1009         if (originalData && unmarshaledData) {
1010             EXPECT_EQ(originalData->GetSize(), unmarshaledData->GetSize());
1011             const uint8_t* originalBytes = static_cast<const uint8_t*>(originalData->GetData());
1012             const uint8_t* unmarshaledBytes = static_cast<const uint8_t*>(unmarshaledData->GetData());
1013             int memResult = memcmp(originalBytes, unmarshaledBytes, originalData->GetSize());
1014             EXPECT_EQ(memResult, 0);
1015         } else {
1016             // If either serialization fails, both should fail consistently
1017             EXPECT_EQ(originalData, unmarshaledData);
1018         }
1019     }
1020 }
1021 
1022 /*
1023  * @tc.name: UnmarshallingErrorHandling001
1024  * @tc.desc: Test ShaderEffect::Unmarshalling error handling scenarios and boundary conditions
1025  * @tc.type: FUNC
1026  * @tc.require: AR000GGNV3
1027  * @tc.author:
1028  */
1029 HWTEST_F(ShaderEffectTest, UnmarshallingErrorHandling001, TestSize.Level1)
1030 {
1031     // Test 1: Empty parcel
1032     {
1033         Parcel emptyParcel;
1034         bool isValid = true;
1035         auto result = ShaderEffect::Unmarshalling(emptyParcel, isValid);
1036         EXPECT_EQ(result, nullptr);
1037     }
1038 
1039     // Test 2: NO_TYPE - 1 (negative boundary)
1040     {
1041         Parcel parcel;
1042         parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::NO_TYPE) - 1);
1043         bool isValid = true;
1044         auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1045         EXPECT_EQ(result, nullptr); // Should be rejected due to invalid type
1046     }
1047 
1048     // Test 3: NO_TYPE (lower boundary) - can construct empty ShaderEffect
1049     {
1050         Parcel parcel;
1051         parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::NO_TYPE));
1052         parcel.WriteInt32(false);
1053         bool isValid = true;
1054         auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1055         EXPECT_NE(result, nullptr); // Should succeed, creating empty ShaderEffect
1056         EXPECT_TRUE(isValid);
1057         if (result) {
1058             EXPECT_EQ(result->GetType(), ShaderEffect::ShaderEffectType::NO_TYPE);
1059         }
1060     }
1061 
1062     // Test 4: LAZY_SHADER (should be rejected in normal ShaderEffect unmarshalling)
1063     {
1064         Parcel parcel;
1065         parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::LAZY_SHADER));
1066         bool isValid = true;
1067         auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1068         EXPECT_EQ(result, nullptr); // Should be rejected
1069     }
1070 
1071     // Test 5: Beyond LAZY_SHADER (upper boundary + 1)
1072     {
1073         Parcel parcel;
1074         parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::LAZY_SHADER) + 1);
1075         bool isValid = true;
1076         auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1077         EXPECT_EQ(result, nullptr); // Should be rejected due to invalid type
1078     }
1079 
1080     // Test 6: Large invalid value
1081     {
1082         Parcel parcel;
1083         parcel.WriteInt32(999);
1084         bool isValid = true;
1085         auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1086         EXPECT_EQ(result, nullptr); // Should be rejected
1087     }
1088 }
1089 
1090 /*
1091  * @tc.name: MarshallingEmptyData001
1092  * @tc.desc: Test ShaderEffect::Marshalling with empty Serialize data
1093  * @tc.type: FUNC
1094  * @tc.require: AR000GGNV3
1095  */
1096 HWTEST_F(ShaderEffectTest, MarshallingEmptyData001, TestSize.Level1)
1097 {
1098     auto mockShader = std::make_shared<MockShaderEffect>();
1099     Parcel parcel;
1100     // Should succeed even with null Serialize data
1101     bool result = mockShader->Marshalling(parcel);
1102     EXPECT_TRUE(result);
1103 
1104     // Verify the parcel contains the expected structure
1105     // Read type
1106     int32_t type;
1107     EXPECT_TRUE(parcel.ReadInt32(type));
1108     EXPECT_EQ(type, static_cast<int32_t>(ShaderEffect::ShaderEffectType::COLOR_SHADER));
1109 
1110     // Read hasData flag - should be false
1111     bool hasData;
1112     EXPECT_TRUE(parcel.ReadBool(hasData));
1113     EXPECT_FALSE(hasData);
1114 
1115     // No more data should be available since hasData was false
1116     EXPECT_EQ(parcel.GetDataSize() - parcel.GetReadPosition(), 0);
1117 }
1118 
1119 /*
1120  * @tc.name: UnmarshallingEmptyData001
1121  * @tc.desc: Test ShaderEffect::Unmarshalling with empty data marker
1122  * @tc.type: FUNC
1123  * @tc.require: AR000GGNV3
1124  */
1125 HWTEST_F(ShaderEffectTest, UnmarshallingEmptyData001, TestSize.Level1)
1126 {
1127     Parcel parcel;
1128     // Write type
1129     EXPECT_TRUE(parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::COLOR_SHADER)));
1130     // Write hasData as false to simulate empty data scenario
1131     EXPECT_TRUE(parcel.WriteBool(false));
1132 
1133     // Should successfully create empty shader
1134     bool isValid = true;
1135     auto shader = ShaderEffect::Unmarshalling(parcel, isValid);
1136     EXPECT_NE(shader, nullptr);
1137     EXPECT_TRUE(isValid);
1138     EXPECT_EQ(shader->GetType(), ShaderEffect::ShaderEffectType::COLOR_SHADER);
1139 }
1140 
1141 /*
1142  * @tc.name: MarshallingUnmarshallingEmptyData001
1143  * @tc.desc: Test round-trip Marshalling and Unmarshalling with empty data
1144  * @tc.type: FUNC
1145  * @tc.require: AR000GGNV3
1146  */
1147 HWTEST_F(ShaderEffectTest, MarshallingUnmarshallingEmptyData001, TestSize.Level1)
1148 {
1149     auto originalShader = std::make_shared<MockShaderEffect>();
1150     Parcel parcel;
1151     // Marshal - should succeed with empty data
1152     bool marshalResult = originalShader->Marshalling(parcel);
1153     EXPECT_TRUE(marshalResult);
1154 
1155     // Unmarshal - should create empty shader with correct type
1156     bool isValid = true;
1157     auto unmarshaledShader = ShaderEffect::Unmarshalling(parcel, isValid);
1158     EXPECT_NE(unmarshaledShader, nullptr);
1159     EXPECT_TRUE(isValid);
1160     EXPECT_EQ(unmarshaledShader->GetType(), ShaderEffect::ShaderEffectType::COLOR_SHADER);
1161 
1162     // Serialize validation - both should return null consistently
1163     auto originalData = originalShader->Serialize();
1164     auto unmarshaledData = unmarshaledShader->Serialize();
1165     EXPECT_EQ(originalData, nullptr);
1166     EXPECT_EQ(unmarshaledData, nullptr);
1167 }
1168 
1169 /*
1170  * @tc.name: MarshallingCallbackFailure001
1171  * @tc.desc: Test ShaderEffect::Marshalling with callback failure to cover (!callback(parcel, data)) branch
1172  * @tc.type: FUNC
1173  * @tc.require: AR000GGNV3
1174  */
1175 HWTEST_F(ShaderEffectTest, MarshallingCallbackFailure001, TestSize.Level1)
1176 {
1177     // Create a valid shader with non-null Serialize data
1178     ColorQuad color = 0xFF0000FF;
1179     auto shader = ShaderEffect::CreateColorShader(color);
1180     ASSERT_NE(shader, nullptr);
1181 
1182     // Backup original callback
1183     auto originalCallback = ObjectHelper::Instance().GetDataMarshallingCallback();
1184 
1185     // Set a failing callback to trigger the (!callback(parcel, data)) branch
1186     ObjectHelper::Instance().SetDataMarshallingCallback(
__anon0e3502780302(Parcel& parcel, std::shared_ptr<Drawing::Data> data) 1187         [](Parcel& parcel, std::shared_ptr<Drawing::Data> data) -> bool {
1188             return false; // Always fail
1189         }
1190     );
1191 
1192     Parcel parcel;
1193     bool result = shader->Marshalling(parcel);
1194     // Should fail due to callback failure
1195     EXPECT_FALSE(result);
1196 
1197     // Restore original callback
1198     ObjectHelper::Instance().SetDataMarshallingCallback(originalCallback);
1199 }
1200 
1201 /*
1202  * @tc.name: UnmarshallingCallbackNull001
1203  * @tc.desc: Test ShaderEffect::Unmarshalling with null callback to cover (if (!callback)) branch
1204  * @tc.type: FUNC
1205  * @tc.require: AR000GGNV3
1206  */
1207 HWTEST_F(ShaderEffectTest, UnmarshallingCallbackNull001, TestSize.Level1)
1208 {
1209     // Backup original callback
1210     auto originalCallback = ObjectHelper::Instance().GetDataUnmarshallingCallback();
1211 
1212     // Set null callback to trigger the (if (!callback)) branch
1213     ObjectHelper::Instance().SetDataUnmarshallingCallback(nullptr);
1214 
1215     Parcel parcel;
1216     // Write valid type
1217     EXPECT_TRUE(parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::COLOR_SHADER)));
1218     // Write hasData as true to reach the callback check
1219     EXPECT_TRUE(parcel.WriteBool(true));
1220 
1221     bool isValid = true;
1222     auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1223     // Should fail due to null callback
1224     EXPECT_EQ(result, nullptr);
1225 
1226     // Restore original callback
1227     ObjectHelper::Instance().SetDataUnmarshallingCallback(originalCallback);
1228 }
1229 
1230 /*
1231  * @tc.name: MarshallingWriteTypeFailure001
1232  * @tc.desc: Test ShaderEffect::Marshalling with WriteInt32(type) failure
1233  * @tc.type: FUNC
1234  * @tc.require: AR000GGNV3
1235  */
1236 HWTEST_F(ShaderEffectTest, MarshallingWriteTypeFailure001, TestSize.Level1)
1237 {
1238     // Create a valid shader
1239     auto shader = ShaderEffect::CreateColorShader(Color::COLOR_BLUE);
1240     ASSERT_NE(shader, nullptr);
1241 
1242     // Create buffer to fill parcel capacity (200K minimum)
1243     const size_t BUFFER_SIZE = 200 * 1024; // 200K
1244     std::vector<uint8_t> fillBuffer(BUFFER_SIZE, 0xFF);
1245 
1246     // Fill parcel completely, then try Marshalling (should fail on WriteInt32(type))
1247     Parcel parcel;
1248     parcel.SetMaxCapacity(BUFFER_SIZE);
1249     bool fillResult = parcel.WriteBuffer(fillBuffer.data(), BUFFER_SIZE);
1250     EXPECT_TRUE(fillResult);
1251 
1252     bool result = shader->Marshalling(parcel);
1253     EXPECT_FALSE(result); // Should fail due to WriteInt32 failure
1254 }
1255 
1256 /*
1257  * @tc.name: MarshallingWriteHasDataFailure001
1258  * @tc.desc: Test ShaderEffect::Marshalling with WriteBool(hasValidData) failure
1259  * @tc.type: FUNC
1260  * @tc.require: AR000GGNV3
1261  */
1262 HWTEST_F(ShaderEffectTest, MarshallingWriteHasDataFailure001, TestSize.Level1)
1263 {
1264     // Create a valid shader
1265     auto shader = ShaderEffect::CreateColorShader(Color::COLOR_RED);
1266     ASSERT_NE(shader, nullptr);
1267 
1268     // Create buffer to fill parcel capacity (200K minimum)
1269     const size_t BUFFER_SIZE = 200 * 1024; // 200K
1270     std::vector<uint8_t> fillBuffer(BUFFER_SIZE, 0xFF);
1271 
1272     // Fill parcel leaving space for int32 only (4 bytes), should fail on WriteBool
1273     Parcel parcel;
1274     parcel.SetMaxCapacity(BUFFER_SIZE);
1275     bool fillResult = parcel.WriteBuffer(fillBuffer.data(), BUFFER_SIZE - 4);
1276     EXPECT_TRUE(fillResult);
1277 
1278     bool result = shader->Marshalling(parcel);
1279     EXPECT_FALSE(result); // Should fail due to WriteBool failure
1280 }
1281 
1282 /*
1283  * @tc.name: MarshallingCallbackNull001
1284  * @tc.desc: Test ShaderEffect::Marshalling with null DataMarshallingCallback
1285  * @tc.type: FUNC
1286  * @tc.require: AR000GGNV3
1287  */
1288 HWTEST_F(ShaderEffectTest, MarshallingCallbackNull001, TestSize.Level1)
1289 {
1290     // Create a valid shader
1291     auto shader = ShaderEffect::CreateColorShader(Color::COLOR_GREEN);
1292     ASSERT_NE(shader, nullptr);
1293 
1294     // Backup original callback
1295     auto originalCallback = ObjectHelper::Instance().GetDataMarshallingCallback();
1296 
1297     // Set null callback to trigger the (if (!callback)) branch
1298     ObjectHelper::Instance().SetDataMarshallingCallback(nullptr);
1299 
1300     Parcel parcel;
1301     bool result = shader->Marshalling(parcel);
1302     EXPECT_FALSE(result); // Should fail due to null callback
1303 
1304     // Restore original callback
1305     ObjectHelper::Instance().SetDataMarshallingCallback(originalCallback);
1306 }
1307 
1308 /*
1309  * @tc.name: UnmarshallingReadHasDataFailure001
1310  * @tc.desc: Test ShaderEffect::Unmarshalling with ReadBool(hasData) failure
1311  * @tc.type: FUNC
1312  * @tc.require: AR000GGNV3
1313  */
1314 HWTEST_F(ShaderEffectTest, UnmarshallingReadHasDataFailure001, TestSize.Level1)
1315 {
1316     Parcel parcel;
1317     // Write valid type
1318     EXPECT_TRUE(parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::COLOR_SHADER)));
1319     // Don't write hasData bool, leaving parcel incomplete
1320 
1321     bool isValid = true;
1322     auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1323     EXPECT_EQ(result, nullptr); // Should fail due to ReadBool failure
1324 }
1325 
1326 /*
1327  * @tc.name: UnmarshallingCallbackReturnNull001
1328  * @tc.desc: Test ShaderEffect::Unmarshalling with callback returning null data
1329  * @tc.type: FUNC
1330  * @tc.require: AR000GGNV3
1331  */
1332 HWTEST_F(ShaderEffectTest, UnmarshallingCallbackReturnNull001, TestSize.Level1)
1333 {
1334     // Backup original callback
1335     auto originalCallback = ObjectHelper::Instance().GetDataUnmarshallingCallback();
1336 
1337     // Set callback that returns null data to trigger the (if (!data)) branch
1338     ObjectHelper::Instance().SetDataUnmarshallingCallback(
__anon0e3502780402(Parcel& parcel) 1339         [](Parcel& parcel) -> std::shared_ptr<Drawing::Data> {
1340             return nullptr; // Always return null
1341         }
1342     );
1343 
1344     Parcel parcel;
1345     // Write valid type
1346     EXPECT_TRUE(parcel.WriteInt32(static_cast<int32_t>(ShaderEffect::ShaderEffectType::COLOR_SHADER)));
1347     // Write hasData as true to reach the callback
1348     EXPECT_TRUE(parcel.WriteBool(true));
1349 
1350     bool isValid = true;
1351     auto result = ShaderEffect::Unmarshalling(parcel, isValid);
1352     EXPECT_EQ(result, nullptr); // Should fail due to null data from callback
1353 
1354     // Restore original callback
1355     ObjectHelper::Instance().SetDataUnmarshallingCallback(originalCallback);
1356 }
1357 #endif
1358 
1359 } // namespace Drawing
1360 } // namespace Rosen
1361 } // namespace OHOS