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 "xml_element.h"
17 #include "gtest/gtest.h"
18
19 using namespace std;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Media {
24 namespace Plugins {
25 namespace HttpPlugin {
26 class XmlElementUnitTest : public testing::Test {
27 public:
SetUpTestCase(void)28 static void SetUpTestCase(void) {}
TearDownTestCase(void)29 static void TearDownTestCase(void) {}
30 void SetUp(void);
31 void TearDown(void);
32 protected:
33 std::shared_ptr<XmlElement> xmlElement_;
34 };
35
SetUp(void)36 void XmlElementUnitTest::SetUp(void)
37 {
38 xmlElement_ = std::make_shared<XmlElement>(nullptr);
39 }
40
TearDown(void)41 void XmlElementUnitTest::TearDown(void)
42 {
43 xmlElement_.reset();
44 }
45
46 /**
47 * @tc.name : Test GetName API
48 * @tc.number: GetName_001
49 * @tc.desc : Test name == nullptr
50 */
51 HWTEST_F(XmlElementUnitTest, GetName_001, TestSize.Level1)
52 {
53 ASSERT_NE(nullptr, xmlElement_);
54 xmlNode node;
55 node.name = nullptr;
56 xmlElement_->xmlNodePtr_ = &node;
57 ASSERT_NE(nullptr, xmlElement_->xmlNodePtr_);
58 ASSERT_EQ("", xmlElement_->GetName());
59 }
60
61 /**
62 * @tc.name : Test GetText API
63 * @tc.number: GetText_001
64 * @tc.desc : Test context == nullptr
65 */
66 HWTEST_F(XmlElementUnitTest, GetText_001, TestSize.Level1)
67 {
68 ASSERT_NE(nullptr, xmlElement_);
69 xmlNode node;
70 node.name = nullptr;
71 xmlElement_->xmlNodePtr_ = &node;
72 ASSERT_EQ("", xmlElement_->GetText());
73 }
74 }
75 }
76 }
77 }