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 "input_unittest.h"
17 #include "input.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 */
HWTEST_F(InputUnittest, SetValue001, TestSize.Level1)31 HWTEST_F(InputUnittest, SetValue001, TestSize.Level1)
32 {
33 GTEST_LOG_(INFO) << "InputUnittest SetValue001 start";
34 /**
35 * @tc.steps: step1. Create a Filter pointer
36 */
37 auto input = std::make_shared<Input>();
38 bool testResult = input != nullptr;
39 EXPECT_TRUE(testResult);
40 /**
41 * @tc.steps: step2. Call SetValue to set the necessary values
42 */
43 auto inputFormat = std::make_shared<std::string>("jpg");
44 auto inputSrc = std::make_shared<std::string>("test.jpg");
45 std::weak_ptr<void> vInputFormat = inputFormat;
46 std::weak_ptr<void> vInputSrc = inputSrc;
47 input->SetValue("format", vInputFormat.lock(), 1);
48 input->SetValue("src", vInputSrc.lock(), 1);
49 }
50
51 /**
52 * @tc.name: SetValue002
53 * @tc.desc: Set some parameters required when the program is compiled
54 * @tc.type: FUNC
55 * @tc.require:
56 * @tc.author:
57 */
HWTEST_F(InputUnittest, SetValue002, TestSize.Level1)58 HWTEST_F(InputUnittest, SetValue002, TestSize.Level1)
59 {
60 GTEST_LOG_(INFO) << "InputUnittest SetValue002 start";
61 /**
62 * @tc.steps: step1. Create a Filter pointer
63 */
64 auto input = std::make_shared<Input>();
65 bool testResult = input != nullptr;
66 EXPECT_TRUE(testResult);
67 /**
68 * @tc.steps: step2. Call SetValue to set the necessary values
69 */
70 auto inputFormat = std::make_shared<std::string>("png");
71 auto inputSrc = std::make_shared<std::string>("test.png");
72 std::weak_ptr<void> vInputFormat = inputFormat;
73 std::weak_ptr<void> vInputSrc = inputSrc;
74 input->SetValue("format", vInputFormat.lock(), 1);
75 input->SetValue("src", vInputSrc.lock(), 1);
76 }
77
78 /**
79 * @tc.name: SetValue003
80 * @tc.desc: Set some parameters required when the program is compiled
81 * @tc.type: FUNC
82 * @tc.require:
83 * @tc.author:
84 */
HWTEST_F(InputUnittest, SetValue003, TestSize.Level1)85 HWTEST_F(InputUnittest, SetValue003, TestSize.Level1)
86 {
87 GTEST_LOG_(INFO) << "InputUnittest SetValue003 start";
88 /**
89 * @tc.steps: step1. Create a Filter pointer
90 */
91 auto input = std::make_shared<Input>();
92 bool testResult = input != nullptr;
93 EXPECT_TRUE(testResult);
94 /**
95 * @tc.steps: step2. Call SetValue to set the necessary values
96 */
97 auto inputFormat = std::make_shared<std::string>("pixelMap");
98 std::weak_ptr<void> vInputFormat = inputFormat;
99 input->SetValue("format", vInputFormat.lock(), 1);
100 Media::InitializationOptions opts;
101 opts.size.width = 512;
102 opts.size.height = 512;
103 opts.editable = true;
104 auto pixelMap = Media::PixelMap::Create(opts);
105 auto shpPixelMap = std::shared_ptr<Media::PixelMap>(pixelMap.release());
106 std::weak_ptr<void> vPixelMap = shpPixelMap;
107 input->SetValue("src", vPixelMap.lock(), 1);
108 }
109
110 /**
111 * @tc.name: SetValue004
112 * @tc.desc: Set some parameters required when the program is compiled
113 * @tc.type: FUNC
114 * @tc.require:
115 * @tc.author:
116 */
HWTEST_F(InputUnittest, SetValue004, TestSize.Level1)117 HWTEST_F(InputUnittest, SetValue004, TestSize.Level1)
118 {
119 GTEST_LOG_(INFO) << "InputUnittest SetValue004 start";
120 /**
121 * @tc.steps: step1. Create a Filter pointer
122 */
123 auto input = std::make_shared<Input>();
124 bool testResult = input != nullptr;
125 EXPECT_TRUE(testResult);
126 /**
127 * @tc.steps: step2. Call SetValue to set the necessary values
128 */
129 auto inputFormat = std::make_shared<std::string>("buffer");
130 std::weak_ptr<void> vInputFormat = inputFormat;
131 input->SetValue("format", vInputFormat.lock(), 1);
132
133 ProcessData data;
134 input->DoProcess(data);
135
136 Media::InitializationOptions opts;
137 opts.size.width = 512;
138 opts.size.height = 512;
139 opts.editable = true;
140 auto pixelMap = Media::PixelMap::Create(opts);
141 auto shpPixelMap = std::shared_ptr<Media::PixelMap>(pixelMap.release());
142 std::weak_ptr<void> vPixelMap = shpPixelMap;
143 input->SetValue("src", vPixelMap.lock(), 1);
144 input->DecodeFromBuffer(data);
145
146 EXPECT_TRUE(input->GetFilterType() == FILTER_TYPE::INPUT);
147 }
148
149 /**
150 * @tc.name: SetValue005
151 * @tc.desc: Set some parameters required when the program is compiled
152 * @tc.type: FUNC
153 * @tc.require:
154 * @tc.author:
155 */
HWTEST_F(InputUnittest, SetValue005, TestSize.Level1)156 HWTEST_F(InputUnittest, SetValue005, TestSize.Level1)
157 {
158 GTEST_LOG_(INFO) << "InputUnittest SetValue005 start";
159 /**
160 * @tc.steps: step1. Create a Filter pointer
161 */
162 auto input = std::make_shared<Input>();
163 bool testResult = input != nullptr;
164 EXPECT_TRUE(testResult);
165 /**
166 * @tc.steps: step2. Call SetValue to set the necessary values
167 */
168 auto inputFormat = std::make_shared<std::string>("buffer");
169 std::weak_ptr<void> vInputFormat = inputFormat;
170 input->SetValue("bufferWidth", vInputFormat.lock(), 1);
171
172 Media::InitializationOptions opts;
173 opts.size.width = 512;
174 opts.size.height = 512;
175 opts.editable = true;
176 auto pixelMap = Media::PixelMap::Create(opts);
177 auto shpPixelMap = std::shared_ptr<Media::PixelMap>(pixelMap.release());
178 std::weak_ptr<void> vPixelMap = shpPixelMap;
179 input->SetValue("bufferHeight", vPixelMap.lock(), 1);
180
181 EXPECT_TRUE(input->GetFilterType() != FILTER_TYPE::OUTPUT);
182 }
183
184 /**
185 * @tc.name: DoProcess001
186 * @tc.desc: Obtain the type of filter according to different implementations of the interface
187 * @tc.type: FUNC
188 * @tc.require:
189 * @tc.author:
190 */
HWTEST_F(InputUnittest, DoProcess001, TestSize.Level1)191 HWTEST_F(InputUnittest, DoProcess001, TestSize.Level1)
192 {
193 GTEST_LOG_(INFO) << "InputUnittest DoProcess001 start";
194 /**
195 * @tc.steps: step1. Create a Filter pointer
196 */
197 auto input = std::make_shared<Input>();
198 bool testResult = input != nullptr;
199 EXPECT_TRUE(testResult);
200 /**
201 * @tc.steps: step2. Call GetFilterType to get the type of Filter
202 */
203 auto inputFormat = std::make_shared<std::string>("jpg");
204 std::weak_ptr<void> vInputFormat = inputFormat;
205 input->SetValue("format", vInputFormat.lock(), 1);
206
207 ProcessData data;
208 input->DoProcess(data);
209 input->DecodeFromFile(data);
210
211 EXPECT_TRUE(input->GetFilterType() != FILTER_TYPE::OUTPUT);
212 }
213
214 /**
215 * @tc.name: DecodeFrom001
216 * @tc.desc: Obtain the type of filter according to different implementations of the interface
217 * @tc.type: FUNC
218 * @tc.require:
219 * @tc.author:
220 */
HWTEST_F(InputUnittest, DecodeFrom001, TestSize.Level1)221 HWTEST_F(InputUnittest, DecodeFrom001, TestSize.Level1)
222 {
223 GTEST_LOG_(INFO) << "InputUnittest DecodeFrom001 start";
224 /**
225 * @tc.steps: step1. Create a Filter pointer
226 */
227 auto input = std::make_shared<Input>();
228 bool testResult = input != nullptr;
229 EXPECT_TRUE(testResult);
230 /**
231 * @tc.steps: step2. Call GetFilterType to get the type of Filter
232 */
233
234 ProcessData data;
235 input->DecodeFromBuffer(data);
236 input->DecodeFromPixelMap(data);
237
238 EXPECT_TRUE(input->GetFilterType() == FILTER_TYPE::INPUT);
239 }
240
241 /**
242 * @tc.name: GetFilterType001
243 * @tc.desc: Obtain the type of filter according to different implementations of the interface
244 * @tc.type: FUNC
245 * @tc.require:
246 * @tc.author:
247 */
HWTEST_F(InputUnittest, GetFilterType001, TestSize.Level1)248 HWTEST_F(InputUnittest, GetFilterType001, TestSize.Level1)
249 {
250 GTEST_LOG_(INFO) << "InputUnittest GetFilterType001 start";
251 /**
252 * @tc.steps: step1. Create a Filter pointer
253 */
254 auto input = std::make_shared<Input>();
255 bool testResult = input != nullptr;
256 EXPECT_TRUE(testResult);
257 /**
258 * @tc.steps: step2. Call GetFilterType to get the type of Filter
259 */
260 EXPECT_TRUE(input->GetFilterType() == FILTER_TYPE::INPUT);
261 }
262
263 /**
264 * @tc.name: GetFilterType002
265 * @tc.desc: Obtain the type of filter according to different implementations of the interface
266 * @tc.type: FUNC
267 * @tc.require:
268 * @tc.author:
269 */
HWTEST_F(InputUnittest, GetFilterType002, TestSize.Level1)270 HWTEST_F(InputUnittest, GetFilterType002, TestSize.Level1)
271 {
272 GTEST_LOG_(INFO) << "InputUnittest GetFilterType002 start";
273 /**
274 * @tc.steps: step1. Create a Filter pointer
275 */
276 auto input = std::make_shared<Input>();
277 bool testResult = input != nullptr;
278 EXPECT_TRUE(testResult);
279 /**
280 * @tc.steps: step2. Call GetFilterType to get the type of Filter
281 */
282 EXPECT_TRUE(input->GetFilterType() != FILTER_TYPE::OUTPUT);
283 }
284
285 /**
286 * @tc.name: GetFilterType003
287 * @tc.desc: Obtain the type of filter according to different implementations of the interface
288 * @tc.type: FUNC
289 * @tc.require:
290 * @tc.author:
291 */
HWTEST_F(InputUnittest, GetFilterType003, TestSize.Level1)292 HWTEST_F(InputUnittest, GetFilterType003, TestSize.Level1)
293 {
294 GTEST_LOG_(INFO) << "InputUnittest GetFilterType003 start";
295 /**
296 * @tc.steps: step1. Create a Filter pointer
297 */
298 auto input = std::make_shared<Input>();
299 bool testResult = input != nullptr;
300 EXPECT_TRUE(testResult);
301 /**
302 * @tc.steps: step2. Call GetFilterType to get the type of Filter
303 */
304 EXPECT_TRUE(input->GetFilterType() != FILTER_TYPE::ALGOFILTER);
305 }
306 } // namespace Rosen
307 } // namespace OHOS
308