1 /*
2 * Copyright (C) 2025 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 <fcntl.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19
20 #include "avtranscoder.h"
21 #include "avtranscoder_unit_test.h"
22 #include "avtranscoder_mock.h"
23 #include "media_errors.h"
24 #include "gtest/gtest.h"
25
26 using namespace OHOS;
27 using namespace OHOS::Media;
28 using namespace testing::ext;
29
30 static const std::string CHINESE_COLOR_MP4 = "/data/test/ChineseColor_H264_AAC_480p_15fps.mp4";
31 static const std::string MOCK_OUTPUT_MP4 = "/data/test/Mock_Output.mp4";
32 static const int32_t ZERO = 0;
33 static const int32_t MOCK_VIDEO_WIDTH = 640;
34 static const int32_t MOCK_VIDEO_HEIGHT = 480;
35 static const int64_t TRANSCODER_FILE_OFFSET = 37508084;
36 static const int64_t TRANSCODER_FILE_SIZE = 2735029;
37 constexpr int32_t TRASCODER_AUDIO_ENCODING_BIT_RATE = 20000;
38 constexpr int32_t TRASCODER_VIDEO_ENCODING_BIT_RATE = 30000;
39 static const int32_t MOCK_NEG = -1;
40
SetUpTestCase(void)41 void NativeAVTranscoderUnitTest::SetUpTestCase(void) {}
42
TearDownTestCase(void)43 void NativeAVTranscoderUnitTest::TearDownTestCase(void) {}
44
SetUp(void)45 void NativeAVTranscoderUnitTest::SetUp(void) {}
46
TearDown(void)47 void NativeAVTranscoderUnitTest::TearDown(void) {}
48
MockOnStateChange(OH_AVTranscoder * transcoder,OH_AVTranscoder_State state,void * userData)49 void MockOnStateChange(OH_AVTranscoder *transcoder, OH_AVTranscoder_State state, void *userData)
50 {
51 if (transcoder == nullptr) {
52 return;
53 }
54 MockUserData* mockUserData = static_cast<MockUserData*>(userData);
55 if (mockUserData == nullptr) {
56 return;
57 }
58 switch (state) {
59 case OH_AVTranscoder_State::AVTRANSCODER_PREPARED:
60 mockUserData->state_ = OH_AVTranscoder_State::AVTRANSCODER_PREPARED;
61 break;
62 case OH_AVTranscoder_State::AVTRANSCODER_STARTED:
63 mockUserData->state_ = OH_AVTranscoder_State::AVTRANSCODER_STARTED;
64 break;
65 case OH_AVTranscoder_State::AVTRANSCODER_PAUSED:
66 mockUserData->state_ = OH_AVTranscoder_State::AVTRANSCODER_PAUSED;
67 break;
68 case OH_AVTranscoder_State::AVTRANSCODER_CANCELLED:
69 mockUserData->state_ = OH_AVTranscoder_State::AVTRANSCODER_CANCELLED;
70 break;
71 case OH_AVTranscoder_State::AVTRANSCODER_COMPLETED:
72 mockUserData->state_ = OH_AVTranscoder_State::AVTRANSCODER_COMPLETED;
73 break;
74 }
75 }
76
MockOnError(OH_AVTranscoder * transcoder,int32_t errorCode,const char * errorMsg,void * userData)77 void MockOnError(OH_AVTranscoder *transcoder, int32_t errorCode, const char *errorMsg,
78 void *userData)
79 {
80 if (transcoder == nullptr) {
81 return;
82 }
83 }
84
MockOnProgressUpdate(OH_AVTranscoder * transcoder,int progress,void * userData)85 void MockOnProgressUpdate(OH_AVTranscoder *transcoder, int progress, void *userData)
86 {
87 if (transcoder == nullptr) {
88 return;
89 }
90 }
91
InitAVTranscoderCallback(OH_AVTranscoder * transcoder,MockUserData & mockUserData)92 void NativeAVTranscoderUnitTest::InitAVTranscoderCallback(OH_AVTranscoder* transcoder, MockUserData& mockUserData)
93 {
94 OH_AVErrCode errorCode{ AV_ERR_OK };
95 errorCode = OH_AVTranscoder_SetErrorCallback(transcoder, MockOnError, static_cast<void*>(&mockUserData));
96 ASSERT_EQ(errorCode, AV_ERR_OK);
97 errorCode = OH_AVTranscoder_SetProgressUpdateCallback(transcoder,
98 MockOnProgressUpdate,
99 static_cast<void*>(&mockUserData));
100 ASSERT_EQ(errorCode, AV_ERR_OK);
101 errorCode = OH_AVTranscoder_SetStateCallback(transcoder,
102 MockOnStateChange,
103 static_cast<void*>(&mockUserData));
104 ASSERT_EQ(errorCode, AV_ERR_OK);
105 }
106
InitAVTranscoderConfig(OH_AVTranscoder_Config * config,int32_t srcFd,int32_t dstFd)107 void NativeAVTranscoderUnitTest::InitAVTranscoderConfig(OH_AVTranscoder_Config* config, int32_t srcFd, int32_t dstFd)
108 {
109 OH_AVErrCode errorCode{ AV_ERR_OK };
110
111 int64_t offset = TRANSCODER_FILE_OFFSET;
112 int64_t size = TRANSCODER_FILE_SIZE;
113 errorCode = OH_AVTranscoderConfig_SetSrcFD(config, srcFd, offset, size);
114 ASSERT_EQ(errorCode, AV_ERR_OK);
115
116 errorCode = OH_AVTranscoderConfig_SetDstFD(config, dstFd);
117 ASSERT_EQ(errorCode, AV_ERR_OK);
118
119 errorCode = OH_AVTranscoderConfig_SetDstFileType(config, OH_AVOutputFormat::AV_OUTPUT_FORMAT_MPEG_4);
120 ASSERT_EQ(errorCode, AV_ERR_OK);
121
122 errorCode = OH_AVTranscoderConfig_SetDstVideoType(config, "video/avc");
123 ASSERT_EQ(errorCode, AV_ERR_OK);
124
125 errorCode = OH_AVTranscoderConfig_SetDstAudioType(config, "audio/mp4a-latm");
126 ASSERT_EQ(errorCode, AV_ERR_OK);
127
128 errorCode = OH_AVTranscoderConfig_SetDstAudioBitrate(config, TRASCODER_AUDIO_ENCODING_BIT_RATE);
129 ASSERT_EQ(errorCode, AV_ERR_OK);
130
131 errorCode = OH_AVTranscoderConfig_SetDstVideoBitrate(config, TRASCODER_VIDEO_ENCODING_BIT_RATE);
132 ASSERT_EQ(errorCode, AV_ERR_OK);
133
134 errorCode = OH_AVTranscoderConfig_SetDstVideoResolution(config, MOCK_VIDEO_WIDTH, MOCK_VIDEO_HEIGHT);
135 ASSERT_EQ(errorCode, AV_ERR_OK);
136 }
137
138 /**
139 * @tc.name: AVTranscoder_Complete001
140 * @tc.desc: Verify the regular transcoding process.
141 * @tc.type: FUNC
142 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Complete001,Level3)143 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Complete001, Level3)
144 {
145 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Complete001 start";
146 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
147 ASSERT_NE(transcoder, nullptr);
148
149 MockUserData mockUserData;
150 InitAVTranscoderCallback(transcoder, mockUserData);
151
152 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
153 ASSERT_NE(config, nullptr);
154 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
155 ASSERT_TRUE(srcFd >= ZERO);
156 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
157 ASSERT_TRUE(dstFd >= ZERO);
158
159 InitAVTranscoderConfig(config, srcFd, dstFd);
160
161 OH_AVErrCode errorCode{ AV_ERR_OK };
162 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
163 ASSERT_EQ(errorCode, AV_ERR_OK);
164
165 errorCode = OH_AVTranscoder_Start(transcoder);
166 ASSERT_EQ(errorCode, AV_ERR_OK);
167
168 errorCode = OH_AVTranscoderConfig_Release(config);
169 ASSERT_EQ(errorCode, AV_ERR_OK);
170 errorCode = OH_AVTranscoder_Release(transcoder);
171 ASSERT_EQ(errorCode, AV_ERR_OK);
172
173 close(srcFd);
174 close(dstFd);
175 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Complete001 end";
176 }
177
178 /**
179 * @tc.name: AVTranscoder_Pause001
180 * @tc.desc: Verify that pause and resume during verification transcoding.
181 * @tc.type: FUNC
182 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Pause001,Level3)183 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Pause001, Level3)
184 {
185 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause001 start";
186 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
187 ASSERT_NE(transcoder, nullptr);
188
189 MockUserData mockUserData;
190 InitAVTranscoderCallback(transcoder, mockUserData);
191
192 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
193 ASSERT_NE(config, nullptr);
194 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
195 ASSERT_TRUE(srcFd >= ZERO);
196 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
197 ASSERT_TRUE(dstFd >= ZERO);
198 InitAVTranscoderConfig(config, srcFd, dstFd);
199
200 OH_AVErrCode errorCode{ AV_ERR_OK };
201 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
202 ASSERT_EQ(errorCode, AV_ERR_OK);
203
204 errorCode = OH_AVTranscoder_Start(transcoder);
205 ASSERT_EQ(errorCode, AV_ERR_OK);
206
207 errorCode = OH_AVTranscoder_Pause(transcoder);
208 ASSERT_EQ(errorCode, AV_ERR_OK);
209
210 errorCode = OH_AVTranscoder_Resume(transcoder);
211 ASSERT_EQ(errorCode, AV_ERR_OK);
212
213 errorCode = OH_AVTranscoderConfig_Release(config);
214 ASSERT_EQ(errorCode, AV_ERR_OK);
215 errorCode = OH_AVTranscoder_Release(transcoder);
216 ASSERT_EQ(errorCode, AV_ERR_OK);
217
218 close(srcFd);
219 close(dstFd);
220 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause001 end";
221 }
222
223 /**
224 * @tc.name: AVTranscoder_Cancel001
225 * @tc.desc: Verify that Cancel operation during transcoding.
226 * @tc.type: FUNC
227 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Cancel001,Level3)228 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Cancel001, Level3)
229 {
230 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel001 start";
231 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
232 ASSERT_NE(transcoder, nullptr);
233
234 MockUserData mockUserData;
235 InitAVTranscoderCallback(transcoder, mockUserData);
236
237 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
238 ASSERT_NE(config, nullptr);
239 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
240 ASSERT_TRUE(srcFd >= ZERO);
241 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
242 ASSERT_TRUE(dstFd >= ZERO);
243 InitAVTranscoderConfig(config, srcFd, dstFd);
244
245 OH_AVErrCode errorCode{ AV_ERR_OK };
246 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
247 ASSERT_EQ(errorCode, AV_ERR_OK);
248
249 errorCode = OH_AVTranscoder_Start(transcoder);
250 ASSERT_EQ(errorCode, AV_ERR_OK);
251
252 errorCode = OH_AVTranscoder_Cancel(transcoder);
253 ASSERT_EQ(errorCode, AV_ERR_OK);
254
255 errorCode = OH_AVTranscoder_Start(transcoder);
256 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
257
258 errorCode = OH_AVTranscoderConfig_Release(config);
259 ASSERT_EQ(errorCode, AV_ERR_OK);
260 errorCode = OH_AVTranscoder_Release(transcoder);
261 ASSERT_EQ(errorCode, AV_ERR_OK);
262
263 close(srcFd);
264 close(dstFd);
265 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel001 end";
266 }
267
268 /**
269 * @tc.name: AVTranscoder_Prepare001
270 * @tc.desc: Verify that repeated prepare operation will fail.
271 * @tc.type: FUNC
272 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Prepare001,Level3)273 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Prepare001, Level3)
274 {
275 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Prepare001 start";
276 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
277 ASSERT_NE(transcoder, nullptr);
278
279 MockUserData mockUserData;
280 InitAVTranscoderCallback(transcoder, mockUserData);
281
282 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
283 ASSERT_NE(config, nullptr);
284 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
285 ASSERT_TRUE(srcFd >= ZERO);
286 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
287 ASSERT_TRUE(dstFd >= ZERO);
288 InitAVTranscoderConfig(config, srcFd, dstFd);
289
290 OH_AVErrCode errorCode{ AV_ERR_OK };
291 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
292 ASSERT_EQ(errorCode, AV_ERR_OK);
293
294 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
295 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
296
297 errorCode = OH_AVTranscoderConfig_Release(config);
298 ASSERT_EQ(errorCode, AV_ERR_OK);
299 errorCode = OH_AVTranscoder_Release(transcoder);
300 ASSERT_EQ(errorCode, AV_ERR_OK);
301
302 close(srcFd);
303 close(dstFd);
304 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Prepare001 end";
305 }
306
307 /**
308 * @tc.name: AVTranscoder_Start001
309 * @tc.desc: Verify that repeated Start operation will not fail.
310 * @tc.type: FUNC
311 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Start001,Level3)312 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Start001, Level3)
313 {
314 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Start001 start";
315 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
316 ASSERT_NE(transcoder, nullptr);
317
318 MockUserData mockUserData;
319 InitAVTranscoderCallback(transcoder, mockUserData);
320
321 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
322 ASSERT_NE(config, nullptr);
323 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
324 ASSERT_TRUE(srcFd >= ZERO);
325 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
326 ASSERT_TRUE(dstFd >= ZERO);
327 InitAVTranscoderConfig(config, srcFd, dstFd);
328
329 OH_AVErrCode errorCode{ AV_ERR_OK };
330 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
331 ASSERT_EQ(errorCode, AV_ERR_OK);
332
333 errorCode = OH_AVTranscoder_Start(transcoder);
334 ASSERT_EQ(errorCode, AV_ERR_OK);
335
336 errorCode = OH_AVTranscoder_Start(transcoder);
337 ASSERT_EQ(errorCode, AV_ERR_OK);
338
339 errorCode = OH_AVTranscoder_Cancel(transcoder);
340 ASSERT_EQ(errorCode, AV_ERR_OK);
341
342 errorCode = OH_AVTranscoderConfig_Release(config);
343 ASSERT_EQ(errorCode, AV_ERR_OK);
344 errorCode = OH_AVTranscoder_Release(transcoder);
345 ASSERT_EQ(errorCode, AV_ERR_OK);
346
347 close(srcFd);
348 close(dstFd);
349 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Start001 end";
350 }
351
352 /**
353 * @tc.name: AVTranscoder_ConfigRelease001
354 * @tc.desc: Verify that call OH_AVTranscoderConfig_Release when input parameter is nullptr will fail.
355 * @tc.type: FUNC
356 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigRelease001,Level3)357 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigRelease001, Level3)
358 {
359 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigRelease001 start";
360 OH_AVErrCode errorCode{ AV_ERR_OK };
361 errorCode = OH_AVTranscoderConfig_Release(nullptr);
362 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
363 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigRelease001 end";
364 }
365
366 /**
367 * @tc.name: AVTranscoder_ConfigSetSrcFD001
368 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetSrcFD when input parameter is invalid.
369 * @tc.type: FUNC
370 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetSrcFD001,Level3)371 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetSrcFD001, Level3)
372 {
373 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetSrcFD001 start";
374 OH_AVErrCode errorCode{ AV_ERR_OK };
375 errorCode = OH_AVTranscoderConfig_SetSrcFD(nullptr, MOCK_NEG, MOCK_NEG, MOCK_NEG);
376 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
377
378 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
379 ASSERT_NE(config, nullptr);
380
381 errorCode = OH_AVTranscoderConfig_SetSrcFD(config, MOCK_NEG, MOCK_NEG, MOCK_NEG);
382 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
383
384 errorCode = OH_AVTranscoderConfig_SetSrcFD(config, ZERO, MOCK_NEG, MOCK_NEG);
385 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
386
387 errorCode = OH_AVTranscoderConfig_SetSrcFD(config, ZERO, ZERO, MOCK_NEG);
388 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
389
390 errorCode = OH_AVTranscoderConfig_SetSrcFD(config, ZERO, ZERO, ZERO);
391 ASSERT_EQ(errorCode, AV_ERR_OK);
392
393 errorCode = OH_AVTranscoderConfig_Release(config);
394 ASSERT_EQ(errorCode, AV_ERR_OK);
395 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetSrcFD001 end";
396 }
397
398 /**
399 * @tc.name: AVTranscoder_ConfigSetDstFD001
400 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstFD when input parameter is invalid.
401 * @tc.type: FUNC
402 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetDstFD001,Level3)403 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetDstFD001, Level3)
404 {
405 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstFD001 start";
406 OH_AVErrCode errorCode{ AV_ERR_OK };
407 errorCode = OH_AVTranscoderConfig_SetDstFD(nullptr, MOCK_NEG);
408 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
409
410 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
411 ASSERT_NE(config, nullptr);
412
413 errorCode = OH_AVTranscoderConfig_SetDstFD(config, MOCK_NEG);
414 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
415
416 errorCode = OH_AVTranscoderConfig_SetDstFD(config, ZERO);
417 ASSERT_EQ(errorCode, AV_ERR_OK);
418
419 errorCode = OH_AVTranscoderConfig_Release(config);
420 ASSERT_EQ(errorCode, AV_ERR_OK);
421 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstFD001 end";
422 }
423
424 /**
425 * @tc.name: AVTranscoder_ConfigSetVideoType001
426 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstVideoType when input parameter is invalid.
427 * @tc.type: FUNC
428 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetVideoType001,Level3)429 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetVideoType001, Level3)
430 {
431 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetVideoType001 start";
432 OH_AVErrCode errorCode{ AV_ERR_OK };
433 errorCode = OH_AVTranscoderConfig_SetDstVideoType(nullptr, nullptr);
434 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
435
436 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
437 ASSERT_NE(config, nullptr);
438
439 errorCode = OH_AVTranscoderConfig_SetDstVideoType(config, nullptr);
440 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
441
442 errorCode = OH_AVTranscoderConfig_SetDstVideoType(config, "Mock");
443 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
444
445 errorCode = OH_AVTranscoderConfig_Release(config);
446 ASSERT_EQ(errorCode, AV_ERR_OK);
447 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetVideoType001 end";
448 }
449
450 /**
451 * @tc.name: AVTranscoder_ConfigSetAudioType001
452 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstAudioType when input parameter is invalid.
453 * @tc.type: FUNC
454 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetAudioType001,Level3)455 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetAudioType001, Level3)
456 {
457 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetAudioType001 start";
458 OH_AVErrCode errorCode{ AV_ERR_OK };
459 errorCode = OH_AVTranscoderConfig_SetDstAudioType(nullptr, nullptr);
460 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
461
462 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
463 ASSERT_NE(config, nullptr);
464
465 errorCode = OH_AVTranscoderConfig_SetDstAudioType(config, nullptr);
466 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
467
468 errorCode = OH_AVTranscoderConfig_SetDstAudioType(config, "Mock");
469 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
470
471 errorCode = OH_AVTranscoderConfig_Release(config);
472 ASSERT_EQ(errorCode, AV_ERR_OK);
473 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetAudioType001 end";
474 }
475
476 /**
477 * @tc.name: AVTranscoder_ConfigSetDstFileType001
478 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstFileType when input parameter is invalid.
479 * @tc.type: FUNC
480 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetDstFileType001,Level3)481 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetDstFileType001, Level3)
482 {
483 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstFileType001 start";
484 OH_AVErrCode errorCode{ AV_ERR_OK };
485 errorCode = OH_AVTranscoderConfig_SetDstFileType(nullptr, OH_AVOutputFormat::AV_OUTPUT_FORMAT_AMR);
486 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
487
488 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
489 ASSERT_NE(config, nullptr);
490
491 errorCode = OH_AVTranscoderConfig_SetDstFileType(config, OH_AVOutputFormat::AV_OUTPUT_FORMAT_AMR);
492 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
493
494 errorCode = OH_AVTranscoderConfig_Release(config);
495 ASSERT_EQ(errorCode, AV_ERR_OK);
496 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstFileType001 end";
497 }
498
499 /**
500 * @tc.name: AVTranscoder_ConfigSetDstAudioBitrate001
501 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstAudioBitrate when input parameter is invalid.
502 * @tc.type: FUNC
503 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetDstAudioBitrate001,Level3)504 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetDstAudioBitrate001, Level3)
505 {
506 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstAudioBitrate001 start";
507 OH_AVErrCode errorCode{ AV_ERR_OK };
508 errorCode = OH_AVTranscoderConfig_SetDstAudioBitrate(nullptr, ZERO);
509 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
510
511 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
512 ASSERT_NE(config, nullptr);
513
514 errorCode = OH_AVTranscoderConfig_SetDstAudioBitrate(config, ZERO);
515 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
516
517 errorCode = OH_AVTranscoderConfig_Release(config);
518 ASSERT_EQ(errorCode, AV_ERR_OK);
519 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstAudioBitrate001 end";
520 }
521
522 /**
523 * @tc.name: AVTranscoder_ConfigSetDstVideoBitrate001
524 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstVideoBitrate when input parameter is invalid.
525 * @tc.type: FUNC
526 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetDstVideoBitrate001,Level3)527 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetDstVideoBitrate001, Level3)
528 {
529 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstVideoBitrate001 start";
530 OH_AVErrCode errorCode{ AV_ERR_OK };
531 errorCode = OH_AVTranscoderConfig_SetDstVideoBitrate(nullptr, ZERO);
532 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
533
534 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
535 ASSERT_NE(config, nullptr);
536
537 errorCode = OH_AVTranscoderConfig_SetDstVideoBitrate(config, ZERO);
538 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
539
540 errorCode = OH_AVTranscoderConfig_Release(config);
541 ASSERT_EQ(errorCode, AV_ERR_OK);
542 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstVideoBitrate001 end";
543 }
544
545 /**
546 * @tc.name: AVTranscoder_ConfigSetDstVideoResolution001
547 * @tc.desc: Verify that call OH_AVTranscoderConfig_SetDstVideoResolution when input parameter is invalid.
548 * @tc.type: FUNC
549 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_ConfigSetDstVideoResolution001,Level3)550 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_ConfigSetDstVideoResolution001, Level3)
551 {
552 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstVideoResolution001 start";
553 OH_AVErrCode errorCode{ AV_ERR_OK };
554 errorCode = OH_AVTranscoderConfig_SetDstVideoResolution(nullptr, ZERO, ZERO);
555 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
556
557 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
558 ASSERT_NE(config, nullptr);
559
560 errorCode = OH_AVTranscoderConfig_SetDstVideoResolution(config, ZERO, ZERO);
561 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
562
563 errorCode = OH_AVTranscoderConfig_SetDstVideoResolution(config, MOCK_VIDEO_WIDTH, ZERO);
564 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
565
566 errorCode = OH_AVTranscoderConfig_SetDstVideoResolution(config, MOCK_VIDEO_WIDTH, MOCK_VIDEO_HEIGHT);
567 ASSERT_EQ(errorCode, AV_ERR_OK);
568
569 errorCode = OH_AVTranscoderConfig_Release(config);
570 ASSERT_EQ(errorCode, AV_ERR_OK);
571 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_ConfigSetDstVideoResolution001 end";
572 }
573
574 /**
575 * @tc.name: AVTranscoder_Prepare002
576 * @tc.desc: Verify that call OH_AVTranscoder_Prepare when input parameter is invalid.
577 * @tc.type: FUNC
578 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Prepare002,Level3)579 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Prepare002, Level3)
580 {
581 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Prepare002 start";
582 OH_AVErrCode errorCode{ AV_ERR_OK };
583 errorCode = OH_AVTranscoder_Prepare(nullptr, nullptr);
584 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
585
586 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
587 ASSERT_NE(config, nullptr);
588
589 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
590 ASSERT_NE(transcoder, nullptr);
591
592 errorCode = OH_AVTranscoder_Prepare(transcoder, nullptr);
593 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
594
595 errorCode = OH_AVTranscoderConfig_Release(config);
596 ASSERT_EQ(errorCode, AV_ERR_OK);
597
598 errorCode = OH_AVTranscoder_Release(transcoder);
599 ASSERT_EQ(errorCode, AV_ERR_OK);
600 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Prepare002 end";
601 }
602
603 /**
604 * @tc.name: AVTranscoder_Start002
605 * @tc.desc: Verify that call OH_AVTranscoder_Start when input parameter is invalid.
606 * @tc.type: FUNC
607 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Start002,Level3)608 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Start002, Level3)
609 {
610 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Start002 start";
611 OH_AVErrCode errorCode{ AV_ERR_OK };
612 errorCode = OH_AVTranscoder_Start(nullptr);
613 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
614 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Start002 end";
615 }
616
617 /**
618 * @tc.name: AVTranscoder_Start003
619 * @tc.desc: Verify that call OH_AVTranscoder_Start when prepare operation has not been invoked.
620 * @tc.type: FUNC
621 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Start003,Level3)622 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Start003, Level3)
623 {
624 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Start003 start";
625 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
626 ASSERT_NE(transcoder, nullptr);
627 OH_AVErrCode errorCode{ AV_ERR_OK };
628 errorCode = OH_AVTranscoder_Start(transcoder);
629 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
630 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Start003 end";
631 }
632
633 /**
634 * @tc.name: AVTranscoder_Pause002
635 * @tc.desc: Verify that call OH_AVTranscoder_Pause when input parameter is invalid.
636 * @tc.type: FUNC
637 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Pause002,Level3)638 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Pause002, Level3)
639 {
640 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause002 start";
641 OH_AVErrCode errorCode{ AV_ERR_OK };
642 errorCode = OH_AVTranscoder_Pause(nullptr);
643 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
644 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause002 end";
645 }
646
647 /**
648 * @tc.name: AVTranscoder_Pause003
649 * @tc.desc: Verify that call OH_AVTranscoder_Pause when pre-operation has not been invoked.
650 * @tc.type: FUNC
651 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Pause003,Level3)652 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Pause003, Level3)
653 {
654 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause003 start";
655 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
656 ASSERT_NE(transcoder, nullptr);
657 OH_AVErrCode errorCode{ AV_ERR_OK };
658 errorCode = OH_AVTranscoder_Pause(transcoder);
659 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
660 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause003 end";
661 }
662
663 /**
664 * @tc.name: AVTranscoder_Pause004
665 * @tc.desc: Verify that repeated Pause operation will not fail.
666 * @tc.type: FUNC
667 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Pause004,Level3)668 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Pause004, Level3)
669 {
670 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause004 start";
671 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
672 ASSERT_NE(transcoder, nullptr);
673
674 MockUserData mockUserData;
675 InitAVTranscoderCallback(transcoder, mockUserData);
676
677 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
678 ASSERT_NE(config, nullptr);
679 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
680 ASSERT_TRUE(srcFd >= ZERO);
681 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
682 ASSERT_TRUE(dstFd >= ZERO);
683 InitAVTranscoderConfig(config, srcFd, dstFd);
684
685 OH_AVErrCode errorCode{ AV_ERR_OK };
686 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
687 ASSERT_EQ(errorCode, AV_ERR_OK);
688
689 errorCode = OH_AVTranscoder_Start(transcoder);
690 ASSERT_EQ(errorCode, AV_ERR_OK);
691
692 errorCode = OH_AVTranscoder_Pause(transcoder);
693 ASSERT_EQ(errorCode, AV_ERR_OK);
694
695 errorCode = OH_AVTranscoder_Pause(transcoder);
696 ASSERT_EQ(errorCode, AV_ERR_OK);
697
698 errorCode = OH_AVTranscoder_Cancel(transcoder);
699 ASSERT_EQ(errorCode, AV_ERR_OK);
700
701 errorCode = OH_AVTranscoderConfig_Release(config);
702 ASSERT_EQ(errorCode, AV_ERR_OK);
703 errorCode = OH_AVTranscoder_Release(transcoder);
704 ASSERT_EQ(errorCode, AV_ERR_OK);
705
706 close(srcFd);
707 close(dstFd);
708 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Pause004 end";
709 }
710
711 /**
712 * @tc.name: AVTranscoder_Resume001
713 * @tc.desc: Verify that call OH_AVTranscoder_Resume when input parameter is invalid.
714 * @tc.type: FUNC
715 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Resume001,Level3)716 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Resume001, Level3)
717 {
718 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Resume001 start";
719 OH_AVErrCode errorCode{ AV_ERR_OK };
720 errorCode = OH_AVTranscoder_Resume(nullptr);
721 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
722 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Resume001 end";
723 }
724
725 /**
726 * @tc.name: AVTranscoder_Resume002
727 * @tc.desc: Verify that call OH_AVTranscoder_Resume when pre-operation has not been invoked.
728 * @tc.type: FUNC
729 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Resume002,Level3)730 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Resume002, Level3)
731 {
732 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Resume002 start";
733 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
734 ASSERT_NE(transcoder, nullptr);
735 OH_AVErrCode errorCode{ AV_ERR_OK };
736 errorCode = OH_AVTranscoder_Resume(transcoder);
737 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
738 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Resume002 end";
739 }
740
741 /**
742 * @tc.name: AVTranscoder_Resume003
743 * @tc.desc: Verify that repeated Resume operation will not fail.
744 * @tc.type: FUNC
745 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Resume003,Level3)746 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Resume003, Level3)
747 {
748 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Resume003 start";
749 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
750 ASSERT_NE(transcoder, nullptr);
751
752 MockUserData mockUserData;
753 InitAVTranscoderCallback(transcoder, mockUserData);
754
755 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
756 ASSERT_NE(config, nullptr);
757 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
758 ASSERT_TRUE(srcFd >= ZERO);
759 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
760 ASSERT_TRUE(dstFd >= ZERO);
761 InitAVTranscoderConfig(config, srcFd, dstFd);
762
763 OH_AVErrCode errorCode{ AV_ERR_OK };
764 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
765 ASSERT_EQ(errorCode, AV_ERR_OK);
766
767 errorCode = OH_AVTranscoder_Start(transcoder);
768 ASSERT_EQ(errorCode, AV_ERR_OK);
769
770 errorCode = OH_AVTranscoder_Pause(transcoder);
771 ASSERT_EQ(errorCode, AV_ERR_OK);
772
773 errorCode = OH_AVTranscoder_Resume(transcoder);
774 ASSERT_EQ(errorCode, AV_ERR_OK);
775
776 errorCode = OH_AVTranscoder_Resume(transcoder);
777 ASSERT_EQ(errorCode, AV_ERR_OK);
778
779 errorCode = OH_AVTranscoder_Cancel(transcoder);
780 ASSERT_EQ(errorCode, AV_ERR_OK);
781
782 errorCode = OH_AVTranscoderConfig_Release(config);
783 ASSERT_EQ(errorCode, AV_ERR_OK);
784 errorCode = OH_AVTranscoder_Release(transcoder);
785 ASSERT_EQ(errorCode, AV_ERR_OK);
786
787 close(srcFd);
788 close(dstFd);
789 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Resume003 end";
790 }
791
792 /**
793 * @tc.name: AVTranscoder_Cancel002
794 * @tc.desc: Verify that call OH_AVTranscoder_Cancel when input parameter is invalid.
795 * @tc.type: FUNC
796 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Cancel002,Level3)797 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Cancel002, Level3)
798 {
799 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel002 start";
800 OH_AVErrCode errorCode{ AV_ERR_OK };
801 errorCode = OH_AVTranscoder_Cancel(nullptr);
802 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
803 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel002 end";
804 }
805
806 /**
807 * @tc.name: AVTranscoder_Cancel003
808 * @tc.desc: Verify that call OH_AVTranscoder_Cancel when pre-operation has not been invoked.
809 * @tc.type: FUNC
810 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Cancel003,Level3)811 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Cancel003, Level3)
812 {
813 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel003 start";
814 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
815 ASSERT_NE(transcoder, nullptr);
816 OH_AVErrCode errorCode{ AV_ERR_OK };
817 errorCode = OH_AVTranscoder_Cancel(transcoder);
818 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
819 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel003 end";
820 }
821
822 /**
823 * @tc.name: AVTranscoder_Cancel004
824 * @tc.desc: Verify that repeated Cancel operation will fail.
825 * @tc.type: FUNC
826 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Cancel004,Level3)827 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Cancel004, Level3)
828 {
829 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel004 start";
830 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
831 ASSERT_NE(transcoder, nullptr);
832
833 MockUserData mockUserData;
834 InitAVTranscoderCallback(transcoder, mockUserData);
835
836 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
837 ASSERT_NE(config, nullptr);
838 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
839 ASSERT_TRUE(srcFd >= ZERO);
840 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
841 ASSERT_TRUE(dstFd >= ZERO);
842 InitAVTranscoderConfig(config, srcFd, dstFd);
843
844 OH_AVErrCode errorCode{ AV_ERR_OK };
845 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
846 ASSERT_EQ(errorCode, AV_ERR_OK);
847
848 errorCode = OH_AVTranscoder_Start(transcoder);
849 ASSERT_EQ(errorCode, AV_ERR_OK);
850
851 errorCode = OH_AVTranscoder_Pause(transcoder);
852 ASSERT_EQ(errorCode, AV_ERR_OK);
853
854 errorCode = OH_AVTranscoder_Resume(transcoder);
855 ASSERT_EQ(errorCode, AV_ERR_OK);
856
857 errorCode = OH_AVTranscoder_Cancel(transcoder);
858 ASSERT_EQ(errorCode, AV_ERR_OK);
859
860 errorCode = OH_AVTranscoder_Cancel(transcoder);
861 ASSERT_EQ(errorCode, AV_ERR_OPERATE_NOT_PERMIT);
862
863 errorCode = OH_AVTranscoderConfig_Release(config);
864 ASSERT_EQ(errorCode, AV_ERR_OK);
865 errorCode = OH_AVTranscoder_Release(transcoder);
866 ASSERT_EQ(errorCode, AV_ERR_OK);
867
868 close(srcFd);
869 close(dstFd);
870 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Cancel004 end";
871 }
872
873 /**
874 * @tc.name: AVTranscoder_Release001
875 * @tc.desc: Verify that call OH_AVTranscoder_Release when input parameter is invalid.
876 * @tc.type: FUNC
877 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Release001,Level3)878 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Release001, Level3)
879 {
880 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Release001 start";
881 OH_AVErrCode errorCode{ AV_ERR_OK };
882 errorCode = OH_AVTranscoder_Release(nullptr);
883 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
884 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Release001 end";
885 }
886
887 /**
888 * @tc.name: AVTranscoder_SetStateCallback001
889 * @tc.desc: Verify that call OH_AVTranscoder_SetStateCallback when input parameter is invalid.
890 * @tc.type: FUNC
891 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_SetStateCallback001,Level3)892 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_SetStateCallback001, Level3)
893 {
894 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_SetStateCallback001 start";
895 OH_AVErrCode errorCode{ AV_ERR_OK };
896 errorCode = OH_AVTranscoder_SetStateCallback(nullptr, nullptr, nullptr);
897 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
898 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_SetStateCallback001 end";
899 }
900
901 /**
902 * @tc.name: AVTranscoder_SetErrorCallback001
903 * @tc.desc: Verify that call OH_AVTranscoder_SetErrorCallback when input parameter is invalid.
904 * @tc.type: FUNC
905 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_SetErrorCallback001,Level3)906 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_SetErrorCallback001, Level3)
907 {
908 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_SetErrorCallback001 start";
909 OH_AVErrCode errorCode{ AV_ERR_OK };
910 errorCode = OH_AVTranscoder_SetErrorCallback(nullptr, nullptr, nullptr);
911 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
912 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_SetErrorCallback001 end";
913 }
914
915 /**
916 * @tc.name: AVTranscoder_SetProgressUpdateCallback001
917 * @tc.desc: Verify that call OH_AVTranscoder_SetProgressUpdateCallback when input parameter is invalid.
918 * @tc.type: FUNC
919 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_SetProgressUpdateCallback001,Level3)920 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_SetProgressUpdateCallback001, Level3)
921 {
922 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_SetProgressUpdateCallback001 start";
923 OH_AVErrCode errorCode{ AV_ERR_OK };
924 errorCode = OH_AVTranscoder_SetProgressUpdateCallback(nullptr, nullptr, nullptr);
925 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
926 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_SetProgressUpdateCallback001 end";
927 }
928
929 /**
930 * @tc.name: AVTranscoder_OnError001
931 * @tc.desc: Verify that the error callback is invoked.
932 * @tc.type: FUNC
933 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_OnError001,Level3)934 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_OnError001, Level3)
935 {
936 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_OnError001 start";
937 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
938 ASSERT_NE(transcoder, nullptr);
939 MockUserData mockUserData;
940 InitAVTranscoderCallback(transcoder, mockUserData);
941 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
942 ASSERT_NE(config, nullptr);
943 OH_AVErrCode errorCode = OH_AVTranscoder_Prepare(transcoder, config);
944 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
945 errorCode = OH_AVTranscoderConfig_Release(config);
946 ASSERT_EQ(errorCode, AV_ERR_OK);
947 errorCode = OH_AVTranscoder_Release(transcoder);
948 ASSERT_EQ(errorCode, AV_ERR_OK);
949 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_OnError001 end";
950 }
951
952 /**
953 * @tc.name: AVTranscoder_OnError002
954 * @tc.desc: Verify that the error callback is not invoked.
955 * @tc.type: FUNC
956 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_OnError002,Level3)957 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_OnError002, Level3)
958 {
959 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_OnError002 start";
960 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
961 ASSERT_NE(transcoder, nullptr);
962 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
963 ASSERT_NE(config, nullptr);
964 OH_AVErrCode errorCode = OH_AVTranscoder_Prepare(transcoder, config);
965 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
966 errorCode = OH_AVTranscoderConfig_Release(config);
967 ASSERT_EQ(errorCode, AV_ERR_OK);
968 errorCode = OH_AVTranscoder_Release(transcoder);
969 ASSERT_EQ(errorCode, AV_ERR_OK);
970 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_OnError002 end";
971 }
972
973 /**
974 * @tc.name: AVTranscoder_OnError003
975 * @tc.desc: Verify that the error callback is invoked.
976 * @tc.type: FUNC
977 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_OnError003,Level3)978 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_OnError003, Level3)
979 {
980 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_OnError003 start";
981 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
982 ASSERT_NE(transcoder, nullptr);
983 MockUserData mockUserData;
984 InitAVTranscoderCallback(transcoder, mockUserData);
985 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
986 ASSERT_NE(config, nullptr);
987
988 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
989 ASSERT_TRUE(srcFd >= ZERO);
990 OH_AVErrCode errorCode = OH_AVTranscoderConfig_SetSrcFD(config, srcFd,
991 TRANSCODER_FILE_OFFSET, TRANSCODER_FILE_SIZE);
992 ASSERT_EQ(errorCode, AV_ERR_OK);
993 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
994 ASSERT_EQ(errorCode, AV_ERR_INVALID_VAL);
995
996 errorCode = OH_AVTranscoderConfig_Release(config);
997 ASSERT_EQ(errorCode, AV_ERR_OK);
998 errorCode = OH_AVTranscoder_Release(transcoder);
999 ASSERT_EQ(errorCode, AV_ERR_OK);
1000 close(srcFd);
1001 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_OnError003 end";
1002 }
1003
1004 /**
1005 * @tc.name: AVTranscoder_Complete002
1006 * @tc.desc: Verify the regular transcoding process without callback.
1007 * @tc.type: FUNC
1008 */
HWTEST_F(NativeAVTranscoderUnitTest,AVTranscoder_Complete002,Level3)1009 HWTEST_F(NativeAVTranscoderUnitTest, AVTranscoder_Complete002, Level3)
1010 {
1011 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Complete002 start";
1012 OH_AVTranscoder *transcoder = OH_AVTranscoder_Create();
1013 ASSERT_NE(transcoder, nullptr);
1014
1015 OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create();
1016 ASSERT_NE(config, nullptr);
1017 int32_t srcFd = open(CHINESE_COLOR_MP4.c_str(), O_RDWR);
1018 ASSERT_TRUE(srcFd >= ZERO);
1019 int32_t dstFd = open(MOCK_OUTPUT_MP4.c_str(), O_RDWR);
1020 ASSERT_TRUE(dstFd >= ZERO);
1021
1022 InitAVTranscoderConfig(config, srcFd, dstFd);
1023
1024 OH_AVErrCode errorCode{ AV_ERR_OK };
1025 errorCode = OH_AVTranscoder_Prepare(transcoder, config);
1026 ASSERT_EQ(errorCode, AV_ERR_OK);
1027
1028 errorCode = OH_AVTranscoder_Start(transcoder);
1029 ASSERT_EQ(errorCode, AV_ERR_OK);
1030
1031 errorCode = OH_AVTranscoderConfig_Release(config);
1032 ASSERT_EQ(errorCode, AV_ERR_OK);
1033 errorCode = OH_AVTranscoder_Release(transcoder);
1034 ASSERT_EQ(errorCode, AV_ERR_OK);
1035
1036 close(srcFd);
1037 close(dstFd);
1038 GTEST_LOG_(INFO) << "NativeAVTranscoderUnitTest: AVTranscoder_Complete002 end";
1039 }