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

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

Issue 2640883002: Enable more unittests for BlueZ and ChromeOS. (Closed)
Patch Set: Added comment in TearDown. Created 3 years, 11 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_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 "1:A2:B3:C4:D5:E6F", 86 "1:A2:B3:C4:D5:E6F",
87 }; 87 };
88 88
89 for (size_t i = 0; i < arraysize(kValidFormats); ++i) { 89 for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
90 SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'"); 90 SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
91 EXPECT_EQ(std::string(), 91 EXPECT_EQ(std::string(),
92 BluetoothDevice::CanonicalizeAddress(kValidFormats[i])); 92 BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
93 } 93 }
94 } 94 }
95 95
96 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
97 // Verifies basic device properties, e.g. GetAddress, GetName, ... 96 // Verifies basic device properties, e.g. GetAddress, GetName, ...
98 TEST_F(BluetoothTest, LowEnergyDeviceProperties) { 97 TEST_F(BluetoothTest, LowEnergyDeviceProperties) {
99 if (!PlatformSupportsLowEnergy()) { 98 if (!PlatformSupportsLowEnergy()) {
100 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 99 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
101 return; 100 return;
102 } 101 }
103 InitWithFakeAdapter(); 102 InitWithFakeAdapter();
104 StartLowEnergyDiscoverySession(); 103 StartLowEnergyDiscoverySession();
105 BluetoothDevice* device = SimulateLowEnergyDevice(1); 104 BluetoothDevice* device = SimulateLowEnergyDevice(1);
106 ASSERT_TRUE(device); 105 ASSERT_TRUE(device);
107 // Bluetooth class information for BLE device is not available on Windows. 106 // Bluetooth class information for BLE device is not available on Windows.
108 #ifndef OS_WIN 107 #ifndef OS_WIN
109 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); 108 EXPECT_EQ(0x1F00u, device->GetBluetoothClass());
110 #endif 109 #endif
111 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress()); 110 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress());
112 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); 111 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource());
113 EXPECT_EQ(0, device->GetVendorID()); 112 EXPECT_EQ(0, device->GetVendorID());
114 EXPECT_EQ(0, device->GetProductID()); 113 EXPECT_EQ(0, device->GetProductID());
115 EXPECT_EQ(0, device->GetDeviceID()); 114 EXPECT_EQ(0, device->GetDeviceID());
116 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetNameForDisplay()); 115 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetNameForDisplay());
117 EXPECT_FALSE(device->IsPaired()); 116 EXPECT_FALSE(device->IsPaired());
118 UUIDSet uuids = device->GetUUIDs(); 117 UUIDSet uuids = device->GetUUIDs();
119 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAccess))); 118 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAccess)));
120 EXPECT_TRUE( 119 EXPECT_TRUE(
121 base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAttribute))); 120 base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAttribute)));
122 } 121 }
123 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
124 122
125 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
126 // Device with no advertised Service UUIDs. 123 // Device with no advertised Service UUIDs.
127 TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) { 124 TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) {
128 if (!PlatformSupportsLowEnergy()) { 125 if (!PlatformSupportsLowEnergy()) {
129 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 126 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
130 return; 127 return;
131 } 128 }
132 InitWithFakeAdapter(); 129 InitWithFakeAdapter();
133 StartLowEnergyDiscoverySession(); 130 StartLowEnergyDiscoverySession();
134 BluetoothDevice* device = SimulateLowEnergyDevice(3); 131 BluetoothDevice* device = SimulateLowEnergyDevice(3);
135 ASSERT_TRUE(device); 132 ASSERT_TRUE(device);
136 UUIDSet uuids = device->GetUUIDs(); 133 UUIDSet uuids = device->GetUUIDs();
137 EXPECT_EQ(0u, uuids.size()); 134 EXPECT_EQ(0u, uuids.size());
138 } 135 }
139 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
140 136
141 #if defined(OS_MACOSX) 137 #if defined(OS_MACOSX)
142 // TODO(ortuno): Enable on Android once it supports Service Data. 138 // TODO(ortuno): Enable on Android once it supports Service Data.
143 // http://crbug.com/639408 139 // http://crbug.com/639408
144 TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) { 140 TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) {
145 if (!PlatformSupportsLowEnergy()) { 141 if (!PlatformSupportsLowEnergy()) {
146 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 142 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
147 return; 143 return;
148 } 144 }
149 InitWithFakeAdapter(); 145 InitWithFakeAdapter();
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 EXPECT_TRUE(device->GetUUIDs().empty()); 666 EXPECT_TRUE(device->GetUUIDs().empty());
671 #if defined(OS_MACOSX) 667 #if defined(OS_MACOSX)
672 // TODO(ortuno): Enable on Android once it supports Service Data. 668 // TODO(ortuno): Enable on Android once it supports Service Data.
673 // http://crbug.com/639408 669 // http://crbug.com/639408
674 EXPECT_TRUE(device->GetServiceData().empty()); 670 EXPECT_TRUE(device->GetServiceData().empty());
675 #endif // defined(OS_MACOSX) 671 #endif // defined(OS_MACOSX)
676 EXPECT_FALSE(device->GetInquiryTxPower()); 672 EXPECT_FALSE(device->GetInquiryTxPower());
677 } 673 }
678 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 674 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
679 675
680 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) 676 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) || \
677 defined(OS_LINUX)
681 // GetName for Device with no name. 678 // GetName for Device with no name.
682 TEST_F(BluetoothTest, GetName_NullName) { 679 TEST_F(BluetoothTest, GetName_NullName) {
683 if (!PlatformSupportsLowEnergy()) { 680 if (!PlatformSupportsLowEnergy()) {
684 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 681 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
685 return; 682 return;
686 } 683 }
687 InitWithFakeAdapter(); 684 InitWithFakeAdapter();
688 685
689 // StartLowEnergyDiscoverySession is not yet implemented on ChromeOS|bluez, 686 // StartLowEnergyDiscoverySession is not yet implemented on ChromeOS|bluez,
690 // and is non trivial to implement. On ChromeOS, it is not essential for 687 // and is non trivial to implement. On ChromeOS, it is not essential for
691 // this test to operate, and so it is simply skipped. Android at least 688 // this test to operate, and so it is simply skipped. Android at least
692 // does require this step. 689 // does require this step.
693 #if !defined(OS_CHROMEOS) 690 #if !defined(OS_CHROMEOS)
694 StartLowEnergyDiscoverySession(); 691 StartLowEnergyDiscoverySession();
695 #endif 692 #endif
696 693
697 BluetoothDevice* device = SimulateLowEnergyDevice(5); 694 BluetoothDevice* device = SimulateLowEnergyDevice(5);
698 EXPECT_FALSE(device->GetName()); 695 EXPECT_FALSE(device->GetName());
699 } 696 }
700 #endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) 697 #endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) ||
698 // defined(OS_LINUX)
701 699
702 // TODO(506415): Test GetNameForDisplay with a device with no name. 700 // TODO(506415): Test GetNameForDisplay with a device with no name.
703 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which 701 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which
704 // requires string resources to be loaded. For that, something like 702 // requires string resources to be loaded. For that, something like
705 // InitSharedInstance must be run. See unittest files that call that. It will 703 // InitSharedInstance must be run. See unittest files that call that. It will
706 // also require build configuration to generate string resources into a .pak 704 // also require build configuration to generate string resources into a .pak
707 // file. 705 // file.
708 706
709 #if defined(OS_ANDROID) || defined(OS_MACOSX) 707 #if defined(OS_ANDROID) || defined(OS_MACOSX)
710 // Basic CreateGattConnection test. 708 // Basic CreateGattConnection test.
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 1332
1335 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); 1333 BluetoothDevice* device2 = SimulateLowEnergyDevice(6);
1336 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); 1334 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType());
1337 1335
1338 BluetoothDevice* device3 = SimulateClassicDevice(); 1336 BluetoothDevice* device3 = SimulateClassicDevice();
1339 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); 1337 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType());
1340 } 1338 }
1341 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 1339 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
1342 1340
1343 } // namespace device 1341 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_unittest.cc ('k') | device/bluetooth/dbus/fake_bluetooth_device_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698