• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "pts_and_index_conversion_unittest.h"
17 
18 #include <string>
19 #include <malloc.h>
20 #include <sys/stat.h>
21 #include <cinttypes>
22 #include <fcntl.h>
23 #include <list>
24 #include <cmath>
25 #include <sys/types.h>
26 #include <fstream>
27 #include <memory>
28 #include "avcodec_errors.h"
29 
30 using namespace OHOS;
31 using namespace OHOS::Media;
32 using namespace testing::ext;
33 using namespace testing;
34 using namespace std;
35 namespace OHOS {
36 namespace Media {
37 const static int32_t ID_TEST = 1;
38 const static int32_t NUM_TEST = 0;
39 const static int32_t INVALID_MODE = 4;
40 using MediaSource = OHOS::Media::Plugins::MediaSource;
41 
SetUpTestCase(void)42 void PtsAndIndexConversionUnitTest::SetUpTestCase(void)
43 {
44 }
45 
TearDownTestCase(void)46 void PtsAndIndexConversionUnitTest::TearDownTestCase(void)
47 {
48 }
49 
SetUp()50 void PtsAndIndexConversionUnitTest::SetUp()
51 {
52     timeAndIndexConversions_ = std::make_shared<TimeAndIndexConversion>();
53 }
54 
TearDown()55 void PtsAndIndexConversionUnitTest::TearDown()
56 {
57     timeAndIndexConversions_ = nullptr;
58 }
59 
60 /**
61  * @tc.name: Test PTSAndIndexConvertSttsAndCttsProcess  API
62  * @tc.number: PTSAndIndexConvertSttsAndCttsProcess_001
63  * @tc.desc: Test sttsIndex < sttsCount && cttsIndex < cttsCount
64  *           Test sttsCurNum == 0
65  */
66 HWTEST_F(PtsAndIndexConversionUnitTest, PTSAndIndexConvertSttsAndCttsProcess_001, TestSize.Level0)
67 {
68     ASSERT_NE(timeAndIndexConversions_, nullptr);
69     TimeAndIndexConversion::TrakInfo testInfo;
70     testInfo.timeScale = ID_TEST;
71     TimeAndIndexConversion::STTSEntry testSEntry;
72     testSEntry.sampleCount = ID_TEST;
73     testSEntry.sampleDelta = ID_TEST;
74     TimeAndIndexConversion::CTTSEntry testCEntry;
75     testCEntry.sampleCount = ID_TEST;
76     testCEntry.sampleOffset = ID_TEST;
77     testInfo.sttsEntries.push_back(testSEntry);
78     testInfo.cttsEntries.push_back(testCEntry);
79     timeAndIndexConversions_->trakInfoVec_.push_back(testInfo);
80     timeAndIndexConversions_->curConvertTrakInfoIndex_ = NUM_TEST;
81     TimeAndIndexConversion::IndexAndPTSConvertMode mode =
82         TimeAndIndexConversion::IndexAndPTSConvertMode::GET_FIRST_PTS;
83     int64_t absolutePTS = NUM_TEST;
84     uint32_t index = NUM_TEST;
85     auto ret = timeAndIndexConversions_->PTSAndIndexConvertSttsAndCttsProcess(mode, absolutePTS, index);
86     auto sttsIndex = NUM_TEST;
87     auto sttsCount = timeAndIndexConversions_->trakInfoVec_[timeAndIndexConversions_->curConvertTrakInfoIndex_]
88         .sttsEntries.size();
89     EXPECT_GE(sttsCount, sttsIndex);
90     EXPECT_EQ(ret, Status::OK);
91 }
92 
93 /**
94  * @tc.name: Test PTSAndIndexConvertSttsAndCttsProcess  API
95  * @tc.number: PTSAndIndexConvertSttsAndCttsProcess_002
96  * @tc.desc: Test cttsCurNum == 0
97  *           Test cttsIndex >= cttsCount
98  *           Test cttsCurNum == 0
99  *           Test sttsCurNum == 0
100  */
101 HWTEST_F(PtsAndIndexConversionUnitTest, PTSAndIndexConvertSttsAndCttsProcess_002, TestSize.Level0)
102 {
103     ASSERT_NE(timeAndIndexConversions_, nullptr);
104     TimeAndIndexConversion::TrakInfo testInfo;
105     testInfo.timeScale = ID_TEST;
106     TimeAndIndexConversion::STTSEntry testSEntry;
107     testSEntry.sampleCount = NUM_TEST;
108     testSEntry.sampleDelta = ID_TEST;
109     TimeAndIndexConversion::STTSEntry testSEntry2;
110     testSEntry2.sampleCount = NUM_TEST;
111     testSEntry2.sampleDelta = NUM_TEST;
112     TimeAndIndexConversion::CTTSEntry testCEntry;
113     testCEntry.sampleCount = NUM_TEST;
114     testCEntry.sampleOffset = ID_TEST;
115     TimeAndIndexConversion::CTTSEntry testCEntry2;
116     testCEntry2.sampleCount = NUM_TEST;
117     testCEntry2.sampleOffset = NUM_TEST;
118     testInfo.sttsEntries.push_back(testSEntry);
119     testInfo.sttsEntries.push_back(testSEntry2);
120     testInfo.cttsEntries.push_back(testCEntry);
121     testInfo.cttsEntries.push_back(testCEntry2);
122     timeAndIndexConversions_->trakInfoVec_.push_back(testInfo);
123     timeAndIndexConversions_->curConvertTrakInfoIndex_ = NUM_TEST;
124     TimeAndIndexConversion::IndexAndPTSConvertMode mode =
125         TimeAndIndexConversion::IndexAndPTSConvertMode::GET_FIRST_PTS;
126     int64_t absolutePTS = NUM_TEST;
127     uint32_t index = NUM_TEST;
128     auto ret = timeAndIndexConversions_->PTSAndIndexConvertSttsAndCttsProcess(mode, absolutePTS, index);
129     auto cttsIndex = NUM_TEST;
130     uint32_t cttsCurNum = timeAndIndexConversions_->trakInfoVec_[timeAndIndexConversions_->curConvertTrakInfoIndex_]
131         .cttsEntries[cttsIndex].sampleCount;
132     EXPECT_EQ(cttsCurNum, NUM_TEST);
133     EXPECT_EQ(ret, Status::OK);
134 }
135 
136 /**
137  * @tc.name: Test PTSAndIndexConvertOnlySttsProcess  API
138  * @tc.number: PTSAndIndexConvertOnlySttsProcess_001
139  * @tc.desc: Test sttsCurNum == 0
140  *           Test sttsCurNum == 0, sttsIndex == sttsCount
141  */
142 HWTEST_F(PtsAndIndexConversionUnitTest, PTSAndIndexConvertOnlySttsProcess_001, TestSize.Level0)
143 {
144     ASSERT_NE(timeAndIndexConversions_, nullptr);
145     TimeAndIndexConversion::TrakInfo testInfo;
146     testInfo.timeScale = ID_TEST;
147     TimeAndIndexConversion::STTSEntry testSEntry;
148     testSEntry.sampleCount = ID_TEST;
149     testSEntry.sampleDelta = ID_TEST;
150     testInfo.sttsEntries.push_back(testSEntry);
151     timeAndIndexConversions_->trakInfoVec_.push_back(testInfo);
152     timeAndIndexConversions_->curConvertTrakInfoIndex_ = NUM_TEST;
153     TimeAndIndexConversion::IndexAndPTSConvertMode mode =
154         TimeAndIndexConversion::IndexAndPTSConvertMode::GET_FIRST_PTS;
155     int64_t absolutePTS = NUM_TEST;
156     uint32_t index = NUM_TEST;
157     auto ret = timeAndIndexConversions_->PTSAndIndexConvertOnlySttsProcess(mode, absolutePTS, index);
158     EXPECT_EQ(ret, Status::OK);
159 }
160 
161 /**
162  * @tc.name: Test PTSAndIndexConvertSwitchProcess  API
163  * @tc.number: PTSAndIndexConvertSwitchProcess_001
164  * @tc.desc: Test case GET_FIRST_PTS
165  *           Test case default
166  */
167 HWTEST_F(PtsAndIndexConversionUnitTest, PTSAndIndexConvertSwitchProcess_001, TestSize.Level0)
168 {
169     ASSERT_NE(timeAndIndexConversions_, nullptr);
170     TimeAndIndexConversion::IndexAndPTSConvertMode mode =
171         static_cast<TimeAndIndexConversion::IndexAndPTSConvertMode>(INVALID_MODE);
172     int64_t pts = ID_TEST;
173     int64_t absolutePTS = ID_TEST;
174     uint32_t index = ID_TEST;
175     timeAndIndexConversions_->absolutePTSIndexZero_ = INVALID_MODE;
176     timeAndIndexConversions_->PTSAndIndexConvertSwitchProcess(mode, pts, absolutePTS, index);
177     mode = TimeAndIndexConversion::IndexAndPTSConvertMode::GET_FIRST_PTS;
178     timeAndIndexConversions_->PTSAndIndexConvertSwitchProcess(mode, pts, absolutePTS, index);
179     EXPECT_EQ(timeAndIndexConversions_->absolutePTSIndexZero_, ID_TEST);
180 }
181 } // Media
182 } // OHOS