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_period_node_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 RET_TEST = 123;
27 const static int32_t NUM_TEST = 0;
SetUpTestCase(void)28 void DashPeriodNodeUnittest::SetUpTestCase(void) {}
TearDownTestCase(void)29 void DashPeriodNodeUnittest::TearDownTestCase(void) {}
SetUp(void)30 void DashPeriodNodeUnittest::SetUp(void)
31 {
32 dashPtr_ = std::make_shared<DashPeriodNode>();
33 }
TearDown(void)34 void DashPeriodNodeUnittest::TearDown(void)
35 {
36 dashPtr_ = nullptr;
37 }
38
39 /**
40 * @tc.name : Test GetAttr(_, std::string)
41 * @tc.number: GetAttr_001
42 * @tc.desc : Test periodAttr_[index].val_.length() > 0
43 */
44 HWTEST_F(DashPeriodNodeUnittest, GetAttr_001, TestSize.Level0)
45 {
46 ASSERT_NE(dashPtr_, nullptr);
47 std::string attrName = "id";
48 std::string sAttrVal = "";
49 dashPtr_->periodAttr_[NUM_TEST].val_ = std::to_string(RET_TEST);
50 dashPtr_->GetAttr(attrName, sAttrVal);
51 EXPECT_EQ(sAttrVal, std::to_string(RET_TEST));
52 }
53
54 /**
55 * @tc.name : Test GetAttr(_, uint32_t)
56 * @tc.number: GetAttr_002
57 * @tc.desc : Test periodAttr_[index].val_.length() > 0
58 */
59 HWTEST_F(DashPeriodNodeUnittest, GetAttr_002, TestSize.Level0)
60 {
61 ASSERT_NE(dashPtr_, nullptr);
62 std::string attrName = "id";
63 uint32_t uiAttrVal = 0;
64 dashPtr_->periodAttr_[NUM_TEST].val_ = std::to_string(RET_TEST);
65 dashPtr_->GetAttr(attrName, uiAttrVal);
66 EXPECT_EQ(uiAttrVal, RET_TEST);
67 }
68
69 /**
70 * @tc.name : Test GetAttr(_, int32_t)
71 * @tc.number: GetAttr_003
72 * @tc.desc : Test periodAttr_[index].val_.length() > 0
73 */
74 HWTEST_F(DashPeriodNodeUnittest, GetAttr_003, TestSize.Level0)
75 {
76 ASSERT_NE(dashPtr_, nullptr);
77 std::string attrName = "id";
78 int32_t uiAttrVal = 0;
79 dashPtr_->periodAttr_[NUM_TEST].val_ = std::to_string(RET_TEST);
80 dashPtr_->GetAttr(attrName, uiAttrVal);
81 EXPECT_EQ(uiAttrVal, RET_TEST);
82 }
83
84 /**
85 * @tc.name : Test GetAttr(_, uint64_t)
86 * @tc.number: GetAttr_004
87 * @tc.desc : Test periodAttr_[index].val_.length() > 0
88 */
89 HWTEST_F(DashPeriodNodeUnittest, GetAttr_004, TestSize.Level0)
90 {
91 ASSERT_NE(dashPtr_, nullptr);
92 std::string attrName = "id";
93 uint64_t uiAttrVal = 0;
94 dashPtr_->periodAttr_[NUM_TEST].val_ = std::to_string(RET_TEST);
95 dashPtr_->GetAttr(attrName, uiAttrVal);
96 EXPECT_EQ(uiAttrVal, RET_TEST);
97 }
98
99 /**
100 * @tc.name : Test GetAttr(_, double)
101 * @tc.number: GetAttr_005
102 * @tc.desc : Test periodAttr_[index].val_.length() > 0
103 */
104 HWTEST_F(DashPeriodNodeUnittest, GetAttr_005, TestSize.Level0)
105 {
106 ASSERT_NE(dashPtr_, nullptr);
107 std::string attrName = "id";
108 double uiAttrVal = 0;
109 dashPtr_->periodAttr_[NUM_TEST].val_ = std::to_string(RET_TEST);
110 dashPtr_->GetAttr(attrName, uiAttrVal);
111 EXPECT_EQ(uiAttrVal, RET_TEST);
112 }
113 }
114 }
115 }
116 }