• 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 
16 #include "gtest/gtest.h"
17 
18 #include <sys/statvfs.h>
19 
20 #include "app_info_collector.h"
21 #include "utils.h"
22 
23 #define private public
24 #define protected public
25 #include "content_sensor_manager.h"
26 #include "device_info_collector.h"
27 #include "storage_info_collector.h"
28 #include "syscap_info_collector.h"
29 #include "system_info_collector.h"
30 #undef private
31 #undef protected
32 
33 namespace OHOS {
34 namespace DeviceProfile {
35 using namespace testing;
36 using namespace testing::ext;
37 namespace {
38 constexpr int32_t OHOS_TYPE = 10;
39 }
40 
41 
42 class ContentSensorTest : public testing::Test {
43 public:
44     static void SetUpTestCase();
45     static void TearDownTestCase();
46     void SetUp();
47     void TearDown();
48 };
49 
SetUpTestCase()50 void ContentSensorTest::SetUpTestCase()
51 {
52 }
53 
TearDownTestCase()54 void ContentSensorTest::TearDownTestCase()
55 {
56 }
57 
SetUp()58 void ContentSensorTest::SetUp()
59 {
60 }
61 
TearDown()62 void ContentSensorTest::TearDown()
63 {
64 }
65 
66 /**
67  * @tc.name: GetDeviceName_001
68  * @tc.desc: get device name
69  * @tc.type: FUNC
70  */
71 HWTEST_F(ContentSensorTest, GetDeviceName_001, TestSize.Level2)
72 {
73     DeviceInfoCollector devInfo;
74     auto result = devInfo.GetDeviceName();
75     EXPECT_NE(result, "");
76 }
77 
78 /**
79  * @tc.name: GetDeviceModel_002
80  * @tc.desc: get device model
81  * @tc.type: FUNC
82  */
83 HWTEST_F(ContentSensorTest, GetDeviceModel_002, TestSize.Level2)
84 {
85     DeviceInfoCollector devInfo;
86     auto result = devInfo.GetDeviceModel();
87     EXPECT_NE(result, "");
88 }
89 
90 /**
91  * @tc.name: GetDeviceUdid_003
92  * @tc.desc: get device udid
93  * @tc.type: FUNC
94  */
95 HWTEST_F(ContentSensorTest, GetDeviceUdid_003, TestSize.Level2)
96 {
97     DeviceInfoCollector devInfo;
98     auto result = devInfo.GetDeviceUdid();
99     EXPECT_NE(result, "");
100 }
101 
102 /**
103  * @tc.name: GetDevType_004
104  * @tc.desc: get device type
105  * @tc.type: FUNC
106  */
107 HWTEST_F(ContentSensorTest, GetDevType_004, TestSize.Level2)
108 {
109     DeviceInfoCollector devInfo;
110     auto result = devInfo.GetDevType();
111     EXPECT_NE(result, "");
112 }
113 
114 /**
115  * @tc.name: GetDeviceManufacturer_001
116  * @tc.desc: get device manufacturer
117  * @tc.type: FUNC
118  */
119 HWTEST_F(ContentSensorTest, GetDeviceManufacturer_001, TestSize.Level2)
120 {
121     DeviceInfoCollector devInfo;
122     auto result = devInfo.GetDeviceManufacturer();
123     EXPECT_NE(result, "");
124 }
125 
126 /**
127  * @tc.name: GetDeviceSerial_001
128  * @tc.desc: get device serial
129  * @tc.type: FUNC
130  */
131 HWTEST_F(ContentSensorTest, GetDeviceSerial_001, TestSize.Level2)
132 {
133     DeviceInfoCollector devInfo;
134     auto result = devInfo.GetDeviceSerial();
135     EXPECT_NE(result, "");
136 }
137 
138 /**
139  * @tc.name: GetTotalSize_001
140  * @tc.desc: get total size
141  * @tc.type: FUNC
142  * @tc.require: I5J7PW
143  */
144 HWTEST_F(ContentSensorTest, GetTotalSize_001, TestSize.Level2)
145 {
146     const char* PATH_DATA = "/data";
147     struct statvfs diskInfo;
148     int ret = statvfs(PATH_DATA, &diskInfo);
149     EXPECT_EQ(ret, 0);
150 }
151 
152 /**
153  * @tc.name: GetDmsVersion_001
154  * @tc.desc: get dms version
155  * @tc.type: FUNC
156  * @tc.require: I5RWKZ
157  */
158 HWTEST_F(ContentSensorTest, GetDmsVersion_001, TestSize.Level2)
159 {
160     AppInfoCollector appInfoCollector;
161     ServiceCharacteristicProfile profile;
162     bool result = appInfoCollector.ConvertToProfileData(profile);
163     EXPECT_EQ(result, true);
164 }
165 
166 /**
167  * @tc.name: GetOsType_001
168  * @tc.desc: GetOsType
169  * @tc.type: FUNC
170  * @tc.require: I52U5M
171  */
172 HWTEST_F(ContentSensorTest, GetOsType_001, TestSize.Level3)
173 {
174     SystemInfoCollector systemInfo;
175     int32_t result = systemInfo.GetOsType();
176     DTEST_LOG << "result:" << result << std::endl;
177     EXPECT_EQ(result, OHOS_TYPE);
178 }
179 
180 /**
181  * @tc.name: GetOsVersion_001
182  * @tc.desc: GetOsVersion
183  * @tc.type: FUNC
184  * @tc.require: I52U5M
185  */
186 HWTEST_F(ContentSensorTest, GetOsVersion_001, TestSize.Level3)
187 {
188     SystemInfoCollector systemInfo;
189     std::string result = systemInfo.GetOsVersion();
190     DTEST_LOG << "result:" << result << std::endl;
191     EXPECT_NE(result, "");
192 }
193 
194 /**
195  * @tc.name: SyscapInfoCollector_001
196  * @tc.desc: syscap info collector
197  * @tc.type: FUNC
198  * @tc.require: I59PZ3
199  */
200 HWTEST_F(ContentSensorTest, SyscapInfoCollector_001, TestSize.Level3)
201 {
202     ServiceCharacteristicProfile profile;
203     profile.SetServiceId("test");
204     profile.SetServiceType("test");
205     SyscapInfoCollector syscapInfo;
206     bool result = syscapInfo.ConvertToProfileData(profile);
207     EXPECT_EQ(result, true);
208 }
209 
210 /**
211  * @tc.name: SyscapInfoCollector_001
212  * @tc.desc: syscap info collector
213  * @tc.type: FUNC
214  * @tc.require: I59PZ3
215  */
216 HWTEST_F(ContentSensorTest, SyscapInfoCollector_002, TestSize.Level3)
217 {
218     ServiceCharacteristicProfile profile;
219     profile.SetServiceId("");
220     profile.SetServiceType("");
221     SyscapInfoCollector syscapInfo;
222     bool result = syscapInfo.ConvertToProfileData(profile);
223     EXPECT_EQ(result, true);
224 }
225 
226 /**
227  * @tc.name: SyscapInfoCollector_001
228  * @tc.desc: syscap info collector
229  * @tc.type: FUNC
230  * @tc.require: I59PZ3
231  */
232 HWTEST_F(ContentSensorTest, SyscapInfoCollector_003, TestSize.Level3)
233 {
234     ServiceCharacteristicProfile profile;
235     profile.SetServiceId("");
236     profile.SetServiceType("test");
237     SyscapInfoCollector syscapInfo;
238     bool result = syscapInfo.ConvertToProfileData(profile);
239     EXPECT_EQ(result, true);
240 }
241 
242 /**
243  * @tc.name: SyscapInfoCollector_001
244  * @tc.desc: syscap info collector
245  * @tc.type: FUNC
246  * @tc.require: I59PZ3
247  */
248 HWTEST_F(ContentSensorTest, SyscapInfoCollector_004, TestSize.Level3)
249 {
250     ServiceCharacteristicProfile profile;
251     profile.SetServiceId("test");
252     profile.SetServiceType("");
253     SyscapInfoCollector syscapInfo;
254     bool result = syscapInfo.ConvertToProfileData(profile);
255     EXPECT_EQ(result, true);
256 }
257 
258 /**
259  * @tc.name: StorageInfoCollector_001
260  * @tc.desc: syscap info collector
261  * @tc.type: FUNC
262  * @tc.require: I59PZ3
263  */
264 HWTEST_F(ContentSensorTest, StorageInfoCollector_001, TestSize.Level3)
265 {
266     ServiceCharacteristicProfile profile;
267     profile.SetServiceId("test");
268     profile.SetServiceType("");
269     StorageInfoCollector storageInfo;
270     bool result = storageInfo.ConvertToProfileData(profile);
271     EXPECT_EQ(result, true);
272 }
273 
274 /**
275  * @tc.name: GetTotalSize_002
276  * @tc.desc: get total size
277  * @tc.type: FUNC
278  * @tc.require: I59PZ3
279  */
280 HWTEST_F(ContentSensorTest, GetTotalSize_002, TestSize.Level3)
281 {
282     StorageInfoCollector storageInfo;
283     int64_t result = storageInfo.GetTotalSize();
284     EXPECT_NE(result, 0);
285 }
286 }
287 }
288