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 "saturation_filter_unittest.h"
17 #include "saturation_filter.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace Rosen {
24 /**
25  * @tc.name: SetValue001
26  * @tc.desc: Set some parameters required when the program is compiled
27  * @tc.type: FUNC
28  * @tc.require:
29  * @tc.author:
30  */
31 HWTEST_F(SaturationFilterUnittest, SetValue001, TestSize.Level1)
32 {
33     GTEST_LOG_(INFO) << "SaturationFilterUnittest SetValue001 start";
34     /**
35      * @tc.steps: step1. Create a Filter pointer
36      */
37     auto saturation = std::make_shared<SaturationFilter>();
38     bool testResult = saturation != nullptr;
39     EXPECT_TRUE(testResult);
40     /**
41      * @tc.steps: step2. Call SetValue to set the necessary values
42      */
43     std::shared_ptr<float> sSaturation = std::make_shared<float>(0.0f);
44     std::weak_ptr<void> vSaturation = sSaturation;
45     saturation->SetValue("saturation", vSaturation.lock(), 1);
46 }
47 
48 /**
49  * @tc.name: SetValue002
50  * @tc.desc: Set some parameters required when the program is compiled
51  * @tc.type: FUNC
52  * @tc.require:
53  * @tc.author:
54  */
55 HWTEST_F(SaturationFilterUnittest, SetValue002, TestSize.Level1)
56 {
57     GTEST_LOG_(INFO) << "SaturationFilterUnittest SetValue002 start";
58     /**
59      * @tc.steps: step1. Create a Filter pointer
60      */
61     auto saturation = std::make_shared<SaturationFilter>();
62     bool testResult = saturation != nullptr;
63     EXPECT_TRUE(testResult);
64     /**
65      * @tc.steps: step2. Call SetValue to set the necessary values
66      */
67     std::shared_ptr<float> sSaturation = std::make_shared<float>(0.5f);
68     std::weak_ptr<void> vSaturation = sSaturation;
69     saturation->SetValue("saturation", vSaturation.lock(), 1);
70 }
71 
72 /**
73  * @tc.name: SetValue003
74  * @tc.desc: Set some parameters required when the program is compiled
75  * @tc.type: FUNC
76  * @tc.require:
77  * @tc.author:
78  */
79 HWTEST_F(SaturationFilterUnittest, SetValue003, TestSize.Level1)
80 {
81     GTEST_LOG_(INFO) << "SaturationFilterUnittest SetValue003 start";
82     /**
83      * @tc.steps: step1. Create a Filter pointer
84      */
85     auto saturation = std::make_shared<SaturationFilter>();
86     bool testResult = saturation != nullptr;
87     EXPECT_TRUE(testResult);
88     /**
89      * @tc.steps: step2. Call SetValue to set the necessary values
90      */
91     std::shared_ptr<float> sSaturation = std::make_shared<float>(1.0f);
92     std::weak_ptr<void> vSaturation = sSaturation;
93     saturation->SetValue("saturation", vSaturation.lock(), 1);
94 }
95 
96 /**
97  * @tc.name: GetVertexShader001
98  * @tc.desc: Get a string used to compile the program
99  * @tc.type: FUNC
100  * @tc.require:
101  * @tc.author:
102  */
103 HWTEST_F(SaturationFilterUnittest, GetVertexShader001, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "SaturationFilterUnittest GetVertexShader001 start";
106     /**
107      * @tc.steps: step1. Create a Filter pointer
108      */
109     auto saturation = std::make_shared<SaturationFilter>();
110     bool testResult = saturation != nullptr;
111     EXPECT_TRUE(testResult);
112     /**
113      * @tc.steps: step2. Call GetVertexShader to get the strings
114      */
115     std::string result = R"SHADER(#version 320 es
116         precision mediump float;
117 
118         layout (location = 0) in vec3 vertexCoord;
119         layout (location = 1) in vec2 inputTexCoord;
120         out vec2 texCoord;
121 
122         void main()
123         {
124             gl_Position = vec4(vertexCoord, 1.0);
125             texCoord = inputTexCoord;
126         }
127     )SHADER";
128     EXPECT_TRUE(saturation->GetVertexShader() == result);
129 }
130 
131 /**
132  * @tc.name: GetVertexShader002
133  * @tc.desc: Get a string used to compile the program
134  * @tc.type: FUNC
135  * @tc.require:
136  * @tc.author:
137  */
138 HWTEST_F(SaturationFilterUnittest, GetVertexShader002, TestSize.Level1)
139 {
140     GTEST_LOG_(INFO) << "SaturationFilterUnittest GetVertexShader002 start";
141     /**
142      * @tc.steps: step1. Create a Filter pointer
143      */
144     auto saturation = std::make_shared<SaturationFilter>();
145     bool testResult = saturation != nullptr;
146     EXPECT_TRUE(testResult);
147     /**
148      * @tc.steps: step2. Call GetVertexShader to get the strings
149      */
150     string result = "";
151     EXPECT_TRUE(saturation->GetVertexShader() != result);
152 }
153 
154 /**
155  * @tc.name: GetFragmentShader001
156  * @tc.desc: Get a string used to compile the program
157  * @tc.type: FUNC
158  * @tc.require:
159  * @tc.author:
160  */
161 HWTEST_F(SaturationFilterUnittest, GetFragmentShader001, TestSize.Level1)
162 {
163     GTEST_LOG_(INFO) << "SaturationFilterUnittest GetFragmentShader001 start";
164     /**
165      * @tc.steps: step1. Create a Filter pointer
166      */
167     auto saturation = std::make_shared<SaturationFilter>();
168     bool testResult = saturation != nullptr;
169     EXPECT_TRUE(testResult);
170     /**
171      * @tc.steps: step2. Call GetFragmentShader to get the strings
172      */
173     std::string result = R"SHADER(#version 320 es
174         precision mediump float;
175         in vec2 texCoord;
176         out vec4 fragColor;
177         uniform sampler2D uTexture;
178         uniform float saturation;
179         const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
180         void main()
181         {
182             vec4 textureColor = texture(uTexture, texCoord);
183             float luminance = dot(textureColor.rgb, luminanceWeighting);
184             vec3 greyScaleColor = vec3(luminance);
185 
186             fragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.a);
187         }
188     )SHADER";
189     EXPECT_TRUE(saturation->GetFragmentShader() == result);
190 }
191 
192 /**
193  * @tc.name: GetFragmentShader002
194  * @tc.desc: Get a string used to compile the program
195  * @tc.type: FUNC
196  * @tc.require:
197  * @tc.author:
198  */
199 HWTEST_F(SaturationFilterUnittest, GetFragmentShader002, TestSize.Level1)
200 {
201     GTEST_LOG_(INFO) << "SaturationFilterUnittest GetFragmentShader002 start";
202     /**
203      * @tc.steps: step1. Create a Filter pointer
204      */
205     auto saturation = std::make_shared<SaturationFilter>();
206     bool testResult = saturation != nullptr;
207     EXPECT_TRUE(testResult);
208     /**
209      * @tc.steps: step2. Call GetFragmentShader to get the strings
210      */
211     string result = "";
212     EXPECT_TRUE(saturation->GetFragmentShader() != result);
213 }
214 } // namespace Rosen
215 } // namespace OHOS
216