• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 #include <mutex>
18 #include <thread>
19 
20 #include "bluetooth_a2dp_src.h"
21 #include "bluetooth_def.h"
22 #include "bluetooth_device_class.h"
23 #include "bluetooth_host.h"
24 #include "bluetooth_errorcode.h"
25 
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace Bluetooth {
30 class BluetoothHostObserverCommon : public BluetoothHostObserver {
31 public:
32     BluetoothHostObserverCommon() = default;
33     virtual ~BluetoothHostObserverCommon() = default;
34     static BluetoothHostObserverCommon &GetInstance();
35     void OnStateChanged(const int transport, const int status) override;
36     void OnDiscoveryStateChanged(int status) override;
OnDiscoveryResult(const BluetoothRemoteDevice & device)37     void OnDiscoveryResult(const BluetoothRemoteDevice &device) override{};
OnPairRequested(const BluetoothRemoteDevice & device)38     void OnPairRequested(const BluetoothRemoteDevice &device) override{};
OnPairConfirmed(const BluetoothRemoteDevice & device,int reqType,int number)39     void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number) override{};
OnDeviceNameChanged(const std::string & deviceName)40     void OnDeviceNameChanged(const std::string &deviceName) override{};
OnScanModeChanged(int mode)41     void OnScanModeChanged(int mode) override{};
OnDeviceAddrChanged(const std::string & address)42     void OnDeviceAddrChanged(const std::string &address) override{};
43 };
44 
GetInstance()45 BluetoothHostObserverCommon &BluetoothHostObserverCommon::GetInstance()
46 {
47     static BluetoothHostObserverCommon instance;
48     return instance;
49 }
50 
OnStateChanged(const int transport,const int status)51 void BluetoothHostObserverCommon::OnStateChanged(const int transport, const int status)
52 {
53     if (transport == BT_TRANSPORT_BLE) {
54         switch (status) {
55             case STATE_TURNING_ON:
56                 GTEST_LOG_(INFO) << "BLE:Turning on ...";
57                 break;
58             case STATE_TURN_ON:
59                 GTEST_LOG_(INFO) << "BLE:Turn on";
60                 break;
61             case STATE_TURNING_OFF:
62                 GTEST_LOG_(INFO) << "BLE:Turning off ...";
63                 break;
64             case STATE_TURN_OFF:
65                 GTEST_LOG_(INFO) << "BLE:Turn off";
66                 break;
67             default:
68                 break;
69         }
70         return;
71     } else {
72         switch (status) {
73             case STATE_TURNING_ON:
74                 GTEST_LOG_(INFO) << "BREDR:Turning on ...";
75                 break;
76             case STATE_TURN_ON:
77                 GTEST_LOG_(INFO) << "BREDR:Turn on";
78                 break;
79             case STATE_TURNING_OFF:
80                 GTEST_LOG_(INFO) << "BREDR:Turning off ...";
81                 break;
82             case STATE_TURN_OFF:
83                 GTEST_LOG_(INFO) << "BREDR:Turn off";
84                 break;
85             default:
86                 break;
87         }
88         return;
89     }
90 }
91 
OnDiscoveryStateChanged(int status)92 void BluetoothHostObserverCommon::OnDiscoveryStateChanged(int status)
93 {
94     switch (status) {
95         case 0x01:
96             GTEST_LOG_(INFO) << "discovery_start";
97             break;
98         case 0x02:
99             GTEST_LOG_(INFO) << "discoverying";
100             break;
101         case 0x03:
102             GTEST_LOG_(INFO) << "discovery_done";
103             break;
104         default:
105             break;
106     }
107 }
108 
109 class HostTest : public testing::Test {
110 public:
HostTest()111     HostTest()
112     {}
~HostTest()113     ~HostTest()
114     {}
115 
116     BluetoothHost *host_;
117     BluetoothHostObserverCommon &btObserver_ = BluetoothHostObserverCommon::GetInstance();
118     static void SetUpTestCase(void);
119     static void TearDownTestCase(void);
120     void SetUp();
121     void TearDown();
122 };
123 
SetUpTestCase(void)124 void HostTest::SetUpTestCase(void)
125 {}
126 
TearDownTestCase(void)127 void HostTest::TearDownTestCase(void)
128 {}
129 
SetUp()130 void HostTest::SetUp()
131 {}
132 
TearDown()133 void HostTest::TearDown()
134 {}
135 
136 HWTEST_F(HostTest, Host_ModuleTest_EnableBt_00100, TestSize.Level1)
137 {
138     GTEST_LOG_(INFO) << "Host_ModuleTest_EnableBt_00100 start";
139 
140     host_ = &BluetoothHost::GetDefaultHost();
141     EXPECT_TRUE(host_->EnableBt());
142 
143     std::this_thread::sleep_for(std::chrono::seconds(3));
144 
145     GTEST_LOG_(INFO) << "Host_ModuleTest_EnableBt_00100 end";
146 }
147 
148 /**
149  * @tc.number: Host_ModuleTest_GetRemoteDevice_00100
150  * @tc.name:
151  * @tc.desc:
152  */
153 HWTEST_F(HostTest, Host_ModuleTest_GetRemoteDevice_00100, TestSize.Level1)
154 {
155     GTEST_LOG_(INFO) << "Host_ModuleTest_GetRemoteDevice_00100 start";
156 
157     host_ = &BluetoothHost::GetDefaultHost();
158 
159     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
160     BluetoothRemoteDevice remoteDevice = host_->GetRemoteDevice(device_.GetDeviceAddr(), BT_TRANSPORT_BREDR);
161     EXPECT_EQ(device_.GetDeviceAddr(), remoteDevice.GetDeviceAddr());
162     std::this_thread::sleep_for(std::chrono::seconds(3));
163 
164     GTEST_LOG_(INFO) << "Host_ModuleTest_GetRemoteDevice_00100 end";
165 }
166 
167 /**
168  * @tc.number: Host_ModuleTest_GetBtState_00100
169  * @tc.name:
170  * @tc.desc:
171  */
172 HWTEST_F(HostTest, Host_ModuleTest_GetBtState_00100, TestSize.Level1)
173 {
174     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtState_00100 start";
175 
176     host_ = &BluetoothHost::GetDefaultHost();
177     EXPECT_EQ(host_->GetBtState(), BTStateID::STATE_TURN_ON);
178 
179     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtState_00100 end";
180 }
181 
182 /**
183  * @tc.number: Host_ModuleTest_BluetoothFactoryReset_00100
184  * @tc.name:
185  * @tc.desc:
186  */
187 HWTEST_F(HostTest, Host_ModuleTest_BluetoothFactoryReset_00100, TestSize.Level1)
188 {
189     GTEST_LOG_(INFO) << "Host_ModuleTest_BluetoothFactoryReset_00100 start";
190 
191     host_ = &BluetoothHost::GetDefaultHost();
192 
193     GTEST_LOG_(INFO) << "Host_ModuleTest_BluetoothFactoryReset_00100 end";
194 }
195 
196 /**
197  * @tc.number: Host_ModuleTest_GetProfileList_00100
198  * @tc.name:
199  * @tc.desc:
200  */
201 HWTEST_F(HostTest, Host_ModuleTest_GetProfileList_00100, TestSize.Level1)
202 {
203     GTEST_LOG_(INFO) << "Host_ModuleTest_GetProfileList_00100 start";
204 
205     host_ = &BluetoothHost::GetDefaultHost();
206     uint32_t profileSize = 10;
207     EXPECT_EQ(host_->GetProfileList().size(), profileSize);
208 
209     GTEST_LOG_(INFO) << "Host_ModuleTest_GetProfileList_00100 end";
210 }
211 
212 /**
213  * @tc.number: Host_ModuleTest_GetMaxNumConnectedAudioDevices_00100
214  * @tc.name:
215  * @tc.desc:
216  */
217 HWTEST_F(HostTest, Host_ModuleTest_GetMaxNumConnectedAudioDevices_00100, TestSize.Level1)
218 {
219     GTEST_LOG_(INFO) << "Host_ModuleTest_GetMaxNumConnectedAudioDevices_00100 start";
220 
221     host_ = &BluetoothHost::GetDefaultHost();
222     EXPECT_EQ(host_->GetMaxNumConnectedAudioDevices(), 6);
223 
224     GTEST_LOG_(INFO) << "Host_ModuleTest_GetMaxNumConnectedAudioDevices_00100 end";
225 }
226 
227 /**
228  * @tc.number: Host_ModuleTest_GetBtProfileConnState_00100
229  * @tc.name:
230  * @tc.desc:
231  */
232 HWTEST_F(HostTest, Host_ModuleTest_GetBtProfileConnState_00100, TestSize.Level1)
233 {
234     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtProfileConnState_00100 start";
235 
236     host_ = &BluetoothHost::GetDefaultHost();
237     int state = static_cast<int>(BTConnectState::DISCONNECTED);
238     host_->GetBtProfileConnState(PROFILE_ID_GATT_CLIENT, state);
239     EXPECT_EQ(state, (int)BTConnectState::DISCONNECTED);
240 
241     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtProfileConnState_00100 end";
242 }
243 
244 /**
245  * @tc.number: Host_ModuleTest_GetBtConnectionState_00100
246  * @tc.name:
247  * @tc.desc:
248  */
249 HWTEST_F(HostTest, Host_ModuleTest_GetBtConnectionState_00100, TestSize.Level1)
250 {
251     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtConnectionState_00100 start";
252 
253     host_ = &BluetoothHost::GetDefaultHost();
254     EXPECT_EQ(host_->GetBtConnectionState(), (int)BTConnectState::DISCONNECTED);
255 
256     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtConnectionState_00100 end";
257 }
258 
259 /**
260  * @tc.number: Host_ModuleTest_Start_00100
261  * @tc.name:
262  * @tc.desc:
263  */
264 HWTEST_F(HostTest, Host_ModuleTest_Start_00100, TestSize.Level1)
265 {
266     GTEST_LOG_(INFO) << "Host_ModuleTest_Start_00100 start";
267 
268     host_ = &BluetoothHost::GetDefaultHost();
269     host_->Start();
270 
271     GTEST_LOG_(INFO) << "Host_ModuleTest_Start_00100 end";
272 }
273 
274 /**
275  * @tc.number: Host_ModuleTest_Stop_00100
276  * @tc.name:
277  * @tc.desc:
278  */
279 HWTEST_F(HostTest, Host_ModuleTest_Stop_00100, TestSize.Level1)
280 {
281     GTEST_LOG_(INFO) << "Host_ModuleTest_Stop_00100 start";
282 
283     host_ = &BluetoothHost::GetDefaultHost();
284     host_->Stop();
285 
286     GTEST_LOG_(INFO) << "Host_ModuleTest_Stop_00100 end";
287 }
288 
289 /**
290  * @tc.number: Host_ModuleTest_GetLocalDeviceClass_00100
291  * @tc.name:
292  * @tc.desc:
293  */
294 HWTEST_F(HostTest, Host_ModuleTest_GetLocalDeviceClass_00100, TestSize.Level1)
295 {
296     GTEST_LOG_(INFO) << "Host_ModuleTest_GetLocalDeviceClass_00100 start";
297 
298     host_ = &BluetoothHost::GetDefaultHost();
299     BluetoothDeviceClass remotCod(0x2A0104);
300     EXPECT_TRUE(host_->SetLocalDeviceClass(remotCod));
301     BluetoothDeviceClass getLocalcod = host_->GetLocalDeviceClass();
302     EXPECT_EQ(remotCod.GetMajorClass(), getLocalcod.GetMajorClass());
303 
304     GTEST_LOG_(INFO) << "Host_ModuleTest_GetLocalDeviceClass_00100 end";
305 }
306 
307 /**
308  * @tc.number: Host_ModuleTest_SetLocalDeviceClass_00100
309  * @tc.name:
310  * @tc.desc:
311  */
312 HWTEST_F(HostTest, Host_ModuleTest_SetLocalDeviceClass_00100, TestSize.Level1)
313 {
314     GTEST_LOG_(INFO) << "Host_ModuleTest_SetLocalDeviceClass_00100 start";
315 
316     host_ = &BluetoothHost::GetDefaultHost();
317     BluetoothDeviceClass remotCod(0x10100);
318     EXPECT_TRUE(host_->SetLocalDeviceClass(remotCod));
319     BluetoothDeviceClass getLocalcod = host_->GetLocalDeviceClass();
320     EXPECT_EQ(remotCod.GetMajorClass(), getLocalcod.GetMajorClass());
321 
322     GTEST_LOG_(INFO) << "Host_ModuleTest_SetLocalDeviceClass_00100 end";
323 }
324 
325 /**
326  * @tc.number: Host_ModuleTest_GetLocalAddress_00100
327  * @tc.name:
328  * @tc.desc:
329  */
330 HWTEST_F(HostTest, Host_ModuleTest_GetLocalAddress_00100, TestSize.Level1)
331 {
332     GTEST_LOG_(INFO) << "Host_ModuleTest_GetLocalAddress_00100 start";
333 
334     host_ = &BluetoothHost::GetDefaultHost();
335     std::string addr = host_->GetLocalAddress();
336     EXPECT_TRUE(!addr.empty() && addr.size() > 0);
337 
338     GTEST_LOG_(INFO) << "Host_ModuleTest_GetLocalAddress_00100 end";
339 }
340 
341 /**
342  * @tc.number: Host_ModuleTest_GetLocalName_00100
343  * @tc.name:
344  * @tc.desc:
345  */
346 HWTEST_F(HostTest, Host_ModuleTest_GetLocalName_00100, TestSize.Level1)
347 {
348     GTEST_LOG_(INFO) << "Host_ModuleTest_GetLocalName_00100 start";
349 
350     host_ = &BluetoothHost::GetDefaultHost();
351     std::string localName = "localName";
352     host_->SetLocalName(localName);
353     EXPECT_EQ(host_->GetLocalName(), localName);
354 
355     GTEST_LOG_(INFO) << "Host_ModuleTest_GetLocalName_00100 end";
356 }
357 
358 /**
359  * @tc.number: Host_ModuleTest_SetLocalName_00100
360  * @tc.name:
361  * @tc.desc:
362  */
363 HWTEST_F(HostTest, Host_ModuleTest_SetLocalName_00100, TestSize.Level1)
364 {
365     GTEST_LOG_(INFO) << "Host_ModuleTest_SetLocalName_00100 start";
366 
367     host_ = &BluetoothHost::GetDefaultHost();
368     std::string localName = "localName";
369     host_->SetLocalName(localName);
370     EXPECT_EQ(host_->GetLocalName(), localName);
371 
372     GTEST_LOG_(INFO) << "Host_ModuleTest_SetLocalName_00100 end";
373 }
374 
375 /**
376  * @tc.number: Host_ModuleTest_SetBtScanMode_00100
377  * @tc.name:
378  * @tc.desc:
379  */
380 HWTEST_F(HostTest, Host_ModuleTest_SetBtScanMode_00100, TestSize.Level1)
381 {
382     GTEST_LOG_(INFO) << "Host_ModuleTest_SetBtScanMode_00100 start";
383 
384     host_ = &BluetoothHost::GetDefaultHost();
385     bool ret = false;
386     int result = host_->SetBtScanMode(SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 0);
387     if (result == BT_SUCCESS) {
388         ret = true;
389     }
390     EXPECT_TRUE(ret);
391 
392     GTEST_LOG_(INFO) << "Host_ModuleTest_SetBtScanMode_00100 end";
393 }
394 
395 /**
396  * @tc.number: Host_ModuleTest_SetBtScanMode_00200
397  * @tc.name:
398  * @tc.desc:
399  */
400 HWTEST_F(HostTest, Host_ModuleTest_SetBtScanMode_00200, TestSize.Level1)
401 {
402     GTEST_LOG_(INFO) << "Host_ModuleTest_SetBtScanMode_00200 start";
403 
404     const int scanModeInvalid = -1;
405     host_ = &BluetoothHost::GetDefaultHost();
406     bool ret = false;
407     int result = host_->SetBtScanMode(scanModeInvalid, 0);
408     if (result == BT_SUCCESS) {
409         ret = true;
410     }
411     EXPECT_FALSE(ret);
412 
413     GTEST_LOG_(INFO) << "Host_ModuleTest_SetBtScanMode_00200 end";
414 }
415 
416 /**
417  * @tc.number: Host_ModuleTest_GetBtScanMode_00100
418  * @tc.name:
419  * @tc.desc:
420  */
421 HWTEST_F(HostTest, Host_ModuleTest_GetBtScanMode_00100, TestSize.Level1)
422 {
423     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtScanMode_00100 start";
424 
425     sleep(1);
426     host_ = &BluetoothHost::GetDefaultHost();
427     int scanmode = 0;
428     host_->GetBtScanMode(scanmode);
429     EXPECT_EQ(SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, scanmode);
430 
431     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtScanMode_00100 end";
432 }
433 
434 /**
435  * @tc.number: Host_ModuleTest_SetBondableMode_00100
436  * @tc.name:
437  * @tc.desc:
438  */
439 HWTEST_F(HostTest, Host_ModuleTest_SetBondableMode_00100, TestSize.Level1)
440 {
441     GTEST_LOG_(INFO) << "Host_ModuleTest_SetBondableMode_00100 start";
442 
443     host_ = &BluetoothHost::GetDefaultHost();
444     EXPECT_TRUE(host_->SetBondableMode(BT_TRANSPORT_BREDR, BONDABLE_MODE_OFF));
445 
446     GTEST_LOG_(INFO) << "Host_ModuleTest_SetBondableMode_00100 end";
447 }
448 
449 /**
450  * @tc.number: Host_ModuleTest_GetBtScanMode_00100
451  * @tc.name:
452  * @tc.desc:
453  */
454 HWTEST_F(HostTest, Host_ModuleTest_GetBondableMode_00100, TestSize.Level1)
455 {
456     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBondableMode_00100 start";
457 
458     host_ = &BluetoothHost::GetDefaultHost();
459     EXPECT_EQ(host_->GetBondableMode(BTTransport::ADAPTER_BREDR), BONDABLE_MODE_OFF);
460 
461     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBondableMode_00100 end";
462 }
463 
464 /**
465  * @tc.number: Host_ModuleTest_StartBtDiscovery_00100
466  * @tc.name:
467  * @tc.desc:
468  */
469 HWTEST_F(HostTest, Host_ModuleTest_StartBtDiscovery_00100, TestSize.Level1)
470 {
471     GTEST_LOG_(INFO) << "Host_ModuleTest_StartBtDiscovery_00100 start";
472 
473     host_ = &BluetoothHost::GetDefaultHost();
474     int ret = host_->StartBtDiscovery();
475     bool isSuccess = false;
476     if (ret == BT_SUCCESS) {
477         isSuccess = true;
478     }
479     EXPECT_TRUE(isSuccess);
480     std::this_thread::sleep_for(std::chrono::seconds(1));
481 
482     GTEST_LOG_(INFO) << "Host_ModuleTest_StartBtDiscovery_00100 end";
483 }
484 
485 /**
486  * @tc.number: Host_ModuleTest_IsBtDiscovering_00100
487  * @tc.name:
488  * @tc.desc:
489  */
490 HWTEST_F(HostTest, Host_ModuleTest_IsBtDiscovering_00100, TestSize.Level1)
491 {
492     GTEST_LOG_(INFO) << "Host_ModuleTest_IsBtDiscovering_00100 start";
493 
494     host_ = &BluetoothHost::GetDefaultHost();
495     EXPECT_TRUE(host_->IsBtDiscovering(BTTransport::ADAPTER_BREDR));
496 
497     GTEST_LOG_(INFO) << "Host_ModuleTest_IsBtDiscovering_00100 end";
498 }
499 
500 /**
501  * @tc.number: Host_ModuleTest_CancelBtDiscovery_00100
502  * @tc.name:
503  * @tc.desc:
504  */
505 HWTEST_F(HostTest, Host_ModuleTest_CancelBtDiscovery_00100, TestSize.Level1)
506 {
507     GTEST_LOG_(INFO) << "Host_ModuleTest_CancelBtDiscovery_00100 start";
508 
509     host_ = &BluetoothHost::GetDefaultHost();
510     int ret = host_->CancelBtDiscovery();
511     bool isSuccess = false;
512     if (ret == BT_SUCCESS) {
513         isSuccess = true;
514     }
515     EXPECT_TRUE(isSuccess);
516     std::this_thread::sleep_for(std::chrono::seconds(1));
517 
518     GTEST_LOG_(INFO) << "Host_ModuleTest_CancelBtDiscovery_00100 end";
519 }
520 
521 /**
522  * @tc.number: Host_ModuleTest_GetBtDiscoveryEndMillis_00100
523  * @tc.name:
524  * @tc.desc:
525  */
526 HWTEST_F(HostTest, Host_ModuleTest_GetBtDiscoveryEndMillis_00100, TestSize.Level1)
527 {
528     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtDiscoveryEndMillis_00100 start";
529 
530     host_ = &BluetoothHost::GetDefaultHost();
531     host_->GetBtDiscoveryEndMillis();
532 
533     GTEST_LOG_(INFO) << "Host_ModuleTest_GetBtDiscoveryEndMillis_00100 end";
534 }
535 
536 /**
537  * @tc.number: Host_ModuleTest_GetPairedDevices_00100
538  * @tc.name:
539  * @tc.desc:
540  */
541 HWTEST_F(HostTest, Host_ModuleTest_GetPairedDevices_00100, TestSize.Level1)
542 {
543     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPairedDevices_00100 start";
544 
545     host_ = &BluetoothHost::GetDefaultHost();
546     std::vector<BluetoothRemoteDevice> remotedeviceList;
547     host_->GetPairedDevices(BT_TRANSPORT_BREDR, remotedeviceList);
548     EXPECT_EQ((int)remotedeviceList.size(), 0);
549 
550     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPairedDevices_00100 end";
551 }
552 
553 /**
554  * @tc.number: Host_ModuleTest_RemovePair_00100
555  * @tc.name:
556  * @tc.desc:
557  */
558 HWTEST_F(HostTest, Host_ModuleTest_RemovePair_00100, TestSize.Level1)
559 {
560     GTEST_LOG_(INFO) << "Host_ModuleTest_RemovePair_00100 start";
561 
562     host_ = &BluetoothHost::GetDefaultHost();
563     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
564 
565     EXPECT_NE(host_->RemovePair(device_), BT_SUCCESS);
566 
567     GTEST_LOG_(INFO) << "Host_ModuleTest_RemovePair_00100 end";
568 }
569 
570 /**
571  * @tc.number: Host_ModuleTest_RemoveAllPairs_00100
572  * @tc.name:
573  * @tc.desc:
574  */
575 HWTEST_F(HostTest, Host_ModuleTest_RemoveAllPairs_00100, TestSize.Level1)
576 {
577     GTEST_LOG_(INFO) << "Host_ModuleTest_RemoveAllPairs_00100 start";
578 
579     host_ = &BluetoothHost::GetDefaultHost();
580     EXPECT_TRUE(host_->RemoveAllPairs());
581 
582     GTEST_LOG_(INFO) << "Host_ModuleTest_RemoveAllPairs_00100 end";
583 }
584 
585 /**
586  * @tc.number: Host_ModuleTest_IsValidBluetoothAddr_00100
587  * @tc.name:
588  * @tc.desc:
589  */
590 HWTEST_F(HostTest, Host_ModuleTest_IsValidBluetoothAddr_00100, TestSize.Level1)
591 {
592     GTEST_LOG_(INFO) << "Host_ModuleTest_IsValidBluetoothAddr_00100 start";
593 
594     host_ = &BluetoothHost::GetDefaultHost();
595     EXPECT_TRUE(host_->IsValidBluetoothAddr("00:00:00:00:00:00"));
596 
597     GTEST_LOG_(INFO) << "Host_ModuleTest_IsValidBluetoothAddr_00100 end";
598 }
599 
600 /**
601  * @tc.number: Host_ModuleTest_IsValidBluetoothAddr_00200
602  * @tc.name:
603  * @tc.desc:
604  */
605 HWTEST_F(HostTest, Host_ModuleTest_IsValidBluetoothAddr_00200, TestSize.Level1)
606 {
607     GTEST_LOG_(INFO) << "Host_ModuleTest_IsValidBluetoothAddr_00200 start";
608 
609     host_ = &BluetoothHost::GetDefaultHost();
610     EXPECT_FALSE(host_->IsValidBluetoothAddr("00"));
611 
612     GTEST_LOG_(INFO) << "Host_ModuleTest_IsValidBluetoothAddr_00200 end";
613 }
614 
615 /**
616  * @tc.number: Host_ModuleTest_GetPhonebookPermission_00100
617  * @tc.name:
618  * @tc.desc:
619  */
620 HWTEST_F(HostTest, Host_ModuleTest_GetPhonebookPermission_00100, TestSize.Level1)
621 {
622     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPhonebookPermission_00100 start";
623 
624     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
625     EXPECT_TRUE(device_.SetPhonebookPermission(static_cast<int>(BTPermissionType::ACCESS_ALLOWED)));
626     EXPECT_EQ(device_.GetPhonebookPermission(), static_cast<int>(BTPermissionType::ACCESS_ALLOWED));
627 
628     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPhonebookPermission_00100 end";
629 }
630 
631 /**
632  * @tc.number: Host_ModuleTest_SetPhonebookPermission_00100
633  * @tc.name:
634  * @tc.desc:
635  */
636 HWTEST_F(HostTest, Host_ModuleTest_SetPhonebookPermission_00100, TestSize.Level1)
637 {
638     GTEST_LOG_(INFO) << "Host_ModuleTest_SetPhonebookPermission_00100 start";
639 
640     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
641     EXPECT_TRUE(device_.SetPhonebookPermission(static_cast<int>(BTPermissionType::ACCESS_FORBIDDEN)));
642     EXPECT_EQ(device_.GetPhonebookPermission(), static_cast<int>(BTPermissionType::ACCESS_FORBIDDEN));
643 
644     GTEST_LOG_(INFO) << "Host_ModuleTest_SetPhonebookPermission_00100 end";
645 }
646 
647 /**
648  * @tc.number: Host_ModuleTest_GetMessagePermission_00100
649  * @tc.name:
650  * @tc.desc:
651  */
652 HWTEST_F(HostTest, Host_ModuleTest_GetMessagePermission_00100, TestSize.Level1)
653 {
654     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPhonebookPermission_00100 start";
655 
656     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
657     EXPECT_TRUE(device_.SetMessagePermission(static_cast<int>(BTPermissionType::ACCESS_ALLOWED)));
658     EXPECT_EQ(device_.GetMessagePermission(), static_cast<int>(BTPermissionType::ACCESS_ALLOWED));
659 
660     GTEST_LOG_(INFO) << "Host_ModuleTest_GetMessagePermission_00100 end";
661 }
662 
663 /**
664  * @tc.number: Host_ModuleTest_SetMessagePermission_00100
665  * @tc.name:
666  * @tc.desc:
667  */
668 HWTEST_F(HostTest, Host_ModuleTest_SetMessagePermission_00100, TestSize.Level1)
669 {
670     GTEST_LOG_(INFO) << "Host_ModuleTest_SetMessagePermission_00100 start";
671 
672     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
673     EXPECT_TRUE(device_.SetMessagePermission(static_cast<int>(BTPermissionType::ACCESS_FORBIDDEN)));
674     EXPECT_EQ(device_.GetMessagePermission(), static_cast<int>(BTPermissionType::ACCESS_FORBIDDEN));
675 
676     GTEST_LOG_(INFO) << "Host_ModuleTest_SetMessagePermission_00100 end";
677 }
678 
679 /**
680  * @tc.number: Host_ModuleTest_SetMessagePermission_00100
681  * @tc.name:
682  * @tc.desc:
683  */
684 HWTEST_F(HostTest, Host_ModuleTest_GetPowerMode_00100, TestSize.Level1)
685 {
686     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPowerMode_00100 start";
687 
688     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
689     EXPECT_GE(device_.GetPowerMode(), 0);
690 
691     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPowerMode_00100 end";
692 }
693 
694 /**
695  * @tc.number: Host_ModuleTest_GetDeviceAddr_00100
696  * @tc.name:
697  * @tc.desc:
698  */
699 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceAddr_00100, TestSize.Level1)
700 {
701     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceAddr_00100 start";
702 
703     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
704     EXPECT_EQ(device_.GetDeviceAddr(), "00:00:00:00:00:00");
705 
706     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceAddr_00100 end";
707 }
708 
709 /**
710  * @tc.number: Host_ModuleTest_GetDeviceName_00100
711  * @tc.name:
712  * @tc.desc:
713  */
714 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceName_00100, TestSize.Level1)
715 {
716     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceName_00100 start";
717 
718     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
719     EXPECT_TRUE(device_.GetDeviceName().empty());
720 
721     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceName_00100 end";
722 }
723 
724 /**
725  * @tc.number: Host_ModuleTest_GetDeviceAlias_00100
726  * @tc.name:
727  * @tc.desc:
728  */
729 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceAlias_00100, TestSize.Level1)
730 {
731     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceAlias_00100 start";
732 
733     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
734     EXPECT_EQ(device_.GetDeviceAlias(), INVALID_NAME);
735 
736     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceAlias_00100 end";
737 }
738 
739 /**
740  * @tc.number: Host_ModuleTest_SetDeviceAlias_00100
741  * @tc.name:
742  * @tc.desc:
743  */
744 HWTEST_F(HostTest, Host_ModuleTest_SetDeviceAlias_00100, TestSize.Level1)
745 {
746     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDeviceAlias_00100 start";
747 
748     host_ = &BluetoothHost::GetDefaultHost();
749     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
750     EXPECT_FALSE(device_.SetDeviceAlias("deviceName"));
751 
752     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDeviceAlias_00100 end";
753 }
754 
755 /**
756  * @tc.number: Host_ModuleTest_GetDeviceType_00100
757  * @tc.name:
758  * @tc.desc:
759  */
760 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceType_00100, TestSize.Level1)
761 {
762     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceType_00100 start";
763 
764     host_ = &BluetoothHost::GetDefaultHost();
765     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
766     EXPECT_EQ(device_.GetDeviceType(), INVALID_VALUE);
767 
768     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceType_00100 end";
769 }
770 
771 /**
772  * @tc.number: Host_ModuleTest_GetPowerMode_00100
773  * @tc.name:
774  * @tc.desc:
775  */
776 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceBatteryLevel_00100, TestSize.Level1)
777 {
778     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceBatteryLevel_00100 start";
779 
780     int batteryLevel = 0;
781     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
782     EXPECT_EQ(device_.GetDeviceBatteryLevel(), batteryLevel);
783 
784     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceBatteryLevel_00100 end";
785 }
786 
787 /**
788  * @tc.number: Host_ModuleTest_GetPairState_00100
789  * @tc.name:
790  * @tc.desc:
791  */
792 HWTEST_F(HostTest, Host_ModuleTest_GetPairState_00100, TestSize.Level1)
793 {
794     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPairState_00100 start";
795 
796     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
797     EXPECT_EQ(device_.GetPairState(), PAIR_NONE);
798 
799     GTEST_LOG_(INFO) << "Host_ModuleTest_GetPairState_00100 end";
800 }
801 
802 /**
803  * @tc.number: Host_ModuleTest_StartPair_00100
804  * @tc.name:
805  * @tc.desc:
806  */
807 HWTEST_F(HostTest, Host_ModuleTest_StartPair_00100, TestSize.Level1)
808 {
809     GTEST_LOG_(INFO) << "Host_ModuleTest_StartPair_00100 start";
810 
811     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
812     EXPECT_TRUE(device_.StartPair());
813 
814     GTEST_LOG_(INFO) << "Host_ModuleTest_StartPair_00100 end";
815 }
816 
817 /**
818  * @tc.number: Host_ModuleTest_CancelPairing_00100
819  * @tc.name:
820  * @tc.desc:
821  */
822 HWTEST_F(HostTest, Host_ModuleTest_CancelPairing_00100, TestSize.Level1)
823 {
824     GTEST_LOG_(INFO) << "Host_ModuleTest_CancelPairing_00100 start";
825 
826     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
827     std::this_thread::sleep_for(std::chrono::seconds(12));
828     EXPECT_FALSE(device_.CancelPairing());
829 
830     GTEST_LOG_(INFO) << "Host_ModuleTest_CancelPairing_00100 end";
831 }
832 
833 /**
834  * @tc.number: Host_ModuleTest_IsBondedFromLocal_00100
835  * @tc.name:
836  * @tc.desc:
837  */
838 HWTEST_F(HostTest, Host_ModuleTest_IsBondedFromLocal_00100, TestSize.Level1)
839 {
840     GTEST_LOG_(INFO) << "Host_ModuleTest_IsBondedFromLocal_00100 start";
841 
842     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
843     EXPECT_FALSE(device_.IsBondedFromLocal());
844 
845     GTEST_LOG_(INFO) << "Host_ModuleTest_IsBondedFromLocal_00100 end";
846 }
847 
848 /**
849  * @tc.number: Host_ModuleTest_IsAclConnected_00100
850  * @tc.name:
851  * @tc.desc:
852  */
853 HWTEST_F(HostTest, Host_ModuleTest_IsAclConnected_00100, TestSize.Level1)
854 {
855     GTEST_LOG_(INFO) << "Host_ModuleTest_IsAclConnected_00100 start";
856 
857     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
858     EXPECT_FALSE(device_.IsAclConnected());
859 
860     GTEST_LOG_(INFO) << "Host_ModuleTest_IsAclConnected_00100 end";
861 }
862 
863 /**
864  * @tc.number: Host_ModuleTest_IsAclEncrypted_00100
865  * @tc.name:
866  * @tc.desc:
867  */
868 HWTEST_F(HostTest, Host_ModuleTest_IsAclEncrypted_00100, TestSize.Level1)
869 {
870     GTEST_LOG_(INFO) << "Host_ModuleTest_IsAclEncrypted_00100 start";
871 
872     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
873     EXPECT_FALSE(device_.IsAclEncrypted());
874 
875     GTEST_LOG_(INFO) << "Host_ModuleTest_IsAclEncrypted_00100 end";
876 }
877 
878 /**
879  * @tc.number: Host_ModuleTest_GetDeviceClass_00100
880  * @tc.name:
881  * @tc.desc:
882  */
883 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceClass_00100, TestSize.Level1)
884 {
885     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceClass_00100 start";
886 
887     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
888     int cod = 0;
889     (void)device_.GetDeviceClass(cod);
890     BluetoothDeviceClass getLocalcod = BluetoothDeviceClass(cod);
891     EXPECT_EQ(getLocalcod.GetMajorClass(), getLocalcod.GetMajorClass());
892 
893     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceClass_00100 end";
894 }
895 
896 /**
897  * @tc.number: Host_ModuleTest_GetDeviceClass_00200
898  * @tc.name:
899  * @tc.desc:
900  */
901 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceClass_00200, TestSize.Level1)
902 {
903     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceClass_00200 start";
904 
905     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
906     int cod = 0;
907     (void)device_.GetDeviceClass(cod);
908     BluetoothDeviceClass getLocalcod = BluetoothDeviceClass(cod);
909     EXPECT_EQ(getLocalcod.GetClassOfDevice(), 0);
910     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceClass_00200 end";
911 }
912 
913 /**
914  * @tc.number: Host_ModuleTest_GetDeviceUuids_00100
915  * @tc.name:
916  * @tc.desc:
917  */
918 HWTEST_F(HostTest, Host_ModuleTest_GetDeviceUuids_00100, TestSize.Level1)
919 {
920     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceUuids_00100 start";
921 
922     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
923     std::vector<ParcelUuid> uuids = device_.GetDeviceUuids();
924     EXPECT_EQ((int)uuids.size(), 0);
925 
926     GTEST_LOG_(INFO) << "Host_ModuleTest_GetDeviceUuids_00100 end";
927 }
928 
929 /**
930  * @tc.number: Host_ModuleTest_SetDevicePin_00100
931  * @tc.name:
932  * @tc.desc:
933  */
934 HWTEST_F(HostTest, Host_ModuleTest_SetDevicePin_00100, TestSize.Level1)
935 {
936     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDevicePin_00100 start";
937 
938     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
939     EXPECT_FALSE(device_.SetDevicePin("000000"));
940 
941     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDevicePin_00100 end";
942 }
943 
944 /**
945  * @tc.number: Host_ModuleTest_SetDevicePairingConfirmation_00100
946  * @tc.name:
947  * @tc.desc:
948  */
949 HWTEST_F(HostTest, Host_ModuleTest_SetDevicePairingConfirmation_00100, TestSize.Level1)
950 {
951     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDevicePairingConfirmation_00100 start";
952 
953     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
954     bool ret = false;
955     int result = device_.SetDevicePairingConfirmation(true);
956     if (result == BT_SUCCESS) {
957         ret = true;
958     }
959     EXPECT_FALSE(ret);
960     bool isSuccess = false;
961     result = device_.SetDevicePairingConfirmation(true);
962     if (result == BT_SUCCESS) {
963         isSuccess = true;
964     }
965     EXPECT_FALSE(isSuccess);
966 
967     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDevicePairingConfirmation_00100 end";
968 }
969 
970 /**
971  * @tc.number: Host_ModuleTest_SetDevicePasskey_00100
972  * @tc.name:
973  * @tc.desc:
974  */
975 HWTEST_F(HostTest, Host_ModuleTest_SetDevicePasskey_00100, TestSize.Level1)
976 {
977     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDevicePasskey_00100 start";
978 
979     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
980     EXPECT_FALSE(device_.SetDevicePasskey(123456, true));
981     EXPECT_FALSE(device_.SetDevicePasskey(123456, false));
982 
983     GTEST_LOG_(INFO) << "Host_ModuleTest_SetDevicePasskey_00100 end";
984 }
985 
986 /**
987  * @tc.number: Host_ModuleTest_PairRequestReply_00100
988  * @tc.name:
989  * @tc.desc:
990  */
991 HWTEST_F(HostTest, Host_ModuleTest_PairRequestReply_00100, TestSize.Level1)
992 {
993     GTEST_LOG_(INFO) << "Host_ModuleTest_PairRequestReply_00100 start";
994 
995     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
996     EXPECT_FALSE(device_.PairRequestReply(true));
997     EXPECT_FALSE(device_.PairRequestReply(false));
998 
999     GTEST_LOG_(INFO) << "Host_ModuleTest_PairRequestReply_00100 end";
1000 }
1001 
1002 /**
1003  * @tc.number: Host_ModuleTest_GetTransportType_00100
1004  * @tc.name:
1005  * @tc.desc:
1006  */
1007 HWTEST_F(HostTest, Host_ModuleTest_GetTransportType_00100, TestSize.Level1)
1008 {
1009     GTEST_LOG_(INFO) << "Host_ModuleTest_GetTransportType_00100 start";
1010 
1011     BluetoothRemoteDevice device1_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
1012     EXPECT_EQ(device1_.GetTransportType(), BT_TRANSPORT_BREDR);
1013 
1014     BluetoothRemoteDevice device2_("00:00:00:00:00:01", BT_TRANSPORT_BLE);
1015     EXPECT_EQ(device2_.GetTransportType(), BT_TRANSPORT_BLE);
1016 
1017     GTEST_LOG_(INFO) << "Host_ModuleTest_GetTransportType_00100 end";
1018 }
1019 
1020 /**
1021  * @tc.number: Host_ModuleTest_ReadRemoteRssiValue_00100
1022  * @tc.name:
1023  * @tc.desc:
1024  */
1025 HWTEST_F(HostTest, Host_ModuleTest_ReadRemoteRssiValue_00100, TestSize.Level1)
1026 {
1027     GTEST_LOG_(INFO) << "Host_ModuleTest_ReadRemoteRssiValue_00100 start";
1028 
1029     BluetoothRemoteDevice device_("00:00:00:00:00:00", BT_TRANSPORT_BREDR);
1030     EXPECT_FALSE(device_.ReadRemoteRssiValue());
1031 
1032     GTEST_LOG_(INFO) << "Host_ModuleTest_ReadRemoteRssiValue_00100 end";
1033 }
1034 
1035 /**
1036  * @tc.number: Host_ModuleTest_IsValidBluetoothRemoteDevice_00100
1037  * @tc.name:
1038  * @tc.desc:
1039  */
1040 HWTEST_F(HostTest, Host_ModuleTest_IsValidBluetoothRemoteDevice_00100, TestSize.Level1)
1041 {
1042     GTEST_LOG_(INFO) << "Host_ModuleTest_IsValidBluetoothRemoteDevice_00100 start";
1043 
1044     BluetoothRemoteDevice device0_("00", BT_TRANSPORT_BREDR);
1045     EXPECT_FALSE(device0_.IsValidBluetoothRemoteDevice());
1046 
1047     BluetoothRemoteDevice device1_("00:00:00:00:00:00", 3);
1048     EXPECT_FALSE(device1_.IsValidBluetoothRemoteDevice());
1049 
1050     GTEST_LOG_(INFO) << "Host_ModuleTest_IsValidBluetoothRemoteDevice_00100 end";
1051 }
1052 
1053 /**
1054  * @tc.number: Host_ModuleTest_DisableBt_00100
1055  * @tc.name:
1056  * @tc.desc:
1057  */
1058 HWTEST_F(HostTest, Host_ModuleTest_DisableBt_00100, TestSize.Level1)
1059 {
1060     GTEST_LOG_(INFO) << "Host_ModuleTest_DisableBt_00100 start";
1061 
1062     host_ = &BluetoothHost::GetDefaultHost();
1063     bool isSuccess = false;
1064     int ret = host_->DisableBt();
1065     if (ret == BT_SUCCESS) {
1066         isSuccess = true;
1067     }
1068     EXPECT_TRUE(isSuccess);
1069     std::this_thread::sleep_for(std::chrono::seconds(3));
1070 
1071     GTEST_LOG_(INFO) << "Host_ModuleTest_DisableBt_00100 end";
1072 }
1073 }  // namespace Bluetooth
1074 }  // namespace OHOS