• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #define private public
21 #define protected public
22 #include "collector.h"
23 #include "distributed_device_profile_client.h"
24 #include "syscap_info_collector.h"
25 #include "system_info_collector.h"
26 #undef private
27 #undef protected
28 
29 namespace OHOS {
30 namespace DistributedDeviceProfile {
31 using namespace testing;
32 using namespace testing::ext;
33 
34 class DpContentSensorTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp();
39     void TearDown();
40 };
41 
SetUpTestCase()42 void DpContentSensorTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void DpContentSensorTest::TearDownTestCase()
47 {
48 }
49 
SetUp()50 void DpContentSensorTest::SetUp()
51 {
52 }
53 
TearDown()54 void DpContentSensorTest::TearDown()
55 {
56 }
57 
58 class CollectorListener : public Collector {
59 public:
CollectorListener()60     CollectorListener()
61     {
62     }
~CollectorListener()63     ~CollectorListener()
64     {
65     }
ConvertToProfile(DeviceProfile & deviceProfile)66     bool ConvertToProfile(DeviceProfile& deviceProfile) override
67     {
68         return true;
69     }
70 };
71 
72 /**
73  * @tc.name: Collect_001
74  * @tc.desc: Collect
75  * @tc.type: FUNC
76  */
77 HWTEST_F(DpContentSensorTest, Collect_001, TestSize.Level2)
78 {
79     CollectorListener collector;
80     DeviceProfile profile;
81     profile.SetDeviceId("test");
82     profile.SetDeviceName("test");
83     collector.Collect(profile);
84 }
85 
86 /**
87  * @tc.name: GetTotalSize_001
88  * @tc.desc: get total size
89  * @tc.type: FUNC
90  * @tc.require: I5J7PW
91  */
92 HWTEST_F(DpContentSensorTest, GetTotalSize_001, TestSize.Level2)
93 {
94     const char* PATH_DATA = "/data";
95     struct statvfs diskInfo;
96     int ret = statvfs(PATH_DATA, &diskInfo);
97     EXPECT_EQ(ret, 0);
98 }
99 
100 /**
101  * @tc.name: GetOsVersion_001
102  * @tc.desc: GetOsVersion
103  * @tc.type: FUNC
104  * @tc.require: I52U5M
105  */
106 HWTEST_F(DpContentSensorTest, GetOsVersion_001, TestSize.Level3)
107 {
108     SystemInfoCollector systemInfo;
109     std::string result = systemInfo.GetOsVersion();
110     EXPECT_NE(result, "");
111 }
112 
113 /**
114  * @tc.name: SyscapInfoCollector_001
115  * @tc.desc: syscap info collector
116  * @tc.type: FUNC
117  * @tc.require: I59PZ3
118  */
119 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_001, TestSize.Level3)
120 {
121     DeviceProfile profile;
122     profile.SetDeviceId("test");
123     profile.SetDeviceName("test");
124     SyscapInfoCollector syscapInfo;
125     bool result = syscapInfo.ConvertToProfile(profile);
126     EXPECT_EQ(result, true);
127 }
128 
129 /**
130  * @tc.name: SyscapInfoCollector_001
131  * @tc.desc: syscap info collector
132  * @tc.type: FUNC
133  * @tc.require: I59PZ3
134  */
135 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_002, TestSize.Level3)
136 {
137     DeviceProfile profile;
138     profile.SetDeviceId("");
139     profile.SetDeviceName("");
140     SyscapInfoCollector syscapInfo;
141     bool result = syscapInfo.ConvertToProfile(profile);
142     EXPECT_EQ(result, true);
143 }
144 
145 /**
146  * @tc.name: SyscapInfoCollector_001
147  * @tc.desc: syscap info collector
148  * @tc.type: FUNC
149  * @tc.require: I59PZ3
150  */
151 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_003, TestSize.Level3)
152 {
153     DeviceProfile profile;
154     profile.SetDeviceId("");
155     profile.SetDeviceName("test");
156     SyscapInfoCollector syscapInfo;
157     bool result = syscapInfo.ConvertToProfile(profile);
158     EXPECT_EQ(result, true);
159 }
160 
161 /**
162  * @tc.name: SyscapInfoCollector_001
163  * @tc.desc: syscap info collector
164  * @tc.type: FUNC
165  * @tc.require: I59PZ3
166  */
167 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_004, TestSize.Level3)
168 {
169     DeviceProfile profile;
170     profile.SetDeviceId("test");
171     profile.SetDeviceName("");
172     SyscapInfoCollector syscapInfo;
173     bool result = syscapInfo.ConvertToProfile(profile);
174     EXPECT_EQ(result, true);
175 }
176 }
177 }
178