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  */
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  */
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  */
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: GetFilterType001
112  * @tc.desc: Obtain the type of filter according to different implementations of the interface
113  * @tc.type: FUNC
114  * @tc.require:
115  * @tc.author:
116  */
117 HWTEST_F(InputUnittest, GetFilterType001, TestSize.Level1)
118 {
119     GTEST_LOG_(INFO) << "InputUnittest GetFilterType001 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 GetFilterType to get the type of Filter
128      */
129     EXPECT_TRUE(input->GetFilterType() == FILTER_TYPE::INPUT);
130 }
131 
132 /**
133  * @tc.name: GetFilterType002
134  * @tc.desc: Obtain the type of filter according to different implementations of the interface
135  * @tc.type: FUNC
136  * @tc.require:
137  * @tc.author:
138  */
139 HWTEST_F(InputUnittest, GetFilterType002, TestSize.Level1)
140 {
141     GTEST_LOG_(INFO) << "InputUnittest GetFilterType002 start";
142     /**
143      * @tc.steps: step1. Create a Filter pointer
144      */
145     auto input = std::make_shared<Input>();
146     bool testResult = input != nullptr;
147     EXPECT_TRUE(testResult);
148     /**
149      * @tc.steps: step2. Call GetFilterType to get the type of Filter
150      */
151     EXPECT_TRUE(input->GetFilterType() != FILTER_TYPE::OUTPUT);
152 }
153 
154 /**
155  * @tc.name: GetFilterType003
156  * @tc.desc: Obtain the type of filter according to different implementations of the interface
157  * @tc.type: FUNC
158  * @tc.require:
159  * @tc.author:
160  */
161 HWTEST_F(InputUnittest, GetFilterType003, TestSize.Level1)
162 {
163     GTEST_LOG_(INFO) << "InputUnittest GetFilterType003 start";
164     /**
165      * @tc.steps: step1. Create a Filter pointer
166      */
167     auto input = std::make_shared<Input>();
168     bool testResult = input != nullptr;
169     EXPECT_TRUE(testResult);
170     /**
171      * @tc.steps: step2. Call GetFilterType to get the type of Filter
172      */
173     EXPECT_TRUE(input->GetFilterType() != FILTER_TYPE::ALGOFILTER);
174 }
175 } // namespace Rosen
176 } // namespace OHOS
177