• 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 <iostream>
17 #include <algorithm>
18 #include "dash_mpd_manager_unittest.h"
19 
20 namespace OHOS {
21 namespace Media {
22 namespace Plugins {
23 namespace HttpPlugin {
24 using namespace testing;
25 using namespace testing::ext;
26 const static int32_t ID_TEST = 1;
27 const static int32_t NUM_TEST = 0;
SetUpTestCase(void)28 void DashMpdManagerUnittest::SetUpTestCase(void) {}
TearDownTestCase(void)29 void DashMpdManagerUnittest::TearDownTestCase(void) {}
SetUp(void)30 void DashMpdManagerUnittest::SetUp(void)
31 {
32     mpdManager_ = std::make_shared<DashMpdManager>();
33 }
TearDown(void)34 void DashMpdManagerUnittest::TearDown(void)
35 {
36     mpdManager_ = nullptr;
37 }
38 
39 /**
40  * @tc.name  : Test Reset
41  * @tc.number: Reset_001
42  * @tc.desc  : Test all
43  */
44 HWTEST_F(DashMpdManagerUnittest, Reset_001, TestSize.Level0)
45 {
46     ASSERT_NE(mpdManager_, nullptr);
47     auto mpdInfo = new DashMpdInfo();
48     mpdManager_->mpdInfo_ = mpdInfo;
49     mpdManager_->mpdUrl_ = "testUrl";
50     ASSERT_NE(mpdManager_->mpdInfo_, nullptr);
51     mpdManager_->Reset();
52     EXPECT_EQ(mpdManager_->mpdInfo_, nullptr);
53     EXPECT_EQ(mpdManager_->mpdUrl_, "");
54     delete mpdInfo;
55 }
56 
57 /**
58  * @tc.name  : Test GetFirstPeriod
59  * @tc.number: GetFirstPeriod_001
60  * @tc.desc  : Test this->mpdInfo_ == nullptr || this->mpdInfo_->periodInfoList_.size() == 0
61  */
62 HWTEST_F(DashMpdManagerUnittest, GetFirstPeriod_001, TestSize.Level0)
63 {
64     ASSERT_NE(mpdManager_, nullptr);
65     mpdManager_->mpdInfo_ = nullptr;
66     auto ret = mpdManager_->GetFirstPeriod();
67     EXPECT_EQ(ret, nullptr);
68 }
69 
70 /**
71  * @tc.name  : Test GetNextPeriod
72  * @tc.number: GetNextPeriod_001
73  * @tc.desc  : Test this->mpdInfo_ == nullptr || this->mpdInfo_->periodInfoList_.size() == 0
74  *             Test periodInfoList_.size() != 0 && (*it) != period
75  */
76 HWTEST_F(DashMpdManagerUnittest, GetNextPeriod_001, TestSize.Level0)
77 {
78     ASSERT_NE(mpdManager_, nullptr);
79     DashPeriodInfo *period;
80     mpdManager_->mpdInfo_ = nullptr;
81     auto ret = mpdManager_->GetNextPeriod(period);
82     EXPECT_EQ(ret, nullptr);
83 
84     auto mpdInfo = new DashMpdInfo();
85     mpdManager_->mpdInfo_ = mpdInfo;
86     DashPeriodInfo *period2 = new DashPeriodInfo();
87     mpdManager_->mpdInfo_->periodInfoList_.push_back(period2);
88     ret = mpdManager_->GetNextPeriod(period);
89     EXPECT_EQ(ret, nullptr);
90     delete period2;
91     delete mpdInfo;
92     mpdManager_->mpdInfo_ = nullptr;
93 }
94 
95 /**
96  * @tc.name  : Test GetBaseUrlList
97  * @tc.number: GetBaseUrlList_001
98  * @tc.desc  : Test this->mpdInfo_ == nullptr || this->mpdInfo_->periodInfoList_.size() == 0
99  *             Test periodInfoList_.size() != 0 && (*it) != period
100  */
101 HWTEST_F(DashMpdManagerUnittest, GetBaseUrlList_001, TestSize.Level0)
102 {
103     ASSERT_NE(mpdManager_, nullptr);
104     mpdManager_->mpdInfo_ = nullptr;
105     std::list<std::string> baseUrlList;
106     mpdManager_->GetBaseUrlList(baseUrlList);
107 
108     auto mpdInfo = new DashMpdInfo();
109     mpdManager_->mpdInfo_ = mpdInfo;
110     mpdManager_->mpdUrl_ = "mpd/manager?testUrl";
111     mpdManager_->GetBaseUrlList(baseUrlList);
112     EXPECT_EQ(baseUrlList.empty(), false);
113     EXPECT_EQ(mpdManager_->mpdInfo_->baseUrl_, baseUrlList);
114     delete mpdInfo;
115 }
116 
117 /**
118  * @tc.name  : Test GetBaseUrl
119  * @tc.number: GetBaseUrl_001
120  * @tc.desc  : Test sepCharIndex != std::string::npos
121  */
122 HWTEST_F(DashMpdManagerUnittest, GetBaseUrl_001, TestSize.Level0)
123 {
124     ASSERT_NE(mpdManager_, nullptr);
125     auto mpdInfo = new DashMpdInfo();
126     mpdManager_->mpdInfo_ = mpdInfo;
127     mpdManager_->mpdUrl_ = "mpd/manager?testUrl";
128     auto ret = mpdManager_->GetBaseUrl();
129     EXPECT_EQ(ret, "mpd/");
130     delete mpdInfo;
131     mpdManager_->mpdInfo_ = nullptr;
132 }
133 
134 /**
135  * @tc.name  : Test MakeBaseUrl
136  * @tc.number: MakeBaseUrl_001
137  * @tc.desc  : Test DashUrlIsAbsolute(baseUrl) == false
138  *             Test baseUrl.find('/') == 0
139  *             Test beginPathIndex != std::string::npos
140  */
141 HWTEST_F(DashMpdManagerUnittest, MakeBaseUrl_001, TestSize.Level0)
142 {
143     ASSERT_NE(mpdManager_, nullptr);
144     auto mpdInfo = new DashMpdInfo();
145     mpdManager_->mpdInfo_ = mpdInfo;
146     mpdManager_->mpdInfo_->baseUrl_.push_back("test/Url");
147     std::string mpdUrlBase = "test/Url";
148     std::string urlSchem = "";
149     mpdManager_->MakeBaseUrl(mpdUrlBase, urlSchem);
150     EXPECT_EQ(mpdUrlBase, "test/Urltest/Url");
151     delete mpdInfo;
152     mpdManager_->mpdInfo_ = nullptr;
153 }
154 
155 /**
156  * @tc.name  : Test Update
157  * @tc.number: Update_001
158  * @tc.desc  : Test all
159  */
160 HWTEST_F(DashMpdManagerUnittest, Update_001, TestSize.Level0)
161 {
162     ASSERT_NE(mpdManager_, nullptr);
163     DashMpdInfo *newMpdInfo = new DashMpdInfo();
164     mpdManager_->Update(newMpdInfo);
165     EXPECT_EQ(mpdManager_->mpdInfo_, newMpdInfo);
166     delete newMpdInfo;
167     mpdManager_->mpdInfo_ = nullptr;
168 }
169 
170 /**
171  * @tc.name  : Test GetDuration
172  * @tc.number: GetDuration_001
173  * @tc.desc  : Test dur == 0
174  */
175 HWTEST_F(DashMpdManagerUnittest, GetDuration_001, TestSize.Level0)
176 {
177     ASSERT_NE(mpdManager_, nullptr);
178     uint32_t *duration = nullptr;
179     mpdManager_->GetDuration(duration);
180 
181     uint32_t testNum = ID_TEST;
182     duration = &testNum;
183     auto mpdInfo = new DashMpdInfo();
184     mpdManager_->mpdInfo_ = mpdInfo;
185     mpdManager_->mpdInfo_->mediaPresentationDuration_ = NUM_TEST;
186     mpdManager_->GetDuration(duration);
187     EXPECT_EQ(*duration, NUM_TEST);
188     delete mpdInfo;
189     mpdManager_->mpdInfo_ = nullptr;
190 }
191 }
192 }
193 }
194 }