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 collector.Collect(profile);
85 EXPECT_EQ(profile.deviceName_, "test");
86 }
87
88 /**
89 * @tc.name: GetTotalSize_001
90 * @tc.desc: get total size
91 * @tc.type: FUNC
92 * @tc.require: I5J7PW
93 */
94 HWTEST_F(DpContentSensorTest, GetTotalSize_001, TestSize.Level2)
95 {
96 const char* PATH_DATA = "/data";
97 struct statvfs diskInfo;
98 int ret = statvfs(PATH_DATA, &diskInfo);
99 EXPECT_EQ(ret, 0);
100 }
101
102 /**
103 * @tc.name: GetOsVersion_001
104 * @tc.desc: GetOsVersion
105 * @tc.type: FUNC
106 * @tc.require: I52U5M
107 */
108 HWTEST_F(DpContentSensorTest, GetOsVersion_001, TestSize.Level3)
109 {
110 SystemInfoCollector systemInfo;
111 std::string result = systemInfo.GetOsVersion();
112 EXPECT_NE(result, "");
113 }
114
115 /**
116 * @tc.name: SyscapInfoCollector_001
117 * @tc.desc: syscap info collector
118 * @tc.type: FUNC
119 * @tc.require: I59PZ3
120 */
121 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_001, TestSize.Level3)
122 {
123 DeviceProfile profile;
124 profile.SetDeviceId("test");
125 profile.SetDeviceName("test");
126 SyscapInfoCollector syscapInfo;
127 bool result = syscapInfo.ConvertToProfile(profile);
128 EXPECT_EQ(result, true);
129 }
130
131 /**
132 * @tc.name: SyscapInfoCollector_001
133 * @tc.desc: syscap info collector
134 * @tc.type: FUNC
135 * @tc.require: I59PZ3
136 */
137 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_002, TestSize.Level3)
138 {
139 DeviceProfile profile;
140 profile.SetDeviceId("");
141 profile.SetDeviceName("");
142 SyscapInfoCollector syscapInfo;
143 bool result = syscapInfo.ConvertToProfile(profile);
144 EXPECT_EQ(result, true);
145 }
146
147 /**
148 * @tc.name: SyscapInfoCollector_001
149 * @tc.desc: syscap info collector
150 * @tc.type: FUNC
151 * @tc.require: I59PZ3
152 */
153 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_003, TestSize.Level3)
154 {
155 DeviceProfile profile;
156 profile.SetDeviceId("");
157 profile.SetDeviceName("test");
158 SyscapInfoCollector syscapInfo;
159 bool result = syscapInfo.ConvertToProfile(profile);
160 EXPECT_EQ(result, true);
161 }
162
163 /**
164 * @tc.name: SyscapInfoCollector_001
165 * @tc.desc: syscap info collector
166 * @tc.type: FUNC
167 * @tc.require: I59PZ3
168 */
169 HWTEST_F(DpContentSensorTest, SyscapInfoCollector_004, TestSize.Level3)
170 {
171 DeviceProfile profile;
172 profile.SetDeviceId("test");
173 profile.SetDeviceName("");
174 SyscapInfoCollector syscapInfo;
175 bool result = syscapInfo.ConvertToProfile(profile);
176 EXPECT_EQ(result, true);
177 }
178 }
179 }
180