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 AVMUXER_UNIT_TEST_H
17 #define AVMUXER_UNIT_TEST_H
18 
19 #include "gtest/gtest.h"
20 #include <fstream>
21 #include "avmuxer_sample.h"
22 #include "buffer/avbuffer.h"
23 #include "buffer/avbuffer_queue_producer.h"
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace MediaAVCodec {
28 class AVMuxerUnitTest : public testing::Test {
29 public:
30     // SetUpTestCase: Called before all test cases
31     static void SetUpTestCase(void);
32     // TearDownTestCase: Called after all test case
33     static void TearDownTestCase(void);
34     // SetUp: Called before each test cases
35     void SetUp(void);
36     // TearDown: Called after each test cases
37     void TearDown(void);
38 
39     int32_t WriteSample(int32_t trackId, std::shared_ptr<std::ifstream> file, bool &eosFlag, uint32_t flag);
40 
41     int32_t WriteSample(sptr<Media::AVBufferQueueProducer> bqProducer,
42         std::shared_ptr<std::ifstream> file, bool &eosFlag);
43 
44 protected:
45     std::shared_ptr<AVMuxerSample> avmuxer_ {nullptr};
46     std::shared_ptr<std::ifstream> inputFile_ = nullptr;
47     int32_t fd_ {-1};
48     uint8_t buffer_[26] = {
49         'a', 'b', 'c', 'd', 'e', 'f', 'g',
50         'h', 'i', 'j', 'k', 'l', 'm', 'n',
51         'o', 'p', 'q', 'r', 's', 't',
52         'u', 'v', 'w', 'x', 'y', 'z'
53     };
54     uint8_t annexBuffer_[72] = {
55         0x00, 0x00, 0x00, 0x01,
56         0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03,
57         0x00, 0x00, 0x03, 0x00, 0x5d, 0x95, 0x98, 0x09,
58         0x00, 0x00, 0x00, 0x01,
59         0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
60         0x00, 0x5d, 0xa0, 0x05, 0xa2, 0x01, 0xe1, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xb9, 0xa0, 0x20, 0x00,
61         0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x07, 0x81
62     };
63 };
64 } // namespace MediaAVCodec
65 } // namespace OHOS
66 #endif // AVMUXER_UNIT_TEST_H