• 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 "UTTest_device_manager_service.h"
17 
18 #include "dm_constants.h"
19 #include "dm_device_info.h"
20 #include "dm_log.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService);
25 
SetUp()26 void DeviceManagerServiceTest::SetUp()
27 {
28 }
29 
TearDown()30 void DeviceManagerServiceTest::TearDown()
31 {
32 }
33 
SetUpTestCase()34 void DeviceManagerServiceTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void DeviceManagerServiceTest::TearDownTestCase()
39 {
40 }
41 
42 namespace {
43 /**
44  * @tc.name: StartDeviceDiscovery_001
45  * @tc.desc: Set StartDeviceDiscovery's flag bit intFlag_ to False and return DM_NOT_INIT
46  * @tc.type: FUNC
47  * @tc.require: AR000GHSJK
48  */
49 HWTEST_F(DeviceManagerServiceTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0)
50 {
51     DeviceManagerService::GetInstance().intFlag_ = false;
52     std::string pkgName = "com.ohos.test";
53     DmSubscribeInfo subscribeInfo;
54     std::string extra = "test";
55     int ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra);
56     EXPECT_EQ(ret, DM_NOT_INIT);
57 }
58 
59 /**
60  * @tc.name: StartDeviceDiscovery_002
61  * @tc.desc: Empty pkgName of StartDeviceDiscovery and return DM_INPUT_PARA_EMPTY
62  * @tc.type: FUNC
63  * @tc.require: AR000GHSJK
64  */
65 HWTEST_F(DeviceManagerServiceTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0)
66 {
67     std::string pkgName;
68     DmSubscribeInfo subscribeInfo;
69     std::string extra = "test";
70     DeviceManagerService::GetInstance().Init();
71     int ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra);
72     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
73 }
74 
75 /**
76  * @tc.name: StartDeviceDiscovery_003
77  * @tc.desc: Call StartDeviceDiscovery twice with pkgName not null and flag bit not false and return
78  * DM_DISCOVERY_REPEATED
79  * @tc.type: FUNC
80  * @tc.require: AR000GHSJK
81  */
82 HWTEST_F(DeviceManagerServiceTest, StartDeviceDiscovery_003, testing::ext::TestSize.Level0)
83 {
84     std::string pkgName = "com.ohos.test";
85     DmSubscribeInfo subscribeInfo;
86     std::string extra = "test";
87     int ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra);
88     pkgName = "1com.ohos.test1";
89     ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra);
90     EXPECT_EQ(ret, DM_DISCOVERY_FAILED);
91 }
92 
93 /**
94  * @tc.name: StopDeviceDiscovery_001
95  * @tc.desc: Set StopDeviceDiscovery's flag bit intFlag_ to false and return DM_NOT_INIT
96  * @tc.type: FUNC
97  * @tc.require: AR000GHSJK
98  */
99 HWTEST_F(DeviceManagerServiceTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0)
100 {
101     DeviceManagerService::GetInstance().intFlag_ = false;
102     std::string pkgName = "com.ohos.test";
103     uint16_t subscribeId = 1;
104     int ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
105     EXPECT_EQ(ret, DM_NOT_INIT);
106 }
107 
108 /**
109  * @tc.name:StopDeviceDiscovery_002
110  * @tc.desc: StopDeviceDiscovery is initialized, pkgName is null, and its return value is DM_INPUT_PARA_EMPTY
111  * @tc.type: FUNC
112  * @tc.require: AR000GHSJK
113  */
114 HWTEST_F(DeviceManagerServiceTest, StopDeviceDiscovery_002, testing::ext::TestSize.Level0)
115 {
116     std::string pkgName;
117     uint16_t subscribeId = 1;
118     DeviceManagerService::GetInstance().Init();
119     int ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
120     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
121 }
122 
123 /**
124  * @tc.name: GetLocalDeviceInfo_001
125  * @tc.desc: Set the flag bit of GetLocalDeviceInfo to intFlag_ to false; The return value is DM_NOT_INIT
126  * @tc.type: FUNC
127  * @tc.require: AR000GHSJK
128  */
129 HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0)
130 {
131     DeviceManagerService::GetInstance().intFlag_ = false;
132     DmDeviceInfo info;
133     int ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info);
134     EXPECT_EQ(ret, DM_NOT_INIT);
135 }
136 
137 /**
138  * @tc.name:GetLocalDeviceInfo_002
139  * @tc.desc: Initialize the GetLocalDeviceInfo function with the return value DM_OK
140  * @tc.type: FUNC
141  * @tc.require: AR000GHSJK
142  */
143 HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_002, testing::ext::TestSize.Level0)
144 {
145     DmDeviceInfo info;
146     DeviceManagerService::GetInstance().Init();
147     int ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info);
148     EXPECT_EQ(ret, DM_OK);
149 }
150 
151 /**
152  * @tc.name: Init_001
153  * @tc.desc: The OnDeviceFound function does the worong case and return DM_INT_MULTIPLE
154  * @tc.type: FUNC
155  * @tc.require: AR000GHSJK
156  */
157 HWTEST_F(DeviceManagerServiceTest, Init_001, testing::ext::TestSize.Level0)
158 {
159     DeviceManagerService::GetInstance().intFlag_ = true;
160     int ret = DeviceManagerService::GetInstance().Init();
161     EXPECT_EQ(ret, DM_INT_MULTIPLE);
162 }
163 
164 /**
165  * @tc.name: Init_002
166  * @tc.desc: The OnDeviceFound function does the correct case and return DM_OK
167  * @tc.type: FUNC
168  * @tc.require: AR000GHSJK
169  */
170 HWTEST_F(DeviceManagerServiceTest, Init_002, testing::ext::TestSize.Level0)
171 {
172     DeviceManagerService::GetInstance().intFlag_ = false;
173     std::shared_ptr<SoftbusConnector> softbusConnector_ = nullptr;
174     int ret = DeviceManagerService::GetInstance().Init();
175     EXPECT_EQ(ret, DM_OK);
176 }
177 
178 /**
179  * @tc.name: GetTrustedDeviceList_001
180  * @tc.desc: Set the intFlag of GetTrustedDeviceList to false. The return value is DM_NOT_INIT
181  * @tc.type: FUNC
182  * @tc.require: AR000GHSJK
183  */
184 
185 HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0)
186 {
187     DeviceManagerService::GetInstance().intFlag_ = false;
188     std::string pkgName = "com.ohos.test";
189     std::string extra = "jdddd";
190     std::vector<DmDeviceInfo> deviceList;
191     int ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
192     EXPECT_EQ(ret, DM_NOT_INIT);
193 }
194 
195 /**
196  * @tc.name: GetTrustedDeviceList_002
197  * @tc.desc:Set the intFlag of GetTrustedDeviceList to true and pkgName = null ; The return value is DM_INPUT_PARA_EMPTY
198  * @tc.type: FUNC
199  * @tc.require: AR000GHSJK
200  */
201 HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_002, testing::ext::TestSize.Level0)
202 {
203     DeviceManagerService::GetInstance().intFlag_ = true;
204     std::string pkgName;
205     std::string extra = "jdddd";
206     std::vector<DmDeviceInfo> deviceList;
207     int ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
208     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
209 }
210 
211 /**
212  * @tc.name: AuthenticateDevice_001
213  * @tc.desc: 将GAuthenticateDevice的intFlag设置为false,设置pkgName = "com.ohos.test";其返回值为DM_NOT_INIT
214  * @tc.type: FUNC
215  * @tc.require: AR000GHSJK
216  */
217 HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_001, testing::ext::TestSize.Level0)
218 {
219     DeviceManagerService::GetInstance().intFlag_ = false;
220     std::string pkgName = "com.ohos.test";
221     std::string extra = "jdddd";
222     int32_t authType = 0;
223     std::string deviceId = "2345";
224     int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
225     EXPECT_EQ(ret, DM_NOT_INIT);
226 }
227 
228 /**
229  * @tc.name: AuthenticateDevice_002
230  * @tc.desc: Set intFlag for GAuthenticateDevice to True and pkgName to null; The return value is DM_INPUT_PARA_EMPTY
231  * @tc.type: FUNC
232  * @tc.require: AR000GHSJK
233  */
234 HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_002, testing::ext::TestSize.Level0)
235 {
236     DeviceManagerService::GetInstance().intFlag_ = true;
237     std::string pkgName;
238     std::string extra = "jdddd";
239     int32_t authType = 0;
240     std::string deviceId = " 2345";
241     int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
242     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
243 }
244 
245 /**
246  * @tc.name: AuthenticateDevice_003
247  * @tc.desc: Set intFlag for GAuthenticateDevice to True and deviceId to null; The return value is DM_INPUT_PARA_EMPTY
248  * @tc.type: FUNC
249  * @tc.require: AR000GHSJK
250  */
251 HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSize.Level0)
252 {
253     DeviceManagerService::GetInstance().intFlag_ = true;
254     std::string pkgName = "com.ohos.test";
255     std::string extra = "jdddd";
256     int32_t authType = 0;
257     std::string deviceId;
258     int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
259     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
260 }
261 /**
262  * @tc.name: AuthenticateDevice_004
263  * @tc.desc: Set intFlag for GAuthenticateDevice to true and pkgName to com.ohos.test
264  * @tc.type: FUNC
265  * @tc.require: AR000GHSJK
266  */
267 HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_004, testing::ext::TestSize.Level0)
268 {
269     DeviceManagerService::GetInstance().intFlag_ = true;
270     std::string pkgName = "com.ohos.test";
271     std::string extra = "jdddd";
272     int32_t authType = 0;
273     std::string deviceId = "123456";
274     int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
275     EXPECT_EQ(ret, DM_AUTH_NOT_SUPPORT);
276 }
277 
278 /**
279  * @tc.name: UnAuthenticateDevice_001
280  * @tc.desc: 将UnAuthenticateDevice的intFlag设置为false,设置pkgName = "com.ohos.test";其返回值为DM_NOT_INIT
281  * @tc.type: FUNC
282  * @tc.require: AR000GHSJK
283  */
284 HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_001, testing::ext::TestSize.Level0)
285 {
286     DeviceManagerService::GetInstance().intFlag_ = false;
287     std::string pkgName = "com.ohos.test";
288     std::string deviceId = "12345";
289     int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
290     EXPECT_EQ(ret, DM_NOT_INIT);
291 }
292 
293 /**
294  * @tc.name: UnAuthenticateDevice_002
295  * @tc.desc:  Set intFlag for UnAuthenticateDevice to True and pkgName to null; The return value is DM_INPUT_PARA_EMPTY
296  * @tc.type: FUNC
297  * @tc.require: AR000GHSJK
298  */
299 HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_002, testing::ext::TestSize.Level0)
300 {
301     DeviceManagerService::GetInstance().intFlag_ = true;
302     std::string pkgName;
303     std::string deviceId = "12345";
304     int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
305     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
306 }
307 
308 /**
309  * @tc.name: UnAuthenticateDevice_003
310  * @tc.desc: Set intFlag for UnAuthenticateDevice to true and pkgName to com.ohos.test; set deviceId  null ,The return
311  * value is DM_INPUT_PARA_EMPTY
312  * @tc.type: FUNC
313  * @tc.require: AR000GHSJK
314  */
315 HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_003, testing::ext::TestSize.Level0)
316 {
317     DeviceManagerService::GetInstance().intFlag_ = true;
318     std::string pkgName = "com.ohos.test";
319     std::string deviceId;
320     int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
321     EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY);
322 }
323 
324 /**
325  * @tc.name: VerifyAuthentication_001
326  * @tc.desc: Set intFlag for VerifyAuthentication to false and  set authParam = "jdjjjj",The return value is
327  * DM_NOT_INIT
328  * @tc.type: FUNC
329  * @tc.require: AR000GHSJK
330  */
331 HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestSize.Level0)
332 {
333     DeviceManagerService::GetInstance().intFlag_ = false;
334     std::string authParam = "jdjjjj";
335     int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam);
336     EXPECT_EQ(ret, DM_NOT_INIT);
337 }
338 } // namespace
339 } // namespace DistributedHardware
340 } // namespace OHOS
341