• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "ble_mock.h"
17 #include "disc_log.h"
18 #include "softbus_error_code.h"
19 
20 using testing::Return;
21 using testing::NotNull;
22 
DiscBleInit(DiscInnerCallback * callback)23 DiscoveryFuncInterface *DiscBleInit(DiscInnerCallback *callback)
24 {
25     return BleMock::Get()->DiscBleInit(callback);
26 }
27 
DiscBleDeinit()28 void DiscBleDeinit()
29 {
30     DISC_LOGI(DISC_TEST, "destroy");
31 }
32 
BlePublish(const PublishOption * option)33 int32_t BleMock::BlePublish(const PublishOption *option)
34 {
35     return Get()->Publish(option);
36 }
37 
BleStartScan(const PublishOption * option)38 int32_t BleMock::BleStartScan(const PublishOption *option)
39 {
40     return Get()->StartScan(option);
41 }
42 
BleUnpublish(const PublishOption * option)43 int32_t BleMock::BleUnpublish(const PublishOption *option)
44 {
45     return Get()->Unpublish(option);
46 }
47 
BleStopScan(const PublishOption * option)48 int32_t BleMock::BleStopScan(const PublishOption *option)
49 {
50     return Get()->StopScan(option);
51 }
52 
BleStartAdvertise(const SubscribeOption * option)53 int32_t BleMock::BleStartAdvertise(const SubscribeOption *option)
54 {
55     return Get()->StartAdvertise(option);
56 }
57 
BleSubscribe(const SubscribeOption * option)58 int32_t BleMock::BleSubscribe(const SubscribeOption *option)
59 {
60     return Get()->Subscribe(option);
61 }
62 
BleUnsubscribe(const SubscribeOption * option)63 int32_t BleMock::BleUnsubscribe(const SubscribeOption *option)
64 {
65     return Get()->Unsubscribe(option);
66 }
67 
BleStopAdvertise(const SubscribeOption * option)68 int32_t BleMock::BleStopAdvertise(const SubscribeOption *option)
69 {
70     return Get()->StopAdvertise(option);
71 }
72 
BleLinkStatusChanged(LinkStatus status)73 void BleMock::BleLinkStatusChanged(LinkStatus status)
74 {
75     Get()->LinkStatusChanged(status);
76 }
77 
BleUpdateLocalDeviceInfo(InfoTypeChanged type)78 void BleMock::BleUpdateLocalDeviceInfo(InfoTypeChanged type)
79 {
80     Get()->UpdateLocalDeviceInfo(type);
81 }
82 
Get()83 BleMock* BleMock::Get()
84 {
85     return instance_;
86 }
87 
BleMock()88 BleMock::BleMock()
89 {
90     instance_ = this;
91 }
92 
~BleMock()93 BleMock::~BleMock()
94 {
95     instance_ = nullptr;
96 }
97 
InjectDeviceFoundEvent(const DeviceInfo * device)98 void BleMock::InjectDeviceFoundEvent(const DeviceInfo *device)
99 {
100     if (deviceFoundCallback_.OnDeviceFound) {
101         InnerDeviceInfoAddtions additions;
102         additions.medium = BLE;
103         deviceFoundCallback_.OnDeviceFound(device, &additions);
104     }
105 }
SetupStub()106 void BleMock::SetupStub()
107 {
108     EXPECT_CALL(*this, DiscBleInit(NotNull())).WillRepeatedly([](DiscInnerCallback *callback) {
109         deviceFoundCallback_ = *callback;
110         return &interface_;
111     });
112     EXPECT_CALL(*this, Publish(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
113     EXPECT_CALL(*this, StartScan(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
114     EXPECT_CALL(*this, Unpublish(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
115     EXPECT_CALL(*this, StopScan(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
116     EXPECT_CALL(*this, StartAdvertise(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
117     EXPECT_CALL(*this, Subscribe(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
118     EXPECT_CALL(*this, Unsubscribe(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
119     EXPECT_CALL(*this, StopAdvertise(NotNull())).WillRepeatedly(Return(SOFTBUS_OK));
120 }
121