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 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 48 protected: 49 std::shared_ptr<AVSourceMock> source_ = nullptr; 50 std::shared_ptr<DemuxerMock> demuxer_ = nullptr; 51 std::shared_ptr<FormatMock> format_ = nullptr; 52 std::shared_ptr<AVMemoryMock> sharedMem_ = nullptr; 53 int32_t fd_ = -1; 54 AVCodecBufferInfo info_; 55 uint32_t flag_; 56 std::vector<uint32_t> selectedTrackIds_; 57 int32_t bufferSize_ = 0; 58 int32_t nbStreams_ = 0; 59 int32_t numbers_ = 0; 60 int32_t ret_ = AV_ERR_OK; 61 bool initStatus_ = false; 62 std::map<uint32_t, int32_t> frames_; 63 std::map<uint32_t, int32_t> keyFrames_; 64 std::map<uint32_t, bool> eosFlag_; 65 }; 66 } // namespace MediaAVCodec 67 } // namespace OHOS 68 #endif // VCODEC_UNIT_TEST_H 69