1 /*
2  * Copyright (C) 2023 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 #ifndef VCODEC_UNIT_TEST_H
17 #define VCODEC_UNIT_TEST_H
18 
19 #include "gtest/gtest.h"
20 #include "demuxer_mock.h"
21 
22 namespace OHOS {
23 namespace MediaAVCodec {
24 class DemuxerUnitTest : public testing::Test {
25 public:
26     // SetUpTestCase: Called before all test cases
27     static void SetUpTestCase(void);
28     // TearDownTestCase: Called after all test case
29     static void TearDownTestCase(void);
30     // SetUp: Called before each test cases
31     void SetUp(void);
32     // TearDown: Called after each test cases
33     void TearDown(void);
34     int64_t GetFileSize(const std::string &fileName);
35     int32_t OpenFile(const std::string &fileName);
36     bool isEOS(std::map<uint32_t, bool>& countFlag);
37     void SetInitValue();
38     void ReadData();
39     void ReadData(int readNum, int64_t &seekTime);
40     void RemoveValue();
41     void SetEosValue();
42     void CountFrames(uint32_t index);
43 
44     void InitResource(const std::string &path, bool local);
45     void ReadSample(const std::string &path, bool local, bool checkBufferInfo = false);
46 
47 protected:
48     std::shared_ptr<AVSourceMock> source_ = nullptr;
49     std::shared_ptr<DemuxerMock> demuxer_ = nullptr;
50     std::shared_ptr<FormatMock> format_ = nullptr;
51     std::shared_ptr<AVMemoryMock> sharedMem_ = nullptr;
52     int32_t fd_ = -1;
53     AVCodecBufferInfo info_;
54     uint32_t flag_;
55     std::vector<uint32_t> selectedTrackIds_;
56     int32_t bufferSize_ = 0;
57     int32_t nbStreams_ = 0;
58     int32_t numbers_ = 0;
59     int32_t ret_ = AV_ERR_OK;
60     bool initStatus_ = false;
61     std::map<uint32_t, int32_t> frames_;
62     std::map<uint32_t, int32_t> keyFrames_;
63     std::map<uint32_t, bool> eosFlag_;
64 };
65 } // namespace MediaAVCodec
66 } // namespace OHOS
67 #endif // VCODEC_UNIT_TEST_H
68