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_representation_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 DashRepresentationManagerUnittest::SetUpTestCase(void) {}
TearDownTestCase(void)29 void DashRepresentationManagerUnittest::TearDownTestCase(void) {}
SetUp(void)30 void DashRepresentationManagerUnittest::SetUp(void)
31 {
32 dashPtr_ = std::make_shared<DashRepresentationManager>();
33 }
TearDown(void)34 void DashRepresentationManagerUnittest::TearDown(void)
35 {
36 dashPtr_ = nullptr;
37 }
38
39 /**
40 * @tc.name : Test Reset
41 * @tc.number: Reset_001
42 * @tc.desc : Test all
43 */
44 HWTEST_F(DashRepresentationManagerUnittest, Reset_001, TestSize.Level0)
45 {
46 ASSERT_NE(dashPtr_, nullptr);
47 auto representationInfo = new DashRepresentationInfo();
48 dashPtr_->representationInfo_ = representationInfo;
49 EXPECT_NE(dashPtr_->representationInfo_, nullptr);
50 dashPtr_->Reset();
51 EXPECT_EQ(dashPtr_->representationInfo_, nullptr);
52 EXPECT_EQ(dashPtr_->segTmpltFlag_, NUM_TEST);
53 delete representationInfo;
54 }
55
56 /**
57 * @tc.name : Test Init
58 * @tc.number: Init_001
59 * @tc.desc : Test representationInfo_ == nullptr
60 */
61 HWTEST_F(DashRepresentationManagerUnittest, Init_001, TestSize.Level0)
62 {
63 ASSERT_NE(dashPtr_, nullptr);
64 dashPtr_->segTmpltFlag_ = ID_TEST;
65 dashPtr_->representationInfo_ = nullptr;
66 dashPtr_->Init();
67 EXPECT_EQ(dashPtr_->segTmpltFlag_, ID_TEST);
68
69 auto representationInfo = new DashRepresentationInfo();
70 dashPtr_->representationInfo_ = representationInfo;
71 EXPECT_NE(dashPtr_->representationInfo_, nullptr);
72 dashPtr_->Init();
73 EXPECT_EQ(dashPtr_->segTmpltFlag_, NUM_TEST);
74 delete representationInfo;
75 dashPtr_->representationInfo_ = nullptr;
76 }
77
78 /**
79 * @tc.name : Test ParseInitSegment
80 * @tc.number: ParseInitSegment_001
81 * @tc.desc : Test representationInfo_->representationSegTmplt_ != nullptr
82 * Test initSegment_ != nullptr
83 */
84 HWTEST_F(DashRepresentationManagerUnittest, ParseInitSegment_001, TestSize.Level0)
85 {
86 ASSERT_NE(dashPtr_, nullptr);
87 auto representationInfo = new DashRepresentationInfo();
88 dashPtr_->representationInfo_ = representationInfo;
89 EXPECT_NE(dashPtr_->representationInfo_, nullptr);
90 DashSegTmpltInfo *dashSegTmpltInfo = new DashSegTmpltInfo();
91 dashSegTmpltInfo->segTmpltInitialization_ = "test";
92 dashPtr_->representationInfo_->representationSegTmplt_ = dashSegTmpltInfo;
93 EXPECT_NE(dashPtr_->representationInfo_->representationSegTmplt_, nullptr);
94 dashPtr_->ParseInitSegment();
95 EXPECT_NE(dashPtr_->initSegment_, nullptr);
96 EXPECT_EQ(dashPtr_->segTmpltFlag_, ID_TEST);
97
98 delete dashSegTmpltInfo;
99 dashPtr_->representationInfo_->representationSegTmplt_ = nullptr;
100 dashPtr_->ParseInitSegment();
101 EXPECT_EQ(dashPtr_->initSegment_, nullptr);
102 delete representationInfo;
103 dashPtr_->representationInfo_ = nullptr;
104 }
105
106 /**
107 * @tc.name : Test ParseInitSegmentBySegTmplt
108 * @tc.number: ParseInitSegmentBySegTmplt_001
109 * @tc.desc : Test all
110 */
111 HWTEST_F(DashRepresentationManagerUnittest, ParseInitSegmentBySegTmplt_001, TestSize.Level0)
112 {
113 ASSERT_NE(dashPtr_, nullptr);
114 auto representationInfo = new DashRepresentationInfo();
115 dashPtr_->representationInfo_ = representationInfo;
116 DashSegTmpltInfo *dashSegTmpltInfo = new DashSegTmpltInfo();
117 DashUrlType *dashUrlType = new DashUrlType();
118 dashSegTmpltInfo->multSegBaseInfo_.segBaseInfo_.initialization_ = dashUrlType;
119 dashPtr_->representationInfo_->representationSegTmplt_ = dashSegTmpltInfo;
120 dashPtr_->ParseInitSegmentBySegTmplt();
121 EXPECT_NE(dashPtr_->initSegment_, nullptr);
122
123
124 delete dashUrlType;
125 dashSegTmpltInfo->multSegBaseInfo_.segBaseInfo_.initialization_ = nullptr;
126 dashSegTmpltInfo->segTmpltInitialization_ = "test";
127 delete dashPtr_->initSegment_;
128 dashPtr_->initSegment_ = nullptr;
129 dashPtr_->ParseInitSegmentBySegTmplt();
130 EXPECT_NE(dashPtr_->initSegment_, nullptr);
131 EXPECT_EQ(dashPtr_->segTmpltFlag_, ID_TEST);
132
133 dashSegTmpltInfo->segTmpltInitialization_ = "";
134 dashPtr_->ParseInitSegmentBySegTmplt();
135 EXPECT_EQ(dashPtr_->initSegment_, nullptr);
136 delete dashSegTmpltInfo;
137 dashPtr_->representationInfo_->representationSegTmplt_ = nullptr;
138 delete representationInfo;
139 dashPtr_->representationInfo_ = nullptr;
140 }
141
142 /**
143 * @tc.name : Test GetRepresentationInfo && GetPreviousRepresentationInfo
144 * @tc.number: GetRepresentationInfo_001
145 * @tc.desc : Test all
146 */
147 HWTEST_F(DashRepresentationManagerUnittest, GetRepresentationInfo_001, TestSize.Level0)
148 {
149 ASSERT_NE(dashPtr_, nullptr);
150 auto ret = dashPtr_->GetRepresentationInfo();
151 EXPECT_EQ(ret, nullptr);
152
153 ret = dashPtr_->GetPreviousRepresentationInfo();
154 EXPECT_EQ(ret, nullptr);
155 }
156 }
157 }
158 }
159 }