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 "contrast_filter_unittest.h"
17 #include "contrast_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(ContrastFilterUnittest, SetValue001, TestSize.Level1)
32 {
33     GTEST_LOG_(INFO) << "ContrastFilterUnittest SetValue001 start";
34     /**
35      * @tc.steps: step1. Create a Filter pointer
36      */
37     auto contrast = std::make_shared<ContrastFilter>();
38     bool testResult = contrast != nullptr;
39     EXPECT_TRUE(testResult);
40     /**
41      * @tc.steps: step2. Call SetValue to set the necessary values
42      */
43     std::shared_ptr<float> sContrast = std::make_shared<float>(0.0f);
44     std::weak_ptr<void> vContrast = sContrast;
45     contrast->SetValue("contrast", vContrast.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(ContrastFilterUnittest, SetValue002, TestSize.Level1)
56 {
57     GTEST_LOG_(INFO) << "ContrastFilterUnittest SetValue002 start";
58     /**
59      * @tc.steps: step1. Create a Filter pointer
60      */
61     auto contrast = std::make_shared<ContrastFilter>();
62     bool testResult = contrast != nullptr;
63     EXPECT_TRUE(testResult);
64     /**
65      * @tc.steps: step2. Call SetValue to set the necessary values
66      */
67     std::shared_ptr<float> sContrast = std::make_shared<float>(0.5f);
68     std::weak_ptr<void> vContrast = sContrast;
69     contrast->SetValue("contrast", vContrast.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(ContrastFilterUnittest, SetValue003, TestSize.Level1)
80 {
81     GTEST_LOG_(INFO) << "ContrastFilterUnittest SetValue003 start";
82     /**
83      * @tc.steps: step1. Create a Filter pointer
84      */
85     auto contrast = std::make_shared<ContrastFilter>();
86     bool testResult = contrast != nullptr;
87     EXPECT_TRUE(testResult);
88     /**
89      * @tc.steps: step2. Call SetValue to set the necessary values
90      */
91     std::shared_ptr<float> sContrast = std::make_shared<float>(1.0f);
92     std::weak_ptr<void> vContrast = sContrast;
93     contrast->SetValue("contrast", vContrast.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(ContrastFilterUnittest, GetVertexShader001, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "ContrastFilterUnittest GetVertexShader001 start";
106     /**
107      * @tc.steps: step1. Create a Filter pointer
108      */
109     auto contrast = std::make_shared<ContrastFilter>();
110     bool testResult = contrast != 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(contrast->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(ContrastFilterUnittest, GetVertexShader002, TestSize.Level1)
139 {
140     GTEST_LOG_(INFO) << "ContrastFilterUnittest GetVertexShader002 start";
141     /**
142      * @tc.steps: step1. Create a Filter pointer
143      */
144     auto contrast = std::make_shared<ContrastFilter>();
145     bool testResult = contrast != nullptr;
146     EXPECT_TRUE(testResult);
147     /**
148      * @tc.steps: step2. Call GetVertexShader to get the strings
149      */
150     string result = "";
151     EXPECT_TRUE(contrast->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(ContrastFilterUnittest, GetFragmentShader001, TestSize.Level1)
162 {
163     GTEST_LOG_(INFO) << "ContrastFilterUnittest GetFragmentShader001 start";
164     /**
165      * @tc.steps: step1. Create a Filter pointer
166      */
167     auto contrast = std::make_shared<ContrastFilter>();
168     bool testResult = contrast != 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 contrast;
179         void main()
180         {
181             vec4 textureColor = texture(uTexture, texCoord);
182             fragColor = vec4(((textureColor.rgb - 0.5) * contrast + 0.5), textureColor.a);
183         }
184     )SHADER";
185     EXPECT_TRUE(contrast->GetFragmentShader() == result);
186 }
187 
188 /**
189  * @tc.name: GetFragmentShader002
190  * @tc.desc: Get a string used to compile the program
191  * @tc.type: FUNC
192  * @tc.require:
193  * @tc.author:
194  */
195 HWTEST_F(ContrastFilterUnittest, GetFragmentShader002, TestSize.Level1)
196 {
197     GTEST_LOG_(INFO) << "ContrastFilterUnittest GetFragmentShader002 start";
198     /**
199      * @tc.steps: step1. Create a Filter pointer
200      */
201     auto contrast = std::make_shared<ContrastFilter>();
202     bool testResult = contrast != nullptr;
203     EXPECT_TRUE(testResult);
204     /**
205      * @tc.steps: step2. Call GetFragmentShader to get the strings
206      */
207     string result = "";
208     EXPECT_TRUE(contrast->GetFragmentShader() != result);
209 }
210 } // namespace Rosen
211 } // namespace OHOS
212