Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2016 The Android Open Source Project |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 19 | #include <array> |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 20 | #include <gmock/gmock.h> |
| 21 | #include <gtest/gtest.h> |
| 22 | |
| 23 | #include "device/include/controller.h" |
| 24 | #include "stack/btm/ble_advertiser_hci_interface.h" |
| 25 | #include "stack/include/ble_advertiser.h" |
| 26 | |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 27 | using ::testing::Args; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 28 | using ::testing::Contains; |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 29 | using ::testing::ElementsAreArray; |
Jakub Pawlowski | 1dd7751 | 2016-10-10 14:25:52 -0700 | [diff] [blame] | 30 | using ::testing::Exactly; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 31 | using ::testing::Field; |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 32 | using ::testing::IsEmpty; |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 33 | using ::testing::SaveArg; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 34 | using ::testing::SizeIs; |
| 35 | using ::testing::_; |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 36 | using base::Bind; |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 37 | using status_cb = BleAdvertiserHciInterface::status_cb; |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 38 | using parameters_cb = BleAdvertiserHciInterface::parameters_cb; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 39 | using SetEnableData = BleAdvertiserHciInterface::SetEnableData; |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 40 | |
| 41 | const int num_adv_instances = 16; |
| 42 | |
| 43 | /* Below are methods that must be implemented if we don't want to compile the |
| 44 | * whole stack. They will be removed, or changed into mocks one by one in the |
| 45 | * future, as the refactoring progresses */ |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 46 | bool BTM_BleLocalPrivacyEnabled() { return true; } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 47 | uint16_t BTM_ReadDiscoverability(uint16_t* p_window, uint16_t* p_interval) { |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 48 | return true; |
| 49 | } |
Jakub Pawlowski | 73af403 | 2017-08-18 04:14:22 -0700 | [diff] [blame] | 50 | void btm_acl_update_conn_addr(uint16_t conn_handle, const RawAddress& address) { |
| 51 | } |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 52 | void btm_gen_resolvable_private_addr( |
| 53 | base::Callback<void(const RawAddress& rpa)> cb) { |
| 54 | cb.Run(RawAddress::kEmpty); |
Jakub Pawlowski | 8c7d060 | 2017-03-16 14:47:55 -0700 | [diff] [blame] | 55 | } |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 56 | |
| 57 | alarm_callback_t last_alarm_cb = nullptr; |
| 58 | void* last_alarm_data = nullptr; |
Jack He | d97e095 | 2018-08-15 22:17:23 -0700 | [diff] [blame] | 59 | void alarm_set_on_mloop(alarm_t* alarm, uint64_t interval_ms, |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 60 | alarm_callback_t cb, void* data) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 61 | last_alarm_cb = cb; |
| 62 | last_alarm_data = data; |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 63 | } |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 64 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 65 | void alarm_cancel(alarm_t* alarm) {} |
| 66 | alarm_t* alarm_new_periodic(const char* name) { return nullptr; } |
| 67 | alarm_t* alarm_new(const char* name) { return nullptr; } |
| 68 | void alarm_free(alarm_t* alarm) {} |
| 69 | const controller_t* controller_get_interface() { return nullptr; } |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 70 | |
| 71 | namespace { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 72 | void DoNothing(uint8_t) {} |
| 73 | |
| 74 | void DoNothing2(uint8_t, uint8_t) {} |
| 75 | |
| 76 | void TriggerRandomAddressUpdate() { |
| 77 | // Call to StartAdvertisingSet set the last_alarm_cb to random address timeout |
| 78 | // callback. Call it now in order to trigger address update |
| 79 | last_alarm_cb(last_alarm_data); |
| 80 | } |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 81 | |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 82 | constexpr uint8_t INTERMEDIATE = |
| 83 | 0x00; // Intermediate fragment of fragmented data |
| 84 | constexpr uint8_t FIRST = 0x01; // First fragment of fragmented data |
| 85 | constexpr uint8_t LAST = 0x02; // Last fragment of fragmented data |
| 86 | constexpr uint8_t COMPLETE = 0x03; // Complete extended advertising data |
| 87 | |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 88 | class AdvertiserHciMock : public BleAdvertiserHciInterface { |
| 89 | public: |
| 90 | AdvertiserHciMock() = default; |
| 91 | ~AdvertiserHciMock() override = default; |
| 92 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 93 | MOCK_METHOD1(ReadInstanceCount, |
| 94 | void(base::Callback<void(uint8_t /* inst_cnt*/)>)); |
| 95 | MOCK_METHOD1(SetAdvertisingEventObserver, |
| 96 | void(AdvertisingEventObserver* observer)); |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 97 | MOCK_METHOD6(SetAdvertisingData, |
| 98 | void(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t*, status_cb)); |
| 99 | MOCK_METHOD6(SetScanResponseData, |
| 100 | void(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t*, status_cb)); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 101 | MOCK_METHOD3(SetRandomAddress, void(uint8_t, const RawAddress&, status_cb)); |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 102 | MOCK_METHOD3(Enable, void(uint8_t, std::vector<SetEnableData>, status_cb)); |
Lakshmipathi K | 8e774d1 | 2017-03-13 10:35:12 -0700 | [diff] [blame] | 103 | MOCK_METHOD5(SetPeriodicAdvertisingParameters, |
| 104 | void(uint8_t, uint16_t, uint16_t, uint16_t, status_cb)); |
| 105 | MOCK_METHOD5(SetPeriodicAdvertisingData, |
| 106 | void(uint8_t, uint8_t, uint8_t, uint8_t*, status_cb)); |
| 107 | MOCK_METHOD3(SetPeriodicAdvertisingEnable, void(uint8_t, uint8_t, status_cb)); |
Jakub Pawlowski | bb858fb | 2017-03-11 16:40:52 -0800 | [diff] [blame] | 108 | MOCK_METHOD2(RemoveAdvertisingSet, void(uint8_t, status_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 109 | MOCK_METHOD1(ClearAdvertisingSets, void(status_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 110 | |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 111 | MOCK_METHOD9(SetParameters1, |
| 112 | void(uint8_t, uint16_t, uint32_t, uint32_t, uint8_t, uint8_t, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 113 | const RawAddress&, uint8_t, const RawAddress&)); |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 114 | MOCK_METHOD8(SetParameters2, void(uint8_t, int8_t, uint8_t, uint8_t, uint8_t, |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 115 | uint8_t, uint8_t, parameters_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 116 | |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 117 | void SetParameters(uint8_t handle, uint16_t properties, uint32_t adv_int_min, |
| 118 | uint32_t adv_int_max, uint8_t channel_map, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 119 | uint8_t own_address_type, const RawAddress& own_address, |
| 120 | uint8_t peer_address_type, const RawAddress& peer_address, |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 121 | uint8_t filter_policy, int8_t tx_power, |
| 122 | uint8_t primary_phy, uint8_t secondary_max_skip, |
| 123 | uint8_t secondary_phy, uint8_t advertising_sid, |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 124 | uint8_t scan_request_notify_enable, |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 125 | parameters_cb cmd_complete) override { |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 126 | SetParameters1(handle, properties, adv_int_min, adv_int_max, channel_map, |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 127 | own_address_type, own_address, peer_address_type, |
| 128 | peer_address); |
| 129 | SetParameters2(filter_policy, tx_power, primary_phy, secondary_max_skip, |
| 130 | secondary_phy, advertising_sid, scan_request_notify_enable, |
| 131 | cmd_complete); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Yi Kong | 183eace | 2019-03-29 15:42:58 -0700 | [diff] [blame] | 134 | bool QuirkAdvertiserZeroHandle() override { return false; } |
Jakub Pawlowski | 8c7d060 | 2017-03-16 14:47:55 -0700 | [diff] [blame] | 135 | |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 136 | private: |
| 137 | DISALLOW_COPY_AND_ASSIGN(AdvertiserHciMock); |
| 138 | }; |
| 139 | |
| 140 | } // namespace |
| 141 | |
| 142 | class BleAdvertisingManagerTest : public testing::Test { |
| 143 | protected: |
| 144 | int reg_inst_id = -1; |
| 145 | int reg_status = -1; |
| 146 | int set_params_status = -1; |
| 147 | int set_data_status = -1; |
| 148 | int enable_status = -1; |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 149 | int start_advertising_status = -1; |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 150 | int start_advertising_set_advertiser_id = -1; |
| 151 | int start_advertising_set_tx_power = -1; |
| 152 | int start_advertising_set_status = -1; |
| 153 | |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 154 | std::unique_ptr<AdvertiserHciMock> hci_mock; |
| 155 | |
Yi Kong | 183eace | 2019-03-29 15:42:58 -0700 | [diff] [blame] | 156 | void SetUp() override { |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 157 | hci_mock.reset(new AdvertiserHciMock()); |
Jakub Pawlowski | 1dd7751 | 2016-10-10 14:25:52 -0700 | [diff] [blame] | 158 | |
| 159 | base::Callback<void(uint8_t)> inst_cnt_Cb; |
| 160 | EXPECT_CALL(*hci_mock, ReadInstanceCount(_)) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 161 | .Times(Exactly(1)) |
| 162 | .WillOnce(SaveArg<0>(&inst_cnt_Cb)); |
Jakub Pawlowski | 1dd7751 | 2016-10-10 14:25:52 -0700 | [diff] [blame] | 163 | |
| 164 | BleAdvertisingManager::Initialize(hci_mock.get()); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 165 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 1dd7751 | 2016-10-10 14:25:52 -0700 | [diff] [blame] | 166 | |
| 167 | // we are a truly gracious fake controller, let the command succeed! |
| 168 | inst_cnt_Cb.Run(num_adv_instances); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Yi Kong | 183eace | 2019-03-29 15:42:58 -0700 | [diff] [blame] | 171 | void TearDown() override { |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 172 | BleAdvertisingManager::CleanUp(); |
| 173 | hci_mock.reset(); |
| 174 | } |
| 175 | |
| 176 | public: |
| 177 | void RegistrationCb(uint8_t inst_id, uint8_t status) { |
| 178 | reg_inst_id = inst_id; |
| 179 | reg_status = status; |
| 180 | } |
| 181 | |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 182 | void SetParametersCb(uint8_t status, int8_t tx_power) { |
| 183 | set_params_status = status; |
| 184 | } |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 185 | void SetDataCb(uint8_t status) { set_data_status = status; } |
| 186 | void EnableCb(uint8_t status) { enable_status = status; } |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 187 | void StartAdvertisingCb(uint8_t status) { start_advertising_status = status; } |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 188 | void StartAdvertisingSetCb(uint8_t advertiser_id, int8_t tx_power, |
| 189 | uint8_t status) { |
| 190 | start_advertising_set_advertiser_id = advertiser_id; |
| 191 | start_advertising_set_tx_power = tx_power; |
| 192 | start_advertising_set_status = status; |
| 193 | } |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | TEST_F(BleAdvertisingManagerTest, test_registration) { |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 197 | for (int i = 0; i < num_adv_instances; i++) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 198 | BleAdvertisingManager::Get()->RegisterAdvertiser(Bind( |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 199 | &BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
| 200 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 201 | EXPECT_EQ(i, reg_inst_id); |
| 202 | } |
| 203 | |
| 204 | // This call should return an error - no more advertisers left. |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 205 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 206 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | 318e310 | 2016-11-22 12:51:20 -0800 | [diff] [blame] | 207 | EXPECT_EQ(ADVERTISE_FAILED_TOO_MANY_ADVERTISERS, reg_status); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 208 | // Don't bother checking inst_id, it doesn't matter |
| 209 | |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 210 | status_cb remove_cb; |
| 211 | EXPECT_CALL(*hci_mock, RemoveAdvertisingSet(_, _)) |
| 212 | .Times(1) |
| 213 | .WillOnce(SaveArg<1>(&remove_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 214 | BleAdvertisingManager::Get()->Unregister(5); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 215 | remove_cb.Run(0); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 216 | |
| 217 | // One advertiser was freed, so should be able to register one now |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 218 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 219 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 220 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 221 | EXPECT_EQ(5, reg_inst_id); |
| 222 | } |
| 223 | |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 224 | /* This test verifies that the following flow is working correctly: register, |
| 225 | * set parameters, set data, enable, ... (advertise) ..., unregister*/ |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 226 | TEST_F(BleAdvertisingManagerTest, test_android_flow) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 227 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 228 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 229 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 230 | int advertiser_id = reg_inst_id; |
| 231 | |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 232 | parameters_cb set_params_cb; |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 233 | tBTM_BLE_ADV_PARAMS params; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 234 | EXPECT_CALL(*hci_mock, SetParameters1(advertiser_id, _, _, _, _, _, _, _, _)) |
| 235 | .Times(1); |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 236 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 237 | .Times(1) |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 238 | .WillOnce(SaveArg<7>(&set_params_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 239 | BleAdvertisingManager::Get()->SetParameters( |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 240 | advertiser_id, ¶ms, |
| 241 | Bind(&BleAdvertisingManagerTest::SetParametersCb, |
| 242 | base::Unretained(this))); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 243 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 244 | |
Jakub Pawlowski | 1dd7751 | 2016-10-10 14:25:52 -0700 | [diff] [blame] | 245 | // we are a truly gracious fake controller, let the command succeed! |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 246 | set_params_cb.Run(0, 0); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 247 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_params_status); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 248 | |
| 249 | status_cb set_data_cb; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 250 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, _, _, _, _, _)) |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 251 | .Times(1) |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 252 | .WillOnce(SaveArg<5>(&set_data_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 253 | BleAdvertisingManager::Get()->SetData( |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 254 | advertiser_id, false, std::vector<uint8_t>(), |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 255 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 256 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 257 | |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 258 | set_data_cb.Run(0); |
| 259 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 260 | |
| 261 | status_cb enable_cb; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 262 | EXPECT_CALL(*hci_mock, |
| 263 | Enable(0x01 /* enable */, |
| 264 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 265 | advertiser_id))), |
| 266 | _)) |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 267 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 268 | .WillOnce(SaveArg<2>(&enable_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 269 | BleAdvertisingManager::Get()->Enable( |
| 270 | advertiser_id, true, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 271 | Bind(&BleAdvertisingManagerTest::EnableCb, base::Unretained(this)), 0, 0, |
| 272 | base::Callback<void(uint8_t)>()); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 273 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 274 | |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 275 | enable_cb.Run(0); |
| 276 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, enable_status); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 277 | |
| 278 | /* fake controller should be advertising */ |
| 279 | |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 280 | EXPECT_CALL(*hci_mock, |
| 281 | Enable(0x00 /* disable */, |
| 282 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 283 | advertiser_id))), |
| 284 | _)) |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 285 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 286 | .WillOnce(SaveArg<2>(&enable_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 287 | status_cb remove_cb; |
| 288 | EXPECT_CALL(*hci_mock, RemoveAdvertisingSet(_, _)) |
| 289 | .Times(1) |
| 290 | .WillOnce(SaveArg<1>(&remove_cb)); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 291 | BleAdvertisingManager::Get()->Unregister(advertiser_id); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 292 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 293 | |
| 294 | enable_cb.Run(0); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 295 | remove_cb.Run(0); |
Jakub Pawlowski | e47b769 | 2016-09-28 07:36:54 -0700 | [diff] [blame] | 296 | } |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 297 | |
| 298 | /* This test verifies that when advertising data is set, tx power and flags will |
| 299 | * be properly filled. */ |
| 300 | TEST_F(BleAdvertisingManagerTest, test_adv_data_filling) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 301 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 302 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 303 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 304 | int advertiser_id = reg_inst_id; |
| 305 | |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 306 | parameters_cb set_params_cb; |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 307 | tBTM_BLE_ADV_PARAMS params; |
Jakub Pawlowski | e0750ca | 2016-12-05 11:46:23 -0800 | [diff] [blame] | 308 | params.advertising_event_properties = |
| 309 | BleAdvertisingManager::advertising_prop_legacy_connectable; |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 310 | params.tx_power = -15; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 311 | EXPECT_CALL(*hci_mock, SetParameters1(advertiser_id, _, _, _, _, _, _, _, _)) |
| 312 | .Times(1); |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 313 | EXPECT_CALL(*hci_mock, SetParameters2(_, params.tx_power, _, _, _, _, _, _)) |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 314 | .Times(1) |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 315 | .WillOnce(SaveArg<7>(&set_params_cb)); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 316 | BleAdvertisingManager::Get()->SetParameters( |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 317 | advertiser_id, ¶ms, |
| 318 | Bind(&BleAdvertisingManagerTest::SetParametersCb, |
| 319 | base::Unretained(this))); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 320 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 321 | |
| 322 | // let the set parameters command succeed! |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 323 | set_params_cb.Run(0, 0); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 324 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_params_status); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 325 | |
| 326 | status_cb set_data_cb; |
| 327 | /* verify that flags will be added, and tx power filled, if call to SetData |
| 328 | * contained only tx power, and the advertisement is connectable */ |
Jakub Pawlowski | e0750ca | 2016-12-05 11:46:23 -0800 | [diff] [blame] | 329 | uint8_t expected_adv_data[] = { |
| 330 | 0x02 /* len */, 0x01 /* flags */, |
| 331 | 0x02 /* flags value */, 0x02 /* len */, |
| 332 | 0x0A /* tx_power */, static_cast<uint8_t>(params.tx_power)}; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 333 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, _, _, _, _, _)) |
| 334 | .With(Args<4, 3>(ElementsAreArray(expected_adv_data))) |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 335 | .Times(1) |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 336 | .WillOnce(SaveArg<5>(&set_data_cb)); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 337 | BleAdvertisingManager::Get()->SetData( |
| 338 | advertiser_id, false, |
| 339 | std::vector<uint8_t>({0x02 /* len */, 0x0A /* tx_power */, 0x00}), |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 340 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 341 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 342 | |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 343 | set_data_cb.Run(0); |
| 344 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /* This test verifies that when advertising is non-connectable, flags will not |
| 348 | * be added. */ |
| 349 | TEST_F(BleAdvertisingManagerTest, test_adv_data_not_filling) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 350 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 351 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 352 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 353 | int advertiser_id = reg_inst_id; |
| 354 | |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 355 | parameters_cb set_params_cb; |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 356 | tBTM_BLE_ADV_PARAMS params; |
Jakub Pawlowski | e0750ca | 2016-12-05 11:46:23 -0800 | [diff] [blame] | 357 | params.advertising_event_properties = |
| 358 | BleAdvertisingManager::advertising_prop_legacy_non_connectable; |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 359 | params.tx_power = -15; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 360 | EXPECT_CALL(*hci_mock, SetParameters1(advertiser_id, _, _, _, _, _, _, _, _)) |
| 361 | .Times(1); |
| 362 | EXPECT_CALL(*hci_mock, |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 363 | SetParameters2(_, (uint8_t)params.tx_power, _, _, _, _, _, _)) |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 364 | .Times(1) |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 365 | .WillOnce(SaveArg<7>(&set_params_cb)); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 366 | BleAdvertisingManager::Get()->SetParameters( |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 367 | advertiser_id, ¶ms, |
| 368 | Bind(&BleAdvertisingManagerTest::SetParametersCb, |
| 369 | base::Unretained(this))); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 370 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 371 | |
| 372 | // let the set parameters command succeed! |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 373 | set_params_cb.Run(0, -15); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 374 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_params_status); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 375 | |
| 376 | status_cb set_data_cb; |
| 377 | /* verify that flags will not be added */ |
| 378 | uint8_t expected_adv_data[] = { |
| 379 | 0x02 /* len */, 0xFF /* manufacturer specific */, 0x01 /* data */}; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 380 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, _, _, _, _, _)) |
| 381 | .With(Args<4, 3>(ElementsAreArray(expected_adv_data))) |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 382 | .Times(1) |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 383 | .WillOnce(SaveArg<5>(&set_data_cb)); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 384 | BleAdvertisingManager::Get()->SetData( |
| 385 | advertiser_id, false, std::vector<uint8_t>({0x02 /* len */, 0xFF, 0x01}), |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 386 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 387 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 388 | |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 389 | set_data_cb.Run(0); |
| 390 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 391 | } |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 392 | |
| 393 | TEST_F(BleAdvertisingManagerTest, test_reenabling) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 394 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 395 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 396 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 397 | EXPECT_EQ(0, reg_inst_id); |
| 398 | |
| 399 | uint8_t advertiser_id = reg_inst_id; |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 400 | status_cb enable_cb; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 401 | EXPECT_CALL(*hci_mock, |
| 402 | Enable(0x01 /* enable */, |
| 403 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 404 | advertiser_id))), |
| 405 | _)) |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 406 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 407 | .WillOnce(SaveArg<2>(&enable_cb)); |
| 408 | BleAdvertisingManager::Get()->Enable(advertiser_id, true, Bind(DoNothing), 0, |
| 409 | 0, Bind(DoNothing)); |
| 410 | enable_cb.Run(0); |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 411 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 412 | |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 413 | EXPECT_CALL(*hci_mock, |
| 414 | Enable(0x01 /* enable */, |
| 415 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 416 | advertiser_id))), |
| 417 | _)) |
| 418 | .Times(1) |
| 419 | .WillOnce(SaveArg<2>(&enable_cb)); |
| 420 | BleAdvertisingManager::Get()->OnAdvertisingSetTerminated(advertiser_id, 0x00, |
| 421 | 0x01ed, 0x00); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 422 | enable_cb.Run(0); |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 423 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* Make sure that instance is not reenabled if it's already disabled */ |
| 427 | TEST_F(BleAdvertisingManagerTest, test_reenabling_disabled_instance) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 428 | uint8_t advertiser_id = 1; // any unregistered value |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 429 | |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 430 | EXPECT_CALL(*hci_mock, Enable(_, _, _)).Times(Exactly(0)); |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 431 | BleAdvertisingManager::Get()->OnAdvertisingSetTerminated(advertiser_id, 0x00, |
| 432 | 0x05, 0x00); |
Jakub Pawlowski | 06325e3 | 2016-11-14 11:20:52 -0800 | [diff] [blame] | 433 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* This test verifies that the only flow that is currently used on Android, is |
| 437 | * working correctly in happy case scenario. */ |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 438 | TEST_F(BleAdvertisingManagerTest, test_start_advertising_set) { |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 439 | std::vector<uint8_t> adv_data; |
| 440 | std::vector<uint8_t> scan_resp; |
| 441 | tBTM_BLE_ADV_PARAMS params; |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 442 | tBLE_PERIODIC_ADV_PARAMS periodic_params; |
| 443 | periodic_params.enable = false; |
| 444 | std::vector<uint8_t> periodic_data; |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 445 | |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 446 | parameters_cb set_params_cb; |
Jakub Pawlowski | 8c7d060 | 2017-03-16 14:47:55 -0700 | [diff] [blame] | 447 | status_cb set_address_cb; |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 448 | status_cb set_data_cb; |
| 449 | status_cb set_scan_resp_data_cb; |
| 450 | status_cb enable_cb; |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 451 | EXPECT_CALL(*hci_mock, SetParameters1(_, _, _, _, _, _, _, _, _)).Times(1); |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 452 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 453 | .Times(1) |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 454 | .WillOnce(SaveArg<7>(&set_params_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 455 | EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _)) |
Jakub Pawlowski | 8c7d060 | 2017-03-16 14:47:55 -0700 | [diff] [blame] | 456 | .Times(1) |
| 457 | .WillOnce(SaveArg<2>(&set_address_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 458 | EXPECT_CALL(*hci_mock, SetAdvertisingData(_, _, _, _, _, _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 459 | .Times(1) |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 460 | .WillOnce(SaveArg<5>(&set_data_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 461 | EXPECT_CALL(*hci_mock, SetScanResponseData(_, _, _, _, _, _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 462 | .Times(1) |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 463 | .WillOnce(SaveArg<5>(&set_scan_resp_data_cb)); |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 464 | EXPECT_CALL(*hci_mock, Enable(0x01 /* enable */, _, _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 465 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 466 | .WillOnce(SaveArg<2>(&enable_cb)); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 467 | |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 468 | BleAdvertisingManager::Get()->StartAdvertisingSet( |
| 469 | Bind(&BleAdvertisingManagerTest::StartAdvertisingSetCb, |
| 470 | base::Unretained(this)), |
| 471 | ¶ms, adv_data, scan_resp, &periodic_params, periodic_data, |
| 472 | 0 /* duration */, 0 /* maxExtAdvEvents */, Bind(DoNothing2)); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 473 | |
| 474 | // we are a truly gracious fake controller, let the commands succeed! |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 475 | int selected_tx_power = -15; |
| 476 | set_params_cb.Run(0, selected_tx_power); |
Jakub Pawlowski | 8c7d060 | 2017-03-16 14:47:55 -0700 | [diff] [blame] | 477 | set_address_cb.Run(0); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 478 | set_data_cb.Run(0); |
| 479 | set_scan_resp_data_cb.Run(0); |
| 480 | enable_cb.Run(0); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 481 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, start_advertising_set_status); |
| 482 | EXPECT_EQ(selected_tx_power, start_advertising_set_tx_power); |
| 483 | int advertiser_id = start_advertising_set_advertiser_id; |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 484 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 485 | |
| 486 | // ... advertising ... |
| 487 | |
| 488 | // Disable advertiser |
| 489 | status_cb disable_cb; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 490 | EXPECT_CALL(*hci_mock, |
| 491 | Enable(0x00 /* disable */, |
| 492 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 493 | advertiser_id))), |
| 494 | _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 495 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 496 | .WillOnce(SaveArg<2>(&disable_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 497 | status_cb remove_cb; |
| 498 | EXPECT_CALL(*hci_mock, RemoveAdvertisingSet(advertiser_id, _)) |
| 499 | .Times(1) |
| 500 | .WillOnce(SaveArg<1>(&remove_cb)); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 501 | BleAdvertisingManager::Get()->Unregister(advertiser_id); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 502 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 503 | |
| 504 | disable_cb.Run(0); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 505 | remove_cb.Run(0); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | TEST_F(BleAdvertisingManagerTest, test_start_advertising_set_params_failed) { |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 509 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 510 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 511 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 512 | int advertiser_id = reg_inst_id; |
| 513 | |
| 514 | std::vector<uint8_t> adv_data; |
| 515 | std::vector<uint8_t> scan_resp; |
| 516 | tBTM_BLE_ADV_PARAMS params; |
| 517 | |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 518 | parameters_cb set_params_cb; |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 519 | EXPECT_CALL(*hci_mock, SetParameters1(advertiser_id, _, _, _, _, _, _, _, _)) |
| 520 | .Times(1); |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 521 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 522 | .Times(1) |
Jakub Pawlowski | cd0d189 | 2017-02-24 11:35:07 -0800 | [diff] [blame] | 523 | .WillOnce(SaveArg<7>(&set_params_cb)); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 524 | |
Jakub Pawlowski | 6998882 | 2016-12-01 15:32:58 -0800 | [diff] [blame] | 525 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, _, _, _, _, _)) |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 526 | .Times(Exactly(0)); |
| 527 | |
| 528 | BleAdvertisingManager::Get()->StartAdvertising( |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 529 | advertiser_id, |
| 530 | Bind(&BleAdvertisingManagerTest::StartAdvertisingCb, |
| 531 | base::Unretained(this)), |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 532 | ¶ms, adv_data, scan_resp, 0, base::Callback<void(uint8_t)>()); |
Jakub Pawlowski | 3b27656 | 2017-01-25 03:06:49 -0800 | [diff] [blame] | 533 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 534 | |
| 535 | // set params failed |
Jakub Pawlowski | 256afc4 | 2017-03-17 12:31:42 -0700 | [diff] [blame] | 536 | set_params_cb.Run(0x01, 0); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 537 | |
| 538 | // Expect the whole flow to fail right away |
| 539 | EXPECT_EQ(BTM_BLE_MULTI_ADV_FAILURE, start_advertising_status); |
Jakub Pawlowski | a75087e | 2016-11-17 13:27:28 -0800 | [diff] [blame] | 540 | } |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 541 | |
| 542 | TEST_F(BleAdvertisingManagerTest, test_data_sender) { |
| 543 | // prepare test input vector |
| 544 | const int max_data_size = 1650; |
| 545 | std::vector<uint8_t> data(max_data_size); |
| 546 | for (int i = 0; i < max_data_size; i++) data[i] = i; |
| 547 | |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 548 | BleAdvertisingManager::Get()->RegisterAdvertiser( |
| 549 | Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 550 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 551 | int advertiser_id = reg_inst_id; |
| 552 | |
| 553 | status_cb set_data_cb; |
| 554 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, FIRST, _, 251, _, _)) |
| 555 | .Times(1) |
| 556 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 557 | EXPECT_CALL(*hci_mock, |
| 558 | SetAdvertisingData(advertiser_id, INTERMEDIATE, _, 251, _, _)) |
| 559 | .Times(5) |
| 560 | .WillRepeatedly(SaveArg<5>(&set_data_cb)); |
| 561 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, LAST, _, 144, _, _)) |
| 562 | .Times(1) |
| 563 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 564 | BleAdvertisingManager::Get()->SetData( |
| 565 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 566 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 567 | for (int i = 0; i < 7; i++) { |
| 568 | set_data_cb.Run(0x00); |
| 569 | } |
| 570 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 571 | // Expect the whole flow to succeed |
| 572 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 573 | |
| 574 | // ***************** Try again with different data size ********************* |
| 575 | data.resize(503); |
| 576 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, FIRST, _, 251, _, _)) |
| 577 | .Times(1) |
| 578 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 579 | EXPECT_CALL(*hci_mock, |
| 580 | SetAdvertisingData(advertiser_id, INTERMEDIATE, _, 251, _, _)) |
| 581 | .Times(1) |
| 582 | .WillRepeatedly(SaveArg<5>(&set_data_cb)); |
| 583 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, LAST, _, 1, _, _)) |
| 584 | .Times(1) |
| 585 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 586 | BleAdvertisingManager::Get()->SetData( |
| 587 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 588 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 589 | for (int i = 0; i < 3; i++) { |
| 590 | set_data_cb.Run(0x00); |
| 591 | } |
| 592 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 593 | // Expect the whole flow to succeed |
| 594 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 595 | |
| 596 | // ***************** Try again with different data size ********************* |
| 597 | data.resize(502); |
| 598 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, FIRST, _, 251, _, _)) |
| 599 | .Times(1) |
| 600 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 601 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, LAST, _, 251, _, _)) |
| 602 | .Times(1) |
| 603 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 604 | BleAdvertisingManager::Get()->SetData( |
| 605 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 606 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 607 | for (int i = 0; i < 2; i++) { |
| 608 | set_data_cb.Run(0x00); |
| 609 | } |
| 610 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 611 | // Expect the whole flow to succeed |
| 612 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 613 | |
| 614 | // ***************** Try again with different data size ********************* |
| 615 | data.resize(501); |
| 616 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, FIRST, _, 251, _, _)) |
| 617 | .Times(1) |
| 618 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 619 | EXPECT_CALL(*hci_mock, SetAdvertisingData(advertiser_id, LAST, _, 250, _, _)) |
| 620 | .Times(1) |
| 621 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 622 | BleAdvertisingManager::Get()->SetData( |
| 623 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 624 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 625 | for (int i = 0; i < 2; i++) { |
| 626 | set_data_cb.Run(0x00); |
| 627 | } |
| 628 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 629 | // Expect the whole flow to succeed |
| 630 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 631 | |
| 632 | // ***************** Try again with different data size ********************* |
| 633 | data.resize(251); |
| 634 | EXPECT_CALL(*hci_mock, |
| 635 | SetAdvertisingData(advertiser_id, COMPLETE, _, 251, _, _)) |
| 636 | .Times(1) |
| 637 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 638 | BleAdvertisingManager::Get()->SetData( |
| 639 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 640 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 641 | set_data_cb.Run(0x00); |
| 642 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 643 | // Expect the whole flow to succeed |
| 644 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 645 | |
| 646 | // ***************** Try again with different data size ********************* |
| 647 | data.resize(120); |
| 648 | EXPECT_CALL(*hci_mock, |
| 649 | SetAdvertisingData(advertiser_id, COMPLETE, _, 120, _, _)) |
| 650 | .Times(1) |
| 651 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 652 | BleAdvertisingManager::Get()->SetData( |
| 653 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 654 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 655 | set_data_cb.Run(0x00); |
| 656 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 657 | // Expect the whole flow to succeed |
| 658 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 659 | |
| 660 | // ***************** Try again with different data size ********************* |
| 661 | data.resize(0); |
| 662 | EXPECT_CALL(*hci_mock, |
| 663 | SetAdvertisingData(advertiser_id, COMPLETE, _, 0, _, _)) |
| 664 | .Times(1) |
| 665 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 666 | BleAdvertisingManager::Get()->SetData( |
| 667 | advertiser_id, false, data, |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 668 | Bind(&BleAdvertisingManagerTest::SetDataCb, base::Unretained(this))); |
Jakub Pawlowski | 331c801 | 2017-03-16 22:10:32 -0700 | [diff] [blame] | 669 | set_data_cb.Run(0x00); |
| 670 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 671 | // Expect the whole flow to succeed |
| 672 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, set_data_status); |
| 673 | } |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 674 | |
| 675 | /* This test makes sure that conectable advertisment with timeout will get it's |
| 676 | * address updated once the timeout passes and one tries to enable it again.*/ |
| 677 | TEST_F(BleAdvertisingManagerTest, |
| 678 | test_connectable_address_update_during_timeout) { |
| 679 | std::vector<uint8_t> adv_data; |
| 680 | std::vector<uint8_t> scan_resp; |
| 681 | tBTM_BLE_ADV_PARAMS params; |
| 682 | params.advertising_event_properties = 0x1 /* connectable */; |
| 683 | tBLE_PERIODIC_ADV_PARAMS periodic_params; |
| 684 | periodic_params.enable = false; |
| 685 | std::vector<uint8_t> periodic_data; |
| 686 | |
| 687 | uint8_t maxExtAdvEvents = 50; |
| 688 | |
| 689 | parameters_cb set_params_cb; |
| 690 | status_cb set_address_cb; |
| 691 | status_cb set_data_cb; |
| 692 | status_cb set_scan_resp_data_cb; |
| 693 | status_cb enable_cb; |
| 694 | EXPECT_CALL(*hci_mock, SetParameters1(_, _, _, _, _, _, _, _, _)).Times(1); |
| 695 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
| 696 | .Times(1) |
| 697 | .WillOnce(SaveArg<7>(&set_params_cb)); |
| 698 | EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _)) |
| 699 | .Times(1) |
| 700 | .WillOnce(SaveArg<2>(&set_address_cb)); |
| 701 | EXPECT_CALL(*hci_mock, SetAdvertisingData(_, _, _, _, _, _)) |
| 702 | .Times(1) |
| 703 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 704 | EXPECT_CALL(*hci_mock, SetScanResponseData(_, _, _, _, _, _)) |
| 705 | .Times(1) |
| 706 | .WillOnce(SaveArg<5>(&set_scan_resp_data_cb)); |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 707 | EXPECT_CALL( |
| 708 | *hci_mock, |
| 709 | Enable( |
| 710 | 0x01 /* enable */, |
| 711 | AllOf(SizeIs(1), |
| 712 | Contains(Field(&SetEnableData::max_extended_advertising_events, |
| 713 | maxExtAdvEvents))), |
| 714 | _)) |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 715 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 716 | .WillOnce(SaveArg<2>(&enable_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 717 | |
| 718 | BleAdvertisingManager::Get()->StartAdvertisingSet( |
| 719 | Bind(&BleAdvertisingManagerTest::StartAdvertisingSetCb, |
| 720 | base::Unretained(this)), |
| 721 | ¶ms, adv_data, scan_resp, &periodic_params, periodic_data, |
| 722 | 0 /* duration */, maxExtAdvEvents, Bind(DoNothing2)); |
| 723 | |
| 724 | // we are a truly gracious fake controller, let the commands succeed! |
| 725 | int selected_tx_power = -15; |
| 726 | set_params_cb.Run(0, selected_tx_power); |
| 727 | set_address_cb.Run(0); |
| 728 | set_data_cb.Run(0); |
| 729 | set_scan_resp_data_cb.Run(0); |
| 730 | enable_cb.Run(0); |
| 731 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, start_advertising_set_status); |
| 732 | EXPECT_EQ(selected_tx_power, start_advertising_set_tx_power); |
| 733 | int advertiser_id = start_advertising_set_advertiser_id; |
| 734 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 735 | |
| 736 | // ... advertising ... |
| 737 | |
| 738 | // No HCI calls should be triggered, becuase there is a timeout on a |
| 739 | // connectable advertisement. |
| 740 | TriggerRandomAddressUpdate(); |
| 741 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 742 | |
| 743 | // Set terminated because we advertised maxExtAdvEvents times! |
| 744 | BleAdvertisingManager::Get()->OnAdvertisingSetTerminated( |
| 745 | 0x43 /*status */, advertiser_id, 0x00 /* conn_handle*/, maxExtAdvEvents); |
| 746 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 747 | |
| 748 | // Try to Enable the advertiser. It should first update it's random address. |
| 749 | EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _)) |
| 750 | .Times(1) |
| 751 | .WillOnce(SaveArg<2>(&set_address_cb)); |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 752 | EXPECT_CALL( |
| 753 | *hci_mock, |
| 754 | Enable( |
| 755 | 0x01 /* enable */, |
| 756 | AllOf(SizeIs(1), |
| 757 | Contains(Field(&SetEnableData::max_extended_advertising_events, |
| 758 | maxExtAdvEvents))), |
| 759 | _)) |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 760 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 761 | .WillOnce(SaveArg<2>(&enable_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 762 | BleAdvertisingManager::Get()->Enable( |
| 763 | advertiser_id, true, |
| 764 | Bind(&BleAdvertisingManagerTest::EnableCb, base::Unretained(this)), 0, |
| 765 | maxExtAdvEvents, Bind(DoNothing)); |
| 766 | set_address_cb.Run(0); |
| 767 | enable_cb.Run(0); |
| 768 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 769 | |
| 770 | // Disable advertiser |
| 771 | status_cb disable_cb; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 772 | EXPECT_CALL(*hci_mock, |
| 773 | Enable(0x00 /* disable */, |
| 774 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 775 | advertiser_id))), |
| 776 | _)) |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 777 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 778 | .WillOnce(SaveArg<2>(&disable_cb)); |
Jakub Pawlowski | 1f62c12 | 2017-04-04 04:08:19 -0700 | [diff] [blame] | 779 | status_cb remove_cb; |
| 780 | EXPECT_CALL(*hci_mock, RemoveAdvertisingSet(advertiser_id, _)) |
| 781 | .Times(1) |
| 782 | .WillOnce(SaveArg<1>(&remove_cb)); |
| 783 | BleAdvertisingManager::Get()->Unregister(advertiser_id); |
| 784 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 785 | |
| 786 | disable_cb.Run(0); |
| 787 | remove_cb.Run(0); |
| 788 | } |
Sunny Kapdi | c15f64f | 2017-06-02 18:11:05 -0700 | [diff] [blame] | 789 | |
| 790 | /* This test makes sure that periodic advertising is stopped before |
| 791 | * unregistering the advertiser, if it was enabled. */ |
| 792 | TEST_F(BleAdvertisingManagerTest, test_periodic_adv_disable_on_unregister) { |
| 793 | std::vector<uint8_t> adv_data; |
| 794 | std::vector<uint8_t> scan_resp; |
| 795 | tBTM_BLE_ADV_PARAMS params; |
| 796 | params.advertising_event_properties = 0x1 /* connectable */; |
| 797 | tBLE_PERIODIC_ADV_PARAMS periodic_params; |
| 798 | periodic_params.enable = true; // enable periodic advertising |
| 799 | std::vector<uint8_t> periodic_data; |
| 800 | |
| 801 | parameters_cb set_params_cb; |
| 802 | status_cb set_address_cb; |
| 803 | status_cb set_data_cb; |
| 804 | status_cb set_scan_resp_data_cb; |
| 805 | status_cb enable_cb; |
| 806 | status_cb set_periodic_params_cb; |
| 807 | status_cb set_periodic_data_cb; |
| 808 | status_cb set_periodic_enable_cb; |
| 809 | EXPECT_CALL(*hci_mock, SetParameters1(_, _, _, _, _, _, _, _, _)).Times(1); |
| 810 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
| 811 | .Times(1) |
| 812 | .WillOnce(SaveArg<7>(&set_params_cb)); |
| 813 | EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _)) |
| 814 | .Times(1) |
| 815 | .WillOnce(SaveArg<2>(&set_address_cb)); |
| 816 | EXPECT_CALL(*hci_mock, SetAdvertisingData(_, _, _, _, _, _)) |
| 817 | .Times(1) |
| 818 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 819 | EXPECT_CALL(*hci_mock, SetScanResponseData(_, _, _, _, _, _)) |
| 820 | .Times(1) |
| 821 | .WillOnce(SaveArg<5>(&set_scan_resp_data_cb)); |
| 822 | EXPECT_CALL(*hci_mock, SetPeriodicAdvertisingParameters(_, _, _, _, _)) |
| 823 | .Times(1) |
| 824 | .WillOnce(SaveArg<4>(&set_periodic_params_cb)); |
| 825 | EXPECT_CALL(*hci_mock, SetPeriodicAdvertisingData(_, _, _, _, _)) |
| 826 | .Times(1) |
| 827 | .WillOnce(SaveArg<4>(&set_periodic_data_cb)); |
| 828 | EXPECT_CALL(*hci_mock, SetPeriodicAdvertisingEnable(0x01 /* enable */, _, _)) |
| 829 | .Times(1) |
| 830 | .WillOnce(SaveArg<2>(&set_periodic_enable_cb)); |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 831 | EXPECT_CALL(*hci_mock, Enable(0x01 /* enable */, _, _)) |
Sunny Kapdi | c15f64f | 2017-06-02 18:11:05 -0700 | [diff] [blame] | 832 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 833 | .WillOnce(SaveArg<2>(&enable_cb)); |
Sunny Kapdi | c15f64f | 2017-06-02 18:11:05 -0700 | [diff] [blame] | 834 | |
| 835 | BleAdvertisingManager::Get()->StartAdvertisingSet( |
| 836 | Bind(&BleAdvertisingManagerTest::StartAdvertisingSetCb, |
| 837 | base::Unretained(this)), |
| 838 | ¶ms, adv_data, scan_resp, &periodic_params, periodic_data, |
| 839 | 0 /* duration */, 0 /* maxExtAdvEvents */, Bind(DoNothing2)); |
| 840 | |
| 841 | // we are a truly gracious fake controller, let the commands succeed! |
| 842 | int selected_tx_power = -15; |
| 843 | set_params_cb.Run(0, selected_tx_power); |
| 844 | set_address_cb.Run(0); |
| 845 | set_data_cb.Run(0); |
| 846 | set_scan_resp_data_cb.Run(0); |
| 847 | set_periodic_params_cb.Run(0); |
| 848 | set_periodic_data_cb.Run(0); |
| 849 | set_periodic_enable_cb.Run(0); |
| 850 | enable_cb.Run(0); |
| 851 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, start_advertising_set_status); |
| 852 | EXPECT_EQ(selected_tx_power, start_advertising_set_tx_power); |
| 853 | int advertiser_id = start_advertising_set_advertiser_id; |
| 854 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 855 | |
| 856 | // ... advertising ... |
| 857 | |
| 858 | // Unregister advertiser - should disable periodic advertising |
| 859 | status_cb disable_cb; |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 860 | EXPECT_CALL(*hci_mock, |
| 861 | Enable(0x00 /* disable */, |
| 862 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 863 | advertiser_id))), |
| 864 | _)) |
Sunny Kapdi | c15f64f | 2017-06-02 18:11:05 -0700 | [diff] [blame] | 865 | .Times(1) |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 866 | .WillOnce(SaveArg<2>(&disable_cb)); |
Sunny Kapdi | c15f64f | 2017-06-02 18:11:05 -0700 | [diff] [blame] | 867 | status_cb disable_periodic_cb; |
| 868 | EXPECT_CALL(*hci_mock, SetPeriodicAdvertisingEnable(0x00 /* disable */, |
| 869 | advertiser_id, _)) |
| 870 | .Times(1) |
| 871 | .WillOnce(SaveArg<2>(&disable_periodic_cb)); |
| 872 | status_cb remove_cb; |
| 873 | EXPECT_CALL(*hci_mock, RemoveAdvertisingSet(advertiser_id, _)) |
| 874 | .Times(1) |
| 875 | .WillOnce(SaveArg<1>(&remove_cb)); |
| 876 | BleAdvertisingManager::Get()->Unregister(advertiser_id); |
| 877 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 878 | |
| 879 | disable_cb.Run(0); |
| 880 | disable_periodic_cb.Run(0); |
| 881 | remove_cb.Run(0); |
| 882 | } |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 883 | |
| 884 | TEST_F(BleAdvertisingManagerTest, test_suspend_resume) { |
| 885 | for (int i = 0; i < 10; i++) { |
| 886 | BleAdvertisingManager::Get()->RegisterAdvertiser(Bind( |
| 887 | &BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this))); |
| 888 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, reg_status); |
| 889 | EXPECT_EQ(i, reg_inst_id); |
| 890 | } |
| 891 | |
| 892 | std::array<int, 3> enabled = {{1, 3, 9}}; |
| 893 | |
| 894 | for (int advertiser_id : enabled) { |
| 895 | status_cb enable_cb; |
| 896 | EXPECT_CALL(*hci_mock, |
| 897 | Enable(0x01 /* enable */, |
| 898 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 899 | advertiser_id))), |
| 900 | _)) |
| 901 | .Times(1) |
| 902 | .WillOnce(SaveArg<2>(&enable_cb)); |
| 903 | BleAdvertisingManager::Get()->Enable( |
| 904 | advertiser_id, true, |
| 905 | Bind(&BleAdvertisingManagerTest::EnableCb, base::Unretained(this)), 0, |
| 906 | 0, base::Callback<void(uint8_t)>()); |
| 907 | enable_cb.Run(0); |
| 908 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 909 | } |
| 910 | |
| 911 | // we have some advertisers registered, three advertising. |
| 912 | |
| 913 | // Call to Suspend() should disable all running advertisers |
| 914 | status_cb disable_cb; |
| 915 | EXPECT_CALL( |
| 916 | *hci_mock, |
| 917 | Enable(0x00 /* disable */, |
| 918 | AllOf(SizeIs(3), Contains(Field(&SetEnableData::handle, 1)), |
| 919 | Contains(Field(&SetEnableData::handle, 3)), |
| 920 | Contains(Field(&SetEnableData::handle, 9))), |
| 921 | _)) |
| 922 | .Times(1) |
| 923 | .WillOnce(SaveArg<2>(&disable_cb)); |
| 924 | |
| 925 | BleAdvertisingManager::Get()->Suspend(); |
| 926 | |
| 927 | disable_cb.Run(0); |
| 928 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 929 | |
| 930 | // Call to Resume() should re-enable advertisers |
| 931 | status_cb enable_cb; |
| 932 | EXPECT_CALL( |
| 933 | *hci_mock, |
| 934 | Enable(0x01 /* enable */, |
| 935 | AllOf(SizeIs(3), Contains(Field(&SetEnableData::handle, 1)), |
| 936 | Contains(Field(&SetEnableData::handle, 3)), |
| 937 | Contains(Field(&SetEnableData::handle, 9))), |
| 938 | _)) |
| 939 | .Times(1) |
| 940 | .WillOnce(SaveArg<2>(&enable_cb)); |
| 941 | |
| 942 | BleAdvertisingManager::Get()->Resume(); |
| 943 | |
| 944 | enable_cb.Run(0); |
| 945 | |
| 946 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 947 | } |
| 948 | |
| 949 | /* This test makes sure that conectable advertisment with timeout will get it's |
| 950 | * duration and maxExtAdvEvents updated, when it's terminated due to incoming |
| 951 | * connection.*/ |
| 952 | TEST_F(BleAdvertisingManagerTest, test_duration_update_during_timeout) { |
| 953 | std::vector<uint8_t> adv_data; |
| 954 | std::vector<uint8_t> scan_resp; |
| 955 | tBTM_BLE_ADV_PARAMS params; |
| 956 | params.advertising_event_properties = 0x1 /* connectable */; |
| 957 | params.adv_int_min = params.adv_int_max = 0xA0 /* 100ms */; |
| 958 | tBLE_PERIODIC_ADV_PARAMS periodic_params; |
| 959 | periodic_params.enable = false; |
| 960 | std::vector<uint8_t> periodic_data; |
| 961 | |
| 962 | uint8_t maxExtAdvEvents = 50; |
| 963 | uint16_t duration = 500 /* 5s */; |
| 964 | |
| 965 | parameters_cb set_params_cb; |
| 966 | status_cb set_address_cb; |
| 967 | status_cb set_data_cb; |
| 968 | status_cb set_scan_resp_data_cb; |
| 969 | status_cb enable_cb; |
| 970 | EXPECT_CALL(*hci_mock, SetParameters1(_, _, _, _, _, _, _, _, _)).Times(1); |
| 971 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
| 972 | .Times(1) |
| 973 | .WillOnce(SaveArg<7>(&set_params_cb)); |
| 974 | EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _)) |
| 975 | .Times(1) |
| 976 | .WillOnce(SaveArg<2>(&set_address_cb)); |
| 977 | EXPECT_CALL(*hci_mock, SetAdvertisingData(_, _, _, _, _, _)) |
| 978 | .Times(1) |
| 979 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 980 | EXPECT_CALL(*hci_mock, SetScanResponseData(_, _, _, _, _, _)) |
| 981 | .Times(1) |
| 982 | .WillOnce(SaveArg<5>(&set_scan_resp_data_cb)); |
| 983 | EXPECT_CALL( |
| 984 | *hci_mock, |
| 985 | Enable(0x01 /* enable */, |
| 986 | AllOf(SizeIs(1), |
| 987 | Contains(AllOf( |
| 988 | Field(&SetEnableData::max_extended_advertising_events, |
| 989 | maxExtAdvEvents), |
| 990 | Field(&SetEnableData::duration, duration)))), |
| 991 | _)) |
| 992 | .Times(1) |
| 993 | .WillOnce(SaveArg<2>(&enable_cb)); |
| 994 | |
| 995 | BleAdvertisingManager::Get()->StartAdvertisingSet( |
| 996 | Bind(&BleAdvertisingManagerTest::StartAdvertisingSetCb, |
| 997 | base::Unretained(this)), |
| 998 | ¶ms, adv_data, scan_resp, &periodic_params, periodic_data, duration, |
| 999 | maxExtAdvEvents, Bind(DoNothing2)); |
| 1000 | |
| 1001 | // we are a truly gracious fake controller, let the commands succeed! |
| 1002 | int selected_tx_power = -15; |
| 1003 | set_params_cb.Run(0, selected_tx_power); |
| 1004 | set_address_cb.Run(0); |
| 1005 | set_data_cb.Run(0); |
| 1006 | set_scan_resp_data_cb.Run(0); |
| 1007 | enable_cb.Run(0); |
| 1008 | EXPECT_EQ(BTM_BLE_MULTI_ADV_SUCCESS, start_advertising_set_status); |
| 1009 | EXPECT_EQ(selected_tx_power, start_advertising_set_tx_power); |
| 1010 | int advertiser_id = start_advertising_set_advertiser_id; |
| 1011 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 1012 | |
| 1013 | // ... advertising ... |
| 1014 | |
| 1015 | sleep(1); |
| 1016 | |
| 1017 | std::vector<SetEnableData> setEnableData; |
| 1018 | // Set terminated because we received connect request! Should trigger |
| 1019 | // re-enabling of the set |
| 1020 | EXPECT_CALL(*hci_mock, Enable(0x01 /* enable */, _, _)) |
| 1021 | .Times(1) |
| 1022 | .WillOnce(DoAll(SaveArg<1>(&setEnableData), SaveArg<2>(&enable_cb))); |
| 1023 | |
| 1024 | BleAdvertisingManager::Get()->OnAdvertisingSetTerminated( |
| 1025 | 0x00 /* Advertising successfully ended with a connection being created */, |
| 1026 | advertiser_id, 0x01fe /* conn_handle*/, 20 /* completed ExtAdvEvents */); |
| 1027 | enable_cb.Run(0); |
| 1028 | |
| 1029 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 1030 | |
| 1031 | uint16_t new_duration = setEnableData[0].duration; |
| 1032 | uint8_t new_extAdvEvents = setEnableData[0].max_extended_advertising_events; |
| 1033 | |
| 1034 | // Sleep is not super-accurate, so assume the recomputed timeouts are around |
| 1035 | // 4s +/- 100ms |
| 1036 | EXPECT_NEAR((duration - new_duration), 100 /*4s */, 10); |
| 1037 | EXPECT_NEAR((maxExtAdvEvents - new_extAdvEvents), 10, 1); |
| 1038 | |
| 1039 | // Disable advertiser |
| 1040 | status_cb disable_cb; |
| 1041 | EXPECT_CALL(*hci_mock, |
| 1042 | Enable(0x00 /* disable */, |
| 1043 | AllOf(SizeIs(1), Contains(Field(&SetEnableData::handle, |
| 1044 | advertiser_id))), |
| 1045 | _)) |
| 1046 | .Times(1) |
| 1047 | .WillOnce(SaveArg<2>(&disable_cb)); |
| 1048 | status_cb remove_cb; |
| 1049 | EXPECT_CALL(*hci_mock, RemoveAdvertisingSet(advertiser_id, _)) |
| 1050 | .Times(1) |
| 1051 | .WillOnce(SaveArg<1>(&remove_cb)); |
| 1052 | BleAdvertisingManager::Get()->Unregister(advertiser_id); |
| 1053 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 1054 | |
| 1055 | disable_cb.Run(0); |
| 1056 | remove_cb.Run(0); |
| 1057 | } |
| 1058 | |
Jakub Pawlowski | ba72629 | 2017-06-22 09:46:18 -0700 | [diff] [blame] | 1059 | /* This test verifies that stack cleanup, and shutdown happening while there is |
| 1060 | * outstanding HCI command is not triggering the callback */ |
| 1061 | TEST_F(BleAdvertisingManagerTest, test_cleanup_during_execution) { |
| 1062 | std::vector<uint8_t> adv_data; |
| 1063 | std::vector<uint8_t> scan_resp; |
| 1064 | tBTM_BLE_ADV_PARAMS params; |
| 1065 | tBLE_PERIODIC_ADV_PARAMS periodic_params; |
| 1066 | periodic_params.enable = false; |
| 1067 | std::vector<uint8_t> periodic_data; |
| 1068 | |
| 1069 | parameters_cb set_params_cb; |
| 1070 | status_cb set_address_cb; |
| 1071 | status_cb set_data_cb; |
| 1072 | EXPECT_CALL(*hci_mock, SetParameters1(_, _, _, _, _, _, _, _, _)).Times(1); |
| 1073 | EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _)) |
| 1074 | .Times(1) |
| 1075 | .WillOnce(SaveArg<7>(&set_params_cb)); |
| 1076 | EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _)) |
| 1077 | .Times(1) |
| 1078 | .WillOnce(SaveArg<2>(&set_address_cb)); |
| 1079 | EXPECT_CALL(*hci_mock, SetAdvertisingData(_, _, _, _, _, _)) |
| 1080 | .Times(1) |
| 1081 | .WillOnce(SaveArg<5>(&set_data_cb)); |
| 1082 | |
| 1083 | BleAdvertisingManager::Get()->StartAdvertisingSet( |
| 1084 | Bind(&BleAdvertisingManagerTest::StartAdvertisingSetCb, |
| 1085 | base::Unretained(this)), |
| 1086 | ¶ms, adv_data, scan_resp, &periodic_params, periodic_data, |
| 1087 | 0 /* duration */, 0 /* maxExtAdvEvents */, Bind(DoNothing2)); |
| 1088 | |
| 1089 | // we are a truly gracious fake controller, let the commands succeed! |
| 1090 | int selected_tx_power = -15; |
| 1091 | set_params_cb.Run(0, selected_tx_power); |
| 1092 | set_address_cb.Run(0); |
| 1093 | |
| 1094 | // Someone shut down the stack in the middle of flow, when the HCI Set |
| 1095 | // Advertise Data was scheduled! |
| 1096 | BleAdvertisingManager::Get()->CleanUp(); |
| 1097 | |
| 1098 | // The HCI call returns with status, and tries to execute the callback. This |
| 1099 | // should just silently drop the call. If it got executed, we would get crash, |
| 1100 | // because BleAdvertisingManager object was already deleted. |
| 1101 | set_data_cb.Run(0); |
| 1102 | |
| 1103 | ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); |
| 1104 | } |
| 1105 | |
Jakub Pawlowski | 757e9b2 | 2017-08-28 09:56:13 -0700 | [diff] [blame] | 1106 | extern void testRecomputeTimeout1(); |
| 1107 | extern void testRecomputeTimeout2(); |
| 1108 | extern void testRecomputeTimeout3(); |
| 1109 | |
| 1110 | TEST_F(BleAdvertisingManagerTest, test_recompute_timeout) { |
| 1111 | testRecomputeTimeout1(); |
| 1112 | testRecomputeTimeout2(); |
| 1113 | testRecomputeTimeout3(); |
| 1114 | } |