Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: device/bluetooth/bluetooth_adapter_unittest.cc

Issue 1544323002: Convert Pass()→std::move() in //device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_adapter.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility>
7 10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 13 #include "base/run_loop.h"
11 #include "build/build_config.h" 14 #include "build/build_config.h"
12 #include "device/bluetooth/bluetooth_adapter.h"
13 #include "device/bluetooth/bluetooth_device.h" 15 #include "device/bluetooth/bluetooth_device.h"
14 #include "device/bluetooth/bluetooth_discovery_session.h" 16 #include "device/bluetooth/bluetooth_discovery_session.h"
15 #include "device/bluetooth/test/bluetooth_test.h" 17 #include "device/bluetooth/test/bluetooth_test.h"
16 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 18 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 #if defined(OS_ANDROID) 21 #if defined(OS_ANDROID)
20 #include "device/bluetooth/test/bluetooth_test_android.h" 22 #include "device/bluetooth/test/bluetooth_test_android.h"
21 #elif defined(OS_MACOSX) 23 #elif defined(OS_MACOSX)
22 #include "device/bluetooth/test/bluetooth_test_mac.h" 24 #include "device/bluetooth/test/bluetooth_test_mac.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 void SetDiscoverable(bool discoverable, 56 void SetDiscoverable(bool discoverable,
55 const base::Closure& callback, 57 const base::Closure& callback,
56 const ErrorCallback& error_callback) override {} 58 const ErrorCallback& error_callback) override {}
57 59
58 bool IsDiscovering() const override { return false; } 60 bool IsDiscovering() const override { return false; }
59 61
60 void StartDiscoverySessionWithFilter( 62 void StartDiscoverySessionWithFilter(
61 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, 63 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
62 const DiscoverySessionCallback& callback, 64 const DiscoverySessionCallback& callback,
63 const ErrorCallback& error_callback) override { 65 const ErrorCallback& error_callback) override {
64 OnStartDiscoverySession(discovery_filter.Pass(), callback); 66 OnStartDiscoverySession(std::move(discovery_filter), callback);
65 } 67 }
66 68
67 void StartDiscoverySession(const DiscoverySessionCallback& callback, 69 void StartDiscoverySession(const DiscoverySessionCallback& callback,
68 const ErrorCallback& error_callback) override {} 70 const ErrorCallback& error_callback) override {}
69 void CreateRfcommService( 71 void CreateRfcommService(
70 const BluetoothUUID& uuid, 72 const BluetoothUUID& uuid,
71 const ServiceOptions& options, 73 const ServiceOptions& options,
72 const CreateServiceCallback& callback, 74 const CreateServiceCallback& callback,
73 const CreateServiceErrorCallback& error_callback) override {} 75 const CreateServiceErrorCallback& error_callback) override {}
74 76
(...skipping 12 matching lines...) Expand all
87 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, 89 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
88 const CreateAdvertisementCallback& callback, 90 const CreateAdvertisementCallback& callback,
89 const CreateAdvertisementErrorCallback& error_callback) override {} 91 const CreateAdvertisementErrorCallback& error_callback) override {}
90 92
91 void TestErrorCallback() {} 93 void TestErrorCallback() {}
92 94
93 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; 95 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
94 96
95 void TestOnStartDiscoverySession( 97 void TestOnStartDiscoverySession(
96 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 98 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
97 discovery_sessions_.push_back(discovery_session.Pass()); 99 discovery_sessions_.push_back(std::move(discovery_session));
98 } 100 }
99 101
100 void CleanupSessions() { discovery_sessions_.clear(); } 102 void CleanupSessions() { discovery_sessions_.clear(); }
101 103
102 void InjectFilteredSession( 104 void InjectFilteredSession(
103 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter) { 105 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter) {
104 StartDiscoverySessionWithFilter( 106 StartDiscoverySessionWithFilter(
105 discovery_filter.Pass(), 107 std::move(discovery_filter),
106 base::Bind(&TestBluetoothAdapter::TestOnStartDiscoverySession, 108 base::Bind(&TestBluetoothAdapter::TestOnStartDiscoverySession,
107 base::Unretained(this)), 109 base::Unretained(this)),
108 base::Bind(&TestBluetoothAdapter::TestErrorCallback, 110 base::Bind(&TestBluetoothAdapter::TestErrorCallback,
109 base::Unretained(this))); 111 base::Unretained(this)));
110 } 112 }
111 113
112 protected: 114 protected:
113 ~TestBluetoothAdapter() override {} 115 ~TestBluetoothAdapter() override {}
114 116
115 void AddDiscoverySession( 117 void AddDiscoverySession(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 221
220 discovery_filter = adapter->GetMergedDiscoveryFilterMasked(nullptr); 222 discovery_filter = adapter->GetMergedDiscoveryFilterMasked(nullptr);
221 EXPECT_TRUE(discovery_filter.get() == nullptr); 223 EXPECT_TRUE(discovery_filter.get() == nullptr);
222 } 224 }
223 225
224 TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterRegular) { 226 TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterRegular) {
225 scoped_refptr<TestBluetoothAdapter> adapter = new TestBluetoothAdapter(); 227 scoped_refptr<TestBluetoothAdapter> adapter = new TestBluetoothAdapter();
226 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter; 228 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter;
227 229
228 // make sure adapter have one session wihout filtering. 230 // make sure adapter have one session wihout filtering.
229 adapter->InjectFilteredSession(discovery_filter.Pass()); 231 adapter->InjectFilteredSession(std::move(discovery_filter));
230 232
231 // having one reglar session should result in no filter 233 // having one reglar session should result in no filter
232 scoped_ptr<BluetoothDiscoveryFilter> resulting_filter = 234 scoped_ptr<BluetoothDiscoveryFilter> resulting_filter =
233 adapter->GetMergedDiscoveryFilter(); 235 adapter->GetMergedDiscoveryFilter();
234 EXPECT_TRUE(resulting_filter.get() == nullptr); 236 EXPECT_TRUE(resulting_filter.get() == nullptr);
235 237
236 // omiting no filter when having one reglar session should result in no filter 238 // omiting no filter when having one reglar session should result in no filter
237 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(nullptr); 239 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(nullptr);
238 EXPECT_TRUE(resulting_filter.get() == nullptr); 240 EXPECT_TRUE(resulting_filter.get() == nullptr);
239 241
(...skipping 10 matching lines...) Expand all
250 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 252 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
251 df->SetRSSI(-30); 253 df->SetRSSI(-30);
252 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 254 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
253 255
254 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 256 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter(
255 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 257 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
256 df2->SetRSSI(-65); 258 df2->SetRSSI(-65);
257 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 259 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
258 260
259 // make sure adapter have one session wihout filtering. 261 // make sure adapter have one session wihout filtering.
260 adapter->InjectFilteredSession(discovery_filter.Pass()); 262 adapter->InjectFilteredSession(std::move(discovery_filter));
261 263
262 // DO_NOTHING should have no impact 264 // DO_NOTHING should have no impact
263 resulting_filter = adapter->GetMergedDiscoveryFilter(); 265 resulting_filter = adapter->GetMergedDiscoveryFilter();
264 resulting_filter->GetRSSI(&resulting_rssi); 266 resulting_filter->GetRSSI(&resulting_rssi);
265 EXPECT_EQ(-30, resulting_rssi); 267 EXPECT_EQ(-30, resulting_rssi);
266 268
267 // should not use df2 at all, as it's not associated with adapter yet 269 // should not use df2 at all, as it's not associated with adapter yet
268 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df2); 270 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df2);
269 resulting_filter->GetRSSI(&resulting_rssi); 271 resulting_filter->GetRSSI(&resulting_rssi);
270 EXPECT_EQ(-30, resulting_rssi); 272 EXPECT_EQ(-30, resulting_rssi);
271 273
272 adapter->InjectFilteredSession(discovery_filter2.Pass()); 274 adapter->InjectFilteredSession(std::move(discovery_filter2));
273 275
274 // result of merging two rssi values should be lower one 276 // result of merging two rssi values should be lower one
275 resulting_filter = adapter->GetMergedDiscoveryFilter(); 277 resulting_filter = adapter->GetMergedDiscoveryFilter();
276 resulting_filter->GetRSSI(&resulting_rssi); 278 resulting_filter->GetRSSI(&resulting_rssi);
277 EXPECT_EQ(-65, resulting_rssi); 279 EXPECT_EQ(-65, resulting_rssi);
278 280
279 // ommit bigger value, result should stay same 281 // ommit bigger value, result should stay same
280 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df); 282 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df);
281 resulting_filter->GetRSSI(&resulting_rssi); 283 resulting_filter->GetRSSI(&resulting_rssi);
282 EXPECT_EQ(-65, resulting_rssi); 284 EXPECT_EQ(-65, resulting_rssi);
283 285
284 // ommit lower value, result should change 286 // ommit lower value, result should change
285 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df2); 287 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df2);
286 resulting_filter->GetRSSI(&resulting_rssi); 288 resulting_filter->GetRSSI(&resulting_rssi);
287 EXPECT_EQ(-30, resulting_rssi); 289 EXPECT_EQ(-30, resulting_rssi);
288 290
289 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( 291 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter(
290 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 292 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
291 df3->SetPathloss(60); 293 df3->SetPathloss(60);
292 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 294 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
293 295
294 // when rssi and pathloss are merged, both should be cleared, becuase there is 296 // when rssi and pathloss are merged, both should be cleared, becuase there is
295 // no way to tell which filter will be more generic 297 // no way to tell which filter will be more generic
296 adapter->InjectFilteredSession(discovery_filter3.Pass()); 298 adapter->InjectFilteredSession(std::move(discovery_filter3));
297 resulting_filter = adapter->GetMergedDiscoveryFilter(); 299 resulting_filter = adapter->GetMergedDiscoveryFilter();
298 EXPECT_FALSE(resulting_filter->GetRSSI(&resulting_rssi)); 300 EXPECT_FALSE(resulting_filter->GetRSSI(&resulting_rssi));
299 EXPECT_FALSE(resulting_filter->GetPathloss(&resulting_pathloss)); 301 EXPECT_FALSE(resulting_filter->GetPathloss(&resulting_pathloss));
300 302
301 adapter->CleanupSessions(); 303 adapter->CleanupSessions();
302 } 304 }
303 305
304 TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterTransport) { 306 TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterTransport) {
305 scoped_refptr<TestBluetoothAdapter> adapter = new TestBluetoothAdapter(); 307 scoped_refptr<TestBluetoothAdapter> adapter = new TestBluetoothAdapter();
306 scoped_ptr<BluetoothDiscoveryFilter> resulting_filter; 308 scoped_ptr<BluetoothDiscoveryFilter> resulting_filter;
307 309
308 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 310 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
309 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 311 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
310 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 312 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
311 313
312 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 314 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter(
313 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 315 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
314 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 316 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
315 317
316 adapter->InjectFilteredSession(discovery_filter.Pass()); 318 adapter->InjectFilteredSession(std::move(discovery_filter));
317 319
318 // Just one filter, make sure transport was properly rewritten 320 // Just one filter, make sure transport was properly rewritten
319 resulting_filter = adapter->GetMergedDiscoveryFilter(); 321 resulting_filter = adapter->GetMergedDiscoveryFilter();
320 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC, 322 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC,
321 resulting_filter->GetTransport()); 323 resulting_filter->GetTransport());
322 324
323 adapter->InjectFilteredSession(discovery_filter2.Pass()); 325 adapter->InjectFilteredSession(std::move(discovery_filter2));
324 326
325 // Two filters, should have OR of both transport's 327 // Two filters, should have OR of both transport's
326 resulting_filter = adapter->GetMergedDiscoveryFilter(); 328 resulting_filter = adapter->GetMergedDiscoveryFilter();
327 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL, 329 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL,
328 resulting_filter->GetTransport()); 330 resulting_filter->GetTransport());
329 331
330 // When 1st filter is masked, 2nd filter transport should be returned. 332 // When 1st filter is masked, 2nd filter transport should be returned.
331 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df); 333 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df);
332 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_LE, 334 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_LE,
333 resulting_filter->GetTransport()); 335 resulting_filter->GetTransport());
334 336
335 // When 2nd filter is masked, 1st filter transport should be returned. 337 // When 2nd filter is masked, 1st filter transport should be returned.
336 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df2); 338 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df2);
337 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC, 339 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC,
338 resulting_filter->GetTransport()); 340 resulting_filter->GetTransport());
339 341
340 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( 342 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter(
341 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 343 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
342 df3->CopyFrom(BluetoothDiscoveryFilter( 344 df3->CopyFrom(BluetoothDiscoveryFilter(
343 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL)); 345 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL));
344 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 346 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
345 347
346 // Merging empty filter in should result in empty filter 348 // Merging empty filter in should result in empty filter
347 adapter->InjectFilteredSession(discovery_filter3.Pass()); 349 adapter->InjectFilteredSession(std::move(discovery_filter3));
348 resulting_filter = adapter->GetMergedDiscoveryFilter(); 350 resulting_filter = adapter->GetMergedDiscoveryFilter();
349 EXPECT_TRUE(resulting_filter->IsDefault()); 351 EXPECT_TRUE(resulting_filter->IsDefault());
350 352
351 adapter->CleanupSessions(); 353 adapter->CleanupSessions();
352 } 354 }
353 355
354 TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterAllFields) { 356 TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterAllFields) {
355 scoped_refptr<TestBluetoothAdapter> adapter = new TestBluetoothAdapter(); 357 scoped_refptr<TestBluetoothAdapter> adapter = new TestBluetoothAdapter();
356 int16_t resulting_rssi; 358 int16_t resulting_rssi;
357 std::set<device::BluetoothUUID> resulting_uuids; 359 std::set<device::BluetoothUUID> resulting_uuids;
(...skipping 14 matching lines...) Expand all
372 374
373 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( 375 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter(
374 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 376 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
375 df3->SetRSSI(-65); 377 df3->SetRSSI(-65);
376 df3->SetTransport(BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 378 df3->SetTransport(BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
377 df3->AddUUID(device::BluetoothUUID("1020")); 379 df3->AddUUID(device::BluetoothUUID("1020"));
378 df3->AddUUID(device::BluetoothUUID("1003")); 380 df3->AddUUID(device::BluetoothUUID("1003"));
379 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 381 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
380 382
381 // make sure adapter have one session wihout filtering. 383 // make sure adapter have one session wihout filtering.
382 adapter->InjectFilteredSession(discovery_filter.Pass()); 384 adapter->InjectFilteredSession(std::move(discovery_filter));
383 adapter->InjectFilteredSession(discovery_filter2.Pass()); 385 adapter->InjectFilteredSession(std::move(discovery_filter2));
384 adapter->InjectFilteredSession(discovery_filter3.Pass()); 386 adapter->InjectFilteredSession(std::move(discovery_filter3));
385 387
386 scoped_ptr<BluetoothDiscoveryFilter> resulting_filter = 388 scoped_ptr<BluetoothDiscoveryFilter> resulting_filter =
387 adapter->GetMergedDiscoveryFilter(); 389 adapter->GetMergedDiscoveryFilter();
388 resulting_filter->GetRSSI(&resulting_rssi); 390 resulting_filter->GetRSSI(&resulting_rssi);
389 resulting_filter->GetUUIDs(resulting_uuids); 391 resulting_filter->GetUUIDs(resulting_uuids);
390 EXPECT_TRUE(resulting_filter->GetTransport()); 392 EXPECT_TRUE(resulting_filter->GetTransport());
391 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL, 393 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL,
392 resulting_filter->GetTransport()); 394 resulting_filter->GetTransport());
393 EXPECT_EQ(-85, resulting_rssi); 395 EXPECT_EQ(-85, resulting_rssi);
394 EXPECT_EQ(4UL, resulting_uuids.size()); 396 EXPECT_EQ(4UL, resulting_uuids.size());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // Start discovery and find a device. 608 // Start discovery and find a device.
607 StartLowEnergyDiscoverySession(); 609 StartLowEnergyDiscoverySession();
608 DiscoverLowEnergyDevice(1); 610 DiscoverLowEnergyDevice(1);
609 DiscoverLowEnergyDevice(4); 611 DiscoverLowEnergyDevice(4);
610 EXPECT_EQ(2, observer.device_added_count()); 612 EXPECT_EQ(2, observer.device_added_count());
611 EXPECT_EQ(2u, adapter_->GetDevices().size()); 613 EXPECT_EQ(2u, adapter_->GetDevices().size());
612 } 614 }
613 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 615 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
614 616
615 } // namespace device 617 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_profile_bluez.cc ('k') | device/bluetooth/bluetooth_advertisement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698