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 "UTTest_dm_anonymous.h"
17
18 namespace OHOS {
19 namespace DistributedHardware {
SetUp()20 void DmAnonymousTest::SetUp()
21 {
22 }
TearDown()23 void DmAnonymousTest::TearDown()
24 {
25 }
SetUpTestCase()26 void DmAnonymousTest::SetUpTestCase()
27 {
28 }
TearDownTestCase()29 void DmAnonymousTest::TearDownTestCase()
30 {
31 }
32
33 namespace {
34 /**
35 * @tc.name: GetAnonyString_001
36 * @tc.desc: Return size of anony string
37 * @tc.type: FUNC
38 * @tc.require: AR000GHSJK
39 */
40 HWTEST_F(DmAnonymousTest, GetAnonyString_001, testing::ext::TestSize.Level0)
41 {
42 const std::string value = "valueTest";
43 std::string str = GetAnonyString(value);
44 int32_t ret = str.size();
45 EXPECT_EQ(ret, 8);
46 }
47
48 /**
49 * @tc.name: GetAnonyString_002
50 * @tc.desc: Return size of anony string
51 * @tc.type: FUNC
52 * @tc.require: AR000GHSJK
53 */
54 HWTEST_F(DmAnonymousTest, GetAnonyString_002, testing::ext::TestSize.Level0)
55 {
56 const std::string value = "va";
57 std::string str = GetAnonyString(value);
58 int32_t ret = str.size();
59 EXPECT_EQ(ret, 6);
60 }
61
62 /**
63 * @tc.name: GetAnonyString_003
64 * @tc.desc: Return size of anony string
65 * @tc.type: FUNC
66 * @tc.require: AR000GHSJK
67 */
68 HWTEST_F(DmAnonymousTest, GetAnonyString_003, testing::ext::TestSize.Level0)
69 {
70 const std::string value = "ohos.distributedhardware.devicemanager.resident";
71 std::string str = GetAnonyString(value);
72 int32_t ret = str.size();
73 EXPECT_EQ(ret, 14);
74 }
75
76 /**
77 * @tc.name: GetAnonyInt32_001
78 * @tc.desc: Return size of anony string
79 * @tc.type: FUNC
80 * @tc.require: AR000GHSJK
81 */
82 HWTEST_F(DmAnonymousTest, GetAnonyInt32_001, testing::ext::TestSize.Level0)
83 {
84 const int32_t value = 1;
85 std::string str = GetAnonyInt32(value);
86 int32_t ret = str.size();
87 EXPECT_EQ(ret, 1);
88 }
89
90 /**
91 * @tc.name: GetAnonyInt32_002
92 * @tc.desc: Return size of anony string
93 * @tc.type: FUNC
94 * @tc.require: AR000GHSJK
95 */
96 HWTEST_F(DmAnonymousTest, GetAnonyInt32_002, testing::ext::TestSize.Level0)
97 {
98 const int32_t value = 12;
99 std::string str = GetAnonyInt32(value);
100 int32_t ret = str.size();
101 EXPECT_EQ(ret, 2);
102 }
103
104 /**
105 * @tc.name: GetAnonyInt32_003
106 * @tc.desc: Return size of anony string
107 * @tc.type: FUNC
108 * @tc.require: AR000GHSJK
109 */
110 HWTEST_F(DmAnonymousTest, GetAnonyInt32_003, testing::ext::TestSize.Level0)
111 {
112 const int32_t value = 123456;
113 std::string str = GetAnonyInt32(value);
114 int32_t ret = str.size();
115 EXPECT_EQ(ret, 6);
116 }
117
118 /**
119 * @tc.name: IsNumberString_001
120 * @tc.desc: Return false if the string is not a number
121 * @tc.type: FUNC
122 * @tc.require: AR000GHSJK
123 */
124 HWTEST_F(DmAnonymousTest, IsNumberString_001, testing::ext::TestSize.Level0)
125 {
126 const std::string inputString = "";
127 bool ret = IsNumberString(inputString);
128 EXPECT_EQ(ret, false);
129 }
130
131 /**
132 * @tc.name: IsNumberString_002
133 * @tc.desc: Return false if the string is not a number
134 * @tc.type: FUNC
135 * @tc.require: AR000GHSJK
136 */
137 HWTEST_F(DmAnonymousTest, IsNumberString_002, testing::ext::TestSize.Level0)
138 {
139 const std::string inputString = "123inputstring";
140 bool ret = IsNumberString(inputString);
141 EXPECT_EQ(ret, false);
142 }
143
144 /**
145 * @tc.name: IsNumberString_003
146 * @tc.desc: Return true if the string is a number
147 * @tc.type: FUNC
148 * @tc.require: AR000GHSJK
149 */
150 HWTEST_F(DmAnonymousTest, IsNumberString_003, testing::ext::TestSize.Level0)
151 {
152 const std::string inputString = "25633981";
153 bool ret = IsNumberString(inputString);
154 EXPECT_EQ(ret, true);
155 }
156
157 /**
158 * @tc.name: GetErrorString_001
159 * @tc.desc: Return true if the string is a number
160 * @tc.type: FUNC
161 * @tc.require: AR000GHSJK
162 */
163 HWTEST_F(DmAnonymousTest, GetErrorString_001, testing::ext::TestSize.Level0)
164 {
165 int failedReason = -20000;
166 std::string errorMessage = "dm process execution failed.";
167 std::string ret = GetErrorString(failedReason);
168 EXPECT_EQ(ret, errorMessage);
169 }
170 } // namespace
171 } // namespace DistributedHardware
172 } // namespace OHOS