• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include <exception>
16 #include <iostream>
17 #include <string>
18 #include <gtest/gtest.h>
19 #include <unistd.h>
20 #include <cstring>
21 #include <cstdint>
22 #include <cstdio>
23 #include <functional>
24 #include "sp_utils.h"
25 
26 using namespace testing::ext;
27 using namespace std;
28 
29 namespace OHOS {
30 namespace SmartPerf {
31 class SPdaemonUtilsTest : public testing::Test {
32 public:
SetUpTestCase()33     static void SetUpTestCase() {}
TearDownTestCase()34     static void TearDownTestCase() {}
SetUp()35     void SetUp() {}
TearDown()36     void TearDown() {}
37 };
38 
39 /**
40  * @tc.name: SPUtils::IntegerValueVerification
41  * @tc.desc: Test IntegerValueVerification
42  * @tc.type: FUNC
43  */
44 HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest001, TestSize.Level1)
45 {
46     std::string errorInfo;
47     std::map<std::string, std::string> mapInfo;
48     std::set<std::string> keys;
49 
50     keys.insert("N");
51     keys.insert("fl");
52     keys.insert("ftl");
53 
54     mapInfo["N"] = "";
55     mapInfo["fl"] = "";
56     mapInfo["ftl"] = "";
57 
58     bool ret = SPUtils::IntegerValueVerification(keys, mapInfo, errorInfo);
59     EXPECT_EQ(ret, false);
60 }
61 
62 HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest002, TestSize.Level1)
63 {
64     std::string errorInfo;
65     std::map<std::string, std::string> mapInfo;
66     std::set<std::string> keys;
67 
68     keys.insert("N");
69     keys.insert("fl");
70     keys.insert("ftl");
71 
72     mapInfo["N"] = "A";
73     mapInfo["fl"] = "B";
74     mapInfo["ftl"] = "C";
75 
76     bool ret = SPUtils::IntegerValueVerification(keys, mapInfo, errorInfo);
77     EXPECT_EQ(ret, false);
78 }
79 
80 HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest003, TestSize.Level1)
81 {
82     std::string errorInfo;
83     std::map<std::string, std::string> mapInfo;
84     std::set<std::string> keys;
85 
86     keys.insert("N");
87     keys.insert("fl");
88     keys.insert("ftl");
89 
90     mapInfo["N"] = "1";
91     mapInfo["fl"] = "2";
92     mapInfo["ftl"] = "3";
93 
94     bool ret = SPUtils::IntegerValueVerification(keys, mapInfo, errorInfo);
95     EXPECT_EQ(ret, true);
96 }
97 
98 /**
99  * @tc.name: SPUtils::VerifyValueStr
100  * @tc.desc: Test VerifyValueStr
101  * @tc.type: FUNC
102  */
103 HWTEST_F(SPdaemonUtilsTest, VerifyValueStrTest001, TestSize.Level1)
104 {
105     std::string errorInfo;
106     std::map<std::string, std::string> mapInfo;
107     mapInfo["VIEW"] = "";
108     bool ret = SPUtils::VerifyValueStr(mapInfo, errorInfo);
109     EXPECT_EQ(ret, false);
110 }
111 
112 HWTEST_F(SPdaemonUtilsTest, VerifyValueStrTest002, TestSize.Level1)
113 {
114     std::string errorInfo;
115     std::map<std::string, std::string> mapInfo;
116     mapInfo["VIEW"] = "TestVIEW";
117     mapInfo["PKG"] = "";
118     bool ret = SPUtils::VerifyValueStr(mapInfo, errorInfo);
119     EXPECT_EQ(ret, false);
120 }
121 
122 HWTEST_F(SPdaemonUtilsTest, VerifyValueStrTest003, TestSize.Level1)
123 {
124     std::string errorInfo;
125     std::map<std::string, std::string> mapInfo;
126     mapInfo["VIEW"] = "TestVIEW";
127     mapInfo["PKG"] = "TestPKG";
128     mapInfo["OUT"] = "";
129     bool ret = SPUtils::VerifyValueStr(mapInfo, errorInfo);
130     EXPECT_EQ(ret, false);
131 }
132 
133 HWTEST_F(SPdaemonUtilsTest, VerifyValueStrTest004, TestSize.Level1)
134 {
135     std::string errorInfo;
136     std::map<std::string, std::string> mapInfo;
137     mapInfo["VIEW"] = "TestVIEW";
138     mapInfo["PKG"] = "TestPKG";
139     mapInfo["OUT"] = "Test/sp_utils_test/";
140     bool ret = SPUtils::VerifyValueStr(mapInfo, errorInfo);
141     EXPECT_EQ(ret, false);
142 }
143 
144 HWTEST_F(SPdaemonUtilsTest, VerifyValueStrTest005, TestSize.Level1)
145 {
146     std::string errorInfo;
147     std::map<std::string, std::string> mapInfo;
148     mapInfo["VIEW"] = "TestVIEW";
149     mapInfo["PKG"] = "TestPKG";
150     mapInfo["OUT"] = "/sp_utils_test";
151     bool ret = SPUtils::VerifyValueStr(mapInfo, errorInfo);
152     EXPECT_EQ(ret, false);
153 }
154 
155 HWTEST_F(SPdaemonUtilsTest, VerifyValueStrTest006, TestSize.Level1)
156 {
157     std::string errorInfo;
158     std::map<std::string, std::string> mapInfo;
159     mapInfo["VIEW"] = "TestVIEW";
160     mapInfo["PKG"] = "TestPKG";
161     bool ret = SPUtils::VerifyValueStr(mapInfo, errorInfo);
162     EXPECT_EQ(ret, true);
163 }
164 
165 /**
166  * @tc.name: SPUtils::VeriyKey
167  * @tc.desc: Test VeriyKey
168  * @tc.type: FUNC
169  */
170 HWTEST_F(SPdaemonUtilsTest, VeriyKey001, TestSize.Level1)
171 {
172     std::set<std::string> keys;
173     std::map<std::string, std::string> mapInfo;
174     std::string errorInfo;
175 
176     keys.insert("apple");
177     keys.insert("banana");
178     keys.insert("cherry");
179     keys.insert("orange");
180     keys.insert("pineapple");
181 
182     mapInfo["A"] = "";
183     mapInfo["B"] = "";
184     mapInfo["C"] = "";
185 
186     bool ret = SPUtils::VeriyKey(keys, mapInfo, errorInfo);
187     EXPECT_EQ(ret, false);
188 }
189 
190 HWTEST_F(SPdaemonUtilsTest, VeriyKey002, TestSize.Level1)
191 {
192     std::set<std::string> keys;
193     std::map<std::string, std::string> mapInfo;
194     std::string errorInfo;
195 
196     keys.insert("apple");
197     keys.insert("banana");
198     keys.insert("cherry");
199     keys.insert("orange");
200     keys.insert("pineapple");
201 
202     mapInfo["apple"] = "";
203     mapInfo["cherry"] = "";
204     mapInfo["pineapple"] = "";
205 
206     bool ret = SPUtils::VeriyKey(keys, mapInfo, errorInfo);
207     EXPECT_EQ(ret, true);
208 }
209 
210 }
211 }
212