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 "scale_filter_unittest.h" 17 #include "scale_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(ScaleFilterUnittest, SetValue001, TestSize.Level1) 32 { 33 GTEST_LOG_(INFO) << "ScaleFilterUnittest SetValue001 start"; 34 /** 35 * @tc.steps: step1. Create a Filter pointer 36 */ 37 auto scale = std::make_shared<ScaleFilter>(); 38 bool testResult = scale != nullptr; 39 EXPECT_TRUE(testResult); 40 /** 41 * @tc.steps: step2. Call SetValue to set the necessary values 42 */ 43 std::shared_ptr<float> sScale = std::make_shared<float>(0.0f); 44 std::weak_ptr<void> vScale = sScale; 45 scale->SetValue("scale", vScale.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(ScaleFilterUnittest, SetValue002, TestSize.Level1) 56 { 57 GTEST_LOG_(INFO) << "ScaleFilterUnittest SetValue002 start"; 58 /** 59 * @tc.steps: step1. Create a Filter pointer 60 */ 61 auto scale = std::make_shared<ScaleFilter>(); 62 bool testResult = scale != nullptr; 63 EXPECT_TRUE(testResult); 64 /** 65 * @tc.steps: step2. Call SetValue to set the necessary values 66 */ 67 std::shared_ptr<float> sScale = std::make_shared<float>(0.5f); 68 std::weak_ptr<void> vScale = sScale; 69 scale->SetValue("scale", vScale.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(ScaleFilterUnittest, SetValue003, TestSize.Level1) 80 { 81 GTEST_LOG_(INFO) << "ScaleFilterUnittest SetValue003 start"; 82 /** 83 * @tc.steps: step1. Create a Filter pointer 84 */ 85 auto scale = std::make_shared<ScaleFilter>(); 86 bool testResult = scale != nullptr; 87 EXPECT_TRUE(testResult); 88 /** 89 * @tc.steps: step2. Call SetValue to set the necessary values 90 */ 91 std::shared_ptr<float> sScale = std::make_shared<float>(1.0f); 92 std::weak_ptr<void> vScale = sScale; 93 scale->SetValue("scale", vScale.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(ScaleFilterUnittest, GetVertexShader001, TestSize.Level1) 104 { 105 GTEST_LOG_(INFO) << "ScaleFilterUnittest GetVertexShader001 start"; 106 /** 107 * @tc.steps: step1. Create a Filter pointer 108 */ 109 auto scale = std::make_shared<ScaleFilter>(); 110 bool testResult = scale != 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 layout (location = 0) in vec3 vertexCoord; 118 layout (location = 1) in vec2 inputTexCoord; 119 out vec2 texCoord; 120 121 void main() 122 { 123 gl_Position = vec4(vertexCoord, 1.0); 124 texCoord = inputTexCoord; 125 } 126 )SHADER"; 127 EXPECT_TRUE(scale->GetVertexShader() == result); 128 } 129 130 /** 131 * @tc.name: GetVertexShader002 132 * @tc.desc: Get a string used to compile the program. 133 * @tc.type: FUNC 134 * @tc.require: 135 * @tc.author: 136 */ 137 HWTEST_F(ScaleFilterUnittest, GetVertexShader002, TestSize.Level1) 138 { 139 GTEST_LOG_(INFO) << "ScaleFilterUnittest GetVertexShader002 start"; 140 /** 141 * @tc.steps: step1. Create a Filter pointer 142 */ 143 auto scale = std::make_shared<ScaleFilter>(); 144 bool testResult = scale != nullptr; 145 EXPECT_TRUE(testResult); 146 /** 147 * @tc.steps: step2. Call GetVertexShader to get the strings 148 */ 149 string result = ""; 150 EXPECT_TRUE(scale->GetVertexShader() != result); 151 } 152 153 /** 154 * @tc.name: GetFragmentShader001 155 * @tc.desc: Get a string used to compile the program. 156 * @tc.type: FUNC 157 * @tc.require: 158 * @tc.author: 159 */ 160 HWTEST_F(ScaleFilterUnittest, GetFragmentShader001, TestSize.Level1) 161 { 162 GTEST_LOG_(INFO) << "ScaleFilterUnittest GetFragmentShader001 start"; 163 /** 164 * @tc.steps: step1. Create a Filter pointer 165 */ 166 auto scale = std::make_shared<ScaleFilter>(); 167 bool testResult = scale != nullptr; 168 EXPECT_TRUE(testResult); 169 /** 170 * @tc.steps: step2. Call GetFragmentShader to get the strings 171 */ 172 std::string result = R"SHADER(#version 320 es 173 precision mediump float; 174 in vec2 texCoord; 175 out vec4 fragColor; 176 uniform sampler2D uTexture; 177 void main() 178 { 179 fragColor = texture(uTexture, texCoord); 180 } 181 )SHADER"; 182 EXPECT_TRUE(scale->GetFragmentShader() == result); 183 } 184 185 /** 186 * @tc.name: GetFragmentShader002 187 * @tc.desc: Get a string used to compile the program. 188 * @tc.type: FUNC 189 * @tc.require: 190 * @tc.author: 191 */ 192 HWTEST_F(ScaleFilterUnittest, GetFragmentShader002, TestSize.Level1) 193 { 194 GTEST_LOG_(INFO) << "ScaleFilterUnittest GetFragmentShader002 start"; 195 /** 196 * @tc.steps: step1. Create a Filter pointer 197 */ 198 auto scale = std::make_shared<ScaleFilter>(); 199 bool testResult = scale != nullptr; 200 EXPECT_TRUE(testResult); 201 /** 202 * @tc.steps: step2. Call GetFragmentShader to get the strings 203 */ 204 string result = ""; 205 EXPECT_TRUE(scale->GetFragmentShader() != result); 206 } 207 } // namespace Rosen 208 } // namespace OHOS 209