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 "image_source_encoder_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void ImageSourceEncoderTest::SetUpTestCase(void) {}
23 
TearDownTestCase(void)24 void ImageSourceEncoderTest::TearDownTestCase(void) {}
25 
SetUp(void)26 void ImageSourceEncoderTest::SetUp(void)
27 {
28     std::shared_ptr<IImageSourceProcessorListener> imageListener = nullptr;
29     encoder = std::make_shared<ImageSourceEncoder>(imageListener);
30 }
31 
TearDown(void)32 void ImageSourceEncoderTest::TearDown(void)
33 {
34     if (encoder != nullptr) {
35         encoder->StopEncoder();
36         encoder->ReleaseEncoder();
37     }
38 }
39 
40 /**
41  * @tc.name: ConfigureEncoder_001
42  * @tc.desc: Verify the ConfigureEncoder function.
43  * @tc.type: FUNC
44  * @tc.require: Issue Number
45  */
46 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_001, TestSize.Level1)
47 {
48     VideoParam configParam;
49     configParam.SetCodecType(2);
50     int32_t actual = encoder->ConfigureEncoder(configParam);
51     EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual);
52 }
53 
54 /**
55  * @tc.name: ConfigureEncoder_002
56  * @tc.desc: Verify the ConfigureEncoder function.
57  * @tc.type: FUNC
58  * @tc.require: Issue Number
59  */
60 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_002, TestSize.Level1)
61 {
62     VideoParam configParam;
63     configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
64     int32_t actual = encoder->ConfigureEncoder(configParam);
65     EXPECT_EQ(ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED, actual);
66 }
67 
68 /**
69  * @tc.name: ConfigureEncoder_003
70  * @tc.desc: Verify the ConfigureEncoder function.
71  * @tc.type: FUNC
72  * @tc.require: Issue Number
73  */
74 
75 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_004, TestSize.Level1)
76 {
77     VideoParam configParam;
78     configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
79     configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH);
80     configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT);
81 
82     int32_t actual = encoder->ConfigureEncoder(configParam);
83     EXPECT_EQ(DH_SUCCESS, actual);
84 }
85 
86 /**
87  * @tc.name: ReleaseEncoder_001
88  * @tc.desc: Verify the ReleaseEncoder function.
89  * @tc.type: FUNC
90  * @tc.require: Issue Number
91  */
92 HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_001, TestSize.Level1)
93 {
94     int32_t actual = encoder->ReleaseEncoder();
95     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
96 }
97 
98 /**
99  * @tc.name: ReleaseEncoder_002
100  * @tc.desc: Verify the ReleaseEncoder function.
101  * @tc.type: FUNC
102  * @tc.require: Issue Number
103  */
104 HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_002, TestSize.Level1)
105 {
106     encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime(
107         std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC));
108 
109     int32_t actual = encoder->ReleaseEncoder();
110     EXPECT_EQ(DH_SUCCESS, actual);
111 }
112 
113 /**
114  * @tc.name: StartEncoder_001
115  * @tc.desc: Verify the StartEncoder function.
116  * @tc.type: FUNC
117  * @tc.require: Issue Number
118  */
119 HWTEST_F(ImageSourceEncoderTest, StartEncoder_001, TestSize.Level1)
120 {
121     int32_t actual = encoder->StartEncoder();
122     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
123 }
124 
125 /**
126  * @tc.name: StartEncoder_002
127  * @tc.desc: Verify the StartEncoder function.
128  * @tc.type: FUNC
129  * @tc.require: Issue Number
130  */
131 HWTEST_F(ImageSourceEncoderTest, StartEncoder_002, TestSize.Level1)
132 {
133     encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime(
134         std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC));
135     int32_t actual = encoder->StartEncoder();
136     EXPECT_EQ(ERR_DH_SCREEN_CODEC_START_FAILED, actual);
137 }
138 
139 /**
140  * @tc.name: StopEncoder_001
141  * @tc.desc: Verify the StopEncoder function.
142  * @tc.type: FUNC
143  * @tc.require: Issue Number
144  */
145 HWTEST_F(ImageSourceEncoderTest, StopEncoder_001, TestSize.Level1)
146 {
147     int32_t actual = encoder->StopEncoder();
148     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
149 }
150 
151 /**
152  * @tc.name: StopEncoder_002
153  * @tc.desc: Verify the StartEncoder function.
154  * @tc.type: FUNC
155  * @tc.require: Issue Number
156  */
157 HWTEST_F(ImageSourceEncoderTest, StopEncoder_002, TestSize.Level1)
158 {
159     encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime(
160         std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC));
161 
162     int32_t actual = encoder->StopEncoder();
163     EXPECT_EQ(ERR_DH_SCREEN_CODEC_STOP_FAILED, actual);
164 }
165 
166 /**
167  * @tc.name: InitVideoEncoder_001
168  * @tc.desc: Verify the InitVideoEncoder function.
169  * @tc.type: FUNC
170  * @tc.require: Issue Number
171  */
172 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_001, TestSize.Level1)
173 {
174     VideoParam configParam;
175     configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
176 
177     int32_t actual = encoder->InitVideoEncoder(configParam);
178     EXPECT_EQ(DH_SUCCESS, actual);
179 }
180 
181 /**
182  * @tc.name: InitVideoEncoder_002
183  * @tc.desc: Verify the InitVideoEncoder function.
184  * @tc.type: FUNC
185  * @tc.require: Issue Number
186  */
187 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_002, TestSize.Level1)
188 {
189     VideoParam configParam;
190     configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4;
191 
192     int32_t actual = encoder->InitVideoEncoder(configParam);
193     EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual);
194 }
195 
196 /**
197  * @tc.name: InitVideoEncoder_003
198  * @tc.desc: Verify the InitVideoEncoder function.
199  * @tc.type: FUNC
200  * @tc.require: Issue Number
201  */
202 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_003, TestSize.Level1)
203 {
204     VideoParam configParam;
205     configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H265;
206 
207     int32_t actual = encoder->InitVideoEncoder(configParam);
208     EXPECT_EQ(DH_SUCCESS, actual);
209 }
210 
211 /**
212  * @tc.name: InitVideoEncoder_004
213  * @tc.desc: Verify the InitVideoEncoder function.
214  * @tc.type: FUNC
215  * @tc.require: Issue Number
216  */
217 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_004, TestSize.Level1)
218 {
219     VideoParam configParam;
220     configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
221 
222     int32_t actual = encoder->InitVideoEncoder(configParam);
223     EXPECT_EQ(DH_SUCCESS, actual);
224 }
225 
226 /**
227  * @tc.name: SetEncoderFormat_001
228  * @tc.desc: Verify the SetEncoderFormat function.
229  * @tc.type: FUNC
230  * @tc.require: Issue Number
231  */
232 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_001, TestSize.Level1)
233 {
234     VideoParam configParam;
235     int32_t actual = encoder->SetEncoderFormat(configParam);
236     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
237 }
238 
239 /**
240  * @tc.name: SetEncoderFormat_002
241  * @tc.desc: Verify the SetEncoderFormat function.
242  * @tc.type: FUNC
243  * @tc.require: Issue Number
244  */
245 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_002, TestSize.Level1)
246 {
247     VideoParam configParam;
248     configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
249     int32_t actual = encoder->InitVideoEncoder(configParam);
250     configParam.codecType_ = -1;
251     actual = encoder->SetEncoderFormat(configParam);
252     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
253 }
254 
255 /**
256  * @tc.name: SetEncoderFormat_003
257  * @tc.desc: Verify the SetEncoderFormat function.
258  * @tc.type: FUNC
259  * @tc.require: Issue Number
260  */
261 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_003, TestSize.Level1)
262 {
263     VideoParam configParam;
264     configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
265     configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH);
266     configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT);
267     int32_t actual = encoder->InitVideoEncoder(configParam);
268     actual = encoder->SetEncoderFormat(configParam);
269 
270     EXPECT_EQ(DH_SUCCESS, actual);
271 }
272 
273 /**
274  * @tc.name: SetEncoderFormat_004
275  * @tc.desc: Verify the SetEncoderFormat function.
276  * @tc.type: FUNC
277  * @tc.require: Issue Number
278  */
279 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_004, TestSize.Level1)
280 {
281     VideoParam configParam;
282     configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H265);
283     configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH);
284     configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT);
285     int32_t actual = encoder->InitVideoEncoder(configParam);
286     actual = encoder->SetEncoderFormat(configParam);
287 
288     EXPECT_EQ(DH_SUCCESS, actual);
289 }
290 
291 
292 /**
293  * @tc.name: SetEncoderFormat_007
294  * @tc.desc: Verify the SetEncoderFormat function.
295  * @tc.type: FUNC
296  * @tc.require: Issue Number
297  */
298 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_007, TestSize.Level1)
299 {
300     VideoParam configParam;
301     configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H265);
302     configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH);
303     configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT);
304     int32_t actual = encoder->InitVideoEncoder(configParam);
305     configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_MPEG4);
306     actual = encoder->SetEncoderFormat(configParam);
307     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
308 }
309 
310 } // DistributedHardware
311 } // OHOS