• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_contour_diagonal_flow_light_shader.h"
18 #include "ge_log.h"
19 #include "draw/canvas.h"
20 #include "image/bitmap.h"
21 #include "utils/rect.h"
22 #include "draw/color.h"
23 #include "draw/path.h"
24 #include "ge_shader_filter_params.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::Rosen;
29 using namespace Drawing;
30 
31 namespace OHOS {
32 namespace Rosen {
33 
34 class GEContourDiagonalFlowLightShaderTest : public Test {
35 public:
SetUpTestCase()36     static void SetUpTestCase()
37     {}
TearDownTestCase()38     static void TearDownTestCase()
39     {}
SetUp()40     void SetUp() override
41     {}
TearDown()42     void TearDown() override
43     {}
44 
45     static inline Canvas canvas_;
46 };
47 
48 HWTEST_F(GEContourDiagonalFlowLightShaderTest, CreateFlowLightShader_001, TestSize.Level1)
49 {
50     // Test case for static CreateFlowLightShader method
51     GEContentDiagonalFlowLightShaderParams params;
52     params.line1Start_ = 0.0f;
53     params.line1Length_ = 0.3f;
54     params.line1Color_ = Vector4f(0.1f, 0.2f, 0.3f, 0.4f);
55     params.line2Start_ = 0.5f;
56     params.line2Length_ = 0.3f;
57     params.line2Color_ = Vector4f(0.5f, 0.6f, 0.7f, 0.8f);
58     params.thickness_ = 0.02f;
59 
60     auto shader = GEContourDiagonalFlowLightShader::CreateFlowLightShader(params);
61     EXPECT_NE(shader, nullptr);
62 }
63 
64 HWTEST_F(GEContourDiagonalFlowLightShaderTest, GEContourDiagonalFlowLightShaderConstructor_001, TestSize.Level1)
65 {
66     // Test case for constructor with parameters
67     GEContentDiagonalFlowLightShaderParams testParams;
68     testParams.line1Start_ = 0.2f;
69     testParams.line1Length_ = 0.3f;
70     testParams.line1Color_ = Vector4f(0.6f, 0.3f, 0.9f, 1.0f);
71     testParams.line2Start_ = 0.7f;
72     testParams.line2Length_ = 0.5f;
73     testParams.line2Color_ = Vector4f(0.5f, 0.6f, 0.7f, 0.8f);
74     testParams.thickness_ = 0.2f;
75 
76     GEContourDiagonalFlowLightShader shader(testParams);
77     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line1Start_, testParams.line1Start_);
78     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line1Length_, testParams.line1Length_);
79     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line1Color_[0], testParams.line1Color_[0]);
80     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line1Color_[1], testParams.line1Color_[1]);
81     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line1Color_[2], testParams.line1Color_[2]);
82     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line1Color_[3], testParams.line1Color_[3]);
83     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line2Start_, testParams.line2Start_);
84     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line2Length_, testParams.line2Length_);
85     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line2Color_[0], testParams.line2Color_[0]);
86     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line2Color_[1], testParams.line2Color_[1]);
87     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line2Color_[2], testParams.line2Color_[2]);
88     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.line2Color_[3], testParams.line2Color_[3]);
89     EXPECT_FLOAT_EQ(shader.contourDiagonalFlowLightParams_.thickness_, testParams.thickness_);
90 }
91 HWTEST_F(GEContourDiagonalFlowLightShaderTest, MakeDrawingShader_001, TestSize.Level1)
92 {
93     // Test case for MakeDrawingShader method
94     Drawing::Rect rect(0, 0, 100, 100);
95     float progress = 0.5f;
96     GEContentDiagonalFlowLightShaderParams params;
97     params.line1Start_ = 0.5f;
98     params.line1Length_ = 0.6f;
99     params.line1Color_ = Vector4f(0.6f, 0.3f, 0.9f, 1.0f);
100     params.line2Start_ = 0.0f;
101     params.line2Length_ = 0.2f;
102     params.line2Color_ = Vector4f(0.67f, 0.24f, 0.35f, 0.8f);
103     params.thickness_ = 0.25f;
104     auto shader = GEContourDiagonalFlowLightShader::CreateFlowLightShader(params);
105     shader->MakeDrawingShader(rect, progress);
106     EXPECT_EQ(shader->GetDrawingShader(), nullptr); // no cache
107 }
108 
109 HWTEST_F(GEContourDiagonalFlowLightShaderTest, Preprocess_001, TestSize.Level1)
110 {
111     // Test case for Preprocess method
112     Drawing::Rect rect(0, 0, 100, 100);
113     GEContentDiagonalFlowLightShaderParams params;
114     params.line1Start_ = 0.1f;
115     params.line1Length_ = 0.6f;
116     params.line1Color_ = Vector4f(0.6f, 0.3f, 0.9f, 1.0f);
117     params.line2Start_ = 0.6f;
118     params.line2Length_ = 0.2f;
119     params.line2Color_ = Vector4f(0.67f, 0.24f, 0.9f, 0.8f);
120     params.thickness_ = 0.25f;
121     auto shader = GEContourDiagonalFlowLightShader::CreateFlowLightShader(params);
122     shader->Preprocess(canvas_, rect);
123     auto cache = shader->GetCache();
124     EXPECT_EQ(cache, nullptr); // less point
125 }
126 
127 HWTEST_F(GEContourDiagonalFlowLightShaderTest, GetContourDiagonalFlowLightBuilder_001, TestSize.Level1)
128 {
129     // Test case for GetContourDiagonalFlowLightBuilder method
130     GEContentDiagonalFlowLightShaderParams params;
131     params.line1Start_ = 0.2f;
132     params.line1Length_ = 0.8f;
133     params.line1Color_ = Vector4f(0.0f, 1.0f, 1.0f, 1.0f);
134     params.line2Start_ = 0.7f;
135     params.line2Length_ = 0.3f;
136     params.line2Color_ = Vector4f(1.0f, 0.0f, 1.0f, 1.0f);
137     params.thickness_ = 0.4f;
138     auto shader = GEContourDiagonalFlowLightShader::CreateFlowLightShader(params);
139     auto builder = shader->GetContourDiagonalFlowLightBuilder();
140     EXPECT_NE(builder, nullptr);
141 }
142 
143 HWTEST_F(GEContourDiagonalFlowLightShaderTest, DrawRuntimeShader_001, TestSize.Level1)
144 {
145     // Test case for DrawRuntimeShader method
146     Drawing::Rect rect(0, 0, 100, 100);
147     GEContentDiagonalFlowLightShaderParams params;
148     params.line1Start_ = 0.05f;
149     params.line1Length_ = 0.6f;
150     params.line1Color_ = Vector4f(0.8f, 0.5f, 1.0f, 1.0f);
151     params.line2Start_ = 0.55f;
152     params.line2Length_ = 0.2f;
153     params.line2Color_ = Vector4f(0.2f, 0.6f, 1.0f, 0.8f);
154     params.thickness_ = 0.5f;
155     auto shader = GEContourDiagonalFlowLightShader::CreateFlowLightShader(params);
156     auto img = shader->DrawRuntimeShader(canvas_, rect);
157     EXPECT_EQ(img, nullptr);
158 }
159 }
160 }