1 /*
2  * Copyright (c) 2024 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_parser_unit_test.h"
17 #include <iostream>
18 #include "mpd_parser/dash_mpd_parser.h"
19 #include "mpd_parser/dash_mpd_manager.h"
20 #include "mpd_parser/dash_period_manager.h"
21 #include "mpd_parser/dash_adpt_set_manager.h"
22 #include "mpd_parser/i_dash_mpd_node.h"
23 #include "base64_utils.h"
24 #include "dash_segment_downloader.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Plugins {
29 namespace HttpPlugin {
30 namespace {
31 static const std::string BASE_MPD = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
32     "<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
33     "xmlns=\"urn:mpeg:DASH:schema:MPD:2011\" schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 "
34     "http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\""
35     " type=\"static\" availabilityStartTime=\"2022-10-05T19:38:39.263Z\" "
36     "mediaPresentationDuration=\"PT0H2M32S\" minBufferTime=\"PT10S\" "
37     "profiles=\"urn:mpeg:dash:profile:isoff-on-demand:2011\" >\n"
38     "    <Period>\n"
39     "        <AdaptationSet id=\"1\" group=\"1\" contentType=\"video\" par=\"4:3\" "
40     "segmentAlignment=\"true\" subsegmentAlignment=\"true\" subsegmentStartsWithSAP=\"1\" startWithSAP=\"1\">\n"
41     "            <Representation id=\"5\" bandwidth=\"7342976\" width=\"1920\" "
42     "height=\"1080\" codecs=\"avc1.640028\">\n"
43     "               <BaseURL>http://127.0.0.1:47777/test_dash/segment_base/2_video_1_1920X1080_6000_0_0.mp4</BaseURL>\n"
44     "                <SegmentBase timescale=\"90000\" indexRangeExact=\"true\" "
45     "indexRange=\"851-1166\">\n"
46     "                    <Initialization range=\"0-850\"/>\n"
47     "                </SegmentBase>\n"
48     "            </Representation>\n"
49     "        </AdaptationSet>\n"
50     "        <AdaptationSet id=\"2\" contentType=\"audio\" lang=\"und\" group=\"2\" "
51     "segmentAlignment=\"true\" subsegmentAlignment=\"true\" subsegmentStartsWithSAP=\"1\" "
52     "mimeType=\"audio/mp4\">\n"
53     "            <Representation id=\"8\" bandwidth=\"67135\" audioSamplingRate=\"44100\" "
54     "codecs=\"mp4a.40.5\">\n"
55     "                <AudioChannelConfiguration "
56     "schemeIdUri=\"urn:dolby:dash:audio_channel_configuration:2011\" value=\"0\"/>\n"
57     "                <BaseURL>http://127.0.0.1:47777/test_dash/segment_base/2_audio_6.mp4</BaseURL>\n"
58     "                <SegmentBase timescale=\"44100\" indexRangeExact=\"true\" "
59     "indexRange=\"756-1167\">\n"
60     "                    <Initialization range=\"0-755\"/>\n"
61     "                </SegmentBase>\n"
62     "            </Representation>\n"
63     "        </AdaptationSet>\n"
64     "        <AdaptationSet id=\"3\" contentType=\"audio\" lang=\"und\" group=\"2\" "
65     "segmentAlignment=\"true\" subsegmentAlignment=\"true\" subsegmentStartsWithSAP=\"1\" "
66     "mimeType=\"audio/mp4\">\n"
67     "        </AdaptationSet>\n"
68     "    </Period>\n"
69     "</MPD>";
70 }
71 using namespace testing::ext;
72 
SetUpTestCase(void)73 void DashMpdParserUnitTest::SetUpTestCase(void) {}
74 
TearDownTestCase(void)75 void DashMpdParserUnitTest::TearDownTestCase(void) {}
76 
SetUp(void)77 void DashMpdParserUnitTest::SetUp(void) {}
78 
TearDown(void)79 void DashMpdParserUnitTest::TearDown(void) {}
80 
81 HWTEST_F(DashMpdParserUnitTest, Test_ParseSegmentBaseMpd_001, TestSize.Level1)
82 {
83     std::string mpd = BASE_MPD;
84     std::shared_ptr<DashMpdParser> mpdParser = std::make_shared<DashMpdParser>();
85     mpdParser->ParseMPD(mpd.c_str(), mpd.length());
86     DashMpdInfo *mpdInfo{nullptr};
87     mpdParser->GetMPD(mpdInfo);
88     if (mpdInfo != nullptr) {
89         std::shared_ptr<DashMpdManager> mpdManager = std::make_shared<DashMpdManager>(mpdInfo, "http://1.0.0.1/1.mpd");
90         mpdManager->GetMpdInfo();
91         mpdManager->GetPeriods();
92         std::list<std::string> baseUrlList;
93         mpdManager->GetBaseUrlList(baseUrlList);
94         std::string mpdUrlBase;
95         std::string urlSchem;
96         mpdManager->MakeBaseUrl(mpdUrlBase, urlSchem);
97         DashPeriodInfo *first = mpdManager->GetFirstPeriod();
98         if (first != nullptr) {
99             DashPeriodInfo *next = mpdManager->GetNextPeriod(first);
100             EXPECT_EQ(next, nullptr);
101             std::shared_ptr<DashPeriodManager> periodMr = std::make_shared<DashPeriodManager>(first);
102             DashList<DashAdptSetInfo*> adptSetList = first->adptSetList_;
103             std::list<std::string> periodBaseUrlList;
104             periodMr->GetBaseUrlList(periodBaseUrlList);
105             EXPECT_EQ(periodBaseUrlList.empty(), true);
106             int32_t flag;
107             periodMr->GetInitSegment(flag);
108             periodMr->GetPeriod();
109             periodMr->GetPreviousPeriod();
110             bool isEmpty = periodMr->Empty();
111             EXPECT_EQ(isEmpty, false);
112         }
113     }
114     EXPECT_NE(nullptr, mpdInfo);
115 }
116 
117 HWTEST_F(DashMpdParserUnitTest, Test_ParseSegmentBaseMpd_002, TestSize.Level1)
118 {
119     std::string mpd = BASE_MPD;
120     std::shared_ptr<DashMpdParser> mpdParser = std::make_shared<DashMpdParser>();
121     mpdParser->ParseMPD(mpd.c_str(), mpd.length());
122     DashMpdInfo *mpdInfo{nullptr};
123     mpdParser->GetMPD(mpdInfo);
124     if (mpdInfo != nullptr) {
125         std::shared_ptr<DashMpdManager> mpdManager = std::make_shared<DashMpdManager>(mpdInfo, "http://1.0.0.1/1.mpd");
126         mpdManager->GetMpdInfo();
127         mpdManager->GetPeriods();
128         std::list<std::string> baseUrlList;
129         mpdManager->GetBaseUrlList(baseUrlList);
130         DashPeriodInfo *first = mpdManager->GetFirstPeriod();
131         if (first != nullptr) {
132             DashList<DashAdptSetInfo*> adptSetList = first->adptSetList_;
133             std::shared_ptr<DashAdptSetManager> adpSetMr = std::make_shared<DashAdptSetManager>(adptSetList.front());
134             bool isOnDemand = adpSetMr->IsOnDemand();
135             EXPECT_EQ(isOnDemand, true);
136             std::list<std::string> adpBaseUrlList;
137             adpSetMr->GetBaseUrlList(adpBaseUrlList);
138             EXPECT_EQ(adpBaseUrlList.empty(), true);
139             std::vector<uint32_t> bandwidths;
140             adpSetMr->GetBandwidths(bandwidths);
141             EXPECT_NE(bandwidths.empty(), true);
142             DashRepresentationInfo *reInfo = adpSetMr->GetRepresentationByBandwidth(7342976);
143             EXPECT_NE(reInfo, nullptr);
144             DashRepresentationInfo *highReInfo = adpSetMr->GetHighRepresentation();
145             EXPECT_NE(highReInfo, nullptr);
146             DashRepresentationInfo *lowReInfo = adpSetMr->GetLowRepresentation();
147             EXPECT_NE(lowReInfo, nullptr);
148             std::string mimeType = adpSetMr->GetMime();
149             EXPECT_NE(mimeType.empty(), true);
150         }
151     }
152     EXPECT_NE(nullptr, mpdInfo);
153 }
154 
155 HWTEST_F(DashMpdParserUnitTest, Test_ParseSegmentListMpd_001, TestSize.Level1)
156 {
157     std::string mpd = "<?xml version=\"1.0\" ?>\n"
158                       "<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\" profiles=\"urn:mpeg:dash:profile:isoff-live:2011\""
159                       " minBufferTime=\"PT2.00S\" mediaPresentationDuration=\"PT01M1.100S\" type=\"static\">\n"
160                       "  <Period>\n"
161                       "    <AdaptationSet mimeType=\"video/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\" "
162                       "minWidth=\"1280\" maxWidth=\"2560\" minHeight=\"720\" maxHeight=\"1440\">\n"
163                       "      <Representation id=\"video/1\" codecs=\"hev1.2.4.H120.90\" width=\"1280\" "
164                       "height=\"720\" scanType=\"progressive\" frameRate=\"30\" bandwidth=\"1955284\">\n"
165                       "        <SegmentList timescale=\"1000\" duration=\"2000\">\n"
166                       "          <Initialization sourceURL=\"video/1/init.mp4\"/>\n"
167                       "          <SegmentTimeline>\n"
168                       "              <S t=\"0\" d=\"2000\" />\n"
169                       "              <S d=\"2000\" />\n"
170                       "              <S d=\"2000\" />\n"
171                       "              <S d=\"2000\" />\n"
172                       "          </SegmentTimeline>\n"
173                       "          <SegmentURL media=\"video/1/seg-1.m4s\" TI=\"6.84\" SI=\"35.15\"/>\n"
174                       "          <SegmentURL media=\"video/1/seg-2.m4s\" TI=\"15.14\" SI=\"38.64\"/>\n"
175                       "        </SegmentList>\n"
176                       "      </Representation>\n"
177                       "      <Representation id=\"video/2\" codecs=\"hev1.2.4.H120.90\" width=\"1920\" "
178                       "height=\"1080\" scanType=\"progressive\" frameRate=\"30\" bandwidth=\"3282547\">\n"
179                       "        <SegmentList timescale=\"1000\" duration=\"2000\">\n"
180                       "          <Initialization sourceURL=\"video/2/init.mp4\"/>\n"
181                       "          <SegmentURL media=\"video/2/seg-1.m4s\" TI=\"6.98\" SI=\"30.1\"/>\n"
182                       "          <SegmentURL media=\"video/2/seg-2.m4s\" TI=\"15.09\" SI=\"33.79\"/>\n"
183                       "        </SegmentList>\n"
184                       "      </Representation>\n"
185                       "    </AdaptationSet>\n"
186                       "    <AdaptationSet mimeType=\"audio/mp4\" startWithSAP=\"1\" segmentAlignment=\"true\">\n"
187                       "      <Representation id=\"audio/und/mp4a\" codecs=\"mp4a.40.2\" bandwidth=\"132195\" "
188                       "audioSamplingRate=\"48000\">\n"
189                       "        <AudioChannelConfiguration "
190                       "schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"2\"/>\n"
191                       "        <SegmentList timescale=\"1000\" duration=\"2000\">\n"
192                       "          <Initialization sourceURL=\"audio/und/mp4a/init.mp4\"/>\n"
193                       "          <SegmentURL media=\"audio/und/mp4a/seg-1.m4s\"/>\n"
194                       "          <SegmentURL media=\"audio/und/mp4a/seg-2.m4s\"/>\n"
195                       "        </SegmentList>\n"
196                       "      </Representation>\n"
197                       "    </AdaptationSet>\n"
198                       "  </Period>\n"
199                       "</MPD>";
200     std::shared_ptr<DashMpdParser> mpdParser = std::make_shared<DashMpdParser>();
201     mpdParser->ParseMPD(mpd.c_str(), mpd.length());
202     DashMpdInfo *mpdInfo{nullptr};
203     mpdParser->GetMPD(mpdInfo);
204     EXPECT_NE(nullptr, mpdInfo);
205 }
206 
207 HWTEST_F(DashMpdParserUnitTest, Test_ParseSegmentTemplateMpd_001, TestSize.Level1)
208 {
209     std::string mpd = "<?xml version=\"1.0\" ?>\n"
210                       "<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\" profiles=\"urn:mpeg:dash:profile:isoff-live:2011\""
211                       " minBufferTime=\"PT2.00S\" mediaPresentationDuration=\"PT01M1.100S\" type=\"static\">\n"
212                       "  <!-- Created with Bento4 mp4-dash.py, VERSION=1.7.0-613 -->\n"
213                       "  <Period>\n"
214                       "    <!-- Video -->\n"
215                       "    <AdaptationSet mimeType=\"video/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\" "
216                       "minWidth=\"1280\" maxWidth=\"2560\" minHeight=\"720\" maxHeight=\"1440\">\n"
217                       "      <SegmentTemplate timescale=\"1000\" duration=\"2000\" "
218                       "initialization=\"$RepresentationID$/init.mp4\" media=\"$RepresentationID$/seg-$Number%04d$.m4s\""
219                       " startNumber=\"1\">\n"
220                       "          <SegmentTimeline>\n"
221                       "              <S t=\"0\" d=\"2000\" />\n"
222                       "              <S d=\"2000\" />\n"
223                       "              <S d=\"2000\" />\n"
224                       "              <S d=\"2000\" />\n"
225                       "          </SegmentTimeline>"
226                       "      </SegmentTemplate>\n"
227                       "      <Representation id=\"video/1\" codecs=\"hev1.2.4.H120.90\" width=\"1280\" height=\"720\" "
228                       "scanType=\"progressive\" frameRate=\"30\" bandwidth=\"1955284\"/>\n"
229                       "      <Representation id=\"video/2\" codecs=\"hev1.2.4.H120.90\" width=\"1920\" height=\"1080\""
230                       " scanType=\"progressive\" frameRate=\"30\" bandwidth=\"3282547\"/>\n"
231                       "      <Representation id=\"video/3\" codecs=\"hev1.2.4.H150.90\" width=\"2560\" height=\"1440\""
232                       " scanType=\"progressive\" frameRate=\"30\" bandwidth=\"4640480\"/>\n"
233                       "    </AdaptationSet>\n"
234                       "    <!-- Audio -->\n"
235                       "    <AdaptationSet mimeType=\"audio/mp4\" startWithSAP=\"1\" segmentAlignment=\"true\">\n"
236                       "      <SegmentTemplate timescale=\"1000\" duration=\"2000\" "
237                       "initialization=\"$RepresentationID$/init.mp4\" media=\"$RepresentationID$/seg-$Number%04d$.m4s\""
238                       " startNumber=\"1\"/>\n"
239                       "      <Representation id=\"audio/und/mp4a\" codecs=\"mp4a.40.2\" bandwidth=\"132195\" "
240                       "audioSamplingRate=\"48000\">\n"
241                       "        <AudioChannelConfiguration "
242                       "schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"2\"/>\n"
243                       "      </Representation>\n"
244                       "    </AdaptationSet>\n"
245                       "  </Period>\n"
246                       "</MPD>";
247     std::shared_ptr<DashMpdParser> mpdParser = std::make_shared<DashMpdParser>();
248     mpdParser->ParseMPD(mpd.c_str(), mpd.length());
249     DashMpdInfo *mpdInfo{nullptr};
250     mpdParser->GetMPD(mpdInfo);
251     EXPECT_NE(nullptr, mpdInfo);
252 }
253 
254 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_001, TestSize.Level1)
255 {
256     IDashMpdNode *node = IDashMpdNode::CreateNode("MPD");
257     if (node != nullptr) {
258         uint32_t uiAttrVal;
259         node->GetAttr("id", uiAttrVal);
260         node->GetAttr("test", uiAttrVal);
261         EXPECT_EQ(uiAttrVal, 0);
262         int32_t iAttrVal;
263         node->GetAttr("id", iAttrVal);
264         node->GetAttr("test", iAttrVal);
265         EXPECT_EQ(iAttrVal, 0);
266         uint64_t ullAttrVal;
267         node->GetAttr("id", ullAttrVal);
268         node->GetAttr("test", ullAttrVal);
269         EXPECT_EQ(ullAttrVal, 0);
270         double dAttrVal;
271         node->GetAttr("id", dAttrVal);
272         node->GetAttr("test", dAttrVal);
273         EXPECT_EQ(dAttrVal, 0.0);
274     }
275 }
276 
277 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_002, TestSize.Level1)
278 {
279     IDashMpdNode *node = IDashMpdNode::CreateNode("Period");
280     if (node != nullptr) {
281         uint32_t uiAttrVal;
282         node->GetAttr("id", uiAttrVal);
283         node->GetAttr("test", uiAttrVal);
284         EXPECT_EQ(uiAttrVal, 0);
285         int32_t iAttrVal;
286         node->GetAttr("id", iAttrVal);
287         node->GetAttr("test", iAttrVal);
288         EXPECT_EQ(iAttrVal, 0);
289         uint64_t ullAttrVal;
290         node->GetAttr("id", ullAttrVal);
291         node->GetAttr("test", ullAttrVal);
292         EXPECT_EQ(ullAttrVal, 0);
293         double dAttrVal;
294         node->GetAttr("id", dAttrVal);
295         node->GetAttr("test", dAttrVal);
296         EXPECT_EQ(dAttrVal, 0.0);
297     }
298 }
299 
300 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_003, TestSize.Level1)
301 {
302     IDashMpdNode *node = IDashMpdNode::CreateNode("AdaptationSet");
303     if (node != nullptr) {
304         uint32_t uiAttrVal;
305         node->GetAttr("id", uiAttrVal);
306         node->GetAttr("test", uiAttrVal);
307         EXPECT_EQ(uiAttrVal, 0);
308         int32_t iAttrVal;
309         node->GetAttr("id", iAttrVal);
310         node->GetAttr("test", iAttrVal);
311         EXPECT_EQ(iAttrVal, 0);
312         uint64_t ullAttrVal;
313         node->GetAttr("id", ullAttrVal);
314         node->GetAttr("test", ullAttrVal);
315         EXPECT_EQ(ullAttrVal, 0);
316         double dAttrVal;
317         node->GetAttr("id", dAttrVal);
318         node->GetAttr("test", dAttrVal);
319         EXPECT_EQ(dAttrVal, 0.0);
320     }
321 }
322 
323 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_004, TestSize.Level1)
324 {
325     IDashMpdNode *node = IDashMpdNode::CreateNode("ContentComponent");
326     if (node != nullptr) {
327         uint32_t uiAttrVal;
328         node->GetAttr("id", uiAttrVal);
329         node->GetAttr("test", uiAttrVal);
330         EXPECT_EQ(uiAttrVal, 0);
331         int32_t iAttrVal;
332         node->GetAttr("id", iAttrVal);
333         node->GetAttr("test", iAttrVal);
334         EXPECT_EQ(iAttrVal, 0);
335         uint64_t ullAttrVal;
336         node->GetAttr("id", ullAttrVal);
337         node->GetAttr("test", ullAttrVal);
338         EXPECT_EQ(ullAttrVal, 0);
339         double dAttrVal;
340         node->GetAttr("id", dAttrVal);
341         node->GetAttr("test", dAttrVal);
342         EXPECT_EQ(dAttrVal, 0.0);
343     }
344 }
345 
346 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_005, TestSize.Level1)
347 {
348     IDashMpdNode *node = IDashMpdNode::CreateNode("Representation");
349     if (node != nullptr) {
350         uint32_t uiAttrVal;
351         node->GetAttr("id", uiAttrVal);
352         node->GetAttr("test", uiAttrVal);
353         EXPECT_EQ(uiAttrVal, 0);
354         int32_t iAttrVal;
355         node->GetAttr("id", iAttrVal);
356         node->GetAttr("test", iAttrVal);
357         EXPECT_EQ(iAttrVal, 0);
358         uint64_t ullAttrVal;
359         node->GetAttr("id", ullAttrVal);
360         node->GetAttr("test", ullAttrVal);
361         EXPECT_EQ(ullAttrVal, 0);
362         double dAttrVal;
363         node->GetAttr("id", dAttrVal);
364         node->GetAttr("test", dAttrVal);
365         EXPECT_EQ(dAttrVal, 0.0);
366     }
367 }
368 
369 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_006, TestSize.Level1)
370 {
371     IDashMpdNode *node = IDashMpdNode::CreateNode("SegmentBase");
372     if (node != nullptr) {
373         uint32_t uiAttrVal;
374         node->GetAttr("timescale", uiAttrVal);
375         node->GetAttr("test", uiAttrVal);
376         EXPECT_EQ(uiAttrVal, 0);
377         int32_t iAttrVal;
378         node->GetAttr("timescale", iAttrVal);
379         node->GetAttr("test", iAttrVal);
380         EXPECT_EQ(iAttrVal, 0);
381         uint64_t ullAttrVal;
382         node->GetAttr("timescale", ullAttrVal);
383         node->GetAttr("test", ullAttrVal);
384         EXPECT_EQ(ullAttrVal, 0);
385         double dAttrVal;
386         node->GetAttr("timescale", dAttrVal);
387         node->GetAttr("test", dAttrVal);
388         EXPECT_EQ(dAttrVal, 0.0);
389     }
390 }
391 
392 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_007, TestSize.Level1)
393 {
394     IDashMpdNode *node = IDashMpdNode::CreateNode("MultipleSegmentBase");
395     if (node != nullptr) {
396         uint32_t uiAttrVal;
397         node->GetAttr("duration", uiAttrVal);
398         node->GetAttr("test", uiAttrVal);
399         EXPECT_EQ(uiAttrVal, 0);
400         int32_t iAttrVal;
401         node->GetAttr("duration", iAttrVal);
402         node->GetAttr("test", iAttrVal);
403         EXPECT_EQ(iAttrVal, 0);
404         uint64_t ullAttrVal;
405         node->GetAttr("duration", ullAttrVal);
406         node->GetAttr("test", ullAttrVal);
407         EXPECT_EQ(ullAttrVal, 0);
408         double dAttrVal;
409         node->GetAttr("duration", dAttrVal);
410         node->GetAttr("test", dAttrVal);
411         EXPECT_EQ(dAttrVal, 0.0);
412     }
413 }
414 
415 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_008, TestSize.Level1)
416 {
417     IDashMpdNode *node = IDashMpdNode::CreateNode("SegmentList");
418     if (node != nullptr) {
419         uint32_t uiAttrVal;
420         node->GetAttr("media", uiAttrVal);
421         node->GetAttr("test", uiAttrVal);
422         EXPECT_EQ(uiAttrVal, 0);
423         int32_t iAttrVal;
424         node->GetAttr("media", iAttrVal);
425         node->GetAttr("test", iAttrVal);
426         EXPECT_EQ(iAttrVal, 0);
427         uint64_t ullAttrVal;
428         node->GetAttr("media", ullAttrVal);
429         node->GetAttr("test", ullAttrVal);
430         EXPECT_EQ(ullAttrVal, 0);
431         double dAttrVal;
432         node->GetAttr("media", dAttrVal);
433         node->GetAttr("test", dAttrVal);
434         EXPECT_EQ(dAttrVal, 0.0);
435     }
436 }
437 
438 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_009, TestSize.Level1)
439 {
440     IDashMpdNode *node = IDashMpdNode::CreateNode("SegmentTemplate");
441     if (node != nullptr) {
442         uint32_t uiAttrVal;
443         node->GetAttr("media", uiAttrVal);
444         node->GetAttr("test", uiAttrVal);
445         EXPECT_EQ(uiAttrVal, 0);
446         int32_t iAttrVal;
447         node->GetAttr("media", iAttrVal);
448         node->GetAttr("test", iAttrVal);
449         EXPECT_EQ(iAttrVal, 0);
450         uint64_t ullAttrVal;
451         node->GetAttr("media", ullAttrVal);
452         node->GetAttr("test", ullAttrVal);
453         EXPECT_EQ(ullAttrVal, 0);
454         double dAttrVal;
455         node->GetAttr("media", dAttrVal);
456         node->GetAttr("test", dAttrVal);
457         EXPECT_EQ(dAttrVal, 0.0);
458     }
459 }
460 
461 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_010, TestSize.Level1)
462 {
463     IDashMpdNode *node = IDashMpdNode::CreateNode("Initialization");
464     if (node != nullptr) {
465         uint32_t uiAttrVal;
466         node->GetAttr("sourceURL", uiAttrVal);
467         node->GetAttr("test", uiAttrVal);
468         EXPECT_EQ(uiAttrVal, 0);
469         int32_t iAttrVal;
470         node->GetAttr("sourceURL", iAttrVal);
471         node->GetAttr("test", iAttrVal);
472         EXPECT_EQ(iAttrVal, 0);
473         uint64_t ullAttrVal;
474         node->GetAttr("sourceURL", ullAttrVal);
475         node->GetAttr("test", ullAttrVal);
476         EXPECT_EQ(ullAttrVal, 0);
477         double dAttrVal;
478         node->GetAttr("sourceURL", dAttrVal);
479         node->GetAttr("test", dAttrVal);
480         EXPECT_EQ(dAttrVal, 0.0);
481     }
482 }
483 
484 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_011, TestSize.Level1)
485 {
486     IDashMpdNode *node = IDashMpdNode::CreateNode("SegmentTimeline");
487     if (node != nullptr) {
488         uint32_t uiAttrVal;
489         node->GetAttr("t", uiAttrVal);
490         node->GetAttr("test", uiAttrVal);
491         EXPECT_EQ(uiAttrVal, 0);
492         int32_t iAttrVal;
493         node->GetAttr("t", iAttrVal);
494         node->GetAttr("test", iAttrVal);
495         EXPECT_EQ(iAttrVal, 0);
496         uint64_t ullAttrVal;
497         node->GetAttr("t", ullAttrVal);
498         node->GetAttr("test", ullAttrVal);
499         EXPECT_EQ(ullAttrVal, 0);
500         double dAttrVal;
501         node->GetAttr("t", dAttrVal);
502         node->GetAttr("test", dAttrVal);
503         EXPECT_EQ(dAttrVal, 0.0);
504     }
505 }
506 
507 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_012, TestSize.Level1)
508 {
509     IDashMpdNode *node = IDashMpdNode::CreateNode("ContentProtection");
510     if (node != nullptr) {
511         uint32_t uiAttrVal;
512         node->GetAttr("schemeIdUri", uiAttrVal);
513         node->GetAttr("test", uiAttrVal);
514         EXPECT_EQ(uiAttrVal, 0);
515         int32_t iAttrVal;
516         node->GetAttr("schemeIdUri", iAttrVal);
517         node->GetAttr("test", iAttrVal);
518         EXPECT_EQ(iAttrVal, 0);
519         uint64_t ullAttrVal;
520         node->GetAttr("schemeIdUri", ullAttrVal);
521         node->GetAttr("test", ullAttrVal);
522         EXPECT_EQ(ullAttrVal, 0);
523         double dAttrVal;
524         node->GetAttr("schemeIdUri", dAttrVal);
525         node->GetAttr("test", dAttrVal);
526         EXPECT_EQ(dAttrVal, 0.0);
527     }
528 }
529 
530 HWTEST_F(DashMpdParserUnitTest, Test_ParserNode_013, TestSize.Level1)
531 {
532     IDashMpdNode *node = IDashMpdNode::CreateNode("SegmentURL");
533     if (node != nullptr) {
534         uint32_t uiAttrVal;
535         node->GetAttr("media", uiAttrVal);
536         node->GetAttr("test", uiAttrVal);
537         EXPECT_EQ(uiAttrVal, 0);
538         int32_t iAttrVal;
539         node->GetAttr("media", iAttrVal);
540         node->GetAttr("test", iAttrVal);
541         EXPECT_EQ(iAttrVal, 0);
542         uint64_t ullAttrVal;
543         node->GetAttr("media", ullAttrVal);
544         node->GetAttr("test", ullAttrVal);
545         EXPECT_EQ(ullAttrVal, 0);
546         double dAttrVal;
547         node->GetAttr("media", dAttrVal);
548         node->GetAttr("test", dAttrVal);
549         EXPECT_EQ(dAttrVal, 0.0);
550     }
551 }
552 
553 HWTEST_F(DashMpdParserUnitTest, Test_Base64, TestSize.Level1)
554 {
555     uint8_t src[2048];
556     uint32_t srcSize = 0;
557     uint8_t dest[2048]; // 2048: pssh len
558     uint32_t destSize = 2048; // 2048: pssh len
559     bool ret = Base64Utils::Base64Decode(src, srcSize, dest, &destSize);
560     EXPECT_FALSE(ret);
561     uint8_t *src1 = nullptr; // 2048: pssh len
562     ret = Base64Utils::Base64Decode(src1, srcSize, dest, &destSize);
563     EXPECT_FALSE(ret);
564     uint8_t *dest1 = nullptr;
565     ret = Base64Utils::Base64Decode(src, srcSize, dest1, &destSize);
566     EXPECT_FALSE(ret);
567     uint32_t *destSize1 = nullptr;
568     ret = Base64Utils::Base64Decode(src, srcSize, dest, destSize1);
569     EXPECT_FALSE(ret);
570     srcSize = 2049;
571     ret = Base64Utils::Base64Decode(src, srcSize, dest, &destSize);
572     EXPECT_FALSE(ret);
573 }
574 
575 HWTEST_F(DashMpdParserUnitTest, Test_Base64_001, TestSize.Level1)
576 {
577     uint8_t src[5] = {0}; // 5: srcSize
578     uint8_t dest[20]; // 20:destSize
579     uint32_t destSize = sizeof(dest);
580     bool ret = Base64Utils::Base64Decode(src, 5, dest, &destSize); // 5: srcSize
581     EXPECT_FALSE(ret);
582 }
583 
584 HWTEST_F(DashMpdParserUnitTest, Test_Base64_002, TestSize.Level1)
585 {
586     const uint8_t src[] = "dGVzdCBzdHJpbmc="; // base64 编码的 "test string"
587     uint8_t dest[20];                         // 20:预期解码输出的大小
588     uint32_t destSize = sizeof(dest);
589 
590     bool ret = Base64Utils::Base64Decode(src, sizeof(src) - 1, dest, &destSize);
591     ASSERT_TRUE(ret);
592     ASSERT_EQ(destSize, 11u); // 11:"test string" 的长度
593     ASSERT_EQ(std::string(reinterpret_cast<char *>(dest), destSize), "test string");
594 }
595 
596 HWTEST_F(DashMpdParserUnitTest, Test_Base64_003, TestSize.Level1)
597 {
598     const uint8_t src[] = "€€€€";
599     uint8_t dest[20]; // 20:destSize
600     uint32_t destSize = sizeof(dest);
601 
602     bool ret = Base64Utils::Base64Decode(src, sizeof(src) - 1, dest, &destSize);
603     EXPECT_FALSE(ret);
604 }
605 }
606 }
607 }
608 }