1 /* 2 * Copyright (C) 2023-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 #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 bool 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 bool CheckKeyFrameIndex(std::vector<uint32_t> keyFrameIndexList, const uint32_t frameIndex, const bool isKeyFrame); 44 45 void InitResource(const std::string &path, bool local); 46 void ReadSample(const std::string &path, bool local, bool checkBufferInfo = false); 47 bool CheckCache(uint32_t readTrackId, uint32_t times, uint32_t checkTrackId, uint32_t expect, bool exist = true); 48 void ReadAllSampleWithCheck(std::vector<uint32_t> &keyFrameIndex); 49 void SeekTest(const std::list<int64_t> &toPtsList, const std::list<Media::SeekMode> &seekModes, 50 const std::vector<std::vector<int32_t>> &ExpVals); 51 52 protected: 53 std::shared_ptr<AVSourceMock> source_ = nullptr; 54 std::shared_ptr<DemuxerMock> demuxer_ = nullptr; 55 std::shared_ptr<FormatMock> format_ = nullptr; 56 std::shared_ptr<AVMemoryMock> sharedMem_ = nullptr; 57 int32_t fd_ = -1; 58 AVCodecBufferInfo info_; 59 uint32_t flag_; 60 std::vector<uint32_t> selectedTrackIds_; 61 int32_t bufferSize_ = 0; 62 int32_t nbStreams_ = 0; 63 int32_t numbers_ = 0; 64 int32_t ret_ = AV_ERR_OK; 65 bool initStatus_ = false; 66 std::map<uint32_t, int32_t> frames_; 67 std::map<uint32_t, int32_t> keyFrames_; 68 std::map<uint32_t, bool> eosFlag_; 69 bool readFlag_ = false; 70 bool seekTestFlag_ = false; 71 }; 72 } // namespace MediaAVCodec 73 } // namespace OHOS 74 #endif // VCODEC_UNIT_TEST_H 75