1 /*
2 * Copyright (c) 2022 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 "gtest/gtest.h"
17
18 #include "utils.h"
19
20 #define private public
21 #define protected public
22 #include "xml_helper.h"
23 #undef private
24 #undef protected
25
26 namespace OHOS {
27 namespace Memory {
28 using namespace testing;
29 using namespace testing::ext;
30
31 class XmlHelperTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void XmlHelperTest::SetUpTestCase()
40 {
41 }
42
TearDownTestCase()43 void XmlHelperTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void XmlHelperTest::SetUp()
48 {
49 }
50
TearDown()51 void XmlHelperTest::TearDown()
52 {
53 }
54
55 HWTEST_F(XmlHelperTest, setIntParamTest1, TestSize.Level1)
56 {
57 std::map<std::string, std::string> param;
58 param.insert(std::make_pair("key", "2147483647"));
59 std::string key = "key";
60 int dst;
61 XmlHelper::SetIntParam(param, key, dst, 0);
62 EXPECT_EQ(dst, 2147483647);
63 }
64
65 HWTEST_F(XmlHelperTest, setIntParamTest2, TestSize.Level1)
66 {
67 std::map<std::string, std::string> param;
68 param.insert(std::make_pair("key", "."));
69 std::string key = "key";
70 int dst;
71 XmlHelper::SetIntParam(param, key, dst, 0);
72 EXPECT_EQ(dst, 0);
73 }
74
75 HWTEST_F(XmlHelperTest, setIntParamTest3, TestSize.Level1)
76 {
77 std::map<std::string, std::string> param;
78 param.insert(std::make_pair("key", " "));
79 std::string key = "key";
80 int dst;
81 XmlHelper::SetIntParam(param, key, dst, 0);
82 EXPECT_EQ(dst, 0);
83 }
84
85 HWTEST_F(XmlHelperTest, setIntParamTest4, TestSize.Level1)
86 {
87 std::map<std::string, std::string> param;
88 param.insert(std::make_pair("key", "2147483648"));
89 std::string key = "key";
90 int dst;
91 XmlHelper::SetIntParam(param, key, dst, 0);
92 EXPECT_EQ(dst, 0);
93 }
94 }
95 }
96