• 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 "dash_mpd_util_unittest.h"
17 
18 namespace OHOS {
19 namespace Media {
20 namespace Plugins {
21 namespace HttpPlugin {
22 using namespace std;
23 using namespace testing;
24 using namespace testing::ext;
25 static const int32_t NUM_0 = 0;
26 static const int32_t ERROR = -1;
27 static const uint32_t MS_OF_TWO_DAYS = 172800000u;
28 
SetUpTestCase(void)29 void DashMpdUtilUnitTest::SetUpTestCase(void) {}
30 
TearDownTestCase(void)31 void DashMpdUtilUnitTest::TearDownTestCase(void) {}
32 
SetUp(void)33 void DashMpdUtilUnitTest::SetUp(void) {}
34 
TearDown(void)35 void DashMpdUtilUnitTest::TearDown(void) {}
36 
37 /**
38  * @tc.name  : Test DashAppendBaseUrl
39  * @tc.number: DashAppendBaseUrl_001
40  * @tc.desc  : Test DashUrlIsAbsolute(baseUrl) == true
41  */
42 HWTEST_F(DashMpdUtilUnitTest, DashAppendBaseUrl_001, TestSize.Level0)
43 {
44     std::string srcUrl;
45     std::string baseUrl = "http://host/path/file";
46     DashAppendBaseUrl(srcUrl, baseUrl);
47     EXPECT_EQ(srcUrl, baseUrl);
48 }
49 
50 /**
51  * @tc.name  : Test DashAppendBaseUrl
52  * @tc.number: DashAppendBaseUrl_002
53  * @tc.desc  : Test baseUrl.find('/') == 0
54  */
55 HWTEST_F(DashMpdUtilUnitTest, DashAppendBaseUrl_002, TestSize.Level0)
56 {
57     std::string srcUrl;
58     std::string baseUrl = "//host/path/file";
59     DashAppendBaseUrl(srcUrl, baseUrl);
60     EXPECT_EQ(srcUrl, baseUrl);
61 }
62 
63 /**
64  * @tc.name  : Test BuildSrcUrl
65  * @tc.number: BuildSrcUrl_001
66  * @tc.desc  : Test DashUrlIsAbsolute(srcUrl) == true
67  *             Test urlSchemIndex != std::string::npos
68  *             Test urlPathIndex != std::string::npos
69  */
70 HWTEST_F(DashMpdUtilUnitTest, BuildSrcUrl_001, TestSize.Level0)
71 {
72     // Test DashUrlIsAbsolute(srcUrl) == true
73     // Test urlSchemIndex != std::string::npos
74     // Test urlPathIndex != std::string::npos
75     std::string srcUrl = "http://host/abc";
76     std::string baseUrl = "/xyz";
77     BuildSrcUrl(srcUrl, baseUrl);
78     EXPECT_EQ(srcUrl, "http://host/xyz");
79 }
80 
81 /**
82  * @tc.name  : Test BuildSrcUrl
83  * @tc.number: BuildSrcUrl_002
84  * @tc.desc  : Test DashUrlIsAbsolute(srcUrl) == false
85  */
86 HWTEST_F(DashMpdUtilUnitTest, BuildSrcUrl_002, TestSize.Level0)
87 {
88     std::string srcUrl;
89     std::string baseUrl = "http://host/path/file";
90     BuildSrcUrl(srcUrl, baseUrl);
91     EXPECT_EQ(srcUrl, baseUrl);
92 }
93 
94 /**
95  * @tc.name  : Test DashSubstituteTmpltStr
96  * @tc.number: DashSubstituteTmpltStr_001
97  * @tc.desc  : Test posEnd == std::string::npos
98  */
99 HWTEST_F(DashMpdUtilUnitTest, DashSubstituteTmpltStr_001, TestSize.Level0)
100 {
101     std::string segTmpltStr = "$Number%012";
102     std::string segTmpltIdentifier = "$Number";
103     std::string substitutionStr = "5";
104     int32_t ret = DashSubstituteTmpltStr(segTmpltStr, segTmpltIdentifier, substitutionStr);
105     EXPECT_EQ(ret, -1);
106 }
107 
108 /**
109  * @tc.name  : Test DashSubstituteTmpltStr
110  * @tc.number: DashSubstituteTmpltStr_002
111  * @tc.desc  : Test (str[0] == '%' && str[1] == '0') == false && (str[0] == '$') == false
112  */
113 HWTEST_F(DashMpdUtilUnitTest, DashSubstituteTmpltStr_002, TestSize.Level0)
114 {
115     std::string segTmpltStr = "$NumberABC";
116     std::string segTmpltIdentifier = "$Number";
117     std::string substitutionStr = "5";
118     int32_t ret = DashSubstituteTmpltStr(segTmpltStr, segTmpltIdentifier, substitutionStr);
119     EXPECT_EQ(ret, -1);
120 }
121 
122 /**
123  * @tc.name  : Test DashStrToDuration
124  * @tc.number: DashStrToDuration_001
125  * @tc.desc  : Test case 'D'
126  */
127 HWTEST_F(DashMpdUtilUnitTest, DashStrToDuration_001, TestSize.Level0)
128 {
129     std::string str = "P2D";
130     uint32_t duration = NUM_0;
131     int32_t ret = DashStrToDuration(str, duration);
132     EXPECT_EQ(ret, NUM_0);
133     EXPECT_EQ(duration, MS_OF_TWO_DAYS);
134 }
135 
136 /**
137  * @tc.name  : Test DashStrToDuration
138  * @tc.number: DashStrToDuration_002
139  * @tc.desc  : Test case default
140  */
141 HWTEST_F(DashMpdUtilUnitTest, DashStrToDuration_002, TestSize.Level0)
142 {
143     std::string str = "P2X";
144     uint32_t duration = NUM_0;
145     int32_t ret = DashStrToDuration(str, duration);
146     EXPECT_EQ(ret, NUM_0);
147     EXPECT_EQ(duration, NUM_0);
148 }
149 
150 /**
151  * @tc.name  : Test DashParseRange
152  * @tc.number: DashParseRange_001
153  * @tc.desc  : Test separatePosition == std::string::npos
154  */
155 HWTEST_F(DashMpdUtilUnitTest, DashParseRange_001, TestSize.Level0)
156 {
157     std::string rangeStr = "123456";
158     int64_t startRange = ERROR;
159     int64_t endRange = ERROR;
160     DashParseRange(rangeStr, startRange, endRange);
161     EXPECT_EQ(startRange, ERROR);
162     EXPECT_EQ(endRange, ERROR);
163 }
164 
165 /**
166  * @tc.name  : Test DashParseRange
167  * @tc.number: DashParseRange_002
168  * @tc.desc  : Test separatePosition == 0
169  */
170 HWTEST_F(DashMpdUtilUnitTest, DashParseRange_002, TestSize.Level0)
171 {
172     std::string rangeStr = "-123456";
173     int64_t startRange = ERROR;
174     int64_t endRange = ERROR;
175     DashParseRange(rangeStr, startRange, endRange);
176     EXPECT_EQ(startRange, ERROR);
177     EXPECT_EQ(endRange, ERROR);
178 }
179 
180 /**
181  * @tc.name  : Test DashStreamIsHdr
182  * @tc.number: DashStreamIsHdr_001
183  * @tc.desc  : Test default
184  */
185 HWTEST_F(DashMpdUtilUnitTest, DashStreamIsHdr_001, TestSize.Level0)
186 {
187     DashList<DashDescriptor*> essentialPropertyList;
188     bool isHdr = DashStreamIsHdr(essentialPropertyList);
189     EXPECT_EQ(isHdr, false);
190 }
191 
192 } // namespace HttpPluginLite
193 } // namespace Plugin
194 } // namespace Media
195 } // namespace OHOS