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 "filter_unittest.h"
17 #include "filter.h"
18 #include "filter_factory.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 /**
26  * @tc.name: SetValue001
27  * @tc.desc: Set some parameters required when the program is compiled
28  * @tc.type: FUNC
29  * @tc.require:
30  * @tc.author:
31  */
32 HWTEST_F(FilterUnittest, SetValue001, TestSize.Level1)
33 {
34     GTEST_LOG_(INFO) << "FilterUnittest SetValue001 start";
35     /**
36      * @tc.steps: step1. Create a Filter pointer
37      */
38     FilterFactory filterFactory;
39     auto brightness = filterFactory.GetFilter("Brightness");
40     bool testResult = brightness != nullptr;
41     EXPECT_TRUE(testResult);
42     /**
43      * @tc.steps: step2. Call SetValue to set the necessary values
44      */
45     std::shared_ptr<float> sBright = std::make_shared<float>(0.0f);
46     std::weak_ptr<void> vBright = sBright;
47     brightness->SetValue("brightness", vBright.lock(), 1);
48 }
49 
50 /**
51  * @tc.name: SetValue002
52  * @tc.desc: Set some parameters required when the program is compiled
53  * @tc.type: FUNC
54  * @tc.require:
55  * @tc.author:
56  */
57 HWTEST_F(FilterUnittest, SetValue002, TestSize.Level1)
58 {
59     GTEST_LOG_(INFO) << "FilterUnittest SetValue002 start";
60     /**
61      * @tc.steps: step1. Create a Filter pointer
62      */
63     FilterFactory filterFactory;
64     auto saturation = filterFactory.GetFilter("Saturation");
65     bool testResult = saturation != nullptr;
66     EXPECT_TRUE(testResult);
67     /**
68      * @tc.steps: step2. Call SetValue to set the necessary values
69      */
70     std::shared_ptr<float> sSaturation = std::make_shared<float>(0.0f);
71     std::weak_ptr<void> vSaturation = sSaturation;
72     saturation->SetValue("saturation", vSaturation.lock(), 1);
73 }
74 
75 /**
76  * @tc.name: SetValue003
77  * @tc.desc: Set some parameters required when the program is compiled
78  * @tc.type: FUNC
79  * @tc.require:
80  * @tc.author:
81  */
82 HWTEST_F(FilterUnittest, SetValue003, TestSize.Level1)
83 {
84     GTEST_LOG_(INFO) << "FilterUnittest SetValue003 start";
85     /**
86      * @tc.steps: step1. Create a Filter pointer
87      */
88     FilterFactory filterFactory;
89     auto contrast = filterFactory.GetFilter("Contrast");
90     bool testResult = contrast != nullptr;
91     EXPECT_TRUE(testResult);
92     /**
93      * @tc.steps: step2. Call SetValue to set the necessary values
94      */
95     std::shared_ptr<float> sContrast = std::make_shared<float>(0.0f);
96     std::weak_ptr<void> vContrast = sContrast;
97     contrast->SetValue("contrast", vContrast.lock(), 1);
98 }
99 
100 /**
101  * @tc.name:Process001
102  * @tc.desc: Action required when rendering
103  * @tc.type: FUNC
104  * @tc.require:
105  * @tc.author:
106  */
107 HWTEST_F(FilterUnittest, Process001, TestSize.Level1)
108 {
109     GTEST_LOG_(INFO) << "FilterUnittestProcess001 start";
110     /**
111      * @tc.steps: step1. Create a Filter pointer
112      */
113     FilterFactory filterFactory;
114     auto contrast = filterFactory.GetFilter("Contrast");
115     bool testResult1 = contrast != nullptr;
116     EXPECT_TRUE(testResult1);
117     ProcessData data;
118     data.srcTextureID = 0;
119     data.dstTextureID = 0;
120     data.frameBufferID = 0;
121     data.textureWidth = 1;
122     data.textureHeight = 1;
123     /**
124      * @tc.steps: step2. Call Process to execute during rendering
125      */
126     auto testResult2 = contrast->Process(data);
127     EXPECT_TRUE(testResult2);
128 }
129 
130 /**
131  * @tc.name:Process002
132  * @tc.desc: Action required when rendering
133  * @tc.type: FUNC
134  * @tc.require:
135  * @tc.author:
136  */
137 HWTEST_F(FilterUnittest, Process002, TestSize.Level1)
138 {
139     GTEST_LOG_(INFO) << "FilterUnittestProcess002 start";
140     /**
141      * @tc.steps: step1. Create a Filter pointer
142      */
143     FilterFactory filterFactory;
144     auto contrast = filterFactory.GetFilter("Contrast");
145     bool testResult1 = contrast != nullptr;
146     EXPECT_TRUE(testResult1);
147     ProcessData data;
148     data.srcTextureID = 0;
149     data.dstTextureID = 0;
150     data.frameBufferID = 0;
151     data.textureWidth = 0;
152     data.textureHeight = 0;
153 
154     /**
155      * @tc.steps: step2. Call Process to execute during rendering
156      */
157     auto testResult2 = contrast->Process(data);
158     EXPECT_FALSE(testResult2);
159 }
160 
161 /**
162  * @tc.name: AddNextFilter001
163  * @tc.desc: Add the next filter to the linked list
164  * @tc.type: FUNC
165  * @tc.require:
166  * @tc.author:
167  */
168 HWTEST_F(FilterUnittest, AddNextFilter001, TestSize.Level1)
169 {
170     GTEST_LOG_(INFO) << "FilterUnittest AddNextFilter001 start";
171     /**
172      * @tc.steps: step1. Create two Filter pointers
173      */
174     FilterFactory filterFactory;
175     auto input = filterFactory.GetFilter("Input");
176     auto output = filterFactory.GetFilter("Output");
177     bool testResult1 = input != nullptr;
178     bool testResult2 = output != nullptr;
179     EXPECT_TRUE(testResult1);
180     EXPECT_TRUE(testResult2);
181     /**
182      * @tc.steps: step2. Call AddNextFilter to execute before rendering
183      */
184     input->AddNextFilter(output);
185 }
186 
187 /**
188  * @tc.name: AddNextFilter002
189  * @tc.desc: Add the next filter to the linked list
190  * @tc.type: FUNC
191  * @tc.require:
192  * @tc.author:
193  */
194 HWTEST_F(FilterUnittest, AddNextFilter002, TestSize.Level1)
195 {
196     GTEST_LOG_(INFO) << "FilterUnittest AddNextFilter002 start";
197     /**
198      * @tc.steps: step1. Create a Filter pointer
199      */
200     FilterFactory filterFactory;
201     auto input = filterFactory.GetFilter("Input");
202     bool testResult = input != nullptr;
203     EXPECT_TRUE(testResult);
204     /**
205      * @tc.steps: step2. Call AddNextFilter to execute before rendering
206      */
207     input->AddNextFilter(nullptr);
208 }
209 
210 /**
211  * @tc.name: GetNextFilter001
212  * @tc.desc: Get the next filter of the current filter.
213  * @tc.type: FUNC
214  * @tc.require:
215  * @tc.author:
216  */
217 HWTEST_F(FilterUnittest, GetNextFilter001, TestSize.Level1)
218 {
219     GTEST_LOG_(INFO) << "FilterUnittest GetNextFilter001 start";
220     /**
221      * @tc.steps: step1. Create two Filter pointers
222      */
223     FilterFactory filterFactory;
224     auto input = filterFactory.GetFilter("Input");
225     auto output = filterFactory.GetFilter("Output");
226     bool testResult1 = input != nullptr;
227     bool testResult2 = output != nullptr;
228     EXPECT_TRUE(testResult1);
229     EXPECT_TRUE(testResult2);
230     input->AddNextFilter(output);
231     /**
232      * @tc.steps: step2. Call GetNextFilter to execute before rendering
233      */
234     auto nextFilter = input->GetNextFilter();
235     bool testResult3 = nextFilter.get() == output.get();
236     EXPECT_TRUE(testResult3);
237 }
238 
239 /**
240  * @tc.name: GetNextFilter002
241  * @tc.desc: Get the next filter of the current filter.
242  * @tc.type: FUNC
243  * @tc.require:
244  * @tc.author:
245  */
246 HWTEST_F(FilterUnittest, GetNextFilter002, TestSize.Level1)
247 {
248     GTEST_LOG_(INFO) << "FilterUnittest GetNextFilter002 start";
249     /**
250      * @tc.steps: step1. Create a Filter pointer
251      */
252     FilterFactory filterFactory;
253     auto input = filterFactory.GetFilter("Input");
254     bool testResult = input != nullptr;
255     EXPECT_TRUE(testResult);
256     input->AddNextFilter(nullptr);
257     /**
258      * @tc.steps: step2. Call GetNextFilter to execute before rendering
259      */
260     auto nextFilter = input->GetNextFilter();
261     bool testResult3 = nextFilter == nullptr;
262     EXPECT_TRUE(testResult3);
263 }
264 
265 /**
266  * @tc.name: AddPreviousFilter001
267  * @tc.desc: Add the previous filter to the linked list.
268  * @tc.type: FUNC
269  * @tc.require:
270  * @tc.author:
271  */
272 HWTEST_F(FilterUnittest, AddPreviousFilter001, TestSize.Level1)
273 {
274     GTEST_LOG_(INFO) << "FilterUnittest AddPreviousFilter001 start";
275     /**
276      * @tc.steps: step1. Create two Filter pointers
277      */
278     FilterFactory filterFactory;
279     auto input = filterFactory.GetFilter("Input");
280     auto output = filterFactory.GetFilter("Output");
281     bool testResult1 = input != nullptr;
282     bool testResult2 = output != nullptr;
283     EXPECT_TRUE(testResult1);
284     EXPECT_TRUE(testResult2);
285     /**
286      * @tc.steps: step2. Call AddPreviousFilter to execute before rendering
287      */
288     output->AddPreviousFilter(output);
289 }
290 
291 /**
292  * @tc.name: AddPreviousFilter002
293  * @tc.desc: Add the previous filter to the linked list.
294  * @tc.type: FUNC
295  * @tc.require:
296  * @tc.author:
297  */
298 HWTEST_F(FilterUnittest, AddPreviousFilter002, TestSize.Level1)
299 {
300     GTEST_LOG_(INFO) << "FilterUnittest AddPreviousFilter002 start";
301     /**
302      * @tc.steps: step1. Create a Filter pointer
303      */
304     FilterFactory filterFactory;
305     auto output = filterFactory.GetFilter("Output");
306     bool testResult = output != nullptr;
307     EXPECT_TRUE(testResult);
308     /**
309      * @tc.steps: step2. Call AddPreviousFilter to execute before rendering
310      */
311     output->AddPreviousFilter(nullptr);
312 }
313 
314 /**
315  * @tc.name: GetPreviousFilter001
316  * @tc.desc: Get the previous filter of the current filter.
317  * @tc.type: FUNC
318  * @tc.require:
319  * @tc.author:
320  */
321 HWTEST_F(FilterUnittest, GetPreviousFilter001, TestSize.Level1)
322 {
323     GTEST_LOG_(INFO) << "FilterUnittest GetPreviousFilter001 start";
324     /**
325      * @tc.steps: step1. Create two Filter pointers
326      */
327     FilterFactory filterFactory;
328     auto input = filterFactory.GetFilter("Input");
329     auto output = filterFactory.GetFilter("Output");
330     bool testResult1 = input != nullptr;
331     bool testResult2 = output != nullptr;
332     EXPECT_TRUE(testResult1);
333     EXPECT_TRUE(testResult2);
334     output->AddPreviousFilter(input);
335     /**
336      * @tc.steps: step2. Call GetPreviousFilter to execute before rendering
337      */
338     auto preFilter = output->GetPreviousFilter();
339     bool testResult3 = preFilter.get() == input.get();
340     EXPECT_TRUE(testResult3);
341 }
342 
343 /**
344  * @tc.name: GetPreviousFilter002
345  * @tc.desc: Get the previous filter of the current filter.
346  * @tc.type: FUNC
347  * @tc.require:
348  * @tc.author:
349  */
350 HWTEST_F(FilterUnittest, GetPreviousFilter002, TestSize.Level1)
351 {
352     GTEST_LOG_(INFO) << "FilterUnittest GetPreviousFilter002 start";
353     /**
354      * @tc.steps: step1. Create a Filter pointer
355      */
356     FilterFactory filterFactory;
357     auto output = filterFactory.GetFilter("Output");
358     bool testResult = output != nullptr;
359     EXPECT_TRUE(testResult);
360     output->AddPreviousFilter(nullptr);
361     /**
362      * @tc.steps: step2. Call AddPreviousFilter to execute before rendering
363      */
364     auto preFilter = output->GetNextFilter();
365     bool testResult3 = preFilter == nullptr;
366     EXPECT_TRUE(testResult3);
367 }
368 
369 /**
370  * @tc.name: GetInputNumber001
371  * @tc.desc: Get the number of filters before the current filter.
372  * @tc.type: FUNC
373  * @tc.require:
374  * @tc.author:
375  */
376 HWTEST_F(FilterUnittest, GetInputNumber001, TestSize.Level1)
377 {
378     GTEST_LOG_(INFO) << "FilterUnittest GetInputNumber001 start";
379     /**
380      * @tc.steps: step1. Create two Filter pointers
381      */
382     FilterFactory filterFactory;
383     auto input = filterFactory.GetFilter("Input");
384     auto output = filterFactory.GetFilter("Output");
385     bool testResult1 = input != nullptr;
386     bool testResult2 = output != nullptr;
387     EXPECT_TRUE(testResult1);
388     EXPECT_TRUE(testResult2);
389     output->AddPreviousFilter(input);
390     /**
391      * @tc.steps: step2. Call GetInputNumber to execute before rendering
392      */
393     auto testResult3 = output->GetInputNumber();
394     EXPECT_EQ(testResult3, 1);
395 }
396 
397 /**
398  * @tc.name: GetInputNumber002
399  * @tc.desc: Get the number of filters before the current filter.
400  * @tc.type: FUNC
401  * @tc.require:
402  * @tc.author:
403  */
404 HWTEST_F(FilterUnittest, GetInputNumber002, TestSize.Level1)
405 {
406     GTEST_LOG_(INFO) << "FilterUnittest GetInputNumber002 start";
407     /**
408      * @tc.steps: step1. Create a Filter pointer
409      */
410     FilterFactory filterFactory;
411     auto input = filterFactory.GetFilter("Input");
412     bool testResult1 = input != nullptr;
413     EXPECT_TRUE(testResult1);
414     /**
415      * @tc.steps: step2. Call GetInputNumber to execute before rendering
416      */
417     auto testResult2 = input->GetInputNumber();
418     EXPECT_EQ(testResult2, 0);
419 }
420 
421 /**
422  * @tc.name: GetOutputNumber001
423  * @tc.desc: Get the number of filters after the current filter.
424  * @tc.type: FUNC
425  * @tc.require:
426  * @tc.author:
427  */
428 HWTEST_F(FilterUnittest, GetOutputNumber001, TestSize.Level1)
429 {
430     GTEST_LOG_(INFO) << "FilterUnittest GetOutputNumber001 start";
431     /**
432      * @tc.steps: step1. Create two Filter pointers
433      */
434     FilterFactory filterFactory;
435     auto input = filterFactory.GetFilter("Input");
436     auto output = filterFactory.GetFilter("Output");
437     bool testResult1 = input != nullptr;
438     bool testResult2 = output != nullptr;
439     EXPECT_TRUE(testResult1);
440     EXPECT_TRUE(testResult2);
441     input->AddNextFilter(output);
442     /**
443      * @tc.steps: step2. Call GetOutputNumber to execute before rendering
444      */
445     auto testResult3 = input->GetOutputNumber();
446     EXPECT_EQ(testResult3, 1);
447 }
448 
449 /**
450  * @tc.name: GetOutputNumber002
451  * @tc.desc: Get the number of filters after the current filter.
452  * @tc.type: FUNC
453  * @tc.require:
454  * @tc.author:
455  */
456 HWTEST_F(FilterUnittest, GetOutputNumber002, TestSize.Level1)
457 {
458     GTEST_LOG_(INFO) << "FilterUnittest GetOutputNumber002 start";
459     /**
460      * @tc.steps: step1. Create a Filter pointer
461      */
462     FilterFactory filterFactory;
463     auto input = filterFactory.GetFilter("Input");
464     bool testResult1 = input != nullptr;
465     EXPECT_TRUE(testResult1);
466     /**
467      * @tc.steps: step2. Call GetInputNumber to execute before rendering
468      */
469     auto testResult2 = input->GetOutputNumber();
470     EXPECT_EQ(testResult2, 0);
471 }
472 
473 /**
474  * @tc.name: GetMaxInputNumber001
475  * @tc.desc: Get the maximum number of filters before the current filter.
476  * @tc.type: FUNC
477  * @tc.require:
478  * @tc.author:
479  */
480 HWTEST_F(FilterUnittest, GetMaxInputNumber001, TestSize.Level1)
481 {
482     GTEST_LOG_(INFO) << "FilterUnittest GetMaxInputNumber001 start";
483     /**
484      * @tc.steps: step1. Create two Filter pointers
485      */
486     FilterFactory filterFactory;
487     auto input = filterFactory.GetFilter("Input");
488     bool testResult1 = input != nullptr;
489     EXPECT_TRUE(testResult1);
490     /**
491      * @tc.steps: step2. Call GetMaxInputNumber to execute before rendering
492      */
493     auto testResult2 = input->GetMaxInputNumber();
494     EXPECT_EQ(testResult2, 1);
495 }
496 
497 /**
498  * @tc.name: GetMaxOutputNumber001
499  * @tc.desc: Get the maximum number of filters after the current filter.
500  * @tc.type: FUNC
501  * @tc.require:
502  * @tc.author:
503  */
504 HWTEST_F(FilterUnittest, GetMaxOutputNumber001, TestSize.Level1)
505 {
506     GTEST_LOG_(INFO) << "FilterUnittest GetMaxOutputNumber001 start";
507     /**
508      * @tc.steps: step1. Create a Filter pointer
509      */
510     FilterFactory filterFactory;
511     auto input = filterFactory.GetFilter("Input");
512     bool testResult1 = input != nullptr;
513     EXPECT_TRUE(testResult1);
514     /**
515      * @tc.steps: step2. Call GetInputNumber to execute before rendering
516      */
517     auto testResult2 = input->GetMaxOutputNumber();
518     EXPECT_EQ(testResult2, 1);
519 }
520 } // namespace Rosen
521 } // namespace OHOS
522