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

Side by Side Diff: device/bluetooth/bluez/bluetooth_bluez_unittest.cc

Issue 2063353002: device/bluetooth: split out transport enum (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renaming header, moving TransportMask back into filter Created 4 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
17 #include "device/bluetooth/bluetooth_adapter.h" 17 #include "device/bluetooth/bluetooth_adapter.h"
18 #include "device/bluetooth/bluetooth_adapter_factory.h" 18 #include "device/bluetooth/bluetooth_adapter_factory.h"
19 #include "device/bluetooth/bluetooth_device.h" 19 #include "device/bluetooth/bluetooth_device.h"
20 #include "device/bluetooth/bluetooth_discovery_session.h" 20 #include "device/bluetooth/bluetooth_discovery_session.h"
21 #include "device/bluetooth/bluetooth_types.h"
21 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 22 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
22 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" 23 #include "device/bluetooth/bluez/bluetooth_device_bluez.h"
23 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" 24 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h"
24 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 25 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
25 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 26 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
26 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" 27 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
27 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 28 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
28 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" 29 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h"
29 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" 30 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h"
30 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 31 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 #include "third_party/cros_system_api/dbus/service_constants.h" 33 #include "third_party/cros_system_api/dbus/service_constants.h"
33 34
34 using device::BluetoothAdapter; 35 using device::BluetoothAdapter;
35 using device::BluetoothAdapterFactory; 36 using device::BluetoothAdapterFactory;
36 using device::BluetoothAudioSink; 37 using device::BluetoothAudioSink;
37 using device::BluetoothDevice; 38 using device::BluetoothDevice;
38 using device::BluetoothDiscoveryFilter; 39 using device::BluetoothDiscoveryFilter;
39 using device::BluetoothDiscoverySession; 40 using device::BluetoothDiscoverySession;
41 using device::BluetoothTransport;
40 using device::BluetoothUUID; 42 using device::BluetoothUUID;
41 using device::TestBluetoothAdapterObserver; 43 using device::TestBluetoothAdapterObserver;
42 44
43 namespace bluez { 45 namespace bluez {
44 46
45 namespace { 47 namespace {
46 48
47 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the 49 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the
48 // connection info to the bound argument. 50 // connection info to the bound argument.
49 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, 51 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out,
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 EXPECT_FALSE(adapter_->IsDiscovering()); 1436 EXPECT_FALSE(adapter_->IsDiscovering());
1435 } 1437 }
1436 1438
1437 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) { 1439 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) {
1438 // Test a simulated discovery session. 1440 // Test a simulated discovery session.
1439 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1441 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1440 GetAdapter(); 1442 GetAdapter();
1441 1443
1442 TestBluetoothAdapterObserver observer(adapter_); 1444 TestBluetoothAdapterObserver observer(adapter_);
1443 1445
1444 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1446 BluetoothDiscoveryFilter* df =
1445 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1447 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1446 df->SetRSSI(-60); 1448 df->SetRSSI(-60);
1447 df->AddUUID(BluetoothUUID("1000")); 1449 df->AddUUID(BluetoothUUID("1000"));
1448 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1450 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1449 1451
1450 adapter_->SetPowered( 1452 adapter_->SetPowered(
1451 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1453 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1452 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1454 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1453 adapter_->StartDiscoverySessionWithFilter( 1455 adapter_->StartDiscoverySessionWithFilter(
1454 std::move(discovery_filter), 1456 std::move(discovery_filter),
1455 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1457 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 EXPECT_EQ(nullptr, filter); 1496 EXPECT_EQ(nullptr, filter);
1495 } 1497 }
1496 1498
1497 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { 1499 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) {
1498 // Test a simulated discovery session. 1500 // Test a simulated discovery session.
1499 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1501 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1500 GetAdapter(); 1502 GetAdapter();
1501 1503
1502 TestBluetoothAdapterObserver observer(adapter_); 1504 TestBluetoothAdapterObserver observer(adapter_);
1503 1505
1504 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1506 BluetoothDiscoveryFilter* df =
1505 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1507 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1506 df->SetRSSI(-60); 1508 df->SetRSSI(-60);
1507 df->AddUUID(BluetoothUUID("1000")); 1509 df->AddUUID(BluetoothUUID("1000"));
1508 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1510 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1509 1511
1510 adapter_->SetPowered( 1512 adapter_->SetPowered(
1511 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1513 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1512 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1514 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1513 EXPECT_EQ(1, callback_count_); 1515 EXPECT_EQ(1, callback_count_);
1514 callback_count_ = 0; 1516 callback_count_ = 0;
1515 1517
(...skipping 21 matching lines...) Expand all
1537 // This test queues two requests to StartDiscovery with pre set filter. This 1539 // This test queues two requests to StartDiscovery with pre set filter. This
1538 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery 1540 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery
1539 // DBus calls 1541 // DBus calls
1540 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { 1542 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) {
1541 // Test a simulated discovery session. 1543 // Test a simulated discovery session.
1542 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1544 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1543 GetAdapter(); 1545 GetAdapter();
1544 1546
1545 TestBluetoothAdapterObserver observer(adapter_); 1547 TestBluetoothAdapterObserver observer(adapter_);
1546 1548
1547 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1549 BluetoothDiscoveryFilter* df =
1548 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1550 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1549 df->SetRSSI(-60); 1551 df->SetRSSI(-60);
1550 df->AddUUID(BluetoothUUID("1000")); 1552 df->AddUUID(BluetoothUUID("1000"));
1551 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1553 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1552 1554
1553 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 1555 BluetoothDiscoveryFilter* df2 =
1554 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 1556 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_CLASSIC);
1555 df2->SetRSSI(-65); 1557 df2->SetRSSI(-65);
1556 df2->AddUUID(BluetoothUUID("1002")); 1558 df2->AddUUID(BluetoothUUID("1002"));
1557 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 1559 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
1558 1560
1559 adapter_->SetPowered( 1561 adapter_->SetPowered(
1560 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1562 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1561 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1563 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1562 1564
1563 EXPECT_EQ(1, callback_count_); 1565 EXPECT_EQ(1, callback_count_);
1564 EXPECT_EQ(0, error_callback_count_); 1566 EXPECT_EQ(0, error_callback_count_);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). 1634 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending).
1633 // Make the first SetDiscoveryFilter fail and the second one succeed. It should 1635 // Make the first SetDiscoveryFilter fail and the second one succeed. It should
1634 // end up with one active discovery session. 1636 // end up with one active discovery session.
1635 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) { 1637 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) {
1636 // Test a simulated discovery session. 1638 // Test a simulated discovery session.
1637 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1639 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1638 GetAdapter(); 1640 GetAdapter();
1639 1641
1640 TestBluetoothAdapterObserver observer(adapter_); 1642 TestBluetoothAdapterObserver observer(adapter_);
1641 1643
1642 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1644 BluetoothDiscoveryFilter* df =
1643 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1645 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1644 df->SetRSSI(-60); 1646 df->SetRSSI(-60);
1645 df->AddUUID(BluetoothUUID("1000")); 1647 df->AddUUID(BluetoothUUID("1000"));
1646 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1648 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1647 1649
1648 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 1650 BluetoothDiscoveryFilter* df2 =
1649 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 1651 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_CLASSIC);
1650 df2->SetRSSI(-65); 1652 df2->SetRSSI(-65);
1651 df2->AddUUID(BluetoothUUID("1002")); 1653 df2->AddUUID(BluetoothUUID("1002"));
1652 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 1654 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
1653 1655
1654 adapter_->SetPowered( 1656 adapter_->SetPowered(
1655 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1657 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1656 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1658 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1657 1659
1658 EXPECT_EQ(1, callback_count_); 1660 EXPECT_EQ(1, callback_count_);
1659 EXPECT_EQ(0, error_callback_count_); 1661 EXPECT_EQ(0, error_callback_count_);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 EXPECT_EQ(1, observer.discovering_changed_count()); 1753 EXPECT_EQ(1, observer.discovering_changed_count());
1752 observer.Reset(); 1754 observer.Reset();
1753 1755
1754 auto null_instance = std::unique_ptr<BluetoothDiscoveryFilter>(); 1756 auto null_instance = std::unique_ptr<BluetoothDiscoveryFilter>();
1755 null_instance.reset(); 1757 null_instance.reset();
1756 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); 1758 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get());
1757 1759
1758 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1760 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1759 EXPECT_EQ(nullptr, filter); 1761 EXPECT_EQ(nullptr, filter);
1760 1762
1761 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1763 BluetoothDiscoveryFilter* df =
1762 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1764 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1763 df->SetRSSI(-60); 1765 df->SetRSSI(-60);
1764 df->AddUUID(BluetoothUUID("1000")); 1766 df->AddUUID(BluetoothUUID("1000"));
1765 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1767 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1766 1768
1767 discovery_sessions_[0]->SetDiscoveryFilter( 1769 discovery_sessions_[0]->SetDiscoveryFilter(
1768 std::move(discovery_filter), 1770 std::move(discovery_filter),
1769 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1771 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1770 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1772 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1771 1773
1772 message_loop_.Run(); 1774 message_loop_.Run();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 EXPECT_EQ(0, error_callback_count_); 1817 EXPECT_EQ(0, error_callback_count_);
1816 EXPECT_TRUE(adapter_->IsPowered()); 1818 EXPECT_TRUE(adapter_->IsPowered());
1817 callback_count_ = 0; 1819 callback_count_ = 0;
1818 1820
1819 TestBluetoothAdapterObserver observer(adapter_); 1821 TestBluetoothAdapterObserver observer(adapter_);
1820 1822
1821 // Request device discovery with pre-set filter 3 times. 1823 // Request device discovery with pre-set filter 3 times.
1822 for (int i = 0; i < 3; i++) { 1824 for (int i = 0; i < 3; i++) {
1823 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter; 1825 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter;
1824 if (i == 0) { 1826 if (i == 0) {
1825 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1827 BluetoothDiscoveryFilter* df =
1826 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1828 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1827 df->SetRSSI(-85); 1829 df->SetRSSI(-85);
1828 df->AddUUID(BluetoothUUID("1000")); 1830 df->AddUUID(BluetoothUUID("1000"));
1829 discovery_filter.reset(df); 1831 discovery_filter.reset(df);
1830 } else if (i == 1) { 1832 } else if (i == 1) {
1831 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1833 BluetoothDiscoveryFilter* df =
1832 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1834 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1833 df->SetRSSI(-60); 1835 df->SetRSSI(-60);
1834 df->AddUUID(BluetoothUUID("1020")); 1836 df->AddUUID(BluetoothUUID("1020"));
1835 df->AddUUID(BluetoothUUID("1001")); 1837 df->AddUUID(BluetoothUUID("1001"));
1836 discovery_filter.reset(df); 1838 discovery_filter.reset(df);
1837 } else if (i == 2) { 1839 } else if (i == 2) {
1838 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1840 BluetoothDiscoveryFilter* df =
1839 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1841 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1840 df->SetRSSI(-65); 1842 df->SetRSSI(-65);
1841 df->AddUUID(BluetoothUUID("1020")); 1843 df->AddUUID(BluetoothUUID("1020"));
1842 df->AddUUID(BluetoothUUID("1003")); 1844 df->AddUUID(BluetoothUUID("1003"));
1843 discovery_filter.reset(df); 1845 discovery_filter.reset(df);
1844 } 1846 }
1845 1847
1846 adapter_->StartDiscoverySessionWithFilter( 1848 adapter_->StartDiscoverySessionWithFilter(
1847 std::move(discovery_filter), 1849 std::move(discovery_filter),
1848 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1850 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1849 base::Unretained(this)), 1851 base::Unretained(this)),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); 1941 EXPECT_FALSE(discovery_sessions_[1]->IsActive());
1940 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); 1942 EXPECT_TRUE(discovery_sessions_[2]->IsActive());
1941 1943
1942 callback_count_ = 0; 1944 callback_count_ = 0;
1943 1945
1944 // Request device discovery 3 times. 1946 // Request device discovery 3 times.
1945 for (int i = 0; i < 3; i++) { 1947 for (int i = 0; i < 3; i++) {
1946 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter; 1948 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter;
1947 1949
1948 if (i == 0) { 1950 if (i == 0) {
1949 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1951 BluetoothDiscoveryFilter* df =
1950 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1952 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1951 df->SetRSSI(-85); 1953 df->SetRSSI(-85);
1952 df->AddUUID(BluetoothUUID("1000")); 1954 df->AddUUID(BluetoothUUID("1000"));
1953 discovery_filter.reset(df); 1955 discovery_filter.reset(df);
1954 } else if (i == 1) { 1956 } else if (i == 1) {
1955 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1957 BluetoothDiscoveryFilter* df =
1956 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1958 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1957 df->SetRSSI(-60); 1959 df->SetRSSI(-60);
1958 df->AddUUID(BluetoothUUID("1020")); 1960 df->AddUUID(BluetoothUUID("1020"));
1959 df->AddUUID(BluetoothUUID("1001")); 1961 df->AddUUID(BluetoothUUID("1001"));
1960 discovery_filter.reset(df); 1962 discovery_filter.reset(df);
1961 } else if (i == 2) { 1963 } else if (i == 2) {
1962 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1964 BluetoothDiscoveryFilter* df =
1963 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1965 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
1964 df->SetRSSI(-65); 1966 df->SetRSSI(-65);
1965 df->AddUUID(BluetoothUUID("1020")); 1967 df->AddUUID(BluetoothUUID("1020"));
1966 df->AddUUID(BluetoothUUID("1003")); 1968 df->AddUUID(BluetoothUUID("1003"));
1967 discovery_filter.reset(df); 1969 discovery_filter.reset(df);
1968 } 1970 }
1969 1971
1970 adapter_->StartDiscoverySessionWithFilter( 1972 adapter_->StartDiscoverySessionWithFilter(
1971 std::move(discovery_filter), 1973 std::move(discovery_filter),
1972 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1974 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1973 base::Unretained(this)), 1975 base::Unretained(this)),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2036 } 2038 }
2037 2039
2038 // This unit test asserts that filter merging logic works correctly for filtered 2040 // This unit test asserts that filter merging logic works correctly for filtered
2039 // discovery requests done via the BluetoothAdapter. 2041 // discovery requests done via the BluetoothAdapter.
2040 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) { 2042 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) {
2041 GetAdapter(); 2043 GetAdapter();
2042 adapter_->SetPowered( 2044 adapter_->SetPowered(
2043 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 2045 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
2044 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2046 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2045 2047
2046 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 2048 BluetoothDiscoveryFilter* df =
2047 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 2049 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
2048 df->SetRSSI(-15); 2050 df->SetRSSI(-15);
2049 df->AddUUID(BluetoothUUID("1000")); 2051 df->AddUUID(BluetoothUUID("1000"));
2050 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 2052 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
2051 2053
2052 adapter_->StartDiscoverySessionWithFilter( 2054 adapter_->StartDiscoverySessionWithFilter(
2053 std::move(discovery_filter), 2055 std::move(discovery_filter),
2054 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2056 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2055 base::Unretained(this)), 2057 base::Unretained(this)),
2056 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2058 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2057 2059
2058 message_loop_.Run(); 2060 message_loop_.Run();
2059 2061
2060 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2062 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2061 EXPECT_EQ("le", *filter->transport); 2063 EXPECT_EQ("le", *filter->transport);
2062 EXPECT_EQ(-15, *filter->rssi); 2064 EXPECT_EQ(-15, *filter->rssi);
2063 EXPECT_EQ(nullptr, filter->pathloss.get()); 2065 EXPECT_EQ(nullptr, filter->pathloss.get());
2064 std::vector<std::string> uuids = *filter->uuids; 2066 std::vector<std::string> uuids = *filter->uuids;
2065 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2067 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2066 2068
2067 df = new BluetoothDiscoveryFilter( 2069 df = new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_LE);
2068 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
2069 df->SetRSSI(-60); 2070 df->SetRSSI(-60);
2070 df->AddUUID(BluetoothUUID("1020")); 2071 df->AddUUID(BluetoothUUID("1020"));
2071 df->AddUUID(BluetoothUUID("1001")); 2072 df->AddUUID(BluetoothUUID("1001"));
2072 discovery_filter = std::unique_ptr<BluetoothDiscoveryFilter>(df); 2073 discovery_filter = std::unique_ptr<BluetoothDiscoveryFilter>(df);
2073 2074
2074 adapter_->StartDiscoverySessionWithFilter( 2075 adapter_->StartDiscoverySessionWithFilter(
2075 std::move(discovery_filter), 2076 std::move(discovery_filter),
2076 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2077 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2077 base::Unretained(this)), 2078 base::Unretained(this)),
2078 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2079 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2079 2080
2080 message_loop_.Run(); 2081 message_loop_.Run();
2081 2082
2082 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2083 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2083 EXPECT_EQ("le", *filter->transport); 2084 EXPECT_EQ("le", *filter->transport);
2084 EXPECT_EQ(-60, *filter->rssi); 2085 EXPECT_EQ(-60, *filter->rssi);
2085 EXPECT_EQ(nullptr, filter->pathloss.get()); 2086 EXPECT_EQ(nullptr, filter->pathloss.get());
2086 uuids = *filter->uuids; 2087 uuids = *filter->uuids;
2087 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2088 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2088 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2089 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2089 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2090 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2090 2091
2091 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( 2092 BluetoothDiscoveryFilter* df3 =
2092 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 2093 new BluetoothDiscoveryFilter(BluetoothTransport::TRANSPORT_CLASSIC);
2093 df3->SetRSSI(-65); 2094 df3->SetRSSI(-65);
2094 df3->AddUUID(BluetoothUUID("1020")); 2095 df3->AddUUID(BluetoothUUID("1020"));
2095 df3->AddUUID(BluetoothUUID("1003")); 2096 df3->AddUUID(BluetoothUUID("1003"));
2096 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 2097 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
2097 2098
2098 adapter_->StartDiscoverySessionWithFilter( 2099 adapter_->StartDiscoverySessionWithFilter(
2099 std::move(discovery_filter3), 2100 std::move(discovery_filter3),
2100 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2101 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2101 base::Unretained(this)), 2102 base::Unretained(this)),
2102 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2103 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
(...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after
4481 adapter_->Shutdown(); 4482 adapter_->Shutdown();
4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4483 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4483 4484
4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4485 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4486 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4486 EXPECT_EQ(0, callback_count_); 4487 EXPECT_EQ(0, callback_count_);
4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4488 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4488 } 4489 }
4489 4490
4490 } // namespace bluez 4491 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698