OLD | NEW |
---|---|
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" | 5 #include "device/bluetooth/bluetooth_adapter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 EXPECT_EQ(2u, result.size()); | 888 EXPECT_EQ(2u, result.size()); |
889 for (const auto& pair : result) { | 889 for (const auto& pair : result) { |
890 EXPECT_TRUE(adapter_->GetDevice(pair.first->GetAddress())); | 890 EXPECT_TRUE(adapter_->GetDevice(pair.first->GetAddress())); |
891 EXPECT_TRUE(pair.second.empty()); | 891 EXPECT_TRUE(pair.second.empty()); |
892 } | 892 } |
893 EXPECT_EQ(BluetoothDevice::UUIDSet({BluetoothUUID(kTestUUIDGenericAccess)}), | 893 EXPECT_EQ(BluetoothDevice::UUIDSet({BluetoothUUID(kTestUUIDGenericAccess)}), |
894 RetrieveConnectedPeripheralServiceUUIDs()); | 894 RetrieveConnectedPeripheralServiceUUIDs()); |
895 EXPECT_EQ(2, observer.device_added_count()); | 895 EXPECT_EQ(2, observer.device_added_count()); |
896 EXPECT_EQ(2u, adapter_->GetDevices().size()); | 896 EXPECT_EQ(2u, adapter_->GetDevices().size()); |
897 } | 897 } |
898 #endif // defined(OS_MACOSX) | |
ortuno
2017/05/04 01:11:49
I'm OK with this change here but could you update
jlebel
2017/05/04 16:38:49
Done.
jlebel
2017/05/04 16:50:31
crrev.com/2863643003
| |
898 | 899 |
899 // Simulate two devices being connected before calling | 900 // Simulate two devices being connected before calling |
900 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with one service filter. | 901 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with one service filter. |
902 #if defined(OS_MACOSX) | |
901 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithFilter) { | 903 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithFilter) { |
902 if (!PlatformSupportsLowEnergy()) { | 904 if (!PlatformSupportsLowEnergy()) { |
903 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 905 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
904 return; | 906 return; |
905 } | 907 } |
906 InitWithFakeAdapter(); | 908 InitWithFakeAdapter(); |
907 TestBluetoothAdapterObserver observer(adapter_); | 909 TestBluetoothAdapterObserver observer(adapter_); |
908 | 910 |
909 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); | 911 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); |
910 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); | 912 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); |
911 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); | 913 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); |
912 device::BluetoothUUID heart_service_uuid = | 914 device::BluetoothUUID heart_service_uuid = |
913 device::BluetoothUUID(kTestUUIDHeartRate); | 915 device::BluetoothUUID(kTestUUIDHeartRate); |
914 discovery_filter.AddUUID(heart_service_uuid); | 916 discovery_filter.AddUUID(heart_service_uuid); |
915 std::unordered_map<BluetoothDevice*, BluetoothDevice::UUIDSet> result = | 917 std::unordered_map<BluetoothDevice*, BluetoothDevice::UUIDSet> result = |
916 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter( | 918 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter( |
917 discovery_filter); | 919 discovery_filter); |
918 | 920 |
919 EXPECT_EQ(1u, result.size()); | 921 EXPECT_EQ(1u, result.size()); |
920 for (const auto& pair : result) { | 922 for (const auto& pair : result) { |
921 EXPECT_EQ(kTestDeviceAddress2, pair.first->GetAddress()); | 923 EXPECT_EQ(kTestDeviceAddress2, pair.first->GetAddress()); |
922 EXPECT_TRUE(adapter_->GetDevice(pair.first->GetAddress())); | 924 EXPECT_TRUE(adapter_->GetDevice(pair.first->GetAddress())); |
923 EXPECT_EQ(BluetoothDevice::UUIDSet({heart_service_uuid}), pair.second); | 925 EXPECT_EQ(BluetoothDevice::UUIDSet({heart_service_uuid}), pair.second); |
924 } | 926 } |
925 EXPECT_EQ(BluetoothDevice::UUIDSet({heart_service_uuid}), | 927 EXPECT_EQ(BluetoothDevice::UUIDSet({heart_service_uuid}), |
926 RetrieveConnectedPeripheralServiceUUIDs()); | 928 RetrieveConnectedPeripheralServiceUUIDs()); |
927 EXPECT_EQ(1, observer.device_added_count()); | 929 EXPECT_EQ(1, observer.device_added_count()); |
928 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 930 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
929 } | 931 } |
932 #endif // defined(OS_MACOSX) | |
930 | 933 |
931 // Simulate two devices being connected before calling | 934 // Simulate two devices being connected before calling |
932 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with one service filter | 935 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with one service filter |
933 // that doesn't match. | 936 // that doesn't match. |
937 #if defined(OS_MACOSX) | |
934 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithWrongFilter) { | 938 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithWrongFilter) { |
935 if (!PlatformSupportsLowEnergy()) { | 939 if (!PlatformSupportsLowEnergy()) { |
936 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 940 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
937 return; | 941 return; |
938 } | 942 } |
939 InitWithFakeAdapter(); | 943 InitWithFakeAdapter(); |
940 TestBluetoothAdapterObserver observer(adapter_); | 944 TestBluetoothAdapterObserver observer(adapter_); |
941 | 945 |
942 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); | 946 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); |
943 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); | 947 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); |
944 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); | 948 BluetoothDiscoveryFilter discovery_filter(BLUETOOTH_TRANSPORT_LE); |
945 discovery_filter.AddUUID(device::BluetoothUUID(kTestUUIDLinkLoss)); | 949 discovery_filter.AddUUID(device::BluetoothUUID(kTestUUIDLinkLoss)); |
946 std::unordered_map<BluetoothDevice*, BluetoothDevice::UUIDSet> result = | 950 std::unordered_map<BluetoothDevice*, BluetoothDevice::UUIDSet> result = |
947 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter( | 951 adapter_->RetrieveGattConnectedDevicesWithDiscoveryFilter( |
948 discovery_filter); | 952 discovery_filter); |
949 | 953 |
950 EXPECT_TRUE(result.empty()); | 954 EXPECT_TRUE(result.empty()); |
951 EXPECT_EQ( | 955 EXPECT_EQ( |
952 BluetoothDevice::UUIDSet({device::BluetoothUUID(kTestUUIDLinkLoss)}), | 956 BluetoothDevice::UUIDSet({device::BluetoothUUID(kTestUUIDLinkLoss)}), |
953 RetrieveConnectedPeripheralServiceUUIDs()); | 957 RetrieveConnectedPeripheralServiceUUIDs()); |
954 EXPECT_EQ(0, observer.device_added_count()); | 958 EXPECT_EQ(0, observer.device_added_count()); |
955 EXPECT_EQ(0u, adapter_->GetDevices().size()); | 959 EXPECT_EQ(0u, adapter_->GetDevices().size()); |
956 } | 960 } |
961 #endif // defined(OS_MACOSX) | |
957 | 962 |
958 // Simulate two devices being connected before calling | 963 // Simulate two devices being connected before calling |
959 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with two service filters | 964 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with two service filters |
960 // that both match. | 965 // that both match. |
966 #if defined(OS_MACOSX) | |
961 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithTwoFilters) { | 967 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceWithTwoFilters) { |
962 if (!PlatformSupportsLowEnergy()) { | 968 if (!PlatformSupportsLowEnergy()) { |
963 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 969 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
964 return; | 970 return; |
965 } | 971 } |
966 InitWithFakeAdapter(); | 972 InitWithFakeAdapter(); |
967 TestBluetoothAdapterObserver observer(adapter_); | 973 TestBluetoothAdapterObserver observer(adapter_); |
968 | 974 |
969 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); | 975 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); |
970 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); | 976 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); |
(...skipping 21 matching lines...) Expand all Loading... | |
992 // Unknown device. | 998 // Unknown device. |
993 EXPECT_TRUE(false); | 999 EXPECT_TRUE(false); |
994 } | 1000 } |
995 } | 1001 } |
996 EXPECT_EQ( | 1002 EXPECT_EQ( |
997 BluetoothDevice::UUIDSet({generic_service_uuid, heart_service_uuid}), | 1003 BluetoothDevice::UUIDSet({generic_service_uuid, heart_service_uuid}), |
998 RetrieveConnectedPeripheralServiceUUIDs()); | 1004 RetrieveConnectedPeripheralServiceUUIDs()); |
999 EXPECT_EQ(2, observer.device_added_count()); | 1005 EXPECT_EQ(2, observer.device_added_count()); |
1000 EXPECT_EQ(2u, adapter_->GetDevices().size()); | 1006 EXPECT_EQ(2u, adapter_->GetDevices().size()); |
1001 } | 1007 } |
1008 #endif // defined(OS_MACOSX) | |
1002 | 1009 |
1003 // Simulate two devices being connected before calling | 1010 // Simulate two devices being connected before calling |
1004 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with one service filter | 1011 // RetrieveGattConnectedDevicesWithDiscoveryFilter() with one service filter |
1005 // that one match device, and then | 1012 // that one match device, and then |
1006 // RetrieveGattConnectedDevicesWithDiscoveryFilter() again. | 1013 // RetrieveGattConnectedDevicesWithDiscoveryFilter() again. |
1014 #if defined(OS_MACOSX) | |
1007 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceTwice) { | 1015 TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceTwice) { |
1008 if (!PlatformSupportsLowEnergy()) { | 1016 if (!PlatformSupportsLowEnergy()) { |
1009 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1017 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
1010 return; | 1018 return; |
1011 } | 1019 } |
1012 InitWithFakeAdapter(); | 1020 InitWithFakeAdapter(); |
1013 TestBluetoothAdapterObserver observer(adapter_); | 1021 TestBluetoothAdapterObserver observer(adapter_); |
1014 | 1022 |
1015 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); | 1023 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::GENERIC_DEVICE); |
1016 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); | 1024 SimulateConnectedLowEnergyDevice(ConnectedDeviceType::HEART_RATE_DEVICE); |
(...skipping 29 matching lines...) Expand all Loading... | |
1046 } | 1054 } |
1047 EXPECT_EQ(BluetoothDevice::UUIDSet({heart_service_uuid}), | 1055 EXPECT_EQ(BluetoothDevice::UUIDSet({heart_service_uuid}), |
1048 RetrieveConnectedPeripheralServiceUUIDs()); | 1056 RetrieveConnectedPeripheralServiceUUIDs()); |
1049 | 1057 |
1050 EXPECT_EQ(0, observer.device_added_count()); | 1058 EXPECT_EQ(0, observer.device_added_count()); |
1051 EXPECT_EQ(1u, adapter_->GetDevices().size()); | 1059 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
1052 } | 1060 } |
1053 #endif // defined(OS_MACOSX) | 1061 #endif // defined(OS_MACOSX) |
1054 | 1062 |
1055 } // namespace device | 1063 } // namespace device |
OLD | NEW |